@@ -88,9 +88,12 @@ public void createPatients(int patientCount, File outputFile) throws IOException
88
88
public void createLongitudinalPatients (File longitudinalNdJsonFile ) throws IOException , ServiceException {
89
89
long start = new Date ().getTime ();
90
90
91
- int multiplier = 1_000 ;
91
+ int ratePerCount = 100_000 ;
92
+ int populationSize = 1_000_000 ;
93
+ int multiplier = populationSize / ratePerCount ;
92
94
93
95
// Model the stats we want the data to reflect
96
+ // The numbers are incidence rate
94
97
Map <Integer , Map <Long , Integer >> yearConceptCountMap = new HashMap <>();
95
98
long asthma = 195967001 ;
96
99
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
106
109
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 );
107
110
108
111
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
+ }
109
120
121
+ Iterator <Patient > patientIterator = allPatients .iterator ();
110
122
try (SequenceWriter patientWriter = objectMapper
111
123
.writerFor (Patient .class )
112
124
.withView (View .API .class )
113
125
.withRootValueSeparator ("\n " )
114
126
.writeValues (longitudinalNdJsonFile )) {
115
127
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 );
132
135
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 ())));
134
137
}
135
138
}
136
139
}
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 ("." );
147
148
}
148
149
patientWriter .flush ();
149
150
System .out .println ();
0 commit comments