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
This commit is contained in:
parent
f71d18a35a
commit
9821d51e31
@ -159,25 +159,25 @@ frappe.ui.form.on('Patient Appointment', {
|
|||||||
slot_html = slot_html + `<br/>` + slot_detail['avail_slot'].map(slot => {
|
slot_html = slot_html + `<br/>` + slot_detail['avail_slot'].map(slot => {
|
||||||
let disabled = '';
|
let disabled = '';
|
||||||
let start_str = slot.from_time;
|
let start_str = slot.from_time;
|
||||||
let start_time = moment(slot.from_time, 'HH:mm:ss');
|
let slot_start_time = moment(slot.from_time, 'HH:mm:ss');
|
||||||
let to_time = moment(slot.to_time, 'HH:mm:ss');
|
let slot_to_time = moment(slot.to_time, 'HH:mm:ss');
|
||||||
let interval = (to_time - start_time)/60000 | 0;
|
let interval = (slot_to_time - slot_start_time)/60000 | 0;
|
||||||
// iterate in all booked appointments, update the start time and duration
|
// iterate in all booked appointments, update the start time and duration
|
||||||
slot_detail['appointments'].forEach(function(booked) {
|
slot_detail['appointments'].forEach(function(booked) {
|
||||||
let booked_moment = moment(booked.appointment_time, 'HH:mm:ss');
|
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){
|
if(booked.duration == 0){
|
||||||
disabled = 'disabled="disabled"';
|
disabled = 'disabled="disabled"';
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
start_time = booked_moment;
|
}
|
||||||
let end_time = booked_moment.add(booked.duration, 'minutes');
|
// Check for overlaps considering appointment duration
|
||||||
if(end_time.isSameOrAfter(to_time) || end_time.add(duration).isAfter(to_time)){
|
if(slot_start_time.isBefore(end_time) && slot_to_time.isAfter(booked_moment)){
|
||||||
disabled = 'disabled="disabled"';
|
// There is an overlap
|
||||||
return false;
|
disabled = 'disabled="disabled"';
|
||||||
}else{
|
return false;
|
||||||
start_str = end_time.format('HH:mm:ss');
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user