Patients can be admitted, transferred, and discharged from unit/bed stays with occupancy sync, so MAR and ward boards have inpatient context. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -6,7 +6,9 @@ use App\Http\Controllers\Controller;
|
||||
use App\Http\Controllers\Care\Concerns\ScopesToAccount;
|
||||
use App\Models\CareUnit;
|
||||
use App\Models\Department;
|
||||
use App\Models\Visit;
|
||||
use App\Services\Care\AuditLogger;
|
||||
use App\Services\Care\CarePermissions;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Validation\Rule;
|
||||
@@ -18,7 +20,7 @@ class CareUnitController extends Controller
|
||||
|
||||
public function index(Request $request): View
|
||||
{
|
||||
$this->authorizeAbility($request, 'admin.departments.view');
|
||||
$this->authorizeCareUnitView($request);
|
||||
$organization = $this->organization($request);
|
||||
$owner = $this->ownerRef($request);
|
||||
|
||||
@@ -98,18 +100,63 @@ class CareUnitController extends Controller
|
||||
|
||||
public function show(Request $request, CareUnit $careUnit): View
|
||||
{
|
||||
$this->authorizeAbility($request, 'admin.departments.view');
|
||||
$this->authorizeCareUnitView($request);
|
||||
$this->authorizeOwner($request, $careUnit);
|
||||
$organization = $this->organization($request);
|
||||
abort_unless((int) $careUnit->organization_id === (int) $organization->id, 404);
|
||||
|
||||
$careUnit->load(['department.branch', 'beds']);
|
||||
|
||||
$placedVisits = Visit::owned($this->ownerRef($request))
|
||||
->where('organization_id', $organization->id)
|
||||
->where('care_unit_id', $careUnit->id)
|
||||
->whereIn('status', [Visit::STATUS_OPEN, Visit::STATUS_IN_PROGRESS])
|
||||
->with(['patient', 'bed'])
|
||||
->orderBy('placed_at')
|
||||
->get();
|
||||
|
||||
$placeableVisits = Visit::owned($this->ownerRef($request))
|
||||
->where('organization_id', $organization->id)
|
||||
->where('branch_id', $careUnit->department?->branch_id)
|
||||
->whereIn('status', [Visit::STATUS_OPEN, Visit::STATUS_IN_PROGRESS])
|
||||
->where(function ($q) use ($careUnit) {
|
||||
$q->whereNull('care_unit_id')
|
||||
->orWhere('care_unit_id', '!=', $careUnit->id);
|
||||
})
|
||||
->with(['patient', 'careUnit'])
|
||||
->orderByDesc('checked_in_at')
|
||||
->limit(50)
|
||||
->get();
|
||||
|
||||
$availableBeds = $careUnit->beds
|
||||
->where('is_active', true)
|
||||
->whereIn('status', ['available', 'reserved'])
|
||||
->values();
|
||||
|
||||
$canPlace = app(CarePermissions::class)->can($this->member($request), 'inpatient.placement.manage');
|
||||
|
||||
return view('care.admin.care-units.show', [
|
||||
'unit' => $careUnit,
|
||||
'kinds' => config('care.care_unit_kinds'),
|
||||
'bedStatuses' => config('care.bed_statuses'),
|
||||
'placedVisits' => $placedVisits,
|
||||
'placeableVisits' => $placeableVisits,
|
||||
'availableBeds' => $availableBeds,
|
||||
'canPlace' => $canPlace,
|
||||
]);
|
||||
}
|
||||
|
||||
protected function authorizeCareUnitView(Request $request): void
|
||||
{
|
||||
$permissions = app(CarePermissions::class);
|
||||
$member = $this->member($request);
|
||||
abort_unless(
|
||||
$permissions->can($member, 'admin.departments.view')
|
||||
|| $permissions->can($member, 'inpatient.placement.view'),
|
||||
403,
|
||||
);
|
||||
}
|
||||
|
||||
public function edit(Request $request, CareUnit $careUnit): View
|
||||
{
|
||||
$this->authorizeAbility($request, 'admin.departments.manage');
|
||||
|
||||
Reference in New Issue
Block a user