I'm loading one of the ccda test master files and validating it using MDHT-models release 3.0.8.20180531. That works fine; I get the expected warnings. However, if I load the same file, save it using CDAUtil.save() then validate it, it contains multiple errors and warnings. The same occurs if I validate the document using the TTP validator.
This works fine, there are no errors in the document
//create the validator
ReferenceCCDAValidator validator = new ReferenceCCDAValidator();
//load a valid document into a string
byte[] data = FileUtils.getFileData(new File("c:/temp/170.315_b5_toc_amb_ccd_r11_sample1_v8.xml"));
String xmlString = new String(data);
//validate it
List<RefCCDAValidationResult> results = validator.validateFile("C-CDA_IG_Plus_Vocab", null, xmlString);
The document created here contains errors
DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance();
DocumentBuilder docBuilder = docFactory.newDocumentBuilder();
//load the document
FileInputStream in = new FileInputStream(new File("c:/temp/170.315_b5_toc_amb_ccd_r11_sample1_v8.xml"));
Document doc = docBuilder.parse(in);
ClinicalDocument cda = CDAUtil.load(doc);
//save the document
ByteArrayOutputStream out = new ByteArrayOutputStream();
CDAUtil.save(cda, out);
String xmlString = out.toString();
FileUtils.setFileData(new File("c:/temp/test_ccda.xml"), out.toByteArray());
//validate it
ReferenceCCDAValidator validator = new ReferenceCCDAValidator();
List<RefCCDAValidationResult> results = validator.validateFile("C-CDA_IG_Plus_Vocab", null, xmlString);
Here are some of the erors:
Error -
cvc-type.2: The type definition cannot be abstract for element value.
Line number: Line number not available
Error -
cvc-complex-type.3.2.2: Attribute 'code' is not allowed to appear in element 'value'.
Line number: Line number not available
Error -
cvc-complex-type.3.2.2: Attribute 'codeSystem' is not allowed to appear in element 'value'.
Line number: Line number not available
Error -
cvc-complex-type.3.2.2: Attribute 'displayName' is not allowed to appear in element 'value'.
Line number: Line number not available
Error -
cvc-type.2: The type definition cannot be abstract for element value.
Line number: Line number not available
It appears that CCDA.save() is saving some of the elements out of order according to the schema. I've attached the saved document.
Thanks
Frank