Search in sources :

Example 1 with BasicValidationHandler

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.");
    }
}
Also used : InputStream(java.io.InputStream) ArrayList(java.util.ArrayList) Diagnostic(org.eclipse.emf.common.util.Diagnostic) Person(org.mitre.synthea.world.agents.Person) BasicValidationHandler(org.eclipse.mdht.uml.cda.util.BasicValidationHandler) Test(org.junit.Test)

Example 2 with BasicValidationHandler

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);
}
Also used : InputStream(java.io.InputStream) ExecutorService(java.util.concurrent.ExecutorService) Diagnostic(org.eclipse.emf.common.util.Diagnostic) Person(org.mitre.synthea.world.agents.Person) BasicValidationHandler(org.eclipse.mdht.uml.cda.util.BasicValidationHandler) Generator(org.mitre.synthea.engine.Generator) Test(org.junit.Test)

Example 3 with BasicValidationHandler

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());
}
Also used : InputStream(java.io.InputStream) ArrayList(java.util.ArrayList) Diagnostic(org.eclipse.emf.common.util.Diagnostic) BasicValidationHandler(org.eclipse.mdht.uml.cda.util.BasicValidationHandler) Test(org.junit.Test)

Aggregations

InputStream (java.io.InputStream)3 Diagnostic (org.eclipse.emf.common.util.Diagnostic)3 BasicValidationHandler (org.eclipse.mdht.uml.cda.util.BasicValidationHandler)3 Test (org.junit.Test)3 ArrayList (java.util.ArrayList)2 Person (org.mitre.synthea.world.agents.Person)2 ExecutorService (java.util.concurrent.ExecutorService)1 Generator (org.mitre.synthea.engine.Generator)1