Function: buildAstmMessage()
buildAstmMessage(
input):string
Build a spec-clean ASTM/CLSI-LIS02 record stream from typed input.
The builder emits the canonical H|\^& header (plus any header fields), then
every body record with each supplied field at its correct 1-based position and
every value escape-encoded, then an L terminator. Nothing clinical is
defaulted - an unsupplied field is empty, never a guessed value - and the
structural pieces (delimiters, record types, sequence counters, terminator) are
computed. The result parses back to an equal message: build → parse fidelity by
construction.
Parameters
input
The message to build.
Returns
string
The serialized, CR-terminated record stream.
Throws
AstmSerializeError when a value contains an unencodable CR/LF.
Example
import { buildAstmMessage, parseAstmRecords, results } from "@cosyte/astm";
const raw = buildAstmMessage({
records: [{ type: "R", universalTestId: ["", "", "", "687"], value: "28.6", units: "U/L" }],
});
results(parseAstmRecords(raw))[0]?.value; // "28.6"