initial commit
This commit is contained in:
@@ -0,0 +1,81 @@
|
||||
using Indotalent.ConfigBackEnd.Extensions;
|
||||
using Indotalent.Data.Entities;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace Indotalent.Infrastructure.Database.Demo;
|
||||
|
||||
public static class PatientContactSeeder
|
||||
{
|
||||
public static async Task GenerateDataAsync(AppDbContext context)
|
||||
{
|
||||
if (await context.PatientContact.AnyAsync()) return;
|
||||
|
||||
var firstNames = new string[]
|
||||
{
|
||||
"James", "Mary", "Robert", "Patricia", "John", "Jennifer",
|
||||
"Michael", "Linda", "David", "Elizabeth", "William", "Barbara",
|
||||
"Richard", "Susan", "Joseph", "Jessica", "Thomas", "Sarah",
|
||||
"Charles", "Karen"
|
||||
};
|
||||
|
||||
var lastNames = new string[]
|
||||
{
|
||||
"Smith", "Johnson", "Williams", "Brown", "Jones", "Garcia",
|
||||
"Miller", "Davis", "Rodriguez", "Martinez", "Hernandez", "Lopez",
|
||||
"Gonzalez", "Wilson", "Anderson", "Thomas", "Taylor", "Moore",
|
||||
"Jackson", "Martin"
|
||||
};
|
||||
|
||||
var relationships = new string[]
|
||||
{
|
||||
"Spouse", "Father", "Mother", "Sibling", "Child",
|
||||
"Emergency Contact", "Next of Kin", "Legal Guardian",
|
||||
"Primary Caregiver", "Partner", "Aunt", "Uncle",
|
||||
"Grandparent", "Cousin", "Friend"
|
||||
};
|
||||
|
||||
var emailDomains = new string[] { "gmail.com", "outlook.com", "yahoo.com", "icloud.com", "hotmail.com" };
|
||||
|
||||
var patientIds = await context.Patient.Select(x => x.Id).ToListAsync();
|
||||
var random = new Random();
|
||||
var entityName = nameof(PatientContact);
|
||||
|
||||
foreach (var patientId in patientIds)
|
||||
{
|
||||
for (int i = 0; i < 2; i++)
|
||||
{
|
||||
var firstName = GetRandomString(firstNames, random);
|
||||
var lastName = GetRandomString(lastNames, random);
|
||||
|
||||
var autoNo = await context.GenerateAutoNumberAsync(
|
||||
entityName: entityName,
|
||||
prefixTemplate: $"{entityName.ToShortNameConsonant(3)}/{{Year}}/"
|
||||
);
|
||||
|
||||
var contact = new PatientContact
|
||||
{
|
||||
Name = $"{firstName} {lastName}",
|
||||
AutoNumber = autoNo,
|
||||
PatientId = patientId,
|
||||
Title = GetRandomString(relationships, random),
|
||||
EmailAddress = $"{firstName.ToLower()}.{lastName.ToLower()}@{GetRandomString(emailDomains, random)}",
|
||||
PhoneNumber = GenerateRandomPhoneNumber(random)
|
||||
};
|
||||
|
||||
await context.PatientContact.AddAsync(contact);
|
||||
}
|
||||
}
|
||||
|
||||
await context.SaveChangesAsync();
|
||||
}
|
||||
|
||||
private static string GetRandomString(string[] array, Random random)
|
||||
{
|
||||
return array[random.Next(array.Length)];
|
||||
}
|
||||
|
||||
private static string GenerateRandomPhoneNumber(Random random)
|
||||
{
|
||||
return $"+1-{random.Next(200, 999)}-{random.Next(100, 999)}-{random.Next(1000, 9999)}";
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user