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());
}
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);
}
}
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());
}
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);
}
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"));
}
Aggregations