Exemple #1
0
        public void TestAgeFilter()
        {
            QueryFilterExtensions.AddExtendedFilter(new AgeQueryFilterExtension());
            var filterQuery = NameValueCollection.ParseQueryString("dateOfBirth=:(age)<P3Y");
            var expr        = QueryExpressionParser.BuildLinqExpression <Patient>(filterQuery);

            Assert.IsTrue(expr.ToString().Contains("Age"));
        }
        public void TestWriteSimpleExtendedFilter()
        {
            QueryFilterExtensions.AddExtendedFilter(new SimpleQueryExtension());
            var query      = QueryExpressionBuilder.BuildQuery <Patient>(o => o.Identifiers.Any(i => i.Value.TestExpression() <= 2));
            var expression = CreateQueryString(query.ToArray());

            Assert.AreEqual("identifier.value=%3A%28test%29%3C%3D2", expression);
        }
Exemple #3
0
 /// <summary>
 /// Static CTOR
 /// </summary>
 static BaseRecordMatchingService()
 {
     foreach (var t in typeof(BaseRecordMatchingService).Assembly.ExportedTypes.Where(t => typeof(IQueryFilterExtension).IsAssignableFrom(t) && !t.IsAbstract))
     {
         QueryFilterExtensions.AddExtendedFilter(Activator.CreateInstance(t) as IQueryFilterExtension);
     }
     ModelSerializationBinder.RegisterModelType(typeof(MatchConfiguration));
 }
        public void TestWriteSelfParameterRef()
        {
            QueryFilterExtensions.AddExtendedFilter(new SimpleQueryExtensionEx());
            DateTime other      = DateTime.Parse("1980-01-01");
            TimeSpan myTime     = new TimeSpan(1, 0, 0, 0);
            var      query      = QueryExpressionBuilder.BuildQuery <Patient>(o => o.DateOfBirth.Value.TestExpressionEx(o.CreationTime.DateTime) < myTime);
            var      expression = CreateQueryString(query.ToArray());

            Assert.AreEqual("dateOfBirth=%3A%28testEx%7C%22%24_.creationTime%22%29%3C1.00%3A00%3A00", expression);
        }
Exemple #5
0
        public void TestExtendedQueryFilterWithParameterVariableCrossReference()
        {
            var expected = "o => ((o.DateOfBirth != null) AndAlso (o.DateOfBirth.Value.TestExpressionEx((Invoke(__xinstance => (((__xinstance.Relationships.Where(guard => ((guard.LoadProperty(\"RelationshipType\") ?? new Concept()).Mnemonic == \"Mother\")).FirstOrDefault() ?? new EntityRelationship()).TargetEntity As Patient) ?? new Patient()).DateOfBirth, o) ?? default(DateTime))) > 7305.00:00:00))";

            QueryFilterExtensions.AddExtendedFilter(new SimpleQueryExtensionEx());
            NameValueCollection httpQueryParameters = new NameValueCollection();

            httpQueryParameters.Add("dateOfBirth", ":(testEx|$_.relationship[Mother][email protected])>20y");
            var expr = QueryExpressionParser.BuildLinqExpression <Patient>(httpQueryParameters);

            Assert.AreEqual(expected, expr.ToString());
        }
Exemple #6
0
        public void TestExtendedQueryFilterWithParameterParse()
        {
            var expected = "o => ((o.DateOfBirth != null) AndAlso (o.DateOfBirth.Value.TestExpressionEx(2018-01-01 12:00:00 AM) > 7305.00:00:00))";

            QueryFilterExtensions.AddExtendedFilter(new SimpleQueryExtensionEx());
            NameValueCollection httpQueryParameters = new NameValueCollection();

            httpQueryParameters.Add("dateOfBirth", ":(testEx|2018-01-01)>20y");
            var expr = QueryExpressionParser.BuildLinqExpression <Patient>(httpQueryParameters);

            Assert.AreEqual(expected, expr.ToString());
        }
Exemple #7
0
        public void TestExtendedQueryFilterParseBool()
        {
            var expected = "o => o.Names.Any(name => name.Component.Where(guard => ((guard.ComponentType ?? new Concept()).Mnemonic == \"OfficialRecord\")).Any(component => (component.Value.BoolTest() == True)))";

            QueryFilterExtensions.AddExtendedFilter(new BoolQueryExtension());
            NameValueCollection httpQueryParameters = new NameValueCollection();

            httpQueryParameters.Add("name.component[OfficialRecord].value", ":(testBool)");
            var expr = QueryExpressionParser.BuildLinqExpression <Patient>(httpQueryParameters);

            Assert.AreEqual(expected, expr.ToString());
        }
Exemple #8
0
        public void TestExtendedQueryFilterWithParameterVariableParse()
        {
            var expected = "o => ((o.DateOfBirth != null) AndAlso (o.DateOfBirth.Value.TestExpressionEx(Convert(Convert(value(SanteDB.Messaging.HDSI.Test.QueryParameterLinqBuilderTest+<>c).<TestExtendedQueryFilterWithParameterVariableParse>b__18_0()))) > 7305.00:00:00))";

            QueryFilterExtensions.AddExtendedFilter(new SimpleQueryExtensionEx());
            NameValueCollection httpQueryParameters = new NameValueCollection();

            httpQueryParameters.Add("dateOfBirth", ":(testEx|$dateOfBirth)>20y");
            var expr = QueryExpressionParser.BuildLinqExpression <Patient>(httpQueryParameters, new System.Collections.Generic.Dictionary <string, Func <Object> >()
            {
                { "dateOfBirth", () => DateTime.Parse("2018-01-01") }
            });

            Assert.AreEqual(expected, expr.ToString());
        }
Exemple #9
0
        public void TestExtendedQueryFilterWithParameterVariableComplexPathParse()
        {
            var expected = "((o.DateOfBirth != null) AndAlso (o.DateOfBirth.Value.TestExpressionEx((Invoke(__xinstance => (((__xinstance.Relationships.Where(guard => ((guard.LoadProperty(\"RelationshipType\") ?? new Concept()).Mnemonic == \"Mother\")).FirstOrDefault() ?? new EntityRelationship()).TargetEntity As Patient) ?? new Patient()).DateOfBirth, Convert(value(SanteDB.Messaging.HDSI.Test.QueryParameterLinqBuilderTest+<>c).<TestExtendedQueryFilterWithParameterVariableComplexPathParse>b__20_0())) ?? default(DateTime))) > 730.12:00:00))";

            QueryFilterExtensions.AddExtendedFilter(new SimpleQueryExtensionEx());
            NameValueCollection httpQueryParameters = new NameValueCollection();

            httpQueryParameters.Add("dateOfBirth", ":(testEx|$input.relationship[Mother][email protected])>2y");
            var expr = QueryExpressionParser.BuildLinqExpression <Patient>(httpQueryParameters, new System.Collections.Generic.Dictionary <string, Func <Object> >()
            {
                { "input", () => new Patient()
                  {
                      DateOfBirth = DateTime.Parse("2018-01-01")
                  } }
            });

            Assert.AreEqual(expected, expr.ToString());
        }
Exemple #10
0
        /// <summary>
        /// Follow property path
        /// </summary>
        /// TODO: Clean this up
        private object FollowPath(Type scopingType, string propertyPath, JObject variables)
        {
            // Get rid f the .
            if (propertyPath.StartsWith("."))
            {
                propertyPath = propertyPath.Substring(1);
            }

            var retVal          = new AutoCompleteTypeInfo(scopingType);
            var propertyExtract = this.m_propertyExtractor.Match(propertyPath);

            if (propertyExtract.Success)
            {
                var property = retVal.Properties.FirstOrDefault(o => o.Name == propertyExtract.Groups[1].Value);

                // Is the property path full?
                if (property == null)
                {
                    // Is it a variable?
                    if (propertyExtract.Groups[1].Value.StartsWith("$"))
                    {
                        var variable = variables[propertyExtract.Groups[1].Value];
                        if (variable != null)
                        {
                            return(this.FollowPath(new ModelSerializationBinder().BindToType(null, variable.Value <String>()), propertyExtract.Groups[3].Value, variables));
                        }
                        else
                        {
                            return(variables.Values().Select(o => o.Path.Substring(1)).ToArray());
                        }
                    }
                    else if (propertyExtract.Groups[1].Value.StartsWith(":(")) // function
                    {
                        var functionMatch = this.m_functionExtractor.Match(propertyPath);
                        if (functionMatch.Success && (!String.IsNullOrEmpty(functionMatch.Groups[2].Value) || !String.IsNullOrEmpty(functionMatch.Groups[3].Value)))
                        {
                            return(this.FollowPath(typeof(Object),
                                                   String.IsNullOrEmpty(functionMatch.Groups[2].Value) ? functionMatch.Groups[3].Value : functionMatch.Groups[2].Value,
                                                   variables));
                        }
                        else
                        {
                            return(QueryFilterExtensions.GetExtendedFilters().Select(o => o.Name));
                        }
                    }
                    return(retVal);
                }
                else if (!String.IsNullOrEmpty(propertyExtract.Groups[2].Value))
                {
                    if (propertyExtract.Groups[2].Value.StartsWith("@")) // We're casting
                    {
                        var modelType = new ModelSerializationBinder().BindToType(null, propertyExtract.Groups[2].Value.Substring(1));
                        if (modelType != null)
                        {
                            return(this.FollowPath(modelType, propertyExtract.Groups[3].Value, variables));
                        }
                        else
                        {
                            return(this.FollowPath(property.SourceProperty.PropertyType.StripGeneric(), propertyExtract.Groups[3].Value, variables));
                        }
                    }
                    else
                    {
                        return(this.FollowPath(property.SourceProperty.PropertyType.StripGeneric(), propertyExtract.Groups[3].Value, variables));
                    }
                }
                else if (propertyExtract.Groups[3].Value.StartsWith("@"))
                {
                    return(AppDomain.CurrentDomain.GetAllTypes()
                           .Where(o => property.SourceProperty.PropertyType.StripGeneric().IsAssignableFrom(o))
                           .Select(o => o.GetCustomAttribute <XmlTypeAttribute>()?.TypeName)
                           .OfType <String>()
                           .ToArray());
                }
                else if (propertyExtract.Groups[3].Value.StartsWith("["))
                {
                    if (property.ClassifierValues?.Any() == true)
                    {
                        return(property.ClassifierValues);
                    }
                    else
                    {
                        return(property);
                    }
                }
                else
                {
                    return(retVal);
                }
            }
            else
            {
                return(retVal);
            }
        }