Exemplo n.º 1
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();
        }