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:
@@ -506,6 +506,93 @@ class CareQueueBridgeTest extends TestCase
|
||||
Http::assertNothingSent();
|
||||
}
|
||||
|
||||
public function test_assigned_doctor_call_next_succeeds_with_waiting_appointments(): void
|
||||
{
|
||||
Http::fake();
|
||||
|
||||
// Provision consultation desks for an existing GP first so ensure() early-returns
|
||||
// with a points list that does not yet include the demo doctor we link next.
|
||||
$other = \App\Models\Practitioner::create([
|
||||
'owner_ref' => $this->owner->public_id,
|
||||
'organization_id' => $this->organization->id,
|
||||
'branch_id' => $this->branch->id,
|
||||
'name' => 'Dr. Other Desk',
|
||||
'room' => 'Room 1',
|
||||
'is_active' => true,
|
||||
]);
|
||||
|
||||
app(\App\Services\Care\CareQueueProvisioner::class)->ensure(
|
||||
$this->organization->fresh(),
|
||||
CareQueueContexts::CONSULTATION,
|
||||
$this->branch->id,
|
||||
);
|
||||
|
||||
$doctorUser = User::create([
|
||||
'public_id' => 'bridge-assigned-doc',
|
||||
'name' => 'Assigned Doctor',
|
||||
'email' => 'bridge-assigned@example.com',
|
||||
]);
|
||||
$doctorMember = Member::create([
|
||||
'owner_ref' => $this->owner->public_id,
|
||||
'organization_id' => $this->organization->id,
|
||||
'user_ref' => $doctorUser->public_id,
|
||||
'role' => 'doctor',
|
||||
'branch_id' => $this->branch->id,
|
||||
]);
|
||||
$doctor = \App\Models\Practitioner::create([
|
||||
'owner_ref' => $this->owner->public_id,
|
||||
'organization_id' => $this->organization->id,
|
||||
'branch_id' => $this->branch->id,
|
||||
'member_id' => $doctorMember->id,
|
||||
'user_ref' => $doctorUser->public_id,
|
||||
'name' => 'Dr. Assigned',
|
||||
'room' => 'Room 9',
|
||||
'is_active' => true,
|
||||
]);
|
||||
|
||||
Appointment::create([
|
||||
'owner_ref' => $this->owner->public_id,
|
||||
'organization_id' => $this->organization->id,
|
||||
'branch_id' => $this->branch->id,
|
||||
'patient_id' => $this->patient->id,
|
||||
'practitioner_id' => $doctor->id,
|
||||
'type' => Appointment::TYPE_WALK_IN,
|
||||
'status' => Appointment::STATUS_WAITING,
|
||||
'scheduled_at' => now(),
|
||||
'waiting_at' => now(),
|
||||
'queue_position' => 1,
|
||||
]);
|
||||
|
||||
// Board KPI / Assigned to you still lists the waiter.
|
||||
$this->actingAs($doctorUser)
|
||||
->get(route('care.queue.index', ['branch_id' => $this->branch->id]))
|
||||
->assertOk()
|
||||
->assertSee('Assigned to you')
|
||||
->assertSee('Ada Lovelace');
|
||||
|
||||
$response = $this->actingAs($doctorUser)
|
||||
->from(route('care.queue.index', ['branch_id' => $this->branch->id]))
|
||||
->post(route('care.queue.call-next'), [
|
||||
'branch_id' => $this->branch->id,
|
||||
])
|
||||
->assertSessionMissing('info')
|
||||
->assertSessionHas('success');
|
||||
|
||||
$appointment = Appointment::query()->where('practitioner_id', $doctor->id)->first();
|
||||
$this->assertNotNull($appointment?->queue_ticket_uuid);
|
||||
$this->assertSame('called', $appointment->queue_ticket_status);
|
||||
$response->assertRedirect(route('care.appointments.show', $appointment));
|
||||
|
||||
$this->assertDatabaseHas('care_service_points', [
|
||||
'organization_id' => $this->organization->id,
|
||||
'kind' => 'practitioner',
|
||||
'ref_id' => $doctor->id,
|
||||
'is_active' => true,
|
||||
]);
|
||||
$this->assertNotNull($other->fresh());
|
||||
Http::assertNothingSent();
|
||||
}
|
||||
|
||||
public function test_call_next_reclaims_ticket_from_wrong_desk_and_announces(): void
|
||||
{
|
||||
Http::fake();
|
||||
|
||||
Reference in New Issue
Block a user