fix: Validate Patient Appointment
diff --git a/erpnext/healthcare/doctype/patient_appointment/patient_appointment.py b/erpnext/healthcare/doctype/patient_appointment/patient_appointment.py
index 1176082..1f7e1b7 100755
--- a/erpnext/healthcare/doctype/patient_appointment/patient_appointment.py
+++ b/erpnext/healthcare/doctype/patient_appointment/patient_appointment.py
@@ -6,7 +6,7 @@
 import frappe
 from frappe.model.document import Document
 import json
-from frappe.utils import getdate, add_days
+from frappe.utils import getdate, add_days, get_time
 from frappe import _
 import datetime
 from frappe.core.doctype.sms_settings.sms_settings import send_sms
@@ -24,6 +24,27 @@
 			frappe.db.set_value("Patient Appointment", self.name, "status", "Open")
 			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):
 		if self.procedure_prescription:
 			frappe.db.set_value("Procedure Prescription", self.procedure_prescription, "appointment_booked", True)