From 8c580f55d61883a2306260bd87085be07aa42715 Mon Sep 17 00:00:00 2001 From: Dr Masroor Ehsan Date: Wed, 22 Jan 2025 11:17:18 +0600 Subject: [PATCH] wip --- .../{InstituteMapper.php => InstituteMapperDicom.php} | 6 ++++-- app/Services/Pacs/Sync/StudiesSync.php | 4 ++-- ...12_28_175040_create_dicom_mapping_rules_table.php} | 11 +++++++---- 3 files changed, 13 insertions(+), 8 deletions(-) rename app/Services/Pacs/{InstituteMapper.php => InstituteMapperDicom.php} (85%) rename database/migrations/{2024_12_28_175040_create_institute_names_table.php => 2024_12_28_175040_create_dicom_mapping_rules_table.php} (66%) diff --git a/app/Services/Pacs/InstituteMapper.php b/app/Services/Pacs/InstituteMapperDicom.php similarity index 85% rename from app/Services/Pacs/InstituteMapper.php rename to app/Services/Pacs/InstituteMapperDicom.php index 9940dfc..2148290 100644 --- a/app/Services/Pacs/InstituteMapper.php +++ b/app/Services/Pacs/InstituteMapperDicom.php @@ -7,7 +7,7 @@ use Illuminate\Support\Facades\Cache; use Illuminate\Support\Facades\DB; -final class InstituteMapper +final class DicomStudyMapper { private static array $patterns = []; @@ -21,7 +21,9 @@ public static function map(?string $input): array if (empty(self::$patterns)) { self::$patterns = Cache::remember('institute_names', now()->addMinutes(15), - fn () => DB::table('institute_names')->orderBy('priority')->get()->toArray() + fn () => DB::table('dicom_mapping_rules') + ->orderByDesc('sort_order') + ->get()->toArray() ); self::$catchAll = DB::table('institutes')->first('id')->id; } diff --git a/app/Services/Pacs/Sync/StudiesSync.php b/app/Services/Pacs/Sync/StudiesSync.php index 6516c30..84ba427 100644 --- a/app/Services/Pacs/Sync/StudiesSync.php +++ b/app/Services/Pacs/Sync/StudiesSync.php @@ -5,8 +5,8 @@ use App\Domain\Study\Priority; use App\Domain\Study\StudyLevelStatus; use App\Models\DicomServer; +use App\Services\Pacs\DicomStudyMapper; use App\Services\Pacs\DicomUtils; -use App\Services\Pacs\InstituteMapper; use App\Services\Pacs\OrthancRestClient; use Carbon\Carbon; use Exception; @@ -108,7 +108,7 @@ public function fetchStudyDetails(string $orthanc_uuid): ?array public function transformData(mixed $orthanc_src): array { $inst_name = data_get($orthanc_src, 'MainDicomTags.InstitutionName'); - $inst_id = InstituteMapper::map($inst_name); + $inst_id = DicomStudyMapper::map($inst_name); $patient_name = data_get($orthanc_src, 'PatientMainDicomTags.PatientName'); diff --git a/database/migrations/2024_12_28_175040_create_institute_names_table.php b/database/migrations/2024_12_28_175040_create_dicom_mapping_rules_table.php similarity index 66% rename from database/migrations/2024_12_28_175040_create_institute_names_table.php rename to database/migrations/2024_12_28_175040_create_dicom_mapping_rules_table.php index bc9cfc4..ae49b07 100644 --- a/database/migrations/2024_12_28_175040_create_institute_names_table.php +++ b/database/migrations/2024_12_28_175040_create_dicom_mapping_rules_table.php @@ -11,19 +11,22 @@ { public function up(): void { - Schema::create('institute_names', function (Blueprint $table) { + Schema::create('dicom_mapping_rules', static function (Blueprint $table) { $table->id(); $table->foreignIdFor(Institute::class)->constrained()->cascadeOnDelete(); $table->foreignIdFor(Facility::class)->nullable()->constrained()->cascadeOnDelete(); - $table->string('name')->unique(); + $table->string('dicom_tag'); + $table->string('search_pattern'); $table->unsignedTinyInteger('match_mode')->default(StringMatchMode::Exact->value); - $table->unsignedTinyInteger('priority')->default(0); + $table->unsignedTinyInteger('sort_order')->default(0); $table->timestamps(); + + $table->unique(['institute_id', 'dicom_tag']); }); } public function down(): void { - Schema::dropIfExists('institute_names'); + Schema::dropIfExists('dicom_mapping_rules'); } };