From bb448a38ebc6de75645c5993066fdc96fead08a8 Mon Sep 17 00:00:00 2001 From: DevSoftTech Server Date: Fri, 31 Jul 2026 18:07:21 +0530 Subject: [PATCH] fix(discharge-template): stop DIETARY_ADVICE at review section --- app/Controllers/Ipd_discharge.php | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/app/Controllers/Ipd_discharge.php b/app/Controllers/Ipd_discharge.php index fca7a32..78af58c 100644 --- a/app/Controllers/Ipd_discharge.php +++ b/app/Controllers/Ipd_discharge.php @@ -592,7 +592,8 @@ class Ipd_discharge extends BaseController $courseInHospital = $section(['Course in the hospital']); $examOnDischarge = $section(['Examination on Discharge']); $dischargeMedications = $section(['Discharge Medications']); - $dietaryAdvice = $section(['Dietary Advice']); + $dietaryAdvice = $section(['Dietary Advice'], ['Review after', 'Review After']); + $dietaryAdvice = $this->trimDietaryAdviceTail($dietaryAdvice); $drugAllergyAdr = $section(['Drug Allergy / ADR']); $coMorbidities = $section(['Co-Morbidities']); // Extract entire signature table - no end markers (it's the last section) @@ -909,6 +910,21 @@ class Ipd_discharge extends BaseController return $html; } + private function trimDietaryAdviceTail(string $html): string + { + $out = trim($html); + if ($out === '') { + return ''; + } + + // In many legacy cached discharge contents, "Review after ..." and + // a trailing signature box appear immediately after dietary advice + // without a dedicated section marker. Trim that tail from this token. + $out = (string) preg_replace('/Review\s+after[\s\S]*$/iu', '', $out); + + return trim($out); + } + private function normalizeLegacyDischargeTemplate(string $html): string { $out = str_replace(["\r\n", "\r"], "\n", $html);