Пример #1
0
 /**
  * function getHL7
  * generating HL7 format
  */
 public function reportAction()
 {
     $request = $this->getRequest();
     $data = $request->getPost();
     if (isset($data['hl7button'])) {
         $form_code = isset($data['codes']) ? $data['codes'] : array();
         $from_date = $request->getPost('from_date', null) ? $this->CommonPlugin()->date_format($request->getPost('from_date', null), 'yyyy-mm-dd', $GLOBALS['date_display_format']) : date('Y-m-d', strtotime(date('Ymd')) - 86400 * 7);
         $to_date = $request->getPost('to_date', null) ? $this->CommonPlugin()->date_format($request->getPost('to_date', null), 'yyyy-mm-dd', $GLOBALS['date_display_format']) : date('Y-m-d');
         $form_get_hl7 = 'true';
         $patient_id = $request->getPost('patient_id', null);
         //pagination
         $results = $request->getPost('form_results', 100);
         $results = $results > 0 ? $results : 100;
         $current_page = $request->getPost('form_current_page', 1);
         $end = $current_page * $results;
         $start = $end - $results;
         $new_search = $request->getPost('form_new_search', null);
         //endpagination
         if (empty($form_code)) {
             $query_codes = '';
         } else {
             $query_codes = 'c.id in ( ';
             foreach ($form_code as $code) {
                 $query_codes .= $code . ",";
             }
             $query_codes = substr($query_codes, 0, -1);
             $query_codes .= ') and ';
         }
         if (empty($patient_id)) {
             $query_pids = '';
         } else {
             $pid_arr = explode(',', $patient_id);
             $query_pids = '(';
             foreach ($pid_arr as $pid_val) {
                 $query_pids .= "p.pid = ( '";
                 $query_pids .= \Application\Model\ApplicationTable::quoteValue($pid_val) . "' ) or ";
                 $query_pids .= "p.fname like ( '%";
                 $query_pids .= \Application\Model\ApplicationTable::quoteValue($pid_val) . "%' ) or ";
                 $query_pids .= "p.mname like ( '%";
                 $query_pids .= \Application\Model\ApplicationTable::quoteValue($pid_val) . "%' ) or ";
                 $query_pids .= "p.lname like ( '%";
                 $query_pids .= \Application\Model\ApplicationTable::quoteValue($pid_val) . "%' ) or ";
             }
             $query_pids = trim($query_pids);
             $query_pids = rtrim($query_pids, 'or');
             $query_pids .= ') and ';
         }
         $params = array('form_from_date' => $from_date, 'form_to_date' => $to_date, 'form_get_hl7' => $form_get_hl7, 'query_codes' => $query_codes, 'results' => $results, 'current_page' => $current_page, 'limit_start' => $start, 'limit_end' => $end, 'query_pids' => $query_pids);
         if ($new_search) {
             $count = $this->getImmunizationTable()->immunizedPatientDetails($params, 1);
         } else {
             $count = $request->getPost('form_count');
             if ($count == '') {
                 $count = $this->getImmunizationTable()->immunizedPatientDetails($params, 1);
             }
         }
         $totalpages = ceil($count / $results);
         $details = $this->getImmunizationTable()->immunizedPatientDetails($params);
         $rows = array();
         foreach ($details as $row) {
             $rows[] = $row;
         }
         $D = "\r";
         $nowdate = date('YmdHis');
         $now = date('YmdGi');
         $now1 = date('Y-m-d G:i');
         $filename = "imm_reg_" . $now . ".hl7";
         // GENERATE HL7 FILE
         if ($form_get_hl7 === 'true') {
             $content = '';
             $patient_id = '';
             foreach ($rows as $r) {
                 $race_code = $administered_unit_title = $administered_route_title = '';
                 $race_title = $ethnicity = $ethnicity_code = $ethnicity_title = '';
                 $administered_site_code = $guardian_relationship_code = $manufacturer_code = '';
                 $immunization_info_source_code = $email = $race = $units = $manufacturer = '';
                 $information_source = $completion_status = $refusal_reason_code = '';
                 $immunization_refusal = $ordering_provider = $entered_by = $publicity_code_val = '';
                 $publicity_code = $imm_registry_status_code = $protection_indicator = '';
                 $guardiansname = '';
                 if ($r['patientid'] != $patient_id) {
                     $content .= "MSH|^~\\&|OPENEMR|" . $r['facility_code'] . "||NIST Test Iz Reg|{$nowdate}||" . "VXU^V04^VXU_V04|OPENEMR-110316102457117|P|2.5.1|||AL|ER" . "{$D}";
                     $race_code = $this->getImmunizationTable()->getNotes($r['race'], 'race');
                     $race_title = $this->CommonPlugin()->getListtitle('race', $r['race']);
                     $ethnicity_code = $this->getImmunizationTable()->getNotes($r['ethnicity'], 'ethnicity');
                     $ethnicity_title = $this->CommonPlugin()->getListtitle('ethnicity', $r['ethnicity']);
                     $guardianarray = explode(' ', $r['guardiansname']);
                     $guardianname = $guardianarray[1] . '^' . $guardianarray[0];
                     if ($r['sex'] === 'Male') {
                         $r['sex'] = 'M';
                     }
                     if ($r['sex'] === 'Female') {
                         $r['sex'] = 'F';
                     }
                     if ($r['status'] === 'married') {
                         $r['status'] = 'M';
                     }
                     if ($r['status'] === 'single') {
                         $r['status'] = 'S';
                     }
                     if ($r['status'] === 'divorced') {
                         $r['status'] = 'D';
                     }
                     if ($r['status'] === 'widowed') {
                         $r['status'] = 'W';
                     }
                     if ($r['status'] === 'separated') {
                         $r['status'] = 'A';
                     }
                     if ($r['status'] === 'domestic partner') {
                         $r['status'] = 'P';
                     }
                     if ($r['email']) {
                         $email = '~^NET^Internet^' . $r['email'];
                     }
                     if ($r['race']) {
                         $race = $race_code . '^' . $race_title . '^HL70005';
                     }
                     if ($r['ethnicity']) {
                         $ethnicity = $ethnicity_code . '^' . $ethnicity_title . '^CDCREC';
                     }
                     $r['ss'] = $r['ss'] ? "~" . $r['ss'] . "^^^MAA^SS" : "";
                     $content .= "PID|" . "1|" . "|" . $r['pubpid'] . "^^^MPI&2.16.840.1.113883.19.3.2.1&ISO^MR" . $r['ss'] . "|" . "|" . $r['patientname'] . "^^^^L|" . $guardianname . "|" . $r['DOB'] . "|" . $r['sex'] . "|" . "|" . $race . "|" . $r['address'] . "^L" . "|" . "|" . "^PRN^PH^^^" . $this->format_phone($r['phone_home']) . "^^" . $email . "|" . "^WPN^PH^^^" . $this->format_phone($r['phone_biz']) . "^^|" . $r['language'] . "|" . $r['status'] . "|" . "|" . "|" . "|" . "|" . "|" . $ethnicity . "|" . "|" . "|" . "|" . "|" . "|" . "|" . "|" . "|" . "|" . "|" . "|" . "|" . "|" . "|" . "|" . "|" . "" . "{$D}";
                     if ($r['publicity_code']) {
                         $publicity_code_val = $this->getImmunizationTable()->getNotes($r['publicity_code'], 'publicity_code');
                         $publicity_code = $publicity_code_val . "^" . $r['publicity_code'] . "^HL70215";
                     }
                     $imm_registry_status_code = $this->getImmunizationTable()->getNotes($r['imm_reg_status'], 'immunization_registry_status');
                     $protection_indicator = $this->getImmunizationTable()->getNotes($r['protect_indicator'], 'yesno');
                     if ($publicity_code || $protection_indicator || $imm_registry_status_code) {
                         $content .= "PD1|" . "|" . "|" . $r['fac_name'] . "|" . $r['primary_care_provider_details'] . "|" . "|" . "|" . "|" . "|" . "|" . "|" . $publicity_code . "|" . $protection_indicator . "|" . $r['protection_effective_date'] . "|" . "|" . "|" . $imm_registry_status_code . "|" . $r['immunization_registry_status_effective_date'] . "|" . $r['publicity_code_effective_date'] . "|" . "|" . "|" . "" . "{$D}";
                     }
                     if ($r['guardiansex'] === 'male') {
                         $r['guardiansex'] = 'M';
                     }
                     if ($r['guardiansex'] === 'female') {
                         $r['guardiansex'] = 'F';
                     }
                     $guardian_relationship_code = $this->getImmunizationTable()->getNotes($r['guardianrelationship'], 'next_of_kin_relationship');
                     if ($r['guardiansname'] && $r['guardianrelationship']) {
                         $content .= "NK1|" . "1|" . $guardianname . "^^^^^L|" . $guardian_relationship_code . "^" . $r['guardianrelationship'] . "^HL70063|" . $r['guardian_address'] . "|" . "^PRN^PH^^^" . $this->format_phone($r['guardianphone']) . "|" . "^WPN^PH^^^" . $this->format_phone($r['guardianworkphone']) . "|" . "|" . "|" . "|" . "|" . "|" . "|" . "|" . $r['guardiansex'] . "|" . "|" . "|" . "|" . "|" . "|" . "|" . "|" . "|" . "|" . "|" . "|" . "|" . "|" . "" . "{$D}";
                     }
                 }
                 if ($r['completion_status'] == 'Refused') {
                     $r['immunizationid'] = '9999';
                 }
                 if ($r['administered_by_id'] == 0 && $r['information_source'] == 'hist_inf_src_unspecified') {
                     $ordering_provider = "";
                 } else {
                     if ($r['ordering_provider']) {
                         $ordering_provider = $r['ordering_provider'] . "^" . $r['ordering_provider_name'] . "^^^^^NIST-AA-1^L";
                     }
                 }
                 if ($r['created_by']) {
                     $entered_by = $r['created_by'] . "^" . $r['entered_by_name'] . "^^^^^NIST-AA-1";
                 }
                 $content .= "ORC" . "|" . "RE|" . "|" . $r['immunizationid'] . "^NDA|" . "|" . "|" . "|" . "|" . "|" . "|" . $entered_by . "|" . "|" . $ordering_provider . "|" . "|" . "|" . "|" . "|" . "|" . "|" . "|" . "|" . "|" . "|" . "|" . "|" . "|" . "|" . "|" . "|" . "|" . "|" . "" . "{$D}";
                 $administered_unit_title = $this->CommonPlugin()->getListtitle('drug_units', $r['administered_unit']);
                 $manufacturer_code = $this->getImmunizationTable()->getNotes($r['manufacturer'], 'Immunization_Manufacturer');
                 $immunization_info_source_code = $this->getImmunizationTable()->getNotes($r['information_source'], 'immunization_informationsource');
                 if ($administered_unit_title) {
                     $units = $administered_unit_title . '^' . $administered_unit_title . '^UCUM^^^';
                 }
                 if ($r['manufacturer']) {
                     $manufacturer = $manufacturer_code . "^" . $r['manufacturer'] . "^" . "MVX";
                 }
                 if ($r['information_source']) {
                     $information_source = $immunization_info_source_code . "^" . $r['information_source'] . "^NIP001";
                 }
                 if ($r['providername'] != NULL && $r['information_source'] == 'new_immunization_record') {
                     $r['providername'] = $r['users_id'] . "^" . $r['providername'];
                 }
                 $refusal_reason_code = $this->getImmunizationTable()->getNotes($r['refusal_reason'], 'immunization_refusal_reason');
                 $completion_status = $this->getImmunizationTable()->getNotes($r['completion_status'], 'Immunization_Completion_Status');
                 if ($r['refusal_reason']) {
                     $completion_status = 'RE';
                     $immunization_refusal = $refusal_reason_code . "^" . $r['refusal_reason'] . "^NIP002";
                 }
                 if ($r['code'] == '998') {
                     $completion_status = 'NA';
                 }
                 $content .= "RXA|" . "0|" . "1|" . $r['administered_date'] . "|" . "|" . $r['code'] . "^" . $r['immunizationtitle'] . "^" . "CVX" . "|" . $r['administered_amount'] . "|" . $units . "|" . "|" . $information_source . "|" . $r['providername'] . "|" . $r['facility_address'] . "|" . "|" . "|" . "|" . $r['lot_number'] . "|" . $r['expiration_date'] . "|" . $manufacturer . "|" . $immunization_refusal . "|" . "|" . $completion_status . "|" . "A" . "{$D}";
                 $administered_route_title = $this->CommonPlugin()->getListtitle('drug_route', $r['route']);
                 $administered_site_code = $this->getImmunizationTable()->getNotes($r['administration_site'], 'immunization_administered_site');
                 if ($r['route_code'] || $r['administration_site']) {
                     $content .= "RXR|" . $r['route_code'] . "^" . $administered_route_title . "^HL70162|" . $administered_site_code . "^" . $r['administration_site'] . "^HL70163" . "|" . "|" . "|" . "" . "{$D}";
                 }
                 $imm_obs_res = $this->getImmunizationTable()->getImmunizationObservationResultsData($r['patientid'], $r['immunizationid']);
                 if (count($imm_obs_res > 0)) {
                     $last_key = 1;
                     foreach ($imm_obs_res as $key_obs => $val_obs) {
                         $criteria_code = $criteria_notes = $obs_value_notes = $obs_value = $obs_method = $date_obs = $value_type = $criteria_value = '';
                         $criteria_code = $this->getImmunizationTable()->getCodes($val_obs['imo_criteria'], 'immunization_observation');
                         $criteria_notes = $this->getImmunizationTable()->getNotes($val_obs['imo_criteria'], 'immunization_observation');
                         $obs_value_notes = $this->getImmunizationTable()->getNotes($val_obs['imo_criteria_value'], 'imm_vac_eligibility_results');
                         $criteria_value = $criteria_code . "^" . $val_obs['imo_criteria'] . "^" . $criteria_notes;
                         $date_obs = preg_replace('/-/', '', substr($val_obs['imo_date_observation'], 0, 10));
                         if ($val_obs['imo_criteria'] == 'funding_program_eligibility') {
                             $obs_value = $obs_value_notes . "^" . $val_obs['imo_criteria_value'] . "^HL70064";
                             $obs_method = "VXC40^per immunization^CDCPHINVS";
                             $value_type = "CE";
                         } else {
                             if ($val_obs['imo_criteria'] == 'vaccine_type') {
                                 $obs_value = $val_obs['imo_code'] . "^" . $val_obs['imo_codetext'] . "^" . $val_obs['imo_codetype'];
                                 $value_type = "CE";
                             } else {
                                 if ($val_obs['imo_criteria'] == 'disease_with_presumed_immunity') {
                                     $value_type = "CE";
                                     $obs_value = $val_obs['imo_code'] . "^" . $val_obs['imo_codetext'] . "^SCT";
                                 }
                             }
                         }
                         if ($key_obs > 1) {
                             if ($last_key > 4) {
                                 $key_val = $last_key + 1;
                             } else {
                                 $key_val = $key_val + 1;
                             }
                         } else {
                             $key_val = $key_obs + 1;
                         }
                         $content .= "OBX|" . $key_val . "|" . $value_type . "|" . $criteria_value . "|" . $key_val . "|" . $obs_value . "|" . "|" . "|" . "|" . "|" . "|" . "F|" . "|" . "|" . $date_obs . "|" . "|" . "|" . $obs_method . "{$D}";
                         $last_key = $key_val;
                         if ($val_obs['imo_vis_date_published'] != 0) {
                             $value_type = "TS";
                             $criteria_value = "29768-9^Date vaccine information statement published^LN";
                             $obs_value = preg_replace('/-/', '', $val_obs['imo_vis_date_published']);
                             if ($key_obs > 1) {
                                 if ($last_key == 4) {
                                     $key_val = $last_key + 1;
                                 } else {
                                     $key_val = $key_val + 1;
                                 }
                             } else {
                                 $key_val = $last_key + 1;
                             }
                             $content .= "OBX|" . $key_val . "|" . $value_type . "|" . $criteria_value . "|" . $last_key . "|" . $obs_value . "|" . "|" . "|" . "|" . "|" . "|" . "F|" . "|" . "|" . $date_obs . "|" . "|" . "|" . "" . "{$D}";
                         }
                         $last_key = $key_val;
                         if ($val_obs['imo_vis_date_presented'] != 0) {
                             $value_type = "TS";
                             $criteria_value = "29769-7^Date vaccine information statement presented^LN";
                             $obs_value = preg_replace('/-/', '', $val_obs['imo_vis_date_presented']);
                             if ($key_obs > 1) {
                                 if ($last_key == 5) {
                                     $key_val = $last_key + 1;
                                 } else {
                                     $key_val = $key_val + 1;
                                 }
                             } else {
                                 $key_val = $last_key + 1;
                             }
                             $content .= "OBX|" . $key_val . "|" . $value_type . "|" . $criteria_value . "|" . ($last_key - 1) . "|" . $obs_value . "|" . "|" . "|" . "|" . "|" . "|" . "F|" . "|" . "|" . $date_obs . "|" . "|" . "|" . "" . "{$D}";
                         }
                         $last_key = $key_val;
                     }
                 }
                 $patient_id = $r['patientid'];
             }
             header('Content-type: text/plain');
             header('Content-Disposition: attachment; filename=' . $filename);
             // put the content in the file
             echo $content;
             exit;
         }
     }
 }