mirror of
https://gitlab.com/signalytic/client-external/streamline/streamline-emr.git
synced 2026-09-11 18:51:31 +00:00
resolved conflicts
This commit is contained in:
+1605
File diff suppressed because it is too large
Load Diff
+1579
File diff suppressed because it is too large
Load Diff
+1718
File diff suppressed because it is too large
Load Diff
Executable
+238
@@ -0,0 +1,238 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Patients\Http\Controllers;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\View\View;
|
||||
use Streamline\Models\Clinic;
|
||||
use Streamline\Models\PatientEpisode;
|
||||
use Streamline\Models\InpatientInfo;
|
||||
use Illuminate\Database\QueryException;
|
||||
use Streamline\Models\Consultation;
|
||||
|
||||
class PatientFlowMonitoringController extends Controller {
|
||||
|
||||
public function __construct() {
|
||||
$this->middleware('auth');
|
||||
$this->middleware('permission:patient-flow-monitoring');
|
||||
}
|
||||
|
||||
public function index(Request $request): View
|
||||
{
|
||||
$clinic_id = $request->clinic_id;
|
||||
$search_by = $request->search_by;
|
||||
$reg_date = $request->reg_date;
|
||||
$start_date = $request->start_date;
|
||||
$end_date = $request->end_date;
|
||||
$order_by = $request->order_by ?? 1;
|
||||
|
||||
if (!isset($clinic_id) && !isset($search_by)){
|
||||
$clinic_id = session()->get('clinic_id');
|
||||
$search_by = session()->get('search_by');
|
||||
$reg_date = session()->get('reg_date');
|
||||
$start_date = session()->get('start_date');
|
||||
$end_date = session()->get('end_date');
|
||||
$order_by = session()->get('order_by');
|
||||
} else {
|
||||
session()->put('clinic_id', $clinic_id);
|
||||
session()->put('search_by', $search_by);
|
||||
session()->put('reg_date', $reg_date);
|
||||
session()->put('start_date', $start_date);
|
||||
session()->put('end_date', $end_date);
|
||||
session()->put('order_by', $order_by);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
if($search_by == 3){
|
||||
//yesterday
|
||||
$start_date_search = Carbon::yesterday()->startOfDay()->toDateTimeString();
|
||||
$end_date_search = Carbon::yesterday()->endOfDay()->toDateTimeString();
|
||||
$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();
|
||||
|
||||
$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();
|
||||
|
||||
$date_search = streamline_date($start_date_search) . " to " . streamline_date($end_date_search);
|
||||
} else {
|
||||
// Today
|
||||
$start_date_search = Carbon::today()->startOfDay()->toDateTimeString();
|
||||
$end_date_search = Carbon::today()->endOfDay()->toDateTimeString();
|
||||
|
||||
$date_search = "Today";
|
||||
}
|
||||
|
||||
switch (get_select_clinic_order_type()) {
|
||||
case 0:
|
||||
if ($order_by == 1) {
|
||||
$order_by_text = "patient_episodes.id";
|
||||
} else {
|
||||
$order_by_text = "triage.severe_grade desc, patient_episodes.id";
|
||||
}
|
||||
break;
|
||||
case 1:
|
||||
if ($order_by == 1) {
|
||||
$order_by_text = "patient_episodes.id desc";
|
||||
} else {
|
||||
$order_by_text = "triage.severe_grade desc, patient_episodes.id desc";
|
||||
}
|
||||
break;
|
||||
case 2:
|
||||
default:
|
||||
if ($order_by == 1) {
|
||||
$order_by_text = "consultations.completed, patient_episodes.id";
|
||||
} else {
|
||||
$order_by_text = "consultations.completed, triage.severe_grade desc, patient_episodes.id";
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
if($clinic_id == 0){
|
||||
//opd
|
||||
$patient_episodes = DB::table('patient_episodes')
|
||||
->whereNull('patient_episodes.deleted_at')
|
||||
->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')
|
||||
->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')
|
||||
->whereBetween('patient_episodes.created_at', [$start_date_search, $end_date_search])
|
||||
->orderByRaw($order_by_text)
|
||||
->paginate(200);
|
||||
$clinic_name = "OPD";
|
||||
} else {
|
||||
//other clinics
|
||||
$patient_episodes = DB::table('patient_episodes')
|
||||
->whereNull('patient_episodes.deleted_at')
|
||||
->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])
|
||||
->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);
|
||||
$clinic_name = get_name($clinic_id, 'id', 'name', 'clinics');
|
||||
}
|
||||
|
||||
$patient_categories = DB::table("patient_categories")->whereNull('deleted_at')->pluck("name", "id");
|
||||
|
||||
$clinics = DB::table("clinics")->whereNull("deleted_at")->orderBy("name")->pluck("name", "id")->toArray();
|
||||
$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 -', '');
|
||||
|
||||
// dd($date_search);
|
||||
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){
|
||||
|
||||
$episode = PatientEpisode::find($episode_id);
|
||||
$patient_id = $episode->patient_id;
|
||||
|
||||
// set up session
|
||||
session()->put(['patient_id' => $patient_id]);
|
||||
session()->put(['episode_id' => $episode_id]);
|
||||
|
||||
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';
|
||||
} elseif ($route == 'create_surgery'){
|
||||
$url = '/theatre_surgery/create';
|
||||
} elseif ($route == 'anaesthetics_history'){
|
||||
$url = '/anaesthetics/history';
|
||||
} elseif ($route == 'surgery_index'){
|
||||
$url = '/theatre_surgery';
|
||||
} elseif ($route == 'treatment') {
|
||||
$url = '/prescriptions/create';
|
||||
} elseif ($route == 'anc_registration_button'){
|
||||
$url = '/ante_natal_clinic/create';
|
||||
} elseif ($route == 'anc_followup_button'){
|
||||
$url = '/ante_natal_clinic_follow_up/create';
|
||||
} elseif ($route == 'investigation') {
|
||||
$url = '/investigations/investigations_review';
|
||||
} elseif ($route == 'triage_without_etat') {
|
||||
session()->put('triage_without_etat', 1);
|
||||
$url = '/triage';
|
||||
} elseif ($route == 'consultation_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);
|
||||
}
|
||||
|
||||
public function inpatient_admission(Request $request)
|
||||
{
|
||||
$episode = PatientEpisode::find($request->admission_episode_id);
|
||||
$patient_id = $episode->patient_id;
|
||||
$ward_id = $request->admission_ward_id;
|
||||
$admitted_on = $request->ward_admission_date;
|
||||
|
||||
try {
|
||||
$episode_id = $episode->id;
|
||||
session()->put(['episode_id' => $episode_id]);
|
||||
session()->put(['patient_id' => $patient_id]);
|
||||
|
||||
$consultation = Consultation::where(['patient_id' => $patient_id, 'episode_id' => $episode_id])->first();
|
||||
if ($consultation) {
|
||||
$consultation->outcome_id = get_name("Admitted", "name", "id", "outcomes");
|
||||
$consultation->ward_id = $ward_id;
|
||||
$consultation->admitted_on = $admitted_on;
|
||||
$consultation->save();
|
||||
}
|
||||
|
||||
// Admit patient in ward
|
||||
$existing_inpatient = InpatientInfo::where(['episode_id' => $episode_id])->first();
|
||||
if ($existing_inpatient) {
|
||||
$ward_id = $existing_inpatient->ward_id;
|
||||
$ward_name = get_name($ward_id, "id", "name", "wards");
|
||||
|
||||
flash("Patient ".get_name($patient_id, "id", "number", "patients")." already admitted for in admitted in ".$ward_name. ". You can use the ward transfer option incase you want to transfer to another ward")->error();
|
||||
} else {
|
||||
$inpatient = is_null($existing_inpatient) ? new InpatientInfo : $existing_inpatient;
|
||||
$inpatient = new InpatientInfo;
|
||||
$inpatient->patient_id = $patient_id;
|
||||
$inpatient->episode_id = $episode_id;
|
||||
$inpatient->admitted_on = $admitted_on;
|
||||
$inpatient->ward_id = $ward_id;
|
||||
$inpatient->created_by = auth()->user()->id;
|
||||
$inpatient->created_at = Carbon::now();
|
||||
$inpatient->save();
|
||||
|
||||
$ward_name = get_name($ward_id, "id", "name", "wards");
|
||||
|
||||
flash("Patient ".get_name($patient_id, "id", "number", "patients")." admitted in ".$ward_name)->success();
|
||||
}
|
||||
|
||||
return redirect('/patient_episodes/');
|
||||
} catch (QueryException $e) {
|
||||
flash("This episode already exists!")->error();
|
||||
return back()->withInput();
|
||||
}
|
||||
}
|
||||
}
|
||||
+498
@@ -0,0 +1,498 @@
|
||||
<?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 Illuminate\Support\Facades\Redirect;
|
||||
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;
|
||||
use Streamline\Services\ItemsStockService;
|
||||
|
||||
class PointOfSaleController extends Controller {
|
||||
|
||||
public function __construct(protected ItemsStockService $itemStockService)
|
||||
{
|
||||
}
|
||||
|
||||
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::id();
|
||||
$episode->updated_by = Auth::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::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::id();
|
||||
$episode->updated_by = Auth::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 (stock_levels_to_consider() == 0) {//getting total stock for optical from both stores and pharmacy
|
||||
foreach($pre_ordered_eye_glasses as $eye) {$eye->total_stock = $this->itemStockService->getItemAllQuantityByTotal($eye->id, 7);}
|
||||
} else{//getting total stock for opticals from pharmacy
|
||||
foreach($pre_ordered_eye_glasses as $eye) {$eye->total_stock = $this->itemStockService->getItemQuantity('pharmacy_stock',$eye->id, 7);}
|
||||
}
|
||||
|
||||
}
|
||||
if ($request->selected_drugs) {
|
||||
if($request->manual_drug_select == 1){
|
||||
$manual_patient_prescriptions = Drug::whereIn('id', $request->selected_drugs)->get();
|
||||
if (stock_levels_to_consider() == 0) {//getting total stock for drugs from both stores and pharmacy
|
||||
foreach($manual_patient_prescriptions as $drug) {$drug->total_stock = $this->itemStockService->getItemAllQuantityByTotal($drug->id, 1);}
|
||||
} else {//getting total stock for drugs from pharmacy
|
||||
foreach($manual_patient_prescriptions as $drug) {$drug->total_stock = $this->itemStockService->getItemQuantity('pharmacy_stock',$drug->id, 1);}
|
||||
}
|
||||
|
||||
}else if($request->automatic_drug_select == 1){
|
||||
$automatic_patient_prescriptions = Drug::whereIn('id', $request->selected_drugs)->get();
|
||||
if (stock_levels_to_consider() == 0) {//getting total stock for drugs from both stores and pharmacy
|
||||
foreach($automatic_patient_prescriptions as $drug) {$drug->total_stock = $this->itemStockService->getItemAllQuantityByTotal($drug->id, 1);}
|
||||
} else{//getting total stock for optical from pharmacy
|
||||
foreach($automatic_patient_prescriptions as $drug) {$drug->total_stock = $this->itemStockService->getItemQuantity('pharmacy_stock',$drug->id, 1);}
|
||||
}
|
||||
}
|
||||
}
|
||||
if ($request->selected_sundries) {
|
||||
$pre_ordered_sundries = Sundry::whereIn('id', $request->selected_sundries)->get();
|
||||
if (stock_levels_to_consider() == 0) {//getting total stock for sundry from both stores and pharmacy
|
||||
foreach($pre_ordered_sundries as $sundry) {$sundry->total_stock = $this->itemStockService->getItemAllQuantityByTotal($sundry->id, 2);}
|
||||
} else{//getting total stock for optical from pharmacy
|
||||
foreach($pre_ordered_sundries as $sundry) {$sundry->total_stock = $this->itemStockService->getItemQuantity('pharmacy_stock',$sundry->id, 2);}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
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){
|
||||
$order_sundries_id = NULL;
|
||||
$treatment_id = NULL;
|
||||
$order_optical_id = NULL;
|
||||
$order_service_id = NULL;
|
||||
|
||||
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->is_pos = 1;
|
||||
$treatment->created_by = Auth::id();
|
||||
$treatment->save();
|
||||
|
||||
$treatment_id = $treatment->id;
|
||||
}
|
||||
|
||||
if($request->eye_glass_item){
|
||||
$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 = implode(",", $request->eye_glass_item);
|
||||
$new_ordered_eye_glasses->quantity = implode(",", $request->eye_glass_quantity);
|
||||
$new_ordered_eye_glasses->payment_status = 0; //0 by default to mean not paid
|
||||
$new_ordered_eye_glasses->created_by = auth()->id();
|
||||
$new_ordered_eye_glasses->is_pos = 1;
|
||||
$new_ordered_eye_glasses->save();
|
||||
|
||||
$order_optical_id = $new_ordered_eye_glasses->id;
|
||||
}
|
||||
|
||||
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()->id();
|
||||
$new_ordered_sundries->is_pos = 1;
|
||||
$new_ordered_sundries->save();
|
||||
|
||||
$order_sundries_id = $new_ordered_sundries->id;
|
||||
}
|
||||
|
||||
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()->id();
|
||||
$new_ordered_service->is_pos = 1;
|
||||
$new_ordered_service->save();
|
||||
|
||||
$order_service_id = $new_ordered_service->id;
|
||||
}
|
||||
|
||||
$treatment_item = $treatment_quantity = $treatment_subtotal = [];
|
||||
// save for treatment
|
||||
if($request->treatment_item){
|
||||
$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_subtotal;
|
||||
$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, "order_id" => $treatment_id
|
||||
]) : 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, "order_id" => $order_optical_id
|
||||
]) : NULL;
|
||||
$pos_record->sundries = count($sundry_item) > 0 ? json_encode([
|
||||
"ids" => $sundry_item, "quantity" => $sundry_quantity,
|
||||
"subtotal" => $sundry_subtotal, "order_id" => $order_sundries_id
|
||||
]) : NULL;
|
||||
$pos_record->services = count($service_ids_array) > 0 ? json_encode([
|
||||
"ids" => $service_ids_array, "quantity" => $service_quantity_array,
|
||||
"subtotal" => $service_prices_array, "order_id" => $order_service_id
|
||||
]) : 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::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');
|
||||
$first_printed_by = $record->created_by;
|
||||
|
||||
$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"] : [];
|
||||
$treatment_number = $treatments_array ? ($treatments_array["order_id"] ?? 0) : [];
|
||||
$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"] : [];
|
||||
$eye_glasses_number = $eye_glasses_array ? ($eye_glasses_array["order_id"] ?? 0) : [];
|
||||
$sundry_item = $sundries_array ? $sundries_array["ids"] : [];
|
||||
$sundry_quantity = $sundries_array ? $sundries_array["quantity"] : [];
|
||||
$sundry_subtotal = $sundries_array ? $sundries_array["subtotal"] : [];
|
||||
$sundry_number = $sundries_array ? ($sundries_array["order_id"] ?? 0) : [];
|
||||
$service_ids_array = $services_array ? $services_array["ids"] : [];
|
||||
$service_quantity_array = $services_array ? $services_array["quantity"] : [];
|
||||
$service_prices_array = $services_array ? $services_array["subtotal"] : [];
|
||||
$service_number = $services_array ? ($services_array["order_id"] ?? 0) : [];
|
||||
|
||||
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', 'first_printed_by',
|
||||
'sundry_item','sundry_quantity','sundry_subtotal', 'service_ids_array', 'service_prices_array', 'service_quantity_array', 'receipt_reprint_date',
|
||||
'eye_glasses_number', 'treatment_number', 'sundry_number', 'service_number'));
|
||||
} 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"] : [];
|
||||
$treatment_number = $treatments_array ? ($treatments_array["order_id"] ?? 0) : [];
|
||||
$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"] : [];
|
||||
$eye_glasses_number = $eye_glasses_array ? ($eye_glasses_array["order_id"] ?? 0) : [];
|
||||
$sundry_item = $sundries_array ? $sundries_array["ids"] : [];
|
||||
$sundry_quantity = $sundries_array ? $sundries_array["quantity"] : [];
|
||||
$sundry_subtotal = $sundries_array ? $sundries_array["subtotal"] : [];
|
||||
$sundry_number = $sundries_array ? ($sundries_array["order_id"] ?? 0) : [];
|
||||
$service_ids_array = $services_array ? $services_array["ids"] : [];
|
||||
$service_quantity_array = $services_array ? $services_array["quantity"] : [];
|
||||
$service_prices_array = $services_array ? $services_array["subtotal"] : [];
|
||||
$service_number = $services_array ? ($services_array["order_id"] ?? 0) : [];
|
||||
|
||||
$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,
|
||||
"treatment_number" => $treatment_number, "eye_glasses_number" => $eye_glasses_number, "sundry_number" => $sundry_number, "service_number" => $service_number,
|
||||
];
|
||||
|
||||
$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>© ' . date('Y') . ' Stre@mline</i>');
|
||||
|
||||
return $pdf->inline('Patient Receipt' . date(" d-m-y h:ia") . '.pdf');
|
||||
} else {
|
||||
return redirect('/point_of_sale');
|
||||
}
|
||||
}
|
||||
}
|
||||
+1238
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user