Skip to main content
Version: v0.0.3

Function: buildAdt()

buildAdt(event, init): Hl7Message

Build a spec-clean ADT message for event (the MSH-9.2 trigger, e.g. "A01", "A04", "A08") from typed inputs.

The result is a real Hl7Message: msg.toString() serialises it, parseHL7(msg.toString()) round-trips with zero warnings, and msg.patient / msg.visit read back the values supplied.

Parameters

event

string

the ADT trigger event (MSH-9.2). Required, non-empty.

init

BuildAdtInit

the MSH envelope + typed PID/PV1/EVN content (patient required).

Returns

Hl7Message

Throws

TypeError when event is empty or init.patient is absent.

Example

import { buildAdt, parseHL7 } from "@cosyte/hl7";
const msg = buildAdt("A01", {
sendingApp: "CLINIC",
receivingApp: "LAB",
patient: {
identifiers: { idNumber: "MRN001", identifierTypeCode: "MR" },
name: { familyName: "Test", givenName: "Ann" },
birthDateTime: "19880705",
administrativeSex: "F",
},
visit: { patientClass: "I", assignedLocation: { pointOfCare: "ICU", room: "1", bed: "A" } },
});
const round = parseHL7(msg.toString());
round.warnings.length; // 0
round.patient?.familyName; // "Test"
round.structure.missingGroups; // []