using Indotalent.ConfigBackEnd.Extensions; using Indotalent.Data.Entities; using Microsoft.EntityFrameworkCore; namespace Indotalent.Infrastructure.Database.Demo; public static class PatientSeeder { public static async Task GenerateDataAsync(AppDbContext context) { if (await context.Patient.AnyAsync()) return; var groups = await context.PatientGroup.Select(x => x.Id).ToArrayAsync(); var categories = await context.PatientCategory.Select(x => x.Id).ToArrayAsync(); var cities = new string[] { "New York", "Los Angeles", "Chicago", "Houston", "Phoenix", "Philadelphia", "Miami", "Seattle", "Austin", "Denver" }; var streets = new string[] { "Maple Street", "Oak Avenue", "Pine Lane", "Cedar Road", "Elm Street", "Washington Blvd", "Lakeview Drive", "Meadow Lane", "Park Avenue", "Sunset Blvd" }; var states = new string[] { "NY", "CA", "IL", "TX", "AZ", "PA", "FL", "WA", "CO", "MA" }; var zipCodes = new string[] { "10001", "90210", "60601", "77001", "85001", "19101", "33101", "98101", "73301", "80201" }; var phoneNumbers = new string[] { "212-555-0101", "310-555-0102", "312-555-0103", "713-555-0104", "602-555-0105", "305-555-0106" }; var emailDomains = new string[] { "gmail.com", "outlook.com", "icloud.com", "yahoo.com", "hotmail.com" }; var random = new Random(); var entityName = nameof(Patient); var patients = new List { new Patient { Name = "James Anderson" }, new Patient { Name = "Maria Garcia" }, new Patient { Name = "Robert Smith" }, new Patient { Name = "Linda Johnson" }, new Patient { Name = "Michael Williams" }, new Patient { Name = "Sarah Davis" }, new Patient { Name = "David Miller" }, new Patient { Name = "Jessica Wilson" }, new Patient { Name = "John Taylor" }, new Patient { Name = "Karen Moore" }, new Patient { Name = "Richard Anderson" }, new Patient { Name = "Nancy Thomas" }, new Patient { Name = "Charles Jackson" }, new Patient { Name = "Lisa White" }, new Patient { Name = "Joseph Harris" }, new Patient { Name = "Margaret Martin" }, new Patient { Name = "Thomas Thompson" }, new Patient { Name = "Sandra Garcia" }, new Patient { Name = "Christopher Martinez" }, new Patient { Name = "Betty Robinson" } }; foreach (var patient in patients) { var autoNo = await context.GenerateAutoNumberAsync( entityName: entityName, prefixTemplate: $"{entityName.ToShortNameConsonant(3)}/{{Year}}/" ); patient.AutoNumber = autoNo; patient.PatientGroupId = GetRandomValue(groups, random); patient.PatientCategoryId = GetRandomValue(categories, random); patient.City = GetRandomString(cities, random); patient.Street = GetRandomString(streets, random); patient.State = GetRandomString(states, random); patient.ZipCode = GetRandomString(zipCodes, random); patient.PhoneNumber = GetRandomString(phoneNumbers, random); patient.EmailAddress = $"{patient.Name?.Replace(" ", ".").ToLower()}@{GetRandomString(emailDomains, random)}"; await context.Patient.AddAsync(patient); } await context.SaveChangesAsync(); } private static T GetRandomValue(T[] array, Random random) { return array[random.Next(array.Length)]; } private static string GetRandomString(string[] array, Random random) { return array[random.Next(array.Length)]; } }