fix(ipd_discharge): enable dual-source medicine loading and full form submit medicine sync
This commit is contained in:
parent
1f8651e3b3
commit
3fddb3ca26
|
|
@ -6204,7 +6204,7 @@ class Ipd_discharge extends BaseController
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($this->request->isAJAX() && in_array($action, ['add_surgery', 'remove_surgery', 'add_procedure', 'remove_procedure', 'add_diagnosis', 'remove_diagnosis', 'add_course', 'remove_course', 'add_drug', 'remove_drug'], true)) {
|
if (($this->request->isAJAX() || $this->request->getPost('ajax_mode') === 'json') && in_array($action, ['add_surgery', 'remove_surgery', 'add_procedure', 'remove_procedure', 'add_diagnosis', 'remove_diagnosis', 'add_course', 'remove_course', 'add_drug', 'remove_drug'], true)) {
|
||||||
$surgeryRows = $this->byIpdRows('ipd_discharge_surgery', ['id', 'surgery_name', 'surgery_date', 'surgery_remark'], 'id ASC', $ipdId);
|
$surgeryRows = $this->byIpdRows('ipd_discharge_surgery', ['id', 'surgery_name', 'surgery_date', 'surgery_remark'], 'id ASC', $ipdId);
|
||||||
$procedureRows = $this->byIpdRows('ipd_discharge_procedure', ['id', 'procedure_name', 'procedure_date', 'procedure_remark'], 'id ASC', $ipdId);
|
$procedureRows = $this->byIpdRows('ipd_discharge_procedure', ['id', 'procedure_name', 'procedure_date', 'procedure_remark'], 'id ASC', $ipdId);
|
||||||
$diagnosisRows = $this->byIpdRows('ipd_discharge_diagnosis', ['id', 'comp_report', 'comp_remark'], 'id ASC', $ipdId);
|
$diagnosisRows = $this->byIpdRows('ipd_discharge_diagnosis', ['id', 'comp_report', 'comp_remark'], 'id ASC', $ipdId);
|
||||||
|
|
@ -6762,9 +6762,6 @@ class Ipd_discharge extends BaseController
|
||||||
}
|
}
|
||||||
|
|
||||||
// DISABLED: Legacy code that re-saved medicines on "Save Discharge Advice" button.
|
// 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') ?? ''));
|
$medicineJson = trim((string) ($this->request->getPost('discharge_medicine_json') ?? ''));
|
||||||
if ($medicineJson !== '') {
|
if ($medicineJson !== '') {
|
||||||
$medicines = json_decode($medicineJson, true);
|
$medicines = json_decode($medicineJson, true);
|
||||||
|
|
@ -6777,40 +6774,46 @@ class Ipd_discharge extends BaseController
|
||||||
if ($legacyTable !== null) {
|
if ($legacyTable !== null) {
|
||||||
foreach ($medicines as $med) {
|
foreach ($medicines as $med) {
|
||||||
$medName = trim((string) ($med['med_name'] ?? ''));
|
$medName = trim((string) ($med['med_name'] ?? ''));
|
||||||
if ($medName === '') {
|
if ($medName === '' || $medName === 'No medicine added') {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
$insert = [
|
$exists = $this->db->table($legacyTable)
|
||||||
'ipd_id' => $ipdId,
|
->where('ipd_id', $ipdId)
|
||||||
'med_id' => 0,
|
->where('med_name', $medName)
|
||||||
'med_name' => $medName,
|
->countAllResults();
|
||||||
'update_by' => $userLabel,
|
|
||||||
];
|
|
||||||
|
|
||||||
$optionalFields = [
|
if ($exists === 0) {
|
||||||
'med_type' => 'med_type',
|
$insert = [
|
||||||
'dosage' => 'dosage',
|
'ipd_id' => $ipdId,
|
||||||
'dosage_when' => 'dosage_when',
|
'med_id' => 0,
|
||||||
'dosage_freq' => 'dosage_freq',
|
'med_name' => $medName,
|
||||||
'no_of_days' => 'no_of_days',
|
'update_by' => $userLabel,
|
||||||
'qty' => 'qty',
|
];
|
||||||
'remark' => 'remark',
|
|
||||||
];
|
|
||||||
|
|
||||||
foreach ($optionalFields as $jsonKey => $colName) {
|
$optionalFields = [
|
||||||
if ($this->db->fieldExists($colName, $legacyTable)) {
|
'med_type' => 'med_type',
|
||||||
$insert[$colName] = trim((string) ($med[$jsonKey] ?? ''));
|
'dosage' => 'dosage',
|
||||||
|
'dosage_when' => 'dosage_when',
|
||||||
|
'dosage_freq' => 'dosage_freq',
|
||||||
|
'no_of_days' => 'no_of_days',
|
||||||
|
'qty' => 'qty',
|
||||||
|
'remark' => 'remark',
|
||||||
|
];
|
||||||
|
|
||||||
|
foreach ($optionalFields as $jsonKey => $colName) {
|
||||||
|
if ($this->db->fieldExists($colName, $legacyTable)) {
|
||||||
|
$insert[$colName] = trim((string) ($med[$jsonKey] ?? ''));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
$this->db->table($legacyTable)->insert($insert);
|
$this->db->table($legacyTable)->insert($insert);
|
||||||
$savedAny = true;
|
$savedAny = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
*/
|
|
||||||
|
|
||||||
// Examination on Admission (General Examination values).
|
// Examination on Admission (General Examination values).
|
||||||
if ($this->tableHasColumns('ipd_discharge_general_exam_col', ['id', 'col_name'])
|
if ($this->tableHasColumns('ipd_discharge_general_exam_col', ['id', 'col_name'])
|
||||||
|
|
|
||||||
|
|
@ -126,7 +126,8 @@ if (! empty($legacyDrugRows)) {
|
||||||
'remark' => (string) ($row['remark'] ?? ''),
|
'remark' => (string) ($row['remark'] ?? ''),
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
} else {
|
}
|
||||||
|
if (! empty($drugRows)) {
|
||||||
foreach ($drugRows as $row) {
|
foreach ($drugRows as $row) {
|
||||||
$medicineRows[] = [
|
$medicineRows[] = [
|
||||||
'id' => (int) ($row['id'] ?? 0),
|
'id' => (int) ($row['id'] ?? 0),
|
||||||
|
|
@ -6880,6 +6881,7 @@ $historyFields = [
|
||||||
resetMedicineFormState();
|
resetMedicineFormState();
|
||||||
$('#discharge_med_name').focus();
|
$('#discharge_med_name').focus();
|
||||||
|
|
||||||
|
serializeDischargeMedicineTable();
|
||||||
setMedicineStatus(editRowId > 0 ? 'Medicine updated successfully.' : 'Medicine saved successfully.', 'success');
|
setMedicineStatus(editRowId > 0 ? 'Medicine updated successfully.' : 'Medicine saved successfully.', 'success');
|
||||||
}).fail(function(xhr, status, error) {
|
}).fail(function(xhr, status, error) {
|
||||||
var responseHtml = xhr && typeof xhr.responseText === 'string' ? xhr.responseText : '';
|
var responseHtml = xhr && typeof xhr.responseText === 'string' ? xhr.responseText : '';
|
||||||
|
|
@ -6891,12 +6893,14 @@ $historyFields = [
|
||||||
initMedicineTools();
|
initMedicineTools();
|
||||||
bindDischargeAjaxSubmit();
|
bindDischargeAjaxSubmit();
|
||||||
syncNavOnScroll();
|
syncNavOnScroll();
|
||||||
|
serializeDischargeMedicineTable();
|
||||||
setMedicineStatus('Medicine saved. Section refreshed from server response.', 'success');
|
setMedicineStatus('Medicine saved. Section refreshed from server response.', 'success');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
setMedicineStatus('Medicine saved successfully.', 'success');
|
serializeDischargeMedicineTable();
|
||||||
|
setMedicineStatus('Medicine added to list. Click Save Discharge Summary to finalize.', 'info');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
@ -6955,6 +6959,7 @@ $historyFields = [
|
||||||
|
|
||||||
function syncEditorValues() {
|
function syncEditorValues() {
|
||||||
syncDischargeComplaintJsonField();
|
syncDischargeComplaintJsonField();
|
||||||
|
serializeDischargeMedicineTable();
|
||||||
|
|
||||||
if (!window.CKEDITOR) {
|
if (!window.CKEDITOR) {
|
||||||
return;
|
return;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user