/**
  * Display the specified resource.
  *
  * @param  int  $id
  * @return Response
  */
 public function show($id)
 {
     $rxnormapi = new RxNormApi();
     $rxnormapi->output_type = 'json';
     $rxnorm = json_decode($rxnormapi->findRxcuiById("NDC", $id), 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'];
         $statusCode = 200;
         $response['resourceType'] = 'Medication';
         $response['id'] = $id;
         $response['text']['status'] = 'generated';
         $response['text']['div'] = '<div>' . $rxnorm1['properties']['name'] . '</div>';
         $response['code']['text'] = $rxnorm1['properties']['name'];
     } else {
         $response = ['error' => "Medication doesn't exist."];
         $statusCode = 404;
     }
     return Response::json($response, $statusCode);
 }
Exemplo n.º 2
0
 protected function resource_detail($row, $resource_type)
 {
     $practice = DB::table('practiceinfo')->where('practice_id', '=', '1')->first();
     $response['resourceType'] = $resource_type;
     $response['text']['status'] = 'generated';
     // Patient
     if ($resource_type == 'Patient') {
         $response['text']['div'] = '<div><table><tbody>';
         $response['identifier'][] = ['use' => 'usual', 'label' => 'MRN', 'system' => 'urn:oid:1.2.36.146.595.217.0.1', 'value' => $row->pid, 'period' => ['start' => date('Y-m-d')], 'assigner' => ['display' => $practice->practice_name]];
         $response['name'][] = ['use' => 'official', 'family' => [$row->lastname], 'given' => [$row->firstname]];
         $response['text']['div'] .= '<tr><td><b>Name</b></td><td>' . $row->firstname . ' ' . $row->lastname . '</td></tr>';
         if ($row->nickname != '') {
             $response['name'][] = ['use' => 'usual', 'given' => [$row->nickname]];
         }
         if ($row->phone_home != '') {
             $response['telecom'][] = ['use' => 'home', 'value' => $row->phone_home, 'system' => 'phone'];
             $response['text']['div'] .= '<tr><td><b>Telcom, Home</b></td><td>' . $row->phone_home . '</td></tr>';
         }
         if ($row->phone_work != '') {
             $response['telecom'][] = ['use' => 'work', 'value' => $row->phone_work, 'system' => 'phone'];
             $response['text']['div'] .= '<tr><td><b>Telcom, Work</b></td><td>' . $row->phone_work . '</td></tr>';
         }
         if ($row->sex == 'f') {
             $gender = 'F';
             $gender_full = 'Female';
         } elseif ($row->sex == 'm') {
             $gender = 'M';
             $gender_full = 'Male';
         } else {
             $gender = 'UN';
             $gender_full = 'Undifferentiated';
         }
         $response['gender']['coding'][] = ['system' => "http://hl7.org/fhir/v3/AdministrativeGender", 'code' => $gender, 'display' => $gender_full];
         $response['text']['div'] .= '<tr><td><b>Gender</b></td><td>' . $gender_full . '</td></tr>';
         $birthdate = date('Y-m-d', $this->human_to_unix($row->DOB));
         $response['birthDate'] = $birthdate;
         $response['text']['div'] .= '<tr><td><b>Birthdate</b></td><td>' . $birthdate . '</td></tr>';
         $response['deceasedBoolean'] = false;
         $response['address'][] = ['use' => 'home', 'line' => [$row->address], 'city' => $row->city, 'state' => $row->state, 'zip' => $row->zip];
         $response['text']['div'] .= '<tr><td><b>Address</b></td><td>' . $row->address . ', ' . $row->city . ', ' . $row->state . ', ' . $row->zip . '</td></tr>';
         $response['contact'][0]['relationship'][0]['coding'][0] = ['system' => "http://hl7.org/fhir/patient-contact-relationship", 'code' => $row->guardian_relationship];
         $response['contact'][0]['name'] = ['family' => [$row->guardian_lastname], 'given' => [$row->guardian_firstname]];
         $response['contact'][0]['telecom'][] = ['system' => 'phone', 'value' => $row->guardian_phone_home];
         $response['text']['div'] .= '<tr><td><b>Contacts</b></td><td>' . $row->guardian_firstname . ' ' . $row->guardian_lastname . ', Phone: ' . $row->guardian_phone_home . ', Relationship: ' . $row->guardian_relationship . '</td></tr>';
         $response['managingOrganization'] = ['reference' => 'Organization/1'];
         if ($row->active == '0') {
             $response['active'] = false;
         } else {
             $response['active'] = true;
         }
         $response['text']['div'] .= '</tbody></table></div>';
     }
     // Condition
     if ($resource_type == 'Condition') {
         $patient = DB::table('demographics')->where('pid', '=', $row->pid)->first();
         $response['patient'] = ['reference' => 'Patient/' . $row->pid, 'display' => $patient->firstname . ' ' . $patient->lastname];
         if ($practice->icd == '9') {
             $condition_system = 'http://hl7.org/fhir/sid/icd-9';
         } else {
             $condition_system = 'http://hl7.org/fhir/sid/icd-10';
         }
         if (isset($row->eid)) {
             $response['encounter'] = ['reference' => 'Encounter/' . $row->eid];
             $response['id'] = 'eid_' . $row->eid;
             $provider = DB::table('users')->where('displayname', '=', $row->encounter_provider)->first();
             $response['dateRecorded'] = date('Y-m-d', $this->human_to_unix($row->assessment_date));
             $i = 1;
             while ($i <= 12) {
                 $condition_row_array = (array) $row;
                 if ($condition_row_array['assessment_' . $i] != '') {
                     $code_array = explode(' [', $condition_row_array['assessment_' . $i]);
                     $response['code']['coding'][] = ['system' => $condition_system, 'code' => str_replace(']', '', $code_array[1]), 'display' => $code_array[0]];
                     $response['text']['div'] = '<div>' . $condition_row_array['assessment_' . $i] . ', <a href="' . route('home') . '/fhir/Encounter/' . $row->eid . '">Encounter Assessment</a>, Date Active: ' . date('Y-m-d', $this->human_to_unix($row->assessment_date)) . '</div>';
                 }
                 $i++;
             }
             $response['category']['coding'][] = ['system' => 'http://hl7.org/fhir/condition-category', 'code' => 'diagnosis', 'display' => 'Diagnosis'];
         } else {
             $response['id'] = 'issue_id_' . $row->issue_id;
             $provider = DB::table('users')->where('displayname', '=', $row->issue_provider)->first();
             $response['dateRecorded'] = date('Y-m-d', $this->human_to_unix($row->issue_date_active));
             $response['onsetDateTime'] = date('Y-m-d', $this->human_to_unix($row->issue_date_active));
             $code_array = explode(' [', $row->issue);
             $response['code']['coding'][] = ['system' => $condition_system, 'code' => str_replace(']', '', $code_array[1]), 'display' => $code_array[0]];
             $response['text']['div'] = '<div>' . $row->issue . ', Problem, Date Active: ' . date('Y-m-d', $this->human_to_unix($row->issue_date_active)) . '</div>';
             $response['category']['coding'][] = ['system' => 'http://snomed.info/sct', 'code' => '55607006', 'display' => 'Problem'];
         }
         $response['asserter'] = ['reference' => 'Practitioner/' . $provider->id, 'display' => $provider->displayname];
         $response['status'] = 'confirmed';
         // missing severity
         // missing evidence
         // missing location
         // missing relatedItem
     }
     // MedicationStatement
     if ($resource_type == 'MedicationStatement') {
         $response['id'] = $row->rxl_id;
         $patient = DB::table('demographics')->where('pid', '=', $row->pid)->first();
         $response['patient'] = ['reference' => 'Patient/' . $row->pid, 'display' => $patient->firstname . ' ' . $patient->lastname];
         $provider = DB::table('users')->where('displayname', '=', $row->rxl_provider)->first();
         if ($provider) {
             $response['recorder'] = ['reference' => 'Practitioner/' . $provider->id, 'display' => $row->rxl_provider];
         }
         $response['dateAsserted'] = date('Y-m-d');
         $response['effectiveDateTime'] = date('Y-m-d', $this->human_to_unix($row->rxl_date_active));
         if ($row->rxl_ndcid != '') {
             $rxnormapi = new RxNormApi();
             $rxnormapi->output_type = 'json';
             $rxnorm = json_decode($rxnormapi->findRxcuiById("NDC", $row->rxl_ndcid), true);
             if (isset($rxnorm['idGroup']['rxnormId'][0])) {
                 $rxnorm1 = json_decode($rxnormapi->getRxConceptProperties($rxnorm['idGroup']['rxnormId'][0]), true);
                 $response['medicationReference'] = ['reference' => 'Medication/' . $row->rxl_ndcid, 'display' => $rxnorm1['properties']['name']];
             }
         }
         $med_prn_array = array("as needed", "PRN");
         if ($row->rxl_sig == '') {
             $response['text']['div'] = '<div>' . $row->rxl_medication . ' ' . $row->rxl_dosage . ' ' . $row->rxl_dosage_unit . ', ' . $row->rxl_instructions . ' for ' . $row->rxl_reason . '</div>';
             $dosage_text = $row->rxl_instructions . ' for ' . $row->rxl_reason;
             $asNeededBoolean = false;
             if (in_array($med_row->rxl_instructions, $med_prn_array)) {
                 $asNeededBoolean = true;
             }
             $dosage_array = ['text' => $dosage_text, 'asNeededBoolean' => $asNeededBoolean, 'quantityQuantity' => ['value' => $row->rxl_quantity]];
         } else {
             $response['text']['div'] = '<div>' . $row->rxl_medication . ' ' . $row->rxl_dosage . ' ' . $row->rxl_dosage_unit . ', ' . $row->rxl_sig . ' ' . $row->rxl_route . ' ' . $row->rxl_frequency . ' for ' . $row->rxl_reason . '</div>';
             $dosage_text = $row->rxl_sig . ' ' . $row->rxl_route . ' ' . $row->rxl_frequency . ' for ' . $row->rxl_reason;
             $med_dosage_parts = explode(" ", $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 ($row->rxl_route == "by mouth") {
                 $med_code = "C1522409";
                 $med_code_description = "Oropharyngeal Route of Administration";
             }
             if ($row->rxl_route == "per rectum") {
                 $med_code = "C1527425";
                 $med_code_description = "Rectal Route of Administration";
             }
             if ($row->rxl_route == "transdermal") {
                 $med_code = "C0040652";
                 $med_code_description = "Transdermal Route of Administration";
             }
             if ($row->rxl_route == "subcutaneously") {
                 $med_code = "C1522438";
                 $med_code_description = "Subcutaneous Route of Administration";
             }
             if ($row->rxl_route == "intravenously") {
                 $med_code = "C2960476";
                 $med_code_description = "Intravascular Route of Administration";
             }
             if ($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($row->rxl_frequency, $med_freq_array_1)) {
                 $med_period = "24";
             }
             if (in_array($row->rxl_frequency, $med_freq_array_2)) {
                 $med_period = "12";
             }
             if (in_array($row->rxl_frequency, $med_freq_array_3)) {
                 $med_period = "8";
             }
             if (in_array($row->rxl_frequency, $med_freq_array_4)) {
                 $med_period = "6";
             }
             if (in_array($row->rxl_frequency, $med_freq_array_5)) {
                 $med_period = "4";
             }
             if (in_array($row->rxl_frequency, $med_freq_array_6)) {
                 $med_period = "3";
             }
             if (in_array($row->rxl_frequency, $med_freq_array_7)) {
                 $med_period = "2";
             }
             if (in_array($row->rxl_frequency, $med_freq_array_8)) {
                 $med_period = "1";
             }
             $asNeededBoolean = false;
             if (in_array($row->rxl_frequency, $med_prn_array)) {
                 $asNeededBoolean = true;
             }
             $dosage_array = ['text' => $dosage_text, 'asNeededBoolean' => $asNeededBoolean, 'quantityQuantity' => ['value' => $row->rxl_quantity]];
             if ($med_period != '') {
                 $dosage_array['timing'] = ['repeat' => ['frequency' => $med_period, 'period' => '1', 'periodUnits' => 'd']];
             }
             if ($med_code != '' && $med_code_description != '') {
                 $dosage_array['route'] = ['coding' => ['0' => ['system' => 'http://ncimeta.nci.nih.gov', 'code' => $med_code, 'display' => $med_code_description]]];
             }
         }
         if ($row->rxl_date_inactive == '0000-00-00 00:00:00' && $row->rxl_date_old == '0000-00-00 00:00:00') {
             $response['status'] = 'active';
             $response['wasNotTaken'] = false;
         }
         if ($row->rxl_date_inactive != '0000-00-00 00:00:00') {
             $response['status'] = 'completed';
             $response['wasNotTaken'] = true;
         }
         $response['dosage'][] = $dosage_array;
     }
     // AllergyIntolerance
     if ($resource_type == 'AllergyIntolerance') {
         $response['id'] = $row->allergies_id;
         $patient = DB::table('demographics')->where('pid', '=', $row->pid)->first();
         $response['patient'] = ['reference' => 'Patient/' . $row->pid, 'display' => $patient->firstname . ' ' . $patient->lastname];
         $provider = DB::table('users')->where('displayname', '=', $row->allergies_provider)->first();
         if ($provider) {
             $response['recorder'] = ['reference' => 'Practitioner/' . $provider->id, 'display' => $row->allergies_provider];
         }
         $response['recordedDate'] = date('Y-m-d', $this->human_to_unix($row->allergies_date_active));
         $rxnormapi = new RxNormApi();
         $rxnormapi->output_type = 'json';
         $rxnorm = json_decode($rxnormapi->findRxcuiByString($row->allergies_med), true);
         $rxnorm1 = array();
         if (isset($rxnorm['idGroup']['rxnormId'][0])) {
             $rxnorm1 = json_decode($rxnormapi->getRxConceptProperties($rxnorm['idGroup']['rxnormId'][0]), true);
             $response['substance']['coding'][] = ['system' => 'http://www.nlm.nih.gov/research/umls/rxnorm', 'code' => $rxnorm['idGroup']['rxnormId'][0], 'display' => $rxnorm1['properties']['name']];
         } else {
             $response['substance']['text'] = $row->allergies_med;
         }
         $response['text']['div'] = '<div>' . $row->allergies_med . ', Reaction: ' . $row->allergies_reaction . ', Severeity ' . $row->allergies_severity . '</div>';
         $response['reaction'][] = ['manifestation' => ['0' => ['coding' => ['0' => ['system' => 'http://snomed.info/sct', 'code' => '', 'display' => '']]]]];
     }
     // Immunization
     if ($resource_type == 'Immunization') {
         $response['id'] = $row->imm_id;
         $patient = DB::table('demographics')->where('pid', '=', $row->pid)->first();
         $response['patient'] = ['reference' => 'Patient/' . $row->pid, 'display' => $patient->firstname . ' ' . $patient->lastname];
         $provider = DB::table('users')->where('displayname', '=', $row->imm_provider)->first();
         if ($provider) {
             $response['requester'] = ['reference' => 'Practitioner/' . $provider->id, 'display' => $row->imm_provider];
         }
         if ($row->imm_cvxcode != '') {
             $response['vaccineCode']['coding'][] = ['system' => 'http://hl7.org/fhir/sid/cvx', 'code' => $row->imm_cvxcode, 'display' => $row->imm_immunization];
         } else {
             $response['vaccineCode']['text'] = $row->imm_immunization;
         }
         $response['date'] = date('Y-m-d', $this->human_to_unix($row->imm_date));
         $response['status'] = 'completed';
         $response['wasNotGiven'] = false;
         if ($row->imm_lot != '') {
             $response['lotNumber'] = $row->imm_lot;
         }
         if ($row->imm_expiration != '') {
             $response['expirationDate'] = date('Y-m-d', $this->human_to_unix($row->imm_expiration));
         }
         if ($row->imm_sequence != '') {
             $response['vaccinationProtocol'][] = ['doseSequence' => $row->imm_sequence];
         }
         if ($row->imm_sequence == '1') {
             $sequence = ', first';
         }
         if ($row->imm_sequence == '2') {
             $sequence = ', second';
         }
         if ($row->imm_sequence == '3') {
             $sequence = ', third';
         }
         if ($row->imm_sequence == '4') {
             $sequence = ', fourth';
         }
         if ($row->imm_sequence == '5') {
             $sequence = ', fifth';
         }
         $response['text']['div'] = '<div>' . $row->imm_immunization . $sequence . ', Given: ' . date('Y-m-d', $this->human_to_unix($row->imm_date)) . '</div>';
     }
     return $response;
 }
Exemplo n.º 3
0
 protected function rxnorm_name_search($name)
 {
     $rxnormapi = new RxNormApi();
     $rxnormapi->output_type = 'json';
     $rxnorm = json_decode($rxnormapi->getDrugs($name), true);
     $result = array();
     $i = 0;
     if (isset($rxnorm['drugGroup']['conceptGroup'][3]['conceptProperties'][0])) {
         foreach ($rxnorm['drugGroup']['conceptGroup'][3]['conceptProperties'] as $item) {
             $result[$i]['rxcui'] = $item['rxcui'];
             $result[$i]['name'] = $item['name'];
             $result[$i]['category'] = 'Generic';
             $i++;
         }
     }
     if (isset($rxnorm['drugGroup']['conceptGroup'][2]['conceptProperties'][0])) {
         foreach ($rxnorm['drugGroup']['conceptGroup'][2]['conceptProperties'] as $item1) {
             $result[$i]['rxcui'] = $item1['rxcui'];
             $result[$i]['name'] = $item1['name'];
             $result[$i]['category'] = 'Brand';
             $i++;
         }
     }
     return $result;
     //$rxcui = $rxnormapi->getRxConceptProperties($rxnorm['drugGroup']['conceptGroup'][2]['conceptProperties'][5]['rxcui']);
     //$rxnorm1 = json_decode($rxnormapi->getRxConceptProperties($rxnorm['idGroup']['rxnormId'][0]), true);
     //$med_rxnorm_code = $rxnorm['idGroup']['rxnormId'][0];
     //$med_name = $rxnorm1['properties']['name'];
     //$rxnorm1 = json_decode($rxnormapi->getRxConceptProperties($rxnorm['drugGroup']['conceptGroup'][2]['conceptProperties'][0]['rxcui']), true);
     //$ndc = json_decode($rxnormapi->getNDCs('823938'), true);
     //return $ndc['ndcGroup']['ndcList']['ndc'][0];
     //}
 }