Skip to content

Commit 3a41258

Browse files
committed
Generator: Update national stats to 1M patients
1 parent 7df804e commit 3a41258

File tree

2 files changed

+30
-29
lines changed

2 files changed

+30
-29
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ data
55
release
66
index
77
snomed-index
8-
patient-data-for-import
8+
patient-data-for-import*
99
*.zip
1010
*.sh
1111
cpt-codes

generator/src/main/java/org/snomed/heathanalytics/datageneration/DemoPatientDataGenerator.java

Lines changed: 29 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -88,9 +88,12 @@ public void createPatients(int patientCount, File outputFile) throws IOException
8888
public void createLongitudinalPatients(File longitudinalNdJsonFile) throws IOException, ServiceException {
8989
long start = new Date().getTime();
9090

91-
int multiplier = 1_000;
91+
int ratePerCount = 100_000;
92+
int populationSize = 1_000_000;
93+
int multiplier = populationSize / ratePerCount;
9294

9395
// Model the stats we want the data to reflect
96+
// The numbers are incidence rate
9497
Map<Integer, Map<Long, Integer>> yearConceptCountMap = new HashMap<>();
9598
long asthma = 195967001;
9699
fillYears(yearConceptCountMap, 2000, asthma, 375, 400, 375, 350, 425, 400, 425, 400, 350, 325, 325, 300, 275, 225, 250, 225, 225, 200, 175, 175, 150);
@@ -106,44 +109,42 @@ public void createLongitudinalPatients(File longitudinalNdJsonFile) throws IOExc
106109
fillYears(yearConceptCountMap, 2000, diabetesType2, 225, 250, 250, 275, 275, 275, 275, 300, 325, 325, 350, 400, 350, 250, 225, 250, 275, 250, 250, 250, 275);
107110

108111
logger.info("******** Generating data for longitudinal patients ...");
112+
113+
List<Patient> allPatients = new ArrayList<>();
114+
for (long i = 0; i < populationSize; i++) {
115+
Patient patient = new Patient(i + 1 + "");
116+
int age = ThreadLocalRandom.current().nextInt(30, 85);
117+
patient.setDob(DateUtil.dateOfBirthFromAge(age));
118+
allPatients.add(patient);
119+
}
109120

121+
Iterator<Patient> patientIterator = allPatients.iterator();
110122
try (SequenceWriter patientWriter = objectMapper
111123
.writerFor(Patient.class)
112124
.withView(View.API.class)
113125
.withRootValueSeparator("\n")
114126
.writeValues(longitudinalNdJsonFile)) {
115127

116-
Map<Long, List<Patient>> disorderPatientPools = new HashMap<>();
117-
int id = 1;
118-
for (Map.Entry<Integer, Map<Long, Integer>> yearConceptCounts : yearConceptCountMap.entrySet()) {
119-
Integer year = yearConceptCounts.getKey();
120-
Map<Long, Integer> conceptCounts = yearConceptCounts.getValue();
121-
for (Map.Entry<Long, Integer> conceptCount : conceptCounts.entrySet()) {
122-
Long concept = conceptCount.getKey();
123-
int count = conceptCount.getValue() * multiplier;
124-
List<Patient> patientsWithDisorder = disorderPatientPools.computeIfAbsent(concept, i -> new ArrayList<>());
125-
while (patientsWithDisorder.size() < count) {
126-
Patient patient = new Patient(id++ + "");
127-
int age = ThreadLocalRandom.current().nextInt(30, 85);
128-
patient.setDob(DateUtil.dateOfBirthFromAge(age));
129-
patientsWithDisorder.add(patient);
130-
}
131-
GregorianCalendar gregorianCalendar = new GregorianCalendar(year, 1, 1);
128+
for (Map.Entry<Integer, Map<Long, Integer>> yearConceptIncidenceCounts : yearConceptCountMap.entrySet()) {
129+
Integer year = yearConceptIncidenceCounts.getKey();
130+
Map<Long, Integer> conceptIncidenceCounts = yearConceptIncidenceCounts.getValue();
131+
for (Map.Entry<Long, Integer> conceptIncidenceCount : conceptIncidenceCounts.entrySet()) {
132+
Long concept = conceptIncidenceCount.getKey();
133+
int count = conceptIncidenceCount.getValue() * multiplier;
134+
GregorianCalendar gregorianCalendar = new GregorianCalendar(year, Calendar.JANUARY, 1);
132135
for (int i = 0; i < count; i++) {
133-
patientsWithDisorder.get(i).addEncounter(new ClinicalEncounter(gregorianCalendar, concepts.selectRandomDescendantOf(concept.toString())));
136+
patientIterator.next().addEncounter(new ClinicalEncounter(gregorianCalendar, concepts.selectRandomDescendantOf(concept.toString())));
134137
}
135138
}
136139
}
137-
long total = 0;
138-
for (List<Patient> list : disorderPatientPools.values()) {
139-
total += list.size();
140-
}
141-
logger.info("Saving {} patients", new DecimalFormat( "#,###,###" ).format(total));
142-
for (List<Patient> patientSet : disorderPatientPools.values()) {
143-
for (List<Patient> batch : Iterables.partition(patientSet, 10_000)) {
144-
patientWriter.writeAll(batch);
145-
System.out.print(".");
146-
}
140+
// long total = 0;
141+
// for (List<Patient> list : disorderPatientPools.values()) {
142+
// total += list.size();
143+
// }
144+
logger.info("Saving {} patients", new DecimalFormat( "#,###,###" ).format(allPatients.size()));
145+
for (List<Patient> batch : Iterables.partition(allPatients, 10_000)) {
146+
patientWriter.writeAll(batch);
147+
System.out.print(".");
147148
}
148149
patientWriter.flush();
149150
System.out.println();

0 commit comments

Comments
 (0)