1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.openehealth.ipf.modules.cda.support;
17
18
19 import org.junit.Before;
20 import org.junit.Test;
21 import org.openehealth.ipf.commons.xml.SchematronProfile;
22 import org.openehealth.ipf.commons.xml.SchematronValidator;
23 import org.slf4j.Logger;
24 import org.slf4j.LoggerFactory;
25
26 import javax.xml.transform.Source;
27 import javax.xml.transform.stream.StreamSource;
28 import java.util.HashMap;
29 import java.util.Map;
30
31 import static org.openehealth.ipf.modules.cda.CDAR2Constants.CCDA_SCHEMATRON_RULES;
32
33
34
35
36 public class CCDASchematronValidationTest {
37
38 protected static final transient Logger LOG = LoggerFactory.getLogger(CCDASchematronValidationTest.class);
39
40 private SchematronValidator schematron;
41 private Map<String, Object> params;
42
43 private static final String[] ccdaFiles = new String[]{"CCD 1", "Consult 1", "DIR.sample", "Discharge Summary 1",
44 "HandP 1", "Op Note 1", "Proc Note 1", "Progress Note 1",
45 "UD 1", "UD 2"};
46
47 @Before
48 public void setUp() throws Exception {
49 params = new HashMap<>();
50 params.put("phase", "errors");
51 schematron = new SchematronValidator();
52 }
53
54 @Test
55 public void validateSchemaGoodSamples() throws Exception {
56 for (String ccdaFile: ccdaFiles){
57 String ccdaFilePathFormat = "/ccda/%s.xml";
58 String ccdaFilePath = String.format(ccdaFilePathFormat, ccdaFile);
59 Source testXml = new StreamSource(getClass().getResourceAsStream(ccdaFilePath));
60 LOG.info("Testing {} ...", ccdaFile);
61 schematron.validate(testXml, new SchematronProfile(CCDA_SCHEMATRON_RULES, params));
62 LOG.info("{} - OK", ccdaFile);
63 }
64 }
65
66 }