fix: {{medical}} prints Generic Name instead of Substitute in OPD consult print
Root cause: the fallback lookup from opd_med_master used
$labelField = $masterSaltField ?? $masterGenericField
which preferred salt_name (the Substitute / other brand names field) over
genericname (the actual Generic Name / composition). If a prescription row's
inline genericname was empty, the Substitute string was written into it and
then printed as \"Salt/Generic\" in the {{medical}} block.
Fixes applied in three places:
1. Opd.php buildOpdLetterPrintData - master lookup now prefers genericname
2. Opd.php buildOpdLetterPrintData second loop - removed inline salt_name
fallback that overwrote genericname with Substitute value
3. Opd.php buildLegacyDashboardTemplateVars - removed salt_name from the
generic resolution chain used when rendering the medicine table HTML
4. Opd_prescription.php medicine list function - same preferGenericname fix
and removed inline salt_name -> genericname overwrite"
This commit is contained in:
parent
2958f2e9b6
commit
bca95f14e6
|
|
@ -2253,7 +2253,8 @@ class Opd extends BaseController
|
|||
if ($formulationPrefix !== '' && $name !== '' && preg_match('/^' . preg_quote($formulationPrefix, '/') . '\b/i', $name) !== 1) {
|
||||
$name = trim($formulationPrefix . ' ' . $name);
|
||||
}
|
||||
$generic = trim((string) ($med['genericname'] ?? $med['generic_name'] ?? $med['salt_name'] ?? ''));
|
||||
// salt_name is Substitute (other brand names), not Generic Name — do not use it as generic fallback
|
||||
$generic = trim((string) ($med['genericname'] ?? $med['generic_name'] ?? ''));
|
||||
$dose = trim((string) ($med['dosage_label'] ?? $med['dosage'] ?? $med['drug_dose'] ?? $med['dose'] ?? ''));
|
||||
$freq = trim((string) ($med['dosage_freq_label'] ?? $med['dosage_freq'] ?? $med['drug_freq'] ?? $med['frequency'] ?? ''));
|
||||
$doseLocalRaw = trim((string) ($med['dosage_local_label'] ?? $med['dosage_local'] ?? ''));
|
||||
|
|
@ -3728,7 +3729,8 @@ class Opd extends BaseController
|
|||
$masterGenericField = $this->resolveFirstField($masterFields, ['genericname', 'generic_name']);
|
||||
$masterSaltField = $this->resolveFirstField($masterFields, ['salt_name', 'sal_name', 'salt', 'saltname']);
|
||||
$masterFormulationField = $this->resolveFirstField($masterFields, ['formulation', 'dosage_form', 'form']);
|
||||
$labelField = $masterSaltField ?? $masterGenericField;
|
||||
// Prefer genericname (Generic Name) over salt_name (Substitute) for "Salt/Generic" print label
|
||||
$labelField = $masterGenericField ?? $masterSaltField;
|
||||
$select = [];
|
||||
if ($masterIdField !== null) {
|
||||
$select[] = $masterIdField . ' as med_id';
|
||||
|
|
@ -3763,7 +3765,8 @@ class Opd extends BaseController
|
|||
}
|
||||
|
||||
foreach ($data['rx_medicines'] as &$medRow) {
|
||||
$genericInline = trim((string) ($medRow['genericname'] ?? ($medRow['salt_name'] ?? '')));
|
||||
// Only check genericname — do NOT fall back to salt_name (that is the Substitute field)
|
||||
$genericInline = trim((string) ($medRow['genericname'] ?? ''));
|
||||
if ($genericInline === '') {
|
||||
$fallback = $medGenericMap[(int) ($medRow['med_id'] ?? 0)] ?? '';
|
||||
if ($fallback !== '') {
|
||||
|
|
|
|||
|
|
@ -1652,7 +1652,8 @@ class Opd_prescription extends BaseController
|
|||
$masterIdField = $this->resolveFirstField($masterFields, ['id']);
|
||||
$masterGenericField = $this->resolveFirstField($masterFields, ['genericname', 'generic_name']);
|
||||
$masterSaltField = $this->resolveFirstField($masterFields, ['salt_name', 'sal_name', 'salt', 'saltname']);
|
||||
$labelField = $masterSaltField ?? $masterGenericField;
|
||||
// Prefer genericname (Generic Name) over salt_name (Substitute)
|
||||
$labelField = $masterGenericField ?? $masterSaltField;
|
||||
|
||||
if ($masterIdField !== null && $labelField !== null) {
|
||||
$medRows = $this->db->table($masterTable)
|
||||
|
|
@ -1679,13 +1680,10 @@ class Opd_prescription extends BaseController
|
|||
|
||||
foreach ($rows as &$row) {
|
||||
if (trim((string) ($row['genericname'] ?? '')) === '') {
|
||||
$inlineSalt = trim((string) ($row['salt_name'] ?? ''));
|
||||
if ($inlineSalt !== '') {
|
||||
$row['genericname'] = $inlineSalt;
|
||||
}
|
||||
|
||||
// Do NOT fall back to salt_name — that field stores Substitute (other brand names),
|
||||
// not the generic/salt composition. Use master lookup only.
|
||||
$fallback = $medGenericMap[(int) ($row['med_id'] ?? 0)] ?? '';
|
||||
if (($row['genericname'] ?? '') === '' && $fallback !== '') {
|
||||
if ($fallback !== '') {
|
||||
$row['genericname'] = $fallback;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user