Skip to main content
Version: v0.1.6

Read a SCRIPT response

Every SCRIPT transaction is answered with a <Status>, an <Error>, or a <Verify>. Read the message with parseScript, branch on msg.disposition, and read the body with status, error, or verify. Each accessor returns undefined unless the body is its own kind.

import { error, parseScript, status } from "@cosyte/ncpdp/script";

const xml = `<Message version="2017071">
<Header>
<MessageID>SYNTH-MSG-0003</MessageID>
<RelatesToMessageID>SYNTH-MSG-0002</RelatesToMessageID>
</Header>
<Body><Error>
<Code>900</Code>
<Description>Prescriber identifier could not be validated.</Description>
</Error></Body>
</Message>`;

const msg = parseScript(xml);

msg.disposition; // => "error"
msg.correlatesTo; // => "SYNTH-MSG-0002"

error(msg)?.code; // => "900"
error(msg)?.description; // => "Prescriber identifier could not be validated."
status(msg); // => undefined
  • disposition is "success" for a Status, "error" for an Error, "verify" for a Verify, and undefined for a message that is not a response. It is derived only from which body element is present, so an <Error> can never read as a success.
  • correlatesTo is the <RelatesToMessageID> of the header, verbatim: the MessageID of the request this answers.
  • Codes and descriptions are verbatim. code, descriptionCode, and description are read as they arrived. We ship no table of what a response code means.

When a message carries more than one answer​

A malformed message can carry two response bodies. The disposition then takes the most conservative one, Error first, and the message is warned:

import { parseScript } from "@cosyte/ncpdp/script";

const msg = parseScript(
`<Message version="2017071"><Body><Status><Code>000</Code></Status><Error><Code>900</Code></Error></Body></Message>`,
);

msg.disposition; // => "error"
msg.warnings.map((w) => w.code); // => ["NCPDP_SCRIPT_RESPONSE_AMBIGUOUS_DISPOSITION"]

Reference: parseScript, status, error, verify, and dispositionOf.

Next​