wip
This commit is contained in:
parent
03862c5460
commit
60c272f07c
@ -2,13 +2,12 @@
|
||||
|
||||
namespace App\DAL\Studies;
|
||||
|
||||
use App\Models\Study;
|
||||
use Illuminate\Contracts\Database\Eloquent\Builder;
|
||||
|
||||
final class AdminWorklist extends WorklistBase
|
||||
{
|
||||
protected function buildQuery(?int $user_id = null): Builder
|
||||
{
|
||||
return self::applySortQuery(Study::active());
|
||||
return $this->getStudiesQuery();
|
||||
}
|
||||
}
|
||||
|
@ -2,19 +2,27 @@
|
||||
|
||||
namespace App\DAL\Studies;
|
||||
|
||||
use App\Models\Enums\ReportStatus;
|
||||
use App\Models\Enums\StudyLevelStatus;
|
||||
use Illuminate\Contracts\Pagination\LengthAwarePaginator;
|
||||
|
||||
interface IUserStudyLister
|
||||
{
|
||||
public function setRadiologist(int $radiologist_id): void;
|
||||
|
||||
public function setStudyStatus(StudyLevelStatus $status): void;
|
||||
|
||||
public function setReportStatus(ReportStatus $status): void;
|
||||
|
||||
public function setPageSize(int $size): void;
|
||||
|
||||
public function setSortColumn(string $column, string $dir): void;
|
||||
|
||||
public function setSearchTerm(string $search): void;
|
||||
|
||||
public function all(?int $user_id = null): LengthAwarePaginator;
|
||||
public function setArchived(bool $archived): void;
|
||||
|
||||
public function pending(?int $user_id = null): LengthAwarePaginator;
|
||||
public function setLocked(bool $locked): void;
|
||||
|
||||
public function completed(?int $user_id = null): LengthAwarePaginator;
|
||||
public function get(?int $user_id = null): LengthAwarePaginator;
|
||||
}
|
||||
|
@ -2,7 +2,6 @@
|
||||
|
||||
namespace App\DAL\Studies;
|
||||
|
||||
use App\Models\Study;
|
||||
use Illuminate\Contracts\Database\Eloquent\Builder;
|
||||
|
||||
final class RadiologistWorklist extends WorklistBase
|
||||
@ -10,9 +9,8 @@ final class RadiologistWorklist extends WorklistBase
|
||||
protected function buildQuery(?int $user_id = null): Builder
|
||||
{
|
||||
$user_id = (int) ($user_id ?? auth()->id());
|
||||
$this->setRadiologist($user_id);
|
||||
|
||||
return self::applySortQuery(
|
||||
Study::active()->where('assigned_physician_id', $user_id)
|
||||
);
|
||||
return $this->getStudiesQuery();
|
||||
}
|
||||
}
|
||||
|
@ -2,7 +2,6 @@
|
||||
|
||||
namespace App\DAL\Studies;
|
||||
|
||||
use App\Models\Study;
|
||||
use Illuminate\Contracts\Database\Eloquent\Builder;
|
||||
|
||||
final class ReferrerWorklist extends WorklistBase
|
||||
@ -11,8 +10,6 @@ protected function buildQuery(?int $user_id = null): Builder
|
||||
{
|
||||
$user_id = (int) ($user_id ?? auth()->id());
|
||||
|
||||
return self::applySortQuery(
|
||||
Study::active()->where('referring_provider_id', $user_id)
|
||||
);
|
||||
return $this->getStudiesQuery()->where('referring_provider_id', $user_id);
|
||||
}
|
||||
}
|
||||
|
@ -2,14 +2,13 @@
|
||||
|
||||
namespace App\DAL\Studies;
|
||||
|
||||
use App\Models\Study;
|
||||
use Illuminate\Contracts\Database\Eloquent\Builder;
|
||||
|
||||
final class TechnicianWorklist extends WorklistBase
|
||||
{
|
||||
protected function buildQuery(?int $user_id = null): Builder
|
||||
{
|
||||
$query = Study::active();
|
||||
$query = $this->getStudiesQuery();
|
||||
$facility_id = auth()->user()->facility_id;
|
||||
if ($facility_id) {
|
||||
$query = $query->where('facility_id', $facility_id);
|
||||
@ -18,6 +17,6 @@ protected function buildQuery(?int $user_id = null): Builder
|
||||
$query = $query->where('institute_id', $institute_id);
|
||||
}
|
||||
|
||||
return self::applySortQuery($query);
|
||||
return $query;
|
||||
}
|
||||
}
|
||||
|
@ -3,6 +3,8 @@
|
||||
namespace App\DAL\Studies;
|
||||
|
||||
use App\Models\Enums\ReportStatus;
|
||||
use App\Models\Enums\StudyLevelStatus;
|
||||
use App\Models\Study;
|
||||
use Illuminate\Contracts\Database\Eloquent\Builder;
|
||||
use Illuminate\Contracts\Pagination\LengthAwarePaginator;
|
||||
|
||||
@ -16,12 +18,77 @@ abstract class WorklistBase implements IUserStudyLister
|
||||
|
||||
private ?string $searchTerm = null;
|
||||
|
||||
private ?int $radiologist_id = null;
|
||||
|
||||
private ?StudyLevelStatus $studyStatus = null;
|
||||
|
||||
private ?ReportStatus $reportStatus = null;
|
||||
|
||||
private ?bool $locked = null;
|
||||
|
||||
private ?bool $archived = null;
|
||||
|
||||
public function setRadiologist(int $radiologist_id): void
|
||||
{
|
||||
$this->radiologist_id = $radiologist_id;
|
||||
}
|
||||
|
||||
public function setStudyStatus(StudyLevelStatus $status): void
|
||||
{
|
||||
$this->studyStatus = $status;
|
||||
}
|
||||
|
||||
private function applyRadiologist(Builder $query): Builder
|
||||
{
|
||||
if ($this->radiologist_id != null) {
|
||||
$rad = $this->radiologist_id;
|
||||
$query = $query->where(function ($query) use ($rad) {
|
||||
$query->orWhere('assigned_physician_id', '=', $rad);
|
||||
$query->orWhere('reading_physician_id', '=', $rad);
|
||||
});
|
||||
}
|
||||
|
||||
return $query;
|
||||
}
|
||||
|
||||
protected function getStudiesQuery(): Builder
|
||||
{
|
||||
if ($this->archived === null) {
|
||||
return Study::active();
|
||||
}
|
||||
|
||||
return Study::query();
|
||||
}
|
||||
|
||||
private function applyStudyStatus(Builder $query): Builder
|
||||
{
|
||||
if ($this->studyStatus != null) {
|
||||
$query = $query->where('study_status', '=', $this->studyStatus->value);
|
||||
}
|
||||
|
||||
return $query;
|
||||
}
|
||||
|
||||
private function applyReportStatus(Builder $query): Builder
|
||||
{
|
||||
if ($this->reportStatus != null) {
|
||||
$query = $query->where('report_status', '=', $this->reportStatus->value);
|
||||
}
|
||||
|
||||
return $query;
|
||||
}
|
||||
|
||||
public function setReportStatus(ReportStatus $status): void
|
||||
{
|
||||
$this->reportStatus = $status;
|
||||
}
|
||||
|
||||
protected static function reportCompleteQuery(Builder $query): Builder
|
||||
{
|
||||
return $query->where('report_status', '=', ReportStatus::Signed->value);
|
||||
}
|
||||
|
||||
protected function applySortQuery(Builder $query): Builder
|
||||
protected function applySort(Builder $query): Builder
|
||||
{
|
||||
if ($this->sortColumn) {
|
||||
return $query->orderBy($this->sortColumn, $this->sortDir ?? 'ASC');
|
||||
@ -32,29 +99,31 @@ protected function applySortQuery(Builder $query): Builder
|
||||
->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
|
||||
public function get(?int $user_id = null): LengthAwarePaginator
|
||||
{
|
||||
return $this->buildQuery($user_id)
|
||||
$query = $this->buildQuery($user_id);
|
||||
$query = $this->applySort($query);
|
||||
$query = $this->applySearch($query);
|
||||
$query = $this->applyRadiologist($query);
|
||||
$query = $this->applyStudyStatus($query);
|
||||
$query = $this->applyReportStatus($query);
|
||||
$query = $this->applyArchived($query);
|
||||
$query = $this->applyLocked($query);
|
||||
|
||||
return $query
|
||||
->paginate($this->getPageSize($user_id));
|
||||
}
|
||||
|
||||
public function pending(?int $user_id = null): LengthAwarePaginator
|
||||
public function setArchived(bool $archived): void
|
||||
{
|
||||
return self::reportPendingQuery(self::buildQuery($user_id))
|
||||
->paginate($this->getPageSize($user_id));
|
||||
$this->archived = $archived;
|
||||
}
|
||||
|
||||
public function completed(?int $user_id = null): LengthAwarePaginator
|
||||
public function setLocked(bool $locked): void
|
||||
{
|
||||
return self::reportCompleteQuery(self::buildQuery($user_id))
|
||||
->paginate($this->getPageSize($user_id));
|
||||
$this->locked = $locked;
|
||||
}
|
||||
|
||||
public function setPageSize(int $size): void
|
||||
@ -73,18 +142,19 @@ public function setSearchTerm(string $search): void
|
||||
$this->searchTerm = $search;
|
||||
}
|
||||
|
||||
public function getPageSize(?int $user_id = null): int
|
||||
private function getPageSize(?int $user_id = null): int
|
||||
{
|
||||
return $this->pageSize ?? $this->getPageSize($user_id);
|
||||
}
|
||||
|
||||
public function applySearch(Builder $query): Builder
|
||||
private function applySearch(Builder $query): Builder
|
||||
{
|
||||
if ($this->searchTerm) {
|
||||
if (filled($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('accession_number', 'like', $search);
|
||||
$query->orWhere('study_description', 'like', $search);
|
||||
$query->orWhere('body_part_examined', 'like', $search);
|
||||
});
|
||||
@ -92,4 +162,22 @@ public function applySearch(Builder $query): Builder
|
||||
|
||||
return $query;
|
||||
}
|
||||
|
||||
private function applyArchived(Builder $query): Builder
|
||||
{
|
||||
if ($this->archived != null) {
|
||||
$query = $query->where('archived', $this->archived);
|
||||
}
|
||||
|
||||
return $query;
|
||||
}
|
||||
|
||||
private function applyLocked(Builder $query): Builder
|
||||
{
|
||||
if ($this->locked != null) {
|
||||
$query = $query->where('locked', $this->locked);
|
||||
}
|
||||
|
||||
return $query;
|
||||
}
|
||||
}
|
||||
|
@ -11,7 +11,7 @@ class StudiesController extends HashidControllerBase
|
||||
{
|
||||
public function index()
|
||||
{
|
||||
$studies = WorklistFactory::getLister()->all();
|
||||
$studies = WorklistFactory::getLister()->get();
|
||||
|
||||
return view('staff.studies.index', compact('studies'));
|
||||
}
|
||||
|
@ -10,7 +10,7 @@ class WorklistController extends HashidControllerBase
|
||||
{
|
||||
public function index()
|
||||
{
|
||||
$studies = StudyPresenter::pagination(WorklistFactory::getLister()->all());
|
||||
$studies = StudyPresenter::pagination(WorklistFactory::getLister()->get());
|
||||
|
||||
return view('staff.worklist.index', compact('studies'));
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user