internal static BundleWrapper ReadEmbeddedSearchParameters( string embeddedResourceName, IModelInfoProvider modelInfoProvider, string embeddedResourceNamespace = null, Assembly assembly = null) { using Stream stream = modelInfoProvider.OpenVersionedFileStream(embeddedResourceName, embeddedResourceNamespace, assembly); using TextReader reader = new StreamReader(stream); using JsonReader jsonReader = new JsonTextReader(reader); try { ISourceNode sourceNode = FhirJsonNode.Read(jsonReader); return(new BundleWrapper(modelInfoProvider.ToTypedElement(sourceNode))); } catch (FormatException ex) { var issue = new OperationOutcomeIssue( OperationOutcomeConstants.IssueSeverity.Fatal, OperationOutcomeConstants.IssueType.Invalid, ex.Message); throw new InvalidDefinitionException( Core.Resources.SearchParameterDefinitionContainsInvalidEntry, new OperationOutcomeIssue[] { issue }); } }
public Task StartAsync(CancellationToken cancellationToken) { using Stream file = _modelInfoProvider.OpenVersionedFileStream("resourcepath-codesystem-mappings.json"); using var reader = new StreamReader(file); _dictionary = JsonConvert.DeserializeObject <Dictionary <string, string> >(reader.ReadToEnd()); return(Task.CompletedTask); }
public void Start() { // The json file is a bundle compiled from the compartment definitions currently defined by HL7. // The definitions are available at https://www.hl7.org/fhir/compartmentdefinition.html. using Stream stream = _modelInfoProvider.OpenVersionedFileStream("compartment.json"); using TextReader reader = new StreamReader(stream); using JsonReader jsonReader = new JsonTextReader(reader); var bundle = new BundleWrapper(FhirJsonNode.Read(jsonReader).ToTypedElement(_modelInfoProvider.StructureDefinitionSummaryProvider)); Build(bundle); }
public static ICapabilityStatementBuilder Create(IModelInfoProvider modelInfoProvider, ISearchParameterDefinitionManager searchParameterDefinitionManager) { EnsureArg.IsNotNull(modelInfoProvider, nameof(modelInfoProvider)); EnsureArg.IsNotNull(searchParameterDefinitionManager, nameof(searchParameterDefinitionManager)); using Stream resourceStream = modelInfoProvider.OpenVersionedFileStream("BaseCapabilities.json"); using var reader = new StreamReader(resourceStream); var statement = JsonConvert.DeserializeObject <ListedCapabilityStatement>(reader.ReadToEnd()); return(new CapabilityStatementBuilder(statement, modelInfoProvider, searchParameterDefinitionManager)); }
public static ICapabilityStatementBuilder Create(IModelInfoProvider modelInfoProvider, ISearchParameterDefinitionManager searchParameterDefinitionManager, IKnowSupportedProfiles supportedProfiles) { EnsureArg.IsNotNull(modelInfoProvider, nameof(modelInfoProvider)); EnsureArg.IsNotNull(searchParameterDefinitionManager, nameof(searchParameterDefinitionManager)); using Stream resourceStream = modelInfoProvider.OpenVersionedFileStream("BaseCapabilities.json"); using var reader = new StreamReader(resourceStream); var statement = JsonConvert.DeserializeObject <ListedCapabilityStatement>(reader.ReadToEnd()); statement.Date = File.GetCreationTime(Assembly.GetExecutingAssembly().Location).ToUniversalTime().ToString("O"); return(new CapabilityStatementBuilder(statement, modelInfoProvider, searchParameterDefinitionManager, supportedProfiles)); }
internal static BundleWrapper ReadEmbeddedSearchParameters( string embeddedResourceName, IModelInfoProvider modelInfoProvider, string embeddedResourceNamespace = null, Assembly assembly = null) { using Stream stream = modelInfoProvider.OpenVersionedFileStream(embeddedResourceName, embeddedResourceNamespace, assembly); using TextReader reader = new StreamReader(stream); var data = reader.ReadToEnd(); var rawResource = new RawResource(data, FhirResourceFormat.Json, true); return(new BundleWrapper(modelInfoProvider.ToTypedElement(rawResource))); }
public Task <IReadOnlyCollection <ResourceSearchParameterStatus> > GetSearchParameterStatuses() { if (_statusResults == null) { using Stream stream = _modelInfoProvider.OpenVersionedFileStream("unsupported-search-parameters.json"); using TextReader reader = new StreamReader(stream); UnsupportedSearchParameters unsupportedParams = JsonConvert.DeserializeObject <UnsupportedSearchParameters>(reader.ReadToEnd()); // Loads unsupported parameters var support = unsupportedParams.Unsupported .Select(x => new ResourceSearchParameterStatus { Uri = x, Status = SearchParameterStatus.Disabled, LastUpdated = Clock.UtcNow, }) .Concat(unsupportedParams.PartialSupport .Select(x => new ResourceSearchParameterStatus { Uri = x, Status = SearchParameterStatus.Enabled, IsPartiallySupported = true, LastUpdated = Clock.UtcNow, })) .ToDictionary(x => x.Uri); // Merge with supported list _statusResults = _searchParameterDefinitionManager.AllSearchParameters .Where(x => !support.ContainsKey(x.Url)) .Select(x => new ResourceSearchParameterStatus { Uri = x.Url, Status = SearchParameterStatus.Enabled, LastUpdated = Clock.UtcNow, }) .Concat(support.Values) .ToArray(); } return(Task.FromResult <IReadOnlyCollection <ResourceSearchParameterStatus> >(_statusResults)); }
public static ICapabilityStatementBuilder Create(IModelInfoProvider modelInfoProvider, ISearchParameterDefinitionManager searchParameterDefinitionManager, IOptions <CoreFeatureConfiguration> configuration, IKnowSupportedProfiles supportedProfiles) { EnsureArg.IsNotNull(modelInfoProvider, nameof(modelInfoProvider)); EnsureArg.IsNotNull(searchParameterDefinitionManager, nameof(searchParameterDefinitionManager)); using Stream resourceStream = modelInfoProvider.OpenVersionedFileStream("BaseCapabilities.json"); using var reader = new StreamReader(resourceStream); var statement = JsonConvert.DeserializeObject <ListedCapabilityStatement>(reader.ReadToEnd()); FileVersionInfo version = ProductVersionInfo.Version; var versionString = $"{version.FileMajorPart}.{version.FileMinorPart}.{version.FileBuildPart}"; statement.Name = string.Format(Resources.CapabilityStatementNameFormat, statement.Publisher, configuration.Value.SoftwareName, versionString); statement.Software = new SoftwareComponent { Name = configuration.Value.SoftwareName, Version = versionString, }; statement.FhirVersion = modelInfoProvider.SupportedVersion.ToString(); statement.Date = ProductVersionInfo.CreationTime.ToString("O"); return(new CapabilityStatementBuilder(statement, modelInfoProvider, searchParameterDefinitionManager, configuration, supportedProfiles)); }
private List <(string ResourceType, SearchParameterInfo SearchParameter)> ValidateAndGetFlattenedList() { var issues = new List <OperationOutcomeIssue>(); BundleWrapper bundle = null; using (Stream stream = _modelInfoProvider.OpenVersionedFileStream(_embeddedResourceName, _embeddedResourceNamespace, _assembly)) { using TextReader reader = new StreamReader(stream); using JsonReader jsonReader = new JsonTextReader(reader); try { bundle = new BundleWrapper(FhirJsonNode.Read(jsonReader).ToTypedElement(_modelInfoProvider.StructureDefinitionSummaryProvider)); } catch (FormatException ex) { AddIssue(ex.Message); } } EnsureNoIssues(); IReadOnlyList <BundleEntryWrapper> entries = bundle.Entries; // Do the first pass to make sure all resources are SearchParameter. for (int entryIndex = 0; entryIndex < entries.Count; entryIndex++) { // Make sure resources are not null and they are SearchParameter. BundleEntryWrapper entry = entries[entryIndex]; ITypedElement searchParameterElement = entry.Resource; if (searchParameterElement == null || !string.Equals(searchParameterElement.InstanceType, KnownResourceTypes.SearchParameter, StringComparison.OrdinalIgnoreCase)) { AddIssue(Core.Resources.SearchParameterDefinitionInvalidResource, entryIndex); continue; } var searchParameter = new SearchParameterWrapper(searchParameterElement); try { SearchParameterInfo searchParameterInfo = CreateSearchParameterInfo(searchParameter); _uriDictionary.Add(new Uri(searchParameter.Url), searchParameterInfo); } catch (FormatException) { AddIssue(Core.Resources.SearchParameterDefinitionInvalidDefinitionUri, entryIndex); continue; } catch (ArgumentException) { AddIssue(Core.Resources.SearchParameterDefinitionDuplicatedEntry, searchParameter.Url); continue; } } EnsureNoIssues(); var validatedSearchParameters = new List <(string ResourceType, SearchParameterInfo SearchParameter)> { // _type is currently missing from the search params definition bundle, so we inject it in here. (KnownResourceTypes.Resource, new SearchParameterInfo(SearchParameterNames.ResourceType, SearchParamType.Token, SearchParameterNames.ResourceTypeUri, null, "Resource.type().name", null)), }; // Do the second pass to make sure the definition is valid. for (int entryIndex = 0; entryIndex < entries.Count; entryIndex++) { BundleEntryWrapper entry = entries[entryIndex]; ITypedElement searchParameterElement = entry.Resource; var searchParameter = new SearchParameterWrapper(searchParameterElement); // If this is a composite search parameter, then make sure components are defined. if (string.Equals(searchParameter.Type, SearchParamType.Composite.GetLiteral(), StringComparison.OrdinalIgnoreCase)) { var composites = searchParameter.Component; if (composites.Count == 0) { AddIssue(Core.Resources.SearchParameterDefinitionInvalidComponent, searchParameter.Url); continue; } for (int componentIndex = 0; componentIndex < composites.Count; componentIndex++) { ITypedElement component = composites[componentIndex]; var definitionUrl = GetComponentDefinition(component); if (definitionUrl == null || !_uriDictionary.TryGetValue(new Uri(definitionUrl), out SearchParameterInfo componentSearchParameter)) { AddIssue( Core.Resources.SearchParameterDefinitionInvalidComponentReference, searchParameter.Url, componentIndex); continue; } if (componentSearchParameter.Type == SearchParamType.Composite) { AddIssue( Core.Resources.SearchParameterDefinitionComponentReferenceCannotBeComposite, searchParameter.Url, componentIndex); continue; } if (string.IsNullOrWhiteSpace(component.Scalar("expression")?.ToString())) { AddIssue( Core.Resources.SearchParameterDefinitionInvalidComponentExpression, searchParameter.Url, componentIndex); continue; } } } // Make sure the base is defined. var bases = searchParameter.Base; if (bases.Count == 0) { AddIssue(Core.Resources.SearchParameterDefinitionBaseNotDefined, searchParameter.Url); continue; } for (int baseElementIndex = 0; baseElementIndex < bases.Count; baseElementIndex++) { var code = bases[baseElementIndex]; string baseResourceType = code; // Make sure the expression is not empty unless they are known to have empty expression. // These are special search parameters that searches across all properties and needs to be handled specially. if (ShouldExcludeEntry(baseResourceType, searchParameter.Name) || (_modelInfoProvider.Version == FhirSpecification.R5 && _knownBrokenR5.Contains(new Uri(searchParameter.Url)))) { continue; } else { if (string.IsNullOrWhiteSpace(searchParameter.Expression)) { AddIssue(Core.Resources.SearchParameterDefinitionInvalidExpression, searchParameter.Url); continue; } } validatedSearchParameters.Add((baseResourceType, CreateSearchParameterInfo(searchParameter))); } } EnsureNoIssues(); return(validatedSearchParameters); void AddIssue(string format, params object[] args) { issues.Add(new OperationOutcomeIssue( OperationOutcomeConstants.IssueSeverity.Fatal, OperationOutcomeConstants.IssueType.Invalid, string.Format(CultureInfo.InvariantCulture, format, args))); } void EnsureNoIssues() { if (issues.Count != 0) { throw new InvalidDefinitionException( Core.Resources.SearchParameterDefinitionContainsInvalidEntry, issues.ToArray()); } } }
public void Start() { using Stream file = _modelInfoProvider.OpenVersionedFileStream("resourcepath-codesystem-mappings.json"); using var reader = new StreamReader(file); _dictionary = JsonConvert.DeserializeObject <Dictionary <string, string> >(reader.ReadToEnd()); }