From 41bd317e252fd28cc96e5b4da7bc87f9446d4b86 Mon Sep 17 00:00:00 2001 From: Rucha Mahabal Date: Tue, 25 Feb 2020 13:51:36 +0530 Subject: [PATCH] refactor: Patient Appointment status --- .../patient_appointment.js | 9 -------- .../patient_appointment.json | 7 +++--- .../patient_appointment.py | 23 +++++++++++++++---- .../patient_appointment_list.js | 10 ++++++++ erpnext/hooks.py | 3 ++- 5 files changed, 33 insertions(+), 19 deletions(-) diff --git a/erpnext/healthcare/doctype/patient_appointment/patient_appointment.js b/erpnext/healthcare/doctype/patient_appointment/patient_appointment.js index 7c6b01166c..133fee1ce8 100644 --- a/erpnext/healthcare/doctype/patient_appointment/patient_appointment.js +++ b/erpnext/healthcare/doctype/patient_appointment/patient_appointment.js @@ -108,15 +108,6 @@ frappe.ui.form.on('Patient Appointment', { }, __('Create')); } - if (frm.doc.status == 'Pending') { - frm.add_custom_button(__('Set Open'), function() { - update_status(frm, 'Open'); - }); - frm.add_custom_button(__('Cancel'), function() { - update_status(frm, 'Cancelled'); - }); - } - frappe.db.get_value('Healthcare Settings', {name: 'Healthcare Settings'}, 'automate_appointment_invoicing', (settings) => { if (settings.automate_appointment_invoicing) { frm.set_df_property('mode_of_payment', 'hidden', 0); diff --git a/erpnext/healthcare/doctype/patient_appointment/patient_appointment.json b/erpnext/healthcare/doctype/patient_appointment/patient_appointment.json index f9dc892c9c..c0119fe8a5 100644 --- a/erpnext/healthcare/doctype/patient_appointment/patient_appointment.json +++ b/erpnext/healthcare/doctype/patient_appointment/patient_appointment.json @@ -89,7 +89,7 @@ "in_filter": 1, "in_list_view": 1, "label": "Status", - "options": "\nScheduled\nOpen\nClosed\nPending\nCancelled", + "options": "\nScheduled\nOpen\nClosed\nCancelled", "read_only": 1, "search_index": 1 }, @@ -257,8 +257,7 @@ "fieldtype": "Link", "ignore_user_permissions": 1, "label": "Referring Practitioner", - "options": "Healthcare Practitioner", - "set_only_once": 1 + "options": "Healthcare Practitioner" }, { "default": "0", @@ -278,7 +277,7 @@ } ], "links": [], - "modified": "2020-02-25 11:29:26.988952", + "modified": "2020-02-25 13:09:50.055119", "modified_by": "Administrator", "module": "Healthcare", "name": "Patient Appointment", diff --git a/erpnext/healthcare/doctype/patient_appointment/patient_appointment.py b/erpnext/healthcare/doctype/patient_appointment/patient_appointment.py index ecabbe3d2c..888ecff257 100755 --- a/erpnext/healthcare/doctype/patient_appointment/patient_appointment.py +++ b/erpnext/healthcare/doctype/patient_appointment/patient_appointment.py @@ -20,6 +20,7 @@ class PatientAppointment(Document): self.validate_overlaps() self.set_appointment_datetime() self.validate_customer_created() + self.set_status() def after_insert(self): invoice_appointment(self) @@ -27,14 +28,17 @@ class PatientAppointment(Document): self.check_fee_validity() send_confirmation_msg(self) - def on_update(self): + def set_status(self): today = getdate() appointment_date = getdate(self.appointment_date) - # If appointment is created for today set status as Open - if today == appointment_date: - frappe.db.set_value('Patient Appointment', self.name, 'status', 'Open') - self.reload() + # If appointment is created for today set status as Open else Scheduled + if appointment_date == today: + self.status = 'Open' + elif appointment_date > today: + self.status = 'Scheduled' + elif appointment_date < today: + self.status = 'Expired' def validate_overlaps(self): end_time = datetime.datetime.combine(getdate(self.appointment_date), get_time(self.appointment_time)) \ @@ -427,3 +431,12 @@ def get_procedure_prescribed(patient): from `tabPatient Encounter` ct, `tabProcedure Prescription` pp where ct.patient='{0}' and pp.parent=ct.name and pp.appointment_booked=0 order by ct.creation desc""".format(patient)) + +def update_appointment_status(): + # update the status of appointments daily + + frappe.db.sql("""update `tabPatient Appointment` set status = 'Open' + where appointment_date = CURDATE() and status = 'Scheduled'""") + + frappe.db.sql("""update `tabPatient Appointment` set status = 'Expired' + where appointment_date < CURDATE() and status NOT IN ('Closed', 'Cancelled')""") \ No newline at end of file diff --git a/erpnext/healthcare/doctype/patient_appointment/patient_appointment_list.js b/erpnext/healthcare/doctype/patient_appointment/patient_appointment_list.js index 701cb69806..721887b459 100644 --- a/erpnext/healthcare/doctype/patient_appointment/patient_appointment_list.js +++ b/erpnext/healthcare/doctype/patient_appointment/patient_appointment_list.js @@ -3,4 +3,14 @@ */ frappe.listview_settings['Patient Appointment'] = { filters: [["status", "=", "Open"]], + get_indicator: function(doc) { + var colors = { + "Open": "orange", + "Scheduled": "yellow", + "Closed": "green", + "Cancelled": "red", + "Expired": "grey" + }; + return [__(doc.status), colors[doc.status], "status,=," + doc.status]; + } }; diff --git a/erpnext/hooks.py b/erpnext/hooks.py index bc3dffaf2d..1f8eb096a1 100644 --- a/erpnext/hooks.py +++ b/erpnext/hooks.py @@ -309,7 +309,8 @@ scheduler_events = { "erpnext.support.doctype.service_level_agreement.service_level_agreement.check_agreement_status", "erpnext.crm.doctype.email_campaign.email_campaign.send_email_to_leads_or_contacts", "erpnext.crm.doctype.email_campaign.email_campaign.set_email_campaign_status", - "erpnext.selling.doctype.quotation.quotation.set_expired_status" + "erpnext.selling.doctype.quotation.quotation.set_expired_status", + "erpnext.healthcare_healthcare.doctype.patient_appointment.patient_appointment.update_appointment_status" ], "daily_long": [ "erpnext.setup.doctype.email_digest.email_digest.send",