Skip to content

Commit

Permalink
fix: Patient Encounter - Submit all orders on validate
Browse files Browse the repository at this point in the history
  • Loading branch information
akashkrishna619 committed Nov 2, 2023
1 parent e155cfd commit a029c29
Show file tree
Hide file tree
Showing 6 changed files with 90 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
"section_break_u9av",
"intent",
"priority",
"medication_request",
"section_break_13",
"comment",
"update_schedule"
Expand Down Expand Up @@ -170,11 +171,19 @@
"fieldtype": "Link",
"label": "Priority",
"options": "FHIR Value Set"
},
{
"allow_on_submit": 1,
"fieldname": "medication_request",
"fieldtype": "Data",
"label": "Medication Request",
"no_copy": 1,
"read_only": 1
}
],
"istable": 1,
"links": [],
"modified": "2023-10-31 15:44:26.100565",
"modified": "2023-11-01 23:09:36.121900",
"modified_by": "Administrator",
"module": "Healthcare",
"name": "Drug Prescription",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"lab_test_code",
"lab_test_name",
"invoiced",
"service_request",
"column_break_4",
"lab_test_comment",
"lab_test_created",
Expand Down Expand Up @@ -92,11 +93,19 @@
"fieldtype": "Link",
"label": "Patient Care Type",
"options": "Patient Care Type"
},
{
"allow_on_submit": 1,
"fieldname": "service_request",
"fieldtype": "Data",
"label": "Service Request",
"no_copy": 1,
"read_only": 1
}
],
"istable": 1,
"links": [],
"modified": "2023-10-31 13:01:53.258924",
"modified": "2023-11-01 23:08:47.227779",
"modified_by": "Administrator",
"module": "Healthcare",
"name": "Lab Prescription",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
"medical_department",
"google_meet_link",
"invoiced",
"submit_orders_on_save",
"sb_symptoms",
"symptoms",
"symptoms_in_print",
Expand Down Expand Up @@ -346,14 +347,21 @@
"fieldname": "status",
"fieldtype": "Select",
"label": "Status",
"options": "\nOpen\nWaiting For Review\nCompleted\nCancelled",
"options": "\nOpen\nOrdered\nCompleted\nCancelled",
"read_only": 1
},
{
"fieldname": "observations",
"fieldtype": "Table",
"label": "Observations",
"options": "Observation Prescription"
},
{
"default": "0",
"depends_on": "eval:!doc.__islocal;",
"fieldname": "submit_orders_on_save",
"fieldtype": "Check",
"label": "Submit Orders on Save"
}
],
"is_submittable": 1,
Expand Down Expand Up @@ -386,7 +394,20 @@
"show_name_in_global_search": 1,
"sort_field": "modified",
"sort_order": "DESC",
"states": [],
"states": [
{
"color": "Orange",
"title": "Ordered"
},
{
"color": "Blue",
"title": "Completed"
},
{
"color": "Red",
"title": "Cancelled"
}
],
"title_field": "title",
"track_changes": 1,
"track_seen": 1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ def validate(self):
self.set_title()
validate_codification_table(self)
self.validate_medications()
if not self.is_new() and self.submit_orders_on_save:
self.make_service_request()
self.make_medication_request()
self.status = "Ordered"

def on_update(self):
if self.appointment:
Expand All @@ -25,7 +29,6 @@ def on_update(self):
def on_submit(self):
if self.therapies:
create_therapy_plan(self)

self.make_service_request()
self.make_medication_request()
# to save service_request name in prescription
Expand All @@ -40,6 +43,8 @@ def before_cancel(self):
order_doc.cancel()

def on_cancel(self):
self.db_set("status", "Cancelled")

if self.appointment:
frappe.db.set_value("Patient Appointment", self.appointment, "status", "Open")

Expand Down Expand Up @@ -150,21 +155,30 @@ def validate_therapies(self):
def make_service_request(self):
if self.lab_test_prescription:
for lab_test in self.lab_test_prescription:
lab_template = frappe.get_doc("Lab Test Template", lab_test.lab_test_code)
order = self.get_order_details(lab_template, lab_test)
order.insert(ignore_permissions=True, ignore_mandatory=True)
if not lab_test.service_request:
lab_template = frappe.get_doc("Lab Test Template", lab_test.lab_test_code)
order = self.get_order_details(lab_template, lab_test)
order.insert(ignore_permissions=True, ignore_mandatory=True)
order.submit()
lab_test.service_request = order.name

if self.procedure_prescription:
for procedure in self.procedure_prescription:
procedure_template = frappe.get_doc("Clinical Procedure Template", procedure.procedure)
order = self.get_order_details(procedure_template, procedure)
order.insert(ignore_permissions=True, ignore_mandatory=True)
if not procedure.service_request:
procedure_template = frappe.get_doc("Clinical Procedure Template", procedure.procedure)
order = self.get_order_details(procedure_template, procedure)
order.insert(ignore_permissions=True, ignore_mandatory=True)
order.submit()
procedure.service_request = order.name

if self.therapies:
for therapy in self.therapies:
therapy_type = frappe.get_doc("Therapy Type", therapy.therapy_type)
order = self.get_order_details(therapy_type, therapy)
order.insert(ignore_permissions=True, ignore_mandatory=True)
if not therapy.service_request:
therapy_type = frappe.get_doc("Therapy Type", therapy.therapy_type)
order = self.get_order_details(therapy_type, therapy)
order.insert(ignore_permissions=True, ignore_mandatory=True)
order.submit()
therapy.service_request = order.name

if self.observations:
for observation in self.observations:
Expand All @@ -179,10 +193,12 @@ def make_medication_request(self):
if self.drug_prescription:
# make_medication_request
for drug in self.drug_prescription:
if drug.medication:
if drug.medication and not drug.medication_request:
medication = frappe.get_doc("Medication", drug.medication)
order = self.get_order_details(medication, drug, True)
order.insert(ignore_permissions=True, ignore_mandatory=True)
order.submit()
drug.medication_request = order.name

def get_order_details(self, template_doc, line_item, medication_request=False):
order = frappe.get_doc(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"procedure_name",
"department",
"practitioner",
"service_request",
"column_break_ky11",
"date",
"comments",
Expand Down Expand Up @@ -117,11 +118,19 @@
{
"fieldname": "column_break_ky11",
"fieldtype": "Column Break"
},
{
"allow_on_submit": 1,
"fieldname": "service_request",
"fieldtype": "Data",
"label": "Service Request",
"no_copy": 1,
"read_only": 1
}
],
"istable": 1,
"links": [],
"modified": "2023-10-31 12:58:54.804015",
"modified": "2023-11-01 23:09:04.600093",
"modified_by": "Administrator",
"module": "Healthcare",
"name": "Procedure Prescription",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"therapy_type",
"no_of_sessions",
"sessions_completed",
"service_request",
"section_break_hywn",
"patient_care_type",
"column_break_eawy",
Expand Down Expand Up @@ -63,11 +64,19 @@
"fieldtype": "Link",
"label": "Priority",
"options": "FHIR Value Set"
},
{
"allow_on_submit": 1,
"fieldname": "service_request",
"fieldtype": "Data",
"label": "Service Request",
"no_copy": 1,
"read_only": 1
}
],
"istable": 1,
"links": [],
"modified": "2023-10-31 13:42:31.937951",
"modified": "2023-11-01 23:10:20.015399",
"modified_by": "Administrator",
"module": "Healthcare",
"name": "Therapy Plan Detail",
Expand Down

0 comments on commit a029c29

Please sign in to comment.