public void String_FindsResourceOnExactValue() { // Default search = partial from the start var q = new Query().For("Patient").Where("family=Mckinney"); var r = index.Search(q); Assert.IsTrue(r.Has("Patient/76")); }
public void ChainWithModifierToString_DoesNotFindResourceOnWronglySpelledValue() { var q = new Query().For("Patient").Where("given=nancy").Where("provider:Organization.name=healthy"); var results = index.Search(q); //results = index.Search("Patient", "given=\"ned\"&provider:Organization.name:partial=\"healthy\""); Assert.IsTrue(results.Count == 0); }
public void ChainWithModifierToStringExact_FindsResourceOnExactValue() { var q = new Query().For("Patient").Where("given=nancy").Where("provider:Organization.name:exact=Health Level Seven International"); var results = index.Search(q); //results = index.Search("Patient", "given=\"ned\"&provider:Organization.name:exact=\"Health Level Seven International\""); Assert.IsTrue(results.Count == 1); }
public void ChainWithModifierToString_FindsResourceOnFirstPartOfValue() { var q = new Query().For("Patient").Where("given=nancy").Where("provider:Organization.name=health"); var results = index.Search(q); //results = index.Search("Patient", "given=\"nancy\"&provider:Organization.name:partial=\"health\""); Assert.IsTrue(results.Count == 1); }
public void String_IgnoresAndReportsInvalidOperator() { var q = new Query().For("Patient").Where("family=>Mckinney"); var r = index.Search(q); Assert.IsTrue(r.HasIssues); Assert.AreEqual(String.Empty, r.UsedCriteria); Assert.IsTrue(r.Count > 0); //All Patient resources should be found. }
public void RetrieveCriteria() { var q = new Query() .For("Patient").Where("name:exact=ewout").OrderBy("birthDate", SortOrder.Descending) .SummaryOnly().Include("Patient.managingOrganization") .LimitTo(20); Assert.AreEqual(1, q.Criteria.Count()); Assert.AreEqual("ewout", Query.ExtractParamValue(q.Criteria.First())); }
internal static Query Load (String resource, IEnumerable<Tuple<String, String>> parameters) { Query result = new Query(); result.ResourceType = resource; foreach (var p in parameters) { result.AddParameter(p.Item1, p.Item2); }; return result; }
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); }
public void ReapplySingleParam() { var q = new Query() .Custom("mySearch").OrderBy("adsfadf").OrderBy("q", SortOrder.Descending) .LimitTo(10).LimitTo(20).Custom("miSearch").SummaryOnly().SummaryOnly(false); Assert.AreEqual("miSearch", q.QueryName); Assert.IsFalse(q.Summary); var o = q.Sort; Assert.AreEqual("q", o.Item1); Assert.AreEqual(SortOrder.Descending, o.Item2); Assert.AreEqual(20, q.Count); Assert.IsFalse(q.Summary); }
public void ManipulateParameters() { var q = new Query(); q.AddParameter("testX", "someVal"); q.AddParameter("testX", "someVal2"); q.AddParameter("testXY", "someVal3"); var vals = q.GetValues("testX"); Assert.AreEqual(2, vals.Count()); Assert.AreEqual("someVal", vals.First()); Assert.AreEqual("someVal2", vals.Skip(1).First()); Assert.AreEqual("someVal3", q.GetSingleValue("testXY")); q.RemoveParameter("testXY"); Assert.IsNull(q.GetSingleValue("testXY")); Assert.AreEqual(2, q.GetValues("testX").Count()); }
public static RestUrl Search(this RestUrl url, Query q) { // The ResourceType is the only parameter that needs special handling, // since the others are all "normal" parameters. Just make sure we don't // include the special _type parameter on the REST url var result = url.Search(q.ResourceType); foreach (var par in q.Parameter) { var paramKey = Query.ExtractParamKey(par); if (paramKey != Query.SEARCH_PARAM_TYPE) { result.AddParam(Query.ExtractParamKey(par), Query.ExtractParamValue(par)); } } return result; }
public SearchResults Search(F.Query query) { SearchResults results = new SearchResults(); var criteria = parseCriteria(query, results); if (!results.HasErrors) { results.UsedCriteria = criteria; var normalizedCriteria = NormalizeNonChainedReferenceCriteria(criteria, query.ResourceType); List <BsonValue> keys = CollectKeys(query.ResourceType, normalizedCriteria, results); int numMatches = keys.Count(); results.AddRange(KeysToSearchResults(keys)); results.MatchCount = numMatches; } return(results); }
public void TestProperties() { var q = new Query(); q.QueryName = "special"; q.ResourceType = "Patient"; q.Count = 31; q.Summary = true; q.Sort = Tuple.Create("sorted", SortOrder.Descending); q.Includes.Add("Patient.name"); q.Includes.Add("Observation.subject"); Assert.AreEqual("special", q.QueryName); Assert.AreEqual("Patient", q.ResourceType); Assert.AreEqual(31, q.Count); Assert.AreEqual(true, q.Summary); Assert.AreEqual(Tuple.Create("sorted", SortOrder.Descending), q.Sort); Assert.AreEqual(2, q.Includes.Count); Assert.AreEqual("Patient.name", q.Includes.First()); Assert.AreEqual("Observation.subject", q.Includes.Skip(1).First()); q.QueryName = "special2"; q.ResourceType = "Observation"; q.Count = 32; q.Summary = false; q.Sort = Tuple.Create("sorted2", SortOrder.Ascending); q.Includes.Add("Patient.name2"); q.Includes.Remove("Patient.name"); q.Includes.Add("Observation.subject2"); Assert.AreEqual("special2", q.QueryName); Assert.AreEqual("Observation", q.ResourceType); Assert.AreEqual(32, q.Count); Assert.AreEqual(false, q.Summary); Assert.AreEqual(Tuple.Create("sorted2", SortOrder.Ascending), q.Sort); Assert.AreEqual(3, q.Includes.Count); Assert.IsTrue(q.Includes.Contains("Patient.name2")); Assert.IsFalse(q.Includes.Contains("Patient.name")); Assert.IsTrue(q.Includes.Contains("Observation.subject")); Assert.IsTrue(q.Includes.Contains("Observation.subject2")); }
public void ManageSearchResult() { var q = new Query() .For("Patient").Where("name:exact=ewout").OrderBy("birthDate", SortOrder.Descending) .SummaryOnly().Include("Patient.managingOrganization") .LimitTo(20); var x = FhirSerializer.SerializeResourceToXml(q); Console.WriteLine(x); Assert.AreEqual("Patient", q.ResourceType); var p = q.Parameter.SingleWithName("name"); Assert.AreEqual("name:exact", Query.ExtractParamKey(p)); Assert.AreEqual("ewout", Query.ExtractParamValue(p)); var o = q.Sort; Assert.AreEqual("birthDate", o.Item1); Assert.AreEqual(SortOrder.Descending, o.Item2); Assert.IsTrue(q.Summary); Assert.IsTrue(q.Includes.Contains("Patient.managingOrganization")); Assert.AreEqual(20,q.Count); }
public void String_FindsResourceOnTwoExactValues() { var q = new Query().For("Patient").Where("given=nancy").Where("family=nuclear"); var results = index.Search(q); //results = index.Search("Patient", "given=\"nancy\"&family=\"nuclear\""); Assert.IsTrue(results.Count == 1); }
public void Reference_FindsResourceOnValidId() { var q = new Query().For("Patient").Where("given=ned").Where("provider=Organization/hl7"); var results = index.Search(q); Assert.AreEqual(1, results.Count); }
public void ChainWithModifierToToken_FindsResourceOnTokenCode() { // THE WORKS var q = new Query().For("Condition").Where("subject.identifier=12345"); var results = index.Search(q); //results = index.Search("Condition", "subject.identifier=12345"); Assert.IsTrue(results.Count >= 2); Assert.IsTrue(results.Has("Condition/example")); Assert.IsTrue(results.Has("Condition/example2")); }
public void StringExact_DoesNotFindResourceOnValueWithDifferentCapitalization() { var q = new Query().For("Patient").Where("family:exact=McKinney"); var r = index.Search(q); Assert.IsFalse(r.Has("Patient/76")); }
public void StringExact_DoesNotFindResourceOnFirstPartOfValue() { var q = new Query().For("Patient").Where("family:exact=Mckinn"); var r = index.Search(q); Assert.IsFalse(r.Has("Patient/76")); }
public void TripleChainToId_FindsResource() { var q = new Query().For("CarePlan").Where("condition.asserter.provider._id=Organization/1"); var results = index.Search(q); Assert.AreEqual(1, results.Count); //TODO: Resulting query is OK, but there is no matching data in the examples. Find an example that does return a result. }
public void TripleChainToString_FindsResourceOnExactValue() { var q = new Query().For("CarePlan").Where("condition.asserter.provider.name=Gastroenterology"); var results = index.Search(q); Assert.AreEqual(1, results.Count); //TODO: Resulting query is OK, but there is no matching data in the examples. Find an example that does return a result. }
public void Token_FindsResourceOnNamespaceAndCode() { var q = new Query().For("Practitioner").Where("gender=urn:oid:2.16.840.1.113883.4.642.1.24|F"); var results = index.Search(q); Assert.IsTrue(results.Has("Practitioner/f005")); }
public void Token_FindsResourceOnText() { var q = new Query().For("Patient").Where("gender:text=male"); var results = index.Search(q); // partial search op code, text or display. (includes "female"!) Assert.IsTrue(results.Has("Patient/80")); // Vera (woman) }
public void Token_ExcludesResourceWhenNamespaceMatchesButCodeDoesNot() { var q = new Query().For("Practitioner").Where("gender=urn:oid:2.16.840.1.113883.4.642.1.24|M"); var results = index.Search(q); Assert.IsFalse(results.Has("Practitioner/f005")); }
public void Token_FindsResourceOnCodeOnly() { // No modifier var q = new Query().For("Patient").Where("gender=F"); var results = index.Search(q); Assert.IsTrue(results.Has("Patient/80")); // Vera (woman) }
public void TokenText_FindsResourceOnEnglishText() { // Text modifier var q = new Query().For("Patient").Where("language:text=dutch"); var results = index.Search(q); Assert.IsTrue(results.Has("Patient/f001")); Assert.IsTrue(results.Has("Patient/f201")); }
public void StringExact_FindsResourceOnExactValue() { var q = new Query().For("Patient").Where("family:exact=Mckinney"); var r = index.Search(q); Assert.IsTrue(r.Has("Patient/76")); }
public void String_DoesNotFindResourceOnMiddlePartOfValue() { var q = new Query().For("Patient").Where("family=kinne"); var r = index.Search(q); Assert.IsFalse(r.Has("Patient/76")); }
public void String_DoesNotFindResourceOnWronglySpelledValue() { var q = new Query().For("Patient").Where("family=Mckinley"); var r = index.Search(q); Assert.IsFalse(r.Has("Patient/76")); }
public void String_FindsResourceOnFirstPartOfValue() { var q = new Query().For("Patient").Where("family=Mckinn"); var r = index.Search(q); Assert.IsTrue(r.Has("Patient/76")); }
public static void SerializeQuery(Hl7.Fhir.Model.Query value, IFhirWriter writer, bool summary) { writer.WriteStartRootObject("Query"); writer.WriteStartComplexContent(); // Serialize element _id if (value.LocalIdElement != null) { writer.WritePrimitiveContents("_id", value.LocalIdElement, XmlSerializationHint.Attribute); } // Serialize element extension if (value.Extension != null && !summary && value.Extension.Count > 0) { writer.WriteStartArrayElement("extension"); foreach (var item in value.Extension) { writer.WriteStartArrayMember("extension"); ExtensionSerializer.SerializeExtension(item, writer, summary); writer.WriteEndArrayMember(); } writer.WriteEndArrayElement(); } // Serialize element language if (value.LanguageElement != null && !summary) { writer.WriteStartElement("language"); CodeSerializer.SerializeCode(value.LanguageElement, writer, summary); writer.WriteEndElement(); } // Serialize element text if (value.Text != null && !summary) { writer.WriteStartElement("text"); NarrativeSerializer.SerializeNarrative(value.Text, writer, summary); writer.WriteEndElement(); } // Serialize element contained if (value.Contained != null && !summary && value.Contained.Count > 0) { writer.WriteStartArrayElement("contained"); foreach (var item in value.Contained) { writer.WriteStartArrayMember("contained"); FhirSerializer.SerializeResource(item, writer, summary); writer.WriteEndArrayMember(); } writer.WriteEndArrayElement(); } // Serialize element identifier if (value.IdentifierElement != null && !summary) { writer.WriteStartElement("identifier"); FhirUriSerializer.SerializeFhirUri(value.IdentifierElement, writer, summary); writer.WriteEndElement(); } // Serialize element parameter if (value.Parameter != null && !summary && value.Parameter.Count > 0) { writer.WriteStartArrayElement("parameter"); foreach (var item in value.Parameter) { writer.WriteStartArrayMember("parameter"); ExtensionSerializer.SerializeExtension(item, writer, summary); writer.WriteEndArrayMember(); } writer.WriteEndArrayElement(); } // Serialize element response if (value.Response != null && !summary) { writer.WriteStartElement("response"); QuerySerializer.SerializeQueryResponseComponent(value.Response, writer, summary); writer.WriteEndElement(); } writer.WriteEndComplexContent(); writer.WriteEndRootObject(); }
public void String_FindsResourceOnValueWithDifferentCapitialization() { var q = new Query().For("Patient").Where("family=McKinney"); var r = index.Search(q); Assert.IsTrue(r.Has("Patient/76")); }
public void TokenText_DoesNotFindResourceOnAcronym() { // Text modifier var q = new Query().For("Patient").Where("language:text=nl"); var results = index.Search(q); Assert.IsFalse(results.Has("Patient/f001")); Assert.IsFalse(results.Has("Patient/f201")); }
/// <summary> /// Parse Query /// </summary> public static Hl7.Fhir.Model.Query ParseQuery(IFhirReader reader, ErrorList errors, Hl7.Fhir.Model.Query existingInstance = null) { Hl7.Fhir.Model.Query result = existingInstance != null ? existingInstance : new Hl7.Fhir.Model.Query(); string currentElementName = reader.CurrentElementName; reader.EnterElement(); while (reader.HasMoreElements()) { var atName = reader.CurrentElementName; // Parse element extension if (atName == "extension") { result.Extension = new List <Hl7.Fhir.Model.Extension>(); reader.EnterArray(); while (ParserUtils.IsAtArrayElement(reader, "extension")) { result.Extension.Add(ExtensionParser.ParseExtension(reader, errors)); } reader.LeaveArray(); } // Parse element language else if (atName == "language") { result.LanguageElement = CodeParser.ParseCode(reader, errors); } // Parse element text else if (atName == "text") { result.Text = NarrativeParser.ParseNarrative(reader, errors); } // Parse element contained else if (atName == "contained") { result.Contained = new List <Hl7.Fhir.Model.Resource>(); reader.EnterArray(); while (ParserUtils.IsAtArrayElement(reader, "contained")) { result.Contained.Add(ParserUtils.ParseContainedResource(reader, errors)); } reader.LeaveArray(); } // Parse element _id else if (atName == "_id") { result.LocalIdElement = Id.Parse(reader.ReadPrimitiveContents(typeof(Id))); } // Parse element identifier else if (atName == "identifier") { result.IdentifierElement = FhirUriParser.ParseFhirUri(reader, errors); } // Parse element parameter else if (atName == "parameter") { result.Parameter = new List <Hl7.Fhir.Model.Extension>(); reader.EnterArray(); while (ParserUtils.IsAtArrayElement(reader, "parameter")) { result.Parameter.Add(ExtensionParser.ParseExtension(reader, errors)); } reader.LeaveArray(); } // Parse element response else if (atName == "response") { result.Response = QueryParser.ParseQueryResponseComponent(reader, errors); } else { errors.Add(String.Format("Encountered unknown element {0} while parsing {1}", reader.CurrentElementName, currentElementName), reader); reader.SkipSubElementsFor(currentElementName); result = null; } } reader.LeaveElement(); return(result); }