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
@@ -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);