/** * @param $rule * @return bool */ private function ckActiveMedicationAllergies($rule) { if (isset($rule['concepts']['ALLE']) && !empty($rule['concepts']['ALLE'])) { $count = 0; foreach ($rule['concepts']['ALLE'] as $concept) { $allergies = $this->Allergies->getPatientActiveDrugAllergiesByPidAndCode($this->Patient->getPatientPid(), $concept['concept_code']); if (empty($allergies)) { continue; } if ($concept['frequency_interval'] == 0) { $count++; continue; } $frequency = 0; foreach ($allergies as $allergy) { if ($this->isWithInterval($allergy['begin_date'], $concept['frequency_interval'], $concept['frequency_operator'], 'Y-m-d')) { $frequency++; if ($concept['frequency'] == $frequency) { break; } } } if ($concept['frequency_operator'] == '' || $this->compare($frequency, $concept['frequency_operator'], $concept['frequency'])) { $count++; } } return $count == count($rule['concepts']['ALLE']); } return true; }
public function rcopia_sync($practice_id) { // Update Notification $row0 = Practiceinfo::find($practice_id); Config::set('app.timezone', $row0->timezone); if ($row0->rcopia_update_notification_lastupdate == "") { $date0 = date('m/d/Y H:i:s', time()); } else { $date0 = $row0->rcopia_update_notification_lastupdate; } $xml0 = "<Request><Command>update_notification</Command>"; $xml0 .= "<LastUpdateDate>" . $date0 . "</LastUpdateDate>"; $xml0 .= "</Request></RCExtRequest>"; $result0 = $this->rcopia($xml0, $practice_id); $response0 = new SimpleXMLElement($result0); if ($response0->Response->Status == "error") { $description0 = $response0->Response->Error->Text . ""; $data0a = array('action' => 'update_notification', 'pid' => '0', 'extensions_name' => 'rcopia', 'description' => $description0, 'practice_id' => $practice_id); DB::table('extensions_log')->insert($data0a); } else { $last_update_date = $response0->Response->LastUpdateDate . ""; $number = $response0->Response->NotificationList->Number . ""; if ($number != "0") { foreach ($response0->Response->NotificationList->Notification as $notification) { $type = $notification->Type . ""; $status = $notification->Status . ""; $rcopia_username = $notification->Provider->Username . ""; $medication_message = $notification->Sig->Drug->BrandName . ""; $form_message = $notification->Sig->Drug->Form . ""; $dose_message = $notification->Sig->Drug->Strength . ""; $sig_message = $notification->Sig->Dose . ""; $sig1_message = $notification->Sig->DoseUnit . ""; $route_message = $notification->Sig->Route . ""; $frequency_message = $notification->Sig->DoseTiming . ""; $instructions_message = $notification->Sig->DoseOther . ""; $quantity_message = $notification->Sig->Quantity . ""; $quantity_message1 = $notification->Sig->QuantityUnit . ""; $refill_message = $notification->Sig->Refills . ""; $pharmacy_message = $notification->Pharmacy->Name . ""; $medication_message = "Medication: " . $medication_message . ", " . $form_message . ", " . $dose_message; $medication_message .= "\nInstructions: " . $sig_message . " " . $sig1_message . " " . $route_message . ", " . $frequency_message; $medication_message .= "\nOther Instructions: " . $instructions_message; $medication_message .= "\nQuantity: " . $quantity_message . " " . $quantity_message1; $medication_message .= "\nRefills: " . $refill_message; $medication_message .= "\nPharmacy: " . $pharmacy_message; $messages_pid = $notification->Patient->ExternalID . ""; $sender = $notification->Sender . ""; $title = $notification->Title . ""; $text = $notification->Text . ""; $full_text = "From: " . $sender . "\nMessage: " . $text; $patient_row = Demographics::where('pid', '=', $messages_pid)->first(); $dob_message = date("m/d/Y", strtotime($patient_row->DOB)); $patient_name = $patient_row->lastname . ', ' . $patient_row->firstname . ' (DOB: ' . $dob_message . ') (ID: ' . $messages_pid . ')'; $provider_row = DB::table('users')->join('providers', 'providers.id', '=', 'users.id')->select('users.lastname', 'users.firstname', 'users.title', 'users.id')->where('providers.rcopia_username', '=', $rcopia_username)->first(); if ($provider_row) { $provider_name = $provider_row->firstname . " " . $provider_row->lastname . ", " . $provider_row->title . " (" . $provider_row->id . ")"; if ($type == "refill") { $subject = "Refill Request for " . $patient_name; $body = $medication_message; } if ($type == "message") { $subject = $title; $body = $full_text; } $data_message = array('pid' => $messages_pid, 'message_to' => $provider_name, 'message_from' => $provider_row->id, 'subject' => $subject, 'body' => $body, 'patient_name' => $patient_name, 'status' => 'Sent', 'mailbox' => $provider_row->id, 'practice_id' => $practice_id); DB::table('messaging')->insert($data_message); $this->audit('Add'); } } } $data_update = array('rcopia_update_notification_lastupdate' => $last_update_date); DB::table('practiceinfo')->where('practice_id', '=', $practice_id)->update($data_update); } // Send Patient $query1 = Demographics::where('rcopia_sync', '=', 'n')->get(); if ($query1) { foreach ($query1 as $row1) { if ($this->check_practice_id($row1->pid, $practice_id)) { $dob = explode(" ", $row1->DOB); $dob1 = explode("-", $dob[0]); $dob_final = $dob1[1] . "/" . $dob1[2] . "/" . $dob1[0]; $xml1 = "<Request><Command>send_patient</Command><Synchronous>y</Synchronous><CheckEligibility>y</CheckEligibility>"; $xml1 .= "<PatientList><Patient>"; $xml1 .= "<FirstName>" . $row1->firstname . "</FirstName>"; $xml1 .= "<LastName>" . $row1->lastname . "</LastName>"; $xml1 .= "<MiddleName>" . $row1->middle . "</MiddleName>"; $xml1 .= "<DOB>" . $dob_final . "</DOB>"; $xml1 .= "<Sex>" . $row1->sex . "</Sex>"; $xml1 .= "<ExternalID>" . $row1->pid . "</ExternalID>"; $xml1 .= "<HomePhone>" . $row1->phone_home . "</HomePhone>"; $xml1 .= "<WorkPhone>" . $row1->phone_work . "</WorkPhone>"; $xml1 .= "<Address1>" . $row1->address . "</Address1>"; $xml1 .= "<Address2></Address2>"; $xml1 .= "<City>" . $row1->city . "</City>"; $xml1 .= "<State>" . $row1->state . "</State>"; $xml1 .= "<Zip>" . $row1->zip . "</Zip>"; $xml1 .= "</Patient></PatientList></Request></RCExtRequest>"; $result1 = $this->rcopia($xml1, $practice_id); $response1 = new SimpleXMLElement($result1); $status1 = $response1->Response->PatientList->Patient->Status . ""; if ($status1 == "error") { $description1 = $response1->Response->PatientList->Patient->Error->Text . ""; $data1a = array('action' => 'send_patient', 'pid' => $row1->pid, 'extensions_name' => 'rcopia', 'description' => $description1, 'practice_id' => $practice_id); DB::table('extensions_log')->insert($data1a); } else { $data1b = array('rcopia_sync' => 'y'); DB::table('demographics')->where('pid', '=', $row1->pid)->update($data1b); $this->audit('Update'); } } } } // Send Allergy $query2 = Allergies::where('rcopia_sync', '=', 'n')->where('allergies_date_inactive', '=', '0000-00-00 00:00:00')->get(); if ($query2) { foreach ($query2 as $row2) { if ($this->check_practice_id($row2->pid, $practice_id)) { $da = explode(" ", $row2->allergies_date_active); $da1 = explode("-", $da[0]); $da_final = $da1[1] . "/" . $da1[2] . "/" . $da1[0]; $xml2 = "<Request><Command>send_allergy</Command><Synchronous>y</Synchronous>"; $xml2 .= "<AllergyList><Allergy>"; $xml2 .= "<ExternalID>" . $row2->allergies_id . "</ExternalID>"; $xml2 .= "<Patient><ExternalID>" . $row2->pid . "</ExternalID></Patient>"; $xml2 .= "<Allergen><Name>" . $row2->allergies_med . "</Name>"; $xml2 .= "<Drug><NDCID>" . $row2->meds_ndcid . "</NDCID></Drug></Allergen>"; $xml2 .= "<Reaction>" . $row2->allergies_reaction . "</Reaction>"; $xml2 .= "<OnsetDate>" . $da_final . "</OnsetDate>"; $xml2 .= "</Allergy></AllergyList></Request></RCExtRequest>"; $result2 = $this->rcopia($xml2, $practice_id); $response2 = new SimpleXMLElement($result2); $status2 = $response2->Response->AllergyList->Allergy->Status . ""; if ($status2 == "error") { $description2 = $response2->Response->AllergyList->Allergy->Error->Text . ""; $data2a = array('action' => 'send_allergy', 'pid' => $row2->pid, 'extensions_name' => 'rcopia', 'description' => $description2, 'practice_id' => $practice_id); DB::table('extensions_log')->insert($data2a); if ($description2 == "Can find neither name, Rcopia ID, or NDC ID for drug.") { $data2c = array('rcopia_sync' => 'ye'); DB::table('allergies')->where('allergies_id', '=', $row2->allergies_id)->update($data2c); $this->audit('Update'); } } else { $data2b = array('rcopia_sync' => 'y'); DB::table('allergies')->where('allergies_id', '=', $row2->allergies_id)->update($data2b); $this->audit('Update'); } } } } //Send Medication $query3 = Rx_list::where('rcopia_sync', '=', 'n')->where('rxl_date_inactive', '=', '0000-00-00 00:00:00')->where('rxl_date_old', '=', '0000-00-00 00:00:00')->get(); if ($query3) { foreach ($query3 as $row3) { if ($this->check_practice_id($row3->pid, $practice_id)) { $dm = explode(" ", $row3->rxl_date_active); $dm1 = explode("-", $dm[0]); $dm_final = $dm1[1] . "/" . $dm1[2] . "/" . $dm1[0]; if ($row3->rxl_due_date != '') { $dn = explode(" ", $row3->rxl_due_date); $dn1 = explode("-", $dn[0]); $dn_final = $dn1[1] . "/" . $dn1[2] . "/" . $dn1[0]; } else { $dn_final = ""; } if ($row3->rxl_ndcid != '') { $ndcid = $row3->rxl_ndcid; } else { $ndcid = ''; } $medication_parts1 = explode(", ", $row3->rxl_medication); $generic_name = $medication_parts1[0]; if (isset($medication_parts[1])) { $form = $medication_parts1[1]; } else { $form = ''; } $strength = $row3->rxl_dosage . " " . $row3->rxl_dosage_unit; if ($row3->rxl_sig != '') { if (strpos($row3->rxl_sig, ' ') !== false) { $sig_parts1 = explode(" ", $row3->rxl_sig); $dose = $sig_parts1[0]; $dose_unit = $sig_parts1[1]; } else { $dose = $row3->rxl_sig; $dose_unit = ''; } } else { $dose = ''; $dose_unit = ''; } if ($row3->rxl_quantity != '') { if (strpos($row3->rxl_quantity, ' ') !== false) { $quantity_parts1 = explode(" ", $row3->rxl_quantity); $quantity = $quantity_parts1[0]; $quantity_unit = $quantity_parts1[1]; } else { $quantity = $row3->rxl_quantity; $quantity_unit = ''; } } else { $quantity = ''; $quantity_unit = ''; } if ($row3->rxl_daw != '') { $daw = 'n'; } else { $daw = 'y'; } $xml3 = "<Request><Command>send_medication</Command><Synchronous>y</Synchronous>"; $xml3 .= "<MedicationList><Medication>"; $xml3 .= "<ExternalID>" . $row3->rxl_id . "</ExternalID>"; $xml3 .= "<Patient><ExternalID>" . $row3->pid . "</ExternalID></Patient>"; $xml3 .= "<Sig>"; $xml3 .= "<Drug><NDCID>" . $ndcid . "</NDCID>"; $xml3 .= "<GenericName>" . $generic_name . "</GenericName>"; $xml3 .= "<Form>" . $form . "</Form>"; $xml3 .= "<Strength>" . $strength . "</Strength></Drug>"; $xml3 .= "<Dose>" . $dose . "</Dose>"; $xml3 .= "<DoseUnit>" . $dose_unit . "</DoseUnit>"; $xml3 .= "<Route>" . $row3->rxl_route . "</Route>"; $xml3 .= "<DoseTiming>" . $row3->rxl_frequency . "</DoseTiming>"; $xml3 .= "<DoseOther>" . $row3->rxl_instructions . "</DoseOther>"; $xml3 .= "<Quantity>" . $quantity . "</Quantity>"; $xml3 .= "<QuantityUnit>" . $quantity_unit . "</QuantityUnit>"; $xml3 .= "<Refills>" . $row3->rxl_refill . "</Refills>"; $xml3 .= "<SubstitutionPermitted>" . $daw . "</SubstitutionPermitted>"; $xml3 .= "</Sig>"; $xml3 .= "<StartDate>" . $dm_final . "</StartDate>"; $xml3 .= "<StopDate>" . $dn_final . "</StopDate>"; $xml3 .= "</Medication></MedicationList></Request></RCExtRequest>"; $result3 = $this->rcopia($xml3, $practice_id); $response3 = new SimpleXMLElement($result3); $status3 = $response3->Response->MedicationList->Medication->Status . ""; if ($status3 == "error") { $description3 = $response3->Response->MedicationList->Medication->Error->Text . ""; $data3a = array('action' => 'send_medication', 'pid' => $row3->pid, 'extensions_name' => 'rcopia', 'description' => $description3, 'practice_id' => $practice_id); DB::table('extensions_log')->insert($data3a); } else { $data3b = array('rcopia_sync' => 'y'); DB::table('rx_list')->where('rxl_id', '=', $row3->rxl_id)->update($data3b); $this->audit('Update'); } } } } //Send Problem List $query4 = Issues::where('rcopia_sync', '=', 'n')->where('issue_date_inactive', '=', '0000-00-00 00:00:00')->get(); if ($query4) { foreach ($query4 as $row4) { if ($this->check_practice_id($row4->pid, $practice_id)) { $di = explode(" [", $row4->issue); $code = str_replace("]", "", $di[1]); $xml4 = "<Request><Command>send_problem</Command><Synchronous>y</Synchronous>"; $xml4 .= "<ProblemList><Problem>"; $xml4 .= "<ExternalID>" . $row4->issue_id . "</ExternalID>"; $xml4 .= "<Patient><ExternalID>" . $row4->pid . "</ExternalID></Patient>"; $xml4 .= "<Code>" . $code . "</Code>"; $xml4 .= "<Description>" . $di[0] . "</Description>"; $xml4 .= "</Problem></ProblemList></Request></RCExtRequest>"; $result4 = $this->rcopia($xml4, $practice_id); $response4 = new SimpleXMLElement($result4); $status4 = $response4->Response->ProblemList->Problem->Status . ""; if ($status4 == "error") { $description4 = $response4->Response->ProblemList->Problem->Error->Text . ""; $data4a = array('action' => 'send_problem', 'pid' => $row4->pid, 'extensions_name' => 'rcopia', 'description' => $description4, 'practice_id' => $practice_id); DB::table('extensions_log')->insert($data4a); } else { $data4b = array('rcopia_sync' => 'y'); DB::table('issues')->where('issue_id', '=', $row4->issue_id)->update($data4b); $this->audit('Update'); } } } } //Delete Allergy $query5 = Allergies::where('rcopia_sync', '=', 'nd')->orWhere('rcopia_sync', '=', 'nd1')->get(); if ($query5) { foreach ($query5 as $row5) { if ($this->check_practice_id($row5->pid, $practice_id)) { $dda = explode(" ", $row5->allergies_date_active); $daa1 = explode("-", $dda[0]); $dda_final = $dda1[1] . "/" . $dda1[2] . "/" . $dda1[0]; $xml5 = "<Request><Command>send_allergy</Command><Synchronous>y</Synchronous>"; $xml5 .= "<AllergyList><Allergy><Deleted>y</Deleted>"; $xml5 .= "<ExternalID>" . $row5->allergies_id . "</ExternalID>"; $xml5 .= "<Patient><ExternalID>" . $row5->pid . "</ExternalID></Patient>"; $xml5 .= "<Allergen><Name>" . $row5->allergies_med . "</Name>"; $xml5 .= "<Drug><NDCID>" . $row5->meds_ndcid . "</NDCID></Drug></Allergen>"; $xml5 .= "<Reaction>" . $row5->allergies_reaction . "</Reaction>"; $xml5 .= "<OnsetDate>" . $dda_final . "</OnsetDate>"; $xml5 .= "</Allergy></AllergyList></Request></RCExtRequest>"; $result5 = $this->rcopia($xml5, $practice_id); $response5 = new SimpleXMLElement($result5); $status5 = $response5->Response->AllergyList->Allergy->Status . ""; if ($status5 == "error") { $description5 = $response5->Response->AllergyList->Allergy->Error->Text . ""; $data5a = array('action' => 'delete_allergy', 'pid' => $row5->pid, 'extensions_name' => 'rcopia', 'description' => $description5, 'practice_id' => $practice_id); DB::table('extensions_log')->insert($data5a); $data5b = array('rcopia_sync' => 'y'); DB::table('allergies')->where('pid', $row5->pid)->update($data5b); $this->audit('Update'); } else { $data5b = array('rcopia_sync' => 'y'); DB::table('allergies')->where('allergies_id', $row5->allergies_id)->update($data5b); $this->audit('Update'); } } } } //Delete Medication $query6 = Rx_list::where('rcopia_sync', '=', 'nd')->orWhere('rcopia_sync', '=', 'nd1')->get(); if ($query6) { foreach ($query6 as $row6) { if ($this->check_practice_id($row6->pid, $practice_id)) { $ddm = explode(" ", $row6->rxl_date_active); $ddm1 = explode("-", $ddm[0]); $ddm_final = $ddm1[1] . "/" . $ddm1[2] . "/" . $ddm1[0]; if ($row3->rxl_due_date != '') { $ddn = explode(" ", $row6->rxl_due_date); $ddn1 = explode("-", $ddn[0]); $ddn_final = $ddn1[1] . "/" . $ddn1[2] . "/" . $ddn1[0]; } else { $ddn_final = ""; } if ($row6->rxl_ndcid != '') { $ndcid1 = $row6->rxl_ndcid; $generic_name1 = ''; $form1 = ''; $strength1 = ''; } else { $ndcid1 = ''; $medication_parts2 = explode(", ", $row6->rxl_medication); if (count($medication_parts2) > 1) { $generic_name1 = $medication_parts2[0]; $form1 = $medication_parts2[1]; } else { $generic_name1 = $medication_parts2[0]; $form1 = ''; } $strength1 = $row6->rxl_dosage . " " . $row6->rxl_dosage_unit; } $sig_parts2 = explode(" ", $row6->rxl_sig); if (count($sig_parts2) > 1) { $dose = $sig_parts2[0]; $doseunit = $sig_parts2[1]; } else { $dose = $sig_parts2[0]; $doseunit = ''; } if ($row6->rxl_quantity != '') { if (strpos($row6->rxl_quantity, ' ') !== false) { $quantity_parts2 = explode(" ", $row6->rxl_quantity); $quantity1 = $quantity_parts2[0]; $quantity_unit1 = $quantity_parts2[1]; } else { $quantity1 = $row6->rxl_quantity; $quantity_unit1 = ''; } } else { $quantity1 = ''; $quantity_unit1 = ''; } if ($row6->rxl_daw != '') { $daw1 = 'n'; } else { $daw1 = 'y'; } $xml6 = "<Request><Command>send_medication</Command><Synchronous>y</Synchronous>"; $xml6 .= "<MedicationList><Medication><Deleted>y</Deleted>"; $xml6 .= "<ExternalID>" . $row6->rxl_id . "</ExternalID>"; $xml6 .= "<Patient><ExternalID>" . $row6->pid . "</ExternalID></Patient>"; $xml6 .= "<Sig>"; $xml6 .= "<Drug><NDCID>" . $ndcid1 . "</NDCID>"; $xml6 .= "<GenericName>" . $generic_name1 . "</GenericName>"; $xml6 .= "<Form>" . $form1 . "</Form>"; $xml6 .= "<Strength>" . $strength1 . "</Strength></Drug>"; $xml6 .= "<Dose>" . $dose . "</Dose>"; $xml6 .= "<DoseUnit>" . $doseunit . "</DoseUnit>"; $xml6 .= "<Route>" . $row6->rxl_route . "</Route>"; $xml6 .= "<DoseTiming>" . $row6->rxl_frequency . "</DoseTiming>"; $xml6 .= "<DoseOther>" . $row6->rxl_instructions . "</DoseOther>"; $xml6 .= "<Quantity>" . $quantity1 . "</Quantity>"; $xml6 .= "<QuantityUnit>" . $quantity_unit1 . "</QuantityUnit>"; $xml6 .= "<Refills>" . $row6->rxl_refill . "</Refills>"; $xml6 .= "<SubstitutionPermitted>" . $daw1 . "</SubstitutionPermitted>"; $xml6 .= "</Sig>"; $xml6 .= "<StartDate>" . $ddm_final . "</StartDate>"; $xml6 .= "<StopDate>" . $ddn_final . "</StopDate>"; $xml6 .= "</Medication></MedicationList></Request></RCExtRequest>"; $result6 = $this->rcopia($xml6, $practice_id); $response6 = new SimpleXMLElement($result6); $status6 = $response6->Response->MedicationList->Medication->Status . ""; if ($status6 == "error") { $description6 = $response3->Response->MedicationList->Medication->Error->Text . ""; $data6a = array('action' => 'delete_medication', 'pid' => $row6->pid, 'extensions_name' => 'rcopia', 'description' => $description6, 'practice_id' => $practice_id); DB::table('extensions_log')->insert($data6a); $data6b = array('rcopia_sync' => 'y'); DB::table('rx_list')->where('pid', '=', $row6->pid)->update($data6b); $this->audit('Update'); } else { $data6b = array('rcopia_sync' => 'y'); DB::table('rx_list')->where('rxl_id', '=', $row6->rxl_id)->update($data6b); $this->audit('Update'); } } } } //Delete Problem List $query7 = Issues::where('rcopia_sync', '=', 'nd')->orWhere('rcopia_sync', '=', 'nd1')->get(); if ($query7) { foreach ($query7 as $row7) { if ($this->check_practice_id($row7->pid, $practice_id)) { $ddi = explode(" [", $row7->issue); $code1 = str_replace("]", "", $ddi[1]); $xml7 = "<Request><Command>send_problem</Command><Synchronous>y</Synchronous>"; $xml7 .= "<ProblemList><Problem><Deleted>y</Deleted>"; $xml7 .= "<ExternalID>" . $row7->issue_id . "</ExternalID>"; $xml7 .= "<Patient><ExternalID>" . $row7->pid . "</ExternalID></Patient>"; $xml7 .= "<Code>" . $code1 . "</Code>"; $xml7 .= "<Description>" . $ddi[0] . "</Description>"; $xml7 .= "</Problem></ProblemList></Request></RCExtRequest>"; $result7 = $this->rcopia($xml7, $practice_id); $response7 = new SimpleXMLElement($result7); $status7 = $response7->Response->ProblemList->Problem->Status . ""; if ($status7 == "error") { $description7 = $response7->Response->ProblemList->Problem->Error->Text . ""; $data7a = array('action' => 'delete_problem', 'pid' => $row7->pid, 'extensions_name' => 'rcopia', 'description' => $description7, 'practice_id' => $practice_id); DB::table('extensions_log')->insert($data7a); $data7b = array('rcopia_sync' => 'y'); DB::table('issues')->where('pid', '=', $row7->pid)->update($data7b); $this->audit('Update'); } else { $data7b = array('rcopia_sync' => 'y'); DB::table('issues')->where('issue_id', '=', $row7->issue_id)->update($data7b); $this->audit('Update'); } } } } }
private function getObjectiveExtraDataByEid($eid) { $ExtraData = ''; $Medications = new Medications(); $medications = $Medications->getPatientMedicationsByEid($eid); if (!empty($medications)) { $lis = ''; foreach ($medications as $foo) { $lis .= '<li>' . $foo['STR'] . '</li>'; } $ExtraData .= '<p>Medications:</p>'; $ExtraData .= '<ul class="ProgressNote-ul">' . $lis . '</ul>'; } unset($Medications); $Immunizations = new Immunizations(); $immunizations = $Immunizations->getImmunizationsByEncounterID($eid); if (!empty($immunizations)) { $lis = ''; foreach ($immunizations as $foo) { $lis .= '<li>Vaccine name: ' . $foo['vaccine_name'] . '<br>'; $lis .= 'Vaccine ID: (' . $foo['code_type'] . ')' . $foo['code'] . '<br>'; $lis .= 'Manufacturer: ' . $foo['manufacturer'] . '<br>'; $lis .= 'Lot Number: ' . $foo['lot_number'] . '<br>'; $lis .= 'Dose: ' . $foo['administer_amount'] . ' ' . $foo['administer_units'] . '<br>'; $lis .= 'Administered By: ' . $foo['administered_by'] . ' </li>'; } $ExtraData .= '<p>Immunizations:</p>'; $ExtraData .= '<ul class="ProgressNote-ul">' . $lis . '</ul>'; } unset($Immunizations); $Allergies = new Allergies(); $allergies = $Allergies->getPatientAllergiesByEid($eid); if (!empty($allergies)) { $lis = ''; foreach ($allergies as $foo) { $lis .= '<li>Allergy: ' . $foo['allergy'] . ' (' . $foo['allergy_type'] . ')<br>'; $lis .= 'Reaction: ' . $foo['reaction'] . '<br>'; $lis .= 'Severity: ' . $foo['severity'] . '<br>'; $lis .= 'Location: ' . $foo['location'] . '<br>'; $lis .= 'Active?: ' . ($foo['end_date'] != null ? 'Yes' : 'No') . '</li>'; } $ExtraData .= '<p>Allergies:</p>'; $ExtraData .= '<ul class="ProgressNote-ul">' . $lis . '</ul>'; } unset($Allergies); /** * Active Problems found in this Encounter */ $ActiveProblems = new ActiveProblems(); $activeProblems = $ActiveProblems->getPatientActiveProblemByEid($eid); if (!empty($activeProblems)) { $lis = ''; foreach ($activeProblems as $foo) { $lis .= '<li>[' . $foo['code'] . '] - ' . $foo['code_text'] . ' </li>'; } $ExtraData .= '<p>Active Problems:</p>'; $ExtraData .= '<ul class="ProgressNote-ul">' . $lis . '</ul>'; } unset($ActiveProblems); return $ExtraData; }
protected function page_ccr($pid) { $data['patientInfo'] = Demographics::find($pid); $data['dob'] = date('m/d/Y', $this->human_to_unix($data['patientInfo']->DOB)); $data['insuranceInfo'] = ''; $query_in = Insurance::where('pid', '=', $pid)->where('insurance_plan_active', '=', 'Yes')->get(); if ($query_in) { foreach ($query_in as $row_in) { $data['insuranceInfo'] .= $row_in->insurance_plan_name . '; ID: ' . $row_in->insurance_id_num . '; Group: ' . $row_in->insurance_group . '; ' . $row_in->insurance_insu_lastname . ', ' . $row_in->insurance_insu_firstname . '<br><br>'; } } $body = 'Active Issues:<br />'; $query = Issues::where('pid', '=', $pid)->where('issue_date_inactive', '=', '0000-00-00 00:00:00')->get(); if ($query) { $body .= '<ul>'; foreach ($query as $row) { $body .= '<li>' . $row->issue . '</li>'; } $body .= '</ul>'; } else { $body .= 'None.'; } $body .= '<hr />Active Medications:<br />'; $query1 = Rx_list::where('pid', '=', $pid)->where('rxl_date_inactive', '=', '0000-00-00 00:00:00')->where('rxl_date_old', '=', '0000-00-00 00:00:00')->get(); if ($query1) { $body .= '<ul>'; foreach ($query1 as $row1) { if ($row1->rxl_sig == '') { $body .= '<li>' . $row1->rxl_medication . ' ' . $row1->rxl_dosage . ' ' . $row1->rxl_dosage_unit . ', ' . $row1->rxl_instructions . ' for ' . $row1->rxl_reason . '</li>'; } else { $body .= '<li>' . $row1->rxl_medication . ' ' . $row1->rxl_dosage . ' ' . $row1->rxl_dosage_unit . ', ' . $row1->rxl_sig . ' ' . $row1->rxl_route . ' ' . $row1->rxl_frequency . ' for ' . $row1->rxl_reason . '</li>'; } } $body .= '</ul>'; } else { $body .= 'None.'; } $body .= '<hr />Immunizations:<br />'; $query2 = Immunizations::where('pid', '=', $pid)->orderBy('imm_immunization', 'asc')->orderBy('imm_sequence', 'asc')->get(); if ($query2) { $body .= '<ul>'; foreach ($query2 as $row2) { $sequence = ''; if ($row2->imm_sequence == '1') { $sequence = ', first,'; } if ($row2->imm_sequence == '2') { $sequence = ', second,'; } if ($row2->imm_sequence == '3') { $sequence = ', third,'; } if ($row2->imm_sequence == '4') { $sequence = ', fourth,'; } if ($row2->imm_sequence == '5') { $sequence = ', fifth,'; } $body .= '<li>' . $row2->imm_immunization . $sequence . ' given on ' . date('F jS, Y', $this->human_to_unix($row2->imm_date)) . '</li>'; } $body .= '</ul>'; } else { $body .= 'None.'; } $body .= '<hr />Allergies:<br />'; $query3 = Allergies::where('pid', '=', $pid)->where('allergies_date_inactive', '=', '0000-00-00 00:00:00')->get(); if ($query3) { $body .= '<ul>'; foreach ($query3 as $row3) { $body .= '<li>' . $row3->allergies_med . ' - ' . $row3->allergies_reaction . '</li>'; } $body .= '</ul>'; } else { $body .= 'No known allergies.'; } $body .= '<br />Printed by ' . Session::get('displayname') . '.'; $data['letter'] = $body; return View::make('pdf.ccr_page', $data); }
/** * Method setAllergiesSection() */ private function setAllergiesSection() { $Allergies = new Allergies(); $allergiesData = $Allergies->getPatientAllergiesByPid($this->pid); unset($Allergies); if ($this->isExcluded('allergies') || empty($allergiesData)) { $allergies['@attributes'] = ['nullFlavor' => 'NI']; } $allergies['templateId'] = ['@attributes' => ['root' => $this->requiredAllergies ? '2.16.840.1.113883.10.20.22.2.6.1' : '2.16.840.1.113883.10.20.22.2.6']]; $allergies['code'] = ['@attributes' => ['code' => '48765-2', 'codeSystemName' => 'LOINC', 'codeSystem' => '2.16.840.1.113883.6.1']]; $allergies['title'] = 'Allergies, Adverse Reactions, Alerts'; $allergies['text'] = ''; if ($this->isExcluded('allergies')) { $this->addSection(['section' => $allergies]); return; } if (!empty($allergiesData)) { $allergies['text'] = ['table' => ['@attributes' => ['border' => '1', 'width' => '100%'], 'thead' => ['tr' => [['th' => [['@value' => 'Substance'], ['@value' => 'Reaction'], ['@value' => 'Severity'], ['@value' => 'Status']]]]], 'tbody' => ['tr' => []]]]; $allergies['entry'] = []; foreach ($allergiesData as $item) { $hasBeginDate = preg_match('/^\\d{4}-\\d{2}-\\d{2}/', $item['begin_date']); $hasEndDate = preg_match('/^\\d{4}-\\d{2}-\\d{2}/', $item['end_date']); $allergies['text']['table']['tbody']['tr'][] = ['td' => [['@value' => $item['allergy']], ['@value' => $item['reaction']], ['@value' => $item['severity']], ['@value' => 'Status Data']]]; $entry = ['act' => ['@attributes' => ['classCode' => 'ACT', 'moodCode' => 'EVN'], 'templateId' => ['@attributes' => ['root' => '2.16.840.1.113883.10.20.22.4.30']], 'id' => ['@attributes' => ['root' => UUID::v4()]], 'code' => ['@attributes' => ['code' => '48765-2', 'codeSystemName' => 'LOINC', 'codeSystem' => '2.16.840.1.113883.6.1']]]]; $entry['act']['statusCode'] = ['@attributes' => ['code' => $item['status_code'] == '55561003' ? 'active' : 'completed']]; $entry['act']['effectiveTime']['low'] = ['@attributes' => ['value' => $this->parseDate($item['begin_date'])]]; if ($hasEndDate) { $entry['act']['effectiveTime']['high'] = ['@attributes' => ['value' => $this->parseDate($item['end_date'])]]; } elseif ($entry['act']['statusCode'] == 'completed' && !$hasEndDate) { $entry['act']['effectiveTime']['high'] = ['@attributes' => ['nullFlavor' => 'UNK']]; } $entry['act']['entryRelationship'] = ['@attributes' => ['typeCode' => 'SUBJ'], 'observation' => ['@attributes' => ['classCode' => 'OBS', 'moodCode' => 'EVN'], 'templateId' => ['@attributes' => ['root' => '2.16.840.1.113883.10.20.22.4.7']], 'id' => ['@attributes' => ['root' => UUID::v4()]], 'code' => ['@attributes' => ['code' => 'ASSERTION', 'codeSystem' => '2.16.840.1.113883.5.4']], 'statusCode' => ['@attributes' => ['code' => 'completed']]]]; // If it is unknown when the allergy began, this effectiveTime // SHALL contain low/@nullFLavor="UNK" (CONF:9103) $entry['act']['entryRelationship']['observation']['effectiveTime'] = ['@attributes' => ['xsi:type' => 'IVL_TS']]; if ($hasBeginDate) { $entry['act']['entryRelationship']['observation']['effectiveTime']['low'] = ['@attributes' => ['value' => $this->parseDate($item['begin_date'])]]; } else { $entry['act']['entryRelationship']['observation']['effectiveTime']['low'] = ['@attributes' => ['nullFLavor' => 'UNK']]; } if ($hasEndDate) { $entry['act']['entryRelationship']['observation']['effectiveTime']['high'] = ['@attributes' => ['value' => $this->parseDate($item['end_date'])]]; } elseif ($entry['act']['statusCode'] == 'completed' && !$hasEndDate) { $entry['act']['entryRelationship']['observation']['effectiveTime']['high'] = ['@attributes' => ['nullFlavor' => 'UNK']]; } // 420134006 SNOMEDCT Propensity to adverse reactions // 418038007 SNOMEDCT Propensity to adverse reactions to substance // 419511003 SNOMEDCT Propensity to adverse reactions to drug // 418471000 SNOMEDCT Propensity to adverse reactions to food // 419199007 SNOMEDCT Allergy to substance // 416098002 SNOMEDCT Drug allergy // 414285001 SNOMEDCT Food allergy // 59037007 SNOMEDCT Drug intolerance // 235719002 SNOMEDCT Food intolerance $entry['act']['entryRelationship']['observation']['value'] = ['@attributes' => ['xsi:type' => 'CD', 'code' => $item['allergy_type_code'], 'displayName' => $item['allergy_type'], 'codeSystemName' => $item['allergy_type_code_type'], 'codeSystem' => $this->codes($item['allergy_type_code_type'])]]; $entry['act']['entryRelationship']['observation']['participant'] = ['@attributes' => ['typeCode' => 'CSM'], 'participantRole' => ['@attributes' => ['classCode' => 'MANU'], 'playingEntity' => ['@attributes' => ['classCode' => 'MMAT'], 'code' => ['@attributes' => ['code' => $item['allergy_code'], 'displayName' => $item['allergy'], 'codeSystemName' => $item['allergy_code_type'], 'codeSystem' => $this->codes($item['allergy_code_type'])]]]]]; // Allergy Status Observation $entryRelationship = ['@attributes' => ['typeCode' => 'SUBJ', 'inversionInd' => 'true'], 'observation' => ['@attributes' => ['classCode' => 'OBS', 'moodCode' => 'EVN'], 'templateId' => ['@attributes' => ['root' => '2.16.840.1.113883.10.20.22.4.28']], 'code' => ['@attributes' => ['code' => '33999-4', 'codeSystemName' => 'LOINC', 'codeSystem' => '2.16.840.1.113883.6.1']], 'statusCode' => ['@attributes' => ['code' => 'completed']]]]; $entryRelationship['observation']['effectiveTime'] = ['@attributes' => ['xsi:type' => 'IVL_TS']]; if ($hasBeginDate) { $entryRelationship['observation']['effectiveTime']['low'] = ['@attributes' => ['value' => $this->parseDate($item['begin_date'])]]; } else { $entryRelationship['observation']['effectiveTime']['low'] = ['@attributes' => ['nullFLavor' => 'UNK']]; } if ($hasEndDate) { $entryRelationship['observation']['effectiveTime']['high'] = ['@attributes' => ['value' => $this->parseDate($item['end_date'])]]; } elseif ($entry['act']['statusCode'] == 'completed' && !$hasEndDate) { $entryRelationship['observation']['effectiveTime']['high'] = ['@attributes' => ['nullFlavor' => 'UNK']]; } $entryRelationship['observation']['value'] = ['@attributes' => ['xsi:type' => 'CE', 'code' => $item['status_code'], 'displayName' => $item['status'], 'codeSystemName' => $item['status_code_type'], 'codeSystem' => $this->codes($item['status_code_type'])]]; $entry['act']['entryRelationship']['observation']['entryRelationship'][] = $entryRelationship; unset($entryRelationship); // Reaction Observation $entryRelationship = ['@attributes' => ['typeCode' => 'MFST', 'inversionInd' => 'true'], 'observation' => ['@attributes' => ['classCode' => 'OBS', 'moodCode' => 'EVN'], 'templateId' => ['@attributes' => ['root' => '2.16.840.1.113883.10.20.22.4.9']], 'id' => ['@attributes' => ['root' => UUID::v4()]], 'code' => ['@attributes' => ['nullFlavor' => 'NA']], 'statusCode' => ['@attributes' => ['code' => 'completed']]]]; $entryRelationship['observation']['effectiveTime'] = ['@attributes' => ['xsi:type' => 'IVL_TS']]; if ($hasBeginDate) { $entryRelationship['observation']['effectiveTime']['low'] = ['@attributes' => ['value' => $this->parseDate($item['begin_date'])]]; } else { $entryRelationship['observation']['effectiveTime']['low'] = ['@attributes' => ['nullFLavor' => 'UNK']]; } if ($hasEndDate) { $entryRelationship['observation']['effectiveTime']['high'] = ['@attributes' => ['value' => $this->parseDate($item['end_date'])]]; } elseif ($entry['act']['statusCode'] == 'completed' && !$hasEndDate) { $entryRelationship['observation']['effectiveTime']['high'] = ['@attributes' => ['nullFlavor' => 'UNK']]; } $entryRelationship['observation']['value'] = ['@attributes' => ['xsi:type' => 'CD', 'code' => $item['reaction_code'], 'displayName' => $item['reaction'], 'codeSystemName' => $item['reaction_code_type'], 'codeSystem' => $this->codes($item['reaction_code_type'])]]; $entry['act']['entryRelationship']['observation']['entryRelationship'][] = $entryRelationship; unset($entryRelationship); // Severity Observation $entryRelationship = ['@attributes' => ['typeCode' => 'SUBJ', 'inversionInd' => 'true'], 'observation' => ['@attributes' => ['classCode' => 'OBS', 'moodCode' => 'EVN'], 'templateId' => ['@attributes' => ['root' => '2.16.840.1.113883.10.20.22.4.8']], 'code' => ['@attributes' => ['code' => 'SEV', 'codeSystemName' => 'ActCode', 'codeSystem' => '2.16.840.1.113883.5.4', 'displayName' => 'Severity Observation']], 'statusCode' => ['@attributes' => ['code' => 'completed']]]]; $entryRelationship['observation']['effectiveTime'] = ['@attributes' => ['xsi:type' => 'IVL_TS']]; if ($hasBeginDate) { $entryRelationship['observation']['effectiveTime']['low'] = ['@attributes' => ['value' => $this->parseDate($item['begin_date'])]]; } else { $entryRelationship['observation']['effectiveTime']['low'] = ['@attributes' => ['nullFLavor' => 'UNK']]; } if ($hasEndDate) { $entryRelationship['observation']['effectiveTime']['high'] = ['@attributes' => ['value' => $this->parseDate($item['end_date'])]]; } elseif ($entry['act']['statusCode'] == 'completed' && !$hasEndDate) { $entryRelationship['observation']['effectiveTime']['high'] = ['@attributes' => ['nullFlavor' => 'UNK']]; } $entryRelationship['observation']['value'] = ['@attributes' => ['xsi:type' => 'CD', 'code' => $item['severity_code'], 'displayName' => $item['severity'], 'codeSystemName' => $item['severity_code_type'], 'codeSystem' => $this->codes($item['severity_code_type'])]]; $entry['act']['entryRelationship']['observation']['entryRelationship'][] = $entryRelationship; unset($entryRelationship); $allergies['entry'][] = $entry; } } if ($this->requiredAllergies || !empty($allergies['entry'])) { $this->addSection(['section' => $allergies]); } unset($allergiesData, $allergies); }
public function postAllergiesList() { $query = Allergies::where('pid', '=', Session::get('pid'))->where('allergies_date_inactive', '=', '0000-00-00 00:00:00')->get(); $result = ''; if ($query) { $result .= '<ul>'; foreach ($query as $row) { $result .= '<li>' . $row->allergies_med . ' - ' . $row->allergies_reaction . '</li>'; } $result .= '</ul>'; } else { $result .= ' No known allergies.'; } echo $result; }
public function postAllergiesList($mobile = false) { $query = Allergies::where('pid', '=', Session::get('pid'))->where('allergies_date_inactive', '=', '0000-00-00 00:00:00')->get(); $result = ''; if ($query) { if ($mobile == false) { $result .= '<ul>'; foreach ($query as $row) { $result .= '<li>' . $row->allergies_med . ' - ' . $row->allergies_reaction . '</li>'; } $result .= '</ul>'; } else { $list_array = []; $form = []; $i = 1; $columns = Schema::getColumnListing('allergies'); $row_index = $columns[0]; $list_array[] = ['label' => 'Add Allergy Item', 'pid' => Session::get('pid'), 'href' => action('AjaxChartController@postMobileEditPage', array('allergies', $row_index, '0')), 'origin' => '../ajaxchart/allergies-list/true']; foreach ($query as $row) { $list_array[] = ['label' => $row->allergies_med . ' - ' . $row->allergies_reaction, 'pid' => Session::get('pid'), 'href' => action('AjaxChartController@postMobileEditPage', array('allergies', $row_index, $row->{$row_index})), 'origin' => '../ajaxchart/allergies-list/true']; } $result .= $this->mobile_result_build($list_array, 'mobile_allergies_list'); } } else { $result .= ' No known allergies.'; } echo $result; }
public function get_EncounterTokensData($eid, $allNeededInfo, $tokens) { $params = new stdClass(); $params->eid = $eid; $encounter = $this->encounter->getEncounter($params); if (!isset($encounter['encounter'])) { return $allNeededInfo; } $encounterCodes = $this->encounter->getEncounterCodes($params); $vitals = end($encounter['encounter']['vitals']); $soap = $encounter['encounter']['soap']; if (isset($encounter['encounter']['reviewofsystemschecks'])) { $rosCks = $encounter['encounter']['reviewofsystemschecks']; unset($rosCks['id'], $rosCks['pid'], $rosCks['eid'], $rosCks['uid'], $rosCks['date']); foreach ($rosCks as $rosc => $num) { if ($num == '' || $num == null || $num == 0) { unset($rosCks[$rosc]); } } } if (isset($encounter['encounter']['reviewofsystems'])) { $reviewofsystems = $encounter['encounter']['reviewofsystems']; unset($reviewofsystems['pid'], $reviewofsystems['eid'], $reviewofsystems['uid'], $reviewofsystems['id'], $reviewofsystems['date']); foreach ($reviewofsystems as $ros => $num) { if ($num == '' || $num == null || $num == 'null') { unset($reviewofsystems[$ros]); } } } $cpt = []; $dx = []; $hcpc = []; $cvx = []; if (isset($encounterCodes['rows'])) { foreach ($encounterCodes['rows'] as $code) { if ($code['code_type'] == 'CPT') { $cpt[] = $code; } elseif ($code['code_type'] == 'ICD' || $code['code_type'] == 'ICD9' || $code['code_type'] == 'ICD10') { $dx[] = $code; } elseif ($code['code_type'] == 'HCPC') { $hcpc[] = $code; } elseif ($code['code_type'] == 'CVX') { $cvx[] = $code; } } } $Medications = new Medications(); $medications = $Medications->getPatientMedicationsByEid($eid); unset($Medications); $Immunizations = new Immunizations(); $immunizations = $Immunizations->getImmunizationsByEid($eid); unset($Immunizations); $Allergies = new Allergies(); $allergies = $Allergies->getPatientAllergiesByEid($eid); unset($Allergies); $ActiveProblems = new ActiveProblems(); $activeProblems = $ActiveProblems->getPatientActiveProblemByEid($eid); unset($ActiveProblems); $encounter = $encounter['encounter']; $encounterInformation = ['[ENCOUNTER_START_DATE]' => $encounter['service_date'], '[ENCOUNTER_END_DATE]' => $encounter['close_date'], '[ENCOUNTER_BRIEF_DESCRIPTION]' => $encounter['brief_description'], '[ENCOUNTER_SENSITIVITY]' => $encounter['priority'], '[ENCOUNTER_WEIGHT_LBS]' => $vitals['weight_lbs'], '[ENCOUNTER_WEIGHT_KG]' => $vitals['weight_kg'], '[ENCOUNTER_HEIGHT_IN]' => $vitals['height_in'], '[ENCOUNTER_HEIGHT_CM]' => $vitals['height_cm'], '[ENCOUNTER_BP_SYSTOLIC]' => $vitals['bp_systolic'], '[ENCOUNTER_BP_DIASTOLIC]' => $vitals['bp_diastolic'], '[ENCOUNTER_PULSE]' => $vitals['pulse'], '[ENCOUNTER_RESPIRATION]' => $vitals['respiration'], '[ENCOUNTER_TEMP_FAHRENHEIT]' => $vitals['temp_f'], '[ENCOUNTER_TEMP_CELSIUS]' => $vitals['temp_c'], '[ENCOUNTER_TEMP_LOCATION]' => $vitals['temp_location'], '[ENCOUNTER_OXYGEN_SATURATION]' => $vitals['oxygen_saturation'], '[ENCOUNTER_HEAD_CIRCUMFERENCE_IN]' => $vitals['head_circumference_in'], '[ENCOUNTER_HEAD_CIRCUMFERENCE_CM]' => $vitals['head_circumference_cm'], '[ENCOUNTER_WAIST_CIRCUMFERENCE_IN]' => $vitals['waist_circumference_in'], '[ENCOUNTER_WAIST_CIRCUMFERENCE_CM]' => $vitals['waist_circumference_cm'], '[ENCOUNTER_BMI]' => $vitals['bmi'], '[ENCOUNTER_BMI_STATUS]' => $vitals['bmi_status'], '[ENCOUNTER_SUBJECTIVE]' => isset($soap['subjective']) ? $soap['subjective'] : '', '[ENCOUNTER_OBJECTIVE]' => isset($soap['objective']) ? $soap['objective'] : '', '[ENCOUNTER_ASSESSMENT]' => isset($soap['assessment']) ? $soap['assessment'] : '', '[ENCOUNTER_PLAN]' => isset($soap['plan']) ? $soap['plan'] : '', '[ENCOUNTER_CPT_CODES]' => $this->tokensForEncountersList($cpt, 1), '[ENCOUNTER_ICD_CODES]' => $this->tokensForEncountersList($dx, 2), '[ENCOUNTER_HCPC_CODES]' => $this->tokensForEncountersList($hcpc, 3), '[ENCOUNTER_ALLERGIES_LIST]' => $this->tokensForEncountersList($allergies, 4), '[ENCOUNTER_MEDICATIONS_LIST]' => $this->tokensForEncountersList($medications, 5), '[ENCOUNTER_ACTIVE_PROBLEMS_LIST]' => $this->tokensForEncountersList($activeProblems, 6), '[ENCOUNTER_IMMUNIZATIONS_LIST]' => $this->tokensForEncountersList($immunizations, 7), '[ENCOUNTER_REVIEWOFSYSTEMSCHECKS]' => isset($rosCks) ? $this->tokensForEncountersList($rosCks, 11) : '', '[ENCOUNTER_REVIEWOFSYSTEMS]' => isset($reviewofsystems) ? $this->tokensForEncountersList($reviewofsystems, 12) : '']; foreach ($tokens as $i => $tok) { if (isset($encounterInformation[$tok]) && ($allNeededInfo[$i] == '' || $allNeededInfo[$i] == null)) { $allNeededInfo[$i] = $encounterInformation[$tok]; } } return $allNeededInfo; }