@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
Back

Outpatient Case Summary | {{ $patient->full_name ?? '' }}

@include('partials._document-header') {{-- Title --}}

Outpatient Case Summary

{{-- PATIENT IDENTITY — row 1 --}}
Name:{{ $patient->full_name ?? '' }} MRN:{{ $patient->mrn ?? '' }} Sex:{{ ucfirst($patient->gender ?? '—') }} Age:{{ $patient->age ?? '—' }}
{{-- PATIENT IDENTITY — row 2: visit facts --}}
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 ?? '—' }}
{{-- VITALS STRIP --}} @if(count($vitals))
@foreach($vitals as $i => $v) @if($i > 0)·@endif {{ $v[0] }}: {{ $v[1] }} @endforeach
@endif {{-- COMPLAINT + HPI — side by side to save vertical space --}}

{{ $consultation?->presenting_complaints ?: '—' }}

{{ $consultation?->history_of_presenting_illness ?: '—' }}

{{-- EXAMINATION --}} @if($consultation?->examination_findings)

{{ $consultation->examination_findings }}

@endif {{-- DIAGNOSIS --}}

{{ $diagnosisLine ?: '—' }}

{{-- INVESTIGATIONS — labs + imaging combined --}} @php $hasInvestigations = $labOrders->count() > 0 || $imagingRequests->count() > 0; @endphp @if($hasInvestigations)
@foreach($labOrders as $lab) @endforeach @foreach($imagingRequests as $img) @endforeach
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
@endif {{-- PROCEDURES — only if recorded on the consult --}} @if($consultation?->procedures_done)

{{ $consultation->procedures_done }}

@endif {{-- TREATMENT GIVEN (prescriptions) --}} @if($prescriptions->count())
@foreach($prescriptions as $rx) @endforeach
Medication Dose Route Frequency Duration
{{ $rx->drug_name }} {{ $rx->dosage ?? '—' }} {{ $rx->route ?? '—' }} {{ $rx->frequency ?? '—' }} {{ $rx->duration ?? '—' }}
@endif {{-- PLAN / FOLLOW-UP --}} @if($consultation?->treatment_plan || $consultation?->follow_up_notes || $consultation?->follow_up_date || $consultation?->referral_notes)

@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

@endif {{-- CLAIM RECONCILIATION STRIP — billed total, payer, auth ref --}} @if($invoice)
Bill Total: KES {{ number_format($invoice->total_amount ?? 0) }} Payer: {{ $payerLabel }} @if($isSha && $shaAuthRef) SHA Auth Ref: {{ $shaAuthRef }} @endif Status: Invoiced
@endif {{-- SIGNATURE + STAMP --}}
Clinician Signature
{{ $consultation?->clinician?->name ?? $visit->clinician?->name ?? '—' }}
{{ $checkOut?->format('d M Y H:i') ?? $checkIn?->format('d M Y H:i') ?? '' }}
Official Stamp
Hospital Stamp
@include('partials._document-footer')
@endsection