public void TestInitialize() { IFhirModel _fhirModel; FhirPropertyIndex _propIndex; ResourceVisitor _resourceVisitor; ElementIndexer _elementIndexer; var _indexStoreMock = new Mock<IIndexStore>(); var spPatientName = new SearchParamDefinition() { Resource = "Patient", Name = "name", Description = @"A portion of either family or given name of the patient", Type = SearchParamType.String, Path = new string[] { "Patient.name", } }; var searchParameters = new List<SearchParamDefinition> { spPatientName }; var resources = new Dictionary<Type, string> { { typeof(Patient), "Patient" }, { typeof(HumanName), "HumanName" } }; var enums = new List<Type>(); //CK: I use real objects: saves me a lot of mocking and provides for a bit of integration testing. _fhirModel = new FhirModel(resources, searchParameters, enums); _propIndex = new FhirPropertyIndex(_fhirModel, new List<Type> { typeof(Patient), typeof(HumanName) }); _resourceVisitor = new ResourceVisitor(_propIndex); _elementIndexer = new ElementIndexer(_fhirModel); //_indexStoreMock.Setup(ixs => ixs.Save(It.IsAny<IndexValue>)) sutLimited = new IndexService(_fhirModel, _propIndex, _resourceVisitor, _elementIndexer, _indexStoreMock.Object); _fhirModel = new FhirModel(); //For this test I want all available types and searchparameters. _propIndex = new FhirPropertyIndex(_fhirModel); _resourceVisitor = new ResourceVisitor(_propIndex); _elementIndexer = new ElementIndexer(_fhirModel); sutFull = new IndexService(_fhirModel, _propIndex, _resourceVisitor, _elementIndexer, _indexStoreMock.Object); }
/// <summary> /// Returns true if the search parameter is one of the following types: Number, Date or Quantity. /// See https://www.hl7.org/fhir/stu3/search.html#prefix for more information. /// </summary> /// <param name="searchParamDefinitions"> /// A List of <see cref="SearchParamDefinition"/>, since this is an extension this is usually a reference /// to ModelInfo.SearcParameters. /// </param> /// <param name="name">A <see cref="string"/> representing the name of the search parameter.</param> /// <returns>Returns true if the search parameter is of type Number, Date or Quanity, otherwise false.</returns> internal static bool CanHaveOperatorPrefix(this List <SearchParamDefinition> searchParamDefinitions, string name) { SearchParamDefinition searchParamDefinition = searchParamDefinitions.Find(p => p.Name == name); return(searchParamDefinition != null && (searchParamDefinition.Type == SearchParamType.Number || searchParamDefinition.Type == SearchParamType.Date || searchParamDefinition.Type == SearchParamType.Quantity)); }
public IndexServiceTests() { var indexStoreMock = new Mock <IIndexStore>(); _examplePatientJson = TextFileHelper.ReadTextFileFromDisk( $".{Path.DirectorySeparatorChar}Examples{Path.DirectorySeparatorChar}patient-example.json"); _exampleAppointmentJson = TextFileHelper.ReadTextFileFromDisk( $".{Path.DirectorySeparatorChar}Examples{Path.DirectorySeparatorChar}appointment-example2doctors.json"); _carePlanWithContainedGoal = TextFileHelper.ReadTextFileFromDisk( $".{Path.DirectorySeparatorChar}Examples{Path.DirectorySeparatorChar}careplan-example-f201-renal.json"); _exampleObservationJson = TextFileHelper.ReadTextFileFromDisk( $".{Path.DirectorySeparatorChar}Examples{Path.DirectorySeparatorChar}observation-example-bloodpressure.json"); var spPatientName = new SearchParamDefinition { Resource = "Patient", Name = "name", Description = new Markdown(@"A portion of either family or given name of the patient"), Type = SearchParamType.String, Path = new[] { "Patient.name" }, Expression = "Patient.name" }; var spMiddleName = new SearchParamDefinition { Resource = "Patient", Name = "middlename", Type = SearchParamType.String, Path = new[] { "Patient.name.extension.where(url='http://hl7.no/fhir/StructureDefinition/no-basis-middlename')" }, Expression = "Patient.name.extension.where(url='http://hl7.no/fhir/StructureDefinition/no-basis-middlename')" }; var searchParameters = new List <SearchParamDefinition> { spPatientName, spMiddleName }; var resources = new Dictionary <Type, string> { { typeof(Patient), "Patient" }, { typeof(HumanName), "HumanName" } }; // For this test setup we want a limited available types and search parameters. IFhirModel limitedFhirModel = new FhirModel(resources, searchParameters); var limitedElementIndexer = new ElementIndexer(limitedFhirModel, new Mock <ILogger <ElementIndexer> >().Object); _limitedIndexService = new IndexService(limitedFhirModel, indexStoreMock.Object, limitedElementIndexer); // For this test setup we want all available types and search parameters. IFhirModel fullFhirModel = new FhirModel(); var fullElementIndexer = new ElementIndexer(fullFhirModel, new Mock <ILogger <ElementIndexer> >().Object); _fullIndexService = new IndexService(fullFhirModel, indexStoreMock.Object, fullElementIndexer); }
private SearchParameter createSearchParameterFromSearchParamDefinition(SearchParamDefinition def) { var result = new ComparableSearchParameter(); result.Name = def.Name; result.Code = def.Name; //CK: SearchParamDefinition has no Code, but in all current SearchParameter resources, name and code are equal. result.Base = new List <ResourceType?> { GetResourceTypeForResourceName(def.Resource) }; result.Type = def.Type; result.Target = def.Target != null?def.Target.ToList().Cast <ResourceType?>() : new List <ResourceType?>(); result.Description = def.Description; // NOTE: This is a fix to handle an issue in firely-net-sdk // where the expression 'ConceptMap.source as uri' returns // a string instead of uri. // FIXME: On a longer term we should refactor the // SearchParameter in-memory cache so we can more elegantly // swap out a SearchParameter if (def.Resource == ResourceType.ConceptMap.GetLiteral()) { if (def.Name == "source-uri") { result.Expression = "ConceptMap.source.as(uri)"; } else if (def.Name == "target-uri") { result.Expression = "ConceptMap.target.as(uri)"; } else { result.Expression = def.Expression; } } else { result.Expression = def.Expression; } //Strip off the [x], for example in Condition.onset[x]. result.SetPropertyPath(def.Path?.Select(p => p.Replace("[x]", "")).ToArray()); //Watch out: SearchParameter is not very good yet with Composite parameters. //Therefore we include a reference to the original SearchParamDefinition :-) result.SetOriginalDefinition(def); return(result); }
private SearchParameter createSearchParameterFromSearchParamDefinition(SearchParamDefinition def) { var result = new SearchParameter(); result.Name = def.Name; result.Code = def.Name; //CK: SearchParamDefinition has no Code, but in all current SearchParameter resources, name and code are equal. result.Base = def.Resource; result.Type = def.Type; result.Target = def.Target != null?def.Target.Select(t => GetResourceNameForResourceType(t)) : new List <string>(); result.Description = def.Description; //Strip off the [x], for example in Condition.onset[x]. result.SetPropertyPath(def.Path?.Select(p => p.Replace("[x]", "")).ToArray()); //Watch out: SearchParameter is not very good yet with Composite parameters. //Therefore we include a reference to the original SearchParamDefinition :-) result.SetOriginalDefinition(def); return(result); }
public void TestInitialize() { IFhirModel _fhirModel; FhirPropertyIndex _propIndex; ResourceVisitor _resourceVisitor; ElementIndexer _elementIndexer; var _indexStoreMock = new Mock <IIndexStore>(); var spPatientName = new SearchParamDefinition() { Resource = "Patient", Name = "name", Description = @"A portion of either family or given name of the patient", Type = SearchParamType.String, Path = new string[] { "Patient.name", } }; var searchParameters = new List <SearchParamDefinition> { spPatientName }; var resources = new Dictionary <Type, string> { { typeof(Patient), "Patient" }, { typeof(HumanName), "HumanName" } }; var enums = new List <Type>(); //CK: I use real objects: saves me a lot of mocking and provides for a bit of integration testing. _fhirModel = new FhirModel(resources, searchParameters, enums); _propIndex = new FhirPropertyIndex(_fhirModel, new List <Type> { typeof(Patient), typeof(HumanName) }); _resourceVisitor = new ResourceVisitor(_propIndex); _elementIndexer = new ElementIndexer(_fhirModel); //_indexStoreMock.Setup(ixs => ixs.Save(It.IsAny<IndexValue>)) sutLimited = new IndexService(_fhirModel, _propIndex, _resourceVisitor, _elementIndexer, _indexStoreMock.Object); _fhirModel = new FhirModel(); //For this test I want all available types and searchparameters. _propIndex = new FhirPropertyIndex(_fhirModel); _resourceVisitor = new ResourceVisitor(_propIndex); _elementIndexer = new ElementIndexer(_fhirModel); sutFull = new IndexService(_fhirModel, _propIndex, _resourceVisitor, _elementIndexer, _indexStoreMock.Object); }
private SearchParameter createSearchParameterFromSearchParamDefinition(SearchParamDefinition def) { var result = new SearchParameter(); result.Name = def.Name; result.Code = def.Name; //CK: SearchParamDefinition has no Code, but in all current SearchParameter resources, name and code are equal. result.Base = def.Resource; result.Type = def.Type; result.Target = def.Target != null ? def.Target.Select(t => GetResourceNameForResourceType(t)) : new List<string>(); result.Description = def.Description; //Strip off the [x], for example in Condition.onset[x]. result.SetPropertyPath(def.Path?.Select(p => p.Replace("[x]", "")).ToArray()); //Watch out: SearchParameter is not very good yet with Composite parameters. //Therefore we include a reference to the original SearchParamDefinition :-) result.SetOriginalDefinition(def); return result; }