adding home visit

This commit is contained in:
Flatlogic Bot 2026-03-17 09:31:25 +00:00
parent 9a2dea5596
commit 43f495d39b
3 changed files with 66 additions and 54 deletions

View File

@ -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();

View File

@ -0,0 +1,12 @@
<?php
require_once __DIR__ . '/db/config.php';
require_once __DIR__ . '/helpers.php';
$db = db();
$id = 15;
$stmt = $db->prepare("DELETE FROM appointments WHERE id = ?");
$stmt->execute([$id]);
echo "Deleted appointment $id\n";

View File

@ -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) {
$('<div id="holidayWarning" class="alert alert-warning mt-3 mb-0 small"><i class="bi bi-exclamation-triangle"></i> Selected doctor is on holiday on this date.</div>').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) {
$('<div id="holidayWarning" class="alert alert-warning mt-3 mb-0 small"><i class="bi bi-exclamation-triangle"></i> Selected doctor is on holiday on this date.</div>').appendTo('#appointmentDetailsModal .modal-body');
}
btnSave.disabled = true;
} else {
$('#holidayWarning').remove();
btnSave.disabled = false;
}
}
});
</script>