Skip to main content

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

NameTypeDescription
fieldsstring[] | Hl7Field[]The HL7 fields. The first field is the segment name.
contextHl7ContextOptional 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

NameTypeDescription
indexnumberThe HL7 field index.

Returns

Hl7Field

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

NameTypeDescription
indexnumberThe HL7 field index.

Returns

Hl7Field

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

NameTypeDefault valueDescription
fieldIndexnumberundefinedThe HL7 field index.
componentnumberundefinedThe component index.
subcomponent?numberundefinedOptional subcomponent index.
repetitionnumber0Optional 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

NameTypeDescription
textstringThe HL7 segment text.
contextHl7ContextOptional HL7 parsing context.

Returns

Hl7Segment

The parsed HL7 segment.

Defined in

packages/core/src/hl7.ts:306