radfusion/app/DAL/Studies/WorklistFactory.php
2025-01-03 21:39:29 +06:00

28 lines
827 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;
$role = Cache::remember('user_role:'.auth()->id(), now()->addMinutes(5), fn () => 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"),
};
}
}