C-CDA validation fails because of "Unknown type" in my server but not in standalone project

554 views Asked by At

I was checking how to use the MDHT libraries to validate C-CDA documents, reviewing the current implementations, to create a validation web service for my project. I firstly made a Eclipse local Java Project, added the JARs to the classpath, and implement the code. The execution was successful. But when I copy the same code to my web project (made with Spring Boot) and send a request that executes such code, the program fails.

To explain better, I made the following minimal method:

public void executeMDHTCode(byte[] fileContents) {
    System.out.println(Arrays.toString(fileContents));
    ValidationResult result = new ValidationResult();
    ClinicalDocument doc = null;

    try {
        ConsolPackage.eINSTANCE.eClass();
        doc = CDAUtil.load(new ByteArrayInputStream(fileContents), result);
    } catch (ClassCastException|SAXParseException|Resource.IOWrappedException e) {
        doc = null;
    } catch (Exception e) {
        throw new RuntimeException("Unknown error: " + e.getMessage(), e);
    }
}

Then I used it in the following main method in my test project

public static void main(String[] args) throws IOException { 
    ByteArrayOutputStream outstr = new ByteArrayOutputStream();
    int b = -1;
    InputStream stream = AppTest.class.getResourceAsStream("xml_ccda_invalid.xml");
    while((b = stream.read()) != -1) {
        outstr.write(b);
    }

    executeMDHTCode(outstr.toByteArray());   // only added 'static'
}

And then used the same code in my server project (encapsulating it in a ccdaService)

@RequestMapping(/*POST endpoint properties*/)
public ResponseEntity<Object> validateCCDAFile(@RequestBody MultipartFile file) throws IOException {
    ccdaService.executeMDHTCode(file.getBytes());
    return null;
}

The document to be tested in both cases, xml_ccda_invalid.xml, contains the following:

<?xml version="1.0" encoding="UTF-8"?>
<ClinicalDocument xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="urn:hl7-org:v3" xsi:schemaLocation="urn:hl7-org:v3 CDA.xsd">
  <realmCode code="US"/>
</ClinicalDocument>

As I said, the test project version terminates correctly. But the server version throws the following exception:

java.lang.UnsupportedOperationException: Unknown type ([vocab, ActClinicalDocument, DOCCLIN])
    at org.eclipse.mdht.uml.cda.operations.ClinicalDocumentOperations.validateClassCode(ClinicalDocumentOperations.java:133) ~[org.eclipse.mdht.uml.cda-3.0.0.201706220503.jar:?]
    at org.eclipse.mdht.uml.cda.impl.ClinicalDocumentImpl.validateClassCode(ClinicalDocumentImpl.java:1659) ~[org.eclipse.mdht.uml.cda-3.0.0.201706220503.jar:?]
    at org.eclipse.mdht.uml.cda.util.CDAValidator.validateClinicalDocument_validateClassCode(CDAValidator.java:1769) ~[org.eclipse.mdht.uml.cda-3.0.0.201706220503.jar:?]
    at org.eclipse.mdht.uml.cda.util.CDAValidator.validateClinicalDocument(CDAValidator.java:1753) ~[org.eclipse.mdht.uml.cda-3.0.0.201706220503.jar:?]
    at org.eclipse.mdht.uml.cda.util.CDAValidator.validate(CDAValidator.java:1075) ~[org.eclipse.mdht.uml.cda-3.0.0.201706220503.jar:?]
    at org.eclipse.emf.ecore.util.EObjectValidator.validate(EObjectValidator.java:324) ~[org.eclipse.emf.ecore-2.12.0.v20160420-0247.jar:?]
    at org.eclipse.emf.ecore.util.Diagnostician.doValidate(Diagnostician.java:171) ~[org.eclipse.emf.ecore-2.12.0.v20160420-0247.jar:?]
    at org.eclipse.emf.ecore.util.Diagnostician.validate(Diagnostician.java:158) ~[org.eclipse.emf.ecore-2.12.0.v20160420-0247.jar:?]
    at org.eclipse.emf.ecore.util.Diagnostician.validate(Diagnostician.java:137) ~[org.eclipse.emf.ecore-2.12.0.v20160420-0247.jar:?]
    at org.eclipse.emf.ecore.util.Diagnostician.validate(Diagnostician.java:108) ~[org.eclipse.emf.ecore-2.12.0.v20160420-0247.jar:?]
    at org.eclipse.mdht.uml.cda.util.CDAUtil.validate(CDAUtil.java:707) ~[org.eclipse.mdht.uml.cda-3.0.0.201706220503.jar:?]
    at org.eclipse.mdht.uml.cda.util.CDAUtil.validate(CDAUtil.java:696) ~[org.eclipse.mdht.uml.cda-3.0.0.201706220503.jar:?]
    at org.eclipse.mdht.uml.cda.util.CDAUtil.performEMFValidation(CDAUtil.java:830) ~[org.eclipse.mdht.uml.cda-3.0.0.201706220503.jar:?]
    at org.eclipse.mdht.uml.cda.util.CDAUtil.load(CDAUtil.java:277) ~[org.eclipse.mdht.uml.cda-3.0.0.201706220503.jar:?]
    at org.eclipse.mdht.uml.cda.util.CDAUtil.load(CDAUtil.java:252) ~[org.eclipse.mdht.uml.cda-3.0.0.201706220503.jar:?]
    at companypackage.service.impl.CCDAServiceImpl.executeMDHTCode(CCDAServiceImpl.java:109) ~[bin/:?]
    at companypackage.controller.CCDAController.validateCCDAFile(CCDAController.java:32) ~[bin/:?]
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_102]
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_102]
    at (other spring and apache calls...)

I used the println statement to check the contents of the input array, and they are in both cases identical, so it's not a matter of server processing of the file.

I have not idea why this happens. I put all the jars of the server project into the test project's classpath and it still worked, so it's not a class name clash. It seems to be only interfere when actually used.

What could I be missing?

2

There are 2 answers

2
user2418114 On

The looks to be an issue with the war file deployment - the ActClinicalDocument is defined in the org.eclipse.mdht.uml.hl7.vocab jar; if you are using maven for the build you can look at the following maven example https://github.com/mdht/mdht-models/tree/develop/examples/org.openhealthtools.mdht.cda.maven.example

if not make sure in your eclipse project that the jars etc are included in the binary build

0
Bryn Lewis On

It sounds like you aren't applying a schema in your standalone project, or maybe not the same schema, so it is validating without reference to the validation process.