diff --git a/api/appointments.php b/api/appointments.php index 43f2566..d987b1d 100644 --- a/api/appointments.php +++ b/api/appointments.php @@ -2,6 +2,10 @@ require_once __DIR__ . '/../db/config.php'; require_once __DIR__ . '/../helpers.php'; +// Prevent caching +header('Cache-Control: no-cache, no-store, must-revalidate'); +header('Pragma: no-cache'); +header('Expires: 0'); header('Content-Type: application/json'); $db = db(); diff --git a/delete_test_appointment_cleanup.php b/delete_test_appointment_cleanup.php new file mode 100644 index 0000000..a9d2295 --- /dev/null +++ b/delete_test_appointment_cleanup.php @@ -0,0 +1,12 @@ +prepare("DELETE FROM appointments WHERE id = ?"); +$stmt->execute([$id]); + +echo "Deleted appointment $id\n"; + diff --git a/includes/pages/appointments.php b/includes/pages/appointments.php index 5e42c70..e884eb5 100644 --- a/includes/pages/appointments.php +++ b/includes/pages/appointments.php @@ -192,6 +192,56 @@ function toggleAddressField() { } } +function validateHolidayFrontend() { + if (!calendar) return; // Calendar not initialized yet + + var btnSave = document.getElementById('btnSaveApt'); + + // Reset state first to avoid getting stuck + $('#holidayWarning').remove(); + if (btnSave) btnSave.disabled = false; + + var providerType = $('#apt_provider_type').val(); + if (providerType === 'Nurse') return; + + var docId = $('#apt_doctor_id').val(); + var startTimeStr = $('#apt_start_time').val(); + + if (!docId || !startTimeStr) return; + + var datePrefix = startTimeStr.split('T')[0]; + var events = calendar.getEvents(); + var isHoliday = false; + + for (var i = 0; i < events.length; i++) { + var ev = events[i]; + // Check for doctor holiday events matching the selected doctor + if (ev.extendedProps && ev.extendedProps.type === 'doctor_holiday' && ev.extendedProps.doctor_id == docId) { + var evStartStr = ev.startStr ? ev.startStr.split('T')[0] : ''; + var evEndStr = ev.end ? ev.endStr.split('T')[0] : evStartStr; + + if (ev.allDay) { + // All day event: check if datePrefix is within range [start, end) + if (datePrefix >= evStartStr && datePrefix < evEndStr) { + isHoliday = true; + break; + } + } else { + // Daily block or single time point + if (datePrefix === evStartStr) { + isHoliday = true; + break; + } + } + } + } + + if (isHoliday) { + $('
Selected doctor is on holiday on this date.
').appendTo('#appointmentDetailsModal .modal-body'); + if (btnSave) btnSave.disabled = true; + } +} + function toggleProviderField() { var type = document.getElementById('apt_provider_type').value; var divDoc = document.getElementById('div_doctor'); @@ -200,7 +250,6 @@ function toggleProviderField() { if (type === 'Nurse') { divDoc.classList.add('d-none'); divNurse.classList.remove('d-none'); - // Clear doctor selection? Maybe not necessary, backend handles nulls based on logic } else { divDoc.classList.remove('d-none'); divNurse.classList.add('d-none'); @@ -447,59 +496,6 @@ document.addEventListener('DOMContentLoaded', function() { $('#apt_doctor_id').on('change', validateHolidayFrontend); $('#apt_start_time').on('change', validateHolidayFrontend); $('#apt_provider_type').on('change', validateHolidayFrontend); // Re-validate when provider changes - - function validateHolidayFrontend() { - var providerType = $('#apt_provider_type').val(); - if (providerType === 'Nurse') { - // Nurses don't have holiday checks yet - $('#holidayWarning').remove(); - document.getElementById('btnSaveApt').disabled = false; - return; - } - - var docId = $('#apt_doctor_id').val(); - var startTimeStr = $('#apt_start_time').val(); - var btnSave = document.getElementById('btnSaveApt'); - - if (!docId || !startTimeStr) return; - - var datePrefix = startTimeStr.split('T')[0]; - var events = calendar.getEvents(); - var isHoliday = false; - - for (var i = 0; i < events.length; i++) { - var ev = events[i]; - // We check against the allDay visible event OR background events - if (ev.extendedProps && ev.extendedProps.type === 'doctor_holiday' && ev.extendedProps.doctor_id == docId) { - var evStartStr = ev.startStr.split('T')[0]; - var evEndStr = ev.end ? ev.endStr.split('T')[0] : evStartStr; - - // If it's an allDay event, the end date might be exclusive (e.g. 17th means up to 16th 23:59:59) - // If it's our new daily block background event, start and end are the same day - if (ev.allDay) { - if (datePrefix >= evStartStr && datePrefix < evEndStr) { - isHoliday = true; - break; - } - } else { - if (datePrefix === evStartStr) { - isHoliday = true; - break; - } - } - } - } - - if (isHoliday) { - if ($('#holidayWarning').length === 0) { - $('
Selected doctor is on holiday on this date.
').appendTo('#appointmentDetailsModal .modal-body'); - } - btnSave.disabled = true; - } else { - $('#holidayWarning').remove(); - btnSave.disabled = false; - } - } });