Exemplo n.º 1
0
        private static IMongoQuery QuantityQuery(String parameterName, Operator optor, String modifier, ValueExpression operand)
        {
            var quantity = operand.ToModelQuantity();

            Fhir.Metrics.Quantity q = quantity.ToUnitsOfMeasureQuantity().Canonical();
            string    decimals      = UnitsOfMeasureHelper.SearchableString(q);
            BsonValue value         = q.GetValueAsBson();

            List <IMongoQuery> queries = new List <IMongoQuery>();

            switch (optor)
            {
            case Operator.EQ:
                queries.Add(M.Query.Matches("decimals", new BsonRegularExpression("^" + decimals)));
                break;

            default:
                queries.Add(ExpressionQuery("value", optor, value));
                break;
            }

            if (quantity.System != null)
            {
                queries.Add(M.Query.EQ("system", quantity.System.ToString()));
            }

            queries.Add(M.Query.EQ("unit", q.Metric.ToString()));

            IMongoQuery query = M.Query.ElemMatch(parameterName, M.Query.And(queries));

            return(query);
        }
Exemplo n.º 2
0
        private static FilterDefinition <BsonDocument> QuantityQuery(String parameterName, Operator optor, String modifier, ValueExpression operand)
        {
            //$elemMatch only works on array values. But the MongoIndexMapper only creates an array if there are multiple values for a given parameter.
            //So we also construct a query for when there is only one set of values in the searchIndex, hence there is no array.
            var quantity = operand.ToModelQuantity();

            Fhir.Metrics.Quantity q = quantity.ToUnitsOfMeasureQuantity().Canonical();
            string    decimals      = q.SearchableString();
            BsonValue value         = q.GetValueAsBson();

            List <FilterDefinition <BsonDocument> > arrayQueries   = new List <FilterDefinition <BsonDocument> >();
            List <FilterDefinition <BsonDocument> > noArrayQueries = new List <FilterDefinition <BsonDocument> >()
            {
                Builders <BsonDocument> .Filter.Not(Builders <BsonDocument> .Filter.Type(parameterName, BsonType.Array))
            };

            switch (optor)
            {
            case Operator.EQ:
                arrayQueries.Add(Builders <BsonDocument> .Filter.Regex("decimals", new BsonRegularExpression("^" + decimals)));
                noArrayQueries.Add(Builders <BsonDocument> .Filter.Regex(parameterName + ".decimals", new BsonRegularExpression("^" + decimals)));
                break;

            default:
                arrayQueries.Add(ExpressionQuery("value", optor, value));
                noArrayQueries.Add(ExpressionQuery(parameterName + ".value", optor, value));
                break;
            }

            if (quantity.System != null)
            {
                arrayQueries.Add(Builders <BsonDocument> .Filter.Eq("system", quantity.System.ToString()));
                noArrayQueries.Add(Builders <BsonDocument> .Filter.Eq(parameterName + ".system", quantity.System.ToString()));
            }
            arrayQueries.Add(Builders <BsonDocument> .Filter.Eq("unit", q.Metric.ToString()));
            noArrayQueries.Add(Builders <BsonDocument> .Filter.Eq(parameterName + ".unit", q.Metric.ToString()));

            var arrayQuery = Builders <BsonDocument> .Filter.ElemMatch(parameterName, Builders <BsonDocument> .Filter.And(arrayQueries));

            var noArrayQuery = Builders <BsonDocument> .Filter.And(noArrayQueries);

            FilterDefinition <BsonDocument> query = Builders <BsonDocument> .Filter.Or(arrayQuery, noArrayQuery);

            return(query);
        }
Exemplo n.º 3
0
        private static IMongoQuery QuantityQuery(String parameterName, Operator optor, String modifier, ValueExpression operand)
        {
            //$elemMatch only works on array values. But the MongoIndexMapper only creates an array if there are multiple values for a given parameter.
            //So we also construct a query for when there is only one set of values in the searchIndex, hence there is no array.
            var quantity = operand.ToModelQuantity();
            Fhir.Metrics.Quantity q = quantity.ToUnitsOfMeasureQuantity().Canonical();
            string decimals = q.SearchableString();
            BsonValue value = q.GetValueAsBson();

            List<IMongoQuery> arrayQueries = new List<IMongoQuery>();
            List<IMongoQuery> noArrayQueries = new List<IMongoQuery>() { M.Query.Not(M.Query.Type(parameterName, BsonType.Array)) };
            switch (optor)
            {
                case Operator.EQ:
                    arrayQueries.Add(M.Query.Matches("decimals", new BsonRegularExpression("^" + decimals)));
                    noArrayQueries.Add(M.Query.Matches(parameterName + ".decimals", new BsonRegularExpression("^" + decimals)));
                    break;

                default:
                    arrayQueries.Add(ExpressionQuery("value", optor, value));
                    noArrayQueries.Add(ExpressionQuery(parameterName + ".value", optor, value));
                    break;
            }

            if (quantity.System != null)
            {
                arrayQueries.Add(M.Query.EQ("system", quantity.System.ToString()));
                noArrayQueries.Add(M.Query.EQ(parameterName + ".system", quantity.System.ToString()));
            }
            arrayQueries.Add(M.Query.EQ("unit", q.Metric.ToString()));
            noArrayQueries.Add(M.Query.EQ(parameterName + ".unit", q.Metric.ToString()));

            var arrayQuery = M.Query.ElemMatch(parameterName, M.Query.And(arrayQueries));
            var noArrayQuery = M.Query.And(noArrayQueries);

            IMongoQuery query = M.Query.Or(arrayQuery, noArrayQuery);
            return query;
        }
        private static IMongoQuery QuantityQuery(String parameterName, Operator optor, String modifier, ValueExpression operand)
        {
            var quantity = operand.ToModelQuantity();
            Fhir.Metrics.Quantity q = quantity.ToUnitsOfMeasureQuantity().Canonical();
            string decimals = UnitsOfMeasureHelper.SearchableString(q);
            BsonValue value = q.GetValueAsBson();

            List<IMongoQuery> queries = new List<IMongoQuery>();
            switch (optor)
            {
                case Operator.EQ:
                    queries.Add(M.Query.Matches("decimals", new BsonRegularExpression("^" + decimals)));
                    break;

                default:
                    queries.Add(ExpressionQuery("value", optor, value));
                    break;
            }

            if (quantity.System != null)
                queries.Add(M.Query.EQ("system", quantity.System.ToString()));

            queries.Add(M.Query.EQ("unit", q.Metric.ToString()));

            IMongoQuery query = M.Query.ElemMatch(parameterName, M.Query.And(queries));
            return query;
        }