Git Product home page Git Product logo

Comments (7)

yuflyud avatar yuflyud commented on September 27, 2024 2

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

from cda2fhir.

tjclifford avatar tjclifford commented on September 27, 2024

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");
}

}

from cda2fhir.

tjclifford avatar tjclifford commented on September 27, 2024

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

from cda2fhir.

tjclifford avatar tjclifford commented on September 27, 2024

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"

from cda2fhir.

msfyuksel avatar msfyuksel commented on September 27, 2024

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?

from cda2fhir.

tjclifford avatar tjclifford commented on September 27, 2024

from cda2fhir.

PriyadarshiniV avatar PriyadarshiniV commented on September 27, 2024

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.

from cda2fhir.

Related Issues (9)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.