@php $Name = $Package->NAME; $Category = $Package->lABCATEGORYPACKAGE->NAME_EN; $Description = $Package->lABCATEGORYPACKAGE->SMART_DESC_AR; $ProfileID = $Profile->ID; $color=''; $Groups=[]; // Result codes that have a dedicated block below. Anything else falls through // to the generic renderer at the end of the loop instead of being dropped. $HandledCodes = [ 'VISO','SODOR','SAC','HTH','TTT','HTT','MXD','SPRB','SCD','SCA','SPCD','SV','SPH','SLI', 'SAD','SPT','SRT','SPCS','TSC','SCE','SPCM','SPWB','SPCC','SPEC','BACT','GAGG','TAGG', 'TMOT','SHN','SHH','SMPD','SCYD','STAD','SHD','SIF','SGA','SGB','SGC','SGD','SAB','SABC', 'SVIT','SDD', ]; // The reference range exactly as the lab configured it in the manager // (PROFILE_ENABLE_RESULT), copied onto the order row when the test is built. $ConfiguredReference = function ($row) { if (!empty($row->REFERENCE_RANGE_TEXT)) return $row->REFERENCE_RANGE_TEXT; $min = $row->MIN_NORMAL ?? $row->Result->MIN_NORMAL; $max = $row->MAX_NORMAL ?? $row->Result->MAX_NORMAL; if (!is_null($min) && !is_null($max) && $max >= $min) return $min . ' - ' . $max; if (!is_null($min)) return '≥ ' . $min; if (!is_null($max)) return '≤ ' . $max; return '--'; }; // The bounds of that same configured range, so the colour agrees with what is // printed. A range kept only as text ("≤ 30", "2 - 5") has no MIN/MAX on the // row, so the numbers are read from the text. $ConfiguredBounds = function ($row) { $text = trim((string) $row->REFERENCE_RANGE_TEXT); if ($text !== '') { if (preg_match('/^(?:≤|<=?|up to)\s*(-?\d+(?:\.\d+)?)$/iu', $text, $m)) return [null, (float) $m[1]]; if (preg_match('/^(?:≥|>=?)\s*(-?\d+(?:\.\d+)?)$/u', $text, $m)) return [(float) $m[1], null]; if (preg_match('/^(-?\d+(?:\.\d+)?)\s*(?:-|to)\s*(-?\d+(?:\.\d+)?)$/iu', $text, $m)) return [(float) $m[1], (float) $m[2]]; return [null, null]; } return [$row->MIN_NORMAL ?? $row->Result->MIN_NORMAL, $row->MAX_NORMAL ?? $row->Result->MAX_NORMAL]; }; // Profiles whose dedicated blocks below must follow the configured range // instead of the hardcoded wording those blocks were written with. $UseConfiguredReference = in_array($ProfileID, [78,77]); @endphp