{{-- Smart Report v2 - CBC analysis card grid. --}} {{-- Mirrors SmartReportService::GetCbcPDF (lines 3116-3347). 6 cells per page --}} {{-- in a 3-row x 2-column grid. Rows are skipped for MXD/MXD# and non-numeric --}} {{-- RESULT values, but v1 paginates on the RAW row index ($key % 6, v1:3110) --}} {{-- where skipped rows still consume an index, and uses the "big cell" name --}} {{-- variant for RAW keys 4 and 5 (v1:3154). --}} @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->buildCbcRows($Package) : []; // buildCbcRows() only emits the surviving rows (indexed by the filtered // counter), so re-derive each surviving row's RAW key here with the same // query and skip rules the service uses. $rawKeys = []; if ($Package) { $rawResults = \App\Models\ENDUSERLABORDERPACKAGERESULT::where('END_USER_PACKAGE_ID', $Package->ID) ->with('Result') ->get(); foreach ($rawResults as $rawKey => $rawRow) { $rawCode = $rawRow->Result->CODE ?? ''; if ($rawCode === 'MXD' || $rawCode === 'MXD#') continue; if (empty($rawRow->RESULT) || !is_numeric($rawRow->RESULT)) continue; $rawKeys[] = $rawKey; } } // v1 starts a new page when a RENDERED row's own raw key is a non-zero // multiple of 6 (a skipped row never triggers a break). $pages = [[]]; $pageNo = 0; foreach ($rows as $i => $row) { $rawKey = $rawKeys[$i] ?? $row['index']; if ($rawKey !== 0 && $rawKey % 6 === 0) { $pageNo++; $pages[$pageNo] = []; } // Big-cell variant follows the raw key (v1:3154), not the filtered counter. $row['is_big_cell'] = in_array($rawKey, [4, 5], true); $pages[$pageNo][] = $row; } if (empty($rows)) $pages = [[]]; // still emit a header-only page @endphp @foreach ($pages as $pageIdx => $pageRows)
@include('pdf.smart_report.components.backgrounds.bg', ['template' => 'smart-report', 'page' => 1]) {{-- Patient header --}} @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->DESC_AR ?? '', ]) {{-- 6-up CBC grid --}} @foreach ($pageRows as $row) @php $x = $row['card_x']; $y = $row['card_y']; @endphp
{{-- Test name (Arabic + embedded Latin like "Basophils#" / --}} {{-- "Neutrophils%" / "(RDW-CV)"). LTR-isolate the Latin/symbol --}} {{-- run so RTL order keeps "Basophils#" from flipping to --}} {{-- "#Basophils". --}} {{-- A long title ("...الدم الحمراء (MCH)") wraps to 2 lines. The --}} {{-- min/max numbers sit just below at top:-13mm, so the box is --}} {{-- bottom-anchored just above them (bottom edge at -13mm) and --}} {{-- grows UPWARD. Use a roomy 3.4mm line box so the two lines have --}} {{-- clear spacing between them instead of being cramped together. --}} {{-- The min/max numbers below use a 10mm line box, so their glyphs --}} {{-- actually paint ~5mm below their -13mm anchor. Sit the title's --}} {{-- bottom just above that (bottom edge ≈ -9.5mm) so it fills the gap --}} {{-- above the numbers instead of floating up toward the card above, --}} {{-- and grows UPWARD with a roomy 3mm line box for two spaced lines. --}} @php $titleW = $row['is_big_cell'] ? 30 : 20; $titleL = $row['is_big_cell'] ? 36 : 40; @endphp
{!! $service->isolateLtrRuns($row['name_ar']) !!}
{{-- Description (right aligned, multiline) --}}
{!! nl2br($service->isolateLtrRuns($row['desc_ar'] ?? '')) !!}
{{-- ── Meter island: gauge line + its min/max threshold numbers --}} {{-- as one unit. Island at the card origin (0,0), so the inner --}} {{-- offsets are the unchanged card-relative values; move the --}} {{-- island to reposition the whole calibrated gauge. --}}
{{-- Min / Max threshold labels --}}
{{ $row['min_normal'] }}
{{ $row['max_normal'] }}
{{-- Meter (LNH-Line) image --}} @if (!empty($row['image'])) @endif
{{-- /.sr-meter --}} {{-- Numeric result + unit (follows indicator arrow, mirrors v1 SetXY switch tables) --}} {{-- Right-edge anchored like v1's Cell(14,46,'R'): long values overflow leftward, keeping the unit column aligned. --}}
{{ $row['result'] }}
{{ $row['unit'] }}
@endforeach
@endforeach