Skip to content

Commit

Permalink
test: order creation on encounter save
Browse files Browse the repository at this point in the history
  • Loading branch information
akashkrishna619 committed Nov 2, 2023
1 parent a029c29 commit cff80d6
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def setup(self):
def test_medication_request(self):
patient, practitioner = create_healthcare_docs()
medication = create_medcation()
encounter = create_encounter(patient, practitioner, "drug_prescription", 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(
"Medication Request", {"order_group": encounter.name}, "name"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def test_creation_on_encounter_submission(self):
patient, practitioner = create_healthcare_docs()
insulin_resistance_template = create_lab_test_template()
encounter = create_encounter(
patient, practitioner, "lab_test_prescription", insulin_resistance_template
patient, practitioner, "lab_test_prescription", insulin_resistance_template, submit=True
)
self.assertTrue(frappe.db.exists("Service Request", {"order_group": encounter.name}))
service_request = frappe.db.get_value("Service Request", {"order_group": encounter.name}, "name")
Expand All @@ -50,8 +50,28 @@ def test_creation_on_encounter_submission(self):
)
self.assertTrue(frappe.db.get_value("Lab Test", lab_test.name, "invoiced"))

def test_creation_on_encounter_with_create_order_on_save_checked(self):
patient, practitioner = create_healthcare_docs()
insulin_resistance_template = create_lab_test_template()
encounter = create_encounter(
patient, practitioner, "lab_test_prescription", insulin_resistance_template
)
encounter.submit_orders_on_save = True
encounter.save()
self.assertTrue(frappe.db.exists("Service Request", {"order_group": encounter.name}))
encounter.submit()

# to check if submit creates order
self.assertEqual(
frappe.db.count(
"Service Request",
filters={"order_group": encounter.name},
),
1,
)

def create_encounter(patient, practitioner, type, template):

def create_encounter(patient, practitioner, type, template, submit=False):
patient_encounter = frappe.new_doc("Patient Encounter")
patient_encounter.patient = patient
patient_encounter.practitioner = practitioner
Expand All @@ -63,8 +83,10 @@ def create_encounter(patient, practitioner, type, template):
)
elif type == "drug_prescription":
patient_encounter.append(type, {"medication": template.name})

patient_encounter.submit()
if submit:
patient_encounter.submit()
else:
patient_encounter.save()
return patient_encounter


Expand Down

0 comments on commit cff80d6

Please sign in to comment.