Exemplo n.º 1
0
 public function doPatientCheck(RsPatient $patient, $beginDate = null, $endDate = null, $options = null)
 {
     $return = false;
     $listOptions = Codes::lookup($this->getOptionId(), 'CVX');
     if (count($listOptions) > 0) {
         $sqlQueryBind = array();
         $query = "SELECT * " . "FROM immunizations " . "WHERE patient_id = ? AND added_erroneously = '0' " . "AND administered_date >= ? " . "AND administered_date <= ? ";
         $query .= "AND ( ";
         $count = 0;
         array_push($sqlQueryBind, $patient->id, $beginDate, $endDate);
         foreach ($listOptions as $option_id) {
             $query .= "cvx_code = ? ";
             $count++;
             if ($count < count($listOptions)) {
                 $query .= "OR ";
             }
             array_push($sqlQueryBind, $option_id);
         }
         $query .= " ) ";
         $result = sqlStatement($query, $sqlQueryBind);
         $rows = array();
         for ($iter = 0; $row = sqlFetchArray($result); $iter++) {
             $rows[$iter] = $row;
         }
         if (isset($options[self::OPTION_COUNT]) && count($rows) >= $options[self::OPTION_COUNT]) {
             $return = true;
         } else {
             if (!isset($options[self::OPTION_COUNT]) && count($rows) > 0) {
                 $return = true;
             }
         }
     }
     return $return;
 }
Exemplo n.º 2
0
 public function doPatientCheck(RsPatient $patient, $beginDate = null, $endDate = null, $options = null)
 {
     $data = Codes::lookup($this->getOptionId());
     $range = new Range(Range::NEG_INF, Range::POS_INF);
     if (isset($options[self::OPTION_RANGE]) && is_a($options[self::OPTION_RANGE], 'Range')) {
         $range = $options[self::OPTION_RANGE];
     }
     foreach ($data as $codeType => $codes) {
         foreach ($codes as $code) {
             // search through vitals to find the most recent lab result in the date range
             // if the result value is within range using Range->test(val), return true
             $sql = "SELECT procedure_result.result, procedure_result.date " . "FROM `procedure_type`, " . "`procedure_order`, " . "`procedure_report`, " . "`procedure_result` " . "WHERE procedure_type.procedure_type_id = procedure_order.procedure_type_id " . "AND procedure_order.procedure_order_id = procedure_report.procedure_order_id " . "AND procedure_report.procedure_report_id = procedure_result.procedure_report_id " . "AND ( procedure_type.standard_code = ? OR procedure_type.procedure_code = ? ) " . "AND procedure_report.date_collected >= ?  " . "AND procedure_report.date_collected <= ?  " . "AND procedure_order.patient_id = ? ";
             if ($range->lowerBound != Range::NEG_INF) {
                 $sql .= "AND procedure_result.result >= ? ";
             }
             if ($range->upperBound != Range::POS_INF) {
                 $sql .= "AND procedure_result.result < ? ";
             }
             $bindings = array($codeType . ':' . $code, $code, $beginDate, $endDate, $patient->id);
             if ($range->lowerBound != Range::NEG_INF) {
                 $bindings[] = $range->lowerBound;
             }
             if ($range->upperBound != Range::POS_INF) {
                 $bindings[] = $range->upperBound;
             }
             $result = sqlStatement($sql, $bindings);
             $number = sqlNumRows($result);
             if ($number > 0) {
                 return true;
             }
         }
     }
     return false;
 }
Exemplo n.º 3
0
 public function doPatientCheck(RsPatient $patient, $beginDate = null, $endDate = null, $options = null)
 {
     $data = Codes::lookup($this->getOptionId());
     $type = $this->getListType();
     foreach ($data as $codeType => $codes) {
         foreach ($codes as $code) {
             if (exist_lists_item($patient->id, $type, $codeType . '::' . $code, $endDate)) {
                 return true;
             }
         }
     }
     return false;
 }
Exemplo n.º 4
0
 public function test(CqmPatient $patient, $beginDate, $endDate)
 {
     //Group A Streptococcus Test Array
     $strep_test_code = "'" . implode("','", Codes::lookup(LabResult::STREPTOCOCCUS_TEST, 'LOINC')) . "'";
     //Patients who were tested for Streptococcus A during the same encounter that the antibiotic was prescribed, Encounter category should be office visit.
     $query = "SELECT count(*) as cnt FROM form_encounter fe " . "INNER JOIN openemr_postcalendar_categories opc ON fe.pc_catid = opc.pc_catid " . "INNER JOIN procedure_order po ON po.encounter_id = fe.encounter " . "INNER JOIN procedure_order_code pc ON po.procedure_order_id = pc.procedure_order_id " . "INNER JOIN procedure_report pr on pr.procedure_order_id = po.procedure_order_id " . "INNER JOIN procedure_result pres on pres.procedure_report_id = pr.procedure_report_id " . "WHERE opc.pc_catname = 'Office Visit' AND fe.pid = ? AND (fe.date BETWEEN ? AND  ? ) " . " AND pres.result_code in ({$strep_test_code}) AND ( DATEDIFF(po.date_ordered,fe.date) between 0 and 3 or DATEDIFF(fe.date,po.date_ordered) between 0 and 3)";
     $check = sqlQuery($query, array($patient->id, $beginDate, $endDate));
     if ($check['cnt'] > 0) {
         return true;
     } else {
         return false;
     }
 }
Exemplo n.º 5
0
 public function test(CqmPatient $patient, $beginDate, $endDate)
 {
     //Also exclude patients with a diagnosis of pregnancy during the measurement period.
     if (Helper::check(ClinicalType::DIAGNOSIS, Diagnosis::PREGNANCY, $patient, $beginDate, $beginDate) || Helper::check(ClinicalType::DIAGNOSIS, Diagnosis::END_STAGE_RENAL_DISEASE, $patient, $beginDate, $beginDate) || Helper::check(ClinicalType::DIAGNOSIS, Diagnosis::CHRONIC_KIDNEY_DISEASE, $patient, $beginDate, $beginDate)) {
         return true;
     }
     $procedure_code = implode(',', Codes::lookup(Procedure::DIALYSIS_SERVICE, 'SNOMED'));
     //Dialysis procedure exists exclude the patient
     $sql = "SELECT count(*) as cnt FROM procedure_order pr " . "INNER JOIN procedure_order_code prc ON pr.procedure_order_id = prc.procedure_order_id " . "WHERE pr.patient_id = ? " . "AND prc.procedure_code IN ({$procedure_code}) " . "AND (pr.date_ordered BETWEEN ? AND ?)";
     //echo $sql;
     $check = sqlQuery($sql, array($patient->id, $beginDate, $endDate));
     if ($check['cnt'] > 0) {
         return true;
     }
     return false;
 }
Exemplo n.º 6
0
 public function test(CqmPatient $patient, $beginDate, $endDate)
 {
     $vac_medication = implode(',', Codes::lookup(Medication::PNEUMOCOCCAL_VAC, 'CVX'));
     $vac_procedure = implode(',', Codes::lookup(Procedure::PNEUMOCOCCAL_VACCINE, 'SNOMED'));
     $query = "select count(*) cnt from form_encounter fe " . "INNER JOIN procedure_order po on po.patient_id = fe.pid " . "INNER JOIN procedure_order_code poc on poc.procedure_order_id = po.procedure_order_id " . "WHERE fe.pid = ? AND fe.date between ? and ? " . "AND poc.procedure_code in ({$vac_procedure}) AND po.date_ordered between ? and ? ";
     $sql = sqlQuery($query, array($patient->id, $beginDate, $endDate, $beginDate, $endDate));
     if ($sql['cnt'] > 0) {
         return true;
     }
     $query = "select count(*) cnt from form_encounter fe " . "INNER JOIN immunizations imm on imm.patient_id = fe.pid " . "WHERE fe.pid = ? and fe.date between ? and  ? " . "AND imm.cvx_code in ({$vac_medication}) AND imm.administered_date between ? and ?";
     $sql = sqlQuery($query, array($patient->id, $beginDate, $endDate, $beginDate, $endDate));
     if ($sql['cnt'] > 0) {
         return true;
     }
     return false;
 }
 public function test(CqmPatient $patient, $beginDate, $endDate)
 {
     $age = $patient->calculateAgeOnDate($beginDate);
     if ($age >= 18 && $age < 75 && Helper::check(ClinicalType::ENCOUNTER, Encounter::ENC_OFF_VIS, $patient, $beginDate, $endDate)) {
         $diabetes_codes = array();
         foreach (Codes::lookup(Diagnosis::DIABETES, 'SNOMED-CT') as $code) {
             $diabetes_codes[] = "SNOMED-CT:" . $code;
         }
         $diabetes_codes = "'" . implode("','", $diabetes_codes) . "'";
         $query = "select count(*) cnt from form_encounter fe " . "inner join lists l on ( l.type='medical_problem' and l.pid = fe.pid )" . "where fe.pid = ? and fe.date between ? and ? " . "and l.diagnosis in ({$diabetes_codes}) and (l.begdate < ? or (l.begdate between ? and ? )) and (l.enddate is null or l.enddate > ? )";
         $sql = sqlQuery($query, array($patient->id, $beginDate, $endDate, $beginDate, $beginDate, $endDate, $endDate));
         if ($sql['cnt'] > 0) {
             return true;
         }
         return false;
     }
     return false;
 }
Exemplo n.º 8
0
 public function test(CqmPatient $patient, $beginDate, $endDate)
 {
     $periodPlus89Days = date('Y-m-d 00:00:00', strtotime('+89 day', strtotime($beginDate)));
     $periodMinus153Days = date('Y-m-d 00:00:00', strtotime('-153 day', strtotime($beginDate)));
     $influenza_procedure = implode(',', Codes::lookup(Procedure::INFLU_VACCINE, 'SNOMED'));
     $influenza_medication = implode(',', Codes::lookup(Medication::INFLUENZA_VACCINE, 'CVX'));
     $provider_communication = implode(',', Codes::lookup(Communication::PREV_RECEIPT_VACCINE, 'SNOMED'));
     // Influenza vaccine procedure check
     $query = "select count(*) as cnt from form_encounter fe " . "INNER JOIN procedure_order po on po.patient_id = fe.pid " . "INNER JOIN procedure_order_code poc on po.procedure_order_id = poc.procedure_order_id " . "WHERE pid = ? and fe.date between ? and  ? " . "AND poc.procedure_code in ({$influenza_procedure}) and ( po.date_ordered <= ? or po.date_ordered <= ? )";
     $sql = sqlQuery($query, array($patient->id, $beginDate, $endDate, $periodMinus153Days, $periodPlus89Days));
     if ($sql['cnt'] > 0) {
         return true;
     }
     $query = "select count(*) as cnt from form_encounter fe " . "INNER JOIN immunizations imm on imm.patient_id = fe.pid " . "WHERE pid = ? and fe.date between ? and ? " . "AND imm.cvx_code in ({$influenza_medication}) and (imm.administered_date <= ? or imm.administered_date <= ?) ";
     $sql = sqlQuery($query, array($patient->id, $beginDate, $endDate, $periodMinus153Days, $periodPlus89Days));
     if ($sql['cnt'] > 0) {
         return true;
     }
     return false;
 }
 public function test(CqmPatient $patient, $beginDate, $endDate)
 {
     $age = $patient->calculateAgeOnDate($beginDate);
     if ($age >= 2 && $age < 18) {
         //Children 2-18 years of age who had an outpatient or emergency department (ED) visit with a diagnosis of pharyngitis during the measurement period and an antibiotic ordered on or three days after the visit
         $antibiotics = implode(',', Codes::lookup(Medication::ANTIBIOTIC_FOR_PHARYNGITIS, 'RXNORM'));
         $query = "SELECT p.drug as drug FROM form_encounter fe " . "INNER JOIN openemr_postcalendar_categories opc ON fe.pc_catid = opc.pc_catid " . "INNER JOIN prescriptions p ON fe.pid = p.patient_id " . "WHERE opc.pc_catname = 'Office Visit' AND fe.pid = ? AND (fe.date BETWEEN ? AND ? ) " . " AND p.rxnorm_drugcode in ( {$antibiotics} ) AND DATEDIFF(fe.date,p.date_added) <= 3";
         $check = sqlQuery($query, array($patient->id, $beginDate, $endDate));
         if ($check['drug'] != "") {
             if (Helper::check(ClinicalType::DIAGNOSIS, Diagnosis::ACUTE_PHARYNGITIS, $patient, $beginDate, $endDate) || Helper::check(ClinicalType::DIAGNOSIS, Diagnosis::ACUTE_TONSILLITIS, $patient, $beginDate, $endDate)) {
                 return true;
             } else {
                 return false;
             }
         } else {
             return false;
         }
     }
     return false;
 }
Exemplo n.º 10
0
 public function test(CqmPatient $patient, $beginDate, $endDate)
 {
     //Children who are taking antibiotics in the 30 days prior to the diagnosis of pharyngitis
     $antibiotics = implode(',', Codes::lookup(Medication::ANTIBIOTIC_FOR_PHARYNGITIS, 'RXNORM'));
     $pharyngitis_snomed_codes = $pharyngitis_icd9_codes = $pharyngitis_icd10_codes = array();
     foreach (Codes::lookup(Diagnosis::ACUTE_PHARYNGITIS, 'SNOMED-CT') as $code) {
         $pharyngitis_snomed_codes[] = "SNOMED-CT:" . $code;
     }
     foreach (Codes::lookup(Diagnosis::ACUTE_PHARYNGITIS, 'ICD9') as $code) {
         $pharyngitis_icd9_codes[] = "ICD9:" . $code;
     }
     foreach (Codes::lookup(Diagnosis::ACUTE_PHARYNGITIS, 'ICD10') as $code) {
         $pharyngitis_icd10_codes[] = "ICD10:" . $code;
     }
     $pharyngitis_snomed_codes = "'" . implode("','", $pharyngitis_snomed_codes) . "'";
     $pharyngitis_icd9_codes = "'" . implode("','", $pharyngitis_icd9_codes) . "'";
     $pharyngitis_icd10_codes = "'" . implode("','", $pharyngitis_icd10_codes) . "'";
     $tonsillitis_snomed_codes = $tonsillitis_icd9_codes = $tonsillitis_icd10_codes = array();
     foreach (Codes::lookup(Diagnosis::ACUTE_TONSILLITIS, 'SNOMED-CT') as $code) {
         $tonsillitis_snomed_codes[] = "SNOMED-CT:" . $code;
     }
     foreach (Codes::lookup(Diagnosis::ACUTE_TONSILLITIS, 'ICD9') as $code) {
         $tonsillitis_icd9_codes[] = "ICD9:" . $code;
     }
     foreach (Codes::lookup(Diagnosis::ACUTE_TONSILLITIS, 'ICD10') as $code) {
         $tonsillitis_icd10_codes[] = "ICD10:" . $code;
     }
     $tonsillitis_snomed_codes = "'" . implode("','", $tonsillitis_snomed_codes) . "'";
     $tonsillitis_icd9_codes = "'" . implode("','", $tonsillitis_icd9_codes) . "'";
     $tonsillitis_icd10_codes = "'" . implode(',', $tonsillitis_icd10_codes) . "'";
     $query = "SELECT count(*) as cnt FROM form_encounter fe " . "INNER JOIN openemr_postcalendar_categories opc ON fe.pc_catid = opc.pc_catid " . " INNER JOIN lists l on l.type='medical_problem' and fe.pid = l.pid " . "INNER JOIN prescriptions p ON fe.pid = p.patient_id " . "WHERE opc.pc_catname = 'Office Visit' AND fe.pid = ? AND fe.date BETWEEN ? and ? " . " AND p.rxnorm_drugcode in ( {$antibiotics} )" . " AND (l.diagnosis in ({$pharyngitis_snomed_codes}) or l.diagnosis in ({$pharyngitis_icd9_codes}) or l.diagnosis in({$pharyngitis_icd10_codes}) " . " or l.diagnosis in({$tonsillitis_snomed_codes}) or l.diagnosis in ({$tonsillitis_icd9_codes}) or l.diagnosis in ({$tonsillitis_icd10_codes})) " . " AND DATEDIFF(l.date,p.date_added) between 0 and 30 AND p.active = 1";
     $check = sqlQuery($query, array($patient->id, $beginDate, $endDate));
     if ($check['cnt'] >= 1) {
         //more than one medication it will exclude
         return true;
     } else {
         return false;
     }
 }
Exemplo n.º 11
0
 public function test(CqmPatient $patient, $beginDate, $endDate)
 {
     // Diagnosis Limited Life Expectancy
     $limited_life = array();
     foreach (Codes::lookup(Diagnosis::LIMITED_LIFE, 'SNOMED-CT') as $code) {
         $limited_life[] = "SNOMED-CT:" . $code;
     }
     $limited_life = "'" . implode("','", $limited_life) . "'";
     $query = "SELECT count(*) as cnt from lists where type ='medical_problem' and pid = ? and diagnosis in ({$limited_life}) and begdate between ? and ? and (enddate is null or enddate > ? )";
     $diagnosis = sqlQuery($query, array($patient->id, $beginDate, $endDate, $endDate));
     if ($diagnosis['cnt'] > 0) {
         return true;
     }
     //Risk Category Tobacco Screening Done to allow a provider to document that the screening was performed along with other numerous options from the Risk
     //Category Assessment not done:  Medical Reason value set with the identifying SNOMEDCT Code attached at the Select List level.
     //Risk Category Assessment SNOMEDCT 161590003, 183932001, 183964008, 183966005, 216952002, 266721009, 269191009
     $riskCatAssessQry = "SELECT count(*) as cnt FROM form_encounter fe " . "INNER JOIN openemr_postcalendar_categories opc ON fe.pc_catid = opc.pc_catid " . "INNER JOIN procedure_order pr ON  fe.encounter = pr.encounter_id " . "INNER JOIN procedure_order_code prc ON pr.procedure_order_id = prc.procedure_order_id " . "WHERE opc.pc_catname = 'Office Visit' " . "AND (fe.date BETWEEN ? AND ?) " . "AND fe.pid = ? " . "AND ( prc.procedure_code = '161590003' OR prc.procedure_code = '183932001' OR prc.procedure_code = '183964008' OR prc.procedure_code = '183966005' OR prc.procedure_code = '216952002' OR prc.procedure_code = '266721009' OR prc.procedure_code = '269191009') " . "AND prc.procedure_order_title = 'Risk Category Assessment'";
     $check = sqlQuery($riskCatAssessQry, array($beginDate, $endDate, $patient->id));
     if ($check['cnt'] > 0) {
         return true;
     } else {
         return false;
     }
 }
Exemplo n.º 12
0
 public function doPatientCheck(RsPatient $patient, $beginDate = null, $endDate = null, $options = null)
 {
     $data = Codes::lookup($this->getOptionId());
     $type = $this->getListType();
     foreach ($data as $codeType => $codes) {
         foreach ($codes as $code) {
             if (exist_lists_item($patient->id, $type, $codeType . '::' . $code, $endDate)) {
                 return true;
             }
         }
     }
     if ($this->getOptionId() == self::FINDING_BMI_PERC) {
         // check for any BMI percentile finding
         // there are a few BMI codes, but it doesn't matter,
         // because we just want to check for any finding
         $query = "SELECT form_vitals.BMI " . "FROM `form_vitals` " . "WHERE form_vitals.BMI IS NOT NULL " . "AND form_vitals.pid = ? " . "AND DATE( form_vitals.date ) >= ? " . "AND DATE( form_vitals.date ) <= ? ";
         $res = sqlStatement($query, array($patient->id, $beginDate, $endDate));
         $number = sqlNumRows($res);
         if ($number >= 1) {
             return true;
         }
     }
     return false;
 }