The Appointments module manages the scheduling system for Nguhöe EHR. It includes doctor availability checking, conflict prevention, status management, and patient self-booking through the patient portal.
Appointments are accessible to Admin, Doctor, and Receptionist roles. Patients can book their own appointments through a dedicated portal.
The system checks doctor schedules and existing appointments to determine available slots:API Endpoint:GET /api/availability Controller:PatientPortalController@getAvailability
// Get availability for a specific doctor and date (PatientPortalController.php:39-95)$request->validate([ 'doctor_id' => 'required|exists:users,id', 'date' => 'required|date_format:Y-m-d',]);// 1. Get doctor's schedule for the day of week$schedule = DoctorSchedule::where('user_id', $doctor_id) ->where('day_of_week', $dayOfWeek) ->first();// 2. If doctor doesn't work that day, return emptyif (!$schedule || !$schedule->is_working) { return response()->json(['slots' => []]);}// 3. Generate 30-minute slots between start and end time// 4. Check each slot against existing appointments// 5. Mark slots as available or occupied
Staff can view and filter appointments (AppointmentController.php:18-42):
// Doctors only see their own appointmentsif ($request->user()->hasRole('doctor')) { $query->where('doctor_id', $request->user()->id);}// Filter by doctor (admin/receptionist)if ($request->has('doctor_id')) { $query->where('doctor_id', $request->get('doctor_id'));}// Filter by dateif ($request->has('date')) { $query->whereDate('start_time', $request->get('date'));}
// Appointment.php relationships// Belongs to Patientpublic function patient(): BelongsTo{ return $this->belongsTo(Patient::class);}// Belongs to Doctor (User)public function doctor(): BelongsTo{ return $this->belongsTo(User::class, 'doctor_id');}