private IEnumerable <SearchParameterInfo> BuildSearchParameterDefinition( ILookup <string, SearchParameterInfo> searchParametersLookup, string resourceType) { if (_resourceTypeDictionary.TryGetValue(resourceType, out IDictionary <string, SearchParameterInfo> cachedSearchParameters)) { return(cachedSearchParameters.Values); } IEnumerable <SearchParameterInfo> results = Enumerable.Empty <SearchParameterInfo>(); Type type = _modelInfoProvider.GetTypeForFhirType(resourceType); Debug.Assert(type != null, $"The type for {resourceType} should not be null."); string baseType = _modelInfoProvider.GetFhirTypeNameForType(type.BaseType); if (baseType != null && Enum.TryParse(baseType, out ResourceType baseResourceType)) { results = BuildSearchParameterDefinition(searchParametersLookup, baseType); } Debug.Assert(results != null, "The results should not be null."); results = results.Concat(searchParametersLookup[resourceType]); Dictionary <string, SearchParameterInfo> searchParameterDictionary = results.ToDictionary( r => r.Name, r => r, StringComparer.Ordinal); _resourceTypeDictionary.Add(resourceType, searchParameterDictionary); return(searchParameterDictionary.Values); }
public static MockModelInfoProviderBuilder Create(FhirSpecification version) { IModelInfoProvider provider = Substitute.For <IModelInfoProvider>(); provider.Version.Returns(version); // Adds normative types by default var seenTypes = new HashSet <string> { "Binary", "Bundle", "CapabilityStatement", "CodeSystem", "Observation", "OperationOutcome", "Patient", "StructureDefinition", "ValueSet", }; provider.GetResourceTypeNames().Returns(_ => seenTypes.Where(x => !string.IsNullOrEmpty(x)).ToArray()); provider.IsKnownResource(Arg.Any <string>()).Returns(x => provider.GetResourceTypeNames().Contains(x[0])); // Simulate inherited behavior // Some code depends on "InheritedResource".BaseType // This adds the ability to resolve "Resource" as the base type provider.GetTypeForFhirType(Arg.Any <string>()).Returns(p => p.ArgAt <string>(0) == "Resource" ? typeof(ResourceObj) : typeof(InheritedResourceObj)); provider.GetFhirTypeNameForType(Arg.Any <Type>()).Returns(p => p.ArgAt <Type>(0) == typeof(ResourceObj) ? "Resource" : null); // IStructureDefinitionSummaryProvider allows the execution of FHIRPath queries provider.ToTypedElement(Arg.Any <ISourceNode>()) .Returns(p => p.ArgAt <ISourceNode>(0).ToTypedElement(new MockStructureDefinitionSummaryProvider(p.ArgAt <ISourceNode>(0), seenTypes))); return(new MockModelInfoProviderBuilder(provider, seenTypes)); }
private static HashSet <SearchParameterInfo> BuildSearchParameterDefinition( ILookup <string, SearchParameterInfo> searchParametersLookup, string resourceType, ConcurrentDictionary <string, ConcurrentDictionary <string, SearchParameterInfo> > resourceTypeDictionary, IModelInfoProvider modelInfoProvider) { HashSet <SearchParameterInfo> results; if (resourceTypeDictionary.TryGetValue(resourceType, out ConcurrentDictionary <string, SearchParameterInfo> cachedSearchParameters)) { results = new HashSet <SearchParameterInfo>(cachedSearchParameters.Values); } else { results = new HashSet <SearchParameterInfo>(); } Type type = modelInfoProvider.GetTypeForFhirType(resourceType); Debug.Assert(type != null, $"The type for {resourceType} should not be null."); string baseType = modelInfoProvider.GetFhirTypeNameForType(type.BaseType); if (baseType != null) { var baseResults = BuildSearchParameterDefinition(searchParametersLookup, baseType, resourceTypeDictionary, modelInfoProvider); results.UnionWith(baseResults); } Debug.Assert(results != null, "The results should not be null."); results.UnionWith(searchParametersLookup[resourceType]); var searchParameterDictionary = new ConcurrentDictionary <string, SearchParameterInfo>( results.ToDictionary( r => r.Code, r => r, StringComparer.Ordinal)); if (!resourceTypeDictionary.TryAdd(resourceType, searchParameterDictionary)) { resourceTypeDictionary[resourceType] = searchParameterDictionary; } return(results); }
public static Type GetTypeForFhirType(string resourceType) { EnsureProvider(); return(_modelInfoProvider.GetTypeForFhirType(resourceType)); }