public static async Task <Bundle> RefreshBundleAsync(this FhirClient client, Bundle bundle) { if (bundle == null) { throw Error.ArgumentNull(nameof(bundle)); } if (bundle.Type != Bundle.BundleType.Searchset) { throw Error.Argument("Refresh is only applicable to bundles of type 'searchset'"); } // Clone old bundle, without the entries (so, just the header) Bundle result = (Bundle)bundle.DeepCopy(); result.Id = "urn:uuid:" + Guid.NewGuid().ToString("n"); result.Meta = new Meta(); result.Meta.LastUpdated = DateTimeOffset.Now; foreach (var entry in result.Entry) { if (entry.Resource != null) { entry.Resource = await client.ReadAsync <Resource>(entry.FullUrl).ConfigureAwait(false); } } return(result); }