Dear to all.
I have a problem with the XML parsing of a RSP^SLI^K11 template message. The starting pipe message is taken from the reference Laboratory IHE technical framework V2. I have a simple Java class, attached (ExampleParser.java), that converts the starting HL7 piped message to XML, and then re-converts it to pipe. The problem is that the second piped message is different from the starting one because segments are switched in order, and this is bad because the SPM segment must collect one or more ORC-OBR-TQ1 3-segment ordered groups, and I lose this order in the final piped XML message, as you can see from standard output (output.txt). I tried this because the same conversion problem occurred me inside a Mirth XML transformation
Am I getting wrong ? Could someone help me?

Regards
Alessandro
START PIPE MESSAGE:MSH|^~\&|LIP|Enter-gastric department|LB|LBL system 
|200701121348||RSP^SLI^RSP_K11|001|P|2.5|||||USA||EN
MSA|AA|||||
QAK|~111069|~OK|~Q22^Specimen Labeling Instructions^IHE_LABTF|~2
QPD|SLI^Specimen Labeling Instructions^IHE_LABTF||1004081037537080|||||
PID|1||1111222^^^Suzuki National Hospital^PI||Toyota^Taro^^^^^L||19810101|M
PV1|1|O|||||||||||||||||3333444
SPM|1|1234560001||001^Venous blood|||||||P||||||20070112|||||||||1|021^Chemistry
ORC|NW|1234561|||||||200701121348|14789^Yamada^Jiro||14789^Yamada^Jiro|||||051^Entergastricdepartment
TQ1|||||||||R
OBR||1234561||17432^liver function^local|||||6.0|||||||14789^Yamada^Jiro
SPM|1|1234560002||001^Venous 
blood|||||||P||||||20070112|||||||||1|015^hematology
ORC|NW|1234562|||||||200701121348|14789^Yamada^Jiro||14789^Yamada^Jiro|||||051^Entergastricdepartment
TQ1|||||||||R
OBR||1234562||18655^blood count^local|||||2.0|||||||14789^Yamada^Jiro

log4j:WARN No appenders could be found for logger 
(ca.uhn.hl7v2.parser.DefaultModelClassFactory).
log4j:WARN Please initialize the log4j system properly.
XML ENCODED MESSAGE:<?xml version="1.0"?>
<RSP_K11 xmlns="urn:hl7-org:v2xml">
    <MSH>
        <MSH.1>|</MSH.1>
        <MSH.2>^~\&amp;</MSH.2>
        <MSH.3>
            <HD.1>LIP</HD.1>
        </MSH.3>
        <MSH.4>
            <HD.1>Enter-gastric department</HD.1>
        </MSH.4>
        <MSH.5>
            <HD.1>LB</HD.1>
        </MSH.5>
        <MSH.6>
            <HD.1>LBL system </HD.1>
        </MSH.6>
        <MSH.7>
            <TS.1>200701121348</TS.1>
        </MSH.7>
        <MSH.9>
            <MSG.1>RSP</MSG.1>
            <MSG.2>SLI</MSG.2>
            <MSG.3>RSP_K11</MSG.3>
        </MSH.9>
        <MSH.10>001</MSH.10>
        <MSH.11>
            <PT.1>P</PT.1>
        </MSH.11>
        <MSH.12>
            <VID.1>2.5</VID.1>
        </MSH.12>
        <MSH.17>USA</MSH.17>
        <MSH.19>
            <CE.1>EN</CE.1>
        </MSH.19>
    </MSH>
    <MSA>
        <MSA.1>AA</MSA.1>
    </MSA>
    <QAK>
        <QAK.1>111069</QAK.1>
        <QAK.2>OK</QAK.2>
        <QAK.3>
            <CE.1>Q22</CE.1>
            <CE.2>Specimen Labeling Instructions</CE.2>
            <CE.3>IHE_LABTF</CE.3>
        </QAK.3>
        <QAK.4>2</QAK.4>
    </QAK>
    <QPD>
        <QPD.1>
            <CE.1>SLI</CE.1>
            <CE.2>Specimen Labeling Instructions</CE.2>
            <CE.3>IHE_LABTF</CE.3>
        </QPD.1>
        <QPD.3>1004081037537080</QPD.3>
    </QPD>
    <PID>
        <PID.1>1</PID.1>
        <PID.3>
            <CX.1>1111222</CX.1>
            <CX.4>
                <HD.1>Suzuki National Hospital</HD.1>
            </CX.4>
            <CX.5>PI</CX.5>
        </PID.3>
        <PID.5>
            <XPN.1>
                <FN.1>Toyota</FN.1>
            </XPN.1>
            <XPN.2>Taro</XPN.2>
            <XPN.7>L</XPN.7>
        </PID.5>
        <PID.7>
            <TS.1>19810101</TS.1>
        </PID.7>
        <PID.8>M</PID.8>
    </PID>
    <PV1>
        <PV1.1>1</PV1.1>
        <PV1.2>O</PV1.2>
        <PV1.19>
            <CX.1>3333444</CX.1>
        </PV1.19>
    </PV1>
    <SPM>
        <SPM.1>1</SPM.1>
        <SPM.2>
            <EIP.1>
                <EI.1>1234560001</EI.1>
            </EIP.1>
        </SPM.2>
        <SPM.4>
            <CWE.1>001</CWE.1>
            <CWE.2>Venous blood</CWE.2>
        </SPM.4>
        <SPM.11>
            <CWE.1>P</CWE.1>
        </SPM.11>
        <SPM.17>
            <DR.1>
                <TS.1>20070112</TS.1>
            </DR.1>
        </SPM.17>
        <SPM.26>1</SPM.26>
        <SPM.27>
            <CWE.1>021</CWE.1>
            <CWE.2>Chemistry</CWE.2>
        </SPM.27>
    </SPM>
    <ORC>
        <ORC.1>NW</ORC.1>
        <ORC.2>
            <EI.1>1234561</EI.1>
        </ORC.2>
        <ORC.9>
            <TS.1>200701121348</TS.1>
        </ORC.9>
        <ORC.10>
            <XCN.1>14789</XCN.1>
            <XCN.2>
                <FN.1>Yamada</FN.1>
            </XCN.2>
            <XCN.3>Jiro</XCN.3>
        </ORC.10>
        <ORC.12>
            <XCN.1>14789</XCN.1>
            <XCN.2>
                <FN.1>Yamada</FN.1>
            </XCN.2>
            <XCN.3>Jiro</XCN.3>
        </ORC.12>
        <ORC.17>
            <CE.1>051</CE.1>
            <CE.2>Entergastricdepartment</CE.2>
        </ORC.17>
    </ORC>
    <TQ1>
        <TQ1.9>
            <CWE.1>R</CWE.1>
        </TQ1.9>
    </TQ1>
    <OBR>
        <OBR.2>
            <EI.1>1234561</EI.1>
        </OBR.2>
        <OBR.4>
            <CE.1>17432</CE.1>
            <CE.2>liver function</CE.2>
            <CE.3>local</CE.3>
        </OBR.4>
        <OBR.9>
            <CQ.1>6.0</CQ.1>
        </OBR.9>
        <OBR.16>
            <XCN.1>14789</XCN.1>
            <XCN.2>
                <FN.1>Yamada</FN.1>
            </XCN.2>
            <XCN.3>Jiro</XCN.3>
        </OBR.16>
    </OBR>
    <SPM>
        <SPM.1>1</SPM.1>
        <SPM.2>
            <EIP.1>
                <EI.1>1234560002</EI.1>
            </EIP.1>
        </SPM.2>
        <SPM.4>
            <CWE.1>001</CWE.1>
            <CWE.2>Venous blood</CWE.2>
        </SPM.4>
        <SPM.11>
            <CWE.1>P</CWE.1>
        </SPM.11>
        <SPM.17>
            <DR.1>
                <TS.1>20070112</TS.1>
            </DR.1>
        </SPM.17>
        <SPM.26>1</SPM.26>
        <SPM.27>
            <CWE.1>015</CWE.1>
            <CWE.2>hematology</CWE.2>
        </SPM.27>
    </SPM>
    <ORC>
        <ORC.1>NW</ORC.1>
        <ORC.2>
            <EI.1>1234562</EI.1>
        </ORC.2>
        <ORC.9>
            <TS.1>200701121348</TS.1>
        </ORC.9>
        <ORC.10>
            <XCN.1>14789</XCN.1>
            <XCN.2>
                <FN.1>Yamada</FN.1>
            </XCN.2>
            <XCN.3>Jiro</XCN.3>
        </ORC.10>
        <ORC.12>
            <XCN.1>14789</XCN.1>
            <XCN.2>
                <FN.1>Yamada</FN.1>
            </XCN.2>
            <XCN.3>Jiro</XCN.3>
        </ORC.12>
        <ORC.17>
            <CE.1>051</CE.1>
            <CE.2>Entergastricdepartment</CE.2>
        </ORC.17>
    </ORC>
    <TQ1>
        <TQ1.9>
            <CWE.1>R</CWE.1>
        </TQ1.9>
    </TQ1>
    <OBR>
        <OBR.2>
            <EI.1>1234562</EI.1>
        </OBR.2>
        <OBR.4>
            <CE.1>18655</CE.1>
            <CE.2>blood count</CE.2>
            <CE.3>local</CE.3>
        </OBR.4>
        <OBR.9>
            <CQ.1>2.0</CQ.1>
        </OBR.9>
        <OBR.16>
            <XCN.1>14789</XCN.1>
            <XCN.2>
                <FN.1>Yamada</FN.1>
            </XCN.2>
            <XCN.3>Jiro</XCN.3>
        </OBR.16>
    </OBR>
</RSP_K11>

END PIPE MESSAGE:MSH|^~\&|LIP|Enter-gastric department|LB|LBL 
system|200701121348||RSP^SLI^RSP_K11|001|P|2.5|||||USA||EN
MSA|AA
QAK|111069|OK|Q22^Specimen Labeling Instructions^IHE_LABTF|2
QPD|SLI^Specimen Labeling Instructions^IHE_LABTF||1004081037537080
PID|1||1111222^^^Suzuki National Hospital^PI||Toyota^Taro^^^^^L||19810101|M
PV1|1|O|||||||||||||||||3333444
SPM|1|1234560001||001^Venous blood|||||||P||||||20070112|||||||||1|021^Chemistry
SPM|1|1234560002||001^Venous 
blood|||||||P||||||20070112|||||||||1|015^hematology
ORC|NW|1234561|||||||200701121348|14789^Yamada^Jiro||14789^Yamada^Jiro|||||051^Entergastricdepartment
ORC|NW|1234562|||||||200701121348|14789^Yamada^Jiro||14789^Yamada^Jiro|||||051^Entergastricdepartment
TQ1|||||||||R
TQ1|||||||||R
OBR||1234561||17432^liver function^local|||||6.0|||||||14789^Yamada^Jiro
OBR||1234562||18655^blood count^local|||||2.0|||||||14789^Yamada^Jiro
package it.hapitest;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.io.StringReader;

import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;

import org.w3c.dom.Document;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;

import ca.uhn.hl7v2.HL7Exception;
import ca.uhn.hl7v2.model.Message;
import ca.uhn.hl7v2.model.v25.message.ORU_R01;
import ca.uhn.hl7v2.parser.DefaultXMLParser;
import ca.uhn.hl7v2.parser.EncodingNotSupportedException;
import ca.uhn.hl7v2.parser.GenericParser;
import ca.uhn.hl7v2.parser.Parser;
import ca.uhn.hl7v2.parser.PipeParser;
import ca.uhn.hl7v2.parser.XMLParser;
import ca.uhn.hl7v2.util.Terser;

public class ExampleParser
{

public static void main(String[] args) throws EncodingNotSupportedException, 
HL7Exception, SAXException, IOException, ParserConfigurationException {
          
                
          String msg = "MSH|^~\\&|LIP|Enter-gastric department|LB|LBL system 
|200701121348||RSP^SLI^RSP_K11|001|P|2.5|||||USA||EN\r"
          +"MSA|AA|||||\r"
          +"QAK|~111069|~OK|~Q22^Specimen Labeling Instructions^IHE_LABTF|~2\r"
          +"QPD|SLI^Specimen Labeling 
Instructions^IHE_LABTF||1004081037537080|||||\r"
          +"PID|1||1111222^^^Suzuki National 
Hospital^PI||Toyota^Taro^^^^^L||19810101|M\r"
          +"PV1|1|O|||||||||||||||||3333444\r"
          +"SPM|1|1234560001||001^Venous 
blood|||||||P||||||20070112|||||||||1|021^Chemistry\r"
          
+"ORC|NW|1234561|||||||200701121348|14789^Yamada^Jiro||14789^Yamada^Jiro|||||051^Entergastricdepartment\r"
          +"TQ1|||||||||R\r"
          +"OBR||1234561||17432^liver 
function^local|||||6.0|||||||14789^Yamada^Jiro\r"
          +"SPM|1|1234560002||001^Venous 
blood|||||||P||||||20070112|||||||||1|015^hematology\r"
          
+"ORC|NW|1234562|||||||200701121348|14789^Yamada^Jiro||14789^Yamada^Jiro|||||051^Entergastricdepartment\r"
          +"TQ1|||||||||R\r"
          +"OBR||1234562||18655^blood 
count^local|||||2.0|||||||14789^Yamada^Jiro\r";
                  
          
          System.out.println("START PIPE MESSAGE:"+msg);
          PipeParser p = new PipeParser();
          Message hapiMsg = p.parse(msg);
          XMLParser xmlParser = new DefaultXMLParser();
          String msgStr = xmlParser.encode(hapiMsg);
          System.out.println("XML ENCODED MESSAGE:"+msgStr);
          
          DocumentBuilder builder = 
DocumentBuilderFactory.newInstance().newDocumentBuilder();
          Document doc = builder.parse(new InputSource(new 
StringReader(msgStr)));
          
          XMLParser defXMLParse = new DefaultXMLParser();
          defXMLParse.setValidationContext(null);
          Message finalMessage = defXMLParse.parseDocument(doc, "2.5");
          String endMsg = finalMessage.encode();
          System.out.println("END PIPE MESSAGE:"+endMsg);
          
     }
 
 }

------------------------------------------------------------------------------
_______________________________________________
Hl7api-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/hl7api-devel

Reply via email to