From 7206e12c2f2d9ed46d11748d9ebb098e034bba28 Mon Sep 17 00:00:00 2001 From: Rucha Mahabal Date: Mon, 4 Jan 2021 12:11:00 +0530 Subject: [PATCH] test: Allow Discharge despite Unbilled Services --- .../healthcare_settings.py | 2 +- .../inpatient_record/inpatient_record.py | 2 +- .../inpatient_record/test_inpatient_record.py | 35 +++++++++++++++++++ 3 files changed, 37 insertions(+), 2 deletions(-) diff --git a/erpnext/healthcare/doctype/healthcare_settings/healthcare_settings.py b/erpnext/healthcare/doctype/healthcare_settings/healthcare_settings.py index e2ccc34a74..a16fceb74d 100644 --- a/erpnext/healthcare/doctype/healthcare_settings/healthcare_settings.py +++ b/erpnext/healthcare/doctype/healthcare_settings/healthcare_settings.py @@ -11,7 +11,7 @@ import json class HealthcareSettings(Document): def validate(self): - for key in ['collect_registration_fee', 'link_customer_to_patient', 'patient_name_by', 'allow_discharge_despite_unbilled_services', + for key in ['collect_registration_fee', 'link_customer_to_patient', 'patient_name_by', 'lab_test_approval_required', 'create_sample_collection_for_lab_test', 'default_medical_code_standard']: frappe.db.set_default(key, self.get(key, "")) diff --git a/erpnext/healthcare/doctype/inpatient_record/inpatient_record.py b/erpnext/healthcare/doctype/inpatient_record/inpatient_record.py index 6a32aca9d0..dc549a65db 100644 --- a/erpnext/healthcare/doctype/inpatient_record/inpatient_record.py +++ b/erpnext/healthcare/doctype/inpatient_record/inpatient_record.py @@ -158,7 +158,7 @@ def discharge_patient(inpatient_record): def validate_inpatient_invoicing(inpatient_record): - if frappe.db.get_default("allow_discharge_despite_unbilled_services"): + if frappe.db.get_single_value("Healthcare Settings", "allow_discharge_despite_unbilled_services"): return pending_invoices = get_pending_invoices(inpatient_record) diff --git a/erpnext/healthcare/doctype/inpatient_record/test_inpatient_record.py b/erpnext/healthcare/doctype/inpatient_record/test_inpatient_record.py index 70706adb2e..e8a9444fec 100644 --- a/erpnext/healthcare/doctype/inpatient_record/test_inpatient_record.py +++ b/erpnext/healthcare/doctype/inpatient_record/test_inpatient_record.py @@ -40,6 +40,31 @@ class TestInpatientRecord(unittest.TestCase): self.assertEqual(None, frappe.db.get_value("Patient", patient, "inpatient_record")) self.assertEqual(None, frappe.db.get_value("Patient", patient, "inpatient_status")) + def test_allow_discharge_despite_unbilled_services(self): + frappe.db.sql("""delete from `tabInpatient Record`""") + setup_inpatient_settings() + patient = create_patient() + # Schedule Admission + ip_record = create_inpatient(patient) + ip_record.expected_length_of_stay = 0 + ip_record.save(ignore_permissions = True) + + # Admit + service_unit = get_healthcare_service_unit() + admit_patient(ip_record, service_unit, now_datetime()) + + # Discharge + schedule_discharge(frappe.as_json({"patient": patient})) + self.assertEqual("Vacant", frappe.db.get_value("Healthcare Service Unit", service_unit, "occupancy_status")) + + ip_record = frappe.get_doc("Inpatient Record", ip_record.name) + # Should not validate Pending Invoices + ip_record.discharge() + + self.assertEqual(None, frappe.db.get_value("Patient", patient, "inpatient_record")) + self.assertEqual(None, frappe.db.get_value("Patient", patient, "inpatient_status")) + + def test_validate_overlap_admission(self): frappe.db.sql("""delete from `tabInpatient Record`""") patient = create_patient() @@ -63,6 +88,13 @@ def mark_invoiced_inpatient_occupancy(ip_record): inpatient_occupancy.invoiced = 1 ip_record.save(ignore_permissions = True) + +def setup_inpatient_settings(): + settings = frappe.get_single("Healthcare Settings") + settings.allow_discharge_despite_unbilled_services = 1 + settings.save() + + def create_inpatient(patient): patient_obj = frappe.get_doc('Patient', patient) inpatient_record = frappe.new_doc('Inpatient Record') @@ -78,6 +110,7 @@ def create_inpatient(patient): inpatient_record.scheduled_date = today() return inpatient_record + def get_healthcare_service_unit(): service_unit = get_random("Healthcare Service Unit", filters={"inpatient_occupancy": 1}) if not service_unit: @@ -105,6 +138,7 @@ def get_healthcare_service_unit(): return service_unit.name return service_unit + def get_service_unit_type(): service_unit_type = get_random("Healthcare Service Unit Type", filters={"inpatient_occupancy": 1}) @@ -116,6 +150,7 @@ def get_service_unit_type(): return service_unit_type.name return service_unit_type + def create_patient(): patient = frappe.db.exists('Patient', '_Test IPD Patient') if not patient: