From 9821d51e319a1f05e6f959cfd6f96b64cee08351 Mon Sep 17 00:00:00 2001 From: mist-01 Date: Fri, 27 Jul 2018 09:32:03 +0400 Subject: [PATCH] Updated appointment availability to consider appointment duration in healthcare domain (#15011) * Updated appointment availability to consider appointment duration in healthcare domain. Fix bug - must clone moment before adding time to avoid updating original moment * Add spaces after comments --- .../patient_appointment.js | 24 +++++++++---------- 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/erpnext/healthcare/doctype/patient_appointment/patient_appointment.js b/erpnext/healthcare/doctype/patient_appointment/patient_appointment.js index 23ec85d074..9799018cea 100644 --- a/erpnext/healthcare/doctype/patient_appointment/patient_appointment.js +++ b/erpnext/healthcare/doctype/patient_appointment/patient_appointment.js @@ -159,25 +159,25 @@ frappe.ui.form.on('Patient Appointment', { slot_html = slot_html + `
` + slot_detail['avail_slot'].map(slot => { let disabled = ''; let start_str = slot.from_time; - let start_time = moment(slot.from_time, 'HH:mm:ss'); - let to_time = moment(slot.to_time, 'HH:mm:ss'); - let interval = (to_time - start_time)/60000 | 0; + let slot_start_time = moment(slot.from_time, 'HH:mm:ss'); + let slot_to_time = moment(slot.to_time, 'HH:mm:ss'); + let interval = (slot_to_time - slot_start_time)/60000 | 0; // iterate in all booked appointments, update the start time and duration slot_detail['appointments'].forEach(function(booked) { let booked_moment = moment(booked.appointment_time, 'HH:mm:ss'); - if(booked_moment.isSame(start_time) || booked_moment.isBetween(start_time, to_time)){ + let end_time = booked_moment.clone().add(booked.duration, 'minutes'); + // Deal with 0 duration appointments + if(booked_moment.isSame(slot_start_time) || booked_moment.isBetween(slot_start_time, slot_to_time)){ if(booked.duration == 0){ disabled = 'disabled="disabled"'; return false; } - start_time = booked_moment; - let end_time = booked_moment.add(booked.duration, 'minutes'); - if(end_time.isSameOrAfter(to_time) || end_time.add(duration).isAfter(to_time)){ - disabled = 'disabled="disabled"'; - return false; - }else{ - start_str = end_time.format('HH:mm:ss'); - } + } + // Check for overlaps considering appointment duration + if(slot_start_time.isBefore(end_time) && slot_to_time.isAfter(booked_moment)){ + // There is an overlap + disabled = 'disabled="disabled"'; + return false; } });