Rx print: fix dose translation (prefix match + one-time-a-day), consistent 11px Hindi font

This commit is contained in:
DevSoftTech Server 2026-04-01 20:08:00 +05:30
parent caba6dc84b
commit 0d500d82b2
2 changed files with 84 additions and 8 deletions

View File

@ -1862,9 +1862,26 @@ class Opd extends BaseController
$inst = trim(($when !== '' ? $when : '') . ($remark !== '' ? ($when !== '' ? ' | ' : '') . $remark : '')); $inst = trim(($when !== '' ? $when : '') . ($remark !== '' ? ($when !== '' ? ' | ' : '') . $remark : ''));
$doseFreqText = trim($dose . ' ' . $freq); $doseFreqText = trim($dose . ' ' . $freq);
// Hindi for freq/schedule: opd_dose_shed > opd_dose_frequency > generic fallback // Hindi for freq/schedule: opd_dose_shed > opd_dose_frequency > prefix match > generic fallback
$freqKey = strtolower($freq); $freqKey = strtolower($freq);
$doseFreqLocal = $doseShedHindiMap[$freqKey] ?? $doseFreqHindiMap[$freqKey] ?? ''; $doseFreqLocal = $doseShedHindiMap[$freqKey] ?? $doseFreqHindiMap[$freqKey] ?? '';
if ($doseFreqLocal === '') {
// Prefix match: "od (one time a day) daily" should match key "od (one time a day)"
foreach ($doseShedHindiMap as $_k => $_v) {
if ($_k !== '' && (str_starts_with($freqKey, $_k . ' ') || str_starts_with($freqKey, $_k . '('))) {
$doseFreqLocal = $_v;
break;
}
}
}
if ($doseFreqLocal === '') {
foreach ($doseFreqHindiMap as $_k => $_v) {
if ($_k !== '' && str_starts_with($freqKey, $_k . ' ')) {
$doseFreqLocal = $_v;
break;
}
}
}
if ($doseFreqLocal === '' && $doseFreqText !== '') { if ($doseFreqLocal === '' && $doseFreqText !== '') {
$fallback = $this->translateToLocalPatientText($doseFreqText); $fallback = $this->translateToLocalPatientText($doseFreqText);
if (strtolower($fallback) !== strtolower($doseFreqText)) { if (strtolower($fallback) !== strtolower($doseFreqText)) {
@ -1872,9 +1889,17 @@ class Opd extends BaseController
} }
} }
// Hindi for when/timing: opd_dose_when > opd_dose_shed > generic fallback // Hindi for when/timing: opd_dose_when > opd_dose_shed > prefix match > generic fallback
$whenKey = strtolower($when); $whenKey = strtolower($when);
$instLocal = $doseWhenHindiMap[$whenKey] ?? $doseShedHindiMap[$whenKey] ?? ''; $instLocal = $doseWhenHindiMap[$whenKey] ?? $doseShedHindiMap[$whenKey] ?? '';
if ($instLocal === '') {
foreach ($doseWhenHindiMap as $_k => $_v) {
if ($_k !== '' && str_starts_with($whenKey, $_k . ' ')) {
$instLocal = $_v;
break;
}
}
}
if ($instLocal === '' && $when !== '') { if ($instLocal === '' && $when !== '') {
$fallback = $this->translateToLocalPatientText($when); $fallback = $this->translateToLocalPatientText($when);
if (strtolower($fallback) !== strtolower($when)) { if (strtolower($fallback) !== strtolower($when)) {
@ -1884,17 +1909,17 @@ class Opd extends BaseController
$nameHtml = esc($name); $nameHtml = esc($name);
if ($generic !== '') { if ($generic !== '') {
$nameHtml .= '<div style="font-size:10px;color:#444;">Salt/Generic: ' . esc($generic) . '</div>'; $nameHtml .= '<div style="font-size:11px;color:#444;">Salt/Generic: ' . esc($generic) . '</div>';
} }
$medicalHtml .= '<tr>' $medicalHtml .= '<tr>'
. '<td>' . $i . '</td>' . '<td>' . $i . '</td>'
. '<td>' . $nameHtml . '</td>' . '<td>' . $nameHtml . '</td>'
. '<td>' . esc($doseFreqText) . '<td>' . esc($doseFreqText)
. ($doseFreqLocal !== '' ? ('<div style="font-size:10px;color:#444;line-height:1.3;">' . esc($doseFreqLocal) . '</div>') : '') . ($doseFreqLocal !== '' ? ('<div style="font-size:11px;color:#444;line-height:1.4;" lang="hi">' . esc($doseFreqLocal) . '</div>') : '')
. '</td>' . '</td>'
. '<td>' . esc($days) . '</td>' . '<td>' . esc($days) . '</td>'
. '<td>' . esc($inst) . '<td>' . esc($inst)
. ($instLocal !== '' ? ('<div style="font-size:10px;color:#444;line-height:1.3;">' . esc($instLocal) . '</div>') : '') . ($instLocal !== '' ? ('<div style="font-size:11px;color:#444;line-height:1.4;" lang="hi">' . esc($instLocal) . '</div>') : '')
. '</td>' . '</td>'
. '</tr>'; . '</tr>';
} }
@ -2094,11 +2119,36 @@ class Opd extends BaseController
'afternoon' => 'दोपहर', 'afternoon' => 'दोपहर',
'evening' => 'शाम', 'evening' => 'शाम',
'night' => 'रात', 'night' => 'रात',
// Dose schedules (longer phrases first for uksort)
'one time a day' => 'दिन में एक बार',
'two times a day' => 'दिन में दो बार',
'three times a day' => 'दिन में तीन बार',
'four times a day' => 'दिन में चार बार',
'twice a day' => 'दिन में दो बार',
'thrice a day' => 'दिन में तीन बार',
'once daily' => 'दिन में एक बार', 'once daily' => 'दिन में एक बार',
'twice daily' => 'दिन में दो बार', 'twice daily' => 'दिन में दो बार',
'thrice daily' => 'दिन में तीन बार', 'thrice daily' => 'दिन में तीन बार',
'at bed time' => 'सोते समय',
'at sleep' => 'सोते समय',
'at bedtime' => 'सोते समय',
'with food' => 'भोजन के साथ',
'with water' => 'पानी के साथ',
'with milk' => 'दूध के साथ',
'empty stomach' => 'खाली पेट',
'before meal' => 'भोजन से पहले',
'after meal' => 'भोजन के बाद',
'as required' => 'जरूरत पड़ने पर',
'as needed' => 'जरूरत पड़ने पर',
'when required' => 'जरूरत पड़ने पर',
'every 4 hours' => 'हर 4 घंटे',
'every 6 hours' => 'हर 6 घंटे',
'every 8 hours' => 'हर 8 घंटे',
'every 12 hours' => 'हर 12 घंटे',
'daily' => 'रोज', 'daily' => 'रोज',
'weekly' => 'साप्ताहिक', 'weekly' => 'साप्ताहिक',
'monthly' => 'मासिक',
'alternate day' => 'एक दिन छोड़कर',
'for' => 'के लिए', 'for' => 'के लिए',
'days' => 'दिन', 'days' => 'दिन',
'day' => 'दिन', 'day' => 'दिन',

View File

@ -88,6 +88,30 @@ $toLocalText = static function (string $input): string {
} }
$map = [ $map = [
// Dose schedule phrases
'one time a day' => 'दिन में एक बार',
'two times a day' => 'दिन में दो बार',
'three times a day' => 'दिन में तीन बार',
'four times a day' => 'दिन में चार बार',
'twice a day' => 'दिन में दो बार',
'thrice a day' => 'दिन में तीन बार',
'twice daily' => 'दिन में दो बार',
'thrice daily' => 'दिन में तीन बार',
'once daily' => 'दिन में एक बार',
'alternate day' => 'एक दिन छोड़कर',
'every 4 hours' => 'हर 4 घंटे',
'every 6 hours' => 'हर 6 घंटे',
'every 8 hours' => 'हर 8 घंटे',
'every 12 hours' => 'हर 12 घंटे',
'at bed time' => 'सोते समय',
'at bedtime' => 'सोते समय',
'at sleep' => 'सोते समय',
'empty stomach' => 'खाली पेट',
'with food' => 'भोजन के साथ',
'with water' => 'पानी के साथ',
'with milk' => 'दूध के साथ',
'before meal' => 'भोजन से पहले',
'after meal' => 'भोजन के बाद',
'before food' => 'भोजन से पहले', 'before food' => 'भोजन से पहले',
'after food' => 'भोजन के बाद', 'after food' => 'भोजन के बाद',
'after breakfast' => 'नाश्ते के बाद', 'after breakfast' => 'नाश्ते के बाद',
@ -96,14 +120,16 @@ $toLocalText = static function (string $input): string {
'before lunch' => 'दोपहर के भोजन से पहले', 'before lunch' => 'दोपहर के भोजन से पहले',
'after dinner' => 'रात के भोजन के बाद', 'after dinner' => 'रात के भोजन के बाद',
'before dinner' => 'रात के भोजन से पहले', 'before dinner' => 'रात के भोजन से पहले',
'as required' => 'जरूरत पड़ने पर',
'as needed' => 'जरूरत पड़ने पर',
'when required' => 'जरूरत पड़ने पर',
'morning' => 'सुबह', 'morning' => 'सुबह',
'afternoon' => 'दोपहर', 'afternoon' => 'दोपहर',
'evening' => 'शाम', 'evening' => 'शाम',
'night' => 'रात', 'night' => 'रात',
'once daily' => 'दिन में एक बार',
'twice daily' => 'दिन में दो बार',
'thrice daily' => 'दिन में तीन बार',
'daily' => 'रोज', 'daily' => 'रोज',
'weekly' => 'साप्ताहिक',
'monthly' => 'मासिक',
'for' => 'के लिए', 'for' => 'के लिए',
'days' => 'दिन', 'days' => 'दिन',
'day' => 'दिन', 'day' => 'दिन',