From 43f465e261a76ac9ed2ce333ccb6442d1fc9717c Mon Sep 17 00:00:00 2001 From: DevSoftTech Server Date: Sat, 4 Jul 2026 14:53:13 +0530 Subject: [PATCH] Fix OPD advice label and Hindi rendering in template output --- app/Controllers/Opd.php | 35 ++++++++++++++++++++++++++++------- 1 file changed, 28 insertions(+), 7 deletions(-) diff --git a/app/Controllers/Opd.php b/app/Controllers/Opd.php index 88c228a..396cbd4 100644 --- a/app/Controllers/Opd.php +++ b/app/Controllers/Opd.php @@ -2931,7 +2931,7 @@ class Opd extends BaseController $rxAdvice = $rxRead($rx, ['advice', 'Advice', 'prescription_advice', 'advice_notes', 'advice_note']); $rxAdviceLocal = ''; - if ($rxAdvice === '' && !empty($data['rx_advices']) && is_array($data['rx_advices'])) { + if (!empty($data['rx_advices']) && is_array($data['rx_advices'])) { $parts = []; $partsLocal = []; foreach ($data['rx_advices'] as $adv) { @@ -2940,14 +2940,19 @@ class Opd extends BaseController $parts[] = $txt; } - $localTxt = trim((string) ($adv['advice_hindi'] ?? ($adv['advice_txt_hindi'] ?? ''))); + $localRaw = (string) ($adv['advice_hindi'] ?? ($adv['advice_txt_hindi'] ?? '')); + $localTxt = trim((string) preg_replace('/\r\n|\r|\n/', "\n", str_replace(['
', '
', '
'], "\n", strip_tags($localRaw)))); if ($localTxt !== '') { $partsLocal[] = $localTxt; } } - $rxAdvice = implode(', ', $parts); + + if ($rxAdvice === '' && !empty($parts)) { + $rxAdvice = implode(', ', array_values(array_unique($parts))); + } + if (!empty($partsLocal)) { - $rxAdviceLocal = implode(' | ', $partsLocal); + $rxAdviceLocal = implode(' | ', array_values(array_unique($partsLocal))); } } @@ -4177,9 +4182,19 @@ class Opd extends BaseController $tokens['InvestigationBlock'] = (string) ($tokens['investigation'] ?? ''); $tokens['RemarksBlock'] = (string) ($tokens['Prescriber_Remarks'] ?? ''); $adviceBlockBody = trim((string) ($tokens['advice'] ?? '')); - $tokens['AdviceBlock'] = $adviceBlockBody !== '' - ? 'Advice : ' . $adviceBlockBody - : ''; + $adviceBlockLocal = trim((string) ($tokens['advice_local'] ?? '')); + if ($adviceBlockBody !== '' || $adviceBlockLocal !== '') { + $adviceBlockLines = []; + if ($adviceBlockBody !== '') { + $adviceBlockLines[] = 'Advice : ' . $adviceBlockBody; + } + if ($adviceBlockLocal !== '') { + $adviceBlockLines[] = 'सलाह : ' . $adviceBlockLocal; + } + $tokens['AdviceBlock'] = implode('
', $adviceBlockLines); + } else { + $tokens['AdviceBlock'] = ''; + } $tokens['NextVisitBlock'] = (string) ($tokens['next_visit'] ?? ''); $tokens['RxTable'] = $medicalHtml; @@ -4393,6 +4408,12 @@ class Opd extends BaseController // Convert generic echo statements that match a known scalar token key. $out = (string) preg_replace('/<\?php\s+echo\s+\$content\s*;?\s*\?>/i', '{{content}}', $out); + // Legacy templates often place {{advice}} on its own line (without label). + // Upgrade only standalone advice placeholders to {{AdviceBlock}} so + // existing templates that already print "Advice: {{advice}}" remain unchanged. + $out = (string) preg_replace('/(^|\n)\s*\{\{\s*advice\s*\}\}\s*(?=\n|$)/i', '$1{{AdviceBlock}}', $out); + $out = (string) preg_replace('/(^|\n)\s*\{\s*advice\s*\}\s*(?=\n|$)/i', '$1{{AdviceBlock}}', $out); + // Remove remaining PHP blocks that cannot be interpreted safely. $out = (string) preg_replace('/<\?(?:php|=)[\s\S]*?\?>/i', '', $out);