Пример #1
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))))));
        }
Пример #2
0
        private async void ErrorOnInvalidLinkReferenceNumber()
        {
            var sessionId             = TestBuilders.Faker().Random.Hash();
            var otpToken              = TestBuilders.Faker().Random.Number().ToString();
            var patientLinkRequest    = new LinkConfirmationRequest(otpToken, sessionId);
            var expectedErrorResponse =
                new ErrorRepresentation(new Error(ErrorCode.NoLinkRequestFound, "No request found"));

            patientVerification.Setup(e => e.Verify(sessionId, otpToken))
            .ReturnsAsync((OtpMessage)null);
            linkRepository.Setup(e => e.GetPatientFor(sessionId))
            .ReturnsAsync(new Tuple <LinkEnquires, Exception>(null, new Exception()));


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

            patientVerification.Verify();
            error.Should().BeEquivalentTo(expectedErrorResponse);
        }
Пример #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);
        }
Пример #4
0
        private async void ReturnOtpExpired()
        {
            var sessionId          = TestBuilders.Faker().Random.Hash();
            var otpToken           = TestBuilders.Faker().Random.Number().ToString();
            var dateTimeStamp      = DateTime.Now.ToUniversalTime().ToString(Constants.DateTimeFormat);
            var testOtpMessage     = new OtpMessage(ResponseType.OtpExpired, "Otp Expired");
            var patientLinkRequest = new LinkConfirmationRequest(otpToken, sessionId);
            var linkEnquires       = new LinkEnquires("", "", "ncg", "",
                                                      dateTimeStamp, new List <CareContext>());
            var expectedErrorResponse =
                new ErrorRepresentation(new Error(ErrorCode.OtpExpired, testOtpMessage.Message));

            linkRepository.Setup(e => e.GetPatientFor(sessionId))
            .ReturnsAsync(new Tuple <LinkEnquires, Exception>(linkEnquires, null));
            patientVerification.Setup(e => e.Verify(sessionId, otpToken))
            .ReturnsAsync(testOtpMessage);

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

            patientVerification.Verify();
            error.Should().BeEquivalentTo(expectedErrorResponse);
        }