2.10 MESSAGE CONSTRUCTION RULES
Note: These message construction rules define the standard HL7 encoding rules, creating variable length delimited messages. Although only one set of encoding rules is defined as a standard in HL7 Version 2.3, other encoding rules are possible (but since they are non-standard, they may only be used by a site-specific agreement). |
Step 1 Construct the segments in the order defined for the message. Each message is constructed as follows:
a) the first three characters are the segment ID code
b) each data field in sequence is inserted in the segment in the following manner:
1) a field separator is placed in the segment
2) if the value is not present, no further characters are required
3) if the value is present, but null, the characters "" (two consecutive double quotation marks) are placed in the field
4) otherwise, place the characters of the value in the segment. As many characters can be included as the maximum defined for the data field. It is not necessary, and is undesirable, to pad fields to fixed lengths. Padding to fixed lengths is permitted. Encode the individual data fields as shown in Section 2.8, "Data types."
5) if the field definition calls for a field to be broken into components, the following rules are used:
i) if more than one component is included they are separated by the component separator
ii) components that are present but null are represented by the characters ""
iii) components that are not present are treated by including no characters in the component
iv) components that are not present at the end of a field need not be represented by component separators. For example, the two data fields are equivalent:
|ABC^DEF^^| and |ABC^DEF|.
6) if the component definition calls for a component to be broken into subcomponents, the following rules are used:
i) if more than one subcomponent is included they are separated by the subcomponent separator
II) subcomponents that are present but null are represented by the characters ""
iii) subcomponents that are not present are treated by including no characters in the subcomponent
iv) subcomponents that are not present at the end of a component need not be represented by subcomponent separators. For example, the two data components are equivalent:
^XXX&YYY&&^ and ^XXX&YYY^.
7) if the field definition permits repetition of a field, the following rules are used, the repetition separator is used only if more than one occurrence is transmitted and is placed between occurrences. (If three occurrences are transmitted, two repetition separators are used.) In the example below, two occurrences of telephone number are being sent:
|234-7120~599-1288B1234|
c) repeat Step 1b while there are any fields present to be sent. If all the data fields remaining in the segment definition are not present there is no requirement to include any more delimiters.
d) end each segment with an ASCII carriage return character
Step 2 Repeat Step 1 until all segments have been generated.
The following rules apply to receiving HL7 messages and converting their contents to data values:
a) ignore segments, fields, components, subcomponents, and extra repetitions of a field that are present but were not expected
b) treat segments that were expected but are not present as consisting entirely of fields that are not present
c) treat fields and components that are expected but were not included in a segment as not present.