radfusion/app/DAL/Studies/WorklistFactory.php
2025-01-05 12:57:50 +06:00

29 lines
870 B
PHP

<?php
namespace App\DAL\Studies;
use App\Models\Enums\UserRole;
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 (UserRole::from($role)) {
UserRole::Admin => new AdminWorklist,
UserRole::Technician => new TechnicianWorklist,
UserRole::Radiologist => new RadiologistWorklist,
UserRole::ReferringDoctor => new ReferrerWorklist,
default => throw new Exception("Unknown user role: {$role}"),
};
}
}