{{-- Smart Report v2 - Semen analysis (SA). --}} {{-- Mirrors SmartReportService::GetSemenanalysisPDF (lines 8677-9788). --}} {{-- Three pages: page 1 = physical, page 2 = morphology, page 3 = motility. --}} @php $service = $service ?? app(\App\Services\SmartReportV2Service::class); // v1 (GetSemenanalysisPDF 8683-8687): title = package test name with // REPORT_DISPLAY_NAME_AR override, description = SMART_DESC_AR. $semenPkg = $group['package'] ?? ($group['firstPackage'] ?? null); $semenTestName = $semenPkg->lABCATEGORYPACKAGE->NAME_AR ?? ''; if (!empty($semenPkg->lABCATEGORYPACKAGE->REPORT_DISPLAY_NAME_AR)) $semenTestName = $semenPkg->lABCATEGORYPACKAGE->REPORT_DISPLAY_NAME_AR; $semenDescription = $semenPkg->lABCATEGORYPACKAGE->SMART_DESC_AR ?? ''; $Package = $group['package'] ?? ($group['firstPackage'] ?? null); $model = $Package ? $service->buildSemenModel($Package) : ['page1' => [], 'page2' => [], 'page3' => []]; $p1 = $model['page1']; $p2 = $model['page2']; $p3 = $model['page3']; // Standard LNH meter left position (normal 1-9, high 1-3, low 1-3) $meterLeft = function ($type, $move) { $move = (int) round($move); if ($type === 'normal') return 24 + ($move - 1) * 4; if ($type === 'high') return 52 + ($move - 1) * 3; return 22 - ($move - 1) * 3; }; // Sperm-Count meter (normal up to 11, no high, low 1-3) $spermMeterLeft = function ($type, $move) { $move = (int) round($move); if ($type === 'normal') { if ($move <= 9) return 24 + ($move - 1) * 4; if ($move === 10) return 52; if ($move === 11) return 55; return 58; } if ($type === 'low') return max(16, 22 - ($move - 1) * 3); return 24; }; $meterColor = fn ($c) => $c === 'green' ? 'rgb(120,201,38)' : 'rgb(221,52,68)'; @endphp {{-- ═══════════════════════════ PAGE 1 ═══════════════════════════ --}}
@include('pdf.smart_report.components.backgrounds.bg', ['template' => 'semen', 'page' => 1]) @include('pdf.smart_report.components.patient_header', [ 'Order' => $Order, 'Profile' => $Profile, 'firstPackage' => $Package, 'Category' => $semenTestName, 'Description' => $semenDescription, 'setAdvice' => false, ]) {{-- ── SV (Semen Volume) ── meter: img(99,103) result y=108 desc y=102 --}} @if (!empty($p1['sv']))
{{ $p1['sv']['min_normal'] }}
{{ $p1['sv']['max_normal'] }}
@if (!empty($p1['sv']['image']) && is_file($p1['sv']['image'])) @endif @php $svLeft = $meterLeft($p1['sv']['type'], $p1['sv']['move']); @endphp
{{ $p1['sv']['result'] }} {{ $p1['sv']['unit'] ?? '' }}
@if (!empty($p1['sv']['desc_ar']))
{!! $service->isolateLtrRuns($p1['sv']['desc_ar']) !!}
@endif @endif {{-- ── VISO (Viscosity) ── image at (99,116) desc at y=117 --}} @if (!empty($p1['viso'])) @if (!empty($p1['viso']['image']) && is_file($p1['viso']['image'])) @endif @php $visoName = $p1['viso']['name_en'] ?? ''; $visoMap = [ 'Viscous' => ['color' => 'rgb(120,201,38)', 'x' => 27], 'Normal' => ['color' => 'rgb(120,201,38)', 'x' => 27], 'Mild' => ['color' => 'rgb(255,192,203)', 'x' => 49], 'Moderate' => ['color' => 'rgb(255,140,0)', 'x' => 40], 'High' => ['color' => 'rgb(221,52,68)', 'x' => 60], 'Hyper Viscous' => ['color' => 'rgb(221,52,68)', 'x' => 60], ]; $visoStyle = $visoMap[$visoName] ?? ['color' => '#000', 'x' => 27]; @endphp
{{ $visoName }}
@if (!empty($p1['viso']['desc_ar']))
{!! $service->isolateLtrRuns($p1['viso']['desc_ar']) !!}
@endif @endif {{-- ── SPH (pH) ── option or numeric --}} @if (!empty($p1['sph'])) @if (($p1['sph']['variant'] ?? '') === 'option') @if (!empty($p1['sph']['image']) && is_file($p1['sph']['image'])) @endif @php $sphOptX = ($p1['sph']['name_en'] === 'Acidic') ? 60 : 27; @endphp
{{ $p1['sph']['name_en'] }}
@else
{{ $p1['sph']['min_normal'] }}
{{ $p1['sph']['max_normal'] }}
@if (!empty($p1['sph']['image']) && is_file($p1['sph']['image'])) @endif @php $sphLeft = $meterLeft($p1['sph']['type'], $p1['sph']['move']); @endphp
{{ $p1['sph']['result'] }} {{ $p1['sph']['unit'] ?? '' }}
@endif @if (!empty($p1['sph']['desc_ar']))
{!! $service->isolateLtrRuns($p1['sph']['desc_ar']) !!}
@endif @endif {{-- ── SLI (Liquefaction) ── meter: img(99,145) result y=150 desc y=144 --}} @if (!empty($p1['sli']))
{{ $p1['sli']['min_normal'] }}
{{ $p1['sli']['max_normal'] }}
@if (!empty($p1['sli']['image']) && is_file($p1['sli']['image'])) @endif @php $sliLeft = $meterLeft($p1['sli']['type'], $p1['sli']['move']); @endphp
{{ $p1['sli']['result'] }} {{ $p1['sli']['unit'] ?? '' }}
@if (!empty($p1['sli']['desc_ar']))
{!! $service->isolateLtrRuns($p1['sli']['desc_ar']) !!}
@endif @endif {{-- ── SODOR (Odor) ── image at (99,159) desc y=153 --}} @if (!empty($p1['sodor'])) @if (!empty($p1['sodor']['image']) && is_file($p1['sodor']['image'])) @endif @if (!empty($p1['sodor']['desc_ar']))
{!! $service->isolateLtrRuns($p1['sodor']['desc_ar']) !!}
@endif @endif {{-- ── SAC (Color) ── image at (99,171) desc y=171 --}} @if (!empty($p1['sac'])) @if (!empty($p1['sac']['image']) && is_file($p1['sac']['image'])) @endif @if (!empty($p1['sac']['desc_ar']))
{!! $service->isolateLtrRuns($p1['sac']['desc_ar']) !!}
@endif @endif {{-- ── SPCS (Sperm Count) ── sperm-count meter: img(99,187) result y=192 desc y=186 --}} @if (!empty($p1['spcs']))
{{ $p1['spcs']['min_normal'] }}
{{ $p1['spcs']['max_normal'] }}
@if (!empty($p1['spcs']['image']) && is_file($p1['spcs']['image'])) @endif @php $spcsLeft = $spermMeterLeft($p1['spcs']['type'], $p1['spcs']['move']); @endphp
{{ $p1['spcs']['result'] }} {{ $p1['spcs']['unit'] ?? '' }}
@if (!empty($p1['spcs']['desc_ar']))
{!! $service->isolateLtrRuns($p1['spcs']['desc_ar']) !!}
@endif @endif {{-- ── SPWB (WBC) ── meter: img(99,223) result y=228 desc y=223 --}} @if (!empty($p1['spwb']))
{{ $p1['spwb']['min_normal'] }}
{{ $p1['spwb']['max_normal'] }}
@if (!empty($p1['spwb']['image']) && is_file($p1['spwb']['image'])) @endif @php $spwbLeft = $meterLeft($p1['spwb']['type'], $p1['spwb']['move']); @endphp
{{ $p1['spwb']['result'] }} {{ $p1['spwb']['unit'] ?? '' }}
@if (!empty($p1['spwb']['desc_ar']))
{!! $service->isolateLtrRuns($p1['spwb']['desc_ar']) !!}
@endif @endif {{-- ── SPRB (RBC) ── option image at (99,235) desc y=236 --}} @if (!empty($p1['sprb'])) @php $sprbName = $p1['sprb']['name_en'] ?? ''; $sprbPositions = [ 'Nill' => ['x' => 25, 'y' => 239], 'Nil' => ['x' => 25, 'y' => 239], 'Negative' => ['x' => 25, 'y' => 241], '+1' => ['x' => 28, 'y' => 241], '+2' => ['x' => 31, 'y' => 241], '+3' => ['x' => 34, 'y' => 241], '+4' => ['x' => 37, 'y' => 241], '+5' => ['x' => 40, 'y' => 241], '+6' => ['x' => 43, 'y' => 241], '+7' => ['x' => 46, 'y' => 241], '+8' => ['x' => 49, 'y' => 241], '+9' => ['x' => 52, 'y' => 241], '+10' => ['x' => 55, 'y' => 241], '+11' => ['x' => 59, 'y' => 241], ]; $sprbPos = $sprbPositions[$sprbName] ?? ['x' => 25, 'y' => 241]; $sprbColorMap = [ 'Nill' => 'rgb(120,201,38)', 'Nil' => 'rgb(120,201,38)', 'Negative' => 'rgb(120,201,38)', '+1' => 'rgb(228,111,1)', '+2' => 'rgb(228,111,1)', '+3' => 'rgb(228,111,1)', '+4' => 'rgb(228,111,1)', '+5' => 'rgb(228,111,1)', '+6' => 'rgb(221,52,68)', '+7' => 'rgb(221,52,68)', '+8' => 'rgb(221,52,68)', '+9' => 'rgb(221,52,68)', '+10' => 'rgb(221,52,68)', '+11' => 'rgb(221,52,68)', ]; $sprbColor = $sprbColorMap[$sprbName] ?? $p1['sprb']['color']; @endphp @if (!empty($p1['sprb']['image']) && is_file($p1['sprb']['image'])) @endif
{{ $sprbName }} {{ $p1['sprb']['unit'] ?? '' }}
@if (!empty($p1['sprb']['desc_ar']))
{!! $service->isolateLtrRuns($p1['sprb']['desc_ar']) !!}
@endif @endif {{-- ── SPCC (Concentration) ── meter: img(99,252) result y=258 desc y=248 --}} @if (!empty($p1['spcc']))
{{ $p1['spcc']['min_normal'] }}
{{ $p1['spcc']['max_normal'] }}
@if (!empty($p1['spcc']['image']) && is_file($p1['spcc']['image'])) @endif @php $spccLeft = $meterLeft($p1['spcc']['type'], $p1['spcc']['move']); @endphp
{{ $p1['spcc']['result'] }} {{ $p1['spcc']['unit'] ?? '' }}
@if (!empty($p1['spcc']['desc_ar']))
{!! $service->isolateLtrRuns($p1['spcc']['desc_ar']) !!}
@endif @endif
{{-- ═══════════════════════════ PAGE 2 ═══════════════════════════ --}}
@include('pdf.smart_report.components.backgrounds.bg', ['template' => 'semen', 'page' => 2]) @include('pdf.smart_report.components.patient_header', [ 'Order' => $Order, 'Profile' => $Profile, 'firstPackage' => $Package, 'Category' => $semenTestName, 'Description' => $semenDescription, 'setAdvice' => false, ]) {{-- ── SPEC (Sperm Evaluation) ── meter: img(99,92) result y=97 desc y=91 --}} @if (!empty($p2['spec']))
{{ $p2['spec']['min_normal'] }}
{{ $p2['spec']['max_normal'] }}
@if (!empty($p2['spec']['image']) && is_file($p2['spec']['image'])) @endif @php $specLeft = $meterLeft($p2['spec']['type'], $p2['spec']['move']); @endphp
{{ $p2['spec']['result'] }} {{ $p2['spec']['unit'] ?? '' }}
@if (!empty($p2['spec']['desc_ar']))
{!! $service->isolateLtrRuns($p2['spec']['desc_ar']) !!}
@endif @endif {{-- ── SCD (Cellular Debris) ── image at (99,103) desc y=104 --}} @if (!empty($p2['scd'])) @if (!empty($p2['scd']['image']) && is_file($p2['scd']['image'])) @endif @if (!empty($p2['scd']['desc_ar']))
{!! $service->isolateLtrRuns($p2['scd']['desc_ar']) !!}
@endif @endif {{-- ── SCA (Agglutination) ── image at (99,118) desc y=117 --}} @if (!empty($p2['sca'])) @if (!empty($p2['sca']['image']) && is_file($p2['sca']['image'])) @endif @if (!empty($p2['sca']['desc_ar']))
{!! $service->isolateLtrRuns($p2['sca']['desc_ar']) !!}
@endif @endif {{-- ── SHH/SHN (Head/Neck Defects pie) ── image at (99,151) --}} @if (!empty($p2['head_neck'])) @if (!empty($p2['head_neck']['image']) && is_file($p2['head_neck']['image'])) @endif
{{ $p2['head_neck']['shh_name'] }}
{{ $p2['head_neck']['shh_result'] }} {{ $p2['head_neck']['shh_unit'] }}
{{ $p2['head_neck']['shn_name'] }}
{{ $p2['head_neck']['shn_result'] }} {{ $p2['head_neck']['shn_unit'] }}
@if (!empty($p2['head_neck']['desc_ar']))
{!! $service->isolateLtrRuns($p2['head_neck']['desc_ar']) !!}
@endif @endif {{-- ── SHD (Head Defects %) ── at (48,177) --}} @if (!empty($p2['shd']))
{{ $p2['shd']['result'] }}%
@endif {{-- ── SIF (Sperm Index Factor) ── code at (25,172) result at (16,167) --}} @if (!empty($p2['sif']))
{{ $p2['sif']['code'] }}
{{ $p2['sif']['result'] }}%
@endif {{-- ── STAD (Tail Defects %) ── at (48,210) --}} @if (!empty($p2['stad']))
{{ $p2['stad']['result'] }}%
@endif {{-- ── SMPD (Midpiece Defects %) ── at (78,194) left-aligned --}} @if (!empty($p2['smpd']))
{{ $p2['smpd']['result'] }}%
@endif {{-- ── SCYD (Cytoplasmic Droplet %) ── at (76,212) left-aligned --}} @if (!empty($p2['scyd']))
{{ $p2['scyd']['result'] }}%
@endif {{-- ── SCE (Sperm Concentration Evaluation) ── --}} @if (!empty($p2['sce']))
{{ $p2['sce']['name_ar'] }}
{{ $p2['sce']['name_en'] }}
{{ $p2['sce']['result'] }}
{{ $p2['sce']['min_normal'] }}
{{ $p2['sce']['max_normal'] }}
@if (!empty($p2['sce']['image']) && is_file($p2['sce']['image'])) @endif @php $sceLeft = $spermMeterLeft($p2['sce']['type'], $p2['sce']['move']); @endphp {{-- v1 draws this in a Cell(85,7): text is vertically centred ~3.5mm below the 252mm origin, which keeps it clear of the description's 2nd line. --}}
{{ $p2['sce']['result'] }} {{ $p2['sce']['unit'] ?? '' }}
@if (!empty($p2['sce']['desc_ar']))
{!! $service->isolateLtrRuns($p2['sce']['desc_ar']) !!}
@endif @endif
{{-- ═══════════════════════════ PAGE 3 ═══════════════════════════ --}}
@include('pdf.smart_report.components.backgrounds.bg', ['template' => 'semen', 'page' => 3]) @include('pdf.smart_report.components.patient_header', [ 'Order' => $Order, 'Profile' => $Profile, 'firstPackage' => $Package, 'Category' => $semenTestName, 'Description' => $semenDescription, 'setAdvice' => true, ]) {{-- ── Grade A-D percentages ── centred inside the small circle at the --}} {{-- bottom of each grade illustration. The circle centre sits at ~86.8% of --}} {{-- the grade image height (top 101.61mm, ~35.2mm tall) → y≈132.2mm, and at --}} {{-- the image centre-x (A 32.18 / B 77.40 / C 122.44 / D 167.66). A 20mm --}} {{-- centred box + centred top puts each number in the middle of its circle. --}} @php $pctY = 130.6; // top so ~3mm text centres on 132.2mm $pctCx = ['sga' => 32.18, 'sgb' => 77.40, 'sgc' => 122.44, 'sgd' => 167.66]; @endphp @foreach (['sga', 'sgb', 'sgc', 'sgd'] as $gk) @if (!empty($p3[$gk]))
{{ $p3[$gk]['result'] }}%
@endif @endforeach {{-- ── SAB (a+b grade meter) ── image at (56,150) w=45 --}} @if (!empty($p3['sab']) && !empty($p3['sab']['image']) && is_file($p3['sab']['image'])) @endif {{-- ── SPT (Production Time) ── --}} @if (!empty($p3['spt']))
{{ $p3['spt']['name_ar'] }}
{{ $p3['spt']['name_en'] }}
{{ $p3['spt']['result'] }}
@endif {{-- ── SRT (Receipt Time) ── --}} @if (!empty($p3['srt']))
{{ $p3['srt']['name_ar'] }}
{{ $p3['srt']['name_en'] }}
{{ $p3['srt']['result'] }}
@endif {{-- ── SAD (Abstinence Days) ── --}} @if (!empty($p3['sad']))
{{ $p3['sad']['name_ar'] }}
{{ $p3['sad']['name_en'] }}
{{ $p3['sad']['result'] }}
@endif