Luca89
Luca89

Reputation: 99

HAPI: Hl7 Parser do not separate the segment of the Hl7 message

I'm getting started to Hl7 using HAPI API. I have an Hl7 test message (picked up from a real case) and I want to read the field of the various segment (MSH, PID, PV1, etc.) The problem is that the Parser do not split the message in segments, but put all the message in the MSH segment. I tried both the PipeParser and the GenericParser. The message is an ORU_R01 message, version 2.3.1 (I used the debug and the getVersion() method to get those information)

Here is the test class

    import java.io.IOException;

import ca.uhn.hl7v2.DefaultHapiContext;
import ca.uhn.hl7v2.HL7Exception;
import ca.uhn.hl7v2.HapiContext;
import ca.uhn.hl7v2.model.Message;
import ca.uhn.hl7v2.model.v231.group.ORU_R01_PIDPD1NK1NTEPV1PV2;
import ca.uhn.hl7v2.model.v231.group.ORU_R01_PIDPD1NK1NTEPV1PV2ORCOBRNTEOBXNTECTI;
import ca.uhn.hl7v2.model.v231.message.ORU_R01;
import ca.uhn.hl7v2.model.v231.segment.MSH;
import ca.uhn.hl7v2.model.v231.segment.PID;
import ca.uhn.hl7v2.parser.Parser;

public class Hl7EncodeTester 
{
    public static void main (String[] args) throws HL7Exception, IOException
    {
        String msg = "MSH|^~\\&|REPO|BCS|THE|Theorema|201412170140||ORU^R01|20140012620415|P|2.3.1||||||||PID|||711697^^^^PI^PRIAMO~RSSMHL69B15B081W^^^^NN||ROSSINI^MICHELE||19690215|F|||VIA^POMPEI^6^ASSO^CO^22063||031700239|||M||RSSMHL69B15B081W|300CP102||||ASSO|||100|||||PV1|||265^INRCA Ospedale^^959^^^0310^^||||||||||||||||||||||||||||||||||||||||||||||||||OBR|1||2014047190|69^RADIOLOGIA||||201412162247||||||||||||0310692014047190||201412162247|||||||||||||||OBX|1|FT|20140001988995||REFERTO FORMATO P7M BASE64 ||||||F|||20141216||CFmedicorefertante^CognomeMedicoRefertante^NomeMedicoRefertante||||TXA|1||multipart|||20141216|||||CFmedicorefertante^^^^^^^^^^^^COMPILATORE||||2014047190||AU|||||||NTE|1|O||";
        HapiContext context = new DefaultHapiContext();
//      Parser p = context.getPipeParser();
        Parser p = context.getGenericParser();
        Message adt = p.parse(msg);
        ORU_R01 oruMsg = (ORU_R01) adt;
        System.out.println("ORU_RO1 message = " + oruMsg.encode());
        MSH msh = oruMsg.getMSH();
        System.out.println("MSH segment = " + msh.encode());
        ORU_R01_PIDPD1NK1NTEPV1PV2ORCOBRNTEOBXNTECTI segment1 = 
                            oruMsg.getPIDPD1NK1NTEPV1PV2ORCOBRNTEOBXNTECTI();
        ORU_R01_PIDPD1NK1NTEPV1PV2 segment2= segment1.getPIDPD1NK1NTEPV1PV2();
        PID pid = segment2.getPID();
        System.out.println("Patient Name = " + pid.getPatientName(0).getXpn2_GivenName().getValue());
    }
}

This is the console output:

ORU_RO1 message = MSH|^~\&|REPO|BCS|THE|Theorema|201412170140||ORU^R01|20140012620415|P|2.3.1||||||||PID|||711697^^^^PI^PRIAMO~RSSMHL69B15B081W^^^^NN||ROSSINI^MICHELE||19690215|F|||VIA^POMPEI^6^ASSO^CO^22063||031700239|||M||RSSMHL69B15B081W|300CP102||||ASSO|||100|||||PV1|||265^INRCA Ospedale^^959^^^0310||||||||||||||||||||||||||||||||||||||||||||||||||OBR|1||2014047190|69^RADIOLOGIA||||201412162247||||||||||||0310692014047190||201412162247|||||||||||||||OBX|1|FT|20140001988995||REFERTO FORMATO P7M BASE64 ||||||F|||20141216||CFmedicorefertante^CognomeMedicoRefertante^NomeMedicoRefertante||||TXA|1||multipart|||20141216|||||CFmedicorefertante^^^^^^^^^^^^COMPILATORE||||2014047190||AU|||||||NTE|1|O

MSH segment = MSH|^~\&|REPO|BCS|THE|Theorema|201412170140||ORU^R01|20140012620415|P|2.3.1||||||||PID|||711697^^^^PI^PRIAMO~RSSMHL69B15B081W^^^^NN||ROSSINI^MICHELE||19690215|F|||VIA^POMPEI^6^ASSO^CO^22063||031700239|||M||RSSMHL69B15B081W|300CP102||||ASSO|||100|||||PV1|||265^INRCA Ospedale^^959^^^0310||||||||||||||||||||||||||||||||||||||||||||||||||OBR|1||2014047190|69^RADIOLOGIA||||201412162247||||||||||||0310692014047190||201412162247|||||||||||||||OBX|1|FT|20140001988995||REFERTO FORMATO P7M BASE64 ||||||F|||20141216||CFmedicorefertante^CognomeMedicoRefertante^NomeMedicoRefertante||||TXA|1||multipart|||20141216|||||CFmedicorefertante^^^^^^^^^^^^COMPILATORE||||2014047190||AU|||||||NTE|1|O
Patient Name = null

The whole message and the MSH segment I obtained are the same, I cannot split the message in segments (there are supposed to be: MSH, PID, PV1, OBR, OBX, TXA and NTE) Someone knows a solution to my problem?

Upvotes: 2

Views: 6345

Answers (1)

xmojmr
xmojmr

Reputation: 8145

There's no segment terminator in your message. So the parser can't find it. Note that this terminator is binary and hard-coded in the standard

HL7 Messaging Standard Version 2.5 → Control → Message Framework → 2.5.4 Message delimiters

...The segment terminator is always a carriage return (in ASCII, a hex 0D). The other delimiters are defined in the MSH segment, with the field delimiter in the 4th character position...

See also:

Upvotes: 3

Related Questions