@extends('backend.template.layouts.template-base') @section('title', 'Enter Results') @section('styles') @endsection @section('content') @php $patient = $bill->patient; if (! $patient && $bill->relationLoaded('booking') && $bill->booking) { $bookingFallback = $bill->booking; } else { $bookingFallback = null; } $patientName = $reportPatientName ?? ($patient ? (trim($patient->name ?? '') ?: trim(($patient->title ?? '') . ' ' . ($patient->first_name ?? '') . ' ' . ($patient->last_name ?? ''))) : ($bookingFallback?->name ?: '—')); $demo = $patientDemo ?? []; $ageSex = $demo['ageSex'] ?? '—'; $sexLabel = $demo['sexLabel'] ?? '—'; $sexIsFemale = $demo['sexIsFemale'] ?? false; $sexIsMale = $demo['sexIsMale'] ?? false; $displayUhid = $patient?->uhid ?: '—'; $regNo = $bill->id; $lineCode = $lineCode ?? ($bill->transaction?->dcn ?: 'L1'); $wf = $workflowStatus ?? []; $statusKey = $wf['statusKey'] ?? ($bill->report_status ?? 'pending'); $statusLabel = $wf['statusLabel'] ?? 'Pending'; $statusIsFinal = $wf['statusIsFinal'] ?? false; $statusBadgeClass = match ($statusKey) { 'final', 'signed_off' => 'er-status-pill', 'in_progress' => 'er-status-pill is-progress', 'new' => 'er-status-pill is-pending', default => 'er-status-pill is-pending', }; $patientPhone = $patient?->mobile ?: ($patient?->phone ?? '—'); $patientEmail = $patient?->email ?: '—'; $patientAddress = collect([ $patient?->address_line1 ?? $patient?->address ?? null, $patient?->city ?? null, $patient?->state ?? null, ])->filter(fn ($v) => filled($v))->implode(', ') ?: '—'; $doctorDisplayName = $bill->referred_by ?: 'Self'; $valueOptionsFor = function ($test) { if (isset($test->value_options) && is_array($test->value_options)) { return $test->value_options; } return match (strtoupper($test->test_name ?? '')) { 'ABO GROUP' => ['A', 'B', 'AB', 'O'], 'RH (ANTI -D)', 'RH (ANTI-D)', 'RH (ANTI D)' => ['POSITIVE', 'NEGATIVE'], default => null, }; }; $isPanelRow = function ($test) { if (! empty($test->is_panel)) { return true; } return ! ($test->is_subtest ?? false) && empty($test->parent_test) && empty($test->result_value) && empty($test->unit); }; $groupTestsIntoBoxes = function ($tests) use ($isPanelRow) { $boxes = []; $current = collect(); $panelName = null; foreach ($tests->values() as $test) { $isPanel = $isPanelRow($test); $parent = trim((string) ($test->parent_test ?? '')); $isChild = ($test->is_subtest ?? false) && $panelName !== null && strcasecmp($parent, $panelName) === 0; if ($isPanel) { if ($current->isNotEmpty()) { $boxes[] = $current; } $current = collect([$test]); $panelName = trim((string) ($test->test_name ?? '')); } elseif ($isChild) { $current->push($test); } else { if ($current->isNotEmpty()) { $boxes[] = $current; } $current = collect([$test]); $panelName = null; } } if ($current->isNotEmpty()) { $boxes[] = $current; } return $boxes; }; $oldFlag = function (string $key, bool $default): bool { $old = old($key); if ($old === null) { return $default; } return in_array((string) $old, ['1', 'true', 'on', 'yes'], true); }; $panelEditUrl = function ($panelName) use ($bill) { return route('backend.template.diagnostic.cases.bills.panel.edit', [ $bill->id, \Illuminate\Support\Str::slug($panelName), ]); }; $packageEditUrls = $packageEditUrls ?? []; $testPackageEditUrl = function ($panelName) use ($packageEditUrls) { return $packageEditUrls[$panelName] ?? route('backend.template.diagnostic.lab.testpackage'); }; $testDatabaseEditUrls = $testDatabaseEditUrls ?? []; $testDatabaseEditUrl = function ($testName) use ($testDatabaseEditUrls) { $name = trim((string) $testName); if ($name === '') { return route('backend.template.diagnostic.lab.testdatabase'); } return $testDatabaseEditUrls[$name] ?? route('backend.template.diagnostic.lab.testdatabase'); }; // Per-test Edit → Labs → Test database. Panel rows keep bill panel config editor. $testConfigEditUrl = function ($test) use ($panelEditUrl, $testDatabaseEditUrl) { if (! empty($test->is_panel)) { return $panelEditUrl($test->test_name); } return $testDatabaseEditUrl($test->test_name ?? ''); }; $rowIndex = 0; $billNav = array_merge([ 'prev' => null, 'next' => null, 'prev_report_url' => null, 'next_report_url' => null, 'prev_edit_url' => null, 'next_edit_url' => null, ], $billNav ?? []); @endphp

Lab report

Reg no. {{ $regNo }} | {{ $lineCode }} {{ $sexLabel }}
Status: {{ $statusLabel }} Printed
@if ($billNav['prev_edit_url']) ‹ @else ‹ @endif Edit @if ($billNav['next_edit_url']) › @else › @endif
@if ($billNav['prev_report_url']) ‹ @else ‹ @endif View @if ($billNav['next_report_url']) › @else › @endif
@if (session('success'))
{{ session('success') }}
@endif @if ($errors->any())
    @foreach ($errors->all() as $error)
  • {{ $error }}
  • @endforeach
@endif
@csrf
Patient Name {{ $patientName }}
Age / Sex {{ $ageSex }}
Referred By {{ $bill->referred_by ?: 'Self' }}
VDL_24 / UHID {{ $bill->id }} / {{ $displayUhid === '—' ? '' : $displayUhid }}
Investigations {{ $investigationTitle }}
@php // Collected starts the day after registration; Received/Reported follow Collected. $registeredDateIso = $bill->created_at?->toDateString(); $collectedMinIso = $bill->created_at ? $bill->created_at->copy()->addDay()->toDateString() : null; @endphp
{{ $bill->created_at?->format('d-m-Y h:i A') }}
print_categories_new_page) ? 'checked' : '' }}>
@foreach ($resultGroups as $category => $tests) @php $categoryEditUrl = $categoryEditUrls[$category] ?? null; $panelMethod = ''; $panelInstrument = ''; $panelInterpretation = ''; @endphp
@if ($categoryEditUrl) @endif
@php $categoryLoopIndex = $loop->index; $panelGenericResults = $tests ->filter(fn ($t) => ($t->is_subtest ?? false) && strcasecmp(trim($t->test_name ?? ''), 'Result') === 0) ->keyBy(fn ($t) => $t->parent_test ?? ''); $panelSlugForCategory = null; $testBoxes = $groupTestsIntoBoxes($tests); @endphp
@foreach ($testBoxes as $boxIndex => $boxTests) @php $boxUid = $categoryLoopIndex . '-' . $boxIndex; $boxTestsList = $boxTests->values(); $pendingPanelInterp = null; $shownInterpFingerprints = []; $headerTest = $boxTestsList->first(function ($t) { return ! (($t->is_subtest ?? false) && strcasecmp(trim($t->test_name ?? ''), 'Result') === 0); }) ?? $boxTestsList->first(); if (! $headerTest) { continue; } $headerIdx = $rowIndex; $headerSkipInterp = $oldFlag( 'skip_interpretation.' . $headerIdx, (bool) ($headerTest->skip_interpretation ?? false) ); $headerPrintReady = $oldFlag( 'print_ready.' . $headerIdx, $headerTest->print_ready ?? true ); $headerPageBreak = $oldFlag( 'page_break_after.' . $headerIdx, (bool) ($headerTest->page_break_after ?? false) ); @endphp
@include('backend.template.diagnostic.cases.bill.partials.enter_result_print_opts', [ 'optIdx' => $headerIdx, 'printReady' => $headerPrintReady, 'pageBreak' => $headerPageBreak, 'skipInterp' => $headerSkipInterp, ]) @foreach ($boxTestsList as $testLoopIndex => $test) @php $isGenericResultRow = ($test->is_subtest ?? false) && strcasecmp(trim($test->test_name ?? ''), 'Result') === 0; if ($isGenericResultRow) { continue; } $idx = $rowIndex; $panel = $isPanelRow($test); $options = $valueOptionsFor($test); $inputType = $test->input_type ?? 'single_line'; if ($inputType === 'multi_line') { $inputType = 'paragraph'; } $val = old('result_value.' . $idx, $test->result_value); $genericResult = $panel ? $panelGenericResults->get($test->test_name) : null; $genericIdx = null; if ($panel && $genericResult) { $genericIdx = $rowIndex + 1; $val = old('result_value.' . $genericIdx, $genericResult->result_value); $options = $valueOptionsFor($genericResult); } if ($panel) { $panelSlugForCategory = \Illuminate\Support\Str::slug($test->test_name); $panelMethod = trim((string) ($test->method ?? '')); $panelInstrument = trim((string) ($test->instrument ?? '')); $panelInterpretation = trim((string) ($test->interpretation ?? '')); } $syncFieldId = $panel && $genericResult ? 'generic-result-val-' . $boxUid . '-' . $idx : null; $interpHtml = old('test_interpretation.' . $idx, $test->interpretation ?? ''); $interpHtml = is_string($interpHtml) ? $interpHtml : ''; $skipOld = old('skip_interpretation.' . $idx); $skipInterp = $skipOld === null ? (bool) ($test->skip_interpretation ?? false) : in_array((string) $skipOld, ['1', 'true', 'on', 'yes'], true); $emptyPanelHeader = $panel && ! $genericResult; $flagRef = old('reference_range.' . $idx, $test->reference_range); $flagRules = $test->reference_rules ?? null; if ($panel && $genericResult) { $flagRef = old('reference_range.' . $genericIdx, $genericResult->reference_range); $flagRules = $genericResult->reference_rules ?? $flagRules; } $flagConfig = \App\Support\LabReferenceRange::normalizeConfig($flagRules, $flagRef); $hlFlag = \App\Support\LabReferenceRange::numericAbnormalFlag( $flagConfig, $patientDemo['sexLetter'] ?? null, $patientDemo['ageYears'] ?? null, $val ) ?? \App\Support\LabReferenceRange::flagForDisplay($flagRef, $val); $flagBounds = \App\Support\LabReferenceRange::boundsForDisplay($flagRef); $rowIndex++; if ($panel && $genericResult) { $rowIndex++; } @endphp @php $refDisplay = old('reference_range.' . $idx, $test->reference_range); $refRulesOld = null; $refRulesOldKey = 'reference_rules.' . $idx; if (old($refRulesOldKey) !== null) { $refRulesOld = old($refRulesOldKey); } if ($refRulesOld !== null && $refRulesOld !== '') { $refConfig = \App\Support\LabReferenceRange::normalizeConfig($refRulesOld, $refDisplay); } else { $refConfig = \App\Support\LabReferenceRange::normalizeConfig($test->reference_rules ?? null, $refDisplay); } $refConfigJson = json_encode($refConfig, JSON_UNESCAPED_UNICODE); $refInputId = 'ref-input-' . $boxUid . '-' . $idx; $refRulesInputId = 'ref-rules-' . $boxUid . '-' . $idx; @endphp @if ($panel && $genericResult) @endif @php $nextVisible = null; for ($look = $testLoopIndex + 1; $look < $boxTestsList->count(); $look++) { $cand = $boxTestsList[$look]; $candGeneric = ($cand->is_subtest ?? false) && strcasecmp(trim((string) ($cand->test_name ?? '')), 'Result') === 0; if ($candGeneric) { continue; } $nextVisible = $cand; break; } $nextIsChildOfThis = $nextVisible && ($nextVisible->is_subtest ?? false) && strcasecmp(trim((string) ($nextVisible->parent_test ?? '')), trim((string) ($test->test_name ?? ''))) === 0; $showRowInterp = ! ($emptyPanelHeader && $nextIsChildOfThis); if ($emptyPanelHeader && $nextIsChildOfThis) { $pendingPanelInterp = [ 'idx' => $idx, 'html' => $interpHtml, 'skip' => $skipInterp, ]; } $flushPanelInterp = false; if ($pendingPanelInterp && ($test->is_subtest ?? false)) { $sameParentNext = $nextVisible && ($nextVisible->is_subtest ?? false) && strcasecmp(trim((string) ($nextVisible->parent_test ?? '')), trim((string) ($test->parent_test ?? ''))) === 0; if (! $sameParentNext) { $flushPanelInterp = true; } } elseif ($pendingPanelInterp && $emptyPanelHeader && $nextVisible === null) { $flushPanelInterp = true; $showRowInterp = true; $pendingPanelInterp = null; } @endphp @if ($showRowInterp) @include('backend.template.diagnostic.cases.bill.partials.enter_result_interpretation', [ 'interpIdx' => $idx, 'interpHtml' => $interpHtml, 'skipInterp' => $skipInterp, ]) @php $fp = \App\Support\RichTextSanitizer::plainTextFingerprint($interpHtml); if ($fp !== '') { $shownInterpFingerprints[] = $fp; } @endphp @endif @if ($flushPanelInterp && $pendingPanelInterp) @php $panelFp = \App\Support\RichTextSanitizer::plainTextFingerprint($pendingPanelInterp['html'] ?? ''); $panelAlreadyShown = $panelFp !== '' && in_array($panelFp, $shownInterpFingerprints, true); @endphp @if (! $panelAlreadyShown) @include('backend.template.diagnostic.cases.bill.partials.enter_result_interpretation', [ 'interpIdx' => $pendingPanelInterp['idx'], 'interpHtml' => $pendingPanelInterp['html'], 'skipInterp' => $pendingPanelInterp['skip'], ]) @else @endif @php $pendingPanelInterp = null; @endphp @endif @endforeach
TEST VALUE UNIT REFERENCE
@if ($panel)
Edit {{ $test->test_name }}
@elseif ($test->is_subtest ?? false)
@if ($testConfigEditUrl($test)) Edit @endif {{ $test->test_name }}
@else
@if ($testConfigEditUrl($test)) Edit @endif {{ old('test_name.' . $idx, $test->test_name) }}
@endif @php $rowMethod = trim((string) ($test->method ?? '')); $rowInstrument = trim((string) ($test->instrument ?? '')); @endphp @if ($rowMethod !== '' || $rowInstrument !== '')
@if ($rowMethod !== '')
Method: {{ $rowMethod }}
@endif @if ($rowInstrument !== '')
Instrument: {{ $rowInstrument }}
@endif
@endif @error('test_name.' . $idx)
{{ $message }}
@enderror
@if (! $emptyPanelHeader) {{ $hlFlag ?: '' }} @endif @if ($panel && $genericResult) @if ($options) @else @endif @error('result_value.' . $genericIdx)
{{ $message }}
@enderror @elseif ($panel) @elseif ($options) @elseif ($inputType === 'paragraph') @elseif ($inputType === 'numeric') @else @endif @if (! $panel || ! $genericResult) @error('result_value.' . $idx)
{{ $message }}
@enderror @endif
@if ($panel) @else @include('backend.template.diagnostic.cases.bill.partials.unit_picker', [ 'fieldName' => 'unit[]', 'value' => old('unit.' . $idx, $test->unit), 'units' => $testUnits ?? [], 'placeholder' => 'Unit', ]) @endif @if ($panel) @else
@error('reference_range.' . $idx)
{{ $message }}
@enderror is_abnormal ?? false))> @endif
@endforeach @php $cfgKey = 'category-' . \Illuminate\Support\Str::slug($category); if (empty($panelSlugForCategory)) { $firstPanel = $tests->first(fn ($t) => ! empty($t->is_panel)); $panelSlugForCategory = $firstPanel ? \Illuminate\Support\Str::slug($firstPanel->test_name) : ''; if ($firstPanel) { $panelMethod = $panelMethod ?: trim((string) ($firstPanel->method ?? '')); $panelInstrument = $panelInstrument ?: trim((string) ($firstPanel->instrument ?? '')); $panelInterpretation = $panelInterpretation ?: trim((string) ($firstPanel->interpretation ?? '')); } } $legacyKey = $panelSlugForCategory ?: 'default'; $savedNotes = old('panel_notes.' . $cfgKey, data_get($bill->result_panel_config, $cfgKey . '.panel_note')); if ($savedNotes === null || $savedNotes === '') { $savedNotes = old('panel_note', data_get($bill->result_panel_config, $legacyKey . '.panel_note', '')); } $savedRemarks = old('panel_remarks.' . $cfgKey, data_get($bill->result_panel_config, $cfgKey . '.panel_remarks')); if ($savedRemarks === null || $savedRemarks === '') { $savedRemarks = data_get($bill->result_panel_config, $legacyKey . '.panel_remarks', ''); } $savedAdvice = old('panel_advice.' . $cfgKey, data_get($bill->result_panel_config, $cfgKey . '.panel_advice')); if ($savedAdvice === null || $savedAdvice === '') { $savedAdvice = data_get($bill->result_panel_config, $legacyKey . '.panel_advice', ''); } $blockId = $categoryLoopIndex; $showNotes = filled($savedNotes); $showRemarks = filled($savedRemarks); $showAdvice = filled($savedAdvice); $cfgMethod = trim((string) data_get($bill->result_panel_config, $legacyKey . '.method', '')); $cfgInstrument = trim((string) data_get($bill->result_panel_config, $legacyKey . '.instrument', '')); $cfgInterpretation = trim((string) data_get($bill->result_panel_config, $legacyKey . '.interpretation', '')); $panelMethod = $panelMethod ?: $cfgMethod; $panelInstrument = $panelInstrument ?: $cfgInstrument; $panelInterpretation = $panelInterpretation ?: $cfgInterpretation; @endphp
@if ($panelMethod !== '' || $panelInstrument !== '')
@if ($panelMethod !== '')
Method: {{ $panelMethod }}
@endif @if ($panelInstrument !== '')
Instrument: {{ $panelInstrument }}
@endif
@endif
Notes
Remarks (optional):
Advice
@endforeach
@error('more_details')
{{ $message }}
@enderror
Cancel
{{-- /.er-main --}}
{{-- /.er-layout --}}
@php $goToMode = old('mode', 'daily'); $goToDateDisplay = old('case_date', now()->format('d/m/Y')); @endphp @include('backend.template.diagnostic.cases.bill.partials.normal_value_modal') @endsection @section('scripts') @endsection