From fd786881e916dc9c55ec55cce1e2a8ac0bdc293d Mon Sep 17 00:00:00 2001 From: Masroor Ehsan Date: Wed, 22 Jan 2025 19:55:21 +0600 Subject: [PATCH] wip --- app/Services/ContentMatcher.php | 2 +- app/Services/Pacs/Sync/StudiesSync.php | 28 +++++++++------- app/Services/StudyRouter/DicomStudyRouter.php | 32 +++++++------------ composer.json | 2 +- 4 files changed, 30 insertions(+), 34 deletions(-) diff --git a/app/Services/ContentMatcher.php b/app/Services/ContentMatcher.php index 13aea54..3d66768 100644 --- a/app/Services/ContentMatcher.php +++ b/app/Services/ContentMatcher.php @@ -6,7 +6,6 @@ final class ContentMatcher { - public static function match(string $input, string $pattern, MatchMode $mode): bool { if (blank($input) || blank($pattern)) { @@ -22,6 +21,7 @@ public static function match(string $input, string $pattern, MatchMode $mode): b MatchMode::Regex => preg_match($pattern, $input) === 1, }; } + private static function matchList(string $input, string $pattern): bool { $patterns = collect(explode(',', $pattern)) diff --git a/app/Services/Pacs/Sync/StudiesSync.php b/app/Services/Pacs/Sync/StudiesSync.php index cf56fd2..5ce8141 100644 --- a/app/Services/Pacs/Sync/StudiesSync.php +++ b/app/Services/Pacs/Sync/StudiesSync.php @@ -106,23 +106,28 @@ public function fetchStudyDetails(string $orthanc_uuid): ?array return $study; } - public function matchOrganization(mixed $orthanc_src) + public function matchRouting(mixed $orthanc_src) { $dicomData = [ DicomTagIdentifiers::PatientName->value => data_get($orthanc_src, 'PatientMainDicomTags.PatientName'), DicomTagIdentifiers::PatientID->value => data_get($orthanc_src, 'PatientMainDicomTags.PatientID'), DicomTagIdentifiers::Modality->value => data_get($orthanc_src, 'RequestedTags.Modality'), + DicomTagIdentifiers::StudyDescription->value => $this->getStudyDescription($orthanc_src), DicomTagIdentifiers::BodyPartExamined->value => data_get($orthanc_src, 'RequestedTags.BodyPartExamined'), + DicomTagIdentifiers::ReferringPhysicianName->value => data_get($orthanc_src, 'MainDicomTags.ReferringPhysicianName'), + DicomTagIdentifiers::AccessionNumber->value => data_get($orthanc_src, 'MainDicomTags.AccessionNumber'), DicomTagIdentifiers::InstitutionName->value => data_get($orthanc_src, 'MainDicomTags.InstitutionName'), DicomTagIdentifiers::InstitutionAddress->value => data_get($orthanc_src, 'RequestedTags.InstitutionAddress'), - DicomTagIdentifiers::StudyDescription->value => $this->getStudyDescription($orthanc_src), - DicomTagIdentifiers::OperatorsName->value => data_get($orthanc_src, 'MainDicomTags.InstitutionName'), - DicomTagIdentifiers::StationName->value => data_get($orthanc_src, 'MainDicomTags.InstitutionName'), - DicomTagIdentifiers::ReferringPhysicianName->value => data_get($orthanc_src, 'MainDicomTags.InstitutionName'), - DicomTagIdentifiers::Manufacturer->value => data_get($orthanc_src, 'MainDicomTags.InstitutionName'), - DicomTagIdentifiers::SoftwareVersions->value => data_get($orthanc_src, 'MainDicomTags.InstitutionName'), - DicomTagIdentifiers::ProtocolName->value => data_get($orthanc_src, 'MainDicomTags.InstitutionName'), + DicomTagIdentifiers::OperatorsName->value => data_get($orthanc_src, 'RequestedTags.OperatorsName'), + DicomTagIdentifiers::StationName->value => data_get($orthanc_src, 'RequestedTags.StationName'), + DicomTagIdentifiers::Manufacturer->value => data_get($orthanc_src, 'RequestedTags.Manufacturer'), + DicomTagIdentifiers::ManufacturerModelName->value => data_get($orthanc_src, 'RequestedTags.ManufacturerModelName'), + DicomTagIdentifiers::SoftwareVersions->value => data_get($orthanc_src, 'RequestedTags.SoftwareVersions'), + DicomTagIdentifiers::ProtocolName->value => data_get($orthanc_src, 'xxx'), ]; + $dicomData = array_purge($dicomData); + + return DicomStudyRouter::matchStudy($dicomData); } public function getStudyDescription(mixed $orthanc_src): ?string @@ -143,7 +148,7 @@ public function getStudyDescription(mixed $orthanc_src): ?string public function transformData(mixed $orthanc_src): array { $inst_name = data_get($orthanc_src, 'MainDicomTags.InstitutionName'); - $inst_id = DicomStudyRouter::matchStudy($inst_name); + $routing = $this->matchRouting($orthanc_src); $patient_name = data_get($orthanc_src, 'PatientMainDicomTags.PatientName'); @@ -152,7 +157,8 @@ public function transformData(mixed $orthanc_src): array 'dicom_server_id' => $this->dicomServer->id, 'orthanc_uuid' => strtolower($orthanc_src['ID']), 'institution_name' => $inst_name, - 'institute_id' => $inst_id, + 'organization_id' => $routing['institute_id'], + 'department_id' => $routing['department_id'], 'patient_uuid' => strtolower($orthanc_src['ParentPatient']), 'patient_id' => data_get($orthanc_src, 'PatientMainDicomTags.PatientID'), @@ -174,7 +180,7 @@ public function transformData(mixed $orthanc_src): array 'series_count' => data_get($orthanc_src, 'Statistics.CountSeries'), 'disk_size' => data_get($orthanc_src, 'Statistics.DiskSize'), - 'study_description' =>$descr, + 'study_description' => $descr, ]; if ((bool) data_get($orthanc_src, 'IsStable', false)) { diff --git a/app/Services/StudyRouter/DicomStudyRouter.php b/app/Services/StudyRouter/DicomStudyRouter.php index cb2624e..65dba66 100644 --- a/app/Services/StudyRouter/DicomStudyRouter.php +++ b/app/Services/StudyRouter/DicomStudyRouter.php @@ -10,6 +10,7 @@ use App\Models\DicomRuleCondition; use App\Models\Organization; use App\Models\User; +use App\Services\ContentMatcher; use Illuminate\Support\Collection; use Illuminate\Support\Facades\Cache; @@ -26,7 +27,7 @@ public static function matchStudy(array $dicomHeaders): array self::initialize(); if (blank($dicomHeaders)) { - return self::fallbackRoute(); + return self::fallbackRouting(); } foreach (self::$rules as $rule) { @@ -38,22 +39,22 @@ public static function matchStudy(array $dicomHeaders): array if ($matches) { return [ - 'institute_id' => $rule->institute_id, - 'facility_id' => $rule->facility_id, + 'organization_id' => $rule->organization_id, + 'department_id' => $rule->department_id, 'rule_id' => $rule->id, 'radiologists' => self::getRadiologists($rule), ]; } } - return self::fallbackRoute(); + return self::fallbackRouting(); } - private static function fallbackRoute(): array + private static function fallbackRouting(): array { return [ - 'institute_id' => self::$catchAll, - 'facility_id' => null, + 'organization_id' => self::$catchAll, + 'department_id' => null, 'rule_id' => null, 'radiologists' => null, ]; @@ -101,23 +102,12 @@ private static function matchCondition(DicomRuleCondition $condition, array $dic } } - switch ($matchMode) { - case MatchMode::Exact: - return $dicomValue === $searchPattern; - case MatchMode::StartsWith: - return str_starts_with($dicomValue, $searchPattern); - case MatchMode::EndsWith: - return str_ends_with($dicomValue, $searchPattern); - case MatchMode::Contains: - return str_contains($dicomValue, $searchPattern); - case MatchMode::Regex: - return preg_match($searchPattern, $dicomValue) === 1; - } + return ContentMatcher::match($dicomValue, $searchPattern, $matchMode); } private static function getRadiologists(DicomRoutingRule $rule): array { - if ($rule->assignment_panel_id) { + if (!is_null($rule->assignment_panel_id)) { $panel = AssignmentPanel::active() ->with('radiologists:id') ->find($rule->assignment_panel_id); @@ -128,7 +118,7 @@ private static function getRadiologists(DicomRoutingRule $rule): array return array_intersect($rads, self::$activeRads->toArray()); } } - } elseif ($rule->radiologist_id) { + } elseif (!is_null($rule->radiologist_id)) { if (self::$activeRads->contains($rule->radiologist_id)) { return [$rule->radiologist_id]; } diff --git a/composer.json b/composer.json index 81c142a..2a1d020 100644 --- a/composer.json +++ b/composer.json @@ -8,7 +8,7 @@ ], "license": "MIT", "require": { - "php": ">=8.3", + "php": ">=8.4", "barryvdh/laravel-dompdf": "^3.0", "culturegr/presenter": "^1.4", "filament/filament": "^3.2",