use of org.mitre.synthea.world.geography.Location in project synthea by synthetichealth.
the class GeneratorTest method testGeneratePeopleByLocation.
@Test
public void testGeneratePeopleByLocation() throws Exception {
String testStateDefault = Config.get("test_state.default", "Massachusetts");
String testTownDefault = Config.get("test_town.default", "Bedford");
String testStateAlt = Config.get("test_state.alternative", "California");
String testTownAlt = Config.get("test_town.alternative", "South Gate");
int numberOfPeople = 2;
Generator.GeneratorOptions opts = new Generator.GeneratorOptions();
opts.population = numberOfPeople;
opts.state = testStateAlt;
opts.city = testTownAlt;
Generator generator = new Generator(opts);
Location location = new Location(testStateAlt, testTownAlt);
List<String> zipCodes = location.getZipCodes(testTownAlt);
for (int i = 0; i < numberOfPeople; i++) {
Person p = generator.generatePerson(i);
assertEquals(testTownAlt, p.attributes.get(Person.CITY));
assertEquals(testStateAlt, p.attributes.get(Person.STATE));
assertTrue(zipCodes.contains(p.attributes.get(Person.ZIP)));
}
opts = new Generator.GeneratorOptions();
opts.population = numberOfPeople;
opts.state = testStateDefault;
opts.city = testTownDefault;
generator = new Generator(opts);
location = new Location(testStateDefault, testTownDefault);
zipCodes = location.getZipCodes(testTownDefault);
for (int i = 0; i < numberOfPeople; i++) {
Person p = generator.generatePerson(i);
assertEquals(testTownDefault, p.attributes.get(Person.CITY));
assertEquals(testStateDefault, p.attributes.get(Person.STATE));
assertTrue(zipCodes.contains(p.attributes.get(Person.ZIP)));
}
}
use of org.mitre.synthea.world.geography.Location in project synthea by synthetichealth.
the class Generator method pickFixedDemographics.
/**
* Pick a person's demographics based on their FixedRecords.
* @param index The index to use.
* @param random Random object.
*/
private Map<String, Object> pickFixedDemographics(int index, Random random) {
// Get the first FixedRecord from the current RecordGroup
FixedRecordGroup recordGroup = this.recordGroups.get(index);
FixedRecord fr = recordGroup.records.get(0);
// Get the city from the location in the fixed record.
this.location = new Location(fr.state, recordGroup.getSafeCity());
Demographics city = this.location.randomCity(random);
// Pick the rest of the demographics based on the location of the fixed record.
Map<String, Object> demoAttributes = pickDemographics(random, city);
// Overwrite the person's attributes with the FixedRecord.
demoAttributes.put(Person.BIRTHDATE, recordGroup.getValidBirthdate());
demoAttributes.put(Person.BIRTH_CITY, city.city);
String g = fr.gender;
if (g.equalsIgnoreCase("None") || StringUtils.isBlank(g)) {
g = "F";
}
demoAttributes.put(Person.GENDER, g);
// Give the person their FixedRecordGroup of FixedRecords.
demoAttributes.put(Person.RECORD_GROUP, recordGroup);
demoAttributes.put(Person.LINK_ID, recordGroup.linkId);
// Return the Demographic Attributes of the current person.
return demoAttributes;
}
use of org.mitre.synthea.world.geography.Location in project synthea by synthetichealth.
the class Generator method init.
private void init() {
if (options.state == null) {
options.state = DEFAULT_STATE;
}
int stateIndex = Location.getIndex(options.state);
if (Config.getAsBoolean("exporter.cdw.export")) {
CDWExporter.getInstance().setKeyStart((stateIndex * 1_000_000) + 1);
}
this.random = new Random(options.seed);
this.timestep = Long.parseLong(Config.get("generate.timestep"));
this.stop = options.endTime;
this.referenceTime = options.referenceTime;
this.location = new Location(options.state, options.city);
this.logLevel = Config.get("generate.log_patients.detail", "simple");
this.onlyDeadPatients = Config.getAsBoolean("generate.only_dead_patients");
this.onlyAlivePatients = Config.getAsBoolean("generate.only_alive_patients");
// If both values are set to true, then they are both set back to the default
if (this.onlyDeadPatients && this.onlyAlivePatients) {
Config.set("generate.only_dead_patients", "false");
Config.set("generate.only_alive_patients", "false");
this.onlyDeadPatients = false;
this.onlyAlivePatients = false;
}
try {
this.maxAttemptsToKeepPatient = Long.parseLong(Config.get("generate.max_attempts_to_keep_patient", "1000"));
if (this.maxAttemptsToKeepPatient == 0) {
// set it to null to make the check more clear
this.maxAttemptsToKeepPatient = null;
}
} catch (Exception e) {
this.maxAttemptsToKeepPatient = null;
}
this.onlyVeterans = Config.getAsBoolean("generate.veteran_population_override");
this.totalGeneratedPopulation = new AtomicInteger(0);
this.stats = Collections.synchronizedMap(new HashMap<String, AtomicInteger>());
this.modulePredicate = getModulePredicate();
stats.put("alive", new AtomicInteger(0));
stats.put("dead", new AtomicInteger(0));
if (Config.getAsBoolean("generate.track_detailed_transition_metrics", false)) {
this.metrics = new TransitionMetrics();
}
// initialize hospitals
Provider.loadProviders(location, options.clinicianSeed);
// Initialize Payers
Payer.loadPayers(location);
// ensure modules load early
if (options.localModuleDir != null) {
Module.addModules(options.localModuleDir);
}
List<String> coreModuleNames = getModuleNames(Module.getModules(path -> false));
List<String> moduleNames = getModuleNames(Module.getModules(modulePredicate));
if (options.keepPatientsModulePath != null) {
try {
Path path = options.keepPatientsModulePath.toPath().toAbsolutePath();
this.keepPatientsModule = Module.loadFile(path, false, null, true);
} catch (Exception e) {
throw new ExceptionInInitializerError(e);
}
}
// ensure cost data loads early
Costs.loadCostData();
String locationName;
if (options.city == null) {
locationName = options.state;
} else {
locationName = options.city + ", " + options.state;
}
System.out.println("Running with options:");
System.out.println(String.format("Population: %d\nSeed: %d\nProvider Seed:%d\nReference Time: %d\nLocation: %s", options.population, options.seed, options.clinicianSeed, options.referenceTime, locationName));
System.out.println(String.format("Min Age: %d\nMax Age: %d", options.minAge, options.maxAge));
if (options.gender != null) {
System.out.println(String.format("Gender: %s", options.gender));
}
if (options.enabledModules != null) {
moduleNames.removeAll(coreModuleNames);
moduleNames.sort(String::compareToIgnoreCase);
System.out.println("Modules: " + String.join("\n & ", moduleNames));
System.out.println(String.format(" > [%d loaded]", moduleNames.size()));
}
if (Config.getAsBoolean("growtherrors", false)) {
HealthRecordEditors hrm = HealthRecordEditors.getInstance();
hrm.registerEditor(new GrowthDataErrorsEditor());
}
}
use of org.mitre.synthea.world.geography.Location in project synthea by synthetichealth.
the class LifecycleModule method birth.
/**
* For unto us a child is born.
* @param person The baby.
* @param time The time of birth.
*/
public static void birth(Person person, long time) {
Map<String, Object> attributes = person.attributes;
attributes.put(Person.ID, person.randUUID().toString());
attributes.put(Person.BIRTHDATE, time);
String gender = (String) attributes.get(Person.GENDER);
String language = (String) attributes.get(Person.FIRST_LANGUAGE);
String firstName = Names.fakeFirstName(gender, language, person);
String lastName = Names.fakeLastName(language, person);
attributes.put(Person.FIRST_NAME, firstName);
attributes.put(Person.LAST_NAME, lastName);
attributes.put(Person.NAME, firstName + " " + lastName);
String motherFirstName = Names.fakeFirstName("F", language, person);
String motherLastName = Names.fakeLastName(language, person);
attributes.put(Person.NAME_MOTHER, motherFirstName + " " + motherLastName);
String fatherFirstName = Names.fakeFirstName("M", language, person);
// this is anglocentric where the baby gets the father's last name
attributes.put(Person.NAME_FATHER, fatherFirstName + " " + lastName);
double prevalenceOfTwins = (double) BiometricsConfig.get("lifecycle.prevalence_of_twins", 0.02);
if ((person.rand() < prevalenceOfTwins)) {
attributes.put(Person.MULTIPLE_BIRTH_STATUS, person.randInt(3) + 1);
}
String phoneNumber = "555-" + ((person.randInt(999 - 100 + 1) + 100)) + "-" + ((person.randInt(9999 - 1000 + 1) + 1000));
attributes.put(Person.TELECOM, phoneNumber);
boolean hasStreetAddress2 = person.rand() < 0.5;
attributes.put(Person.ADDRESS, Names.fakeAddress(hasStreetAddress2, person));
// If using FixedRecords, overwrite the person's attributes with the FixedRecord attributes.
if (person.attributes.get(Person.RECORD_GROUP) != null) {
FixedRecordGroup recordGroup = (FixedRecordGroup) person.attributes.get(Person.RECORD_GROUP);
FixedRecord fr = recordGroup.records.get(0);
attributes.putAll(fr.getFixedRecordAttributes());
}
String ssn = "999-" + ((person.randInt(99 - 10 + 1) + 10)) + "-" + ((person.randInt(9999 - 1000 + 1) + 1000));
attributes.put(Person.IDENTIFIER_SSN, ssn);
String city = (String) attributes.get(Person.CITY);
Location location = (Location) attributes.get(Person.LOCATION);
if (location != null) {
// should never happen in practice, but can happen in unit tests
location.assignPoint(person, city);
person.attributes.put(Person.ZIP, location.getZipCode(city, person));
String[] birthPlace;
if ("english".equalsIgnoreCase((String) attributes.get(Person.FIRST_LANGUAGE))) {
birthPlace = location.randomBirthPlace(person);
} else {
birthPlace = location.randomBirthplaceByLanguage(person, (String) person.attributes.get(Person.FIRST_LANGUAGE));
}
attributes.put(Person.BIRTH_CITY, birthPlace[0]);
attributes.put(Person.BIRTH_STATE, birthPlace[1]);
attributes.put(Person.BIRTH_COUNTRY, birthPlace[2]);
// For CSV exports so we don't break any existing schemas
attributes.put(Person.BIRTHPLACE, birthPlace[3]);
}
attributes.put(Person.ACTIVE_WEIGHT_MANAGEMENT, false);
// TODO: Why are the percentiles a vital sign? Sounds more like an attribute?
double heightPercentile = person.rand();
PediatricGrowthTrajectory pgt = new PediatricGrowthTrajectory(person.seed, time);
double weightPercentile = pgt.reverseWeightPercentile(gender, heightPercentile);
person.setVitalSign(VitalSign.HEIGHT_PERCENTILE, heightPercentile);
person.setVitalSign(VitalSign.WEIGHT_PERCENTILE, weightPercentile);
person.attributes.put(Person.GROWTH_TRAJECTORY, pgt);
// Temporarily generate a mother
Person mother = new Person(person.randLong());
mother.attributes.put(Person.GENDER, "F");
mother.attributes.put("pregnant", true);
mother.attributes.put(Person.RACE, person.attributes.get(Person.RACE));
mother.attributes.put(Person.ETHNICITY, person.attributes.get(Person.ETHNICITY));
mother.attributes.put(BirthStatistics.BIRTH_SEX, person.attributes.get(Person.GENDER));
BirthStatistics.setBirthStatistics(mother, time);
person.setVitalSign(VitalSign.HEIGHT, // cm
(double) mother.attributes.get(BirthStatistics.BIRTH_HEIGHT));
person.setVitalSign(VitalSign.WEIGHT, // kg
(double) mother.attributes.get(BirthStatistics.BIRTH_WEIGHT));
// cm
person.setVitalSign(VitalSign.HEAD, childHeadCircumference(person, time));
attributes.put(AGE, 0);
attributes.put(AGE_MONTHS, 0);
boolean isRHNeg = person.rand() < 0.15;
attributes.put("RH_NEG", isRHNeg);
double adherenceBaseline = Config.getAsDouble("lifecycle.adherence.baseline", 0.05);
person.attributes.put(ADHERENCE_PROBABILITY, adherenceBaseline);
// set initial height and weight from percentiles
grow(person, time);
// Set initial values for many vital signs.
calculateVitalSigns(person, time);
String orientation = sexualOrientationData.next(person);
attributes.put(Person.SEXUAL_ORIENTATION, orientation);
// Setup vital signs which follow the generator approach
setupVitalSignGenerators(person);
}
use of org.mitre.synthea.world.geography.Location in project synthea by synthetichealth.
the class PayerFinderTest method onePayerRandom.
@Test
public void onePayerRandom() {
Config.set("generate.payers.selection_behavior", "random");
Payer.clear();
Payer.loadPayers(new Location((String) person.attributes.get(Person.STATE), null));
PayerFinderRandom finder = new PayerFinderRandom();
Payer payer = finder.find(Payer.getPrivatePayers(), person, null, 0L);
assertNotNull(payer);
assertNotEquals("NO_INSURANCE", payer.getName());
}
Aggregations