{{-- Lazy-loaded expansion of a single encounter row. Variables: $details - array from PatientHistoryService::details() $patient - Patient model $billingOnly - bool, suppresses clinical sections for cashier roles --}}
{{-- ── CLINICAL SECTION (clinicians only) ───────────────────── --}} @unless($billingOnly) {{-- Vitals (visit only — IPD/ANC/Maternity carry vitals via different paths) --}} @if(($details['type'] === 'visit') && !empty($details['vitals'])) @php $t = $details['vitals']; @endphp

Vitals

BP: {{ $t->blood_pressure_systolic ?? '—' }}/{{ $t->blood_pressure_diastolic ?? '—' }}
Pulse: {{ $t->pulse ?? '—' }}
Temp: {{ $t->temperature ?? '—' }}°C
Weight: {{ $t->weight ?? '—' }} kg
@if($t->oxygen_saturation)
SpO₂: {{ $t->oxygen_saturation }}%
@endif
@endif {{-- Clinical notes (visit consultation) --}} @if(($details['type'] === 'visit') && !empty($details['consultation'])) @php $c = $details['consultation']; $diag = is_array($c->diagnosis) ? implode(', ', array_filter($c->diagnosis)) : (string) ($c->diagnosis ?? ''); @endphp

Clinical Notes

@if($c->presenting_complaints)
Presenting complaints: {{ $c->presenting_complaints }}
@endif @if($c->history_of_presenting_illness)
HPI: {{ $c->history_of_presenting_illness }}
@endif @if($c->examination_findings)
Exam: {{ $c->examination_findings }}
@endif @if($diag)
Diagnosis: {{ $diag }}
@endif @if($c->treatment_plan)
Plan: {{ $c->treatment_plan }}
@endif
@endif {{-- ANC episode summary --}} @if($details['type'] === 'anc') @php $r = $details['registration']; @endphp

ANC Episode

LMP: {{ $r->lmp?->format('d M Y') ?? '—' }}
EDD: {{ $r->edd?->format('d M Y') ?? '—' }}
G/P: G{{ $r->gravida ?? '—' }}P{{ $r->parity ?? '—' }}
Risk: {{ $r->risk_status ?? 'normal' }}
@if($r->package_type)
Package: {{ $r->package_type }} — KES {{ number_format($r->package_amount ?? 0) }}
@endif @if($r->outcome)
Outcome: {{ $r->outcome }} @if($r->outcome_date)on {{ $r->outcome_date?->format('d M Y') }}@endif
@endif
@if($details['anc_visits']->count())

Encounters in this episode ({{ $details['anc_visits']->count() }})

@foreach($details['anc_visits'] as $av)
{{ $av->visit_date?->format('d M Y') ?? '—' }} · GA {{ $av->gestational_age_weeks ?? '—' }}w @if($av->risk_level){{ $av->risk_level }} risk@endif
@endforeach
@endif
@endif {{-- Admission / Maternity admission summary --}} @if(in_array($details['type'], ['admission', 'maternity'])) @php $a = $details['admission']; @endphp

{{ $details['type'] === 'maternity' ? 'Maternity Admission' : 'IPD Admission' }}

Admitted: {{ $a->admission_date?->format('d M Y H:i') ?? '—' }}
Discharged: {{ $a->discharge_date?->format('d M Y H:i') ?? 'still admitted' }}
{{-- Reason field name differs: Admission uses 'reason'; MaternityAdmission uses 'reason_for_admission' --}} @if($details['type'] === 'admission' && ($a->reason ?? null))
Reason: {{ $a->reason }}
@elseif($details['type'] === 'maternity' && ($a->reason_for_admission ?? null))
Reason: {{ $a->reason_for_admission }}
@endif {{-- Diagnosis field name differs: Admission has 'diagnosis_on_admission'; MaternityAdmission has 'diagnosis' --}} @if($details['type'] === 'admission' && ($a->diagnosis_on_admission ?? null))
Diagnosis: {{ $a->diagnosis_on_admission }}
@elseif($details['type'] === 'maternity' && ($a->diagnosis ?? null))
Diagnosis: {{ $a->diagnosis }}
@endif
@if($details['type'] === 'maternity' && !empty($details['delivery'])) @php $d = $details['delivery']; @endphp

Delivery

Mode: {{ str_replace('_', ' ', $d->mode_of_delivery ?? '—') }}
Date: {{ $d->delivery_date?->format('d M Y H:i') ?? '—' }}
@if($d->newborns?->count())
Newborns: {{ $d->newborns->count() }}
@endif
@endif
@endif {{-- Lab orders (universal) --}} @if(!empty($details['lab_orders']) && $details['lab_orders']->count())

Labs ({{ $details['lab_orders']->count() }})

@foreach($details['lab_orders'] as $lab) @php // LabResult.results is cast as array. Render as a // compact "key: value" summary; fall back to em-dash. $resultArr = optional($lab->result)->results; $resultStr = '—'; if (is_array($resultArr) && count($resultArr)) { $pairs = []; foreach ($resultArr as $k => $v) { $pairs[] = is_string($k) ? $k.': '.$v : (string) $v; } $resultStr = implode(' · ', $pairs); } @endphp @endforeach
Test Result Status
{{ $lab->test_name ?? '—' }} {{ $resultStr }} {{ $lab->status }}
@endif {{-- Imaging (universal) --}} @if(!empty($details['imaging']) && $details['imaging']->count())

Imaging ({{ $details['imaging']->count() }})

@endif {{-- Prescriptions (universal) --}} @if(!empty($details['prescriptions']) && $details['prescriptions']->count())

Prescriptions ({{ $details['prescriptions']->count() }})

@endif @endunless {{-- ── BILLING SECTION (always visible) ─────────────────────── --}} @php // Normalise: ANC has multiple invoices, others have one. $invoices = collect(); if (!empty($details['invoices'])) $invoices = $details['invoices']; elseif (!empty($details['invoice'])) $invoices = collect([$details['invoice']]); @endphp @if($invoices->count())

Billing ({{ $invoices->count() }} invoice{{ $invoices->count() > 1 ? 's' : '' }})

@foreach($invoices as $inv) @endforeach
Invoice # Date Total Paid Balance
{{ $inv->invoice_number ?? '—' }} {{ $inv->created_at?->format('d M Y') ?? '—' }} KES {{ number_format($inv->total_amount ?? 0) }} KES {{ number_format($inv->amount_paid ?? 0) }} KES {{ number_format($inv->balance ?? 0) }}
@endif