46 lines
1.4 KiB
PHP
46 lines
1.4 KiB
PHP
<?php
|
|
namespace App\Models;
|
|
|
|
/**
|
|
* Class Room
|
|
* Massage Room Realtime Status Model
|
|
*
|
|
* @package App\Models
|
|
*/
|
|
class Room extends Model
|
|
{
|
|
protected string $table = 'rooms';
|
|
|
|
/**
|
|
* Get rooms by branch with current queue and patient info
|
|
*/
|
|
public function getStatusBoard(int $branchId): array
|
|
{
|
|
$sql = "SELECT r.*, q.queue_no, q.status AS queue_status,
|
|
CONCAT(p.first_name_th, ' ', p.last_name_th) AS patient_name,
|
|
CONCAT(u.first_name, ' ', u.last_name) AS therapist_name,
|
|
q.est_end_time
|
|
FROM `{$this->table}` r
|
|
LEFT JOIN `queues` q ON r.current_queue_id = q.id
|
|
LEFT JOIN `patients` p ON q.patient_id = p.id
|
|
LEFT JOIN `therapists` t ON q.therapist_id = t.id
|
|
LEFT JOIN `users` u ON t.user_id = u.id
|
|
WHERE r.branch_id = :bid AND r.is_active = 1
|
|
ORDER BY r.room_no ASC";
|
|
$stmt = self::getDB()->prepare($sql);
|
|
$stmt->execute(['bid' => $branchId]);
|
|
return $stmt->fetchAll();
|
|
}
|
|
|
|
/**
|
|
* Update room status
|
|
*/
|
|
public function updateStatus(int $roomId, string $status, ?int $queueId = null): bool
|
|
{
|
|
return $this->update($roomId, [
|
|
'status' => $status,
|
|
'current_queue_id' => $queueId,
|
|
]);
|
|
}
|
|
}
|