wip
This commit is contained in:
parent
75065baae8
commit
5a4d7ce7b4
14
app/DAL/Studies/AdminStudyLister.php
Normal file
14
app/DAL/Studies/AdminStudyLister.php
Normal file
@ -0,0 +1,14 @@
|
||||
<?php
|
||||
|
||||
namespace App\DAL\Studies;
|
||||
|
||||
use App\Models\Study;
|
||||
use Illuminate\Database\Query\Builder;
|
||||
|
||||
class AdminStudyLister extends UserStudyListerBase
|
||||
{
|
||||
protected static function defaultQuery(?int $user_id = null): Builder
|
||||
{
|
||||
return self::defaultSortQuery(Study::active());
|
||||
}
|
||||
}
|
14
app/DAL/Studies/IUserStudyLister.php
Normal file
14
app/DAL/Studies/IUserStudyLister.php
Normal file
@ -0,0 +1,14 @@
|
||||
<?php
|
||||
|
||||
namespace App\DAL\Studies;
|
||||
|
||||
use Illuminate\Contracts\Pagination\LengthAwarePaginator;
|
||||
|
||||
interface IUserStudyLister
|
||||
{
|
||||
public function all(?int $user_id = null): LengthAwarePaginator;
|
||||
|
||||
public function pending(?int $user_id = null): LengthAwarePaginator;
|
||||
|
||||
public function completed(?int $user_id = null): LengthAwarePaginator;
|
||||
}
|
18
app/DAL/Studies/RadiologistStudyLister.php
Normal file
18
app/DAL/Studies/RadiologistStudyLister.php
Normal file
@ -0,0 +1,18 @@
|
||||
<?php
|
||||
|
||||
namespace App\DAL\Studies;
|
||||
|
||||
use App\Models\Study;
|
||||
use Illuminate\Database\Query\Builder;
|
||||
|
||||
class RadiologistStudyLister extends UserStudyListerBase
|
||||
{
|
||||
protected static function defaultQuery(?int $user_id = null): Builder
|
||||
{
|
||||
$user_id = (int) ($user_id ?? auth()->id());
|
||||
|
||||
return self::defaultSortQuery(
|
||||
Study::active()->where('assigned_physician_id', $user_id)
|
||||
);
|
||||
}
|
||||
}
|
23
app/DAL/Studies/TechnicianStudyLister.php
Normal file
23
app/DAL/Studies/TechnicianStudyLister.php
Normal file
@ -0,0 +1,23 @@
|
||||
<?php
|
||||
|
||||
namespace App\DAL\Studies;
|
||||
|
||||
use App\Models\Study;
|
||||
use Illuminate\Database\Query\Builder;
|
||||
|
||||
class TechnicianStudyLister extends UserStudyListerBase
|
||||
{
|
||||
protected static function defaultQuery(?int $user_id = null): Builder
|
||||
{
|
||||
$query = Study::active();
|
||||
$facility_id = auth()->user()->facility_id;
|
||||
if ($facility_id) {
|
||||
$query = $query->where('facility_id', $facility_id);
|
||||
} else {
|
||||
$institute_id = auth()->user()->institute_id;
|
||||
$query = $query->where('institute_id', $institute_id);
|
||||
}
|
||||
|
||||
return self::defaultSortQuery($query);
|
||||
}
|
||||
}
|
47
app/DAL/Studies/UserStudyListerBase.php
Normal file
47
app/DAL/Studies/UserStudyListerBase.php
Normal file
@ -0,0 +1,47 @@
|
||||
<?php
|
||||
|
||||
namespace App\DAL\Studies;
|
||||
|
||||
use App\Models\Enums\ReportStatus;
|
||||
use Illuminate\Contracts\Pagination\LengthAwarePaginator;
|
||||
use Illuminate\Database\Query\Builder;
|
||||
|
||||
abstract class UserStudyListerBase implements IUserStudyLister
|
||||
{
|
||||
protected static function reportCompleteQuery(Builder $query): Builder
|
||||
{
|
||||
return $query->where('report_status', '=', ReportStatus::Signed->value);
|
||||
}
|
||||
|
||||
protected static function defaultSortQuery(Builder $query): Builder
|
||||
{
|
||||
return $query
|
||||
->orderBy('study_priority', 'desc')
|
||||
->orderBy('received_at', 'asc');
|
||||
}
|
||||
|
||||
protected static function reportPendingQuery(Builder $query): Builder
|
||||
{
|
||||
return $query->where('report_status', '<', ReportStatus::Finalized->value);
|
||||
}
|
||||
|
||||
abstract protected static function defaultQuery(?int $user_id = null): Builder;
|
||||
|
||||
public function all(?int $user_id = null): LengthAwarePaginator
|
||||
{
|
||||
return self::defaultQuery($user_id)
|
||||
->paginate(user_per_page($user_id));
|
||||
}
|
||||
|
||||
public function pending(?int $user_id = null): LengthAwarePaginator
|
||||
{
|
||||
return self::reportPendingQuery(self::defaultQuery($user_id))
|
||||
->paginate(user_per_page($user_id));
|
||||
}
|
||||
|
||||
public function completed(?int $user_id = null): LengthAwarePaginator
|
||||
{
|
||||
return self::reportCompleteQuery(self::defaultQuery($user_id))
|
||||
->paginate(user_per_page($user_id));
|
||||
}
|
||||
}
|
24
app/DAL/Studies/UserStudyListerFactory.php
Normal file
24
app/DAL/Studies/UserStudyListerFactory.php
Normal file
@ -0,0 +1,24 @@
|
||||
<?php
|
||||
|
||||
namespace App\DAL\Studies;
|
||||
|
||||
use App\Models\Enums\UserRole;
|
||||
use Exception;
|
||||
|
||||
final readonly class UserStudyListerFactory
|
||||
{
|
||||
/**
|
||||
* @throws Exception
|
||||
*/
|
||||
public static function getLister(): IUserStudyLister
|
||||
{
|
||||
$user_role = (int) auth()->user()->user_role;
|
||||
|
||||
return match (UserRole::from($user_role)) {
|
||||
UserRole::Admin => new AdminStudyLister,
|
||||
UserRole::Technician => new TechnicianStudyLister,
|
||||
UserRole::Radiologist => new RadiologistStudyLister,
|
||||
default => throw new Exception("Unknown user role: $user_role"),
|
||||
};
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user