Skip to content

Commit

Permalink
feat: allow booking appointments against department / service_unit ba…
Browse files Browse the repository at this point in the history
…sed on appointment type
  • Loading branch information
akurungadam authored and akashkrishna619 committed Jul 25, 2023
1 parent 94a876c commit fd2e271
Show file tree
Hide file tree
Showing 2 changed files with 87 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,88 @@ frappe.ui.form.on('Patient Appointment', {
});
},

appointment_for: function(frm) {
if (frm.doc.appointment_for == 'Practitioner') {
if (!frm.doc.practitioner) {
frm.set_value('department', '');
}
frm.set_value('service_unit', '');
frm.trigger('set_check_availability_action');
} else if (frm.doc.appointment_for == 'Service Unit') {
frm.set_value({
'practitioner': '',
'practitioner_name': '',
'department': '',
});
frm.trigger('set_book_action');
} else if (frm.doc.appointment_for == 'Department') {
frm.set_value({
'practitioner': '',
'practitioner_name': '',
'service_unit': '',
});
frm.trigger('set_book_action');
} else {
if (frm.doc.appointment_for == 'Department') {
frm.set_value('service_unit', '');
}
frm.set_value({
'practitioner': '',
'practitioner_name': '',
'department': '',
'service_unit': '',
});
frm.page.clear_primary_action();
}
},

set_book_action: function(frm) {
frm.page.set_primary_action(__('Book'), function() {
frm.enable_save();
frm.save();
});
},

set_check_availability_action: function(frm) {
frm.page.set_primary_action(__('Check Availability'), function() {
if (!frm.doc.patient) {
frappe.msgprint({
title: __('Not Allowed'),
message: __('Please select Patient first'),
indicator: 'red'
});
} else {
frappe.call({
method: 'healthcare.healthcare.doctype.patient_appointment.patient_appointment.check_payment_fields_reqd',
args: { 'patient': frm.doc.patient },
callback: function(data) {
if (data.message == true) {
if (frm.doc.mode_of_payment && frm.doc.paid_amount) {
check_and_set_availability(frm);
}
if (!frm.doc.mode_of_payment) {
frappe.msgprint({
title: __('Not Allowed'),
message: __('Please select a Mode of Payment first'),
indicator: 'red'
});
}
if (!frm.doc.paid_amount) {
frappe.msgprint({
title: __('Not Allowed'),
message: __('Please set the Paid Amount first'),
indicator: 'red'
});
}
} else {
check_and_set_availability(frm);
}
}
});
}
});
},

patient: function(frm) {
if (frm.doc.patient) {
frm.trigger('toggle_payment_fields');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class OverlapError(frappe.ValidationError):
class PatientAppointment(Document):
def validate(self):
self.validate_overlaps()
self.validate_based_on_appointments_for()
self.validate_appointments_without_practitioner()
self.validate_service_unit()
self.set_appointment_datetime()
self.validate_customer_created()
Expand Down Expand Up @@ -166,8 +166,8 @@ def validate_overlaps(self):
OverlapError,
)

def validate_based_on_appointments_for(self):
if self.appointment_for:
def validate_appointments_without_practitioner(self):
if not self.practitioner and self.appointment_type:
# fieldname: practitioner / department / service_unit
appointment_for_field = frappe.scrub(self.appointment_for)

Expand All @@ -178,12 +178,7 @@ def validate_based_on_appointments_for(self):
frappe.MandatoryError,
)

if self.appointment_for == "Practitioner":
# appointments for practitioner are validated separately,
# based on practitioner schedule
return

# validate if patient already has an appointment for the day
# validate if patient already has an appointment
booked_appointment = frappe.db.exists(
"Patient Appointment",
{
Expand All @@ -197,7 +192,7 @@ def validate_based_on_appointments_for(self):

if booked_appointment:
frappe.throw(
_("Patient already has an appointment {} booked for {} on {}").format(
_("Patient already has an appointment {} booked at {} on {}").format(
get_link_to_form("Patient Appointment", booked_appointment),
frappe.bold(self.get(appointment_for_field)),
frappe.bold(format_date(self.appointment_date)),
Expand Down

0 comments on commit fd2e271

Please sign in to comment.