Skip to content

Commit

Permalink
fix: Inpatient Medication Order - get from encounter
Browse files Browse the repository at this point in the history
  • Loading branch information
akashkrishna619 committed May 26, 2023
1 parent 871d663 commit f6f2927
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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 = '';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)

0 comments on commit f6f2927

Please sign in to comment.