## Hl7Message class

The Hl7Message class represents one HL7 message. A message is a collection of segments.

**Signature:**

```typescript
export declare class Hl7Message
```

## Constructors

| Constructor | Modifiers | Description |
| --- | --- | --- |
| [(constructor)(segments, context)](/content/docs/sdk/core.hl7message._constructor_/index.html) |  | Creates a new HL7 message.<br>Segment strings are not parsed until they are accessed via [Hl7Message.getSegment()](/content/docs/sdk/core.hl7message.getsegment), [Hl7Message.getAllSegments()](/content/docs/sdk/core.hl7message.getallsegments), [Hl7Message.header](/content/docs/sdk/core.hl7message.header), or the [Hl7Message.segments](/content/docs/sdk/core.hl7message.segments) getter. |

## Properties

| Property | Modifiers | Type | Description |
| --- | --- | --- | --- |
| [context](/content/docs/sdk/core.hl7message.context) | `readonly` | [Hl7Context](/content/docs/sdk/core.hl7context) |  |
| [header](/content/docs/sdk/core.hl7message.header) | `readonly` | [Hl7Segment](/content/docs/sdk/core.hl7segment) | Returns the HL7 message header. |
| [segments](/content/docs/sdk/core.hl7message.segments) | `readonly` | [Hl7Segment](/content/docs/sdk/core.hl7segment) | Returns all HL7 segments, parsing any unparsed segment strings on first access.<br>Prefer [Hl7Message.getSegment()](/content/docs/sdk/core.hl7message.getsegment) or [Hl7Message.getAllSegments()](/content/docs/sdk/core.hl7message.getallsegments) when you only need a subset of segments; those methods avoid parsing unrelated segments. |

## Methods

| Method | Modifiers | Description |
| --- | --- | --- |
| [buildAck(options)](/content/docs/sdk/core.hl7message.buildack) |  | Returns an HL7 "ACK" (acknowledgement) message for this message. |
| [get(index)](/content/docs/sdk/core.hl7message.get) |  | Returns an HL7 segment by index or by name. |
| [getAckType()](/content/docs/sdk/core.hl7message.getacktype) |  | Returns this message's acknowledgment code (MSA-1), if it is a recognized HL7 ACK code.<br>Useful on an ACK message to decide the outcome of the acknowledged message — e.g. AA/CA (accepted) vs AR/CR (rejected) vs AE/CE (error). The value is upper-cased before matching. Returns undefined when there is no MSA segment, MSA-1 is empty, or the value is not a known `AckCode`. |
| [getAll(name)](/content/docs/sdk/core.hl7message.getall) |  | Returns all HL7 segments of a given name. |
| [getAllSegments(name)](/content/docs/sdk/core.hl7message.getallsegments) |  | Returns all HL7 segments of a given name.<br>Only the segments that match the requested name are parsed, which avoids parsing unrelated segments when scanning a message. |
| [getSegment(index)](/content/docs/sdk/core.hl7message.getsegment) |  | Returns an HL7 segment by index or by name.<br>When using a numeric index, the first segment (usually the MSH header segment) is at index 0.<br>When using a string index, this method returns the first segment with the specified name.<br>Segments are lazily parsed; the requested segment is parsed and cached on demand. |
| [parse(text)](/content/docs/sdk/core.hl7message.parse) | `static` | Parses an HL7 message string into an Hl7Message object. |
| [setSegment(index, segment)](/content/docs/sdk/core.hl7message.setsegment) |  | Sets or replaces a segment at the specified index. Only allows MSH header to be replaced as first segment. If index is a number and is larger than the length of the segments array, it will be appended as the last segment. If the index is a string, replaces the first segment with that name. |
| [toString()](/content/docs/sdk/core.hl7message.tostring) |  | Returns the HL7 message as a string.<br>Unparsed segments are emitted directly from their original string form, which preserves the source text without forcing a parse. |

- [Hl7Message class](/content/docs/sdk/core.hl7message#hl7message-class/index.html)
- [Constructors](/content/docs/sdk/core.hl7message#constructors/index.html)
- [Properties](/content/docs/sdk/core.hl7message#properties/index.html)
- [Methods](/content/docs/sdk/core.hl7message#methods/index.html)
