52 lines
1.5 KiB
PHP
52 lines
1.5 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use CodeIgniter\Model;
|
|
|
|
class DoctorBookingModel extends Model
|
|
{
|
|
protected $table = 'doctor_bookings';
|
|
protected $primaryKey = 'id';
|
|
protected $useAutoIncrement = true;
|
|
protected $returnType = 'array';
|
|
protected $useSoftDeletes = false;
|
|
protected $protectFields = true;
|
|
protected $allowedFields = ['appointment_id', 'doctor_id', 'booking_date', 'booking_time', 'status', 'created_by'];
|
|
|
|
protected bool $allowEmptyInserts = false;
|
|
protected bool $updateOnlyChanged = true;
|
|
|
|
// Dates
|
|
protected $useTimestamps = false;
|
|
|
|
public function isDoctorBooked($doctorId, $date, $time): bool
|
|
{
|
|
return $this->where('doctor_id', $doctorId)
|
|
->where('booking_date', $date)
|
|
->where('booking_time', $time)
|
|
->where('status', 'assigned')
|
|
->countAllResults() > 0;
|
|
}
|
|
|
|
public function syncBooking(int $appointmentId, int $doctorId, string $date, string $time, string $status, ?int $createdBy = null)
|
|
{
|
|
$existing = $this->where('appointment_id', $appointmentId)->first();
|
|
|
|
$data = [
|
|
'appointment_id' => $appointmentId,
|
|
'doctor_id' => $doctorId,
|
|
'booking_date' => $date,
|
|
'booking_time' => $time,
|
|
'status' => $status,
|
|
'created_by' => $createdBy
|
|
];
|
|
|
|
if ($existing) {
|
|
return $this->update($existing['id'], $data);
|
|
}
|
|
|
|
return $this->insert($data);
|
|
}
|
|
}
|