Fix patient queue showing position 1 for every waiter.
Deploy Ladill Care / deploy (push) Successful in 1m44s

Specialty demo seed reused slot+1 per module; repair duplicates on queue load and renumber after demo seed so waiting lists show 1..n.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
isaacclad
2026-07-18 05:54:47 +00:00
co-authored by Cursor
parent 6cfecc1763
commit 4e910a1db7
3 changed files with 125 additions and 2 deletions
+33
View File
@@ -73,6 +73,8 @@ class AppointmentService
*/
public function queue(string $ownerRef, int $branchId, ?int $practitionerId = null): Collection
{
$this->repairDuplicateQueuePositions($ownerRef, $branchId);
$query = Appointment::owned($ownerRef)
->where('branch_id', $branchId)
->whereIn('status', [Appointment::STATUS_WAITING, Appointment::STATUS_CHECKED_IN])
@@ -381,6 +383,37 @@ class AppointmentService
return ($max ?? 0) + 1;
}
/**
* Demo specialty seed used to set every module's waiter to position 1.
* Repair duplicates in place so the patient queue shows 1..n.
*/
protected function repairDuplicateQueuePositions(string $ownerRef, int $branchId): void
{
$waiters = Appointment::owned($ownerRef)
->where('branch_id', $branchId)
->whereIn('status', [Appointment::STATUS_WAITING, Appointment::STATUS_CHECKED_IN])
->orderByRaw('COALESCE(waiting_at, checked_in_at, scheduled_at) asc')
->orderBy('id')
->get(['id', 'queue_position']);
if ($waiters->count() < 2) {
return;
}
$positions = $waiters->pluck('queue_position');
if ($positions->filter(fn ($p) => $p !== null)->unique()->count() === $waiters->count()) {
return;
}
foreach ($waiters as $index => $appointment) {
$position = $index + 1;
if ((int) $appointment->queue_position === $position) {
continue;
}
Appointment::whereKey($appointment->id)->update(['queue_position' => $position]);
}
}
protected function assertTransition(Appointment $appointment, string ...$allowedFrom): void
{
if (! in_array($appointment->status, $allowedFrom, true)) {