diff --git a/app/Models/DicomRoutingRule.php b/app/Models/DicomRoutingRule.php new file mode 100644 index 0000000..c96bfb9 --- /dev/null +++ b/app/Models/DicomRoutingRule.php @@ -0,0 +1,36 @@ +hasMany(DicomRuleCondition::class); + } + + public function institute(): BelongsTo + { + return $this->belongsTo(Institute::class); + } + + public function facility(): BelongsTo + { + return $this->belongsTo(Facility::class); + } + + protected function casts(): array + { + return [ + 'is_active' => 'boolean', + 'match_condition' => MatchCondition::class, + ]; + } +} diff --git a/app/Models/DicomRuleCondition.php b/app/Models/DicomRuleCondition.php new file mode 100644 index 0000000..54f365a --- /dev/null +++ b/app/Models/DicomRuleCondition.php @@ -0,0 +1,25 @@ +belongsTo(DicomRoutingRule::class); + } + + protected function casts(): array + { + return [ + 'case_sensitive' => 'boolean', + 'match_mode' => MatchMode::class, + ]; + } +} diff --git a/app/Services/Pacs/InstituteMapperDicom.php b/app/Services/Pacs/DicomStudyMapper.php similarity index 68% rename from app/Services/Pacs/InstituteMapperDicom.php rename to app/Services/Pacs/DicomStudyMapper.php index dc48d6a..b4b967b 100644 --- a/app/Services/Pacs/InstituteMapperDicom.php +++ b/app/Services/Pacs/DicomStudyMapper.php @@ -9,7 +9,7 @@ final class DicomStudyMapper { - private static array $patterns = []; + private static array $rules = []; private static int $catchAll = -1; @@ -18,20 +18,24 @@ final class DicomStudyMapper */ public static function map(?string $input): array { - if (empty(self::$patterns)) { - self::$patterns = Cache::remember('institute_names', + if (empty(self::$rules)) { + self::$rules = Cache::remember('institute_names', now()->addMinutes(15), fn () => DB::table('dicom_routing_rules') ->orderByDesc('priority') - ->get()->toArray() + ->get() + ->toArray() ); - self::$catchAll = DB::table('institutes')->first('id')->id; + self::$catchAll = DB::table('institutes') + ->where('name', 'Catch-all') + ->first('id') + ->id; } if (! blank($input)) { $input = strtolower($input); - foreach (self::$patterns as $pattern) { + foreach (self::$rules as $pattern) { if (StringMatcher::match($input, $pattern->name, MatchMode::from($pattern->match_mode))) { return [$pattern->institute_id, $pattern->facility_id]; } diff --git a/app/Services/Pacs/DicomTagIdentifiers.php b/app/Services/Pacs/DicomTagIdentifiers.php new file mode 100644 index 0000000..8f79b49 --- /dev/null +++ b/app/Services/Pacs/DicomTagIdentifiers.php @@ -0,0 +1,63 @@ + "Patient's Name", + DicomTagIdentifiers::PatientID => 'Patient ID', + DicomTagIdentifiers::PatientBirthDate => "Patient's Birth Date", + DicomTagIdentifiers::PatientSex => "Patient's Sex", + DicomTagIdentifiers::StudyInstanceUID => 'Study Instance UID', + DicomTagIdentifiers::SeriesInstanceUID => 'Series Instance UID', + DicomTagIdentifiers::StudyID => 'Study ID', + DicomTagIdentifiers::SeriesNumber => 'Series Number', + DicomTagIdentifiers::InstanceNumber => 'Instance Number', + DicomTagIdentifiers::SOPClassUID => 'SOP Class UID', + DicomTagIdentifiers::SOPInstanceUID => 'SOP Instance UID', + DicomTagIdentifiers::StudyDate => 'Study Date', + DicomTagIdentifiers::StudyTime => 'Study Time', + DicomTagIdentifiers::AccessionNumber => 'Accession Number', + DicomTagIdentifiers::Modality => 'Modality', + DicomTagIdentifiers::Manufacturer => 'Manufacturer', + DicomTagIdentifiers::InstitutionName => 'Institution Name', + DicomTagIdentifiers::ReferringPhysicianName => "Referring Physician's Name", + DicomTagIdentifiers::StationName => 'Station Name', + DicomTagIdentifiers::SeriesDescription => 'Series Description', + DicomTagIdentifiers::ManufacturerModelName => "Manufacturer's Model Name", + DicomTagIdentifiers::PatientAge => "Patient's Age", + DicomTagIdentifiers::PatientWeight => "Patient's Weight", + DicomTagIdentifiers::BodyPartExamined => 'Body Part Examined', + DicomTagIdentifiers::ProtocolName => 'Protocol Name', + DicomTagIdentifiers::SoftwareVersions => 'Software Versions', + DicomTagIdentifiers::AcquisitionDate => 'Acquisition Date', + DicomTagIdentifiers::AcquisitionTime => 'Acquisition Time', + DicomTagIdentifiers::ContentDate => 'Content Date', + DicomTagIdentifiers::ContentTime => 'Content Time', + DicomTagIdentifiers::AcquisitionDeviceProcessingDescription => 'Acquisition Device Processing Description', + DicomTagIdentifiers::InstitutionAddress => 'Institution Address', + DicomTagIdentifiers::StudyDescription => 'Study Description', + DicomTagIdentifiers::OperatorsName => "Operator's Name", + DicomTagIdentifiers::Private10 => 'Private Tag 10', + DicomTagIdentifiers::IW_Private => 'IW Private Tag', + DicomTagIdentifiers::ImageType => 'Image Type', + DicomTagIdentifiers::PatientOrientation => 'Patient Orientation', + DicomTagIdentifiers::ImagePositionPatient => 'Image Position (Patient)', + DicomTagIdentifiers::ImageOrientationPatient => 'Image Orientation (Patient)', + DicomTagIdentifiers::FrameOfReferenceUID => 'Frame of Reference UID', + DicomTagIdentifiers::PositionReferenceIndicator => 'Position Reference Indicator', + DicomTagIdentifiers::SliceLocation => 'Slice Location', + DicomTagIdentifiers::SamplesPerPixel => 'Samples per Pixel', + DicomTagIdentifiers::PhotometricInterpretation => 'Photometric Interpretation', + DicomTagIdentifiers::Rows => 'Rows', + DicomTagIdentifiers::Columns => 'Columns', + DicomTagIdentifiers::PixelSpacing => 'Pixel Spacing', + DicomTagIdentifiers::BitsAllocated => 'Bits Allocated', + DicomTagIdentifiers::BitsStored => 'Bits Stored', + DicomTagIdentifiers::HighBit => 'High Bit', + DicomTagIdentifiers::PixelRepresentation => 'Pixel Representation', + DicomTagIdentifiers::WindowCenter => 'Window Center', + DicomTagIdentifiers::WindowWidth => 'Window Width', + DicomTagIdentifiers::RescaleIntercept => 'Rescale Intercept', + DicomTagIdentifiers::RescaleSlope => 'Rescale Slope', + }; + } } diff --git a/app/Services/StringMatcher.php b/app/Services/StringMatcher.php index 30e9d60..0db51d4 100644 --- a/app/Services/StringMatcher.php +++ b/app/Services/StringMatcher.php @@ -23,7 +23,6 @@ public static function match(string $input, string $pattern, MatchMode $mode): b MatchMode::StartsWith => str_starts_with($input, $pattern), MatchMode::EndsWith => str_ends_with($input, $pattern), MatchMode::Regex => preg_match($pattern, $input) === 1, - default => false, }; } }