Fix OPD Consult visit completion trigger, medicine formulation normalization, and blank frequency defaults
This commit is contained in:
parent
41b6231548
commit
071dcca953
|
|
@ -2020,15 +2020,8 @@ class Opd extends BaseController
|
|||
}
|
||||
|
||||
$data['print_layout_mode'] = $layoutMode;
|
||||
|
||||
if ($includeContent) {
|
||||
try {
|
||||
$rxCtrl = new \App\Controllers\Opd_prescription();
|
||||
$rxCtrl->finalizeOpdPrescriptionOnPrint($opdId, $sessionId);
|
||||
} catch (\Throwable $e) {
|
||||
log_message('warning', '[opd_lettre_pdf] finalizeOpdPrescriptionOnPrint error: ' . $e->getMessage());
|
||||
}
|
||||
}
|
||||
// OPD Consult Visit finalization and status completion happen exclusively in
|
||||
// Opd_prescription::opd_prescription_print() (Prescription Rx print), never via OPD Head links.
|
||||
|
||||
$isComposedTemplate = $templateKey !== '' && str_starts_with($templateKey, 'compose_');
|
||||
if ($isComposedTemplate) {
|
||||
|
|
|
|||
|
|
@ -733,7 +733,7 @@ class Opd_prescription extends BaseController
|
|||
}
|
||||
}
|
||||
|
||||
$this->markOpdVisitedOnConsultCompletion((int) $opdId);
|
||||
// OPD Consult Visit is marked Done (opd_status = 2) only on Prescription (Rx) print.
|
||||
|
||||
// Queue background SNOMED coding (fail-open — do not block save response)
|
||||
try {
|
||||
|
|
@ -1818,6 +1818,14 @@ class Opd_prescription extends BaseController
|
|||
return $this->response->setJSON(['update' => 0, 'error_text' => 'Rx group not found']);
|
||||
}
|
||||
|
||||
if (! empty($row) && isset($row['formulation'])) {
|
||||
$row['formulation'] = $this->normalizeMedicineFormulation((string) $row['formulation'], (string) ($row['item_name'] ?? $row['med_name'] ?? ''));
|
||||
}
|
||||
foreach (['dosage', 'dosage_when', 'dosage_freq', 'dosage_where'] as $dosageField) {
|
||||
if (! empty($row) && array_key_exists($dosageField, $row)) {
|
||||
$row[$dosageField] = $this->sanitizeMedicineMasterDefaultField((string) ($row[$dosageField] ?? ''), $dosageField);
|
||||
}
|
||||
}
|
||||
return $this->response->setJSON(['update' => 1, 'row' => $row]);
|
||||
}
|
||||
|
||||
|
|
@ -2045,6 +2053,14 @@ class Opd_prescription extends BaseController
|
|||
return $this->response->setJSON(['update' => 0, 'error_text' => 'Rx medicine not found']);
|
||||
}
|
||||
|
||||
if (! empty($row) && isset($row['formulation'])) {
|
||||
$row['formulation'] = $this->normalizeMedicineFormulation((string) $row['formulation'], (string) ($row['item_name'] ?? $row['med_name'] ?? ''));
|
||||
}
|
||||
foreach (['dosage', 'dosage_when', 'dosage_freq', 'dosage_where'] as $dosageField) {
|
||||
if (! empty($row) && array_key_exists($dosageField, $row)) {
|
||||
$row[$dosageField] = $this->sanitizeMedicineMasterDefaultField((string) ($row[$dosageField] ?? ''), $dosageField);
|
||||
}
|
||||
}
|
||||
return $this->response->setJSON(['update' => 1, 'row' => $row]);
|
||||
}
|
||||
|
||||
|
|
@ -2275,6 +2291,12 @@ class Opd_prescription extends BaseController
|
|||
$builder->orLike($saltField, $q);
|
||||
}
|
||||
$rows = $builder->groupEnd()->orderBy($nameField, 'ASC')->limit(30)->get()->getResultArray();
|
||||
foreach ($rows as &$row) {
|
||||
if (isset($row['med_type'])) {
|
||||
$row['med_type'] = $this->normalizeMedicineFormulation((string) $row['med_type'], (string) ($row['med_name'] ?? ''));
|
||||
}
|
||||
}
|
||||
unset($row);
|
||||
|
||||
return $this->response->setJSON(['rows' => $rows]);
|
||||
}
|
||||
|
|
@ -2632,6 +2654,9 @@ class Opd_prescription extends BaseController
|
|||
}
|
||||
|
||||
foreach ($rows as &$row) {
|
||||
if (isset($row['formulation'])) {
|
||||
$row['formulation'] = $this->normalizeMedicineFormulation((string) $row['formulation'], (string) ($row['item_name'] ?? ''));
|
||||
}
|
||||
$generic = trim((string) ($row['genericname'] ?? ''));
|
||||
if ($generic === '') {
|
||||
$salt = trim((string) ($row['salt_name'] ?? ''));
|
||||
|
|
@ -2715,6 +2740,14 @@ class Opd_prescription extends BaseController
|
|||
if (empty($row)) {
|
||||
return $this->response->setJSON(['update' => 0, 'error_text' => 'Medicine not found']);
|
||||
}
|
||||
if (! empty($row) && isset($row['formulation'])) {
|
||||
$row['formulation'] = $this->normalizeMedicineFormulation((string) $row['formulation'], (string) ($row['item_name'] ?? $row['med_name'] ?? ''));
|
||||
}
|
||||
foreach (['dosage', 'dosage_when', 'dosage_freq', 'dosage_where'] as $dosageField) {
|
||||
if (! empty($row) && array_key_exists($dosageField, $row)) {
|
||||
$row[$dosageField] = $this->sanitizeMedicineMasterDefaultField((string) ($row[$dosageField] ?? ''), $dosageField);
|
||||
}
|
||||
}
|
||||
return $this->response->setJSON(['update' => 1, 'row' => $row]);
|
||||
}
|
||||
|
||||
|
|
@ -2808,7 +2841,7 @@ class Opd_prescription extends BaseController
|
|||
|
||||
$id = (int) $this->request->getPost('id');
|
||||
$itemName = trim((string) $this->request->getPost('item_name'));
|
||||
$formulation = trim((string) $this->request->getPost('formulation'));
|
||||
$formulation = $this->normalizeMedicineFormulation(trim((string) $this->request->getPost('formulation')), $itemName);
|
||||
if ($itemName === '') {
|
||||
return $this->response->setJSON(['update' => 0, 'error_text' => 'Medicine name is required']);
|
||||
}
|
||||
|
|
@ -2861,7 +2894,11 @@ class Opd_prescription extends BaseController
|
|||
|
||||
foreach (['dosage', 'dosage_when', 'dosage_freq', 'dosage_where', 'no_of_days', 'qty', 'remark'] as $dosageField) {
|
||||
if (in_array($dosageField, $fields, true)) {
|
||||
$data[$dosageField] = trim((string) $this->request->getPost($dosageField));
|
||||
$val = trim((string) $this->request->getPost($dosageField));
|
||||
if (in_array($dosageField, ['dosage', 'dosage_when', 'dosage_freq', 'dosage_where'], true)) {
|
||||
$val = $this->sanitizeMedicineMasterDefaultField($val, $dosageField);
|
||||
}
|
||||
$data[$dosageField] = $val;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -3496,6 +3533,14 @@ class Opd_prescription extends BaseController
|
|||
return $this->response->setJSON(['update' => 0, 'error_text' => 'Advice not found']);
|
||||
}
|
||||
|
||||
if (! empty($row) && isset($row['formulation'])) {
|
||||
$row['formulation'] = $this->normalizeMedicineFormulation((string) $row['formulation'], (string) ($row['item_name'] ?? $row['med_name'] ?? ''));
|
||||
}
|
||||
foreach (['dosage', 'dosage_when', 'dosage_freq', 'dosage_where'] as $dosageField) {
|
||||
if (! empty($row) && array_key_exists($dosageField, $row)) {
|
||||
$row[$dosageField] = $this->sanitizeMedicineMasterDefaultField((string) ($row[$dosageField] ?? ''), $dosageField);
|
||||
}
|
||||
}
|
||||
return $this->response->setJSON(['update' => 1, 'row' => $row]);
|
||||
}
|
||||
|
||||
|
|
@ -8393,7 +8438,7 @@ class Opd_prescription extends BaseController
|
|||
}
|
||||
|
||||
$userId = (int) ($this->getCurrentUserId() ?? 0);
|
||||
$cacheKey = 'medicine_search_v4_' . md5(json_encode([
|
||||
$cacheKey = 'medicine_search_v6_' . md5(json_encode([
|
||||
'q' => strtoupper($q),
|
||||
'scope' => $scope,
|
||||
'user' => $userId,
|
||||
|
|
@ -8468,6 +8513,14 @@ class Opd_prescription extends BaseController
|
|||
foreach ($rows as &$row) {
|
||||
$medId = (int) ($row['id'] ?? 0);
|
||||
$name = trim((string) ($row['med_name'] ?? ''));
|
||||
if (array_key_exists('med_type', $row)) {
|
||||
$row['med_type'] = $this->normalizeMedicineFormulation((string) ($row['med_type'] ?? ''), $name);
|
||||
}
|
||||
foreach (['dosage', 'dosage_when', 'dosage_freq', 'dosage_where'] as $dosageField) {
|
||||
if (array_key_exists($dosageField, $row)) {
|
||||
$row[$dosageField] = $this->sanitizeMedicineMasterDefaultField((string) ($row[$dosageField] ?? ''), $dosageField);
|
||||
}
|
||||
}
|
||||
$nameUpper = strtoupper($name);
|
||||
$nameLoose = trim((string) (preg_replace('/[^A-Z0-9]+/', ' ', $nameUpper) ?? $nameUpper));
|
||||
$nameNormalized = trim((string) (preg_replace('/[^A-Z0-9]+/', '', $nameUpper) ?? $nameUpper));
|
||||
|
|
@ -8706,9 +8759,136 @@ class Opd_prescription extends BaseController
|
|||
}
|
||||
|
||||
$rows = $builder->orderBy($nameField, 'ASC')->limit(25)->get()->getResultArray();
|
||||
foreach ($rows as &$row) {
|
||||
if (isset($row['med_type'])) {
|
||||
$row['med_type'] = $this->normalizeMedicineFormulation((string) $row['med_type'], (string) ($row['med_name'] ?? ''));
|
||||
}
|
||||
}
|
||||
unset($row);
|
||||
return $this->response->setJSON(['rows' => $rows]);
|
||||
}
|
||||
|
||||
private function sanitizeMedicineMasterDefaultField(string $raw, string $field = ''): string
|
||||
{
|
||||
$val = trim($raw);
|
||||
if ($val === '' || preg_match('/^\d+$/', $val) === 1) {
|
||||
return '';
|
||||
}
|
||||
|
||||
if ($field === 'dosage_freq') {
|
||||
$upper = strtoupper($val);
|
||||
$freqMap = [
|
||||
'0D' => 'OD',
|
||||
'OD (ONCE DAILY)' => 'OD',
|
||||
'BD (TWICE DAILY)' => 'BD',
|
||||
'TDS (THRICE DAILY)' => 'TDS',
|
||||
'QID (4 TIMES/DAY)' => 'QID',
|
||||
];
|
||||
if (isset($freqMap[$upper])) {
|
||||
return $freqMap[$upper];
|
||||
}
|
||||
}
|
||||
|
||||
return $val;
|
||||
}
|
||||
|
||||
private function normalizeMedicineFormulation(string $raw, string $medName = ''): string
|
||||
{
|
||||
$form = strtoupper(trim($raw));
|
||||
if ($form !== '' && preg_match('/^\d+$/', $form) === 1) {
|
||||
$form = '';
|
||||
}
|
||||
|
||||
$map = [
|
||||
'TABLETS' => 'TAB',
|
||||
'TABLET' => 'TAB',
|
||||
'TABS' => 'TAB',
|
||||
'TA' => 'TAB',
|
||||
'1 TAB' => 'TAB',
|
||||
'CAPSULES' => 'CAP',
|
||||
'CAPSULE' => 'CAP',
|
||||
'CAPS' => 'CAP',
|
||||
'SYRUP' => 'SYR',
|
||||
'SYRUPS' => 'SYR',
|
||||
'SYP' => 'SYR',
|
||||
'INJECTIONS' => 'INJ',
|
||||
'INJECTION' => 'INJ',
|
||||
'1 AMP' => 'INJ',
|
||||
'AMP' => 'INJ',
|
||||
'AMPOULE' => 'INJ',
|
||||
'VIAL' => 'INJ',
|
||||
'IV' => 'INJ',
|
||||
'IM' => 'INJ',
|
||||
'I V FLUD' => 'IV FLUID',
|
||||
'IV FLUIDS' => 'IV FLUID',
|
||||
'I V FLUD IN 24 HRS' => 'IV FLUID',
|
||||
'INFUSION' => 'IV FLUID',
|
||||
'IV INFUSION' => 'IV FLUID',
|
||||
'OINTMENT' => 'OINT',
|
||||
'OINTMENTS' => 'OINT',
|
||||
'CREAMS' => 'CREAM',
|
||||
'GELS' => 'GEL',
|
||||
'JELLY' => 'GEL',
|
||||
'EYE DROPS' => 'EYE DROP',
|
||||
'EAR DROPS' => 'EAR DROP',
|
||||
'NASAL DROPS' => 'NASAL DROP',
|
||||
'NASAL SPRAYS' => 'NASAL SPRAY',
|
||||
'DROPS (PAEDIATRIC)' => 'DROPS',
|
||||
'ORAL DROPS' => 'DROPS',
|
||||
'DROP' => 'DROPS',
|
||||
'POWDERS' => 'POWDER',
|
||||
'ORAL POWDER' => 'POWDER',
|
||||
'LOTIONS' => 'LOTION',
|
||||
'SPRAYS' => 'SPRAY',
|
||||
'PATCHES' => 'PATCH',
|
||||
'SACHETS' => 'SACHET',
|
||||
'1 SACHET' => 'SACHET',
|
||||
'GRANULES' => 'SACHET',
|
||||
'LOZENGES' => 'LOZENGE',
|
||||
'TROCHE' => 'LOZENGE',
|
||||
'SUSPENSION' => 'SUSP',
|
||||
'SUSPENSIONS' => 'SUSP',
|
||||
'SOLUTION' => 'SOLN',
|
||||
'SOLUTIONS' => 'SOLN',
|
||||
'ORAL SOLUTION' => 'SOLN',
|
||||
'SHAMPOOS' => 'SHAMPOO',
|
||||
'SOAPS' => 'SOAP',
|
||||
'SOAP BAR' => 'SOAP',
|
||||
'OILS' => 'OIL',
|
||||
'INHALERS' => 'INHALER',
|
||||
'ROTACAP' => 'INHALER',
|
||||
'ROTACAPS' => 'INHALER',
|
||||
'INHALTION' => 'INHALER',
|
||||
'INHALATION' => 'INHALER',
|
||||
'MDI' => 'INHALER',
|
||||
'RESPULE' => 'RESPULES',
|
||||
'NEBULISER' => 'RESPULES',
|
||||
'NEBULIZER' => 'RESPULES',
|
||||
'MOUTHWASH' => 'GARGLE',
|
||||
'MOUTH WASH' => 'GARGLE',
|
||||
'GARGLES' => 'GARGLE',
|
||||
'SUPPOSITORIES' => 'SUPPOSITORY',
|
||||
'PESSARIES' => 'PESSARY',
|
||||
'VAGINAL PESSARY' => 'PESSARY',
|
||||
'VAGINAL TAB' => 'PESSARY',
|
||||
'VAGINAL TABLET' => 'PESSARY',
|
||||
];
|
||||
|
||||
if ($form !== '' && isset($map[$form])) {
|
||||
return $map[$form];
|
||||
}
|
||||
|
||||
if ($form === '' && $medName !== '') {
|
||||
$upperName = strtoupper(trim($medName));
|
||||
if (preg_match('/\((SYRUPS?|SYR|SYP|TABLETS?|TABS?|CAPSULES?|CAPS?|INJECTIONS?|INJ|DROPS?|OINTMENTS?|OINT|CREAMS?|GELS?|SUSPENSIONS?|SUSP|SOLUTIONS?|SOLN|LOTIONS?|POWDERS?|SACHETS?|INHALERS?|RESPULES?)\)/i', $upperName, $m)) {
|
||||
$extracted = strtoupper($m[1]);
|
||||
return $map[$extracted] ?? $extracted;
|
||||
}
|
||||
}
|
||||
|
||||
return $form;
|
||||
}
|
||||
|
||||
public function medicine_favorite_toggle()
|
||||
{
|
||||
if (! $this->request->isAJAX()) {
|
||||
|
|
|
|||
|
|
@ -365,14 +365,14 @@
|
|||
if (desc && desc.toLowerCase() !== label.toLowerCase()) {
|
||||
text += ' - ' + desc;
|
||||
}
|
||||
html += '<option value="' + $('<div>').text(id).html() + '">' + $('<div>').text(text).html() + '</option>';
|
||||
html += '<option value="' + $('<div>').text(label).html() + '">' + $('<div>').text(text).html() + '</option>';
|
||||
});
|
||||
$select.html(html);
|
||||
}
|
||||
|
||||
function ensureDefaultMasterOption($select, value) {
|
||||
value = (value || '').toString().trim();
|
||||
if (!value || value === '0') {
|
||||
if (!value || /^\d+$/.test(value)) {
|
||||
return;
|
||||
}
|
||||
var safeValue = value.replace(/"/g, '"');
|
||||
|
|
@ -384,7 +384,7 @@
|
|||
|
||||
function setDefaultMasterValue($select, value) {
|
||||
var raw = (value || '').toString().trim();
|
||||
if (!raw || raw === '0') {
|
||||
if (!raw || /^\d+$/.test(raw)) {
|
||||
$select.val('');
|
||||
return;
|
||||
}
|
||||
|
|
@ -483,25 +483,29 @@
|
|||
$('#med_id').val(row.id || 0);
|
||||
$('#med_item_name').val(row.item_name || '');
|
||||
var rawForm = (row.formulation || '').toString().trim().toUpperCase();
|
||||
if (rawForm === 'TABLETS' || rawForm === 'TABLET' || rawForm === 'TABS') {
|
||||
if (rawForm === 'TABLETS' || rawForm === 'TABLET' || rawForm === 'TABS' || rawForm === 'TA' || rawForm === '1 TAB') {
|
||||
rawForm = 'TAB';
|
||||
} else if (rawForm === 'CAPSULES' || rawForm === 'CAPSULE' || rawForm === 'CAPS') {
|
||||
rawForm = 'CAP';
|
||||
} else if (rawForm === 'SYRUP' || rawForm === 'SYRUPS') {
|
||||
} else if (rawForm === 'SYRUP' || rawForm === 'SYRUPS' || rawForm === 'SYP') {
|
||||
rawForm = 'SYR';
|
||||
} else if (rawForm === 'INJECTIONS' || rawForm === 'INJECTION') {
|
||||
} else if (rawForm === 'INJECTIONS' || rawForm === 'INJECTION' || rawForm === '1 AMP' || rawForm === 'AMP' || rawForm === 'AMPOULE' || rawForm === 'VIAL' || rawForm === 'IV' || rawForm === 'IM') {
|
||||
rawForm = 'INJ';
|
||||
} else if (rawForm === 'I V FLUD' || rawForm === 'IV FLUIDS' || rawForm === 'I V FLUD IN 24 HRS' || rawForm === 'INFUSION' || rawForm === 'IV INFUSION') {
|
||||
rawForm = 'IV FLUID';
|
||||
} else if (rawForm === 'OINTMENT' || rawForm === 'OINTMENTS') {
|
||||
rawForm = 'OINT';
|
||||
} else if (rawForm === 'CREAMS') {
|
||||
rawForm = 'CREAM';
|
||||
} else if (rawForm === 'GELS') {
|
||||
} else if (rawForm === 'GELS' || rawForm === 'JELLY') {
|
||||
rawForm = 'GEL';
|
||||
} else if (rawForm === 'EYE DROPS') {
|
||||
rawForm = 'EYE DROP';
|
||||
} else if (rawForm === 'EAR DROPS') {
|
||||
rawForm = 'EAR DROP';
|
||||
} else if (rawForm === 'POWDERS') {
|
||||
} else if (rawForm === 'DROPS (PAEDIATRIC)' || rawForm === 'ORAL DROPS' || rawForm === 'DROP') {
|
||||
rawForm = 'DROPS';
|
||||
} else if (rawForm === 'POWDERS' || rawForm === 'ORAL POWDER') {
|
||||
rawForm = 'POWDER';
|
||||
} else if (rawForm === 'LOTIONS') {
|
||||
rawForm = 'LOTION';
|
||||
|
|
@ -509,11 +513,11 @@
|
|||
rawForm = 'SPRAY';
|
||||
} else if (rawForm === 'PATCHES') {
|
||||
rawForm = 'PATCH';
|
||||
} else if (rawForm === 'SACHETS') {
|
||||
} else if (rawForm === 'SACHETS' || rawForm === '1 SACHET' || rawForm === 'GRANULES') {
|
||||
rawForm = 'SACHET';
|
||||
} else if (rawForm === 'SUSPENSION' || rawForm === 'SUSPENSIONS') {
|
||||
rawForm = 'SUSP';
|
||||
} else if (rawForm === 'SOLUTION' || rawForm === 'SOLUTIONS') {
|
||||
} else if (rawForm === 'SOLUTION' || rawForm === 'SOLUTIONS' || rawForm === 'ORAL SOLUTION') {
|
||||
rawForm = 'SOLN';
|
||||
} else if (rawForm === 'SHAMPOOS') {
|
||||
rawForm = 'SHAMPOO';
|
||||
|
|
@ -521,13 +525,15 @@
|
|||
rawForm = 'SOAP';
|
||||
} else if (rawForm === 'OILS') {
|
||||
rawForm = 'OIL';
|
||||
} else if (rawForm === 'INHALERS') {
|
||||
} else if (rawForm === 'INHALERS' || rawForm === 'ROTACAP' || rawForm === 'ROTACAPS' || rawForm === 'INHALTION' || rawForm === 'INHALATION' || rawForm === 'MDI') {
|
||||
rawForm = 'INHALER';
|
||||
} else if (rawForm === 'RESPULE' || rawForm === 'NEBULISER' || rawForm === 'NEBULIZER') {
|
||||
rawForm = 'RESPULES';
|
||||
} else if (rawForm === 'MOUTHWASH' || rawForm === 'MOUTH WASH' || rawForm === 'GARGLES') {
|
||||
rawForm = 'GARGLE';
|
||||
} else if (rawForm === 'SUPPOSITORIES') {
|
||||
rawForm = 'SUPPOSITORY';
|
||||
} else if (rawForm === 'PESSARIES') {
|
||||
} else if (rawForm === 'PESSARIES' || rawForm === 'VAGINAL PESSARY' || rawForm === 'VAGINAL TAB' || rawForm === 'VAGINAL TABLET') {
|
||||
rawForm = 'PESSARY';
|
||||
}
|
||||
if (rawForm && !$('#med_formulation option[value="' + rawForm.replace(/"/g, '"') + '"]').length) {
|
||||
|
|
|
|||
|
|
@ -1870,7 +1870,7 @@
|
|||
var medicineSuggestRows = [];
|
||||
var medicineSearchCache = {};
|
||||
var medicineSearchCacheTtlMs = 120000;
|
||||
var medicineSearchLocalDbKey = 'opd_medicine_search_cache_v1';
|
||||
var medicineSearchLocalDbKey = 'opd_medicine_search_cache_v3';
|
||||
var medicineSearchCacheMaxEntries = 250;
|
||||
var medicineSearchLocalDbReady = false;
|
||||
var autotypeSuggestCache = {};
|
||||
|
|
@ -8948,11 +8948,75 @@
|
|||
}
|
||||
}
|
||||
|
||||
function normalizeMedFormType(raw, medName) {
|
||||
var rawForm = (raw || '').toString().trim().toUpperCase();
|
||||
if (rawForm && /^\d+$/.test(rawForm)) {
|
||||
rawForm = '';
|
||||
}
|
||||
var map = {
|
||||
'TABLETS': 'TAB', 'TABLET': 'TAB', 'TABS': 'TAB', 'TA': 'TAB', '1 TAB': 'TAB',
|
||||
'CAPSULES': 'CAP', 'CAPSULE': 'CAP', 'CAPS': 'CAP',
|
||||
'SYRUP': 'SYR', 'SYRUPS': 'SYR', 'SYP': 'SYR',
|
||||
'INJECTIONS': 'INJ', 'INJECTION': 'INJ', '1 AMP': 'INJ', 'AMP': 'INJ', 'AMPOULE': 'INJ', 'VIAL': 'INJ', 'IV': 'INJ', 'IM': 'INJ',
|
||||
'I V FLUD': 'IV FLUID', 'IV FLUIDS': 'IV FLUID', 'I V FLUD IN 24 HRS': 'IV FLUID', 'INFUSION': 'IV FLUID', 'IV INFUSION': 'IV FLUID',
|
||||
'OINTMENT': 'OINT', 'OINTMENTS': 'OINT',
|
||||
'CREAMS': 'CREAM',
|
||||
'GELS': 'GEL', 'JELLY': 'GEL',
|
||||
'EYE DROPS': 'EYE DROP',
|
||||
'EAR DROPS': 'EAR DROP',
|
||||
'NASAL DROPS': 'NASAL DROP',
|
||||
'NASAL SPRAYS': 'NASAL SPRAY',
|
||||
'DROPS (PAEDIATRIC)': 'DROPS', 'ORAL DROPS': 'DROPS', 'DROP': 'DROPS',
|
||||
'POWDERS': 'POWDER', 'ORAL POWDER': 'POWDER',
|
||||
'LOTIONS': 'LOTION',
|
||||
'SPRAYS': 'SPRAY',
|
||||
'PATCHES': 'PATCH',
|
||||
'SACHETS': 'SACHET', '1 SACHET': 'SACHET', 'GRANULES': 'SACHET',
|
||||
'LOZENGES': 'LOZENGE', 'TROCHE': 'LOZENGE',
|
||||
'SUSPENSION': 'SUSP', 'SUSPENSIONS': 'SUSP',
|
||||
'SOLUTION': 'SOLN', 'SOLUTIONS': 'SOLN', 'ORAL SOLUTION': 'SOLN',
|
||||
'SHAMPOOS': 'SHAMPOO',
|
||||
'SOAPS': 'SOAP', 'SOAP BAR': 'SOAP',
|
||||
'OILS': 'OIL',
|
||||
'INHALERS': 'INHALER', 'ROTACAP': 'INHALER', 'ROTACAPS': 'INHALER', 'INHALTION': 'INHALER', 'INHALATION': 'INHALER', 'MDI': 'INHALER',
|
||||
'RESPULE': 'RESPULES', 'NEBULISER': 'RESPULES', 'NEBULIZER': 'RESPULES',
|
||||
'MOUTHWASH': 'GARGLE', 'MOUTH WASH': 'GARGLE', 'GARGLES': 'GARGLE',
|
||||
'SUPPOSITORIES': 'SUPPOSITORY',
|
||||
'PESSARIES': 'PESSARY', 'VAGINAL PESSARY': 'PESSARY', 'VAGINAL TAB': 'PESSARY', 'VAGINAL TABLET': 'PESSARY'
|
||||
};
|
||||
if (rawForm && map[rawForm]) {
|
||||
return map[rawForm];
|
||||
}
|
||||
if (!rawForm && medName) {
|
||||
var m = (medName || '').toString().trim().toUpperCase().match(/\((SYRUPS?|SYR|SYP|TABLETS?|TABS?|CAPSULES?|CAPS?|INJECTIONS?|INJ|DROPS?|OINTMENTS?|OINT|CREAMS?|GELS?|SUSPENSIONS?|SUSP|SOLUTIONS?|SOLN|LOTIONS?|POWDERS?|SACHETS?|INHALERS?|RESPULES?)\)/i);
|
||||
if (m && m[1]) {
|
||||
var ext = m[1].toUpperCase();
|
||||
return map[ext] || ext;
|
||||
}
|
||||
}
|
||||
return rawForm;
|
||||
}
|
||||
|
||||
function setMedTypeSelectValue($select, raw, medName) {
|
||||
if (!$select || !$select.length) return '';
|
||||
var norm = normalizeMedFormType(raw, medName);
|
||||
if (!norm) {
|
||||
$select.val('');
|
||||
return '';
|
||||
}
|
||||
var safeVal = norm.replace(/"/g, '"');
|
||||
if (!$select.find('option[value="' + safeVal + '"]').length) {
|
||||
$select.append('<option value="' + $('<div>').text(norm).html() + '">' + $('<div>').text(norm).html() + '</option>');
|
||||
}
|
||||
$select.val(norm);
|
||||
return norm;
|
||||
}
|
||||
|
||||
function setMedicineEditMode(row) {
|
||||
$('#med_item_id').val(row.id || 0);
|
||||
$('#med_name').val(row.name || '');
|
||||
$('#med_name').removeData('med-id');
|
||||
$('#med_type').val(row.type || '');
|
||||
setMedTypeSelectValue($('#med_type'), row.type || '', row.name || '');
|
||||
ensureMedicineMasterOption($('#med_dosage'), row.dose || '');
|
||||
ensureMedicineMasterOption($('#med_when'), row.when || '');
|
||||
ensureMedicineMasterOption($('#med_freq_master'), row.freq || '');
|
||||
|
|
@ -9731,7 +9795,7 @@
|
|||
function applyMedicineSelection(rowData) {
|
||||
var medName = (rowData.med_name || '').toString().trim();
|
||||
if (medName) { $('#med_name').val(medName); }
|
||||
$('#med_type').val((rowData.med_type || '').toString());
|
||||
var resolvedMedType = setMedTypeSelectValue($('#med_type'), (rowData.med_type || '').toString(), medName);
|
||||
|
||||
var dosage = (rowData.dosage || '').toString().trim();
|
||||
var whenValue = (rowData.dosage_when || '').toString().trim();
|
||||
|
|
@ -9740,6 +9804,10 @@
|
|||
var daysValue = (rowData.no_of_days || '').toString().trim();
|
||||
var qtyValue = (rowData.qty || '').toString().trim();
|
||||
var remarkValue = (rowData.remark || '').toString().trim();
|
||||
if (/^\d+$/.test(dosage)) { dosage = ''; }
|
||||
if (/^\d+$/.test(whenValue)) { whenValue = ''; }
|
||||
if (/^\d+$/.test(freqValue)) { freqValue = ''; }
|
||||
if (/^\d+$/.test(whereValue)) { whereValue = ''; }
|
||||
|
||||
if (dosage) {
|
||||
ensureMedicineMasterOption($('#med_dosage'), dosage);
|
||||
|
|
@ -9764,7 +9832,7 @@
|
|||
$('#med_where').val(whereValue).trigger('change');
|
||||
} else {
|
||||
$('#med_where').val('').trigger('change');
|
||||
autoSelectDefaultRoute(rowData.med_type || $('#med_type').val(), $('#med_where'));
|
||||
autoSelectDefaultRoute(resolvedMedType || rowData.med_type || $('#med_type').val(), $('#med_where'));
|
||||
}
|
||||
if (daysValue) {
|
||||
$('#med_days').val(daysValue);
|
||||
|
|
@ -9987,7 +10055,7 @@
|
|||
if (matchedRow) {
|
||||
$('#med_name').data('med-id', parseInt(matchedRow.id || 0, 10));
|
||||
if (!($('#med_type').val() || '').trim()) {
|
||||
$('#med_type').val((matchedRow.med_type || '').toString());
|
||||
setMedTypeSelectValue($('#med_type'), (matchedRow.med_type || '').toString(), medName);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -10129,7 +10197,7 @@
|
|||
|
||||
$('#med_name').val(medName).data('med-id', medId).trigger('change');
|
||||
if (!($('#med_type').val() || '').trim()) {
|
||||
$('#med_type').val(medType);
|
||||
setMedTypeSelectValue($('#med_type'), medType, medName);
|
||||
}
|
||||
});
|
||||
|
||||
|
|
@ -10187,7 +10255,7 @@
|
|||
|
||||
$('#med_name').val(medName).data('med-id', medId).trigger('change');
|
||||
if (medType) {
|
||||
$('#med_type').val(medType);
|
||||
medType = setMedTypeSelectValue($('#med_type'), medType, medName);
|
||||
}
|
||||
|
||||
$btn.prop('disabled', true).text('Adding...');
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user