public async Task <Option <LinkedAccounts> > Save(string consentManagerUserId,
                                                          string patientReferenceNumber,
                                                          string linkReferenceNumber,
                                                          IEnumerable <string> careContextReferenceNumbers)
        {
            var linkedAccounts = new LinkedAccounts(patientReferenceNumber,
                                                    linkReferenceNumber,
                                                    consentManagerUserId,
                                                    DateTime.Now.ToUniversalTime().ToString(Constants.DateTimeFormat),
                                                    careContextReferenceNumbers.ToList());

            try
            {
                await linkPatientContext.LinkedAccounts.AddAsync(linkedAccounts).ConfigureAwait(false);

                await linkPatientContext.SaveChangesAsync().ConfigureAwait(false);

                return(Option.Some(linkedAccounts));
            }
            catch (Exception exception)
            {
                Log.Fatal(exception, exception.StackTrace);
                return(Option.None <LinkedAccounts>());
            }
        }
Пример #2
0
        public async Task SubscribeTask(string account)
        {
            var url = $"https://steamid.venner.io/raw.php?input={account}";

            using (var client = new WebClient())
            {
                var json = client.DownloadString(url);
                var obj  = JsonConvert.DeserializeObject <SteamConvertData>(json);

                string reply;
                if (LinkedAccounts.UserDictionary.TryAdd(Context.User.Id, obj.Uid))
                {
                    reply = $"Now I know you as [{obj.Name}](http://steamcommunity.com/profiles/{obj.Steamid64}) 🙂";
                    LinkedAccounts.Save();
                }
                else
                {
                    url =
                        $"https://steamid.venner.io/raw.php?input=[U:1:{LinkedAccounts.UserDictionary[Context.User.Id]}]";
                    json  = client.DownloadString(url);
                    obj   = JsonConvert.DeserializeObject <SteamConvertData>(json);
                    reply =
                        $"But But But I already know you as [{obj.Name}](http://steamcommunity.com/profiles/{obj.Steamid64}) 😕";
                }

                var embed = new EmbedBuilder {
                    Description = reply
                };
                await ReplyAsync(string.Empty, false, embed.Build());
            }
        }
Пример #3
0
        // Update 'Linked Accounts' Field of the 'current user'
        public async Task UpdateTalentLinkedAccountsAsync(string userId, LinkedAccounts linkedAccounts)
        {
            var user = (await GetTalentByIDAsync(userId));

            user.LinkedAccounts.LinkedIn = linkedAccounts.LinkedIn;
            user.LinkedAccounts.Github   = linkedAccounts.Github;

            await _talentRepository.Update(user);
        }
Пример #4
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);
        }
Пример #5
0
 public async Task UnSubscribeTask(string accountId)
 {
     if (LinkedAccounts.UserDictionary.ContainsKey(Context.User.Id))
     {
         if (LinkedAccounts.UserDictionary[Context.User.Id] == accountId.Steam32Parse())
         {
             LinkedAccounts.UserDictionary.Remove(Context.User.Id);
             LinkedAccounts.Save();
             await ReplyAsync("Okay you are no longer " + accountId +
                              "\nI curse you to give a parameter every-time you use an `accountID` demanding command. RIP!");
         }
         else
         {
             await ReplyAsync("You were never " + accountId);
         }
     }
     else
     {
         await ReplyAsync(
             "Uhh I don't know who you are 😑" +
             "\n*I've arranged us a secret meeting at* `I am [you account]` 😉");
     }
 }
Пример #6
0
        private async void ShouldReturnPatientForAlreadyLinkedPatient()
        {
            var patientDiscovery = new PatientDiscovery(
                matchingRepository.Object,
                discoveryRequestRepository.Object,
                linkPatientRepository.Object,
                patientRepository.Object,
                logger.Object);
            var phoneNumber           = Faker().Phone.PhoneNumber();
            var verifiedIdentifiers   = new[] { new Identifier(IdentifierType.MOBILE, phoneNumber) };
            var unverifiedIdentifiers = new[] { new Identifier(IdentifierType.MR, Faker().Random.String()) };
            var patientId             = Faker().Random.String();
            var name          = Faker().Name.FullName();
            var alreadyLinked =
                new CareContextRepresentation(Faker().Random.Uuid().ToString(), Faker().Random.String());
            var unlinkedCareContext =
                new CareContextRepresentation(Faker().Random.Uuid().ToString(), Faker().Random.String());
            var expectedPatient = new PatientEnquiryRepresentation(
                patientId,
                name,
                new[] { unlinkedCareContext },
                new[] { Match.ConsentManagerUserId.ToString() });
            var transactionId  = Faker().Random.String();
            var patientRequest = new PatientEnquiry(patientId,
                                                    verifiedIdentifiers,
                                                    unverifiedIdentifiers,
                                                    name,
                                                    HipLibrary.Patient.Model.Gender.M,
                                                    2019);
            var discoveryRequest  = new DiscoveryRequest(patientRequest, RandomString(), transactionId, DateTime.Now);
            var sessionId         = Faker().Random.Hash();
            var linkedCareContext = new[] { alreadyLinked.ReferenceNumber };
            var testLinkAccounts  = new LinkedAccounts(patientId,
                                                       sessionId,
                                                       Faker().Random.Hash(),
                                                       It.IsAny <string>(),
                                                       linkedCareContext.ToList());
            var testPatient =
                new HipLibrary.Patient.Model.Patient
            {
                PhoneNumber  = phoneNumber,
                Identifier   = patientId,
                Gender       = Faker().PickRandom <HipLibrary.Patient.Model.Gender>(),
                Name         = name,
                CareContexts = new[]
                {
                    alreadyLinked,
                    unlinkedCareContext
                }
            };

            linkPatientRepository.Setup(e => e.GetLinkedCareContexts(patientId))
            .ReturnsAsync(new Tuple <IEnumerable <LinkedAccounts>, Exception>(
                              new List <LinkedAccounts> {
                testLinkAccounts
            },
                              null));
            patientRepository.Setup(x => x.PatientWith(testPatient.Identifier))
            .Returns(Option.Some(testPatient));

            var(discoveryResponse, error) = await patientDiscovery.PatientFor(discoveryRequest);

            discoveryResponse.Patient.Should().BeEquivalentTo(expectedPatient);
            discoveryRequestRepository.Verify(
                x => x.Add(It.Is <HipService.Discovery.Model.DiscoveryRequest>(
                               r => r.TransactionId == transactionId && r.ConsentManagerUserId == patientId)),
                Times.Once);
            error.Should().BeNull();
        }