96 lines
2.7 KiB
PHP
96 lines
2.7 KiB
PHP
<?php
|
|
|
|
namespace App\DAL\Studies;
|
|
|
|
use App\Models\Enums\ReportStatus;
|
|
use Illuminate\Contracts\Database\Eloquent\Builder;
|
|
use Illuminate\Contracts\Pagination\LengthAwarePaginator;
|
|
|
|
abstract class WorklistBase implements IUserStudyLister
|
|
{
|
|
private ?int $pageSize = null;
|
|
|
|
private ?string $sortColumn = null;
|
|
|
|
private ?string $sortDir = null;
|
|
|
|
private ?string $searchTerm = null;
|
|
|
|
protected static function reportCompleteQuery(Builder $query): Builder
|
|
{
|
|
return $query->where('report_status', '=', ReportStatus::Signed->value);
|
|
}
|
|
|
|
protected function applySortQuery(Builder $query): Builder
|
|
{
|
|
if ($this->sortColumn) {
|
|
return $query->orderBy($this->sortColumn, $this->sortDir ?? 'ASC');
|
|
}
|
|
|
|
return $query
|
|
->orderByDesc('study_priority')
|
|
->orderByDesc('received_at');
|
|
}
|
|
|
|
protected static function reportPendingQuery(Builder $query): Builder
|
|
{
|
|
return $query->where('report_status', '<', ReportStatus::Finalized->value);
|
|
}
|
|
|
|
abstract protected function buildQuery(?int $user_id = null): Builder;
|
|
|
|
public function all(?int $user_id = null): LengthAwarePaginator
|
|
{
|
|
return $this->buildQuery($user_id)
|
|
->paginate($this->getPageSize($user_id));
|
|
}
|
|
|
|
public function pending(?int $user_id = null): LengthAwarePaginator
|
|
{
|
|
return self::reportPendingQuery(self::buildQuery($user_id))
|
|
->paginate($this->getPageSize($user_id));
|
|
}
|
|
|
|
public function completed(?int $user_id = null): LengthAwarePaginator
|
|
{
|
|
return self::reportCompleteQuery(self::buildQuery($user_id))
|
|
->paginate($this->getPageSize($user_id));
|
|
}
|
|
|
|
public function setPageSize(int $size): void
|
|
{
|
|
$this->pageSize = $size;
|
|
}
|
|
|
|
public function setSortColumn(string $column, string $dir): void
|
|
{
|
|
$this->sortColumn = $column;
|
|
$this->sortDir = $dir;
|
|
}
|
|
|
|
public function setSearchTerm(string $search): void
|
|
{
|
|
$this->searchTerm = $search;
|
|
}
|
|
|
|
public function getPageSize(?int $user_id = null): int
|
|
{
|
|
return $this->pageSize ?? $this->getPageSize($user_id);
|
|
}
|
|
|
|
public function applySearch(Builder $query): Builder
|
|
{
|
|
if ($this->searchTerm) {
|
|
$search = "%{$this->searchTerm}%";
|
|
$query = $query->where(function ($query) use ($search) {
|
|
$query->orWhere('patient_name', 'like', $search);
|
|
$query->orWhere('patient_id', 'like', $search);
|
|
$query->orWhere('study_description', 'like', $search);
|
|
$query->orWhere('body_part_examined', 'like', $search);
|
|
});
|
|
}
|
|
|
|
return $query;
|
|
}
|
|
}
|