Esempio n. 1
0
        private async Task GivenLegacyUserHasPermissionsForTbServiceInHospital(string username, string tbServiceCode, Guid hospitalGuid)
        {
            _usernameToLegacyUserHospitalDict.Add(
                username,
                new List <MigrationLegacyUserHospital> {
                new MigrationLegacyUserHospital {
                    HospitalId = hospitalGuid
                }
            }
                );
            await _context.Hospital.AddAsync(new Hospital { HospitalId = hospitalGuid, TBService = new TBService {
                                                                Code = tbServiceCode
                                                            } });

            await _context.SaveChangesAsync();
        }
Esempio n. 2
0
        static async Task GenerateNotifications(NtbsContext context, bool addTreatmentEvents = false)
        {
            var numberOfNotifications = 3000;
            var rand      = new Random();
            var hospitals = (await context.Hospital.ToListAsync());

            var notificationsOperable = Builder <Notification> .CreateListOfSize(numberOfNotifications)
                                        .All()
                                        .With(n => n.NotificationId              = 0)
                                        .With(n => n.NotificationStatus          = NotificationStatus.Notified)
                                        .With(n => n.PatientDetails.GivenName    = Faker.Name.First())
                                        .With(n => n.PatientDetails.FamilyName   = Faker.Name.Last())
                                        .With(n => n.PatientDetails.NoFixedAbode = true)
                                        .With(n => n.TestData.HasTestCarriedOut  = false)
                                        .With(n => n.ClinicalDetails.Notes       = "UniqueBulkInsert")
                                        .With(n => n.GroupId = null)
                                        // Add randomised fields that Faker cannot generate
                                        .With(n => n.PatientDetails.Dob         = AddRandomDateTimeBetween1950And2000(rand))
                                        .With(n => n.PatientDetails.SexId       = rand.Next(1, 3))
                                        .With(n => n.PatientDetails.EthnicityId = 4)
                                        .With(n => n.PatientDetails.CountryId   = 235)
                                        .With(n => n.NotificationDate           = AddRandomDateTimeBetween2014And2017(rand))
                                        .With(n =>
            {
                var hospital = GetRandomHospital(rand, hospitals);
                n.HospitalDetails.TBServiceCode = hospital.TBServiceCode;
                n.HospitalDetails.HospitalId    = hospital.HospitalId;
                return(true);
            }
                                              )
                                        .With(n => n.HospitalDetails.HospitalId = hospitals.FirstOrDefault(h => h.TBServiceCode == n.HospitalDetails.TBServiceCode)?.HospitalId)
                                        .With(n => n.PatientDetails.NhsNumber   = AddRandomTestNhsNumber(rand))
                                        .With(n => n.NotificationSites          = new List <NotificationSite>
            {
                new NotificationSite
                {
                    SiteId = 1
                }
            })
                                        .With(n => n.ClinicalDetails.DiagnosisDate = new DateTime(2014, 1, 1))
                                        .With(n => n.DeletionReason = null);


            if (addTreatmentEvents)
            {
                notificationsOperable = await AddDataQualityTreatmentEvents(notificationsOperable, context);
            }

            var notifications = notificationsOperable.Build();

            context.AddRange(notifications);
            await context.SaveChangesAsync();
        }
        public async Task FiltersOutNotificationsWithTheAlertTypeAlreadyPresent()
        {
            // ARRANGE
            // We will use the birth country alert as a proxy for testing the common path ways of the
            // data quality repository
            // All seeded notifications will be eligible for this alert

            var notification1 = NotificationEligibleForCountryOfBirthDqAlert(NoAlertsName);

            var notification2 = NotificationEligibleForCountryOfBirthDqAlert(BirthCountryAlertName);

            notification2.Alerts = new List <Alert> {
                new DataQualityBirthCountryAlert()
            };

            var notification3 = NotificationEligibleForCountryOfBirthDqAlert(ClinicalDatesAlertName);

            notification3.Alerts = new List <Alert> {
                new DataQualityClinicalDatesAlert()
            };

            await _context.AddRangeAsync(notification1, notification2, notification3);

            await _context.SaveChangesAsync();

            var repo = new DataQualityRepository(_context);

            // ACT
            // Get all possible ones
            var notifications = await repo.GetNotificationsEligibleForDqBirthCountryAlertsAsync(100, 0);

            // ASSERT
            // Out of the 3 eligible notifications, 1 already has the alert
            Assert.True(notifications.Any(n => n.PatientDetails.FamilyName == NoAlertsName),
                        "Eligible notification with no other alerts not selected");
            Assert.True(notifications.Any(n => n.PatientDetails.FamilyName == ClinicalDatesAlertName),
                        "Eligible notification with only other alerts types not selected");
            Assert.Equal(2, notifications.Count);
        }
Esempio n. 4
0
        private async Task <Notification> GivenNotificationWithCaseManagerAndTbService(User caseManager, TBService tbService)
        {
            var notification = await _context.Notification.AddAsync(new Notification { NotificationId  = 6655,
                                                                                       HospitalDetails = new HospitalDetails
                                                                                       {
                                                                                           CaseManager = caseManager,
                                                                                           TBService   = tbService
                                                                                       } });

            await _context.SaveChangesAsync();

            return(notification.Entity);
        }
Esempio n. 5
0
        private async Task AddUserAndTbServices(User user, IList <TBService> tbServices)
        {
            user.IsCaseManager         = tbServices?.Any() ?? false;
            user.CaseManagerTbServices =
                tbServices?
                .Select(tbs => new CaseManagerTbService {
                TbService = tbs, CaseManager = user
            })
                .ToList();

            _context.User.Add(user);
            await _context.SaveChangesAsync();
        }
        public async Task <List <Notification> > AddLinkedNotificationsAsync(List <Notification> notifications)
        {
            if (notifications.Count > 1)
            {
                var group = new NotificationGroup();
                _context.NotificationGroup.Add(group);
                notifications.ForEach(n => n.Group = group);
            }

            _context.Notification.AddRange(notifications);
            _context.AddAuditCustomField(CustomFields.AuditDetails, NotificationAuditType.Imported);
            await _context.SaveChangesAsync();

            return(notifications);
        }