diff --git a/.gitignore b/.gitignore index 01d05cf..1926098 100644 --- a/.gitignore +++ b/.gitignore @@ -1,15 +1,2 @@ -*.class - -# Mobile Tools for Java (J2ME) -.mtj.tmp/ - -# Package Files # -*.jar -*.war -*.ear - -# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml -hs_err_pid* - target -/CDAGenerator/.jrebel_disabled +/CDAGenerator/src/main/resources/testCDA.xml diff --git a/CDAGenerator/pom.xml b/CDAGenerator/pom.xml index ae1b762..8489d17 100644 --- a/CDAGenerator/pom.xml +++ b/CDAGenerator/pom.xml @@ -3,24 +3,71 @@ 4.0.0 de.fhg.isst.ehealth.cda CDAGenerator - 1.1.4 + 1.2.0 jar UTF-8 - 1.7 - 1.7 + 2.3.0 + + + + isst-artifactory + artifactory.isst.fraunhofer.de-releases + https://artifactory.isst.fraunhofer.de:443/artifactory/oe220-rzv-external-maven/ + + + + + isst-artifactory + artifactory.isst.fraunhofer.de-snapshots + https://artifactory.isst.fraunhofer.de:443/artifactory/oe220-rzv-external-maven/ + + + isst-artifactory + artifactory.isst.fraunhofer.de-releases + https://artifactory.isst.fraunhofer.de:443/artifactory/oe220-rzv-external-maven/ + + + - - log4j - log4j - 1.2.17 - junit junit 4.10 test + + + + + com.sun.xml.bind + jaxb-impl + ${com.sun.xml.version} + + + + com.sun.xml.bind + jaxb-core + ${com.sun.xml.version} + + + javax.xml.bind + jaxb-api + ${com.sun.xml.version} + + + + + org.apache.maven.plugins + maven-compiler-plugin + 3.8.0 + + 8 + 8 + + + + \ No newline at end of file diff --git a/CDAGenerator/src/main/java/de/fhg/isst/cda/choices/clinicalstatements/Observation.java b/CDAGenerator/src/main/java/de/fhg/isst/cda/choices/clinicalstatements/Observation.java index e2f3a0e..ca9d0c5 100644 --- a/CDAGenerator/src/main/java/de/fhg/isst/cda/choices/clinicalstatements/Observation.java +++ b/CDAGenerator/src/main/java/de/fhg/isst/cda/choices/clinicalstatements/Observation.java @@ -2,6 +2,7 @@ import java.math.BigInteger; import java.util.ArrayList; +import java.util.List; import de.fhg.isst.cda.classes.ClinicalStatement; import de.fhg.isst.cda.classes.Code; @@ -25,6 +26,9 @@ public class Observation extends ClinicalStatement { /** The ids. */ private ArrayList ids; + + /** The template ids */ + private List templateId; /** The code. */ private Code code; @@ -111,10 +115,10 @@ public XActMoodDocumentObservation getMoodCode() { public void setMoodCode(XActMoodDocumentObservation moodCode) { this.moodCode = moodCode; } - + /** * Gets the ids. - * + * * @return the ids */ public ArrayList getIds() { @@ -123,6 +127,13 @@ public ArrayList getIds() { } return ids; } + + public List getTemplateId() { + if (templateId==null){ + templateId = new ArrayList<>(); + } + return templateId; + } /** * Sets the ids. diff --git a/CDAGenerator/src/main/java/de/fhg/isst/cda/services/CDAService.java b/CDAGenerator/src/main/java/de/fhg/isst/cda/services/CDAService.java index 2f23406..6bc1514 100644 --- a/CDAGenerator/src/main/java/de/fhg/isst/cda/services/CDAService.java +++ b/CDAGenerator/src/main/java/de/fhg/isst/cda/services/CDAService.java @@ -17,9 +17,6 @@ import javax.xml.validation.SchemaFactory; import javax.xml.validation.Validator; -import org.apache.log4j.LogManager; -import org.apache.log4j.Logger; -import org.apache.log4j.PropertyConfigurator; import org.hl7.v3.cda.*; import org.xml.sax.SAXException; @@ -116,6 +113,10 @@ import de.fhg.isst.cda.classes.Telecom; import de.fhg.isst.cda.exceptions.MissingAttributeException; import de.fhg.isst.cda.exceptions.MissingNodeException; +import java.io.Serializable; +import java.io.StringWriter; +import org.w3c.dom.CDATASection; +import org.w3c.dom.Element; // TODO: Auto-generated Javadoc /** @@ -129,22 +130,13 @@ public class CDAService { /** The factory. */ private ObjectFactory factory; - private Logger logger; - /** * Instantiates a new CDA Service. */ public CDAService() { - this.logger = LogManager.getLogger(CDAService.class.getName()); - this.log4j(); - } - - private void log4j() { - - PropertyConfigurator.configureAndWatch("log4j.properties"); this.factory = new ObjectFactory(); } - + /** * Save. * @@ -175,6 +167,43 @@ public void save(String xmlPath, CDADocument mapDocument) throws MissingAttribut marshaller.marshal(saveDoc, os); os.close(); } + /** + * Save. + * + * @param file + * @param mapDocument + * @throws MissingAttributeException + * @throws MissingNodeException + * @throws FileNotFoundException + * @throws JAXBException + * @throws IOException + */ + public void save(File file, CDADocument mapDocument)throws MissingAttributeException, MissingNodeException, FileNotFoundException, + JAXBException, IOException { + POCDMT000040ClinicalDocument saveDoc = this.generate(mapDocument); + + OutputStream os = new FileOutputStream(file); + JAXBContext jaxbcontext = JAXBContext.newInstance(POCDMT000040ClinicalDocument.class); + Marshaller marshaller = jaxbcontext.createMarshaller(); + marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); + + marshaller.marshal(saveDoc, os); + os.close(); + } + + public String getCdaString(CDADocument mapDocument)throws MissingAttributeException, MissingNodeException, FileNotFoundException, + JAXBException, IOException { + POCDMT000040ClinicalDocument saveDoc = this.generate(mapDocument); + + StringWriter writer = new StringWriter(); + JAXBContext jaxbcontext = JAXBContext.newInstance(POCDMT000040ClinicalDocument.class); + Marshaller marshaller = jaxbcontext.createMarshaller(); + marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); + + marshaller.marshal(saveDoc, writer); + + return writer.toString(); + } /** * Prints the. @@ -212,7 +241,6 @@ public void print(CDADocument mapDocument) throws MissingAttributeException, Mis * @return true, if successful */ public boolean validate(String xsdPath, String xmlPath) { - this.logger.trace("Entering CDA Validation"); boolean state = false; try { SchemaFactory factory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI); @@ -221,10 +249,8 @@ public boolean validate(String xsdPath, String xmlPath) { validator.validate(new StreamSource(new File(xmlPath))); state = true; } catch (SAXException | IOException e) { - this.logger.error("CDA Validation Error"); - this.logger.error(e.getMessage()); + e.printStackTrace(); } - this.logger.trace("Exiting CDA Validation"); return state; } @@ -3287,6 +3313,13 @@ private POCDMT000040Observation createCDAObservation(Observation mapObservation) } } + if (!mapObservation.getTemplateId().isEmpty()){ + for (ID templateId : mapObservation.getTemplateId()) + { + cdaObservation.getTemplateId().add(createCDAId(templateId)); + } + } + if (mapObservation.getCode() != null) { cdaObservation.setCode(this.createCDACE(mapObservation.getCode())); } @@ -3334,10 +3367,15 @@ private POCDMT000040Observation createCDAObservation(Observation mapObservation) } if (mapObservation.getValue()!=null) { - if (mapObservation.getValue() instanceof String) { ED mapObservationValue = factory.createED(); - mapObservationValue.getContent().add((String)mapObservation.getValue()); + String value = (String) mapObservation.getValue(); + if(value.equals("CDA_CONSENT_SAML")) + { + mapObservationValue.setMediaType("text/xml"); + mapObservationValue.setRepresentation(BinaryDataEncoding.TXT); + } + mapObservationValue.getContent().add(value); cdaObservation.getValue().add(mapObservationValue); } else if (mapObservation.getValue() instanceof Code) {