diff --git a/healthcare/healthcare/doctype/medication/medication.js b/healthcare/healthcare/doctype/medication/medication.js index 46f0f4daef..f7b8a2a522 100644 --- a/healthcare/healthcare/doctype/medication/medication.js +++ b/healthcare/healthcare/doctype/medication/medication.js @@ -13,6 +13,18 @@ frappe.ui.form.on('Medication', { } }; }); + + if (!frm.is_new()) { + frm.add_custom_button( + __("Browse Medication"), + function () { + frappe.route_options = { + medication: frm.doc.name, + }; + frappe.set_route("Tree", "Medication"); + }, + ); + } } }); diff --git a/healthcare/healthcare/doctype/medication/medication.py b/healthcare/healthcare/doctype/medication/medication.py index 264d6ec34a..5f9637afbf 100644 --- a/healthcare/healthcare/doctype/medication/medication.py +++ b/healthcare/healthcare/doctype/medication/medication.py @@ -126,3 +126,43 @@ def change_item_code_from_medication(item_code, doc): rename_doc("Item", doc.item_code, item_code, ignore_permissions=True) frappe.db.set_value("Medication", doc.name, "item_code", item_code) return + + +@frappe.whitelist() +def get_children(parent=None, is_root=False, **filters): + if not parent or parent == "Medication": + frappe.msgprint(_("Please select a Medication")) + return + + if parent: + frappe.form_dict.parent = parent + + if frappe.form_dict.parent: + medication_doc = frappe.get_cached_doc("Medication", frappe.form_dict.parent) + frappe.has_permission("Medication", doc=medication_doc, throw=True) + + medication_items = frappe.get_all( + "Medication Linked Item", + fields=["item as item_code", "rate"], + filters=[["parent", "=", frappe.form_dict.parent]], + order_by="idx", + ) + + item_names = tuple(d.get("item_code") for d in medication_items) + + items = frappe.get_list( + "Item", + fields=["image", "description", "name", "stock_uom", "item_name"], + filters=[["name", "in", item_names]], + ) # to get only required item dicts + + for medication_item in medication_items: + # extend medication_item dict with respective item dict + medication_item.update( + # returns an item dict from items list which matches with item_code + next(item for item in items if item.get("name") == medication_item.get("item_code")) + ) + medication_item.image = frappe.db.escape(medication_item.image) + medication_item.currency = frappe.db.get_single_value("Global Defaults", "default_currency") + + return medication_items diff --git a/healthcare/healthcare/doctype/medication/medication_item_preview.html b/healthcare/healthcare/doctype/medication/medication_item_preview.html new file mode 100644 index 0000000000..967bd772bb --- /dev/null +++ b/healthcare/healthcare/doctype/medication/medication_item_preview.html @@ -0,0 +1,43 @@ +
Class : {{ data.medication_class ? data.medication_class : "" }}
+Strength : {{ data.strength ? data.strength : "" }}
+UOM : {{ data.uom ? data.uom : "" }}
+{{ data.description }}
+Rate: {{ format_currency(data.rate, data.currency) }}
++ {% if data.value && data.value != "Medication" %} + + {{ __("Open Medication {0}", [data.value.bold()]) }} + {% endif %} + {% if data.item_code %} + + {{ __("Open Item {0}", [data.item_code.bold()]) }} + {% endif %} +
+