middleware('auth'); $this->middleware('permission:nira-birth-report', ['only' => ['birth_report']]); } public function birth_report() { $episode_id = session()->get('episode_id'); // Getting details from the maternity delivery records table $deliveryRecord = MaternityDeliveryRecord::select('patient_id', 'foetal_number', 'date_of_birth', 'delivery_time', 'gender', 'weight') ->where('episode_id', $episode_id)->first(); $hospitalInfo = HospitalInformation::select('name', 'district', 'parish', 'sub_county', 'country', 'sub_district')->where('id', 1)->first(); $hospitalDistrict = District::find($hospitalInfo->district)->name; $hospitalSubcounty = Subcounty::find($hospitalInfo->sub_county)->name; $hospitalParish = Parish::find($hospitalInfo->parish)->name; $hospitalLocation = $hospitalParish . ',' . $hospitalSubcounty; $hospitalDistrict = $hospitalDistrict . ',' . $hospitalInfo->country; $date_of_birth = is_null($deliveryRecord) ? [] : explode(',', $deliveryRecord->date_of_birth); $delivery_time = is_null($deliveryRecord) ? [] : explode(',', $deliveryRecord->delivery_time); $babyOne = [ 'dob' => is_null($deliveryRecord) ? 'NA' : $date_of_birth[0], 'delivery_time' => is_null($deliveryRecord) ? 'NA' : Carbon::parse($delivery_time[0])->format('g:i A'), 'hospitalLocation' => is_null($deliveryRecord) ? 'NA' : $hospitalLocation, 'hospitalDistrict' => is_null($deliveryRecord) ? 'NA' : $hospitalDistrict, 'hospitalName' => is_null($deliveryRecord) ? 'NA' : $hospitalInfo->name, 'gender' => is_null($deliveryRecord) ? 'NA' : $deliveryRecord->gender[0], 'weight' => is_null($deliveryRecord) ? 'NA' : $deliveryRecord->weight[0], ]; $motherDetail = is_null($deliveryRecord) ? '' : Patient::select('first_name', 'last_name', 'occupation_id', 'national_id', 'district_id', 'county_id', 'subcounty_id', 'parish_id', 'village_id') ->where('id', $deliveryRecord->patient_id)->first(); $mother = [ 'last_name' => is_null($deliveryRecord) ? 'NA' : $motherDetail->last_name, 'first_name' => is_null($deliveryRecord) ? 'NA' : $motherDetail->first_name, 'NIN' => is_null($deliveryRecord) ? 'NA' : $motherDetail->national_id, 'occupation' => is_null($deliveryRecord) ? 'NA' : Occupation::find($motherDetail->occupation_id)->name, 'district' => is_null($deliveryRecord) ? 'NA' : District::find($motherDetail->district_id)->name, 'county' => is_null($deliveryRecord) ? 'NA' : County::find($motherDetail->county_id)->name, 'subcounty' => is_null($deliveryRecord) ? 'NA' : Subcounty::find($motherDetail->subcounty_id)->name, 'parish' => is_null($deliveryRecord) ? 'NA' : Parish::find($motherDetail->parish_id)->name, 'village' => is_null($deliveryRecord) ? 'NA' : Village::find($motherDetail->village_id)->name ]; if (is_null($deliveryRecord)): flash("The MATERNITY DELIVERY RECORD has not been saved on Stre@mline.")->error(); endif; return view('reports::reports.nira.birth', compact('babyOne', 'mother')); } public function death_report() { $episode_id = session()->get('episode_id'); return view('reports::reports.nira.death'); } }