Understanding Segments
Segments are the structural building blocks of HL7 v2.x messages. Correct parsing is necessary, but operational correctness depends on field semantics, cardinality, and message-profile context.
Segment structure fundamentals
| Concept | Meaning |
|---|---|
| Segment ID | Three-character code (MSH, PID, PV1, OBR, OBX, etc.) |
| Field position | Ordinal field number by delimiter index |
| Data type | Type-specific encoding rules (for example TS, XPN, CWE, NM) |
| Cardinality | Required/optional and repeating constraints |
Common segments by domain
| Segment | Domain role |
|---|---|
| MSH | Message envelope and routing metadata |
| PID | Patient identity and demographics |
| PV1 | Encounter and location state |
| OBR | Order and observation request context |
| OBX | Observation result payload |
| AL1 | Allergy and intolerance information |
| DG1 | Diagnosis coding and clinical problem context |
MSH - Message Header
MSH field reference
| Field | Name | Purpose |
|---|---|---|
| MSH-1 | Field Separator | Defines field delimiter for message |
| MSH-2 | Encoding Characters | Defines component/repetition/escape/subcomponent |
| MSH-7 | Date/Time of Message | Message generation timestamp |
| MSH-9 | Message Type | Type and trigger event (for example ORU^R01) |
| MSH-10 | Message Control ID | Unique message correlation key |
| MSH-12 | Version ID | HL7 version negotiation |
MSH Segment Example
Minimal MSH example with key routing and control fields.
Click on a segment above to highlight its fields
Hover or click any field value for detailed explanation
- Always treat MSH parsing as mandatory precondition for the rest of the message.
- Reject messages with invalid or missing MSH-9, MSH-10, or MSH-12 where required.
- Audit MSH control IDs for replay and idempotency behavior.
PID - Patient Identification
PID field reference
| Field | Name | Notes |
|---|---|---|
| PID-3 | Patient Identifier List | Primary MRN and alternate IDs |
| PID-5 | Patient Name | Family and given name components |
| PID-7 | Date/Time of Birth | Demographic and matching attribute |
| PID-8 | Administrative Sex | Administrative demographic field |
| PID-11 | Patient Address | Mailing/physical address structure |
PID Segment with Full Demographics
PID sample with identity and demographic content.
Click on a segment above to highlight its fields
Hover or click any field value for detailed explanation
Identity normalization must preserve assigning authority and identifier type codes to avoid cross-facility collisions.
PV1 - Patient Visit
PV1 field reference
| Field | Name | Purpose |
|---|---|---|
| PV1-2 | Patient Class | Inpatient/outpatient context |
| PV1-3 | Assigned Patient Location | Unit, room, and bed assignment |
| PV1-7 | Attending Doctor | Responsible provider details |
| PV1-19 | Visit Number | Encounter-level unique identifier |
PV1 Segment with Full Visit Information
Visit segment with patient class, location, and attending details.
Click on a segment above to highlight its fields
Hover or click any field value for detailed explanation
Patient class values (PV1-2)
| Code | Meaning |
|---|---|
| I | Inpatient |
| O | Outpatient |
| E | Emergency |
| P | Preadmit |
OBR and OBX - Orders and Results
OBR Field Reference
| Field | Purpose |
|---|---|
| OBR-2 | Placer order number |
| OBR-3 | Filler order number |
| OBR-4 | Universal service ID (test/procedure) |
| OBR-7 | Observation date/time |
OBR Segment - Lab Order
Order context carrying placer/filler identifiers and service code.
Click on a segment above to highlight its fields
Hover or click any field value for detailed explanation
OBX Field Reference
| Field | Purpose |
|---|---|
| OBX-2 | Value type (NM, ST, TX, CWE, etc.) |
| OBX-3 | Observation identifier |
| OBX-5 | Observation value payload |
| OBX-6 | Units |
| OBX-7 | Reference range |
| OBX-11 | Result status |
OBX value types (OBX-2)
| Type | Typical use |
|---|---|
| NM | Numeric result |
| ST | Short text result |
| TX | Long narrative text |
| CWE | Coded value with coding system metadata |
OBX Segment - CBC Result
Result payload with value, units, reference range, and final status.
Click on a segment above to highlight its fields
Hover or click any field value for detailed explanation
AL1 and DG1 - Allergy and Diagnosis
AL1 field reference
| Field | Purpose |
|---|---|
| AL1-3 | Allergen code and description |
| AL1-4 | Allergy severity |
| AL1-6 | Reaction details |
AL1 Segments - Patient Allergies
Sample allergy record with severity and reaction context.
Click on a segment above to highlight its fields
Hover or click any field value for detailed explanation
Allergy severity codes
| Code | Meaning |
|---|---|
| MI | Mild |
| MO | Moderate |
| SV | Severe |
DG1 field reference
| Field | Purpose |
|---|---|
| DG1-3 | Diagnosis code and display text |
| DG1-5 | Diagnosis timestamp |
| DG1-6 | Diagnosis type |
DG1 Segment - Diagnosis Information
Diagnosis coding record for clinical and billing workflows.
Click on a segment above to highlight its fields
Hover or click any field value for detailed explanation
Segment Relationships and Message Structure
ADT message relationship flow
Loading diagram...
Flattening repeating OBX rows without preserving parent OBR context is a common source of clinical misinterpretation.
- Preserve segment order where profiles require strict ordering.
- Preserve OBR/OBX parent-child grouping for result integrity.
- Support repeating segments (AL1, DG1, OBX) as first-class structures.
Radiology-Specific Segment Usage
Radiology ORU with Structured OBX
Radiology result with narrative and coded result components.
Click on a segment above to highlight its fields
Hover or click any field value for detailed explanation
Common radiology LOINC codes
| LOINC | Meaning |
|---|---|
| 24627-2 | MRI brain |
| 19005-8 | Diagnostic imaging impression |
| 18782-3 | Radiology narrative report |
- Use structured OBX coding for computable downstream analytics.
- Pair narrative text OBX with coded OBX where possible.
- Maintain accession and order identifiers for PACS/RIS/EHR reconciliation.
Common Implementation Patterns
Implementation checklist
| Category | Practices |
|---|---|
| Required vs optional fields | Enforce profile-required fields and segment presence early |
| Data type handling | Validate TS, NM, CWE, XPN, XAD formats before persistence |
| Null values | Handle explicit nulls and empty values according to profile semantics |
| Segment repetition | Store and process repeated segments and fields without flattening |
Common Segments Reference Table
This comprehensive reference table covers all commonly used HL7 v2.x segments with their purpose, key fields, and typical usage scenarios.
Complete HL7 v2.x segment reference
| Segment | Name | Purpose | Key Fields | Common Messages |
|---|---|---|---|---|
| MSH | Message Header | Message envelope and routing metadata | MSH-3/4 (Sending), MSH-5/6 (Receiving), MSH-9 (Type), MSH-10 (Control ID) | ALL |
| EVN | Event Type | Event timing and trigger information | EVN-1 (Event Code), EVN-2 (Recorded Date) | ADT, ORM, ORU |
| PID | Patient Identification | Patient demographics and identifiers | PID-3 (MRN), PID-5 (Name), PID-7 (DOB), PID-8 (Sex) | ADT, ORM, ORU, SIU |
| PV1 | Patient Visit | Encounter and location information | PV1-2 (Class), PV1-3 (Location), PV1-7 (Attending), PV1-19 (Visit #) | ADT |
| NK1 | Next of Kin | Emergency contact and associated parties | NK1-1 (Set ID), NK1-3 (Relationship), NK1-4 (Name) | ADT |
| AL1 | Allergy Information | Patient allergies and intolerances | AL1-3 (Allergen), AL1-4 (Severity), AL1-6 (Reaction) | ADT, ORM |
| DG1 | Diagnosis | Diagnosis codes and clinical problems | DG1-3 (Diagnosis Code), DG1-5 (Date), DG1-6 (Type) | ADT, DFT |
| PR1 | Procedures | Procedure information | PR1-3 (Procedure Code), PR1-6 (Date) | ADT, DFT |
| ORC | Common Order | Order control and status | ORC-1 (Control Code), ORC-2 (Placer #), ORC-3 (Filler #) | ORM, ORR, ORU |
| OBR | Observation Request | Order/result details | OBR-2/3 (Order #), OBR-4 (Service), OBR-7 (Date) | ORM, ORU |
| OBX | Observation/Result | Observation values and results | OBX-2 (Type), OBX-3 (ID), OBX-5 (Value), OBX-11 (Status) | ORU, ORM |
| MRG | Merge | Prior identifiers for merges | MRG-1 (Prior ID), MRG-3 (Prior Visit #) | ADT^A40 |
| FT1 | Financial Transaction | Charge and billing data | FT1-4 (Date), FT1-6 (Type), FT1-7 (Code), FT1-10 (Amount) | DFT |
| IN1 | Insurance | Insurance plan information | IN1-1 (Set ID), IN1-2 (Plan ID), IN1-3 (Company ID) | ADT, DFT |
Segment Optionality
Segment presence depends on message type and implementation guide. Always consult your trading partner specification for required vs. optional segments.
Field Breakdown - Detailed Field Analysis
Understanding individual field structure is critical for proper HL7 parsing and transformation. This section provides detailed breakdowns of commonly used fields.
PID-3: Patient Identifier List (CX Data Type)
CX component structure
| Component | Name | Example |
|---|---|---|
| 1 | ID Number | 123456 |
| 2 | Check Digit | (optional) |
| 3 | Assigning Authority | HOSPITAL |
| 4 | Identifier Type | MR (Medical Record) |
| 5 | Assigning Facility | MAIN_CAMPUS |
PID-3: Patient Identifier List Examples
PID-3 examples showing CX data type variations with multiple identifiers.
Click on a segment above to highlight its fields
Hover or click any field value for detailed explanation
PID-5: Patient Name (XPN Data Type)
XPN component structure
| Component | Name | Example |
|---|---|---|
| 1 | Family Name | DOE |
| 2 | Given Name | JOHN |
| 3 | Middle Name | MICHAEL |
| 4 | Suffix | JR |
| 5 | Prefix | MR |
PID-5: Patient Name Examples
PID-5 examples showing XPN data type variations with name components.
Click on a segment above to highlight its fields
Hover or click any field value for detailed explanation
PV1-3: Assigned Patient Location (PL Data Type)
PL component structure
| Component | Name | Example |
|---|---|---|
| 1 | Point of Care | ICU |
| 2 | Room | 101 |
| 3 | Bed | A |
| 4 | Facility | HOSPITAL |
PV1-3: Assigned Patient Location Examples
PV1-3 examples showing PL data type variations for location hierarchy.
Click on a segment above to highlight its fields
Hover or click any field value for detailed explanation
OBX-5: Observation Value (Variable Data Type)
OBX-5 data type depends on OBX-2 (Value Type):
OBX value type examples
| OBX-2 | Data Type | OBX-5 Example |
|---|---|---|
| NM | Numeric | 7.5 |
| ST | String | NEGATIVE |
| TX | Text | No acute findings. |
| CWE | Coded | 260373001^Detected^SCT |
| DT | Date | 20240315 |
| TS | Timestamp | 20240315143022 |
Further Reading
HL7 v2.5.1 messaging standard
Official HL7 v2.5.1 messaging standard specification
HL7 v2.5.1 StandardLOINC terminology resources
Logical Observation Identifiers Names and Codes for laboratory and clinical observations
LOINCKnowledge Check
Test your understanding with this quiz. You need to answer all questions correctly to mark this section as complete.