private ResourceElement CreateBundle(SearchResult result, Bundle.BundleType type, Func <ResourceWrapper, Bundle.EntryComponent> selectionFunction) { EnsureArg.IsNotNull(result, nameof(result)); // Create the bundle from the result. var bundle = new Bundle(); if (result != null) { IEnumerable <Bundle.EntryComponent> entries = result.Results.Select(selectionFunction); bundle.Entry.AddRange(entries); if (result.ContinuationToken != null) { bundle.NextLink = _urlResolver.ResolveRouteUrl( result.UnsupportedSearchParameters, Convert.ToBase64String(System.Text.Encoding.UTF8.GetBytes(result.ContinuationToken))); } } // Add the self link to indicate which search parameters were used. bundle.SelfLink = _urlResolver.ResolveRouteUrl(result.UnsupportedSearchParameters); bundle.Id = _fhirRequestContextAccessor.FhirRequestContext.CorrelationId; bundle.Type = type; bundle.Total = result?.TotalCount; bundle.Meta = new Meta { LastUpdated = Clock.UtcNow, }; return(bundle.ToResourceElement()); }
private ResourceElement CreateBundle(SearchResult result, Bundle.BundleType type, Func <SearchResultEntry, Bundle.EntryComponent> selectionFunction) { EnsureArg.IsNotNull(result, nameof(result)); // Create the bundle from the result. var bundle = new Bundle(); if (result != null) { IEnumerable <Bundle.EntryComponent> entries = result.Results.Select(selectionFunction); bundle.Entry.AddRange(entries); if (result.ContinuationToken != null) { bundle.NextLink = _urlResolver.ResolveRouteUrl( result.UnsupportedSearchParameters, result.UnsupportedSortingParameters, Convert.ToBase64String(System.Text.Encoding.UTF8.GetBytes(result.ContinuationToken)), true); } if (result.Partial) { // if the query resulted in a partial indication, add appropriate outcome // as an entry var resource = new OperationOutcome(); resource.Issue = new List <OperationOutcome.IssueComponent>(); resource.Issue.Add(new OperationOutcome.IssueComponent { Severity = OperationOutcome.IssueSeverity.Warning, Code = OperationOutcome.IssueType.Incomplete, Diagnostics = Core.Resources.TruncatedIncludeMessage, }); bundle.Entry.Add(new Bundle.EntryComponent() { Resource = resource, }); } } // Add the self link to indicate which search parameters were used. bundle.SelfLink = _urlResolver.ResolveRouteUrl(result.UnsupportedSearchParameters, result.UnsupportedSortingParameters); bundle.Id = _fhirRequestContextAccessor.FhirRequestContext.CorrelationId; bundle.Type = type; bundle.Total = result?.TotalCount; bundle.Meta = new Meta { LastUpdated = Clock.UtcNow, }; return(bundle.ToResourceElement()); }
public Bundle CreateHistoryBundle(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); var hasVerb = Enum.TryParse(r.Request?.Method, true, out Bundle.HTTPVerb httpVerb); return(new Bundle.EntryComponent { FullUrlElement = new FhirUri(_urlResolver.ResolveResourceUrl(resource, true)), Resource = resource, Request = new Bundle.RequestComponent { Method = hasVerb ? (Bundle.HTTPVerb?)httpVerb: null, Url = r.Request?.Url?.ToString(), }, Response = new Bundle.ResponseComponent { LastModified = r.LastModified, Etag = WeakETag.FromVersionId(r.Version).ToString(), }, }); }); bundle.Entry.AddRange(entries); if (result.ContinuationToken != null) { bundle.NextLink = _urlResolver.ResolveRouteUrl( _fhirRequestContextAccessor.FhirRequestContext.RouteName, unsupportedSearchParams, result.ContinuationToken); } } // Add the self link to indicate which search parameters were used. bundle.SelfLink = _urlResolver.ResolveRouteUrl(_fhirRequestContextAccessor.FhirRequestContext.RouteName, unsupportedSearchParams); bundle.Id = _fhirRequestContextAccessor.FhirRequestContext.CorrelationId; bundle.Type = Bundle.BundleType.History; bundle.Total = result?.TotalCount; bundle.Meta = new Meta { LastUpdated = Clock.UtcNow, }; return(bundle); }
private ResourceElement CreateBundle(SearchResult result, Bundle.BundleType type, Func <SearchResultEntry, Bundle.EntryComponent> selectionFunction) { EnsureArg.IsNotNull(result, nameof(result)); // Create the bundle from the result. var bundle = new Bundle(); if (_fhirRequestContextAccessor.RequestContext.BundleIssues.Any()) { var operationOutcome = new OperationOutcome { Id = _fhirRequestContextAccessor.RequestContext.CorrelationId, Issue = new List <OperationOutcome.IssueComponent>(_fhirRequestContextAccessor.RequestContext.BundleIssues.Select(x => x.ToPoco())), }; bundle.Entry.Add(new Bundle.EntryComponent { Resource = operationOutcome, Search = new Bundle.SearchComponent { Mode = Bundle.SearchEntryMode.Outcome, }, }); } IEnumerable <Bundle.EntryComponent> entries = result.Results.Select(selectionFunction); bundle.Entry.AddRange(entries); if (result.ContinuationToken != null) { bundle.NextLink = _urlResolver.ResolveRouteUrl( result.UnsupportedSearchParameters, result.SortOrder, Convert.ToBase64String(System.Text.Encoding.UTF8.GetBytes(result.ContinuationToken)), true); } // Add the self link to indicate which search parameters were used. bundle.SelfLink = _urlResolver.ResolveRouteUrl(result.UnsupportedSearchParameters, result.SortOrder); bundle.Id = _fhirRequestContextAccessor.RequestContext.CorrelationId; bundle.Type = type; bundle.Total = result?.TotalCount; bundle.Meta = new Meta { LastUpdated = Clock.UtcNow, }; return(bundle.ToResourceElement()); }
public ResourceElement CreateSearchBundle(SearchResult result) { EnsureArg.IsNotNull(result, nameof(result)); // Create the bundle from the result. var bundle = new Bundle(); if (result != null) { IEnumerable <Bundle.EntryComponent> entries = result.Results.Select(r => { ResourceElement resource = _deserializer.Deserialize(r); return(new Bundle.EntryComponent { FullUrlElement = new FhirUri(_urlResolver.ResolveResourceUrl(resource)), Resource = resource.Instance.ToPoco <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.ResolveRouteUrl( result.UnsupportedSearchParameters, result.ContinuationToken); } } // Add the self link to indicate which search parameters were used. bundle.SelfLink = _urlResolver.ResolveRouteUrl(result.UnsupportedSearchParameters); bundle.Id = _fhirRequestContextAccessor.FhirRequestContext.CorrelationId; bundle.Type = Bundle.BundleType.Searchset; bundle.Total = result?.TotalCount; bundle.Meta = new Meta { LastUpdated = Clock.UtcNow, }; return(bundle.ToResourceElement()); }
public void GivenAnEmptySearchResult_WhenCreateSearchBundle_ThenCorrectBundleShouldBeReturned() { _urlResolver.ResolveRouteUrl(_unsupportedSearchParameters).Returns(_selfUrl); ResourceElement actual = null; using (Mock.Property(() => ClockResolver.UtcNowFunc, () => _dateTime)) { actual = _bundleFactory.CreateSearchBundle(new SearchResult(new SearchResultEntry[0], null, null, _unsupportedSearchParameters)); } Assert.NotNull(actual); Assert.Equal(Bundle.BundleType.Searchset.ToString().ToLowerInvariant(), actual.Scalar <string>("Bundle.type")); Assert.Equal(_correlationId.ToString(), actual.Id); Assert.Equal(_dateTime, actual.LastUpdated); Assert.Equal(_selfUrl.OriginalString, actual.Scalar <string>("Bundle.link.where(relation='self').url")); }
private void CreateLinks(SearchResult result, Bundle bundle) { bool problemWithLinks = false; if (result.ContinuationToken != null) { try { bundle.NextLink = _urlResolver.ResolveRouteUrl( result.UnsupportedSearchParameters, result.SortOrder, Convert.ToBase64String(System.Text.Encoding.UTF8.GetBytes(result.ContinuationToken)), true); } catch (UriFormatException) { problemWithLinks = true; } } try { // Add the self link to indicate which search parameters were used. bundle.SelfLink = _urlResolver.ResolveRouteUrl(result.UnsupportedSearchParameters, result.SortOrder); } catch (UriFormatException) { problemWithLinks = true; } if (problemWithLinks) { _fhirRequestContextAccessor.RequestContext.BundleIssues.Add( new OperationOutcomeIssue( OperationOutcomeConstants.IssueSeverity.Warning, OperationOutcomeConstants.IssueType.NotSupported, string.Format(Core.Resources.LinksCantBeCreated))); } }