36 lines
924 B
PHP
36 lines
924 B
PHP
<?php
|
|
|
|
namespace App\Services\Pacs;
|
|
|
|
use App\Models\Enums\NameMatchModes;
|
|
use App\Services\InputMatcher;
|
|
use Cache;
|
|
use DB;
|
|
|
|
final class InstituteMapper
|
|
{
|
|
private static array $patterns = [];
|
|
|
|
private static int $catchAll = -1;
|
|
|
|
public static function map(string $input): int
|
|
{
|
|
if (empty(self::$patterns)) {
|
|
self::$patterns = Cache::remember('institute_names', now()->addDay(), function () {
|
|
return DB::table('institute_names')->orderBy('priority')->get()->toArray();
|
|
});
|
|
self::$catchAll = DB::table('institutes')->first('id')->id;
|
|
}
|
|
|
|
$input = strtolower($input);
|
|
|
|
foreach (self::$patterns as $pattern) {
|
|
if (InputMatcher::match($input, $pattern->name, NameMatchModes::from($pattern->match_mode))) {
|
|
return $pattern->institute_id;
|
|
}
|
|
}
|
|
|
|
return self::$catchAll;
|
|
}
|
|
}
|