Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Need help with this function, gives overlapping times and does not appropriately give times appoitnment for new patients: function calculateAppointmentTime ( $isNewPatient, $desiredStartTime, $desiredEndTime )

Need help with this function, gives overlapping times and does not appropriately give times appoitnment for new patients:
function calculateAppointmentTime($isNewPatient, $desiredStartTime, $desiredEndTime){
$startTime = strtotime("09:00");
$endTime = strtotime("18:00");
$appointmentDuration =30*60;
if ($isNewPatient === "Yes"){
$appointmentDuration =60*60;
}
$desiredStartTime = empty($desiredStartTime)? $startTime : strtotime(date('Y-m-d').''. $desiredStartTime);
$desiredEndTime = empty($desiredEndTime)? $endTime : strtotime(date('Y-m-d').''. $desiredEndTime);
if ($desiredStartTime < $startTime || $desiredEndTime > $endTime){
return "* Constraints Violated";
}
$latestEndTime = $startTime;
foreach ($_SESSION['patients'] as $patient){
$patientEndTime = strtotime($patient['Appointment Time'])+ $appointmentDuration;
$latestEndTime = max($latestEndTime, $patientEndTime);
}
$driveTime =($index >0)? calculateDriveTime($_SESSION['patients'][$index -1]['Address Coordinates'], $addressc) : 0;
$appointmentTime = max($desiredStartTime, $latestEndTime)+ $driveTime;
while ($appointmentTime < $desiredEndTime){
$isSlotAvailable = true;
foreach ($_SESSION['patients'] as $patient){
$patientAppointmentTime = strtotime($patient['Appointment Time']);
$patientEndTime = $patientAppointmentTime + $appointmentDuration;
if (
($appointmentTime >= $patientAppointmentTime && $appointmentTime < $patientEndTime)||
($appointmentTime + $appointmentDuration > $patientAppointmentTime && $appointmentTime + $appointmentDuration <= $patientEndTime)
){
$isSlotAvailable = false;
break;
}
}
if ($isSlotAvailable){
if ($appointmentTime + $appointmentDuration <= $desiredEndTime){
break;
}
}
$appointmentTime += $appointmentDuration;
}
return date("g:i a", $appointmentTime);
}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

The Power Of Numbers In Health Care A Students Journey In Data Analysis

Authors: Kaiden

1st Edition

8119747887, 978-8119747887

More Books

Students also viewed these Databases questions