The HL7 MSH (Message Header) segment is present in every HL7 message type and defines the message’s source, purpose, destination, and certain syntax specifics like delimiters (separator characters) and character sets. It is always the first segment in the HL7 message, with the only exception being HL7 batch messages.
There are 19 fields in the MSH segment, six of which (field separator, encoding characters, message type, message control ID, processing ID, and version ID) are required for all messages processed using the HL7 standard. The most important of the MSH fields, and perhaps the most important field in the entire message, is the MSH-9 (Message Type) field. This field specifies what type of message is being transmitted (ADT, ORM, ORU, ACK, etc.) and what the trigger event is. When a message is loaded, often the first field examined in order to determine processing is the value in this field.
The fields in the MSH segment are as follows:
|7||26||TS||O||Date/Time of Message|
|10||20||ST||R||Message Control Id|
|15||2||ID||O||Accept Acknowledgement Type|
|16||2||ID||O||Application Acknowledgement Type|
|19||3||CE||O||Principal Language of Message|
*Note: For the complete HL7 Standard, please go to the HL7 organization website.
The first two fields in the MSH segment define the separator characters to be used throughout the message. The MSH-1 field defines the field separator, and the MSH-2 field defines the other separator characters for the message in this order: component, field repeat, escape character, subcomponent.
The standard requires that a carriage return (ASCII 13 or HEX 0D) be used as the segment separator, so this value cannot be changed. However the HL7 recommended values for the other separator characters include the following:
||||Field separator (pipe)||Separates fields in a message|
|^||Component separator (hat)||Separates components in a field|
|~||Field repeat separator||Separates repeated fields in a segment|
|\||Escape character||Used to signal special characters in a field of text (i.e. \H\ = start highlighting; \F\ = component separator)|
|&||Sub-component separator||Separates components within components (see Data Types)|
The values in the chart are recommended values – and are generally utilized by most systems – but you may elect to use different separator characters in your message if you choose (with the exception of the segment separator). If you do elect to use other separator characters, the chosen values must be specified in the MSH-2 segment for the message.
The beginning of an HL7 message using the recommended values looks like this:
The other required MSH fields are described below:
Not all systems will send messages with MSH segments that conform to the HL7 requirements described above. For instance, the messages may not include a Message ID or Version ID, or they may include additional fields of information that are not specified in the HL7 standard. For this reason, it is important that your system be able to anticipate non-conformant messages and know how to process these messages in an effective manner.