diff --git a/healthcare/healthcare/doctype/patient_encounter/patient_encounter.js b/healthcare/healthcare/doctype/patient_encounter/patient_encounter.js index 59cee6984b..ce91f31cc8 100644 --- a/healthcare/healthcare/doctype/patient_encounter/patient_encounter.js +++ b/healthcare/healthcare/doctype/patient_encounter/patient_encounter.js @@ -181,18 +181,14 @@ frappe.ui.form.on('Patient Encounter', { if (frappe.meta.get_docfield('Drug Prescription', 'medication').in_list_view === 1) { frm.set_query('drug_code', 'drug_prescription', function(doc, cdt, cdn) { let row = frappe.get_doc(cdt, cdn); + let filters = { is_stock_item: 1 }; if (row.medication) { - return { - query: 'healthcare.healthcare.doctype.patient_encounter.patient_encounter.get_medications_query', - filters: { name: row.medication } - }; - } else { - return { - filters: { - is_stock_item: 1 - } - }; + filters.medication = row.medication; } + return { + query: 'healthcare.healthcare.doctype.patient_encounter.patient_encounter.get_medications_query', + filters: filters + }; }); } var table_list = ["drug_prescription", "lab_test_prescription", "procedure_prescription", "therapies"] diff --git a/healthcare/healthcare/doctype/patient_encounter/patient_encounter.py b/healthcare/healthcare/doctype/patient_encounter/patient_encounter.py index b701bd70d8..d8facb59e8 100644 --- a/healthcare/healthcare/doctype/patient_encounter/patient_encounter.py +++ b/healthcare/healthcare/doctype/patient_encounter/patient_encounter.py @@ -478,19 +478,24 @@ def create_medication_request(encounter): @frappe.whitelist() @frappe.validate_and_sanitize_search_inputs def get_medications_query(doctype, txt, searchfield, start, page_len, filters): - medication_name = filters.get("name") + medication_name = filters.get("medication") + medication_child = frappe.qb.DocType("Medication Linked Item") medication = frappe.qb.DocType("Medication") item = frappe.qb.DocType("Item") - data = ( + query = ( frappe.qb.select(medication_child.brand, medication_child.manufacturer, medication_child.item) .from_(medication_child) .left_join(medication) .on(medication.name == medication_child.parent) .left_join(item) .on(item.name == medication_child.item) - .where((medication.name == medication_name) & (item.disabled == 0)) - ).run(as_dict=True) + .where(item.disabled == 0) + ) + if medication_name: + query = query.where(medication.name == medication_name) + + data = query.run(as_dict=True) data_list = [] for d in data: display_list = [] @@ -503,9 +508,9 @@ def get_medications_query(doctype, txt, searchfield, start, page_len, filters): default_warehouse = frappe.get_cached_value("Stock Settings", None, "default_warehouse") if default_warehouse: actual_qty = frappe.db.get_value( - "Bin", {"warehouse": default_warehouse, "item_code": d.get("name")}, "actual_qty" + "Bin", {"warehouse": default_warehouse, "item_code": d.get("item")}, "actual_qty" ) - display_list.append("Qty:" + str(actual_qty) if actual_qty else "0") + display_list.append("
Actual Qty : " + (str(actual_qty) if actual_qty else "0")) data_list.append(display_list) res = tuple(tuple(sub) for sub in data_list) return res