Skip to main content
Version: v0.0.3

Function: buildNewRx()

buildNewRx(input): ScriptMessage

Build a spec-clean SCRIPT NewRx message. The conservative (emit) half of Postel's Law: it refuses to construct a NewRx with no prescribed-medication description (SCRIPT_BUILD_CODES.MISSING_MEDICATION) or carrying an XML-illegal control character (SCRIPT_BUILD_CODES.INVALID_CHARACTER), throwing NcpdpScriptBuildError rather than emitting an unusable message.

The returned ScriptMessage serializes (via "./serialize".serializeScript / toString()) to XML that re-parses with zero warnings.

Parameters

input

NewRxInput

The header, parties, and medication to build.

Returns

ScriptMessage

A frozen ScriptMessage carrying a NewRx body.

Throws

NcpdpScriptBuildError when the input cannot form a spec-clean NewRx.

Example

import { buildNewRx } from "@cosyte/ncpdp/script";
const msg = buildNewRx({
header: { version: "2017071", messageId: "SYNTH-1" },
medication: { description: "Amoxicillin 500 MG Oral Capsule" },
});
msg.toString(); // canonical SCRIPT XML