Skip to content

Commit

Permalink
fix(Patient Encounter): show items actual qty in drug prescription
Browse files Browse the repository at this point in the history
(cherry picked from commit ac19668)
  • Loading branch information
Sajinsr committed Sep 23, 2024
1 parent dfa46b1 commit d4fb716
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 = []
Expand All @@ -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("<br>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
Expand Down

0 comments on commit d4fb716

Please sign in to comment.