Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions data-replicator/NHSNumberGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ public static string GenerateNHSNumber()
{
// Generate 9 random digits
Random random = new Random();
nineDigits = "";
for (int i = 0; i < 9; i++)
nineDigits = "9";
for (int i = 1; i < 9; i++)
{
nineDigits += random.Next(0, 10).ToString();
}
Expand Down
24 changes: 24 additions & 0 deletions data-replicator/PDSPatient.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
namespace data_replicator;

internal class PDSPatient
{
public string UNIQUE_ID { get; set; }
public string NHS_NO { get; set; }
public string DOB { get; set; }
public string DOD { get; set; }
public string FAMILY_NAME { get; set; }
public string GIVEN_NAME { get; set; }
public string OTHER_GIVEN_NAME { get; set; }
public string TITLE { get; set; }
public string GENDER { get; set; }
public string ADDR1 { get; set; }
public string ADDR2 { get; set; }
public string ADDR3 { get; set; }
public string ADDR4 { get; set; }
public string ADDR5 { get; set; }
public string POST_CODE { get; set; }
public string SENSITIVE_FLAG { get; set; }
public string GPP { get; set; }
public string SCENARIO { get; set; }

}
94 changes: 77 additions & 17 deletions data-replicator/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,14 @@ static T GetRandomRecord<T>(T[] array)
return array[next];
}

private static void LoadPdsPatients()
{
using var reader = new StreamReader("TD005777-34389.csv");
using var csv = new CsvReader(reader, CultureInfo.InvariantCulture);

_pdsPatientEnumerator = csv.GetRecords<PDSPatient>().ToList().GetEnumerator();
}

private static string FindFilePath(string path, string type)
{
var files = Directory.GetFiles(path, "*.csv");
Expand Down Expand Up @@ -82,6 +90,7 @@ private static string FindFilePath(string path, string type)
private static dynamic[] CareRecord_Problem;
private static dynamic[] Prescribing_DrugRecord;
private static dynamic[] Prescribing_IssueRecord;
private static IEnumerator<PDSPatient> _pdsPatientEnumerator;

private static IEnumerable<object> GetEmisObjects(ProgressBar progressBar, int orgNumber, int targetPatientCount)
{
Expand All @@ -96,13 +105,15 @@ private static IEnumerable<object> GetEmisObjects(ProgressBar progressBar, int o

string orgGuid = Guid.NewGuid().ToString();

string odsCode = $"ODS{orgGuid[..5]}";

yield return
new Organisation
{
OrganisationGuid = orgGuid,
CDB = GetRandomValue(Admin_Organisation, o => o.CDB),
OrganisationName = GetRandomValue(Admin_Organisation, o => o.OrganisationName),
ODSCode = GetRandomValue(Admin_Organisation, o => o.ODSCode),
ODSCode = odsCode,
ParentOrganisationGuid = GetRandomValue(Admin_Organisation, o => o.ParentOrganisationGuid),
CCGOrganisationGuid = GetRandomValue(Admin_Organisation, o => o.CCGOrganisationGuid),
OrganisationType = GetRandomValue(Admin_Organisation, o => o.OrganisationType),
Expand Down Expand Up @@ -153,24 +164,10 @@ private static IEnumerable<object> GetEmisObjects(ProgressBar progressBar, int o
PatientGuid = patientGuid,
OrganisationGuid = orgGuid,
UsualGpUserInRoleGuid = GetRandomValue<UserInRole>(userInRoleArray, o => o.UserInRoleGuid),
Sex = GetRandomValue(Admin_Patient, o => o.Sex),
DateOfBirth = GetRandomValue(Admin_Patient, o => o.DateOfBirth),
DateOfDeath = GetRandomValue(Admin_Patient, o => o.DateOfDeath),
Title = GetRandomValue(Admin_Patient, o => o.Title),
GivenName = GetRandomValue(Admin_Patient, o => o.GivenName),
MiddleNames = GetRandomValue(Admin_Patient, o => o.MiddleNames),
Surname = GetRandomValue(Admin_Patient, o => o.Surname),
DateOfRegistration = GetRandomValue(Admin_Patient, o => o.DateOfRegistration),
NhsNumber = NHSNumberGenerator.GenerateNHSNumber(),
PatientNumber = patientIndex.ToString(),
PatientTypeDescription = GetRandomValue(Admin_Patient, o => o.PatientTypeDescription),
DummyType = GetRandomValue(Admin_Patient, o => o.DummyType),
HouseNameFlatNumber = GetRandomValue(Admin_Patient, o => o.HouseNameFlatNumber),
NumberAndStreet = GetRandomValue(Admin_Patient, o => o.NumberAndStreet),
Village = GetRandomValue(Admin_Patient, o => o.Village),
Town = GetRandomValue(Admin_Patient, o => o.Town),
County = GetRandomValue(Admin_Patient, o => o.County),
Postcode = GetRandomValue(Admin_Patient, o => o.Postcode),
ResidentialInstituteCode = GetRandomValue(Admin_Patient, o => o.ResidentialInstituteCode),
NHSNumberStatus = GetRandomValue(Admin_Patient, o => o.NHSNumberStatus),
CarerName = GetRandomValue(Admin_Patient, o => o.CarerName),
Expand All @@ -187,10 +184,71 @@ private static IEnumerable<object> GetEmisObjects(ProgressBar progressBar, int o
ExternalUsualGP = GetRandomValue(Admin_Patient, o => o.ExternalUsualGP),
ExternalUsualGPOrganisation = GetRandomValue(Admin_Patient, o => o.ExternalUsualGPOrganisation),
ContactComments = GetRandomValue(Admin_Patient, o => o.ContactComments),
ProcessingId = GetRandomValue(Admin_Patient, o => o.ProcessingId),

ProcessingId = GetRandomValue(Admin_Patient, o => o.ProcessingId)
};

if (_pdsPatientEnumerator.MoveNext())
{
// We will use a test PDS patient

string ParseSex(string text)
{
return text switch
{
"Male" => "M",
"Female" => "F",
_ => throw new NotImplementedException()
};
}

string ParseDate(string text)
{
if (text == "")
return "";

var date = DateTime.Parse(text, new CultureInfo("en-GB"));

return date.ToString("yyyy-MM-dd");
}

if (_pdsPatientEnumerator.Current.GENDER == "Indeterminate" || _pdsPatientEnumerator.Current.GENDER == "Not known")
continue; // We can't code this gender for EMIS systems, so just skip the patient.

patient.Sex = ParseSex(_pdsPatientEnumerator.Current.GENDER);
patient.DateOfBirth = ParseDate(_pdsPatientEnumerator.Current.DOB);
patient.DateOfDeath = ParseDate(_pdsPatientEnumerator.Current.DOD);
patient.Title = _pdsPatientEnumerator.Current.TITLE;
patient.GivenName = _pdsPatientEnumerator.Current.GIVEN_NAME;
patient.MiddleNames = GetRandomValue(Admin_Patient, o => o.MiddleNames);
patient.Surname = _pdsPatientEnumerator.Current.FAMILY_NAME;
patient.NhsNumber = _pdsPatientEnumerator.Current.NHS_NO;
patient.HouseNameFlatNumber = _pdsPatientEnumerator.Current.ADDR1;
patient.NumberAndStreet = _pdsPatientEnumerator.Current.ADDR2;
patient.Village = _pdsPatientEnumerator.Current.ADDR3;
patient.Town = _pdsPatientEnumerator.Current.ADDR4;
patient.County = _pdsPatientEnumerator.Current.ADDR5;
patient.Postcode = _pdsPatientEnumerator.Current.POST_CODE;
}
else
{
// We will generate a synthetic patient based on existing test data.

patient.Sex = GetRandomValue(Admin_Patient, o => o.Sex);
patient.DateOfBirth = GetRandomValue(Admin_Patient, o => o.DateOfBirth);
patient.DateOfDeath = GetRandomValue(Admin_Patient, o => o.DateOfDeath);
patient.Title = GetRandomValue(Admin_Patient, o => o.Title);
patient.GivenName = GetRandomValue(Admin_Patient, o => o.GivenName);
patient.MiddleNames = GetRandomValue(Admin_Patient, o => o.MiddleNames);
patient.Surname = GetRandomValue(Admin_Patient, o => o.Surname);
patient.NhsNumber = NHSNumberGenerator.GenerateNHSNumber();
patient.HouseNameFlatNumber = GetRandomValue(Admin_Patient, o => o.HouseNameFlatNumber);
patient.NumberAndStreet = GetRandomValue(Admin_Patient, o => o.NumberAndStreet);
patient.Village = GetRandomValue(Admin_Patient, o => o.Village);
patient.Town = GetRandomValue(Admin_Patient, o => o.Town);
patient.County = GetRandomValue(Admin_Patient, o => o.County);
patient.Postcode = GetRandomValue(Admin_Patient, o => o.Postcode);
}

yield return patient;

patientList.Add(patient);
Expand Down Expand Up @@ -540,6 +598,8 @@ private static void WriteRecords(string path, IEnumerable<object> records, strin
Prescribing_IssueRecord_csv.WriteHeader(typeof(IssueRecord));
Prescribing_IssueRecord_csv.NextRecord();

LoadPdsPatients();

int rowCounter = 0;

foreach (var record in records)
Expand Down
Loading