@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