コード例 #1
0
        private void ShouldEnqueueLinkConfirmationRequestAndReturnAccepted()
        {
            var          linkReferenceNumber = Faker().Random.Hash();
            const string token            = "1234";
            var          cmId             = "ncg";
            var          careContext      = new[] { new CareContextRepresentation("129", Faker().Random.Word()) };
            var          expectedResponse = new PatientLinkConfirmationRepresentation(new LinkConfirmationRepresentation("4",
                                                                                                                         Faker().Random.Word()
                                                                                                                         , careContext));
            var correlationId = Uuid.Generate().ToString();

            link.Setup(e => e.VerifyAndLinkCareContext(It.Is <LinkConfirmationRequest>(p =>
                                                                                       p.Token == "1234" &&
                                                                                       p.LinkReferenceNumber == linkReferenceNumber)))
            .ReturnsAsync((expectedResponse, cmId, null));

            var linkPatientRequest = new LinkPatientRequest(Faker().Random.Hash(),
                                                            It.IsAny <string>(),
                                                            new LinkConfirmation(linkReferenceNumber, token));
            var response = linkController.LinkPatientFor(correlationId, linkPatientRequest);

            backgroundJobClient.Verify(client => client.Create(
                                           It.Is <Job>(job => job.Method.Name == "LinkPatientCareContextFor" && job.Args[0] == linkPatientRequest),
                                           It.IsAny <EnqueuedState>()));

            link.Verify();
            discoveryRequestRepository.Verify();
            response.StatusCode.Should().Be(StatusCodes.Status202Accepted);
        }
コード例 #2
0
        VerifyAndLinkCareContext(
            LinkConfirmationRequest request)
        {
            var(linkEnquires, exception) =
                await linkPatientRepository.GetPatientFor(request.LinkReferenceNumber);

            var cmId = "";

            if (exception != null)
            {
                return(null, cmId,
                       new ErrorRepresentation(new Error(ErrorCode.NoLinkRequestFound, ErrorMessage.NoLinkRequestFound)));
            }
            cmId = linkEnquires.ConsentManagerId;

            var errorResponse = await patientVerification.Verify(request.LinkReferenceNumber, request.Token);

            if (errorResponse != null)
            {
                return(null, cmId, new ErrorRepresentation(errorResponse.toError()));
            }

            var patient = await patientRepository.PatientWithAsync(linkEnquires.PatientReferenceNumber);

            return(await patient.Map(async patient =>
            {
                var savedLinkRequests = await linkPatientRepository.Get(request.LinkReferenceNumber);
                savedLinkRequests.MatchSome(linkRequests =>
                {
                    foreach (var linkRequest in linkRequests)
                    {
                        linkRequest.Status = true;
                        linkPatientRepository.Update(linkRequest);
                    }
                });

                var representations = linkEnquires.CareContexts
                                      .Where(careContext =>
                                             patient.CareContexts.Any(info => info.ReferenceNumber == careContext.CareContextNumber))
                                      .Select(context => new CareContextRepresentation(context.CareContextNumber,
                                                                                       patient.CareContexts.First(info => info.ReferenceNumber == context.CareContextNumber)
                                                                                       .Display));
                var patientLinkResponse = new PatientLinkConfirmationRepresentation(
                    new LinkConfirmationRepresentation(
                        linkEnquires.PatientReferenceNumber,
                        $"{patient.Name}",
                        representations));
                return await SaveLinkedAccounts(linkEnquires)
                        ? (patientLinkResponse, cmId, (ErrorRepresentation)null)
                        : (null, cmId,
                           new ErrorRepresentation(new Error(ErrorCode.NoPatientFound,
                                                             ErrorMessage.NoPatientFound)));
            }).ValueOr(
                       Task.FromResult <ValueTuple <PatientLinkConfirmationRepresentation, string, ErrorRepresentation> >(
                           (null, cmId, new ErrorRepresentation(new Error(ErrorCode.CareContextNotFound,
                                                                          ErrorMessage.CareContextNotFound))))));
        }
コード例 #3
0
        private async void SuccessLinkPatientForValidOtp()
        {
            const string programRefNo                   = "129";
            var          sessionId                      = TestBuilders.Faker().Random.Hash();
            var          otpToken                       = TestBuilders.Faker().Random.Number().ToString();
            var          patientLinkRequest             = new LinkConfirmationRequest(otpToken, sessionId);
            ICollection <CareContext> linkedCareContext = new[] { new CareContext(programRefNo) };
            var testLinkRequest = new LinkEnquires(testPatient.Identifier, sessionId,
                                                   TestBuilders.Faker().Random.Hash(), TestBuilders.Faker().Random.Hash()
                                                   , It.IsAny <string>(), linkedCareContext);
            var testLinkedAccounts = new LinkedAccounts(testLinkRequest.PatientReferenceNumber,
                                                        testLinkRequest.LinkReferenceNumber,
                                                        testLinkRequest.ConsentManagerUserId, It.IsAny <string>(), new[] { programRefNo }.ToList());

            patientVerification.Setup(e => e.Verify(sessionId, otpToken))
            .ReturnsAsync((OtpMessage)null);
            linkRepository.Setup(e => e.GetPatientFor(sessionId))
            .ReturnsAsync(new Tuple <LinkEnquires, Exception>(testLinkRequest, null));
            patientRepository.Setup(x => x.PatientWithAsync(testPatient.Identifier))
            .ReturnsAsync(Option.Some(testPatient));
            linkRepository.Setup(x => x.Save(testLinkRequest.ConsentManagerUserId,
                                             testLinkRequest.PatientReferenceNumber,
                                             testLinkRequest.LinkReferenceNumber,
                                             new[] { programRefNo }))
            .ReturnsAsync(Option.Some(testLinkedAccounts));
            var expectedLinkResponse = new PatientLinkConfirmationRepresentation(
                new LinkConfirmationRepresentation(
                    testPatient.Identifier,
                    $"{testPatient.Name}",
                    new[] { new CareContextRepresentation("129", "National Cancer program") }));

            var(response, cmId, _) = await linkPatient.VerifyAndLinkCareContext(patientLinkRequest);

            patientVerification.Verify();
            linkRepository.Verify();
            guidGenerator.Verify();
            response.Patient.ReferenceNumber.Should().BeEquivalentTo(expectedLinkResponse.Patient.ReferenceNumber);
            response.Patient.Display.Should().BeEquivalentTo(expectedLinkResponse.Patient.Display);
        }