Search code examples
javaparsinghl7hapihl7-v2

HL7 segments order


I'm parsing SIU S14 with the following segments order: MSH SCH PID PV1 RGS AIL AIS

and although it parses without error, I can't retrieve data from AIS segment. But when I move AIS segement before AIL, everything seems to work fine. So does segments order matter in HL7?


Solution

  • The order of segments in a HL7 message is predetermined by the message type. In Schedule Information Unsolicited messages the AIS segment has to be ahead of AIL.

    SIU^S12-S24,S26,S27^SIU_S12: Schedule Information Unsolicited
    

      MSH   Message Header  
      SCH   Schedule Activity Information       
        [ { TQ1 } ] Timing/Quantity     
        [ { NTE } ] Notes and Comments for the SCH  
      [ {   --- PATIENT begin       
          PID   Patient Identification  
          [ PD1 ]   Additional Demographics     
          [ PV1 ]   Patient Visit       
          [ PV2 ]   Patient Visit - Additional Info     
          [ { OBX } ]   Observation/Result      
          [ { DG1 } ]   Diagnosis       
      } ]   --- PATIENT end     
      {     --- RESOURCES begin     
        RGS      Resource Group Segment     
        [ { --- SERVICE begin       
            AIS     Appointment Information - Service       
            [ { NTE } ] Notes and Comments for the AIS      
        } ] --- SERVICE end     
        [ { --- GENERAL_RESOURCE begin      
            AIG      Appointment Information - General Resource     
            [ { NTE } ] Notes and Comments for the AIG      
        } ] --- GENERAL_RESOURCE end        
        [ { --- LOCATION_RESOURCE begin     
            AIL      Appointment Information - Location Resource        
            [ { NTE } ] Notes and Comments for the AIL      
        } ] --- LOCATION_RESOURCE end       
        [ { --- PERSONNEL_RESOURCE begin        
            AIP   Appointment Information - Personnel Resource      
            [ { NTE } ] Notes and Comments for the AIP      
        } ] --- PERSONNEL_RESOURCE end      
      } --- RESOURCES end       
    

    But both segments respectively their segment groups are optional. So a message with just an AIL and no AIS segment is syntactically ok. And as HL7 messages are open, there are additional or local defined segments allowed after a complete message.In order to retrieve this additional data you need an adapted template.