Allow specialty doctors to open patient charts and order labs.
Deploy Ladill Care / deploy (push) Successful in 1m18s

Branch-scoped staff could 404 on charts when the patient's home branch differed from the visit site; Orders also linked doctors to a lab index they could not access.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
isaacclad
2026-07-18 16:49:59 +00:00
co-authored by Cursor
parent c3a090112b
commit e227f8705f
7 changed files with 159 additions and 21 deletions
@@ -4,8 +4,10 @@ namespace App\Http\Controllers\Care;
use App\Http\Controllers\Controller;
use App\Http\Controllers\Care\Concerns\ScopesToAccount;
use App\Models\Appointment;
use App\Models\Branch;
use App\Models\Patient;
use App\Models\Visit;
use App\Services\Care\AdminOverviewService;
use App\Services\Care\CareFeatures;
use App\Services\Care\CarePermissions;
@@ -293,9 +295,24 @@ class PatientController extends Controller
abort_unless($patient->organization_id === $this->organization($request)->id, 404);
$branchId = app(OrganizationResolver::class)->branchScope($this->member($request));
if ($branchId !== null && $patient->branch_id !== $branchId) {
abort(404);
if ($branchId === null || $patient->branch_id === $branchId) {
return;
}
// Home branch may differ from the site where care is delivered — allow chart
// access when the patient has a visit or appointment at the member's branch.
$hasLocalActivity = Visit::query()
->where('patient_id', $patient->id)
->where('organization_id', $patient->organization_id)
->where('branch_id', $branchId)
->exists()
|| Appointment::query()
->where('patient_id', $patient->id)
->where('organization_id', $patient->organization_id)
->where('branch_id', $branchId)
->exists();
abort_unless($hasLocalActivity, 404);
}
/**