src/ncpdp
@cosyte/synth/ncpdp: the NCPDP generation surface, exposed as its own subpath so importing the
package root does not pull @cosyte/ncpdp. This is the lazy, per-format boundary: a consumer
who only needs NCPDP fixtures imports @cosyte/synth/ncpdp; one who needs only the core primitives
never loads a parser.
@cosyte/ncpdp is an optional peer dependency, present only for this subpath.
This subpath ships spec-clean generation across both NCPDP standards, each built through
@cosyte/ncpdp's own emit surface:
- SCRIPT ePrescribing (
@cosyte/ncpdp/script):generateNewRx(via the validatedbuildNewRxbuilder),generateRxRenewalRequest, andgenerateRxChangeRequest(via the parser's public typedScriptMessagemodel +serializeScript), each round-tripping throughparseScriptwith zero warnings, and carrying a prescriber whose NPI is invalid-Luhn and whose DEA is invalid-checksum. - Telecom claims (
@cosyte/ncpdp/telecom):generateB1(billing),generateB2(reversal), andgenerateB3(rebill) viabuildTelecomRequest+serializeTelecom, each round-tripping throughparseTelecomwith zero warnings, with patient / cardholder identity from the synthetic providers.
Deferred: quirk mode. SCRIPT is limited to the transactions @cosyte/ncpdp can build: NewRx
plus the
renewal/change requests; the renewal/change responses and the reversal cases beyond B2's
reference set track the parser's builder surface, never hand-written bytes.
Interfaces
GenerateScriptOptions
Options for the SCRIPT generators.
Properties
seed
readonlyseed:number
The seed (deterministic: same seed yields a byte-identical message).
GenerateTelecomOptions
Options for the Telecom generators.
Properties
seed
readonlyseed:number
The seed (deterministic: same seed yields a byte-identical transaction).
NcpdpCardholder
A synthetic cardholder / insurance identity: the covered person on a Telecom claim.
Properties
cardholderId
readonlycardholderId:string
Cardholder / member id, synthetic-AA scoped (MBR-prefixed).
groupId
readonlygroupId:string
Group id, synthetic.
person
readonlyperson:SyntheticName
The cardholder name (may differ from the patient).
personCode
readonlypersonCode:string
Person code (01 = cardholder, 02 = spouse, 03 = child, structural).
NcpdpCorpusOptions
Options for ncpdpCorpus.
Properties
count?
readonlyoptionalcount?:number
How many transactions to generate. Defaults to the length of the mix.
mix?
readonlyoptionalmix?: readonlyNcpdpCorpusKind[]
The transaction kinds to cycle through. Defaults to one of each.
seed
readonlyseed:number
The seed for the whole corpus (deterministic).
NcpdpExampleDrug
One example drug: a widely-known generic description + an invented, clearly-example NDC.
Properties
description
readonlydescription:string
A widely-known generic drug description (RxNorm-style; public knowledge, not NCPDP prose).
form
readonlyform:string
The dispense quantity unit-of-measure qualifier hint (structural only).
ndc
readonlyndc:string
An invented 11-digit NDC (5-4-2, digits only), an example product code, never a real NDC.
NcpdpPatient
A synthetic patient: every field from ../safe.
Properties
address
readonlyaddress:SyntheticAddress
Synthetic postal address (reserved non-real ZIP).
dob
readonlydob:string
Date of birth CCYYMMDD from the seeded generator.
gender
readonlygender:"1"|"2"
Administrative gender code (1 = male, 2 = female, NCPDP gender codes).
patientId
readonlypatientId:string
Patient id, synthetic-AA scoped (MBR-prefixed, never a bare SSN).
person
readonlyperson:SyntheticName
Name from the shipped fake-name pool.
phone
readonlyphone:string
Reserved 555-01xx phone.
NcpdpPharmacy
A synthetic dispensing pharmacy: business name + invalid-Luhn NPI + synthetic NCPDP id.
Properties
businessName
readonlybusinessName:string
A clearly-fictional pharmacy business name.
ncpdpId
readonlyncpdpId:string
A 7-digit NCPDP provider id (synthetic, an all-digit id under no real chain).
npi
readonlynpi:string
A 10-digit NPI with a deliberately-invalid Luhn check digit.
NcpdpPrescriber
A synthetic prescriber: name + invalid-Luhn NPI + invalid-checksum DEA.
Properties
dea
readonlydea:string
A DEA number with a deliberately-invalid checksum (never a real DEA registration).
npi
readonlynpi:string
A 10-digit NPI with a deliberately-invalid Luhn check digit (never a real NPI).
person
readonlyperson:SyntheticName
A clearly-fake prescriber name.
NcpdpScriptRouting
A seeded SCRIPT routing/correlation bundle: message ids + timestamps, all reproducible.
Properties
date
readonlydate:string
A CCYYMMDD written / service date (seeded, recent window).
messageId
readonlymessageId:string
<MessageID>: a synthetic message id.
prescriberOrderNumber
readonlyprescriberOrderNumber:string
<PrescriberOrderNumber>, a synthetic order number.
sentTime
readonlysentTime:string
<SentTime>, a seeded ISO-8601 timestamp (never wall-clock).
RoundTripResult
The verdict of one round-trip through @cosyte/ncpdp.
Properties
byteStable
readonlybyteStable:boolean
Whether re-serializing the re-parsed message is byte-identical to content.
content
readonlycontent:string
The serialized NCPDP wire text (the serializer's own conservative emit).
specClean
readonlyspecClean:boolean
true iff the artifact is spec-clean: zero warnings and byte-stable.
warnings
readonlywarnings: readonlystring[]
The warning codes the parser emitted on re-parse. Empty ⇒ spec-clean.
Type Aliases
NcpdpCorpusKind
NcpdpCorpusKind =
"NewRx"|"RxRenewalRequest"|"RxChangeRequest"|"B1"|"B2"|"B3"
Every NCPDP transaction kind ncpdpCorpus generates: the label used as the corpus kind.
TelecomTransactionCode
TelecomTransactionCode =
"B1"|"B2"|"B3"
The Telecom transaction codes synth generates.
Variables
DAW_CODES
constDAW_CODES: readonlystring[]
Dispense-as-written / product-selection codes (single-digit, structural).
EXAMPLE_DRUGS
constEXAMPLE_DRUGS: readonlyNcpdpExampleDrug[]
A small pool of license-clean example drugs. The NDCs use the invented labeler prefix 00000
(never an FDA-assigned labeler), so they are transparently examples; the descriptions are common
generics anyone can name without a licensed database.
EXAMPLE_SIG_TEXT
constEXAMPLE_SIG_TEXT: readonlystring[]
Example free-text SIG directions (public, common-sense dosing text, not NCPDP prose).
Functions
generateB1()
generateB1(
options):string
Generate a spec-clean Telecom B1 billing claim.
Parameters
options
The seed.
Returns
string
The serialized Telecom wire string.
Example
import { generateB1 } from "@cosyte/synth/ncpdp";
const wire = generateB1({ seed: 1 });
generateB2()
generateB2(
options):string
Generate a spec-clean Telecom B2 reversal.
Parameters
options
The seed.
Returns
string
The serialized Telecom wire string.
Example
import { generateB2 } from "@cosyte/synth/ncpdp";
const wire = generateB2({ seed: 1 });
generateB3()
generateB3(
options):string
Generate a spec-clean Telecom B3 rebill.
Parameters
options
The seed.
Returns
string
The serialized Telecom wire string.
Example
import { generateB3 } from "@cosyte/synth/ncpdp";
const wire = generateB3({ seed: 1 });
generateNewRx()
generateNewRx(
options):string
Generate a spec-clean SCRIPT NewRx ePrescription, built through @cosyte/ncpdp's validated
buildNewRx and serialized by serializeScript. Every identity value is synthetic-by-construction; the
message round-trips through parseScript with zero warnings.
Parameters
options
The seed. See GenerateScriptOptions.
Returns
string
The serialized SCRIPT XML.
Example
import { generateNewRx } from "@cosyte/synth/ncpdp";
const xml = generateNewRx({ seed: 42 });
generateRxChangeRequest()
generateRxChangeRequest(
options):string
Generate a spec-clean SCRIPT RxChangeRequest (a pharmacy-initiated change request), built as
@cosyte/ncpdp's public typed ScriptMessage model and serialized by serializeScript. Every
identity value is synthetic-by-construction; the message round-trips through parseScript with zero
warnings.
Parameters
options
The seed. See GenerateScriptOptions.
Returns
string
The serialized SCRIPT XML.
Example
import { generateRxChangeRequest } from "@cosyte/synth/ncpdp";
const xml = generateRxChangeRequest({ seed: 7 });
generateRxRenewalRequest()
generateRxRenewalRequest(
options):string
Generate a spec-clean SCRIPT RxRenewalRequest (a pharmacy-initiated renewal), built as
@cosyte/ncpdp's public typed ScriptMessage model and serialized by serializeScript. Every
identity value is synthetic-by-construction; the message round-trips through parseScript with zero
warnings (verified by ./round-trip.scriptRoundTrip).
Parameters
options
The seed. See GenerateScriptOptions.
Returns
string
The serialized SCRIPT XML.
Example
import { generateRxRenewalRequest } from "@cosyte/synth/ncpdp";
const xml = generateRxRenewalRequest({ seed: 7 });
generateTelecom()
generateTelecom(
code,options):string
Generate a spec-clean Telecom transaction of the given code, built through
@cosyte/ncpdp's buildTelecomRequest + serializeTelecom. B1/B3 carry the full
patient / insurance / prescriber / claim segment set; B2 (reversal) is the minimal
insurance + claim-reference set a reversal actually carries. Every identity value is
synthetic-by-construction; the transaction round-trips through parseTelecom with zero
warnings.
Parameters
code
"B1" billing, "B2" reversal, or "B3" rebill.
options
The seed. See GenerateTelecomOptions.
Returns
string
The serialized Telecom wire string.
Example
import { generateTelecom } from "@cosyte/synth/ncpdp";
const wire = generateTelecom("B1", { seed: 42 });
ncpdpCardholder()
ncpdpCardholder(
rng):NcpdpCardholder
Mint a synthetic cardholder / insurance identity for a Telecom claim.
Parameters
rng
The seeded generator.
Returns
A synthetic NcpdpCardholder.
Example
import { createRng } from "@cosyte/synth";
import { ncpdpCardholder } from "@cosyte/synth/ncpdp";
const c = ncpdpCardholder(createRng(1));
ncpdpCorpus()
ncpdpCorpus(
options):Corpus
Build a reproducible Corpus of spec-clean NCPDP transactions. Each transaction is generated
from a distinct sub-seed derived from the corpus seed (so the set is deterministic) and round-tripped
through @cosyte/ncpdp; the per-artifact warnings record the parser's verdict (empty ⇒ spec-clean).
Parameters
options
Seed, count, and the transaction mix. See NcpdpCorpusOptions.
Returns
A deep-frozen Corpus.
Example
import { ncpdpCorpus } from "@cosyte/synth/ncpdp";
const corpus = ncpdpCorpus({ seed: 42 });
corpus.artifacts.every((a) => a.warnings.length === 0); // true, spec-clean
ncpdpPatient()
ncpdpPatient(
rng):NcpdpPatient
Mint a synthetic patient. Fixed draw order (name → DOB → gender → id → phone → address) so the same seed yields the same patient.
Parameters
rng
The seeded generator.
Returns
A synthetic NcpdpPatient.
Example
import { createRng } from "@cosyte/synth";
import { ncpdpPatient } from "@cosyte/synth/ncpdp";
const { person, patientId } = ncpdpPatient(createRng(1));
ncpdpPharmacy()
ncpdpPharmacy(
rng):NcpdpPharmacy
Mint a synthetic dispensing pharmacy: a fictional business name, an invalid-Luhn NPI, and a 7-digit synthetic NCPDP provider id.
Parameters
rng
The seeded generator.
Returns
A synthetic NcpdpPharmacy.
Example
import { createRng } from "@cosyte/synth";
import { ncpdpPharmacy } from "@cosyte/synth/ncpdp";
const rx = ncpdpPharmacy(createRng(1));
ncpdpPrescriber()
ncpdpPrescriber(
rng):NcpdpPrescriber
Mint a synthetic prescriber: a person name, an invalid-Luhn NPI, and an invalid-checksum DEA (the DEA's second letter is derived from the prescriber's family name so it reads plausibly).
Parameters
rng
The seeded generator.
Returns
A synthetic NcpdpPrescriber.
Example
import { createRng } from "@cosyte/synth";
import { ncpdpPrescriber } from "@cosyte/synth/ncpdp";
const p = ncpdpPrescriber(createRng(1)); // p.npi invalid-Luhn; p.dea invalid-checksum
ncpdpScriptRouting()
ncpdpScriptRouting(
rng):NcpdpScriptRouting
Mint a seeded SCRIPT routing bundle. The timestamp is drawn from the seeded generator in a recent window (2024 to 2026) so a message reads current while staying byte-reproducible.
Parameters
rng
The seeded generator.
Returns
A synthetic NcpdpScriptRouting.
Example
import { createRng } from "@cosyte/synth";
import { ncpdpScriptRouting } from "@cosyte/synth/ncpdp";
const r = ncpdpScriptRouting(createRng(1));
scriptRoundTrip()
scriptRoundTrip(
xml):RoundTripResult
Round-trip a generated SCRIPT XML string through parse → serialize and report the verdict. A spec-clean message re-parses with zero warnings and re-serializes byte-identically.
Parameters
xml
string
The SCRIPT XML (typically from generateNewRx / generateRxRenewalRequest / …).
Returns
The RoundTripResult.
Example
import { generateNewRx, scriptRoundTrip } from "@cosyte/synth/ncpdp";
const { specClean } = scriptRoundTrip(generateNewRx({ seed: 1 })); // specClean === true
telecomRoundTrip()
telecomRoundTrip(
wire):RoundTripResult
Round-trip a generated Telecom wire string through parse → serialize and report the verdict. A spec-clean transaction re-parses with zero warnings and re-serializes byte-identically.
Parameters
wire
string
The Telecom wire string (typically from generateB1 / generateB2 / generateB3).
Returns
The RoundTripResult.
Example
import { generateB1, telecomRoundTrip } from "@cosyte/synth/ncpdp";
const { specClean } = telecomRoundTrip(generateB1({ seed: 1 })); // specClean === true