{{-- Smart Report v2 - PCR template group. --}} {{-- Covers all CODEs that use pcr-test-smart-report.pdf as their background. --}} {{-- Mirrors: GetPCRPDF / GetPCRQUAPDF / GetPCRGENPDF / GetMTBPCRPDF / --}} {{-- GetIgraPDF / GetStoneAnalysisPDF / GetQuantiferonAnalysisPDF / --}} {{-- GetProteinElectrophoresisPDF / GetMTHFRPCRPDF / GetNIPTPCRPDF / --}} {{-- GetNBSPDF / GetBFPDF / GetNIPTCTRAnalysisPDF / GetDFGTAnalysisPDF --}} @php /** @var \App\Services\SmartReportV2Service $service */ $service = $service ?? app(\App\Services\SmartReportV2Service::class); $Package = $group['package'] ?? ($group['firstPackage'] ?? null); $code = $Package->lABCATEGORYPACKAGE->CODE ?? ''; // $bgTemplate may be passed by general_card when it delegates PCR-code // rendering; all current callers use the shared "pcr" background. $bgTemplate = $bgTemplate ?? 'pcr'; $model = $Package ? $service->buildPcrModel($Package, $code) : ['variant' => 'pcr_qual', 'result' => null]; $variant = $model['variant'] ?? 'pcr_qual'; @endphp {{-- ═══════════════════════════════════════════════════════════════════════ --}} {{-- VARIANT: pcr_qual (GetPCRPDF / GetMTBPCRPDF — single result) --}} {{-- ═══════════════════════════════════════════════════════════════════════ --}} @if ($variant === 'pcr_qual')
@include('pdf.smart_report.components.backgrounds.bg', ['template' => $bgTemplate, 'page' => 1]) @include('pdf.smart_report.components.patient_header', [ 'Order' => $Order, 'Profile' => $Profile, 'firstPackage' => $Package, 'Category' => (($Package->lABCATEGORYPACKAGE->REPORT_DISPLAY_NAME_AR ?? null) ?: ($Package->lABCATEGORYPACKAGE->NAME_AR ?? '')), 'Description' => $Package->lABCATEGORYPACKAGE->SMART_DESC_AR ?? '', 'setAdvice' => false, ]) {{-- Column headers at y=70 --}}
Test
Result
@if (!empty($model['unit']))
Unit
Reference range
Not Detected
{{ $model['unit'] }}
@else
Reference range
Not Detected
@endif {{-- Result row at y=78 --}}
Result:
@if (!empty($model['result']))
{{ $model['result'] }}
@endif {{-- Comment label at y=107 --}}
Comment:
@if (!empty($model['ref_first']))
{{ $model['ref_first'] }}
Methodology Brief:
@endif @if (!empty($model['ref_second']))
{{ $model['ref_second'] }}
@endif @if (!empty($model['ref_second']) && empty($model['limit_new_page']))
Limitation:
@endif @if (!empty($model['ref_third']) && empty($model['limit_new_page']))
{{ $model['ref_third'] }}
@endif
{{-- Limitation overflow page (v1: addPage when lineWrap(y+5, third) > 232) --}} @if (!empty($model['limit_new_page']) && !empty($model['ref_third']))
@include('pdf.smart_report.components.backgrounds.bg', ['template' => $bgTemplate, 'page' => 1]) @include('pdf.smart_report.components.patient_header', [ 'Order' => $Order, 'Profile' => $Profile, 'firstPackage' => $Package, 'Category' => (($Package->lABCATEGORYPACKAGE->REPORT_DISPLAY_NAME_AR ?? null) ?: ($Package->lABCATEGORYPACKAGE->NAME_AR ?? '')), 'Description' => $Package->lABCATEGORYPACKAGE->SMART_DESC_AR ?? '', 'setAdvice' => false, ])
Limitation:
{{ $model['ref_third'] }}
@endif {{-- ═══════════════════════════════════════════════════════════════════════ --}} {{-- VARIANT: pcr_qua (GetPCRQUAPDF — qualitative + sample type) --}} {{-- ═══════════════════════════════════════════════════════════════════════ --}} @elseif ($variant === 'pcr_qua')
@include('pdf.smart_report.components.backgrounds.bg', ['template' => $bgTemplate, 'page' => 1]) @include('pdf.smart_report.components.patient_header', [ 'Order' => $Order, 'Profile' => $Profile, 'firstPackage' => $Package, 'Category' => (($Package->lABCATEGORYPACKAGE->REPORT_DISPLAY_NAME_AR ?? null) ?: ($Package->lABCATEGORYPACKAGE->NAME_AR ?? '')), 'Description' => $Package->lABCATEGORYPACKAGE->SMART_DESC_AR ?? '', 'setAdvice' => false, ])
Test
Result
Sample type
@if (!empty($model['sample_type']))
{{ $model['sample_type'] }}
@endif @if (!empty($model['unit']))
Unit
Reference range
Not Detected
{{ $model['unit'] }}
@else
Reference range
Not Detected
@endif
Result:
@if (!empty($model['result']))
{{ $model['result'] }}
@endif
Comment:
@if (!empty($model['ref_first']))
{{ $model['ref_first'] }}
Methodology Brief:
@endif @if (!empty($model['ref_second']))
{{ $model['ref_second'] }}
@endif @if (!empty($model['ref_second']) && empty($model['limit_new_page']))
Limitation:
@endif @if (!empty($model['ref_third']) && empty($model['limit_new_page']))
{{ $model['ref_third'] }}
@endif
{{-- Limitation overflow page (v1: addPage when lineWrap(y+5, third) > 232) --}} @if (!empty($model['limit_new_page']) && !empty($model['ref_third']))
@include('pdf.smart_report.components.backgrounds.bg', ['template' => $bgTemplate, 'page' => 1]) @include('pdf.smart_report.components.patient_header', [ 'Order' => $Order, 'Profile' => $Profile, 'firstPackage' => $Package, 'Category' => (($Package->lABCATEGORYPACKAGE->REPORT_DISPLAY_NAME_AR ?? null) ?: ($Package->lABCATEGORYPACKAGE->NAME_AR ?? '')), 'Description' => $Package->lABCATEGORYPACKAGE->SMART_DESC_AR ?? '', 'setAdvice' => false, ])
Limitation:
{{ $model['ref_third'] }}
@endif {{-- ═══════════════════════════════════════════════════════════════════════ --}} {{-- VARIANT: pcr_gen (GetPCRGENPDF — HRHPV per-row options) --}} {{-- ═══════════════════════════════════════════════════════════════════════ --}} @elseif ($variant === 'pcr_gen')
@include('pdf.smart_report.components.backgrounds.bg', ['template' => $bgTemplate, 'page' => 1]) @include('pdf.smart_report.components.patient_header', [ 'Order' => $Order, 'Profile' => $Profile, 'firstPackage' => $Package, 'Category' => (($Package->lABCATEGORYPACKAGE->REPORT_DISPLAY_NAME_AR ?? null) ?: ($Package->lABCATEGORYPACKAGE->NAME_AR ?? '')), 'Description' => $Package->lABCATEGORYPACKAGE->SMART_DESC_AR ?? '', 'setAdvice' => false, ]) {{-- Sample type / Result / Reference range as a table (header + body, --}} {{-- columns 73/50/57mm ≈ old x 20/93/143). Comment anchor stays at $y. --}}
Sample type
Result
Reference range
@foreach ($model['rows'] ?? [] as $row)
{{ $row['name_en'] }}
{{ $row['result_en'] }}
{{ $row['ref_range'] }}
@endforeach
@php $y = 105 + 8 * count($model['rows'] ?? []); @endphp
Comment:
@if (!empty($model['ref_first']))
{{ $model['ref_first'] }}
Methodology Brief:
@endif @if (!empty($model['ref_second']))
{{ $model['ref_second'] }}
@endif @if (!empty($model['ref_second']) && empty($model['limit_new_page']))
Limitation:
@endif @if (!empty($model['ref_third']) && empty($model['limit_new_page']))
{{ $model['ref_third'] }}
@endif
{{-- Limitation overflow page (v1: addPage when lineWrap(y, third) > 232) --}} @if (!empty($model['limit_new_page']) && !empty($model['ref_third']))
@include('pdf.smart_report.components.backgrounds.bg', ['template' => $bgTemplate, 'page' => 1]) @include('pdf.smart_report.components.patient_header', [ 'Order' => $Order, 'Profile' => $Profile, 'firstPackage' => $Package, 'Category' => (($Package->lABCATEGORYPACKAGE->REPORT_DISPLAY_NAME_AR ?? null) ?: ($Package->lABCATEGORYPACKAGE->NAME_AR ?? '')), 'Description' => $Package->lABCATEGORYPACKAGE->SMART_DESC_AR ?? '', 'setAdvice' => false, ])
Limitation:
{{ $model['ref_third'] }}
@endif {{-- ═══════════════════════════════════════════════════════════════════════ --}} {{-- VARIANT: pcr_table (PROEL, QTGPT, IGRA, STONEA, NIPTCTR, DFGT, BF) --}} {{-- ═══════════════════════════════════════════════════════════════════════ --}} @elseif ($variant === 'pcr_table') @foreach ($model['pages'] as $pageIdx => $rows)
@include('pdf.smart_report.components.backgrounds.bg', ['template' => $bgTemplate, 'page' => 1]) @include('pdf.smart_report.components.patient_header', [ 'Order' => $Order, 'Profile' => $Profile, 'firstPackage' => $Package, 'Category' => (($Package->lABCATEGORYPACKAGE->REPORT_DISPLAY_NAME_AR ?? null) ?: ($Package->lABCATEGORYPACKAGE->NAME_AR ?? '')), 'Description' => $Package->lABCATEGORYPACKAGE->SMART_DESC_AR ?? '', 'setAdvice' => false, ]) @php $pCode = $model['code'] ?? ''; $isDfgt = ($pCode === 'DFGT'); $isNiptctr = ($pCode === 'NIPTCTR'); $headerLeft = $isDfgt ? 70 : ($isNiptctr ? 88 : 79); $refLeft = $isNiptctr ? 124 : 119; $unitLeft = $isDfgt ? 120 : 170; @endphp {{-- Column headers at y=105 --}}
{{ in_array($pCode, ['PROEL'], true) ? 'Fractions' : 'Test Name' }}
Result
@if (!$isDfgt)
Reference Range
@endif
Units
@php $y = 115; @endphp @foreach ($rows as $row)
{{ $row['name_en'] }}
@if (!empty($row['result_en']) || $row['result_raw'] !== null)
{{ $row['result_en'] ?? $row['result_raw'] }}
@endif @if (!$isDfgt && !empty($row['ref_range']))
{{ $row['ref_range'] }}
@endif @if (!empty($row['unit']))
{{ $row['unit'] }}
@else
--
@endif @if (!empty($row['gender_img']) && is_file($row['gender_img'])) @endif @php $y += 7; @endphp @endforeach {{-- Append reference texts after data rows on last page. --}} @if ($pageIdx === count($model['pages']) - 1) @if (!empty($model['ref_first']))
{{ $model['ref_first'] }}
@php $y += 14; @endphp @endif @if (!empty($model['ref_second']))
{{ $model['ref_second'] }}
@php $y += 20; @endphp @endif @if (!empty($model['comment']))
{!! $service->sanitizeCommentHtml($model['comment']) !!}
@endif @endif
@endforeach {{-- ═══════════════════════════════════════════════════════════════════════ --}} {{-- VARIANT: pcr_mthfr (GetMTHFRPCRPDF) --}} {{-- ═══════════════════════════════════════════════════════════════════════ --}} @elseif ($variant === 'pcr_mthfr')
@include('pdf.smart_report.components.backgrounds.bg', ['template' => $bgTemplate, 'page' => 1]) @include('pdf.smart_report.components.patient_header', [ 'Order' => $Order, 'Profile' => $Profile, 'firstPackage' => $Package, 'Category' => (($Package->lABCATEGORYPACKAGE->REPORT_DISPLAY_NAME_AR ?? null) ?: ($Package->lABCATEGORYPACKAGE->NAME_AR ?? '')), 'Description' => $Package->lABCATEGORYPACKAGE->SMART_DESC_AR ?? '', 'setAdvice' => false, ])
MTHFR Result Interpretation:
@if (!empty($model['st']))
{{ $model['st']['label'] }}:
{{ $model['st']['value'] }}
@endif @if (!empty($model['c677t']))
{{ $model['c677t']['label'] }}:
{{ $model['c677t']['value'] }}
@endif @if (!empty($model['a1298c']))
{{ $model['a1298c']['label'] }}:
{{ $model['a1298c']['value'] }}
@endif @if (!empty($model['ref_second']))
Methodology:
{{ $model['ref_second'] }}
@endif @if (!empty($model['ref_first']))
Analytical Sensitivity & Specificity:
{{ $model['ref_first'] }}
@endif @if (!empty($model['ref_third']))
Limitation:
{{ $model['ref_third'] }}
@endif @if (!empty($model['ref_fourth']))
Disclaimer:
{{ $model['ref_fourth'] }}
@endif
{{-- ═══════════════════════════════════════════════════════════════════════ --}} {{-- VARIANT: pcr_nipt (GetNIPTPCRPDF — NIPTPCR / GDDDPCR) --}} {{-- ═══════════════════════════════════════════════════════════════════════ --}} @elseif ($variant === 'pcr_nipt')
@include('pdf.smart_report.components.backgrounds.bg', ['template' => $bgTemplate, 'page' => 1]) @include('pdf.smart_report.components.patient_header', [ 'Order' => $Order, 'Profile' => $Profile, 'firstPackage' => $Package, 'Category' => (($Package->lABCATEGORYPACKAGE->REPORT_DISPLAY_NAME_AR ?? null) ?: ($Package->lABCATEGORYPACKAGE->NAME_AR ?? '')), 'Description' => $Package->lABCATEGORYPACKAGE->SMART_DESC_AR ?? '', 'setAdvice' => false, ]) @php $sy = 90; @endphp @foreach (['ST', 'GA'] as $sc) @if (!empty($model['scalars'][$sc]))
{{ $model['scalars'][$sc]['label'] }}:
{{ $model['scalars'][$sc]['value'] }}
@php $sy += 8; @endphp @endif @endforeach @php $ty = $sy + 7; @endphp
Test
Result
Reference Range
@php $ty += 7; @endphp @foreach ($model['typed'] ?? [] as $tr)
{{ $tr['label'] }}
{{ $tr['value'] }}
{{ $tr['normal'] }}
@php $ty += 7; @endphp @endforeach @if (!empty($model['gender_img']) && is_file($model['gender_img'])) @endif @foreach (['In', 'RE'] as $sc) @if (!empty($model['scalars'][$sc])) @php $ty += 4; @endphp
{{ $model['scalars'][$sc]['label'] }}:
{{ $model['scalars'][$sc]['value'] }}
@php $ty += 20; @endphp @endif @endforeach
{{-- ═══════════════════════════════════════════════════════════════════════ --}} {{-- VARIANT: pcr_nbs (GetNBSPDF — Newborn Screening) --}} {{-- ═══════════════════════════════════════════════════════════════════════ --}} @elseif ($variant === 'pcr_nbs') {{-- Newborn Screening: a flowing table, paginated server-side into --}} {{-- $model['pages'] (each page = a list of blocks). Rows auto-size to their --}} {{-- reference text (the 8-line 17-OHP ref pushes the next row down instead of --}} {{-- overlapping — the coordinate y+=12 layout could not). A block is either --}} {{-- the ungrouped analytes or one disease group (title + Markers status; a --}} {{-- non-remarkable group collapses to those + recommendations, an abnormal one --}} {{-- also lists its marker sub-values). --}} @php // Shared result-cell resolver so ungrouped and grouped rows look identical. $nbsResultCell = function ($row) { if (!empty($row['result_opt'])) return ['text' => $row['result_opt'], 'color' => $row['color'] ?? '#000']; if (!empty($row['result_multi'])) return ['text' => $row['result_multi'], 'color' => '#000']; if (($row['result_raw'] ?? null) !== null) return ['text' => $row['result_raw'], 'color' => $row['color'] ?? '#000']; return ['text' => '', 'color' => '#000']; }; $nbsRefLines = function ($row) { if (!empty($row['hardcoded_ref'])) return $row['hardcoded_ref']; if ($row['type'] !== 'TEXTAREA' && ($row['result_raw'] ?? null) !== null && ($row['min_normal'] !== null || $row['max_normal'] !== null)) { return [trim(($row['min_normal'] ?? '') . ' - ' . ($row['max_normal'] ?? ''), ' -')]; } return []; }; $nbsPages = $model['pages'] ?? [[]]; @endphp @foreach ($nbsPages as $pageIdx => $blocks)
@include('pdf.smart_report.components.backgrounds.bg', ['template' => $bgTemplate, 'page' => 1]) @include('pdf.smart_report.components.patient_header', [ 'Order' => $Order, 'Profile' => $Profile, 'firstPackage' => $Package, 'Category' => (($Package->lABCATEGORYPACKAGE->REPORT_DISPLAY_NAME_AR ?? null) ?: ($Package->lABCATEGORYPACKAGE->NAME_AR ?? '')), 'Description' => $Package->lABCATEGORYPACKAGE->SMART_DESC_AR ?? '', 'setAdvice' => false, ])
{{-- Continuation pages label the first column "Diseases" (v1). --}} @foreach ($blocks as $block) @if ($block['type'] === 'ungrouped') @foreach ($block['rows'] as $row) @php $res = $nbsResultCell($row); $refs = $nbsRefLines($row); @endphp @endforeach @else @php $grp = $block['group']; @endphp @foreach ($grp['rows'] as $row) @php // Non-remarkable groups hide their raw acylcarnitine // sub-values (mirrors v1's $Nonremarkable guard). $isSub = ($row['result_opt'] === null && $row['result_multi'] === null && $row['type'] !== 'TEXTAREA' && ($row['result_raw'] ?? null) !== null); if ($grp['nonremarkable'] && $isSub) continue; $res = $nbsResultCell($row); $refs = $nbsRefLines($row); @endphp @endforeach @endif @endforeach
{{ $pageIdx === 0 ? 'Test Name' : 'Diseases' }} Result Reference Range Units
{{ $row['type'] === 'TEXTAREA' ? '' : $row['name_en'] }} {{ $res['text'] }} @foreach ($refs as $ln){{ $ln }}@if (!$loop->last)
@endif @endforeach
{{ $row['type'] === 'TEXTAREA' ? '' : (!empty($row['unit']) ? $row['unit'] : '--') }}
{{ $grp['title'] }}
{{ $row['show_name'] && $row['type'] !== 'TEXTAREA' ? $row['name_en'] : '' }} {{ $res['text'] }} @foreach ($refs as $ln){{ $ln }}@if (!$loop->last)
@endif @endforeach
{{ $row['type'] === 'TEXTAREA' ? '' : (!empty($row['unit']) ? $row['unit'] : '--') }}
@endforeach @endif {{-- end variant dispatch --}}