public ElementNode AnonymizeResourceNode(ElementNode root)
        {
            EnsureArg.IsNotNull(root, nameof(root));

            if (root.IsBundleNode())
            {
                var entryResources = root.GetEntryResourceChildren();
                AnonymizeInternalResourceNodes(entryResources);
            }

            if (root.HasContainedNode())
            {
                var containedResources = root.GetContainedChildren();
                AnonymizeInternalResourceNodes(containedResources);
            }

            var resourceContext = ResourceAnonymizerContext.Create(root, _configurationManger);

            foreach (var rule in resourceContext.RuleList)
            {
                var pathCompileExpression = new FhirPathCompiler().Compile($"{rule.Path}");
                var matchedNodes          = pathCompileExpression(root, EvaluationContext.CreateDefault())
                                            .Cast <ElementNode>();
                foreach (var node in matchedNodes)
                {
                    AnonymizeChildNode(node, rule.Method, resourceContext.PathSet);
                }
            }

            return(root);
        }
Esempio n. 2
0
        public static Closure Root(ITypedElement root, EvaluationContext ctx = null)
        {
            var newContext = new Closure()
            {
                EvaluationContext = ctx ?? EvaluationContext.CreateDefault()
            };

            var input = new[] { root };

            newContext.SetThis(input);
            newContext.SetThat(input);
            newContext.SetOriginalContext(input);
            if (ctx.Container != null)
            {
                newContext.SetResource(new[] { ctx.Container });
            }

            return(newContext);
        }
Esempio n. 3
0
        public ElementNode AnonymizeResourceNode(ElementNode root)
        {
            EnsureArg.IsNotNull(root, nameof(root));

            if (root.IsBundleNode())
            {
                var entryResources = root.GetEntryResourceChildren();
                AnonymizeInternalResourceNodes(entryResources);
            }

            if (root.HasContainedNode())
            {
                var containedResources = root.GetContainedChildren();
                AnonymizeInternalResourceNodes(containedResources);
            }

            var resourceContext = ResourceAnonymizerContext.Create(root, _configurationManger);
            var resourceId      = root.GetNodeId();

            foreach (var rule in resourceContext.RuleList)
            {
                var pathCompileExpression = new FhirPathCompiler().Compile($"{rule.Path}");
                var matchedNodes          = pathCompileExpression(root, EvaluationContext.CreateDefault())
                                            .Cast <ElementNode>();

                _logger.LogDebug(rule.Type == AnonymizerRuleType.PathRule ?
                                 $"Path {rule.Source} matches {matchedNodes.Count()} nodes in resource ID {resourceId}." :
                                 $"Type {rule.Source} matches {matchedNodes.Count()} nodes with path {rule.Path} in resource ID {resourceId}.");

                foreach (var node in matchedNodes)
                {
                    AnonymizeChildNode(node, rule, resourceContext.PathSet, resourceId);
                }
            }

            return(root);
        }
        public static IEnumerable <ITypedElement> Select(this ITypedElement input, string expression, EvaluationContext ctx = null)
        {
            var evaluator = GetCompiledExpression(expression);

            return(evaluator(input, ctx ?? EvaluationContext.CreateDefault()));
        }