wip rules engine
This commit is contained in:
parent
21b24fe542
commit
ce9669b556
@ -3,16 +3,13 @@
|
||||
namespace App\Services\StudyRouter;
|
||||
|
||||
use App\Domain\ACL\Role;
|
||||
use App\Domain\Rule\MatchCondition;
|
||||
use App\Domain\Rule\MatchMode;
|
||||
use App\Models\AssignmentPanel;
|
||||
use App\Models\DicomRoutingRule;
|
||||
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;
|
||||
use Symfony\Component\ExpressionLanguage\ExpressionLanguage;
|
||||
|
||||
final class DicomStudyRouter
|
||||
{
|
||||
@ -30,22 +27,16 @@ public static function matchStudy(array $dicomHeaders): array
|
||||
return self::fallbackRouting();
|
||||
}
|
||||
|
||||
$expression = new ExpressionLanguage;
|
||||
foreach (self::$rules as $rule) {
|
||||
$conditions = $rule->conditions()->orderByDesc('priority')->get();
|
||||
$matches = $rule->match_condition === MatchCondition::ALL
|
||||
? $conditions->every(fn ($condition) => self::matchCondition($condition, $dicomHeaders))
|
||||
: $conditions->contains(fn ($condition) => self::matchCondition($condition, $dicomHeaders));
|
||||
$matches = (bool) $expression->evaluate($rule->condition, ['study' => $dicomHeaders]);
|
||||
|
||||
/*
|
||||
if ($dicomHeaders[RawDicomTags::Modality->value] === 'CR') {
|
||||
dd($rule, $conditions->toArray(), $matches, $dicomHeaders[RawDicomTags::Modality->value]);
|
||||
}
|
||||
*/
|
||||
if ($matches) {
|
||||
return [
|
||||
'organization_id' => $rule->organization_id,
|
||||
'department_id' => $rule->department_id,
|
||||
'rule_id' => $rule->id,
|
||||
'rule_name' => $rule->name,
|
||||
'radiologists' => self::getRadiologists($rule),
|
||||
];
|
||||
}
|
||||
@ -70,7 +61,6 @@ private static function initialize(): void
|
||||
self::$rules = Cache::remember('dicom.rules',
|
||||
now()->addMinutes(self::CACHE_TTL),
|
||||
fn () => DicomRoutingRule::active()
|
||||
->with('conditions')
|
||||
->orderByDesc('priority')
|
||||
->get()
|
||||
);
|
||||
@ -92,22 +82,6 @@ private static function initialize(): void
|
||||
}
|
||||
}
|
||||
|
||||
private static function matchCondition(DicomRuleCondition $condition, array $dicomHeaders): bool
|
||||
{
|
||||
$dicomTag = $condition->dicom_tag;
|
||||
$dicomValue = $dicomHeaders[$dicomTag] ?? '';
|
||||
$searchPattern = $condition->search_pattern;
|
||||
|
||||
if (! $condition->case_sensitive) {
|
||||
$dicomValue = strtolower($dicomValue);
|
||||
if ($condition->match_mode !== MatchMode::Regex) {
|
||||
$searchPattern = strtolower($searchPattern);
|
||||
}
|
||||
}
|
||||
|
||||
return ContentMatcher::match($dicomValue, $searchPattern, $condition->match_mode);
|
||||
}
|
||||
|
||||
private static function getRadiologists(DicomRoutingRule $rule): array
|
||||
{
|
||||
if (! is_null($rule->assignment_panel_id)) {
|
||||
|
Loading…
Reference in New Issue
Block a user