public async Task <string> SearchAsync( BaseFhirApiOptions fhirApiOptions, CancellationToken cancellationToken = default) { if (cancellationToken.IsCancellationRequested) { throw new OperationCanceledException(); } Uri searchUri; try { searchUri = CreateSearchUri(fhirApiOptions); } catch (Exception ex) { _logger.LogError("Create search Uri failed, Reason: '{reason}'", ex); throw new FhirSearchException("Create search Uri failed", ex); } string accessToken = null; if (fhirApiOptions.IsAccessTokenRequired) { try { if (_dataSource.Authentication == AuthenticationType.ManagedIdentity) { // Currently we support accessing FHIR server endpoints with Managed Identity. // Obtaining access token against a resource uri only works with Azure API for FHIR now. // To do: add configuration for OSS FHIR server endpoints. // The thread-safe AzureServiceTokenProvider class caches the token in memory and retrieves it from Azure AD just before expiration. // https://docs.microsoft.com/en-us/dotnet/api/overview/azure/service-to-service-authentication#using-the-library accessToken = await _accessTokenProvider.GetAccessTokenAsync(_dataSource.FhirServerUrl, cancellationToken); } } catch (Exception ex) { _logger.LogError("Get fhir server access token failed, Reason: '{reason}'", ex); throw new FhirSearchException("Get fhir server access token failed", ex); } } return(await GetResponseFromHttpRequestAsync(searchUri, accessToken, cancellationToken)); }
private Uri CreateSearchUri(BaseFhirApiOptions fhirApiOptions) { var serverUrl = _dataSource.FhirServerUrl; var baseUri = new Uri(serverUrl); var uri = new Uri(baseUri, fhirApiOptions.RelativeUri()); // the query parameters is null for metadata if (fhirApiOptions.QueryParameters == null) { return(uri); } uri = uri.AddQueryString(fhirApiOptions.QueryParameters); // add shared parameters _count & sort var queryParameters = new List <KeyValuePair <string, string> > { new (FhirApiConstants.PageCountKey, FhirApiConstants.PageCount.ToString()), new (FhirApiConstants.SortKey, FhirApiConstants.LastUpdatedKey), };
public string Search(BaseFhirApiOptions fhirApiOptions) { if (fhirApiOptions.IsAccessTokenRequired && _dataSource.Authentication == AuthenticationType.ManagedIdentity) { _logger.LogError("Synchronous search doesn't support AccessToken, please use Asynchronous method SearchAsync() instead."); throw new FhirSearchException( "Synchronous search doesn't support AccessToken, please use Asynchronous method SearchAsync() instead."); } Uri searchUri; try { searchUri = CreateSearchUri(fhirApiOptions); } catch (Exception ex) { _logger.LogError("Create search Uri failed, Reason: '{reason}'", ex); throw new FhirSearchException("Create search Uri failed", ex); } return(GetResponseFromHttpRequest(searchUri)); }