protected function generate_ccda($hippa_id = '', $pid = '') { $ccda = file_get_contents(__DIR__ . '/../../public/ccda.xml'); $practice_info = Practiceinfo::find(Session::get('practice_id')); $ccda = str_replace('?practice_name?', $practice_info->practice_name, $ccda); $date_format = "YmdHisO"; $ccda = str_replace('?effectiveTime?', date($date_format), $ccda); $ccda_name = time() . '_ccda.xml'; if ($pid == '') { $pid = Session::get('pid'); } $ccda = str_replace('?pid?', $pid, $ccda); $demographics = Demographics::find($pid); $ccda = str_replace('?ss?', $demographics->ss, $ccda); $ccda = str_replace('?street_address1?', $demographics->address, $ccda); $ccda = str_replace('?city?', $demographics->city, $ccda); $ccda = str_replace('?state?', $demographics->state, $ccda); $ccda = str_replace('?zip?', $demographics->zip, $ccda); $ccda = str_replace('?phone_home?', $demographics->phone_home, $ccda); $ccda = str_replace('?firstname?', $demographics->firstname, $ccda); $ccda = str_replace('?lastname?', $demographics->lastname, $ccda); if ($demographics->sex == 'f') { $gender = 'F'; $gender_full = 'Female'; } elseif ($demographics->sex == 'm') { $gender = 'M'; $gender_full = 'Male'; } else { $gender = 'U'; $gender_full = 'Undifferentiated Gender'; } $ccda = str_replace('?gender?', $gender, $ccda); $ccda = str_replace('?gender_full?', $gender_full, $ccda); $ccda = str_replace('?dob?', date('Ymd', $this->human_to_unix($demographics->DOB)), $ccda); $marital_code = "U"; if ($demographics->marital_status == 'Annulled') { $marital_code = "N"; } if ($demographics->marital_status == 'Common law') { $marital_code = "C"; } if ($demographics->marital_status == 'Divorced') { $marital_code = "D"; } if ($demographics->marital_status == 'Domestic partner') { $marital_code = "P"; } if ($demographics->marital_status == 'Interlocutory') { $marital_code = "I"; } if ($demographics->marital_status == 'Legally Separated') { $marital_code = "E"; } if ($demographics->marital_status == 'Living together') { $marital_code = "G"; } if ($demographics->marital_status == 'Married') { $marital_code = "M"; } if ($demographics->marital_status == 'Other') { $marital_code = "O"; } if ($demographics->marital_status == 'Registered domestic partner') { $marital_code = "R"; } if ($demographics->marital_status == 'Separated') { $marital_code = "A"; } if ($demographics->marital_status == 'Single') { $marital_code = "S"; } if ($demographics->marital_status == 'Unknown') { $marital_code = "U"; } if ($demographics->marital_status == 'Unmarried') { $marital_code = "B"; } if ($demographics->marital_status == 'Unreported') { $marital_code = "T"; } if ($demographics->marital_status == 'Widowed') { $marital_code = "O"; } $ccda = str_replace('?marital_status?', $demographics->marital_status, $ccda); $ccda = str_replace('?marital_code?', $marital_code, $ccda); $ccda = str_replace('?race?', $demographics->race, $ccda); $ccda = str_replace('?race_code?', $demographics->race_code, $ccda); $ccda = str_replace('?ethnicity?', $demographics->ethnicity, $ccda); $ccda = str_replace('?ethnicity_code?', $demographics->ethnicity_code, $ccda); $ccda = str_replace('?guardian_code?', $demographics->guardian_code, $ccda); $ccda = str_replace('?guardian_relationship?', $demographics->guardian_relationship, $ccda); $ccda = str_replace('?guardian_lastname?', $demographics->guardian_lastname, $ccda); $ccda = str_replace('?guardian_firstname?', $demographics->guardian_firstname, $ccda); $ccda = str_replace('?guardian_address?', $demographics->guardian_address, $ccda); $ccda = str_replace('?guardian_city?', $demographics->guardian_city, $ccda); $ccda = str_replace('?guardian_state?', $demographics->guardian_state, $ccda); $ccda = str_replace('?guardian_zip?', $demographics->guardian_zip, $ccda); $ccda = str_replace('?guardian_phone_home?', $demographics->guardian_phone_home, $ccda); if ($practice_info->street_address2 != '') { $practice_info->street_address1 .= ', ' . $practice_info->street_address2; } $ccda = str_replace('?practiceinfo_street_address?', $practice_info->street_address1, $ccda); $ccda = str_replace('?practiceinfo_city?', $practice_info->city, $ccda); $ccda = str_replace('?practiceinfo_state?', $practice_info->state, $ccda); $ccda = str_replace('?practiceinfo_zip?', $practice_info->zip, $ccda); $ccda = str_replace('?practiceinfo_phone?', $practice_info->phone, $ccda); $user_id = Session::get('user_id'); $user = User::find($user_id); $ccda = str_replace('?user_id?', $user->id, $ccda); $ccda = str_replace('?user_lastname?', $user->lastname, $ccda); $ccda = str_replace('?user_firstname?', $user->firstname, $ccda); $ccda = str_replace('?user_title?', $user->title, $ccda); $date_format1 = "Ymd"; $ccda = str_replace('?effectiveTimeShort?', date($date_format1), $ccda); $ccda = str_replace('?lang_code?', $demographics->lang_code, $ccda); if ($hippa_id != '') { $hippa_info = Hippa::find($hippa_id); $ccda = str_replace('?hippa_provider?', $hippa_info->hippa_provider, $ccda); $ccda = str_replace('?encounter_role?', $hippa_info->hippa_role, $ccda); if ($hippa_info->hippa_role == "Primary Care Provider") { $hippa_role_code = "PP"; } if ($hippa_info->hippa_role == "Consulting Provider") { $hippa_role_code = "CP"; } if ($hippa_info->hippa_role == "Referring Provider") { $hippa_role_code = "RP"; } } else { $ccda = str_replace('?hippa_provider?', '', $ccda); $ccda = str_replace('?encounter_role?', '', $ccda); $hippa_role_code = ""; } $ccda = str_replace('?encounter_role_code?', $hippa_role_code, $ccda); $recent_encounter_query = DB::table('encounters')->where('pid', '=', $pid)->where('addendum', '=', 'n')->where('practice_id', '=', Session::get('practice_id'))->where('encounter_signed', '=', 'Yes')->orderBy('encounter_DOS', 'desc')->take(1)->first(); if ($recent_encounter_query) { $ccda = str_replace('?eid?', $recent_encounter_query->eid, $ccda); $encounter_info = Encounters::find($recent_encounter_query->eid); $provider_info = User::find($encounter_info->user_id); $provider_info1 = Providers::find($encounter_info->user_id); if ($provider_info1) { $npi = $provider_info1->npi; } else { $npi = ''; } $ccda = str_replace('?npi?', $npi, $ccda); $ccda = str_replace('?provider_title?', $provider_info->title, $ccda); $ccda = str_replace('?provider_firstname?', $provider_info->firstname, $ccda); $ccda = str_replace('?provider_lastname?', $provider_info->lastname, $ccda); $ccda = str_replace('?encounter_dos?', date('Ymd', $this->human_to_unix($encounter_info->encounter_DOS)), $ccda); $assessment_info = Assessment::find($recent_encounter_query->eid); if ($assessment_info) { $recent_icd = $assessment_info->assessment_icd1; $assessment_info1 = DB::table('icd9')->where('icd9', '=', $recent_icd)->first(); if ($assessment_info1) { $recent_icd_description = $assessment_info1->icd9_description; } else { $recent_icd_description = ''; } } else { $recent_icd = ''; $recent_icd_description = ''; } $ccda = str_replace('?icd9?', $recent_icd, $ccda); $ccda = str_replace('?icd9_description?', $recent_icd_description, $ccda); } else { $ccda = str_replace('?eid?', '', $ccda); $ccda = str_replace('?npi?', '', $ccda); $ccda = str_replace('?provider_title?', '', $ccda); $ccda = str_replace('?provider_firstname?', '', $ccda); $ccda = str_replace('?provider_lastname?', '', $ccda); $ccda = str_replace('?encounter_dos?', '', $ccda); $ccda = str_replace('?icd9?', '', $ccda); $ccda = str_replace('?icd9_description?', '', $ccda); } $allergies_query = DB::table('allergies')->where('pid', '=', $pid)->get(); $allergies_table = ""; $allergies_file_final = ""; if ($allergies_query) { $i = 1; foreach ($allergies_query as $allergies_row) { $allergies_table .= "<tr>"; $allergies_table .= "<td>" . $allergies_row->allergies_med . "</td>"; $allergies_table .= "<td><content ID='reaction" . $i . "'>" . $allergies_row->allergies_reaction . "</content></td>"; $allergies_table .= "<td><content ID='severity" . $i . "'>" . $allergies_row->allergies_severity . "</content></td>"; if ($allergies_row->allergies_date_inactive == '0000-00-00 00:00:00') { $allergies_table .= "<td>Active</td>"; $allergies_status = "Active"; $allergies_file = file_get_contents(__DIR__ . '/../../public/allergies_active.xml'); $allergies_file = str_replace('?allergies_date_active?', date('Ymd', $this->human_to_unix($allergies_row->allergies_date_active)), $allergies_file); } else { $allergies_table .= "<td>Inactive</td>"; $allergies_status = "Inactive"; $allergies_file = file_get_contents(__DIR__ . '/../../public/allergies_inactive.xml'); $allergies_file = str_replace('?allergies_date_active?', date('Ymd', $this->human_to_unix($allergies_row->allergies_date_active)), $allergies_file); $allergies_file = str_replace('?allergies_date_inactive?', date('Ymd', $this->human_to_unix($allergies_row->allergies_date_inactive)), $allergies_file); } $allergies_table .= "</tr>"; $reaction_number = "#reaction" . $i; $severity_number = "#severity" . $i; $allergies_file = str_replace('?reaction_number?', $reaction_number, $allergies_file); $allergies_file = str_replace('?severity_number?', $severity_number, $allergies_file); $allergies_file = str_replace('?allergies_med?', $allergies_row->allergies_med, $allergies_file); $allergies_file = str_replace('?allergies_status?', $allergies_status, $allergies_file); $allergies_file = str_replace('?allergies_reaction?', $allergies_row->allergies_reaction, $allergies_file); $allergies_file = str_replace('?allergies_code?', '', $allergies_file); // Need allergies severity field $allergies_file = str_replace('?allergies_severity?', '', $allergies_file); $allergy_random_id1 = $this->gen_uuid(); $allergy_random_id2 = $this->gen_uuid(); $allergy_random_id3 = $this->gen_uuid(); $allergies_file = str_replace('?allergy_random_id1?', $allergy_random_id1, $allergies_file); $allergies_file = str_replace('?allergy_random_id2?', $allergy_random_id2, $allergies_file); $allergies_file = str_replace('?allergy_random_id3?', $allergy_random_id3, $allergies_file); $allergies_file_final .= $allergies_file; $i++; } } $ccda = str_replace('?allergies_table?', $allergies_table, $ccda); $ccda = str_replace('?allergies_file?', $allergies_file_final, $ccda); $encounters_query = DB::table('encounters')->where('pid', '=', $pid)->where('addendum', '=', 'n')->where('practice_id', '=', Session::get('practice_id'))->where('encounter_signed', '=', 'Yes')->orderBy('encounter_DOS', 'desc')->get(); $e = 1; $encounters_table = ""; $encounters_file_final = ""; if ($encounters_query) { foreach ($encounters_query as $encounters_row) { $encounters_table .= "<tr>"; $encounters_table .= "<td><content ID='Encounter" . $e . "'>" . $encounters_row->encounter_cc . "</content></td>"; $encounters_table .= "<td>" . $encounters_row->encounter_provider . "</td>"; $encounters_table .= "<td>" . $practice_info->practice_name . "</td>"; $encounters_table .= "<td>" . date('m-d-Y', $this->human_to_unix($encounters_row->encounter_DOS)) . "</td>"; $encounters_table .= "</tr>"; $encounters_file = file_get_contents(__DIR__ . '/../../public/encounters.xml'); $encounters_number = "#Encounter" . $e; $billing = DB::table('billing_core')->where('eid', '=', $encounters_row->eid)->where('billing_group', '=', '1')->where('cpt', 'NOT LIKE', "sp%")->orderBy('cpt_charge', 'desc')->take(1)->first(); if ($billing) { $cpt_query = DB::table('cpt_relate')->where('cpt', '=', $billing->cpt)->first(); if ($cpt_query) { $cpt_result = DB::table('cpt_relate')->where('cpt', '=', $billing->cpt)->first(); } else { $cpt_result = DB::table('cpt')->where('cpt', '=', $billing->cpt)->first(); } $encounter_code = $billing->cpt; if ($cpt_result) { $cpt_description = $cpt_result->cpt_description; } else { $cpt_description = ''; } } else { $encounter_code = ''; $cpt_description = ''; } $provider_info2 = User::find($encounters_row->user_id); if ($provider_info2) { $provider_firstname = $provider_info2->firstname; $provider_lastname = $provider_info2->lastname; $provider_title = $provider_info2->title; } else { $provider_firstname = ''; $provider_lastname = ''; $provider_title = ''; } $encounters_file = str_replace('?encounter_cc?', $encounters_row->encounter_cc, $encounters_file); $encounters_file = str_replace('?encounter_number?', $encounters_row->eid, $encounters_file); $encounters_file = str_replace('?encounter_code?', $encounter_code, $encounters_file); $encounters_file = str_replace('?encounter_code_desc?', $cpt_description, $encounters_file); $encounters_file = str_replace('?encounter_provider?', $encounters_row->encounter_provider, $encounters_file); $encounters_file = str_replace('?encounter_dos1?', date('m-d-Y', $this->human_to_unix($encounters_row->encounter_DOS)), $encounters_file); $encounters_file = str_replace('?provider_firstname?', $provider_firstname, $encounters_file); $encounters_file = str_replace('?provider_lastname?', $provider_lastname, $encounters_file); $encounters_file = str_replace('?provider_title?', $provider_title, $encounters_file); $encounters_file = str_replace('?encounter_dos?', date('Ymd', $this->human_to_unix($encounters_row->encounter_DOS)), $encounters_file); $encounters_file = str_replace('?practiceinfo_street_address?', $practice_info->street_address1, $encounters_file); $encounters_file = str_replace('?practiceinfo_city?', $practice_info->city, $encounters_file); $encounters_file = str_replace('?practiceinfo_state?', $practice_info->state, $encounters_file); $encounters_file = str_replace('?practiceinfo_zip?', $practice_info->zip, $encounters_file); $encounters_file = str_replace('?practiceinfo_phone?', $practice_info->phone, $encounters_file); $encounters_file = str_replace('?practice_name?', $practice_info->practice_name, $encounters_file); $encounter_random_id1 = $this->gen_uuid(); $encounter_random_id2 = $this->gen_uuid(); $encounter_random_id3 = $this->gen_uuid(); $encounters_file = str_replace('?encounter_random_id1?', $encounter_random_id1, $encounters_file); $encounters_file = str_replace('?encounter_random_id2?', $encounter_random_id2, $encounters_file); $assessment_info1 = Assessment::find($encounters_row->eid); $encounter_diagnosis = ''; if ($assessment_info1) { $dx_array[] = $assessment_info1->assessment_icd1; if ($assessment_info1->assessment_icd2 != "") { $dx_array[] = $assessment_info1->assessment_icd2; } if ($assessment_info1->assessment_icd3 != "") { $dx_array[] = $assessment_info1->assessment_icd3; } if ($assessment_info1->assessment_icd4 != "") { $dx_array[] = $assessment_info1->assessment_icd4; } if ($assessment_info1->assessment_icd5 != "") { $dx_array[] = $assessment_info1->assessment_icd5; } if ($assessment_info1->assessment_icd6 != "") { $dx_array[] = $assessment_info1->assessment_icd6; } if ($assessment_info1->assessment_icd7 != "") { $dx_array[] = $assessment_info1->assessment_icd7; } if ($assessment_info1->assessment_icd8 != "") { $dx_array[] = $assessment_info1->assessment_icd8; } foreach ($dx_array as $dx_item) { $dx_file = file_get_contents(__DIR__ . '/../../public/encounter_diagnosis.xml'); $dx_random_id1 = $this->gen_uuid(); $dx_random_id2 = $this->gen_uuid(); $dx_random_id3 = $this->gen_uuid(); $dx_file = str_replace('?dx_random_id1?', $dx_random_id1, $dx_file); $dx_file = str_replace('?dx_random_id2?', $dx_random_id2, $dx_file); $dx_file = str_replace('?dx_random_id3?', $dx_random_id3, $dx_file); $dx_file = str_replace('?icd9?', $dx_item, $dx_file); $dx_file = str_replace('?encounter_dos?', date('Ymd', $this->human_to_unix($encounter_info->encounter_DOS)), $dx_file); $dx_info = DB::table('icd9')->where('icd9', '=', $dx_item)->first(); if ($dx_info) { $icd_description = $dx_info->icd9_description; } else { $icd_description = ''; } $dx_file = str_replace('?icd9_description?', $icd_description, $dx_file); $encounter_diagnosis .= $dx_file; } } $encounters_file = str_replace('?encounter_diagnosis?', $encounter_diagnosis, $encounters_file); $encounters_file_final .= $encounters_file; $e++; } } $ccda = str_replace('?encounters_table?', $encounters_table, $ccda); $ccda = str_replace('?encounters_file?', $encounters_file_final, $ccda); $imm_query = DB::table('immunizations')->where('pid', '=', $pid)->orderBy('imm_immunization', 'asc')->orderBy('imm_sequence', 'asc')->get(); $imm_table = ""; $imm_file_final = ""; if ($imm_query) { $j = 1; foreach ($imm_query as $imm_row) { $imm_table .= "<tr>"; $imm_table .= "<td><content ID='immun" . $j . "'>" . $imm_row->imm_immunization . "</content></td>"; $imm_table .= "<td>" . date('m-d-Y', $this->human_to_unix($imm_row->imm_date)) . "</td>"; $imm_table .= "<td>Completed</td>"; $imm_table .= "</tr>"; $imm_file = file_get_contents(__DIR__ . '/../../public/immunizations.xml'); $immun_number = "#immun" . $j; $imm_file = str_replace('?immun_number?', $immun_number, $imm_file); $imm_file = str_replace('?imm_date?', date('Ymd', $this->human_to_unix($imm_row->imm_date)), $imm_file); $imm_code = ''; $imm_code_description = ''; if ($imm_row->imm_route == "intramuscularly") { $imm_code = "C1556154"; $imm_code_description = "Intramuscular Route of Administration"; } if ($imm_row->imm_route == "subcutaneously") { $imm_code = "C1522438"; $imm_code_description = "Subcutaneous Route of Administration"; } if ($imm_row->imm_route == "intravenously") { $imm_code = "C2960476"; $imm_code_description = "Intravascular Route of Administration"; } if ($imm_row->imm_route == "by mouth") { $imm_code = "C1522409"; $imm_code_description = "Oropharyngeal Route of Administration"; } $imm_file = str_replace('?imm_code?', $imm_code, $imm_file); $imm_file = str_replace('?imm_code_description?', $imm_code_description, $imm_file); $imm_file = str_replace('?imm_dosage?', $imm_row->imm_dosage, $imm_file); $imm_file = str_replace('?imm_dosage_unit?', $imm_row->imm_dosage_unit, $imm_file); $imm_file = str_replace('?imm_cvxcode?', $imm_row->imm_cvxcode, $imm_file); $imm_random_id1 = $this->gen_uuid(); $imm_file = str_replace('?imm_random_id1?', $imm_random_id1, $imm_file); $cvx = DB::table('cvx')->where('cvx_code', '=', $imm_row->imm_cvxcode)->first(); if ($cvx) { $vaccine_name = $cvx->vaccine_name; } else { $vaccine_name = ''; } $imm_file = str_replace('?vaccine_name?', $vaccine_name, $imm_file); $imm_file = str_replace('?imm_manufacturer?', $imm_row->imm_manufacturer, $imm_file); $imm_file_final .= $imm_file; $j++; } } $ccda = str_replace('?imm_table?', $imm_table, $ccda); $ccda = str_replace('?imm_file?', $imm_file_final, $ccda); $med_query = DB::table('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(); $sup_query = DB::table('sup_list')->where('pid', '=', $pid)->where('sup_date_inactive', '=', '0000-00-00 00:00:00')->get(); $med_table = ""; $med_file_final = ""; $k = 1; if ($med_query) { foreach ($med_query as $med_row) { $med_table .= "<tr>"; $med_table .= "<td><content ID='med" . $k . "'>" . $med_row->rxl_medication . ' ' . $med_row->rxl_dosage . ' ' . $med_row->rxl_dosage_unit . "</content></td>"; if ($med_row->rxl_sig == '') { $instructions = $med_row->rxl_instructions; $med_dosage = ''; $med_dosage_unit = ''; $med_code = ''; $med_code_description = ''; $med_period = ''; } else { $instructions = $med_row->rxl_sig . ' ' . $med_row->rxl_route . ' ' . $med_row->rxl_frequency; $med_dosage_parts = explode(" ", $med_row->rxl_sig); $med_dosage = $med_dosage_parts[0]; if (count($med_dosage_parts) > 1) { $med_dosage_unit = $med_dosage_parts[1]; } else { $med_dosage_unit = ''; } $med_code = ''; $med_code_description = ''; if ($med_row->rxl_route == "by mouth") { $med_code = "C1522409"; $med_code_description = "Oropharyngeal Route of Administration"; } if ($med_row->rxl_route == "per rectum") { $med_code = "C1527425"; $med_code_description = "Rectal Route of Administration"; } if ($med_row->rxl_route == "transdermal") { $med_code = "C0040652"; $med_code_description = "Transdermal Route of Administration"; } if ($med_row->rxl_route == "subcutaneously") { $med_code = "C1522438"; $med_code_description = "Subcutaneous Route of Administration"; } if ($med_row->rxl_route == "intravenously") { $med_code = "C2960476"; $med_code_description = "Intravascular Route of Administration"; } if ($med_row->rxl_route == "intramuscularly") { $med_code = "C1556154"; $med_code_description = "Intramuscular Route of Administration"; } $med_period = ''; $med_freq_array_1 = array("once daily", "every 24 hours", "once a day", "1 time a day", "QD"); $med_freq_array_2 = array("twice daily", "every 12 hours", "two times a day", "2 times a day", "BID", "q12h", "Q12h"); $med_freq_array_3 = array("three times daily", "every 8 hours", "three times a day", "3 times daily", "3 times a day", "TID", "q8h", "Q8h"); $med_freq_array_4 = array("every six hours", "every 6 hours", "four times daily", "4 times a day", "four times a day", "4 times daily", "QID", "q6h", "Q6h"); $med_freq_array_5 = array("every four hours", "every 4 hours", "six times a day", "6 times a day", "six times daily", "6 times daily", "q4h", "Q4h"); $med_freq_array_6 = array("every three hours", "every 3 hours", "eight times a day", "8 times a day", "eight times daily", "8 times daily", "q3h", "Q3h"); $med_freq_array_7 = array("every two hours", "every 2 hours", "twelve times a day", "12 times a day", "twelve times daily", "12 times daily", "q2h", "Q2h"); $med_freq_array_8 = array("every hour", "every 1 hour", "every one hour", "q1h", "Q1h"); if (in_array($med_row->rxl_frequency, $med_freq_array_1)) { $med_period = "24"; } if (in_array($med_row->rxl_frequency, $med_freq_array_2)) { $med_period = "12"; } if (in_array($med_row->rxl_frequency, $med_freq_array_3)) { $med_period = "8"; } if (in_array($med_row->rxl_frequency, $med_freq_array_4)) { $med_period = "6"; } if (in_array($med_row->rxl_frequency, $med_freq_array_5)) { $med_period = "4"; } if (in_array($med_row->rxl_frequency, $med_freq_array_6)) { $med_period = "3"; } if (in_array($med_row->rxl_frequency, $med_freq_array_7)) { $med_period = "2"; } if (in_array($med_row->rxl_frequency, $med_freq_array_8)) { $med_period = "1"; } } $med_table .= "<td>" . $instructions . "</td>"; $med_table .= "<td>" . date('m-d-Y', $this->human_to_unix($med_row->rxl_date_active)) . "</td>"; $med_table .= "<td>Active</td>"; $med_table .= "<td>" . $med_row->rxl_reason . "</td>"; $med_table .= "</tr>"; $med_file = file_get_contents(__DIR__ . '/../../public/medications.xml'); $med_number = "#med" . $k; $med_random_id1 = $this->gen_uuid(); $med_random_id2 = $this->gen_uuid(); $med_file = str_replace('?med_random_id1?', $med_random_id1, $med_file); $med_file = str_replace('?med_random_id2?', $med_random_id2, $med_file); $med_file = str_replace('?med_number?', $med_number, $med_file); $med_file = str_replace('?med_date_active?', date('Ymd', $this->human_to_unix($med_row->rxl_date_active)), $med_file); $med_file = str_replace('?med_code?', $med_code, $med_file); $med_file = str_replace('?med_code_description?', $med_code_description, $med_file); $med_file = str_replace('?med_period?', $med_period, $med_file); $med_file = str_replace('?med_dosage?', $med_dosage, $med_file); $med_file = str_replace('?med_dosage_unit?', $med_dosage_unit, $med_file); $rxnormapi = new RxNormApi(); $rxnormapi->output_type = 'json'; $rxnorm = json_decode($rxnormapi->findRxcuiById("NDC", $med_row->rxl_ndcid), true); if (isset($rxnorm['idGroup']['rxnormId'][0])) { $rxnorm1 = json_decode($rxnormapi->getRxConceptProperties($rxnorm['idGroup']['rxnormId'][0]), true); $med_rxnorm_code = $rxnorm['idGroup']['rxnormId'][0]; $med_name = $rxnorm1['properties']['name']; } else { $med_rxnorm_code = ''; $med_name = $med_row->rxl_medication . ' ' . $med_row->rxl_dosage . ' ' . $med_row->rxl_dosage_unit; } $med_file = str_replace('?med_rxnorm_code?', $med_rxnorm_code, $med_file); $med_file = str_replace('?med_name?', $med_name, $med_file); $med_file_final .= $med_file; $k++; } } if ($sup_query) { foreach ($sup_query as $sup_row) { $med_table .= "<tr>"; $med_table .= "<td><content ID='med" . $k . "'>" . $sup_row->sup_supplement . ' ' . $sup_row->sup_dosage . ' ' . $sup_row->sup_dosage_unit . "</content></td>"; if ($sup_row->sup_sig == '') { $instructions = $sup_row->sup_instructions; $med_dosage = ''; $med_dosage_unit = ''; $med_code = ''; $med_code_description = ''; $med_period = ''; } else { $instructions = $sup_row->sup_sig . ' ' . $sup_row->sup_route . ' ' . $sup_row->sup_frequency; $med_dosage_parts = explode(" ", $sup_row->sup_sig); $med_dosage = $med_dosage_parts[0]; $med_dosage_unit = ''; if (isset($med_dosage_parts[1])) { $med_dosage_unit = $med_dosage_parts[1]; } $med_code = ''; $med_code_description = ''; if ($sup_row->sup_route == "by mouth") { $med_code = "C1522409"; $med_code_description = "Oropharyngeal Route of Administration"; } if ($sup_row->sup_route == "per rectum") { $med_code = "C1527425"; $med_code_description = "Rectal Route of Administration"; } if ($sup_row->sup_route == "transdermal") { $med_code = "C0040652"; $med_code_description = "Transdermal Route of Administration"; } if ($sup_row->sup_route == "subcutaneously") { $med_code = "C1522438"; $med_code_description = "Subcutaneous Route of Administration"; } if ($sup_row->sup_route == "intravenously") { $med_code = "C2960476"; $med_code_description = "Intravascular Route of Administration"; } if ($sup_row->sup_route == "intramuscularly") { $med_code = "C1556154"; $med_code_description = "Intramuscular Route of Administration"; } $med_period = ''; $med_freq_array_1 = array("once daily", "every 24 hours", "once a day", "1 time a day", "QD"); $med_freq_array_2 = array("twice daily", "every 12 hours", "two times a day", "2 times a day", "BID", "q12h", "Q12h"); $med_freq_array_3 = array("three times daily", "every 8 hours", "three times a day", "3 times daily", "3 times a day", "TID", "q8h", "Q8h"); $med_freq_array_4 = array("every six hours", "every 6 hours", "four times daily", "4 times a day", "four times a day", "4 times daily", "QID", "q6h", "Q6h"); $med_freq_array_5 = array("every four hours", "every 4 hours", "six times a day", "6 times a day", "six times daily", "6 times daily", "q4h", "Q4h"); $med_freq_array_6 = array("every three hours", "every 3 hours", "eight times a day", "8 times a day", "eight times daily", "8 times daily", "q3h", "Q3h"); $med_freq_array_7 = array("every two hours", "every 2 hours", "twelve times a day", "12 times a day", "twelve times daily", "12 times daily", "q2h", "Q2h"); $med_freq_array_8 = array("every hour", "every 1 hour", "every one hour", "q1h", "Q1h"); if (in_array($sup_row->sup_frequency, $med_freq_array_1)) { $med_period = "24"; } if (in_array($sup_row->sup_frequency, $med_freq_array_2)) { $med_period = "12"; } if (in_array($sup_row->sup_frequency, $med_freq_array_3)) { $med_period = "8"; } if (in_array($sup_row->sup_frequency, $med_freq_array_4)) { $med_period = "6"; } if (in_array($sup_row->sup_frequency, $med_freq_array_5)) { $med_period = "4"; } if (in_array($sup_row->sup_frequency, $med_freq_array_6)) { $med_period = "3"; } if (in_array($sup_row->sup_frequency, $med_freq_array_7)) { $med_period = "2"; } if (in_array($sup_row->sup_frequency, $med_freq_array_8)) { $med_period = "1"; } } $med_table .= "<td>" . $instructions . "</td>"; $med_table .= "<td>" . date('m-d-Y', $this->human_to_unix($sup_row->sup_date_active)) . "</td>"; $med_table .= "<td>Active</td>"; $med_table .= "<td>" . $sup_row->sup_reason . "</td>"; $med_table .= "</tr>"; $med_file = file_get_contents(__DIR__ . '/../../public/medications.xml'); $med_number = "#med" . $k; $med_random_id1 = $this->gen_uuid(); $med_random_id2 = $this->gen_uuid(); $med_file = str_replace('?med_random_id1?', $med_random_id1, $med_file); $med_file = str_replace('?med_random_id2?', $med_random_id2, $med_file); $med_file = str_replace('?med_number?', $med_number, $med_file); $med_file = str_replace('?med_date_active?', date('Ymd', $this->human_to_unix($sup_row->sup_date_active)), $med_file); $med_file = str_replace('?med_code?', $med_code, $med_file); $med_file = str_replace('?med_code_description?', $med_code_description, $med_file); $med_file = str_replace('?med_period?', $med_period, $med_file); $med_file = str_replace('?med_dosage?', $med_dosage, $med_file); $med_file = str_replace('?med_dosage_unit?', $med_dosage_unit, $med_file); $med_rxnorm_code = ''; $med_name = $sup_row->sup_supplement . ' ' . $sup_row->sup_dosage . ' ' . $sup_row->sup_dosage_unit; $med_file = str_replace('?med_rxnorm_code?', $med_rxnorm_code, $med_file); $med_file = str_replace('?med_name?', $med_name, $med_file); $med_file_final .= $med_file; $k++; } } $ccda = str_replace('?med_table?', $med_table, $ccda); $ccda = str_replace('?med_file?', $med_file_final, $ccda); $orders_table = ""; $orders_file_final = ""; if ($recent_encounter_query) { $orders_query = DB::table('orders')->where('eid', '=', $recent_encounter_query->eid)->get(); if ($orders_query) { foreach ($orders_query as $orders_row) { if ($orders_row->orders_labs != '') { $orders_labs_array = explode("\n", $orders_row->orders_labs); $n1 = 1; foreach ($orders_labs_array as $orders_labs_row) { $orders_table .= "<tr>"; $orders_table .= "<td><content ID='orders_labs_" . $n1 . "'>" . $orders_labs_row . "</td>"; $orders_table .= "<td>" . date('m-d-Y', $this->human_to_unix($orders_row->orders_date)) . "</td>"; $orders_table .= "</tr>"; $orders_file_final .= $this->get_snomed_code($orders_labs_row, $orders_row->orders_date, '#orders_lab_' . $n1); $n1++; } } if ($orders_row->orders_radiology != '') { $orders_rad_array = explode("\n", $orders_row->orders_radiology); $n2 = 1; foreach ($orders_rad_array as $orders_rad_row) { $orders_table .= "<tr>"; $orders_table .= "<td><content ID='orders_rad_" . $n2 . "'>" . $orders_rad_row . "</td>"; $orders_table .= "<td>" . date('m-d-Y', $this->human_to_unix($orders_row->orders_date)) . "</td>"; $orders_table .= "</tr>"; $orders_file_final .= $this->get_snomed_code($orders_rad_row, $orders_row->orders_date, '#orders_rad_' . $n2); $n2++; } } if ($orders_row->orders_cp != '') { $orders_cp_array = explode("\n", $orders_row->orders_cp); $n3 = 1; foreach ($orders_cp_array as $orders_cp_row) { $orders_table .= "<tr>"; $orders_table .= "<td><content ID='orders_cp_" . $n3 . "'>" . $orders_cp_row . "</td>"; $orders_table .= "<td>" . date('m-d-Y', $this->human_to_unix($orders_row->orders_date)) . "</td>"; $orders_table .= "</tr>"; $orders_file_final .= $this->get_snomed_code($orders_cp_row, $orders_row->orders_date, '#orders_cp_' . $n3); $n3++; } } if ($orders_row->orders_referrals != '') { $referral_orders = explode("\nRequested action:\n", $orders_row->orders_referrals); if (count($referral_orders) > 1) { $orders_ref_array = explode("\n", $referral_orders[0]); $n4 = 1; foreach ($orders_ref_array as $orders_ref_row) { $orders_table .= "<tr>"; $orders_table .= "<td><content ID='orders_ref_" . $n4 . "'>" . $orders_ref_row . "</td>"; $orders_table .= "<td>" . date('m-d-Y', $this->human_to_unix($orders_row->orders_date)) . "</td>"; $orders_table .= "</tr>"; $orders_file_final .= $this->get_snomed_code($orders_ref_row, $orders_row->orders_date, '#orders_ref_' . $n4); $n4++; } } } } } } $ccda = str_replace('?orders_table?', $orders_table, $ccda); $ccda = str_replace('?orders_file?', $orders_file_final, $ccda); $issues_query = DB::table('issues')->where('pid', '=', $pid)->get(); $issues_table = ""; $issues_file_final = ""; if ($issues_query) { $l = 1; foreach ($issues_query as $issues_row) { $issues_table .= "<list listType='ordered'>"; $issues_array = explode(' [', $issues_row->issue); $issue_code = str_replace("]", "", $issues_array[1]); $issue_code_description = $issues_array[0]; if ($issues_row->issue_date_inactive != '0000-00-00 00:00:00') { $issues_table .= "<item><content ID='problem" . $l . "'>" . $issues_row->issue . ": Status - Resolved</content></item>"; $issues_status = "Resolved"; $issues_code = "413322009"; $issues_file = file_get_contents(__DIR__ . '/../../public/issues_inactive.xml'); $issues_file = str_replace('?issue_date_inactive?', date('Ymd', $this->human_to_unix($issues_row->issue_date_inactive)), $issues_file); } else { $issues_table .= "<item><content ID='problem" . $l . "'>" . $issues_row->issue . ": Status - Active</content></item>"; $issues_status = "Active"; $issues_code = "55561003"; $issues_file = file_get_contents(__DIR__ . '/../../public/issues_active.xml'); } $issues_table .= "</list>"; $issues_file = str_replace('?issue_date_active?', date('Ymd', $this->human_to_unix($issues_row->issue_date_active)), $issues_file); $issues_file = str_replace('?issue_code?', $issue_code, $issues_file); $issues_file = str_replace('?issue_code_description?', $issue_code_description, $issues_file); $issues_number = "#problem" . $l; $issues_random_id1 = $this->gen_uuid(); $issues_file = str_replace('?issues_random_id1?', $issues_random_id1, $issues_file); $issues_file = str_replace('?issues_number?', $issues_number, $issues_file); $issues_file = str_replace('?issues_code?', $issues_code, $issues_file); $issues_file = str_replace('?issues_status?', $issues_status, $issues_file); $issues_file_final .= $issues_file; $l++; } } $ccda = str_replace('?issues_table?', $issues_table, $ccda); $ccda = str_replace('?issues_file?', $issues_file_final, $ccda); $proc_table = ""; $proc_file_final = ""; if ($recent_encounter_query) { $proc_query = DB::table('procedure')->where('eid', '=', $recent_encounter_query->eid)->get(); if ($proc_query) { $m = 1; foreach ($proc_query as $proc_row) { $proc_table .= "<tr>"; $proc_table .= "<td><content ID='proc" . $m . "'>" . $proc_row->proc_type . "</content></td>"; $proc_table .= "<td>" . date('m-d-Y', $this->human_to_unix($proc_row->proc_date)) . "</td>"; $proc_table .= "</tr>"; $proc_file = file_get_contents(__DIR__ . '/../../public/proc.xml'); $proc_file = str_replace('?proc_date?', date('Ymd', $this->human_to_unix($proc_row->proc_date)), $proc_file); $proc_file = str_replace('?proc_type?', $proc_row->proc_type, $proc_file); $proc_file = str_replace('?proc_cpt?', $proc_row->proc_cpt, $proc_file); $proc_file = str_replace('?practiceinfo_street_address?', $practice_info->street_address1, $proc_file); $proc_file = str_replace('?practiceinfo_city?', $practice_info->city, $proc_file); $proc_file = str_replace('?practiceinfo_state?', $practice_info->state, $proc_file); $proc_file = str_replace('?practiceinfo_zip?', $practice_info->zip, $proc_file); $proc_file = str_replace('?practiceinfo_phone?', $practice_info->phone, $proc_file); $proc_file = str_replace('?practice_name?', $practice_info->practice_name, $proc_file); $proc_number = "#proc" . $m; $proc_random_id1 = $this->gen_uuid(); $proc_file = str_replace('?proc_random_id1?', $proc_random_id1, $proc_file); $proc_file_final .= $proc_file; $m++; } } } $ccda = str_replace('?proc_table?', $proc_table, $ccda); $ccda = str_replace('?proc_file?', $proc_file_final, $ccda); $other_history_table = ""; $other_history_file = ""; if ($recent_encounter_query) { $other_history_row = DB::table('other_history')->where('eid', '=', $recent_encounter_query->eid)->first(); if ($other_history_row) { if ($other_history_row->oh_tobacco != '') { $other_history_table .= "<td>Smoking Status</td>"; $other_history_table .= "<td><content ID='other_history1'>" . $other_history_row->oh_tobacco . "</td>"; $other_history_table .= "<td>" . date('m-d-Y', $this->human_to_unix($other_history_row->oh_date)) . "</td>"; $other_history_table .= "</tr>"; $other_history_table .= "<tr>"; if ($demographics->tobacco == 'yes') { $other_history_code = "77176002"; $other_history_description = "Smoker"; } else { $other_history_code = "8392000"; $other_history_description = "Non-Smoker"; } $other_history_file = file_get_contents(__DIR__ . '/../../public/social_history.xml'); $other_history_file = str_replace('?other_history_code?', $other_history_code, $other_history_file); $other_history_file = str_replace('?other_history_description?', $other_history_description, $other_history_file); $other_history_file = str_replace('?other_history_date?', date('Ymd', $this->human_to_unix($other_history_row->oh_date)), $other_history_file); } } } $ccda = str_replace('?other_history_table?', $other_history_table, $ccda); $ccda = str_replace('?other_history_file?', $other_history_file, $ccda); $vitals_table = ""; $vitals_file_final = ""; if ($recent_encounter_query) { $vitals_row = DB::table('vitals')->where('eid', '=', $recent_encounter_query->eid)->first(); if ($vitals_row) { $vitals_table .= '<thead><tr><th align="right">Date / Time: </th><th>' . date('m-d-Y h:i A', $this->human_to_unix($vitals_row->vitals_date)) . '</th></tr></thead><tbody>'; $vitals_file_final .= ' <entry typeCode="DRIV"><organizer classCode="CLUSTER" moodCode="EVN"><templateId root="2.16.840.1.113883.10.20.22.4.26"/><id root="'; $vitals_file_final .= $this->gen_uuid() . '"/><code code="46680005" codeSystem="2.16.840.1.113883.6.96" codeSystemName="SNOMED-CT" displayName="Vital signs"/><statusCode code="completed"/><effectiveTime value="'; $vitals_file_final .= date('Ymd', $this->human_to_unix($vitals_row->vitals_date)) . '"/>'; if ($vitals_row->height != '') { $vitals_table .= '<tr><th align="left">Height</th><td><content ID="vit_height">'; $vitals_table .= $vitals_row->height . ' ' . $practice_info->height_unit; $vitals_table .= '</content></td></tr>'; $vitals_code1 = "8302-2"; $vitals_description1 = "Body height"; $vitals_file = file_get_contents(__DIR__ . '/../../public/vitals.xml'); $vitals_file = str_replace('?vitals_code?', $vitals_code1, $vitals_file); $vitals_file = str_replace('?vitals_description?', $vitals_description1, $vitals_file); $vitals_file = str_replace('?vitals_date?', date('Ymd', $this->human_to_unix($vitals_row->vitals_date)), $vitals_file); $vitals_file = str_replace('?vitals_id?', '#vit_height', $vitals_file); $vitals_file = str_replace('?vitals_value?', $vitals_row->height, $vitals_file); $vitals_file = str_replace('?vitals_unit?', $practice_info->height_unit, $vitals_file); $vitals_random_id1 = $this->gen_uuid(); $vitals_file = str_replace('?vitals_random_id1?', $vitals_random_id1, $vitals_file); } if ($vitals_row->weight != '') { $vitals_table .= '<tr><th align="left">Weight</th><td><content ID="vit_weight">'; $vitals_table .= $vitals_row->weight . ' ' . $practice_info->weight_unit; $vitals_table .= '</content></td></tr>'; $vitals_code2 = "3141-9"; $vitals_description2 = "Body weight Measured"; $vitals_file = file_get_contents(__DIR__ . '/../../public/vitals.xml'); $vitals_file = str_replace('?vitals_code?', $vitals_code2, $vitals_file); $vitals_file = str_replace('?vitals_description?', $vitals_description2, $vitals_file); $vitals_file = str_replace('?vitals_date?', date('Ymd', $this->human_to_unix($vitals_row->vitals_date)), $vitals_file); $vitals_file = str_replace('?vitals_id?', '#vit_weight', $vitals_file); $vitals_file = str_replace('?vitals_value?', $vitals_row->weight, $vitals_file); $vitals_file = str_replace('?vitals_unit?', $practice_info->weight_unit, $vitals_file); $vitals_random_id2 = $this->gen_uuid(); $vitals_file = str_replace('?vitals_random_id1?', $vitals_random_id2, $vitals_file); } if ($vitals_row->bp_systolic != '' && $vitals_row->bp_diastolic) { $vitals_table .= '<tr><th align="left">Blood Pressure</th><td><content ID="vit_bp">'; $vitals_table .= $vitals_row->bp_systolic . '/' . $vitals_row->bp_diastolic . ' mmHg'; $vitals_table .= '</content></td></tr>'; $vitals_code3 = "8480-6"; $vitals_description3 = "Intravascular Systolic"; $vitals_file = file_get_contents(__DIR__ . '/../../public/vitals.xml'); $vitals_file = str_replace('?vitals_code?', $vitals_code3, $vitals_file); $vitals_file = str_replace('?vitals_description?', $vitals_description3, $vitals_file); $vitals_file = str_replace('?vitals_date?', date('Ymd', $this->human_to_unix($vitals_row->vitals_date)), $vitals_file); $vitals_file = str_replace('?vitals_id?', '#vit_bp', $vitals_file); $vitals_file = str_replace('?vitals_value?', $vitals_row->bp_systolic, $vitals_file); $vitals_file = str_replace('?vitals_unit?', "mmHg", $vitals_file); $vitals_random_id3 = $this->gen_uuid(); $vitals_file = str_replace('?vitals_random_id1?', $vitals_random_id3, $vitals_file); } $vitals_table .= '</tbody>'; $vitals_file_final .= ' </organizer>'; $vitals_file_final .= ' </entry>'; } } $ccda = str_replace('?vitals_table?', $vitals_table, $ccda); $ccda = str_replace('?vitals_file?', $vitals_file_final, $ccda); return $ccda; }
public function postElectronicOrders() { $pid = Session::get('pid'); $orders_id = Input::get('orders_id'); $row = Orders::find($orders_id); $row1 = Addressbook::find($row->address_id); if ($row1->electronic_order == '') { echo "Laboratory provider is not configured for electronic order entry. Please use an alternate method for delivery."; exit(0); } else { $row2 = Demographics::find($pid); $row3 = User::find($row->id); $row4 = Providers::find($row->id); if ($row1->electronic_order == 'PeaceHealth') { $date = date('YmdHi'); $dob = date('Ymd', $this->human_to_unix($row2->DOB)); $order_date = date('YmdHi', $this->human_to_unix($row->orders_pending_date)); $middle = substr($row3->middle, 0, 1); $pname = substr($row3->lastname, 0, 5) . substr($row3->firstname, 0, 1) . substr($row3->middle, 0, 1); $hl7 = "MSH|^~\\&|QDX|" . strtoupper($pname) . "|||" . $date . "00||ORM^O01|R10063131003.1|P|2.3||^" . strtoupper($pname); $hl7 .= "\r"; $hl7 .= "PID|1|" . $pid . "|||" . strtoupper($row2->lastname) . "^" . strtoupper($row2->firstname) . "||" . $dob . "|" . strtoupper($row2->sex) . "|||||||||||"; $hl7 .= "\r"; $hl7 .= "ORC|NW|" . $orders_id . "|||A||^^^" . $order_date . "00||" . $date . "00|||" . strtoupper($row4->peacehealth_id) . "^" . strtoupper($row3->lastname) . "^" . strtoupper($row3->firstname) . "^" . strtoupper($middle) . "^^^" . strtoupper($row3->title) . "||||^|" . strtoupper($row4->peacehealth_id) . "^" . strtoupper($row3->lastname) . "^" . strtoupper($row3->firstname) . "^" . strtoupper($middle) . "^^^" . strtoupper($row3->title) . "||||100^QA-Central Laboratory|QA-Central Laboratory|QA-Central Laboratory^123 International Way^Springfield^OR^97477|1-800-826-3616"; $orders_array = explode("\n", $row->orders_labs); $j = 1; foreach ($orders_array as $orders_row) { if ($orders_row != "") { $orders_row_array = explode(";", $orders_row); $testname = $orders_row_array[0]; $i = 0; foreach ($orders_row_array as $orders_row1) { if (strpos($orders_row1, " Code: ") !== FALSE) { $testcode = str_replace(" Code: ", "", $orders_row1); $i++; } if (strpos($orders_row1, " AOEAnswer: ") !== FALSE) { $aoe_answer = str_replace(" AOEAnswer: ", "", $orders_row1); if (strpos($aoe_answer, "|") !== FALSE) { $aoe_answer_array = explode("|", $aoe_answer); } else { $aoe_answer_array[] = $aoe_answer; } } if (strpos($orders_row1, " AOECode: ") !== FALSE) { $aoe_code = str_replace(" AOECode: ", "", $orders_row1); $aoe_code = str_replace("\r", "", $aoe_code); if (strpos($aoe_code, "|") !== FALSE) { $aoe_code_array = explode("|", $aoe_code); } else { $aoe_code_array[] = $aoe_code; } } } if ($i == 0) { echo "Laboratory order code is missing for the electronic order entry. Be sure you are choosing an order from an Electronic Order Entry list"; exit(0); } $hl7 .= "\r"; $orders_cc = ''; $hl7 .= "OBR|" . $j . "|" . $orders_id . "||" . strtoupper($testcode) . "^" . strtoupper($testname) . "^^|R|" . $order_date . "00|" . $date . "|||||||" . $date . "00|SST^BLD|96666|||||PHL^PeaceHealth Laboratories^123 International Way^Springfield^OR^97477|||||||" . $orders_cc . "|"; $j++; } } if ($row->orders_insurance != 'Bill Client') { $in1_array = explode("\n", $row->orders_insurance); $k = 1; foreach ($in1_array as $in1_row) { $in1_array1 = explode(";", $in1_row); $payor_id = str_replace(" Payor ID: ", "", $in1_array1[1]); if ($payor_id == "Unknown") { $payor_id = 'UNK.'; } $plan_id = str_replace(" ID: ", "", $in1_array1[2]); if (strpos($in1_array1[3], " Group: ") !== FALSE) { $group_id = str_replace(" Group: ", "", $in1_array1[3]); $name_array = explode(", ", $in1_array1[4]); } else { $group_id = ""; $name_array = explode(", ", $in1_array1[3]); } $hl7 .= "\r"; $hl7 .= "IN1|" . $k . "|UNK.|" . strtoupper($payor_id) . "|" . strtoupper($in1_array1[0]) . "||||" . strtoupper($group_id) . "||||||||" . strtoupper($name_array[0]) . "^" . strtoupper($name_array[1]) . "^^^||||||||||||||||||||" . strtoupper($plan_id) . "|||||||||"; $k++; } } if (isset($aoe_answer_array)) { for ($l = 0; $l < count($aoe_answer_array); $l++) { $hl7 .= "\r"; $m = $l + 1; $hl7 .= "OBX|" . $m . "||" . strtoupper($aoe_code_array[$l]) . "||" . strtoupper($aoe_answer_array[$l]) . "||||||P|||" . $date . "00|"; } } $file = "/srv/ftp/shared/export/PHLE_" . time(); file_put_contents($file, $hl7); echo "Electronic order entry sent!"; exit(0); } } }
public function postCropSignature() { $signature = Providers::find(Session::get('user_id')); $targ_w = 198; $targ_h = 55; $img_r = $this->getImageFile($signature->signature); $dst_r = ImageCreateTrueColor($targ_w, $targ_h); $x = Input::get('x'); $y = Input::get('y'); $w = Input::get('w'); $h = Input::get('h'); imagecopyresampled($dst_r, $img_r, 0, 0, $x, $y, $targ_w, $targ_h, $w, $h); $this->saveImage($dst_r, $signature->signature); $result['link'] = HTML::image($signature->signature, 'Provider Signature', array('border' => '0', 'id' => 'image_target')); $result['growl'] = "Signature cropped and saved!"; $img = $this->getImageFile($signature->signature); $result['button'] = ""; if (imagesx($img) > 198) { $result['message'] = "Image width is too large (less than 198px is recommended). Use the cropping tool to get to the correct width."; $result['button'] = "<br><button id='image_crop'>Crop Image</button>"; } else { $result['message'] = "Image width is correct."; } if (imagesy($img) > 55) { $result['message'] .= " Image height is too large (less than 55px is recommended). Use the cropping tool to get to the correct height."; $result['button'] = "<br><button id='image_crop'>Crop Image</button>"; } else { $result['message'] .= " Image height is correct."; } echo json_encode($result); }
public function dashboard() { $user_id = Session::get('user_id'); $practice_id = Session::get('practice_id'); $data['practiceinfo'] = Practiceinfo::find($practice_id); $result = User::find($user_id); $data['displayname'] = $result->displayname; $displayname = $result->displayname; $fax_query = Received::where('practice_id', '=', $practice_id)->count(); $from = $displayname . ' (' . $user_id . ')'; if (Session::get('group_id') == '2') { $data['number_messages'] = Messaging::where('mailbox', '=', $user_id)->count(); $data['number_documents'] = Scans::where('practice_id', '=', $practice_id)->count() + $fax_query; $data['number_appts'] = $this->getNumberAppts($user_id); $query1 = DB::table('t_messages')->join('demographics', 't_messages.pid', '=', 'demographics.pid')->where('t_messages.t_messages_from', '=', $from)->where('t_messages.t_messages_signed', '=', 'No')->count(); $query2 = DB::table('encounters')->join('demographics', 'encounters.pid', '=', 'demographics.pid')->where('encounters.encounter_provider', '=', $displayname)->where('encounters.encounter_signed', '=', 'No')->count(); $data['number_drafts'] = $query1 + $query2; $data['number_reminders'] = DB::table('alerts')->join('demographics', 'alerts.pid', '=', 'demographics.pid')->where('alerts.alert_provider', '=', $user_id)->where('alerts.alert_date_complete', '=', '0000-00-00 00:00:00')->where('alerts.alert_reason_not_complete', '=', '')->where(function ($query_array) { $query_array->where('alerts.alert', '=', 'Laboratory results pending')->orWhere('alerts.alert', '=', 'Radiology results pending')->orWhere('alerts.alert', '=', 'Cardiopulmonary results pending')->orWhere('alerts.alert', '=', 'Referral pending')->orWhere('alerts.alert', '=', 'Reminder')->orWhere('alerts.alert', '=', 'REMINDER'); })->count(); $data['number_bills'] = Encounters::where('bill_submitted', '=', 'No')->where('user_id', '=', $user_id)->count(); $data['number_tests'] = Tests::whereNull('pid')->where('practice_id', '=', $practice_id)->count(); if ($data['practiceinfo']->mtm_extension == 'y') { $mtm_users_array = explode(",", $data['practiceinfo']->mtm_alert_users); if (in_array($user_id, $mtm_users_array)) { $data['mtm_alerts'] = Alerts::where('alert_date_complete', '=', '0000-00-00 00:00:00')->where('alert_reason_not_complete', '=', '')->where('alert', '=', 'Medication Therapy Management')->where('practice_id', '=', $practice_id)->count(); $data['mtm_alerts_status'] = "y"; } else { $data['mtm_alerts_status'] = "n"; } } else { $data['mtm_alerts_status'] = "n"; } $data['vaccine_supplement_alert'] = $this->vaccine_supplement_alert($practice_id); } if (Session::get('group_id') == '3') { $data['number_messages'] = Messaging::where('mailbox', '=', $user_id)->count(); $data['number_documents'] = Scans::where('practice_id', '=', $practice_id)->count() + $fax_query; $data['number_drafts'] = DB::table('t_messages')->join('demographics', 't_messages.pid', '=', 'demographics.pid')->where('t_messages.t_messages_from', '=', $from)->where('t_messages.t_messages_signed', '=', 'No')->count(); $data['number_reminders'] = DB::table('alerts')->join('demographics', 'alerts.pid', '=', 'demographics.pid')->where('alerts.alert_provider', '=', $user_id)->where('alerts.alert_date_complete', '=', '0000-00-00 00:00:00')->where('alerts.alert_reason_not_complete', '=', '')->where(function ($query_array) { $query_array->where('alerts.alert', '=', 'Laboratory results pending')->orWhere('alerts.alert', '=', 'Radiology results pending')->orWhere('alerts.alert', '=', 'Cardiopulmonary results pending')->orWhere('alerts.alert', '=', 'Referral pending')->orWhere('alerts.alert', '=', 'Reminder')->orWhere('alerts.alert', '=', 'REMINDER'); })->count(); $data['number_bills'] = Encounters::where('bill_submitted', '=', 'No')->where('practice_id', '=', $practice_id)->count(); $data['number_tests'] = Tests::whereNull('pid')->where('practice_id', '=', $practice_id)->count(); $data['vaccine_supplement_alert'] = $this->vaccine_supplement_alert($practice_id); } if (Session::get('group_id') == '4') { $data['number_messages'] = Messaging::where('mailbox', '=', $user_id)->count(); $data['number_bills'] = Encounters::where('bill_submitted', '=', 'No')->where('practice_id', '=', $practice_id)->count(); $data['number_documents'] = Scans::where('practice_id', '=', $practice_id)->count() + $fax_query; } if (Session::get('group_id') == '100') { $row = Demographics_relate::where('id', '=', $user_id)->first(); Session::put('pid', $row->pid); } if (Session::get('group_id') == '1') { if ($practice_id == '1') { $data['saas_admin'] = 'y'; } else { $data['saas_admin'] = 'n'; } if (Session::get('patient_centric') != 'y') { $users = DB::table('users')->where('group_id', '=', '2')->where('practice_id', '=', Session::get('practice_id'))->first(); if ($users) { $data['users_needed'] = 'n'; } else { $data['users_needed'] = 'y'; } } else { $data['users_needed'] = 'n'; } if (Session::get('patient_centric') != 'y') { $schedule = DB::table('practiceinfo')->where('practice_id', '=', Session::get('practice_id'))->whereNull('minTime')->first(); if ($schedule) { $data['schedule_needed'] = 'y'; } else { $data['schedule_needed'] = 'n'; } } else { $data['schedule_needed'] = 'n'; } } if ($data['practiceinfo']->weekends == '1') { $data['weekends'] = 'true'; } else { $data['weekends'] = 'false'; } $data['minTime'] = ltrim($data['practiceinfo']->minTime, "0"); $data['maxTime'] = ltrim($data['practiceinfo']->maxTime, "0"); if (Session::get('group_id') == '2') { $provider = Providers::find(Session::get('user_id')); $data['schedule_increment'] = $provider->schedule_increment; } else { $data['schedule_increment'] = '15'; } if (!Session::get('encounter_active')) { Session::put('encounter_active', 'n'); } if ($data['practiceinfo']->fax_type != "") { $data1['fax'] = true; } else { $data1['fax'] = false; } $this->layout->style = $this->css_assets(); $this->layout->script = $this->js_assets('home'); $this->layout->content = ''; if (Session::get('group_id') == '1') { $this->layout->content .= View::make('search', $this->getSearchData())->render(); $this->layout->content .= View::make('dashboard', $data)->render(); $this->layout->content .= View::make('setup')->render(); $this->layout->content .= View::make('users')->render(); $this->layout->content .= View::make('extensions', $data)->render(); $this->layout->content .= View::make('schedule_admin')->render(); $this->layout->content .= View::make('update')->render(); $this->layout->content .= View::make('logs')->render(); $this->layout->content .= View::make('schedule')->render(); } if (Session::get('group_id') == '2' || Session::get('group_id') == '3' || Session::get('group_id') == '4') { $this->layout->content .= View::make('search', $this->getSearchData())->render(); $this->layout->content .= View::make('dashboard', $data)->render(); $this->layout->content .= View::make('demographics')->render(); $this->layout->content .= View::make('options')->render(); $this->layout->content .= View::make('messaging', $data1)->render(); $this->layout->content .= View::make('schedule')->render(); $this->layout->content .= View::make('billing')->render(); $this->layout->content .= View::make('financial')->render(); $this->layout->content .= View::make('office')->render(); if (Session::get('patient_centric') == 'yp' && Session::get('group_id') == '2') { $this->layout->content .= View::make('setup')->render(); } } if (Session::get('group_id') == '100') { $this->layout->content .= View::make('dashboard', $data)->render(); $this->layout->content .= View::make('demographics')->render(); $this->layout->content .= View::make('messaging', $data1)->render(); $this->layout->content .= View::make('schedule')->render(); $this->layout->content .= View::make('issues')->render(); $this->layout->content .= View::make('encounters')->render(); $this->layout->content .= View::make('t_messages')->render(); $this->layout->content .= View::make('medications')->render(); $this->layout->content .= View::make('supplements')->render(); $this->layout->content .= View::make('allergies')->render(); $this->layout->content .= View::make('immunizations')->render(); $this->layout->content .= View::make('documents')->render(); $this->layout->content .= View::make('forms')->render(); $this->layout->content .= View::make('graph')->render(); } }
public function main() { $row = Practiceinfo::find(Session::get('practice_id')); if (isset($row->default_pos_id)) { $data['default_pos'] = $row->default_pos_id; } else { $data['default_pos'] = ''; } $data['encounter_template'] = $row->encounter_template; if ($row->weekends == '1') { $data['weekends'] = 'true'; } else { $data['weekends'] = 'false'; } $data['minTime'] = ltrim($row->minTime, "0"); $data['maxTime'] = ltrim($row->maxTime, "0"); if (!Session::get('encounter_active')) { Session::put('encounter_active', 'n'); } if (Session::get('group_id') == '2') { $provider = Providers::find(Session::get('user_id')); $data['schedule_increment'] = $provider->schedule_increment; } else { $data['schedule_increment'] = '15'; } if ($row->fax_type != "") { $data1['fax'] = true; } else { $data1['fax'] = false; } $patient = DB::table('demographics_relate')->where('pid', '=', Session::get('pid'))->where('practice_id', '=', Session::get('practice_id'))->whereNotNull('id')->first(); if ($patient) { $data2['portal_active'] = true; } else { $data2['portal_active'] = false; } $patient1 = DB::table('demographics_relate')->where('pid', '=', Session::get('pid'))->where('practice_id', '=', Session::get('practice_id'))->whereNotNull('url')->first(); if ($patient1) { $data['url'] = 'Connected'; } else { $data['url'] = 'Not Connected'; } $this->layout->style = $this->css_assets(); $this->layout->script = $this->js_assets('chart'); $this->layout->search = View::make('search', $this->getSearchData())->render(); $this->layout->menu = View::make('menu', $this->getMenuData())->render(); $this->layout->content = View::make('chart', $data)->render(); $this->layout->modules = View::make('demographics')->render(); $this->layout->modules .= View::make('options')->render(); $this->layout->modules .= View::make('issues')->render(); $this->layout->modules .= View::make('medications')->render(); $this->layout->modules .= View::make('allergies')->render(); $this->layout->modules .= View::make('supplements')->render(); $this->layout->modules .= View::make('immunizations')->render(); $this->layout->modules .= View::make('print')->render(); $this->layout->modules .= View::make('billing')->render(); $this->layout->modules .= View::make('documents')->render(); $this->layout->modules .= View::make('t_messages')->render(); $this->layout->modules .= View::make('encounters')->render(); $this->layout->modules .= View::make('alerts', $data2)->render(); $this->layout->modules .= View::make('lab')->render(); $this->layout->modules .= View::make('rad')->render(); $this->layout->modules .= View::make('cp')->render(); $this->layout->modules .= View::make('ref')->render(); $this->layout->modules .= View::make('messaging', $data1)->render(); $this->layout->modules .= View::make('schedule')->render(); $this->layout->modules .= View::make('financial')->render(); $this->layout->modules .= View::make('office')->render(); $this->layout->modules .= View::make('graph')->render(); $this->layout->modules .= View::make('image')->render(); if ($row->mtm_extension == 'y') { $this->layout->content .= View::make('mtm')->render(); $this->layout->script .= HTML::script('/js/mtm.js'); } }