示例#1
0
        public static async Task <IEnumerable <TResource> > ReadFromBundleWithContinuationAsync <TResource>(this Bundle bundle, FhirClient fhirClient, int?count = null)
            where TResource : Resource
        {
            EnsureArg.IsNotNull(fhirClient, nameof(fhirClient));

            var resources = new List <TResource>();

            while (bundle != null)
            {
                foreach (var r in bundle.ReadFromBundle <TResource>(count))
                {
                    if (count == 0)
                    {
                        break;
                    }

                    resources.Add(r);
                    if (count != null)
                    {
                        count--;
                    }
                }

                bundle = await fhirClient.ContinueAsync(bundle).ConfigureAwait(false);
            }

            return(resources);
        }
        public async Task SearchUsingPostWithCriteria_AsyncContinue_SearchReturned()
        {
            var client = new FhirClient(_endpointSupportingSearchUsingPost)
            {
                PreferredFormat    = ResourceFormat.Json,
                ReturnFullResource = true
            };

            var result1 = await client.SearchAsync <Patient>(new[] { "family=Chalmers" }, null, 1);

            Assert.IsTrue(result1.Entry.Count >= 1);

            while (result1 != null)
            {
                foreach (var e in result1.Entry)
                {
                    Patient p = (Patient)e.Resource;
                    if (p.Name.Any())
                    {
                        Console.WriteLine(
                            $"NAME: {p.Name[0].Given.FirstOrDefault()} {p.Name[0].Family.FirstOrDefault()}");
                    }
                }
                Console.WriteLine("Fetching more results...");
                result1 = await client.ContinueAsync(result1);
            }

            Console.WriteLine("Test Completed");
        }
示例#3
0
        public static async IAsyncEnumerable <T> GetAll <T>(
            this FhirClient client,
            string url,
            [EnumeratorCancellation] CancellationToken cancellationToken = default)
            where T : Resource
        {
            var allResources = await client.GetAsync(url).ConfigureAwait(false) as Bundle;

            foreach (var resource in allResources.GetResources().OfType <T>())
            {
                cancellationToken.ThrowIfCancellationRequested();
                yield return(resource);
            }

            while (allResources != null && allResources.NextLink != null)
            {
                cancellationToken.ThrowIfCancellationRequested();
                allResources = await client.ContinueAsync(allResources).ConfigureAwait(false);

                if (allResources == null)
                {
                    yield break;
                }

                foreach (var resource in allResources.GetResources().OfType <T>())
                {
                    yield return(resource);
                }
            }
        }