Esempio n. 1
0
        public void HandleMultiValueParam()
        {
            var p1 = new ChoiceValue(new ValueExpression[] { new StringValue("hello, world!"), new NumberValue(18.4M) });

            Assert.AreEqual(@"hello\, world!,18.4", p1.ToString());

            var p2 = ChoiceValue.Parse(@"hello\, world!,18.4");

            Assert.AreEqual(2, p2.Choices.Length);
            Assert.AreEqual("hello, world!", ((UntypedValue)p2.Choices[0]).AsStringValue().Value);
            Assert.AreEqual(18.4M, ((UntypedValue)p2.Choices[1]).AsNumberValue().Value);
        }
Esempio n. 2
0
        /// <summary>
        /// CloseCriterium("patient.name=\"Teun\"") -> "patient=id1,id2"
        /// </summary>
        /// <param name="resourceType"></param>
        /// <param name="crit"></param>
        /// <returns></returns>
        private Criterium CloseCriterium(Criterium crit, string resourceType)
        {
            List <string> targeted = crit.GetTargetedReferenceTypes(resourceType);
            List <string> allKeys  = new List <string>();

            foreach (var target in targeted)
            {
                var keys = CollectKeys(target, new List <Criterium> {
                    (Criterium)crit.Operand
                });                                                                                            //Recursive call to CollectKeys!
                allKeys.AddRange(keys.Select(k => k.ToString()));
            }
            crit.Type    = Operator.IN;
            crit.Operand = ChoiceValue.Parse(String.Join(",", allKeys));
            return(crit);
        }
Esempio n. 3
0
        public void HandleComposites()
        {
            var pX = new CompositeValue(new ValueExpression[] { new StringValue("hello, world!"), new NumberValue(14.8M) });
            var pY = new TokenValue("NOK", "http://somesuch.org");
            var p1 = new ChoiceValue(new ValueExpression[] { pX, pY });

            Assert.AreEqual(@"hello\, world!$14.8,http://somesuch.org|NOK", p1.ToString());

            var crit1 = ChoiceValue.Parse(@"hello\, world$14.8,http://somesuch.org|NOK");

            Assert.AreEqual(2, crit1.Choices.Length);
            Assert.IsTrue(crit1.Choices[0] is CompositeValue);
            var comp1 = crit1.Choices[0] as CompositeValue;

            Assert.AreEqual(2, comp1.Components.Length);
            Assert.AreEqual("hello, world", ((UntypedValue)comp1.Components[0]).AsStringValue().Value);
            Assert.AreEqual(14.8M, ((UntypedValue)comp1.Components[1]).AsNumberValue().Value);
            Assert.AreEqual("http://somesuch.org|NOK", ((UntypedValue)crit1.Choices[1]).AsTokenValue().ToString());
        }
Esempio n. 4
0
        private static Criterium fromPathTuples(IEnumerable <Tuple <string, string> > path, string value)
        {
            var        first    = path.First();
            var        name     = first.Item1;
            var        modifier = first.Item2;
            var        type     = Operator.EQ;
            Expression operand  = null;

            // If this is a chained search, unfold the chain first
            if (path.Count() > 1)
            {
                type    = Operator.CHAIN;
                operand = fromPathTuples(path.Skip(1), value);
            }

            // :missing modifier is actually not a real modifier and is turned into
            // either a ISNULL or NOTNULL operator
            else if (modifier == MISSINGMODIF)
            {
                modifier = null;

                if (value == MISSINGTRUE)
                {
                    type = Operator.ISNULL;
                }
                else if (value == MISSINGFALSE)
                {
                    type = Operator.NOTNULL;
                }
                else
                {
                    throw Error.Argument("value", "For the :missing modifier, only values 'true' and 'false' are allowed");
                }

                operand = null;
            }

            // else see if the value starts with a comparator
            else
            {
                var compVal = findComparator(value);

                type  = compVal.Item1;
                value = compVal.Item2;

                if (value == null)
                {
                    throw new FormatException("Value is empty");
                }

                // Parse the value. If there's > 1, we are using the IN operator, unless
                // the input already specifies another comparison, which would be illegal
                var values = ChoiceValue.Parse(value);

                if (values.Choices.Length > 1)
                {
                    if (type != Operator.EQ)
                    {
                        throw new InvalidOperationException("Multiple values cannot be used in combination with a comparison operator");
                    }
                    type    = Operator.IN;
                    operand = values;
                }
                else
                {
                    // Not really a multi value, just a single ValueExpression
                    operand = values.Choices[0];
                }
            }

            // Construct the new criterium based on the parsed values
            return(new Criterium()
            {
                ParamName = name,
                Type = type,
                Modifier = modifier,
                Operand = operand
            });
        }
Esempio n. 5
0
		public void HandleComposites()
		{
			var pX = new CompositeValue(new ValueExpression[] { new StringValue("hello, world!"), new NumberValue(14.8M) });
			var pY = new TokenValue("NOK", "http://somesuch.org");
			var p1 = new ChoiceValue(new ValueExpression[] { pX, pY });
			Assert.AreEqual(@"hello\, world!$14.8,http://somesuch.org|NOK", p1.ToString());

			var crit1 = ChoiceValue.Parse(@"hello\, world$14.8,http://somesuch.org|NOK");
			Assert.AreEqual(2, crit1.Choices.Length);
			Assert.IsTrue(crit1.Choices[0] is CompositeValue);
			var comp1 = crit1.Choices[0] as CompositeValue;
			Assert.AreEqual(2, comp1.Components.Length);
			Assert.AreEqual("hello, world", ((UntypedValue)comp1.Components[0]).AsStringValue().Value);
			Assert.AreEqual(14.8M, ((UntypedValue)comp1.Components[1]).AsNumberValue().Value);
			Assert.AreEqual("http://somesuch.org|NOK", ((UntypedValue)crit1.Choices[1]).AsTokenValue().ToString());
		}
Esempio n. 6
0
		public void HandleMultiValueParam()
		{
			var p1 = new ChoiceValue(new ValueExpression[] { new StringValue("hello, world!"), new NumberValue(18.4M) });
			Assert.AreEqual(@"hello\, world!,18.4", p1.ToString());

			var p2 = ChoiceValue.Parse(@"hello\, world!,18.4");
			Assert.AreEqual(2, p2.Choices.Length);
			Assert.AreEqual("hello, world!", ((UntypedValue)p2.Choices[0]).AsStringValue().Value);
			Assert.AreEqual(18.4M, ((UntypedValue)p2.Choices[1]).AsNumberValue().Value);
		}