Import latest app updates from streamline

An updated set of source files and initialization was provided by streamline to
address issues observed during initial testing. These files have been updated in
order to generate a new set of app images.
This commit is contained in:
2024-04-11 11:16:51 -07:00
parent cb4c6b4c1a
commit 4a89356390
10435 changed files with 107737 additions and 1220538 deletions
File diff suppressed because it is too large Load Diff
@@ -37,8 +37,17 @@ class NutritionController extends Controller {
foreach($data as $item) {
$split_item = explode(',', $item);
$lengths[] = +$split_item[0];
$formatted_data[+$split_item[0]] = [+$split_item[1], +$split_item[2], +$split_item[3], +$split_item[4], +str_replace(["\r", "\n"], "", $split_item[5])];
$lengths[] = intval($split_item[0]);
$formatted_data[intval($split_item[0])] = [intval($split_item[1]), intval($split_item[2]), intval($split_item[3]), intval($split_item[4]), intval(str_replace(["\r", "\n"], "", $split_item[5]))];
}
// check if height is out of bounds
if ($height < $lengths[0] || $height > $lengths[count($lengths) - 1]) {
$text = "Nutrition Status Not Available";
$reason = "Height is out of range";
$text_color = "red";
return $text . "&&&&" . $reason . "&&&&" . $text_color;
}
$reference_height = get_closest_element_in_array($lengths, $height);
@@ -82,8 +91,8 @@ class NutritionController extends Controller {
foreach($data as $item) {
$split_item = explode(',', $item);
$ages_in_months[] = +$split_item[0];
$formatted_data[+$split_item[0]] = [+$split_item[1], +$split_item[2], +$split_item[3], +$split_item[4], +str_replace(["\r", "\n"], "", $split_item[5])];
$ages_in_months[] = intval($split_item[0]);
$formatted_data[intval($split_item[0])] = [intval($split_item[1]), intval($split_item[2]), intval($split_item[3]), intval($split_item[4]), intval(str_replace(["\r", "\n"], "", $split_item[5]))];
}
$reference_age = get_closest_element_in_array($ages_in_months, $age_diff_months);
File diff suppressed because it is too large Load Diff
@@ -80,39 +80,40 @@ class PatientDocumentController extends Controller {
/**
* Store a newly created resource in storage.
*
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Http\Response
*/
public function store(Request $request) {
$validator = Validator::make($request->all(), [
'documenttitle' => 'required',
request()->validate([
'documenttitle' => 'required'
]);
if ($validator->fails()) {
$string = "";
foreach ($validator->errors()->getMessages() as $item) {
$string .= "{$item[0]}<br>";
}
return back()->withErrors($validator)->withInput();
$patient_document = new PatientDocument;
$patient_document->patient_id = session()->get('patient_id');
$patient_document->episode_id = session()->get('episode_id');
$patient_document->title = $request->documenttitle;
$patient_document->description = $request->description;
if ($request->file('document')->isValid()) {
$file = $request->file('document');
$store = public_path() . '/uploads/patient-documents/';
$file_name = $file->getClientOriginalName();
$file->move($store, $file_name);
$patient_document->path = public_path() . '/uploads/patient-documents/' . $file_name;
}
$patient_document->date_taken = \Carbon\Carbon::createFromFormat('d/m/Y', $request->documentdate)->toDateString();
$patient_document->created_by = auth()->user()->id;
$patient_document->úpdated_by = auth()->user()->id;
$patient_document->save();
flash("document has been added.")->success();
// redirect to consultation or patient_episode page depending on where the user is from
if (session()->has('redirect_to_consultation')) {
$url = session()->get('redirect_to_consultation');
session()->forget('redirect_to_consultation');
return redirect($url);
} else {
$patient_document = new PatientDocument;
$patient_document->patient_id = session()->get('patient_id');
$patient_document->episode_id = session()->get('episode_id');
$patient_document->title = $request->documenttitle;
$patient_document->description = $request->description;
if ($request->file('document')->isValid()) {
$file = $request->file('document');
$store = public_path() . '/uploads/patient-documents/';
$file_name = $file->getClientOriginalName();
$file->move($store, $file_name);
$patient_document->path = public_path() . '/uploads/patient-documents/' . $file_name;
}
$patient_document->date_taken = \Carbon\Carbon::createFromFormat('d/m/Y', $request->documentdate)->toDateString();
$patient_document->created_by = auth()->user()->id;
$patient_document->úpdated_by = auth()->user()->id;
$patient_document->save();
flash("document has been added.")->success();
return redirect('/patient_episodes');
return redirect("/patient_episodes");
}
}
@@ -9,6 +9,9 @@ use Illuminate\Http\Request;
use Illuminate\Support\Facades\Log;
use Streamline\Models\Alert;
use Streamline\Models\Allergy;
use Streamline\Models\EmergencySign;
use Streamline\Models\EyeClinicBaseExamRefraction;
use Streamline\Models\EyeClinicMainExam;
use Streamline\Models\HospitalInformation;
use Streamline\Models\Investigation;
use Streamline\Models\InvestigationResults;
@@ -27,7 +30,10 @@ use Illuminate\Support\Facades\Validator;
use Illuminate\Support\Facades\DB;
use Carbon\Carbon;
use Illuminate\Support\Facades\Session;
use Streamline\Models\PrioritySign;
use Streamline\Models\ServiceDeposit;
use Streamline\Models\SlitLampTestArea;
use Streamline\Models\SlitLampTestAreaValue;
use Streamline\Models\StaffPerformedService;
use Streamline\Models\Sundry;
use Streamline\Models\Treatment;
@@ -38,9 +44,11 @@ use Streamline\Models\Consultation;
use Streamline\Models\OrderedSundry;
use Streamline\Models\Services;
class PatientEpisodeController extends Controller {
class PatientEpisodeController extends Controller
{
public function __construct() {
public function __construct()
{
$this->middleware('auth');
}
@@ -49,15 +57,16 @@ class PatientEpisodeController extends Controller {
*
* @return \Illuminate\Http\Response
*/
public function index() {
public function index()
{
$patient_id = session()->get('patient_id');
$patient_episodes = DB::table('patient_episodes')
->where(['patient_id' => $patient_id])
->whereNull('deleted_at')
->orderBy('id', 'desc')
->get();
->where(['patient_id' => $patient_id])
->whereNull('deleted_at')
->orderBy('id', 'desc')
->get();
$patient = Patient::where(['id' => $patient_id])->first();
$categories = DB::table('patient_categories')->where('available', 1)->pluck("name", "id");
$marital_statuses = DB::table('marital_statuses')->pluck("name", "id");
@@ -79,33 +88,33 @@ class PatientEpisodeController extends Controller {
//$special_clinics = DB::table('clinics')->where('slug', '!=', 'general')->pluck("name", "id")->prepend('GENERAL OPD', 'general_opd')->prepend('- select -', '');
$special_clinics = DB::table('clinics')->where('available', 1)->whereNull('deleted_at')->pluck("name", "id")->prepend('- select -', '');
$wards = DB::table('wards')->where('available', 1)->whereNull('deleted_at')->pluck("name", "id")->prepend('- select -', '');
$users_collection = DB::table('users')->orderBy("first_name","asc")->select("id")->get()->toArray();
$users_collection = DB::table('users')->orderBy("first_name", "asc")->select("id")->get()->toArray();
$users_array = [];
foreach ($users_collection as $value){
foreach ($users_collection as $value) {
$user = User::find($value->id);
if (!is_null($user)) {
if ($user->hasRole('Doctors') || $user->hasRole('Doctor')) {
$consultation_records = DB::table('services')
->join('staff_payment_configurations','staff_payment_configurations.item_id', '=', 'services.id')
->where('services.item_type', 'Consultation')
->where('staff_payment_configurations.user_id',$value->id)
->where('staff_payment_configurations.item_category',3)
->whereNull('staff_payment_configurations.deleted_at')
->orderBy('staff_payment_configurations.created_at','asc')
->select('services.*')
->get();
->join('staff_payment_configurations', 'staff_payment_configurations.item_id', '=', 'services.id')
->where('services.item_type', 'Consultation')
->where('staff_payment_configurations.user_id', $value->id)
->where('staff_payment_configurations.item_category', 3)
->whereNull('staff_payment_configurations.deleted_at')
->orderBy('staff_payment_configurations.created_at', 'asc')
->select('services.*')
->get();
foreach ($consultation_records as $record) {
$price_list_id = is_patient_category_attached_to_price_list($patient_id);
if ($price_list_id) {
$users_consultation_fee = get_price_list_category_price($price_list_id, 6, $record->id);
} else{
} else {
$users_consultation_fee = $record->non_insured_price;
}
//concatnate the service_record_id with the users id to form the key for the array
$users_array[$record->id."__".$value->id] = get_full_name($value->id, 'id', 'first_name', 'last_name', 'users')." (".$record->name." Fee: ".ugandan_shillings($users_consultation_fee).")";
$users_array[$record->id . "__" . $value->id] = get_full_name($value->id, 'id', 'first_name', 'last_name', 'users') . " (" . $record->name . " Fee: " . ugandan_shillings($users_consultation_fee) . ")";
}
}
}
@@ -119,7 +128,8 @@ class PatientEpisodeController extends Controller {
* Show the form for creating a new resource.
*
*/
public function create() {
public function create()
{
//
}
@@ -127,7 +137,8 @@ class PatientEpisodeController extends Controller {
* Store a newly created resource in storage.
*
*/
public function store(Request $request) {
public function store(Request $request)
{
//
}
@@ -135,7 +146,8 @@ class PatientEpisodeController extends Controller {
* Display the specified resource.
*
*/
public function show($id) {
public function show($id)
{
//
}
@@ -143,18 +155,20 @@ class PatientEpisodeController extends Controller {
* Show the form for editing the specified resource.
*
*/
public function edit($id) {
public function edit($id)
{
//
}
public function update(Request $request, $id) {
public function update(Request $request, $id)
{
/* Update Claim Number */
$episode = PatientEpisode::find($id);
$episode->claim_number = $request->claim_number;
$episode->save();
if(session()->get('edit_claim_number') == 'patient_home'){
if (session()->get('edit_claim_number') == 'patient_home') {
return redirect()->route('patient_episodes.index');
}else{
} else {
return redirect()->route('patient_finance.home');
}
}
@@ -163,7 +177,8 @@ class PatientEpisodeController extends Controller {
* Remove the specified resource from storage.
*
*/
public function destroy($id) {
public function destroy($id)
{
//
}
@@ -171,11 +186,13 @@ class PatientEpisodeController extends Controller {
* Create new episode for a patient.
*
*/
public function create_episode(Request $request) {
public function create_episode(Request $request)
{
$logged_in_user_id = Auth()->user()->id;
$episode = new PatientEpisode;
$episode->patient_id = $request->patient_id;
$episode->clinic_id = get_default_hospital_clinic();
$episode->created_by = $logged_in_user_id;
$episode->updated_by = $logged_in_user_id;
@@ -206,7 +223,8 @@ class PatientEpisodeController extends Controller {
* @param int $id
* @return \Illuminate\Http\Response
*/
public function set_patient_id($id) {
public function set_patient_id($id)
{
session()->put('patient_id', $id);
return redirect('/patient_episodes/');
@@ -218,7 +236,8 @@ class PatientEpisodeController extends Controller {
* @param int $id
* @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
*/
public function route_patient_episode(Request $request) {
public function route_patient_episode(Request $request)
{
//set session for episode_id
session()->put('episode_id', $request->episode_id);
@@ -226,82 +245,63 @@ class PatientEpisodeController extends Controller {
switch ($request->submit) {
case 'triage':
session()->put('triage_without_etat', 0);
return redirect('/triage/');
break;
case 'triage_without_etat':
return redirect('/triage/create_without_etat');
break;
session()->put('triage_without_etat', 1);
return redirect('/triage/');
case 'investigations':
return redirect('/investigations/investigations_review');
break;
case 'consultation':
if ($is_patient_allowed_to_do_consultation == false) {
session()->put('consultation_not_paid', 'consultation_not_paid');
return redirect()->back()->withInput();
}
session()->put('consultation_with_notes', 0);
return redirect('/consultation/route');
break;
case 'consultation_with_notes':
if ($is_patient_allowed_to_do_consultation == false) {
session()->put('consultation_not_paid', 'consultation_not_paid');
return redirect()->back()->withInput();
}
return redirect('/consultation/create_with_notes');
break;
session()->put('consultation_with_notes', 1);
return redirect('/consultation/route');
case 'procedure':
return redirect('/order_procedures');
break;
case 'sundries':
return redirect('/order_sundries');
break;
case 'create_anaesthetics':
return redirect('anaesthetics/create');
break;
case 'create_surgery':
return redirect('theatre_surgery/create');
break;
case 'anaesthetics_history':
return redirect('anaesthetics/history');
break;
case 'surgery_index':
return redirect('theatre_surgery');
break;
case 'inpatient-sheet-button':
case 'maternity_summary':
return redirect('in_patient_sheet');
break;
case 'inpatient_billing':
return redirect('inpatient_billing');
break;
case 'patient_document':
return redirect('patient_documents/create');
break;
case 'death_report_btn':
return redirect('reports/nira/death');
break;
case 'eye_clinic':
return redirect('/eye_clinic/');
break;
case 'drug_refill':
session()->forget('alter_episode_id');
session()->forget('alter_patient_id');
return redirect('drug_refill');
break;
case 'services':
return redirect('order_services');
break;
case 'edit_claim_number':
session()->put(['edit_claim_number' => 'patient_home']);
return redirect('edit_claim_number');
break;
case 'prescription':
session()->forget('alter_episode_id');
session()->forget('alter_patient_id');
return redirect('/prescriptions/create/');
break;
case 'record_all_items':
return redirect('record_staff_service_performance');
break;
case 'maternity_admission':
return redirect('maternity_inpatient_sheet');
case 'delivery_record':
@@ -310,19 +310,29 @@ class PatientEpisodeController extends Controller {
return redirect('/reports/nira/birth');
case 'inpatient_attendant_pass':
return redirect('inpatient_attendant_pass');
break;
case 'main_exam':
return redirect('/eye_clinic/main_exam_route');
case 'base_refraction_exam':
return redirect('/eye_clinic/base_exam_refraction');
case 'eye_glasses':
return redirect('/eye_glasses/order');
case 'treatment_sheet':
session()->put(['treatment_sheet_route' => 'patient_home']);
return redirect('treatment_sheet/view');
default:
return redirect('/patient_episodes/');
}
}
public function edit_claim_number() {
public function edit_claim_number()
{
$episode_id = session()->get('episode_id');
$episode = PatientEpisode::find($episode_id);
return view('patients::patient_episodes.edit_claim_number', compact('episode', 'episode_id'));
}
public function internal_clinic_transfer($id) {
public function internal_clinic_transfer($id)
{
// get triage id
$triage = Triage::where('episode_id', $id)->first();
$consultation = Consultation::where('episode_id', $id)->first();
@@ -330,20 +340,21 @@ class PatientEpisodeController extends Controller {
if ($triage) {
if ($consultation) {
return $triage->id . "," . $triage->clinic_allocation . "," . get_name($triage->clinic_allocation, 'id', 'name', 'clinics') . ",". $consultation->consultation_done_by. ",". $triage->patient_id;
return $triage->id . "," . $triage->clinic_allocation . "," . get_name($triage->clinic_allocation, 'id', 'name', 'clinics') . "," . $consultation->consultation_done_by . "," . $triage->patient_id;
}
return $triage->id . "," . $triage->clinic_allocation . "," . get_name($triage->clinic_allocation, 'id', 'name', 'clinics'). ",". 0 . ",". $triage->patient_id; //no doctor was allocated so it is zero
return $triage->id . "," . $triage->clinic_allocation . "," . get_name($triage->clinic_allocation, 'id', 'name', 'clinics') . "," . 0 . "," . $triage->patient_id; //no doctor was allocated so it is zero
} elseif ($episode_details && !is_null($episode_details->clinic_id)) {
if ($consultation) {
return 0 . "," . $episode_details->clinic_id . "," . get_name($episode_details->clinic_id, 'id', 'name', 'clinics') . ",". $consultation->consultation_done_by. ",". $episode_details->patient_id;
return 0 . "," . $episode_details->clinic_id . "," . get_name($episode_details->clinic_id, 'id', 'name', 'clinics') . "," . $consultation->consultation_done_by . "," . $episode_details->patient_id;
}
return 0 . "," . $episode_details->clinic_id . "," . get_name($episode_details->clinic_id, 'id', 'name', 'clinics') . ",". 0 . ",". $episode_details->patient_id;
return 0 . "," . $episode_details->clinic_id . "," . get_name($episode_details->clinic_id, 'id', 'name', 'clinics') . "," . 0 . "," . $episode_details->patient_id;
} else {
return 0;
}
}
public function save_internal_clinic_transfer(Request $request) {
public function save_internal_clinic_transfer(Request $request)
{
$transfered_to_doctor = null;
$transfered_from_doctor = null;
@@ -384,7 +395,7 @@ class PatientEpisodeController extends Controller {
}
if ($request->transfer_to_doctor) {
$consultation = Consultation::where(['patient_id'=> $patient_id, 'episode_id' => $episode_id])->first();
$consultation = Consultation::where(['patient_id' => $patient_id, 'episode_id' => $episode_id])->first();
if ($consultation) {
// first, check if there is a previously ordered service attached to current doctor
$already_ordered_service = OrderedService::where('performed', 1)
@@ -416,8 +427,14 @@ class PatientEpisodeController extends Controller {
$consultation_record->save();
// create new ordered service record
$service_performed_id = record_staff_that_has_performed_the_service($patient_id, $episode_id, 3,
$allocated_service_id, 0, $request->transfer_to_doctor);
$service_performed_id = record_staff_that_has_performed_the_service(
$patient_id,
$episode_id,
3,
$allocated_service_id,
0,
$request->transfer_to_doctor
);
$service_order = new OrderedService;
$service_order->patient_id = $patient_id;
@@ -441,7 +458,8 @@ class PatientEpisodeController extends Controller {
}
}
public function select_patient_create_session_variables(Request $request) {
public function select_patient_create_session_variables(Request $request)
{
if (isset($request->ward_id)) {
session()->put(['ward_id' => $request->ward_id]);
session()->put(['date' => $request->date]);
@@ -477,10 +495,10 @@ class PatientEpisodeController extends Controller {
session()->put(['episode_id' => $last_inserted_id]);
flash("Patient has been allocated to ".$clinic_name)->success();
flash("Patient has been allocated to " . $clinic_name)->success();
$clinic_slug = get_name($clinic_id, "id", "slug", "clinics");
if ($clinic_slug == "art"){
if ($clinic_slug == "art") {
//return redirect("hiv_menu");
}
@@ -517,6 +535,7 @@ class PatientEpisodeController extends Controller {
$episode = new PatientEpisode;
$episode->patient_id = $request->patient_id;
$episode->clinic_id = get_default_hospital_clinic();
$episode->created_by = $logged_in_user_id;
$episode->updated_by = $logged_in_user_id;
$ward_id = $request->admission_ward_id;
@@ -538,7 +557,7 @@ class PatientEpisodeController extends Controller {
$inpatient->created_at = Carbon::now();
$inpatient->save();
flash("Patient admitted in ".$ward_name)->success();
flash("Patient admitted in " . $ward_name)->success();
return redirect('/patient_episodes/');
} catch (QueryException $e) {
$errorCode = $e->errorInfo[1];
@@ -549,7 +568,8 @@ class PatientEpisodeController extends Controller {
}
}
public function admit_patient_with_episode(Request $request) {
public function admit_patient_with_episode(Request $request)
{
$ward_id = $request->admission_ward_id;
$admitted_on = $request->ward_admission_date;
$ward_name = get_name($ward_id, 'id', 'name', 'wards');
@@ -564,7 +584,7 @@ class PatientEpisodeController extends Controller {
//$inpatient->created_at = Carbon::now();
$inpatient->save();
flash("The patient has been admitted in ".$ward_name)->success();
flash("The patient has been admitted in " . $ward_name)->success();
return redirect('/patient_episodes/');
}
@@ -580,6 +600,7 @@ class PatientEpisodeController extends Controller {
$episode = new PatientEpisode;
$episode->patient_id = $request->patient_id;
$episode->clinic_id = get_default_hospital_clinic();
$episode->created_by = $logged_in_user_id;
$episode->updated_by = $logged_in_user_id;
@@ -590,7 +611,7 @@ class PatientEpisodeController extends Controller {
session()->put(['episode_id' => $last_inserted_id]);
flash("Patient has been allocated to ".$allocated_persons_name)->success();
flash("Patient has been allocated to " . $allocated_persons_name)->success();
/* create a record in consultations table attached to allocated doctor */
$consultation_record = new Consultation;
@@ -602,8 +623,14 @@ class PatientEpisodeController extends Controller {
$consultation_record->save();
// create new ordered service record
$service_performed_id = record_staff_that_has_performed_the_service($episode->patient_id, $last_inserted_id, 3,
$allocated_service_id, 0, $allocated_user_id);
$service_performed_id = record_staff_that_has_performed_the_service(
$episode->patient_id,
$last_inserted_id,
3,
$allocated_service_id,
0,
$allocated_user_id
);
$service_order = new OrderedService;
$service_order->patient_id = $episode->patient_id;
@@ -667,8 +694,14 @@ class PatientEpisodeController extends Controller {
$consultation_record->save();
// create new ordered service record
$service_performed_id = record_staff_that_has_performed_the_service($episode->patient_id, $last_inserted_id, 3,
$allocated_service_id, 0, $allocated_user_id);
$service_performed_id = record_staff_that_has_performed_the_service(
$episode->patient_id,
$last_inserted_id,
3,
$allocated_service_id,
0,
$allocated_user_id
);
$service_order = new OrderedService;
$service_order->patient_id = $episode->patient_id;
@@ -690,7 +723,7 @@ class PatientEpisodeController extends Controller {
/**********************/
$clinic_slug = get_name($clinic_id, "id", "slug", "clinics");
if ($clinic_slug == "art"){
if ($clinic_slug == "art") {
//return redirect("hiv_menu");
}
@@ -712,7 +745,7 @@ class PatientEpisodeController extends Controller {
session()->put(['episode_id' => $last_inserted_id]);
flash("Patient has been allocated to ".$allocated_persons_name)->success();
flash("Patient has been allocated to " . $allocated_persons_name)->success();
return redirect('/patient_episodes/');
} catch (QueryException $e) {
@@ -724,11 +757,13 @@ class PatientEpisodeController extends Controller {
}
}
public function create_episode_with_lab_self_request(Request $request) {
public function create_episode_with_lab_self_request(Request $request)
{
$logged_in_user_id = auth()->user()->id;
$episode = new PatientEpisode;
$episode->patient_id = $request->patient_id;
$episode->clinic_id = get_default_hospital_clinic();
$episode->episode_type = 1; //self lab request episode
$episode->created_by = $logged_in_user_id;
$episode->updated_by = $logged_in_user_id;
@@ -748,9 +783,24 @@ class PatientEpisodeController extends Controller {
}
}
public function episode_summary($episode_id) {
public function episode_summary($episode_id)
{
$patient_id = session()->get('patient_id');
if(is_eye_module_enabled() && is_patient_in_eye_clinic($episode_id)) {
$main_exam = EyeClinicMainExam::where(['patient_id' => $patient_id, 'episode_id' => $episode_id])->first();
$base_exam = EyeClinicBaseExamRefraction::where(['patient_id' => $patient_id, 'episode_id' => $episode_id])->first();
$slit_lamp_test_areas = SlitLampTestArea::all();
$slit_lamp_test_area_values = SlitLampTestAreaValue::pluck('name', 'id')->toArray();
$slit_lamp_test_area_ids = SlitLampTestAreaValue::pluck('id')->toArray();
} else {
$main_exam = false;
$base_exam = false;
$slit_lamp_test_areas = [];
$slit_lamp_test_area_values = [];
$slit_lamp_test_area_ids = [];
}
$priority_signs = $emergent_signs =[];
$patient = DB::table('patients')->find(session()->get('patient_id'));
$episode = PatientEpisode::find($episode_id);
$hospital_information = HospitalInformation::find(1);
@@ -778,6 +828,9 @@ class PatientEpisodeController extends Controller {
// get all results
$investigation_results_order_ids = InvestigationResults::pluck('order_id', 'id')->toArray();
$dateBorn = \Carbon\Carbon::parse($patient->date_of_birth);
$years = $dateBorn->diffInYears();
//triage details
$triage = null;
if ($episode && $episode->triage_id) {
@@ -786,6 +839,7 @@ class PatientEpisodeController extends Controller {
// get all symptoms
$symptoms = DB::table('symptoms')->where('available', 1)->pluck("name", "id");
foreach ($ordered_investigations as $investigation) {
$investigation_ids = explode(",", $investigation->investigation_id);
$inpatient_status = explode(",", $investigation->for_inpatient);
@@ -812,6 +866,13 @@ class PatientEpisodeController extends Controller {
$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 {
@@ -833,6 +894,13 @@ class PatientEpisodeController extends Controller {
$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;
}
@@ -851,6 +919,13 @@ class PatientEpisodeController extends Controller {
$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 {
@@ -872,6 +947,13 @@ class PatientEpisodeController extends Controller {
$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 {
@@ -885,8 +967,33 @@ class PatientEpisodeController extends Controller {
}
}
}
if(between($years, 0, 12)) {
$priority_signs_records = PrioritySign::where('triage_id', $episode->triage_id)->first();
if ($priority_signs_records) {
$priority_signs = unserialize($priority_signs_records->signs);
}
$emergency_signs = EmergencySign::where('triage_id', $episode->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;
}
}
$data = [
'main_exam' => $main_exam,
'base_exam' => $base_exam,
'slit_lamp_test_areas' => $slit_lamp_test_areas,
'slit_lamp_test_area_values' => $slit_lamp_test_area_values,
'slit_lamp_test_area_ids' => $slit_lamp_test_area_ids,
'hospitalInfo' => $hospital_information,
'patient' => $patient,
'episode' => $episode,
@@ -900,13 +1007,17 @@ class PatientEpisodeController extends Controller {
'opd_investigations' => $opd_investigations,
'inpatient_infos' => $inpatient_infos,
'sundries' => $sundries,
'ordered_sundries'=>$ordered_sundries,
'services' =>$services,
'ordered_services'=>$ordered_services,
'ordered_sundries' => $ordered_sundries,
'services' => $services,
'ordered_services' => $ordered_services,
'outcomes' => $outcomes,
'antenatal_data' => $antenatal_data,
'symptoms'=> $symptoms
];
'symptoms'=> $symptoms,
'triage' =>$triage,
'priority_signs' => $priority_signs,
'emergent_signs'=> $emergent_signs,
'years'=>$years
];
$pdf = SnappyPDF::loadView('patients::patient_episodes/episode_summary', $data)
->setOrientation('portrait')
@@ -921,7 +1032,7 @@ class PatientEpisodeController extends Controller {
public function get_assigned_doctor($episode_id)
{
$patient_id = session()->get('patient_id');
$consultation = Consultation::where(['patient_id'=> $patient_id, 'episode_id' => $episode_id])->first();
$consultation = Consultation::where(['patient_id' => $patient_id, 'episode_id' => $episode_id])->first();
if ($consultation) {
$doctor_id = $consultation->consultation_done_by;
$doctor_name = get_full_name($doctor_id, "id", "first_name", "last_name", "users");
@@ -931,7 +1042,8 @@ class PatientEpisodeController extends Controller {
return 0;
}
public function save_doctor_transfer(Request $request) {
public function save_doctor_transfer(Request $request)
{
$patient_id = session()->get('patient_id');
$doctor_to_transfer_to = $request->dt_doctor_to;
$episode_id = $request->episode_id;
@@ -942,7 +1054,7 @@ class PatientEpisodeController extends Controller {
$allocated_service_id = $services_id_with_user_id_array[0];
$transfer_to_doctor = $services_id_with_user_id_array[1];
$consultation = Consultation::where(['patient_id'=> $patient_id, 'episode_id' => $request->episode_id])->first();
$consultation = Consultation::where(['patient_id' => $patient_id, 'episode_id' => $request->episode_id])->first();
if ($consultation) {
// first, check if there is a previously ordered service attached to current doctor
@@ -979,8 +1091,14 @@ class PatientEpisodeController extends Controller {
$episode_record = PatientEpisode::find($episode_id);
// create new ordered service record
$service_performed_id = record_staff_that_has_performed_the_service($patient_id, $episode_id, 3,
$allocated_service_id, 0, $transfer_to_doctor);
$service_performed_id = record_staff_that_has_performed_the_service(
$patient_id,
$episode_id,
3,
$allocated_service_id,
0,
$transfer_to_doctor
);
$service_order = new OrderedService;
$service_order->patient_id = $patient_id;
@@ -1026,12 +1144,12 @@ class PatientEpisodeController extends Controller {
// reassign the appointment_fulfilled to 1
$appointment->appointment_fulfilled = 1;
$appointment->updated_by = Auth()->user()->id;
if ($appointment->save()){
if ($appointment->save()) {
$episode = new PatientEpisode;
$episode->clinic_id = $selected_clinic_id;
$episode->patient_id = $patient_id;
$episode->parent_episode_id = $appointment->episode_id == 0 ? null : $appointment->episode_id;//the original episode_id
$episode->parent_episode_id = $appointment->episode_id == 0 ? null : $appointment->episode_id; //the original episode_id
$episode->created_by = auth()->user()->id;
$episode->updated_by = auth()->user()->id;
$episode->save();
@@ -1039,7 +1157,7 @@ class PatientEpisodeController extends Controller {
$last_inserted_id = $episode->id;
if ($services_id_with_user_id) {
$allocated_persons_name = get_full_name($allocated_user_id, "id","first_name","last_name","users");
$allocated_persons_name = get_full_name($allocated_user_id, "id", "first_name", "last_name", "users");
/* create a record in consultations table attached to allocated doctor */
$consultation_record = new Consultation;
$consultation_record->patient_id = $episode->patient_id;
@@ -1069,8 +1187,8 @@ class PatientEpisodeController extends Controller {
$previous_anc_visit = \Streamline\Models\AnteNatalClinicFollowup::where(['patient_id' => $episode->patient_id, 'episode_id' => $episode->parent_episode_id])->first();
if ($previous_anc_visit) {
create_anc_registration_record_from_previous_visit($patient_id, $episode->parent_episode_id, $episode->id);
}
}
// check where the function was called from and return there
if (isset($request->is_from_finance)) {
// return to finance home
@@ -1096,7 +1214,8 @@ class PatientEpisodeController extends Controller {
}
}
function delete_episode($episode_id) {
function delete_episode($episode_id)
{
$episode = PatientEpisode::find($episode_id);
// check if consultation record exists with that id
@@ -1118,48 +1237,48 @@ class PatientEpisodeController extends Controller {
$patient_id = session()->get('patient_id');
$patient = Patient::find($patient_id);
$episodes = PatientEpisode::where('patient_id', $patient_id)->orderBy('id','desc')->get();
$episodes = PatientEpisode::where('patient_id', $patient_id)->orderBy('id', 'desc')->get();
$diagnoses = DB::table('diagnoses')->where('available', 1)->pluck("name", "id");
$clinics = DB::table('clinics')->pluck("name", "id")->prepend('- select -', '');
$special_clinics = DB::table('clinics')->where('available', 1)->whereNull('deleted_at')->pluck("name", "id")->prepend('- select -', '');
$wards = DB::table('wards')->where('available', 1)->pluck("name", "id")->prepend('- select -', '');
$users_collection = DB::table('users')->orderBy("first_name","asc")->select("id")->get()->toArray();
$users_collection = DB::table('users')->orderBy("first_name", "asc")->select("id")->get()->toArray();
$users_array = [];
foreach ($users_collection as $value){
foreach ($users_collection as $value) {
$user = User::find($value->id);
if (!is_null($user)) {
if ($user->hasRole('Doctors') || $user->hasRole('Doctor')) {
//use this join query instead of the commented out query to cater for execution speed (N+1)
$consultation_records = DB::table('services')
->join('staff_payment_configurations','staff_payment_configurations.item_id', '=', 'services.id')
->where('services.item_type', 'Consultation')
->where('staff_payment_configurations.user_id',$value->id)
->where('staff_payment_configurations.item_category',3)
->whereNull('staff_payment_configurations.deleted_at')
->orderBy('staff_payment_configurations.created_at','asc')
->select('services.*')
->get();
->join('staff_payment_configurations', 'staff_payment_configurations.item_id', '=', 'services.id')
->where('services.item_type', 'Consultation')
->where('staff_payment_configurations.user_id', $value->id)
->where('staff_payment_configurations.item_category', 3)
->whereNull('staff_payment_configurations.deleted_at')
->orderBy('staff_payment_configurations.created_at', 'asc')
->select('services.*')
->get();
foreach ($consultation_records as $record) {
$price_list_id = is_patient_category_attached_to_price_list($patient_id);
if ($price_list_id) {
$users_consultation_fee = get_price_list_category_price($price_list_id, 6, $record->id);
} else{
} else {
$users_consultation_fee = $record->non_insured_price;
}
//concatnate the service_record_id with the users id to form the key for the array
$users_array[$record->id."__".$value->id] = get_full_name($value->id, 'id', 'first_name', 'last_name', 'users')." (".$record->name." Fee: ".ugandan_shillings($users_consultation_fee).")";
$users_array[$record->id . "__" . $value->id] = get_full_name($value->id, 'id', 'first_name', 'last_name', 'users') . " (" . $record->name . " Fee: " . ugandan_shillings($users_consultation_fee) . ")";
}
}
}
}
$users_array = ['' => '- select -'] + $users_array;
return view('patients::patient_episodes.merge_episodes',compact('patient', 'episodes', 'diagnoses', 'clinics', 'special_clinics', 'wards', 'users_array'));
return view('patients::patient_episodes.merge_episodes', compact('patient', 'episodes', 'diagnoses', 'clinics', 'special_clinics', 'wards', 'users_array'));
}
public function display_original_and_duplicate_episodes(Request $request)
@@ -1170,74 +1289,74 @@ class PatientEpisodeController extends Controller {
$episode_one = PatientEpisode::find($episode_id_one);
$html_text_one = "<table class='table table-bordered table-striped'>";
$html_text_one .= "<tr>";
$html_text_one .= "<th><strong>Select which episode to keep</strong></th><td><input type='checkbox' name='all_original_fields' id='all_original_fields'> Episode started on <font color='blue'>". streamline_date_time($episode_one->created_at)."</font></td><input name='original_id' type='hidden' value='".$episode_one->id."'";
$html_text_one .= "</tr>";
$html_text_one .= "<tr>";
$html_text_one .= "<th><strong>Select which episode to keep</strong></th><td><input type='checkbox' name='all_original_fields' id='all_original_fields'> Episode started on <font color='blue'>" . streamline_date_time($episode_one->created_at) . "</font></td><input name='original_id' type='hidden' value='" . $episode_one->id . "'";
$html_text_one .= "</tr>";
$html_text_one .= "<tr>";
$html_text_one .= "<th><font color='black'>Clinics</font></th><td><input type='radio' class='original_radio' name='clinic_id' value=". $episode_one->clinic_id."> " . get_name($episode_one->clinic_id, "id", "name", "clinics") . "</td>";
$html_text_one .= "</tr>";
$html_text_one .= "<tr>";
$html_text_one .= "<th><font color='black'>Clinics</font></th><td><input type='radio' class='original_radio' name='clinic_id' value=" . $episode_one->clinic_id . "> " . get_name($episode_one->clinic_id, "id", "name", "clinics") . "</td>";
$html_text_one .= "</tr>";
$html_text_one .= "<tr>";
$html_text_one .= "<th><font color='black'>Primary Diagnosis</font></th><td><input type='radio' class='original_radio' name='primary_diagnosis' value=". get_name($episode_one->consultation_id, 'id', 'primary_diagnosis', 'consultations')."> " . get_name(get_name($episode_one->consultation_id, "id", "primary_diagnosis", "consultations"), "id", "name", "diagnoses") . "</td>";
$html_text_one .= "</tr>";
$html_text_one .= "<tr>";
$html_text_one .= "<th><font color='black'>Primary Diagnosis</font></th><td><input type='radio' class='original_radio' name='primary_diagnosis' value=" . get_name($episode_one->consultation_id, 'id', 'primary_diagnosis', 'consultations') . "> " . get_name(get_name($episode_one->consultation_id, "id", "primary_diagnosis", "consultations"), "id", "name", "diagnoses") . "</td>";
$html_text_one .= "</tr>";
$html_text_one .= "<tr>";
$html_text_one .= "<th><font color='black'>Triage Comments</font></th><td><input type='radio' disabled class='original_radio' name='triage_comments' value=". get_name($episode_one->triage_id, 'id', 'comments', 'triage')."> " . get_name($episode_one->triage_id, "id", "comments", "triage") . "</td>";
$html_text_one .= "</tr>";
$html_text_one .= "<tr>";
$html_text_one .= "<th><font color='black'>Triage Comments</font></th><td><input type='radio' disabled class='original_radio' name='triage_comments' value=" . get_name($episode_one->triage_id, 'id', 'comments', 'triage') . "> " . get_name($episode_one->triage_id, "id", "comments", "triage") . "</td>";
$html_text_one .= "</tr>";
$html_text_one .= "<tr>";
$html_text_one .= "<th><font color='black'>Consultation Comments</font></th><td><input type='radio' class='original_radio' name='consultation_comments' value=". get_name($episode_one->consultation_id, 'id', 'comments', 'consultations')."> " . get_name($episode_one->consultation_id, "id", "comments", "consultations") . "</td>";
$html_text_one .= "</tr>";
$html_text_one .= "<tr>";
$html_text_one .= "<th><font color='black'>Consultation Comments</font></th><td><input type='radio' class='original_radio' name='consultation_comments' value=" . get_name($episode_one->consultation_id, 'id', 'comments', 'consultations') . "> " . get_name($episode_one->consultation_id, "id", "comments", "consultations") . "</td>";
$html_text_one .= "</tr>";
$html_text_one .= "<tr>";
$html_text_one .= "<th><font color='black'>Examination Comments</font></th><td><input type='radio' class='original_radio' name='clinic_examination_comments' value=". get_name($episode_one->consultation_id, 'id', 'clinic_examination_comments', 'consultations')."> " . get_name($episode_one->consultation_id, "id", "clinic_examination_comments", "consultations") . "</td>";
$html_text_one .= "</tr>";
$html_text_one .= "<tr>";
$html_text_one .= "<th><font color='black'>Examination Comments</font></th><td><input type='radio' class='original_radio' name='clinic_examination_comments' value=" . get_name($episode_one->consultation_id, 'id', 'clinic_examination_comments', 'consultations') . "> " . get_name($episode_one->consultation_id, "id", "clinic_examination_comments", "consultations") . "</td>";
$html_text_one .= "</tr>";
$html_text_one .= "<tr>";
$html_text_one .= "<th><font color='black'>Management Plan</font></th><td><input type='radio' class='original_radio' name='investigation_and_management_plan_comments' value=". get_name($episode_one->consultation_id, 'id', 'investigation_and_management_plan_comments', 'consultations')."> " . get_name($episode_one->consultation_id, "id", "investigation_and_management_plan_comments", "consultations") . "</td>";
$html_text_one .= "</tr>";
$html_text_one .= "<tr>";
$html_text_one .= "<th><font color='black'>Management Plan</font></th><td><input type='radio' class='original_radio' name='investigation_and_management_plan_comments' value=" . get_name($episode_one->consultation_id, 'id', 'investigation_and_management_plan_comments', 'consultations') . "> " . get_name($episode_one->consultation_id, "id", "investigation_and_management_plan_comments", "consultations") . "</td>";
$html_text_one .= "</tr>";
$html_text_one .= "<tr>";
$html_text_one .= "<th><font color='black'>History Comments</font></th><td><input type='radio' class='original_radio' name='history_comments' value=". get_name($episode_one->consultation_id, 'id', 'history_comments', 'consultations')."> " . get_name($episode_one->consultation_id, "id", "history_comments", "consultations") . "</td>";
$html_text_one .= "</tr>";
$html_text_one .= "<tr>";
$html_text_one .= "<th><font color='black'>History Comments</font></th><td><input type='radio' class='original_radio' name='history_comments' value=" . get_name($episode_one->consultation_id, 'id', 'history_comments', 'consultations') . "> " . get_name($episode_one->consultation_id, "id", "history_comments", "consultations") . "</td>";
$html_text_one .= "</tr>";
$html_text_one .= "</table>";
$episode_two = PatientEpisode::find($episode_id_two);
$html_text_two = "<table class='table table-bordered table-striped'>";
$html_text_two .= "<tr>";
$html_text_two .= "<td><input type='checkbox' name='all_duplicate_fields' id='all_duplicate_fields'> Episode started on <font color='blue'>". streamline_date_time($episode_two->created_at)."</font></td><input name='duplicate_id' type='hidden' value='".$episode_two->id."'";
$html_text_two .= "</tr>";
$html_text_two .= "<tr>";
$html_text_two .= "<td><input type='checkbox' name='all_duplicate_fields' id='all_duplicate_fields'> Episode started on <font color='blue'>" . streamline_date_time($episode_two->created_at) . "</font></td><input name='duplicate_id' type='hidden' value='" . $episode_two->id . "'";
$html_text_two .= "</tr>";
$html_text_two .= "<tr>";
$html_text_two .= "<td><input type='radio' class='duplicate_radio' name='clinic_id' value=". $episode_two->clinic_id."> " . get_name($episode_two->clinic_id, "id", "name", "clinics") . "</td>";
$html_text_two .= "</tr>";
$html_text_two .= "<tr>";
$html_text_two .= "<td><input type='radio' class='duplicate_radio' name='clinic_id' value=" . $episode_two->clinic_id . "> " . get_name($episode_two->clinic_id, "id", "name", "clinics") . "</td>";
$html_text_two .= "</tr>";
$html_text_two .= "<tr>";
$html_text_two .= "<td><input type='radio' class='duplicate_radio' name='primary_diagnosis' value=". get_name($episode_two->consultation_id, 'id', 'primary_diagnosis', 'consultations')."> " . get_name(get_name($episode_two->consultation_id, "id", "primary_diagnosis", "consultations"), "id", "name", "diagnoses") . "</td>";
$html_text_two .= "</tr>";
$html_text_two .= "<tr>";
$html_text_two .= "<td><input type='radio' class='duplicate_radio' name='primary_diagnosis' value=" . get_name($episode_two->consultation_id, 'id', 'primary_diagnosis', 'consultations') . "> " . get_name(get_name($episode_two->consultation_id, "id", "primary_diagnosis", "consultations"), "id", "name", "diagnoses") . "</td>";
$html_text_two .= "</tr>";
$html_text_two .= "<tr>";
$html_text_two .= "<td><input type='radio' disabled class='duplicate_radio' name='triage_comments' value=". get_name($episode_two->triage_id, 'id', 'comments', 'triage')."> " . get_name($episode_two->triage_id, "id", "comments", "triage") . "</td>";
$html_text_two .= "</tr>";
$html_text_two .= "<tr>";
$html_text_two .= "<td><input type='radio' disabled class='duplicate_radio' name='triage_comments' value=" . get_name($episode_two->triage_id, 'id', 'comments', 'triage') . "> " . get_name($episode_two->triage_id, "id", "comments", "triage") . "</td>";
$html_text_two .= "</tr>";
$html_text_two .= "<tr>";
$html_text_two .= "<td><input type='radio' class='duplicate_radio' name='consultation_comments' value=". get_name($episode_two->consultation_id, 'id', 'comments', 'consultations')."> " . get_name($episode_two->consultation_id, "id", "comments", "consultations") . "</td>";
$html_text_two .= "</tr>";
$html_text_two .= "<tr>";
$html_text_two .= "<td><input type='radio' class='duplicate_radio' name='consultation_comments' value=" . get_name($episode_two->consultation_id, 'id', 'comments', 'consultations') . "> " . get_name($episode_two->consultation_id, "id", "comments", "consultations") . "</td>";
$html_text_two .= "</tr>";
$html_text_two .= "<tr>";
$html_text_two .= "<td><input type='radio' class='duplicate_radio' name='clinic_examination_comments' value=". get_name($episode_two->consultation_id, 'id', 'clinic_examination_comments', 'consultations')."> " . get_name($episode_two->consultation_id, "id", "clinic_examination_comments", "consultations") . "</td>";
$html_text_two .= "</tr>";
$html_text_two .= "<tr>";
$html_text_two .= "<td><input type='radio' class='duplicate_radio' name='clinic_examination_comments' value=" . get_name($episode_two->consultation_id, 'id', 'clinic_examination_comments', 'consultations') . "> " . get_name($episode_two->consultation_id, "id", "clinic_examination_comments", "consultations") . "</td>";
$html_text_two .= "</tr>";
$html_text_two .= "<tr>";
$html_text_two .= "<td><input type='radio' class='duplicate_radio' name='investigation_and_management_plan_comments' value=". get_name($episode_two->consultation_id, 'id', 'investigation_and_management_plan_comments', 'consultations')."> " . get_name($episode_two->consultation_id, "id", "investigation_and_management_plan_comments", "consultations") . "</td>";
$html_text_two .= "</tr>";
$html_text_two .= "<tr>";
$html_text_two .= "<td><input type='radio' class='duplicate_radio' name='investigation_and_management_plan_comments' value=" . get_name($episode_two->consultation_id, 'id', 'investigation_and_management_plan_comments', 'consultations') . "> " . get_name($episode_two->consultation_id, "id", "investigation_and_management_plan_comments", "consultations") . "</td>";
$html_text_two .= "</tr>";
$html_text_two .= "<tr>";
$html_text_two .= "<td><input type='radio' class='duplicate_radio' name='history_comments' value=". get_name($episode_two->consultation_id, 'id', 'history_comments', 'consultations')."> " . get_name($episode_two->consultation_id, "id", "history_comments", "consultations") . "</td>";
$html_text_two .= "</tr>";
$html_text_two .= "<tr>";
$html_text_two .= "<td><input type='radio' class='duplicate_radio' name='history_comments' value=" . get_name($episode_two->consultation_id, 'id', 'history_comments', 'consultations') . "> " . get_name($episode_two->consultation_id, "id", "history_comments", "consultations") . "</td>";
$html_text_two .= "</tr>";
$html_text_two .= "</table>";
return json_encode([
@@ -1476,15 +1595,15 @@ class PatientEpisodeController extends Controller {
$ordered_sundry->episode_id = $episode_id_to_keep;
$ordered_sundry->update();
}
$tables = ['ward_inpatient_sheet_nurse_comments','ward_inpatient_detailed_notes','ward_dispensing_per_charts','patient_documents','patient_one_off_discounts','triage_nutrition','triage_news','surgeries','sundries_deposits','smart_triage','patient_refunds','patient_account_consumptions','patient_appointments','phone_followup_patients','point_of_sale_records','procedure_deposits','cancel_patient_transactions','central_billing_deposits','chronic_patients','chi_deposits','debtors','debt_plan','dependants_consumptions','family_account_consumptions','inpatient_attendant_passes','inpatient_ward_discounts','inpatient_sheet_audits','maternity_delivery_records','maternity_inpatients','mental_health_consultation','ordered_investigations','ordered_procedures'];
$tables = ['ward_inpatient_sheet_nurse_comments', 'ward_inpatient_detailed_notes', 'ward_dispensing_per_charts', 'patient_documents', 'patient_one_off_discounts', 'triage_nutrition', 'triage_news', 'surgeries', 'sundries_deposits', 'smart_triage', 'patient_refunds', 'patient_account_consumptions', 'patient_appointments', 'phone_followup_patients', 'point_of_sale_records', 'procedure_deposits', 'cancel_patient_transactions', 'central_billing_deposits', 'chronic_patients', 'chi_deposits', 'debtors', 'debt_plan', 'dependants_consumptions', 'family_account_consumptions', 'inpatient_attendant_passes', 'inpatient_ward_discounts', 'inpatient_sheet_audits', 'maternity_delivery_records', 'maternity_inpatients', 'mental_health_consultation', 'ordered_investigations', 'ordered_procedures'];
foreach ($tables as $table) {
$episodes = DB::table($table)->where('episode_id', $episode_id_to_delete)->get();
foreach ($episodes as $episode) DB::table($table)->where('id', $episode->id)->update(['episode_id' => $episode_id_to_keep]);
foreach ($episodes as $episode) DB::table($table)->where('id', $episode->id)->update(['episode_id' => $episode_id_to_keep]);
}
$incoming_ward_charts = DB::table('incoming_ward_charts')->whereRaw('FIND_IN_SET(' . $episode_id_to_delete . ',episode_ids)')->get();
foreach ($incoming_ward_charts as $incoming_ward_chart) {
$episode_ids = explode(',',$incoming_ward_chart->episode_ids);
foreach ($episode_ids as $key => $episode_id) if( $episode_id == $episode_id_to_delete) $episode_ids[$key]=$episode_id_to_keep;
$episode_ids = explode(',', $incoming_ward_chart->episode_ids);
foreach ($episode_ids as $key => $episode_id) if ($episode_id == $episode_id_to_delete) $episode_ids[$key] = $episode_id_to_keep;
DB::table('incoming_ward_charts')->where('id', $incoming_ward_chart->id)->update(['episode_ids' => implode(',', $episode_ids)]);
}
flash("Episodes have been merged")->success();
@@ -1505,7 +1624,8 @@ class PatientEpisodeController extends Controller {
return "unpaid";
}
public function is_patient_allowed_to_have_consultation($patient_id, $episode_id) {
public function is_patient_allowed_to_have_consultation($patient_id, $episode_id)
{
$patient_details = Patient::withTrashed()->find($patient_id);
$episode_details = PatientEpisode::withTrashed()->find($episode_id);
$patient_episodes_payment_setting = $patient_details->episode_payments;
@@ -42,35 +42,29 @@ class PatientFlowMonitoringController extends Controller {
session()->put('order_by', $order_by);
}
$filters = [];
if($search_by === 0){
// last 24 hours
$last_day = Carbon::now()->subDay();
$start_date_search = Carbon::yesterday()->startOfDay()->toDateTimeString();
$end_date_search = Carbon::yesterday()->endOfDay()->toDateTimeString();
array_push($filters, ['patient_episodes.created_at', '>', $last_day]);
$date_search = "Last 24 hours";
$date_search = "Yesterday";
} elseif($search_by == 1){
// custom date
$start_date_search = Carbon::parse($reg_date)->startOfDay()->toDateTimeString();;
$end_date_search = Carbon::parse($reg_date)->endOfDay()->toDateTimeString();;
$start_date_search = Carbon::parse($reg_date)->startOfDay()->toDateTimeString();
$end_date_search = Carbon::parse($reg_date)->endOfDay()->toDateTimeString();
array_push($filters, ['patient_episodes.created_at', '>', $start_date_search]);
array_push($filters, ['patient_episodes.created_at', '<', $end_date_search]);
$date_search = streamline_date($start_date_search);
} elseif($search_by == 2){
// custom date range
$start_date_search = Carbon::parse($start_date)->startOfDay()->toDateTimeString();;
$end_date_search = Carbon::parse($end_date)->endOfDay()->toDateTimeString();;
$start_date_search = Carbon::parse($start_date)->startOfDay()->toDateTimeString();
$end_date_search = Carbon::parse($end_date)->endOfDay()->toDateTimeString();
array_push($filters, ['patient_episodes.created_at', '>', $start_date_search]);
array_push($filters, ['patient_episodes.created_at', '<', $end_date_search]);
$date_search = streamline_date($start_date_search) . " to " . streamline_date($end_date_search);
} else {
// Today
$today = Carbon::today()->toDateTimeString();
$start_date_search = Carbon::today()->startOfDay()->toDateTimeString();
$end_date_search = Carbon::today()->endOfDay()->toDateTimeString();
array_push($filters, ['patient_episodes.created_at', '>=', $today]);
$date_search = "Today";
}
@@ -106,7 +100,7 @@ class PatientFlowMonitoringController extends Controller {
->leftJoin('ante_natal_clinic_followups as a', 'patient_episodes.id', '=', 'a.episode_id')
->leftJoin('triage', 'patient_episodes.id', '=', 'triage.episode_id')
->select('patient_episodes.*', 'consultations.primary_diagnosis','consultations.outcome_id','consultations.completed','consultations.created_by as consultation_created_by','consultations.updated_by as consultation_updated_by','consultations.consultation_done_by', 'a.primary_diagnosis as antenatal_primary_diagnosis','a.outcome_id as antenatal_outcome_id','a.completion_status as antenatal_completed','a.created_by as antenatal_created_by','a.updated_by as antenatal_updated_by', 'triage.id as episode_triage_id', 'triage.severe_grade', 'triage.clinic_allocation')
->where($filters)
->whereBetween('patient_episodes.created_at', [$start_date_search, $end_date_search])
->orderByRaw($order_by_text)
->paginate(200);
$clinic_name = "OPD";
@@ -116,7 +110,8 @@ class PatientFlowMonitoringController extends Controller {
->leftJoin('consultations', 'patient_episodes.id', '=', 'consultations.episode_id')
->leftJoin('ante_natal_clinic_followups as a', 'patient_episodes.id', '=', 'a.episode_id')
->leftJoin('triage', 'patient_episodes.id', '=', 'triage.episode_id')
->where(['patient_episodes.clinic_id' => $clinic_id])->where($filters)
->where(['patient_episodes.clinic_id' => $clinic_id])
->whereBetween('patient_episodes.created_at', [$start_date_search, $end_date_search])
->orderByRaw($order_by_text)
->select('patient_episodes.*', 'consultations.primary_diagnosis','consultations.outcome_id','consultations.completed','consultations.created_by as consultation_created_by','consultations.updated_by as consultation_updated_by','consultations.consultation_done_by', 'a.primary_diagnosis as antenatal_primary_diagnosis','a.outcome_id as antenatal_outcome_id','a.completion_status as antenatal_completed','a.created_by as antenatal_created_by','a.updated_by as antenatal_updated_by','triage.id as episode_triage_id', 'triage.severe_grade', 'triage.clinic_allocation')
->paginate(200);
@@ -129,9 +124,11 @@ class PatientFlowMonitoringController extends Controller {
$clinics = [0 => 'OPD'] + $clinics;
$clinics = ['' => '- select -'] + $clinics;
$diagnoses = DB::table('diagnoses')->where('available', 1)->whereNull('deleted_at')->pluck("name", "id")->toArray();
$wards = DB::table('wards')->where('available', 1)->whereNull('deleted_at')->pluck("name", "id")->prepend('- select -', '');
return view('patients::patient_flow_monitoring.index', compact('patient_episodes', 'clinics', 'patient_categories','clinic_name','search_by', 'date_search', 'wards'));
return view('patients::patient_flow_monitoring.index', compact('patient_episodes', 'clinics', 'patient_categories','clinic_name','search_by', 'date_search', 'wards', 'diagnoses'));
}
public function patient_route($episode_id, $route){
@@ -145,7 +142,9 @@ class PatientFlowMonitoringController extends Controller {
if($route == 'triage'){
$url = '/triage';
session()->put('triage_without_etat', 0);
} elseif ($route == 'consultation'){
session()->put('consultation_with_notes', 0);
$url = '/consultation/route';
} elseif ($route == 'create_anaesthetics'){
$url = '/anaesthetics/create';
@@ -164,11 +163,17 @@ class PatientFlowMonitoringController extends Controller {
} elseif ($route == 'investigation') {
$url = '/investigations/investigations_review';
} elseif ($route == 'triage_without_etat') {
$url = '/triage/create_without_etat';
session()->put('triage_without_etat', 1);
$url = '/triage';
} elseif ($route == 'consultation_with_notes') {
$url = '/consultation/create_with_notes';
session()->put('consultation_with_notes', 1);
$url = '/consultation/route';
} elseif ($route == 'view_patient_history') {
$url = '/patient_episodes/';
} elseif ($route == 'main_exam') {
$url = '/eye_clinic/main_exam_route';
} elseif ($route == 'base_refraction_exam') {
$url = '/eye_clinic/base_exam_refraction';
}
return response()->json($url);
@@ -219,11 +224,8 @@ class PatientFlowMonitoringController extends Controller {
return redirect('/patient_episodes/');
} catch (QueryException $e) {
$errorCode = $e->errorInfo[1];
if ($errorCode == 1062) { //error code for duplicate entry to a unique field
flash("This episode already exists!")->error();
return back()->withInput();
}
flash("This episode already exists!")->error();
return back()->withInput();
}
}
}
@@ -0,0 +1,451 @@
<?php
namespace Modules\Patients\Http\Controllers;
use Barryvdh\Snappy\Facades\SnappyPdf;
use Carbon\Carbon;
use Illuminate\Database\QueryException;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\DB;
use Streamline\Models\Drug;
use Streamline\Models\EyeGlasses;
use Streamline\Models\HospitalInformation;
use Streamline\Models\OrderedEyeGlasses;
use Streamline\Models\OrderedService;
use Streamline\Models\OrderedSundry;
use Streamline\Models\Patient;
use Streamline\Models\PatientEpisode;
use Streamline\Models\PointOfSaleRecord;
use Streamline\Models\ReferralHospital;
use Streamline\Models\Sundry;
use Streamline\Models\Services;
use Streamline\Models\Treatment;
class PointOfSaleController extends Controller {
public function index(Request $request){
$search_text = "";
switch ($request->search_date_by){
case 'yesterday':
$end_date = Carbon::yesterday()->endOfDay();
$start_date = Carbon::yesterday()->startOfDay();
$search_text .= "Yesterday ";
break;
case 'custom_date':
$end_date = Carbon::parse($request->start_date)->endOfDay();
$start_date = Carbon::parse($request->start_date)->startOfDay();
$search_text .= "From: " . streamline_date($start_date) . " ";
break;
case 'custom_date_range':
$end_date = Carbon::parse($request->end_date)->endOfDay();
$start_date = Carbon::parse($request->start_date)->startOfDay();
$search_text .= "From: " . streamline_date($start_date) . " to " . streamline_date($end_date) . " ";
break;
case 'today':
default:
$end_date = Carbon::today()->endOfDay();
$start_date = Carbon::today()->startOfDay();
$search_text .= "Today ";
break;
}
$records = PointOfSaleRecord::join('patients', 'point_of_sale_records.patient_id', '=', 'patients.id')
->whereBetween('point_of_sale_records.created_at', [$start_date, $end_date])
->limit(500)->get(['point_of_sale_records.*', 'patients.first_name', 'patients.last_name', 'patients.number']);
return view('patients::point_of_sale.index', compact('records', 'search_text'));
}
public function order_items(){
$drugs = Drug::get();
$sundries = Sundry::where('available', 1)->get();
$services = Services::where('available', 1)->get();
$eye_glasses = EyeGlasses::get();
$referral_hospitals = ReferralHospital::orderBy('name')->get();
return view('patients::point_of_sale.order_items', compact('drugs', 'eye_glasses', 'sundries', 'referral_hospitals', 'services'));
}
public function confirm_items(Request $request){
$pre_ordered_eye_glasses = [];
$manual_patient_prescriptions = [];
$automatic_patient_prescriptions = [];
$pre_ordered_sundries = [];
$pre_ordered_services = [];
if($request->patient_id) {
$patient_id = $request->patient_id;
$patient = Patient::find($patient_id);
// double check if for existing patient_id
if($patient){
$patient_number = Patient::where('id', $patient_id)->pluck('number')->first();
$episode_id = PatientEpisode::where('patient_id',$patient_id)->whereDate('created_at', Carbon::today()->toDateString())->pluck('id')->first();
if(!$episode_id){
$episode = new PatientEpisode;
$episode->patient_id = $patient_id;
$episode->paid_over = "pos";
$episode->created_by = Auth::user()->id;
$episode->updated_by = Auth::user()->id;
$episode->save();
flash('A new episode for patient with patient number ' . $patient_number . ' has been initiated.');
$episode_id = $episode->id;
}
} else {
flash('Patient not found')->error();
redirect('point_of_sale');
}
} else {
$patient = new Patient;
$patient->first_name = $request->first_name;
$patient->last_name = $request->last_name;
$patient->phone = $request->phone_number ?? "";
$patient->referred_from = $request->referral_hospital ?? 1;
$patient->category_id = 1;
$patient->created_by = Auth::user()->id;
$patient->gender = $request->gender ?? 2;
if (is_null($request->date_of_birth)) {
$age_in_years = $request->age_in_years ?? 18;
$calculated_dob = \Carbon\Carbon::now()->subYears($age_in_years);
$calculated_date_of_birth = $calculated_dob->toDateString();
$patient->date_of_birth = $calculated_date_of_birth;
} else {
$patient->date_of_birth = Carbon::createFromFormat('d/m/Y', $request->date_of_birth)->toDateString();
}
if ($patient->save()):
$prefix = DB::table('hospital_information')->where('id', 1)->value('patient_number_abbr');
$patient_id = $patient->id;
$new_id = quadLimit($patient_id);
$patient_number = $prefix . "-" . $new_id;
DB::table('patients')->where('id', $new_id)->update(['number' => $patient_number]); // Updating the patient number
else:
flash("There was an error")->error();
return back()->withInput();
endif;
$episode = new PatientEpisode;
$episode->patient_id = $patient_id;
$episode->clinic_id = get_default_hospital_clinic();
$episode->paid_over = "pos";
$episode->created_by = Auth::user()->id;
$episode->updated_by = Auth::user()->id;
try {
$episode->save();
$episode_id = $episode->id;
flash('Patient with patient number ' . $patient_number . ' has been successfully registered.')->success();
} catch (QueryException $e) {
flash("This episode already exists!")->error();
return back()->withInput();
}
}
if ($request->selected_eye_glasses) {
$pre_ordered_eye_glasses = EyeGlasses::whereIn('id', $request->selected_eye_glasses)->get();
}
if ($request->selected_drugs) {
if($request->manual_drug_select == 1){
$manual_patient_prescriptions = Drug::whereIn('id', $request->selected_drugs)->get();
}else if($request->automatic_drug_select == 1){
$automatic_patient_prescriptions = Drug::whereIn('id', $request->selected_drugs)->get();
}
}
if ($request->selected_sundries) {
$pre_ordered_sundries = Sundry::whereIn('id', $request->selected_sundries)->get();
}
if ($request->selected_services) {
$pre_ordered_services = Services::whereIn('id', $request->selected_services)->get();
}
$allergies = DB::table('allergies')->where(['patient_id' => $patient_id])->pluck('patient_id', 'names');
return view('patients::point_of_sale.confirm_items', compact('patient_id', 'episode_id', 'pre_ordered_eye_glasses',
'manual_patient_prescriptions', 'automatic_patient_prescriptions', 'allergies', 'patient', 'pre_ordered_sundries', 'pre_ordered_services'));
}
public function confirm_pricing(Request $request){
if($request->treatment_item){
$treatment = new Treatment;
$treatment->patient_id = $request->patient_id;
$treatment->episode_id = $request->episode_id;
$treatment->drugs = implode(',', $request->treatment_item);
$drugs_array = $request->treatment_item;
$duration_array = $request->duration;
$time_array = $request->time;
$time_duration = [];
$doses = $request->dose ?? [];
$frequencies = $request->frequency ?? [];
$dose_array = [];
$frequencies_array = [];
$instructions_array = [];
for ($i = 0; $i < count($drugs_array); $i++) {
if (is_drug_chronic($drugs_array[$i])) {
register_chronic_patient($request->patient_id, $request->episode_id, $drugs_array[$i]);
}
if (isset($duration_array[$i]) && isset($time_array[$i])) {
$time_duration[] = $duration_array[$i] . " " . $time_array[$i];
} else {
$time_duration[] = "1 Days";
}
if (isset($doses[$i])) {
$dose_array[] = $doses[$i];
} else {
$dose_array[] = "1";
}
if (isset($frequencies[$i])) {
$frequencies_array[] = $frequencies[$i];
} else {
$frequencies_array[] = "2";
}
$instructions_array[] = "";
}
$treatment->doses = implode(',', $dose_array);
$treatment->frequencies = implode(',', $frequencies_array);
$treatment->instruction = implode(',', $instructions_array);
$treatment->durations = implode(',', $time_duration);
$treatment->quantities_dispensed = implode(',', $request->treatment_quantity);
$treatment->dispense_status = 0;
$treatment->created_by = Auth::id();
$treatment->save();
$request->treatment_id = DB::table('treatments')->where('episode_id', $request->episode_id)->where('patient_id', $request->patient_id)->latest()->pluck('id')->first();
}
$eye_glass_ids = $request->eye_glass_item;
$eye_glass_quantity = $request->eye_glass_quantity;
if($request->eye_glass_item){
for ($i=0; $i < count($eye_glass_ids) ; $i++) {
$new_ordered_eye_glasses = new OrderedEyeGlasses;
$new_ordered_eye_glasses->patient_id = $request->patient_id;
$new_ordered_eye_glasses->episode_id = $request->episode_id;
$new_ordered_eye_glasses->eye_glasses_id = $eye_glass_ids[$i];
$new_ordered_eye_glasses->quantity = $eye_glass_quantity[$i];
$new_ordered_eye_glasses->payment_status = 0; //0 by default to mean not paid
$new_ordered_eye_glasses->created_by = auth()->user()->id;
$new_ordered_eye_glasses->save();
}
}
if($request->pos_sundry_ids){
$new_ordered_sundries = new OrderedSundry;
$new_ordered_sundries->patient_id = $request->patient_id;
$new_ordered_sundries->episode_id = $request->episode_id;
$new_ordered_sundries->sundries_id = implode(",", $request->pos_sundry_ids);
$new_ordered_sundries->quantity = implode(",", $request->sundry_quantity);
$new_ordered_sundries->created_by = auth()->user()->id;
$new_ordered_sundries->save();
}
if ($request->service_id && $request->service_id[0] != null) {
$new_ordered_service = new OrderedService;
$new_ordered_service->patient_id = $request->patient_id;
$new_ordered_service->episode_id = $request->episode_id;
$new_ordered_service->service_id = implode(",", $request->service_id);
$new_ordered_service->quantity = implode(",", $request->quantity);
$new_ordered_service->performed = 0;
$new_ordered_service->performed_id = 0;
$new_ordered_service->created_by = auth()->user()->id;
$new_ordered_service->save();
}
$request->ordered_sundry_ids = OrderedSundry::where('episode_id', $request->episode_id)->where('patient_id', $request->patient_id)
->whereDate('created_at', Carbon::today()->toDateString())->pluck('id')->toArray();
$treatment_item = $treatment_quantity = $treatment_subtotal = [];
// save for treatment
if($request->treatment_id){
$treatment_item = $request->treatment_item;
$treatment_quantity = $request->treatment_quantity;
$treatment_subtotal = $request->treatment_subtotal;
}
$eye_glasses_prices_array = $eye_glasses_quantity_array = $eye_glasses_ids_array = [];
// save for eye_glasses arrays
if($request->eye_glass_item){
$eye_glasses_prices_array = $request->eye_glass_amount;
$eye_glasses_quantity_array = $request->eye_glass_quantity;
$eye_glasses_ids_array = $request->eye_glass_item;
}
$sundry_item = $sundry_quantity = $sundry_subtotal = [];
// save for sundries array
if($request->pos_sundry_ids){
$sundry_item = $request->pos_sundry_ids;
$sundry_quantity = $request->sundry_quantity;
$sundry_subtotal = $request->sundry_subtotal;
}
// save for service arrays
$service_ids_array = [];
$service_prices_array = [];
$service_quantity_array = [];
if($request->service_id){
$service_prices_array = $request->service_item_subtotal;
$service_ids_array = $request->service_id;
$service_quantity_array = $request->quantity;
}
$pos_record = new PointOfSaleRecord();
$pos_record->patient_id = $request->patient_id;
$pos_record->episode_id = $request->episode_id;
$pos_record->treatments = count($treatment_item) > 0 ? json_encode([
"ids" => $treatment_item, "quantity" => $treatment_quantity,
"subtotal" => $treatment_subtotal
]) : NULL;
$pos_record->eye_glasses = count($eye_glasses_ids_array) > 0 ? json_encode([
"ids" => $eye_glasses_ids_array, "quantity" => $eye_glasses_quantity_array,
"subtotal" => $eye_glasses_prices_array
]) : NULL;
$pos_record->sundries = count($sundry_item) > 0 ? json_encode([
"ids" => $sundry_item, "quantity" => $sundry_quantity,
"subtotal" => $sundry_subtotal
]) : NULL;
$pos_record->services = count($service_ids_array) > 0 ? json_encode([
"ids" => $service_ids_array, "quantity" => $service_quantity_array,
"subtotal" => $service_prices_array
]) : NULL;
$pos_record->created_by = Auth::id();
$pos_record->save();
return redirect('point_of_sale/print/' . $pos_record->id);
}
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_patient(Request $request){
$patient = Patient::where('id', $request->patient_id)->first();
return $patient;
}
public function print($id) {
$record = PointOfSaleRecord::find($id);
if ($record) {
if (is_cashier_receipt_type_print_html()) {
$hospital_information = HospitalInformation::first();
$patient = Patient::find($record->patient_id);
$receipt_date = $record->created_at;
$receipt_reprint_date = date('Y-m-d h:i:s');
$treatments_array = json_decode($record->treatments, true);
$sundries_array = json_decode($record->sundries, true);
$eye_glasses_array = json_decode($record->eye_glasses, true);
$services_array = json_decode($record->services, true);
$treatment_item = $treatments_array ? $treatments_array["ids"] : [];
$treatment_quantity = $treatments_array ? $treatments_array["quantity"] : [];
$treatment_subtotal = $treatments_array ? $treatments_array["subtotal"] : [];
$eye_glasses_ids_array = $eye_glasses_array ? $eye_glasses_array["ids"] : [];
$eye_glasses_quantity_array = $eye_glasses_array ? $eye_glasses_array["quantity"] : [];
$eye_glasses_prices_array = $eye_glasses_array ? $eye_glasses_array["subtotal"] : [];
$sundry_item = $sundries_array ? $sundries_array["ids"] : [];
$sundry_quantity = $sundries_array ? $sundries_array["quantity"] : [];
$sundry_subtotal = $sundries_array ? $sundries_array["subtotal"] : [];
$service_ids_array = $services_array ? $services_array["ids"] : [];
$service_quantity_array = $services_array ? $services_array["quantity"] : [];
$service_prices_array = $services_array ? $services_array["subtotal"] : [];
return view('patients::point_of_sale.receipt', compact('treatment_item', 'treatment_quantity', 'treatment_subtotal',
'eye_glasses_prices_array', 'eye_glasses_quantity_array', 'eye_glasses_ids_array', 'hospital_information', 'patient', 'receipt_date',
'sundry_item','sundry_quantity','sundry_subtotal', 'service_ids_array', 'service_prices_array', 'service_quantity_array', 'receipt_reprint_date'));
} else {
// set up the redirect link for html
session()->put('print_pos_pdf', 1);
session()->put('print_pos_pdf_id', $id);
return redirect('/point_of_sale');
}
} else {
return redirect('/point_of_sale');
}
}
public function print_pos_pdf() {
$id = session()->get("print_pos_pdf_id");
// add check for when the people try to reload the page
if (!$id) {
return redirect('/point_of_sale');
}
// lest i forget Thy love for me
session()->forget('print_pos_pdf');
session()->forget('print_pos_pdf_id');
$record = PointOfSaleRecord::find($id);
if ($record) {
$hospital_information = HospitalInformation::first();
$patient = Patient::find($record->patient_id);
$receipt_date = $record->created_at;
$receipt_reprint_date = date('Y-m-d h:i:s');
$treatments_array = json_decode($record->treatments, true);
$sundries_array = json_decode($record->sundries, true);
$eye_glasses_array = json_decode($record->eye_glasses, true);
$services_array = json_decode($record->services, true);
$treatment_item = $treatments_array ? $treatments_array["ids"] : [];
$treatment_quantity = $treatments_array ? $treatments_array["quantity"] : [];
$treatment_subtotal = $treatments_array ? $treatments_array["subtotal"] : [];
$eye_glasses_ids_array = $eye_glasses_array ? $eye_glasses_array["ids"] : [];
$eye_glasses_quantity_array = $eye_glasses_array ? $eye_glasses_array["quantity"] : [];
$eye_glasses_prices_array = $eye_glasses_array ? $eye_glasses_array["subtotal"] : [];
$sundry_item = $sundries_array ? $sundries_array["ids"] : [];
$sundry_quantity = $sundries_array ? $sundries_array["quantity"] : [];
$sundry_subtotal = $sundries_array ? $sundries_array["subtotal"] : [];
$service_ids_array = $services_array ? $services_array["ids"] : [];
$service_quantity_array = $services_array ? $services_array["quantity"] : [];
$service_prices_array = $services_array ? $services_array["subtotal"] : [];
$data = [
"patient" => $patient, "receipt_date" => $receipt_date, "receipt_reprint_date" => $receipt_reprint_date, "hospital_information" => $hospital_information,
"treatment_item" => $treatment_item, "treatment_quantity" => $treatment_quantity, "treatment_subtotal" => $treatment_subtotal,
"eye_glasses_ids_array" => $eye_glasses_ids_array, "eye_glasses_quantity_array" => $eye_glasses_quantity_array, "eye_glasses_prices_array" => $eye_glasses_prices_array,
"sundry_item" => $sundry_item, "sundry_quantity" => $sundry_quantity, "sundry_subtotal" => $sundry_subtotal,
"service_ids_array" => $service_ids_array, "service_quantity_array" => $service_quantity_array, "service_prices_array" => $service_prices_array,
];
$pdf = SnappyPDF::loadView('patients::point_of_sale.print_pos_pdf', $data)
->setOrientation('portrait')
->setPaper('a4')
->setOption('margin-bottom', 5)
->setOption('margin-top', 5)
->setOption('footer-html', '<i>&copy; ' . date('Y') . ' Stre@mline</i>');
return $pdf->inline('Patient Receipt' . date(" d-m-y h:ia") . '.pdf');
} else {
return redirect('/point_of_sale');
}
}
}
File diff suppressed because it is too large Load Diff