Search in sources :

Example 6 with DefaultRandomNumberGenerator

use of org.mitre.synthea.helpers.DefaultRandomNumberGenerator in project synthea by synthetichealth.

the class GeneratorTest method testUpdateAfterCreation.

@Test
public void testUpdateAfterCreation() throws Exception {
    // Get 100 people
    Generator.GeneratorOptions opts = new Generator.GeneratorOptions();
    opts.population = 1;
    opts.minAge = 50;
    opts.maxAge = 100;
    Generator generator = new Generator(opts);
    final int NUM_RECS = 10;
    Person[] people = new Person[NUM_RECS];
    for (int i = 0; i < NUM_RECS; i++) {
        long personSeed = UUID.randomUUID().getMostSignificantBits() & Long.MAX_VALUE;
        RandomNumberGenerator random = new DefaultRandomNumberGenerator(personSeed);
        Map<String, Object> demoAttributes = generator.randomDemographics(random);
        people[i] = generator.createPerson(personSeed, demoAttributes);
        generator.recordPerson(people[i], i);
    }
    // Update them for 10 years in the future
    generator.stop = generator.stop + Utilities.convertTime("years", 10);
    for (Person p : people) {
        generator.updatePerson(p);
    }
}
Also used : DefaultRandomNumberGenerator(org.mitre.synthea.helpers.DefaultRandomNumberGenerator) RandomNumberGenerator(org.mitre.synthea.helpers.RandomNumberGenerator) DefaultRandomNumberGenerator(org.mitre.synthea.helpers.DefaultRandomNumberGenerator) Person(org.mitre.synthea.world.agents.Person) DefaultRandomNumberGenerator(org.mitre.synthea.helpers.DefaultRandomNumberGenerator) RandomNumberGenerator(org.mitre.synthea.helpers.RandomNumberGenerator) Test(org.junit.Test)

Example 7 with DefaultRandomNumberGenerator

use of org.mitre.synthea.helpers.DefaultRandomNumberGenerator 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.populationRandom = new DefaultRandomNumberGenerator(options.seed);
    this.clinicianRandom = new DefaultRandomNumberGenerator(options.clinicianSeed);
    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, this.clinicianRandom);
    // 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());
    }
}
Also used : TypeToken(com.google.gson.reflect.TypeToken) Location(org.mitre.synthea.world.geography.Location) ObjectInputStream(java.io.ObjectInputStream) Costs(org.mitre.synthea.world.concepts.Costs) StringUtils(org.apache.commons.lang3.StringUtils) Demographics(org.mitre.synthea.world.geography.Demographics) Person(org.mitre.synthea.world.agents.Person) VitalSign(org.mitre.synthea.world.concepts.VitalSign) TransitionMetrics(org.mitre.synthea.helpers.TransitionMetrics) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Gson(com.google.gson.Gson) Map(java.util.Map) Path(java.nio.file.Path) RandomNumberGenerator(org.mitre.synthea.helpers.RandomNumberGenerator) Predicate(java.util.function.Predicate) UUID(java.util.UUID) Collectors(java.util.stream.Collectors) CDWExporter(org.mitre.synthea.export.CDWExporter) FileNotFoundException(java.io.FileNotFoundException) Executors(java.util.concurrent.Executors) Utilities(org.mitre.synthea.helpers.Utilities) HealthInsuranceModule(org.mitre.synthea.modules.HealthInsuranceModule) List(java.util.List) Type(java.lang.reflect.Type) LifecycleModule(org.mitre.synthea.modules.LifecycleModule) FilenameFilter(java.io.FilenameFilter) GrowthDataErrorsEditor(org.mitre.synthea.editors.GrowthDataErrorsEditor) IOCase(org.apache.commons.io.IOCase) DefaultRandomNumberGenerator(org.mitre.synthea.helpers.DefaultRandomNumberGenerator) HashMap(java.util.HashMap) FixedRecordGroup(org.mitre.synthea.input.FixedRecordGroup) ObjectOutputStream(java.io.ObjectOutputStream) LinkedList(java.util.LinkedList) ExecutorService(java.util.concurrent.ExecutorService) Config(org.mitre.synthea.helpers.Config) Iterator(java.util.Iterator) EncounterModule(org.mitre.synthea.modules.EncounterModule) FileOutputStream(java.io.FileOutputStream) FileInputStream(java.io.FileInputStream) Payer(org.mitre.synthea.world.agents.Payer) File(java.io.File) TimeUnit(java.util.concurrent.TimeUnit) Provider(org.mitre.synthea.world.agents.Provider) Exporter(org.mitre.synthea.export.Exporter) WildcardFileFilter(org.apache.commons.io.filefilter.WildcardFileFilter) FileReader(java.io.FileReader) DeathModule(org.mitre.synthea.modules.DeathModule) Collections(java.util.Collections) FixedRecord(org.mitre.synthea.input.FixedRecord) Path(java.nio.file.Path) DefaultRandomNumberGenerator(org.mitre.synthea.helpers.DefaultRandomNumberGenerator) HashMap(java.util.HashMap) FileNotFoundException(java.io.FileNotFoundException) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) TransitionMetrics(org.mitre.synthea.helpers.TransitionMetrics) GrowthDataErrorsEditor(org.mitre.synthea.editors.GrowthDataErrorsEditor) Location(org.mitre.synthea.world.geography.Location)

Aggregations

DefaultRandomNumberGenerator (org.mitre.synthea.helpers.DefaultRandomNumberGenerator)7 Test (org.junit.Test)5 RandomNumberGenerator (org.mitre.synthea.helpers.RandomNumberGenerator)5 Person (org.mitre.synthea.world.agents.Person)3 File (java.io.File)2 FileReader (java.io.FileReader)2 FhirContext (ca.uhn.fhir.context.FhirContext)1 FhirValidator (ca.uhn.fhir.validation.FhirValidator)1 SingleValidationMessage (ca.uhn.fhir.validation.SingleValidationMessage)1 ValidationResult (ca.uhn.fhir.validation.ValidationResult)1 Table (com.google.common.collect.Table)1 Gson (com.google.gson.Gson)1 TypeToken (com.google.gson.reflect.TypeToken)1 BufferedReader (java.io.BufferedReader)1 FileInputStream (java.io.FileInputStream)1 FileNotFoundException (java.io.FileNotFoundException)1 FileOutputStream (java.io.FileOutputStream)1 FilenameFilter (java.io.FilenameFilter)1 IOException (java.io.IOException)1 ObjectInputStream (java.io.ObjectInputStream)1