Parse() public static method

public static Parse ( string text ) : Criterium
text string
return Criterium
Exemplo n.º 1
0
        public void HandleDateParam()
        {
            // Brian: Not sure tha these tests SHOULD pass...
            // a time component on the Date?
            var p1 = new DateValue(new DateTimeOffset(1972, 11, 30, 15, 20, 49, TimeSpan.Zero));

            Assert.AreEqual("1972-11-30", p1.ToString());

            // we can parse a valid FHIR datetime and strip the time part off
            // (but it must be a valid FHIR datetime)
            var p2 = DateValue.Parse("1972-11-30T18:45:36Z");

            Assert.AreEqual("1972-11-30", p2.ToString());

            var crit = Criterium.Parse("paramX=1972-11-30");
            var p3   = ((UntypedValue)crit.Operand).AsDateValue();

            Assert.AreEqual("1972-11-30", p3.Value);

            try
            {
                // Test with an invalid FHIR datetime (no timezone specified)
                var p4 = DateValue.Parse("1972-11-30T18:45:36");
                Assert.Fail("The datetime [1972-11-30T18:45:36] does not have a timezone, hence should fail parsing as a datevalue (via fhirdatetime)");
            }
            catch (ArgumentException)
            {
            }
        }
Exemplo n.º 2
0
        public void ParseCriteriumDSTU1()
        {
            var crit = Criterium.Parse("paramX=18");

            Assert.AreEqual("paramX", crit.ParamName);
            Assert.IsNull(crit.Modifier);
            Assert.AreEqual("18", crit.Operand.ToString());
            Assert.AreEqual(Operator.EQ, crit.Operator);

            crit = Criterium.Parse("paramX=>18");
            Assert.AreEqual("paramX", crit.ParamName);
            Assert.IsNull(crit.Modifier);
            Assert.AreEqual("18", crit.Operand.ToString());
            Assert.AreEqual(Operator.GT, crit.Operator);

            crit = Criterium.Parse("paramX:modif1=~18");
            Assert.AreEqual("paramX", crit.ParamName);
            Assert.AreEqual("18", crit.Operand.ToString());
            Assert.AreEqual("modif1", crit.Modifier);
            Assert.AreEqual(Operator.APPROX, crit.Operator);

            crit = Criterium.Parse("paramX:missing=true");
            Assert.AreEqual("paramX", crit.ParamName);
            Assert.IsNull(crit.Operand);
            Assert.IsNull(crit.Modifier);
            Assert.AreEqual(Operator.ISNULL, crit.Operator);

            crit = Criterium.Parse("paramX:missing=false");
            Assert.AreEqual("paramX", crit.ParamName);
            Assert.IsNull(crit.Operand);
            Assert.IsNull(crit.Modifier);
            Assert.AreEqual(Operator.NOTNULL, crit.Operator);
        }
Exemplo n.º 3
0
        public void HandleReferenceParam()
        {
            var p1 = new ReferenceValue("2");

            Assert.AreEqual("2", p1.Value);

            var p2 = new ReferenceValue("http://server.org/fhir/Patient/1");

            Assert.AreEqual("http://server.org/fhir/Patient/1", p2.Value);

            var crit = Criterium.Parse(@"paramX=http://server.org/\$4/fhir/Patient/1");
            var p3   = ((UntypedValue)crit.Operand).AsReferenceValue();

            Assert.AreEqual("http://server.org/$4/fhir/Patient/1", p3.Value);
        }
Exemplo n.º 4
0
        public void HandleDateTimeParam()
        {
            var p1 = new FhirDateTime(new DateTimeOffset(1972, 11, 30, 15, 20, 49, TimeSpan.Zero));

            Assert.AreEqual("1972-11-30T15:20:49+00:00", p1.Value.ToString());

            var crit = Criterium.Parse("paramX=1972-11-30T18:45:36Z");
            var p3   = ((UntypedValue)crit.Operand).AsDateValue();

            Assert.AreEqual("1972-11-30", p3.Value);

            var p4 = ((UntypedValue)crit.Operand).AsDateTimeValue();

            Assert.AreEqual("1972-11-30T18:45:36Z", p4.Value);
        }
Exemplo n.º 5
0
        public void HandleTokenParam()
        {
            var p1 = new TokenValue("NOK", "http://somewhere.nl/codes");

            Assert.AreEqual("http://somewhere.nl/codes|NOK", p1.ToString());

            var p2 = new TokenValue("y|n", "http://some|where.nl/codes");

            Assert.AreEqual(@"http://some\|where.nl/codes|y\|n", p2.ToString());

            var p3 = new TokenValue("NOK", matchAnyNamespace: true);

            Assert.AreEqual("NOK", p3.ToString());

            var p4 = new TokenValue("NOK", matchAnyNamespace: false);

            Assert.AreEqual("|NOK", p4.ToString());

            var p5 = TokenValue.Parse("http://somewhere.nl/codes|NOK");

            Assert.AreEqual("http://somewhere.nl/codes", p5.Namespace);
            Assert.AreEqual("NOK", p5.Value);
            Assert.IsFalse(p4.AnyNamespace);

            var p6 = TokenValue.Parse(@"http://some\|where.nl/codes|y\|n");

            Assert.AreEqual(@"http://some|where.nl/codes", p6.Namespace);
            Assert.AreEqual("y|n", p6.Value);
            Assert.IsFalse(p6.AnyNamespace);

            var p7 = TokenValue.Parse("|NOK");

            Assert.AreEqual(null, p7.Namespace);
            Assert.AreEqual("NOK", p7.Value);
            Assert.IsFalse(p7.AnyNamespace);

            var p8 = TokenValue.Parse("NOK");

            Assert.AreEqual(null, p8.Namespace);
            Assert.AreEqual("NOK", p8.Value);
            Assert.IsTrue(p8.AnyNamespace);

            var crit = Criterium.Parse("paramX=|NOK");
            var p9   = ((UntypedValue)crit.Operand).AsTokenValue();

            Assert.AreEqual("NOK", p9.Value);
            Assert.IsFalse(p9.AnyNamespace);
        }
Exemplo n.º 6
0
        private List <Criterium> parseCriteria(F.Query query, SearchResults results)
        {
            var result = new List <Criterium>();

            foreach (var c in query.Criteria)
            {
                try
                {
                    result.Add(Criterium.Parse(c));
                }
                catch (Exception ex)
                {
                    results.AddIssue(String.Format("Could not parse parameter [{0}] for reason [{1}].", c.ToString(), ex.Message));
                }
            }
            return(result);
        }
Exemplo n.º 7
0
        public void ParseChain()
        {
            var crit = Criterium.Parse("par1:type1.par2.par3:text=hoi");

            Assert.IsTrue(crit.Operator == Operator.CHAIN);
            Assert.AreEqual("type1", crit.Modifier);
            Assert.IsTrue(crit.Operand is Criterium);

            crit = crit.Operand as Criterium;
            Assert.IsTrue(crit.Operator == Operator.CHAIN);
            Assert.AreEqual(null, crit.Modifier);
            Assert.IsTrue(crit.Operand is Criterium);

            crit = crit.Operand as Criterium;
            Assert.IsTrue(crit.Operator == Operator.EQ);
            Assert.AreEqual("text", crit.Modifier);
            Assert.IsTrue(crit.Operand is UntypedValue);
        }
Exemplo n.º 8
0
        public void HandleStringParam()
        {
            var p1 = new StringValue("Hello, world");

            Assert.AreEqual(@"Hello\, world", p1.ToString());

            var p2 = new StringValue("Pay $300|Pay $100|");

            Assert.AreEqual(@"Pay \$300\|Pay \$100\|", p2.ToString());

            var p3 = StringValue.Parse(@"Pay \$300\|Pay \$100\|");

            Assert.AreEqual("Pay $300|Pay $100|", p3.Value);

            var crit = Criterium.Parse(@"paramX=Hello\, world");
            var p4   = ((UntypedValue)crit.Operand).AsStringValue();

            Assert.AreEqual("Hello, world", p4.Value);
        }
Exemplo n.º 9
0
        public void HandleNumberParam()
        {
            var p1 = new NumberValue(18);

            Assert.AreEqual("18", p1.ToString());

            var p2 = NumberValue.Parse("18");

            Assert.AreEqual(18M, p2.Value);

            var p3 = NumberValue.Parse("18.00");

            Assert.AreEqual(18.00M, p3.Value);

            var crit = Criterium.Parse("paramX=18.34");
            var p4   = ((UntypedValue)crit.Operand).AsNumberValue();

            Assert.AreEqual(18.34M, p4.Value);
        }
Exemplo n.º 10
0
        public void HandleQuantityParam()
        {
            var p1 = new QuantityValue(3.141M, "http://unitsofmeasure.org", "mg");

            Assert.AreEqual("3.141|http://unitsofmeasure.org|mg", p1.ToString());

            var p2 = new QuantityValue(3.141M, "mg");

            Assert.AreEqual("3.141||mg", p2.ToString());

            var p3 = new QuantityValue(3.141M, "http://system.com/id$4", "$/d");

            Assert.AreEqual(@"3.141|http://system.com/id\$4|\$/d", p3.ToString());

            var p4 = QuantityValue.Parse("3.141|http://unitsofmeasure.org|mg");

            Assert.AreEqual(3.141M, p4.Number);
            Assert.AreEqual("http://unitsofmeasure.org", p4.Namespace);
            Assert.AreEqual("mg", p4.Unit);

            var p5 = QuantityValue.Parse("3.141||mg");

            Assert.AreEqual(3.141M, p5.Number);
            Assert.IsNull(p5.Namespace);
            Assert.AreEqual("mg", p5.Unit);

            var p6 = QuantityValue.Parse(@"3.141|http://system.com/id\$4|\$/d");

            Assert.AreEqual(3.141M, p6.Number);
            Assert.AreEqual("http://system.com/id$4", p6.Namespace);
            Assert.AreEqual("$/d", p6.Unit);

            var crit = Criterium.Parse("paramX=3.14||mg");
            var p7   = ((UntypedValue)crit.Operand).AsQuantityValue();

            Assert.AreEqual(3.14M, p7.Number);
            Assert.IsNull(p7.Namespace);
            Assert.AreEqual("mg", p7.Unit);
        }
Exemplo n.º 11
0
        public void ParseCriteriumDSTU2()
        {
            var crit = Criterium.Parse("paramX=18");

            Assert.AreEqual("paramX", crit.ParamName);
            Assert.IsNull(crit.Modifier);
            Assert.AreEqual("18", crit.Operand.ToString());
            Assert.AreEqual(Operator.EQ, crit.Operator);

            crit = Criterium.Parse("paramX=eq18");
            Assert.AreEqual("paramX", crit.ParamName);
            Assert.IsNull(crit.Modifier);
            Assert.AreEqual("18", crit.Operand.ToString());
            Assert.AreEqual(Operator.EQ, crit.Operator);

            crit = Criterium.Parse("paramX=ne18");
            Assert.AreEqual("paramX", crit.ParamName);
            Assert.IsNull(crit.Modifier);
            Assert.AreEqual("18", crit.Operand.ToString());
            Assert.AreEqual(Operator.NOT_EQUAL, crit.Operator);

            crit = Criterium.Parse("paramX=gt18");
            Assert.AreEqual("paramX", crit.ParamName);
            Assert.IsNull(crit.Modifier);
            Assert.AreEqual("18", crit.Operand.ToString());
            Assert.AreEqual(Operator.GT, crit.Operator);

            crit = Criterium.Parse("paramX=ge18");
            Assert.AreEqual("paramX", crit.ParamName);
            Assert.IsNull(crit.Modifier);
            Assert.AreEqual("18", crit.Operand.ToString());
            Assert.AreEqual(Operator.GTE, crit.Operator);

            crit = Criterium.Parse("paramX=lt18");
            Assert.AreEqual("paramX", crit.ParamName);
            Assert.IsNull(crit.Modifier);
            Assert.AreEqual("18", crit.Operand.ToString());
            Assert.AreEqual(Operator.LT, crit.Operator);

            crit = Criterium.Parse("paramX=le18");
            Assert.AreEqual("paramX", crit.ParamName);
            Assert.IsNull(crit.Modifier);
            Assert.AreEqual("18", crit.Operand.ToString());
            Assert.AreEqual(Operator.LTE, crit.Operator);

            crit = Criterium.Parse("paramX:modif1=ap18");
            Assert.AreEqual("paramX", crit.ParamName);
            Assert.AreEqual("18", crit.Operand.ToString());
            Assert.AreEqual("modif1", crit.Modifier);
            Assert.AreEqual(Operator.APPROX, crit.Operator);

            crit = Criterium.Parse("paramX:missing=true");
            Assert.AreEqual("paramX", crit.ParamName);
            Assert.IsNull(crit.Operand);
            Assert.IsNull(crit.Modifier);
            Assert.AreEqual(Operator.ISNULL, crit.Operator);

            crit = Criterium.Parse("paramX:missing=false");
            Assert.AreEqual("paramX", crit.ParamName);
            Assert.IsNull(crit.Operand);
            Assert.IsNull(crit.Modifier);
            Assert.AreEqual(Operator.NOTNULL, crit.Operator);
        }
Exemplo n.º 12
0
        public void ParseCriteriumDSTU2()
        {
            var crit = Criterium.Parse("birthdate=2018-01-01");

            Assert.AreEqual("birthdate", crit.ParamName);
            Assert.IsNull(crit.Modifier);
            Assert.AreEqual("2018-01-01", crit.Operand.ToString());
            Assert.AreEqual(Operator.EQ, crit.Operator);

            crit = Criterium.Parse("birthdate=eq2018-01-01");
            Assert.AreEqual("birthdate", crit.ParamName);
            Assert.IsNull(crit.Modifier);
            Assert.AreEqual("2018-01-01", crit.Operand.ToString());
            Assert.AreEqual(Operator.EQ, crit.Operator);

            crit = Criterium.Parse("birthdate=ne2018-01-01");
            Assert.AreEqual("birthdate", crit.ParamName);
            Assert.IsNull(crit.Modifier);
            Assert.AreEqual("2018-01-01", crit.Operand.ToString());
            Assert.AreEqual(Operator.NOT_EQUAL, crit.Operator);

            crit = Criterium.Parse("birthdate=gt2018-01-01");
            Assert.AreEqual("birthdate", crit.ParamName);
            Assert.IsNull(crit.Modifier);
            Assert.AreEqual("2018-01-01", crit.Operand.ToString());
            Assert.AreEqual(Operator.GT, crit.Operator);

            crit = Criterium.Parse("birthdate=ge2018-01-01");
            Assert.AreEqual("birthdate", crit.ParamName);
            Assert.IsNull(crit.Modifier);
            Assert.AreEqual("2018-01-01", crit.Operand.ToString());
            Assert.AreEqual(Operator.GTE, crit.Operator);

            crit = Criterium.Parse("birthdate=lt2018-01-01");
            Assert.AreEqual("birthdate", crit.ParamName);
            Assert.IsNull(crit.Modifier);
            Assert.AreEqual("2018-01-01", crit.Operand.ToString());
            Assert.AreEqual(Operator.LT, crit.Operator);

            crit = Criterium.Parse("birthdate=le2018-01-01");
            Assert.AreEqual("birthdate", crit.ParamName);
            Assert.IsNull(crit.Modifier);
            Assert.AreEqual("2018-01-01", crit.Operand.ToString());
            Assert.AreEqual(Operator.LTE, crit.Operator);

            crit = Criterium.Parse("birthdate:modif1=ap2018-01-01");
            Assert.AreEqual("birthdate", crit.ParamName);
            Assert.AreEqual("2018-01-01", crit.Operand.ToString());
            Assert.AreEqual("modif1", crit.Modifier);
            Assert.AreEqual(Operator.APPROX, crit.Operator);

            crit = Criterium.Parse("birthdate:missing=true");
            Assert.AreEqual("birthdate", crit.ParamName);
            Assert.IsNull(crit.Operand);
            Assert.IsNull(crit.Modifier);
            Assert.AreEqual(Operator.ISNULL, crit.Operator);

            crit = Criterium.Parse("birthdate:missing=false");
            Assert.AreEqual("birthdate", crit.ParamName);
            Assert.IsNull(crit.Operand);
            Assert.IsNull(crit.Modifier);
            Assert.AreEqual(Operator.NOTNULL, crit.Operator);
        }
Exemplo n.º 13
0
        public void ParseComparatorOperatorForNumber()
        {
            var criterium = Criterium.Parse("length=gt20");

            Assert.AreEqual(Operator.GT, criterium.Operator);
        }
Exemplo n.º 14
0
        public void ParseComparatorOperatorForQuantity()
        {
            var criterium = Criterium.Parse("value-quantity=le5.4|http://unitsofmeasure.org|mg");

            Assert.AreEqual(Operator.LTE, criterium.Operator);
        }
Exemplo n.º 15
0
        public void ParseComparatorOperatorForDate()
        {
            var criterium = Criterium.Parse("birthdate=lt2018-01-01");

            Assert.AreEqual(Operator.LT, criterium.Operator);
        }