title: HAPI: Hl7 Parser do not separate the segment of the Hl7 message
body: <p>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)</p>
  
  <p>Here is the test class</p>
  
  <pre><code>    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|^~\\&amp;|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());
      }
  }
  </code></pre>
  
  <p>This is the console output:</p>
  
  <pre><code>ORU_RO1 message = MSH|^~\&amp;|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|^~\&amp;|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
  </code></pre>
  
  <p>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?</p>