Skip to content

Commit

Permalink
hapifhir#43: add hapi-bom module
Browse files Browse the repository at this point in the history
  • Loading branch information
ohr committed May 28, 2020
1 parent d09c11c commit 5b3a318
Show file tree
Hide file tree
Showing 15 changed files with 160 additions and 41 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ GNU General Public License (the �GPL�), in which case the provisions of the
import java.util.Set;

import ca.uhn.hl7v2.DefaultHapiContext;
import ca.uhn.hl7v2.model.GenericMessage;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.w3c.dom.DOMException;
Expand Down Expand Up @@ -106,6 +107,12 @@ public DefaultXMLParser(ModelClassFactory theFactory) {
public Document encodeDocument(Message source) throws HL7Exception {
String messageClassName = source.getClass().getName();
String messageName = messageClassName.substring(messageClassName.lastIndexOf('.') + 1);

// Handle GenericMessages which will have an errant $ in their class name.
if (source instanceof GenericMessage) {
messageName = messageName.replaceAll("\\$", "");
}

try {
Document doc = XMLUtils.emptyDocument(messageName);
encode(source, doc.getDocumentElement());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -749,8 +749,8 @@ public void parse(Message message, String string) throws HL7Exception {

messageIter.setDirection(name);
FilterIterator.Predicate<Structure> byDirection = obj -> {
log.debug("PipeParser iterating message in direction {} at {} ", name, ((Structure) obj).getName());
return ((Structure) obj).getName().matches(name + "\\d*");
log.debug("PipeParser iterating message in direction {} at {} ", name, obj.getName());
return obj.getName().matches(name + "\\d*");
};
FilterIterator<Structure> dirIter = new FilterIterator<>(segmentIter, byDirection);
if (dirIter.hasNext()) {
Expand Down
6 changes: 3 additions & 3 deletions hapi-base/src/main/java/ca/uhn/hl7v2/parser/XMLParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -233,15 +233,15 @@ protected String doEncode(Message source, String encoding) throws HL7Exception {
* fields are null)
*/
protected String doEncode(Message source) throws HL7Exception {
/*
if (source instanceof GenericMessage) {
throw new HL7Exception(
"Can't XML-encode a GenericMessage. Message must have a recognized structure.");
}
*/
log.info("XML-Encoding a GenericMessage is not covered by the specification. ");

Document doc = encodeDocument(source);
// Element documentElement = doc.getDocumentElement();
// if (!documentElement.hasAttribute("xmlns"))
// documentElement.setAttribute("xmlns", "urn:hl7-org:v2xml");
try {
return XMLUtils.serialize(doc, getParserConfiguration().isPrettyPrintWhenEncodingXml());
} catch (Exception e) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
#This file contains mappings from HL7 character set codes (table 211) to character set names recognized by Java

#The following are supported by all Java platforms:
ASCII US-ASCII
8859/1 ISO-8859-1
UNICODE UTF-16
ASCII=US-ASCII
8859/1=ISO-8859-1
UNICODE=UTF-16

#The following additional codes work on the standard JVM:
"ISO IR159" JIS_X0212-1990
8859/2 ISO-8859-2
8859/3 ISO-8859-3
8859/4 ISO-8859-4
8859/5 ISO-8859-5
8859/6 ISO-8859-6
8859/7 ISO-8859-7
8859/8 ISO-8859-8
8859/9 ISO-8859-9
"ISO=IR159" JIS_X0212-1990
8859/2=ISO-8859-2
8859/3=ISO-8859-3
8859/4=ISO-8859-4
8859/5=ISO-8859-5
8859/6=ISO-8859-6
8859/7=ISO-8859-7
8859/8=ISO-8859-8
8859/9=ISO-8859-9

#The following are not supported by the standard JVM but are included for possible use in another JVM:
"ISO IR14" JIS_C6220-1969-ro
"ISO IR87" JIS_C6226-1983
"ISO=IR14" JIS_C6220-1969-ro
"ISO=IR87" JIS_C6226-1983

#The following are supported by all Java platforms but don't appear in HL7 table 0211:
#UTF-8: Eight-bit UCS Transformation Format
Expand Down
91 changes: 91 additions & 0 deletions hapi-bom/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<artifactId>hapi-bom</artifactId>
<packaging>pom</packaging>
<name>HAPI - Java HL7 API - BOM</name>

<parent>
<artifactId>hapi</artifactId>
<groupId>ca.uhn.hapi</groupId>
<version>2.4-SNAPSHOT</version>
</parent>

<dependencyManagement>
<dependencies>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>hapi-base</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>hapi-structures-v21</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>hapi-structures-v22</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>hapi-structures-v23</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>hapi-structures-v24</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>hapi-structures-v25</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>hapi-structures-v26</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>hapi-structures-v27</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>hapi-structures-v28</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>hapi-structures-v231</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>hapi-structures-v231-alternatenames</artifactId>
<version>${project.version}</version>
</dependency>
<!--
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>hapi-structures-v271</artifactId>
<version>${project.version}</version>
</dependency>
-->
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>hapi-structures-v281</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>hapi-hl7overhttp</artifactId>
<version>${project.version}</version>
</dependency>

</dependencies>
</dependencyManagement>
</project>
2 changes: 1 addition & 1 deletion hapi-hl7overhttp/cobertura/js/sortabletable.js
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@ SortableTable.prototype.getCache = function (sType, nColumn) {
value: this.getRowValue(r, sType, nColumn),
element: r
};
};
}
return a;
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,11 +95,11 @@ public static void makeAll(String baseDirectory, String version, String theTempl
String basePackage = DefaultModelClassFactory.getVersionPackageName(version);

String hapiTestGenType = System.getProperty("hapi.test.gentype");
if (hapiTestGenType != null && !hapiTestGenType.contains((String) type)) {
if (hapiTestGenType != null && !hapiTestGenType.contains(type)) {
continue;
}

make(targetDir, (String) type, version, basePackage, theTemplatePackage, theFileExt);
make(targetDir, type, version, basePackage, theTemplatePackage, theFileExt);
} catch (DataTypeException dte) {
log.warn("{} - {}", dte.getClass().getName(), dte.getMessage());
} catch (Exception e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ GNU General Public License (the "GPL"), in which case the provisions of the GPL

import java.io.*;
import java.net.URL;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Iterator;
Expand Down Expand Up @@ -196,7 +197,7 @@ private void writeFile(String source, DatatypeDef def, Version version) throws I
}
String targetFile = String.format("%s/%s.java", dirName, def.getType());

try (BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(targetFile, false), "UTF-8"))) {
try (BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(targetFile, false), StandardCharsets.UTF_8))) {
writer.write(source);
writer.flush();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ GNU General Public License (the "GPL"), in which case the provisions of the GPL

import java.io.*;
import java.net.URL;
import java.nio.charset.StandardCharsets;
import java.util.*;

import ca.uhn.hl7v2.Version;
Expand Down Expand Up @@ -179,7 +180,7 @@ private void writeFile(String source, String type, String name, Version version)
}
String targetFile = String.format("%s/%s.java", dirName, name);

try (BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(targetFile, false), "UTF-8"))) {
try (BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(targetFile, false), StandardCharsets.UTF_8))) {
writer.write(source);
writer.flush();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ GNU General Public License (the "GPL"), in which case the provisions of the GPL

import java.io.*;
import java.net.URL;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Iterator;
Expand Down Expand Up @@ -214,7 +215,7 @@ private void writeFile(String source, String segmentName, Version version) throw
}
String targetFile = String.format("%s/%s.java", dirName, segmentName);

try (BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(targetFile, false), "UTF-8"))) {
try (BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(targetFile, false), StandardCharsets.UTF_8))) {
writer.write(source);
writer.flush();
}
Expand Down
2 changes: 1 addition & 1 deletion hapi-test/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,7 @@
<artifactId>maven-surefire-plugin</artifactId>
<version>${maven.surefire.plugin.version}</version>
<configuration>
<argLine>-Xmx512m -XX:MaxPermSize=128m</argLine>
<argLine>-Xmx512m</argLine>
<forkMode>once</forkMode>
</configuration>
</plugin>
Expand Down
18 changes: 17 additions & 1 deletion hapi-test/src/test/java/ca/uhn/hl7v2/parser/XMLParserTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
package ca.uhn.hl7v2.parser;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
// import hapi.on.olis.erp_z99.message.ERP_R09;
Expand All @@ -18,6 +19,8 @@

import ca.uhn.hl7v2.DefaultHapiContext;
import ca.uhn.hl7v2.HapiContext;
import ca.uhn.hl7v2.Version;
import ca.uhn.hl7v2.model.GenericMessage;
import ca.uhn.hl7v2.util.Hl7InputStreamMessageIterator;
import org.junit.Before;
import org.junit.Ignore;
Expand Down Expand Up @@ -443,7 +446,7 @@ public void testMessageParseMethodAndEncodeMethodWithEscapes() throws HL7Excepti
* </p>
*/
@Test
public void test_ParseEncodedXml() throws Exception {
public void testParseEncodedXml() throws Exception {

// Create a context
HapiContext context = new DefaultHapiContext();
Expand All @@ -464,6 +467,19 @@ public void test_ParseEncodedXml() throws Exception {
}
}

@Test
public void testEncodeGenericMessage() throws Exception {
DefaultXMLParser xmlParser = new DefaultXMLParser();
for (Version version : Version.values()) {
Class<? extends Message> c = GenericMessage.getGenericMessageClass(version.getVersion());
Message m = c.getConstructor(ModelClassFactory.class).newInstance(new GenericModelClassFactory());
Document d = xmlParser.encodeDocument(m);
assertNotNull(d);
assertEquals("GenericMessage" + version.name(), d.getDocumentElement().getTagName());
assertNotNull(xmlParser.encode(m));
}
}

private String loadFile(String name) throws IOException {
return loadFile(name, '\n');
}
Expand Down
2 changes: 1 addition & 1 deletion hapi-testmindeps/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@
<artifactId>maven-surefire-plugin</artifactId>
<version>${maven.surefire.plugin.version}</version>
<configuration>
<argLine>-Xmx512m -XX:MaxPermSize=128m</argLine>
<argLine>-Xmx512m</argLine>
<forkMode>once</forkMode>
</configuration>
</plugin>
Expand Down
4 changes: 2 additions & 2 deletions hapi-testnodeps/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
<artifactId>maven-surefire-plugin</artifactId>
<version>${maven.surefire.plugin.version}</version>
<configuration>
<argLine>-Xmx512m -XX:MaxPermSize=128m</argLine>
<argLine>-Xmx512m</argLine>
<forkMode>once</forkMode>
</configuration>
</plugin>
Expand All @@ -68,7 +68,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-report-plugin</artifactId>
<version>2.7.2</version>
<version>${maven.surefire.report.plugin.version}</version>
</plugin>
</plugins>
</reporting>
Expand Down
Loading

0 comments on commit 5b3a318

Please sign in to comment.