core.hl7segment | Medplum
Hl7Segment class
The Hl7Segment class represents one HL7 segment. A segment is a collection of fields. The name field is the first field.
Signature:
export declare class Hl7Segment
Constructors
| Constructor | Modifiers | Description |
|---|---|---|
| (constructor)(fields, context) | Creates a new HL7 segment. Field strings are not parsed until they are accessed via Hl7Segment.getField() or via the Hl7Segment.fields getter. |
Properties
| Property | Modifiers | Type | Description |
|---|---|---|---|
| context | readonly |
Hl7Context | |
| fields | readonly |
Hl7Field | Returns all HL7 fields, parsing any unparsed field strings on first access. Prefer Hl7Segment.getField() when you only need a subset of fields; that method avoids parsing unrelated fields. |
| name | readonly |
string |
Methods
| Method | Modifiers | Description |
|---|---|---|
| get(index) | Returns an HL7 field by index. | |
| getComponent(fieldIndex, component, subcomponent, repetition) | Returns an HL7 component by field index and component index. This is a shortcut for getField(field).getComponent(component).Note that both indices are 1-based, not 0-based. For example, to get the first component, use getComponent(1, 1).This aligns with HL7 component names such as MSH.9.2. |
|
| getField(index) | Returns an HL7 field by index. Note that the index is 1-based, not 0-based. For example, to get the first field, use getField(1).This aligns with HL7 field names such as PID.1, PID.2, etc. Field zero is the segment name. Fields are lazily parsed; the requested field is parsed and cached on demand. |
|
| parse(text, context) | static |
Parses an HL7 segment string into an Hl7Segment object. |
| setComponent(fieldIndex, component, value, subcomponent, repetition) | Sets a component value by field index and component index. This is a shortcut for getField(field).setComponent(component, value). Note that both indices are 1-based, not 0-based. |
|
| setField(index, field) | Sets a field at the specified index. If that index does not exist, it will be added. Note that the index is 1-based, not 0-based. | |
| toString() | Returns the HL7 segment as a string. Unparsed fields are emitted directly from their original string form, which preserves the source text without forcing a parse. |