{{-- Smart Report v2 - HE / PT-INR analysis card grid. --}} {{-- Mirrors SmartReportService::GetHEPDF (lines 2752-3063). 4 cells per page, --}} {{-- branched by Result CODE: HBA/PRT -> LNH; HBA2/HBF/INR -> NH; --}} {{-- HBD/HBS/HBC/Sickle -> BP. Profile->ID 18/34 force HBA2 -> LNH. --}} @php /** @var array $group Group view-model from WebController v2 dispatch */ /** @var \App\Services\SmartReportV2Service $service */ $service = $service ?? app(\App\Services\SmartReportV2Service::class); $Package = $group['package'] ?? ($group['firstPackage'] ?? null); $rows = $Package ? $service->buildHeRows($Package, $Profile) : []; // Group by the v1 raw-key page number (skipped rows keep their grid // slots, so a page can hold fewer than 4 cards — mirrors GetHEPDF). $pages = []; foreach ($rows as $heRow) { $pages[$heRow['page']][] = $heRow; } $pages = array_values($pages); if (empty($pages)) $pages = [[]]; $TestName = $Package->lABCATEGORYPACKAGE->REPORT_DISPLAY_NAME_AR ?? ($Package->lABCATEGORYPACKAGE->NAME_AR ?? ''); @endphp @foreach ($pages as $pageIdx => $pageRows)
@include('pdf.smart_report.components.backgrounds.bg', ['template' => 'smart-report', 'page' => 1]) @include('pdf.smart_report.components.patient_header', [ 'Order' => $Order, 'Profile' => $Profile, 'firstPackage' => $Package, 'Category' => $Package->lABCATEGORYPACKAGE->NAME_AR ?? '', 'Description' => $Package->lABCATEGORYPACKAGE->SMART_DESC_AR ?? '', ]) {{-- 4-up HE grid --}} @foreach ($pageRows as $row) @php $x = $row['card_x']; $y = $row['card_y']; $headerText = $row['name_ar'] ?: $TestName; $titleFontSize = (mb_strlen($headerText, 'UTF-8') > 30) ? 8 : 10; $meter = $row['meter_offsets'] ?? ['top' => 1, 'left' => 9, 'width' => 45]; // Result+unit font shrinks when unit is long (mirrors v1). $unitLen = mb_strlen((string) ($row['unit'] ?? ''), 'UTF-8'); $resultPt = ($unitLen > 10) ? 9 : 13; @endphp
{{-- Card background --}} {{-- Title bar --}}
{{ $headerText }}
{{-- ── Meter island: gauge PNG + threshold labels as one unit. ── --}} {{-- Island at the card origin (0,0), so inner offsets are the --}} {{-- unchanged card-relative values; move the island to nudge the --}} {{-- whole calibrated gauge instead of each element. --}}
{{-- Meter image (LNH / NH / BP) --}} @if (!empty($row['image'])) @endif {{-- Threshold labels --}} @foreach ($row['threshold_labels'] as $label)
{{ $label['text'] }}
@endforeach
{{-- /.sr-meter --}} {{-- Description --}}
{!! nl2br($service->isolateLtrRuns($row['desc_ar'] ?? '')) !!}
{{-- Result + unit --}} @if ($row['show_value'] ?? true) @php // Drop a "unit" that is only punctuation (some rows store // "." as the unit, which rendered as a stray trailing dot). $heUnit = trim((string) ($row['unit'] ?? '')); if ($heUnit !== '' && !preg_match('/[\p{L}\p{N}%\/]/u', $heUnit)) $heUnit = ''; $heValue = trim($row['result'] . ' ' . $heUnit); @endphp {{-- Right-edge anchored like v1's Cell(14,46,'R') at x+70: long values overflow to the LEFT (card is 100mm wide). isolateLtrRuns keeps "16.7 Seconds" from flipping to "Seconds 16.7" under the RTL page direction. --}}
{!! $service->isolateLtrRuns($heValue) !!}
@endif
@endforeach
@endforeach