mirror of
https://gitlab.com/signalytic/client-external/streamline/streamline-emr.git
synced 2026-09-11 18:51:31 +00:00
1233 lines
62 KiB
PHP
Executable File
1233 lines
62 KiB
PHP
Executable File
<?php
|
|
|
|
namespace Modules\Theatre\Http\Controllers;
|
|
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Support\Facades\Auth;
|
|
use Illuminate\Support\Facades\DB;
|
|
use Illuminate\Support\Facades\Response;
|
|
use Modules\WardManagement\Http\Controllers\InpatientController;
|
|
use Spatie\Permission\Models\Role;
|
|
use Streamline\Models\Alert;
|
|
use Streamline\Models\Allergy;
|
|
use Streamline\Models\Anaesthesia;
|
|
use Streamline\Models\ChartOfAccount;
|
|
use Streamline\Models\Clinic;
|
|
use Streamline\Models\Consultation;
|
|
use Streamline\Models\Diagnosis;
|
|
use Streamline\Models\DrugCategory;
|
|
use Streamline\Models\InpatientInfo;
|
|
use Streamline\Models\MaritalStatus;
|
|
use Streamline\Models\Occupation;
|
|
use Streamline\Models\OrderedProcedure;
|
|
use Streamline\Models\Patient;
|
|
use Streamline\Models\PatientAppointment;
|
|
use Streamline\Models\PatientCategory;
|
|
use Streamline\Models\PatientDocument;
|
|
use Streamline\Models\PatientEpisode;
|
|
use Streamline\Models\PriceListCategories;
|
|
use Streamline\Models\Procedure;
|
|
use Streamline\Models\SecurityQuestion;
|
|
use Streamline\Models\Surgery;
|
|
use Streamline\Models\TheatreLocation;
|
|
use Streamline\Models\User;
|
|
use Carbon\Carbon;
|
|
use Streamline\Models\OrderedSundry;
|
|
use Streamline\Models\WardExtra;
|
|
use Streamline\Models\WardProcedure;
|
|
use Streamline\Models\WardStock;
|
|
use Barryvdh\Snappy\Facades\SnappyPdf;
|
|
use Streamline\Models\Treatment;
|
|
use Streamline\Models\WardSundryDispensation;
|
|
use Streamline\Models\WardTreatmentDispensation;
|
|
use Streamline\Services\WardManagement\WardTreatmentDispensationService;
|
|
|
|
class TheatreSurgeryController extends Controller
|
|
{
|
|
public function __construct(protected WardTreatmentDispensationService $dispensationService)
|
|
{
|
|
}
|
|
|
|
/**
|
|
* Display a listing of the resource.
|
|
*
|
|
* @return \Illuminate\Http\Response
|
|
*/
|
|
public function index()
|
|
{
|
|
$patient_id = session()->get('patient_id');
|
|
$episode_id = session()->get('episode_id');
|
|
$patient = Patient::find($patient_id);
|
|
$drug_categories = DB::table('drug_categories')->whereNull('deleted_at')->orderBy('name','asc')->get();
|
|
$drug_categories_array = DB::table('drug_categories')->whereNull('deleted_at')->pluck('name', 'id');
|
|
$categories = DB::table('patient_categories')->where('available', 1)->whereNull('deleted_at')->pluck("name", "id");
|
|
$known_patient_allergies = Allergy::where('patient_id' , $patient_id)->orderBy('created_at','desc')->take(2)->get();
|
|
$known_patient_alerts = Alert::where('patient_id' , $patient_id)->orderBy('created_at','desc')->take(2)->get();
|
|
|
|
$surgeries = DB::table('surgeries')->whereNull('deleted_at')->where('episode_id', $episode_id)->where('patient_id', $patient_id)->get()->toArray();
|
|
$performed_anaesthesia = DB::table('anaesthesias')->whereNull('deleted_at')->where('episode_id', $episode_id)->where('patient_id', $patient_id)->get()->toArray();
|
|
|
|
return view('theatre::theatre_surgeries.index', compact('patient_id', 'episode_id', 'patient', 'categories',
|
|
'known_patient_alerts', 'known_patient_allergies', 'drug_categories', 'surgeries', 'performed_anaesthesia', 'drug_categories_array'));
|
|
}
|
|
|
|
/**
|
|
* Show the form for creating a new resource.
|
|
*
|
|
* @return \Illuminate\Http\Response
|
|
*/
|
|
public function create()
|
|
{
|
|
$patient_id = session()->get('patient_id');
|
|
$episode_id = session()->get('episode_id');
|
|
$patient = Patient::find($patient_id);
|
|
|
|
$positions = DB::table('staff_positions')->whereNull('deleted_at')->orderBy('name')->pluck('name', 'id');
|
|
$positions->prepend('- select -', '');
|
|
|
|
$security_questions = SecurityQuestion::orderBy('name')->pluck('name', 'id');
|
|
$security_questions->prepend('- select -', '');
|
|
$drug_categories = DB::table('drug_categories')->whereNull('deleted_at')->orderBy('name','asc')->get();
|
|
$roles = Role::pluck('name', 'name')->all();
|
|
|
|
$surgeries = DB::table('surgeries')->whereNull('deleted_at')->where('episode_id', $episode_id)->where('patient_id', $patient_id)->get()->toArray();
|
|
$performed_anaesthesia = DB::table('anaesthesias')->where('episode_id', $episode_id)->where('patient_id', $patient_id)->get()->toArray();
|
|
|
|
$documents = DB::table('patient_documents')->whereNull('deleted_at')->where('patient_id',$patient_id)->orderBy('date_taken','desc')->take(2)->get();
|
|
$categories = DB::table('patient_categories')->where('available', 1)->whereNull('deleted_at')->pluck("name", "id");
|
|
$drug_categories = DB::table('drug_categories')->whereNull('deleted_at')->orderBy('name','asc')->get();
|
|
//allergies and alerts
|
|
$known_patient_allergies = Allergy::where('patient_id' , $patient_id)->orderBy('created_at','desc')->take(2)->get();
|
|
$known_patient_alerts = Alert::where('patient_id' , $patient_id)->orderBy('created_at','desc')->take(2)->get();
|
|
$drug_categories_array = DB::table('drug_categories')->whereNull('deleted_at')->pluck('name', 'id');
|
|
//dropdown options
|
|
$procedures = DB::table('procedures')->where('available', 1)->whereNull('deleted_at')->orderBy("name","asc")->pluck("name", "id");
|
|
$theatre_locations = DB::table('theatre_locations')->whereNull('deleted_at')->orderBy("name","asc")->pluck("name", "id")->prepend('- select -', '');
|
|
$outcomes = DB::table('outcomes')->whereNull('deleted_at')->orderBy("name","asc")->pluck("name", "id")->prepend('- select -', '');
|
|
$users = DB::table('users')->whereNull('deleted_at')->orderBy("first_name","asc")->select("id")->get()->toArray();
|
|
$doctors = [];
|
|
$nursing = [];
|
|
$theatre_in_charge_users = [];
|
|
foreach ($users as $value){
|
|
$user = User::find($value->id);
|
|
if (!is_null($user)) {
|
|
if ($user->hasRole('Doctors') || $user->hasRole('Doctor')) {
|
|
$doctors[$value->id] = get_full_name($value->id, 'id', 'first_name', 'last_name', 'users');
|
|
}
|
|
if ($user->hasRole('Nursing')) {
|
|
$nursing[$value->id] = get_full_name($value->id, 'id', 'first_name', 'last_name', 'users');
|
|
}
|
|
if ($user->hasRole('Doctors') || $user->hasRole('Nursing - senior ward staff') || $user->hasRole('Doctor') || $user->hasRole('Specialist Nurses') || $user->hasRole('Midwives')) {
|
|
$theatre_in_charge_users[$value->id] = get_full_name($value->id, 'id', 'first_name', 'last_name', 'users');
|
|
}
|
|
}
|
|
}
|
|
|
|
$doctors = ['' => '- select -'] + $doctors;
|
|
$nursing = ['' => '- select -'] + $nursing;
|
|
$doctors[0] = "None";
|
|
$nursing[0] = "None";
|
|
$theatre_in_charge_users = ['' => '- select -'] + $theatre_in_charge_users;
|
|
$theatre_in_charge_users[0] = "None";
|
|
|
|
//$anaesthesia_id
|
|
$anaesthesia = DB::table('anaesthesias')->whereNull('deleted_at')->where('patient_id', $patient_id)->where('episode_id', $episode_id)->first();
|
|
if(!is_null($anaesthesia)){
|
|
$anaesthesia_complete = TRUE;
|
|
} else {
|
|
$anaesthesia_complete = FALSE;
|
|
}
|
|
|
|
$wards = DB::table('wards')->where('available', 1)->whereNull('deleted_at')->orderBy("name","asc")->pluck("name", "id")->prepend('- select -', '');
|
|
$referrals = DB::table('referral_hospitals')->whereNull('deleted_at')->orderBy("name","asc")->pluck("name", "id")->prepend('- select -', '');
|
|
$sundries_array = DB::table('sundries')->whereNull('deleted_at')->orderBy("name","asc")->pluck("name", "id")->prepend('- select -', '');
|
|
|
|
$episode_consultation_details = Consultation::where(['patient_id' => $patient_id, 'episode_id' => $episode_id])->first();
|
|
$episode_consultation_outcome = null;
|
|
//dd($episode_consultation_details);
|
|
$ward_id = null;
|
|
$admission_date = null;
|
|
|
|
if ($episode_consultation_details) {
|
|
$episode_consultation_outcome = $episode_consultation_details->outcome_id;
|
|
if ($episode_consultation_outcome == 1) {
|
|
$inpatient_record = InpatientInfo::where(['patient_id' => $patient_id, 'episode_id' => $episode_id])->first();
|
|
$ward_id = $inpatient_record->ward_id;
|
|
$admission_date = $episode_consultation_details->admitted_on;
|
|
}
|
|
} else {
|
|
$inpatient_record = InpatientInfo::where(['patient_id' => $patient_id, 'episode_id' => $episode_id])->first();
|
|
if ($inpatient_record) {
|
|
$episode_consultation_outcome = $inpatient_record->outcome_id;
|
|
if ($episode_consultation_outcome == 1) {
|
|
$ward_id = $inpatient_record->ward_id;
|
|
$admission_date = $inpatient_record->admitted_on;
|
|
}
|
|
}
|
|
}
|
|
|
|
$clinics = Clinic::orderBy('name')->pluck("name", "id")->toArray();
|
|
$clinics = ['0' => "Don't assign clinic"] + $clinics;
|
|
$users_collection = DB::table('users')->whereNull('deleted_at')->orderBy("first_name","asc")->select("id")->get()->toArray();
|
|
$users = User::orderBy('first_name')->select("id", "first_name", "last_name")->get();
|
|
$diagnoses = Diagnosis::where('available', 1)->orderby('name', 'asc')->pluck("name", "id")->prepend('- select -', '');
|
|
$diagnoses_all = Diagnosis::select('id', 'prompts', 'reference_areas', 'reference_names')->get();
|
|
$drugs = DB::table('drugs')->where('available', 1)->whereNull('deleted_at')->orderBy('name')->pluck('name', 'id')->prepend('- select -', '');
|
|
$units = DB::table('drug_units')->whereNull('deleted_at')->orderBy('name')->pluck('name', 'id')->prepend('- select -', '');
|
|
|
|
$hmis_categories = DB::table('hmis_categories')->whereNull('deleted_at')->orderBy('title', 'asc')->pluck('title', 'id')->toArray();
|
|
$hmis_categories = ['' => '- select -'] + $hmis_categories;
|
|
|
|
return view('theatre::theatre_surgeries.create',compact('episode_id','patient_id','patient','documents', 'categories','drug_categories','known_patient_alerts','known_patient_allergies','drug_categories_array', 'procedures','theatre_locations','outcomes','doctors', 'anaesthesia', 'anaesthesia_complete','positions', 'roles', 'security_questions', 'surgeries', 'performed_anaesthesia','nursing','wards','referrals','theatre_in_charge_users',
|
|
'sundries_array','episode_consultation_details','clinics','users', 'episode_consultation_outcome', 'diagnoses', 'diagnoses_all', 'drugs', 'units', 'ward_id', 'admission_date', 'hmis_categories'));
|
|
}
|
|
|
|
/**
|
|
* Store a newly created resource in storage.
|
|
*
|
|
* @param \Illuminate\Http\Request $request
|
|
* @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
|
|
*/
|
|
public function store(Request $request)
|
|
{
|
|
$patient_id = session()->get('patient_id');
|
|
$episode_id = session()->get('episode_id');
|
|
|
|
$anaesthesia_id = $request->anaesthesia_id;
|
|
$theatre_ward_id = get_name("theatre", "slug", "id", "wards");
|
|
|
|
if (!is_integer($theatre_ward_id)) {
|
|
flash('Theatre ward not registered')->error();
|
|
return redirect()->back()->withInput();
|
|
}
|
|
|
|
$procedures = implode(",", $request->procedure_id);
|
|
$surgery_type = $request->surgery_type;
|
|
$surgeon = $request->surgeon;
|
|
$assistant_surgeon = $request->assistant_surgeon;
|
|
$scrub_nurse = $request->scrub_nurse;
|
|
$authorised_swab_check = $request->authorised_swab_check;
|
|
$theatre_location = $request->theatre_location;
|
|
$time_surgery_completed = $request->time_surgery_completed;//change to carbon time format
|
|
$date_surgery_completed = $request->date_surgery_completed; //change to carbon date format
|
|
|
|
$theatre_incharge = $request->theatre_incharge;
|
|
$estimated_blood_loss = $request->estimated_blood_loss;
|
|
$outcome = $request->outcome;
|
|
/*$vicryl_sutures_used = $request->vicryl_sutures_used;
|
|
$other_sutures_used = $request->other_sutures_used;*/
|
|
$other_scrub_staff = $request->other_scrub_staff;
|
|
$comments = $request->comments;
|
|
$staff_id = $request->theatre_incharge;
|
|
|
|
// Prepare the other drugs given and cost for storing
|
|
$drug_ids = $request->drugs;
|
|
|
|
$inpatient_info = InpatientInfo::where(['patient_id' => $patient_id,'episode_id' => $episode_id,'discharged' => 0])->orderBy('created_at','desc')->first();
|
|
|
|
if (count($drug_ids) > 0) {
|
|
$doses = $request->dose;
|
|
$units = $request->units;
|
|
$drugs_given = [];
|
|
$drugs_cost = [];
|
|
$drug_quantity_used_array = $drug_frequency_array = $drug_purchased_elsewhere = $drug_eyey_array = $drug_order_comments_array = $drug_instructions_array = $drug_duration_array = [];
|
|
|
|
foreach ($drug_ids as $key => $value):
|
|
$drugs_given[] = [
|
|
'id' => $value,
|
|
'dose' => $doses[$key],
|
|
'unit' => $units[$key]
|
|
];
|
|
|
|
$drug = DB::table('drugs')->whereNull('deleted_at')->select('non_insured_price', 'strength', 'pack')->find($value);
|
|
|
|
if ($drug) {
|
|
$drugs_cost[] = (($doses[$key] / $drug->strength) / $drug->pack) * $drug->non_insured_price;
|
|
$drug_quantity_used = ($doses[$key] / $drug->strength) / $drug->pack;
|
|
reduce_ward_stock_with_consumed_quantity($value, $drug_quantity_used, 1, $theatre_ward_id, $patient_id, $episode_id, null);
|
|
|
|
$drug_quantity_used_array[] = $drug_quantity_used;
|
|
$drug_frequency_array[] = "";
|
|
$drug_purchased_elsewhere[] = "";
|
|
$drug_eyey_array[] = "";
|
|
$drug_instructions_array[] = "";
|
|
$drug_duration_array[] = "";
|
|
}
|
|
endforeach;
|
|
|
|
$drugs_given_serial = serialize($drugs_given);
|
|
$drugs_cost_serial = serialize($drugs_cost);
|
|
|
|
if ($inpatient_info){
|
|
for ($i=0; $i < count($drug_ids) ; $i++) {
|
|
if (isset($drug_quantity_used_array[$i]) && isset( $drug_ids[$i])) {
|
|
$ward_treatment_id = $this->dispensationService->saveDispensation((int)$patient_id, (int)$episode_id, $drug_ids[$i], (int)$drug_quantity_used_array[$i],
|
|
0, $request->ward_id ?? 0);
|
|
}
|
|
}
|
|
} else {
|
|
$treatment = new Treatment;
|
|
$treatment->patient_id = $patient_id;
|
|
$treatment->episode_id = $episode_id;
|
|
$treatment->drugs = implode(',', $drug_ids);
|
|
$treatment->doses = implode(',', $doses);
|
|
$treatment->frequencies = implode(',', $drug_frequency_array);
|
|
$treatment->durations = implode(',', $drug_duration_array);
|
|
$treatment->quantities_dispensed = implode(',', $drug_quantity_used_array);
|
|
$treatment->instruction = implode(',', $drug_instructions_array);
|
|
$treatment->purchased_elsewhere = implode(',', $drug_purchased_elsewhere);
|
|
$treatment->dispense_status = 0;
|
|
$treatment->eye = implode(",", $drug_eyey_array);
|
|
$treatment->order_comments = "";
|
|
$treatment->created_by = auth()->user()->id;
|
|
$treatment->save();
|
|
}
|
|
} else {
|
|
$drugs_given_serial = null;
|
|
$drugs_cost_serial = null;
|
|
}
|
|
|
|
// insert data to surgery table
|
|
$surgery = new Surgery;
|
|
|
|
switch ($outcome){
|
|
case 1: // Admitted
|
|
$surgery->ward_id_admitted = $request->ward_id;
|
|
$surgery->admitted_on = $request->admitted_on;
|
|
|
|
// check if the patient is currently admitted and just update their status
|
|
if ($inpatient_info) {
|
|
$inpatient_info->ward_id = $request->ward_id;
|
|
$inpatient_info->updated_by = $staff_id;
|
|
$inpatient_info->save();
|
|
} else {
|
|
// admit the patient
|
|
$inpatient = new InpatientInfo;
|
|
$inpatient->patient_id = $patient_id;
|
|
$inpatient->episode_id = $episode_id;
|
|
$inpatient->admitted_on = Carbon::createFromFormat('Y-m-d', $request->admitted_on)->toDateString();
|
|
$inpatient->ward_id = $request->ward_id;
|
|
$inpatient->primary_diagnosis = "";
|
|
$inpatient->comments = $comments;
|
|
$inpatient->created_by = $staff_id;
|
|
$inpatient->save();
|
|
}
|
|
break;
|
|
case 2: // Discharged
|
|
// discharge the patient if admitted
|
|
discharge_patient_from_ward($patient_id, $episode_id, Auth::id(), date('Y-m-d'));
|
|
break;
|
|
case 3: // Home with Follow up
|
|
// discharge the patient if admitted
|
|
discharge_patient_from_ward($patient_id, $episode_id, Auth::id(), date('Y-m-d'));
|
|
|
|
$surgery->followup_where = $request->followup_where;
|
|
$surgery->followup_when = $request->followup_when;
|
|
|
|
// get current clinic of patient if available
|
|
$episode_information = PatientEpisode::find($episode_id);
|
|
|
|
if ($episode_information->clinic_id){
|
|
$clinic_allocation_id = $episode_information->clinic_id;
|
|
} else {
|
|
$clinic_allocation_id = 0;
|
|
}
|
|
|
|
// save information to the follow-up table
|
|
$appointment = new PatientAppointment();
|
|
$appointment->patient_id = $patient_id;
|
|
$appointment->incharge_id = Auth::id();
|
|
$appointment->clinic_allocation = $clinic_allocation_id;
|
|
$appointment->episode_id = $episode_id;
|
|
$appointment->appointment_date = Carbon::createFromFormat('Y-m-d', $request->followup_when)->toDateString();
|
|
$appointment->appointment_time = "09:00:00";
|
|
$appointment->created_from = "Surgery";
|
|
$appointment->created_by = Auth::id();
|
|
$appointment->updated_by = Auth::id();
|
|
$appointment->save();
|
|
break;
|
|
case 4: // Referred
|
|
$surgery->referred_to = $request->referral_id;
|
|
|
|
// discharge the patient if admitted
|
|
discharge_patient_from_ward($patient_id, $episode_id, Auth::id(), date('Y-m-d'));
|
|
break;
|
|
case 5: // Died
|
|
// discharge the patient if admitted
|
|
discharge_patient_from_ward($patient_id, $episode_id, Auth::id(), date('Y-m-d'));
|
|
break;
|
|
case 6: // Return to ward
|
|
$inpatient_info = InpatientInfo::where(['patient_id' => $patient_id,'episode_id' => $episode_id,'discharged' => 0])->orderBy('created_at','desc')->first();
|
|
if ($inpatient_info) {
|
|
$inpatient_info->outcome_id = 1;
|
|
$inpatient_info->discharged = 0;
|
|
$inpatient_info->update();
|
|
}
|
|
break;
|
|
}
|
|
|
|
if ($request->anaesthesia_complete) {
|
|
$surgery->anaesthesia_id = $anaesthesia_id;
|
|
}
|
|
|
|
$surgery->episode_id = $episode_id;
|
|
$surgery->patient_id = $patient_id;
|
|
$surgery->procedure_id = $procedures;
|
|
$surgery->surgery_type = $surgery_type;
|
|
$surgery->primary_diagnosis = $request->primary_diagnosis;
|
|
$surgery->other_diagnoses = serialize($request->other_diagnosis);
|
|
$surgery->surgeon = $surgeon;
|
|
$surgery->assistant_surgeon = $assistant_surgeon;
|
|
$surgery->scrub_nurse = $scrub_nurse;
|
|
$surgery->authorised_swab_check = $authorised_swab_check;
|
|
$surgery->theatre_location = $theatre_location;
|
|
$surgery->time_surgery_completed = $time_surgery_completed;
|
|
$surgery->date_surgery_completed = !is_null($date_surgery_completed) ? Carbon::createFromFormat('Y-m-d', $date_surgery_completed)->toDateString() : null;
|
|
$surgery->theatre_in_charge = $theatre_incharge;
|
|
$surgery->estimated_blood_loss = $estimated_blood_loss;
|
|
$surgery->outcome = $outcome;
|
|
$surgery->other_scrub_staff = $other_scrub_staff;
|
|
$surgery->other_drugs_given = $drugs_given_serial;
|
|
$surgery->other_drugs_cost = $drugs_cost_serial;
|
|
/*$surgery->vicryl_sutures_used = $vicryl_sutures_used;
|
|
$surgery->other_sutures_used = $other_sutures_used;*/
|
|
$extras_array = $request->extras_used;
|
|
$extras_cost_array = $request->extras_cost;
|
|
$unserialized_extras_array = array(
|
|
"extras" => $extras_array,
|
|
"cost" => $extras_cost_array
|
|
);
|
|
$surgery->extras_used = serialize($unserialized_extras_array);
|
|
|
|
$sundry_used_array = $request->sundries_used;
|
|
$sundry_quantity_array = $request->sundries_quantity_used;
|
|
$unserialized_sundries_array = array(
|
|
"sundries" => $sundry_used_array,
|
|
"quantity" => $sundry_quantity_array
|
|
);
|
|
$surgery->sundries_used = serialize($unserialized_sundries_array);
|
|
|
|
$surgery->comments = $comments;
|
|
$surgery->created_by = Auth::id();
|
|
$surgery->save();
|
|
|
|
// save the procedure info in inpatient or OPD if anaesthesia is not complete
|
|
/* i have commented out the if stmt coz i dt remember why we needed to check if anaeasthesia is done or not before saving the procedure in the respective table */
|
|
//if (!$request->anaesthesia_complete){
|
|
$inpatient_info = InpatientInfo::where(['patient_id' => $patient_id,'episode_id' => $episode_id])->orderBy('created_at','desc')->first();
|
|
|
|
if ($inpatient_info){
|
|
//check_if_there_are_exisiting_procedures and add the new ones instead of over riding them
|
|
if(!is_null($inpatient_info->procedures) && $inpatient_info->procedures != ''){
|
|
$procedures_array = @unserialize($inpatient_info->procedures);
|
|
$unserialized_procedures_array[] = isset($procedures_array[0]) ? $procedures_array[0] : [];
|
|
for ($i=0; $i < count($request->procedure_id) ; $i++) {
|
|
$unserialized_procedures_array[] = $request->procedure_id[$i];
|
|
}
|
|
$inpatient_info->procedures = serialize($unserialized_procedures_array);
|
|
} else {
|
|
$fresh_procedure_array = [];
|
|
for ($i=0; $i < count($request->procedure_id) ; $i++) {
|
|
$fresh_procedure_array[] = $request->procedure_id[$i];
|
|
}
|
|
$inpatient_info->procedures = serialize($fresh_procedure_array);
|
|
}
|
|
|
|
// procedure_done_by
|
|
if(!is_null($inpatient_info->procedures_done_by) && $inpatient_info->procedures_done_by != ''){
|
|
$procedures_done_by_array = @unserialize($inpatient_info->procedures_done_by);
|
|
for ($i=0; $i < count($request->procedure_id) ; $i++) {
|
|
$procedures_done_by_array[] = $request->surgeon;
|
|
}
|
|
$inpatient_info->procedures_done_by = serialize($procedures_done_by_array);
|
|
} else {
|
|
$fresh_procedure_done_by_array = [];
|
|
for ($i=0; $i < count($request->procedure_id) ; $i++) {
|
|
$fresh_procedure_done_by_array[] = $request->surgeon;
|
|
}
|
|
$inpatient_info->procedures_done_by = serialize($fresh_procedure_done_by_array);
|
|
}
|
|
|
|
// procedure_hospital_fee
|
|
if(!is_null($inpatient_info->procedure_hospital_fee) && $inpatient_info->procedure_hospital_fee != ''){
|
|
$procedures_hospital_fee_array = @unserialize($inpatient_info->procedure_hospital_fee);
|
|
for ($i=0; $i < count($request->procedure_id) ; $i++) {
|
|
$procedures_hospital_fee_array[] = get_procedure_hospital_fees_func($request->procedure_id[$i], $patient_id);
|
|
}
|
|
$inpatient_info->procedure_hospital_fee = serialize($procedures_hospital_fee_array);
|
|
} else {
|
|
$fresh_procedure_hospital_fee_array = [];
|
|
for ($i=0; $i < count($request->procedure_id); $i++) {
|
|
$fresh_procedure_hospital_fee_array[] = get_procedure_hospital_fees_func($request->procedure_id[$i], $patient_id);
|
|
}
|
|
$inpatient_info->procedure_hospital_fee = serialize($fresh_procedure_hospital_fee_array);
|
|
}
|
|
|
|
// procedure_staff_fee
|
|
if(!is_null($inpatient_info->procedure_staff_fee) && $inpatient_info->procedure_staff_fee != ''){
|
|
$procedures_staff_fee_array = @unserialize($inpatient_info->procedure_staff_fee);
|
|
for ($i=0; $i < count($request->procedure_id) ; $i++) {
|
|
$procedures_staff_fee_array[] = $request->procedure_performance_fee;
|
|
}
|
|
$inpatient_info->procedure_staff_fee = serialize($procedures_staff_fee_array);
|
|
} else {
|
|
$fresh_procedure_staff_fee_array = [];
|
|
for ($i=0; $i < count($request->procedure_id) ; $i++) {
|
|
$fresh_procedure_staff_fee_array[] = $request->procedure_performance_fee;
|
|
}
|
|
$inpatient_info->procedure_staff_fee = serialize($fresh_procedure_staff_fee_array);
|
|
}
|
|
$inpatient_info->updated_by = Auth::id();
|
|
$inpatient_info->save();
|
|
|
|
for ($i=0; $i < count($request->procedure_id) ; $i++) {
|
|
$ward_procedures_record = WardProcedure::firstOrNew(['patient_id' => $patient_id, 'episode_id' => $episode_id, 'procedure_id' => $request->procedure_id[$i], 'performed_by' => $request->surgeon]);
|
|
$ward_procedures_record->patient_id = $patient_id;
|
|
$ward_procedures_record->episode_id = $episode_id;
|
|
$ward_procedures_record->procedure_id = $request->procedure_id[$i];
|
|
$ward_procedures_record->performed_by = $request->surgeon;
|
|
$ward_procedures_record->hospital_fee = get_procedure_hospital_fees_func($request->procedure_id[$i], $patient_id);
|
|
$ward_procedures_record->staff_fee = $request->procedure_performance_fee;
|
|
$ward_procedures_record->ward_id = $inpatient_info->ward_id;
|
|
$ward_procedures_record->created_by = Auth::id();
|
|
$ward_procedures_record->save();
|
|
}
|
|
|
|
$ward_sundries_ids_array = $request->sundries_used;
|
|
$ward_sundries_quantities_array = $request->sundries_quantity_used;
|
|
|
|
if (is_array($ward_sundries_ids_array)) {
|
|
for ($j = 0; $j < count($ward_sundries_ids_array); $j++) {
|
|
// only save if the dispensed drug quantity is not null
|
|
if (!is_null($ward_sundries_quantities_array[$j])) {
|
|
$ward_sundry_dispensations = new WardSundryDispensation;
|
|
$ward_sundry_dispensations->patient_id = $patient_id;
|
|
$ward_sundry_dispensations->episode_id = $episode_id;
|
|
$ward_sundry_dispensations->sundry_id = $ward_sundries_ids_array[$j];
|
|
$ward_sundry_dispensations->quantity_given = $ward_sundries_quantities_array[$j];
|
|
$ward_sundry_dispensations->ward_id = $inpatient_info->ward_id;
|
|
$ward_sundry_dispensations->created_by = Auth::id();
|
|
$ward_sundry_dispensations->save();
|
|
}
|
|
}
|
|
}
|
|
|
|
$extra_items_array = $request->extras_used;
|
|
$extra_costs_array = $request->extras_cost;
|
|
|
|
$ward_extras_income_account = ChartOfAccount::where('slug', 'ward_extras_income_account')->first();
|
|
|
|
if (is_array($extra_items_array)) {
|
|
for ($k = 0; $k < count($extra_items_array); $k++) {
|
|
// only save if the dispensed drug quantity is not null
|
|
if (!is_null($extra_items_array[$k])) {
|
|
$ward_extra = new WardExtra;
|
|
$ward_extra->patient_id = $patient_id;
|
|
$ward_extra->episode_id = $episode_id;
|
|
$ward_extra->extra_item = $extra_items_array[$k];
|
|
$ward_extra->extra_cost = $extra_costs_array[$k];
|
|
$ward_extra->current_chart_of_account = !is_null($ward_extras_income_account) ? $ward_extras_income_account->id : 0;
|
|
$ward_extra->ward_id = $inpatient_info->ward_id;
|
|
$ward_extra->created_by = Auth::id();
|
|
$ward_extra->save();
|
|
}
|
|
}
|
|
}
|
|
} else {
|
|
for ($i=0; $i < count($request->procedure_id) ; $i++) {
|
|
$procedure_performed_id = record_staff_that_has_performed_the_service($patient_id, $episode_id, 1, $request->procedure_id[$i], 0, $request->surgeon);
|
|
|
|
$ordered_procedure = new OrderedProcedure;
|
|
$ordered_procedure->patient_id = $patient_id;
|
|
$ordered_procedure->episode_id = $episode_id;
|
|
$ordered_procedure->procedure_id = $request->procedure_id[$i];
|
|
$ordered_procedure->payment_status = 0;
|
|
$ordered_procedure->performed = 1;
|
|
$ordered_procedure->performed_id = $procedure_performed_id;
|
|
$ordered_procedure->created_by = Auth::id();
|
|
$ordered_procedure->save();
|
|
}
|
|
}
|
|
//}
|
|
|
|
//insert sundries e.g vicryl sutures used into sundries deposit table so that they are billed too
|
|
$sundry_used_array = $request->sundries_used;
|
|
$sundry_quantity_array = $request->sundries_quantity_used;
|
|
|
|
if($inpatient_info){
|
|
$inpatient_sundries = @unserialize($inpatient_info->sundries);
|
|
$sundries_array = isset($inpatient_sundries['sundries']) ? $inpatient_sundries['sundries'] : [];
|
|
$quantity_array = isset($inpatient_sundries['quantity']) ? $inpatient_sundries['quantity'] : [];
|
|
|
|
//add the used sundries from theatre to any exisiting ones to inpatient
|
|
for ($i=0; $i < count($sundry_used_array); $i++) {
|
|
if (!is_null($sundry_used_array[$i])) {
|
|
$sundries_array[] = $sundry_used_array[$i];
|
|
$quantity_array[] = $sundry_quantity_array[$i];
|
|
reduce_ward_stock_with_consumed_quantity($sundry_used_array[$i], $sundry_quantity_array[$i], 2, $theatre_ward_id, $patient_id, $episode_id, null);
|
|
}
|
|
}
|
|
|
|
$unserialized_sundries_array = array(
|
|
"sundries" => $sundries_array,
|
|
"quantity" => $quantity_array
|
|
);
|
|
|
|
$inpatient_info->sundries = serialize($unserialized_sundries_array);
|
|
$inpatient_info->save();
|
|
} else{
|
|
for ($i=0; $i < count($sundry_used_array); $i++) {
|
|
if (!is_null($sundry_used_array[$i])) {
|
|
$ordered_sundry_objects = OrderedSundry::where(['patient_id' => $patient_id, 'episode_id' => $episode_id])->where('sundries_id',$sundry_used_array[$i])->get();
|
|
|
|
if (count($ordered_sundry_objects) > 0) {
|
|
foreach ($ordered_sundry_objects as $sundry_to_update) {
|
|
$sundry_to_update->quantity = $sundry_quantity_array[$i];
|
|
$sundry_to_update->payment_status = 0;
|
|
$sundry_to_update->update();
|
|
}
|
|
} else {
|
|
$ordered_sundry = new OrderedSundry;
|
|
$ordered_sundry->patient_id = $patient_id;
|
|
$ordered_sundry->episode_id = $episode_id;
|
|
$ordered_sundry->sundries_id = $sundry_used_array[$i];
|
|
$ordered_sundry->quantity = $sundry_quantity_array[$i];
|
|
$ordered_sundry->payment_status = 0;
|
|
$ordered_sundry->created_by = Auth::id();
|
|
$ordered_sundry->save();
|
|
}
|
|
|
|
reduce_ward_stock_with_consumed_quantity($sundry_used_array[$i], $sundry_quantity_array[$i], 2, $theatre_ward_id, $patient_id, $episode_id, null);
|
|
}
|
|
}
|
|
}
|
|
|
|
$surgery = Response::json(array('success' => true, 'last_insert_id' => $surgery->id), 200);
|
|
|
|
if ($request->anaesthesia_complete) {
|
|
// update anaesthesia table with surgery_id
|
|
$update = DB::table('anaesthesias')->whereNull('deleted_at')->where('id',$anaesthesia_id )->update([
|
|
"surgery_id" => $surgery->getData()->last_insert_id
|
|
]);
|
|
}
|
|
|
|
flash("Surgery information saved successfully")->success();
|
|
return redirect("/theatre_surgery/");
|
|
|
|
}
|
|
|
|
public function theatre_surgery_quick_store(Request $request){
|
|
|
|
$user = new User();
|
|
|
|
$user->first_name = $request->first_name;
|
|
$user->last_name = $request->last_name;
|
|
$user->username = $request->user_name;
|
|
$user->phone = $request->phone_number;
|
|
$user->position_id = $request->position_id;
|
|
$user->registration_number = $request->registration_number;
|
|
$user->email = $request->email;
|
|
$user->pin = $request->secret_pin;
|
|
$user->security_question_id = $request->security_question;
|
|
$user->security_answer = $request->security_answer;
|
|
|
|
$user->created_by = Auth::id();
|
|
if ($user->save()) {
|
|
$last_inserted_id = $user->id;
|
|
return $last_inserted_id;
|
|
}
|
|
return 'error occurred';
|
|
}
|
|
|
|
public function add_new_theatre_location(Request $request)
|
|
{
|
|
$theatre_location = new TheatreLocation;
|
|
$theatre_location->name = $request->name;
|
|
|
|
$theatre_location->created_by = Auth::id();
|
|
if ($theatre_location->save()) {
|
|
$last_inserted_id = $theatre_location->id;
|
|
return $last_inserted_id;
|
|
}
|
|
return 'error occurred';
|
|
}
|
|
|
|
public function details($id){
|
|
|
|
$surgery = Surgery::find($id);
|
|
$patient_id = $surgery->patient_id;
|
|
$episode_id = $surgery->episode_id;
|
|
|
|
$patient = Patient::find($patient_id);
|
|
$categories = PatientCategory::pluck("name", "id");
|
|
$marital_statuses = MaritalStatus::pluck("name", "id");
|
|
$occupations = Occupation::pluck('name', 'id');
|
|
$drug_categories = DrugCategory::orderBy('name', 'asc')->get();
|
|
$documents = PatientDocument::where('patient_id', $patient_id)->orderBy('created_at', 'desc')->take(2)->get();
|
|
$known_patient_allergies = Allergy::where('patient_id' , $patient_id)->orderBy('created_at','desc')->take(2)->get();
|
|
$known_patient_alerts = Alert::where('patient_id' , $patient_id)->orderBy('created_at','desc')->take(2)->get();
|
|
$drug_categories_array = DrugCategory::pluck('name', 'id');
|
|
$diagnoses = DB::table('diagnoses')->where('available', 1)->whereNull('deleted_at')->orderBy('name')->pluck("name", "id")->prepend('- select -', '');
|
|
|
|
|
|
return view('theatre::theatre_surgeries.detail',compact('patient_id', 'episode_id', 'patient',
|
|
'categories', 'known_patient_allergies', 'drug_categories', 'drug_categories_array',
|
|
'documents', 'marital_statuses', 'occupations', 'surgery', 'known_patient_alerts', 'diagnoses'));
|
|
}
|
|
|
|
/*
|
|
get staff positions from
|
|
*/
|
|
public function get_cadre(Request $request){
|
|
$result = User::where('id', $request->user_id)->first();
|
|
$cadre = get_name($result->position_id, 'id', 'name', 'staff_positions');
|
|
return $cadre;
|
|
}
|
|
|
|
/**
|
|
* Display the specified resource.
|
|
*
|
|
* @param int $id
|
|
* @return \Illuminate\Http\Response
|
|
*/
|
|
public function show($id)
|
|
{
|
|
//
|
|
}
|
|
|
|
/**
|
|
* Show the form for editing the specified resource.
|
|
*
|
|
* @param int $id
|
|
* @return \Illuminate\Http\Response
|
|
*/
|
|
public function edit($id)
|
|
{
|
|
$surgery_record = Surgery::find($id);
|
|
|
|
$patient_id = $surgery_record->patient_id;
|
|
$episode_id = $surgery_record->episode_id;
|
|
$patient = Patient::find($patient_id);
|
|
|
|
$positions = DB::table('staff_positions')->whereNull('deleted_at')->orderBy('name')->pluck('name', 'id');
|
|
$positions->prepend('- select -', '');
|
|
|
|
$security_questions = SecurityQuestion::orderBy('name')->pluck('name', 'id');
|
|
$security_questions->prepend('- select -', '');
|
|
$drug_categories = DB::table('drug_categories')->whereNull('deleted_at')->orderBy('name','asc')->get();
|
|
$roles = Role::pluck('name', 'name')->all();
|
|
|
|
$surgeries = DB::table('surgeries')->whereNull('deleted_at')->where('episode_id', $episode_id)->where('patient_id', $patient_id)->get()->toArray();
|
|
$performed_anaesthesia = DB::table('anaesthesias')->whereNull('deleted_at')->where('episode_id', $episode_id)->where('patient_id', $patient_id)->get()->toArray();
|
|
|
|
$documents = DB::table('patient_documents')->whereNull('deleted_at')->where('patient_id',$patient_id)->orderBy('date_taken','desc')->take(2)->get();
|
|
$categories = DB::table('patient_categories')->where('available', 1)->whereNull('deleted_at')->pluck("name", "id");
|
|
$drug_categories = DB::table('drug_categories')->whereNull('deleted_at')->orderBy('name','asc')->get();
|
|
//allergies and alerts
|
|
$known_patient_allergies = Allergy::where('patient_id' , $patient_id)->orderBy('created_at','desc')->take(2)->get();
|
|
$known_patient_alerts = Alert::where('patient_id' , $patient_id)->orderBy('created_at','desc')->take(2)->get();
|
|
$drug_categories_array = DB::table('drug_categories')->whereNull('deleted_at')->pluck('name', 'id');
|
|
//dropdown options
|
|
$procedures = DB::table('procedures')->whereNull('deleted_at')->orderBy("name","asc")->pluck("name", "id")->prepend('- select -', '');
|
|
$theatre_locations = DB::table('theatre_locations')->whereNull('deleted_at')->orderBy("name","asc")->pluck("name", "id")->prepend('- select -', '');
|
|
$outcomes = DB::table('outcomes')->whereNull('deleted_at')->orderBy("name","asc")->pluck("name", "id")->prepend('- select -', '');
|
|
$users = DB::table('users')->whereNull('deleted_at')->orderBy("first_name","asc")->select("id")->get()->toArray();
|
|
$doctors = [];
|
|
$nursing = [];
|
|
$theatre_in_charge_users = [];
|
|
$all_staff = [];
|
|
foreach ($users as $value){
|
|
$user = User::find($value->id);
|
|
if (!is_null($user)) {
|
|
if ($user->hasRole('Doctors') || $user->hasRole('Doctor')) {
|
|
$doctors[$value->id] = get_full_name($value->id, 'id', 'first_name', 'last_name', 'users');
|
|
}
|
|
if ($user->hasRole('Nursing')) {
|
|
$nursing[$value->id] = get_full_name($value->id, 'id', 'first_name', 'last_name', 'users');
|
|
}
|
|
if ($user->hasRole('Doctors') || $user->hasRole('Nursing - senior ward staff') || $user->hasRole('Doctor') || $user->hasRole('Specialist Nurses') || $user->hasRole('Midwives')) {
|
|
$theatre_in_charge_users[$value->id] = get_full_name($value->id, 'id', 'first_name', 'last_name', 'users');
|
|
}
|
|
$all_staff[$value->id] = get_full_name($value->id, 'id', 'first_name', 'last_name', 'users');
|
|
}
|
|
}
|
|
|
|
$doctors = ['' => '- select -'] + $doctors;
|
|
$nursing = ['' => '- select -'] + $nursing;
|
|
$doctors[0] = "None";
|
|
$nursing[0] = "None";
|
|
$theatre_in_charge_users = ['' => '- select -'] + $theatre_in_charge_users;
|
|
$theatre_in_charge_users[0] = "None";
|
|
$all_staff = ['' => '- select -'] + $all_staff;
|
|
|
|
//$anaesthesia_id
|
|
$anaesthesia = DB::table('anaesthesias')->whereNull('deleted_at')->where('patient_id', $patient_id)->where('episode_id', $episode_id)->first();
|
|
if(!is_null($anaesthesia)){
|
|
$anaesthesia_complete = TRUE;
|
|
}else{
|
|
$anaesthesia_complete = FALSE;
|
|
}
|
|
|
|
$sundries_array = DB::table('sundries')->whereNull('deleted_at')->orderBy("name","asc")->pluck("name", "id")->prepend('- select -', '');
|
|
//get sundries used
|
|
$ordered_sundries = OrderedSundry::where(['patient_id' => $patient_id, 'episode_id' => $episode_id])->get();
|
|
$used_sundries__ids_array = [];
|
|
$used_sundries_quantities_array = [];
|
|
foreach ($ordered_sundries as $order_sundry) {
|
|
$used_sundries__ids_array[] = $order_sundry->sundries_id;
|
|
$used_sundries_quantities_array[] = $order_sundry->quantity;
|
|
}
|
|
|
|
$wards = DB::table('wards')->where('available', 1)->whereNull('deleted_at')->orderBy("name","asc")->pluck("name", "id")->prepend('- select -', '');
|
|
$referrals = DB::table('referral_hospitals')->whereNull('deleted_at')->orderBy("name","asc")->pluck("name", "id")->prepend('- select -', '');
|
|
|
|
$episode_consultation_details = Consultation::where(['patient_id' => $patient_id, 'episode_id' => $episode_id])->first();
|
|
$episode_consultation_outcome = null;
|
|
/*if ($episode_consultation_details) {
|
|
$episode_consultation_outcome = $episode_consultation_details->outcome_id;
|
|
}*/
|
|
$ward_id = null;
|
|
$admission_date = null;
|
|
|
|
if ($episode_consultation_details) {
|
|
$episode_consultation_outcome = $episode_consultation_details->outcome_id;
|
|
if ($episode_consultation_outcome == 1) {
|
|
$inpatient_record = InpatientInfo::where(['patient_id' => $patient_id, 'episode_id' => $episode_id])->first();
|
|
$ward_id = $inpatient_record->ward_id;
|
|
$admission_date = $episode_consultation_details->admitted_on;
|
|
}
|
|
} else {
|
|
$inpatient_record = InpatientInfo::where(['patient_id' => $patient_id, 'episode_id' => $episode_id])->first();
|
|
if ($inpatient_record) {
|
|
$episode_consultation_outcome = $inpatient_record->outcome_id;
|
|
if ($episode_consultation_outcome == 1) {
|
|
$ward_id = $inpatient_record->ward_id;
|
|
$admission_date = $inpatient_record->admitted_on;
|
|
}
|
|
}
|
|
}
|
|
|
|
$clinics = Clinic::orderBy('name')->pluck("name", "id")->toArray();
|
|
$clinics = ['0' => "Don't assign clinic"] + $clinics;
|
|
$users_collection = DB::table('users')->whereNull('deleted_at')->orderBy("first_name","asc")->select("id")->get()->toArray();
|
|
$users = User::orderBy('first_name')->select("id", "first_name", "last_name")->get();
|
|
$diagnoses = Diagnosis::where('available', 1)->orderby('name', 'asc')->pluck("name", "id")->prepend('- select -', '');
|
|
$diagnoses_all = Diagnosis::select('id', 'prompts', 'reference_areas', 'reference_names')->get();
|
|
|
|
return view('theatre::theatre_surgeries.edit',compact('surgery_record','episode_id','patient_id','patient','documents','categories','drug_categories','known_patient_alerts','known_patient_allergies','drug_categories_array','procedures','theatre_locations','outcomes','doctors', 'anaesthesia', 'anaesthesia_complete','positions','roles', 'security_questions', 'surgeries', 'performed_anaesthesia','nursing','sundries_array','all_staff','used_sundries__ids_array','used_sundries_quantities_array','wards','referrals','sundries_array','episode_consultation_details','clinics','users','diagnoses', 'diagnoses_all', 'ward_id', 'admission_date','episode_consultation_outcome'));
|
|
}
|
|
|
|
/**
|
|
* Update the specified resource in storage.
|
|
*
|
|
* @param \Illuminate\Http\Request $request
|
|
* @param int $id
|
|
* @return \Illuminate\Http\Response
|
|
*/
|
|
public function update(Request $request, $id)
|
|
{
|
|
$patient_id = $request->patient_id;
|
|
$episode_id = $request->episode_id;
|
|
|
|
$anaesthesia_id = $request->anaesthesia_id;
|
|
$surgery_id = $request->surgery_id;
|
|
|
|
$procedures = implode(",", $request->procedure_id);
|
|
$surgery_type = $request->surgery_type;
|
|
$surgeon = $request->surgeon;
|
|
$assistant_surgeon = $request->assistant_surgeon;
|
|
$scrub_nurse = $request->scrub_nurse;
|
|
$authorised_swab_check = $request->authorised_swab_check;
|
|
$theatre_location = $request->theatre_location;
|
|
$time_surgery_completed = $request->time_surgery_completed;//change to carbon time format
|
|
$date_surgery_completed = $request->date_surgery_completed; //change to carbon date format
|
|
|
|
$theatre_incharge = $request->theatre_incharge;
|
|
$estimated_blood_loss = $request->estimated_blood_loss;
|
|
$outcome = $request->outcome;
|
|
/*$vicryl_sutures_used = $request->vicryl_sutures_used;
|
|
$other_sutures_used = $request->other_sutures_used;*/
|
|
$other_scrub_staff = $request->other_scrub_staff;
|
|
$comments = $request->comments;
|
|
$staff_id = $request->theatre_incharge;
|
|
|
|
// insert data to surgery table
|
|
$surgery = Surgery::find($surgery_id);
|
|
|
|
$previous_procedure_id = $surgery->procedure_id;
|
|
|
|
$inpatient_info = InpatientInfo::where(['patient_id' => $patient_id,'episode_id' => $episode_id,'discharged' => 0])->orderBy('created_at','desc')->first();
|
|
|
|
switch ($outcome){
|
|
case 1: // Admitted
|
|
$surgery->ward_id_admitted = $request->ward_id;
|
|
$surgery->admitted_on = $request->admitted_on;
|
|
|
|
// check if the patient is currently admitted and just update their status
|
|
if ($inpatient_info) {
|
|
$inpatient_info->ward_id = $request->ward_id;
|
|
$inpatient_info->updated_by = $staff_id;
|
|
$inpatient_info->save();
|
|
} else {
|
|
// admit the patient
|
|
$inpatient = new InpatientInfo;
|
|
$inpatient->patient_id = $patient_id;
|
|
$inpatient->episode_id = $episode_id;
|
|
$inpatient->admitted_on = $request->admitted_on; //Carbon::createFromFormat('d/m/Y', $request->admitted_on)->toDateString();
|
|
$inpatient->ward_id = $request->ward_id;
|
|
$inpatient->primary_diagnosis = "";
|
|
$inpatient->comments = $comments;
|
|
$inpatient->created_by = $staff_id;
|
|
$inpatient->save();
|
|
}
|
|
break;
|
|
case 2: // Discharged
|
|
// discharge the patient if admitted
|
|
discharge_patient_from_ward($patient_id, $episode_id, Auth::id(), date('Y-m-d'));
|
|
break;
|
|
case 3: // Home with Follow up
|
|
// discharge the patient if admitted
|
|
discharge_patient_from_ward($patient_id, $episode_id, Auth::id(), date('Y-m-d'));
|
|
|
|
$surgery->followup_where = $request->followup_where;
|
|
$surgery->followup_when = $request->followup_when;
|
|
|
|
// get current clinic of patient if available
|
|
$episode_information = PatientEpisode::find($episode_id);
|
|
|
|
if ($episode_information->clinic_id){
|
|
$clinic_allocation_id = $episode_information->clinic_id;
|
|
} else {
|
|
$clinic_allocation_id = 0;
|
|
}
|
|
|
|
// save information to the follow-up table
|
|
$appointment = new PatientAppointment();
|
|
$appointment->patient_id = $patient_id;
|
|
$appointment->incharge_id = Auth::id();
|
|
$appointment->clinic_allocation = $clinic_allocation_id;
|
|
$appointment->episode_id = $episode_id;
|
|
$appointment->appointment_date = Carbon::createFromFormat('d/m/Y', $request->followup_when)->toDateString();
|
|
$appointment->appointment_time = "09:00:00";
|
|
$appointment->created_from = "Surgery";
|
|
$appointment->created_by = Auth::id();
|
|
$appointment->updated_by = Auth::id();
|
|
$appointment->save();
|
|
break;
|
|
case 4: // Referred
|
|
$surgery->referred_to = $request->referral_id;
|
|
|
|
// discharge the patient if admitted
|
|
discharge_patient_from_ward($patient_id, $episode_id, Auth::id(), date('Y-m-d'));
|
|
break;
|
|
case 5: // Died
|
|
// discharge the patient if admitted
|
|
discharge_patient_from_ward($patient_id, $episode_id, Auth::id(), date('Y-m-d'));
|
|
break;
|
|
case 6: // Return to ward
|
|
$inpatient_info = InpatientInfo::where(['patient_id' => $patient_id,'episode_id' => $episode_id,'discharged' => 0])->orderBy('created_at','desc')->first();
|
|
if ($inpatient_info) {
|
|
$inpatient_info->outcome_id = 1;
|
|
$inpatient_info->discharged = 0;
|
|
$inpatient_info->update();
|
|
}
|
|
break;
|
|
}
|
|
|
|
if ($request->anaesthesia_complete) {
|
|
$surgery->anaesthesia_id = $anaesthesia_id;
|
|
}
|
|
|
|
//$surgery->episode_id = $episode_id;
|
|
//$surgery->patient_id = $patient_id;
|
|
$surgery->procedure_id = $procedures;
|
|
$surgery->surgery_type = $surgery_type;
|
|
$surgery->surgeon = $surgeon;
|
|
$surgery->assistant_surgeon = $assistant_surgeon;
|
|
$surgery->scrub_nurse = $scrub_nurse;
|
|
$surgery->authorised_swab_check = $authorised_swab_check;
|
|
$surgery->theatre_location = $theatre_location;
|
|
$surgery->time_surgery_completed = $time_surgery_completed;
|
|
$surgery->date_surgery_completed = !is_null($date_surgery_completed) ? Carbon::createFromFormat('d/m/Y', $date_surgery_completed)->toDateString() : null;
|
|
$surgery->theatre_in_charge = $theatre_incharge;
|
|
$surgery->estimated_blood_loss = $estimated_blood_loss;
|
|
$surgery->outcome = $outcome;
|
|
$surgery->other_scrub_staff = $other_scrub_staff;
|
|
/*$surgery->vicryl_sutures_used = $vicryl_sutures_used;
|
|
$surgery->other_sutures_used = $other_sutures_used;*/
|
|
$extras_array = $request->extras_used;
|
|
$extras_cost_array = $request->extras_cost;
|
|
$unserialized_extras_array = array(
|
|
"extras" => $extras_array,
|
|
"cost" => $extras_cost_array
|
|
);
|
|
$surgery->extras_used = serialize($unserialized_extras_array);
|
|
|
|
$sundry_used_array = $request->sundries_used;
|
|
$sundry_quantity_array = $request->sundries_quantity_used;
|
|
$unserialized_sundries_array = array(
|
|
"sundries" => $sundry_used_array,
|
|
"quantity" => $sundry_quantity_array
|
|
);
|
|
$surgery->sundries_used = serialize($unserialized_sundries_array);
|
|
|
|
$surgery->comments = $comments;
|
|
$surgery->created_by = Auth::id();
|
|
$surgery->save();
|
|
|
|
// save the procedure info in inpatient or OPD if anaesthesia is not complete
|
|
$inpatient_info = InpatientInfo::where(['patient_id' => $patient_id,'episode_id' => $episode_id])->orderBy('created_at','desc')->first();
|
|
|
|
if ($inpatient_info){
|
|
//check_if_there_are_exisiting_procedures and add the new ones instead of over riding them
|
|
if(!is_null($inpatient_info->procedures)){
|
|
$unserialized_procedures_array[] = unserialize($inpatient_info->procedures);
|
|
for ($i=0; $i < count($request->procedure_id) ; $i++) {
|
|
if (!in_array($request->procedure_id[$i], $unserialized_procedures_array)) {
|
|
$unserialized_procedures_array[] = $request->procedure_id[$i];
|
|
}
|
|
}
|
|
$inpatient_info->procedures = serialize($unserialized_procedures_array);
|
|
} else {
|
|
$inpatient_info->procedures = serialize($request->procedure_id);
|
|
}
|
|
$inpatient_info->updated_by = Auth::id();
|
|
$inpatient_info->save();
|
|
|
|
for ($i=0; $i < count($request->procedure_id) ; $i++) {
|
|
$ward_procedures_record = WardProcedure::firstOrNew(['patient_id' => $patient_id, 'episode_id' => $episode_id, 'procedure_id' => $request->procedure_id[$i], 'performed_by' => $request->surgeon]);
|
|
$ward_procedures_record->patient_id = $patient_id;
|
|
$ward_procedures_record->episode_id = $episode_id;
|
|
$ward_procedures_record->procedure_id = $request->procedure_id[$i];
|
|
$ward_procedures_record->performed_by = $request->surgeon;
|
|
$ward_procedures_record->hospital_fee = $request->procedure_hospital_fee;
|
|
$ward_procedures_record->staff_fee = $request->procedure_performance_fee;
|
|
$ward_procedures_record->ward_id = $inpatient_info->ward_id;
|
|
$ward_procedures_record->created_by = Auth::id();
|
|
$ward_procedures_record->save();
|
|
}
|
|
} else {
|
|
for ($i=0; $i < count($request->procedure_id) ; $i++) {
|
|
$exisiting_ordered_procedure = OrderedProcedure::where(['patient_id' => $patient_id, 'episode_id' => $episode_id])->where('procedure_id',$request->procedure_id[$i])->first();
|
|
|
|
$ordered_procedure = $exisiting_ordered_procedure ? $exisiting_ordered_procedure : new OrderedProcedure;
|
|
$ordered_procedure->patient_id = $patient_id;
|
|
$ordered_procedure->episode_id = $episode_id;
|
|
$ordered_procedure->procedure_id = $request->procedure_id[$i];
|
|
$ordered_procedure->payment_status = 0;
|
|
$ordered_procedure->performed = 1;
|
|
$ordered_procedure->performed_id = 0;
|
|
$ordered_procedure->created_by = Auth::id();
|
|
$ordered_procedure->save();
|
|
}
|
|
}
|
|
|
|
//insert sundries e.g vicryl sutures used into sundries deposit table so that they are billed too
|
|
$sundry_used_array = $request->sundries_used;
|
|
$sundry_quantity_array = $request->sundries_quantity_used;
|
|
|
|
if($inpatient_info){
|
|
|
|
$inpatient_sundries = @unserialize($inpatient_info->sundries);
|
|
$sundries_array = isset($inpatient_sundries['sundries']) ? $inpatient_sundries['sundries'] : [];
|
|
$quantity_array = isset($inpatient_sundries['quantity']) ? $inpatient_sundries['quantity'] : [];
|
|
|
|
//add the used sundries from theatre to any exisiting ones to inpatient
|
|
for ($i=0; $i < count($sundry_used_array); $i++) {
|
|
if (!is_null($sundry_used_array[$i])) {
|
|
$sundries_array[] = $sundry_used_array[$i];
|
|
$quantity_array[] = $sundry_quantity_array[$i];
|
|
}
|
|
}
|
|
|
|
$unserialized_sundries_array = array(
|
|
"sundries" => $sundries_array,
|
|
"quantity" => $quantity_array
|
|
);
|
|
|
|
$inpatient_info->sundries = serialize($unserialized_sundries_array);
|
|
$inpatient_info->save();
|
|
} else{
|
|
for ($i=0; $i < count($sundry_used_array); $i++) {
|
|
if (!is_null($sundry_used_array[$i])) {
|
|
$ordered_sundry_objects = OrderedSundry::where(['patient_id' => $patient_id, 'episode_id' => $episode_id])->where('sundries_id',$sundry_used_array[$i])->get();
|
|
|
|
if (count($ordered_sundry_objects) > 0) {
|
|
foreach ($ordered_sundry_objects as $sundry_to_update) {
|
|
$sundry_to_update->quantity = $sundry_quantity_array[$i];
|
|
$sundry_to_update->payment_status = 0;
|
|
$sundry_to_update->update();
|
|
}
|
|
} else {
|
|
$ordered_sundry = new OrderedSundry;
|
|
$ordered_sundry->patient_id = $patient_id;
|
|
$ordered_sundry->episode_id = $episode_id;
|
|
$ordered_sundry->sundries_id = $sundry_used_array[$i];
|
|
$ordered_sundry->quantity = $sundry_quantity_array[$i];
|
|
$ordered_sundry->payment_status = 0;
|
|
$ordered_sundry->created_by = Auth::id();
|
|
$ordered_sundry->save();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
$surgery = Response::json(array('success' => true, 'last_insert_id' => $surgery->id), 200);
|
|
|
|
if ($request->anaesthesia_complete) {
|
|
// update anaesthesia table with surgery_id
|
|
$update = DB::table('anaesthesias')->where('id',$anaesthesia_id )->update([
|
|
"surgery_id" => $surgery->getData()->last_insert_id
|
|
]);
|
|
}
|
|
|
|
flash("Surgery information has been updated successfully")->success();
|
|
return redirect("patient_episodes");
|
|
}
|
|
|
|
/**
|
|
* Remove the specified resource from storage.
|
|
*
|
|
* @param int $id
|
|
* @return \Illuminate\Http\Response
|
|
*/
|
|
public function destroy($id)
|
|
{
|
|
//
|
|
}
|
|
|
|
public function drugs_stock_sheet(Request $request)
|
|
{
|
|
$theatre_ward_id = get_name("theatre", "slug", "id", "wards");
|
|
|
|
if (!is_integer($theatre_ward_id)) {
|
|
flash('Theatre ward not registered')->error();
|
|
return redirect()->back()->withInput();
|
|
}
|
|
|
|
$ward_stock_records = WardStock::where(['ward_id' => $theatre_ward_id, 'item_type' => 1])->get();
|
|
|
|
return view('theatre::theatre_surgeries.drugs_stock_sheet',compact('ward_stock_records', 'theatre_ward_id'));
|
|
}
|
|
|
|
public function update_drugs_stock_sheet(Request $request)
|
|
{
|
|
$theatre_ward_id = $request->theatre_ward_id;
|
|
$drugs_ids_array = $request->drug_id;
|
|
$quantity_array = $request->quantity;
|
|
|
|
for ($i=0; $i < count($drugs_ids_array); $i++) {
|
|
$drug_ward_stock = WardStock::where(['ward_id' => $theatre_ward_id, 'item_type' => 1, 'item_id' => $drugs_ids_array[$i]])->first();
|
|
$drug_ward_stock->ward_item_stock = $quantity_array[$i];
|
|
$drug_ward_stock->update();
|
|
}
|
|
|
|
return redirect('theatre_drugs_stock_sheet');
|
|
}
|
|
|
|
public function sundries_stock_sheet(Request $request)
|
|
{
|
|
$theatre_ward_id = get_name("theatre", "slug", "id", "wards");
|
|
|
|
if (!is_integer($theatre_ward_id)) {
|
|
flash('Theatre ward not registered')->error();
|
|
return redirect()->back()->withInput();
|
|
}
|
|
|
|
$ward_stock_records = WardStock::where(['ward_id' => $theatre_ward_id, 'item_type' => 2])->get();
|
|
|
|
return view('theatre::theatre_surgeries.sundries_stock_sheet',compact('ward_stock_records', 'theatre_ward_id'));
|
|
}
|
|
|
|
public function update_sundries_stock_sheet(Request $request)
|
|
{
|
|
//$items_array
|
|
$theatre_ward_id = $request->theatre_ward_id;
|
|
$sundry_ids_array = $request->sundry_id;
|
|
$quantity_array = $request->quantity;
|
|
|
|
for ($i=0; $i < count($sundry_ids_array); $i++) {
|
|
$sundry_ward_stock = WardStock::where(['ward_id' => $theatre_ward_id, 'item_type' => 2, 'item_id' => $sundry_ids_array[$i]])->first();
|
|
$sundry_ward_stock->ward_item_stock = $quantity_array[$i];
|
|
$sundry_ward_stock->update();
|
|
}
|
|
|
|
return redirect('theatre_sundries_stock_sheet');
|
|
}
|
|
|
|
public function quick_add_procedure(Request $request)
|
|
{
|
|
// get all current price lists
|
|
$price_list = PriceListCategories::withTrashed()->select('id')->get();
|
|
$price_list_category = [];
|
|
$price_list_price = [];
|
|
|
|
foreach ($price_list as $record){
|
|
array_push($price_list_category, $record->id);
|
|
array_push($price_list_price, $request->non_insured_price);
|
|
}
|
|
|
|
$logged_in_user_id = Auth::user()->id;
|
|
$procedure = new Procedure;
|
|
|
|
$procedure->name = $request->name;
|
|
$procedure->non_insured_price = $request->non_insured_price;
|
|
$procedure->insured_price = $request->insured_price;
|
|
$procedure->insurance = $request->insurance;
|
|
$procedure->price_list_category = implode(",", $price_list_category);
|
|
$procedure->price_list_price = implode(",", $price_list_price);
|
|
$procedure->account_id = $request->account_id;
|
|
$procedure->category_id = $request->category;
|
|
$procedure->hmis_number = $request->hmis_number;
|
|
/*== hmis stuff =====*/
|
|
$procedure->hmis_no_outpatient = is_array($request->hmis_no_outpatient) ? implode(",", $request->hmis_no_outpatient) : "";
|
|
$procedure->hmis_category = is_array($request->hmis_category) ? implode(",", $request->hmis_category) : "";
|
|
$procedure->hmis_no_inpatient = $request->hmis_no_inpatient;
|
|
$procedure->hmis_category_inpatient = $request->hmis_category_inpatient;
|
|
/*===================*/
|
|
$procedure->created_by = $logged_in_user_id;
|
|
$procedure->updated_by = $logged_in_user_id;
|
|
|
|
if ($procedure->save()) {
|
|
$last_inserted_id = $procedure->id;
|
|
return $last_inserted_id;
|
|
}
|
|
return 'error occurred';
|
|
}
|
|
|
|
public function surgery_print($surgery_id)
|
|
{
|
|
$surgery = Surgery::withTrashed()->find($surgery_id);
|
|
if (!$surgery) {
|
|
return redirect()->back();
|
|
}
|
|
|
|
$patient_id = $surgery->patient_id;
|
|
$episode_id = $surgery->episode_id;
|
|
|
|
$patient = Patient::find($patient_id);
|
|
$hospitalInfo = DB::table('hospital_information')->find(1);
|
|
$anaesthesia = Anaesthesia::where(['patient_id' => $patient_id, 'episode_id' => $episode_id])->first();
|
|
$diagnoses = DB::table('diagnoses')->where('available', 1)->whereNull('deleted_at')->orderBy('name')->pluck("name", "id")->prepend('- select -', '');
|
|
|
|
$data = [
|
|
'patient' => $patient,
|
|
'patient_id' => $patient_id,
|
|
'episode_id' => $episode_id,
|
|
'hospitalInfo' => $hospitalInfo,
|
|
'diagnoses' => $diagnoses,
|
|
'anaesthesia' => $anaesthesia,
|
|
'surgery' => $surgery
|
|
];
|
|
|
|
$pdf = SnappyPDF::loadView('theatre::theatre_surgeries/surgery_print', $data)
|
|
->setOrientation('portrait')
|
|
->setOption('margin-bottom', 7)
|
|
->setOption('margin-top', 5)
|
|
->setOption('footer-html', '<i>Stre@mline</i>');
|
|
|
|
|
|
return $pdf->inline('Surgery Details' . date(" d-m-y h:ia") . '.pdf');
|
|
}
|
|
}
|