refactored

This commit is contained in:
Masroor Ehsan 2025-01-25 17:42:12 +06:00
parent d01d462996
commit 3792d108cc
8 changed files with 38 additions and 31 deletions

View File

@ -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;

View File

@ -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;

View File

@ -2,7 +2,7 @@
namespace App\Domain\Study;
enum StudyLevelStatus: int
enum WorkflowLevel: int
{
case Pending = 0;
case Unassigned = 10;

View File

@ -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',

View File

@ -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';

View File

@ -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);
}

View File

@ -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)) {

View File

@ -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']);
});
}