@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 admission's diagnosis
field captured at admit time was never visible/editable again
after the patient hit the ward. This card lets the attending
clinician set or refine the working diagnosis at any point
during the stay; the value also pre-fills the Final Diagnosis
on the Discharge tab. --}}
Working Diagnosis
Pre-fills the Final Diagnosis at discharge. Update as the picture clarifies during the admission.
@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.
{{-- Dispense (one tap) — green shield-check, matches OPD encounter. --}}
@if($matRxCanDispense)
@endif
@if($matCanOrder && !$matRxLocked)
@endif
@if($matCanCancelRx && !$matRxLocked)
@elseif($matRxLocked)
🔒
@endif
{{-- Reverse dispense — Admin, Clinician or Nurse. Amber icon,
identical to the OPD encounter. Returns units to stock and
re-queues the Rx; invoice line stays (use Delete to drop it). --}}
@if($matCanOrder && $matRxDispensed > 0 && $rx->status !== 'cancelled')
@endif
@if($matCanOrder && !$matRxLocked)
@endif
@endforeach
@else
No prescriptions yet.
@endif
@if($matCanOrder && !$discharged)
@endif
@endif {{-- /$matVisit check --}}
{{-- ═══ 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('Receptionist','Clinician','Nurse','Triage Nurse','Dental User','Hospital Admin','Super Admin');
@endphp
@endforeach
{{-- Record payment --}}
@if(auth()->user()->hasAnyRole('Receptionist','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
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 17: the Case Summary button was removed from the maternity
ward at clinician request. The route + controller method remain
in place so the document family stays available for any future
re-introduction, but no UI surface in the ward links to it. --}}
@php
$matVisit_btn = $ma->visit;
$matPayments_btn = $matInv?->payments ?? collect();
$matLastReceipt = $matPayments_btn->last()?->receipt;
@endphp
The discharge summary will be available to print here once the attending clinician completes the discharge.
@else
{{-- Not yet discharged: build the structured discharge form --}}
Maternity Discharge Summary
{{-- Round 16 fix: the previous button called window.print() on this
in-tab form, which produced an unformatted screen print without
the CRH letterhead. The link now opens the proper print view
(which uses partials/_document-header) in a new tab. Works
before AND after discharge — the print template renders from
whatever fields have been saved so far, so clinicians can
preview the document as they fill it in. --}}
Preview & Print