app/Http/Controllers/DrugController.php
/**
     * Show the form for creating a new resource.
     *
     * @return \Illuminate\Http\Response
     */
Show the form for creating a new resource.
@return \Illuminate\Http\Response
Show the form for creating a new resource . @return \ Illuminate \ Http \ Response
public function create()
    {
        $allPatientRegistration ="";
        $vitals="";
        $other_medication="";
        $detentionBill ="";
        $getBills ="";
        $medication="";
        $totalCashSales = Bill::sum('total_amount_to_pay');
        $totalSales = Bill::sum('amount');
        $totalNhisSale = Bill::sum('insurance_amount');
        $not_seen = Registration::with('patient')
            ->where('vitals',1)
            ->where('consult',1)
            ->where('medication',0)
            ->get();
        $registration = Registration::with('patient')
            ->where('vitals',1)
            ->where('consult',1)
            ->where('medication',0)
            ->whereDate('created_at', Carbon::today())
            ->limit(1)
            ->orderBy('created_at','asc')
            ->first();
        if (empty($registration)){
            $registration = Registration::with('patient')
                ->where('vitals',1)
                ->where('review',1)
                ->where('medication',0)
                ->whereDate('created_at', Carbon::today())
                ->limit(1)
                ->orderBy('created_at','asc')
                ->first();
        }
        if (!empty($registration)){
            $allPatientRegistration = Registration::where('patient_id',$registration->patient_id)->get();
            $vitals = Vital::where('registration_id',$registration->id)
                ->where('patient_id',$registration->patient_id)
                ->latest()->first();
            $medication= Medication::with('drugs')
                ->where('dispensed',0)
                ->where('registration_id',$registration->id)
                ->where('patient_id',$registration->patient_id)
                ->get();
            $getBills = Bill::where('patient_id',$registration->patient_id)
                ->where('registration_id',$registration->id)
                ->get();
            if ( $registration->detain == 0){
                $detentionBill = 0;
            }
            elseif ( $registration->detain == 1){
                $dateAdmitted = \Carbon\Carbon::createFromFormat('Y-m-d H:s:i', $registration->created_at);
                $today = \Carbon\Carbon::createFromFormat('Y-m-d H:s:i', date('Y-m-d H:s:i'));
                $detentionDays = $today->diffInDays($dateAdmitted);
                if ($detentionDays < 3){
                    $detentionBill = 20;
                }else{
                    $additionalDays = $detentionDays - 2;
                    $calAdditionalCharges = $additionalDays*5;
                    $detentionBill = $calAdditionalCharges+20;
                }
            }
            elseif ($registration->detain == 2){
                $dateAdmitted = \Carbon\Carbon::createFromFormat('Y-m-d H:s:i', $registration->created_at);
                $today = \Carbon\Carbon::createFromFormat('Y-m-d H:s:i', $registration->discharged_date);
                $detentionDays = $today->diffInDays($dateAdmitted);
                if ($detentionDays < 3){
                    $detentionBill = 20;
                }else{
                    $additionalDays = $detentionDays - 2;
                    $calAdditionalCharges = $additionalDays*5;
                    $detentionBill = $calAdditionalCharges+20;
                }
            }
            $other_medication= OtherMedication::where('registration_id',$registration->id)
                ->where('patient_id',$registration->patient_id)
                ->whereDate('created_at', Carbon::today())
                ->latest()->get();
        }
        $drugs = Drug::all()->count();
        return view('pages.pharmacy.drug-dispense')
            ->with('registration',$registration)
            ->with('drugs',$drugs)
            ->with('vitals',$vitals)
            ->with('medication',$medication)
            ->with('totalCashSales',$totalCashSales)
            ->with('totalNhisSale',$totalNhisSale)
            ->with('totalSales',$totalSales)
            ->with('getBills',$getBills)
            ->with('detentionBill',$detentionBill)
            ->with('other_medication',$other_medication)
            ->with('allPatientRegistration',$allPatientRegistration)
            ->with('not_seen',$not_seen);
    }
public function create ( ) { $ allPatientRegistration = " " ; $ vitals = " " ; $ other_medication = " " ; $ detentionBill = " " ; $ getBills = " " ; $ medication = " " ; $ totalCashSales = Bill :: sum ( 'total_amount_to_pay' ) ; $ totalSales = Bill :: sum ( 'amount' ) ; $ totalNhisSale = Bill :: sum ( 'insurance_amount' ) ; $ not_seen = Registration :: with ( 'patient' ) -> where ( 'vitals' , 1 ) -> where ( 'consult' , 1 ) -> where ( 'medication' , 0 ) -> get ( ) ; $ registration = Registration :: with ( 'patient' ) -> where ( 'vitals' , 1 ) -> where ( 'consult' , 1 ) -> where ( 'medication' , 0 ) -> whereDate ( 'created_at' , Carbon :: today ( ) ) -> limit ( 1 ) -> orderBy ( 'created_at' , 'asc' ) -> first ( ) ; if ( empty ( $ registration ) ) { $ registration = Registration :: with ( 'patient' ) -> where ( 'vitals' , 1 ) -> where ( 'review' , 1 ) -> where ( 'medication' , 0 ) -> whereDate ( 'created_at' , Carbon :: today ( ) ) -> limit ( 1 ) -> orderBy ( 'created_at' , 'asc' ) -> first ( ) ; } if ( ! empty ( $ registration ) ) { $ allPatientRegistration = Registration :: where ( 'patient_id' , $ registration -> patient_id ) -> get ( ) ; $ vitals = Vital :: where ( 'registration_id' , $ registration -> id ) -> where ( 'patient_id' , $ registration -> patient_id ) -> latest ( ) -> first ( ) ; $ medication = Medication :: with ( 'drugs' ) -> where ( 'dispensed' , 0 ) -> where ( 'registration_id' , $ registration -> id ) -> where ( 'patient_id' , $ registration -> patient_id ) -> get ( ) ; $ getBills = Bill :: where ( 'patient_id' , $ registration -> patient_id ) -> where ( 'registration_id' , $ registration -> id ) -> get ( ) ; if ( $ registration -> detain == 0 ) { $ detentionBill = 0 ; } elseif ( $ registration -> detain == 1 ) { $ dateAdmitted = \ Carbon \ Carbon :: createFromFormat ( 'Y-m-d H:s:i' , $ registration -> created_at ) ; $ today = \ Carbon \ Carbon :: createFromFormat ( 'Y-m-d H:s:i' , date ( 'Y-m-d H:s:i' ) ) ; $ detentionDays = $ today -> diffInDays ( $ dateAdmitted ) ; if ( $ detentionDays < 3 ) { $ detentionBill = 20 ; } else { $ additionalDays = $ detentionDays - 2 ; $ calAdditionalCharges = $ additionalDays * 5 ; $ detentionBill = $ calAdditionalCharges + 20 ; } } elseif ( $ registration -> detain == 2 ) { $ dateAdmitted = \ Carbon \ Carbon :: createFromFormat ( 'Y-m-d H:s:i' , $ registration -> created_at ) ; $ today = \ Carbon \ Carbon :: createFromFormat ( 'Y-m-d H:s:i' , $ registration -> discharged_date ) ; $ detentionDays = $ today -> diffInDays ( $ dateAdmitted ) ; if ( $ detentionDays < 3 ) { $ detentionBill = 20 ; } else { $ additionalDays = $ detentionDays - 2 ; $ calAdditionalCharges = $ additionalDays * 5 ; $ detentionBill = $ calAdditionalCharges + 20 ; } } $ other_medication = OtherMedication :: where ( 'registration_id' , $ registration -> id ) -> where ( 'patient_id' , $ registration -> patient_id ) -> whereDate ( 'created_at' , Carbon :: today ( ) ) -> latest ( ) -> get ( ) ; } $ drugs = Drug :: all ( ) -> count ( ) ; return view ( 'pages.pharmacy.drug-dispense' ) -> with ( 'registration' , $ registration ) -> with ( 'drugs' , $ drugs ) -> with ( 'vitals' , $ vitals ) -> with ( 'medication' , $ medication ) -> with ( 'totalCashSales' , $ totalCashSales ) -> with ( 'totalNhisSale' , $ totalNhisSale ) -> with ( 'totalSales' , $ totalSales ) -> with ( 'getBills' , $ getBills ) -> with ( 'detentionBill' , $ detentionBill ) -> with ( 'other_medication' , $ other_medication ) -> with ( 'allPatientRegistration' , $ allPatientRegistration ) -> with ( 'not_seen' , $ not_seen ) ; }
Show the form for creating a new resource.
Show the form for creating a new resource .
//            return $medication; //                ->where('type','!=','Drug') /*       $checkForArrears = Payment::where('patient_id',$registration->patient_id)
       //                ->where('arrears','<=','grand_total')
                       ->where('arrears','!=',0)
                       ->get();

                   return $checkForArrears;*/ //check if patient is detained Or Admitted //get date admitted //if patient is discharged, then use discharged_date instead of today //get date admitted /*
             * End detention bill calculation
             */