Fix queue handoff so tickets keep their number across services.
Deploy Ladill Queue / deploy (push) Successful in 40s
Deploy Ladill Queue / deploy (push) Successful in 40s
Handoff now frees the counter, ends the service session, and requeues the same ticket for the next department — critical for hospital flows like doctor → lab. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -157,6 +157,64 @@ class QmsQueueTest extends TestCase
|
||||
$this->assertNotNull($session->ended_at);
|
||||
}
|
||||
|
||||
public function test_handoff_keeps_ticket_number_and_frees_counter(): void
|
||||
{
|
||||
[$user, $org, $branch, $queue] = $this->setUpOrg();
|
||||
$lab = ServiceQueue::create([
|
||||
'owner_ref' => $user->public_id,
|
||||
'organization_id' => $org->id,
|
||||
'branch_id' => $branch->id,
|
||||
'name' => 'Lab',
|
||||
'prefix' => 'L',
|
||||
'strategy' => 'fifo',
|
||||
'is_active' => true,
|
||||
]);
|
||||
|
||||
$engine = app(QueueEngine::class);
|
||||
$ticket = $engine->issueTicket($queue, $user->public_id, [
|
||||
'source' => 'reception',
|
||||
'customer_name' => 'Patient One',
|
||||
]);
|
||||
$this->assertSame('A001', $ticket->ticket_number);
|
||||
|
||||
$counter = \App\Models\Counter::create([
|
||||
'owner_ref' => $user->public_id,
|
||||
'organization_id' => $org->id,
|
||||
'branch_id' => $branch->id,
|
||||
'name' => 'Doctor 1',
|
||||
'status' => 'available',
|
||||
'is_active' => true,
|
||||
]);
|
||||
|
||||
$engine->callTicket($ticket, $counter, $user->public_id);
|
||||
$engine->startServing($ticket->fresh(), $user->public_id);
|
||||
|
||||
$handedOff = $engine->transfer(
|
||||
$ticket->fresh(),
|
||||
$lab,
|
||||
$counter,
|
||||
'Lab tests needed',
|
||||
$user->public_id,
|
||||
);
|
||||
|
||||
$this->assertSame('A001', $handedOff->ticket_number);
|
||||
$this->assertSame($lab->id, $handedOff->service_queue_id);
|
||||
$this->assertSame('waiting', $handedOff->status);
|
||||
$this->assertNull($handedOff->counter_id);
|
||||
$this->assertNull($handedOff->completed_at);
|
||||
$this->assertSame('available', $counter->fresh()->status);
|
||||
$this->assertDatabaseHas('queue_ticket_transfers', [
|
||||
'ticket_id' => $ticket->id,
|
||||
'from_service_queue_id' => $queue->id,
|
||||
'to_service_queue_id' => $lab->id,
|
||||
'reason' => 'Lab tests needed',
|
||||
]);
|
||||
|
||||
$session = \App\Models\ServiceSession::where('ticket_id', $ticket->id)->first();
|
||||
$this->assertNotNull($session);
|
||||
$this->assertNotNull($session->ended_at);
|
||||
}
|
||||
|
||||
public function test_reports_sqlite_compatible(): void
|
||||
{
|
||||
[$user, $org, , $queue] = $this->setUpOrg();
|
||||
|
||||
Reference in New Issue
Block a user