public static function createNextAppointment($doctor_id, $appointment) { $freeSlots = DoctorTime::getFreeSlotByDoctor($doctor_id); foreach ($freeSlots as $freeSlot) { $datetime = $freeSlot['datetime']; if ($datetime < new \DateTime($appointment->time)) { continue; } return Appointment::makeAppointment($doctor_id, $appointment->patient_id, $datetime); } }
public function makeAppointment(Request $request) { if (!Patient::isPatient() && !HospitalEmployee::isStaff()) { return response()->json(["success" => false, "error" => 'notlogin or notvalid']); } $datetime = $request->input('datetime'); $emp_id = $request->input('doctor_id'); if (Patient::isPatient()) { $patient_id = Auth::user()->userable->id; } else { if (HospitalEmployee::isStaff()) { if (!$request->input('patient_id')) { return response()->json(["success" => false, "error" => 'no_patient_id']); } $patient_id = $request->input('patient_id'); } } return response()->json(["success" => true, "data" => Appointment::makeAppointment($emp_id, $patient_id, $datetime)]); }