private static IMongoQuery CreateFilter(ModelInfo.SearchParamDefinition parameter, Operator op, String modifier, Expression operand)
 {
     if (op == Operator.CHAIN)
     {
         throw new NotSupportedException("Chain operators should be handled in MongoSearcher.");
     }
     else // There's only one operand.
     {
         var valueOperand = (ValueExpression)operand;
         switch (parameter.Type)
         {
             case Conformance.SearchParamType.Composite:
                 return CompositeQuery(parameter, op, modifier, valueOperand);
             case Conformance.SearchParamType.Date:
                 return DateQuery(parameter.Name, op, modifier, valueOperand);
             case Conformance.SearchParamType.Number:
                 return NumberQuery(parameter.Name, op, valueOperand);
             case Conformance.SearchParamType.Quantity:
                 return QuantityQuery(parameter.Name, op, modifier, valueOperand);
             case Conformance.SearchParamType.Reference:
                 //Chain is handled in MongoSearcher, so here we have the result of a closed criterium: IN [ list of id's ]
                 return StringQuery(parameter.Name, op, modifier, valueOperand);
             case Conformance.SearchParamType.String:
                 return StringQuery(parameter.Name, op, modifier, valueOperand);
             case Conformance.SearchParamType.Token:
                 return TokenQuery(parameter.Name, op, modifier, valueOperand);
             default:
                 //return M.Query.Null;
                 throw new NotSupportedException("Only SearchParamType.Number or String is supported.");
         }
     }
 }
Example #2
0
 public static Definition CreateDefinition(ModelInfo.SearchParamDefinition paramdef)
 {
     Definition definition = new Definition();
     definition.Argument = ArgumentFactory.Create(paramdef.Type);
     definition.Resource = paramdef.Resource;
     definition.ParamName = paramdef.Name;
     definition.Query = new ElementQuery(paramdef.Path);
     definition.ParamType = paramdef.Type;
     definition.Description = paramdef.Description;
     return definition;
 }
Example #3
0
        private static IMongoQuery CreateFilter(ModelInfo.SearchParamDefinition parameter, Operator op, String modifier, Expression operand)
        {
            if (op == Operator.CHAIN)
            {
                throw new NotSupportedException("Chain operators should be handled in MongoSearcher.");
            }
            else // There's only one operand.
            {
                string parameterName = parameter.Name;
                if (parameterName == "_id")
                    parameterName = "fhir_id"; //See MongoIndexMapper for counterpart.

                var valueOperand = (ValueExpression)operand;
                switch (parameter.Type)
                {
                    case SearchParamType.Composite:
                        return CompositeQuery(parameter, op, modifier, valueOperand);
                    case SearchParamType.Date:
                        return DateQuery(parameterName, op, modifier, valueOperand);
                    case SearchParamType.Number:
                        return NumberQuery(parameter.Name, op, valueOperand);
                    case SearchParamType.Quantity:
                        return QuantityQuery(parameterName, op, modifier, valueOperand);
                    case SearchParamType.Reference:
                        //Chain is handled in MongoSearcher, so here we have the result of a closed criterium: IN [ list of id's ]
                        return StringQuery(parameterName, op, modifier, valueOperand);
                    case SearchParamType.String:
                        return StringQuery(parameterName, op, modifier, valueOperand);
                    case SearchParamType.Token:
                        return TokenQuery(parameterName, op, modifier, valueOperand);
                    case SearchParamType.Uri:
                        return UriQuery(parameterName, op, modifier, valueOperand);
                    default:
                        //return M.Query.Null;
                        throw new NotSupportedException(String.Format("SearchParamType {0} on parameter {1} not supported.", parameter.Type, parameter.Name));
                }
            }
        }
Example #4
0
        private static IMongoQuery CompositeQuery(ModelInfo.SearchParamDefinition parameterDef, Operator optor, String modifier, ValueExpression operand)
        {
            if (optor == Operator.IN)
            {
                var choices = ((ChoiceValue)operand);
                var queries = new List<IMongoQuery>();
                foreach (var choice in choices.Choices)
                {
                    queries.Add(CompositeQuery(parameterDef, Operator.EQ, modifier, choice));
                }
                return M.Query.Or(queries);
            }
            else if (optor == Operator.EQ)
            {
                var typedOperand = (CompositeValue)operand;
                var queries = new List<IMongoQuery>();
                var components = typedOperand.Components;
                var subParams = parameterDef.CompositeParams;

                if (components.Count() != subParams.Count())
                {
                    throw new ArgumentException(String.Format("Parameter {0} requires exactly {1} composite values, not the currently provided {2} values.", parameterDef.Name, subParams.Count(), components.Count()));
                }

                for (int i = 0; i < subParams.Count(); i++)
                {
                    var subCrit = new Criterium();
                    subCrit.Operator = Operator.EQ;
                    subCrit.ParamName = subParams[i];
                    subCrit.Operand = components[i];
                    subCrit.Modifier = modifier;
                    queries.Add(subCrit.ToFilter(parameterDef.Resource));
                }
                return M.Query.And(queries);
            }
            throw new ArgumentException(String.Format("Invalid operator {0} on composite parameter {1}", optor.ToString(), parameterDef.Name));
        }
Example #5
0
        private static List<string> GetTargetedReferenceTypes(ModelInfo.SearchParamDefinition parameter, String modifier)
        {
            var allowedResourceTypes = ModelInfo.SupportedResources; //TODO: restrict to parameter.ReferencedResources. This means not making this static, because you want to use IFhirModel.
            List<string> searchResourceTypes = new List<string>();
            if (String.IsNullOrEmpty(modifier))
                searchResourceTypes.AddRange(allowedResourceTypes);
            else if (allowedResourceTypes.Contains(modifier))
            {
                searchResourceTypes.Add(modifier);
            }
            else
            {
                throw new NotSupportedException(String.Format("Referenced type cannot be of type %s.", modifier));
            }

            return searchResourceTypes;
        }
 public static void SetOriginalDefinition(this SearchParameter searchParameter, ModelInfo.SearchParamDefinition definition)
 {
     searchParameter.UserData.Add("original_definition", definition);
 }