From 3792d108cc817b51afd946155d125132261cbd7f Mon Sep 17 00:00:00 2001 From: Masroor Ehsan Date: Sat, 25 Jan 2025 17:42:12 +0600 Subject: [PATCH] refactored --- app/DAL/Studies/IUserStudyLister.php | 4 ++-- app/DAL/Studies/WorklistBase.php | 22 +++++++++++-------- ...StudyLevelStatus.php => WorkflowLevel.php} | 2 +- app/Models/Study.php | 11 +++++----- app/Services/ACL/WorklistColumn.php | 2 +- .../Pacs/Sync/Pipes/FilterStudies.php | 12 +++++----- app/Services/Pacs/Sync/StudiesSync.php | 8 +++---- ...2024_12_27_060234_create_studies_table.php | 8 ++++--- 8 files changed, 38 insertions(+), 31 deletions(-) rename app/Domain/Study/{StudyLevelStatus.php => WorkflowLevel.php} (86%) diff --git a/app/DAL/Studies/IUserStudyLister.php b/app/DAL/Studies/IUserStudyLister.php index 64d0973..26d8613 100644 --- a/app/DAL/Studies/IUserStudyLister.php +++ b/app/DAL/Studies/IUserStudyLister.php @@ -3,7 +3,7 @@ namespace App\DAL\Studies; use App\Domain\Report\ReportStatus; -use App\Domain\Study\StudyLevelStatus; +use App\Domain\Study\WorkflowLevel; use Illuminate\Contracts\Database\Eloquent\Builder; use Illuminate\Contracts\Pagination\LengthAwarePaginator; @@ -11,7 +11,7 @@ interface IUserStudyLister { public function setRadiologist(int $radiologist_id): self; - public function setStudyStatus(StudyLevelStatus $status): self; + public function setWorkflowLevel(WorkflowLevel $status): self; public function setReportStatus(ReportStatus $status): self; diff --git a/app/DAL/Studies/WorklistBase.php b/app/DAL/Studies/WorklistBase.php index 81e6e1b..705b05e 100644 --- a/app/DAL/Studies/WorklistBase.php +++ b/app/DAL/Studies/WorklistBase.php @@ -3,7 +3,7 @@ namespace App\DAL\Studies; use App\Domain\Report\ReportStatus; -use App\Domain\Study\StudyLevelStatus; +use App\Domain\Study\WorkflowLevel; use App\Models\Study; use Carbon\Carbon; use Illuminate\Contracts\Pagination\LengthAwarePaginator; @@ -19,7 +19,7 @@ abstract class WorklistBase implements IUserStudyLister private ?int $radiologist_id = null; - private ?StudyLevelStatus $studyStatus = null; + private ?WorkflowLevel $workflowLevel = null; private ?ReportStatus $reportStatus = null; @@ -51,9 +51,9 @@ public function setRadiologist(int $radiologist_id): self return $this; } - public function setStudyStatus(StudyLevelStatus $status): self + public function setWorkflowLevel(WorkflowLevel $status): self { - $this->studyStatus = $status; + $this->workflowLevel = $status; return $this; } @@ -80,7 +80,7 @@ public function get(?int $user_id = null): LengthAwarePaginator $query = $this->applySort($query); $query = $this->applySearch($query); $query = $this->applyRadiologist($query); - $query = $this->applyStudyStatus($query); + $query = $this->applyWorkflowLevel($query); $query = $this->applyReportStatus($query); $query = $this->applyArchived($query); $query = $this->applyLocked($query); @@ -227,10 +227,10 @@ private function applyRadiologist(Builder $query): Builder return $query; } - private function applyStudyStatus(Builder $query): Builder + private function applyWorkflowLevel(Builder $query): Builder { - if ($this->studyStatus != null) { - $query = $query->where('study_status', '=', $this->studyStatus->value); + if ($this->workflowLevel != null) { + $query = $query->where('workflow_level', '=', $this->workflowLevel->value); } return $query; @@ -282,7 +282,11 @@ private function applyArchived(Builder $query): Builder private function applyLocked(Builder $query): Builder { if ($this->locked != null) { - $query = $query->where('is_locked', $this->locked); + if ((bool) $this->locked) { + $query = $query->whereNotNull('locked_at'); + } else { + $query = $query->whereNull('locked_at'); + } } return $query; diff --git a/app/Domain/Study/StudyLevelStatus.php b/app/Domain/Study/WorkflowLevel.php similarity index 86% rename from app/Domain/Study/StudyLevelStatus.php rename to app/Domain/Study/WorkflowLevel.php index 331dc5f..f3371b2 100644 --- a/app/Domain/Study/StudyLevelStatus.php +++ b/app/Domain/Study/WorkflowLevel.php @@ -2,7 +2,7 @@ namespace App\Domain\Study; -enum StudyLevelStatus: int +enum WorkflowLevel: int { case Pending = 0; case Unassigned = 10; diff --git a/app/Models/Study.php b/app/Models/Study.php index a1b923f..c69cd52 100644 --- a/app/Models/Study.php +++ b/app/Models/Study.php @@ -5,7 +5,7 @@ use App\Domain\ACL\Permission; use App\Domain\Report\ReportStatus; use App\Domain\Study\Priority; -use App\Domain\Study\StudyLevelStatus; +use App\Domain\Study\WorkflowLevel; use App\Models\Traits\HasDepartment; use App\Models\Traits\HashableId; use App\Models\Traits\HasOrganization; @@ -369,14 +369,14 @@ public function isUnlocked(): bool return $this->locked_at === null; } - public function lockStudy(User|int|null $user = null, ?StudyLevelStatus $status = null): void + public function lockStudy(User|int|null $user = null, ?WorkflowLevel $status = null): void { $params = [ 'locking_physician_id' => me($user)->id, 'locked_at' => now(), ]; if ($status) { - $params['study_status'] = $status->value; + $params['workflow_level'] = $status->value; } $this->update($params); @@ -520,10 +520,11 @@ public function isStudyComplete(): bool protected function casts(): array { return [ - 'is_archived' => 'boolean', - 'study_status' => StudyLevelStatus::class, + 'workflow_level' => WorkflowLevel::class, 'report_status' => ReportStatus::class, 'priority' => Priority::class, + 'archived_at' => 'immutable_datetime', + 'approved_at' => 'immutable_datetime', 'received_at' => 'immutable_datetime', 'read_at' => 'immutable_datetime', 'assigned_at' => 'immutable_datetime', diff --git a/app/Services/ACL/WorklistColumn.php b/app/Services/ACL/WorklistColumn.php index 9d9d4c5..9786d5e 100644 --- a/app/Services/ACL/WorklistColumn.php +++ b/app/Services/ACL/WorklistColumn.php @@ -4,7 +4,7 @@ enum WorklistColumn: string { - case StudyStatus = 'study_status'; + case WorkflowLevel = 'workflow_level'; case ReportStatus = 'report_status'; case StudyHash = 'hash'; case PatientName = 'patient_name'; diff --git a/app/Services/Pacs/Sync/Pipes/FilterStudies.php b/app/Services/Pacs/Sync/Pipes/FilterStudies.php index 3af5402..e89c62d 100644 --- a/app/Services/Pacs/Sync/Pipes/FilterStudies.php +++ b/app/Services/Pacs/Sync/Pipes/FilterStudies.php @@ -2,7 +2,7 @@ namespace App\Services\Pacs\Sync\Pipes; -use App\Domain\Study\StudyLevelStatus; +use App\Domain\Study\WorkflowLevel; use App\Services\Pacs\Sync\StudiesSync; use Closure; use Illuminate\Support\Collection; @@ -16,8 +16,8 @@ public function __invoke(StudiesSync $sync, Closure $next): StudiesSync $studies = DB::table('studies') ->whereNull('archived_at') - ->get(['orthanc_uuid', 'study_status']) - ->pluck('study_status', 'orthanc_uuid'); + ->get(['orthanc_uuid', 'workflow_level']) + ->pluck('workflow_level', 'orthanc_uuid'); $study_ids = $sync->getStudyIds(); foreach ($study_ids as $study_id) { @@ -34,14 +34,14 @@ public function __invoke(StudiesSync $sync, Closure $next): StudiesSync private function checkUpdate(string $orthanc_uuid, StudiesSync $sync, Collection $studies): void { - $study_status = $studies->get($orthanc_uuid); - if ($study_status === null) { + $workflow_level = $studies->get($orthanc_uuid); + if ($workflow_level === null) { $sync->getInsertQueue()->add($orthanc_uuid); return; } - if ($study_status < StudyLevelStatus::Unassigned->value) { + if ($workflow_level < WorkflowLevel::Unassigned->value) { // this is an "unstable" study. queue for update $sync->getUpdateQueue()->add($orthanc_uuid); } diff --git a/app/Services/Pacs/Sync/StudiesSync.php b/app/Services/Pacs/Sync/StudiesSync.php index 4bbdafd..8325648 100644 --- a/app/Services/Pacs/Sync/StudiesSync.php +++ b/app/Services/Pacs/Sync/StudiesSync.php @@ -3,7 +3,7 @@ namespace App\Services\Pacs\Sync; use App\Domain\Study\Priority; -use App\Domain\Study\StudyLevelStatus; +use App\Domain\Study\WorkflowLevel; use App\Models\DicomServer; use App\Services\Pacs\DicomUtils; use App\Services\Pacs\OrthancRestClient; @@ -177,9 +177,9 @@ public function transformData(mixed $orthanc_src): array 'study_description' => $descr, ]; - $study['study_status'] = $stable_study - ? StudyLevelStatus::Unassigned->value - : StudyLevelStatus::Pending->value; + $study['workflow_level'] = $stable_study + ? WorkflowLevel::Unassigned->value + : WorkflowLevel::Pending->value; $study['patient_birthdate'] = null; $dob = data_get($orthanc_src, 'PatientMainDicomTags.PatientBirthDate'); if (filled($dob)) { diff --git a/database/migrations/2024_12_27_060234_create_studies_table.php b/database/migrations/2024_12_27_060234_create_studies_table.php index 78d8e67..bbd1f05 100644 --- a/database/migrations/2024_12_27_060234_create_studies_table.php +++ b/database/migrations/2024_12_27_060234_create_studies_table.php @@ -2,7 +2,7 @@ use App\Domain\Report\ReportStatus; use App\Domain\Study\Priority; -use App\Domain\Study\StudyLevelStatus; +use App\Domain\Study\WorkflowLevel; use App\Models\Department; use App\Models\DicomServer; use App\Models\Organization; @@ -21,8 +21,9 @@ public function up(): void $table->foreignIdFor(Department::class)->nullable()->index(); $table->unsignedTinyInteger('priority')->default(Priority::Routine->value); - $table->unsignedTinyInteger('study_status')->default(StudyLevelStatus::Pending->value); + $table->unsignedTinyInteger('workflow_level')->default(WorkflowLevel::Pending->value); $table->unsignedTinyInteger('report_status')->default(ReportStatus::Unread->value); + $table->boolean('requires_approval')->default(false); $table->string('orthanc_uuid')->index(); $table->string('patient_uuid')->nullable()->index(); @@ -53,7 +54,6 @@ public function up(): void $table->timestamp('approved_at')->nullable(); $table->timestamp('archived_at')->nullable(); - // $table->unsignedBigInteger('assigned_physician_id')->nullable(); $table->unsignedBigInteger('locking_physician_id')->nullable(); $table->unsignedBigInteger('reading_physician_id')->nullable(); $table->unsignedBigInteger('approving_physician_id')->nullable(); @@ -72,6 +72,8 @@ public function up(): void $table->index(['department_id', 'received_at']); $table->index(['department_id', 'assigned_at']); $table->index(['department_id', 'locked_at']); + + $table->index(['requires_approval', 'report_status']); }); }