@php
$currentDate = $Package->eNDUSERLABORDER->CREATE_DATE ?? $Package->COLLECTION_TIME ?? date('Y-m-d H:i:s');
$Age = getDateDifference($Package->DATE_OF_BIRTH, $currentDate) + 1;
$LabCategoryPackageGroups = \App\Models\ENDUSERLABORDERPACKAGERESULT::where('END_USER_PACKAGE_ID', $Package->ID)
->with('Option', 'Result', 'Result.NormalOption')->get()->groupBy('Result.PARENT_ID');
$withOutGroup = $LabCategoryPackageGroups[""];
unset($LabCategoryPackageGroups[""]);
$normalColor = 'color: #78C938;'; // Color for normal results
$abnormalColor = 'color: #DD3444;'; // Color for abnormal results
$blackColor = 'color: #000;';
$HEMODIS = [];
$HEMODISComment = [];
@endphp
@php
// Summary table data - calculate at the beginning
$summaryTests = [
'NTSH' => ['name' => 'Neonatal Thyroid Stimulating Hormone (TSH)', 'result' => null, 'status' => 'Non-Remarkable'],
'BTNDASE' => ['name' => 'Neonatal Biotinidase Activity (BTD)', 'result' => null, 'status' => 'Non-Remarkable'],
'GALT' => ['name' => 'Neonatal Galactose-1-phosphate Uridyl Transferase (GALT)', 'result' => null, 'status' => 'Non-Remarkable'],
'N17P' => ['name' => 'Progesterone Neonatal 17 (OH)', 'result' => null, 'status' => 'Non-Remarkable'],
'G6PD' => ['name' => 'phosphate dehydrogenase Neonatal Glucose-6-(G6PD)', 'result' => null, 'status' => 'Non-Remarkable'],
'MSMS' => ['name' => 'Amino Acidemias, Organic Acidemias, and Fatty Acid Oxidation Disorders.', 'result' => 'Screened', 'status' => 'Non-Remarkable'],
'HEMODIS' => ['name' => 'Hemoglobin Disorders', 'result' => null, 'status' => 'Non-Remarkable'],
];
// Collect results for summary
foreach($withOutGroup as $item) {
$code = $item->Result->CODE ?? null;
if(isset($summaryTests[$code]) && !empty($item->RESULT)) {
$summaryTests[$code]['result'] = $item->RESULT;
// Use the same logic as TEST RESULTS table
$minNormal = $item->Result->MIN_NORMAL ?? null;
$maxNormal = $item->Result->MAX_NORMAL ?? null;
// Handle NOP special case
if($code == 'NOP' || $code == 'N17P') {
$maxNormal = ($Age > 0.709589) ? 41.9 : 109;
}
// Parse result value, handling symbols like >, <, >=, <=
$resultValue = $item->RESULT;
$symbol = null;
if (preg_match('/[\'^£$%&*()}{@#~?><>,>=|=_+¬-]/', $resultValue)) {
if (str_contains($resultValue, '>=')) {
$symbol = '>=';
} elseif (str_contains($resultValue, '>')) {
$symbol = '>';
$resultValue = (float)filter_var($resultValue, FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_FRACTION) + 0.01;
} elseif (str_contains($resultValue, '<=')) {
$symbol = '<=';
} elseif (str_contains($resultValue, '<')) {
$symbol = '<';
$resultValue = (float)filter_var($resultValue, FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_FRACTION) - 0.01;
}
} else {
$resultValue = (float)filter_var($resultValue, FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_FRACTION);
}
// Determine status based on MIN_NORMAL and MAX_NORMAL
if($minNormal !== null && $maxNormal !== null && is_numeric($resultValue)) {
if($resultValue >= $minNormal && $resultValue <= $maxNormal) {
$summaryTests[$code]['status'] = 'Non-Remarkable';
} else {
$summaryTests[$code]['status'] = 'Remarkable';
}
}
}
}
$msmsRemarkable = false;
foreach ($LabCategoryPackageGroups as $LabCategoryPackageGroup) {
$groupNonremarkable = false;
foreach ($LabCategoryPackageGroup as $LabCategoryPackageResult) {
// Skip HEMODIS and comments
if(in_array($LabCategoryPackageResult->Result->CODE ?? '', ['HEMODIS', 'UpNormalComm'])) {
continue;
}
$resultOption = $LabCategoryPackageResult->Option->NAME_EN ?? null;
$resultValue = $LabCategoryPackageResult->RESULT ?? null;
// Check if this group has Non-remarkable results (same logic as DISEASES table)
if (!empty($LabCategoryPackageResult->Option)) {
if ($LabCategoryPackageResult->Option->IS_NORMAL ?? false) {
$groupNonremarkable = true;
}
}
// If option result exists and is NOT remarkable, skip checking numeric results
if(!empty($resultOption)) {
continue;
}
// Check numeric results only if NOT in a Non-remarkable group
if(!empty($resultValue) && !$groupNonremarkable) {
$minNormal = $LabCategoryPackageResult->Result->MIN_NORMAL ?? null;
$maxNormal = $LabCategoryPackageResult->Result->MAX_NORMAL ?? null;
if($minNormal !== null && $maxNormal !== null && is_numeric($resultValue)) {
$resultValue = (float)$resultValue;
// If value is outside normal range, it's remarkable
if($resultValue < $minNormal || $resultValue > $maxNormal) {
$msmsRemarkable = true;
break 2;
}
}
}
}
}
if($msmsRemarkable) {
$summaryTests['MSMS']['status'] = 'Remarkable';
}
// Check for Hemoglobin Disorders
foreach ($LabCategoryPackageGroups as $LabCategoryPackageGroup) {
foreach ($LabCategoryPackageGroup as $LabCategoryPackageResult) {
if($LabCategoryPackageResult->Result->CODE == 'HEMODIS') {
$HEMODIS = $LabCategoryPackageResult;
if(!empty($HEMODIS->Option->NAME_EN)) {
$summaryTests['HEMODIS']['result'] = $HEMODIS->Option->NAME_EN;
$summaryTests['HEMODIS']['status'] = $HEMODIS->Option->IS_NORMAL ? 'Non-Remarkable' : 'Remarkable';
}
break 2;
}
}
}
@endphp
|
SUMMARY
|
| TEST NAME |
RESULT |
STATUS |
@foreach($summaryTests as $key => $test)
@if($key == 'G6PD' && empty($test['result']))
@continue
@endif
@if($key == 'HEMODIS' && empty($test['result']))
@continue
@endif
|
{{ $test['name'] }}
|
{{ $test['result'] ?? '--' }}
|
{{ $test['status'] }}
|
@endforeach
|
TEST RESULTS
|
| Conditions |
RESULT |
REFERENCE RANGE |
UNIT |
@foreach($withOutGroup as $LabCategoryPackageResult)
@php
$normalColor = '#2e7d32';
$abnormalColor = '#c62828';
$blackColor = '#000;';
@endphp
@if (!empty($LabCategoryPackageResult->Option))
|
{!! $LabCategoryPackageResult->Result->NAME_EN !!}
|
{!! $LabCategoryPackageResult->Option->NAME_EN !!}
|
|
|
@elseif (!empty($LabCategoryPackageResult->MULTIPLE_OPTION_ID))
@php
$ResultOptions = new \App\Models\LABCATEGORYPACKAGERESULTOPTIONS();
$Multiple = explode(",", $LabCategoryPackageResult->MULTIPLE_OPTION_ID);
$Multiple = $ResultOptions->whereIn('ID', $Multiple)->get();
$arr = [];
@endphp
@if (!empty($Multiple))
@foreach ($Multiple as $item)
@php $arr[] = $item->NAME_EN; @endphp
@endforeach
@php $str = implode(", ", $arr); @endphp
|
{!! $LabCategoryPackageResult->Result->NAME_EN !!}
|
{!! $str !!}
|
|
|
@endif
@elseif (!empty($LabCategoryPackageResult->RESULT))
@php
$is_comment = false;
if($LabCategoryPackageResult->Result->NAME_EN == 'Comment') {
$is_comment = true;
$normalColor = $abnormalColor = $blackColor;
}
@endphp
@if($is_comment)
|
Comment: {!! $LabCategoryPackageResult->RESULT !!}
|
@else
|
{!! $LabCategoryPackageResult->Result->NAME_EN !!}
|
@if ($LabCategoryPackageResult->Result->CODE == 'NOP')
@if ($Age > 0.709589)
@php $LabCategoryPackageResult->Result->MAX_NORMAL = 41.9; @endphp
@else
@php $LabCategoryPackageResult->Result->MAX_NORMAL = 109; @endphp
@endif
@endif
@php
$DecimalResult = $LabCategoryPackageResult->RESULT;
$symbol = null;
@endphp
@if (preg_match('/[\'^£$%&*()}{@#~?><>,>=|=_+¬-]/', $DecimalResult))
@if (str_contains($DecimalResult, '>='))
@php $symbol = '>='; @endphp
@elseif (str_contains($DecimalResult, '>'))
@php
$symbol = '>';
$DecimalResult = (float)filter_var($DecimalResult, FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_FRACTION) + 0.01;
@endphp
@elseif (str_contains($DecimalResult, '<='))
@php $symbol = '<='; @endphp
@elseif (str_contains($DecimalResult, '<'))
@php
$symbol = '<';
$DecimalResult = (float)filter_var($DecimalResult, FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_FRACTION) - 0.01;
@endphp
@endif
@endif
{!! $LabCategoryPackageResult->RESULT !!}
|
@if($LabCategoryPackageResult->Result->CODE == 'NTSH')
Hypothyroidism: >40 Questionable: 20-40 Normal: <20
@elseif($LabCategoryPackageResult->Result->CODE == 'G6PD')
Deficient: ≤ 2.7 Normal: > 2.7
@elseif($LabCategoryPackageResult->Result->CODE == 'GALT')
Deficient: ≤ 2.6 Questionable: 2.7-3.4 Normal: > 3.4
@elseif($LabCategoryPackageResult->Result->CODE == 'NBTD')
Deficient: <44 Questionable: 44-49.2 Normal: > 49.2
@elseif($LabCategoryPackageResult->Result->CODE == 'NOP')
@if($LabCategoryPackageResult->Result->MAX_NORMAL == 109)
Normal: <109 Questionable: 109-180 CAH: >180
@else
Normal: <42 Questionable: 42-90 CAH: >90
@endif
@elseif($LabCategoryPackageResult->Result->CODE == 'BTNDASE')
Deficient: <44 Questionable: 44.5-49.2 Normal: > 49.2
@elseif($LabCategoryPackageResult->Result->CODE == 'N17P')
Age > 37 weeks: Normal: <42, Quest: 42-90, CAH: >90 Age < 37 weeks: Normal: <109, Quest: 109-180, CAH: >180
@elseif($LabCategoryPackageResult->Result->TYPE != 'TEXTAREA')
{{ $LabCategoryPackageResult->Result->MIN_NORMAL }} - {{ $LabCategoryPackageResult->Result->MAX_NORMAL }}
@endif
|
@if ($LabCategoryPackageResult->Result->UNIT && $LabCategoryPackageResult->Result->TYPE != 'TEXTAREA')
{!! $LabCategoryPackageResult->Result->UNIT !!}
@endif
|
@endif
@endif
@endforeach
@php
$counter = 0;
@endphp
|
Test Results
|
| Conditions |
RESULT |
REFERENCE RANGE |
UNIT |
@foreach ($LabCategoryPackageGroups as $LabCategoryPackageGroup)
@php
$Nonremarkable = false;
if($counter == 2)
{
$counter = 0;
}
$firstResult = $LabCategoryPackageGroup[0]->Result->DESC_EN;
$fontSize = strlen($firstResult) > 30 ? '10px' : '12px';
$counter++;
@endphp
@foreach ($LabCategoryPackageGroup as $key => $LabCategoryPackageResult)
@if($LabCategoryPackageResult->Result->CODE == 'HEMODIS')
@php
$HEMODIS = $LabCategoryPackageResult;
@endphp
@continue
@endif
@if($LabCategoryPackageResult->Result->CODE == 'UpNormalComm')
@php
$HEMODISComment = $LabCategoryPackageResult;
@endphp
@continue
@endif
@php
$resultName = $LabCategoryPackageResult->Result->NAME_EN;
$resultOption = $LabCategoryPackageResult->Option->NAME_EN ?? null;
$unit = $LabCategoryPackageResult->Result->UNIT ?? '--';
$resultValue = $LabCategoryPackageResult->RESULT;
// Determine text color
if ($LabCategoryPackageResult->Option->IS_NORMAL ?? false) {
$color = '#2e7d32'; // Normal green
$Nonremarkable = true;
} else {
$color = '#c62828'; // Abnormal red
}
@endphp
@if(!empty($resultOption))
|
@if($key == 0)
{{ $firstResult }}
@endif
|
{{ $resultOption }}
|
@if ($key != 0)
{{ $resultName }}
@endif
|
{{ $unit }}
|
@elseif(!empty($LabCategoryPackageResult->MULTIPLE_OPTION_ID))
@php
$Multiple = explode(",", $LabCategoryPackageResult->MULTIPLE_OPTION_ID);
$resultOptions = \App\Models\LABCATEGORYPACKAGERESULTOPTIONS::whereIn('ID', $Multiple)->get();
$optionNames = $resultOptions->pluck('NAME_EN')->toArray();
$optionsString = implode(", ", $optionNames);
@endphp
|
@if ($key != 0)
{{ $resultName }}
@endif
|
@if(str_contains($resultName, 'Recommendation') || str_contains($resultName, 'Additional'))
{{ $optionsString }}
|
@else
{{ $optionsString }}
|
|
{{ $unit }} |
@endif
@elseif(!empty($resultValue) && !$Nonremarkable)
|
@if ($key != 0)
{{ $resultName == 'Comment' ? '* '.$resultName : $resultName }}
@endif
|
@if($resultName == 'Comment')
{{ $resultValue }}
|
@else
{{ $resultValue }}
|
@if($LabCategoryPackageResult->Result->TYPE != 'TEXTAREA')
{{ $LabCategoryPackageResult->Result->MIN_NORMAL . ' - ' . $LabCategoryPackageResult->Result->MAX_NORMAL }}
@endif
|
{{ $unit }}
|
@endif
@elseif(!empty($LabCategoryPackageResult->RESULT) && $Nonremarkable && $LabCategoryPackageResult->Result->TYPE == 'TEXTAREA')
|
@if($key != 0)
{!! e($LabCategoryPackageResult->Result->NAME_EN) !!}
@endif
|
{!! e($LabCategoryPackageResult->RESULT) !!}
|
@else
@continue
@endif
@endforeach
@endforeach
@if(!empty($HEMODIS))
@include('pdf.normal_report.components.analysis_tests.layout.comment')
Sample Type & Methodology
Sample Type:
Dried Blood Spot (DBS) on Special Filter Card
Methodology:
Amino acids, Organic acids, and Fatty acids were screened using the Qsight 210MD Triple Quadrupole LC-MS/MS system (Perkin Elmer) using NeoBase Non-derivatized MSMS kit (Perkin Elmer). TSH, GALT, Biotinidase,G6PD, and 17 OH progesterone were analyzed on VICTOR™2D Fluorometer (Perkin Elmer)@if(!empty($HEMODIS)) & FEIA Fluorometer (LabSystems), and Hemoglobin disorders were screened using Variant nbs (BIO-RAD)@endif.
⚠ Limitations
•
Laboratory findings in this report represent "screening" results and are intended to identify newborns at risk for the screened disorders only and/or in need of more confirmatory testing.
•
This test might not reveal inborn error of metabolism or endocrinal disorders screened for if the newborn is on therapy that keeps the measured markers within the normal reference range. Medical examination is mandatory if any symptoms of such diseases appear.
•
The results are valid only if the sample is collected at least 24 hours after birth and the newborn has not received blood transfusion prior to sample collection.
•
Unremarkable results refer to marker(s) that are measured in the DBS specimen and fall within the normal reference interval, however, results should be clinically correlated with factors such as age, nutrition, birth weight, prematurity, health status, and treatments at the time of DBS sampling.
References
1)
Clinical Laboratory Standard Institute, NBS01-AD7:2021- Blood Collection on Filter paper for Newborn Screening Programs; Approved Standard- Seventh Edition, July 2021.
2)
Clinical Laboratory Standard Institute, NBS04-ED2: 2017, New born screening by Tandem Mass Spectrometry; Approved guidelines, July 2017.
3)
American College of Medical Genetics (ACMG) ACT Sheets and Confirmatory Algorithms.