radfusion/app/DAL/Studies/WorklistFactory.php
2025-01-22 18:17:24 +06:00

29 lines
839 B
PHP

<?php
namespace App\DAL\Studies;
use App\Domain\ACL\Role;
use Exception;
use Illuminate\Support\Facades\Cache;
final readonly class WorklistFactory
{
/**
* @throws Exception
*/
public static function getLister(): IUserStudyLister
{
// $role = auth()->user()->roles()->first()->name;
$key = sprintf('user_role:%d', auth()->id());
$role = Cache::remember($key, now()->addMinutes(5), fn (): string => auth()->user()->roles()->first()->name);
return match (Role::from($role)) {
Role::Admin => new AdminWorklist,
Role::Technician => new TechnicianWorklist,
Role::Radiologist => new RadiologistWorklist,
Role::Clinician => new ClinicianWorklist,
default => throw new Exception("Unknown user role: {$role}"),
};
}
}