Lock doctors to their assigned patients and hide branch filters.
Deploy Ladill Care / deploy (push) Successful in 1m2s

Doctors no longer see branch/practitioner pickers; queue, appointments, patients, and dashboard only include visits on their linked desk.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
isaacclad
2026-07-18 06:28:07 +00:00
co-authored by Cursor
parent 5264035705
commit dcbc62d1d3
11 changed files with 361 additions and 89 deletions
+86 -32
View File
@@ -33,43 +33,84 @@ class QueueController extends Controller
$this->authorizeAbility($request, 'appointments.view');
$organization = $this->organization($request);
$member = $this->member($request);
$owner = $this->ownerRef($request);
$resolver = app(OrganizationResolver::class);
$practitionerScope = $resolver->practitionerScope($organization, $member);
$lockToPractitioner = $practitionerScope !== null;
$branches = $this->branchContext->branches($request, $organization, $member);
$branchId = $this->branchContext->resolve($request, $organization, $member);
$practitionerId = $request->input('practitioner_id') ? (int) $request->input('practitioner_id') : null;
$practitionerId = $lockToPractitioner
? ($practitionerScope[0] ?? null)
: ($request->input('practitioner_id') ? (int) $request->input('practitioner_id') : null);
$queueIntegration = ['enabled' => false];
if ($branchId && $this->queueBridge->isEnabled($organization)) {
// Catch up tickets for every waiting appointment (consultation + specialties).
$this->queueBridge->syncMissingAppointmentTickets($organization, $branchId, 100);
$queueIntegration = $this->queueBridge->listMeta($organization, CareQueueContexts::CONSULTATION, $branchId);
if ($this->queueBridge->isEnabled($organization)) {
$syncBranches = $lockToPractitioner
? Practitioner::owned($owner)
->whereIn('id', $practitionerScope ?: [0])
->pluck('branch_id')
->map(fn ($id) => (int) $id)
->unique()
->filter()
->values()
->all()
: array_filter([$branchId]);
foreach ($syncBranches as $syncBranchId) {
$this->queueBridge->syncMissingAppointmentTickets($organization, $syncBranchId, 100);
}
if ($branchId > 0) {
$queueIntegration = $this->queueBridge->listMeta($organization, CareQueueContexts::CONSULTATION, $branchId);
} elseif ($syncBranches !== []) {
$queueIntegration = $this->queueBridge->listMeta(
$organization,
CareQueueContexts::CONSULTATION,
(int) $syncBranches[0],
);
}
}
$queue = $branchId
? $this->appointments->queue($this->ownerRef($request), $branchId, $practitionerId)
: collect();
if ($lockToPractitioner) {
$queue = $this->appointments->queueForPractitioners($owner, $practitionerScope ?? []);
$inConsultation = Appointment::owned($owner)
->where('organization_id', $organization->id)
->where('status', Appointment::STATUS_IN_CONSULTATION)
->whereIn('practitioner_id', $practitionerScope ?: [0])
->with(['patient', 'practitioner', 'consultation'])
->orderBy('started_at')
->get();
} else {
$queue = $branchId
? $this->appointments->queue($owner, $branchId, $practitionerId)
: collect();
$inConsultation = Appointment::owned($owner)
->where('organization_id', $organization->id)
->where('status', Appointment::STATUS_IN_CONSULTATION)
->when($branchId, fn ($q) => $q->where('branch_id', $branchId))
->when($practitionerId, fn ($q) => $q->where('practitioner_id', $practitionerId))
->with(['patient', 'practitioner', 'consultation'])
->orderBy('started_at')
->get();
}
$inConsultation = Appointment::owned($this->ownerRef($request))
$canManageQueue = app(CarePermissions::class)->can($member, 'queue.manage');
$canConsult = app(CarePermissions::class)->can($member, 'consultations.manage');
$todayQuery = Appointment::owned($owner)
->where('organization_id', $organization->id)
->where('status', Appointment::STATUS_IN_CONSULTATION)
->when($branchId, fn ($q) => $q->where('branch_id', $branchId))
->when($practitionerId, fn ($q) => $q->where('practitioner_id', $practitionerId))
->with(['patient', 'practitioner', 'consultation'])
->orderBy('started_at')
->get();
$canManageQueue = app(CarePermissions::class)
->can($this->member($request), 'queue.manage');
$canConsult = app(CarePermissions::class)
->can($this->member($request), 'consultations.manage');
->whereDate('scheduled_at', today());
if ($lockToPractitioner) {
$todayQuery->whereIn('practitioner_id', $practitionerScope ?: [0]);
} elseif ($branchId) {
$todayQuery->where('branch_id', $branchId);
}
$heroStats = [
'waiting' => $queue->count(),
'in_consultation' => $inConsultation->count(),
'today' => Appointment::owned($this->ownerRef($request))
->where('organization_id', $organization->id)
->when($branchId, fn ($q) => $q->where('branch_id', $branchId))
->whereDate('scheduled_at', today())
->count(),
'today' => $todayQuery->count(),
];
return view('care.queue.index', [
@@ -77,12 +118,15 @@ class QueueController extends Controller
'branches' => $branches,
'branchId' => $branchId,
'canSwitchBranch' => $this->branchContext->canSwitch($member),
'practitioners' => Practitioner::owned($this->ownerRef($request))
->where('organization_id', $organization->id)
->where('is_active', true)
->when($branchId, fn ($q) => $q->where('branch_id', $branchId))
->orderBy('name')
->get(),
'lockToPractitioner' => $lockToPractitioner,
'practitioners' => $lockToPractitioner
? collect()
: Practitioner::owned($owner)
->where('organization_id', $organization->id)
->where('is_active', true)
->when($branchId, fn ($q) => $q->where('branch_id', $branchId))
->orderBy('name')
->get(),
'practitionerId' => $practitionerId,
'queue' => $queue,
'inConsultation' => $inConsultation,
@@ -100,7 +144,17 @@ class QueueController extends Controller
abort_unless($this->queueBridge->isEnabled($organization), 404);
$member = $this->member($request);
$practitionerScope = app(OrganizationResolver::class)->practitionerScope($organization, $member);
$branchId = $this->branchContext->resolve($request, $organization, $member);
$practitionerId = $request->input('practitioner_id') ? (int) $request->input('practitioner_id') : null;
if ($practitionerScope !== null) {
abort_unless($practitionerScope !== [], 422);
$practitionerId = $practitionerScope[0];
$prac = Practitioner::owned($this->ownerRef($request))->find($practitionerId);
$branchId = (int) ($prac?->branch_id ?: $branchId);
}
abort_unless($branchId > 0, 422);
$result = $this->queueBridge->callNext(
@@ -108,7 +162,7 @@ class QueueController extends Controller
CareQueueContexts::CONSULTATION,
$branchId,
$member,
$request->input('practitioner_id') ? (int) $request->input('practitioner_id') : null,
$practitionerId,
);
$ticket = $result['ticket'] ?? null;
if (! $ticket) {