Fix Call next when doctor desk is missing from cached points.
Deploy Ladill Care / deploy (push) Successful in 48s
Deploy Ladill Care / deploy (push) Successful in 48s
Assigned doctors could see board waiters while Call next returned empty because ensure() early-returned without provisioning a newly linked desk. Re-provision on point miss, recover stale tickets, and align empty messaging with visible waiters. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -455,16 +455,37 @@ class CareQueueBridge
|
||||
): array {
|
||||
$empty = ['ticket' => null, 'entity' => null, 'resources' => $resources];
|
||||
|
||||
$appointment = $this->nextCallableAppointment($organization, $context, $branchId, $practitionerId);
|
||||
if (! $appointment) {
|
||||
$candidates = $this->callableAppointments($organization, $context, $branchId, $practitionerId);
|
||||
if ($candidates === []) {
|
||||
$this->syncMissingTickets($organization, $context, $branchId, 25);
|
||||
$appointment = $this->nextCallableAppointment($organization, $context, $branchId, $practitionerId);
|
||||
$candidates = $this->callableAppointments($organization, $context, $branchId, $practitionerId);
|
||||
}
|
||||
|
||||
if (! $appointment) {
|
||||
return $empty;
|
||||
foreach ($candidates as $appointment) {
|
||||
$called = $this->callSpecificAppointment($organization, $context, $branchId, $appointment, $resources, $point);
|
||||
if ($called['ticket']) {
|
||||
return $called;
|
||||
}
|
||||
}
|
||||
|
||||
return $empty;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array{queue_uuid?: ?string, counter_uuid?: ?string, points?: list<array<string, mixed>>} $resources
|
||||
* @param array<string, mixed> $point
|
||||
* @return array{ticket: ?array<string, mixed>, entity: ?Model, resources: array<string, mixed>}
|
||||
*/
|
||||
protected function callSpecificAppointment(
|
||||
Organization $organization,
|
||||
string $context,
|
||||
int $branchId,
|
||||
Appointment $appointment,
|
||||
array $resources,
|
||||
array $point,
|
||||
): array {
|
||||
$empty = ['ticket' => null, 'entity' => null, 'resources' => $resources];
|
||||
|
||||
if (blank($appointment->queue_ticket_uuid)) {
|
||||
$appointment = $this->issueForAppointment(
|
||||
$organization,
|
||||
@@ -505,6 +526,43 @@ class CareQueueBridge
|
||||
(string) $point['counter_uuid'],
|
||||
);
|
||||
|
||||
// Stale uuid / wrong queue / non-waiting row — clear and re-issue onto this desk.
|
||||
if (! $ticket) {
|
||||
$appointment->forceFill([
|
||||
'queue_ticket_uuid' => null,
|
||||
'queue_ticket_number' => null,
|
||||
'queue_ticket_status' => null,
|
||||
'queue_service_point_uuid' => null,
|
||||
])->save();
|
||||
|
||||
$ticket = $this->issue(
|
||||
$organization,
|
||||
$context,
|
||||
$branchId,
|
||||
$appointment->patient,
|
||||
[
|
||||
'care_entity' => 'appointment',
|
||||
'care_entity_uuid' => $appointment->uuid,
|
||||
'care_entity_id' => $appointment->id,
|
||||
'practitioner_id' => $appointment->practitioner_id,
|
||||
],
|
||||
$appointment->type === Appointment::TYPE_WALK_IN ? 'walk_in' : 'appointment',
|
||||
'appointment',
|
||||
$point,
|
||||
);
|
||||
if (! $ticket) {
|
||||
return $empty;
|
||||
}
|
||||
$this->applyTicket($appointment, $ticket, $point);
|
||||
$appointment = $appointment->fresh() ?? $appointment;
|
||||
|
||||
$ticket = $this->attemptCallWaitingTicket(
|
||||
$organization,
|
||||
(string) $appointment->queue_ticket_uuid,
|
||||
(string) $point['counter_uuid'],
|
||||
);
|
||||
}
|
||||
|
||||
if (! $ticket) {
|
||||
return $empty;
|
||||
}
|
||||
@@ -518,12 +576,15 @@ class CareQueueBridge
|
||||
];
|
||||
}
|
||||
|
||||
protected function nextCallableAppointment(
|
||||
/**
|
||||
* @return list<Appointment>
|
||||
*/
|
||||
protected function callableAppointments(
|
||||
Organization $organization,
|
||||
string $context,
|
||||
int $branchId,
|
||||
?int $practitionerId,
|
||||
): ?Appointment {
|
||||
): array {
|
||||
$owner = (string) $organization->owner_ref;
|
||||
|
||||
$query = Appointment::owned($owner)
|
||||
@@ -546,6 +607,7 @@ class CareQueueBridge
|
||||
$query->where('practitioner_id', $practitionerId);
|
||||
}
|
||||
|
||||
$callable = [];
|
||||
foreach ($query->get() as $appointment) {
|
||||
if ($this->contextForAppointment($organization, $appointment) !== $context) {
|
||||
continue;
|
||||
@@ -557,10 +619,10 @@ class CareQueueBridge
|
||||
continue;
|
||||
}
|
||||
|
||||
return $appointment;
|
||||
$callable[] = $appointment;
|
||||
}
|
||||
|
||||
return null;
|
||||
return $callable;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user