public bool IsSearchParameterSupported(SearchParameterInfo parameterInfo)
        {
            EnsureArg.IsNotNull(parameterInfo, nameof(parameterInfo));

            Expression parsed = _compiler.Parse(parameterInfo.Expression);

            (SearchParamType Type, Expression, Uri DefinitionUrl)[] componentExpressions = parameterInfo.Component
Beispiel #2
0
        public void TestTreeVisualizerVisitor()
        {
            var compiler = new FhirPathCompiler();
            var expr     = compiler.Parse("doSomething('ha!', 4, {}, $this, somethingElse(true))");
            var result   = expr.Dump();

            Debug.WriteLine(result);
        }
Beispiel #3
0
        public (bool Supported, bool IsPartiallySupported) IsSearchParameterSupported(SearchParameterInfo parameterInfo)
        {
            EnsureArg.IsNotNull(parameterInfo, nameof(parameterInfo));

            if (string.IsNullOrWhiteSpace(parameterInfo.Expression))
            {
                return(false, false);
            }

            Expression parsed = _compiler.Parse(parameterInfo.Expression);

            (SearchParamType Type, Expression, Uri DefinitionUrl)[] componentExpressions = parameterInfo.Component
        public void GivenAFhirPathExpressionWithFirstFunction_WhenResolvingTypes_ThenTheyAreReturnedCorrectly()
        {
            var expression = _compiler.Parse("Patient.extension.where(url = 'http://hl7.org/fhir/us/core/StructureDefinition/us-core-race').first().extension.where(url = 'ombCategory').value");

            SearchParameterTypeResult[] results = SearchParameterToTypeResolver.Resolve(
                KnownResourceTypes.Patient,
                (SearchParamType.Token, expression, new Uri("http://hl7.org/fhir/SearchParameter/Patient-race")),
                null).ToArray();
            var types = results.Select(x => x.FhirNodeType).OrderBy(x => x).ToArray();

            if (ModelInfoProvider.Version == FhirSpecification.Stu3)
            {
                Assert.Equal(51, types.Length);
            }
            else if (ModelInfoProvider.Version == FhirSpecification.R4)
            {
                Assert.Equal(59, types.Length);
            }
            else
            {
                Assert.Equal(62, types.Length);
            }
        }
Beispiel #5
0
        public Resource Apply(Resource resource, Parameters patch)
        {
            foreach (var component in patch.Parameter.Where(x => x.Name == "operation"))
            {
                var operationType = component.Part.First(x => x.Name == "type").Value.ToString();
                var path          = component.Part.First(x => x.Name == "path").Value.ToString();
                var name          = component.Part.FirstOrDefault(x => x.Name == "name")?.Value.ToString();
                var value         = component.Part.FirstOrDefault(x => x.Name == "value")?.Value ?? component.Part.FirstOrDefault(x => x.Name == "value")?.Part[0].Value;

                var parameterExpression = Expression.Parameter(resource.GetType(), "x");
                var expression          = operationType == "add" ? _compiler.Parse($"{path}.{name}") : _compiler.Parse(path);
                var result = expression.Accept(
                    new ResourceVisitor(parameterExpression),
                    new fhirExpression.SymbolTable());
                var valueExpression = CreateValueExpression(value, result);
                switch (operationType)
                {
                case "add":
                    result = AddValue(result, valueExpression);
                    break;

                case "insert":
                    result = InsertValue(result, valueExpression);
                    break;

                case "replace":
                    result = Expression.Assign(result, valueExpression);
                    break;

                case "delete":
                    result = DeleteValue(result);
                    break;

                case "move":
                    var source      = int.Parse(component.Part.First(x => x.Name == "source").Value.ToString() !);
                    var destination = int.Parse(component.Part.First(x => x.Name == "destination").Value.ToString() !);
                    result = MoveItem(result, source, destination);
                    break;
                }

                var compiled = Expression.Lambda(result !, parameterExpression).Compile();
                compiled.DynamicInvoke(resource);
            }

            return(resource);
        }
        public ParseExpressionOutCome ParseExpression(string Expression)
        {
            var OutCome = new ParseExpressionOutCome();

            OutCome.ExpressionString = Expression;
            FhirPathCompiler Compiler = new FhirPathCompiler();

            try
            {
                OutCome.Expression = Compiler.Parse(Expression);
                OutCome.PasreOk    = true;
                return(OutCome);
            }
            catch (Exception Exec)
            {
                OutCome.PasreOk      = false;
                OutCome.ErrorMessage = Exec.Message;
                return(OutCome);
            }
        }
        public ParseExpressionOutCome ParseExpression(string Expression)
        {
            var OutCome = new ParseExpressionOutCome();

            OutCome.ExpressionString = Expression;
            Hl7.FhirPath.FhirPathCompiler.DefaultSymbolTable.AddFhirExtensions();
            FhirPathCompiler Compiler = new FhirPathCompiler();

            try
            {
                OutCome.Expression = Compiler.Parse(Expression);
                OutCome.PasreOk    = true;
                return(OutCome);
            }
            catch (Exception Exec)
            {
                OutCome.PasreOk      = false;
                OutCome.ErrorMessage = Exec.Message;
                return(OutCome);
            }
        }