public async Task AddSearchParameterAsync(ITypedElement searchParam)
        {
            try
            {
                _searchParameterDefinitionManager.AddNewSearchParameters(new List <ITypedElement>()
                {
                    searchParam
                });

                var searchParameterWrapper = new SearchParameterWrapper(searchParam);
                await _searchParameterStatusManager.AddSearchParameterStatusAsync(new List <string>() { searchParameterWrapper.Url });
            }
            catch (FhirException fex)
            {
                fex.Issues.Add(new OperationOutcomeIssue(
                                   OperationOutcomeConstants.IssueSeverity.Error,
                                   OperationOutcomeConstants.IssueType.Exception,
                                   Core.Resources.CustomSearchCreateError));

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

                throw customSearchException;
            }
        }
        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;
            }
        }
        public async Task UpdateSearchParameterAsync(ITypedElement searchParam, RawResource previousSearchParam)
        {
            try
            {
                // We need to make sure we have the latest search parameters before trying to update
                // 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.None);

                var searchParameterWrapper = new SearchParameterWrapper(searchParam);
                var searchParameterInfo    = new SearchParameterInfo(searchParameterWrapper);
                (bool Supported, bool IsPartiallySupported)supportedResult = _searchParameterSupportResolver.IsSearchParameterSupported(searchParameterInfo);

                if (!supportedResult.Supported)
                {
                    throw new SearchParameterNotSupportedException(searchParameterInfo.Url);
                }

                // check data store specific support for SearchParameter
                if (!_dataStoreSearchParameterValidator.ValidateSearchParameter(searchParameterInfo, out var errorMessage))
                {
                    throw new SearchParameterNotSupportedException(errorMessage);
                }

                var prevSearchParam    = _modelInfoProvider.ToTypedElement(previousSearchParam);
                var prevSearchParamUrl = prevSearchParam.GetStringScalar("url");

                // As any part of the SearchParameter may have been changed, including the URL
                // the most reliable method of updating the SearchParameter is to delete the previous
                // data and insert the updated version
                await _searchParameterStatusManager.DeleteSearchParameterStatusAsync(prevSearchParamUrl);

                _searchParameterDefinitionManager.DeleteSearchParameter(prevSearchParam);
                _searchParameterDefinitionManager.AddNewSearchParameters(new List <ITypedElement>()
                {
                    searchParam
                });
                await _searchParameterStatusManager.AddSearchParameterStatusAsync(new List <string>() { searchParameterWrapper.Url });
            }
            catch (FhirException fex)
            {
                fex.Issues.Add(new OperationOutcomeIssue(
                                   OperationOutcomeConstants.IssueSeverity.Error,
                                   OperationOutcomeConstants.IssueType.Exception,
                                   Core.Resources.CustomSearchUpdateError));

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

                throw customSearchException;
            }
        }
        public async Task AddSearchParameterAsync(ITypedElement searchParam, CancellationToken cancellationToken)
        {
            try
            {
                // verify the parameter is supported before continuing
                var searchParameterWrapper = new SearchParameterWrapper(searchParam);
                var searchParameterInfo    = new SearchParameterInfo(searchParameterWrapper);

                if (searchParameterInfo.Component?.Any() == true)
                {
                    foreach (SearchParameterComponentInfo c in searchParameterInfo.Component)
                    {
                        c.ResolvedSearchParameter = _searchParameterDefinitionManager.GetSearchParameter(c.DefinitionUrl.OriginalString);
                    }
                }

                (bool Supported, bool IsPartiallySupported)supportedResult = _searchParameterSupportResolver.IsSearchParameterSupported(searchParameterInfo);

                if (!supportedResult.Supported)
                {
                    throw new SearchParameterNotSupportedException(searchParameterInfo.Url);
                }

                // check data store specific support for SearchParameter
                if (!_dataStoreSearchParameterValidator.ValidateSearchParameter(searchParameterInfo, out var errorMessage))
                {
                    throw new SearchParameterNotSupportedException(errorMessage);
                }

                _logger.LogTrace("Adding the search parameter '{url}'", searchParameterWrapper.Url);
                _searchParameterDefinitionManager.AddNewSearchParameters(new List <ITypedElement> {
                    searchParam
                });

                await _searchParameterStatusManager.AddSearchParameterStatusAsync(new List <string> {
                    searchParameterWrapper.Url
                }, cancellationToken);
            }
            catch (FhirException fex)
            {
                fex.Issues.Add(new OperationOutcomeIssue(
                                   OperationOutcomeConstants.IssueSeverity.Error,
                                   OperationOutcomeConstants.IssueType.Exception,
                                   Core.Resources.CustomSearchCreateError));

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

                throw customSearchException;
            }
        }
        public async Task AddSearchParameterAsync(ITypedElement searchParam)
        {
            try
            {
                // verify the parameter is supported before continuing
                var searchParameterWrapper = new SearchParameterWrapper(searchParam);
                var searchParameterInfo    = new SearchParameterInfo(searchParameterWrapper);
                (bool Supported, bool IsPartiallySupported)supportedResult = _searchParameterSupportResolver.IsSearchParameterSupported(searchParameterInfo);

                if (!supportedResult.Supported)
                {
                    throw new SearchParameterNotSupportedException(searchParameterInfo.Url);
                }

                // check data store specific support for SearchParameter
                if (!_dataStoreSearchParameterValidator.ValidateSearchParameter(searchParameterInfo, out var errorMessage))
                {
                    throw new SearchParameterNotSupportedException(errorMessage);
                }

                _searchParameterDefinitionManager.AddNewSearchParameters(new List <ITypedElement>()
                {
                    searchParam
                });

                var searchParameterUrl = searchParam.GetStringScalar("url");
                await _searchParameterStatusManager.AddSearchParameterStatusAsync(new List <string>() { searchParameterWrapper.Url });
            }
            catch (FhirException fex)
            {
                fex.Issues.Add(new OperationOutcomeIssue(
                                   OperationOutcomeConstants.IssueSeverity.Error,
                                   OperationOutcomeConstants.IssueType.Exception,
                                   Core.Resources.CustomSearchCreateError));

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

                throw customSearchException;
            }
        }
        public async Task UpdateSearchParameterAsync(ITypedElement searchParam, RawResource prevSearchParamRaw)
        {
            try
            {
                var searchParameterWrapper = new SearchParameterWrapper(searchParam);
                var searchParameterInfo    = new SearchParameterInfo(searchParameterWrapper);
                (bool Supported, bool IsPartiallySupported)supportedResult = _searchParameterSupportResolver.IsSearchParameterSupported(searchParameterInfo);

                if (!supportedResult.Supported)
                {
                    throw new SearchParameterNotSupportedException(searchParameterInfo.Url);
                }

                var prevSearchParam    = _modelInfoProvider.ToTypedElement(prevSearchParamRaw);
                var prevSearchParamUrl = prevSearchParam.GetStringScalar("url");

                // As any part of the SearchParameter may have been changed, including the URL
                // the most reliable method of updating the SearchParameter is to delete the previous
                // data and insert the updated version
                await _searchParameterStatusManager.DeleteSearchParameterStatusAsync(prevSearchParamUrl);

                _searchParameterDefinitionManager.DeleteSearchParameter(prevSearchParam);
                _searchParameterDefinitionManager.AddNewSearchParameters(new List <ITypedElement>()
                {
                    searchParam
                });
                await _searchParameterStatusManager.AddSearchParameterStatusAsync(new List <string>() { searchParameterWrapper.Url });
            }
            catch (FhirException fex)
            {
                fex.Issues.Add(new OperationOutcomeIssue(
                                   OperationOutcomeConstants.IssueSeverity.Error,
                                   OperationOutcomeConstants.IssueType.Exception,
                                   Core.Resources.CustomSearchUpdateError));

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

                throw customSearchException;
            }
        }
Example #7
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;
            }
        }