Lock doctors to a single branch — never a branch picker.
Deploy Ladill Care / deploy (push) Successful in 1m3s

Doctors were treated as multi-branch when Identity cleared branch_id; now they stay on their assigned/desk site, specialty desks are home-branch only, and the queue shows site name as text only.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
isaacclad
2026-07-18 08:45:57 +00:00
co-authored by Cursor
parent bb4dbee81a
commit d643687335
10 changed files with 120 additions and 23 deletions
+24 -3
View File
@@ -180,7 +180,7 @@ class OrganizationResolver
};
}
/** Branch ID the member may access; null = all branches. */
/** Branch ID the member may access; null = all branches (admins only). */
public function branchScope(?Member $member): ?int
{
if ($member === null) {
@@ -191,12 +191,30 @@ class OrganizationResolver
return null;
}
if ($member->branch_id) {
return (int) $member->branch_id;
}
// Doctors are always one site. Prefer linked desk when Identity omitted branch_id.
if ($member->role === 'doctor') {
$deskBranch = Practitioner::query()
->where('is_active', true)
->where(function ($query) use ($member) {
$query->where('member_id', $member->id)
->orWhere('user_ref', $member->user_ref);
})
->orderBy('id')
->value('branch_id');
return $deskBranch ? (int) $deskBranch : 0;
}
return $member->branch_id;
}
/**
* Practitioner IDs a doctor is locked to. Null = no practitioner lock (non-doctors).
* Empty array = doctor with no linked practitioner desk (see no clinical queue).
* Practitioner IDs a doctor is locked to (single branch). Null = no practitioner lock.
* Empty array = doctor with no linked desk on their branch.
*
* @return list<int>|null
*/
@@ -206,9 +224,12 @@ class OrganizationResolver
return null;
}
$branchId = $this->branchScope($member);
return Practitioner::owned((string) $organization->owner_ref)
->where('organization_id', $organization->id)
->where('is_active', true)
->when($branchId, fn ($q) => $q->where('branch_id', $branchId))
->where(function ($query) use ($member) {
$query->where('member_id', $member->id)
->orWhere('user_ref', $member->user_ref);