diff --git a/healthcare/healthcare/doctype/inpatient_medication_order/inpatient_medication_order.js b/healthcare/healthcare/doctype/inpatient_medication_order/inpatient_medication_order.js index 690e2e7a90..142dbd07be 100644 --- a/healthcare/healthcare/doctype/inpatient_medication_order/inpatient_medication_order.js +++ b/healthcare/healthcare/doctype/inpatient_medication_order/inpatient_medication_order.js @@ -8,6 +8,7 @@ frappe.ui.form.on('Inpatient Medication Order', { } frm.events.show_medication_order_button(frm); + frm.events.show_get_from_encounter_button(frm); frm.set_query('patient', () => { return { @@ -82,6 +83,26 @@ frappe.ui.form.on('Inpatient Medication Order', { }); }, + show_get_from_encounter_button: function(frm) { + frm.fields_dict['medication_orders'].grid.add_custom_button(__('Get From Encounter'), () => { + if (!frm.doc.patient_encounter) { + frappe.throw(__("Please select a Patient Encounter to get from")); + } + frm.call({ + doc: frm.doc, + method: 'get_from_encounter', + args: { + encounter: frm.doc.patient_encounter + }, + freeze: true, + freeze_message: __('Getting From Encounter'), + callback: function() { + frm.refresh_field('medication_orders'); + } + }); + }); + }, + show_progress: function(frm) { let bars = []; let message = ''; diff --git a/healthcare/healthcare/doctype/inpatient_medication_order/inpatient_medication_order.py b/healthcare/healthcare/doctype/inpatient_medication_order/inpatient_medication_order.py index 50e8166856..fb618f5724 100644 --- a/healthcare/healthcare/doctype/inpatient_medication_order/inpatient_medication_order.py +++ b/healthcare/healthcare/doctype/inpatient_medication_order/inpatient_medication_order.py @@ -80,3 +80,11 @@ def add_order_entries(self, order): entry.time = dose.strength_time self.end_date = dates[-1] return + + @frappe.whitelist() + def get_from_encounter(self, encounter): + patient_encounter = frappe.get_doc("Patient Encounter", encounter) + if not patient_encounter.drug_prescription: + return + for drug in patient_encounter.drug_prescription: + self.add_order_entries(drug)