Search in sources :

Example 1 with DefaultRandomNumberGenerator

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

the class HospitalExporterTestR4 method testFHIRExport.

@Test
public void testFHIRExport() throws Exception {
    FhirContext ctx = FhirR4.getContext();
    FhirValidator validator = ctx.newValidator();
    validator.setValidateAgainstStandardSchema(true);
    validator.setValidateAgainstStandardSchematron(true);
    File tempOutputFolder = tempFolder.newFolder();
    Config.set("exporter.baseDirectory", tempOutputFolder.toString());
    Config.set("exporter.hospital.fhir.export", "true");
    Config.set("exporter.fhir.transaction_bundle", "true");
    // set this manually, in case it has already been loaded.
    FhirR4.TRANSACTION_BUNDLE = true;
    TestHelper.loadTestProperties();
    Generator.DEFAULT_STATE = Config.get("test_state.default", "Massachusetts");
    Location location = new Location(Generator.DEFAULT_STATE, null);
    Provider.clear();
    Provider.loadProviders(location, ProviderTest.providerRandom);
    assertNotNull(Provider.getProviderList());
    assertFalse(Provider.getProviderList().isEmpty());
    Provider.getProviderList().get(0).incrementEncounters(EncounterType.WELLNESS, 0);
    HospitalExporterR4.export(new DefaultRandomNumberGenerator(0L), 0L);
    File expectedExportFolder = tempOutputFolder.toPath().resolve("fhir").toFile();
    assertTrue(expectedExportFolder.exists() && expectedExportFolder.isDirectory());
    File expectedExportFile = expectedExportFolder.toPath().resolve("hospitalInformation0.json").toFile();
    assertTrue(expectedExportFile.exists() && expectedExportFile.isFile());
    FileReader fileReader = new FileReader(expectedExportFile.getPath());
    BufferedReader bufferedReader = new BufferedReader(fileReader);
    StringBuilder fhirJson = new StringBuilder();
    String line = null;
    while ((line = bufferedReader.readLine()) != null) {
        fhirJson.append(line);
    }
    bufferedReader.close();
    IBaseResource resource = ctx.newJsonParser().parseResource(fhirJson.toString());
    ValidationResult result = validator.validateWithResult(resource);
    if (result.isSuccessful() == false) {
        for (SingleValidationMessage message : result.getMessages()) {
            System.out.println(message.getSeverity().toString() + ": " + message.getMessage());
        }
    }
    assertTrue(result.isSuccessful());
}
Also used : FhirContext(ca.uhn.fhir.context.FhirContext) DefaultRandomNumberGenerator(org.mitre.synthea.helpers.DefaultRandomNumberGenerator) SingleValidationMessage(ca.uhn.fhir.validation.SingleValidationMessage) BufferedReader(java.io.BufferedReader) FileReader(java.io.FileReader) FhirValidator(ca.uhn.fhir.validation.FhirValidator) IBaseResource(org.hl7.fhir.instance.model.api.IBaseResource) ValidationResult(ca.uhn.fhir.validation.ValidationResult) File(java.io.File) Location(org.mitre.synthea.world.geography.Location) Test(org.junit.Test) ProviderTest(org.mitre.synthea.world.agents.ProviderTest)

Example 2 with DefaultRandomNumberGenerator

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

the class GeneratorTest method testUpdateAfterCreationAndSerialization.

@Test
public void testUpdateAfterCreationAndSerialization() throws Exception {
    // serialization
    if (Boolean.valueOf(Config.get("physiology.generators.enabled", "false"))) {
        System.out.println("Skipping test GeneratorTest.testUpdateAfterCreationAndSerialization");
        System.out.println("Set config physiology.generators.enabled=false to enable this test");
        return;
    }
    // Get 10 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);
    }
    people = serializeAndDeserialize(people);
    // 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 3 with DefaultRandomNumberGenerator

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

the class PersonTest method testSerializationAndDeserialization.

@Test
public void testSerializationAndDeserialization() throws Exception {
    // serialization
    if (Boolean.valueOf(Config.get("physiology.generators.enabled", "false"))) {
        System.out.println("Skipping test PersonTest.testSerializationAndDeserialization");
        System.out.println("Set config physiology.generators.enabled=false to enable this test");
        return;
    }
    // Generate a filled-out patient record to test on
    Generator.GeneratorOptions opts = new Generator.GeneratorOptions();
    opts.population = 1;
    opts.minAge = 50;
    opts.maxAge = 100;
    Generator generator = new Generator(opts);
    RandomNumberGenerator random = new DefaultRandomNumberGenerator(0);
    Map<String, Object> demoAttributes = generator.randomDemographics(random);
    Person original = generator.createPerson(0, demoAttributes);
    Person rehydrated = serializeAndDeserialize(original);
    // Compare the original to the serialized+deserialized version
    assertEquals(original.randInt(), rehydrated.randInt());
    assertEquals(original.getSeed(), rehydrated.getSeed());
    assertEquals(original.populationSeed, rehydrated.populationSeed);
    assertEquals(original.symptoms.keySet(), rehydrated.symptoms.keySet());
    assertEquals(original.getOnsetConditionRecord().getSources().keySet(), rehydrated.getOnsetConditionRecord().getSources().keySet());
    assertEquals(original.hasMultipleRecords, rehydrated.hasMultipleRecords);
    assertEquals(original.attributes.keySet(), rehydrated.attributes.keySet());
    assertEquals(original.vitalSigns.keySet(), rehydrated.vitalSigns.keySet());
    assertEquals(original.chronicMedications.keySet(), rehydrated.chronicMedications.keySet());
    assertEquals(original.hasMultipleRecords, rehydrated.hasMultipleRecords);
    if (original.hasMultipleRecords) {
        assertEquals(original.records.keySet(), rehydrated.records.keySet());
    }
    assertEquals(original.coverage.getPlanHistory().size(), rehydrated.coverage.getPlanHistory().size());
}
Also used : GeneratorOptions(org.mitre.synthea.engine.Generator.GeneratorOptions) DefaultRandomNumberGenerator(org.mitre.synthea.helpers.DefaultRandomNumberGenerator) RandomNumberGenerator(org.mitre.synthea.helpers.RandomNumberGenerator) DefaultRandomNumberGenerator(org.mitre.synthea.helpers.DefaultRandomNumberGenerator) GeneratorOptions(org.mitre.synthea.engine.Generator.GeneratorOptions) DefaultRandomNumberGenerator(org.mitre.synthea.helpers.DefaultRandomNumberGenerator) Generator(org.mitre.synthea.engine.Generator) RandomNumberGenerator(org.mitre.synthea.helpers.RandomNumberGenerator) Test(org.junit.Test)

Example 4 with DefaultRandomNumberGenerator

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

the class DemographicsTest method setUp.

/**
 * Set up the demographics to use for testing.
 */
@BeforeClass
@SuppressWarnings("rawtypes")
public static void setUp() throws IOException {
    demographicsFile = Config.get("generate.demographics.default_file");
    Config.set("generate.demographics.default_file", "geography/test_demographics.csv");
    Table pa = Demographics.load("Pennsylvania");
    philly = (Demographics) pa.get("Pennsylvania", "27237");
    random = new DefaultRandomNumberGenerator(0);
}
Also used : Table(com.google.common.collect.Table) DefaultRandomNumberGenerator(org.mitre.synthea.helpers.DefaultRandomNumberGenerator) BeforeClass(org.junit.BeforeClass)

Example 5 with DefaultRandomNumberGenerator

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

the class BB2RIFExporterTest method testCodeMapper.

@Test
public void testCodeMapper() {
    // these tests depend on the presence of the code map file and will not be run in CI
    try {
        Utilities.readResource("condition_code_map.json");
    } catch (IOException | IllegalArgumentException e) {
        return;
    }
    RandomNumberGenerator random = new DefaultRandomNumberGenerator(0);
    CodeMapper mapper = new CodeMapper("condition_code_map.json");
    assertTrue(mapper.canMap("10509002"));
    assertEquals("J20.9", mapper.map("10509002", random));
    assertEquals("J209", mapper.map("10509002", random, true));
    assertFalse(mapper.canMap("not a code"));
}
Also used : DefaultRandomNumberGenerator(org.mitre.synthea.helpers.DefaultRandomNumberGenerator) RandomNumberGenerator(org.mitre.synthea.helpers.RandomNumberGenerator) DefaultRandomNumberGenerator(org.mitre.synthea.helpers.DefaultRandomNumberGenerator) IOException(java.io.IOException) CodeMapper(org.mitre.synthea.export.BB2RIFExporter.CodeMapper) Test(org.junit.Test)

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