Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Code in client program just like CCDTransformerTest giving ClassCast error #4

Open
tjclifford opened this issue Feb 23, 2018 · 7 comments

Comments

@tjclifford
Copy link

Good day.
Thank you for your hard work on this project. I'm hoping it will help me.
I work for a Michigan HIE, and I'm trying to put together a self-service project so
providers, insurers, etc., can convert their CCDs to FHIR format.
I downloaded your project, built it, and the tests ran fine.

I tried to take three of the methods that convert CCDs to FHIR from your test, and
put them into a command-line-runnable client using the same methods (renamed).
I copied the pom.xml and I believe I have the same repo jar versions as the original.

I first tried setting up the client as it's own project, and including the jar created from
the build of srdc/cda2fhir. I put the validator jar in the project lib dir also,
and I am able to get it to run where it executes the three methods, but for each
method, I'm getting:

15:05:05.074 [org.mihin.ccda2fhir.clients.CCD2JsonClient.main()] ERROR
t.c.s.c.t.CCDTransformerImpl - ClinicalDocument could not be cast to
ContinuityOfCareDocument. Returning null
java.lang.ClassCastException: org.openhealthtools.mdht.uml.cda.impl.
ClinicalDocumentImpl cannot be cast to org.openhealthtools.mdht.uml.cda.
consol.ContinuityOfCareDocument
at tr.com.srdc.cda2fhir.transform.CCDTransformerImpl.transformDocument(CCDTransformerImpl.java:150)
at org.mihin.ccda2fhir.clients.CCD2JsonClient.runReferenceCCDInstance(CCD2JsonClient.java:121)
at org.mihin.ccda2fhir.clients.CCD2JsonClient.execute(CCD2JsonClient.java:93)
at org.mihin.ccda2fhir.clients.CCD2JsonClient.main(CCD2JsonClient.java:60)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.codehaus.mojo.exec.ExecJavaMojo$1.run(ExecJavaMojo.java:297)
at java.lang.Thread.run(Thread.java:748)

The line in my client this occurs at is apparently the FHIRUtil.printJSON(bundle, "");
call, but the line numbers only match the second and third methods, not the first.
I've cleaned and re-built the project a fiew times, but I still get the above.

I could send the class file and a log of the run, but there is no place to submit them.
I can email them if you'd like. Text only.

Thank you again.

@tjclifford
Copy link
Author

Here is the class:

package org.mihin.ccda2fhir.clients;

/*

  • Test client for CCD files by Tom Clifford
    • utilizes the CDA to FHIR Transformer Library,
  • Copyright (C) 2016 SRDC Yazilim Arastirma ve Gelistirme ve Danismanlik Tic. A.S.
  • Licensed under the Apache License, Version 2.0 (the "License");
  • you may not use this file except in compliance with the License.
  • You may obtain a copy of the License at
  •  http://www.apache.org/licenses/LICENSE-2.0
    
  • Unless required by applicable law or agreed to in writing, software
  • distributed under the License is distributed on an "AS IS" BASIS,
  • WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  • See the License for the specific language governing permissions and
  • limitations under the License.
  • #L%
    */

import java.io.IOException;

import ca.uhn.fhir.model.dstu2.resource.Bundle;
//import org.junit.BeforeClass;
//import org.junit.Test;
import org.openhealthtools.mdht.uml.cda.ClinicalDocument;
import org.openhealthtools.mdht.uml.cda.util.CDAUtil;
import tr.com.srdc.cda2fhir.conf.Config;
import tr.com.srdc.cda2fhir.transform.CCDTransformerImpl;
import tr.com.srdc.cda2fhir.transform.ICDATransformer;
import tr.com.srdc.cda2fhir.util.FHIRUtil;
import tr.com.srdc.cda2fhir.util.IdGeneratorEnum;

import java.io.File;
import java.io.FileInputStream;

import org.apache.log4j.Logger;

public class CCD2JsonClient {

private static File dataFile = null;

public static void main(String[] argv) {
    System.out.println("CCD-2-Json-client starts.");
    System.out.println("Checking input arguments...");
    if (argv.length != 1) {
        System.err.println("Usage: java CCD-2-Json-client datafile");
        System.exit(1);
    }
    //try {
    	//File stylesheetFile = new File(argv[0]);
    	dataFile = new File(argv[0]);
    //} catch (IOException ioe) {
        // I/O error
    //    ioe.printStackTrace();
    //    System.out.println("One or more files not found...terminating.");
    //    System.exit(1);
    //}
    CCD2JsonClient ccd2json = new CCD2JsonClient();
    	
    // run examples
    
    ccd2json.execute();
    System.out.println("CCD-2-Json-client DONE!.");
}

// default, no-arg constructor

public CCD2JsonClient() {}
    
private void execute()
{
    // Load MDHT CDA packages. Otherwise ContinuityOfCareDocument and similar documents will not be recognised.
    // This has to be called before loading the document; otherwise will have no effect.
    CDAUtil.loadPackages();
    
    try {
	    System.out.println(" runReferenceCCDInstance....");
	    runReferenceCCDInstance( dataFile );
	    System.out.println(" runReferenceCCDInstanceWithoutDAF....");
	    runReferenceCCDInstanceWithoutDAF( dataFile );
	    System.out.println(" runReferenceCCDInstanceWithoutDAFAndNarrative....");
		runReferenceCCDInstanceWithoutDAFAndNarrative( dataFile );
    } catch( Exception e ) {
	    System.err.println(" Exception translating dataFile with stylesheet: " );
	    e.printStackTrace();
	    System.err.println(" program terminates. " );
	    System.exit(1);
    }
}


// with DAF profile in meta.profile
//public void runReferenceCCDInstance( File styleSheet, File dataFile ) throws Exception {
public void runReferenceCCDInstance( File dataFile ) throws Exception {
    //FileInputStream fis = new FileInputStream("src/test/resources/C-CDA_R2-1_CCD.xml");
    FileInputStream fis = new FileInputStream( dataFile );

    ClinicalDocument cda = CDAUtil.load(fis);
    ICDATransformer ccdTransformer = new CCDTransformerImpl(IdGeneratorEnum.COUNTER);
    Config.setGenerateDafProfileMetadata(true);
    Config.setGenerateNarrative(true);
    Bundle bundle = ccdTransformer.transformDocument(cda);
    if(bundle != null) 
    	FHIRUtil.printJSON(bundle, "output/output01.json");
}

// without DAF profile in meta.profile
//public void runReferenceCCDInstanceWithoutDAF( File styleSheet, File dataFile ) throws Exception {
public void runReferenceCCDInstanceWithoutDAF( File dataFile ) throws Exception {
    //FileInputStream fis = new FileInputStream("src/test/resources/C-CDA_R2-1_CCD.xml");
    FileInputStream fis = new FileInputStream( dataFile );

    ClinicalDocument cda = CDAUtil.load(fis);
    ICDATransformer ccdTransformer = new CCDTransformerImpl(IdGeneratorEnum.COUNTER);
    Config.setGenerateDafProfileMetadata(false);
    Config.setGenerateNarrative(true);
    Bundle bundle = ccdTransformer.transformDocument(cda);
    if(bundle != null)
        FHIRUtil.printJSON(bundle, "output/output01-wo-daf.json");
}

// C-CDA_R2-1_CCD.xml - without DAF profile in meta.profile and without narrative generated in resources
//public void runReferenceCCDInstanceWithoutDAFAndNarrative( File styleSheet, File dataFile ) throws Exception {
public void runReferenceCCDInstanceWithoutDAFAndNarrative( File dataFile ) throws Exception {
    //FileInputStream fis = new FileInputStream("src/test/resources/C-CDA_R2-1_CCD.xml");
    FileInputStream fis = new FileInputStream( dataFile );

    ClinicalDocument cda = CDAUtil.load(fis);
    ICDATransformer ccdTransformer = new CCDTransformerImpl(IdGeneratorEnum.COUNTER);
    Config.setGenerateDafProfileMetadata(false);
    Config.setGenerateNarrative(false);
    Bundle bundle = ccdTransformer.transformDocument(cda);
    if(bundle != null)
        FHIRUtil.printJSON(bundle, "output/output01-wo-daf-narrative.json");
}

}

@tjclifford
Copy link
Author

Here is the log:

Run of CCD2JsonClient:

C:\dl\mihin\0projects\ccda-to-fhir 15:12:56.65

runccd2jsonclient
[INFO] Scanning for projects...
[WARNING]
[WARNING] Some problems were encountered while building the effective model for org.mihin:ccdr-to-fhir:jar:0.0.1-SNAPSHOT
[WARNING] 'dependencies.dependency.(groupId:artifactId:type:classifier)' must be unique: org.openehealth.ipf.oht.mdht:ipf-oht-mdht-uml-hl7-vocab:jar -> duplicate declaration of version 1.2.0.201212201425 @ line 149, column 15
[WARNING] 'dependencies.dependency.systemPath' for org.hl7.fhir:validator:jar should not point at files within the project directory, ${project.basedir}/lib/org.hl7.fhir.validator.jar will be unresolvable by dependent projects @ line 227, column 25
[WARNING] 'dependencies.dependency.systemPath' for tr.com.srdc.cda2fhir:cda2fhir:jar should not point at files within the project directory, ${project.basedir}/lib/cda2fhir-0.2.jar will be unresolvable by dependent projects @ line 242, column 25
[WARNING] 'build.plugins.plugin.version' for org.apache.maven.plugins:maven-jar-plugin is missing. @ line 279, column 11
[WARNING]
[WARNING] It is highly recommended to fix these problems because they threaten the stability of your build.
[WARNING]
[WARNING] For this reason, future Maven versions might no longer support building such malformed projects.
[WARNING]
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building CCDR to FHIR conversion project 0.0.1-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] >>> exec-maven-plugin:1.2.1:java (default-cli) > validate @ ccdr-to-fhir >>>
[INFO]
[INFO] <<< exec-maven-plugin:1.2.1:java (default-cli) < validate @ ccdr-to-fhir <<<
[INFO]
[INFO]
[INFO] --- exec-maven-plugin:1.2.1:java (default-cli) @ ccdr-to-fhir ---
log4j:WARN No appenders could be found for logger (org.mihin.ccda2fhir.clients.CCD2JsonClient).
log4j:WARN Please initialize the log4j system properly.
log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.
runReferenceCCDInstance....
15:13:07.783 [org.mihin.ccda2fhir.clients.CCD2JsonClient.main()] INFO c.u.f.u.VersionUtil - HAPI FHIR version is: 2.0
15:13:07.790 [org.mihin.ccda2fhir.clients.CCD2JsonClient.main()] INFO c.u.f.c.FhirContext - Creating new FHIR context for FHIR version [DSTU2]
15:13:07.796 [org.mihin.ccda2fhir.clients.CCD2JsonClient.main()] INFO t.c.s.c.c.Config - System file encoding is: windows-1252
15:13:07.800 [org.mihin.ccda2fhir.clients.CCD2JsonClient.main()] ERROR t.c.s.c.t.CCDTransformerImpl - ClinicalDocument could not be cast to ContinuityOfCareDocument. Returning null
java.lang.ClassCastException: org.openhealthtools.mdht.uml.cda.impl.ClinicalDocumentImpl cannot be cast to org.openhealthtools.mdht.uml.cda.consol.ContinuityOfCareDocument
at tr.com.srdc.cda2fhir.transform.CCDTransformerImpl.transformDocument(CCDTransformerImpl.java:150)
at org.mihin.ccda2fhir.clients.CCD2JsonClient.runReferenceCCDInstance(CCD2JsonClient.java:121)
at org.mihin.ccda2fhir.clients.CCD2JsonClient.execute(CCD2JsonClient.java:93)
at org.mihin.ccda2fhir.clients.CCD2JsonClient.main(CCD2JsonClient.java:60)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.codehaus.mojo.exec.ExecJavaMojo$1.run(ExecJavaMojo.java:297)
at java.lang.Thread.run(Thread.java:748)
runReferenceCCDInstanceWithoutDAF....
15:13:07.901 [org.mihin.ccda2fhir.clients.CCD2JsonClient.main()] ERROR t.c.s.c.t.CCDTransformerImpl - ClinicalDocument could not be cast to ContinuityOfCareDocument. Returning null
java.lang.ClassCastException: org.openhealthtools.mdht.uml.cda.impl.ClinicalDocumentImpl cannot be cast to org.openhealthtools.mdht.uml.cda.consol.ContinuityOfCareDocument
at tr.com.srdc.cda2fhir.transform.CCDTransformerImpl.transformDocument(CCDTransformerImpl.java:150)
at org.mihin.ccda2fhir.clients.CCD2JsonClient.runReferenceCCDInstanceWithoutDAF(CCD2JsonClient.java:136)
at org.mihin.ccda2fhir.clients.CCD2JsonClient.execute(CCD2JsonClient.java:95)
at org.mihin.ccda2fhir.clients.CCD2JsonClient.main(CCD2JsonClient.java:60)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.codehaus.mojo.exec.ExecJavaMojo$1.run(ExecJavaMojo.java:297)
at java.lang.Thread.run(Thread.java:748)
runReferenceCCDInstanceWithoutDAFAndNarrative....
15:13:08.003 [org.mihin.ccda2fhir.clients.CCD2JsonClient.main()] ERROR t.c.s.c.t.CCDTransformerImpl - ClinicalDocument could not be cast to ContinuityOfCareDocument. Returning null
java.lang.ClassCastException: org.openhealthtools.mdht.uml.cda.impl.ClinicalDocumentImpl cannot be cast to org.openhealthtools.mdht.uml.cda.consol.ContinuityOfCareDocument
at tr.com.srdc.cda2fhir.transform.CCDTransformerImpl.transformDocument(CCDTransformerImpl.java:150)
at org.mihin.ccda2fhir.clients.CCD2JsonClient.runReferenceCCDInstanceWithoutDAFAndNarrative(CCD2JsonClient.java:151)
at org.mihin.ccda2fhir.clients.CCD2JsonClient.execute(CCD2JsonClient.java:97)
at org.mihin.ccda2fhir.clients.CCD2JsonClient.main(CCD2JsonClient.java:60)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.codehaus.mojo.exec.ExecJavaMojo$1.run(ExecJavaMojo.java:297)
at java.lang.Thread.run(Thread.java:748)
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 2.328 s
[INFO] Finished at: 2018-02-23T15:13:08-05:00
[INFO] Final Memory: 19M/369M
[INFO] ------------------------------------------------------------------------

C:\dl\mihin\0projects\ccda-to-fhir 15:13:08.19

@tjclifford
Copy link
Author

P.S. I'm using the file from your test/resources dir, "C-CDA_R2-1_CCD.xml" as a test file (after renaming it).
maven is v3.5.2, Java 1.8.0_161 (64-bit).
my command to run the client class:
mvn exec:java -Dexec.mainClass="org.mihin.ccda2fhir.clients.CCD2JsonClient" -Dexec.args="input/inputCCD01.xml"

@msfyuksel
Copy link
Member

Hi,

Nothing seems wrong in your code, and I can actually run it successfully when I copy your class directly in the cda2fhir project itself. You can test it.

I can only reproduce the error when I comment the following line, which is a must for loading CDA definitions from the mdht library:

CDAUtil.loadPackages();

I suspect that the required libraries, especially mdht is found in your classpath while you are trying to run via mvn exec. Can you make sure of this and test again?

@tjclifford
Copy link
Author

tjclifford commented Feb 25, 2018 via email

@yuflyud
Copy link

yuflyud commented Aug 17, 2018

This worked for me:
ContinuityOfCareDocument cda = (ContinuityOfCareDocument) CDAUtil.loadAs(in, ConsolPackage.eINSTANCE.getContinuityOfCareDocument());

@PriyadarshiniV
Copy link

This worked to get the bundle with bare minimum resources. It still misses all the references like e.g. medication section has only the coding and the text part but is missing all the references to medication statement, substance etc. Similarly for the other sections.

I face this particular issue only when running this as a spring boot WEB project. When run as a regular spring boot application, this issue does not occuer. I assume it is not loading certain packages when run as a web project.

Any leads would be appreciated.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants