updated streamline-setup v2

This commit is contained in:
2025-01-15 08:53:49 -08:00
committed by alec.turner
parent a2ce9248f0
commit 4b569f81b0
20228 changed files with 2932048 additions and 63204 deletions
@@ -25,6 +25,11 @@ use Streamline\Models\CardioEchoResult;
use Barryvdh\Snappy\Facades\SnappyPdf;
use Streamline\Models\Investigation;
use Streamline\Models\Outcome;
use Streamline\Models\PrioritySign;
use Streamline\Models\EmergencySign;
use Streamline\Models\WardInpatientDetailedNote;
use Streamline\Models\MessageBoard;
use Illuminate\Database\QueryException;
class ConsultationController extends Controller
{
@@ -49,7 +54,8 @@ class ConsultationController extends Controller
if (!session()->has('patient_id') || !session()->has('episode_id')) :
flash('Patient is not selected')->error();
return view('home');
$messages = MessageBoard::orderBy('created_at', 'desc')->paginate(3);
return view('home', compact('messages'));
endif;
$clinics = Clinic::orderBy('name')->pluck("name", "id")->toArray();
@@ -285,7 +291,8 @@ class ConsultationController extends Controller
if (!session()->has('patient_id') || !session()->has('episode_id')) :
flash('Patient is not selected')->error();
return view('home');
$messages = MessageBoard::orderBy('created_at', 'desc')->paginate(3);
return view('home', compact('messages'));
endif;
$consultation = new Consultation;
@@ -493,7 +500,17 @@ class ConsultationController extends Controller
}
$episode = PatientEpisode::find($episode_id);
if(!empty($request->investigation_and_management_plan_comments) || !empty($request->clinic_examination_comments) || !empty($request->history_comments)){
$notes = new WardInpatientDetailedNote;
$notes->patient_id = $patient_id;
$notes->episode_id = $episode_id;
$notes->ward_id = 0;
$notes->investigation_and_management_plan_comments = $request->investigation_and_management_plan_comments?? null;
$notes->clinic_examination_comments = $request->clinic_examination_comments?? null;
$notes->history_comments = $request->history_comments;
$notes->created_by = Auth::user()->id;
$notes->save();
}
// Handle the buttons on the consultation page
switch ($request->get('submit-btn')):
@@ -595,8 +612,9 @@ class ConsultationController extends Controller
if (session()->get('consultation_with_notes') == 1) {
$consultation_with_notes = true;
$consultation_notes = WardInpatientDetailedNote::where(['patient_id' => $patient->id, 'episode_id' => $episode->id, 'ward_id' => 0])->latest()->get();
} else {
$consultation_with_notes = false;
$consultation_with_notes = false; $consultation_notes = '';
}
$is_mental_health_clinic = false;
@@ -657,7 +675,7 @@ class ConsultationController extends Controller
/* ========end of varibales added to cater for review episodes ========*/
$cardio_echo = CardioEchoResult::where('episode_id', $consultation->episode_id)->first();
$users = DB::table('users')->pluck(DB::raw("CONCAT(first_name,' ',last_name) AS name"), 'id');
return view('patients::consultations.show', compact(
'consultation',
'patient',
@@ -688,7 +706,9 @@ class ConsultationController extends Controller
'parent_episode_ordered_sundries',
'parent_episode_ordered_investigations',
'parent_episode_investigation_results',
'cardio_echo'
'cardio_echo',
'consultation_notes',
'users'
));
}
@@ -705,7 +725,7 @@ class ConsultationController extends Controller
$clinics = Clinic::orderBy('name')->pluck("name", "id")->toArray();
$clinics = ['0' => "Don't assign clinic"] + $clinics;
$users = User::orderBy('first_name')->select("id", "first_name", "last_name")->get();
$users = User::pluck(DB::raw("CONCAT(first_name,' ',last_name) AS name"), 'id');
//Patient, Triage and Episode
$patient = Patient::where('id', $consultation->patient_id)->first();
@@ -714,10 +734,13 @@ class ConsultationController extends Controller
if (session()->get('consultation_with_notes') == 1) {
$consultation_with_notes = true;
$all_notes = WardInpatientDetailedNote::where(['patient_id' => $patient->id, 'episode_id' => $episode->id, 'ward_id' => 0])->latest()->get();
$consultation_notes = $all_notes->take(5);
$notes = $all_notes->skip(5);
$view_notes = $notes->all();
} else {
$consultation_with_notes = false;
}
$consultation_with_notes = false; $consultation_notes = $view_notes ='';
}
$is_mental_health_clinic = false;
// fetch the clinic id and determine if this is a mental health consultation
$clinic_slug = get_name($episode->clinic_id, "id", "slug", "clinics");
@@ -918,7 +941,9 @@ class ConsultationController extends Controller
'users_array',
'is_mental_health_clinic',
'hmis_categories',
'cardio_echo'
'cardio_echo',
'consultation_notes',
'view_notes'
));
}
@@ -927,7 +952,8 @@ class ConsultationController extends Controller
if (!session()->has('patient_id') || !session()->has('episode_id')) :
flash('Patient is not selected')->error();
return view('home');
$messages = MessageBoard::orderBy('created_at', 'desc')->paginate(3);
return view('home', compact('messages'));
endif;
$consultation = Consultation::find($id);
@@ -1131,6 +1157,26 @@ class ConsultationController extends Controller
$mental_health_consultation->update();
}
if(!empty($request->investigation_and_management_plan_comments) || !empty($request->clinic_examination_comments) || !empty($request->history_comments)){
$notes = new WardInpatientDetailedNote;
$notes->patient_id = $patient_id;
$notes->episode_id = $episode_id;
$notes->ward_id = 0;
$notes->investigation_and_management_plan_comments = $request->investigation_and_management_plan_comments?? null;
$notes->clinic_examination_comments = $request->clinic_examination_comments?? null;
$notes->history_comments = $request->history_comments?? null;
$notes->created_by = Auth::user()->id;
$notes->save();
}
if(!empty($request->deleted_notes)){
foreach($request->deleted_notes as $note){
if(!empty($note)) {
$notes = WardInpatientDetailedNote::find($note);
$notes->delete();
}
}
}
switch ($request->get('submit-btn')):
case 'investigation':
$consultation->save();
@@ -1292,10 +1338,8 @@ class ConsultationController extends Controller
$diagnosis->save();
return $diagnosis->id;
} catch (QueryException $e) {
$errorCode = $e->errorInfo[1];
if ($errorCode == 1062) { //error code for duplicate entry to a unique field
return response()->json(['error' => $e]);
}
flash("An error occurred")->error();
return back()->withInput();
}
}
@@ -1319,20 +1363,20 @@ class ConsultationController extends Controller
$hospitalInfo = DB::table('hospital_information')->find(1);
$consultation = Consultation::where(['patient_id' => $patient_id, 'episode_id' => $episode_id])->orderBy('created_at', 'desc')->first();
$triage = Triage::where(['patient_id' => $patient_id, 'episode_id' => $episode_id])->first();
$patient_discount = \Streamline\Models\PatientDiscount::where(['patient_category' => $patient->category_id])->select("discount", "pay_later")->first();
if (!is_null($patient_discount)) {
$patient_discount->toArray();
}
$treatments = Treatment::where(['patient_id' => $patient_id, 'episode_id' => $episode_id])->get();
$all_diagnoses = DB::table('diagnoses')->pluck("name", "id");
/* ====== start work on investigations */
// prep the inpatient investigation arrays and counters
$opd_investigations = [];
$opd_investigations_position = [];
$opd_investigations_date = [];
$ward_investigations = [];
$ward_investigations_position = [];
$ward_investigations_date = [];
// get all investigations ordered in this episode
@@ -1342,22 +1386,6 @@ class ConsultationController extends Controller
$investigation_results_order_ids = InvestigationResults::pluck('order_id', 'id')->toArray();
foreach ($ordered_investigations as $investigation) {
if (isset($ward_investigations['id'])) {
$ward_investigations_position[] = count($ward_investigations['id']);
} else {
$ward_investigations_position[] = 0;
}
if (isset($opd_investigations['id'])) {
$opd_investigations_position[] = count($opd_investigations['id']);
} else {
$opd_investigations_position[] = 0;
}
$ward_investigations_date[] = "Ordered on " . streamline_date_time($investigation->created_at) . " by " .
get_full_name($investigation->created_by, 'id', 'first_name', 'last_name', 'users');
$opd_investigations_date[] = streamline_date_time($investigation->created_at);
$investigation_ids = explode(",", $investigation->investigation_id);
$inpatient_status = explode(",", $investigation->for_inpatient);
@@ -1377,61 +1405,81 @@ class ConsultationController extends Controller
if ($results->all_authenticated == 1) {
for ($i = 0; $i < count($inpatient_status); $i++) {
if (isset($inpatient_status[$i]) && $inpatient_status[$i] == 0) {
$result = Investigation::withTrashed()->find($investigation_ids[$i]);
$opd_investigations['id'][] = $result->id;
$opd_investigations['name'][] = $result->name;
$opd_investigations['type'][] = $result->type;
$opd_investigations['slug'][] = $result->slug;
$opd_investigations['value'][] = $investigation_results[$i];
$opd_investigations['comment'][] = $investigation_comments[$i];
if ($inpatient_status[$i] == 0) {
if (isset($investigation_ids[$i]) && $investigation_ids[$i] != "") {
$result = Investigation::where('id', $investigation_ids[$i])->first();
$opd_investigations['name'][] = $result->name;
$opd_investigations['value'][] = $investigation_results[$i];
$opd_investigations['comment'][] = $investigation_comments[$i];
if($result->range_type == 1) {
$opd_investigations['normal_ranges'][] = get_dynamic_normal_range($result->id, get_patient_age_group($patient_id), get_name($patient_id, 'id', 'gender', 'patients'));
} else {
$opd_investigations['normal_ranges'][] = $result->normal_ranges;
}
$opd_investigations['type'][] = $result->type;
}
} else {
$result = Investigation::withTrashed()->find($investigation_ids[$i]);
$ward_investigations['id'][] = $result->id;
$ward_investigations['name'][] = $result->name;
$ward_investigations['type'][] = $result->type;
$ward_investigations['slug'][] = $result->slug;
$ward_investigations['value'][] = isset($investigation_results[$i]) ? $investigation_results[$i] : "";
$ward_investigations['comment'][] = isset($investigation_comments[$i]) ? $investigation_comments[$i] : "";
if (isset($investigation_ids[$i]) && $investigation_ids[$i] != "") {
$result = Investigation::where('id', $investigation_ids[$i])->first();
$ward_investigations['name'][] = $result->name;
$ward_investigations['value'][] = $investigation_results[$i];
$ward_investigations['comment'][] = $investigation_comments[$i];
$ward_investigations['type'][] = $result->type;
}
}
}
} else {
for ($i = 0; $i < count($inpatient_status); $i++) {
$investigation = \Streamline\Models\Investigation::withTrashed()->find($investigation_ids[$i]);
if (isset($investigation_per_valid[$i]) && $investigation_per_valid[$i] == 1) {
if ($investigation_per_valid[$i] == 1) {
// this investigation is authenticated
if (isset($inpatient_status[$i]) && $inpatient_status[$i] == 0) {
$opd_investigations['id'][] = $investigation->id;
$opd_investigations['name'][] = $investigation->name;
$opd_investigations['type'][] = $investigation->type;
$opd_investigations['slug'][] = $investigation->slug;
$opd_investigations['value'][] = $investigation_results[$i];
$opd_investigations['comment'][] = $investigation_comments[$i];
if ($inpatient_status[$i] == 0) {
if (isset($investigation_ids[$i]) && $investigation_ids[$i] != "") {
$result = Investigation::where('id', $investigation_ids[$i])->first();
$opd_investigations['name'][] = $result->name;
$opd_investigations['value'][] = $investigation_results[$i];
if($result->range_type == 1) {
$opd_investigations['normal_ranges'][] = get_dynamic_normal_range($result->id, get_patient_age_group($patient_id), get_name($patient_id, 'id', 'gender', 'patients'));
} else {
$opd_investigations['normal_ranges'][] = $result->normal_ranges;
}
$opd_investigations['comment'][] = $investigation_comments[$i];
$opd_investigations['type'][] = $result->type;
}
} else {
$ward_investigations['id'][] = $investigation->id;
$ward_investigations['name'][] = $investigation->name;
$ward_investigations['type'][] = $investigation->type;
$ward_investigations['slug'][] = $investigation->slug;
$ward_investigations['value'][] = $investigation_results[$i];
$ward_investigations['comment'][] = $investigation_comments[$i];
if (isset($investigation_ids[$i]) && $investigation_ids[$i] != "") {
$result = Investigation::where('id', $investigation_ids[$i])->first();
$ward_investigations['name'][] = $result->name;
$ward_investigations['value'][] = $investigation_results[$i];
$ward_investigations['comment'][] = $investigation_comments[$i];
$ward_investigations['type'][] = $result->type;
}
}
} else {
if (isset($investigation_per_valid[$i]) && $inpatient_status[$i] == 0) {
$opd_investigations['id'][] = $investigation->id;
$opd_investigations['name'][] = $investigation->name;
$opd_investigations['type'][] = $investigation->type;
$opd_investigations['slug'][] = $investigation->slug;
$opd_investigations['value'][] = "Pending";
$opd_investigations['comment'][] = "Pending";
if ($inpatient_status[$i] == 0) {
if (isset($investigation_ids[$i]) && $investigation_ids[$i] != "") {
$result = Investigation::where('id', $investigation_ids[$i])->first();
$opd_investigations['name'][] = $result->name;
$opd_investigations['value'][] = "Pending";
if($result->range_type == 1) {
$opd_investigations['normal_ranges'][] = get_dynamic_normal_range($result->id, get_patient_age_group($patient_id), get_name($patient_id, 'id', 'gender', 'patients'));
} else {
$opd_investigations['normal_ranges'][] = $result->normal_ranges;
}
$opd_investigations['comment'][] = "Pending";
}
} else {
$ward_investigations['id'][] = $investigation->id;
$ward_investigations['name'][] = $investigation->name;
$ward_investigations['type'][] = $investigation->type;
$ward_investigations['slug'][] = $investigation->slug;
$ward_investigations['value'][] = "Pending";
$ward_investigations['comment'][] = "Pending";
if (isset($investigation_ids[$i]) && $investigation_ids[$i] != "") {
$result = Investigation::where('id', $investigation_ids[$i])->first();
$ward_investigations['name'][] = $result->name;
$ward_investigations['value'][] = "Pending";
$ward_investigations['comment'][] = "Pending";
}
}
}
}
@@ -1439,27 +1487,58 @@ class ConsultationController extends Controller
}
} else {
for ($i = 0; $i < count($inpatient_status); $i++) {
if (isset($inpatient_status[$i]) && $inpatient_status[$i] == 0) {
$result = Investigation::withTrashed()->find($investigation_ids[$i]);
$opd_investigations['id'][] = $result->id;
$opd_investigations['name'][] = $result->name;
$opd_investigations['type'][] = $result->type;
$opd_investigations['slug'][] = $result->slug;
$opd_investigations['value'][] = "Pending";
$opd_investigations['comment'][] = "Pending";
if ($inpatient_status[$i] == 0) {
if (isset($investigation_ids[$i]) && $investigation_ids[$i] != "") {
$result = Investigation::where('id', $investigation_ids[$i])->first();
$opd_investigations['name'][] = $result->name;
$opd_investigations['value'][] = "Pending";
if($result->range_type == 1) {
$opd_investigations['normal_ranges'][] = get_dynamic_normal_range($result->id, get_patient_age_group($patient_id), get_name($patient_id, 'id', 'gender', 'patients'));
} else {
$opd_investigations['normal_ranges'][] = $result->normal_ranges;
}
$opd_investigations['comment'][] = "Pending";
}
} else {
$result = Investigation::withTrashed()->find($investigation_ids[$i]);
$ward_investigations['id'][] = $result->id;
$ward_investigations['name'][] = $result->name;
$ward_investigations['type'][] = $result->type;
$ward_investigations['slug'][] = $result->slug;
$ward_investigations['value'][] = "Pending";
$ward_investigations['comment'][] = "Pending";
if (isset($investigation_ids[$i]) && $investigation_ids[$i] != "") {
$result = Investigation::where('id', $investigation_ids[$i])->first();
$ward_investigations['name'][] = $result->name;
$ward_investigations['value'][] = "Pending";
$ward_investigations['comment'][] = "Pending";
}
}
}
}
}
/* ====== end work on investigations */
$ordered_procedures = OrderedProcedure::where(['patient_id' => $patient_id, 'episode_id' => $episode_id])->get();
$procedures = DB::table('procedures')->where('available', 1)->pluck("name", "id");
$cons_notes = WardInpatientDetailedNote::where(['patient_id' => $patient_id, 'episode_id' => $episode_id, 'ward_id' => 0])->latest()->get(['investigation_and_management_plan_comments', 'clinic_examination_comments', 'history_comments', 'created_by']);
$priority_signs = $emergent_signs =[];
$dateBorn = Carbon::parse($patient->date_of_birth);
$years = $dateBorn->diffInYears();
if(between($years, 0, 12) && !empty($triage)) {
$priority_signs_records = PrioritySign::where('triage_id', $triage->id)->first();
if ($priority_signs_records) {
$priority_signs = unserialize($priority_signs_records->signs);
}
$emergency_signs = EmergencySign::where('triage_id', $triage->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);
$emergencySigns= array_merge($airway,$circulation, $dehydration,$neurological);
foreach($emergencySigns as $key => $sign) if($sign == 'Yes') $emergent_signs[] = $key;
}
}
// get all symptoms
$symptoms = DB::table('symptoms')->where('available', 1)->pluck("name", "id");
$data = [
'patient' => $patient,
@@ -1469,12 +1548,20 @@ class ConsultationController extends Controller
'patient_discount' => $patient_discount,
'ward_investigations' => $ward_investigations,
'opd_investigations' => $opd_investigations,
'opd_investigations_position' => $opd_investigations_position,
'ward_investigations_position' => $ward_investigations_position,
'ordered_procedures' => $ordered_procedures,
'procedures' => $procedures,
'treatments' => $treatments,
'all_diagnoses' => $all_diagnoses,
'cons_notes' => $cons_notes,
'triage' => $triage,
'years' => $years,
'symptoms' => $symptoms,
'priority_signs' => $priority_signs,
'emergent_signs' => $emergent_signs,
'opd_investigations_date' => $opd_investigations_date,
'ward_investigations_date' => $ward_investigations_date
];
// return view('patients::consultations/referral_notes_print', $data);
$pdf = SnappyPDF::loadView('patients::consultations/referral_notes_print', $data)
->setOrientation('portrait')
->setOption('margin-bottom', 7)
@@ -1493,4 +1580,26 @@ class ConsultationController extends Controller
return "";
}
public function delete_consultation_clinical_notes($id)
{
$ward_doctor_notes = WardInpatientDetailedNote::find($id);
$ward_doctor_notes->delete();
flash('Notes have been deleted')->success();
return redirect('in_patient_sheet');
}
public function update_consultation_clinical_notes(Request $request)
{
$consultation_clinical_notes = WardInpatientDetailedNote::find($request->id);
$consultation_clinical_notes->history_comments = $request->history_comments?? null;
$consultation_clinical_notes->investigation_and_management_plan_comments = $request->investigation_and_management_plan_comments?? null;
$consultation_clinical_notes->clinic_examination_comments = $request->clinic_examination_comments?? null;
$consultation_clinical_notes->updated_by = Auth::user()->id;
if($consultation_clinical_notes->save()) return $consultation_clinical_notes->id;
else return 0;
}
}