Skip to main content
Version: v0.0.4

Function: messages()

messages(msg): readonly AstmStreamMessage[]

Split a parsed stream into the HL messages it carries.

This is the safe path and it never throws: a single-message stream yields exactly one entry, and pairing a patient with a result inside one entry is correct by construction.

Returns an array, not an iterator: the stream is already fully parsed and frozen, so there is no work to defer, and every other extractor in this package returns a readonly array.

Parameters

msg

AstmMessage

A parsed stream.

Returns

readonly AstmStreamMessage[]

The messages, in wire order; never empty for a parsed stream.

Example

import { parseAstmRecords, messages } from "@cosyte/astm";
const stream = parseAstmRecords("H|\\^&\rP|1|PRAC-1\rR|1|^^^687|1.0|U/L||N||F\rL|1\r");
for (const m of messages(stream)) {
m.patient?.practiceAssignedId; // "PRAC-1"
m.results[0]?.value; // "1.0"
}