public async Task DeleteSearchParameterAsync(RawResource searchParamResource)
        {
            try
            {
                var searchParam        = _modelInfoProvider.ToTypedElement(searchParamResource);
                var searchParameterUrl = searchParam.GetStringScalar("url");

                // First we delete the status metadata from the data store as this fuction depends on the
                // the in memory definition manager.  Once complete we remove the SearchParameter from
                // the definition manager.
                await _searchParameterStatusManager.DeleteSearchParameterStatusAsync(searchParameterUrl);

                _searchParameterDefinitionManager.DeleteSearchParameter(searchParam);
            }
            catch (FhirException fex)
            {
                fex.Issues.Add(new OperationOutcomeIssue(
                                   OperationOutcomeConstants.IssueSeverity.Error,
                                   OperationOutcomeConstants.IssueType.Exception,
                                   Core.Resources.CustomSearchDeleteError));

                throw;
            }
            catch (Exception ex)
            {
                var customSearchException = new ConfigureCustomSearchException(Core.Resources.CustomSearchDeleteError);
                customSearchException.Issues.Add(new OperationOutcomeIssue(
                                                     OperationOutcomeConstants.IssueSeverity.Error,
                                                     OperationOutcomeConstants.IssueType.Exception,
                                                     ex.Message));

                throw customSearchException;
            }
        }
Example #2
0
        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 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));
        }
Example #4
0
        public async Task DeleteSearchParameterAsync(RawResource searchParamResource, CancellationToken cancellationToken)
        {
            try
            {
                // We need to make sure we have the latest search parameters before trying to delete
                // existing search parameter. This is to avoid trying to update a search parameter that
                // was recently added and that hasn't propogated to all fhir-server instances.
                await GetAndApplySearchParameterUpdates(cancellationToken);

                var searchParam        = _modelInfoProvider.ToTypedElement(searchParamResource);
                var searchParameterUrl = searchParam.GetStringScalar("url");

                // First we delete the status metadata from the data store as this fuction depends on the
                // the in memory definition manager.  Once complete we remove the SearchParameter from
                // the definition manager.
                _logger.LogTrace("Deleting the search parameter '{url}'", searchParameterUrl);
                await _searchParameterStatusManager.DeleteSearchParameterStatusAsync(searchParameterUrl, cancellationToken);

                _searchParameterDefinitionManager.DeleteSearchParameter(searchParam);
            }
            catch (FhirException fex)
            {
                fex.Issues.Add(new OperationOutcomeIssue(
                                   OperationOutcomeConstants.IssueSeverity.Error,
                                   OperationOutcomeConstants.IssueType.Exception,
                                   Core.Resources.CustomSearchDeleteError));

                throw;
            }
            catch (Exception ex)
            {
                var customSearchException = new ConfigureCustomSearchException(Core.Resources.CustomSearchDeleteError);
                customSearchException.Issues.Add(new OperationOutcomeIssue(
                                                     OperationOutcomeConstants.IssueSeverity.Error,
                                                     OperationOutcomeConstants.IssueType.Exception,
                                                     ex.Message));

                throw customSearchException;
            }
        }
        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)));
        }
        /// <summary>
        /// Converts the RawResource to an ITypedElement
        /// </summary>
        /// <param name="rawResource">The RawResource to convert</param>
        /// <param name="modelInfoProvider">The IModelInfoProvider to use when converting the RawResource</param>
        /// <returns>An ITypedElement of the RawResource</returns>
        public static ITypedElement ToITypedElement(this RawResource rawResource, IModelInfoProvider modelInfoProvider)
        {
            EnsureArg.IsNotNull(rawResource, nameof(rawResource));
            EnsureArg.IsNotNull(modelInfoProvider, nameof(modelInfoProvider));

            using TextReader reader     = new StringReader(rawResource.Data);
            using JsonReader jsonReader = new JsonTextReader(reader);
            try
            {
                ISourceNode sourceNode = FhirJsonNode.Read(jsonReader);
                return(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 });
            }
        }