Exemplo n.º 1
0
        public static async Task DeleteAllResources(this FhirClient client, ResourceType resourceType, string searchUrl)
        {
            Bundle bundle = null;

            while (bundle == null || bundle.NextLink != null)
            {
                bundle = bundle == null ? await client.SearchAsync(resourceType, searchUrl, count : 100) : await client.SearchAsync(bundle.NextLink.ToString());

                foreach (Bundle.EntryComponent entry in bundle.Entry)
                {
                    using var response = await client.DeleteAsync(entry.FullUrl);
                }
            }
        }
Exemplo n.º 2
0
        public static async Task <TResource[]> CreateResourcesAsync <TResource>(this FhirClient client, int count)
            where TResource : Resource, new()
        {
            TResource[] resources = new TResource[count];

            for (int i = 0; i < resources.Length; i++)
            {
                TResource resource = new TResource();

                resources[i] = await client.CreateAsync(resource);
            }

            return(resources);
        }
Exemplo n.º 3
0
        public static async Task <TResource[]> CreateResourcesAsync <TResource>(this FhirClient client, params Action <TResource>[] resourceCustomizer)
            where TResource : Resource, new()
        {
            TResource[] resources = new TResource[resourceCustomizer.Length];

            for (int i = 0; i < resources.Length; i++)
            {
                TResource resource = new TResource();

                resourceCustomizer[i](resource);

                resources[i] = await client.CreateAsync(resource);
            }

            return(resources);
        }
Exemplo n.º 4
0
        public static async Task DeleteAllResources(this FhirClient client, ResourceType resourceType, string searchUrl)
        {
            while (true)
            {
                Bundle bundle = await client.SearchAsync(resourceType, searchUrl, count : 100);

                if (!bundle.Entry.Any())
                {
                    break;
                }

                foreach (Bundle.EntryComponent entry in bundle.Entry)
                {
                    await client.DeleteAsync(entry.FullUrl);
                }
            }
        }
        /// <summary>
        /// Sets the authenticated token on the FhirClient via OpenId user password.
        /// </summary>
        /// <param name="fhirClient">The FhirClient 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>
        /// <returns>A task representing the successful setting of the token.</returns>
        public static async Task AuthenticateOpenIdUserPassword(
            this FhirClient fhirClient,
            string clientId,
            string clientSecret,
            string resource,
            string scope,
            string username,
            string password)
        {
            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);
        }
Exemplo n.º 6
0
        public static async Task <TResource[]> CreateResourcesAsync <TResource>(this FhirClient client, int count, string tag)
            where TResource : Resource, new()
        {
            TResource[] resources = new TResource[count];

            for (int i = 0; i < resources.Length; i++)
            {
                TResource resource = new TResource();
                resource.Meta = new Meta()
                {
                    Tag = new List <Coding>
                    {
                        new Coding("testTag", tag),
                    },
                };

                using var response = await client.CreateAsync(resource);

                resources[i] = response;
            }

            return(resources);
        }
        /// <summary>
        /// Sets the authenticated token on the FhirClient via OpenId client credentials.
        /// </summary>
        /// <param name="fhirClient">The FhirClient 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>
        /// <returns>A task representing the successful setting of the token.</returns>
        public static async Task AuthenticateOpenIdClientCredentials(
            this FhirClient fhirClient,
            string clientId,
            string clientSecret,
            string resource,
            string scope)
        {
            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);
        }
Exemplo n.º 8
0
 public static async Task DeleteAllResources(this FhirClient client, ResourceType resourceType)
 {
     await DeleteAllResources(client, resourceType, null);
 }