Skip to content

Commit

Permalink
fix(Patient Encounter): set medication in drug prescription if Medica…
Browse files Browse the repository at this point in the history
…tion is already created

change tests - Medication, Service Request
change Patient Encounter drug_prescription filter
  • Loading branch information
akashkrishna619 committed Feb 16, 2024
1 parent d04c086 commit b2dfea8
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@

import frappe

from erpnext.stock.doctype.item.test_item import create_item

from healthcare.healthcare.doctype.patient_appointment.test_patient_appointment import (
create_healthcare_docs,
)
Expand All @@ -20,7 +22,7 @@ def setup(self):

def test_medication_request(self):
patient, practitioner = create_healthcare_docs()
medication = create_medcation()
medication = create_medication()
encounter = create_encounter(patient, practitioner, "drug_prescription", medication, submit=True)
self.assertTrue(frappe.db.exists("Medication Request", {"order_group": encounter.name}))
medication_request = frappe.db.get_value(
Expand All @@ -39,7 +41,7 @@ def test_medication_request(self):
)


def create_medcation():
def create_medication():
if not frappe.db.exists("Medication", "_Test Medication"):
if not frappe.db.exists("Medication Class", "Tablet"):
try:
Expand All @@ -52,6 +54,8 @@ def create_medcation():
except frappe.DuplicateEntryError:
pass
try:
item_name = "_Test PL Item"
item = create_item(item_code=item_name, is_stock_item=0)
medication = frappe.get_doc(
{
"doctype": "Medication",
Expand All @@ -60,13 +64,12 @@ def create_medcation():
"abbr": "Test",
"strength": 500,
"strength_uom": "Unit",
"item_code": "_Test",
"item_group": "Drug",
"dosage_form": "Capsule",
"default_prescription_dosage": "0-1-0",
"default_prescription_duration": "1 Hour",
"is_billable": 1,
"rate": 800,
"linked_items": [{"item": item.item_code, "item_code": item.item_name, "item_group": "Drug"}],
}
).insert(ignore_permissions=True, ignore_mandatory=True)
return medication
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -181,10 +181,18 @@ 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);
return {
query: 'healthcare.healthcare.doctype.patient_encounter.patient_encounter.get_medications_query',
filters: { name: row.medication }
};
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
}
};
}
});
}
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 @@ -141,10 +141,17 @@ def validate_medications(self):
return

for item in self.drug_prescription:
if not item.medication and not item.drug_code:
frappe.throw(
_("Row #{0} (Drug Prescription): Medication or Item Code is mandatory").format(item.idx)
)
if not item.drug_code:
frappe.throw(_("Row #{0} (Drug Prescription): Drug Code is mandatory").format(item.idx))
else:
if not item.medication:
medication = frappe.db.get_value(
"Medication Linked Item",
{"item": item.drug_code},
"parent",
)
if medication:
item.medication = medication

def validate_therapies(self):
if not self.therapies:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,9 @@ def create_encounter(
type, {"lab_test_code": template.item, "lab_test_name": template.lab_test_name}
)
elif type == "drug_prescription":
patient_encounter.append(type, {"medication": template.name})
patient_encounter.append(
type, {"medication": template.name, "drug_code": template.linked_items[0].get("item")}
)
else:
patient_encounter.append(type, {"observation_template": template.name})

Expand Down

0 comments on commit b2dfea8

Please # to comment.