fix(discharge-template): stop DIETARY_ADVICE at review section

This commit is contained in:
DevSoftTech Server 2026-07-31 18:07:21 +05:30
parent fb7ea94157
commit bb448a38eb

View File

@ -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);