Fix patient queue showing position 1 for every waiter.
Deploy Ladill Care / deploy (push) Successful in 1m44s
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:
@@ -125,7 +125,6 @@ class DemoTenantSeeder
|
||||
$ownerRef,
|
||||
$volumes,
|
||||
);
|
||||
$this->assignAllDemoWaiters($organization, $ownerRef, $branches, $practitioners);
|
||||
if (in_array($plan, ['pro', 'enterprise'], true)) {
|
||||
$appointmentCount += $this->seedSpecialtyDemoData(
|
||||
$organization->fresh(),
|
||||
@@ -135,6 +134,8 @@ class DemoTenantSeeder
|
||||
$ownerRef,
|
||||
);
|
||||
}
|
||||
$this->assignAllDemoWaiters($organization, $ownerRef, $branches, $practitioners);
|
||||
$this->renumberWaitingQueuePositions($organization, $ownerRef, $branches);
|
||||
|
||||
if ($volumes['paid_modules']) {
|
||||
$this->seedPaidModules(
|
||||
@@ -297,6 +298,39 @@ class DemoTenantSeeder
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Give each waiting/checked-in appointment a unique 1..n position per branch.
|
||||
*
|
||||
* @param list<Branch> $branches
|
||||
*/
|
||||
private function renumberWaitingQueuePositions(
|
||||
Organization $organization,
|
||||
string $ownerRef,
|
||||
array $branches,
|
||||
): void {
|
||||
foreach ($branches as $branch) {
|
||||
$waiters = Appointment::withTrashed()
|
||||
->owned($ownerRef)
|
||||
->where('organization_id', $organization->id)
|
||||
->where('branch_id', $branch->id)
|
||||
->whereIn('status', [Appointment::STATUS_WAITING, Appointment::STATUS_CHECKED_IN])
|
||||
->orderByRaw('COALESCE(waiting_at, checked_in_at, scheduled_at) asc')
|
||||
->orderBy('id')
|
||||
->get();
|
||||
|
||||
foreach ($waiters as $index => $appointment) {
|
||||
$position = $index + 1;
|
||||
if ((int) $appointment->queue_position === $position) {
|
||||
continue;
|
||||
}
|
||||
$appointment->forceFill([
|
||||
'queue_position' => $position,
|
||||
'deleted_at' => null,
|
||||
])->save();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Ensure the demo tenant has an onboarded organization + owner member.
|
||||
* Safe to call on the SSO request path before redirecting.
|
||||
@@ -751,6 +785,8 @@ class DemoTenantSeeder
|
||||
|
||||
$count = 0;
|
||||
$catalog = config('care.specialty_modules', []);
|
||||
/** @var array<int, int> $nextPositionByBranch */
|
||||
$nextPositionByBranch = [];
|
||||
foreach ($catalog as $key => $definition) {
|
||||
$type = (string) ($definition['department_type'] ?? '');
|
||||
if ($type === '') {
|
||||
@@ -814,6 +850,13 @@ class DemoTenantSeeder
|
||||
);
|
||||
}
|
||||
|
||||
$inQueue = in_array($status, [Appointment::STATUS_WAITING, Appointment::STATUS_CHECKED_IN], true);
|
||||
$queuePosition = null;
|
||||
if ($inQueue) {
|
||||
$nextPositionByBranch[$branch->id] = ($nextPositionByBranch[$branch->id] ?? 0) + 1;
|
||||
$queuePosition = $nextPositionByBranch[$branch->id];
|
||||
}
|
||||
|
||||
Appointment::withTrashed()->updateOrCreate(
|
||||
['uuid' => $this->demoUuid("appt|{$ownerRef}|{$token}")],
|
||||
[
|
||||
@@ -828,11 +871,12 @@ class DemoTenantSeeder
|
||||
'status' => $status,
|
||||
'scheduled_at' => $scheduledAt,
|
||||
'checked_in_at' => $visit?->checked_in_at,
|
||||
'waiting_at' => $inQueue ? $scheduledAt->copy()->addMinutes(5) : null,
|
||||
'completed_at' => $status === Appointment::STATUS_COMPLETED
|
||||
? $scheduledAt->copy()->addHour()
|
||||
: null,
|
||||
'cancelled_at' => null,
|
||||
'queue_position' => $slot + 1,
|
||||
'queue_position' => $queuePosition,
|
||||
'reason' => $moduleReasons[$slot % count($moduleReasons)],
|
||||
'created_by' => $ownerRef,
|
||||
'deleted_at' => null,
|
||||
|
||||
Reference in New Issue
Block a user