Beispiel #1
0
        public async Task <EverythingOperationResponse> Handle(EverythingOperationRequest request, CancellationToken cancellationToken)
        {
            EnsureArg.IsNotNull(request, nameof(request));

            if (await _authorizationService.CheckAccess(DataActions.Read, cancellationToken) != DataActions.Read)
            {
                throw new UnauthorizedFhirActionException();
            }

            if (!string.Equals(request.EverythingOperationType, ResourceType.Patient.ToString(), StringComparison.Ordinal))
            {
                throw new RequestNotValidException(string.Format(Core.Resources.ResourceNotSupported, request.EverythingOperationType));
            }

            SearchResult searchResult = await _patientEverythingService.SearchAsync(
                request.ResourceId,
                request.Start,
                request.End,
                request.Since,
                request.ResourceTypes,
                request.ContinuationToken,
                cancellationToken);

            ResourceElement bundle = request.UnsupportedParameters != null && request.UnsupportedParameters.Any()
                ? _bundleFactory.CreateSearchBundle(new SearchResult(searchResult.Results, searchResult.ContinuationToken, searchResult.SortOrder, request.UnsupportedParameters))
                : _bundleFactory.CreateSearchBundle(searchResult);

            return(new EverythingOperationResponse(bundle));
        }
Beispiel #2
0
        public async Task GivenAnEverythingOperationRequest_WhenHandled_ThenABundleShouldBeReturned()
        {
            var request = new EverythingOperationRequest("Patient", "123");

            var searchResult = new SearchResult(Enumerable.Empty <SearchResultEntry>(), null, null, new Tuple <string, string> [0]);

            _patientEverythingService.SearchAsync(
                request.ResourceId,
                request.Start,
                request.End,
                request.Since,
                request.ResourceTypes,
                request.ContinuationToken,
                CancellationToken.None).Returns(searchResult);

            var expectedBundle = new Bundle().ToResourceElement();

            _bundleFactory.CreateSearchBundle(searchResult).Returns(expectedBundle);

            EverythingOperationResponse actualResponse = await _everythingOperationHandler.Handle(request, CancellationToken.None);

            Assert.NotNull(actualResponse);
            Assert.Equal(expectedBundle, actualResponse.Bundle);
        }