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
dispositionis"success"for a Status,"error"for an Error,"verify"for a Verify, andundefinedfor 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.correlatesTois the<RelatesToMessageID>of the header, verbatim: theMessageIDof the request this answers.- Codes and descriptions are verbatim.
code,descriptionCode, anddescriptionare 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
- Read renewals, changes, and cancels: the lifecycle responses, which carry an approval or a denial rather than a Status.
- Build and serialize messages: write a Status, Error, or Verify
of your own with
buildScriptResponse. - How the parser reads safely: the fail-safe rules this page relies on.