feat: Allow Discharge despite Unbilled Healthcare Services
This commit is contained in:
parent
a245f667d0
commit
03b25be9e9
@ -17,6 +17,8 @@
|
|||||||
"enable_free_follow_ups",
|
"enable_free_follow_ups",
|
||||||
"max_visits",
|
"max_visits",
|
||||||
"valid_days",
|
"valid_days",
|
||||||
|
"inpatient_settings_section",
|
||||||
|
"allow_discharge_despite_unbilled_services",
|
||||||
"healthcare_service_items",
|
"healthcare_service_items",
|
||||||
"inpatient_visit_charge_item",
|
"inpatient_visit_charge_item",
|
||||||
"op_consulting_charge_item",
|
"op_consulting_charge_item",
|
||||||
@ -302,11 +304,22 @@
|
|||||||
"fieldname": "enable_free_follow_ups",
|
"fieldname": "enable_free_follow_ups",
|
||||||
"fieldtype": "Check",
|
"fieldtype": "Check",
|
||||||
"label": "Enable Free Follow-ups"
|
"label": "Enable Free Follow-ups"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldname": "inpatient_settings_section",
|
||||||
|
"fieldtype": "Section Break",
|
||||||
|
"label": "Inpatient Settings"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"default": "0",
|
||||||
|
"fieldname": "allow_discharge_despite_unbilled_services",
|
||||||
|
"fieldtype": "Check",
|
||||||
|
"label": "Allow Discharge Despite Unbilled Healthcare Services"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"issingle": 1,
|
"issingle": 1,
|
||||||
"links": [],
|
"links": [],
|
||||||
"modified": "2020-07-08 15:17:21.543218",
|
"modified": "2021-01-04 10:19:22.329272",
|
||||||
"modified_by": "Administrator",
|
"modified_by": "Administrator",
|
||||||
"module": "Healthcare",
|
"module": "Healthcare",
|
||||||
"name": "Healthcare Settings",
|
"name": "Healthcare Settings",
|
||||||
|
@ -11,7 +11,7 @@ import json
|
|||||||
|
|
||||||
class HealthcareSettings(Document):
|
class HealthcareSettings(Document):
|
||||||
def validate(self):
|
def validate(self):
|
||||||
for key in ['collect_registration_fee', 'link_customer_to_patient', 'patient_name_by',
|
for key in ['collect_registration_fee', 'link_customer_to_patient', 'patient_name_by', 'allow_discharge_despite_unbilled_services',
|
||||||
'lab_test_approval_required', 'create_sample_collection_for_lab_test', 'default_medical_code_standard']:
|
'lab_test_approval_required', 'create_sample_collection_for_lab_test', 'default_medical_code_standard']:
|
||||||
frappe.db.set_default(key, self.get(key, ""))
|
frappe.db.set_default(key, self.get(key, ""))
|
||||||
|
|
||||||
|
@ -5,7 +5,7 @@
|
|||||||
from __future__ import unicode_literals
|
from __future__ import unicode_literals
|
||||||
import frappe, json
|
import frappe, json
|
||||||
from frappe import _
|
from frappe import _
|
||||||
from frappe.utils import today, now_datetime, getdate, get_datetime
|
from frappe.utils import today, now_datetime, getdate, get_datetime, get_link_to_form
|
||||||
from frappe.model.document import Document
|
from frappe.model.document import Document
|
||||||
from frappe.desk.reportview import get_match_cond
|
from frappe.desk.reportview import get_match_cond
|
||||||
|
|
||||||
@ -113,6 +113,7 @@ def schedule_inpatient(args):
|
|||||||
inpatient_record.status = 'Admission Scheduled'
|
inpatient_record.status = 'Admission Scheduled'
|
||||||
inpatient_record.save(ignore_permissions = True)
|
inpatient_record.save(ignore_permissions = True)
|
||||||
|
|
||||||
|
|
||||||
@frappe.whitelist()
|
@frappe.whitelist()
|
||||||
def schedule_discharge(args):
|
def schedule_discharge(args):
|
||||||
discharge_order = json.loads(args)
|
discharge_order = json.loads(args)
|
||||||
@ -126,16 +127,19 @@ def schedule_discharge(args):
|
|||||||
frappe.db.set_value('Patient', discharge_order['patient'], 'inpatient_status', inpatient_record.status)
|
frappe.db.set_value('Patient', discharge_order['patient'], 'inpatient_status', inpatient_record.status)
|
||||||
frappe.db.set_value('Patient Encounter', inpatient_record.discharge_encounter, 'inpatient_status', inpatient_record.status)
|
frappe.db.set_value('Patient Encounter', inpatient_record.discharge_encounter, 'inpatient_status', inpatient_record.status)
|
||||||
|
|
||||||
|
|
||||||
def set_details_from_ip_order(inpatient_record, ip_order):
|
def set_details_from_ip_order(inpatient_record, ip_order):
|
||||||
for key in ip_order:
|
for key in ip_order:
|
||||||
inpatient_record.set(key, ip_order[key])
|
inpatient_record.set(key, ip_order[key])
|
||||||
|
|
||||||
|
|
||||||
def set_ip_child_records(inpatient_record, inpatient_record_child, encounter_child):
|
def set_ip_child_records(inpatient_record, inpatient_record_child, encounter_child):
|
||||||
for item in encounter_child:
|
for item in encounter_child:
|
||||||
table = inpatient_record.append(inpatient_record_child)
|
table = inpatient_record.append(inpatient_record_child)
|
||||||
for df in table.meta.get('fields'):
|
for df in table.meta.get('fields'):
|
||||||
table.set(df.fieldname, item.get(df.fieldname))
|
table.set(df.fieldname, item.get(df.fieldname))
|
||||||
|
|
||||||
|
|
||||||
def check_out_inpatient(inpatient_record):
|
def check_out_inpatient(inpatient_record):
|
||||||
if inpatient_record.inpatient_occupancies:
|
if inpatient_record.inpatient_occupancies:
|
||||||
for inpatient_occupancy in inpatient_record.inpatient_occupancies:
|
for inpatient_occupancy in inpatient_record.inpatient_occupancies:
|
||||||
@ -144,54 +148,88 @@ def check_out_inpatient(inpatient_record):
|
|||||||
inpatient_occupancy.check_out = now_datetime()
|
inpatient_occupancy.check_out = now_datetime()
|
||||||
frappe.db.set_value("Healthcare Service Unit", inpatient_occupancy.service_unit, "occupancy_status", "Vacant")
|
frappe.db.set_value("Healthcare Service Unit", inpatient_occupancy.service_unit, "occupancy_status", "Vacant")
|
||||||
|
|
||||||
|
|
||||||
def discharge_patient(inpatient_record):
|
def discharge_patient(inpatient_record):
|
||||||
validate_invoiced_inpatient(inpatient_record)
|
validate_inpatient_invoicing(inpatient_record)
|
||||||
inpatient_record.discharge_date = today()
|
inpatient_record.discharge_date = today()
|
||||||
inpatient_record.status = "Discharged"
|
inpatient_record.status = "Discharged"
|
||||||
|
|
||||||
inpatient_record.save(ignore_permissions = True)
|
inpatient_record.save(ignore_permissions = True)
|
||||||
|
|
||||||
def validate_invoiced_inpatient(inpatient_record):
|
|
||||||
pending_invoices = []
|
def validate_inpatient_invoicing(inpatient_record):
|
||||||
|
if frappe.db.get_default("allow_discharge_despite_unbilled_services"):
|
||||||
|
return
|
||||||
|
|
||||||
|
pending_invoices = get_pending_invoices(inpatient_record)
|
||||||
|
|
||||||
|
if pending_invoices:
|
||||||
|
message = _("Cannot mark Inpatient Record as Discharged since there are unbilled services. ")
|
||||||
|
|
||||||
|
formatted_doc_rows = ''
|
||||||
|
|
||||||
|
for doctype, docnames in pending_invoices.items():
|
||||||
|
formatted_doc_rows += """
|
||||||
|
<td>{0}</td>
|
||||||
|
<td>{1}</td>
|
||||||
|
</tr>""".format(doctype, docnames)
|
||||||
|
|
||||||
|
message += """
|
||||||
|
<table class='table'>
|
||||||
|
<thead>
|
||||||
|
<th>{0}</th>
|
||||||
|
<th>{1}</th>
|
||||||
|
</thead>
|
||||||
|
{2}
|
||||||
|
</table>
|
||||||
|
""".format(_("Healthcare Service"), _("Documents"), formatted_doc_rows)
|
||||||
|
|
||||||
|
frappe.throw(message, title=_("Unbilled Services"), is_minimizable=True, wide=True)
|
||||||
|
|
||||||
|
|
||||||
|
def get_pending_invoices(inpatient_record):
|
||||||
|
pending_invoices = {}
|
||||||
if inpatient_record.inpatient_occupancies:
|
if inpatient_record.inpatient_occupancies:
|
||||||
service_unit_names = False
|
service_unit_names = False
|
||||||
for inpatient_occupancy in inpatient_record.inpatient_occupancies:
|
for inpatient_occupancy in inpatient_record.inpatient_occupancies:
|
||||||
if inpatient_occupancy.invoiced != 1:
|
if not inpatient_occupancy.invoiced:
|
||||||
if service_unit_names:
|
if service_unit_names:
|
||||||
service_unit_names += ", " + inpatient_occupancy.service_unit
|
service_unit_names += ", " + inpatient_occupancy.service_unit
|
||||||
else:
|
else:
|
||||||
service_unit_names = inpatient_occupancy.service_unit
|
service_unit_names = inpatient_occupancy.service_unit
|
||||||
if service_unit_names:
|
if service_unit_names:
|
||||||
pending_invoices.append("Inpatient Occupancy (" + service_unit_names + ")")
|
pending_invoices["Inpatient Occupancy"] = service_unit_names
|
||||||
|
|
||||||
docs = ["Patient Appointment", "Patient Encounter", "Lab Test", "Clinical Procedure"]
|
docs = ["Patient Appointment", "Patient Encounter", "Lab Test", "Clinical Procedure"]
|
||||||
|
|
||||||
for doc in docs:
|
for doc in docs:
|
||||||
doc_name_list = get_inpatient_docs_not_invoiced(doc, inpatient_record)
|
doc_name_list = get_unbilled_inpatient_docs(doc, inpatient_record)
|
||||||
if doc_name_list:
|
if doc_name_list:
|
||||||
pending_invoices = get_pending_doc(doc, doc_name_list, pending_invoices)
|
pending_invoices = get_pending_doc(doc, doc_name_list, pending_invoices)
|
||||||
|
|
||||||
if pending_invoices:
|
return pending_invoices
|
||||||
frappe.throw(_("Can not mark Inpatient Record Discharged, there are Unbilled Invoices {0}").format(", "
|
|
||||||
.join(pending_invoices)), title=_('Unbilled Invoices'))
|
|
||||||
|
|
||||||
def get_pending_doc(doc, doc_name_list, pending_invoices):
|
def get_pending_doc(doc, doc_name_list, pending_invoices):
|
||||||
if doc_name_list:
|
if doc_name_list:
|
||||||
doc_ids = False
|
doc_ids = False
|
||||||
for doc_name in doc_name_list:
|
for doc_name in doc_name_list:
|
||||||
|
doc_link = get_link_to_form(doc, doc_name.name)
|
||||||
if doc_ids:
|
if doc_ids:
|
||||||
doc_ids += ", "+doc_name.name
|
doc_ids += ", " + doc_link
|
||||||
else:
|
else:
|
||||||
doc_ids = doc_name.name
|
doc_ids = doc_link
|
||||||
if doc_ids:
|
if doc_ids:
|
||||||
pending_invoices.append(doc + " (" + doc_ids + ")")
|
pending_invoices[doc] = doc_ids
|
||||||
|
|
||||||
return pending_invoices
|
return pending_invoices
|
||||||
|
|
||||||
def get_inpatient_docs_not_invoiced(doc, inpatient_record):
|
|
||||||
|
def get_unbilled_inpatient_docs(doc, inpatient_record):
|
||||||
return frappe.db.get_list(doc, filters = {'patient': inpatient_record.patient,
|
return frappe.db.get_list(doc, filters = {'patient': inpatient_record.patient,
|
||||||
'inpatient_record': inpatient_record.name, 'docstatus': 1, 'invoiced': 0})
|
'inpatient_record': inpatient_record.name, 'docstatus': 1, 'invoiced': 0})
|
||||||
|
|
||||||
|
|
||||||
def admit_patient(inpatient_record, service_unit, check_in, expected_discharge=None):
|
def admit_patient(inpatient_record, service_unit, check_in, expected_discharge=None):
|
||||||
inpatient_record.admitted_datetime = check_in
|
inpatient_record.admitted_datetime = check_in
|
||||||
inpatient_record.status = 'Admitted'
|
inpatient_record.status = 'Admitted'
|
||||||
@ -203,6 +241,7 @@ def admit_patient(inpatient_record, service_unit, check_in, expected_discharge=N
|
|||||||
frappe.db.set_value('Patient', inpatient_record.patient, 'inpatient_status', 'Admitted')
|
frappe.db.set_value('Patient', inpatient_record.patient, 'inpatient_status', 'Admitted')
|
||||||
frappe.db.set_value('Patient', inpatient_record.patient, 'inpatient_record', inpatient_record.name)
|
frappe.db.set_value('Patient', inpatient_record.patient, 'inpatient_record', inpatient_record.name)
|
||||||
|
|
||||||
|
|
||||||
def transfer_patient(inpatient_record, service_unit, check_in):
|
def transfer_patient(inpatient_record, service_unit, check_in):
|
||||||
item_line = inpatient_record.append('inpatient_occupancies', {})
|
item_line = inpatient_record.append('inpatient_occupancies', {})
|
||||||
item_line.service_unit = service_unit
|
item_line.service_unit = service_unit
|
||||||
@ -212,6 +251,7 @@ def transfer_patient(inpatient_record, service_unit, check_in):
|
|||||||
|
|
||||||
frappe.db.set_value("Healthcare Service Unit", service_unit, "occupancy_status", "Occupied")
|
frappe.db.set_value("Healthcare Service Unit", service_unit, "occupancy_status", "Occupied")
|
||||||
|
|
||||||
|
|
||||||
def patient_leave_service_unit(inpatient_record, check_out, leave_from):
|
def patient_leave_service_unit(inpatient_record, check_out, leave_from):
|
||||||
if inpatient_record.inpatient_occupancies:
|
if inpatient_record.inpatient_occupancies:
|
||||||
for inpatient_occupancy in inpatient_record.inpatient_occupancies:
|
for inpatient_occupancy in inpatient_record.inpatient_occupancies:
|
||||||
@ -221,6 +261,7 @@ def patient_leave_service_unit(inpatient_record, check_out, leave_from):
|
|||||||
frappe.db.set_value("Healthcare Service Unit", inpatient_occupancy.service_unit, "occupancy_status", "Vacant")
|
frappe.db.set_value("Healthcare Service Unit", inpatient_occupancy.service_unit, "occupancy_status", "Vacant")
|
||||||
inpatient_record.save(ignore_permissions = True)
|
inpatient_record.save(ignore_permissions = True)
|
||||||
|
|
||||||
|
|
||||||
@frappe.whitelist()
|
@frappe.whitelist()
|
||||||
@frappe.validate_and_sanitize_search_inputs
|
@frappe.validate_and_sanitize_search_inputs
|
||||||
def get_leave_from(doctype, txt, searchfield, start, page_len, filters):
|
def get_leave_from(doctype, txt, searchfield, start, page_len, filters):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user