diff --git a/healthcare/healthcare/doctype/lab_prescription/lab_prescription.json b/healthcare/healthcare/doctype/lab_prescription/lab_prescription.json index bdbf561f66..3b3fe41a92 100644 --- a/healthcare/healthcare/doctype/lab_prescription/lab_prescription.json +++ b/healthcare/healthcare/doctype/lab_prescription/lab_prescription.json @@ -8,6 +8,7 @@ "engine": "InnoDB", "field_order": [ "lab_test_code", + "observation_template", "lab_test_name", "invoiced", "service_request", @@ -25,16 +26,14 @@ "fieldname": "lab_test_code", "fieldtype": "Link", "ignore_user_permissions": 1, - "in_list_view": 1, "label": "Lab Test", - "options": "Lab Test Template", - "reqd": 1 + "options": "Lab Test Template" }, { + "depends_on": "lab_test_code;", "fetch_from": "lab_test_code.lab_test_name", "fieldname": "lab_test_name", "fieldtype": "Data", - "in_list_view": 1, "label": "Lab Test Name" }, { @@ -101,11 +100,18 @@ "label": "Service Request", "no_copy": 1, "read_only": 1 + }, + { + "fieldname": "observation_template", + "fieldtype": "Link", + "in_list_view": 1, + "label": "Observation", + "options": "Observation Template" } ], "istable": 1, "links": [], - "modified": "2023-11-01 23:08:47.227779", + "modified": "2023-11-07 15:48:41.681329", "modified_by": "Administrator", "module": "Healthcare", "name": "Lab Prescription", diff --git a/healthcare/healthcare/doctype/observation_prescription/__init__.py b/healthcare/healthcare/doctype/observation_prescription/__init__.py deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/healthcare/healthcare/doctype/observation_prescription/observation_prescription.js b/healthcare/healthcare/doctype/observation_prescription/observation_prescription.js deleted file mode 100644 index dc4a271860..0000000000 --- a/healthcare/healthcare/doctype/observation_prescription/observation_prescription.js +++ /dev/null @@ -1,8 +0,0 @@ -// Copyright (c) 2023, healthcare and contributors -// For license information, please see license.txt - -// frappe.ui.form.on("Observation Prescription", { -// refresh(frm) { - -// }, -// }); diff --git a/healthcare/healthcare/doctype/observation_prescription/observation_prescription.json b/healthcare/healthcare/doctype/observation_prescription/observation_prescription.json deleted file mode 100644 index 241a13f440..0000000000 --- a/healthcare/healthcare/doctype/observation_prescription/observation_prescription.json +++ /dev/null @@ -1,80 +0,0 @@ -{ - "actions": [], - "allow_rename": 1, - "creation": "2023-06-23 18:24:42.698297", - "default_view": "List", - "doctype": "DocType", - "editable_grid": 1, - "engine": "InnoDB", - "field_order": [ - "observation_template", - "comments", - "service_request", - "section_break_rwih", - "patient_care_type", - "column_break_lbyq", - "intent", - "priority" - ], - "fields": [ - { - "fieldname": "observation_template", - "fieldtype": "Link", - "in_list_view": 1, - "label": "Observation Template", - "options": "Observation Template" - }, - { - "fieldname": "comments", - "fieldtype": "Small Text", - "in_list_view": 1, - "label": "Comments" - }, - { - "allow_on_submit": 1, - "fieldname": "service_request", - "fieldtype": "Data", - "label": "Service Request", - "no_copy": 1, - "read_only": 1 - }, - { - "fieldname": "section_break_rwih", - "fieldtype": "Section Break" - }, - { - "fieldname": "patient_care_type", - "fieldtype": "Link", - "label": "Patient Care Type", - "options": "Patient Care Type" - }, - { - "fieldname": "column_break_lbyq", - "fieldtype": "Column Break" - }, - { - "fieldname": "intent", - "fieldtype": "Link", - "label": "Intent", - "options": "Code Value" - }, - { - "fieldname": "priority", - "fieldtype": "Link", - "label": "Priority", - "options": "Code Value" - } - ], - "index_web_pages_for_search": 1, - "istable": 1, - "links": [], - "modified": "2023-10-31 12:53:37.172371", - "modified_by": "Administrator", - "module": "Healthcare", - "name": "Observation Prescription", - "owner": "Administrator", - "permissions": [], - "sort_field": "modified", - "sort_order": "DESC", - "states": [] -} \ No newline at end of file diff --git a/healthcare/healthcare/doctype/observation_prescription/observation_prescription.py b/healthcare/healthcare/doctype/observation_prescription/observation_prescription.py deleted file mode 100644 index adec120522..0000000000 --- a/healthcare/healthcare/doctype/observation_prescription/observation_prescription.py +++ /dev/null @@ -1,9 +0,0 @@ -# Copyright (c) 2023, healthcare and contributors -# For license information, please see license.txt - -# import frappe -from frappe.model.document import Document - - -class ObservationPrescription(Document): - pass diff --git a/healthcare/healthcare/doctype/observation_prescription/test_observation_prescription.py b/healthcare/healthcare/doctype/observation_prescription/test_observation_prescription.py deleted file mode 100644 index 33d85e288f..0000000000 --- a/healthcare/healthcare/doctype/observation_prescription/test_observation_prescription.py +++ /dev/null @@ -1,9 +0,0 @@ -# Copyright (c) 2023, healthcare and Contributors -# See license.txt - -# import frappe -from frappe.tests.utils import FrappeTestCase - - -class TestObservationPrescription(FrappeTestCase): - pass diff --git a/healthcare/healthcare/doctype/patient_encounter/patient_encounter.js b/healthcare/healthcare/doctype/patient_encounter/patient_encounter.js index 95f27ba6e8..c25001bbff 100644 --- a/healthcare/healthcare/doctype/patient_encounter/patient_encounter.js +++ b/healthcare/healthcare/doctype/patient_encounter/patient_encounter.js @@ -40,12 +40,6 @@ frappe.ui.form.on('Patient Encounter', { frm.get_field('drug_prescription').grid.editable_fields.splice(0, 0, {fieldname: 'medication', columns: 3}); frm.get_field('drug_prescription').grid.editable_fields.splice(2, 1); // remove item description } - - frm.get_field('lab_test_prescription').grid.editable_fields = [ - {fieldname: 'lab_test_code', columns: 2}, - {fieldname: 'lab_test_name', columns: 4}, - {fieldname: 'lab_test_comment', columns: 4} - ]; }, refresh: function(frm) { @@ -180,7 +174,7 @@ frappe.ui.form.on('Patient Encounter', { }; }); } - var table_list = ["drug_prescription", "lab_test_prescription", "observations", "procedure_prescription", "therapies"] + var table_list = ["drug_prescription", "lab_test_prescription", "procedure_prescription", "therapies"] apply_code_sm_filter_to_child(frm, "priority", table_list, "Priority") apply_code_sm_filter_to_child(frm, "intent", table_list, "Intent") }, diff --git a/healthcare/healthcare/doctype/patient_encounter/patient_encounter.json b/healthcare/healthcare/doctype/patient_encounter/patient_encounter.json index f3c7729c1c..deb0c9caa9 100644 --- a/healthcare/healthcare/doctype/patient_encounter/patient_encounter.json +++ b/healthcare/healthcare/doctype/patient_encounter/patient_encounter.json @@ -43,7 +43,6 @@ "drug_prescription", "sb_test_prescription", "lab_test_prescription", - "observations", "sb_procedures", "procedure_prescription", "rehabilitation_section", @@ -350,12 +349,6 @@ "options": "\nOpen\nOrdered\nCompleted\nCancelled", "read_only": 1 }, - { - "fieldname": "observations", - "fieldtype": "Table", - "label": "Observations", - "options": "Observation Prescription" - }, { "default": "0", "depends_on": "eval:!doc.__islocal;", @@ -366,7 +359,7 @@ ], "is_submittable": 1, "links": [], - "modified": "2023-10-25 05:22:26.351979", + "modified": "2023-11-07 18:03:12.793649", "modified_by": "Administrator", "module": "Healthcare", "name": "Patient Encounter", diff --git a/healthcare/healthcare/doctype/patient_encounter/patient_encounter.py b/healthcare/healthcare/doctype/patient_encounter/patient_encounter.py index 36f438fb3a..2ef3e03a20 100644 --- a/healthcare/healthcare/doctype/patient_encounter/patient_encounter.py +++ b/healthcare/healthcare/doctype/patient_encounter/patient_encounter.py @@ -15,8 +15,10 @@ class PatientEncounter(Document): def validate(self): self.set_title() - validate_codification_table(self) self.validate_medications() + self.validate_therapies() + self.validate_observations() + set_codification_table_from_diagnosis(self) if not self.is_new() and self.submit_orders_on_save: self.make_service_request() self.make_medication_request() @@ -130,7 +132,7 @@ def set_treatment_plan_item(self, plan_item): ) if plan_item.type == "Observation Template": - self.append("observations", {"observation_template": plan_item.template}) + self.append("lab_test_prescription", {"observation_template": plan_item.template}) def validate_medications(self): if not self.drug_prescription: @@ -152,11 +154,31 @@ def validate_therapies(self): _("Row #{0} (Therapies): Number of Sessions should be at least 1").format(therapy.idx) ) + def validate_observations(self): + if not self.lab_test_prescription: + return + + for observation in self.lab_test_prescription: + if not observation.observation_template and not observation.lab_test_code: + frappe.throw( + _("Row #{0} (Lab Tests): Observation Template or Lab Test Template is mandatory").format( + observation.idx + ) + ) + def make_service_request(self): if self.lab_test_prescription: for lab_test in self.lab_test_prescription: + if lab_test.observation_template: + template_doc = "Observation Template" + template = "observation_template" + elif lab_test.lab_test_code: + template_doc = "Lab Test Template" + template = "lab_test_code" + else: + continue if not lab_test.service_request: - lab_template = frappe.get_doc("Lab Test Template", lab_test.lab_test_code) + lab_template = frappe.get_doc(template_doc, lab_test.get(template)) order = self.get_order_details(lab_template, lab_test) order.insert(ignore_permissions=True, ignore_mandatory=True) order.submit() @@ -180,15 +202,6 @@ def make_service_request(self): order.submit() therapy.service_request = order.name - if self.observations: - for observation in self.observations: - if not observation.service_request: - template = frappe.get_doc("Observation Template", observation.observation_template) - order = self.get_order_details(template, observation) - order.insert(ignore_permissions=True, ignore_mandatory=True) - order.submit() - observation.service_request = order.name - def make_medication_request(self): if self.drug_prescription: # make_medication_request @@ -331,9 +344,8 @@ def delete_ip_medication_order(encounter): frappe.delete_doc("Inpatient Medication Order", record, force=1) -def validate_codification_table(doc): - if doc.diagnosis: - doc.codification_table = [] +def set_codification_table_from_diagnosis(doc): + if doc.diagnosis and not doc.codification_table: for diag in doc.diagnosis: medical_code_details = get_medical_codes("Diagnosis", diag.diagnosis) if medical_code_details and len(medical_code_details) > 0: