48 lines
1.2 KiB
PHP
48 lines
1.2 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 $rules = [];
|
|
|
|
private static int $catchAll = -1;
|
|
|
|
/**
|
|
* @return array<int, ?int>
|
|
*/
|
|
public static function map(?string $input): array
|
|
{
|
|
if (empty(self::$rules)) {
|
|
self::$rules = Cache::remember('institute_names',
|
|
now()->addMinutes(15),
|
|
fn () => DB::table('dicom_routing_rules')
|
|
->orderByDesc('priority')
|
|
->get()
|
|
->toArray()
|
|
);
|
|
self::$catchAll = DB::table('institutes')
|
|
->where('name', 'Catch-all')
|
|
->first('id')
|
|
->id;
|
|
}
|
|
|
|
if (! blank($input)) {
|
|
$input = strtolower($input);
|
|
|
|
foreach (self::$rules as $pattern) {
|
|
if (StringMatcher::match($input, $pattern->name, MatchMode::from($pattern->match_mode))) {
|
|
return [$pattern->institute_id, $pattern->facility_id];
|
|
}
|
|
}
|
|
}
|
|
|
|
return [self::$catchAll, null];
|
|
}
|
|
}
|