e57f1b837e662b3d7690b87c1fc0c4784403c3e7
[openemr.git] / library / classes / ClinicalTypes / LabResult.php
blobe57f1b837e662b3d7690b87c1fc0c4784403c3e7
1 <?php
2 // Copyright (C) 2011 Ken Chapple <ken@mi-squared.com>
3 //
4 // This program is free software; you can redistribute it and/or
5 // modify it under the terms of the GNU General Public License
6 // as published by the Free Software Foundation; either version 2
7 // of the License, or (at your option) any later version.
8 //
9 require_once( 'ClinicalType.php' );
11 class LabResult extends ClinicalType
13 const OPTION_RANGE = 'range';
15 const HB1AC_TEST = 'lab_hb1ac_test';
16 const LDL_TEST = 'lab_ldl_test';
18 public function getListId()
20 return 'Clinical_Rules_Lab_Res_Types';
23 public function doPatientCheck( RsPatient $patient, $beginDate = null, $endDate = null, $options = null )
25 $data = Codes::lookup( $this->getOptionId() );
27 $range = new Range( Range::NEG_INF, Range::POS_INF );
28 if ( isset( $options[self::OPTION_RANGE] ) &&
29 is_a( $options[self::OPTION_RANGE], 'Range' ) ) {
30 $range = $options[self::OPTION_RANGE];
33 foreach( $data as $codeType => $codes ) {
34 foreach ( $codes as $code ) {
35 // search through vitals to find the most recent lab result in the date range
36 // if the result value is within range using Range->test(val), return true
37 $sql = "SELECT procedure_result.result, procedure_result.date " .
38 "FROM `procedure_type`, " .
39 "`procedure_order`, " .
40 "`procedure_report`, " .
41 "`procedure_result` " .
42 "WHERE procedure_type.procedure_type_id = procedure_order.procedure_type_id " .
43 "AND procedure_order.procedure_order_id = procedure_report.procedure_order_id " .
44 "AND procedure_report.procedure_report_id = procedure_result.procedure_report_id " .
45 "AND ( procedure_type.standard_code = ? OR procedure_type.procedure_code = ? ) " .
46 "AND procedure_report.date_collected >= ? " .
47 "AND procedure_report.date_collected <= ? " .
48 "AND procedure_order.patient_id = ? ";
49 if ( $range->lowerBound != Range::NEG_INF ) {
50 $sql .= "AND procedure_result.result >= ? ";
52 if ( $range->upperBound != Range::POS_INF ) {
53 $sql .= "AND procedure_result.result < ? ";
56 $bindings = array( $codeType.':'.$code, $code, $beginDate, $endDate, $patient->id );
57 if ( $range->lowerBound != Range::NEG_INF ) {
58 $bindings []= $range->lowerBound;
60 if ( $range->upperBound != Range::POS_INF ) {
61 $bindings []= $range->upperBound;
63 $result = sqlStatement( $sql, $bindings );
65 $number = sqlNumRows($result);
66 if ( $number > 0 ) {
67 return true;
72 return false;