Fix Call next when Care waiters lack Queue tickets.
Deploy Ladill Care / deploy (push) Successful in 1m35s

Demo/pre-integration waiting lists showed patients but Call next hit an empty Queue and flashed a red error. Backfill missing tickets on Call next and queue load, and treat empty Call next as info.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
isaacclad
2026-07-17 16:53:52 +00:00
co-authored by Cursor
parent 015a4cc7fe
commit c5151ad476
11 changed files with 393 additions and 23 deletions
+1 -1
View File
@@ -72,7 +72,7 @@ class BillController extends Controller
$result = $this->queueBridge->callNext($organization, CareQueueContexts::BILLING, $branchId);
$ticket = $result['ticket'] ?? null;
if (! $ticket) {
return back()->with('error', 'No bills waiting in the billing queue.');
return back()->with('info', 'No bills waiting in the billing queue.');
}
return back()->with('success', 'Called '.$ticket['ticket_number'].'.');
@@ -96,7 +96,7 @@ class InvestigationController extends Controller
$result = $this->queueBridge->callNext($organization, CareQueueContexts::LABORATORY, $branchId);
$ticket = $result['ticket'] ?? null;
if (! $ticket) {
return back()->with('error', 'No lab work waiting in the laboratory queue.');
return back()->with('info', 'No lab work waiting in the laboratory queue.');
}
return back()->with('success', 'Called '.$ticket['ticket_number'].'.');
@@ -98,7 +98,7 @@ class PrescriptionController extends Controller
$result = $this->queueBridge->callNext($organization, CareQueueContexts::PHARMACY, $branchId);
$ticket = $result['ticket'] ?? null;
if (! $ticket) {
return back()->with('error', 'No prescriptions waiting in the pharmacy queue.');
return back()->with('info', 'No prescriptions waiting in the pharmacy queue.');
}
return back()->with('success', 'Called '.$ticket['ticket_number'].'.');
@@ -43,6 +43,13 @@ class QueueController extends Controller
$branchId = (int) ($request->input('branch_id') ?: $branchScope ?: $branches->first()?->id);
$practitionerId = $request->input('practitioner_id') ? (int) $request->input('practitioner_id') : null;
$queueIntegration = ['enabled' => false];
if ($branchId && $this->queueBridge->isEnabled($organization)) {
// Catch up tickets for waiters created before Queue was linked (demo / pre-enable).
$this->queueBridge->syncMissingTickets($organization, CareQueueContexts::CONSULTATION, $branchId, 25);
$queueIntegration = $this->queueBridge->listMeta($organization, CareQueueContexts::CONSULTATION, $branchId);
}
$queue = $branchId
? $this->appointments->queue($this->ownerRef($request), $branchId, $practitionerId)
: collect();
@@ -86,9 +93,7 @@ class QueueController extends Controller
'canManageQueue' => $canManageQueue,
'canConsult' => $canConsult,
'heroStats' => $heroStats,
'queueIntegration' => $branchId
? $this->queueBridge->listMeta($organization, CareQueueContexts::CONSULTATION, $branchId)
: ['enabled' => false],
'queueIntegration' => $queueIntegration,
]);
}
@@ -106,7 +111,7 @@ class QueueController extends Controller
$result = $this->queueBridge->callNext($organization, CareQueueContexts::CONSULTATION, $branchId);
$ticket = $result['ticket'] ?? null;
if (! $ticket) {
return back()->with('error', 'No patients waiting in the consultation queue.');
return back()->with('info', 'No patients waiting in the consultation queue.');
}
return back()->with('success', 'Called '.$ticket['ticket_number'].' — '.($ticket['customer_name'] ?? 'patient').'.');
@@ -9,6 +9,8 @@ use App\Services\Care\AppointmentPatientNotifier;
use App\Services\Care\AuditLogger;
use App\Services\Care\CareFeatures;
use App\Services\Care\CarePermissions;
use App\Services\Care\CareQueueBridge;
use App\Services\Care\CareQueueContexts;
use App\Services\Care\CareQueueProvisioner;
use App\Services\Care\PlanService;
use App\Services\Billing\PlatformEmailClient;
@@ -155,7 +157,22 @@ class SettingsController extends Controller
if ($wantsQueue && $queue->configured()) {
try {
$provisioner->provisionOrganization($organization->fresh());
$organization = $organization->fresh();
$provisioner->provisionOrganization($organization);
// Backfill tickets for patients already waiting when Queue was just linked.
$bridge = app(CareQueueBridge::class);
$branches = Branch::owned($owner)
->where('organization_id', $organization->id)
->where('is_active', true)
->pluck('id');
foreach ($branches as $branchId) {
foreach (array_keys(CareQueueContexts::departments()) as $context) {
if ($context === CareQueueContexts::RECEPTION) {
continue;
}
$bridge->syncMissingTickets($organization, $context, (int) $branchId, 50);
}
}
} catch (\Throwable) {
// Best-effort; role pages will lazy-ensure on next use.
}
@@ -97,7 +97,7 @@ class SpecialtyModuleController extends Controller
$result = $queueBridge->callNext($organization, $module, $branchId);
$ticket = $result['ticket'] ?? null;
if (! $ticket) {
return back()->with('error', 'No patients waiting in this specialty queue.');
return back()->with('info', 'No patients waiting in this specialty queue.');
}
return back()->with('success', 'Called '.$ticket['ticket_number'].'.');