{{-- Smart Report v2 - General template group. --}} {{-- Handles: BMI, BP, GRAMSA, NBSV2, CSFEP (new layouts here) plus --}} {{-- IGRA/QTGPT/PROEL/STONEA/NBS/BF/DFGT (delegate to pcr_card variants). --}} @php /** @var array $group Group view-model from WebController v2 dispatch */ /** @var object $Order */ /** @var object $Profile */ /** @var \App\Services\SmartReportV2Service $service */ $service = $service ?? app(\App\Services\SmartReportV2Service::class); $Package = $group['package'] ?? ($group['firstPackage'] ?? null); $code = strtoupper($group['code'] ?? ($Package->lABCATEGORYPACKAGE->CODE ?? '')); $model = $Package ? $service->buildGeneralModel($Package, $code) : ['variant' => 'general_stub', 'comment' => null]; $variant = $model['variant'] ?? 'general_stub'; // PCR-delegate codes: hand off to pcr_card which already handles these variants $pcrDelegates = ['IGRA','QTGPT','PROEL','STONEA','NBS','BF','DFGT']; @endphp {{-- ------------------------------------------------------------------ --}} {{-- PCR-delegate codes: reuse pcr_card layout. v1 renders all seven on --}} {{-- the PCR template (storage/pdf/pcr-test-smart-report.pdf), so they --}} {{-- keep the PCR background rather than the general one. --}} {{-- ------------------------------------------------------------------ --}} @if (in_array($code, $pcrDelegates)) @include('pdf.smart_report.components.pcr_card', [ 'group' => $group, 'Order' => $Order, 'Profile' => $Profile, 'bgTemplate' => 'pcr', ]) {{-- ------------------------------------------------------------------ --}} {{-- BMI --}} {{-- ------------------------------------------------------------------ --}} @elseif ($variant === 'bmi')
@include('pdf.smart_report.components.backgrounds.bg', ['template' => 'general', 'page' => 1]) @include('pdf.smart_report.components.patient_header', [ 'Order' => $Order, 'Profile' => $Profile, 'firstPackage' => $Package, 'Category' => $group['category_ar'] ?? '', 'Description' => $group['category_description_ar'] ?? '', 'setAdvice' => true, ]) {{-- Height row: top:93mm right-aligned inside 78mm from left:97mm --}} @if ($model['height'])
{{ $model['height']['name_ar'] }} : {{ $model['height']['unit'] }}  {{ $model['height']['result'] }}
@endif {{-- Weight row: top:93mm right-aligned inside 78mm from left:46mm --}} @if ($model['weight'])
{{ $model['weight']['name_ar'] }} : {{ $model['weight']['unit'] }}  {{ $model['weight']['result'] }}
@endif {{-- BMI row: top:93mm right-aligned inside 78mm from left:0 --}} @if ($model['bmi'] !== null)
{{ $model['bmi_label'] }} : kg/m2  {{ $model['bmi'] }}
{{-- Zone labels (x=100, y=123 origin) --}} @php $zones = $model['zones']; @endphp {{-- LOW_TITLE_AR : (x-56, y+33) = (44, 156) --}} @if (!empty($zones['low_title']))
{{ $zones['low_title'] }}
@endif {{-- MAX_LOW : (x-37, y+12) = (63, 135) --}} @if (!empty($zones['max_low']))
{{ $zones['max_low'] }}
@endif {{-- MAX_NORMAL : (x-7, y-4) = (93, 119) --}} @if (!empty($zones['max_normal']))
{{ $zones['max_normal'] }}
@endif {{-- MID_TITLE_AR : (x-28, y-4) = (72, 119), repositioned to --}} {{-- (x-36, y-1) = (64, 122) per v1:9846-9847 (isEnglishText). --}} @if (!empty($zones['mid_title']))
{{ $zones['mid_title'] }}
@endif {{-- HIGH_BORDER_TITLE : (x-26, y-1) = (74, 122) --}} @if (!empty($zones['high_border_title']))
{{ $zones['high_border_title'] }}
@endif {{-- MAX_HIGH_BORDERLINE : (x-15, y+12) = (85, 135) --}} @if (!empty($zones['max_high_borderline']))
{{ $zones['max_high_borderline'] }}
@endif {{-- HIGH_TITLE_AR : (x+4, y+33) = (104, 156) --}} @if (!empty($zones['high_title']))
{{ $zones['high_title'] }}
@endif {{-- Counter image: (x-50, y+3, w:95) = left:50mm top:126mm --}} @if ($model['img'] && is_file($model['img']['path'])) @endif {{-- BMI value: (x-7, y+57) = left:93mm top:180mm 15pt. --}} {{-- High-borderline zone is gold (155,135,12) per v1:9890. --}} @php $bmiColor = $model['img']['color'] ?? 'green'; $bmiCss = $bmiColor === 'green' ? '#6bac64' : ($bmiColor === 'gold' ? '#9b870c' : '#dd3444'); @endphp
{{ $model['bmi'] }}
{{-- BMI name label: (x-82, y+47) = left:18mm top:170mm --}}
{{ $model['bmi_label'] }}
@endif {{-- Comment --}} @if (!empty($model['comment']))
{!! $service->sanitizeCommentHtml($model['comment']) !!}
@endif
{{-- ------------------------------------------------------------------ --}} {{-- BP --}} {{-- ------------------------------------------------------------------ --}} @elseif ($variant === 'bp')
@include('pdf.smart_report.components.backgrounds.bg', ['template' => 'general', 'page' => 1]) @include('pdf.smart_report.components.patient_header', [ 'Order' => $Order, 'Profile' => $Profile, 'firstPackage' => $Package, 'Category' => $group['category_ar'] ?? '', 'Description' => $group['category_description_ar'] ?? '', 'setAdvice' => true, ]) {{-- Vertical divider image at (99, 133) --}} @php $vertLine = public_path('img/smart-report-pdf/vert-line.png'); @endphp @if (is_file($vertLine)) @endif {{-- v1:13718-13898 loops the result rows and draws BOTH the BPD half --}} {{-- (x=100) and the BPS half (x=10), each with its own thresholds, --}} {{-- labels and needle. --}} @foreach ($model['meters'] ?? [] as $bpMeter) @php $active = $bpMeter['active']; $subtype = $bpMeter['subtype']; $x = $bpMeter['x']; $y = $bpMeter['y']; // 123 $zones = $bpMeter['zones']; // Value/name label positions if ($subtype === 'bpd') { // (140, 93) label; (114, 93) result; (125, 93) unit $labelLeft = 140; $resultLeft = 114; $unitLeft = 125; } else { // (16, 93) label right-aligned in 78mm; (29, 93) result; (40, 93) unit $labelLeft = 16; $resultLeft = 29; $unitLeft = 40; } @endphp {{-- Name label --}} @if ($subtype === 'bpd')
{{ $active['name_ar'] }} :
@else
{{ $active['name_ar'] }} :
@endif {{-- Result --}}
{{ $active['result'] }}
{{-- Unit --}}
{{ $active['unit'] }}
{{-- Zone labels (relative to $x, $y=123) --}} {{-- HIGH_BORDER_TITLE: (x+48, y+3) --}}
{{ $zones['high_border_title'] }}
{{-- MAX_HIGH_BORDERLINE: (x+55, y+12) --}}
{{ $zones['max_high_borderline'] }}
{{-- MIN_HIGH_BORDERLINE: (x+37, y+3) --}}
{{ $zones['min_high_borderline'] }}
{{-- MID_TITLE_AR: (x+7, y+25) --}}
{{ $zones['mid_title'] }}
{{-- LOW_TITLE_AR: (x+20, y+3) --}}
{{ $zones['low_title'] }}
{{-- MAX_NORMAL: (x+19, y+11) --}}
{{ $zones['max_normal'] }}
{{-- HIGH_TITLE_AR: (x+32, y+25), centred in 85mm like v1's Cell(85, ..., 'C') --}}
{{ $zones['high_title'] }}
{{-- Counter image: (x+8, y+7, w:60) --}} @if ($bpMeter['img'] && is_file($bpMeter['img']['path'])) @endif {{-- Value: (x+36, y+35) 15pt --}} @php $bpColor = ['green' => '#6bac64', 'orange' => '#ff8c00', 'dark-green' => '#006400', 'red' => '#dd3444'][$bpMeter['img']['color'] ?? 'green'] ?? '#6bac64'; @endphp
{{ $active['result'] }}
{{-- Name: (x+22, y+45) 13pt --}}
{{ $active['name_ar'] }}
@endforeach @if (!empty($model['comment']))
{!! $service->sanitizeCommentHtml($model['comment']) !!}
@endif
{{-- ------------------------------------------------------------------ --}} {{-- GRAMSA — 4-col table identical to pcr_table but general background --}} {{-- ------------------------------------------------------------------ --}} @elseif ($variant === 'gramsa')
@include('pdf.smart_report.components.backgrounds.bg', ['template' => 'general', 'page' => 1]) @include('pdf.smart_report.components.patient_header', [ 'Order' => $Order, 'Profile' => $Profile, 'firstPackage' => $Package, 'Category' => $group['category_ar'] ?? '', 'Description' => $group['category_description_ar'] ?? '', 'setAdvice' => true, ]) {{-- Column headers at y=92mm --}}
Test Name
Result
Normal Range
Units
@php $y = 105; @endphp @foreach ($model['rows'] as $row) {{-- Test name left:17mm width:60mm --}}
{{ $row['name_en'] }}
@if ($row['result'] !== null && $row['result'] !== '') {{-- Numeric result --}}
{{ $row['result'] }}
@elseif ($row['opt_name'] !== null) {{-- Option result: coloured by IS_NORMAL --}} @php $optColor = $row['is_normal'] ? '#78c926' : '#dd3444'; @endphp
{{ $row['opt_name'] }}
@if ($row['norm_opt'])
{{ $row['norm_opt'] }}
@endif @endif {{-- Unit or '--' --}} @if ($row['unit'])
{{ $row['unit'] }}
@else
--
@endif @php $y += 12; @endphp @endforeach @if (!empty($model['comment']))
{!! $service->sanitizeCommentHtml($model['comment']) !!}
@endif
{{-- ------------------------------------------------------------------ --}} {{-- NBSV2 — 2-col table with bilingual descriptions --}} {{-- ------------------------------------------------------------------ --}} @elseif ($variant === 'nbsv2') @php // Estimate rows per page: each row = ~19mm (7mm name + 12mm desc) // Paginate when accumulated y > 260. $pages = [[]]; $pageIdx = 0; $accY = 105; foreach ($model['rows'] as $row) { $rowH = ($row['code'] === 'MS') ? 26 : 19; // MS gets extra for line-wrap if ($accY + $rowH > 258 && count($pages[$pageIdx]) > 0) { $pages[] = []; $pageIdx++; $accY = 105; } $pages[$pageIdx][] = $row; $accY += $rowH; } @endphp @foreach ($pages as $pageRows)
@include('pdf.smart_report.components.backgrounds.bg', ['template' => 'general', 'page' => 1]) @include('pdf.smart_report.components.patient_header', [ 'Order' => $Order, 'Profile' => $Profile, 'firstPackage' => $Package, 'Category' => $group['category_ar'] ?? '', 'Description' => $group['category_description_ar'] ?? '', 'setAdvice' => false, ]) {{-- Headers at y=95mm --}}
Screened Disorder
Result
@php $y = 105; @endphp @foreach ($pageRows as $row) {{-- Name EN: left:22mm width:85mm 11pt --}}
{{ $row['name_en'] }}
{{-- DESC_EN: top:y+12 left:22mm 10pt --}} @if (!empty($row['desc_en']))
{{ $row['desc_en'] }}
@endif {{-- DESC_AR: top:y+12 left:130mm 10pt --}} @if (!empty($row['desc_ar']))
{!! $service->isolateLtrRuns($row['desc_ar']) !!}
@endif {{-- Option result: left:146mm width:40mm centre --}} @if ($row['opt_name'] !== null) @php $optColor = $row['is_normal'] ? '#006400' : '#d20000'; @endphp
{{ $row['opt_name'] }}
@endif @php $y += ($row['code'] === 'MS') ? 26 : 19; @endphp @endforeach {{-- Disclaimer on last page only --}} @if ($loop->last)
{{ $model['disclaimer'] }}
@php $y += 12; @endphp @if (!empty($model['comment']))
{!! $service->sanitizeCommentHtml($model['comment']) !!}
@endif @endif
@endforeach {{-- ------------------------------------------------------------------ --}} {{-- CSFEP — 4-col table with numeric colour and special ref display --}} {{-- ------------------------------------------------------------------ --}} @elseif ($variant === 'csfep')
@include('pdf.smart_report.components.backgrounds.bg', ['template' => 'general', 'page' => 1]) @include('pdf.smart_report.components.patient_header', [ 'Order' => $Order, 'Profile' => $Profile, 'firstPackage' => $Package, 'Category' => $group['category_ar'] ?? '', 'Description' => $group['category_description_ar'] ?? '', 'setAdvice' => true, ]) {{-- Headers at y=92mm --}}
Test Name
Result
Normal Range
Units
@php $y = 105; @endphp @foreach ($model['rows'] as $row) {{-- Name left:17mm width:60mm --}}
{{ $row['name_en'] }}
@if ($row['opt_name'] !== null) {{-- Option result --}} @php $optColor = $row['is_normal'] ? '#78c926' : '#dd3444'; @endphp
{{ $row['opt_name'] }}
@if ($row['norm_opt'])
{{ $row['norm_opt'] }}
@endif @else {{-- Numeric result: colour by normal range unless special code --}} @php if ($row['code'] === 'WBCC' || $row['code'] === 'GS') { $numColor = '#000000'; } else { $numColor = $row['numeric_is_normal'] ? '#006400' : '#d20000'; } @endphp
{{ $row['result'] }}
{{-- Ref range display --}} @if (is_array($row['ref_display'])) {{-- WBCC two-line ref --}}
{{ $row['ref_display'][0] }}
{{ $row['ref_display'][1] }}
@elseif ($row['ref_display'])
{{ $row['ref_display'] }}
@endif @endif {{-- Unit --}} @if ($row['unit'])
{{ $row['unit'] }}
@else
--
@endif @php $y += 12; @endphp @endforeach @if (!empty($model['comment']))
{!! $service->sanitizeCommentHtml($model['comment']) !!}
@endif
{{-- ------------------------------------------------------------------ --}} {{-- Fallback stub --}} {{-- ------------------------------------------------------------------ --}} @else @include('pdf.smart_report.components._stub', [ 'group' => $group, 'Order' => $Order, 'Profile' => $Profile, ]) @endif