Skip to content

Commit

Permalink
fix: Key error during schedule discharge
Browse files Browse the repository at this point in the history
The checkout time for inpatient occupancy should also be based on
scheduled order datetime.
  • Loading branch information
mujeerhashmi committed Sep 23, 2023
1 parent d46e417 commit 602a9d8
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
"inpatient_occupancies",
"btn_transfer",
"sb_discharge_details",
"discharge_ordered_date",
"discharge_ordered_datetime",
"discharge_practitioner",
"discharge_encounter",
"discharge_datetime",
Expand Down Expand Up @@ -387,10 +387,10 @@
"label": "Discharge Instructions"
},
{
"fieldname": "discharge_ordered_date",
"fieldtype": "Date",
"fieldname": "discharge_ordered_datetime",
"fieldtype": "Datetime",
"in_list_view": 1,
"label": "Discharge Ordered Date",
"label": "Discharge Ordered Datetime",
"read_only": 1
},
{
Expand Down Expand Up @@ -433,6 +433,18 @@
"fieldtype": "Link",
"label": "Admission Nursing Checklist Template",
"options": "Nursing Checklist Template"
},
{
"collapsible": 1,
"fieldname": "cancellation_details_section",
"fieldtype": "Section Break",
"label": "Cancellation Details"
},
{
"fieldname": "reason_for_cancellation",
"fieldtype": "Small Text",
"label": "Reason for Cancellation",
"read_only": 1
}
],
"index_web_pages_for_search": 1,
Expand Down Expand Up @@ -471,23 +483,9 @@
"group": "Nursing",
"link_doctype": "Vital Signs",
"link_fieldname": "inpatient_record"
},
{
"collapsible": 1,
"fieldname": "cancellation_details_section",
"fieldtype": "Section Break",
"label": "Cancellation Details"
},
{
"fieldname": "reason_for_cancellation",
"fieldtype": "Small Text",
"label": "Reason for Cancellation",
"read_only": 1
}
],
"index_web_pages_for_search": 1,
"links": [],
"modified": "2022-04-28 17:26:28.973945",
"modified": "2023-09-20 17:57:02.408982",
"modified_by": "Administrator",
"module": "Healthcare",
"name": "Inpatient Record",
Expand Down Expand Up @@ -574,17 +572,11 @@
"share": 1
}
],
"links": [
{
"link_doctype": "Nursing Task",
"link_fieldname": "reference_name"
}
],
"restrict_to_domain": "Healthcare",
"search_fields": "patient",
"sort_field": "modified",
"sort_order": "DESC",
"states": [],
"title_field": "patient",
"track_changes": 1
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def validate(self):

def validate_dates(self):
if (getdate(self.expected_discharge) < getdate(self.scheduled_date)) or (
getdate(self.discharge_ordered_date) < getdate(self.scheduled_date)
getdate(self.discharge_ordered_datetime) < getdate(self.scheduled_date)
):
frappe.throw(_("Expected and Discharge dates cannot be less than Admission Schedule date"))

Expand Down Expand Up @@ -155,7 +155,7 @@ def schedule_discharge(args):
if inpatient_record_id:

inpatient_record = frappe.get_doc("Inpatient Record", inpatient_record_id)
check_out_inpatient(inpatient_record)
check_out_inpatient(inpatient_record, discharge_order)
set_details_from_ip_order(inpatient_record, discharge_order)
inpatient_record.status = "Discharge Scheduled"
inpatient_record.save(ignore_permissions=True)
Expand Down Expand Up @@ -191,12 +191,15 @@ def set_ip_child_records(inpatient_record, inpatient_record_child, encounter_chi
table.set(df.fieldname, item.get(df.fieldname))


def check_out_inpatient(inpatient_record):
def check_out_inpatient(inpatient_record, discharge_order):
if inpatient_record.inpatient_occupancies:
for inpatient_occupancy in inpatient_record.inpatient_occupancies:
if inpatient_occupancy.left != 1:
inpatient_occupancy.left = True
inpatient_occupancy.check_out = now_datetime()
if (discharge_order.has_key("discharge_ordered_datetime")):
inpatient_occupancy.check_out = discharge_order["discharge_ordered_datetime"]
else:
inpatient_occupancy.check_out = now_datetime()
frappe.db.set_value(
"Healthcare Service Unit", inpatient_occupancy.service_unit, "occupancy_status", "Vacant"
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,7 @@ var schedule_discharge = function(frm) {
var dialog = new frappe.ui.Dialog ({
title: 'Inpatient Discharge',
fields: [
{fieldtype: 'Date', label: 'Discharge Ordered Date', fieldname: 'discharge_ordered_date', default: 'Today', read_only: 1},
{fieldtype: 'Datetime', label: 'Discharge Ordered Datetime', fieldname: 'discharge_ordered_datetime', default: 'Today', read_only: 1},
{fieldtype: 'Date', label: 'Followup Date', fieldname: 'followup_date'},
{fieldtype: 'Link', label: 'Nursing Checklist Template', options: 'Nursing Checklist Template', fieldname: 'discharge_nursing_checklist_template'},
{fieldtype: 'Column Break'},
Expand All @@ -348,7 +348,7 @@ var schedule_discharge = function(frm) {
patient: frm.doc.patient,
discharge_encounter: frm.doc.name,
discharge_practitioner: frm.doc.practitioner,
discharge_ordered_date: dialog.get_value('discharge_ordered_date'),
discharge_ordered_datetime: dialog.get_value('discharge_ordered_datetime'),
followup_date: dialog.get_value('followup_date'),
discharge_instructions: dialog.get_value('discharge_instructions'),
discharge_note: dialog.get_value('discharge_note'),
Expand Down

0 comments on commit 602a9d8

Please sign in to comment.