public Bundle CreateSearchBundle(string resourceType, IEnumerable <Tuple <string, string> > unsupportedSearchParams, SearchResult result) { // Create the bundle from the result. var bundle = new Bundle(); if (result != null) { IEnumerable <Bundle.EntryComponent> entries = result.Results.Select(r => { Resource resource = ResourceDeserializer.Deserialize(r); return(new Bundle.EntryComponent { FullUrlElement = new FhirUri(_urlResolver.ResolveResourceUrl(resource)), Resource = resource, Search = new Bundle.SearchComponent { // TODO: For now, everything returned is a match. We will need to // distinct between match and include once we support it. Mode = Bundle.SearchEntryMode.Match, }, }); }); bundle.Entry.AddRange(entries); if (result.ContinuationToken != null) { bundle.NextLink = _urlResolver.ResolveSearchUrl( resourceType, unsupportedSearchParams, result.ContinuationToken); } } // Add the self link to indicate which search parameters were used. bundle.SelfLink = _urlResolver.ResolveSearchUrl(resourceType, unsupportedSearchParams); bundle.Id = _fhirRequestContextAccessor.FhirRequestContext.CorrelationId; bundle.Type = Bundle.BundleType.Searchset; bundle.Total = result?.TotalCount; bundle.Meta = new Meta { LastUpdated = Clock.UtcNow, }; return(bundle); }