@extends('layouts.app')
@section('title', 'Maternity Inpatient | ' . ($maternityAdmission->patient->full_name ?? ''))
@section('styles')
@endsection
@section('content')
@php
$ma = $maternityAdmission;
$p = $ma->patient;
$discharged = app(\App\Services\VisitLockService::class)->isClosed($ma);
$entries = $ma->labourMonitoring;
@endphp
{{-- Unified visit lock banner (read-only + reactivate for admins) --}}
@include('partials._visit-lock-banner', ['entity' => $ma, 'type' => 'maternity'])
{{-- ═══ PATIENT BALANCE SUMMARY (compact strip) ═══ --}}
@include('partials._patient-balance-summary', ['patient' => $ma->patient])
{{-- Patient header --}}
@php
// Round 15: LMP/EDD live on the linked AncRegistration. Surface them
// on the maternity banner so the clinician sees the dating without
// having to navigate away. If the admission has no ANC registration
// linked (walk-in delivery, no prior enrolment), $matReg will be
// null and we show a prompt to set LMP inline.
$matReg = $ma->ancRegistration;
$matLmp = $matReg?->lmp;
$matEdd = $matReg?->edd;
$matCanEditLmpEdd = auth()->user()->hasAnyRole('Clinician', 'Nurse', 'Triage Nurse', 'Hospital Admin', 'Super Admin');
@endphp
{{-- LMP / EDD strip (round 15). Shows the dating from the linked
AncRegistration; clinicians can click "Edit" to update or set
it for walk-in admissions that have no ANC enrolment yet.
Note: the GA in the banner above remains the admission-day
snapshot (gestational_age_weeks recorded on the MaternityAdmission)
— clinically the relevant figure for the encounter. --}}
LMP
{{ $matLmp ? $matLmp->format('d M Y') : '— Not recorded' }}
EDD
{{ $matEdd ? $matEdd->format('d M Y') : '— Not recorded' }}
@if($matCanEditLmpEdd)
@endif
@if($matCanEditLmpEdd)
{{-- Inline edit form — hidden by default; toggled by the button above.
The EDD field auto-fills from LMP via Naegele's rule on input
(LMP + 280 days). Clinician can override it if needed. --}}
@endif
{{-- TABS --}}
@foreach(['overview'=>'Overview','labour'=>'WHO Labour Care Guide','delivery'=>'Delivery','orders'=>'Orders','postnatal'=>'Postnatal','billing'=>'Billing','discharge'=>'Discharge'] as $tab => $label)
@endforeach
{{-- ═══ OVERVIEW TAB ═══ --}}
Admission Details
Admitted: {{ $ma->admission_date?->format('d M Y H:i') ?? '-' }}
{{-- ═══ WORKING DIAGNOSIS (editable inline) ═══
Round 16 — clinicians flagged that the Case Summary print was
permanently disabled because there's no consultation gate on a
maternity admission, so the diagnosis field on the admission
itself was never visible/editable after admit. This card lets
the attending clinician set or update the working diagnosis at
any time during the stay, which unlocks the Case Summary print
on the Billing tab and seeds the Final Diagnosis on Discharge. --}}
Working Diagnosis
Required to print the Case Summary (Billing tab) and pre-fills the Final Diagnosis at discharge.
@if($ma->diagnosis)
Recorded
@else
Not recorded
@endif
@if($discharged)
{{-- Patient already discharged: show read-only --}}
Only clinicians and ward staff can edit the diagnosis.
@endif
{{-- ═══ WHO LABOUR CARE GUIDE TAB ═══ --}}
{{-- ═══════════════════════════════════════════════════════════════════════
WHO LABOUR CARE GUIDE — GRAPHICAL PARTOGRAPH
Multi-track stacked chart sharing a common 0-12h time axis. Each track
renders the corresponding observation column from labour_monitoring rows.
═══════════════════════════════════════════════════════════════════════ --}}
WHO Labour Care Guide | Partograph
{{ $p->full_name }} · Admitted {{ $ma->admission_date?->format('d M Y H:i') }}
@if($ma->labour_onset) · Onset: {{ ucfirst(str_replace('_',' ',$ma->labour_onset)) }} @endif
@if($entries->count())
{{-- Stacked tracks; canvas spans full width and is sized via JS based on parent width --}}
{{-- Legend --}}
X = Cervix (cm)
O = Descent (fifths)
Alert / Action lines
FHR normal band 110–160
{{-- Tabular log (collapsible, hidden by default) --}}
Show tabular observation log ({{ $entries->count() }} {{ Str::plural('entry', $entries->count()) }})
Use the entry form below to record the first observation.
@endif
{{-- ═══════════════════════════════════════════════════════════════════════
RECORD OBSERVATION — collapsible bars below the partograph
Grouped by WHO LCG categories. Each opens independently so a busy
midwife can record only the data points that changed since last entry.
═══════════════════════════════════════════════════════════════════════ --}}
@if(!$discharged)
Record Observation
@endif
{{-- ═══════════════════════════════════════════════════════════════════════
DELIVERY TAB
Empty state: inline form to record the delivery + first newborn.
Filled state: show the delivery summary + newborn cards + "Add Another
Newborn" collapsible (for twins / multiples).
═══════════════════════════════════════════════════════════════════════ --}}
@elseif($matCanDeliver && !$discharged)
{{-- ═══ No delivery yet — show full form ═══ --}}
Record Delivery
Complete delivery details and (optionally) the first newborn. Additional newborns can be added after saving.
@else
@if($discharged) This patient has been discharged. Delivery cannot be recorded.
@else Only clinicians and nurses can record a delivery. @endif
@endif
{{-- ═══════════════════════════════════════════════════════════════════════
MATERNAL COMPLICATIONS (moved here from the standalone Complications
tab — round 16). Clinically these belong next to the delivery record:
PPH, eclampsia, retained placenta, obstructed labour etc. are
intrapartum / immediate postpartum events that document the same
encounter the delivery does. Keeping them on the Delivery tab means
clinicians don't have to flip tabs to reconstruct the event timeline.
═══════════════════════════════════════════════════════════════════════ --}}
Maternal Complications
PPH, eclampsia, sepsis, retained placenta and other intrapartum / immediate postpartum events.
This admission has no linked visit, so lab, imaging and prescription orders cannot be placed here. Orders must be placed from the patient's OPD/IPD encounter.
{{-- ═══ BILLING TAB ═══ --}}
{{-- Mirrors the IPD Billing tab (resources/views/inpatient/show.blade.php
#tab-billing) — same line-items table, same payments table, same
record-payment form, same role gating. No auto-billed lines: per CRH
policy the cashier adds everything manually from the service catalog.
The empty invoice container is created in MaternityController::inpatientShow(). --}}
@foreach($matInv->items as $item)
@php
// Same logic as IPD: only auto-generated and manual lines are
// freely editable in-place. Pharmacy items are locked to the
// Prescriptions section as the single source of truth.
$matIsEditable = in_array($item->source_type, ['auto_consultation','lab_order','imaging_request', null, ''])
&& auth()->user()->hasAnyRole('Reception/Cashier','Clinician','Nurse','Triage Nurse','Dental User','Hospital Admin','Super Admin');
@endphp
@endforeach
{{-- Record payment --}}
@if(auth()->user()->hasAnyRole('Reception/Cashier','Clinician','Nurse','Triage Nurse','Dental User','Super Admin','Hospital Admin'))
@php
// SHA detection — same convention used by OPD/ANC/IPD/Dental.
$matShaCompany = \App\Models\InsuranceCompany::where('code', 'SHA')->first();
$matShaName = $matShaCompany?->name ?? 'SHA (Social Health Authority)';
$matShaCover = null;
if ($matShaCompany && ($ma->visit?->patient_id ?? null)) {
$matShaCover = \App\Models\PatientInsurance::where('patient_id', $ma->visit->patient_id)
->where('insurance_company_id', $matShaCompany->id)
->where('is_active', true)
->latest()
->first();
}
@endphp
@endif
Total Paid
KES {{ number_format($matInv->amount_paid) }}
Balance Due
KES {{ number_format($matInv->balance) }}
{{-- Print buttons: Invoice | Interim Receipt | Final Receipt | Case Summary
Mirrors the OPD/ANC pattern in resources/views/partials/_payment-section.blade.php.
Inline (not @include) for the same reason as IPD — line items +
payments tables are already rendered above. Round 13.
Round 16 — Case Summary now uses the maternity-specific print
endpoint and is gated on the admission's own diagnosis field
(set/updated from the Overview tab), not a phantom consultation
that doesn't exist for maternity encounters. --}}
@php
$matVisit_btn = $ma->visit;
$matPayments_btn = $matInv?->payments ?? collect();
$matLastReceipt = $matPayments_btn->last()?->receipt;
$matHasDiagnosis = !empty(trim((string) $ma->diagnosis));
@endphp