Class: Hl7Segment
The Hl7Segment class represents one HL7 segment. A segment is a collection of fields. The name field is the first field.
Constructors
constructor
• new Hl7Segment(fields
, context?
)
Creates a new HL7 segment.
Parameters
Name | Type | Description |
---|---|---|
fields | string [] | Hl7Field [] | The HL7 fields. The first field is the segment name. |
context | Hl7Context | Optional HL7 parsing context. |
Defined in
packages/core/src/hl7.ts:218
Properties
context
• Readonly
context: Hl7Context
Defined in
packages/core/src/hl7.ts:209
name
• Readonly
name: string
Defined in
packages/core/src/hl7.ts:210
fields
• Readonly
fields: Hl7Field
[]
Defined in
packages/core/src/hl7.ts:211
Methods
get
▸ get(index
): Hl7Field
Returns an HL7 field by index.
Parameters
Name | Type | Description |
---|---|---|
index | number | The HL7 field index. |
Returns
The HL7 field.
Deprecated
Use getSegment() instead. This method includes the segment name in the index, which leads to confusing behavior. This method will be removed in a future release.
Defined in
packages/core/src/hl7.ts:234
getField
▸ getField(index
): Hl7Field
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.
Parameters
Name | Type | Description |
---|---|---|
index | number | The HL7 field index. |
Returns
The HL7 field.
Defined in
packages/core/src/hl7.ts:252
getComponent
▸ getComponent(fieldIndex
, component
, subcomponent?
, repetition?
): string
Returns an HL7 component by field index and component index.
This is a shortcut for getField(field).getComponent(component)
.
Note that both indexex 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.
Parameters
Name | Type | Default value | Description |
---|---|---|---|
fieldIndex | number | undefined | The HL7 field index. |
component | number | undefined | The component index. |
subcomponent? | number | undefined | Optional subcomponent index. |
repetition | number | 0 | Optional repetition index. |
Returns
string
The string value of the specified component.
Defined in
packages/core/src/hl7.ts:288
toString
▸ toString(): string
Returns the HL7 segment as a string.
Returns
string
The HL7 segment as a string.
Defined in
packages/core/src/hl7.ts:296
parse
▸ Static
parse(text
, context?
): Hl7Segment
Parses an HL7 segment string into an Hl7Segment object.
Parameters
Name | Type | Description |
---|---|---|
text | string | The HL7 segment text. |
context | Hl7Context | Optional HL7 parsing context. |
Returns
The parsed HL7 segment.
Defined in
packages/core/src/hl7.ts:306