mirror of
https://gitlab.com/signalytic/client-external/streamline/streamline-emr.git
synced 2026-09-11 10:41:32 +00:00
1239 lines
53 KiB
PHP
Executable File
1239 lines
53 KiB
PHP
Executable File
<?php
|
|
|
|
namespace Modules\Patients\Http\Controllers;
|
|
|
|
use Carbon\Carbon;
|
|
use Illuminate\Http\Request;
|
|
use Streamline\Models\Alert;
|
|
use Streamline\Models\Allergy;
|
|
use Streamline\Models\Clinic;
|
|
use Streamline\Models\Diagnosis;
|
|
use Streamline\Models\DrugCategory;
|
|
use Streamline\Models\FamilyPlanningMethod;
|
|
use Streamline\Models\FamilyRelationship;
|
|
use Streamline\Models\MaritalStatus;
|
|
use Streamline\Models\Observation;
|
|
use Streamline\Models\Occupation;
|
|
use Streamline\Models\PatientCategory;
|
|
use Streamline\Models\SmartTriage;
|
|
use Streamline\Models\Triage;
|
|
use Streamline\Models\TriageNews;
|
|
use Streamline\Models\EmergencySign;
|
|
use Streamline\Models\PrioritySign;
|
|
use Streamline\Models\Patient;
|
|
use Streamline\Models\PatientEpisode;
|
|
use Streamline\Models\Symptom;
|
|
use Illuminate\Support\Facades\Auth;
|
|
use Streamline\Models\ReferralHospital;
|
|
use Illuminate\Support\Facades\Validator;
|
|
use Illuminate\Support\Facades\DB;
|
|
use Illuminate\Support\Facades\Session;
|
|
use Streamline\Models\GenderBasedViolence;
|
|
use Streamline\Models\HivGenderBaseViolence;
|
|
use Illuminate\Database\QueryException;
|
|
|
|
class TriageController extends Controller
|
|
{
|
|
|
|
/**
|
|
* Display a listing of the resource.
|
|
*
|
|
* @return \Illuminate\Http\RedirectResponse
|
|
*/
|
|
public function index()
|
|
{
|
|
$patient_id = session()->get('patient_id');
|
|
$episode_id = session()->get('episode_id');
|
|
|
|
$triage_results = DB::table('triage')
|
|
->where('patient_id', '=', $patient_id)
|
|
->where('episode_id', '=', $episode_id)
|
|
->first();
|
|
|
|
if ($triage_results) {
|
|
//triage already performed
|
|
return redirect('triage/' . $triage_results->id);
|
|
} else {
|
|
//triage not performed
|
|
return redirect("/triage/create");
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Show the form for creating a new resource.
|
|
*
|
|
* @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
|
|
*/
|
|
public function create()
|
|
{
|
|
$patient_id = session()->get('patient_id');
|
|
$episode_id = session()->get('episode_id');
|
|
$patient = Patient::where('id', $patient_id)->first();
|
|
|
|
if (session()->get('triage_without_etat') == 1) {
|
|
$triage_without_etat = true;
|
|
} else {
|
|
$triage_without_etat = false;
|
|
}
|
|
|
|
$clinics = DB::table('clinics')->where('available', 1)->whereNull('deleted_at')->orderBy('name')->pluck("name", "id")->toArray();
|
|
$referral_hospitals = DB::table('referral_hospitals')->whereNull('deleted_at')->orderBy('name')->pluck("name", "id")->toArray();
|
|
$symptoms = DB::table('symptoms')->whereNull('deleted_at')->orderBy('name')->pluck("name", "id")->toArray();
|
|
$family_planning_methods = DB::table('family_planning_methods')->orderBy('name')->pluck("name", "id")->toArray();
|
|
|
|
$clinics = ['' => '- select -'] + $clinics;
|
|
$referral_hospitals = ['' => '- select -'] + $referral_hospitals;
|
|
$symptoms = ['' => '- select -'] + $symptoms;
|
|
$family_planning_methods = ['' => '- select -'] + $family_planning_methods;
|
|
|
|
$symptoms_periods = ['' => '- select -', 'Hours' => 'Hours', 'Days' => 'Days', 'Weeks' => 'Weeks', 'Months' => 'Months', 'Years' => 'Years'];
|
|
|
|
//determine the age group
|
|
$today = date("Y-m-d");
|
|
$dob = isset($patient) ? Carbon::parse($patient->date_of_birth) : null;
|
|
$age_diff_days = isset($patient) ? $dob->diffInDays(Carbon::now()) : null;
|
|
$age_diff_months = isset($patient) ? $age_diff_days / 30.436875 : null;
|
|
$difference = days_months_years($dob, $today);
|
|
|
|
$days = $difference[0];
|
|
$months = $difference[1];
|
|
$years = $difference[2];
|
|
|
|
// create default age group
|
|
$age_group_display = '';
|
|
$age_group = 0;
|
|
$age_group_id = 0;
|
|
|
|
$age_group_records = DB::table('age_groups')->whereNull('deleted_at')->get()->toArray();
|
|
|
|
foreach ($age_group_records as $age_group_record) {
|
|
// turn into days
|
|
if ($age_group_record->age_type == 3) {
|
|
// days
|
|
$first_day = $age_group_record->from_age;
|
|
$last_day = $age_group_record->to_age;
|
|
} elseif ($age_group_record->age_type == 2) {
|
|
// months
|
|
$first_day = $age_group_record->from_age * 30;
|
|
$last_day = $age_group_record->to_age * 30;
|
|
} else {
|
|
// years
|
|
$first_day = $age_group_record->from_age * 365;
|
|
$last_day = $age_group_record->to_age * 365;
|
|
}
|
|
|
|
if (between($age_diff_days, $first_day, $last_day)) {
|
|
$age_group_display = $age_group_record->name;
|
|
$age_group_id = $age_group_record->id;
|
|
break;
|
|
}
|
|
}
|
|
|
|
if (between($days, 0, 28) && between($months, 0, 0) && between($years, 0, 0)) {
|
|
$age_group = 1;
|
|
$default_age_group_display = "0 - 28 Days";
|
|
} elseif (between($days, 0, 31) && between($months, 1, 12) && between($years, 0, 0)) {
|
|
$age_group = 2;
|
|
$default_age_group_display = "1 - 12 Months";
|
|
} elseif (between($days, 0, 31) && between($months, 0, 12) && between($years, 1, 5)) {
|
|
$age_group = 3;
|
|
$default_age_group_display = "1 - 5 Years";
|
|
} elseif (between($days, 0, 31) && between($months, 0, 12) && between($years, 6, 12)) {
|
|
$age_group = 4;
|
|
$default_age_group_display = "6 - 12 Years";
|
|
} elseif (between($days, 0, 31) && between($months, 0, 12) && between($years, 13, 200)) {
|
|
$age_group = 5;
|
|
$default_age_group_display = "> 12 Years";
|
|
}
|
|
|
|
// if none of the age groups has a fit lets use the default
|
|
if ($age_group_display == '') {
|
|
$age_group_display = $default_age_group_display;
|
|
}
|
|
|
|
$observations = DB::table('observations')->whereNull('deleted_at')->whereRaw('FIND_IN_SET(' . $age_group_id . ',age_group)')->get();
|
|
|
|
return view('patients::triage.create', compact('episode_id', 'age_group_display', 'age_group', 'symptoms', 'years', 'patient', 'family_planning_methods', 'referral_hospitals', 'clinics', 'patient_id',
|
|
'episode_id', 'observations', 'symptoms_periods', 'age_diff_months', 'triage_without_etat'));
|
|
}
|
|
|
|
/**
|
|
* Store a newly created resource in storage.
|
|
*
|
|
*/
|
|
public function store(Request $request)
|
|
{
|
|
$validator = Validator::make($request->all(), [
|
|
'triage_grade' => 'required',
|
|
'referral_hospital' => 'required',
|
|
'clinic_allocation' => 'required',
|
|
'patient_id' => 'required',
|
|
'episode_id' => 'required|unique:triage',
|
|
'observationsValues' => ['required_unless:any_tb_sysmptoms, 1'],
|
|
'mother_hiv_positive' => 'boolean',
|
|
'has_been_sick_last_3_months' => ['required_if:mother_hiv_positive,true,boolean'],
|
|
'has_recurring_skin_problem' => ['required_if:mother_hiv_positive,true,boolean'],
|
|
'has_lost_weight_last_3_months' => ['required_if:mother_hiv_positive,true,boolean'],
|
|
'has_had_tb' => ['required_if:mother_hiv_positive,true,boolean'],
|
|
'is_growing_well' => ['required_if:mother_hiv_positive,true,boolean'],
|
|
]);
|
|
|
|
if ($validator->fails()) {
|
|
$string = "";
|
|
foreach ($validator->errors()->getMessages() as $item) {
|
|
$string .= "{$item[0]}<br>";
|
|
}
|
|
flash()->error($string);
|
|
return back()->withErrors($validator)->withInput();
|
|
} else {
|
|
$logged_in_user_id = Auth()->user()->id;
|
|
|
|
$triage = new Triage;
|
|
|
|
$patient_id = $request->patient_id;
|
|
$episode_id = $request->episode_id;
|
|
|
|
// @TODO First check if there is a triage with the same patient and the same episode Alert the user and then not proceed
|
|
$emergency_signs = false;
|
|
|
|
// Receiving the emergency signs from here
|
|
if (isset($request->cyanosis)) :
|
|
$emergency_signs = true;
|
|
|
|
// Airway
|
|
$cyanosis = $request->cyanosis;
|
|
$stridor = $request->stridor;
|
|
$severe_distress = $request->severe_distress;
|
|
|
|
// Circulation
|
|
$refill = $request->refill;
|
|
$severe_bleeding = $request->severe_bleeding;
|
|
$weak_fast_pulse = $request->weak_fast_pulse;
|
|
|
|
// neurological
|
|
$coma = $request->coma;
|
|
$convulsing_now = $request->convulsing_now;
|
|
|
|
// Dehydration
|
|
$lethargy = $request->lethargy;
|
|
|
|
$airway_array = array(
|
|
__('layout.cyanosis') => $cyanosis,
|
|
__('layout.stridor_breathing_choking') => $stridor,
|
|
__('layout.severe_resp_distress') => $severe_distress
|
|
);
|
|
|
|
$circulation_array = array(
|
|
__('layout.capillary_refill_seconds') => $refill,
|
|
__('layout.severe_bleeding') => $severe_bleeding,
|
|
__('layout.weak_fast_pulse') => $weak_fast_pulse
|
|
);
|
|
|
|
$neurological_array = array(
|
|
__('layout.coma') => $coma,
|
|
__('layout.convulsing_now') => $convulsing_now
|
|
);
|
|
|
|
$dehydration_array = array(
|
|
__('layout.diarrhoea_lethargy_sunken_eyes') => $lethargy
|
|
);
|
|
|
|
$airway = serialize($airway_array);
|
|
$circulation = serialize($circulation_array);
|
|
$neurological = serialize($neurological_array);
|
|
$dehydration = serialize($dehydration_array);
|
|
endif;
|
|
|
|
|
|
// Receiving the priority signs
|
|
$priority_signs = array();
|
|
|
|
isset($request->trauma) ? $priority_signs[] = __('layout.significant_trauma') : '';
|
|
isset($request->severe_pain) ? $priority_signs[] = __('layout.severe_pain') : '';
|
|
isset($request->oedema) ? $priority_signs[] = __('layout.oedema_both_feet') : '';
|
|
isset($request->surgical_condition) ? $priority_signs[] = __('layout.urgent_surgical_condition') : '';
|
|
isset($request->continuously_irritable) ? $priority_signs[] = __('layout.restless_irritable') : '';
|
|
isset($request->severe_wasting) ? $priority_signs[] = __('layout.malnutrition_visible_wasting') : '';
|
|
isset($request->severe_pallor) ? $priority_signs[] = __('layout.severe_pallor') : '';
|
|
isset($request->burns) ? $priority_signs[] = __('layout.burns_major') : '';
|
|
$priority_array = serialize($priority_signs);
|
|
|
|
|
|
// Receiving family planning
|
|
$too_sick = $request->too_sick;
|
|
$sexually_active = $request->sexually_active;
|
|
$pregnant = $request->pregnant;
|
|
$menopause = $request->menopause;
|
|
$fp_method = $request->fp_method;
|
|
$fp_action = $request->fp_action;
|
|
|
|
|
|
// Other triage fields
|
|
$new_attendance = !empty($request->new_attendance) ? 1 : 0;
|
|
$re_attendance = !empty($request->re_attendance) ? 1 : 0;
|
|
|
|
$episode_id = $request->episode_id;
|
|
|
|
$triage_grade = $request->triage_grade;
|
|
$comment = $request->comment;
|
|
$referal = $request->referral_hospital;
|
|
$clinic_allocation = $request->clinic_allocation;
|
|
|
|
// Build symptoms and duration variables
|
|
$symptoms_array = $request->symptoms ?? [];
|
|
$duration_array = $request->duration ?? [];
|
|
$time_array = $request->time ?? [];
|
|
$durations_final = [];
|
|
|
|
for ($x = 0; $x < count($symptoms_array); $x++) {
|
|
$durations_final[] = $duration_array[$x] . " " . $time_array[$x];
|
|
}
|
|
|
|
// Build observation variables
|
|
$observationsNames_array = !empty($request->observationsNames)? $request->observationsNames:[];
|
|
$obersavationsValues_array = $request->observationsValues;
|
|
$observations = [];
|
|
|
|
for ($z = 0; $z < count($observationsNames_array); $z++) {
|
|
$observations[] = $observationsNames_array[$z] . '=' . $obersavationsValues_array[$z];
|
|
}
|
|
|
|
$triage->referral = $referal;
|
|
$triage->symptoms = implode(",", $symptoms_array);
|
|
$triage->symptom_duration = implode(",", $durations_final);
|
|
$triage->observations = implode(",", $observations);
|
|
$triage->severe_grade = $triage_grade;
|
|
$triage->comments = $comment;
|
|
$triage->clinic_allocation = $clinic_allocation;
|
|
$triage->patient_id = $patient_id;
|
|
$triage->episode_id = $episode_id;
|
|
$triage->sexually_active = $sexually_active;
|
|
$triage->pregnant = $pregnant;
|
|
$triage->menopause = $menopause;
|
|
$triage->fp_method = $fp_method;
|
|
$triage->fp_action = $fp_action;
|
|
$triage->fp_too_sick = $too_sick;
|
|
$triage->new_attendance = $new_attendance;
|
|
$triage->re_attendance = $re_attendance;
|
|
$triage->any_tb_sysmptoms = $request->any_tb_sysmptoms;
|
|
$triage->cough_for_2_weeks = $request->cough_for_2_weeks;
|
|
$triage->fever_for_2_weeks = $request->fever_for_2_weeks;
|
|
$triage->tb_weight_loss = $request->tb_weight_loss;
|
|
$triage->tb_excessive_night_sweats = $request->tb_excessive_night_sweats;
|
|
$triage->tb_poor_weight_gain = $request->tb_poor_weight_gain;
|
|
$triage->tb_contact_with_tb_person = $request->tb_contact_with_tb_person;
|
|
$triage->blood_group = $request->blood_group ?? NULL;
|
|
$triage->rhesus_factor = $request->rhesus_factor ?? NULL;
|
|
$triage->observation_notes = $request->observation_notes ?? NULL;
|
|
$triage->nursing_notes = $request->nursing_notes ?? NULL;
|
|
$triage->created_by = $logged_in_user_id;
|
|
|
|
// begin saving for discharge mortality risk
|
|
$discharge_mortality = DB::table('discharge_mortality_risk')->where('patient_id', $patient_id)
|
|
->where('episode_id', $episode_id)
|
|
->first();
|
|
|
|
if(!empty($observationsNames_array)) $observation_array = array_combine($observationsNames_array, $obersavationsValues_array);
|
|
|
|
if ($discharge_mortality && is_smart_discharge_enabled()) {
|
|
if (isset($request->bcs_eye_movement) && isset($request->bcs_best_mortal) && isset($request->bcs_best_verbal)) {
|
|
$total = $request->bcs_eye_movement + $request->bcs_best_mortal + $request->bcs_best_verbal;
|
|
|
|
|
|
if ($total == 5) {
|
|
$bcs = 0;
|
|
} else {
|
|
$bcs = 1;
|
|
}
|
|
} else {
|
|
$bcs = null;
|
|
}
|
|
|
|
if (isset($request->maternal_hiv)) {
|
|
if ($request->maternal_hiv == 1) {
|
|
$hiv_mom_positive = 0;
|
|
$hiv_mom_unknown = 0;
|
|
} else if ($request->maternal_hiv == 2) {
|
|
$hiv_mom_positive = 1;
|
|
$hiv_mom_unknown = 0;
|
|
} else if ($request->maternal_hiv == 3) {
|
|
$hiv_mom_positive = 0;
|
|
$hiv_mom_unknown = 1;
|
|
} else {
|
|
$hiv_mom_positive = 0;
|
|
$hiv_mom_unknown = 0;
|
|
}
|
|
} else {
|
|
$hiv_mom_positive = null;
|
|
$hiv_mom_unknown = null;
|
|
}
|
|
|
|
DB::table('discharge_mortality_risk')
|
|
->where('id', $discharge_mortality->id)
|
|
->update([
|
|
'weight' => $observation_array["Weight"] ?? null,
|
|
'muac_below_6' => isset($observation_array["MUAC"]) ? ($observation_array["MUAC"] * 10) : null,
|
|
'bmi_below_6' => $observation_array["BMI"] ?? null,
|
|
'hospital_travel_duration_below_6' => $request->hospital_travel_duration ?? null,
|
|
'illness_duration_at_admission_below_6' => $request->illness_duration ?? null,
|
|
'tone_normal_6mo' => $request->tone_normal_6mo ?? null,
|
|
'last_hospitalization' => $request->last_hospitalization ?? null,
|
|
'water_source' => $request->water_source ?? null,
|
|
'filter_water' => $request->safe_water ?? null,
|
|
'child_mosquito_net' => $request->child_mosquito_net ?? null,
|
|
'mother_education_level' => $request->mother_education_level ?? null,
|
|
'hospital_travel_duration' => $request->hospital_travel_duration ?? null,
|
|
'muac' => isset($observation_array["MUAC"]) ? ($observation_array["MUAC"] * 10) : null,
|
|
'temperature' => $observation_array["Temperature"] ?? null,
|
|
'oxy_saturation' => $observation_array["SaO2"] ?? null,
|
|
'bcs' => $bcs,
|
|
'bcs_eye_movement' => $request->bcs_eye_movement ?? null,
|
|
'bcs_best_mortal' => $request->bcs_best_mortal ?? null,
|
|
'bcs_best_verbal' => $request->bcs_best_verbal ?? null,
|
|
'maternal_hiv' => $request->maternal_hiv ?? null,
|
|
'hiv_mom_positive' => $hiv_mom_positive,
|
|
'hiv_mom_unknown' => $hiv_mom_unknown,
|
|
'maternal_age' => $request->maternal_age ?? null,
|
|
'child_hiv' => $request->child_hiv ?? null,
|
|
'child_with_proven_infection' => $request->child_with_proven_infection ?? null,
|
|
]);
|
|
}
|
|
// end discharge mortality risk save
|
|
|
|
try {
|
|
if ($triage->save()) {
|
|
|
|
// Get the previous inserted id of the triage
|
|
$new_triage_id = $triage->id;
|
|
|
|
// Inserting National Early Warning Score
|
|
if (isset($request->adult)) {
|
|
$triage_news = new TriageNews;
|
|
$triage_news->triage_id = $new_triage_id;
|
|
$triage_news->episode_id = $episode_id;
|
|
$triage_news->patient_id = $patient_id;
|
|
$triage_news->temperature = isset($request->tempNews) ? $request->tempNews : null;
|
|
$triage_news->heart_rate = isset($request->pulseNews) ? $request->pulseNews : null;
|
|
$triage_news->respiration_rate = isset($request->respNews) ? $request->respNews : null;
|
|
$triage_news->oxygen_saturations = isset($request->saNews) ? $request->saNews : null;
|
|
$triage_news->systolic_bp = isset($request->sysNews) ? $request->sysNews : null;
|
|
$triage_news->conscious_level = isset($request->conNews) ? $request->conNews : null;
|
|
$triage_news->supplementary_oxygen = isset($request->suOxNews) ? $request->suOxNews : null;
|
|
$triage_news->created_by = $logged_in_user_id;
|
|
$triage_news->save();
|
|
}
|
|
|
|
// Inserting the emergency signs
|
|
if ($emergency_signs) :
|
|
$emergency_sign = new EmergencySign;
|
|
|
|
$emergency_sign->airway = $airway;
|
|
$emergency_sign->circulation = $circulation;
|
|
$emergency_sign->neurological = $neurological;
|
|
$emergency_sign->dehydration = $dehydration;
|
|
$emergency_sign->patient_id = $patient_id;
|
|
$emergency_sign->triage_id = $new_triage_id;
|
|
$emergency_sign->episode_id = $episode_id;
|
|
$emergency_sign->created_by = $logged_in_user_id;
|
|
$emergency_sign->save();
|
|
endif;
|
|
|
|
// Inserting the priority signs
|
|
if ($priority_signs != "") :
|
|
$priority_sign = new PrioritySign;
|
|
$priority_sign->signs = $priority_array;
|
|
$priority_sign->triage_id = $new_triage_id;
|
|
$priority_sign->patient_id = $patient_id;
|
|
$priority_sign->episode_id = $episode_id;
|
|
$priority_sign->created_by = $logged_in_user_id;
|
|
$priority_sign->save();
|
|
endif;
|
|
|
|
// Updating the patient episode table with the triage details
|
|
$episode_update = PatientEpisode::find($episode_id);
|
|
$episode_update->triage_id = $new_triage_id;
|
|
$episode_update->clinic_id = $clinic_allocation;
|
|
$episode_update->updated_by = $logged_in_user_id;
|
|
$episode_update->save();
|
|
|
|
flash("Triage has been saved")->success();
|
|
|
|
$clinic_slug = get_name($clinic_allocation, "id", "slug", "clinics");
|
|
|
|
if ($clinic_slug == "art") {
|
|
return redirect()->route('triage.show', $new_triage_id)->with('alert-info', 'Recommended to be transmitted to the ART clinic.');
|
|
//- return redirect("hiv_menu");
|
|
}
|
|
}
|
|
|
|
|
|
|
|
return redirect("/patient_episodes");
|
|
} catch (QueryException $e) {
|
|
flash("An error occurred")->error();
|
|
return back()->withInput();
|
|
}
|
|
}
|
|
}
|
|
|
|
public function show($id)
|
|
{
|
|
$airway = [];
|
|
$circulation = [];
|
|
$neurological = [];
|
|
$dehydration = [];
|
|
$priority_signs = [];
|
|
$triage = Triage::where('id', $id)->first();
|
|
$patient_episode = PatientEpisode::where('triage_id', $id)->first();
|
|
$patient_id = DB::table('triage')->where('id', $id)->value('patient_id');
|
|
$episode_id = DB::table('patient_episodes')->where('triage_id', $id)->value('id');
|
|
$patient = Patient::find($patient_id);
|
|
if (is_null($patient)) {
|
|
flash("This patient was deleted from the system")->error();
|
|
return redirect()->back();
|
|
}
|
|
$today = date("Y-m-d");
|
|
$difference = days_months_years($patient->date_of_birth, $today);
|
|
$years = $difference[2];
|
|
$clinics = DB::table('clinics')->pluck("name", "id");
|
|
$referral_hospitals = DB::table('referral_hospitals')->pluck('name', 'id');
|
|
$symptoms = DB::table('symptoms')->where('available', 1)->pluck('name', 'id');
|
|
$categories = DB::table('patient_categories')->where('available', 1)->pluck("name", "id");
|
|
$family_planning_methods = DB::table('family_planning_methods')->pluck("name", "id");
|
|
|
|
if (between($years, 0, 12)) {
|
|
$emergency_signs = EmergencySign::where('triage_id', $id)->first();
|
|
|
|
if ($emergency_signs) {
|
|
$airway = unserialize($emergency_signs->airway);
|
|
$circulation = unserialize($emergency_signs->circulation);
|
|
$neurological = unserialize($emergency_signs->neurological);
|
|
$dehydration = unserialize($emergency_signs->dehydration);
|
|
}
|
|
}
|
|
|
|
if (between($years, 0, 12)) {
|
|
$priority_signs_records = PrioritySign::where('triage_id', $id)->first();
|
|
|
|
if ($priority_signs_records) {
|
|
$priority_signs = unserialize($priority_signs_records->signs);
|
|
}
|
|
}
|
|
|
|
// fetch any discharge mortality info
|
|
$discharge_mortality = DB::table('discharge_mortality_risk')->where('patient_id', $patient_id)
|
|
->where('episode_id', $episode_id)
|
|
->first();
|
|
|
|
$nutrition = DB::table('triage_nutrition')->where('patient_id', $patient_id)
|
|
->where('episode_id', $episode_id)
|
|
->first();
|
|
|
|
if (session()->get('triage_without_etat') == 1) {
|
|
$triage_without_etat = true;
|
|
} else {
|
|
$triage_without_etat = false;
|
|
}
|
|
|
|
$age_diff_months = Carbon::parse($patient->date_of_birth)->diffInMonths(Carbon::now());
|
|
$triage_hiv = HivGenderBaseViolence::where('triage_id', $triage->id)->first();
|
|
|
|
return view('patients::triage.show', compact('triage', 'patient_episode', 'patient', 'clinics', 'referral_hospitals', 'symptoms', 'categories', 'family_planning_methods', 'triage_hiv',
|
|
'episode_id', 'years', 'airway', 'circulation', 'neurological', 'dehydration', 'discharge_mortality', 'age_diff_months', 'priority_signs', 'nutrition', 'triage_without_etat'));
|
|
}
|
|
|
|
/**
|
|
* Show the form for editing the specified resource.
|
|
*
|
|
* @param int $id
|
|
* @return \Illuminate\Contracts\View\Factory|\Illuminate\Foundation\Application|\Illuminate\View\View
|
|
*/
|
|
public function edit($id)
|
|
{
|
|
$patient_id = session()->get('patient_id');
|
|
$episode_id = session()->get('episode_id');
|
|
$patient = Patient::where('id', $patient_id)->first();
|
|
|
|
$clinics = DB::table('clinics')->where('available', 1)->whereNull('deleted_at')->orderBy('name')->pluck("name", "id")->toArray();
|
|
$referral_hospitals = DB::table('referral_hospitals')->whereNull('deleted_at')->orderBy('name')->pluck("name", "id")->toArray();
|
|
$symptoms = DB::table('symptoms')->whereNull('deleted_at')->orderBy('name')->pluck("name", "id")->toArray();
|
|
$family_planning_methods = DB::table('family_planning_methods')->orderBy('name')->pluck("name", "id")->toArray();
|
|
|
|
$clinics = ['' => '- select -'] + $clinics;
|
|
$referral_hospitals = ['' => '- select -'] + $referral_hospitals;
|
|
$symptoms = ['' => '- select -'] + $symptoms;
|
|
$family_planning_methods = ['' => '- select -'] + $family_planning_methods;
|
|
|
|
$symptoms_periods = ['' => '- select -', 'Hours' => 'Hours', 'Days' => 'Days', 'Weeks' => 'Weeks', 'Months' => 'Months', 'Years' => 'Years'];
|
|
|
|
//determine the age group
|
|
$today = date("Y-m-d");
|
|
$dob = Carbon::parse($patient->date_of_birth);
|
|
$age_diff_days = $dob->diffInDays(Carbon::now());
|
|
|
|
$difference = days_months_years($dob, $today);
|
|
|
|
$days = $difference[0];
|
|
$months = $difference[1];
|
|
$years = $difference[2];
|
|
|
|
$age_group_display = '';
|
|
$age_group = 0;
|
|
$age_group_id = 0;
|
|
|
|
$age_group_records = DB::table('age_groups')->whereNull('deleted_at')->get()->toArray();
|
|
|
|
foreach ($age_group_records as $age_group_record) {
|
|
// turn into days
|
|
if ($age_group_record->age_type == 3) {
|
|
// days
|
|
$first_day = $age_group_record->from_age;
|
|
$last_day = $age_group_record->to_age;
|
|
} elseif ($age_group_record->age_type == 2) {
|
|
// months
|
|
$first_day = $age_group_record->from_age * 30;
|
|
$last_day = $age_group_record->to_age * 30;
|
|
} else {
|
|
// years
|
|
$first_day = $age_group_record->from_age * 365;
|
|
$last_day = $age_group_record->to_age * 365;
|
|
}
|
|
|
|
if (between($age_diff_days, $first_day, $last_day)) {
|
|
$age_group_display = $age_group_record->name;
|
|
$age_group_id = $age_group_record->id;
|
|
break;
|
|
}
|
|
}
|
|
|
|
if (between($days, 0, 28) && between($months, 0, 0) && between($years, 0, 0)) {
|
|
$age_group = 1;
|
|
$default_age_group_display = "0 - 28 Days";
|
|
} elseif (between($days, 0, 31) && between($months, 1, 12) && between($years, 0, 0)) {
|
|
$age_group = 2;
|
|
$default_age_group_display = "1 - 12 Months";
|
|
} elseif (between($days, 0, 31) && between($months, 0, 12) && between($years, 1, 5)) {
|
|
$age_group = 3;
|
|
$default_age_group_display = "1 - 5 Years";
|
|
} elseif (between($days, 0, 31) && between($months, 0, 12) && between($years, 6, 12)) {
|
|
$age_group = 4;
|
|
$default_age_group_display = "6 - 12 Years";
|
|
} elseif (between($days, 0, 31) && between($months, 0, 12) && between($years, 13, 200)) {
|
|
$age_group = 5;
|
|
$default_age_group_display = "> 12 Years";
|
|
}
|
|
|
|
// if none of the age groups has a fit lets use the default
|
|
if ($age_group_display == '') {
|
|
$age_group_display = $default_age_group_display;
|
|
}
|
|
|
|
$observations = DB::table('observations')->whereNull('deleted_at')->whereRaw('FIND_IN_SET(' . $age_group_id . ',age_group)')->get();
|
|
|
|
$triage = Triage::find($id);
|
|
|
|
$emergency_signs = EmergencySign::where('triage_id', $id)->first();
|
|
|
|
if (!empty($emergency_signs)) {
|
|
$airway = unserialize($emergency_signs->airway);
|
|
$circulation = unserialize($emergency_signs->circulation);
|
|
$neurological = unserialize($emergency_signs->neurological);
|
|
$dehydration = unserialize($emergency_signs->dehydration);
|
|
} else {
|
|
$airway = [];
|
|
$circulation = [];
|
|
$neurological = [];
|
|
$dehydration = [];
|
|
}
|
|
|
|
$observations_to_edit_temp = explode(",", $triage->observations);
|
|
$observations_to_edit = [];
|
|
|
|
foreach ($observations_to_edit_temp as $value) {
|
|
$temp_array = explode("=", $value);
|
|
|
|
$observations_to_edit[$temp_array[0]] = $temp_array[1]?? null;
|
|
}
|
|
|
|
$priority_signs = PrioritySign::where('triage_id', $id)->first();
|
|
$priority_signs = $priority_signs ? unserialize($priority_signs->signs) : [];
|
|
|
|
$dob = Carbon::parse($patient->date_of_birth);
|
|
|
|
$age_diff_months = $dob->diffInMonths(Carbon::now());
|
|
$triage_hiv = HivGenderBaseViolence::where('triage_id', $triage->id)->first();
|
|
|
|
return view('patients::triage.edit', compact(
|
|
'episode_id',
|
|
'age_group_display',
|
|
'age_group',
|
|
'symptoms',
|
|
'years',
|
|
'patient',
|
|
'family_planning_methods',
|
|
'referral_hospitals',
|
|
'clinics',
|
|
'patient_id',
|
|
'episode_id',
|
|
'observations',
|
|
'triage',
|
|
'airway',
|
|
'circulation',
|
|
'neurological',
|
|
'dehydration',
|
|
'observations_to_edit',
|
|
'priority_signs',
|
|
'symptoms_periods',
|
|
'age_diff_months',
|
|
'triage_hiv',
|
|
));
|
|
}
|
|
|
|
/**
|
|
* Update the specified resource in storage.
|
|
*
|
|
* @param \Illuminate\Http\Request $request
|
|
* @param int $id
|
|
* @return \Illuminate\Http\RedirectResponse
|
|
*/
|
|
public function update(Request $request, $id)
|
|
{
|
|
$validator = Validator::make($request->all(), [
|
|
'triage_grade' => 'required',
|
|
'referral_hospital' => 'required',
|
|
'clinic_allocation' => 'required',
|
|
'observationsValues' => 'required'
|
|
]);
|
|
|
|
if ($validator->fails()) {
|
|
$string = "";
|
|
foreach ($validator->errors()->getMessages() as $item) {
|
|
$string .= "{$item[0]}<br>";
|
|
}
|
|
flash()->error($string);
|
|
return back()->withErrors($validator)->withInput();
|
|
} else {
|
|
$logged_in_user_id = Auth()->user()->id;
|
|
$triage = Triage::find($id);
|
|
|
|
$emergency_signs = false;
|
|
|
|
// Receiving the emergency signs from here
|
|
if (isset($request->cyanosis)) :
|
|
$emergency_signs = true;
|
|
|
|
// Airway
|
|
$cyanosis = $request->cyanosis;
|
|
$stridor = $request->stridor;
|
|
$severe_distress = $request->severe_distress;
|
|
|
|
// Circulation
|
|
$refill = $request->refill;
|
|
$severe_bleeding = $request->severe_bleeding;
|
|
$weak_fast_pulse = $request->weak_fast_pulse;
|
|
|
|
// neurological
|
|
$coma = $request->coma;
|
|
$convulsing_now = $request->convulsing_now;
|
|
|
|
// Dehydration
|
|
$lethargy = $request->lethargy;
|
|
|
|
$airway_array = array(
|
|
'Cyanosis' => $cyanosis,
|
|
'Stridor / obstructed breathing/ choking' => $stridor,
|
|
'Severe respiratory distress' => $severe_distress
|
|
);
|
|
|
|
$circulation_array = array(
|
|
'Capillary refill > 3 seconds' => $refill,
|
|
'Severe bleeding' => $severe_bleeding,
|
|
'Weak fast pulse' => $weak_fast_pulse
|
|
);
|
|
|
|
$neurological_array = array(
|
|
'Coma' => $coma,
|
|
'Convulsing Now' => $convulsing_now
|
|
);
|
|
|
|
$dehydration_array = array(
|
|
'Diarrhoea with Lethargy, sunken eyes or very slow skin pinch' => $lethargy
|
|
);
|
|
|
|
$airway = serialize($airway_array);
|
|
$circulation = serialize($circulation_array);
|
|
$neurological = serialize($neurological_array);
|
|
$dehydration = serialize($dehydration_array);
|
|
endif;
|
|
|
|
// Receiving the priority signs
|
|
$priority_signs = array();
|
|
|
|
isset($request->trauma) ? $priority_signs[] = 'Significant trauma' : '';
|
|
isset($request->severe_pain) ? $priority_signs[] = 'severe_pain' : '';
|
|
isset($request->oedema) ? $priority_signs[] = 'Oedema of both feet' : '';
|
|
isset($request->surgical_condition) ? $priority_signs[] = 'Urgent surgical condition' : '';
|
|
isset($request->continuously_irritable) ? $priority_signs[] = 'Restless continuously irritable, lethargic' : '';
|
|
isset($request->severe_wasting) ? $priority_signs[] = 'Malnutrution: visible severe wasting' : '';
|
|
isset($request->severe_pallor) ? $priority_signs[] = 'Severe pallor' : '';
|
|
isset($request->burns) ? $priority_signs[] = 'Burns (Major)' : '';
|
|
$priority_array = serialize($priority_signs);
|
|
|
|
|
|
// Receiving family planning
|
|
$too_sick = $request->too_sick;
|
|
$sexually_active = $request->sexually_active;
|
|
$pregnant = $request->pregnant;
|
|
$menopause = $request->menopause;
|
|
$fp_method = $request->fp_method;
|
|
$fp_action = $request->fp_action;
|
|
|
|
|
|
// Other triage fields
|
|
$new_attendance = !empty($request->new_attendance) ? 1 : 0;
|
|
$re_attendance = !empty($request->re_attendance) ? 1 : 0;
|
|
|
|
$episode_id = $request->episode_id;
|
|
|
|
$triage_grade = $request->triage_grade;
|
|
$comment = $request->comment;
|
|
$referal = $request->referral_hospital;
|
|
$clinic_allocation = $request->clinic_allocation;
|
|
|
|
|
|
// Build symptoms and duration variables
|
|
$symptoms_array = $request->symptoms ?? [];
|
|
$duration_array = $request->duration ?? [];
|
|
$time_array = $request->time ?? [];
|
|
$durations_final = [];
|
|
|
|
for ($x = 0; $x < count($symptoms_array); $x++) {
|
|
$durations_final[] = $duration_array[$x] . " " . $time_array[$x];
|
|
}
|
|
|
|
// Build observation variables
|
|
$observationsNames_array = $request->observationsNames;
|
|
$obersavationsValues_array = $request->observationsValues;
|
|
$observations = [];
|
|
|
|
for ($z = 0; $z < count($observationsNames_array); $z++) {
|
|
$observations[] = $observationsNames_array[$z] . '=' . $obersavationsValues_array[$z];
|
|
}
|
|
|
|
$triage->referral = $referal;
|
|
$triage->symptoms = implode(",", $symptoms_array);
|
|
$triage->symptom_duration = implode(",", $durations_final);
|
|
$triage->observations = implode(",", $observations);
|
|
$triage->severe_grade = $triage_grade;
|
|
$triage->comments = $comment;
|
|
$triage->clinic_allocation = $clinic_allocation;
|
|
$triage->sexually_active = $sexually_active;
|
|
$triage->pregnant = $pregnant;
|
|
$triage->menopause = $menopause;
|
|
$triage->fp_method = $fp_method;
|
|
$triage->fp_action = $fp_action;
|
|
$triage->fp_too_sick = $too_sick;
|
|
$triage->new_attendance = $new_attendance;
|
|
$triage->re_attendance = $re_attendance;
|
|
$triage->updated_by = $logged_in_user_id;
|
|
|
|
if ($triage->save()) {
|
|
|
|
// Inserting National Early Warning Score
|
|
if (isset($request->adult)) {
|
|
$triage_news = TriageNews::where('triage_id', $id)->first();
|
|
$triage_news->temperature = isset($request->tempNews) ? $request->tempNews : null;
|
|
$triage_news->heart_rate = isset($request->pulseNews) ? $request->pulseNews : null;
|
|
$triage_news->respiration_rate = isset($request->respNews) ? $request->respNews : null;
|
|
$triage_news->oxygen_saturations = isset($request->saNews) ? $request->saNews : null;
|
|
$triage_news->systolic_bp = isset($request->sysNews) ? $request->sysNews : null;
|
|
$triage_news->conscious_level = isset($request->conNews) ? $request->conNews : null;
|
|
$triage_news->supplementary_oxygen = isset($request->suOxNews) ? $request->suOxNews : null;
|
|
$triage_news->updated_by = $logged_in_user_id;
|
|
$triage_news->save();
|
|
}
|
|
|
|
// Inserting the emergency signs
|
|
if ($emergency_signs) :
|
|
$emergency_sign = EmergencySign::where('triage_id', $id)->first();
|
|
|
|
if(!empty($emergency_sign)){
|
|
$emergency_sign->airway = $airway;
|
|
$emergency_sign->circulation = $circulation;
|
|
$emergency_sign->neurological = $neurological;
|
|
$emergency_sign->dehydration = $dehydration;
|
|
$emergency_sign->updated_by = $logged_in_user_id;
|
|
$emergency_sign->save();
|
|
}else {
|
|
$emergency_sign = new EmergencySign;
|
|
$emergency_sign->patient_id = $triage->patient_id;
|
|
$emergency_sign->triage_id = $id;
|
|
$emergency_sign->episode_id = $triage->episode_id;
|
|
$emergency_sign->airway = $airway;
|
|
$emergency_sign->circulation = $circulation;
|
|
$emergency_sign->neurological = $neurological;
|
|
$emergency_sign->dehydration = $dehydration;
|
|
$emergency_sign->created_by = $logged_in_user_id;
|
|
$emergency_sign->save();
|
|
}
|
|
endif;
|
|
|
|
// Inserting the priority signs
|
|
if ($priority_signs != "") :
|
|
$priority_sign = PrioritySign::where('triage_id', $id)->first();
|
|
$priority_sign->signs = $priority_array;
|
|
$priority_sign->updated_by = $logged_in_user_id;
|
|
$priority_sign->save();
|
|
endif;
|
|
|
|
// Updating the patient episode table with the triage details
|
|
$episode_update = PatientEpisode::find($episode_id);
|
|
$episode_update->clinic_id = $clinic_allocation;
|
|
$episode_update->updated_by = $logged_in_user_id;
|
|
$episode_update->save();
|
|
|
|
flash("Triage has been updated")->success();
|
|
|
|
$clinic_slug = get_name($clinic_allocation, "id", "slug", "clinics");
|
|
if ($clinic_slug == "art") {
|
|
return redirect()->route('triage.show', $triage->id)->with('alert-info', 'Recommended to be transmitted to the ART clinic.');
|
|
//- return redirect("hiv_menu");
|
|
}
|
|
}
|
|
|
|
return redirect("/patient_episodes");
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Remove the specified resource from storage.
|
|
*
|
|
* @param int $id
|
|
* @return \Illuminate\Http\Response
|
|
*/
|
|
public function destroy($id)
|
|
{
|
|
//
|
|
}
|
|
|
|
public function add_symptom(Request $request)
|
|
{
|
|
|
|
$logged_in_user_id = Auth()->user()->id;
|
|
$symptom = new Symptom;
|
|
$symptom->name = $request->symptom_name;
|
|
$symptom->created_by = $logged_in_user_id;
|
|
if ($symptom->save()) {
|
|
//insert successful
|
|
return 1;
|
|
} else {
|
|
return 0;
|
|
}
|
|
}
|
|
|
|
public function add_referral(Request $request)
|
|
{
|
|
|
|
$logged_in_user_id = Auth()->user()->id;
|
|
$referral_hospital = new ReferralHospital;
|
|
$referral_hospital->name = $request->name;
|
|
$referral_hospital->created_by = $logged_in_user_id;
|
|
$referral_hospital->updated_by = $logged_in_user_id;
|
|
|
|
if ($referral_hospital->save()) {
|
|
//insert successful
|
|
return $referral_hospital->id;
|
|
} else {
|
|
return 0;
|
|
}
|
|
}
|
|
|
|
public function get_prompt(Request $request)
|
|
{
|
|
|
|
$result = DB::table('symptoms')->where('id', $request->symptom_id)->first();
|
|
|
|
if (!empty($result->prompts)) {
|
|
$prompt = $result->prompts;
|
|
} else {
|
|
$prompt = "No prompt available";
|
|
}
|
|
|
|
if (!empty($result->reference_link) && !empty($result->reference_link) && $result->reference_link != "-") {
|
|
//some links just have "-"
|
|
$ref_text = '<a style="color: blue;" href="' . $result->reference_link . '" target="_blank">' . $result->reference_text . '</a>';
|
|
} else {
|
|
$ref_text = "No reference link available";
|
|
}
|
|
|
|
return $prompt . "&&&&" . $ref_text;
|
|
}
|
|
|
|
public function save_smart_triage_score(Request $request) {
|
|
$smart_triage = SmartTriage::where('episode_id', $request->episode_id)->first();
|
|
|
|
if ($smart_triage) {
|
|
$smart_triage->age = $request->age;
|
|
$smart_triage->pulse_rate = $request->pulse_rate;
|
|
$smart_triage->temperature = $request->temperature;
|
|
$smart_triage->muac = $request->muac;
|
|
$smart_triage->transformed_oxygen_saturation = $request->transformed_oxygen_saturation;
|
|
$smart_triage->oxygen_saturation = $request->oxygen_saturation;
|
|
$smart_triage->parent_concern = $request->parent_concern;
|
|
$smart_triage->respiratory_distress = $request->respiratory_distress;
|
|
$smart_triage->oedema = $request->oedema;
|
|
$smart_triage->pallor = $request->pallor;
|
|
$smart_triage->respirations_rate = $request->respirations_rate;
|
|
$smart_triage->burns = $request->burns;
|
|
$smart_triage->severe_pain = $request->severe_pain;
|
|
$smart_triage->trauma = $request->trauma;
|
|
$smart_triage->continously_irritable = $request->continously_irritable;
|
|
$smart_triage->lethargy = $request->lethargy;
|
|
$smart_triage->convulsing = $request->convulsing;
|
|
$smart_triage->coma = $request->coma;
|
|
$smart_triage->weak_fast_pulse = $request->weak_fast_pulse;
|
|
$smart_triage->refill = $request->refill;
|
|
$smart_triage->stridor = $request->stridor;
|
|
$smart_triage->cyanosis = $request->cyanosis;
|
|
$smart_triage->linear_predictor = $request->linear_predictor;
|
|
$smart_triage->risk_score = $request->risk_score;
|
|
$smart_triage->auto_triage_grade = $request->triage_grade;
|
|
$smart_triage->selected_triage_grade = $request->selected_triage_grade;
|
|
|
|
$smart_triage->save();
|
|
} else {
|
|
$smart_triage = new SmartTriage();
|
|
$smart_triage->patient_id = $request->patient_id;
|
|
$smart_triage->episode_id = $request->episode_id;
|
|
$smart_triage->age = $request->age;
|
|
$smart_triage->pulse_rate = $request->pulse_rate;
|
|
$smart_triage->temperature = $request->temperature;
|
|
$smart_triage->muac = $request->muac;
|
|
$smart_triage->transformed_oxygen_saturation = $request->transformed_oxygen_saturation;
|
|
$smart_triage->oxygen_saturation = $request->oxygen_saturation;
|
|
$smart_triage->parent_concern = $request->parent_concern;
|
|
$smart_triage->respiratory_distress = $request->respiratory_distress;
|
|
$smart_triage->oedema = $request->oedema;
|
|
$smart_triage->pallor = $request->pallor;
|
|
$smart_triage->respirations_rate = $request->respirations_rate;
|
|
$smart_triage->burns = $request->burns;
|
|
$smart_triage->severe_pain = $request->severe_pain;
|
|
$smart_triage->trauma = $request->trauma;
|
|
$smart_triage->continously_irritable = $request->continously_irritable;
|
|
$smart_triage->lethargy = $request->lethargy;
|
|
$smart_triage->convulsing = $request->convulsing;
|
|
$smart_triage->coma = $request->coma;
|
|
$smart_triage->weak_fast_pulse = $request->weak_fast_pulse;
|
|
$smart_triage->refill = $request->refill;
|
|
$smart_triage->stridor = $request->stridor;
|
|
$smart_triage->cyanosis = $request->cyanosis;
|
|
$smart_triage->linear_predictor = $request->linear_predictor;
|
|
$smart_triage->risk_score = $request->risk_score;
|
|
$smart_triage->auto_triage_grade = $request->triage_grade;
|
|
$smart_triage->selected_triage_grade = $request->selected_triage_grade;
|
|
|
|
$smart_triage->save();
|
|
}
|
|
|
|
return 1;
|
|
}
|
|
|
|
public function smart_triage_report(Request $request)
|
|
{
|
|
if (isset($request->start_date) && isset($request->end_date)) {
|
|
$start_date = Carbon::parse($request->start_date)->startOfDay()->toDateTimeString();
|
|
$end_date = Carbon::parse($request->end_date)->endOfDay()->toDateTimeString();
|
|
} else {
|
|
$start_date = Carbon::today()->startOfDay()->toDateTimeString();
|
|
$end_date = Carbon::today()->endOfDay()->toDateTimeString();
|
|
}
|
|
|
|
$records = DB::table('smart_triage')
|
|
->whereBetween('smart_triage.created_at', [$start_date, $end_date])
|
|
->leftJoin('patients', 'smart_triage.patient_id', '=', 'patients.id')
|
|
->select('smart_triage.*', 'patients.number as patients_number', 'patients.first_name', 'patients.last_name', 'patients.date_of_birth')
|
|
->limit(300)->get();
|
|
|
|
return view('patients::triage.smart_triage_report', compact('records', 'start_date', 'end_date'));
|
|
}
|
|
|
|
public function edit_for_post_discharge($episode_id)
|
|
{
|
|
$triage = DB::table('triage')->where('episode_id', $episode_id)->first();
|
|
|
|
$temperature = "";
|
|
$oxy_sat = "";
|
|
$muac = "";
|
|
$height = "";
|
|
$weight = "";
|
|
$bmi = "";
|
|
|
|
if ($triage) {
|
|
$old_observations = explode(",", $triage->observations);
|
|
|
|
foreach ($old_observations as $value) {
|
|
$split_values = explode("=", $value);
|
|
|
|
switch ($split_values[0]) {
|
|
case "Temperature":
|
|
$temperature = $split_values[1];
|
|
break;
|
|
case "SaO2":
|
|
$oxy_sat = $split_values[1];
|
|
break;
|
|
case "MUAC":
|
|
$muac = $split_values[1];
|
|
break;
|
|
case "Height":
|
|
$height = $split_values[1];
|
|
break;
|
|
case "Weight":
|
|
$weight = $split_values[1];
|
|
break;
|
|
case "BMI":
|
|
$bmi = $split_values[1];
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
|
|
$patient_episode = PatientEpisode::where('id', $episode_id)->first();
|
|
$patient_id = $patient_episode->patient_id;
|
|
|
|
$patient = Patient::find($patient_id);
|
|
|
|
$dob = Carbon::parse($patient->date_of_birth);
|
|
$age_diff_months = $dob->diffInMonths(Carbon::now());
|
|
|
|
$today = date("Y-m-d");
|
|
|
|
$difference = days_months_years($dob, $today);
|
|
$days = $difference[0];
|
|
$months = $difference[1];
|
|
$years = $difference[2];
|
|
|
|
// create default age group
|
|
$age_group_display = '';
|
|
$age_group = 0;
|
|
|
|
if (between($days, 0, 28) && between($months, 0, 0) && between($years, 0, 0)) :
|
|
$age_group_display = "0 - 28 Days";
|
|
$age_group = 1;
|
|
elseif (between($days, 0, 31) && between($months, 1, 12) && between($years, 0, 0)) :
|
|
$age_group_display = "1 - 12 Months";
|
|
$age_group = 2;
|
|
elseif (between($days, 0, 31) && between($months, 0, 12) && between($years, 1, 5)) :
|
|
$age_group_display = "1 - 5 Years";
|
|
$age_group = 3;
|
|
elseif (between($days, 0, 31) && between($months, 0, 12) && between($years, 6, 12)) :
|
|
$age_group_display = "6 - 12 Years";
|
|
$age_group = 4;
|
|
elseif (between($days, 0, 31) && between($months, 0, 12) && between($years, 13, 200)) :
|
|
$age_group_display = "> 12 Years";
|
|
$age_group = 5;
|
|
endif;
|
|
|
|
$categories = DB::table('patient_categories')->where('available', 1)->pluck("name", "id");
|
|
|
|
// fetch any discharge mortality info
|
|
$discharge_mortality = DB::table('discharge_mortality_risk')->where('patient_id', $patient_id)
|
|
->where('episode_id', $episode_id)
|
|
->first();
|
|
|
|
return view('patients::triage.edit_for_post_discharge', compact(
|
|
'triage',
|
|
'patient_episode',
|
|
'patient',
|
|
'categories',
|
|
'muac',
|
|
'oxy_sat',
|
|
'episode_id',
|
|
'years',
|
|
'age_diff_months',
|
|
'discharge_mortality',
|
|
'age_group',
|
|
'age_group_display',
|
|
'patient_id',
|
|
'temperature',
|
|
'weight',
|
|
'height',
|
|
'bmi'
|
|
));
|
|
}
|
|
|
|
public function save_edits_for_post_discharge(Request $request)
|
|
{
|
|
$episode_id = $request->episode_id;
|
|
$patient_id = $request->patient_id;
|
|
|
|
// begin saving for discharge mortality risk
|
|
$discharge_mortality = DB::table('discharge_mortality_risk')->where('patient_id', $patient_id)
|
|
->where('episode_id', $episode_id)
|
|
->first();
|
|
|
|
if ($discharge_mortality) {
|
|
if (isset($request->bcs_eye_movement) && isset($request->bcs_best_mortal) && isset($request->bcs_best_verbal)) {
|
|
$total = $request->bcs_eye_movement + $request->bcs_best_mortal + $request->bcs_best_verbal;
|
|
|
|
|
|
if ($total == 5) {
|
|
$bcs = 0;
|
|
} else {
|
|
$bcs = 1;
|
|
}
|
|
} else {
|
|
$bcs = null;
|
|
}
|
|
|
|
if (isset($request->maternal_hiv)) {
|
|
if ($request->maternal_hiv == 0) {
|
|
$hiv_mom_positive = 0;
|
|
$hiv_mom_unknown = 1;
|
|
} else if ($request->maternal_hiv == 1) {
|
|
$hiv_mom_positive = 0;
|
|
$hiv_mom_unknown = 0;
|
|
} else {
|
|
$hiv_mom_positive = 1;
|
|
$hiv_mom_unknown = 0;
|
|
}
|
|
} else {
|
|
$hiv_mom_positive = null;
|
|
$hiv_mom_unknown = null;
|
|
}
|
|
|
|
DB::table('discharge_mortality_risk')
|
|
->where('id', $discharge_mortality->id)
|
|
->update([
|
|
'weight' => $request->weight ?? null,
|
|
'muac_below_6' => isset($request->muac) ? ($request->muac * 10) : null,
|
|
'bmi_below_6' => $request->bmi ?? null,
|
|
'hospital_travel_duration_below_6' => $request->hospital_travel_duration ?? null,
|
|
'illness_duration_at_admission_below_6' => $request->illness_duration ?? null,
|
|
'last_hospitalization' => $request->last_hospitalization ?? null,
|
|
'water_source' => $request->water_source ?? null,
|
|
'filter_water' => $request->safe_water ?? null,
|
|
'child_mosquito_net' => $request->child_mosquito_net ?? null,
|
|
'mother_education_level' => $request->mother_education_level ?? null,
|
|
'hospital_travel_duration' => $request->hospital_travel_duration ?? null,
|
|
'muac' => isset($request->muac) ? ($request->muac * 10) : null,
|
|
'temperature' => $request->temperature ?? null,
|
|
'oxy_saturation' => $request->oxy_sat ?? null,
|
|
'bcs' => $bcs,
|
|
'bcs_eye_movement' => $request->bcs_eye_movement ?? null,
|
|
'bcs_best_mortal' => $request->bcs_best_mortal ?? null,
|
|
'bcs_best_verbal' => $request->bcs_best_verbal ?? null,
|
|
'maternal_hiv' => $request->maternal_hiv ?? null,
|
|
'hiv_mom_positive' => $hiv_mom_positive,
|
|
'hiv_mom_unknown' => $hiv_mom_unknown,
|
|
'maternal_age' => $request->maternal_age ?? null,
|
|
'child_hiv' => $request->child_hiv ?? null,
|
|
'child_with_proven_infection' => $request->child_with_proven_infection ?? null
|
|
]);
|
|
}
|
|
// end discharge mortality risk save
|
|
|
|
flash("The post discharge risk score has been calculated")->success();
|
|
return redirect('patient_episodes');
|
|
}
|
|
}
|