Search in sources :

Example 1 with GeneratorOptions

use of org.mitre.synthea.engine.Generator.GeneratorOptions in project synthea by synthetichealth.

the class PersonTest method testPersonCcdaRecreation.

@Test()
public void testPersonCcdaRecreation() throws Exception {
    TestHelper.loadTestProperties();
    TestHelper.exportOff();
    Generator.DEFAULT_STATE = Config.get("test_state.default", "Massachusetts");
    Config.set("exporter.ccda.export", "true");
    SimpleDateFormat format = new SimpleDateFormat("YYYYMMDD");
    format.setTimeZone(TimeZone.getTimeZone("UTC"));
    GeneratorOptions options = new GeneratorOptions();
    options.clinicianSeed = 9L;
    options.seed = 9L;
    options.referenceTime = format.parse("20200704").getTime();
    options.overflow = false;
    Generator generator = new Generator(options);
    List<List<String>> fileContents = new ArrayList<>();
    // the file names should be identical
    for (int i = 0; i < 2; i++) {
        File tempOutputFolder = tempFolder.newFolder();
        Config.set("exporter.baseDirectory", tempOutputFolder.toString());
        generator.generatePerson(0, 42L);
        // Check that the output files exist
        File expectedExportFolder = tempOutputFolder.toPath().resolve("ccda").toFile();
        assertTrue(expectedExportFolder.exists() && expectedExportFolder.isDirectory());
        for (File txtFile : expectedExportFolder.listFiles()) {
            if (!txtFile.getName().endsWith(".xml")) {
                continue;
            }
            fileContents.add(Files.readAllLines(txtFile.toPath()));
        }
    }
    // Check that there are exactly two files
    assertEquals("Expected 2 files, found " + fileContents.size(), 2, fileContents.size());
    // Check that the two files are identical
    for (int i = 0; i < fileContents.get(0).size(); i++) {
        assertEquals(fileContents.get(0).get(i), fileContents.get(1).get(i));
    }
}
Also used : GeneratorOptions(org.mitre.synthea.engine.Generator.GeneratorOptions) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) SimpleDateFormat(java.text.SimpleDateFormat) File(java.io.File) Generator(org.mitre.synthea.engine.Generator) Test(org.junit.Test)

Example 2 with GeneratorOptions

use of org.mitre.synthea.engine.Generator.GeneratorOptions in project synthea by synthetichealth.

the class FixedRecordTest method setup.

/**
 * Configure settings across these tests.
 * @throws Exception on test configuration loading errors.
 */
@Before
public void setup() {
    Generator.DEFAULT_STATE = Config.get("test_state.default", "Massachusetts");
    Config.set("generate.only_dead_patients", "false");
    Config.set("exporter.split_records", "true");
    Provider.clear();
    Payer.clear();
    // Create a generator with the preset fixed demographics test file.
    GeneratorOptions go = new GeneratorOptions();
    go.fixedRecordPath = new File("src/test/resources/fixed_demographics/fixed_demographics_test.json");
    // Examples are based on Colorado.
    go.state = "Colorado";
    // Should be overwritten by number of patients in input file.
    go.population = 100;
    generator = new Generator(go);
    // Allows us to access patients within generator.
    generator.internalStore = new LinkedList<>();
}
Also used : GeneratorOptions(org.mitre.synthea.engine.Generator.GeneratorOptions) File(java.io.File) Before(org.junit.Before)

Example 3 with GeneratorOptions

use of org.mitre.synthea.engine.Generator.GeneratorOptions in project synthea by synthetichealth.

the class CSVExporterTest method testCSVExportExcludes.

@Test
public void testCSVExportExcludes() throws Exception {
    Config.set("exporter.csv.included_files", "");
    Config.set("exporter.csv.excluded_files", "patients.csv, medications, payers, providers");
    CSVExporter.getInstance().init();
    Payer.clear();
    Config.set("generate.payers.insurance_companies.default_file", "generic/payers/test_payers.csv");
    Payer.loadPayers(new Location(Generator.DEFAULT_STATE, null));
    int numberOfPeople = 10;
    ExporterRuntimeOptions exportOpts = new ExporterRuntimeOptions();
    exportOpts.deferExports = true;
    GeneratorOptions generatorOpts = new GeneratorOptions();
    generatorOpts.population = numberOfPeople;
    Generator generator = new Generator(generatorOpts, exportOpts);
    generator.options.overflow = false;
    for (int i = 0; i < numberOfPeople; i++) {
        generator.generatePerson(i);
    }
    // Adding post completion exports to generate organizations and providers CSV files
    Exporter.runPostCompletionExports(generator, exportOpts);
    // if we get here we at least had no exceptions
    File expectedExportFolder = exportDir.toPath().resolve("csv").toFile();
    assertTrue(expectedExportFolder.exists() && expectedExportFolder.isDirectory());
    boolean foundPatients = false;
    boolean foundMedications = false;
    boolean foundPayers = false;
    boolean foundProviders = false;
    int count = 0;
    for (File csvFile : expectedExportFolder.listFiles()) {
        if (!csvFile.getName().endsWith(".csv")) {
            continue;
        }
        switch(csvFile.getName()) {
            case "patients.csv":
                foundPatients = true;
                break;
            case "medications.csv":
                foundMedications = true;
                break;
            case "payers.csv":
                foundPayers = true;
                break;
            case "providers.csv":
                foundProviders = true;
                break;
            default:
        }
        String csvData = new String(Files.readAllBytes(csvFile.toPath()));
        // the CSV exporter doesn't use the SimpleCSV class to write the data,
        // so we can use it here for a level of validation
        SimpleCSV.parse(csvData);
        assertTrue("CSV validation: " + csvFile.getName(), SimpleCSV.isValid(csvData));
        count++;
    }
    int expected = NUMBER_OF_FILES - 4;
    assertEquals("Expected " + expected + " CSV files in the output directory, found " + count, expected, count);
    assertTrue("patients.csv is present but should have been excluded", !foundPatients);
    assertTrue("medications.csv is present but should have been excluded", !foundMedications);
    assertTrue("payers.csv is present but should have been excluded", !foundPayers);
    assertTrue("providers.csv is present but should have been excluded", !foundProviders);
}
Also used : GeneratorOptions(org.mitre.synthea.engine.Generator.GeneratorOptions) File(java.io.File) Location(org.mitre.synthea.world.geography.Location) ExporterRuntimeOptions(org.mitre.synthea.export.Exporter.ExporterRuntimeOptions) Generator(org.mitre.synthea.engine.Generator) Test(org.junit.Test)

Example 4 with GeneratorOptions

use of org.mitre.synthea.engine.Generator.GeneratorOptions in project synthea by synthetichealth.

the class PersonTest method testPersonFhirSTU3Recreation.

@Test()
public void testPersonFhirSTU3Recreation() throws Exception {
    TestHelper.loadTestProperties();
    TestHelper.exportOff();
    Generator.DEFAULT_STATE = Config.get("test_state.default", "Massachusetts");
    Config.set("exporter.fhir_stu3.export", "true");
    SimpleDateFormat format = new SimpleDateFormat("YYYYMMDD");
    format.setTimeZone(TimeZone.getTimeZone("UTC"));
    GeneratorOptions options = new GeneratorOptions();
    options.clinicianSeed = 9L;
    options.seed = 9L;
    options.referenceTime = format.parse("20200704").getTime();
    options.overflow = false;
    Generator generator = new Generator(options);
    List<List<String>> fileContents = new ArrayList<>();
    // the file names should be identical
    for (int i = 0; i < 2; i++) {
        File tempOutputFolder = tempFolder.newFolder();
        Config.set("exporter.baseDirectory", tempOutputFolder.toString());
        generator.generatePerson(0, 42L);
        // Check that the output files exist
        File expectedExportFolder = tempOutputFolder.toPath().resolve("fhir_stu3").toFile();
        assertTrue(expectedExportFolder.exists() && expectedExportFolder.isDirectory());
        for (File txtFile : expectedExportFolder.listFiles()) {
            if (!txtFile.getName().endsWith(".json")) {
                continue;
            }
            fileContents.add(Files.readAllLines(txtFile.toPath()));
        }
    }
    // Check that there are exactly two files
    assertEquals("Expected 2 files, found " + fileContents.size(), 2, fileContents.size());
    // Check that the two files are identical
    for (int i = 0; i < fileContents.get(0).size(); i++) {
        assertEquals(fileContents.get(0).get(i), fileContents.get(1).get(i));
    }
}
Also used : GeneratorOptions(org.mitre.synthea.engine.Generator.GeneratorOptions) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) SimpleDateFormat(java.text.SimpleDateFormat) File(java.io.File) Generator(org.mitre.synthea.engine.Generator) Test(org.junit.Test)

Example 5 with GeneratorOptions

use of org.mitre.synthea.engine.Generator.GeneratorOptions in project synthea by synthetichealth.

the class PersonTest method testPersonRecreationSerialDifferentGenerator.

@Test()
public void testPersonRecreationSerialDifferentGenerator() throws Exception {
    TestHelper.loadTestProperties();
    TestHelper.exportOff();
    Generator.DEFAULT_STATE = Config.get("test_state.default", "Massachusetts");
    Config.set("exporter.text.export", "true");
    SimpleDateFormat format = new SimpleDateFormat("YYYYMMDD");
    format.setTimeZone(TimeZone.getTimeZone("UTC"));
    GeneratorOptions options = new GeneratorOptions();
    options.clinicianSeed = 9L;
    options.seed = 9L;
    options.referenceTime = format.parse("20200704").getTime();
    options.overflow = false;
    List<List<String>> fileContents = new ArrayList<>();
    // the file names should be identical
    for (int i = 0; i < 2; i++) {
        File tempOutputFolder = tempFolder.newFolder();
        Config.set("exporter.baseDirectory", tempOutputFolder.toString());
        Generator generator = new Generator(options);
        generator.generatePerson(0, 42L);
        File expectedExportFolder = tempOutputFolder.toPath().resolve("text").toFile();
        assertTrue(expectedExportFolder.exists() && expectedExportFolder.isDirectory());
        // Read the output files
        for (File txtFile : expectedExportFolder.listFiles()) {
            if (!txtFile.getName().endsWith(".txt")) {
                continue;
            }
            fileContents.add(Files.readAllLines(txtFile.toPath()));
        }
    }
    // Check that there are exactly two files
    assertEquals("Expected 2 files, found " + fileContents.size(), 2, fileContents.size());
    // Check that the two files are identical
    for (int i = 0; i < fileContents.get(0).size(); i++) {
        assertEquals(fileContents.get(0).get(i), fileContents.get(1).get(i));
    }
}
Also used : GeneratorOptions(org.mitre.synthea.engine.Generator.GeneratorOptions) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) SimpleDateFormat(java.text.SimpleDateFormat) File(java.io.File) Generator(org.mitre.synthea.engine.Generator) Test(org.junit.Test)

Aggregations

File (java.io.File)12 GeneratorOptions (org.mitre.synthea.engine.Generator.GeneratorOptions)12 Test (org.junit.Test)10 Generator (org.mitre.synthea.engine.Generator)10 SimpleDateFormat (java.text.SimpleDateFormat)7 ArrayList (java.util.ArrayList)7 List (java.util.List)7 ExporterRuntimeOptions (org.mitre.synthea.export.Exporter.ExporterRuntimeOptions)3 Location (org.mitre.synthea.world.geography.Location)3 ExecutorService (java.util.concurrent.ExecutorService)1 Future (java.util.concurrent.Future)1 Before (org.junit.Before)1 BeforeClass (org.junit.BeforeClass)1