Ejemplo n.º 1
0
 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 postHippaView($hippa_id, $pid)
 {
     $row = Hippa::find($hippa_id);
     $row1 = Demographics::find($pid);
     $text = '<strong>Patient:</strong>  ' . $row1->firstname . " " . $row1->lastname . '<br><br><strong>Date Released:</strong>  ' . date('m/d/Y', $this->human_to_unix($row->hippa_date_release)) . '<br><br><strong>Release to:</strong>  ' . $row->hippa_provider . '<br><br><strong>Reason:</strong> ' . $row->hippa_reason;
     echo $text;
 }