Fix: Prevent duplicate medicine saves on 'Save Discharge Advice' button
ISSUE: Medicines were being saved twice - once via Add button AJAX, and again when clicking 'Save Discharge Advice' button. ROOT CAUSE: 1. Legacy code in save_main handler (lines 5489-5538) read 'discharge_medicine_json' POST field 2. JavaScript serializeDischargeMedicineTable() collected all medicine table rows into JSON 3. On form submit (Save Discharge Advice), JSON was sent and controller re-inserted all medicines 4. Result: duplicate entries in ipd_discharge_prescrption_prescribed table SOLUTION: - DISABLED controller code that processes discharge_medicine_json in save_main handler - DISABLED JavaScript call to serializeDischargeMedicineTable() on form submit - Medicines now saved ONLY via Add button AJAX (action='add_drug') - Save Discharge Advice button now only saves dietary advice, instructions, review after, etc. TESTING: 1. Add medicines via Add button (saves immediately) 2. Click Save Discharge Advice (does NOT save medicines again) 3. No duplicate entries in database
This commit is contained in:
parent
783ddcbacc
commit
ea07063675
|
|
@ -5479,7 +5479,10 @@ class Ipd_discharge extends BaseController
|
|||
$savedAny = $this->upsertByIpd('ipd_discharge_drug_food_interaction', $ipdId, $legacyData) || $savedAny;
|
||||
}
|
||||
|
||||
// Process discharge medicine JSON (newly added medicines from the form).
|
||||
// DISABLED: Legacy code that re-saved medicines on "Save Discharge Advice" button.
|
||||
// Medicines are now saved immediately via Add button AJAX (action='add_drug').
|
||||
// Keeping this code would create duplicate medicine entries.
|
||||
/*
|
||||
$medicineJson = trim((string) ($this->request->getPost('discharge_medicine_json') ?? ''));
|
||||
if ($medicineJson !== '') {
|
||||
$medicines = json_decode($medicineJson, true);
|
||||
|
|
@ -5490,10 +5493,6 @@ class Ipd_discharge extends BaseController
|
|||
]);
|
||||
|
||||
if ($legacyTable !== null) {
|
||||
// Clear previously added client-side medicines (optional - keeps only DB-saved ones).
|
||||
// Comment out if you want to preserve all medicines.
|
||||
// $this->db->table($legacyTable)->where('ipd_id', $ipdId)->where('med_id', 0)->delete();
|
||||
|
||||
foreach ($medicines as $med) {
|
||||
$medName = trim((string) ($med['med_name'] ?? ''));
|
||||
if ($medName === '') {
|
||||
|
|
@ -5507,7 +5506,6 @@ class Ipd_discharge extends BaseController
|
|||
'update_by' => $userLabel,
|
||||
];
|
||||
|
||||
// Add optional fields if columns exist.
|
||||
$optionalFields = [
|
||||
'med_type' => 'med_type',
|
||||
'dosage' => 'dosage',
|
||||
|
|
@ -5530,6 +5528,7 @@ class Ipd_discharge extends BaseController
|
|||
}
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
// Examination on Admission (General Examination values).
|
||||
if ($this->tableHasColumns('ipd_discharge_general_exam_col', ['id', 'col_name'])
|
||||
|
|
|
|||
|
|
@ -4689,7 +4689,8 @@ $allergyStatusNoKnown = in_array($allergyStatusNormalized, ['no known drug aller
|
|||
form.addEventListener('submit', function(e) {
|
||||
e.preventDefault();
|
||||
syncEditorValues();
|
||||
serializeDischargeMedicineTable();
|
||||
// DISABLED: No longer needed since medicines are saved via AJAX on Add button
|
||||
// serializeDischargeMedicineTable();
|
||||
syncClinicalLabSelection(form);
|
||||
syncCoMorbidityHidden(form);
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user