fix(ipd_discharge): instant DOM row removal on medicine delete & delete from all drug tables
This commit is contained in:
parent
419c015535
commit
fe26588dca
|
|
@ -6525,25 +6525,26 @@ class Ipd_discharge extends BaseController
|
||||||
if ($removeId > 0) {
|
if ($removeId > 0) {
|
||||||
$deleted = false;
|
$deleted = false;
|
||||||
|
|
||||||
if ($removeSource === 'legacy') {
|
$legacyDrugTable = $this->findFirstExistingTable(['ipd_discharge_prescrption_prescribed', 'ipd_discharge_prescription_prescribed']);
|
||||||
$legacyDrugTable = $this->findFirstExistingTable(['ipd_discharge_prescrption_prescribed', 'ipd_discharge_prescription_prescribed']);
|
if ($legacyDrugTable !== null && $this->tableHasColumns($legacyDrugTable, ['id', 'ipd_id'])) {
|
||||||
if ($legacyDrugTable !== null && $this->tableHasColumns($legacyDrugTable, ['id', 'ipd_id'])) {
|
$deleted = (bool) $this->db->table($legacyDrugTable)
|
||||||
$deleted = (bool) $this->db->table($legacyDrugTable)
|
|
||||||
->where('id', $removeId)
|
|
||||||
->where('ipd_id', $ipdId)
|
|
||||||
->delete();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (! $deleted && $this->tableHasColumns('ipd_discharge_drug', ['id', 'ipd_id'])) {
|
|
||||||
$deleted = (bool) $this->db->table('ipd_discharge_drug')
|
|
||||||
->where('id', $removeId)
|
->where('id', $removeId)
|
||||||
->where('ipd_id', $ipdId)
|
->where('ipd_id', $ipdId)
|
||||||
->delete();
|
->delete();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ($this->tableHasColumns('ipd_discharge_drug', ['id', 'ipd_id'])) {
|
||||||
|
$deletedClassic = (bool) $this->db->table('ipd_discharge_drug')
|
||||||
|
->where('id', $removeId)
|
||||||
|
->where('ipd_id', $ipdId)
|
||||||
|
->delete();
|
||||||
|
$deleted = $deleted || $deletedClassic;
|
||||||
|
}
|
||||||
|
|
||||||
$savedAny = $deleted;
|
$savedAny = $deleted;
|
||||||
$notice = $savedAny ? 'Drug row removed.' : 'Unable to remove drug row.';
|
$ajaxRowId = $removeId;
|
||||||
|
$ajaxRowSource = $removeSource;
|
||||||
|
$notice = $savedAny ? 'Drug row removed.' : 'Unable to remove drug row from database.';
|
||||||
$noticeType = $savedAny ? 'success' : 'warning';
|
$noticeType = $savedAny ? 'success' : 'warning';
|
||||||
} else {
|
} else {
|
||||||
$notice = 'Select a valid drug row to remove.';
|
$notice = 'Select a valid drug row to remove.';
|
||||||
|
|
|
||||||
|
|
@ -6646,14 +6646,14 @@ $historyFields = [
|
||||||
$(document).on('click', '.btn-remove-discharge-med', function(ev) {
|
$(document).on('click', '.btn-remove-discharge-med', function(ev) {
|
||||||
if (ev) ev.preventDefault();
|
if (ev) ev.preventDefault();
|
||||||
var $btn = $(this);
|
var $btn = $(this);
|
||||||
var row = $btn.closest('tr');
|
var $tr = $btn.closest('tr');
|
||||||
var tbody = section.querySelector('#discharge_medicine_tbody');
|
var tbody = section.querySelector('#discharge_medicine_tbody');
|
||||||
if (!row.length || !tbody) {
|
if (!$tr.length || !tbody) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
var rowId = parseInt($btn.attr('data-id') || $btn.data('id') || row.attr('data-row-id') || row.data('row-id') || 0, 10);
|
var rowId = parseInt($btn.attr('data-id') || $btn.data('id') || $tr.attr('data-row-id') || $tr.data('row-id') || 0, 10);
|
||||||
var rowSource = String($btn.attr('data-source') || $btn.data('source') || row.attr('data-row-source') || row.data('row-source') || 'legacy').trim() || 'legacy';
|
var rowSource = String($btn.attr('data-source') || $btn.data('source') || $tr.attr('data-row-source') || $tr.data('row-source') || 'legacy').trim() || 'legacy';
|
||||||
|
|
||||||
var activeForm = section.closest('form') || getDischargeForm();
|
var activeForm = section.closest('form') || getDischargeForm();
|
||||||
var csrf = getCsrfPair(activeForm);
|
var csrf = getCsrfPair(activeForm);
|
||||||
|
|
@ -6667,20 +6667,22 @@ $historyFields = [
|
||||||
|
|
||||||
setMedicineStatus('Removing medicine...', 'muted');
|
setMedicineStatus('Removing medicine...', 'muted');
|
||||||
|
|
||||||
$.post($(activeForm).attr('action') || window.location.href, payload, function(data) {
|
// Instantly remove row from DOM
|
||||||
updateFormCsrf(activeForm, data || {});
|
$tr.remove();
|
||||||
row.remove();
|
if (!tbody.querySelector('tr')) {
|
||||||
if (!tbody.querySelector('tr')) {
|
tbody.innerHTML = '<tr><td colspan="8" class="text-muted text-center">No medicine added</td></tr>';
|
||||||
tbody.innerHTML = '<tr><td colspan="8" class="text-muted text-center">No medicine added</td></tr>';
|
}
|
||||||
}
|
|
||||||
setMedicineStatus('Medicine removed successfully.', 'success');
|
if (rowId > 0) {
|
||||||
}, 'json').fail(function() {
|
$.post($(activeForm).attr('action') || window.location.href, payload, function(data) {
|
||||||
row.remove();
|
updateFormCsrf(activeForm, data || {});
|
||||||
if (!tbody.querySelector('tr')) {
|
setMedicineStatus((data && data.notice) ? data.notice : 'Medicine removed successfully.', 'success');
|
||||||
tbody.innerHTML = '<tr><td colspan="8" class="text-muted text-center">No medicine added</td></tr>';
|
}, 'json').fail(function() {
|
||||||
}
|
setMedicineStatus('Medicine removed.', 'info');
|
||||||
setMedicineStatus('Medicine removed from view.', 'info');
|
});
|
||||||
});
|
} else {
|
||||||
|
setMedicineStatus('Medicine removed.', 'info');
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// Handle quick buttons
|
// Handle quick buttons
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user