Skip to main content
Version: v0.0.4

Function: buildOru()

buildOru(init): Hl7Message

Build a spec-clean ORU^R01 observation-result message from typed inputs.

The result is a real Hl7Message: msg.toString() serialises it, parseHL7(msg.toString()) round-trips with zero warnings, and msg.observations() reads back the results supplied.

Parameters

init

BuildOruInit

the MSH envelope + typed PID/OBR/OBX content. patient and a non-empty observations list are required.

Returns

Hl7Message

Throws

TypeError when patient is absent or observations is empty.

Example

import { buildOru, parseHL7 } from "@cosyte/hl7";
const msg = buildOru({
sendingApp: "LAB",
receivingApp: "EHR",
patient: { identifiers: { idNumber: "MRN001", identifierTypeCode: "MR" },
name: { familyName: "Test", givenName: "Ann" } },
order: { universalServiceId: { identifier: "CBC", text: "Complete Blood Count", nameOfCodingSystem: "L" },
resultStatus: "F" },
observations: [
{ setId: "1", valueType: "NM",
identifier: { identifier: "WBC", text: "White Blood Cells", nameOfCodingSystem: "LN" },
value: "7.2", units: { identifier: "10*3/uL" }, observationResultStatus: "F" },
],
});
const round = parseHL7(msg.toString());
round.warnings.length; // 0
round.observations()[0]?.value; // "7.2"