Add in-app Ladill Queue integration for service queue consoles.
Deploy Ladill Care / deploy (push) Successful in 37s

Settings toggle provisions Queue org via API; reception staff manage counters without leaving Care.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
isaacclad
2026-06-29 21:51:17 +00:00
co-authored by Cursor
parent d25a884911
commit 40c0eaa1a6
11 changed files with 381 additions and 1 deletions
+4
View File
@@ -19,6 +19,10 @@ SESSION_LIFETIME=1440
CACHE_STORE=database
QUEUE_CONNECTION=database
# Ladill Queue service API (in-app service queue console)
QUEUE_API_URL=https://queue.ladill.com/api/v1
QUEUE_API_KEY_CARE=
# --- Ladill SSO (Sign in with Ladill — auth.ladill.com OIDC client) ---
LADILL_SSO_CLIENT_ID=
LADILL_SSO_CLIENT_SECRET=
@@ -0,0 +1,87 @@
<?php
namespace App\Http\Controllers\Care;
use App\Http\Controllers\Controller;
use App\Http\Controllers\Care\Concerns\ScopesToAccount;
use App\Models\Branch;
use App\Services\Queue\QueueClient;
use Illuminate\Http\Client\RequestException;
use Illuminate\Http\RedirectResponse;
use Illuminate\Http\Request;
use Illuminate\View\View;
class ServiceQueueController extends Controller
{
use ScopesToAccount;
public function index(Request $request, QueueClient $queue): View|RedirectResponse
{
$this->authorizeAbility($request, 'service_queues.console');
$organization = $this->organization($request);
if (! $this->integrationEnabled($organization)) {
return redirect()->route('care.settings')->with('error', 'Enable Ladill Queue integration in settings first.');
}
$owner = $this->ownerRef($request);
try {
$counters = $queue->counters($owner);
} catch (RequestException $e) {
return redirect()->route('care.settings')->with('error', 'Could not reach Ladill Queue. Check API keys and enable integration in Queue settings.');
}
return view('care.service-queues.index', compact('counters', 'organization'));
}
public function console(Request $request, string $counterUuid, QueueClient $queue): View|RedirectResponse
{
$this->authorizeAbility($request, 'service_queues.console');
$organization = $this->organization($request);
$owner = $this->ownerRef($request);
if (! $this->integrationEnabled($organization)) {
return redirect()->route('care.settings');
}
try {
$state = $queue->console($owner, $counterUuid);
} catch (RequestException) {
return redirect()->route('care.service-queues.index')->with('error', 'Counter console unavailable.');
}
return view('care.service-queues.console', [
'state' => $state,
'counterUuid' => $counterUuid,
'organization' => $organization,
]);
}
public function action(Request $request, string $counterUuid, QueueClient $queue): RedirectResponse
{
$this->authorizeAbility($request, 'service_queues.console');
$owner = $this->ownerRef($request);
$validated = $request->validate([
'action' => ['required', 'string'],
'queue_uuid' => ['nullable', 'uuid'],
'ticket_uuid' => ['nullable', 'uuid'],
'to_queue_uuid' => ['nullable', 'uuid'],
'reason' => ['nullable', 'string', 'max:500'],
]);
try {
$queue->consoleAction($owner, $counterUuid, $validated);
} catch (RequestException) {
return back()->with('error', 'Queue action failed. Try again.');
}
return back()->with('success', 'Queue updated.');
}
protected function integrationEnabled(\App\Models\Organization $organization): bool
{
return (bool) data_get($organization->settings, 'queue_integration_enabled', false);
}
}
@@ -7,6 +7,7 @@ use App\Http\Controllers\Care\Concerns\ScopesToAccount;
use App\Models\Branch;
use App\Services\Care\AuditLogger;
use App\Services\Care\CarePermissions;
use App\Services\Queue\QueueClient;
use App\Support\OrganizationBranding;
use Illuminate\Http\RedirectResponse;
use Illuminate\Http\Request;
@@ -39,7 +40,7 @@ class SettingsController extends Controller
]);
}
public function update(Request $request): RedirectResponse
public function update(Request $request, QueueClient $queue): RedirectResponse
{
$this->authorizeAbility($request, 'settings.manage');
$organization = $this->organization($request);
@@ -51,12 +52,26 @@ class SettingsController extends Controller
'facility_type' => ['required', 'string', 'in:clinic,hospital,diagnostic,specialist'],
'logo' => ['nullable', 'image', 'mimes:jpeg,png,jpg,webp,svg', 'max:2048'],
'remove_logo' => ['nullable', 'boolean'],
'queue_integration_enabled' => ['nullable', 'boolean'],
]);
$settings = $organization->settings ?? [];
$settings['onboarded'] = true;
$settings['facility_type'] = $validated['facility_type'];
$wantsQueue = $request->boolean('queue_integration_enabled');
$hadQueue = (bool) data_get($settings, 'queue_integration_enabled', false);
$settings['queue_integration_enabled'] = $wantsQueue;
if ($wantsQueue && ! $hadQueue && $queue->configured()) {
$branch = Branch::owned($owner)->where('organization_id', $organization->id)->orderBy('name')->first();
try {
$queue->enable($owner, $organization->name, $branch?->name);
} catch (\Throwable) {
return back()->withInput()->with('error', 'Could not provision Ladill Queue for this account. Ensure Queue API keys are configured and Queue allows Care integration.');
}
}
$logoPath = $organization->logo_path;
if ($request->boolean('remove_logo')) {
+2
View File
@@ -13,6 +13,7 @@ class CarePermissions
'receptionist' => [
'dashboard.view', 'patients.view', 'patients.manage',
'appointments.view', 'appointments.manage', 'queue.manage',
'service_queues.console',
],
'doctor' => [
'dashboard.view', 'patients.view', 'appointments.view',
@@ -22,6 +23,7 @@ class CarePermissions
'nurse' => [
'dashboard.view', 'patients.view', 'appointments.view',
'consultations.view', 'vitals.manage', 'queue.manage',
'service_queues.console',
],
'lab_technician' => [
'dashboard.view', 'patients.view', 'lab.view', 'lab.manage',
+113
View File
@@ -0,0 +1,113 @@
<?php
namespace App\Services\Queue;
use Illuminate\Http\Client\RequestException;
use Illuminate\Support\Facades\Http;
class QueueClient
{
private function base(): string
{
return rtrim((string) config('care.queue.api_url'), '/');
}
private function token(): string
{
return (string) (config('care.queue.api_key') ?? '');
}
private function http(string $owner)
{
return Http::withToken($this->token())
->acceptJson()
->timeout(12)
->withQueryParameters(['owner' => $owner]);
}
public function configured(): bool
{
return $this->token() !== '' && $this->base() !== '';
}
/**
* @return array<string, mixed>
*/
public function status(string $owner): array
{
$response = $this->http($owner)->get($this->base().'/integrations/status');
$response->throw();
return (array) ($response->json('data') ?? []);
}
/**
* @return array<string, mixed>
*/
public function enable(string $owner, string $organizationName, ?string $branchName = null): array
{
$response = $this->http($owner)->post($this->base().'/integrations/provision', array_filter([
'organization_name' => $organizationName,
'branch_name' => $branchName,
'industry' => 'healthcare',
]));
$response->throw();
return (array) ($response->json('data') ?? []);
}
public function disable(string $owner): void
{
// Local Care setting only; Queue must be disabled separately in Queue settings.
}
public function isLinked(string $owner): bool
{
if (! $this->configured()) {
return false;
}
try {
$status = $this->status($owner);
return (bool) ($status['provisioned'] ?? false)
&& (bool) data_get($status, 'integrations.care', false);
} catch (RequestException) {
return false;
}
}
/**
* @return list<array<string, mixed>>
*/
public function counters(string $owner): array
{
$response = $this->http($owner)->get($this->base().'/counters');
$response->throw();
return (array) ($response->json('data') ?? []);
}
/**
* @return array<string, mixed>
*/
public function console(string $owner, string $counterUuid): array
{
$response = $this->http($owner)->get($this->base().'/counters/'.$counterUuid.'/console');
$response->throw();
return (array) ($response->json('data') ?? []);
}
/**
* @param array<string, mixed> $payload
* @return array<string, mixed>
*/
public function consoleAction(string $owner, string $counterUuid, array $payload): array
{
$response = $this->http($owner)->post($this->base().'/counters/'.$counterUuid.'/console', $payload);
$response->throw();
return (array) ($response->json('data') ?? []);
}
}
+5
View File
@@ -217,4 +217,9 @@ return [
],
],
'queue' => [
'api_url' => env('QUEUE_API_URL', 'https://queue.ladill.com/api/v1'),
'api_key' => env('QUEUE_API_KEY_CARE'),
],
];
@@ -0,0 +1,97 @@
@php
$counter = $state['counter'] ?? [];
$current = $state['current_ticket'] ?? null;
$queues = $state['queues'] ?? [];
$waiting = $state['waiting_by_queue'] ?? [];
$transferQueues = $state['transfer_queues'] ?? [];
@endphp
<x-app-layout title="Console · {{ $counter['name'] ?? 'Counter' }}">
<div class="flex flex-wrap items-start justify-between gap-4">
<div>
<a href="{{ route('care.service-queues.index') }}" class="text-sm font-medium text-indigo-600"> Service queues</a>
<h1 class="mt-2 text-xl font-semibold text-slate-900">{{ $counter['name'] ?? 'Counter' }}</h1>
<p class="mt-1 text-sm text-slate-500">{{ $counter['branch'] ?? '' }} · Ladill Queue console</p>
</div>
<div class="flex gap-2">
<form method="POST" action="{{ route('care.service-queues.action', $counterUuid) }}">@csrf<input type="hidden" name="action" value="available"><button class="btn-secondary text-sm">Available</button></form>
<form method="POST" action="{{ route('care.service-queues.action', $counterUuid) }}">@csrf<input type="hidden" name="action" value="offline"><button class="btn-secondary text-sm">Offline</button></form>
</div>
</div>
@if ($current)
<section class="mt-6 overflow-hidden rounded-2xl border border-indigo-200 bg-gradient-to-br from-indigo-50 via-white to-white shadow-sm">
<div class="border-b border-indigo-100 px-6 py-4">
<p class="text-xs font-semibold uppercase tracking-wider text-indigo-600">Current customer</p>
</div>
<div class="px-6 py-5">
<p class="text-5xl font-bold tracking-tight text-slate-900">{{ $current['ticket_number'] }}</p>
<p class="mt-2 text-sm text-slate-600">{{ $current['queue']['name'] ?? '' }}</p>
<p class="mt-1 font-medium text-slate-800">{{ $current['customer_name'] ?? 'Walk-in customer' }}</p>
<div class="mt-6 grid gap-2 sm:grid-cols-2 lg:grid-cols-3">
@foreach ([
'recall' => 'Recall',
'start' => 'Start serving',
'hold' => 'Hold',
'skip' => 'Skip',
'complete' => 'Complete',
'no_show' => 'No show',
] as $action => $label)
<form method="POST" action="{{ route('care.service-queues.action', $counterUuid) }}">
@csrf
<input type="hidden" name="action" value="{{ $action }}">
<input type="hidden" name="ticket_uuid" value="{{ $current['uuid'] }}">
<button type="submit" class="btn-secondary w-full text-sm">{{ $label }}</button>
</form>
@endforeach
</div>
@if (count($transferQueues) > 1)
<form method="POST" action="{{ route('care.service-queues.action', $counterUuid) }}" class="mt-4 flex flex-wrap items-end gap-2 border-t border-indigo-100 pt-4">
@csrf
<input type="hidden" name="action" value="transfer">
<input type="hidden" name="ticket_uuid" value="{{ $current['uuid'] }}">
<select name="to_queue_uuid" class="rounded-lg border-slate-300 text-sm">
@foreach ($transferQueues as $q)
@if (($q['uuid'] ?? '') !== ($current['queue']['uuid'] ?? ''))
<option value="{{ $q['uuid'] }}">{{ $q['name'] }}</option>
@endif
@endforeach
</select>
<input type="text" name="reason" placeholder="Reason" class="rounded-lg border-slate-300 text-sm">
<button type="submit" class="btn-secondary text-sm">Transfer</button>
</form>
@endif
</div>
</section>
@else
<section class="mt-6 rounded-2xl border border-dashed border-slate-300 bg-slate-50 px-6 py-10 text-center text-sm text-slate-600">
No active customer call the next ticket from a queue below.
</section>
@endif
<div class="mt-6 grid gap-4 lg:grid-cols-2">
@foreach ($queues as $queue)
<section class="rounded-2xl border border-slate-200 bg-white shadow-sm">
<div class="flex items-center justify-between border-b border-slate-100 px-5 py-4">
<h2 class="font-semibold text-slate-900">{{ $queue['name'] }}</h2>
<form method="POST" action="{{ route('care.service-queues.action', $counterUuid) }}">
@csrf
<input type="hidden" name="action" value="call_next">
<input type="hidden" name="queue_uuid" value="{{ $queue['uuid'] }}">
<button type="submit" class="btn-primary text-sm">Call next</button>
</form>
</div>
<ul class="divide-y divide-slate-50 px-2 py-2">
@forelse ($waiting[$queue['uuid']] ?? [] as $ticket)
<li class="flex items-center justify-between px-3 py-2.5 text-sm">
<span class="font-mono font-semibold">{{ $ticket['ticket_number'] }}</span>
<span class="text-slate-500">{{ $ticket['customer_name'] ?? 'Walk-in' }}</span>
</li>
@empty
<li class="px-3 py-6 text-center text-sm text-slate-500">Queue is empty</li>
@endforelse
</ul>
</section>
@endforeach
</div>
</x-app-layout>
@@ -0,0 +1,34 @@
<x-app-layout title="Service queues">
<div class="flex flex-wrap items-start justify-between gap-4">
<div>
<h1 class="text-xl font-semibold text-slate-900">Service queues</h1>
<p class="mt-1 text-sm text-slate-500">Powered by Ladill Queue call tickets and manage counters without leaving Care</p>
</div>
<a href="https://queue.ladill.com" target="_blank" class="btn-secondary text-sm">Open Queue admin</a>
</div>
@if (session('error'))
<div class="mt-4 rounded-lg bg-rose-50 px-4 py-3 text-sm text-rose-800">{{ session('error') }}</div>
@endif
<div class="mt-5 grid gap-4 md:grid-cols-2 xl:grid-cols-3">
@forelse ($counters as $counter)
<article class="rounded-2xl border border-slate-200 bg-white p-5 shadow-sm">
<div class="flex items-start justify-between gap-3">
<div>
<h2 class="text-lg font-semibold text-slate-900">{{ $counter['name'] }}</h2>
<p class="mt-1 text-sm text-slate-500">{{ $counter['status'] ?? 'offline' }}</p>
</div>
</div>
<p class="mt-3 text-sm text-slate-600">
Queues: {{ collect($counter['queues'] ?? [])->join(', ') ?: 'None assigned' }}
</p>
<a href="{{ route('care.service-queues.console', $counter['uuid']) }}" class="btn-primary mt-4 inline-block w-full text-center text-sm">Open console</a>
</article>
@empty
<div class="col-span-full rounded-2xl border border-dashed border-slate-300 bg-slate-50 px-6 py-12 text-center text-sm text-slate-600">
No counters found in Ladill Queue. Create counters in Queue admin, then return here.
</div>
@endforelse
</div>
</x-app-layout>
@@ -36,6 +36,16 @@
<label class="mt-2 flex items-center gap-2 text-sm"><input type="checkbox" name="remove_logo" value="1"> Remove current logo</label>
@endif
</div>
<div class="rounded-xl border border-slate-200 p-4">
<h2 class="text-sm font-semibold text-slate-900">Ladill Queue</h2>
<p class="mt-1 text-xs text-slate-500">Manage service queues and counters in Care. You must also enable Care integration in Ladill Queue settings.</p>
<label class="mt-3 flex items-center gap-2 text-sm">
<input type="checkbox" name="queue_integration_enabled" value="1" @checked(data_get($organization->settings, 'queue_integration_enabled'))>
Enable Ladill Queue integration
</label>
</div>
<button type="submit" class="btn-primary">Save settings</button>
@endif
</form>
@@ -9,6 +9,9 @@
? app(\App\Services\Care\OrganizationResolver::class)->memberFor(auth()->user())
: null;
$permissions = app(\App\Services\Care\CarePermissions::class);
$organization = auth()->user()
? app(\App\Services\Care\OrganizationResolver::class)->resolveForUser(auth()->user())
: null;
$nav = [
['name' => 'Dashboard', 'route' => route('care.dashboard'), 'active' => request()->routeIs('care.dashboard'),
@@ -52,6 +55,11 @@
'icon' => '<path stroke-linecap="round" stroke-linejoin="round" d="M3 13.125C3 12.504 3.504 12 4.125 12h2.25c.621 0 1.125.504 1.125 1.125v6.75C7.5 20.496 6.996 21 6.375 21h-2.25A1.125 1.125 0 0 1 3 19.875v-6.75ZM9.75 8.625c0-.621.504-1.125 1.125-1.125h2.25c.621 0 1.125.504 1.125 1.125v11.25c0 .621-.504 1.125-1.125 1.125h-2.25a1.125 1.125 0 0 1-1.125-1.125V8.625ZM16.5 4.125c0-.621.504-1.125 1.125-1.125h2.25C20.496 3 21 3.504 21 4.125v15.75c0 .621-.504 1.125-1.125 1.125h-2.25a1.125 1.125 0 0 1-1.125-1.125V4.125Z" />'];
}
if ($organization && data_get($organization->settings, 'queue_integration_enabled') && $permissions->can($member, 'service_queues.console')) {
$nav[] = ['name' => 'Service queues', 'route' => route('care.service-queues.index'), 'active' => request()->routeIs('care.service-queues.*'),
'icon' => '<path stroke-linecap="round" stroke-linejoin="round" d="M16.5 6v.75m0 3v.75m0 3v.75m0 3V18m-9-5.25h5.25M7.5 15h3M3.375 5.25c-.621 0-1.125.504-1.125 1.125v3.026a2.999 2.999 0 0 1 0 5.198v3.026c0 .621.504 1.125 1.125 1.125h17.25c.621 0 1.125-.504 1.125-1.125v-3.026a2.999 2.999 0 0 1 0-5.198V6.375c0-.621-.504-1.125-1.125-1.125H3.375Z" />'];
}
$adminNav = [];
if ($permissions->can($member, 'admin.branches.view')) {
$adminNav[] = ['name' => 'Branches', 'route' => route('care.branches.index'), 'active' => request()->routeIs('care.branches.*'),
+5
View File
@@ -19,6 +19,7 @@ use App\Http\Controllers\Care\PatientController;
use App\Http\Controllers\Care\PrescriptionController;
use App\Http\Controllers\Care\QueueController;
use App\Http\Controllers\Care\ReportController;
use App\Http\Controllers\Care\ServiceQueueController;
use App\Http\Controllers\Care\SettingsController;
use Illuminate\Support\Facades\Route;
@@ -71,6 +72,10 @@ Route::middleware(['auth', 'platform.session'])->group(function () {
Route::get('/queue', [QueueController::class, 'index'])->name('care.queue.index');
Route::post('/queue/{appointment}/start', [QueueController::class, 'start'])->name('care.queue.start');
Route::get('/service-queues', [ServiceQueueController::class, 'index'])->name('care.service-queues.index');
Route::get('/service-queues/console/{counterUuid}', [ServiceQueueController::class, 'console'])->name('care.service-queues.console');
Route::post('/service-queues/console/{counterUuid}/action', [ServiceQueueController::class, 'action'])->name('care.service-queues.action');
Route::get('/consultations/{consultation}', [ConsultationController::class, 'show'])->name('care.consultations.show');
Route::put('/consultations/{consultation}', [ConsultationController::class, 'update'])->name('care.consultations.update');
Route::post('/consultations/{consultation}/complete', [ConsultationController::class, 'complete'])->name('care.consultations.complete');