@php $patient = $order->patient; // Derived states the sections below keep asking about, settled once. $closed = in_array($order->status, ['cancelled', 'rejected'], true); $uncollected = $order->items->whereIn('status', ['pending'])->where(fn ($i) => $i->specimen_id === null); $untouched = $order->items->every(fn ($item) => $item->status === 'pending'); $chargeable = $order->items ->whereNotNull('charge_item_id') ->whereNull('invoice_item_id') ->where('price', '>', 0) ->whereNotIn('status', ['rejected', 'cancelled']); $unpriced = $order->items->whereNull('charge_item_id')->whereNotIn('status', ['rejected', 'cancelled']); $chargeEstimate = $chargeable->sum(fn ($item) => (float) $item->price); $criticalOpen = $order->items ->whereIn('flag', ['critical_high', 'critical_low']) ->whereNull('critical_called_at') ->whereNotIn('status', ['rejected', 'cancelled']); $canRelease = in_array($order->status, ['completed', 'verified'], true) && $order->released_at === null; $canCancel = ! $closed && $untouched; $canCharge = $order->is_billable && ! in_array($order->status, ['cancelled'], true) && $chargeable->isNotEmpty(); $specimens = $order->items->filter(fn ($item) => $item->specimen !== null)->map(fn ($item) => $item->specimen)->unique('id')->values(); $flags = \App\Support\Lookup::options('result_flag'); $analyzerOptions = $analyzers->mapWithKeys(fn ($analyzer) => [ $analyzer->id => $analyzer->code.' — '.$analyzer->name, ])->all(); $resultedCount = $order->items->whereIn('status', ['completed', 'verified'])->count(); $verifiedCount = $order->items->where('status', 'verified')->count(); $initials = $patient ? Str::of($patient->full_name)->explode(' ')->filter()->take(2) ->map(fn (string $part) => Str::upper(Str::substr($part, 0, 1)))->implode('') : '—'; @endphp @if (! $order->is_billable) Not billable @endif @if ($patient?->isRestricted()) Restricted record @endif @can('lab.collect-sample') @if ($order->items->whereIn('status', ['pending', 'collected'])->isNotEmpty()) Sticker sheet @endif @endcan Report Patient copy {{-- ------------------------------------------------------------ notices --}} @if ($errors->any())
    @foreach ($errors->all() as $message)
  • {{ $message }}
  • @endforeach
@endif @if ($order->status === 'cancelled')
{{ $order->cancel_reason }} Cancelled by {{ $order->cancelledBy?->name ?? 'an unknown account' }} @if ($order->cancelled_at) on {{ $order->cancelled_at->format('d M Y \a\t H:i') }} @endif — no further work will be done on it.
@elseif ($order->status === 'rejected')
A specimen on this request was rejected, closing its lines. Draw a fresh sample to restart the work.
@endif @if ($criticalOpen->isNotEmpty())
{{ $criticalOpen->map(fn ($item) => $item->labTest?->name)->filter()->implode(', ') }} came back critical and no physician call has been recorded. The line cannot be verified until the call is logged with the name it was given to.
@endif @if ($patient?->isRestricted())
Access to this record is limited. You are seeing it because your account holds the restricted-access permission, and this access has been logged.
@endif
{{-- ------------------------------------------------------ the bench --}}
{{ $order->items->count() }} line(s) · {{ $resultedCount }} resulted · {{ $verifiedCount }} verified
    @foreach ($order->items as $item) @php $isNumeric = ($item->labTest?->result_type ?: 'numeric') === 'numeric'; $isCriticalFlag = in_array($item->flag ?? '', ['critical_high', 'critical_low'], true); $canEnterResult = in_array($item->status, ['in_progress', 'completed'], true); $canVerifyResult = $item->status === 'completed' && $item->performed_at !== null && (! $isCriticalFlag || $item->critical_called_at !== null); $report = $item->radiologyReport; @endphp
  • {{ $loop->iteration }}

    {{ $item->labTest?->name ?? 'Test #'.$item->lab_test_id }}

    @if ($item->flag) @endif @if ($item->panel) {{ $item->panel->name }} @endif @if ($report?->is_critical) Critical finding @endif

    {{ collect([ $item->labTest?->code, $item->labTest?->specimen_type, $item->labTest?->container, $item->labTest?->tat_hours ? 'TAT '.$item->labTest->tat_hours.' h' : null, $item->specimen?->barcode ? 'Tube '.$item->specimen->barcode : null, ])->filter()->implode(' · ') ?: 'No catalogue detail on this line' }}

    {{-- ---------------------------------- the result --}} @if ($item->result_value !== null || $item->result_text !== null)
    @if ($item->result_value !== null) {{ $item->result_value }} {{ $item->result_unit }} @else {{ $item->result_text }} @endif
    @if ($item->ref_range_applied)

    Reference: {{ $item->ref_range_applied }}

    @endif @if ($item->previous_result !== null)

    Previous {{ $item->previous_result }} @if ($item->delta_pct !== null) · delta {{ $item->delta_pct > 0 ? '+' : '' }}{{ $item->delta_pct }}% @endif · {{ $item->delta_check_label }}

    @endif @if ($item->comments)

    {{ $item->comments }}

    @endif

    @if ($item->performedBy) Performed by {{ $item->performedBy->name }} @if ($item->performed_at) · {{ $item->performed_at->format('d M H:i') }}@endif @endif @if ($item->verifiedBy) · Verified by {{ $item->verifiedBy->name }} @if ($item->verified_at) {{ $item->verified_at->format('d M H:i') }}@endif @if ($item->signature_hash) sig {{ Str::limit($item->signature_hash, 12, '') }}… @endif @endif

    @elseif (in_array($item->status, ['pending', 'collected', 'received'], true))

    @if ($item->status === 'pending') Awaiting sample collection. @elseif ($item->status === 'collected') Sample drawn — awaiting receipt at the bench. @elseif ($item->status === 'received') At the bench — the result is not entered yet. @endif

    @elseif (in_array($item->status, ['rejected', 'cancelled'], true))

    {{ $item->status_label }}@if ($item->rejection_reason) — {{ $item->rejection_reason }}@endif.

    @endif {{-- ------------------------- the imaging report --}} @if ($report)
    {{ $report->study_name ?: 'Imaging study' }} @can('radiology.view') Open the study @endcan
    @endif {{-- --------------------- the critical-value loop --}} @if ($isCriticalFlag) @if ($item->critical_called_at)
    Called to {{ $item->critical_called_to }} by {{ $item->criticalCalledBy?->name ?? '—' }} at {{ $item->critical_called_at->format('d M H:i') }}. @if ($item->critical_acknowledged_at) Acknowledged @if ($item->criticalAcknowledgedBy) by {{ $item->criticalAcknowledgedBy->name }}@endif @elseif (can('lab.verify-results'))
    @csrf @method('PATCH')
    @endif
    @elseif (can('lab.enter-results'))
    Record the critical-value call
    @csrf
    @else

    Critical value — a physician call is required before verification.

    @endif @endif
    {{-- --------------------------- bench controls --}} @if (! $closed)
    @can('lab.enter-results') @if ($canEnterResult)
    result_value === null && $item->result_text === null) open @endif> {{ $item->status === 'completed' ? 'Correct result' : 'Enter result' }}
    @csrf @if ($isNumeric) @else @endif
    @endif @endcan @can('lab.verify-results') @if ($canVerifyResult)
    @csrf @method('PATCH')
    @elseif ($isCriticalFlag && $item->status === 'completed' && ! $item->critical_called_at) Verification held @endif @endcan @if ($item->invoiceItem?->invoice) @php $invoiceUrl = route_if('invoices.show', $item->invoiceItem->invoice_id); @endphp @if ($invoiceUrl) {{ $item->invoiceItem->invoice->invoice_no }} @else On the bill @endif @endif
    @endif
  • @endforeach
{{-- --------------------------------------------------- specimens --}} @if ($specimens->isNotEmpty()) {{ $specimens->count() }} tube(s) on this request
    @foreach ($specimens as $specimen)
  • {{ $specimen->barcode }}

    {{ collect([ $specimen->specimen_type, $specimen->container, $specimen->collected_at?->format('d M Y H:i'), ])->filter()->implode(' · ') }}

    @if ($specimen->rejection_reason)

    Rejected — {{ $specimen->rejection_reason }}

    @endif {{-- the custody ledger --}}
      @foreach ($specimen->events as $event)
    1. {{ \App\Support\Lookup::label('specimen_event', $event->event) }} @if ($event->location) · {{ $event->location }} @endif

      {{ $event->performedBy?->name ?? '—' }} @if ($event->performed_at) · {{ $event->performed_at->format('d M H:i') }}@endif @if ($event->storage_condition) · {{ $event->storage_condition }}@endif

      @if ($event->notes)

      {{ $event->notes }}

      @endif
    2. @endforeach
    @if (! in_array($specimen->status, ['rejected', 'discarded'], true))
    @can('lab.receive-sample')
    Custody step
    @csrf
    @endcan @can('lab.reject-sample')
    Reject sample
    @csrf @method('PATCH')
    @endcan
    @endif
  • @endforeach
@elseif (! $closed && $order->items->whereIn('status', ['pending'])->isNotEmpty())

No sample has been drawn yet. Print the sticker sheet, draw one tube per distinct specimen requirement, and collect from the actions on the right — the barcode binds tube to request.

@endif {{-- ----------------------------------------------- analyzer bridge --}} @can('lab.analyzers-manage') @if ($analyzers->isEmpty())

No active bidirectional machine is registered for {{ $order->department_label }} — results for this request will be entered by hand at the bench.

@else
@csrf
@endif @if ($bridgeMessages->isNotEmpty())

Wire traffic on this request

    @foreach ($bridgeMessages as $message)
  • {{ $message->getTypeLabelAttribute() }} {{ $message->analyzer?->code }} {{ $message->control_id }} {{ $message->created_at?->format('d M H:i') }}
    {{ $message->result_count }} channel(s) — raw payload
    {{ $message->payload }}
  • @endforeach
@endif
@endcan @if ($order->clinical_notes || $order->provisional_diagnosis)
@if ($order->provisional_diagnosis)

Provisional diagnosis

{{ $order->provisional_diagnosis }}

@endif @if ($order->clinical_notes)

Clinical notes

{{ $order->clinical_notes }}

@endif
@endif
{{-- --------------------------------------------------------- the file --}}
{{ $initials }}

{{ $patient?->full_name ?? 'Unattached' }}

{{ $patient?->medical_record_number ?? '—' }} @if ($patient) · {{ $patient->age_display }} · {{ $patient->gender_label }} @endif

@if ($patient?->phone)

{{ $patient->phone }}

@endif
@if ($patient) @if ($patient->allergies_summary)
Allergies: {{ $patient->allergies_summary }}
@endif @if ($patient->isRestricted())
Restricted record — handle per facility policy.
@endif
@can('patients.view') Record @endcan @can('patients.view-clinical') Clinical chart @endcan
@endif
Status
{{ $order->status_label }}
Ordered
{{ $order->ordered_at?->format('d M Y H:i') ?? '—' }} @if ($order->orderedBy) {{ $order->orderedBy->name }} @endif
@if ($order->accessioned_at)
Accessioned
{{ $order->accessioned_at->format('d M Y H:i') }} @if ($order->accessionedBy) {{ $order->accessionedBy->name }} @endif
@endif @if ($order->completed_at)
Bench work finished
{{ $order->completed_at->format('d M Y H:i') }}
@endif @if ($order->released_at)
Released
{{ $order->released_at->format('d M Y H:i') }} @if ($order->releasedBy) {{ $order->releasedBy->name }} @endif
@endif @if ($order->encounter)
Encounter
@php $encounterUrl = route_if('encounters.show', $order->encounter); @endphp @if ($encounterUrl) {{ $order->encounter->encounter_no }} @else {{ $order->encounter->encounter_no }} @endif
@endif @if ($order->visit)
Visit
{{ $order->visit->visit_no }}
@endif
Billing
@if ($order->is_charged) Charged to the bill. @elseif (! $order->is_billable) Marked not billable. @else Not yet carried onto an invoice. @endif
@if (! $closed)
@can('lab.collect-sample') @if ($uncollected->isNotEmpty())
@csrf @method('PATCH')

{{ $uncollected->count() }} line(s) still waiting for a draw — one tube per distinct specimen requirement, each carrying the sticker barcode.

@else

Every line has its sample.

@endif @endcan @can('lab.receive-sample') @if ($order->accessioned_at === null) @if ($order->items->whereIn('status', ['pending'])->isNotEmpty())
@csrf @method('PATCH')
@endif @else

Accessioned {{ $order->accessioned_at->format('d M H:i') }}.

@endif @endcan @can('lab.verify-results') @if ($canRelease)
@csrf @method('PATCH')
@endif @endcan @can('lab-orders.cancel') @if ($canCancel)
Withdraw request
@csrf @method('PATCH')
@else

Work has started — this request is corrected at the bench rather than withdrawn.

@endif @endcan
@endif @if ($order->is_billable) @if ($order->is_charged || $order->items->whereNotNull('invoice_item_id')->isNotEmpty())

Carried onto the patient's bill.

@else

{{ $chargeable->count() }} priced line(s) ready to carry @if ($chargeEstimate > 0) — about {{ money($chargeEstimate) }}@endif.

@endif @if ($unpriced->isNotEmpty())

{{ $unpriced->count() }} guide test(s) have no standard charge — the billing office prices them at charge time.

@endif @can('invoices.create') @if ($canCharge)
@csrf
@endif @endcan
@endif