{{-- ═══ ANC ORDERS — mirrors the OPD encounter's Lab / Imaging / Prescription sections ═══ Expects: $registration AncRegistration $backingVisit Visit (the ANC backing visit; has labOrders, imagingRequests, prescriptions) $labOrders, $imagingRequests, $prescriptions (already on $backingVisit, passed for convenience) $coverage (optional — used to show scan-covered hints) Element IDs (lab-search, drug-search, imaging-search, drug-item-id, etc.) are deliberately the same as the OPD view so the shared JS helpers bind. --}} @php $user = auth()->user(); $isAdmin = $user && $user->hasAnyRole('Super Admin', 'Hospital Admin'); $canEditLab = $user && ($user->hasRole('Super Admin') || $user->hasRole('Hospital Admin') || $user->hasRole('Clinician') || $user->hasRole('Nurse')); $canEditImaging = $canEditLab; $canEditPrescriptions = $canEditLab; $canDeletePrescription = $canEditLab || ($user && $user->hasRole('Pharmacy User')); $visit = $backingVisit; // alias so the template matches OPD 1:1 @endphp {{-- ═══ LABORATORY TESTS ═══ --}}

Laboratory Tests

@if($visit->labOrders->count()){{ $visit->labOrders->count() }} orders@endif
@if($canEditLab)@endif @forelse($visit->labOrders as $lo) @if($canEditLab) @endif @empty @endforelse @if($canEditLab) @endif
Test Result Reference Range Notes Urgency StatusDelete
{{ $lo->test_name }} @if($lo->result && is_array($lo->result->results)) @php $resData = $lo->result->results; @endphp @if(isset($resData['generic'])) {{ $resData['generic']['value'] ?? '-' }} {{ $resData['generic']['unit'] ?? '' }} @else @foreach($resData as $param) @if(is_array($param) && isset($param['name']))
{{ $param['short_code'] ?? $param['name'] }}: {{ $param['value'] ?? '-' }} {{ $param['unit'] ?? '' }}
@endif @endforeach @endif @else — @endif
@if($lo->result && is_array($lo->result->results)) @foreach($lo->result->results as $param) @if(is_array($param) && isset($param['reference_range']))
{{ $param['reference_range'] }}
@endif @endforeach @else — @endif
{{ $lo->clinical_notes ?? '—' }} {{ $lo->urgency }} {{ ucfirst($lo->status) }} @if(!in_array($lo->status, ['validated','cancelled','resulted']))
@csrf @method('DELETE')
@endif
No lab orders yet.
@csrf

{{-- ═══ RADIOLOGY / IMAGING ═══ --}}

Radiology / Imaging

@if($visit->imagingRequests->count()){{ $visit->imagingRequests->count() }} orders@endif @if(($coverage['mode'] ?? null) === 'package' && ($coverage['ultrasounds_quota'] ?? 0) > 0) Package ultrasounds: {{ $coverage['ultrasounds_used'] }} / {{ $coverage['ultrasounds_quota'] }} @endif
@if($canEditImaging)@endif @forelse($visit->imagingRequests as $ir) @if($canEditImaging) @endif @empty @endforelse @if($canEditImaging) @endif
Imaging Type Clinical Indication Findings StatusDelete
{{ $ir->imaging_type }} {{ $ir->clinical_indication ?? '—' }} {{ $ir->report ? \Illuminate\Support\Str::limit($ir->report->findings, 80) : '—' }} {{ ucfirst($ir->status) }} @if(!in_array($ir->status, ['reported','cancelled','verified']))
@csrf @method('DELETE')
@endif
No imaging orders yet.
@csrf

{{-- ═══ PRESCRIPTIONS ═══ --}}

Prescriptions

@if($visit->prescriptions->count()){{ $visit->prescriptions->count() }} items@endif
@if($canEditPrescriptions)@endif @forelse($visit->prescriptions as $rx) @php $rxLocked = in_array($rx->status, ['dispensed','cancelled']); $rxCanEdit = $canEditPrescriptions && !$rxLocked; // Used by the Reverse button below. $rxDispensedQty = \App\Models\PharmacyDispense::where('prescription_id', $rx->id) ->whereNull('reversed_at')->sum('quantity_dispensed'); // Used by the one-tap Dispense button (mirrors the OPD encounter). $rxRemainingQty = max(0, ((int) $rx->quantity) - (int) $rxDispensedQty); $rxCanDispense = $canEditPrescriptions && !$rxLocked && $rx->drug_item_id && $rxRemainingQty > 0; @endphp @if($canEditPrescriptions) @endif @empty @endforelse @if($canEditPrescriptions) @endif
Drug Dosage Frequency Route Duration Qty StatusActions
{{ $rx->drug_name }} {{ $rx->dosage ?? '—' }} {{ $rx->frequency ?? '—' }} {{ $rx->route ?? '—' }} {{ $rx->duration ?? '—' }} {{ $rx->quantity }} {{ ucfirst($rx->status) }} {{-- Dispense (one tap) — green shield-check, matches OPD encounter. --}} @if($rxCanDispense)
@csrf
@endif {{-- Reverse dispense — Admin, Clinician or Nurse. Sends the prescription back to the pharmacy queue. Invoice line stays; use Delete to also drop the charge. --}} @if($canEditPrescriptions && $rxDispensedQty > 0 && $rx->status !== 'cancelled')
@csrf
@endif @if($canDeletePrescription && !$rxLocked)
@csrf @method('DELETE')
@endif
No prescriptions yet.
@csrf