From 059360245259cfcac5d806517ad2fd93810e2cef Mon Sep 17 00:00:00 2001 From: Masroor Ehsan Date: Wed, 22 Jan 2025 18:46:48 +0600 Subject: [PATCH] wip --- app/Domain/Rule/MatchMode.php | 1 + ..._00_163912_create_organizations_table.php} | 4 +- ...01_01_075136_create_departments_table.php} | 12 +-- ...75040_create_dicom_routing_rules_table.php | 2 +- ...754_create_dicom_rule_conditions_table.php | 5 +- database/seeders/InstituteSeeder.php | 86 +++++++++++++++---- 6 files changed, 85 insertions(+), 25 deletions(-) rename database/migrations/{0000_00_00_163912_create_institutes_table.php => 0000_00_00_163912_create_organizations_table.php} (84%) rename database/migrations/{0000_01_01_075136_create_facilities_table.php => 0000_01_01_075136_create_departments_table.php} (53%) diff --git a/app/Domain/Rule/MatchMode.php b/app/Domain/Rule/MatchMode.php index 36d24b2..2a625e7 100644 --- a/app/Domain/Rule/MatchMode.php +++ b/app/Domain/Rule/MatchMode.php @@ -8,5 +8,6 @@ enum MatchMode: string case Contains = 'CONTAINS'; case StartsWith = 'STARTS_WITH'; case EndsWith = 'ENDS_WITH'; + case InArray = 'IN_ARRAY'; case Regex = 'REGEX'; } diff --git a/database/migrations/0000_00_00_163912_create_institutes_table.php b/database/migrations/0000_00_00_163912_create_organizations_table.php similarity index 84% rename from database/migrations/0000_00_00_163912_create_institutes_table.php rename to database/migrations/0000_00_00_163912_create_organizations_table.php index 2f67bec..0279090 100644 --- a/database/migrations/0000_00_00_163912_create_institutes_table.php +++ b/database/migrations/0000_00_00_163912_create_organizations_table.php @@ -8,7 +8,7 @@ { public function up(): void { - Schema::create('institutes', static function (Blueprint $table) { + Schema::create('organizations', static function (Blueprint $table) { $table->id(); $table->string('guid', 40)->unique()->index()->default(DB::raw("concat('INS-', gen_random_uuid())")); $table->string('name')->unique(); @@ -21,6 +21,6 @@ public function up(): void public function down(): void { - Schema::dropIfExists('institutes'); + Schema::dropIfExists('organizations'); } }; diff --git a/database/migrations/0000_01_01_075136_create_facilities_table.php b/database/migrations/0000_01_01_075136_create_departments_table.php similarity index 53% rename from database/migrations/0000_01_01_075136_create_facilities_table.php rename to database/migrations/0000_01_01_075136_create_departments_table.php index 51b57b0..49239a0 100644 --- a/database/migrations/0000_01_01_075136_create_facilities_table.php +++ b/database/migrations/0000_01_01_075136_create_departments_table.php @@ -1,5 +1,6 @@ id(); $table->string('guid', 40)->unique()->index()->default(DB::raw("concat('FAC-', gen_random_uuid())")); - $table->boolean('is_active')->default(false); - $table->foreignId('institute_id')->constrained('institutes')->cascadeOnDelete(); + $table->boolean('is_active')->default(false)->index(); + $table->foreignIdFor(Organization::class)->constrained()->cascadeOnDelete(); $table->string('name'); $table->timestamps(); - $table->unique(['institute_id', 'name']); + $table->unique(['organization_id', 'name']); + $table->index(['organization_id', 'is_active']); }); } public function down(): void { - Schema::dropIfExists('facilities'); + Schema::dropIfExists('departments'); } }; diff --git a/database/migrations/2024_12_28_175040_create_dicom_routing_rules_table.php b/database/migrations/2024_12_28_175040_create_dicom_routing_rules_table.php index 759c922..3574334 100644 --- a/database/migrations/2024_12_28_175040_create_dicom_routing_rules_table.php +++ b/database/migrations/2024_12_28_175040_create_dicom_routing_rules_table.php @@ -20,7 +20,7 @@ public function up(): void $table->foreignIdFor(Department::class)->nullable()->constrained()->cascadeOnDelete(); $table->foreignIdFor(User::class)->nullable()->constrained()->nullOnDelete(); $table->foreignIdFor(AssignmentPanel::class)->nullable()->constrained()->nullOnDelete(); - $table->string('description')->nullable(); + $table->string('name')->nullable(); $table->string('match_condition')->default(MatchCondition::ANY->value); $table->unsignedTinyInteger('priority')->default(0); $table->timestamps(); diff --git a/database/migrations/2024_12_29_073754_create_dicom_rule_conditions_table.php b/database/migrations/2024_12_29_073754_create_dicom_rule_conditions_table.php index 0b628ab..07acf00 100644 --- a/database/migrations/2024_12_29_073754_create_dicom_rule_conditions_table.php +++ b/database/migrations/2024_12_29_073754_create_dicom_rule_conditions_table.php @@ -1,6 +1,7 @@ id(); - $table->foreignId('dicom_routing_rule_id')->constrained()->cascadeOnDelete(); + $table->foreignIdFor(DicomRoutingRule::class)->constrained()->cascadeOnDelete(); $table->string('dicom_tag'); $table->string('search_pattern'); $table->boolean('case_sensitive')->default(false); @@ -19,7 +20,7 @@ public function up(): void $table->unsignedTinyInteger('priority')->default(0); $table->timestamps(); - $table->index(['dicom_mapping_rules_id', 'priority']); + $table->index(['dicom_routing_rule_id', 'priority']); }); } diff --git a/database/seeders/InstituteSeeder.php b/database/seeders/InstituteSeeder.php index 2f314c3..d2afd88 100644 --- a/database/seeders/InstituteSeeder.php +++ b/database/seeders/InstituteSeeder.php @@ -2,12 +2,15 @@ namespace Database\Seeders; +use App\Domain\Rule\MatchCondition; use App\Domain\Rule\MatchMode; use App\Models\Department; +use App\Models\DicomRoutingRule; +use App\Models\DicomRuleCondition; use App\Models\DicomServer; use App\Models\Organization; +use App\Services\StudyRouter\DicomTagIdentifiers; use Illuminate\Database\Seeder; -use Illuminate\Support\Facades\DB; class InstituteSeeder extends Seeder { @@ -34,28 +37,81 @@ public function run(): void [ 'is_active' => true, 'name' => 'Chevron XR', - 'institute_id' => $chev->id, + 'organization_id' => $chev->id, + ] + ); + $chev_dep_ct_mr = Department::create( + [ + 'is_active' => true, + 'name' => 'Chevron CT/MR', + 'organization_id' => $chev->id, ] ); $cmch_mr = Department::create( [ 'is_active' => false, 'name' => 'CMCH MR', - 'institute_id' => $cmch->id, + 'organization_id' => $cmch->id, ] ); - DB::table('dicom_mapping_rules')->insert([ - 'dicom_tag' => 'InstitutionName', - 'name' => 'CHEVRON CLINICAL LABORATORY , PANCHLAISH,CTG', - 'search_pattern' => $chev->id, - 'match_mode' => MatchMode::Exact->value, + $rul_chev_mr = DicomRoutingRule::create( + [ + 'is_active' => true, + 'name' => 'Chevron MR', + 'organization_id' => $chev->id, + 'department_id' => $chev_dep_ct_mr->id, + 'match_condition' => MatchCondition::ALL->value, + ] + ); + $rul_chev_ct = DicomRoutingRule::create( + [ + 'is_active' => true, + 'name' => 'Chevron CT', + 'organization_id' => $chev->id, + 'department_id' => $chev_dep_ct_mr->id, + 'match_condition' => MatchCondition::ALL->value, + ] + ); + + $rul_chev_xr = DicomRoutingRule::create( + [ + 'is_active' => true, + 'name' => 'Chevron XR', + 'organization_id' => $chev->id, + 'department_id' => $chev_dep_ct_mr->id, + 'match_condition' => MatchCondition::ALL->value, + ] + ); + + DicomRuleCondition::create([ + 'dicom_tag' => DicomTagIdentifiers::InstitutionName->value, + 'search_pattern' => 'chevron', + 'dicom_routing_rule_id' => $rul_chev_mr->id, + 'match_mode' => MatchMode::Contains->value, + 'case_sensitive' => false, ]); - DB::table('dicom_mapping_rules')->insert([ - 'dicom_tag' => 'InstitutionName', - 'search_pattern' => 'CHEVRON CLINICAL', - 'institute_id' => $chev->id, - 'match_mode' => MatchMode::StartsWith->value, + DicomRuleCondition::create([ + 'dicom_tag' => DicomTagIdentifiers::Modality->value, + 'search_pattern' => 'MR,CT', + 'dicom_routing_rule_id' => $rul_chev_mr->id, + 'match_mode' => MatchMode::InArray->value, + 'case_sensitive' => true, + ]); + + DicomRuleCondition::create([ + 'dicom_tag' => DicomTagIdentifiers::InstitutionName->value, + 'search_pattern' => 'chevron', + 'dicom_routing_rule_id' => $rul_chev_xr->id, + 'match_mode' => MatchMode::Contains->value, + 'case_sensitive' => false, + ]); + DicomRuleCondition::create([ + 'dicom_tag' => DicomTagIdentifiers::Modality->value, + 'search_pattern' => 'CR,DX', + 'dicom_routing_rule_id' => $rul_chev_xr->id, + 'match_mode' => MatchMode::InArray->value, + 'case_sensitive' => true, ]); DicomServer::create( @@ -82,8 +138,8 @@ public function run(): void 'wado_path' => 'dicom-web', 'stone_viewer_path' => 'stone-webviewer/index.html', 'ohif_viewer_path' => 'ohif/viewer', - 'institute_id' => $chev->id, - 'facility_id' => $chev_xr->id, + 'organization_id' => $chev->id, + 'department_id' => $chev_xr->id, ] ); }