use of org.eclipse.mdht.uml.cda.util.BasicValidationHandler in project synthea by synthetichealth.
the class CCDAExporterTest method testExportWithNoPreferredWellnessProvider.
@Test
public void testExportWithNoPreferredWellnessProvider() throws Exception {
TestHelper.loadTestProperties();
Person[] people = TestHelper.getGeneratedPeople();
List<String> validationErrors = new ArrayList<String>();
TestHelper.exportOff();
Config.set("exporter.ccda.export", "true");
Optional<Person> personWithWellnessProvider = Arrays.stream(people).filter((person -> {
return person.attributes.get(Person.PREFERREDYPROVIDER + "wellness") != null;
})).findFirst();
if (personWithWellnessProvider.isPresent()) {
Person toExport = personWithWellnessProvider.get();
toExport.attributes.remove(Person.PREFERREDYPROVIDER + "wellness");
String ccdaXml = CCDAExporter.export(toExport, System.currentTimeMillis());
InputStream inputStream = IOUtils.toInputStream(ccdaXml, "UTF-8");
try {
CDAUtil.load(inputStream, new BasicValidationHandler() {
public void handleError(Diagnostic diagnostic) {
System.out.println("ERROR: " + diagnostic.getMessage());
validationErrors.add(diagnostic.getMessage());
}
});
} catch (Exception e) {
e.printStackTrace();
validationErrors.add(e.getMessage());
}
assertEquals(0, validationErrors.size());
} else {
System.out.println("There were no people generated that have wellness providers... odd.");
}
}
use of org.eclipse.mdht.uml.cda.util.BasicValidationHandler in project synthea by synthetichealth.
the class ExportBreakerTest method runUntilBreaking.
@Test
public void runUntilBreaking() throws Exception {
int numberOfPeople = 10000;
Generator generator = new Generator(numberOfPeople);
generator.options.overflow = false;
TestHelper.loadTestProperties();
Generator.DEFAULT_STATE = Config.get("test_state.default", "Massachusetts");
Config.set("exporter.baseDirectory", tempFolder.newFolder().toString());
// This is currently set up for CCDA testing, but it should be easy to remove this and do FHIR
// testing or whatever else needs to be run.
CDAUtil.loadPackages();
TestHelper.exportOff();
Config.set("exporter.ccda.export", "true");
// I picked 6 because it allows me to run tests on my 8 core machine, but have it still be
// usable for other things.
ExecutorService service = Executors.newFixedThreadPool(6);
for (int i = 0; i < numberOfPeople; i++) {
final int personIndex = i;
service.submit(() -> {
try {
Person p = generator.generatePerson(personIndex);
// Export work goes here
String ccdaXml = CCDAExporter.export(p, System.currentTimeMillis());
InputStream inputStream = IOUtils.toInputStream(ccdaXml, "UTF-8");
// Validation work goes here
CDAUtil.load(inputStream, new BasicValidationHandler() {
public void handleError(Diagnostic diagnostic) {
System.out.println("ERROR: " + diagnostic.getMessage());
System.out.println(ccdaXml);
}
});
} catch (Exception e) {
throw new RuntimeException(e);
}
});
}
service.shutdown();
service.awaitTermination(1, TimeUnit.HOURS);
}
use of org.eclipse.mdht.uml.cda.util.BasicValidationHandler in project synthea by synthetichealth.
the class CCDAExporterTest method testCCDAExport.
@Test
public void testCCDAExport() throws Exception {
TestHelper.loadTestProperties();
Generator.DEFAULT_STATE = Config.get("test_state.default", "Massachusetts");
Config.set("exporter.baseDirectory", tempFolder.newFolder().toString());
CDAUtil.loadPackages();
List<String> errors = ParallelTestingService.runInParallel((person) -> {
List<String> validationErrors = new ArrayList<String>();
TestHelper.exportOff();
Config.set("exporter.ccda.export", "true");
String ccdaXml = CCDAExporter.export(person, System.currentTimeMillis());
InputStream inputStream = IOUtils.toInputStream(ccdaXml, "UTF-8");
try {
CDAUtil.load(inputStream, new BasicValidationHandler() {
public void handleError(Diagnostic diagnostic) {
System.out.println("ERROR: " + diagnostic.getMessage());
validationErrors.add(diagnostic.getMessage());
}
});
} catch (Exception e) {
e.printStackTrace();
validationErrors.add(e.getMessage());
}
if (!validationErrors.isEmpty()) {
Exporter.export(person, System.currentTimeMillis());
}
return validationErrors;
});
assertEquals("Validation of exported CCDA failed: " + String.join("|", errors), 0, errors.size());
}
Aggregations