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:
@@ -475,6 +475,10 @@ class CareQueueProvisioner
|
||||
/**
|
||||
* Resolve a service point for a practitioner on a queue context.
|
||||
*
|
||||
* When a doctor is linked after queues were first provisioned, ensure() may
|
||||
* early-return with a stale points list — refresh provisioning on miss so
|
||||
* Call next can still reach board waiters assigned to that desk.
|
||||
*
|
||||
* @return array<string, mixed>|null
|
||||
*/
|
||||
public function pointForPractitioner(
|
||||
@@ -482,17 +486,93 @@ class CareQueueProvisioner
|
||||
int $branchId,
|
||||
int $practitionerId,
|
||||
string $context = CareQueueContexts::CONSULTATION,
|
||||
): ?array {
|
||||
$point = $this->findPractitionerPoint($organization, $context, $branchId, $practitionerId);
|
||||
if ($point && ! empty($point['counter_uuid'])) {
|
||||
return $point;
|
||||
}
|
||||
|
||||
if (! $this->shouldProvision($organization)) {
|
||||
return $this->practitionerPointFromDb($organization, $context, $branchId, $practitionerId);
|
||||
}
|
||||
|
||||
if (CareQueueContexts::isSpecialty($context)) {
|
||||
$this->provisionSpecialtyContextBranch($organization->fresh() ?? $organization, $context, $branchId);
|
||||
} elseif (CareQueueContexts::isDepartment($context)) {
|
||||
$this->provisionContextBranch($organization->fresh() ?? $organization, $context, $branchId);
|
||||
} else {
|
||||
return $this->practitionerPointFromDb($organization, $context, $branchId, $practitionerId);
|
||||
}
|
||||
|
||||
$organization = $organization->fresh() ?? $organization;
|
||||
$point = $this->findPractitionerPoint($organization, $context, $branchId, $practitionerId);
|
||||
if ($point && ! empty($point['counter_uuid'])) {
|
||||
return $point;
|
||||
}
|
||||
|
||||
return $this->practitionerPointFromDb($organization, $context, $branchId, $practitionerId);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<string, mixed>|null
|
||||
*/
|
||||
protected function findPractitionerPoint(
|
||||
Organization $organization,
|
||||
string $context,
|
||||
int $branchId,
|
||||
int $practitionerId,
|
||||
): ?array {
|
||||
$resources = $this->resourcesFor($organization, $context, $branchId);
|
||||
if (! $resources) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return collect($resources['points'])->first(
|
||||
return collect($resources['points'] ?? [])->first(
|
||||
fn ($p) => ($p['kind'] ?? '') === 'practitioner' && (int) ($p['ref_id'] ?? 0) === $practitionerId
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<string, mixed>|null
|
||||
*/
|
||||
protected function practitionerPointFromDb(
|
||||
Organization $organization,
|
||||
string $context,
|
||||
int $branchId,
|
||||
int $practitionerId,
|
||||
): ?array {
|
||||
$row = CareServicePoint::query()
|
||||
->where('organization_id', $organization->id)
|
||||
->where('kind', 'practitioner')
|
||||
->where('ref_id', $practitionerId)
|
||||
->where('is_active', true)
|
||||
->whereHas(
|
||||
'serviceQueue',
|
||||
fn ($q) => $q
|
||||
->where('organization_id', $organization->id)
|
||||
->where('context', $context)
|
||||
->where('branch_id', $branchId)
|
||||
->where('is_active', true),
|
||||
)
|
||||
->first();
|
||||
|
||||
if (! $row) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return [
|
||||
'kind' => 'practitioner',
|
||||
'ref_id' => $practitionerId,
|
||||
'name' => $row->name,
|
||||
'destination' => $row->destination,
|
||||
'staff_ref' => $row->staff_ref,
|
||||
'staff_display_name' => $row->staff_display_name,
|
||||
'external_key' => $row->external_key,
|
||||
'counter_uuid' => $row->uuid,
|
||||
'synced' => true,
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<string, mixed>|null
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user