/*
* XMLParserTest.java
*
* Created on March 15, 2002, 12:53 PM
*/
package ca.uhn.hl7v2.parser;
import java.io.IOException;
import java.io.InputStream;
import junit.framework.Assert;
import junit.framework.TestCase;
import ca.uhn.hl7v2.HL7Exception;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.w3c.dom.Document;
import ca.uhn.hl7v2.model.Composite;
import ca.uhn.hl7v2.model.Message;
import ca.uhn.hl7v2.model.Segment;
import ca.uhn.hl7v2.model.Type;
import ca.uhn.hl7v2.model.v25.datatype.ED;
import ca.uhn.hl7v2.model.v25.datatype.ST;
import ca.uhn.hl7v2.model.v25.message.OMD_O03;
import ca.uhn.hl7v2.model.v25.message.ORU_R01;
/**
* JUnit test harness for XMLParser
* @author Bryan Tripp
*/
public class XMLParserTest extends TestCase {
XMLParser parser;
private static final Log ourLog = LogFactory.getLog(XMLParserTest.class);
/** Creates a new instance of XMLParserTest */
public XMLParserTest(String arg) {
super(arg);
}
public void setUp() throws Exception {
parser = new DummyXMLParser();
}
public void tearDown() throws Exception {
}
/**
* Tests a fix to bug 2164291
*
* XML parsing of segments which appear twice in a message structure definition (e.g. the
* duplicate PID segments in a swap patient message) should be handled correctly.
*/
public void testParseDuplicateSegment() throws IOException, EncodingNotSupportedException, HL7Exception {
InputStream stream = XMLParserTest.class.getClassLoader().getResourceAsStream("ca/uhn/hl7v2/parser/adt_a17.xml");
byte[] bytes = new byte[10000];
StringBuffer buffer = new StringBuffer();
int count;
while ((count = stream.read(bytes)) > 0) {
buffer.append(new String(bytes), 0, count);
}
String xmlMessage = buffer.toString();
Message message = new DefaultXMLParser().parse(xmlMessage);
String er7Message = new PipeParser().encode(message).replaceAll("\\r", "\r\n");
System.out.println("Re-encoded:\r\n" + er7Message);
// We should have only two reps of PID
int firstIndex = er7Message.indexOf("PID");
int secondIndex = er7Message.indexOf("PID", firstIndex + 1);
int thirdIndex = er7Message.indexOf("PID", secondIndex + 1);
assertTrue(firstIndex > 0);
assertTrue(secondIndex > firstIndex);
assertTrue("Found third PID " + firstIndex + " " + secondIndex + " " + thirdIndex + ":\r\n" + er7Message, thirdIndex == -1);
}
public void testGetAckID() throws HL7Exception {
assertEquals(parser.getAckID("12"), "12");
assertEquals(parser.getAckID(" help >>> *** x");
assertEquals(null, ackID);
ackID = parser.getAckID("x");
assertEquals(null, ackID);
ackID = parser.getAckID(" 12 \r");
assertEquals("12", ackID);
ackID = parser.getAckID("|^~/&MPIISOHealthLinkISOUHN VistaISOUHNISO200204292049RSPK22RSP_K22200204292049100799P2.4Q22AA876OKQ22");
assertEquals("876", ackID);
}
public void testGetEncoding() throws Exception {
String test1 = "\r|\r^~\\&\r";
String test2 = "\r|\r^~\\&\r"; //bad: no
assertEquals("XML", parser.getEncoding(test1));
assertEquals(null, parser.getEncoding(test2));
}
/*public void testParse() throws Exception {
String test1 = "\r|\r^~\\&\r";
Message m = parser.parse(test1);
assertEquals(null, m);
}*/
public void testGetVersion() throws Exception {
String message = " | ^~/& UHN Vista ISO UHN ISO MPI ISO HealthLink ISO 20020429132718.734-0400 QBP Q22 QBP_Q21 855 P 2.4 Q22 Q22 Find Candidates HL7nnnn @PID.3.19583518684@PID.3.4.1CANON@PID.5.1.1ECG-Acharya@PID.5.2Nf@PID.5.7L@PID.7197104010000@PID.8M 100 TTH 13831ULTIuser2234564R&H Med I 100RD R ";
String ver = parser.getVersion(message);
assertEquals("2.4", ver);
}
public void testRemoveWhitespace() throws Exception {
assertEquals("hello", parser.removeWhitespace("\t\r\nhello "));
assertEquals("hello there", parser.removeWhitespace(" hello \t \rthere\r\n"));
}
/**
* -
* @throws HL7Exception -
*/
public void testGetCriticalResponseData() throws HL7Exception {
String message = "\r\n" +
" \r\n" +
" |\r\n" +
" ^~\\&\r\n" +
" LABMI1\r\n" +
" DMCRES\r\n" +
" \r\n" +
" 19951010134000\r\n" +
" \r\n" +
" \r\n" +
" ORU\r\n" +
" R01\r\n" +
" \r\n" +
" LABMI1199510101340007\r\n" +
" D\r\n" +
" 2.2\r\n" +
" AL\r\n" +
" ";
Segment data = parser.getCriticalResponseData(message);
Type actual = data.getField(2, 0);
String expected = "^~\\&";
assertEquals(expected, actual.toString()); // Encoding
}
public class DummyXMLParser extends XMLParser {
public DummyXMLParser() throws HL7Exception {
super();
}
public Message parseDocument(Document XMLMessage, String version) throws HL7Exception {
return null;
}
public Document encodeDocument(Message source) throws HL7Exception {
return null;
}
}
public void testEdIssue() throws EncodingNotSupportedException, HL7Exception {
String messageText = "\r\n" +
" \r\n" +
" |\r\n" +
" ^~\\&\r\n" +
" \r\n" +
" APPNAME\r\n" +
" \r\n" +
" \r\n" +
" VENDOR NAME\r\n" +
" \r\n" +
" \r\n" +
" CLINIC APPLICATION\r\n" +
" \r\n" +
" \r\n" +
" CLINIC ID\r\n" +
" \r\n" +
" \r\n" +
" 20100723170708\r\n" +
" \r\n" +
" \r\n" +
" ORU\r\n" +
" R01\r\n" +
" \r\n" +
" 12345\r\n" +
" \r\n" +
" P\r\n" +
" \r\n" +
" \r\n" +
" 2.5\r\n" +
" \r\n" +
" \r\n" +
" \r\n" +
" \r\n" +
" \r\n" +
" \r\n" +
" MODEL:xxx/SERIAL:xxx\r\n" +
" \r\n" +
" STJ\r\n" +
" \r\n" +
" U\r\n" +
" \r\n" +
" \r\n" +
" \r\n" +
" Doe\r\n" +
" \r\n" +
" John\r\n" +
" Adams\r\n" +
" \r\n" +
" \r\n" +
" 197903110920\r\n" +
" \r\n" +
" M\r\n" +
" \r\n" +
" \r\n" +
" Street\r\n" +
" \r\n" +
" City\r\n" +
" 06531\r\n" +
" Country\r\n" +
" \r\n" +
" \r\n" +
" \r\n" +
" \r\n" +
" 1\r\n" +
" R\r\n" +
" \r\n" +
" DoctorID\r\n" +
" \r\n" +
" \r\n" +
" 123456\r\n" +
" \r\n" +
" \r\n" +
" \r\n" +
" \r\n" +
" \r\n" +
" \r\n" +
" 1\r\n" +
" \r\n" +
" 123456\r\n" +
" \r\n" +
" \r\n" +
" Remote Follow-up\r\n" +
" \r\n" +
" \r\n" +
" 20040328134623\r\n" +
" \r\n" +
" \r\n" +
" 20040328134623\r\n" +
" \r\n" +
" \r\n" +
" 20040328134623\r\n" +
" \r\n" +
" F\r\n" +
" \r\n" +
" \r\n" +
" 1\r\n" +
" L\r\n" +
" Comment\r\n" +
" \r\n" +
" \r\n" +
" \r\n" +
" 1\r\n" +
" ST\r\n" +
" \r\n" +
" 257\r\n" +
" MDC-IDC_SYSTEM_STATUS\r\n" +
" MDC_IDC\r\n" +
" \r\n" +
" 1\r\n" +
" \r\n" +
" m\r\n" +
" \r\n" +
" L\r\n" +
" F\r\n" +
" \r\n" +
" 20070422170125\r\n" +
" \r\n" +
" \r\n" +
" LastFU\r\n" +
" Since Last Follow-up Aggregate\r\n" +
" \r\n" +
" \r\n" +
" \r\n" +
" \r\n" +
" \r\n" +
" 2\r\n" +
" ED\r\n" +
" \r\n" +
" 18750-0\r\n" +
" Cardiac Electrophysiology Report\r\n" +
" LN\r\n" +
" \r\n" +
" \r\n" +
" Application\r\n" +
" PDF\r\n" +
" Base64\r\n" +
"\r\n" +
"\r\n" +
"JVBERi0xLjMKJeLjz9MKCjEgMCBvYmoKPDwgL1R5cGUgL0NhdGFsb2cKL091dGxpbmVzID\r\n" +
"IgMCBS\r\n" +
"\r\n" +
"Ci9QYWdlcyAzIDAgUgovT3BlbkFjdGlvbiA4IDAgUiA+PgplbmRvYmoKMiAwIG9iago8PCAvVHlw\r\n" +
"\r\n" +
"ZSAvT3V0bGluZXMgL0NvdW50IDAgPj4KZW5kb2JqCjMgMCBvYmoKPDwgL1R5cGUgL1BhZ2VzCi9L\r\n" +
"\r\n" +
"aWRzIFs2IDAgUgpdCi9Db3VudCAxCi9SZXNvdXJjZXMgPDwKL1Byb2NTZXQgNCAwIFIKL0ZvbnQg\r\n" +
"\r\n" +
"PDwgCi9GMSAxMSAwIFIKL0YyIDEyIDAgUgovRjMgMTcgMCBSID4+Ci9YT2JqZWN0IDw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BuIAowMDAwMDAwMDk4IDAwMDAwIG4gCjAwMDAwMDAxNDQgMDAwMDAgbiAKMDAw\r\n" +
"\r\n" +
"MDAwMDM0NyAwMDAwMCBuIAowMDAwMDAwMzg0IDAwMDAwIG4gCjAwMDAwMDA0NjAgMDAwMDAgbiAK\r\n" +
"\r\n" +
"MDAwMDAwMDU0OSAwMDAwMCBuIAowMDAwMDAxNTM5IDAwMDAwIG4gCjAwMDAwMDE1NjggMDAwMDAg\r\n" +
"\r\n" +
"biAKMDAwMDAwMzg2OCAwMDAwMCBuIAowMDAwMDA0MDUyIDAwMDAwIG4gCjAwMDAwMDQxNjAgMDAw\r\n" +
"\r\n" +
"MDAgbiAKMDAwMDAwNDI4MCAwMDAwMCBuIAowMDAwMDA0NDA4IDAwMDAwIG4gCjAwMDAwMDQ0ODgg\r\n" +
"\r\n" +
"MDAwMDAgbiAKMDAwMDAwNDYxNCAwMDAwMCBuIAowMDAwMDA0Njk1IDAwMDAwIG4gCnRyYWlsZXIK\r\n" +
"\r\n" +
"PDwKL1NpemUgMTgKL1Jvb3QgMSAwIFIKL0luZm8gNSAwIFIKPj4Kc3RhcnR4cmVmCjQ4MDgKJSVF\r\n" +
"T0YK\r\n" +
" \r\n" +
" F\r\n" +
" \r\n" +
" 20070422170125\r\n" +
" \r\n" +
" \r\n" +
" \r\n" +
" \r\n" +
" \r\n" +
" 3\r\n" +
" CE\r\n" +
" \r\n" +
" 257\r\n" +
" MDC-IDC_SYSTEM_STATUS\r\n" +
" MDC_IDC\r\n" +
" \r\n" +
" 1\r\n" +
" \r\n" +
" T57000\r\n" +
" GALLBLADDER\r\n" +
" SNM\r\n" +
" \r\n" +
" \r\n" +
" m\r\n" +
" \r\n" +
" L\r\n" +
" F\r\n" +
" \r\n" +
" 20070422170125\r\n" +
" \r\n" +
" \r\n" +
" LastFU\r\n" +
" Since Last Follow-up Aggregate\r\n" +
" \r\n" +
" \r\n" +
" \r\n" +
" \r\n" +
" \r\n" +
"";
ORU_R01 message = (ORU_R01) new DefaultXMLParser().parse(messageText);
ED obx5 = (ED) message.getPATIENT_RESULT().getORDER_OBSERVATION().getOBSERVATION(1).getOBX().getObx5_ObservationValue(0).getData();
assertTrue(obx5.getData().getValue().startsWith("JVBERi0xLjMKJeLjz9MKCjEgMCBvYmoKPDwgL1R5cG"));
}
/**
* Test for issue reported here: https://sourceforge.net/tracker/?func=detail&aid=3115671&group_id=38899&atid=423835
*/
public void testEncodeOmdO03() throws EncodingNotSupportedException, HL7Exception {
String texto = "MSH|^~\\&|DIETOOLS|1^DOMINION|JARA||20101027181706||OMD^O03^OMD_O03|20101027181706|P|2.5|||ER|AL\r"+
"PID|1||CIPNUM^^^CAEX^CIP^^^^EX&&ES-EX||DUMAS^VICTOR HUGO|ZAPATA|19740325|1\r"+
"PV1|1|I|^^51C302-1^^^^^^^0005&51UHP31&UH TERCERA 1 HSPA&TIPOUOENF||||||||||||||||100002739^005^^^^^^^^0005&APARATO DIGESTIVO&5DIG&TIPOUOSERV|\r"+
"ORC|XO||||||||20101117|1^^HERNAME\r"+
"TQ1|1||CE||||20101117\r"+
"ODS|D||PAN4^PEDIATRICA 1|\r"+
"ODS|P||EVENTO^LACT|\r"+
"ODS|P||CARACTERISTICA^SIN SAL|\r"+
"ODS|P||CARACTERISTICA^DIABETICO|\r";
String textoXML = new String();
//parseamos para conseguir un string de un xml con formato hl7
XMLParser xmlParser = new DefaultXMLParser();
PipeParser pipeParser = new PipeParser();
OMD_O03 msg = (OMD_O03) pipeParser.parse(texto);
textoXML = xmlParser.encode(msg);
System.out.println("Objeto transformado0: " + textoXML);
Assert.assertTrue(textoXML.contains("OMD_O03.DIET"));
}
/**
* See https://sourceforge.net/tracker/?func=detail&atid=423835&aid=3308845&group_id=38899
*/
public void testEncodeLongValuesDoesntWrap() throws HL7Exception, IOException {
// OBX-5 is a really really long string
String obx5Value = "AAAABBBB CCCCDDDD ";
obx5Value = obx5Value + obx5Value + obx5Value + obx5Value + obx5Value;
obx5Value = obx5Value + obx5Value + obx5Value + obx5Value + obx5Value;
obx5Value = obx5Value.trim();
ORU_R01 msg = new ORU_R01();
msg.initQuickstart("ORU", "R01", "T");
msg.getPATIENT_RESULT().getORDER_OBSERVATION().getOBSERVATION().getOBX().getObx2_ValueType().parse("ST");
msg.getPATIENT_RESULT().getORDER_OBSERVATION().getOBSERVATION().getOBX().getObx5_ObservationValue(0).parse(obx5Value);
DefaultXMLParser p = new DefaultXMLParser();
String encoded = p.encode(msg);
ourLog.info("Encoded: " + encoded);
msg = (ORU_R01) p.parse(encoded);
ST st = (ST) msg.getPATIENT_RESULT().getORDER_OBSERVATION().getOBSERVATION().getOBX().getObx5_ObservationValue(0).getData();
String actual = st.getValue();
Assert.assertEquals(obx5Value, actual);
}
}