Route Care tickets to per-staff service points instead of shared branch queues.
Deploy Ladill Care / deploy (push) Successful in 1m40s
Deploy Ladill Care / deploy (push) Successful in 1m40s
Provision one consultation point per doctor (room + identity) and role-based points for pharmacy, lab, billing, and triage. Fixed-doctor appointments and walk-ins issue only to the assigned point; Call next respects that assignment and flags unresolved patients rather than random routing. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -80,10 +80,18 @@ class CareQueueBridgeTest extends TestCase
|
||||
'prefix' => 'C',
|
||||
'active' => true,
|
||||
'synced' => true,
|
||||
'routing_mode' => 'assigned_only',
|
||||
'queue_uuid' => 'aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa',
|
||||
'counter_uuid' => 'bbbbbbbb-bbbb-bbbb-bbbb-bbbbbbbbbbbb',
|
||||
'queue_external_key' => CareQueueContexts::queueExternalKey(CareQueueContexts::CONSULTATION, $this->branch->id),
|
||||
'counter_external_key' => CareQueueContexts::counterExternalKey(CareQueueContexts::CONSULTATION, $this->branch->id),
|
||||
'points' => [[
|
||||
'kind' => 'practitioner',
|
||||
'ref_id' => 0, // filled after practitioner create in tests that need it
|
||||
'destination' => 'Consultation desk',
|
||||
'counter_uuid' => 'bbbbbbbb-bbbb-bbbb-bbbb-bbbbbbbbbbbb',
|
||||
'synced' => true,
|
||||
]],
|
||||
]],
|
||||
],
|
||||
];
|
||||
@@ -103,13 +111,38 @@ class CareQueueBridgeTest extends TestCase
|
||||
|
||||
public function test_check_in_issues_consultation_ticket_when_integration_on(): void
|
||||
{
|
||||
$practitioner = \App\Models\Practitioner::create([
|
||||
'owner_ref' => $this->owner->public_id,
|
||||
'organization_id' => $this->organization->id,
|
||||
'branch_id' => $this->branch->id,
|
||||
'name' => 'Dr. Bridge',
|
||||
'room' => 'Room 1',
|
||||
'is_active' => true,
|
||||
]);
|
||||
|
||||
$settings = $this->organization->settings;
|
||||
$settings['department_queue_provisioning'][CareQueueContexts::CONSULTATION]['queues'][0]['points'] = [[
|
||||
'kind' => 'practitioner',
|
||||
'ref_id' => $practitioner->id,
|
||||
'destination' => 'Room 1',
|
||||
'staff_display_name' => 'Dr. Bridge',
|
||||
'counter_uuid' => 'bbbbbbbb-bbbb-bbbb-bbbb-bbbbbbbbbbbb',
|
||||
'synced' => true,
|
||||
]];
|
||||
$this->organization->update(['settings' => $settings]);
|
||||
|
||||
Http::fake(function (\Illuminate\Http\Client\Request $request) {
|
||||
if (str_contains($request->url(), '/tickets') && $request->method() === 'POST') {
|
||||
$this->assertSame('bbbbbbbb-bbbb-bbbb-bbbb-bbbbbbbbbbbb', $request['assigned_counter_id'] ?? null);
|
||||
|
||||
return Http::response([
|
||||
'data' => [
|
||||
'uuid' => 'cccccccc-cccc-cccc-cccc-cccccccccccc',
|
||||
'ticket_number' => 'C001',
|
||||
'status' => 'waiting',
|
||||
'assigned_counter' => ['uuid' => 'bbbbbbbb-bbbb-bbbb-bbbb-bbbbbbbbbbbb'],
|
||||
'destination' => 'Room 1',
|
||||
'staff_display_name' => 'Dr. Bridge',
|
||||
],
|
||||
], 201);
|
||||
}
|
||||
@@ -122,6 +155,7 @@ class CareQueueBridgeTest extends TestCase
|
||||
'organization_id' => $this->organization->id,
|
||||
'branch_id' => $this->branch->id,
|
||||
'patient_id' => $this->patient->id,
|
||||
'practitioner_id' => $practitioner->id,
|
||||
'type' => Appointment::TYPE_SCHEDULED,
|
||||
'status' => Appointment::STATUS_SCHEDULED,
|
||||
'scheduled_at' => now()->addHour(),
|
||||
@@ -193,10 +227,29 @@ class CareQueueBridgeTest extends TestCase
|
||||
|
||||
public function test_call_next_backfills_missing_ticket_then_calls(): void
|
||||
{
|
||||
$practitioner = \App\Models\Practitioner::create([
|
||||
'owner_ref' => $this->owner->public_id,
|
||||
'organization_id' => $this->organization->id,
|
||||
'branch_id' => $this->branch->id,
|
||||
'name' => 'Dr. Backfill',
|
||||
'room' => 'Room 3',
|
||||
'is_active' => true,
|
||||
]);
|
||||
|
||||
$settings = $this->organization->settings;
|
||||
$settings['department_queue_provisioning'][CareQueueContexts::CONSULTATION]['queues'][0]['points'] = [[
|
||||
'kind' => 'practitioner',
|
||||
'ref_id' => $practitioner->id,
|
||||
'destination' => 'Room 3',
|
||||
'counter_uuid' => 'bbbbbbbb-bbbb-bbbb-bbbb-bbbbbbbbbbbb',
|
||||
'synced' => true,
|
||||
]];
|
||||
$settings['department_queue_provisioning'][CareQueueContexts::CONSULTATION]['queues'][0]['counter_uuid'] = 'bbbbbbbb-bbbb-bbbb-bbbb-bbbbbbbbbbbb';
|
||||
$this->organization->update(['settings' => $settings]);
|
||||
|
||||
$ticketSeq = 0;
|
||||
Http::fake(function (\Illuminate\Http\Client\Request $request) use (&$ticketSeq) {
|
||||
if (str_contains($request->url(), '/call-next') && $request->method() === 'POST') {
|
||||
// First call: empty queue; second (after issue): ticket returned.
|
||||
if ($ticketSeq < 1) {
|
||||
return Http::response(['data' => null], 200);
|
||||
}
|
||||
@@ -219,6 +272,7 @@ class CareQueueBridgeTest extends TestCase
|
||||
'uuid' => 'ffffffff-ffff-ffff-ffff-ffffffffffff',
|
||||
'ticket_number' => 'C100',
|
||||
'status' => 'waiting',
|
||||
'assigned_counter' => ['uuid' => 'bbbbbbbb-bbbb-bbbb-bbbb-bbbbbbbbbbbb'],
|
||||
],
|
||||
], 201);
|
||||
}
|
||||
@@ -231,6 +285,7 @@ class CareQueueBridgeTest extends TestCase
|
||||
'organization_id' => $this->organization->id,
|
||||
'branch_id' => $this->branch->id,
|
||||
'patient_id' => $this->patient->id,
|
||||
'practitioner_id' => $practitioner->id,
|
||||
'type' => Appointment::TYPE_WALK_IN,
|
||||
'status' => Appointment::STATUS_WAITING,
|
||||
'scheduled_at' => now(),
|
||||
@@ -240,7 +295,10 @@ class CareQueueBridgeTest extends TestCase
|
||||
|
||||
$this->actingAs($this->owner)
|
||||
->from(route('care.queue.index'))
|
||||
->post(route('care.queue.call-next'), ['branch_id' => $this->branch->id])
|
||||
->post(route('care.queue.call-next'), [
|
||||
'branch_id' => $this->branch->id,
|
||||
'practitioner_id' => $practitioner->id,
|
||||
])
|
||||
->assertRedirect(route('care.queue.index'))
|
||||
->assertSessionHas('success');
|
||||
|
||||
@@ -259,7 +317,7 @@ class CareQueueBridgeTest extends TestCase
|
||||
->from(route('care.queue.index'))
|
||||
->post(route('care.queue.call-next'), ['branch_id' => $this->branch->id])
|
||||
->assertRedirect(route('care.queue.index'))
|
||||
->assertSessionHas('info', 'No patients waiting in the consultation queue.')
|
||||
->assertSessionHas('info', 'No patients waiting at your consultation service point.')
|
||||
->assertSessionMissing('error');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -213,6 +213,42 @@ class CareQueueWorkflowTest extends TestCase
|
||||
{
|
||||
$this->fakeQueueApi();
|
||||
|
||||
$practitioner = \App\Models\Practitioner::create([
|
||||
'owner_ref' => $this->owner->public_id,
|
||||
'organization_id' => $this->organization->id,
|
||||
'branch_id' => $this->branch->id,
|
||||
'name' => 'Dr. Workflow',
|
||||
'room' => 'Room 2',
|
||||
'is_active' => true,
|
||||
]);
|
||||
|
||||
$this->organization->update([
|
||||
'settings' => array_merge($this->organization->settings ?? [], [
|
||||
'department_queue_provisioning' => [
|
||||
CareQueueContexts::CONSULTATION => [
|
||||
'queues' => [[
|
||||
'branch_id' => $this->branch->id,
|
||||
'branch_name' => 'Main',
|
||||
'name' => 'Consultation',
|
||||
'prefix' => 'C',
|
||||
'active' => true,
|
||||
'synced' => true,
|
||||
'routing_mode' => 'assigned_only',
|
||||
'queue_uuid' => 'aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa',
|
||||
'counter_uuid' => 'cccccccc-cccc-cccc-cccc-cccccccccccc',
|
||||
'points' => [[
|
||||
'kind' => 'practitioner',
|
||||
'ref_id' => $practitioner->id,
|
||||
'destination' => 'Room 2',
|
||||
'counter_uuid' => 'cccccccc-cccc-cccc-cccc-cccccccccccc',
|
||||
'synced' => true,
|
||||
]],
|
||||
]],
|
||||
],
|
||||
],
|
||||
]),
|
||||
]);
|
||||
|
||||
$patient = Patient::create([
|
||||
'uuid' => (string) Str::uuid(),
|
||||
'owner_ref' => $this->owner->public_id,
|
||||
@@ -229,6 +265,7 @@ class CareQueueWorkflowTest extends TestCase
|
||||
'organization_id' => $this->organization->id,
|
||||
'branch_id' => $this->branch->id,
|
||||
'patient_id' => $patient->id,
|
||||
'practitioner_id' => $practitioner->id,
|
||||
'type' => Appointment::TYPE_SCHEDULED,
|
||||
'status' => Appointment::STATUS_SCHEDULED,
|
||||
'scheduled_at' => now(),
|
||||
@@ -246,6 +283,14 @@ class CareQueueWorkflowTest extends TestCase
|
||||
{
|
||||
$this->fakeQueueApi();
|
||||
|
||||
$pharmacist = Member::create([
|
||||
'owner_ref' => $this->owner->public_id,
|
||||
'organization_id' => $this->organization->id,
|
||||
'user_ref' => 'pharm-workflow',
|
||||
'role' => 'pharmacist',
|
||||
'branch_id' => $this->branch->id,
|
||||
]);
|
||||
|
||||
$this->organization->update([
|
||||
'settings' => array_merge($this->organization->settings ?? [], [
|
||||
'department_queue_provisioning' => [
|
||||
@@ -257,10 +302,19 @@ class CareQueueWorkflowTest extends TestCase
|
||||
'prefix' => 'P',
|
||||
'active' => true,
|
||||
'synced' => true,
|
||||
'routing_mode' => 'assigned_only',
|
||||
'queue_uuid' => 'bbbbbbbb-bbbb-bbbb-bbbb-bbbbbbbbbbbb',
|
||||
'counter_uuid' => 'dddddddd-dddd-dddd-dddd-dddddddddddd',
|
||||
'queue_external_key' => CareQueueContexts::queueExternalKey(CareQueueContexts::PHARMACY, $this->branch->id),
|
||||
'counter_external_key' => CareQueueContexts::counterExternalKey(CareQueueContexts::PHARMACY, $this->branch->id),
|
||||
'points' => [[
|
||||
'kind' => 'member',
|
||||
'ref_id' => $pharmacist->id,
|
||||
'staff_ref' => 'pharm-workflow',
|
||||
'destination' => 'Pharmacy counter 1',
|
||||
'counter_uuid' => 'dddddddd-dddd-dddd-dddd-dddddddddddd',
|
||||
'synced' => true,
|
||||
]],
|
||||
]],
|
||||
],
|
||||
],
|
||||
@@ -341,7 +395,7 @@ class CareQueueWorkflowTest extends TestCase
|
||||
->assertOk()
|
||||
->assertDontSee('Service counter')
|
||||
->assertSee('Call next')
|
||||
->assertSee('tickets are for this department only', false);
|
||||
->assertSee('assigned service point', false);
|
||||
}
|
||||
|
||||
public function test_integration_off_hides_queue_ops_on_pharmacy_page(): void
|
||||
|
||||
@@ -0,0 +1,447 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature;
|
||||
|
||||
use App\Http\Middleware\EnsurePlatformSession;
|
||||
use App\Models\Appointment;
|
||||
use App\Models\Branch;
|
||||
use App\Models\Member;
|
||||
use App\Models\Organization;
|
||||
use App\Models\Patient;
|
||||
use App\Models\Practitioner;
|
||||
use App\Models\User;
|
||||
use App\Services\Care\AppointmentService;
|
||||
use App\Services\Care\CareQueueBridge;
|
||||
use App\Services\Care\CareQueueContexts;
|
||||
use App\Services\Care\CareQueueProvisioner;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Illuminate\Support\Facades\Http;
|
||||
use Illuminate\Support\Str;
|
||||
use Tests\TestCase;
|
||||
|
||||
class CareServicePointRoutingTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
protected User $owner;
|
||||
|
||||
protected Organization $organization;
|
||||
|
||||
protected Branch $branch;
|
||||
|
||||
protected Practitioner $doctorA;
|
||||
|
||||
protected Practitioner $doctorB;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
$this->withoutMiddleware(EnsurePlatformSession::class);
|
||||
|
||||
config([
|
||||
'care.queue.api_url' => 'https://queue.test/api/v1',
|
||||
'care.queue.api_key' => 'care-test-key',
|
||||
]);
|
||||
|
||||
$this->owner = User::create([
|
||||
'public_id' => 'sp-care-owner',
|
||||
'name' => 'Owner',
|
||||
'email' => 'sp-care@example.com',
|
||||
]);
|
||||
|
||||
$this->organization = Organization::create([
|
||||
'owner_ref' => $this->owner->public_id,
|
||||
'name' => 'Ridge Medical Centre',
|
||||
'slug' => 'ridge-medical',
|
||||
'settings' => [
|
||||
'onboarded' => true,
|
||||
'facility_type' => 'hospital',
|
||||
'plan' => 'pro',
|
||||
'plan_expires_at' => now()->addMonth()->toIso8601String(),
|
||||
'queue_integration_enabled' => true,
|
||||
],
|
||||
]);
|
||||
|
||||
Member::create([
|
||||
'owner_ref' => $this->owner->public_id,
|
||||
'organization_id' => $this->organization->id,
|
||||
'user_ref' => $this->owner->public_id,
|
||||
'role' => 'hospital_admin',
|
||||
]);
|
||||
|
||||
$this->branch = Branch::create([
|
||||
'owner_ref' => $this->owner->public_id,
|
||||
'organization_id' => $this->organization->id,
|
||||
'name' => 'Main',
|
||||
'is_active' => true,
|
||||
]);
|
||||
|
||||
$this->doctorA = Practitioner::create([
|
||||
'owner_ref' => $this->owner->public_id,
|
||||
'organization_id' => $this->organization->id,
|
||||
'branch_id' => $this->branch->id,
|
||||
'name' => 'Dr. Mensah',
|
||||
'specialty' => 'General',
|
||||
'room' => 'Consultation Room 4',
|
||||
'user_ref' => 'doc-mensah',
|
||||
'is_active' => true,
|
||||
]);
|
||||
|
||||
$this->doctorB = Practitioner::create([
|
||||
'owner_ref' => $this->owner->public_id,
|
||||
'organization_id' => $this->organization->id,
|
||||
'branch_id' => $this->branch->id,
|
||||
'name' => 'Dr. Okai',
|
||||
'specialty' => 'Pediatrics',
|
||||
'room' => 'Consultation Room 5',
|
||||
'user_ref' => 'doc-okai',
|
||||
'is_active' => true,
|
||||
]);
|
||||
|
||||
$settings = $this->organization->settings;
|
||||
$settings['department_queue_provisioning'] = [
|
||||
CareQueueContexts::CONSULTATION => [
|
||||
'queues' => [[
|
||||
'branch_id' => $this->branch->id,
|
||||
'branch_name' => 'Main',
|
||||
'name' => 'Consultation',
|
||||
'prefix' => 'C',
|
||||
'active' => true,
|
||||
'synced' => true,
|
||||
'routing_mode' => 'assigned_only',
|
||||
'queue_uuid' => 'aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa',
|
||||
'queue_external_key' => CareQueueContexts::queueExternalKey(CareQueueContexts::CONSULTATION, $this->branch->id),
|
||||
'points' => [
|
||||
[
|
||||
'kind' => 'practitioner',
|
||||
'ref_id' => $this->doctorA->id,
|
||||
'name' => 'Dr. Mensah',
|
||||
'destination' => 'Consultation Room 4',
|
||||
'staff_display_name' => 'Dr. Mensah',
|
||||
'external_key' => CareQueueContexts::pointExternalKey(
|
||||
CareQueueContexts::CONSULTATION,
|
||||
$this->branch->id,
|
||||
'practitioner',
|
||||
$this->doctorA->id,
|
||||
),
|
||||
'counter_uuid' => '11111111-1111-1111-1111-111111111111',
|
||||
'synced' => true,
|
||||
],
|
||||
[
|
||||
'kind' => 'practitioner',
|
||||
'ref_id' => $this->doctorB->id,
|
||||
'name' => 'Dr. Okai',
|
||||
'destination' => 'Consultation Room 5',
|
||||
'staff_display_name' => 'Dr. Okai',
|
||||
'external_key' => CareQueueContexts::pointExternalKey(
|
||||
CareQueueContexts::CONSULTATION,
|
||||
$this->branch->id,
|
||||
'practitioner',
|
||||
$this->doctorB->id,
|
||||
),
|
||||
'counter_uuid' => '22222222-2222-2222-2222-222222222222',
|
||||
'synced' => true,
|
||||
],
|
||||
],
|
||||
]],
|
||||
],
|
||||
CareQueueContexts::PHARMACY => [
|
||||
'queues' => [[
|
||||
'branch_id' => $this->branch->id,
|
||||
'name' => 'Pharmacy',
|
||||
'prefix' => 'P',
|
||||
'active' => true,
|
||||
'synced' => true,
|
||||
'routing_mode' => 'assigned_only',
|
||||
'queue_uuid' => 'bbbbbbbb-bbbb-bbbb-bbbb-bbbbbbbbbbbb',
|
||||
'points' => [[
|
||||
'kind' => 'member',
|
||||
'ref_id' => 1,
|
||||
'destination' => 'Pharmacy counter 1',
|
||||
'counter_uuid' => '33333333-3333-3333-3333-333333333333',
|
||||
'synced' => true,
|
||||
]],
|
||||
]],
|
||||
],
|
||||
];
|
||||
$this->organization->update(['settings' => $settings]);
|
||||
}
|
||||
|
||||
public function test_fixed_doctor_appointment_issues_to_that_doctors_point(): void
|
||||
{
|
||||
Http::fake(function (\Illuminate\Http\Client\Request $request) {
|
||||
if ($request->method() === 'POST' && str_contains($request->url(), '/tickets')) {
|
||||
$this->assertSame('11111111-1111-1111-1111-111111111111', $request['assigned_counter_id'] ?? null);
|
||||
$this->assertSame('aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa', $request['service_queue_id'] ?? null);
|
||||
|
||||
return Http::response([
|
||||
'data' => [
|
||||
'uuid' => (string) Str::uuid(),
|
||||
'ticket_number' => 'C001',
|
||||
'status' => 'waiting',
|
||||
'destination' => 'Consultation Room 4',
|
||||
'staff_display_name' => 'Dr. Mensah',
|
||||
'assigned_counter' => [
|
||||
'uuid' => '11111111-1111-1111-1111-111111111111',
|
||||
'destination' => 'Consultation Room 4',
|
||||
'staff_display_name' => 'Dr. Mensah',
|
||||
],
|
||||
],
|
||||
], 201);
|
||||
}
|
||||
|
||||
return Http::response(['message' => 'unexpected'], 500);
|
||||
});
|
||||
|
||||
$patient = Patient::create([
|
||||
'uuid' => (string) Str::uuid(),
|
||||
'owner_ref' => $this->owner->public_id,
|
||||
'organization_id' => $this->organization->id,
|
||||
'branch_id' => $this->branch->id,
|
||||
'patient_number' => 'P-1',
|
||||
'first_name' => 'Ada',
|
||||
'last_name' => 'Lovelace',
|
||||
]);
|
||||
|
||||
$appointment = Appointment::create([
|
||||
'uuid' => (string) Str::uuid(),
|
||||
'owner_ref' => $this->owner->public_id,
|
||||
'organization_id' => $this->organization->id,
|
||||
'branch_id' => $this->branch->id,
|
||||
'patient_id' => $patient->id,
|
||||
'practitioner_id' => $this->doctorA->id,
|
||||
'type' => Appointment::TYPE_SCHEDULED,
|
||||
'status' => Appointment::STATUS_SCHEDULED,
|
||||
'scheduled_at' => now()->addHour(),
|
||||
]);
|
||||
|
||||
$result = app(AppointmentService::class)->checkIn($appointment, $this->owner->public_id);
|
||||
|
||||
$this->assertSame('C001', $result->queue_ticket_number);
|
||||
$this->assertSame('11111111-1111-1111-1111-111111111111', $result->queue_service_point_uuid);
|
||||
$this->assertSame('Consultation Room 4', $result->queue_destination);
|
||||
$this->assertSame('Dr. Mensah', $result->queue_staff_display_name);
|
||||
$this->assertSame(CareQueueContexts::ROUTING_ROUTED, $result->queue_routing_status);
|
||||
}
|
||||
|
||||
public function test_walk_in_without_doctor_flags_unresolved_and_does_not_issue(): void
|
||||
{
|
||||
Http::fake();
|
||||
|
||||
$patient = Patient::create([
|
||||
'uuid' => (string) Str::uuid(),
|
||||
'owner_ref' => $this->owner->public_id,
|
||||
'organization_id' => $this->organization->id,
|
||||
'branch_id' => $this->branch->id,
|
||||
'patient_number' => 'P-2',
|
||||
'first_name' => 'Bob',
|
||||
'last_name' => 'Builder',
|
||||
]);
|
||||
|
||||
$appointment = Appointment::create([
|
||||
'uuid' => (string) Str::uuid(),
|
||||
'owner_ref' => $this->owner->public_id,
|
||||
'organization_id' => $this->organization->id,
|
||||
'branch_id' => $this->branch->id,
|
||||
'patient_id' => $patient->id,
|
||||
'practitioner_id' => null,
|
||||
'type' => Appointment::TYPE_WALK_IN,
|
||||
'status' => Appointment::STATUS_WAITING,
|
||||
'waiting_at' => now(),
|
||||
]);
|
||||
|
||||
$result = app(CareQueueBridge::class)->issueForAppointment($this->organization, $appointment);
|
||||
|
||||
$this->assertNull($result->queue_ticket_uuid);
|
||||
$this->assertSame(CareQueueContexts::ROUTING_UNRESOLVED, $result->queue_routing_status);
|
||||
Http::assertNothingSent();
|
||||
}
|
||||
|
||||
public function test_walk_in_with_selected_doctor_routes_only_to_that_point(): void
|
||||
{
|
||||
Http::fake(function (\Illuminate\Http\Client\Request $request) {
|
||||
if ($request->method() === 'POST' && str_contains($request->url(), '/tickets')) {
|
||||
$this->assertSame('22222222-2222-2222-2222-222222222222', $request['assigned_counter_id'] ?? null);
|
||||
|
||||
return Http::response([
|
||||
'data' => [
|
||||
'uuid' => (string) Str::uuid(),
|
||||
'ticket_number' => 'C002',
|
||||
'status' => 'waiting',
|
||||
'assigned_counter' => ['uuid' => '22222222-2222-2222-2222-222222222222'],
|
||||
'destination' => 'Consultation Room 5',
|
||||
'staff_display_name' => 'Dr. Okai',
|
||||
],
|
||||
], 201);
|
||||
}
|
||||
|
||||
return Http::response(['message' => 'unexpected'], 500);
|
||||
});
|
||||
|
||||
$patient = Patient::create([
|
||||
'uuid' => (string) Str::uuid(),
|
||||
'owner_ref' => $this->owner->public_id,
|
||||
'organization_id' => $this->organization->id,
|
||||
'branch_id' => $this->branch->id,
|
||||
'patient_number' => 'P-3',
|
||||
'first_name' => 'Cara',
|
||||
'last_name' => 'Clinic',
|
||||
]);
|
||||
|
||||
$appointment = app(AppointmentService::class)->walkIn(
|
||||
$this->organization,
|
||||
$this->owner->public_id,
|
||||
[
|
||||
'branch_id' => $this->branch->id,
|
||||
'patient_id' => $patient->id,
|
||||
'practitioner_id' => $this->doctorB->id,
|
||||
'reason' => 'Fever',
|
||||
],
|
||||
$this->owner->public_id,
|
||||
);
|
||||
|
||||
$this->assertSame($this->doctorB->id, $appointment->practitioner_id);
|
||||
$this->assertSame('C002', $appointment->queue_ticket_number);
|
||||
$this->assertSame('Consultation Room 5', $appointment->queue_destination);
|
||||
}
|
||||
|
||||
public function test_pharmacist_call_next_uses_pharmacy_point(): void
|
||||
{
|
||||
$pharmacist = Member::create([
|
||||
'owner_ref' => $this->owner->public_id,
|
||||
'organization_id' => $this->organization->id,
|
||||
'user_ref' => 'pharm-1',
|
||||
'role' => 'pharmacist',
|
||||
'branch_id' => $this->branch->id,
|
||||
]);
|
||||
|
||||
$settings = $this->organization->settings;
|
||||
$settings['department_queue_provisioning'][CareQueueContexts::PHARMACY]['queues'][0]['points'] = [[
|
||||
'kind' => 'member',
|
||||
'ref_id' => $pharmacist->id,
|
||||
'destination' => 'Pharmacy counter 1',
|
||||
'staff_ref' => 'pharm-1',
|
||||
'counter_uuid' => '33333333-3333-3333-3333-333333333333',
|
||||
'synced' => true,
|
||||
]];
|
||||
$this->organization->update(['settings' => $settings]);
|
||||
|
||||
Http::fake(function (\Illuminate\Http\Client\Request $request) {
|
||||
if (str_contains($request->url(), '/call-next')) {
|
||||
$this->assertStringContainsString('bbbbbbbb-bbbb-bbbb-bbbb-bbbbbbbbbbbb', $request->url());
|
||||
$this->assertSame('33333333-3333-3333-3333-333333333333', $request['counter_id'] ?? null);
|
||||
|
||||
return Http::response([
|
||||
'data' => [
|
||||
'uuid' => (string) Str::uuid(),
|
||||
'ticket_number' => 'P001',
|
||||
'status' => 'called',
|
||||
],
|
||||
], 200);
|
||||
}
|
||||
|
||||
return Http::response(['message' => 'unexpected'], 500);
|
||||
});
|
||||
|
||||
$result = app(CareQueueBridge::class)->callNext(
|
||||
$this->organization->fresh(),
|
||||
CareQueueContexts::PHARMACY,
|
||||
$this->branch->id,
|
||||
$pharmacist,
|
||||
);
|
||||
|
||||
$this->assertSame('P001', $result['ticket']['ticket_number'] ?? null);
|
||||
}
|
||||
|
||||
public function test_integration_off_preserves_behavior_without_ticket_issuance(): void
|
||||
{
|
||||
$settings = $this->organization->settings;
|
||||
$settings['queue_integration_enabled'] = false;
|
||||
$this->organization->update(['settings' => $settings]);
|
||||
|
||||
Http::fake();
|
||||
|
||||
$patient = Patient::create([
|
||||
'uuid' => (string) Str::uuid(),
|
||||
'owner_ref' => $this->owner->public_id,
|
||||
'organization_id' => $this->organization->id,
|
||||
'branch_id' => $this->branch->id,
|
||||
'patient_number' => 'P-4',
|
||||
'first_name' => 'Dee',
|
||||
'last_name' => 'Demo',
|
||||
]);
|
||||
|
||||
$appointment = Appointment::create([
|
||||
'uuid' => (string) Str::uuid(),
|
||||
'owner_ref' => $this->owner->public_id,
|
||||
'organization_id' => $this->organization->id,
|
||||
'branch_id' => $this->branch->id,
|
||||
'patient_id' => $patient->id,
|
||||
'practitioner_id' => $this->doctorA->id,
|
||||
'type' => Appointment::TYPE_SCHEDULED,
|
||||
'status' => Appointment::STATUS_SCHEDULED,
|
||||
'scheduled_at' => now()->addHour(),
|
||||
]);
|
||||
|
||||
$result = app(AppointmentService::class)->checkIn($appointment, $this->owner->public_id);
|
||||
|
||||
$this->assertNull($result->queue_ticket_uuid);
|
||||
Http::assertNothingSent();
|
||||
}
|
||||
|
||||
public function test_provisioner_builds_one_point_per_practitioner_idempotently(): void
|
||||
{
|
||||
$calls = ['queues' => 0, 'counters' => 0];
|
||||
|
||||
Http::fake(function (\Illuminate\Http\Client\Request $request) use (&$calls) {
|
||||
if (str_contains($request->url(), '/integrations/status')) {
|
||||
return Http::response(['data' => ['provisioned' => true, 'integrations' => ['care' => true]]], 200);
|
||||
}
|
||||
if (str_contains($request->url(), '/branches') && $request->method() === 'POST') {
|
||||
return Http::response(['data' => ['name' => 'Main']], 201);
|
||||
}
|
||||
if (str_contains($request->url(), '/departments') && $request->method() === 'POST') {
|
||||
return Http::response(['data' => ['id' => 9, 'name' => $request['name'] ?? 'Dept']], 201);
|
||||
}
|
||||
if (str_contains($request->url(), '/queues') && $request->method() === 'POST' && ! str_contains($request->url(), 'call-next')) {
|
||||
$calls['queues']++;
|
||||
$this->assertSame('assigned_only', $request['routing_mode'] ?? null);
|
||||
|
||||
return Http::response([
|
||||
'data' => [
|
||||
'uuid' => (string) Str::uuid(),
|
||||
'name' => $request['name'] ?? 'Q',
|
||||
'external_key' => $request['external_key'] ?? null,
|
||||
],
|
||||
], 201);
|
||||
}
|
||||
if (str_contains($request->url(), '/counters') && $request->method() === 'POST') {
|
||||
$calls['counters']++;
|
||||
|
||||
return Http::response([
|
||||
'data' => [
|
||||
'uuid' => (string) Str::uuid(),
|
||||
'name' => $request['name'] ?? 'C',
|
||||
'destination' => $request['destination'] ?? null,
|
||||
],
|
||||
], 201);
|
||||
}
|
||||
|
||||
return Http::response(['message' => 'unexpected '.$request->url()], 500);
|
||||
});
|
||||
|
||||
// Clear prior stub so provisioner builds fresh.
|
||||
$settings = $this->organization->settings;
|
||||
unset($settings['department_queue_provisioning']);
|
||||
$this->organization->update(['settings' => $settings]);
|
||||
|
||||
app(CareQueueProvisioner::class)->provisionOrganization($this->organization->fresh());
|
||||
$first = data_get($this->organization->fresh()->settings, 'department_queue_provisioning.consultation.queues.0.points');
|
||||
$this->assertIsArray($first);
|
||||
$this->assertGreaterThanOrEqual(2, count($first));
|
||||
|
||||
app(CareQueueProvisioner::class)->provisionOrganization($this->organization->fresh());
|
||||
$second = data_get($this->organization->fresh()->settings, 'department_queue_provisioning.consultation.queues.0.points');
|
||||
$this->assertCount(count($first), $second);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user