core.hl7message.getsegment | Medplum

Hl7Message.getSegment() method

Returns an HL7 segment by index or by name.

When using a numeric index, the first segment (usually the MSH header segment) is at index 0.

When using a string index, this method returns the first segment with the specified name.

Segments are lazily parsed; the requested segment is parsed and cached on demand.

Signature:

getSegment(index: number | string): Hl7Segment | undefined;

Parameters [​](/content/docs/sdk/core.hl7message.getsegment#parameters "Direct link to Parameters"/index.html)

Parameter Type Description
index number | string The HL7 segment index or name.

Returns:

Hl7Segment | undefined

The HL7 segment if found; otherwise, undefined.