@php use App\Services\SiboBreathTestService; $LabCategoryPackageResults = \App\Models\ENDUSERLABORDERPACKAGERESULT::where('END_USER_PACKAGE_ID', $Package->ID) ->with('Result') ->get(); $Values = []; foreach ($LabCategoryPackageResults as $Row) { if (empty($Row->Result) || empty($Row->Result->CODE)) continue; $Values[$Row->Result->CODE] = $Row->RESULT; } $SiboService = new SiboBreathTestService(); $Evaluation = $SiboService->evaluate($Values); $H2 = $Evaluation['h2']; $CH4 = $Evaluation['ch4']; // The narrative cells are open text: show what the lab stored, and fall back to // the derived wording for results saved before the cells were auto filled. $StoredResult = trim((string) ($Values[SiboBreathTestService::RESULT_CODE] ?? '')); $StoredDetection = trim((string) ($Values[SiboBreathTestService::DETECTION_CODE] ?? '')); $StoredConclusion = trim((string) ($Values[SiboBreathTestService::CONCLUSION_CODE] ?? '')); $StoredRecommendation = trim((string) ($Values[SiboBreathTestService::RECOMMENDATION_CODE] ?? '')); $ResultText = $StoredResult !== '' ? $StoredResult : $Evaluation['result']; $DetectionText = $StoredDetection !== '' ? $StoredDetection : $Evaluation['detection']; $ConclusionText = $StoredConclusion !== '' ? $StoredConclusion : $Evaluation['conclusion']; // A hand written recommendation replaces the lead and its bullets entirely. // Matching on the lead rather than the whole paragraph keeps auto filled results // rendering as bullets even after the bullet wording is edited. $CustomRecommendation = $StoredRecommendation !== '' && $Evaluation['recommendation_lead'] !== '' && !str_starts_with($StoredRecommendation, $Evaluation['recommendation_lead']); $Positive = $Evaluation['positive']; $Danger = '#E9473A'; $Normal = '#1FA345'; $Navy = '#1F3864'; $Orange = '#F5A623'; $ppm = function ($value) { if ($value === null) return '--'; return rtrim(rtrim(number_format((float) $value, 2, '.', ''), '0'), '.'); }; $signed = function ($value) use ($ppm) { if ($value === null) return '--'; return ($value > 0 ? '+' : '') . $ppm($value); }; // The report-wide stylesheet forces white cells, centred text and grey borders on // every table with !important, so the coloured blocks have to out-shout it inline. $th = 'background-color:' . $Navy . ' !important; color:#fff !important; font-weight:700; padding:6px 8px !important;'; $plain = 'border:none !important; background-color:transparent !important; text-align:left !important; vertical-align:top;'; $TimeLabels = ['Baseline', '30 Min', '60 Min', '75 Min', '90 Min']; $TimeMins = [0, 30, 60, 75, 90]; @endphp {{-- ── Result banner + conclusion ─────────────────────────────────────────── --}}
|
{{ $ResultText }}
{{ $DetectionText }}
|
Conclusion
{!! nl2br(e($ConclusionText)) !!}
|
| Time Point | Time (min) | H2 (ppm) | CH4 (ppm) | H2 Status | CH4 Status |
|---|---|---|---|---|---|
| {{ $Label }} | {{ $TimeMins[$Index] }} | {{ $ppm($H2Point['value']) }} | {{ $ppm($CH4Point['value']) }} | @if($H2Point['value'] === null) -- @elseif($Index === 0) Baseline @else {{ $signed($Rise) }} · {{ !empty($H2Point['positive']) ? 'Above threshold' : 'Normal' }} @endif | {{ $CH4Point['value'] === null ? '--' : (!empty($CH4Point['positive']) ? 'Above threshold' : 'Normal') }} |
|
Hydrogen (H2) Result
Baseline: {{ $ppm($H2['baseline']) }} ppm Peak: {{ $ppm($H2['peak']) }} ppm@if($H2['peak_label']) at {{ $H2['peak_label'] }}@endif
Rise above baseline: {{ $signed($H2['peak_rise']) }} ppm Diagnostic threshold: {{ $ppm($H2['threshold']) }} ppm or more rise above baseline {{ $H2['positive'] ? 'Above threshold' : 'Below threshold — Normal' }} {{ $H2['positive'] ? 'Suggests hydrogen-producing bacteria in the small intestine.' : 'No hydrogen-producing bacteria in the small intestine.' }} |
Methane (CH4) Result
Baseline: {{ $ppm($CH4['baseline']) }} ppm Peak: {{ $ppm($CH4['peak']) }} ppm@if($CH4['peak_label']) at {{ $CH4['peak_label'] }}@endif
Diagnostic threshold: {{ $ppm($CH4['threshold']) }} ppm or more at any point {{ $CH4['positive'] ? 'Above threshold' : 'Below threshold — Normal' }} {{ $CH4['positive'] ? 'Small intestinal methanogen overgrowth (IMO) detected.' : 'No small intestinal methanogen overgrowth (IMO) detected.' }} |
| Gas | Normal Range | Diagnostic Threshold | Patient Result | Status |
|---|---|---|---|---|
| Hydrogen (H2) | < {{ $ppm($H2['threshold']) }} ppm rise | {{ $ppm($H2['threshold']) }} ppm above baseline | {{ $signed($H2['peak_rise']) }} ppm / Peak {{ $ppm($H2['peak']) }} | {{ $H2['positive'] ? 'Above threshold' : 'Normal' }} |
| Methane (CH4) | < {{ $ppm($CH4['threshold']) }} ppm | {{ $ppm($CH4['threshold']) }} ppm at any point | {{ $ppm($CH4['peak']) }} ppm | {{ $CH4['positive'] ? 'Above threshold' : 'Normal' }} |
|
Clinical Recommendation
@if($CustomRecommendation)
{!! nl2br(e($StoredRecommendation)) !!}
@else
{{ $Evaluation['recommendation_lead'] }}
@endif
|
@if(!$CustomRecommendation)
|
@endif