fix: Validate Patient Appointment
This commit is contained in:
parent
c0097ad729
commit
52ac72e63e
@ -6,7 +6,7 @@ from __future__ import unicode_literals
|
|||||||
import frappe
|
import frappe
|
||||||
from frappe.model.document import Document
|
from frappe.model.document import Document
|
||||||
import json
|
import json
|
||||||
from frappe.utils import getdate, add_days
|
from frappe.utils import getdate, add_days, get_time
|
||||||
from frappe import _
|
from frappe import _
|
||||||
import datetime
|
import datetime
|
||||||
from frappe.core.doctype.sms_settings.sms_settings import send_sms
|
from frappe.core.doctype.sms_settings.sms_settings import send_sms
|
||||||
@ -24,6 +24,27 @@ class PatientAppointment(Document):
|
|||||||
frappe.db.set_value("Patient Appointment", self.name, "status", "Open")
|
frappe.db.set_value("Patient Appointment", self.name, "status", "Open")
|
||||||
self.reload()
|
self.reload()
|
||||||
|
|
||||||
|
def validate(self):
|
||||||
|
end_time = datetime.datetime.combine(getdate(self.appointment_date), get_time(self.appointment_time)) + datetime.timedelta(minutes=float(self.duration))
|
||||||
|
overlaps = frappe.db.sql("""
|
||||||
|
select
|
||||||
|
name, practitioner, patient, appointment_time, duration
|
||||||
|
from
|
||||||
|
`tabPatient Appointment`
|
||||||
|
where
|
||||||
|
appointment_date=%s and name!=%s and status NOT IN ("Closed", "Cancelled")
|
||||||
|
and (practitioner=%s or patient=%s) and
|
||||||
|
((appointment_time<%s and appointment_time + INTERVAL duration MINUTE>%s) or
|
||||||
|
(appointment_time>%s and appointment_time<%s) or
|
||||||
|
(appointment_time=%s))
|
||||||
|
""", (self.appointment_date, self.name, self.practitioner, self.patient,
|
||||||
|
self.appointment_time, end_time.time(), self.appointment_time, end_time.time(), self.appointment_time))
|
||||||
|
|
||||||
|
print (overlaps)
|
||||||
|
if overlaps:
|
||||||
|
frappe.throw(_("""Appointment overlaps with {0}.<br> {1} has appointment scheduled
|
||||||
|
with {2} at {3} having {4} minute(s) duration.""").format(overlaps[0][0], overlaps[0][1], overlaps[0][2], overlaps[0][3], overlaps[0][4]))
|
||||||
|
|
||||||
def after_insert(self):
|
def after_insert(self):
|
||||||
if self.procedure_prescription:
|
if self.procedure_prescription:
|
||||||
frappe.db.set_value("Procedure Prescription", self.procedure_prescription, "appointment_booked", True)
|
frappe.db.set_value("Procedure Prescription", self.procedure_prescription, "appointment_booked", True)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user