Example #1
0
 public static function refreshDoctorTime($doctor_id)
 {
     $appointments = Appointment::where('emp_id', $doctor_id)->get();
     $doctorTimes = DoctorTime::where('doctor_id', $doctor_id)->get();
     foreach ($appointments as $appointment) {
         $aptime = new DateTime($appointment->time);
         $del = true;
         foreach ($doctorTimes as $doctorTime) {
             $begin = new DateTime($doctorTime->doctorTime_begin);
             $end = new DateTime($doctorTime->doctorTime_end);
             if ($aptime >= $begin && $aptime < $end) {
                 $del = false;
             }
         }
         if ($del) {
             // find a new appointment
             Appointment::createNextAppointment($doctor_id, $appointment);
             // delete the old one
             Appointment::deleteAppointment($appointment->appointment_id);
         }
     }
     $docTime = DoctorTime::orderBy('doctorTime_begin', 'asc')->where('doctor_id', $doctor_id)->get();
     return ["success" => true, "new doctorTime" => $docTime];
 }