diff --git a/healthcare/healthcare/doctype/nursing_task/nursing_task.py b/healthcare/healthcare/doctype/nursing_task/nursing_task.py index 7734eda549..38001b10f0 100644 --- a/healthcare/healthcare/doctype/nursing_task/nursing_task.py +++ b/healthcare/healthcare/doctype/nursing_task/nursing_task.py @@ -14,16 +14,12 @@ class NursingTask(Document): def before_insert(self): - # set requested start / end self.set_task_schedule() - self.title = "{} - {}".format(_(self.patient), _(self.activity)) - self.age = frappe.get_doc("Patient", self.patient).get_age() def validate(self): if self.status == "Requested": - # auto submit if status is Requested self.docstatus = 1 def on_submit(self): @@ -47,10 +43,11 @@ def on_update_after_submit(self): self.db_set("task_start_time", now_datetime()) elif self.status == "Completed": + task_end_time = now_datetime() self.db_set( { - "task_end_time": now_datetime(), - "task_duration": time_diff_in_seconds(self.task_end_time, self.task_start_time), + "task_end_time": task_end_time, + "task_duration": time_diff_in_seconds(task_end_time, self.task_start_time), } ) diff --git a/healthcare/healthcare/doctype/nursing_task/test_nursing_task.py b/healthcare/healthcare/doctype/nursing_task/test_nursing_task.py index c6768cc33f..f38fe10b28 100644 --- a/healthcare/healthcare/doctype/nursing_task/test_nursing_task.py +++ b/healthcare/healthcare/doctype/nursing_task/test_nursing_task.py @@ -58,6 +58,8 @@ def test_lab_test_submission_should_validate_pending_nursing_tasks(self): lab_test.descriptive_test_items[2].result_value = 2.3 lab_test.save() + start_nusing_tasks(lab_test) + self.assertRaises(frappe.ValidationError, lab_test.submit) complete_nusing_tasks(lab_test) @@ -70,12 +72,15 @@ def test_start_clinical_procedure_should_validate_pending_nursing_tasks(self): procedure_template.save() procedure = create_procedure(procedure_template, self.patient, self.practitioner) + start_nusing_tasks(procedure) + self.assertRaises(frappe.ValidationError, procedure.start_procedure) complete_nusing_tasks(procedure) procedure.start_procedure() - def test_admit_inpatient_should_validate_pending_nursing_tasks(self): + def test_admit_discharge_inpatient_should_validate_pending_nursing_tasks(self): + """nursing tasks on admit and discharge of same ip_record""" self.settings.allow_discharge_despite_unbilled_services = 1 self.settings.save() @@ -86,6 +91,7 @@ def test_admit_inpatient_should_validate_pending_nursing_tasks(self): NursingTask.create_nursing_tasks_from_template( ip_record.admission_nursing_checklist_template, ip_record, start_time=now_datetime() ) + start_nusing_tasks(ip_record) service_unit = get_healthcare_service_unit() kwargs = { @@ -103,6 +109,7 @@ def test_admit_inpatient_should_validate_pending_nursing_tasks(self): NursingTask.create_nursing_tasks_from_template( ip_record.admission_nursing_checklist_template, ip_record, start_time=now_datetime() ) + start_nusing_tasks(ip_record) self.assertRaises(frappe.ValidationError, discharge_patient, inpatient_record=ip_record) @@ -116,6 +123,7 @@ def test_submit_therapy_session_should_validate_pending_nursing_tasks(self): therapy_plan = create_therapy_plan() therapy_session = create_therapy_session(self.patient, therapy_type.name, therapy_plan.name) + start_nusing_tasks(therapy_session) self.assertRaises(frappe.ValidationError, therapy_session.submit) @@ -123,6 +131,20 @@ def test_submit_therapy_session_should_validate_pending_nursing_tasks(self): therapy_session.submit() +def start_nusing_tasks(document): + filters = { + "reference_name": document.name, + "mandatory": 1, + "status": ["not in", ["Completed", "Cancelled"]], + } + tasks = frappe.get_all("Nursing Task", filters=filters) + for task_name in tasks: + task = frappe.get_doc("Nursing Task", task_name) + task.submit() + task.status = "In Progress" # should set task_start_time + task.save() + + def complete_nusing_tasks(document): filters = { "reference_name": document.name,