private DiagnosticReport createDiagnosticsReport(ServiceRequest order, Patient p, IEnumerable <ResourceReference> producers, IEnumerable <ResourceReference> consumers, List <Observation> observations) { return(new DiagnosticReport() { Id = Uuid.Generate().ToString(), Identifier = new List <Identifier>() { new Identifier(model.Event.Producer, $"{model.Result.Id}/{model.Result.Version}") }, BasedOn = new List <ResourceReference> { order.BundleRef() }, Code = Constants.ORDER_PROCEDURE_REQUEST_CODE, Subject = p.BundleRef(), Performer = producers.ToList(), ResultsInterpreter = consumers.ToList(), Result = observations.Select(x => x.BundleRef()).ToList(), PresentedForm = new List <Attachment>() { new Attachment() { Language = "en", ContentType = "application/pdf", Size = 100, Data = new byte[] { 1, 2, 3, 4, 5, 6, 7 }, Creation = model.Result.DocumentDateTime.ToString(Constants.DATE_FORMAT), Hash = new byte[] { 1, 2, 3 }, Title = "Report" }, new Attachment() { Language = "ro", ContentType = "application/pdf", Size = 100, Data = new byte[] { 1, 2, 3, 4, 5, 6, 7 }, Creation = model.Result.DocumentDateTime.ToString(Constants.DATE_FORMAT), Hash = new byte[] { 1, 2, 3 }, Title = "Report" }, } }); }
private async void CheckInternalServerErrorOnSaveDataFailure() { var consentMangerId = TestBuilder.Faker().Random.String(); var request = TestBuilder.HealthInformationRequest(TestBuilder.Faker().Random.Hash()); var expectedError = new ErrorRepresentation(new Error(ErrorCode.ServerInternalError, ErrorMessage.InternalServerError)); var correlationId = Uuid.Generate().ToString(); dataFlow.Setup(d => d.HealthInformationRequestFor(request, consentMangerId, correlationId)) .ReturnsAsync( new Tuple <HealthInformationTransactionResponse, ErrorRepresentation>(null, expectedError)); var response = await dataFlowController.HealthInformationRequestFor(request, correlationId, consentMangerId) as ObjectResult; dataFlow.Verify(); response.StatusCode .Should() .Be(StatusCodes.Status500InternalServerError); }
private async void ShouldReturnAccessToken() { var handlerMock = new Mock <HttpMessageHandler>(MockBehavior.Strict); var httpClient = new HttpClient(handlerMock.Object); const string rootRul = "http://someUrl"; var expectedUri = new Uri($"{rootRul}/{PATH_SESSIONS}"); var correlationId = Uuid.Generate().ToString(); var configuration = new GatewayConfiguration { Url = rootRul, ClientId = TestBuilder.RandomString(), ClientSecret = TestBuilder.RandomString() }; var response = JsonConvert.SerializeObject(new { tokenType = "bearer", accessToken = "token" }); handlerMock .Protected() .Setup <Task <HttpResponseMessage> >( "SendAsync", ItExpr.IsAny <HttpRequestMessage>(), ItExpr.IsAny <CancellationToken>()) .ReturnsAsync(new HttpResponseMessage { StatusCode = HttpStatusCode.OK, Content = new StringContent(response, Encoding.UTF8, MediaTypeNames.Application.Json) }) .Verifiable(); var client = new GatewayClient(httpClient, configuration); var result = await client.Authenticate(correlationId); result.HasValue.Should().BeTrue(); result.MatchSome(token => token.Should().BeEquivalentTo("bearer token")); handlerMock.Protected().Verify( "SendAsync", Times.Exactly(1), ItExpr.Is <HttpRequestMessage>(message => message.Method == HttpMethod.Post && message.RequestUri == expectedUri), ItExpr.IsAny <CancellationToken>()); }
private async void ShouldNotReturnTokenWhenErrorResponse(HttpStatusCode statusCode) { var handlerMock = new Mock <HttpMessageHandler>(MockBehavior.Strict); var httpClient = new HttpClient(handlerMock.Object); const string centralRegistryRootUrl = "http://someUrl"; var expectedUri = new Uri($"{centralRegistryRootUrl}/{PATH_SESSIONS}"); var configuration = new GatewayConfiguration { Url = centralRegistryRootUrl, ClientId = TestBuilder.RandomString(), ClientSecret = TestBuilder.RandomString() }; var response = JsonConvert.SerializeObject(new { error = "some failure happened" }); var correlationId = Uuid.Generate().ToString(); handlerMock .Protected() .Setup <Task <HttpResponseMessage> >( "SendAsync", ItExpr.IsAny <HttpRequestMessage>(), ItExpr.IsAny <CancellationToken>()) .ReturnsAsync(new HttpResponseMessage { StatusCode = statusCode, Content = new StringContent(response, Encoding.UTF8, MediaTypeNames.Application.Json) }) .Verifiable(); var client = new GatewayClient(httpClient, configuration); var result = await client.Authenticate(correlationId); result.HasValue.Should().BeFalse(); handlerMock.Protected().Verify( "SendAsync", Times.Exactly(1), ItExpr.Is <HttpRequestMessage>(message => message.Method == HttpMethod.Post && message.RequestUri == expectedUri), ItExpr.IsAny <CancellationToken>()); }
internal static HipLibrary.Patient.Model.TraceableDataRequest TraceableDataRequest(string transactionId) { const string consentManagerId = "ConsentManagerId"; const string consentId = "ConsentId"; var dateRange = new HipLibrary.Patient.Model.DateRange("from", "to"); const string callBackUrl = "http://callback/data/notification"; var keyMaterial = new KeyMaterialLib(faker.Random.Word(), faker.Random.Word(), new KeyStructureLib("", "", faker.Random.Hash()), faker.Random.Hash()); return(new HipLibrary.Patient.Model.TraceableDataRequest(new List <GrantedContext>(), dateRange, callBackUrl, new List <HiType>(), transactionId, keyMaterial, consentManagerId, consentId, faker.Random.Word(), Uuid.Generate().ToString() )); }
private async void ReturnTransactionId() { var consentMangerId = TestBuilder.Faker().Random.String(); var transactionId = TestBuilder.Faker().Random.Hash(); var request = TestBuilder.HealthInformationRequest(transactionId); var expectedResponse = new HealthInformationTransactionResponse(transactionId); var correlationId = Uuid.Generate().ToString(); dataFlow.Setup(d => d.HealthInformationRequestFor(request, consentMangerId, correlationId)) .ReturnsAsync( new Tuple <HealthInformationTransactionResponse, ErrorRepresentation>(expectedResponse, null)); var response = await dataFlowController.HealthInformationRequestFor(request, correlationId, consentMangerId); dataFlow.Verify(); response.Should() .NotBeNull() .And .Subject.As <OkObjectResult>() .Value .Should() .BeEquivalentTo(expectedResponse); }
private async void ReturnEntriesForHina() { const string consentId = "ConsentId"; const string consentManagerId = "ConsentManagerId"; var grantedContexts = new List <GrantedContext> { new GrantedContext("RVH1003", "BI-KTH-12.05.0024"), new GrantedContext("RVH1003", "NCP1008") }; var dateRange = new DateRange("2017-12-01T15:43:00.818234", "2021-12-31T15:43:00.818234"); var hiTypes = new List <HiType> { HiType.Condition, HiType.Observation, HiType.DiagnosticReport, HiType.MedicationRequest, HiType.DocumentReference, HiType.Prescription, HiType.DischargeSummary, HiType.OPConsultation }; var traceableDataRequest = new TraceableDataRequest(grantedContexts, dateRange, "/someUrl", hiTypes, "someTxnId", null, consentManagerId, consentId, "sometext", Uuid.Generate().ToString()); var entries = await collect.CollectData(traceableDataRequest); entries.ValueOrDefault().CareBundles.Count().Should().Be(18); }
private async void ReturnErrorOnFailure() { var consentMangerId = TestBuilder.Faker().Random.String(); var transactionId = TestBuilder.Faker().Random.Hash(); var request = TestBuilder.HealthInformationRequest(transactionId); dataFlowRepository.Setup(d => d.SaveRequest(transactionId, request)) .ReturnsAsync(Option.Some(new Exception())); var expectedError = new ErrorRepresentation(new Error(ErrorCode.ServerInternalError, ErrorMessage.InternalServerError)); consentRepository.Setup(d => d.GetFor(request.Consent.Id)) .ReturnsAsync(TestBuilder.DataFlowConsent()); var(_, errorResponse) = await dataFlowService.HealthInformationRequestFor(request, consentMangerId, Uuid.Generate().ToString()); dataFlowRepository.Verify(); errorResponse.Should().BeEquivalentTo(expectedError); }
private async void ReturnAcknowledgementIdOnSuccess() { var consentMangerId = TestBuilder.Faker().Random.String(); var transactionId = TestBuilder.Faker().Random.Hash(); var request = TestBuilder.HealthInformationRequest(transactionId); dataFlowRepository.Setup(d => d.SaveRequest(transactionId, request)) .ReturnsAsync(Option.None <Exception>()); consentRepository.Setup(d => d.GetFor(request.Consent.Id)) .ReturnsAsync(TestBuilder.DataFlowConsent()); var(healthInformationResponse, _) = await dataFlowService.HealthInformationRequestFor(request, consentMangerId, Uuid.Generate().ToString()); dataFlowRepository.Verify(); healthInformationResponse.AcknowledgementId.Should().BeEquivalentTo(transactionId); }