3

I know that the order of fields and components matter, but what about the order of segments in an HL7 message? They all obviously have to have the MSH at the beginning, but is there anything in the HL7 guides that explicitly state that hl7 Segments must be in a particular order. Certainly, the documentation lists segments in a certain order when describing a message type, but isn't that just the order it was written down? Do you need to have your messages in the same order (other than the grouped items)? I would have thought that the PID-1 would be irrelevant if the order was set by the order in the message.

I'm keen to hear any opinions, but I would particularly like to hear from someone that can reference some documentation that specifies this.

user2081514
  • 95
  • 1
  • 7

2 Answers2

4

Yes it does matter -

There is a specific requirement that a required segment be in between two identical segments.

From version 2.5.1 chapter 2:

A named segment X may occur more than once in an abstract message syntax. This differs from repetition described earlier in this section.

When this occurs, the following rules must be adhered to: If, within an abstract message syntax, a named segment X appears in two individual or group locations, and a) Either appearance is optional or repeating in an individual location; b) or, either appearance is optional or repeating, in a group location then, the occurrences of segment X must be separated by at least one required segment of a different name so that no ambiguity can exist as to the individual or group location of any occurrence of segment X in a message instance.

A real world example of this is ROL segments in ADT^A02, one follows PD1, and one follows PV2, but PV1 is required in between the two.

If you're writing some kind of parser though, I would be wary of anyone actually respecting this rule.

Community
  • 1
  • 1
Nick Hatt
  • 357
  • 1
  • 7
  • I think your example is pointing at groups not all segments. However, I also found this in chapter 2.11. "A message is the atomic unit of data transferred between systems. It is comprised of a group of segments in a defined sequence". It's not 100% conclusive in my mind as is could be saying the fields are in a defined order, but I know when I'm beaten. Thanks – user2081514 Aug 11 '17 at 09:13
2

Absolutely. The order of segments is defined in the HL7 standard.

For example (I'm using version 2.4 International) section 4.4.1 ORM ‑ general order message (event O01) regarding Order Entry shows the following as the structure of an ORM order message (formatting is not ideal)

ORM^O01^ORM_O01
MSH
[{NTE}]
[
 PID
 [PD1]
 [{NTE}]
 [
   PV1
   [PV2]]
   [{IN1
     [IN2]
     [IN3]
   }]
   [GT1]
   [{AL1}]
  ]
  {
   ORC
   [
    <OBR|RQD|RQ1| RXO|ODS|ODT>
      [{NTE}]
      [CTD]
      [{DG1}]
      [{
        OBX
        [{NTE}]
      }]
    ]
    [{FT1}]
    [{CTI}]
    [BLG]
   }

The square brackets indicate possible repetitions, and the curly brackets that segments are optional (for example directly after the MSH you could have 0, 1 or n NTE segments.)

To be a valid ORM message, an OBR segment should come after an ORC segment that itself should come after a PID etc. An OBR segment is thus for example not allowed to be sent before a PID segment (see this as a layer structure, the Observation Request comes under an Order Common segment that itself is related to a Patient Visit that is specific to a Patient.)

The PID-1 field you mentioned is not a good example, as most messages will only have one PID segment, and PID-1 thus be 1. (I'm not aware of messages containing more than one PID segment, please add to the comments if anyone knows concrete examples from the HL7 specs). But if you look at for example OBR-1, there can be multiple Observervation Requests in the same Order message, for example an order for a Kalium and a Natrium, there would thus be a sequence number sent in OBR-1 to ensure data from the different orders are not mixed up, e.g.:

ORC|...
OBR|1|12345||KA^Kalium|...
OBR|2|12346||NA^Natrium|...
Emilien
  • 2,971
  • 2
  • 22
  • 32
  • 1
    Thanks for your response. I am familiar with these examples, and I have found that the HL7 Documentation does state that the grouped items must be in the correct order (in agreement with your OCR Before the OBR - the ORC is a parent to the OBR). However, I haven't been able to find anything that states that the AIL must come after the GT1 other than that is the order they were printed in. They had to be stated in some order after all. I've used integration systems like Mirth and HL7 Soup, and they simply don't care about the order, they are just as fast at getting the values in any order. – user2081514 Aug 09 '17 at 22:29