diff --git a/app/DAL/Studies/IUserStudyLister.php b/app/DAL/Studies/IUserStudyLister.php index 3b9bc01..3d6e249 100644 --- a/app/DAL/Studies/IUserStudyLister.php +++ b/app/DAL/Studies/IUserStudyLister.php @@ -25,4 +25,8 @@ public function setArchived(bool $archived): self; public function setLocked(bool $locked): self; public function get(?int $user_id = null): LengthAwarePaginator; + + public function setStudyDate(string $from, ?string $to = null): self; + + public function setReceiveDate(string $from, ?string $to = null): self; } diff --git a/app/DAL/Studies/WorklistBase.php b/app/DAL/Studies/WorklistBase.php index 969f15d..92cb085 100644 --- a/app/DAL/Studies/WorklistBase.php +++ b/app/DAL/Studies/WorklistBase.php @@ -5,6 +5,7 @@ use App\Models\Enums\ReportStatus; use App\Models\Enums\StudyLevelStatus; use App\Models\Study; +use Carbon\Carbon; use Illuminate\Contracts\Database\Eloquent\Builder; use Illuminate\Contracts\Pagination\LengthAwarePaginator; @@ -14,8 +15,6 @@ abstract class WorklistBase implements IUserStudyLister private array $sortColumns = []; - private ?string $sortDir = null; - private ?string $searchTerm = null; private ?int $radiologist_id = null; @@ -28,6 +27,14 @@ abstract class WorklistBase implements IUserStudyLister private ?bool $archived = null; + private ?string $studyDateFrom = null; + + private ?string $studyDateTo = null; + + private ?string $receiveDateFrom = null; + + private ?string $receiveDateTo = null; + public function setRadiologist(int $radiologist_id): self { $this->radiologist_id = $radiologist_id; @@ -115,6 +122,7 @@ public function get(?int $user_id = null): LengthAwarePaginator $query = $this->applyReportStatus($query); $query = $this->applyArchived($query); $query = $this->applyLocked($query); + $query = $this->applyDateFilters($query); return $query->paginate($this->getPageSize($user_id)); } @@ -200,4 +208,47 @@ private function applyLocked(Builder $query): Builder return $query; } + + private function applyDateFilter(Builder $query, string $column, string $from, ?string $to): Builder + { + $start = Carbon::parse($from); + if (filled($to)) { + $end = Carbon::parse($to); + $query = $query->whereBetween($column, [$start->toDateString(), $end->toDateString()]); + } else { + $query = $query->where($column, '>=', $start->toDateString()); + } + + return $query; + + } + + private function applyDateFilters(Builder $query): Builder + { + if (filled($this->studyDateFrom)) { + $query = $this->applyDateFilter($query, 'study_date', $this->studyDateFrom, $this->studyDateTo); + } + + if (filled($this->receiveDateFrom)) { + $query = $this->applyDateFilter($query, 'receive_date', $this->receiveDateFrom, $this->receiveDateTo); + } + + return $query; + } + + public function setStudyDate(string $from, ?string $to = null): self + { + $this->studyDateFrom = $from; + $this->studyDateTo = $to; + + return $this; + } + + public function setReceiveDate(string $from, ?string $to = null): self + { + $this->receiveDateFrom = $from; + $this->receiveDateTo = $to; + + return $this; + } } diff --git a/app/Http/Controllers/Api/WorklistController.php b/app/Http/Controllers/Api/WorklistController.php new file mode 100644 index 0000000..6ce2abb --- /dev/null +++ b/app/Http/Controllers/Api/WorklistController.php @@ -0,0 +1,22 @@ +ajax()) { + abort(404); + } + $studies = StudyPresenter::pagination(WorklistFactory::getLister()->get()); + + // ->toArray();dd($studies); + return response()->json($studies); + } +} diff --git a/app/Models/Study.php b/app/Models/Study.php index fb7cd00..d0203bc 100644 --- a/app/Models/Study.php +++ b/app/Models/Study.php @@ -174,4 +174,14 @@ public function allowed(): array 'ohif.seg' => filled($this->getOhifSegmentationLink()), ]; } + + public function toArray(): array + { + return array_merge(parent::toArray(), [ + 'sex_age' => $this->sexAge(), + 'num_instances' => $this->numInstances(), + 'links' => $this->links(), + 'allowed' => $this->allowed(), + ]); + } } diff --git a/app/Presenters/StudyPresenter.php b/app/Presenters/StudyPresenter.php index 2b197bd..f56373a 100644 --- a/app/Presenters/StudyPresenter.php +++ b/app/Presenters/StudyPresenter.php @@ -2,7 +2,6 @@ namespace App\Presenters; -use Carbon\Carbon; use CultureGr\Presenter\Presenter; class StudyPresenter extends Presenter @@ -11,12 +10,4 @@ public function toArray(): array { return $this->model->toArray(); } - - public function sexAge(): array - { - $dob = $this->model->patient_birthdate; - $age = $dob ? Carbon::make($dob)->diffInYears() : null; - - return "$age / {$this->model->patient_sex}"; - } } diff --git a/routes/web.php b/routes/web.php index ed5d829..9655f6f 100644 --- a/routes/web.php +++ b/routes/web.php @@ -1,5 +1,6 @@ name('dashboard'); + Route::group(['prefix' => 'api', 'as' => 'api.'], function () { + Route::get('studies', [ApiWorklistController::class, 'studies'])->name('studies'); + }); + Route::group(['prefix' => 'radiologist', 'as' => 'radiologist.'], function () { Route::get('/report-write/{id}', ReportWriteController::class)->name('report-write'); });