'date', ]; /** * Relasi ke User (sebagai Pasien). */ public function patient() { return $this->belongsTo(User::class, 'patient_id'); } /** * Relasi ke Dokter (Tabel Doctors). */ public function doctor() { // Diarahkan ke model Doctor, bukan User return $this->belongsTo(Doctor::class, 'doctor_id'); } /** * Relasi ke Kategori Layanan (Poli). */ public function serviceCategory() { return $this->belongsTo(ServiceCategory::class, 'service_category_id'); } /** * Relasi ke MedicalRecord (jika sudah ada rekam medis untuk appointment ini). */ public function medicalRecord() { return $this->hasOne(MedicalRecord::class, 'appointment_id'); } /** * Relasi ke User (siapa yang membuat data ini, Admin atau Pasien sendiri). */ public function creator() { return $this->belongsTo(User::class, 'created_by'); } /** * Scope untuk mempermudah filter antrean hari ini. */ public function scopeToday($query) { return $query->whereDate('appointment_date', today()); } public static function generateNextQueue($date) { return self::whereDate('appointment_date', $date)->count() + 1; } }