@extends('layouts.app') @section('title', 'Outpatient Case Summary | ' . ($visit->patient->full_name ?? '')) @section('styles') @endsection @section('content') @php $patient = $visit->patient; $consultation = $visit->consultation; $triage = $visit->triage; // latestOfMany on the Visit model $labOrders = $visit->labOrders ?? collect(); $imagingRequests = $visit->imagingRequests ?? collect(); $prescriptions = $visit->prescriptions ?? collect(); $invoice = $visit->invoice; // Diagnosis line — uses the formatted accessor that handles both // structured ICD-10 entries and the legacy free-text fallback. $diagnosisLine = $consultation ? $consultation->formatted_diagnosis : ''; // SHA payment lookup — prefer the most recent SHA payment on this // invoice (so the values printed match what the cashier captured) // and fall back to the patient's stored SHA cover when no payment // has been recorded yet. $shaCompany = \App\Models\InsuranceCompany::where('code', 'SHA')->first(); $shaPay = $shaCompany ? $invoice?->payments?->whereNotNull('sha_number')->sortByDesc('created_at')->first() : null; $shaCover = (!$shaPay && $shaCompany && ($invoice?->insurance_company_id ?? null) == $shaCompany->id) ? \App\Models\PatientInsurance::where('patient_id', $patient->id) ->where('insurance_company_id', $shaCompany->id) ->where('is_active', true) ->latest()->first() : null; $shaNumber = $shaPay->sha_number ?? $shaCover->member_number ?? null; $shaMemberName = $shaPay->sha_member_name ?? $shaCover->principal_name ?? null; $shaRelationship = $shaPay->sha_relationship ?? $shaCover->relationship ?? null; $shaAuthRef = $shaPay->sha_auth_reference ?? null; $isSha = !empty($shaNumber); // Payer label for the claim-reconciliation footer $payerLabel = match($invoice?->payment_mode) { 'insurance' => $invoice?->insuranceCompany?->name ?? 'Insurance', 'corporate' => 'Corporate', 'cash' => 'Cash', 'mpesa' => 'M-Pesa', 'bank_transfer'=> 'Bank Transfer', 'waiver' => 'Waiver', default => ucfirst($invoice?->payment_mode ?? '—'), }; // Vitals — show only fields that have values (a triage entry with // only BP recorded shouldn't print empty Temp/Pulse/SpO2 placeholders). $vitals = []; if ($triage) { if ($triage->blood_pressure_systolic && $triage->blood_pressure_diastolic) { $vitals[] = ['BP', $triage->blood_pressure_systolic . '/' . $triage->blood_pressure_diastolic . ' mmHg']; } if ($triage->pulse) $vitals[] = ['Pulse', $triage->pulse . ' bpm']; if ($triage->temperature) $vitals[] = ['Temp', $triage->temperature . '°C']; if ($triage->respiratory_rate) $vitals[] = ['RR', $triage->respiratory_rate . '/min']; if ($triage->oxygen_saturation) $vitals[] = ['SpO₂', $triage->oxygen_saturation . '%']; if ($triage->weight) $vitals[] = ['Wt', $triage->weight . ' kg']; if ($triage->bmi) $vitals[] = ['BMI', $triage->bmi]; if ($triage->blood_sugar) $vitals[] = ['RBS', $triage->blood_sugar . ' mmol/L']; if ($triage->pain_score !== null) $vitals[] = ['Pain', $triage->pain_score . '/10']; } // Length of visit (useful for SHA — proves time spent) $checkIn = $visit->check_in_at; $checkOut = $visit->check_out_at; $durationLabel = ($checkIn && $checkOut) ? $checkIn->diffForHumans($checkOut, ['parts' => 2, 'short' => true, 'syntax' => \Carbon\CarbonInterface::DIFF_ABSOLUTE]) : '—'; @endphp
| Name: | {{ $patient->full_name ?? '' }} | MRN: | {{ $patient->mrn ?? '' }} | Sex: | {{ ucfirst($patient->gender ?? '—') }} | Age: | {{ $patient->age ?? '—' }} |
| Visit No.: | {{ $visit->visit_number ?? '' }} | Date: | {{ $checkIn?->format('d M Y') ?? '—' }} | In: | {{ $checkIn?->format('H:i') ?? '—' }} | Out: | {{ $checkOut?->format('H:i') ?? '—' }} | Clinician: | {{ $consultation?->clinician?->name ?? $visit->clinician?->name ?? '—' }} |
Presenting Complaint
{{ $consultation?->presenting_complaints ?: '—' }}
History of Presenting Illness
{{ $consultation?->history_of_presenting_illness ?: '—' }}
Examination Findings
{{ $consultation->examination_findings }}
Diagnosis (ICD-10)
{{ $diagnosisLine ?: '—' }}
Investigations & Results
| Type | Test / Study | Result / Findings |
|---|---|---|
| Lab | {{ $lab->test_name }} | Results Attached |
| Imaging |
{{ $img->imaging_type }}
@if($img->body_part) {{ $img->body_part }} @endif
|
Results Attached |
Procedures Performed
{{ $consultation->procedures_done }}
Treatment Given
| Medication | Dose | Route | Frequency | Duration |
|---|---|---|---|---|
| {{ $rx->drug_name }} | {{ $rx->dosage ?? '—' }} | {{ $rx->route ?? '—' }} | {{ $rx->frequency ?? '—' }} | {{ $rx->duration ?? '—' }} |
Plan & Follow-up
@if($consultation?->treatment_plan){{ $consultation->treatment_plan }}@endif @if($consultation?->follow_up_notes){{ "\n" }}{{ $consultation->follow_up_notes }}@endif @if($consultation?->follow_up_date){{ "\n" }}Follow-up: {{ $consultation->follow_up_date->format('d M Y') }}@endif @if($consultation?->referral_notes){{ "\n" }}Referral: {{ $consultation->referral_notes }}@endif