public void ParseCriterium() { 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.Type); 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.Type); 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.Type); crit = Criterium.Parse("paramX:missing=true"); Assert.AreEqual("paramX", crit.ParamName); Assert.IsNull(crit.Operand); Assert.IsNull(crit.Modifier); Assert.AreEqual(Operator.ISNULL, crit.Type); crit = Criterium.Parse("paramX:missing=false"); Assert.AreEqual("paramX", crit.ParamName); Assert.IsNull(crit.Operand); Assert.IsNull(crit.Modifier); Assert.AreEqual(Operator.NOTNULL, crit.Type); }
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) { } }
private IMongoQuery createSimpleQuery(Query query) // without chains { IMongoQuery resourceFilter = query.ResourceFilter(); var criteria = query.Criteria.Select(c => Criterium.Parse(c)); IMongoQuery criteriaFilter = M.Query.And(criteria.Select(c => c.ToFilter(query.ResourceType))); return(M.Query.And(resourceFilter, criteriaFilter)); }
public void ParseCriteriumFromParameter() { Parameters.ParametersParameterComponent parameter = Parameters.BuildParamExtension("Subject.name", "Teun"); Criterium sut = Criterium.Parse(parameter); Assert.AreEqual("Subject", sut.ParamName); Assert.IsTrue(sut.Operand is Criterium); Criterium sub = sut.Operand as Criterium; Assert.AreEqual("Teun", sub.Operand.ToString()); Assert.AreEqual(Operator.EQ, sub.Type); }
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); }
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); }
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); }
private string BuildAndReturnQueryFilterAsJsonString(ResourceType resourceType, string searchParameter, string query) { var bsonSerializerRegistry = new BsonSerializerRegistry(); bsonSerializerRegistry.RegisterSerializationProvider(new BsonSerializationProvider()); var resourceTypeAsString = resourceType.GetLiteral(); var criterium = Criterium.Parse(query); criterium.SearchParameters.AddRange(ModelInfo.SearchParameters.Where(p => p.Resource == resourceTypeAsString && p.Name == searchParameter)); var filter = criterium.ToFilter(resourceType.GetLiteral()); var jsonFilter = filter?.Render(null, bsonSerializerRegistry)?.ToJson(); return(jsonFilter); }
//TODO: Delete, F.Query is obsolete. /* * public SearchResults Search(F.Query query) * { * SearchResults results = new SearchResults(); * * var criteria = parseCriteria(query, results); * * if (!results.HasErrors) * { * results.UsedCriteria = criteria; * //TODO: ResourceType.ToString() sufficient, or need to use EnumMapping? * var normalizedCriteria = NormalizeNonChainedReferenceCriteria(criteria, query.ResourceType.ToString()); * List<BsonValue> keys = CollectKeys(query.ResourceType.ToString(), normalizedCriteria, results); * * int numMatches = keys.Count(); * * results.AddRange(KeysToSearchResults(keys)); * results.MatchCount = numMatches; * } * * return results; * } */ private List <Criterium> parseCriteria(SearchParams searchCommand, SearchResults results) { var result = new List <Criterium>(); foreach (var c in searchCommand.Parameters) { try { result.Add(Criterium.Parse(c.Item1, c.Item2)); } catch (Exception ex) { results.AddIssue(String.Format("Could not parse parameter [{0}] for reason [{1}].", c.ToString(), ex.Message)); } } return(result); }
public void StringQueryTest() { var resourceType = ResourceType.Subscription.GetLiteral(); var searchParamName = "criteria"; var criterium = Criterium.Parse("criteria=Observation?patient.identifier=http://somehost.no/fhir/Name%20Hospital|someId"); criterium.SearchParameters.AddRange(ModelInfo.SearchParameters.Where(p => p.Resource == resourceType && p.Name == searchParamName)); var filter = criterium.ToFilter(resourceType); var jsonFilter = filter?.Render(null, null)?.ToJson(); Assert.Equal( "{ \"criteria\" : /^Observation?patient.identifier=http:\\/\\/somehost.no\\/fhir\\/Name%20Hospital|someId/i }", jsonFilter); }
public void ParseChain() { var crit = Criterium.Parse("par1:type1.par2.par3:text=hoi"); Assert.IsTrue(crit.Type == Operator.CHAIN); Assert.AreEqual("type1", crit.Modifier); Assert.IsTrue(crit.Operand is Criterium); crit = crit.Operand as Criterium; Assert.IsTrue(crit.Type == Operator.CHAIN); Assert.AreEqual(null, crit.Modifier); Assert.IsTrue(crit.Operand is Criterium); crit = crit.Operand as Criterium; Assert.IsTrue(crit.Type == Operator.EQ); Assert.AreEqual("text", crit.Modifier); Assert.IsTrue(crit.Operand is UntypedValue); }
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); }
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); }
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); }
/// <inheritdoc /> public async Task <SearchResults> Search(string resource, SearchParams searchCommand) { _logger.LogDebug($"{resource} search requested with {searchCommand.ToUriParamList().ToQueryString()}"); var resources = await GetIndexValues(resource, searchCommand).ConfigureAwait(false); var count = resources.Count; if (searchCommand.Count.HasValue && searchCommand.Count.Value > 0) { resources = resources.Take(searchCommand.Count.Value).ToList(); } var keys = resources.ToList(); var results = new SearchResults { MatchCount = count, UsedCriteria = searchCommand.Parameters.Select(t => Criterium.Parse(t.Item1, t.Item2)).ToList() }; results.AddRange(keys); return(results); }
public void ParseComparatorOperatorForDate() { var criterium = Criterium.Parse("birthdate=lt2018-01-01"); Assert.Equal(Operator.LT, criterium.Operator); }
public void ParseComparatorOperatorForNumber() { var criterium = Criterium.Parse("length=gt20"); Assert.Equal(Operator.GT, criterium.Operator); }
public void ParseCriteriumDstu2() { var crit = Criterium.Parse("birthdate=2018-01-01"); Assert.Equal("birthdate", crit.ParamName); Assert.Null(crit.Modifier); Assert.Equal("2018-01-01", crit.Operand.ToString()); Assert.Equal(Operator.EQ, crit.Operator); crit = Criterium.Parse("birthdate=eq2018-01-01"); Assert.Equal("birthdate", crit.ParamName); Assert.Null(crit.Modifier); Assert.Equal("2018-01-01", crit.Operand.ToString()); Assert.Equal(Operator.EQ, crit.Operator); crit = Criterium.Parse("birthdate=ne2018-01-01"); Assert.Equal("birthdate", crit.ParamName); Assert.Null(crit.Modifier); Assert.Equal("2018-01-01", crit.Operand.ToString()); Assert.Equal(Operator.NOT_EQUAL, crit.Operator); crit = Criterium.Parse("birthdate=gt2018-01-01"); Assert.Equal("birthdate", crit.ParamName); Assert.Null(crit.Modifier); Assert.Equal("2018-01-01", crit.Operand.ToString()); Assert.Equal(Operator.GT, crit.Operator); crit = Criterium.Parse("birthdate=ge2018-01-01"); Assert.Equal("birthdate", crit.ParamName); Assert.Null(crit.Modifier); Assert.Equal("2018-01-01", crit.Operand.ToString()); Assert.Equal(Operator.GTE, crit.Operator); crit = Criterium.Parse("birthdate=lt2018-01-01"); Assert.Equal("birthdate", crit.ParamName); Assert.Null(crit.Modifier); Assert.Equal("2018-01-01", crit.Operand.ToString()); Assert.Equal(Operator.LT, crit.Operator); crit = Criterium.Parse("birthdate=le2018-01-01"); Assert.Equal("birthdate", crit.ParamName); Assert.Null(crit.Modifier); Assert.Equal("2018-01-01", crit.Operand.ToString()); Assert.Equal(Operator.LTE, crit.Operator); crit = Criterium.Parse("birthdate:modif1=ap2018-01-01"); Assert.Equal("birthdate", crit.ParamName); Assert.Equal("2018-01-01", crit.Operand.ToString()); Assert.Equal("modif1", crit.Modifier); Assert.Equal(Operator.APPROX, crit.Operator); crit = Criterium.Parse("birthdate:missing=true"); Assert.Equal("birthdate", crit.ParamName); Assert.Null(crit.Operand); Assert.Null(crit.Modifier); Assert.Equal(Operator.ISNULL, crit.Operator); crit = Criterium.Parse("birthdate:missing=false"); Assert.Equal("birthdate", crit.ParamName); Assert.Null(crit.Operand); Assert.Null(crit.Modifier); Assert.Equal(Operator.NOTNULL, crit.Operator); }
public void ParseComparatorOperatorForQuantity() { var criterium = Criterium.Parse("value-quantity=le5.4|http://unitsofmeasure.org|mg"); Assert.Equal(Operator.LTE, criterium.Operator); }