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]; }
public function deleteDoctorTime($doctor_time_id) { if (!HospitalEmployee::isDoctor()) { return response()->json(["success" => false, "messages" => ['notlogin or notvalid']]); } // if(!HospitalEmployee::isDoctor()) // return response()->json(["success" = false]; $doctorTime = DoctorTime::where('doctorTime_id', $doctor_time_id)->first(); if ($doctorTime) { $doctorTime->delete(); } return response()->json(["success" => true]); }