44 lines
1.1 KiB
PHP
44 lines
1.1 KiB
PHP
<?php
|
|
|
|
namespace App\Services\Pacs;
|
|
|
|
use App\Domain\Rule\MatchMode;
|
|
use App\Services\StringMatcher;
|
|
use Illuminate\Support\Facades\Cache;
|
|
use Illuminate\Support\Facades\DB;
|
|
|
|
final class DicomStudyMapper
|
|
{
|
|
private static array $patterns = [];
|
|
|
|
private static int $catchAll = -1;
|
|
|
|
/**
|
|
* @return array<int, ?int>
|
|
*/
|
|
public static function map(?string $input): array
|
|
{
|
|
if (empty(self::$patterns)) {
|
|
self::$patterns = Cache::remember('institute_names',
|
|
now()->addMinutes(15),
|
|
fn () => DB::table('dicom_routing_rules')
|
|
->orderByDesc('priority')
|
|
->get()->toArray()
|
|
);
|
|
self::$catchAll = DB::table('institutes')->first('id')->id;
|
|
}
|
|
|
|
if (! blank($input)) {
|
|
$input = strtolower($input);
|
|
|
|
foreach (self::$patterns as $pattern) {
|
|
if (StringMatcher::match($input, $pattern->name, MatchMode::from($pattern->match_mode))) {
|
|
return [$pattern->institute_id, $pattern->facility_id];
|
|
}
|
|
}
|
|
}
|
|
|
|
return [self::$catchAll, null];
|
|
}
|
|
}
|