fix: appointment reminders not working
This commit is contained in:
parent
24055e1552
commit
5100e11fb6
@ -30,12 +30,12 @@
|
|||||||
"appointment_datetime",
|
"appointment_datetime",
|
||||||
"duration",
|
"duration",
|
||||||
"section_break_16",
|
"section_break_16",
|
||||||
"invoiced",
|
|
||||||
"ref_sales_invoice",
|
|
||||||
"column_break_2",
|
|
||||||
"mode_of_payment",
|
"mode_of_payment",
|
||||||
"paid_amount",
|
"paid_amount",
|
||||||
"company",
|
"company",
|
||||||
|
"column_break_2",
|
||||||
|
"invoiced",
|
||||||
|
"ref_sales_invoice",
|
||||||
"section_break_3",
|
"section_break_3",
|
||||||
"notes",
|
"notes",
|
||||||
"referring_practitioner",
|
"referring_practitioner",
|
||||||
@ -83,7 +83,6 @@
|
|||||||
"read_only": 1
|
"read_only": 1
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"default": "Scheduled",
|
|
||||||
"depends_on": "eval:!doc.__islocal",
|
"depends_on": "eval:!doc.__islocal",
|
||||||
"fieldname": "status",
|
"fieldname": "status",
|
||||||
"fieldtype": "Select",
|
"fieldtype": "Select",
|
||||||
@ -202,9 +201,9 @@
|
|||||||
{
|
{
|
||||||
"fieldname": "appointment_datetime",
|
"fieldname": "appointment_datetime",
|
||||||
"fieldtype": "Datetime",
|
"fieldtype": "Datetime",
|
||||||
"hidden": 1,
|
"label": "Appointment Datetime",
|
||||||
"label": "Date TIme",
|
|
||||||
"print_hide": 1,
|
"print_hide": 1,
|
||||||
|
"read_only": 1,
|
||||||
"report_hide": 1,
|
"report_hide": 1,
|
||||||
"search_index": 1
|
"search_index": 1
|
||||||
},
|
},
|
||||||
@ -227,6 +226,7 @@
|
|||||||
"default": "0",
|
"default": "0",
|
||||||
"fieldname": "invoiced",
|
"fieldname": "invoiced",
|
||||||
"fieldtype": "Check",
|
"fieldtype": "Check",
|
||||||
|
"in_filter": 1,
|
||||||
"label": "Invoiced",
|
"label": "Invoiced",
|
||||||
"read_only": 1,
|
"read_only": 1,
|
||||||
"search_index": 1
|
"search_index": 1
|
||||||
@ -279,7 +279,7 @@
|
|||||||
}
|
}
|
||||||
],
|
],
|
||||||
"links": [],
|
"links": [],
|
||||||
"modified": "2020-02-10 22:38:55.401247",
|
"modified": "2020-02-24 21:29:28.374886",
|
||||||
"modified_by": "Administrator",
|
"modified_by": "Administrator",
|
||||||
"module": "Healthcare",
|
"module": "Healthcare",
|
||||||
"name": "Patient Appointment",
|
"name": "Patient Appointment",
|
||||||
|
@ -18,6 +18,7 @@ from erpnext.healthcare.utils import check_validity_exists, get_service_item_and
|
|||||||
class PatientAppointment(Document):
|
class PatientAppointment(Document):
|
||||||
def validate(self):
|
def validate(self):
|
||||||
self.validate_overlaps()
|
self.validate_overlaps()
|
||||||
|
self.set_appointment_datetime()
|
||||||
|
|
||||||
def after_insert(self):
|
def after_insert(self):
|
||||||
invoice_appointment(self)
|
invoice_appointment(self)
|
||||||
@ -59,6 +60,9 @@ class PatientAppointment(Document):
|
|||||||
overlaps[0][1], overlaps[0][2], overlaps[0][3], overlaps[0][4])
|
overlaps[0][1], overlaps[0][2], overlaps[0][3], overlaps[0][4])
|
||||||
frappe.throw(_(overlapping_details))
|
frappe.throw(_(overlapping_details))
|
||||||
|
|
||||||
|
def set_appointment_datetime(self):
|
||||||
|
self.appointment_datetime = "%s %s" % (self.appointment_date, self.appointment_time or "00:00:00")
|
||||||
|
|
||||||
def update_prescription_details(self):
|
def update_prescription_details(self):
|
||||||
if self.procedure_prescription:
|
if self.procedure_prescription:
|
||||||
frappe.db.set_value('Procedure Prescription', self.procedure_prescription, 'appointment_booked', 1)
|
frappe.db.set_value('Procedure Prescription', self.procedure_prescription, 'appointment_booked', 1)
|
||||||
@ -151,6 +155,7 @@ def cancel_appointment(appointment_id):
|
|||||||
else:
|
else:
|
||||||
frappe.msgprint(_('Appointment Cancelled'))
|
frappe.msgprint(_('Appointment Cancelled'))
|
||||||
|
|
||||||
|
|
||||||
def validate_appointment_in_fee_validity(appointment, valid_end_date, ref_invoice):
|
def validate_appointment_in_fee_validity(appointment, valid_end_date, ref_invoice):
|
||||||
valid_days = frappe.db.get_single_value('Healthcare Settings', 'valid_days')
|
valid_days = frappe.db.get_single_value('Healthcare Settings', 'valid_days')
|
||||||
max_visit = frappe.db.get_single_value('Healthcare Settings', 'max_visit')
|
max_visit = frappe.db.get_single_value('Healthcare Settings', 'max_visit')
|
||||||
@ -172,6 +177,7 @@ def validate_appointment_in_fee_validity(appointment, valid_end_date, ref_invoic
|
|||||||
return True
|
return True
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
||||||
def cancel_sales_invoice(sales_invoice):
|
def cancel_sales_invoice(sales_invoice):
|
||||||
if frappe.db.get_single_value('Healthcare Settings', 'automate_appointment_invoicing'):
|
if frappe.db.get_single_value('Healthcare Settings', 'automate_appointment_invoicing'):
|
||||||
if len(sales_invoice.items) == 1:
|
if len(sales_invoice.items) == 1:
|
||||||
@ -179,6 +185,7 @@ def cancel_sales_invoice(sales_invoice):
|
|||||||
return True
|
return True
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
||||||
def check_si_item_exists(appointment):
|
def check_si_item_exists(appointment):
|
||||||
return frappe.db.exists(
|
return frappe.db.exists(
|
||||||
'Sales Invoice Item',
|
'Sales Invoice Item',
|
||||||
@ -188,6 +195,7 @@ def check_si_item_exists(appointment):
|
|||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
def check_sales_invoice_exists(appointment):
|
def check_sales_invoice_exists(appointment):
|
||||||
si_item = check_si_item_exists(appointment)
|
si_item = check_si_item_exists(appointment)
|
||||||
if si_item:
|
if si_item:
|
||||||
@ -195,6 +203,7 @@ def check_sales_invoice_exists(appointment):
|
|||||||
return sales_invoice
|
return sales_invoice
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
||||||
@frappe.whitelist()
|
@frappe.whitelist()
|
||||||
def get_availability_data(date, practitioner):
|
def get_availability_data(date, practitioner):
|
||||||
"""
|
"""
|
||||||
@ -223,6 +232,7 @@ def get_availability_data(date, practitioner):
|
|||||||
|
|
||||||
return {'slot_details': slot_details}
|
return {'slot_details': slot_details}
|
||||||
|
|
||||||
|
|
||||||
def check_employee_wise_availability(date, practitioner_doc):
|
def check_employee_wise_availability(date, practitioner_doc):
|
||||||
employee = None
|
employee = None
|
||||||
if practitioner_doc.employee:
|
if practitioner_doc.employee:
|
||||||
@ -245,6 +255,7 @@ def check_employee_wise_availability(date, practitioner_doc):
|
|||||||
else:
|
else:
|
||||||
frappe.throw(_('{0} is on Leave on {1}').format(practitioner_doc.name, date))
|
frappe.throw(_('{0} is on Leave on {1}').format(practitioner_doc.name, date))
|
||||||
|
|
||||||
|
|
||||||
def get_available_slots(practitioner_schedules, date):
|
def get_available_slots(practitioner_schedules, date):
|
||||||
available_slots = []
|
available_slots = []
|
||||||
slot_details = []
|
slot_details = []
|
||||||
@ -315,6 +326,7 @@ def send_confirmation_msg(doc):
|
|||||||
message = frappe.db.get_single_value('Healthcare Settings', 'appointment_confirmation_msg')
|
message = frappe.db.get_single_value('Healthcare Settings', 'appointment_confirmation_msg')
|
||||||
send_message(doc, message)
|
send_message(doc, message)
|
||||||
|
|
||||||
|
|
||||||
@frappe.whitelist()
|
@frappe.whitelist()
|
||||||
def make_encounter(source_name, target_doc=None):
|
def make_encounter(source_name, target_doc=None):
|
||||||
doc = get_mapped_doc('Patient Appointment', source_name, {
|
doc = get_mapped_doc('Patient Appointment', source_name, {
|
||||||
@ -331,25 +343,26 @@ def make_encounter(source_name, target_doc=None):
|
|||||||
]
|
]
|
||||||
}
|
}
|
||||||
}, target_doc)
|
}, target_doc)
|
||||||
|
|
||||||
return doc
|
return doc
|
||||||
|
|
||||||
def remind_appointment():
|
|
||||||
|
def send_appointment_reminder():
|
||||||
if frappe.db.get_single_value('Healthcare Settings', 'send_appointment_reminder'):
|
if frappe.db.get_single_value('Healthcare Settings', 'send_appointment_reminder'):
|
||||||
remind_before = datetime.datetime.strptime(frappe.get_single_value('Healthcare Settings', 'remind_before'), '%H:%M:%S')
|
remind_before = datetime.datetime.strptime(frappe.db.get_single_value('Healthcare Settings', 'remind_before'), '%H:%M:%S')
|
||||||
reminder_dt = datetime.datetime.now() + datetime.timedelta(
|
reminder_dt = datetime.datetime.now() + datetime.timedelta(
|
||||||
hours=remind_before.hour, minutes=remind_before.minute, seconds=remind_before.second)
|
hours=remind_before.hour, minutes=remind_before.minute, seconds=remind_before.second)
|
||||||
|
|
||||||
appointment_list = frappe.db.sql(
|
appointment_list = frappe.db.get_all('Patient Appointment', {
|
||||||
'select name from `tabPatient Appointment` where start_dt between %s and %s and reminded = 0 ',
|
'appointment_datetime': ['between', (datetime.datetime.now(), reminder_dt)],
|
||||||
(datetime.datetime.now(), reminder_dt)
|
'reminded': 0,
|
||||||
)
|
'status': ['!=', 'Cancelled']
|
||||||
|
})
|
||||||
|
|
||||||
for i in range(0, len(appointment_list)):
|
for appointment in appointment_list:
|
||||||
doc = frappe.get_doc('Patient Appointment', appointment_list[i][0])
|
doc = frappe.get_doc('Patient Appointment', appointment.name)
|
||||||
message = frappe.db.get_single_value('Healthcare Settings', 'appointment_reminder_msg')
|
message = frappe.db.get_single_value('Healthcare Settings', 'appointment_reminder_msg')
|
||||||
send_message(doc, message)
|
send_message(doc, message)
|
||||||
frappe.db.set_value('Patient Appointment', doc.name, 'reminded',1)
|
frappe.db.set_value('Patient Appointment', doc.name, 'reminded', 1)
|
||||||
|
|
||||||
def send_message(doc, message):
|
def send_message(doc, message):
|
||||||
patient = frappe.get_doc('Patient', doc.patient)
|
patient = frappe.get_doc('Patient', doc.patient)
|
||||||
@ -363,6 +376,7 @@ def send_message(doc, message):
|
|||||||
number = [patient.mobile]
|
number = [patient.mobile]
|
||||||
send_sms(number, message)
|
send_sms(number, message)
|
||||||
|
|
||||||
|
|
||||||
@frappe.whitelist()
|
@frappe.whitelist()
|
||||||
def get_events(start, end, filters=None):
|
def get_events(start, end, filters=None):
|
||||||
"""Returns events for Gantt / Calendar view rendering.
|
"""Returns events for Gantt / Calendar view rendering.
|
||||||
@ -372,7 +386,7 @@ def get_events(start, end, filters=None):
|
|||||||
:param filters: Filters (JSON).
|
:param filters: Filters (JSON).
|
||||||
"""
|
"""
|
||||||
from frappe.desk.calendar import get_event_conditions
|
from frappe.desk.calendar import get_event_conditions
|
||||||
conditions = get_event_conditions("Patient Appointment", filters)
|
conditions = get_event_conditions('Patient Appointment', filters)
|
||||||
|
|
||||||
data = frappe.db.sql("""
|
data = frappe.db.sql("""
|
||||||
select
|
select
|
||||||
@ -394,6 +408,7 @@ def get_events(start, end, filters=None):
|
|||||||
|
|
||||||
return data
|
return data
|
||||||
|
|
||||||
|
|
||||||
@frappe.whitelist()
|
@frappe.whitelist()
|
||||||
def get_procedure_prescribed(patient):
|
def get_procedure_prescribed(patient):
|
||||||
return frappe.db.sql("""select pp.name, pp.procedure, pp.parent, ct.practitioner,
|
return frappe.db.sql("""select pp.name, pp.procedure, pp.parent, ct.practitioner,
|
||||||
|
@ -273,7 +273,8 @@ auto_cancel_exempted_doctypes= [
|
|||||||
|
|
||||||
scheduler_events = {
|
scheduler_events = {
|
||||||
"all": [
|
"all": [
|
||||||
"erpnext.projects.doctype.project.project.project_status_update_reminder"
|
"erpnext.projects.doctype.project.project.project_status_update_reminder",
|
||||||
|
"erpnext.healthcare_healthcare.doctype.patient_appointment.patient_appointment.send_appointment_reminder"
|
||||||
],
|
],
|
||||||
"hourly": [
|
"hourly": [
|
||||||
'erpnext.hr.doctype.daily_work_summary_group.daily_work_summary_group.trigger_emails',
|
'erpnext.hr.doctype.daily_work_summary_group.daily_work_summary_group.trigger_emails',
|
||||||
|
Loading…
x
Reference in New Issue
Block a user