From 6e53c98925dab6d6859f2d26b9a6bbf0dcb5cc07 Mon Sep 17 00:00:00 2001 From: Masroor Ehsan Date: Tue, 31 Dec 2024 14:51:56 +0600 Subject: [PATCH] wip --- app/DAL/Studies.php | 18 ++++++++++++++++++ .../Pacs/Sync/Pipes/ArchiveStudies.php | 9 +++++---- app/Services/Pacs/Sync/Pipes/UpdateStudies.php | 6 ++++-- app/Services/Pacs/Sync/StudiesSync.php | 3 --- ..._28_175040_create_institute_names_table.php | 4 +++- 5 files changed, 30 insertions(+), 10 deletions(-) create mode 100644 app/DAL/Studies.php diff --git a/app/DAL/Studies.php b/app/DAL/Studies.php new file mode 100644 index 0000000..6db1ca5 --- /dev/null +++ b/app/DAL/Studies.php @@ -0,0 +1,18 @@ +addHours(1), + fn () => DB::table('studies') + ->where('orthanc_uuid', strtolower($orthanc_uuid)) + ->value('id')); + } +} diff --git a/app/Services/Pacs/Sync/Pipes/ArchiveStudies.php b/app/Services/Pacs/Sync/Pipes/ArchiveStudies.php index e6ef4ed..b193eda 100644 --- a/app/Services/Pacs/Sync/Pipes/ArchiveStudies.php +++ b/app/Services/Pacs/Sync/Pipes/ArchiveStudies.php @@ -2,6 +2,7 @@ namespace App\Services\Pacs\Sync\Pipes; +use App\DAL\Studies; use App\Services\AuditTrail\Activity; use App\Services\AuditTrail\Category; use App\Services\Pacs\Sync\StudiesSync; @@ -13,8 +14,8 @@ public function __invoke(StudiesSync $sync, Closure $next): StudiesSync { foreach ($sync->getArchiveQueue() as $orthanc_uuid) { - $row_id = DB::table('studies')->where(compact('orthanc_uuid'))->value('id'); - if ($row_id === null) { + $study_id = Studies::getStudyIdByOrthancUuid($orthanc_uuid); + if ($study_id === null) { continue; } @@ -22,12 +23,12 @@ public function __invoke(StudiesSync $sync, Closure $next): StudiesSync 'is_archived' => true, 'updated_at' => now(), ]; - DB::table('studies')->find($row_id)->update($payload); + DB::table('studies')->where('id', $study_id)->update($payload); audit() ->by(sync_agent_id()) ->category(Category::SYSTEM) - ->on($row_id) + ->on($study_id) ->orthanc($orthanc_uuid) ->did(Activity::Study_Archived) ->log(false); diff --git a/app/Services/Pacs/Sync/Pipes/UpdateStudies.php b/app/Services/Pacs/Sync/Pipes/UpdateStudies.php index 0a12829..93e6f38 100644 --- a/app/Services/Pacs/Sync/Pipes/UpdateStudies.php +++ b/app/Services/Pacs/Sync/Pipes/UpdateStudies.php @@ -2,6 +2,7 @@ namespace App\Services\Pacs\Sync\Pipes; +use App\DAL\Studies; use App\Services\AuditTrail\Activity; use App\Services\AuditTrail\Category; use App\Services\Pacs\Sync\StudiesSync; @@ -17,7 +18,8 @@ public function __invoke(StudiesSync $sync, Closure $next): StudiesSync if ($study == null) { continue; } - $study_id = DB::table('studies')->where(compact('orthanc_uuid'))->value('id'); + + $study_id = Studies::getStudyIdByOrthancUuid($orthanc_uuid); if ($study_id === null) { continue; } @@ -25,7 +27,7 @@ public function __invoke(StudiesSync $sync, Closure $next): StudiesSync $payload = $sync->transformData($study); unset($payload['study']['orthanc_uuid']); $payload['study']['updated_at'] = now(); - DB::table('studies')->find($study_id)->update($payload['study']); + DB::table('studies')->where('id', $study_id)->update($payload['study']); if (! empty($payload['details'])) { $payload['details']['updated_at'] = now(); diff --git a/app/Services/Pacs/Sync/StudiesSync.php b/app/Services/Pacs/Sync/StudiesSync.php index 1790423..7fbd6cd 100644 --- a/app/Services/Pacs/Sync/StudiesSync.php +++ b/app/Services/Pacs/Sync/StudiesSync.php @@ -104,9 +104,6 @@ public function transformData(mixed $orthanc_src): array $study = [ 'orthanc_uuid' => strtolower($orthanc_src['ID']), - 'is_locked' => false, - 'is_active' => true, - 'institution_name' => $inst_name, 'institute_id' => $inst_id, diff --git a/database/migrations/2024_12_28_175040_create_institute_names_table.php b/database/migrations/2024_12_28_175040_create_institute_names_table.php index 46ac29c..ec8b9dc 100644 --- a/database/migrations/2024_12_28_175040_create_institute_names_table.php +++ b/database/migrations/2024_12_28_175040_create_institute_names_table.php @@ -1,6 +1,7 @@ id(); - $table->foreignIdFor(Institute::class)->constrained()->onDelete('CASCADE'); + $table->foreignIdFor(Institute::class)->constrained()->cascadeOnDelete(); + $table->foreignIdFor(Facility::class)->nullable()->constrained()->cascadeOnDelete(); $table->string('name')->unique(); $table->unsignedTinyInteger('match_mode')->default(NameMatchModes::Exact->value); $table->unsignedTinyInteger('priority')->default(0);