Persist admin branch filter across Patient, Pharmacy, Lab, and Bills queues.
Deploy Ladill Care / deploy (push) Successful in 57s

Admins pick a working branch once; session keeps Pharmacy Call Next and lists scoped to that site so ticket numbers no longer collide across branches.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
isaacclad
2026-07-18 05:49:24 +00:00
co-authored by Cursor
parent 88f84a4f96
commit 6cfecc1763
9 changed files with 365 additions and 55 deletions
+8 -10
View File
@@ -8,6 +8,7 @@ use App\Models\Bill;
use App\Models\Consultation;
use App\Models\Visit;
use App\Services\Care\BillService;
use App\Services\Care\BranchContext;
use App\Services\Care\CareQueueBridge;
use App\Services\Care\CareQueueContexts;
use App\Services\Care\ConsultationReturnContext;
@@ -26,6 +27,7 @@ class BillController extends Controller
protected BillService $bills,
protected MerchantGatewayService $gateway,
protected CareQueueBridge $queueBridge,
protected BranchContext $branchContext,
) {}
public function index(Request $request): View
@@ -33,26 +35,23 @@ class BillController extends Controller
$this->authorizeAbility($request, 'bills.view');
$organization = $this->organization($request);
$member = $this->member($request);
$branchScope = app(OrganizationResolver::class)->branchScope($member);
$branches = $this->branchContext->branches($request, $organization, $member);
$branchId = $this->branchContext->resolve($request, $organization, $member);
$bills = $this->bills->list(
$this->ownerRef($request),
$organization->id,
$request->only(['status', 'patient_id']),
$branchScope,
$branchId > 0 ? $branchId : null,
);
$branchId = (int) ($branchScope ?: \App\Models\Branch::owned($this->ownerRef($request))
->where('organization_id', $organization->id)
->where('is_active', true)
->orderBy('name')
->value('id'));
return view('care.bills.index', [
'organization' => $organization,
'bills' => $bills,
'statuses' => config('care.bill_statuses'),
'branches' => $branches,
'branchId' => $branchId,
'canSwitchBranch' => $this->branchContext->canSwitch($member),
'queueIntegration' => $branchId
? $this->queueBridge->listMeta($organization, CareQueueContexts::BILLING, $branchId)
: ['enabled' => false],
@@ -66,8 +65,7 @@ class BillController extends Controller
$this->authorizeAbility($request, 'bills.manage');
$organization = $this->organization($request);
$member = $this->member($request);
$branchScope = app(OrganizationResolver::class)->branchScope($member);
$branchId = (int) ($request->input('branch_id') ?: $branchScope);
$branchId = $this->branchContext->resolve($request, $organization, $member);
abort_unless($branchId > 0, 422);
abort_unless($this->queueBridge->isEnabled($organization), 404);
@@ -4,11 +4,11 @@ namespace App\Http\Controllers\Care;
use App\Http\Controllers\Controller;
use App\Http\Controllers\Care\Concerns\ScopesToAccount;
use App\Models\Branch;
use App\Models\Consultation;
use App\Models\InvestigationRequest;
use App\Models\InvestigationType;
use App\Models\Member;
use App\Services\Care\BranchContext;
use App\Services\Care\CareQueueBridge;
use App\Services\Care\CareQueueContexts;
use App\Services\Care\ConsultationReturnContext;
@@ -25,19 +25,21 @@ class InvestigationController extends Controller
public function __construct(
protected InvestigationService $investigations,
protected CareQueueBridge $queueBridge,
protected BranchContext $branchContext,
) {}
public function index(Request $request): View
{
$this->authorizeAbility($request, 'lab.view');
$organization = $this->organization($request);
$branchScope = app(OrganizationResolver::class)->branchScope($this->member($request));
$member = $this->member($request);
$branchId = $this->branchContext->resolve($request, $organization, $member);
$requests = $this->investigations->list(
$this->ownerRef($request),
$organization->id,
$request->only(['status', 'patient_id']),
$branchScope,
$branchId > 0 ? $branchId : null,
);
return view('care.lab.requests.index', [
@@ -51,16 +53,9 @@ class InvestigationController extends Controller
{
$this->authorizeAbility($request, 'lab.manage');
$organization = $this->organization($request);
$branchScope = app(OrganizationResolver::class)->branchScope($this->member($request));
$branches = Branch::owned($this->ownerRef($request))
->where('organization_id', $organization->id)
->where('is_active', true)
->when($branchScope, fn ($q) => $q->where('id', $branchScope))
->orderBy('name')
->get();
$branchId = (int) ($request->input('branch_id') ?: $branchScope ?: $branches->first()?->id);
$member = $this->member($request);
$branches = $this->branchContext->branches($request, $organization, $member);
$branchId = $this->branchContext->resolve($request, $organization, $member);
$status = $request->input('status');
$queue = $branchId
@@ -71,6 +66,7 @@ class InvestigationController extends Controller
'organization' => $organization,
'branches' => $branches,
'branchId' => $branchId,
'canSwitchBranch' => $this->branchContext->canSwitch($member),
'status' => $status,
'queue' => $queue,
'statuses' => config('care.investigation_statuses'),
@@ -89,8 +85,7 @@ class InvestigationController extends Controller
$this->authorizeAbility($request, 'lab.manage');
$organization = $this->organization($request);
$member = $this->member($request);
$branchScope = app(OrganizationResolver::class)->branchScope($member);
$branchId = (int) ($request->input('branch_id') ?: $branchScope);
$branchId = $this->branchContext->resolve($request, $organization, $member);
abort_unless($branchId > 0, 422);
abort_unless($this->queueBridge->isEnabled($organization), 404);
@@ -7,6 +7,7 @@ use App\Http\Controllers\Care\Concerns\ScopesToAccount;
use App\Models\Consultation;
use App\Models\Prescription;
use App\Models\Practitioner;
use App\Services\Care\BranchContext;
use App\Services\Care\CareQueueBridge;
use App\Services\Care\CareQueueContexts;
use App\Services\Care\ConsultationReturnContext;
@@ -25,19 +26,21 @@ class PrescriptionController extends Controller
protected PrescriptionService $prescriptions,
protected PharmacyService $pharmacy,
protected CareQueueBridge $queueBridge,
protected BranchContext $branchContext,
) {}
public function index(Request $request): View
{
$this->authorizeAbility($request, 'prescriptions.view');
$organization = $this->organization($request);
$branchScope = app(OrganizationResolver::class)->branchScope($this->member($request));
$member = $this->member($request);
$branchId = $this->branchContext->resolve($request, $organization, $member);
$prescriptions = $this->prescriptions->list(
$this->ownerRef($request),
$organization->id,
$request->only(['status', 'patient_id']),
$branchScope,
$branchId > 0 ? $branchId : null,
);
return view('care.prescriptions.index', [
@@ -52,16 +55,12 @@ class PrescriptionController extends Controller
$this->authorizeAbility($request, 'prescriptions.view');
$organization = $this->organization($request);
$member = $this->member($request);
$branchScope = app(OrganizationResolver::class)->branchScope($member);
$branchId = (int) ($branchScope ?: \App\Models\Branch::owned($this->ownerRef($request))
->where('organization_id', $organization->id)
->where('is_active', true)
->orderBy('name')
->value('id'));
$branches = $this->branchContext->branches($request, $organization, $member);
$branchId = $this->branchContext->resolve($request, $organization, $member);
$queue = $this->prescriptions->pharmacyQueue($this->ownerRef($request), $organization->id);
if ($branchScope) {
$queue = $queue->filter(fn (Prescription $rx) => (int) ($rx->visit?->branch_id) === $branchScope)->values();
if ($branchId > 0) {
$queue = $queue->filter(fn (Prescription $rx) => (int) ($rx->visit?->branch_id) === $branchId)->values();
}
$queueIntegration = ['enabled' => false];
@@ -69,10 +68,6 @@ class PrescriptionController extends Controller
// Issue tickets in Care FIFO order so Queue Call Next matches this list.
$this->queueBridge->syncMissingTickets($organization, CareQueueContexts::PHARMACY, $branchId, 50);
$queueIntegration = $this->queueBridge->listMeta($organization, CareQueueContexts::PHARMACY, $branchId);
$queue = $this->prescriptions->pharmacyQueue($this->ownerRef($request), $organization->id);
if ($branchScope) {
$queue = $queue->filter(fn (Prescription $rx) => (int) ($rx->visit?->branch_id) === $branchScope)->values();
}
}
$memberPoint = $branchId
@@ -112,7 +107,9 @@ class PrescriptionController extends Controller
'queue' => $queue,
'drugs' => $drugs,
'canDispense' => $canDispense,
'branches' => $branches,
'branchId' => $branchId,
'canSwitchBranch' => $this->branchContext->canSwitch($member),
'queueIntegration' => $queueIntegration,
'memberCounterUuid' => $memberCounterUuid,
]);
@@ -123,8 +120,7 @@ class PrescriptionController extends Controller
$this->authorizeAbility($request, 'prescriptions.dispense');
$organization = $this->organization($request);
$member = $this->member($request);
$branchScope = app(OrganizationResolver::class)->branchScope($member);
$branchId = (int) ($request->input('branch_id') ?: $branchScope);
$branchId = $this->branchContext->resolve($request, $organization, $member);
abort_unless($branchId > 0, 422);
abort_unless($this->queueBridge->isEnabled($organization), 404);
+7 -13
View File
@@ -5,9 +5,9 @@ namespace App\Http\Controllers\Care;
use App\Http\Controllers\Care\Concerns\ScopesToAccount;
use App\Http\Controllers\Controller;
use App\Models\Appointment;
use App\Models\Branch;
use App\Models\Practitioner;
use App\Services\Care\AppointmentService;
use App\Services\Care\BranchContext;
use App\Services\Care\CarePermissions;
use App\Services\Care\CareQueueBridge;
use App\Services\Care\CareQueueContexts;
@@ -25,6 +25,7 @@ class QueueController extends Controller
protected AppointmentService $appointments,
protected ConsultationService $consultations,
protected CareQueueBridge $queueBridge,
protected BranchContext $branchContext,
) {}
public function index(Request $request): View
@@ -32,16 +33,8 @@ class QueueController extends Controller
$this->authorizeAbility($request, 'appointments.view');
$organization = $this->organization($request);
$member = $this->member($request);
$branchScope = app(OrganizationResolver::class)->branchScope($member);
$branches = Branch::owned($this->ownerRef($request))
->where('organization_id', $organization->id)
->where('is_active', true)
->when($branchScope, fn ($q) => $q->where('id', $branchScope))
->orderBy('name')
->get();
$branchId = (int) ($request->input('branch_id') ?: $branchScope ?: $branches->first()?->id);
$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;
$queueIntegration = ['enabled' => false];
@@ -83,9 +76,11 @@ class QueueController extends Controller
'organization' => $organization,
'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(),
'practitionerId' => $practitionerId,
@@ -105,8 +100,7 @@ class QueueController extends Controller
abort_unless($this->queueBridge->isEnabled($organization), 404);
$member = $this->member($request);
$branchScope = app(OrganizationResolver::class)->branchScope($member);
$branchId = (int) ($request->input('branch_id') ?: $branchScope);
$branchId = $this->branchContext->resolve($request, $organization, $member);
abort_unless($branchId > 0, 422);
$result = $this->queueBridge->callNext(