From a20ff58614a2d3fc776aad036751c6615355521f Mon Sep 17 00:00:00 2001 From: Dr Masroor Ehsan Date: Tue, 31 Dec 2024 09:45:16 +0600 Subject: [PATCH] refx --- app/Models/Study.php | 19 +++++++++++++------ app/Services/Pacs/StudyImporter.php | 7 +++++-- ...2024_12_27_060234_create_studies_table.php | 11 ++++------- ...2_28_144858_create_study_details_table.php | 1 + 4 files changed, 23 insertions(+), 15 deletions(-) diff --git a/app/Models/Study.php b/app/Models/Study.php index fcc85c2..c28b1aa 100644 --- a/app/Models/Study.php +++ b/app/Models/Study.php @@ -9,12 +9,19 @@ class Study extends BaseModel { - protected $casts = [ - 'is_locked' => 'boolean', - 'is_archived' => 'boolean', - 'study_status' => StudyLevelStatus::class, - 'report_status' => ReportStatus::class, - ]; + protected function casts(): array + { + return [ + 'is_locked' => 'boolean', + 'is_archived' => 'boolean', + 'study_status' => StudyLevelStatus::class, + 'report_status' => ReportStatus::class, + 'received_at' => 'datetime', + 'reported_at' => 'datetime', + 'assigned_at' => 'datetime', + 'study_date' => 'datetime', + ]; + } public function details(): HasOne { diff --git a/app/Services/Pacs/StudyImporter.php b/app/Services/Pacs/StudyImporter.php index 17a6536..76b5f4f 100644 --- a/app/Services/Pacs/StudyImporter.php +++ b/app/Services/Pacs/StudyImporter.php @@ -114,7 +114,7 @@ private function prepareData(mixed $orthanc_src): array 'body_part_examined' => data_get($orthanc_src, 'RequestedTags.BodyPartExamined'), 'study_date' => DicomUtils::dateTimeToCarbon($orthanc_src['MainDicomTags']['StudyDate'], $orthanc_src['MainDicomTags']['StudyTime']), - 'receive_date' => Carbon::parse($orthanc_src['LastUpdate'], 'UTC'), + 'received_at' => Carbon::parse($orthanc_src['LastUpdate'], 'UTC'), 'image_count' => data_get($orthanc_src, 'Statistics.CountInstances'), 'series_count' => data_get($orthanc_src, 'Statistics.CountSeries'), @@ -175,7 +175,7 @@ private function prepareData(mixed $orthanc_src): array $params = [ 'orthanc_uuid' => strtolower($ser['ID']), 'series_instance_uid' => data_get($ser, 'MainDicomTags.SeriesInstanceUID'), - 'series_date' => DicomUtils::dateTimeToCarbon($ser['MainDicomTags']['SeriesDate'], $ser['MainDicomTags']['SeriesTime']), + 'series_date' => DicomUtils::dateTimeToCarbon(data_get($ser, 'MainDicomTags.SeriesDate'), data_get($ser, 'MainDicomTags.SeriesTime')), 'series_number' => data_get($ser, 'MainDicomTags.SeriesNumber'), 'series_description' => data_get($ser, 'MainDicomTags.SeriesDescription'), 'protocol_name' => data_get($ser, 'MainDicomTags.ProtocolName'), @@ -193,6 +193,9 @@ private function prepareData(mixed $orthanc_src): array if (empty($series)) { $series = null; + } else { + // $series = array_multisort(array_column($series, 'series_number'), SORT_ASC, $series); + usort($series, fn ($a, $b): int => (int) $a['series_number'] <=> (int) $b['series_number']); } if (empty($properties)) { $properties = null; 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 61e93ff..1240d18 100644 --- a/database/migrations/2024_12_27_060234_create_studies_table.php +++ b/database/migrations/2024_12_27_060234_create_studies_table.php @@ -34,8 +34,10 @@ public function up(): void $table->string('referring_physician_name')->nullable(); $table->string('study_modality', 4)->nullable(); $table->dateTime('study_date'); - $table->dateTime('receive_date'); - $table->dateTime('report_date')->nullable(); + + $table->dateTime('received_at'); + $table->dateTime('reported_at')->nullable(); + $table->dateTime('assigned_at')->nullable(); $table->foreignIdFor(Institute::class)->constrained()->onDelete('cascade'); $table->unsignedTinyInteger('study_status')->default(StudyLevelStatus::Pending->value); $table->unsignedTinyInteger('report_status')->default(ReportStatus::Pending->value); @@ -50,11 +52,6 @@ public function up(): void $table->foreignIdFor(User::class, 'reading_physician_id')->nullable()->constrained()->onDelete('set null'); $table->timestamps(); - - $table->index(['referring_physician_id', 'receive_date']); - $table->index(['institute_id', 'receive_date', 'is_archived']); - $table->index(['institute_id', 'report_status', 'study_priority', 'receive_date']); - $table->index(['assigned_physician_id', 'report_status', 'study_priority', 'receive_date']); }); } diff --git a/database/migrations/2024_12_28_144858_create_study_details_table.php b/database/migrations/2024_12_28_144858_create_study_details_table.php index 73197ad..d74d2b2 100644 --- a/database/migrations/2024_12_28_144858_create_study_details_table.php +++ b/database/migrations/2024_12_28_144858_create_study_details_table.php @@ -18,6 +18,7 @@ public function up(): void $table->text('clinical_diagnosis')->nullable(); $table->jsonb('properties')->nullable(); $table->jsonb('series')->nullable(); + $table->jsonb('assignment_log')->nullable(); $table->timestamps(); }); }