コード例 #1
0
        public static async System.Threading.Tasks.Task EnsurePatientDeviceAsync(this IFhirClient client, string userId)
        {
            var patient = await client.EnsureResourceByIdentifierAsync <Patient>(
                userId,
                FhirConstants.MyHealthSystem,
                (patient, identifier) =>
            {
                patient.Id         = userId;
                patient.Identifier = new List <Identifier> {
                    identifier
                };
            });

            await client.EnsureResourceByIdentifierAsync <Device>(
                userId,
                FhirConstants.MyHealthSystem,
                (device, identifier) =>
            {
                device.Id         = userId;
                device.Identifier = new List <Identifier> {
                    identifier
                };
                device.Patient = patient.ToReference();
            });
        }
コード例 #2
0
        public static Parameters ConceptLookup(this IFhirClient client,
                                               Code code     = null, FhirUri system    = null, FhirString version = null,
                                               Coding coding = null, FhirDateTime date = null)

        {
            return(ConceptLookupAsync(client, code, system, version, coding, date).WaitResult());
        }
コード例 #3
0
        public async static Task <ValidateCodeResult> ValidateCodeAsync(this IFhirClient client,
                                                                        FhirUri identifier    = null, FhirUri context                 = null, ValueSet valueSet  = null, Code code = null,
                                                                        FhirUri system        = null, FhirString version              = null, FhirString display = null,
                                                                        Coding coding         = null, CodeableConcept codeableConcept = null, FhirDateTime date  = null,
                                                                        FhirBoolean @abstract = null)
        {
            var par = new Parameters()
                      .Add(nameof(identifier), identifier)
                      .Add(nameof(context), context)
                      .Add(nameof(valueSet), valueSet)
                      .Add(nameof(code), code)
                      .Add(nameof(system), system)
                      .Add(nameof(version), version)
                      .Add(nameof(display), display)
                      .Add(nameof(coding), coding)
                      .Add(nameof(codeableConcept), codeableConcept)
                      .Add(nameof(date), date)
                      .Add(nameof(@abstract), @abstract);

            var result = await client.TypeOperationAsync <ValueSet>(RestOperation.VALIDATE_CODE, par).ConfigureAwait(false);

            if (result != null)
            {
                return(ValidateCodeResult.FromParameters(result.OperationResult <Parameters>()));
            }
            else
            {
                return(null);
            }
        }
コード例 #4
0
 public R4FhirImportService(IResourceIdentityService resourceIdentityService, IFhirClient fhirClient, IFhirTemplateProcessor <ILookupTemplate <IFhirTemplate>, Model.Observation> fhirTemplateProcessor, IMemoryCache observationCache)
 {
     _fhirTemplateProcessor = EnsureArg.IsNotNull(fhirTemplateProcessor, nameof(fhirTemplateProcessor));
     _client = EnsureArg.IsNotNull(fhirClient, nameof(fhirClient));
     _resourceIdentityService = EnsureArg.IsNotNull(resourceIdentityService, nameof(resourceIdentityService));
     _observationCache        = EnsureArg.IsNotNull(observationCache, nameof(observationCache));
 }
コード例 #5
0
        /// <summary>
        /// Sets the authenticated token on the <see cref="IFhirClient"/> via OpenId client credentials.
        /// </summary>
        /// <param name="fhirClient">The <see cref="IFhirClient"/> to authenticate.</param>
        /// <param name="clientId">The clientId of the application.</param>
        /// <param name="clientSecret">The clientSecret of the application.</param>
        /// <param name="resource">The resource to authenticate with.</param>
        /// <param name="scope">The scope to authenticate with.</param>
        /// <param name="cancellationToken">The <see cref="CancellationToken"/> for the request.</param>
        /// <returns>A <see cref="Task"/> representing the successful setting of the token.</returns>
        public static async Task AuthenticateOpenIdClientCredentials(
            this IFhirClient fhirClient,
            string clientId,
            string clientSecret,
            string resource,
            string scope,
            CancellationToken cancellationToken)
        {
            EnsureArg.IsNotNull(fhirClient, nameof(fhirClient));
            EnsureArg.IsNotNullOrWhiteSpace(clientId, nameof(clientId));
            EnsureArg.IsNotNullOrWhiteSpace(clientSecret, nameof(clientSecret));
            EnsureArg.IsNotNullOrWhiteSpace(resource, nameof(resource));
            EnsureArg.IsNotNullOrWhiteSpace(scope, nameof(scope));

            var formData = new List <KeyValuePair <string, string> >
            {
                new KeyValuePair <string, string>(OpenIdConnectParameterNames.ClientId, clientId),
                new KeyValuePair <string, string>(OpenIdConnectParameterNames.ClientSecret, clientSecret),
                new KeyValuePair <string, string>(OpenIdConnectParameterNames.GrantType, OpenIdConnectGrantTypes.ClientCredentials),
                new KeyValuePair <string, string>(OpenIdConnectParameterNames.Scope, scope),
                new KeyValuePair <string, string>(OpenIdConnectParameterNames.Resource, resource),
            };

            await ObtainTokenAndSetOnClient(fhirClient, formData, cancellationToken);
        }
コード例 #6
0
        private static async Task ObtainTokenAndSetOnClient(IFhirClient fhirClient, List <KeyValuePair <string, string> > formData, CancellationToken cancellationToken)
        {
            using var formContent = new FormUrlEncodedContent(formData);
            using HttpResponseMessage tokenResponse = await fhirClient.HttpClient.PostAsync(fhirClient.TokenUri, formContent, cancellationToken);

            var openIdConnectMessage = new OpenIdConnectMessage(await tokenResponse.Content.ReadAsStringAsync());

            fhirClient.SetBearerToken(openIdConnectMessage.AccessToken);
        }
コード例 #7
0
 public static ValidateCodeResult ValidateCode(this IFhirClient client,
                                               FhirUri identifier    = null, FhirUri context                 = null, ValueSet valueSet  = null, Code code = null,
                                               FhirUri system        = null, FhirString version              = null, FhirString display = null,
                                               Coding coding         = null, CodeableConcept codeableConcept = null, FhirDateTime date  = null,
                                               FhirBoolean @abstract = null)
 {
     return(ValidateCodeAsync(client, identifier, context, valueSet, code, system, version, display,
                              coding, codeableConcept, date, @abstract).WaitResult());
 }
コード例 #8
0
        /// <summary>
        /// Sets the authenticated token on the <see cref="IFhirClient"/> to the supplied resource via Managed Identity.
        /// </summary>
        /// <param name="fhirClient">The <see cref="IFhirClient"/> to authenticate.</param>
        /// <param name="resource">The resource to obtain a token to.</param>
        /// <param name="tenantId">The optional tenantId to use when requesting a token.</param>
        /// <param name="cancellationToken">The <see cref="CancellationToken"/> for the request.</param>
        /// <returns>A <see cref="Task"/> representing the successful setting of the token.</returns>
        public static async Task AuthenticateWithManagedIdentity(this IFhirClient fhirClient, string resource, string tenantId = null, CancellationToken cancellationToken = default)
        {
            EnsureArg.IsNotNull(fhirClient, nameof(fhirClient));
            EnsureArg.IsNotNullOrWhiteSpace(resource, nameof(resource));

            var    azureServiceTokenProvider = new AzureServiceTokenProvider();
            string accessToken = await azureServiceTokenProvider.GetAccessTokenAsync(resource, tenantId, cancellationToken);

            fhirClient.SetBearerToken(accessToken);
        }
コード例 #9
0
        public virtual async Task <TResource> GetResourceByIdentityAsync <TResource>(IFhirClient client, string value, string system)
            where TResource : Model.Resource, new()
        {
            EnsureArg.IsNotNull(client, nameof(client));
            EnsureArg.IsNotNullOrWhiteSpace(value, nameof(value));

            var identifier = BuildIdentifier(value, system);

            return(await GetResourceByIdentityAsync <TResource>(client, identifier).ConfigureAwait(false));
        }
コード例 #10
0
 public AccountDeletionJob(
     ILoggerFactory log,
     IExceptionFilter exceptionFilter,
     IFhirClient fhirClient,
     IConsentStore consentStore,
     IVendorClient vendorClient)
 {
     this.log             = log.CreateLogger <AccountDeletionJob>();
     this.exceptionFilter = exceptionFilter;
     this.fhirClient      = fhirClient;
     this.consentStore    = consentStore;
     this.vendorClient    = vendorClient;
 }
コード例 #11
0
 public ObservationsEndpoint(
     ILoggerFactory log,
     IExceptionFilter exceptionFilter,
     IAuthentication auth,
     IConsentStore consentStore,
     IFhirClient fhirClient)
 {
     this.log             = log.CreateLogger <ObservationsEndpoint>();
     this.exceptionFilter = exceptionFilter;
     this.auth            = auth;
     this.consentStore    = consentStore;
     this.fhirClient      = fhirClient;
 }
コード例 #12
0
 public FitbitProviderUpdateEventHandler(
     IFitbitClient fitbitClient,
     IFitbitTokenService fitbitTokenService,
     IIoMTDataPublisher iomtDataPublisher,
     IFhirClient fhirClient,
     ILogger <FitbitProviderUpdateEventHandler> logger)
 {
     _fitbitClient       = fitbitClient ?? throw new ArgumentNullException(nameof(fitbitClient));
     _fitbitTokenService = fitbitTokenService ?? throw new ArgumentNullException(nameof(fitbitTokenService));
     _iomtDataPublisher  = iomtDataPublisher ?? throw new ArgumentNullException(nameof(iomtDataPublisher));
     _fhirClient         = fhirClient ?? throw new ArgumentNullException(nameof(fhirClient));
     _logger             = logger ?? throw new ArgumentNullException(nameof(logger));
 }
コード例 #13
0
        public static async Task <Parameters> ConceptLookupAsync(this IFhirClient client,
                                                                 Code code     = null, FhirUri system    = null, FhirString version = null,
                                                                 Coding coding = null, FhirDateTime date = null)
        {
            var par = new Parameters()
                      .Add(nameof(code), code)
                      .Add(nameof(system), system)
                      .Add(nameof(version), version)
                      .Add(nameof(coding), coding)
                      .Add(nameof(date), date);

            return((await client.TypeOperationAsync <ValueSet>(RestOperation.CONCEPT_LOOKUP, par).ConfigureAwait(false))
                   .OperationResult <Parameters>());
        }
コード例 #14
0
 public StravaProviderUpdateEventHandler(
     IStravaClient stravaClient,
     IStravaAuthenticationService stravaAuthenticationService,
     ILogger <StravaProviderUpdateEventHandler> logger,
     IIntegrationRepository integrationRepository,
     IIoMTDataPublisher iomtDataPublisher,
     IFhirClient fhirClient)
 {
     _stravaClient = stravaClient;
     _stravaAuthenticationService = stravaAuthenticationService;
     _logger = logger;
     _integrationRepository = integrationRepository;
     _iomtDataPublisher     = iomtDataPublisher;
     _fhirClient            = fhirClient;
 }
コード例 #15
0
 public UserEndpoint(
     ILoggerFactory log,
     IExceptionFilter exceptionFilter,
     IAuthentication auth,
     IConsentStore consentStore,
     IVendorClient vendorClient,
     IFhirClient fhirClient,
     IUserFactory userFactory,
     IGuidFactory guidFactory)
 {
     this.log             = log.CreateLogger <UserEndpoint>();
     this.exceptionFilter = exceptionFilter;
     this.auth            = auth;
     this.consentStore    = consentStore;
     this.vendorClient    = vendorClient;
     this.fhirClient      = fhirClient;
     this.userFactory     = userFactory;
     this.guidFactory     = guidFactory;
 }
コード例 #16
0
        public static async Task <bool> ValidateFhirClientAsync(
            this IFhirClient client,
            ITelemetryLogger logger)
        {
            EnsureArg.IsNotNull(client, nameof(client));
            EnsureArg.IsNotNull(logger, nameof(logger));

            try
            {
                await client.ReadAsync <Hl7.Fhir.Model.CapabilityStatement>("metadata?_summary=true").ConfigureAwait(false);

                return(true);
            }
            catch (Exception exception)
            {
                FhirServiceExceptionProcessor.ProcessException(exception, logger);
                return(false);
            }
        }
コード例 #17
0
        public MainMenuForm()
        {
            InitializeComponent();

            // initialize resource string
            fhirResourceString = "";

            // set up restful client
            client = new RestClient("http://hackathon.siim.org/fhir/");
            client.AddDefaultHeader("Content-Type", "application/fhir+json");
            client.AddDefaultHeader("apikey", Environment.GetEnvironmentVariable("SiimApiKey"));
            driver = new MainMenuFormDriver(client);

            // make form instances
            fhirClient = new FhirClient("http://hackathon.siim.org/fhir/");
            fhirClient.OnBeforeRequest += (object sender, BeforeRequestEventArgs e) => {
                e.RawRequest.Headers.Add("apikey", Environment.GetEnvironmentVariable("SiimApiKey")); //requires environment variable to match
            };
            patientForm = new PatientForm(fhirClient);
        }
コード例 #18
0
 public Jobs(
     ILoggerFactory log,
     IExceptionFilter exceptionFilter,
     IFhirClient fhirClient,
     IJson json,
     IWithingsClient withingsClient,
     IConsentStore consentStore,
     INotification notification,
     IGuidFactory guidFactory,
     IWithingsToFhirConverter converter)
 {
     this.log             = log.CreateLogger <Jobs>();
     this.exceptionFilter = exceptionFilter;
     this.fhirClient      = fhirClient;
     this.json            = json;
     this.withingsClient  = withingsClient;
     this.consentStore    = consentStore;
     this.notification    = notification;
     this.guidFactory     = guidFactory;
     this.converter       = converter;
 }
コード例 #19
0
        /// <summary>
        /// Sets the authenticated token on the <see cref="IFhirClient"/> via OpenId user password.
        /// </summary>
        /// <param name="fhirClient">The <see cref="IFhirClient"/> to authenticate.</param>
        /// <param name="clientId">The clientId of the application.</param>
        /// <param name="clientSecret">The clientSecret of the application.</param>
        /// <param name="resource">The resource to authenticate with.</param>
        /// <param name="scope">The scope to authenticate with.</param>
        /// <param name="username">The username to authenticate.</param>
        /// <param name="password">The password to authenticate.</param>
        /// <param name="cancellationToken">The <see cref="CancellationToken"/> for the request.</param>
        /// <returns>A <see cref="Task"/> representing the successful setting of the token.</returns>
        public static async Task AuthenticateOpenIdUserPassword(
            this IFhirClient fhirClient,
            string clientId,
            string clientSecret,
            string resource,
            string scope,
            string username,
            string password,
            CancellationToken cancellationToken)
        {
            var formData = new List <KeyValuePair <string, string> >
            {
                new KeyValuePair <string, string>(OpenIdConnectParameterNames.ClientId, clientId),
                new KeyValuePair <string, string>(OpenIdConnectParameterNames.ClientSecret, clientSecret),
                new KeyValuePair <string, string>(OpenIdConnectParameterNames.GrantType, OpenIdConnectGrantTypes.Password),
                new KeyValuePair <string, string>(OpenIdConnectParameterNames.Scope, scope),
                new KeyValuePair <string, string>(OpenIdConnectParameterNames.Resource, resource),
                new KeyValuePair <string, string>(OpenIdConnectParameterNames.Username, username),
                new KeyValuePair <string, string>(OpenIdConnectParameterNames.Password, password),
            };

            await ObtainTokenAndSetOnClient(fhirClient, formData, cancellationToken);
        }
コード例 #20
0
        public static async Task <ValidateCodeResult> ValidateCodeAsync(this IFhirClient client, String valueSetId,
                                                                        FhirUri identifier    = null, FhirUri context                 = null, ValueSet valueSet  = null, Code code = null,
                                                                        FhirUri system        = null, FhirString version              = null, FhirString display = null,
                                                                        Coding coding         = null, CodeableConcept codeableConcept = null, FhirDateTime date  = null,
                                                                        FhirBoolean @abstract = null)
        {
            if (valueSetId == null)
            {
                throw new ArgumentNullException(nameof(valueSetId));
            }

            var par = new Parameters()
                      .Add(nameof(identifier), identifier)
                      .Add(nameof(context), context)
                      .Add(nameof(valueSet), valueSet)
                      .Add(nameof(code), code)
                      .Add(nameof(system), system)
                      .Add(nameof(version), version)
                      .Add(nameof(display), display)
                      .Add(nameof(coding), coding)
                      .Add(nameof(codeableConcept), codeableConcept)
                      .Add(nameof(date), date)
                      .Add(nameof(@abstract), @abstract);

            ResourceIdentity location = new ResourceIdentity("ValueSet/" + valueSetId);
            var result = await client.InstanceOperationAsync(location.WithoutVersion().MakeRelative(), RestOperation.VALIDATE_CODE, par).ConfigureAwait(false);

            if (result != null)
            {
                return(ValidateCodeResult.FromParameters(result.OperationResult <Parameters>()));
            }
            else
            {
                return(null);
            }
        }
コード例 #21
0
 public PatientController()
 {
     _client = new FhirClient("https://fhir.monash.edu/hapi-fhir-jpaserver/fhir/");
 }
コード例 #22
0
 public R4DeviceAndPatientCreateIdentityService(IFhirClient fhirClient, ResourceManagementService resourceIdService)
     : base(fhirClient, resourceIdService)
 {
 }
コード例 #23
0
 public ExternalTerminologyService(IFhirClient client)
 {
     Endpoint = client;
 }
コード例 #24
0
 public R4DeviceAndPatientCreateIdentityService(IFhirClient fhirClient)
     : base(fhirClient)
 {
 }
コード例 #25
0
 public R4DeviceAndPatientLookupIdentityService(IFhirClient fhirClient, ResourceManagementService resourceManagementService)
 {
     _fhirClient = EnsureArg.IsNotNull(fhirClient, nameof(fhirClient));
     _resourceManagementService = EnsureArg.IsNotNull(resourceManagementService, nameof(resourceManagementService));
 }
コード例 #26
0
 public R4DeviceAndPatientLookupIdentityService(IFhirClient fhirClient)
     : this(fhirClient, new ResourceManagementService())
 {
 }
コード例 #27
0
        protected static async Task <TResource> GetResourceByIdentityAsync <TResource>(IFhirClient client, Model.Identifier identifier)
            where TResource : Model.Resource, new()
        {
            EnsureArg.IsNotNull(client, nameof(client));
            EnsureArg.IsNotNull(identifier, nameof(identifier));
            var searchParams = identifier.ToSearchParams();
            var result       = await client.SearchAsync <TResource>(searchParams).ConfigureAwait(false);

            return(await result.ReadOneFromBundleWithContinuationAsync <TResource>(client));
        }
コード例 #28
0
 public GetPatientHandler(IFhirClient client)
 {
     _client = client;
 }
コード例 #29
0
        protected static async Task <TResource> CreateResourceByIdentityAsync <TResource>(IFhirClient client, Model.Identifier identifier, Action <TResource, Model.Identifier> propertySetter)
            where TResource : Model.Resource, new()
        {
            EnsureArg.IsNotNull(client, nameof(client));
            EnsureArg.IsNotNull(identifier, nameof(identifier));
            var resource = new TResource();

            propertySetter?.Invoke(resource, identifier);

            return(await client.CreateAsync <TResource>(resource).ConfigureAwait(false));
        }
コード例 #30
0
ファイル: BundleExtensions.cs プロジェクト: iBoonz/iomt-fhir
        public static async Task <IEnumerable <TResource> > SearchWithContinuationAsync <TResource>(this IFhirClient fhirClient, SearchParams searchParams)
            where TResource : Resource
        {
            var result = await fhirClient.SearchAsync <TResource>(searchParams).ConfigureAwait(false) as Bundle;

            return(await result.ReadFromBundleWithContinuationAsync <TResource>(fhirClient, searchParams.Count).ConfigureAwait(false));
        }