Skip to content

Commit

Permalink
fix: Patient Encounter - merge observation and lab_test prescription …
Browse files Browse the repository at this point in the history
…table
  • Loading branch information
akashkrishna619 committed Nov 8, 2023
1 parent 59f9200 commit 4cc446b
Show file tree
Hide file tree
Showing 9 changed files with 40 additions and 141 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"engine": "InnoDB",
"field_order": [
"lab_test_code",
"observation_template",
"lab_test_name",
"invoiced",
"service_request",
Expand All @@ -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"
},
{
Expand Down Expand Up @@ -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",
Expand Down
Empty file.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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")
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@
"drug_prescription",
"sb_test_prescription",
"lab_test_prescription",
"observations",
"sb_procedures",
"procedure_prescription",
"rehabilitation_section",
Expand Down Expand Up @@ -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;",
Expand All @@ -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",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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:
Expand All @@ -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()
Expand All @@ -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
Expand Down Expand Up @@ -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:
Expand Down

0 comments on commit 4cc446b

Please sign in to comment.