@cosyte/synth 0.0.2 → 0.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +321 -0
- package/README.md +13 -4
- package/dist/astm/index.cjs +83 -42
- package/dist/astm/index.cjs.map +1 -1
- package/dist/astm/index.d.cts +1 -1
- package/dist/astm/index.d.ts +1 -1
- package/dist/astm/index.mjs +83 -42
- package/dist/astm/index.mjs.map +1 -1
- package/dist/ccda/index.cjs +89 -44
- package/dist/ccda/index.cjs.map +1 -1
- package/dist/ccda/index.d.cts +5 -3
- package/dist/ccda/index.d.ts +5 -3
- package/dist/ccda/index.mjs +89 -44
- package/dist/ccda/index.mjs.map +1 -1
- package/dist/deid/index.cjs +92 -13
- package/dist/deid/index.cjs.map +1 -1
- package/dist/deid/index.d.cts +1 -1
- package/dist/deid/index.d.ts +1 -1
- package/dist/deid/index.mjs +93 -14
- package/dist/deid/index.mjs.map +1 -1
- package/dist/fhir/index.cjs +78 -5
- package/dist/fhir/index.cjs.map +1 -1
- package/dist/fhir/index.mjs +78 -5
- package/dist/fhir/index.mjs.map +1 -1
- package/dist/hl7/index.cjs +89 -41
- package/dist/hl7/index.cjs.map +1 -1
- package/dist/hl7/index.d.cts +1 -1
- package/dist/hl7/index.d.ts +1 -1
- package/dist/hl7/index.mjs +89 -41
- package/dist/hl7/index.mjs.map +1 -1
- package/dist/index.cjs +91 -40
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +126 -8
- package/dist/index.d.ts +126 -8
- package/dist/index.mjs +89 -41
- package/dist/index.mjs.map +1 -1
- package/dist/ncpdp/index.cjs +56 -4
- package/dist/ncpdp/index.cjs.map +1 -1
- package/dist/ncpdp/index.mjs +56 -4
- package/dist/ncpdp/index.mjs.map +1 -1
- package/dist/{quirk-JLyO1Ncj.d.ts → quirk-C9t9CkPS.d.ts} +17 -6
- package/dist/{quirk-DmkgoZdh.d.cts → quirk-DYMDojVw.d.cts} +17 -6
- package/dist/x12/index.cjs +82 -13
- package/dist/x12/index.cjs.map +1 -1
- package/dist/x12/index.d.cts +2 -1
- package/dist/x12/index.d.ts +2 -1
- package/dist/x12/index.mjs +83 -14
- package/dist/x12/index.mjs.map +1 -1
- package/package.json +2 -2
package/dist/hl7/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/rng/splitmix32.ts","../../src/rng/sfc32.ts","../../src/rng/rng.ts","../../src/corpus.ts","../../src/hl7/field.ts","../../src/safe/reserved.ts","../../src/safe/names-pool.ts","../../src/safe/providers.ts","../../src/safe/index.ts","../../src/hl7/common.ts","../../src/hl7/adt.ts","../../src/hl7/example-codes.ts","../../src/hl7/oru.ts","../../src/hl7/orm.ts","../../src/hl7/siu.ts","../../src/hl7/vxu.ts","../../src/hl7/round-trip.ts","../../src/profile.ts","../../src/codes.ts","../../src/quirk.ts","../../src/hl7/quirk.ts","../../src/hl7/index.ts"],"names":["buildMessage","address","phone","parseHL7","name","hl7Profiles"],"mappings":";;;;;AA0BO,SAAS,WAAW,IAAA,EAA4B;AACrD,EAAA,IAAI,IAAI,IAAA,GAAO,CAAA;AACf,EAAA,OAAO,SAAS,IAAA,GAAe;AAC7B,IAAA,CAAA,GAAK,IAAI,UAAA,GAAc,CAAA;AACvB,IAAA,IAAI,CAAA,GAAI,IAAK,CAAA,KAAM,EAAA;AACnB,IAAA,CAAA,GAAI,IAAA,CAAK,IAAA,CAAK,CAAA,EAAG,SAAU,CAAA;AAC3B,IAAA,CAAA,GAAI,IAAK,CAAA,KAAM,EAAA;AACf,IAAA,CAAA,GAAI,IAAA,CAAK,IAAA,CAAK,CAAA,EAAG,UAAU,CAAA;AAC3B,IAAA,CAAA,GAAI,IAAK,CAAA,KAAM,EAAA;AACf,IAAA,OAAO,CAAA,KAAM,CAAA;AAAA,EACf,CAAA;AACF;;;ACOO,SAAS,UAAU,CAAA,EAAuB;AAC/C,EAAA,CAAA,CAAE,CAAA,IAA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,EAAA,CAAG;AAAA,KACf;AAAA,EACF,CAAC,CAAA;AACD,EAAA,OAAO,UAAA,CAAW,MAAM,SAAS,CAAA;AACnC","file":"index.cjs","sourcesContent":["/**\n * `splitmix32` — a tiny, well-studied 32-bit mixing PRNG used **only** to expand a single integer\n * seed into the four 32-bit state words that seed {@link ../rng/sfc32.sfc32}. It is not the corpus\n * generator itself (that is `sfc32`); it exists so that a one-number seed deterministically produces a\n * well-distributed 128-bit `sfc32` state, avoiding the poor low-bit behavior of naive\n * `state = seed`-style initialization.\n *\n * Zero-dependency, `Math.random`-free (lint-enforced): the whole point of the library is that a seed —\n * and only the seed — determines the output, on any machine, any run.\n *\n * @module\n */\n\n/**\n * A stateful `splitmix32` step function. Each call advances the internal 32-bit state and returns the\n * next unsigned 32-bit integer. Deterministic for a given seed.\n *\n * @param seed - The 32-bit seed. Coerced to a 32-bit integer via `| 0`.\n * @returns A nullary function returning the next `uint32` in the stream.\n * @example\n * ```ts\n * import { splitmix32 } from \"@cosyte/synth\";\n * const next = splitmix32(12345);\n * const a = next(); // deterministic uint32\n * ```\n */\nexport function splitmix32(seed: number): () => number {\n let a = seed | 0;\n return function next(): number {\n a = (a + 0x9e3779b9) | 0;\n let t = a ^ (a >>> 16);\n t = Math.imul(t, 0x21f0aaad);\n t = t ^ (t >>> 15);\n t = Math.imul(t, 0x735a2d97);\n t = t ^ (t >>> 15);\n return t >>> 0;\n };\n}\n","/**\n * `sfc32` (Small Fast Counter, 32-bit, 128-bit state) — the deterministic, non-cryptographic PRNG that\n * drives every value `@cosyte/synth` generates. Chosen over `mulberry32` (whose author flags that it\n * skips ~1/3 of 32-bit outputs) and over a CSPRNG (`node:crypto`, which is **not seedable** and would\n * defeat reproducibility). A synthetic-fixture generator has **no secrets** — statistical quality plus\n * byte-for-byte reproducibility is exactly the right trade.\n *\n * The state is four 32-bit words. This module exposes the raw step function; {@link ../rng/rng.Rng}\n * wraps it with a seed-expansion ({@link ./splitmix32.splitmix32}) and the ergonomic draw helpers.\n *\n * @module\n */\n\n/**\n * The mutable four-word `sfc32` state. Threaded explicitly (never global) by {@link ../rng/rng.Rng}.\n */\nexport interface Sfc32State {\n /** State word `a`. */\n a: number;\n /** State word `b`. */\n b: number;\n /** State word `c`. */\n c: number;\n /** Counter word `d`. */\n d: number;\n}\n\n/**\n * Advance an {@link Sfc32State} in place by one step and return the next unsigned 32-bit integer.\n *\n * This is the canonical `sfc32` step. The state object is mutated (the counter `d` increments and the\n * mixing words rotate); callers that need reproducible independence hold their own state and never\n * share it — {@link ../rng/rng.Rng} creates a fresh state per seed so two runs from the same seed are\n * identical.\n *\n * @param s - The state to advance. Mutated in place.\n * @returns The next `uint32` in the stream.\n * @example\n * ```ts\n * import { sfc32Next, type Sfc32State } from \"@cosyte/synth\";\n * const s: Sfc32State = { a: 1, b: 2, c: 3, d: 4 };\n * const x = sfc32Next(s); // uint32\n * ```\n */\nexport function sfc32Next(s: Sfc32State): number {\n s.a |= 0;\n s.b |= 0;\n s.c |= 0;\n s.d |= 0;\n const t = (((s.a + s.b) | 0) + s.d) | 0;\n s.d = (s.d + 1) | 0;\n s.a = s.b ^ (s.b >>> 9);\n s.b = (s.c + (s.c << 3)) | 0;\n s.c = (s.c << 21) | (s.c >>> 11);\n s.c = (s.c + t) | 0;\n return t >>> 0;\n}\n","/**\n * `Rng` — the seeded, deterministic random source every `@cosyte/synth` provider draws from.\n *\n * **The reproducibility contract.** A seed — and only the seed — determines the output.\n * `createRng(seed)` expands the integer seed through {@link ./splitmix32.splitmix32} into the four\n * `sfc32` state words, then every draw advances that state via {@link ./sfc32.sfc32Next}. Two `Rng`s\n * created from the same seed emit the **identical** sequence on any machine, any run — the property\n * the parsers', `transform`'s, and `deid`'s regression suites depend on.\n *\n * **Explicit, never global.** An `Rng` is a value you thread through a build; there is no ambient\n * shared generator and **`Math.random` is lint-banned** in `src/` (it is not seedable — its seed is\n * engine-chosen and cannot be reset, so a corpus built on it is not reproducible). Because each\n * generation creates a fresh `Rng` from its seed, generations are independent and parallel-safe.\n *\n * The `Rng` object is stateful by nature (a PRNG advances). Immutability in this library lives where it\n * is testable and matters: the generated **artifacts and the `Corpus` are deep-frozen** (see\n * `../corpus.ts`). Determinism, not object-immutability, is the `Rng`'s guarantee.\n *\n * @module\n */\n\nimport { splitmix32 } from \"./splitmix32.js\";\nimport { sfc32Next, type Sfc32State } from \"./sfc32.js\";\n\n/**\n * A seeded, deterministic random source. Created via {@link createRng}; passed explicitly to every\n * provider. All draw methods advance the internal state deterministically.\n */\nexport interface Rng {\n /** The integer seed this generator was created from (part of the `Corpus` manifest). */\n readonly seed: number;\n /** The next unsigned 32-bit integer. */\n nextUint32(): number;\n /** The next float in `[0, 1)`. */\n float(): number;\n /**\n * A uniformly-distributed integer in the inclusive range `[min, max]`.\n *\n * @param min - Inclusive lower bound (integer).\n * @param max - Inclusive upper bound (integer, `>= min`).\n */\n int(min: number, max: number): number;\n /** `true` with probability `p` (default `0.5`). */\n bool(p?: number): boolean;\n /**\n * Pick one element from a non-empty array.\n *\n * @param items - A non-empty readonly array.\n */\n pick<T>(items: readonly T[]): T;\n /**\n * A string of `n` decimal digits (`0`–`9`), each drawn uniformly.\n *\n * @param n - The number of digits (`>= 0`).\n */\n digits(n: number): string;\n}\n\n/**\n * The concrete {@link Rng}. Holds the mutable `sfc32` state; every method advances it deterministically.\n */\nclass Sfc32Rng implements Rng {\n public readonly seed: number;\n readonly #state: Sfc32State;\n\n public constructor(seed: number) {\n this.seed = seed | 0;\n // Expand the single seed into four well-distributed state words. Seeding sfc32 directly from the\n // raw seed gives poor low-bit behavior; splitmix32 is the standard fix (bryc / roadmap §5).\n const mix = splitmix32(this.seed);\n this.#state = { a: mix(), b: mix(), c: mix(), d: mix() };\n // A short warm-up so nearby seeds diverge immediately.\n for (let i = 0; i < 8; i += 1) sfc32Next(this.#state);\n }\n\n public nextUint32(): number {\n return sfc32Next(this.#state);\n }\n\n public float(): number {\n return this.nextUint32() / 0x1_0000_0000;\n }\n\n public int(min: number, max: number): number {\n if (max < min) throw new RangeError(`Rng.int: max (${String(max)}) < min (${String(min)})`);\n const span = max - min + 1;\n return min + Math.floor(this.float() * span);\n }\n\n public bool(p = 0.5): boolean {\n return this.float() < p;\n }\n\n public pick<T>(items: readonly T[]): T {\n if (items.length === 0) throw new RangeError(\"Rng.pick: empty array\");\n // `int(0, length-1)` is always in-bounds on a non-empty array, so this access cannot be a hole;\n // the cast discharges `noUncheckedIndexedAccess`'s `T | undefined` without a runtime re-check.\n return items[this.int(0, items.length - 1)] as T;\n }\n\n public digits(n: number): string {\n let out = \"\";\n for (let i = 0; i < n; i += 1) out += String(this.int(0, 9));\n return out;\n }\n}\n\n/**\n * Create a seeded, deterministic {@link Rng}. The same `seed` yields the same sequence everywhere.\n *\n * @param seed - The integer seed. Coerced to a 32-bit integer.\n * @returns A fresh, independent {@link Rng}.\n * @example\n * ```ts\n * import { createRng } from \"@cosyte/synth\";\n * const rng = createRng(12345);\n * rng.int(1, 6); // deterministic for seed 12345\n * ```\n */\nexport function createRng(seed: number): Rng {\n return new Sfc32Rng(seed);\n}\n","/**\n * The `Corpus` abstraction — a seed plus a self-describing manifest of what was generated, so a\n * fixture set is itself reproducible and regenerable. A downstream repo pins a seed\n * and gets a stable fixture set that regenerates identically.\n *\n * Generated artifacts and the `Corpus` are **deep-frozen** — this is where the archetype's immutability\n * invariant lives in a generator: a consumer cannot mutate a shared fixture out from under\n * another test.\n *\n * @module\n */\n\n/** The format an artifact was generated for. */\nexport type SynthFormat = \"hl7v2\" | \"fhir\" | \"ccda\" | \"x12\" | \"ncpdp\" | \"astm\";\n\n/**\n * One generated artifact — the serialized wire text plus the metadata needed to reproduce and check\n * it. `warnings` records what the artifact's own parser reported on the round-trip (zero for a\n * spec-clean artifact).\n */\nexport interface Artifact {\n /** The format this artifact belongs to. */\n readonly format: SynthFormat;\n /** A format-specific kind label (e.g. `\"ADT^A01\"`). */\n readonly kind: string;\n /** The serialized wire text, produced by the parser's own conservative serializer. */\n readonly content: string;\n /** The warning codes the parser emitted when the artifact was round-tripped (empty = spec-clean). */\n readonly warnings: readonly string[];\n}\n\n/** A self-describing manifest of a {@link Corpus}. */\nexport interface CorpusManifest {\n /** The formats present in the corpus. */\n readonly formats: readonly SynthFormat[];\n /** Per-kind artifact counts (e.g. `{ \"ADT^A01\": 3 }`). */\n readonly counts: Readonly<Record<string, number>>;\n /** The quirk names applied. */\n readonly quirks: readonly string[];\n}\n\n/** A reproducible, self-describing set of generated artifacts. */\nexport interface Corpus {\n /** The seed the corpus was generated from — regenerating from it yields byte-identical artifacts. */\n readonly seed: number;\n /** The manifest describing what was generated. */\n readonly manifest: CorpusManifest;\n /** The generated artifacts, in generation order. */\n readonly artifacts: readonly Artifact[];\n}\n\n/**\n * Assemble a deep-frozen {@link Corpus} from a seed and its artifacts, deriving the manifest.\n *\n * @param seed - The seed the artifacts were generated from.\n * @param artifacts - The generated artifacts, in order.\n * @param quirks - The quirk names applied (default none).\n * @returns A deep-frozen, self-describing {@link Corpus}.\n * @example\n * ```ts\n * import { makeCorpus } from \"@cosyte/synth\";\n * const corpus = makeCorpus(1, [{ format: \"hl7v2\", kind: \"ADT^A01\", content, warnings: [] }]);\n * corpus.manifest.counts[\"ADT^A01\"]; // 1\n * ```\n */\nexport function makeCorpus(\n seed: number,\n artifacts: readonly Artifact[],\n quirks: readonly string[] = [],\n): Corpus {\n const counts: Record<string, number> = {};\n const formats = new Set<SynthFormat>();\n const frozenArtifacts = artifacts.map((a) => {\n counts[a.kind] = (counts[a.kind] ?? 0) + 1;\n formats.add(a.format);\n return Object.freeze({ ...a, warnings: Object.freeze([...a.warnings]) });\n });\n const manifest: CorpusManifest = Object.freeze({\n formats: Object.freeze([...formats]),\n counts: Object.freeze(counts),\n quirks: Object.freeze([...quirks]),\n });\n return Object.freeze({\n seed,\n manifest,\n artifacts: Object.freeze(frozenArtifacts),\n });\n}\n","/**\n * Thin helpers that build `@cosyte/hl7` `RawField` objects with **components** for `addSegment`.\n *\n * Why this exists: `Hl7Message.addSegment` accepts a field as either a plain string or a structured\n * `RawField`. A plain string is emitted **verbatim** — a literal `^` in it is escaped to `\\S\\`, not\n * treated as a component separator (the parser re-escapes on serialize, by design). To place true\n * components (a name's family/given, a CX's id/authority/type) we must hand `addSegment` a `RawField`\n * with explicit `components`, so the parser's own conservative serializer lays out the separators.\n * That is the whole point of building *through* the parser.\n *\n * @module\n */\n\nimport type { RawField } from \"@cosyte/hl7\";\n\n/**\n * Build a `RawField` from a flat list of component strings (single repetition, single subcomponent\n * per component). Empty strings become empty components (absent at the wire level).\n *\n * @param components - The component values, in HL7 component order.\n * @returns A `RawField` the hl7 serializer lays out with `^` separators.\n * @example\n * ```ts\n * import { componentsField } from \"@cosyte/synth/hl7\";\n * componentsField([\"Testerson\", \"Quilliam\"]); // family^given\n * ```\n */\nexport function componentsField(components: readonly string[]): RawField {\n return {\n repetitions: [{ components: components.map((c) => ({ subcomponents: [c] })) }],\n isNull: false,\n };\n}\n","/**\n * The reserved / never-collide identifier facts that make a `@cosyte/synth` value **provably\n * synthetic** — the ground truth behind the synthetic-safety invariant.\n *\n * These are **facts**, not copyrighted prose: authoritative ranges published by SSA, NANPA, and the\n * IETF that are guaranteed never to denote a real person or a real routable resource. Every provider\n * draws only from these; the predicates here are the executable half of the CI synthetic-safety gate —\n * they let a test assert that no emitted value falls **outside** a reserved source.\n *\n * Sources:\n * - **SSN** — SSA never issues area numbers `000`, `666`, or `900–999`; the `987-65-4320…4329` block\n * is SSA's explicitly-reserved advertising range. (ssa.gov)\n * - **Phone** — NANP reserves `555-0100…555-0199` as the fictional/non-working line range. (nanpa.com)\n * - **Email/domain** — RFC 2606 / RFC 6761 reserved: `example.com`/`.net`/`.org` and the `.example`,\n * `.test`, `.invalid`, `.localhost` TLDs.\n * - **IP** — RFC 5737 IPv4 TEST-NET-1/2/3 (`192.0.2.0/24`, `198.51.100.0/24`, `203.0.113.0/24`) and\n * RFC 3849 IPv6 documentation prefix `2001:db8::/32`.\n * - **NPI** — a real National Provider Identifier is a 10-digit number whose last digit is a Luhn\n * check digit computed over the `80840` prefix + the 9-digit base (CMS NPI check-digit rule, ISO\n * 7812). A number whose check digit is **wrong** therefore cannot be a NPPES-issued NPI. `synth`\n * emits NPIs with a deliberately-invalid check digit, so no generated NPI can collide with a real\n * provider.\n *\n * @module\n */\n\n/**\n * The synthetic **assigning authority** `@cosyte/synth` mints MRNs / account / member identifiers\n * under. There is **no** reserved MRN range (an MRN is unique only within its assigning-authority /\n * OID namespace), so — a documented design decision — every synthetic identifier\n * is scoped to a namespace that clearly cannot be a real facility's: a `SYNTH`-labelled authority whose\n * OID lives under HL7's designated **example** root `2.16.840.1.113883.19`. A value under this AA can\n * never collide with a real record because the *namespace itself* is synthetic.\n */\nexport const SYNTHETIC_ASSIGNING_AUTHORITY = Object.freeze({\n /** The human-readable assigning-authority namespace id (HL7 HD.1). */\n namespaceId: \"COSYTE-SYNTH\",\n /** The universal id — an OID under HL7's example arc `2.16.840.1.113883.19` (HD.2). */\n universalId: \"2.16.840.1.113883.19.999\",\n /** The universal id type (HD.3). */\n universalIdType: \"ISO\",\n});\n\n/** RFC 2606 / 6761 reserved email domains `@cosyte/synth` draws from. */\nexport const RESERVED_EMAIL_DOMAINS: readonly string[] = Object.freeze([\n \"example.com\",\n \"example.org\",\n \"example.net\",\n]);\n\n/** RFC 5737 IPv4 documentation (TEST-NET) `/24` network prefixes. */\nexport const TEST_NET_V4_PREFIXES: readonly string[] = Object.freeze([\n \"192.0.2\", // TEST-NET-1\n \"198.51.100\", // TEST-NET-2\n \"203.0.113\", // TEST-NET-3\n]);\n\n/** RFC 3849 IPv6 documentation prefix. */\nexport const DOC_V6_PREFIX = \"2001:db8\";\n\n/**\n * The `80840` prefix prepended to a 10-digit NPI before the Luhn check (the CMS NPI check-digit\n * rule — `80840` is the ISO 7812 issuer identifier for the US health-application namespace). A real\n * NPI satisfies `luhn(\"80840\" + npi) ≡ 0 (mod 10)`.\n */\nexport const NPI_LUHN_PREFIX = \"80840\";\n\n/**\n * The Luhn sum (mod 10) of a numeric string, doubling every second digit from the right. Used to\n * verify (or deliberately break) an NPI check digit.\n *\n * @param digits - A string of decimal digits.\n * @returns The Luhn sum modulo 10 (0 ⇒ the string passes the Luhn check).\n * @internal\n */\nexport function luhnMod10(digits: string): number {\n let sum = 0;\n // Standard Luhn: the RIGHTMOST digit is never doubled; doubling starts one position in and\n // alternates. For a full payload+check string this makes a Luhn-valid string sum to 0 (mod 10);\n // for a payload with a `0` placeholder in the check position it yields the complement of the\n // correct check digit.\n let double = false;\n for (let i = digits.length - 1; i >= 0; i -= 1) {\n let d = digits.charCodeAt(i) - 48;\n if (d < 0 || d > 9) continue;\n if (double) {\n d *= 2;\n if (d > 9) d -= 9;\n }\n sum += d;\n double = !double;\n }\n return sum % 10;\n}\n\n/**\n * The correct NPI check digit for a 9-digit base — the value that makes `80840` + base + check pass\n * the Luhn check.\n *\n * @param base9 - The 9-digit NPI base (positions 1–9).\n * @returns The check digit (`0`–`9`) a real NPI would carry for this base.\n * @example\n * ```ts\n * import { npiCheckDigit } from \"@cosyte/synth\";\n * npiCheckDigit(\"123456789\"); // 3 — so 1234567893 is a Luhn-valid NPI shape\n * ```\n */\nexport function npiCheckDigit(base9: string): number {\n // Luhn over \"80840\" + base9 with a trailing 0 check placeholder; the check digit closes the sum.\n const partial = luhnMod10(`${NPI_LUHN_PREFIX}${base9}0`);\n return (10 - partial) % 10;\n}\n\n/**\n * The DEA-registration prefix letters `@cosyte/synth` draws a synthetic DEA number's first character\n * from. A real DEA number is `<registrant-type><last-name-initial>` + 7 digits; the first letter is the\n * registrant type (A/B/F/G/M/P/R/X are the widely-published values; the second letter is the\n * registrant's last-name initial). These letters are a **fact** about the number's shape, not\n * copyrighted prose — they only shape the value; the synthetic guarantee is the deliberately-**invalid\n * checksum** (see {@link dea} / {@link isSyntheticDea}).\n */\nexport const DEA_REGISTRANT_TYPES: readonly string[] = Object.freeze([\n \"A\",\n \"B\",\n \"F\",\n \"G\",\n \"M\",\n \"P\",\n \"R\",\n \"X\",\n]);\n\n/**\n * The correct DEA check digit for a 7-digit numeric base. The published DEA checksum is\n * `(d1 + d3 + d5) + 2·(d2 + d4 + d6)`, whose **units digit** is the 7th (check) digit. A real DEA\n * number satisfies this; a number whose 7th digit differs cannot be a validly-issued DEA registration.\n *\n * @param base6 - The first 6 digits of the DEA number (positions 1–6).\n * @returns The check digit (`0`–`9`) a real DEA number would carry for this base.\n * @example\n * ```ts\n * import { deaCheckDigit } from \"@cosyte/synth\";\n * deaCheckDigit(\"123456\"); // the units digit of (1+3+5) + 2·(2+4+6)\n * ```\n */\nexport function deaCheckDigit(base6: string): number {\n let odd = 0;\n let even = 0;\n for (let i = 0; i < 6; i += 1) {\n const digit = base6.charCodeAt(i) - 48;\n if (i % 2 === 0) odd += digit;\n else even += digit;\n }\n return (odd + 2 * even) % 10;\n}\n\n/**\n * Whether a DEA number (`XX` + 7 digits, case-insensitive) is **provably synthetic** — its check digit\n * (the 7th digit) does **not** match the published DEA checksum, so it cannot be a validly-issued DEA\n * registration. A checksum-valid DEA number (which *could* denote a real prescriber) returns `false`; a\n * value that is not the DEA shape returns `false`.\n *\n * @param value - The candidate DEA number (with or without incidental separators).\n * @returns `true` when the DEA number's checksum is wrong (never a real DEA registration).\n * @example\n * ```ts\n * import { isSyntheticDea } from \"@cosyte/synth\";\n * isSyntheticDea(\"AF1234561\"); // depends on the base — true when the 7th digit is wrong\n * ```\n */\nexport function isSyntheticDea(value: string): boolean {\n const compact = value.replace(/[\\s-]/g, \"\").toUpperCase();\n if (!/^[A-Z]{2}\\d{7}$/.test(compact)) return false;\n const digits = compact.slice(2);\n const check = digits.charCodeAt(6) - 48;\n return deaCheckDigit(digits.slice(0, 6)) !== check;\n}\n\n/**\n * Whether a 10-digit NPI is **provably synthetic** — i.e. its check digit is invalid, so it cannot be\n * a NPPES-issued NPI. A Luhn-valid 10-digit NPI (which *could* denote a real registered provider)\n * returns `false`; a non-10-digit value returns `false` (not an NPI shape).\n *\n * @param value - The candidate NPI (digits only, or with incidental separators).\n * @returns `true` when the NPI's check digit is wrong (never a real NPI).\n * @example\n * ```ts\n * import { isSyntheticNpi } from \"@cosyte/synth\";\n * isSyntheticNpi(\"1234567894\"); // true — invalid check digit (valid would be 1234567893)\n * isSyntheticNpi(\"1234567893\"); // false — Luhn-valid, could be a real NPI\n * ```\n */\nexport function isSyntheticNpi(value: string): boolean {\n const digits = value.replace(/\\D/g, \"\");\n if (digits.length !== 10) return false;\n return luhnMod10(`${NPI_LUHN_PREFIX}${digits}`) !== 0;\n}\n\n/**\n * Whether a `ddd-dd-dddd` (or `ddddddddd`) SSN string is drawn from an SSA never-issued / reserved\n * space — area `000`, `666`, or `900–999`. A real, issuable SSN returns `false`.\n *\n * @param value - The candidate SSN (dashes optional).\n * @returns `true` when the SSN is provably synthetic.\n * @example\n * ```ts\n * import { isSyntheticSsn } from \"@cosyte/synth\";\n * isSyntheticSsn(\"900-12-3456\"); // true (never issued)\n * isSyntheticSsn(\"123456789\"); // false (issuable area 123)\n * ```\n */\nexport function isSyntheticSsn(value: string): boolean {\n const digits = value.replace(/\\D/g, \"\");\n if (digits.length !== 9) return false;\n const area = Number(digits.slice(0, 3));\n return area === 0 || area === 666 || area >= 900;\n}\n\n/**\n * Whether a phone string contains the NANP `555-0100…555-0199` reserved fictional line range.\n *\n * @param value - The candidate phone (any formatting).\n * @returns `true` when the number is in the reserved fictional block.\n * @example\n * ```ts\n * import { isSyntheticPhone } from \"@cosyte/synth\";\n * isSyntheticPhone(\"(202) 555-0142\"); // true\n * ```\n */\nexport function isSyntheticPhone(value: string): boolean {\n const digits = value.replace(/\\D/g, \"\");\n // The reserved guarantee is the 7-digit tail: exchange 555 + line 01NN.\n const tail = digits.slice(-7);\n return /^555 ?01\\d\\d$/.test(tail) || /^55501\\d\\d$/.test(tail);\n}\n\n/**\n * Whether an email's domain is an RFC 2606 / 6761 reserved / test domain.\n *\n * @param value - The candidate email address.\n * @returns `true` when the domain is reserved (never real).\n * @example\n * ```ts\n * import { isSyntheticEmail } from \"@cosyte/synth\";\n * isSyntheticEmail(\"faux.testerson@example.com\"); // true\n * ```\n */\nexport function isSyntheticEmail(value: string): boolean {\n const at = value.lastIndexOf(\"@\");\n if (at < 0) return false;\n const domain = value.slice(at + 1).toLowerCase();\n if (RESERVED_EMAIL_DOMAINS.includes(domain)) return true;\n return /\\.(example|test|invalid|localhost)$/.test(domain);\n}\n\n/**\n * Whether an IP string is in an RFC 5737 (IPv4 TEST-NET) or RFC 3849 (IPv6 documentation) reserved\n * block. A real routable address returns `false`.\n *\n * @param value - The candidate IPv4 or IPv6 address.\n * @returns `true` when the address is a reserved documentation address.\n * @example\n * ```ts\n * import { isSyntheticIp } from \"@cosyte/synth\";\n * isSyntheticIp(\"192.0.2.44\"); // true (TEST-NET-1)\n * isSyntheticIp(\"8.8.8.8\"); // false (real)\n * ```\n */\nexport function isSyntheticIp(value: string): boolean {\n if (value.toLowerCase().startsWith(`${DOC_V6_PREFIX}:`)) return true;\n return TEST_NET_V4_PREFIXES.some((prefix) => value.startsWith(`${prefix}.`));\n}\n","/**\n * The shipped **clearly-fake name pool** — `@cosyte/synth`'s own license-clean synthetic data.\n *\n * Deliberately **not** a `faker`-style realistic-name corpus (which could match a real person at a real\n * address — the exact hazard the synthetic-safety invariant forbids). Every token is\n * an obviously-invented, fixture-flavoured word: a reader can tell at a glance it names no one. The pool\n * is small on purpose — structural coverage, not demographic realism, is the goal.\n *\n * `# synthetic: true`\n *\n * @module\n */\n\n/** Obviously-synthetic given names. None is a plausible real person's name. */\nexport const SYNTHETIC_GIVEN_NAMES: readonly string[] = Object.freeze([\n \"Testina\",\n \"Fixtura\",\n \"Synthos\",\n \"Placeholda\",\n \"Sampleton\",\n \"Prototius\",\n \"Stubbina\",\n \"Exampla\",\n \"Quilliam\",\n \"Fabrica\",\n \"Simula\",\n \"Testry\",\n \"Seedwin\",\n \"Corpora\",\n \"Reprodo\",\n \"Mocktavia\",\n \"Dummett\",\n \"Voidwin\",\n \"Deteria\",\n \"Randomir\",\n]);\n\n/** Obviously-synthetic family names. None is a plausible real surname at a real address. */\nexport const SYNTHETIC_FAMILY_NAMES: readonly string[] = Object.freeze([\n \"Testerson\",\n \"Fauxman\",\n \"Placeholt\",\n \"Mockridge\",\n \"Fixtingham\",\n \"Synthwell\",\n \"Dummerton\",\n \"Examplewood\",\n \"Fabricant\",\n \"Simulacre\",\n \"Nonesuch\",\n \"Seedman\",\n \"Corpusworth\",\n \"Reprodus\",\n \"Voidmark\",\n \"Deterwood\",\n \"Randomson\",\n \"Quillfeather\",\n \"Notreal\",\n \"Genfield\",\n]);\n\n/** Obviously-synthetic street names for structured address fields. */\nexport const SYNTHETIC_STREET_NAMES: readonly string[] = Object.freeze([\n \"Fixture Lane\",\n \"Sample Street\",\n \"Placeholder Avenue\",\n \"Synthetic Way\",\n \"Example Boulevard\",\n \"Testing Terrace\",\n \"Mock Road\",\n \"Prototype Court\",\n]);\n\n/**\n * Obviously-synthetic city names. Combined only ever with a synthetic street + a fake name (the\n * *combination* is what identifies, and the combination is always synthetic).\n */\nexport const SYNTHETIC_CITY_NAMES: readonly string[] = Object.freeze([\n \"Faketon\",\n \"Synthville\",\n \"Exampleburg\",\n \"Testford\",\n \"Mockhaven\",\n \"Fixtureton\",\n]);\n","/**\n * The synthetic-safety provider layer — every identifier, contact point, name, and date\n * `@cosyte/synth` emits is minted here, and **only** from a guaranteed-non-colliding source. There is no code\n * path that returns a value not drawn from a reserved range or the\n * shipped fake-name pool. This is the inverse of a parser's liberality: the generator is *closed-world*\n * on its data sources, so no output *can* be real or plausibly-real PHI.\n *\n * All providers are pure functions of an explicit {@link ../rng/rng.Rng} — same seed, same values.\n *\n * @module\n */\n\nimport type { Rng } from \"../rng/rng.js\";\n\nimport {\n RESERVED_EMAIL_DOMAINS,\n TEST_NET_V4_PREFIXES,\n DOC_V6_PREFIX,\n SYNTHETIC_ASSIGNING_AUTHORITY,\n npiCheckDigit,\n deaCheckDigit,\n DEA_REGISTRANT_TYPES,\n} from \"./reserved.js\";\nimport {\n SYNTHETIC_GIVEN_NAMES,\n SYNTHETIC_FAMILY_NAMES,\n SYNTHETIC_STREET_NAMES,\n SYNTHETIC_CITY_NAMES,\n} from \"./names-pool.js\";\n\n/** A synthetic person name drawn from the shipped fake-name pool. */\nexport interface SyntheticName {\n /** A clearly-fake given name. */\n readonly given: string;\n /** A clearly-fake family name. */\n readonly family: string;\n}\n\n/** A synthetic postal address — synthetic street + city, a fixed non-real ZIP. */\nexport interface SyntheticAddress {\n /** A clearly-fake street line. */\n readonly street: string;\n /** A clearly-fake city. */\n readonly city: string;\n /** A US state abbreviation (structural only; never combined with a real street + name + DOB). */\n readonly state: string;\n /** A reserved non-real ZIP (`00000`). */\n readonly zip: string;\n}\n\n/** A synthetic identifier scoped to the synthetic assigning authority. */\nexport interface SyntheticIdentifier {\n /** The identifier value (digits) — unique only within the synthetic namespace. */\n readonly value: string;\n /** HL7 identifier type code (`MR` = medical record, `AN` = account, `MB` = member). */\n readonly typeCode: \"MR\" | \"AN\" | \"MB\";\n /** The synthetic assigning-authority namespace id. */\n readonly assigningAuthority: string;\n /** The synthetic assigning-authority OID (HL7 example arc). */\n readonly assigningAuthorityOid: string;\n}\n\n/** Which SSN reserved space to draw from. */\nexport type SsnBlock = \"never-issued\" | \"advertising\";\n\n/**\n * A **synthetic SSN** — dashed `AAA-GG-SSSS`. Default draws the SSA never-issued area space\n * (`900–999`); `block: \"advertising\"` draws SSA's reserved advertising block (`987-65-4320…4329`).\n * A value from this function can never be a real SSN.\n *\n * @param rng - The seeded generator.\n * @param block - Which reserved space to draw from. Defaults to `\"never-issued\"`.\n * @returns A dashed synthetic SSN string.\n * @example\n * ```ts\n * import { createRng, ssn } from \"@cosyte/synth\";\n * ssn(createRng(1)); // e.g. a 900-area, never-issued SSN\n * ```\n */\nexport function ssn(rng: Rng, block: SsnBlock = \"never-issued\"): string {\n if (block === \"advertising\") {\n // SSA's explicitly-reserved advertising block: last digit 0..9 within -4320..-4329.\n return `987-65-432${String(rng.int(0, 9))}`;\n }\n const area = rng.int(900, 999); // SSA never issues 900-999.\n const group = rng.digits(2);\n const serial = rng.digits(4);\n return `${String(area)}-${group}-${serial}`;\n}\n\n/**\n * A **synthetic phone** in the NANP reserved fictional block — `(AAA) 555-01NN`. The reserved\n * guarantee is the `555-01NN` tail (exchange 555, line 0100–0199); the area code is any NANP-valid\n * `NXX`. Can never be a working number.\n *\n * @param rng - The seeded generator.\n * @returns A formatted synthetic phone string.\n * @example\n * ```ts\n * import { createRng, phone } from \"@cosyte/synth\";\n * phone(createRng(1)); // e.g. \"(2XX) 555-01NN\"\n * ```\n */\nexport function phone(rng: Rng): string {\n const area = `${String(rng.int(2, 9))}${rng.digits(2)}`; // NXX area code.\n const line = `01${rng.digits(2)}`; // reserved 0100-0199.\n return `(${area}) 555-${line}`;\n}\n\n/**\n * A **synthetic name** drawn from the shipped clearly-fake pool.\n *\n * @param rng - The seeded generator.\n * @returns A {@link SyntheticName}.\n * @example\n * ```ts\n * import { createRng, name } from \"@cosyte/synth\";\n * const { given, family } = name(createRng(1));\n * ```\n */\nexport function name(rng: Rng): SyntheticName {\n return { given: rng.pick(SYNTHETIC_GIVEN_NAMES), family: rng.pick(SYNTHETIC_FAMILY_NAMES) };\n}\n\n/**\n * A **synthetic email** at an RFC 2606 / 6761 reserved domain — `<slug>@example.com`.\n *\n * @param rng - The seeded generator.\n * @param person - Optional name to derive the local-part slug from; otherwise a random slug is used.\n * @returns A synthetic email address.\n * @example\n * ```ts\n * import { createRng, email, name } from \"@cosyte/synth\";\n * email(createRng(1), name(createRng(1))); // \"<given>.<family>@example.com\"\n * ```\n */\nexport function email(rng: Rng, person?: SyntheticName): string {\n const domain = rng.pick(RESERVED_EMAIL_DOMAINS);\n const slug = person ? `${person.given}.${person.family}`.toLowerCase() : `synth${rng.digits(6)}`;\n return `${slug}@${domain}`;\n}\n\n/**\n * A **synthetic IPv4** in an RFC 5737 TEST-NET block — never routable.\n *\n * @param rng - The seeded generator.\n * @returns A TEST-NET IPv4 address string.\n * @example\n * ```ts\n * import { createRng, ipv4 } from \"@cosyte/synth\";\n * ipv4(createRng(1)); // e.g. \"192.0.2.NN\"\n * ```\n */\nexport function ipv4(rng: Rng): string {\n return `${rng.pick(TEST_NET_V4_PREFIXES)}.${String(rng.int(1, 254))}`;\n}\n\n/**\n * A **synthetic IPv6** in the RFC 3849 documentation prefix `2001:db8::/32` — never routable.\n *\n * @param rng - The seeded generator.\n * @returns A documentation-prefix IPv6 address string.\n * @example\n * ```ts\n * import { createRng, ipv6 } from \"@cosyte/synth\";\n * ipv6(createRng(1)); // e.g. \"2001:db8::NNNN\"\n * ```\n */\nexport function ipv6(rng: Rng): string {\n const tail = rng.nextUint32().toString(16).padStart(4, \"0\").slice(-4);\n return `${DOC_V6_PREFIX}::${tail}`;\n}\n\n/**\n * A **deterministic UUIDv4-shaped** surrogate key from the seeded generator. Because it is seeded (not\n * from `node:crypto`, which is not reproducible), the cryptographic non-collision argument is weaker —\n * acceptable because the identifier namespace is synthetic anyway, and noted honestly.\n *\n * @param rng - The seeded generator.\n * @returns A canonical `8-4-4-4-12` lowercase-hex UUID string with version `4` and RFC 4122 variant.\n * @example\n * ```ts\n * import { createRng, uuid } from \"@cosyte/synth\";\n * uuid(createRng(1)); // \"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx\"\n * ```\n */\nexport function uuid(rng: Rng): string {\n const bytes = new Uint8Array(16);\n for (let i = 0; i < 16; i += 1) bytes[i] = rng.int(0, 255);\n bytes[6] = ((bytes[6] ?? 0) & 0x0f) | 0x40; // version 4\n bytes[8] = ((bytes[8] ?? 0) & 0x3f) | 0x80; // variant 10xx\n const hex = Array.from(bytes, (b) => b.toString(16).padStart(2, \"0\"));\n return `${hex.slice(0, 4).join(\"\")}-${hex.slice(4, 6).join(\"\")}-${hex.slice(6, 8).join(\"\")}-${hex.slice(8, 10).join(\"\")}-${hex.slice(10, 16).join(\"\")}`;\n}\n\n/**\n * A **synthetic NPI** — a 10-digit National Provider Identifier with a **deliberately-invalid Luhn\n * check digit**, so it can never be a NPPES-issued NPI (a real NPI must satisfy the `80840`-prefixed\n * Luhn check). The 9-digit base is drawn from the seeded generator; the check digit is\n * set to `(correct + 1) mod 10`, guaranteeing the full value fails validation.\n *\n * @param rng - The seeded generator.\n * @returns A 10-digit NPI-shaped string that is provably not a real NPI.\n * @example\n * ```ts\n * import { createRng, npi, isSyntheticNpi } from \"@cosyte/synth\";\n * isSyntheticNpi(npi(createRng(1))); // true — invalid check digit by construction\n * ```\n */\nexport function npi(rng: Rng): string {\n const base9 = rng.digits(9);\n const wrongCheck = (npiCheckDigit(base9) + 1) % 10;\n return `${base9}${String(wrongCheck)}`;\n}\n\n/**\n * A **synthetic DEA number** — `<registrant-type><initial>` + 7 digits with a **deliberately-invalid\n * checksum**, so it can never be a validly-issued DEA registration (a real DEA number's 7th digit\n * satisfies the published DEA checksum). The first letter is a registrant-type letter, the\n * second is derived from `person` (its family initial) when supplied so the number reads plausibly; the\n * 6-digit base is seeded and the check digit is set to `(correct + 1) mod 10`, guaranteeing the value\n * fails validation. NCPDP carries prescriber DEA, and this is the identity locus a refuter attacks\n * hardest, so — like {@link npi} — non-collision is a construction-level guarantee, not a heuristic.\n *\n * @param rng - The seeded generator.\n * @param person - Optional name whose family initial becomes the DEA's second letter.\n * @returns A DEA-shaped string that is provably not a real DEA registration.\n * @example\n * ```ts\n * import { createRng, dea, isSyntheticDea } from \"@cosyte/synth\";\n * isSyntheticDea(dea(createRng(1))); // true — invalid checksum by construction\n * ```\n */\nexport function dea(rng: Rng, person?: SyntheticName): string {\n const type = rng.pick(DEA_REGISTRANT_TYPES);\n const initialSource = person?.family ?? rng.pick(SYNTHETIC_FAMILY_NAMES);\n const initial = initialSource.slice(0, 1).toUpperCase();\n const base6 = rng.digits(6);\n const wrongCheck = (deaCheckDigit(base6) + 1) % 10;\n return `${type}${initial}${base6}${String(wrongCheck)}`;\n}\n\n/**\n * A **synthetic identifier** (MRN / account / member id) scoped to the synthetic assigning authority.\n * There is no reserved MRN range, so non-collision is guaranteed by the *namespace*, not the value: the\n * identifier lives under a `SYNTH` authority no real facility uses.\n *\n * @param rng - The seeded generator.\n * @param typeCode - The HL7 identifier type: `MR` (default), `AN`, or `MB`.\n * @returns A {@link SyntheticIdentifier}.\n * @example\n * ```ts\n * import { createRng, identifier } from \"@cosyte/synth\";\n * identifier(createRng(1), \"MR\"); // { value, typeCode: \"MR\", assigningAuthority: \"COSYTE-SYNTH\", ... }\n * ```\n */\nexport function identifier(\n rng: Rng,\n typeCode: SyntheticIdentifier[\"typeCode\"] = \"MR\",\n): SyntheticIdentifier {\n return {\n value: rng.digits(8),\n typeCode,\n assigningAuthority: SYNTHETIC_ASSIGNING_AUTHORITY.namespaceId,\n assigningAuthorityOid: SYNTHETIC_ASSIGNING_AUTHORITY.universalId,\n };\n}\n\n/**\n * A **synthetic address** — a fake street + city, a reserved non-real ZIP (`00000`). A real state\n * abbreviation may appear (structural only) but is never combined with a real street + name + DOB.\n *\n * @param rng - The seeded generator.\n * @returns A {@link SyntheticAddress}.\n * @example\n * ```ts\n * import { createRng, address } from \"@cosyte/synth\";\n * address(createRng(1)); // { street, city, state, zip: \"00000\" }\n * ```\n */\nexport function address(rng: Rng): SyntheticAddress {\n const number = rng.int(1, 9999);\n return {\n street: `${String(number)} ${rng.pick(SYNTHETIC_STREET_NAMES)}`,\n city: rng.pick(SYNTHETIC_CITY_NAMES),\n state: rng.pick(US_STATES),\n zip: \"00000\",\n };\n}\n\n/**\n * A **synthetic date** in HL7 `YYYYMMDD` form, drawn uniformly within an inclusive year range. Comes\n * from the seeded generator (never wall-clock), so it is reproducible and implies no real event.\n *\n * @param rng - The seeded generator.\n * @param minYear - Inclusive lower year bound (default `1930`).\n * @param maxYear - Inclusive upper year bound (default `2010`).\n * @returns An `YYYYMMDD` date string (always a valid calendar day).\n * @example\n * ```ts\n * import { createRng, dateYmd } from \"@cosyte/synth\";\n * dateYmd(createRng(1), 1970, 2000); // \"YYYYMMDD\"\n * ```\n */\nexport function dateYmd(rng: Rng, minYear = 1930, maxYear = 2010): string {\n const year = rng.int(minYear, maxYear);\n const month = rng.int(1, 12);\n const daysInMonth = new Date(Date.UTC(year, month, 0)).getUTCDate();\n const day = rng.int(1, daysInMonth);\n return `${String(year).padStart(4, \"0\")}${String(month).padStart(2, \"0\")}${String(day).padStart(2, \"0\")}`;\n}\n\n/** US state abbreviations — structural only (see {@link address}). */\nconst US_STATES: readonly string[] = Object.freeze([\n \"AL\",\n \"AK\",\n \"AZ\",\n \"AR\",\n \"CA\",\n \"CO\",\n \"CT\",\n \"DE\",\n \"FL\",\n \"GA\",\n \"HI\",\n \"ID\",\n \"IL\",\n \"IN\",\n \"IA\",\n \"KS\",\n \"KY\",\n \"LA\",\n \"ME\",\n \"MD\",\n \"MA\",\n \"MI\",\n \"MN\",\n \"MS\",\n \"MO\",\n \"MT\",\n \"NE\",\n \"NV\",\n \"NH\",\n \"NJ\",\n \"NM\",\n \"NY\",\n \"NC\",\n \"ND\",\n \"OH\",\n \"OK\",\n \"OR\",\n \"PA\",\n \"RI\",\n \"SC\",\n \"SD\",\n \"TN\",\n \"TX\",\n \"UT\",\n \"VT\",\n \"VA\",\n \"WA\",\n \"WV\",\n \"WI\",\n \"WY\",\n]);\n","/**\n * The `safe` namespace — the single entry point for every synthetic-by-construction value provider.\n *\n * Grouped under one object so a consumer reads `safe.ssn(rng)` / `safe.phone(rng)` and it is\n * self-evident that the value is drawn from a guaranteed-non-colliding synthetic source.\n * The individual functions and the reserved-range predicates are also exported by name from the\n * package root for direct import.\n *\n * @module\n */\n\nimport {\n ssn,\n phone,\n name,\n email,\n ipv4,\n ipv6,\n uuid,\n identifier,\n address,\n dateYmd,\n npi,\n dea,\n} from \"./providers.js\";\n\nexport * from \"./providers.js\";\nexport * from \"./reserved.js\";\nexport * from \"./names-pool.js\";\n\n/**\n * The synthetic-safety provider namespace. Every function draws only from a reserved range or the\n * shipped fake-name pool — no value it returns can be real or plausibly-real PHI.\n *\n * @example\n * ```ts\n * import { createRng, safe } from \"@cosyte/synth\";\n * const rng = createRng(42);\n * safe.ssn(rng); // never-issued SSN\n * safe.phone(rng); // reserved 555-01NN number\n * ```\n */\nexport const safe = Object.freeze({\n ssn,\n phone,\n name,\n email,\n ipv4,\n ipv6,\n uuid,\n identifier,\n address,\n dateYmd,\n npi,\n dea,\n});\n","/**\n * Shared HL7 v2 building blocks for every message family `@cosyte/synth` generates — the MSH scaffold,\n * the seeded timestamp, and the patient-identity bundle + its `PID` segment. Factored out so `ADT`,\n * `ORU`, `ORM`, `SIU`, and `VXU` all mint identity from the **same** synthetic-safety providers in the\n * **same** draw order, and all emit through `@cosyte/hl7`'s conservative serializer. Nothing here draws a\n * value that is not sourced from `../safe` — the synthetic-by-construction\n * invariant holds by construction for every family.\n *\n * @module\n */\n\nimport { buildMessage, type Hl7Message, type RawField } from \"@cosyte/hl7\";\n\nimport { type Rng } from \"../rng/rng.js\";\nimport {\n safe,\n type SyntheticName,\n type SyntheticAddress,\n type SyntheticIdentifier,\n} from \"../safe/index.js\";\n\nimport { componentsField } from \"./field.js\";\n\n/**\n * A seeded HL7 `YYYYMMDDHHMMSS` timestamp (message/event time; recent-year range). Strict HL7 DTM, so\n * `@cosyte/hl7` parses it back with no `TIMESTAMP_FALLBACK_FORMAT` warning.\n *\n * @param rng - The seeded generator.\n * @returns A 14-digit `YYYYMMDDHHMMSS` timestamp string.\n * @example\n * ```ts\n * import { createRng } from \"@cosyte/synth\";\n * // \"20230714…\"\n * ```\n */\nexport function seededTimestamp(rng: Rng): string {\n const date = safe.dateYmd(rng, 2020, 2025);\n const hh = String(rng.int(0, 23)).padStart(2, \"0\");\n const mm = String(rng.int(0, 59)).padStart(2, \"0\");\n const ss = String(rng.int(0, 59)).padStart(2, \"0\");\n return `${date}${hh}${mm}${ss}`;\n}\n\n/** The MSH scaffold shared by every generated message: the built message plus its seeded MSH values. */\nexport interface MessageScaffold {\n /** The `Hl7Message` with a complete MSH — chain `.addSegment(...)` to append the payload. */\n readonly message: Hl7Message;\n /** The seeded `YYYYMMDDHHMMSS` message timestamp (MSH-7), reused for event/observation times. */\n readonly timestamp: string;\n /** The seeded message control id (MSH-10). */\n readonly controlId: string;\n}\n\n/**\n * Build the MSH scaffold for a message of the given `MSH-9` type through `@cosyte/hl7`'s `buildMessage`,\n * so the delimiters, control id, and header layout are the parser's own conservative emit. Draws the\n * timestamp then the control id from `rng` (a fixed order — the reproducibility contract).\n *\n * @param rng - The seeded generator.\n * @param type - The `MSH-9` message type, e.g. `\"ORU^R01\"`.\n * @returns The {@link MessageScaffold}.\n * @example\n * ```ts\n * import { createRng } from \"@cosyte/synth\";\n * // mshScaffold(createRng(1), \"ORU^R01\").message.addSegment(\"PID\", […]);\n * ```\n */\nexport function mshScaffold(rng: Rng, type: string): MessageScaffold {\n const timestamp = seededTimestamp(rng);\n const controlId = `SYNTH${rng.digits(10)}`;\n const message = buildMessage({\n type,\n sendingApp: \"COSYTE-SYNTH\",\n sendingFacility: \"SYNTH-FAC\",\n receivingApp: \"RECEIVER\",\n receivingFacility: \"RECV-FAC\",\n controlId,\n timestamp,\n version: \"2.5\",\n processingId: \"P\",\n });\n return { message, timestamp, controlId };\n}\n\n/** A complete synthetic patient identity — every field drawn from `../safe`. */\nexport interface PatientIdentity {\n /** Name from the shipped fake-name pool. */\n readonly person: SyntheticName;\n /** Medical-record identifier scoped to the synthetic assigning authority. */\n readonly mrn: SyntheticIdentifier;\n /** Date of birth (`YYYYMMDD`) from the seeded generator. */\n readonly dob: string;\n /** Administrative sex. */\n readonly sex: \"M\" | \"F\";\n /** Synthetic postal address (reserved non-real ZIP). */\n readonly address: SyntheticAddress;\n /** Reserved `555-01xx` phone number. */\n readonly phone: string;\n /** Never-issued SSN as 9 digits (no dashes), for `PID-19`. */\n readonly ssnDigits: string;\n}\n\n/**\n * Mint a complete synthetic {@link PatientIdentity}. Every value comes from a synthetic-safety provider\n * — no code path here can return a real or plausibly-real identifier. The draw order is\n * fixed (name → MRN → DOB → sex → address → phone → SSN) so the same seed yields the same identity.\n *\n * @param rng - The seeded generator.\n * @returns A synthetic {@link PatientIdentity}.\n * @example\n * ```ts\n * import { createRng } from \"@cosyte/synth\";\n * // const id = patientIdentity(createRng(1)); // id.person, id.mrn, …\n * ```\n */\nexport function patientIdentity(rng: Rng): PatientIdentity {\n const person = safe.name(rng);\n const mrn = safe.identifier(rng, \"MR\");\n const dob = safe.dateYmd(rng, 1930, 2010);\n const sex = rng.pick([\"M\", \"F\"] as const);\n const address = safe.address(rng);\n const phone = safe.phone(rng);\n const ssnDigits = safe.ssn(rng).replace(/-/g, \"\");\n return { person, mrn, dob, sex, address, phone, ssnDigits };\n}\n\n/**\n * Lay out a fully-populated `PID` segment from a {@link PatientIdentity} as `addSegment` fields — the\n * PHI-dense segment shared by every family. Components go through {@link componentsField} so the parser\n * lays out the `^` separators (building *through* the parser).\n *\n * @param id - The synthetic identity to render.\n * @returns The `PID` field list for `Hl7Message.addSegment(\"PID\", …)`.\n * @example\n * ```ts\n * // msg.addSegment(\"PID\", pidSegment(patientIdentity(createRng(1))));\n * ```\n */\nexport function pidSegment(id: PatientIdentity): readonly (string | RawField)[] {\n return [\n \"1\", // PID-1 set id\n \"\", // PID-2 (legacy, absent)\n componentsField([id.mrn.value, \"\", \"\", id.mrn.assigningAuthority, id.mrn.typeCode]), // PID-3 CX\n \"\", // PID-4\n componentsField([id.person.family, id.person.given]), // PID-5 XPN\n \"\", // PID-6\n id.dob, // PID-7 DOB\n id.sex, // PID-8 sex\n \"\", // PID-9\n \"\", // PID-10\n componentsField([id.address.street, \"\", id.address.city, id.address.state, id.address.zip]), // PID-11 XAD\n \"\", // PID-12\n id.phone, // PID-13 phone\n \"\", // PID-14\n \"\", // PID-15\n \"\", // PID-16\n \"\", // PID-17\n \"\", // PID-18\n id.ssnDigits, // PID-19 SSN (digits)\n ];\n}\n","/**\n * Spec-clean HL7 v2 `ADT` generation, built **through `@cosyte/hl7`'s `buildMessage`** so MSH\n * delimiters, segment layout, and escaping are the parser's own conservative emit — spec-clean *by\n * construction*. Every PHI-bearing field (name, DOB, SSN, MRN,\n * address, phone) is drawn from the synthetic-safety providers (`../safe`), so no value can be real.\n *\n * `ADT^A01/A04/A08` all require the `PID` (patient) + `PV1` (visit) groups the parser's structure net\n * checks for — so a generated message round-trips through `@cosyte/hl7` with **zero warnings**.\n *\n * @module\n */\n\nimport type { Hl7Message } from \"@cosyte/hl7\";\n\nimport { createRng } from \"../rng/rng.js\";\n\nimport { componentsField } from \"./field.js\";\nimport { mshScaffold, patientIdentity, pidSegment } from \"./common.js\";\n\n/** The ADT trigger events this generator produces (all require the PID + PV1 groups). */\nexport type AdtTrigger = \"A01\" | \"A04\" | \"A08\";\n\n/** Options for {@link generateAdt}. */\nexport interface GenerateAdtOptions {\n /** The seed — the same seed yields a byte-identical message. Defaults to `0`. */\n readonly seed?: number;\n /** The ADT trigger event. Defaults to `\"A01\"`. */\n readonly trigger?: AdtTrigger;\n}\n\n/**\n * Generate a spec-clean `ADT` {@link Hl7Message} through `@cosyte/hl7`. Deterministic in `seed`.\n *\n * The message carries a complete MSH (seeded control id + timestamp, so the bytes are reproducible),\n * `EVN`, a fully-populated `PID` (identity from the synthetic providers), and `PV1` (the visit group),\n * so it parses back through `@cosyte/hl7` with **zero warnings** (proven by {@link ./round-trip}).\n *\n * @param options - Seed + trigger. See {@link GenerateAdtOptions}.\n * @returns A spec-clean `ADT` `Hl7Message`.\n * @example\n * ```ts\n * import { generateAdt } from \"@cosyte/synth/hl7\";\n * const msg = generateAdt({ seed: 12345, trigger: \"A01\" });\n * console.log(msg.toString());\n * ```\n */\nexport function generateAdt(options: GenerateAdtOptions = {}): Hl7Message {\n const seed = options.seed ?? 0;\n const trigger = options.trigger ?? \"A01\";\n const rng = createRng(seed);\n\n const { message, timestamp } = mshScaffold(rng, `ADT^${trigger}`);\n message.addSegment(\"EVN\", [trigger, timestamp]);\n message.addSegment(\"PID\", pidSegment(patientIdentity(rng)));\n\n const patientClass = rng.pick([\"I\", \"O\", \"E\"] as const);\n message.addSegment(\"PV1\", [\n \"1\", // PV1-1 set id\n patientClass, // PV1-2 patient class\n componentsField([\"SYNTHWARD\", String(rng.int(1, 999)).padStart(3, \"0\"), \"01\"]), // PV1-3 PL\n ]);\n\n return message;\n}\n","/**\n * A tiny, curated, **license-clean** pool of example codes used to fill coded fields in generated HL7\n * messages (`OBR`/`OBX` observations, `ORC`/`OBR` orders, `RXA` vaccines). These are **public code\n * facts** — the spec examples' own values — not copyrighted terminology tables: `@cosyte/synth` bundles\n * **no** SNOMED/CPT/LOINC/RxNorm content. The pool exists only so a generated message is *structurally*\n * realistic; a consumer who\n * needs their own codes supplies them.\n *\n * Nothing here is PHI — codes and their display text are not identifiers. The synthetic-safety\n * invariant governs identity fields (name/DOB/SSN/MRN/phone/address), which come from `../safe`.\n *\n * @module\n */\n\n/** A coded concept: an identifier code, human-readable text, and its code system (HL7 `CE`/`CWE`). */\nexport interface ExampleCode {\n /** The code value (component 1). */\n readonly code: string;\n /** The human-readable display text (component 2). */\n readonly text: string;\n /** The coding-system id (component 3), e.g. `\"LN\"` (LOINC) or `\"CVX\"`. */\n readonly system: string;\n /** Reporting units (UCUM), where the concept is a measured quantity. */\n readonly units?: string;\n}\n\n/**\n * A handful of common LOINC laboratory-observation example codes (for `OBX`). Public LOINC identifiers\n * used purely as illustrative structural fillers.\n */\nexport const EXAMPLE_LAB_OBSERVATIONS: readonly ExampleCode[] = Object.freeze([\n Object.freeze({ code: \"4548-4\", text: \"Hemoglobin A1c\", system: \"LN\", units: \"%\" }),\n Object.freeze({ code: \"718-7\", text: \"Hemoglobin\", system: \"LN\", units: \"g/dL\" }),\n Object.freeze({ code: \"2345-7\", text: \"Glucose\", system: \"LN\", units: \"mg/dL\" }),\n Object.freeze({ code: \"2951-2\", text: \"Sodium\", system: \"LN\", units: \"mmol/L\" }),\n Object.freeze({ code: \"2823-3\", text: \"Potassium\", system: \"LN\", units: \"mmol/L\" }),\n Object.freeze({ code: \"789-8\", text: \"Erythrocytes\", system: \"LN\", units: \"10*6/uL\" }),\n]);\n\n/**\n * A handful of LOINC panel/service example codes (for the `OBR`/`ORC` universal service id). Public\n * identifiers used as structural fillers.\n */\nexport const EXAMPLE_ORDER_SERVICES: readonly ExampleCode[] = Object.freeze([\n Object.freeze({ code: \"24323-8\", text: \"Comprehensive metabolic panel\", system: \"LN\" }),\n Object.freeze({ code: \"58410-2\", text: \"CBC panel\", system: \"LN\" }),\n Object.freeze({ code: \"24356-8\", text: \"Urinalysis panel\", system: \"LN\" }),\n Object.freeze({ code: \"24331-1\", text: \"Lipid panel\", system: \"LN\" }),\n]);\n\n/**\n * A handful of CDC CVX vaccine example codes (for `RXA-5`). Public CVX identifiers used as structural\n * fillers; `@cosyte/synth` bundles no vaccine terminology.\n */\nexport const EXAMPLE_VACCINES: readonly ExampleCode[] = Object.freeze([\n Object.freeze({ code: \"08\", text: \"Hep B, adolescent or pediatric\", system: \"CVX\" }),\n Object.freeze({ code: \"20\", text: \"DTaP\", system: \"CVX\" }),\n Object.freeze({ code: \"03\", text: \"MMR\", system: \"CVX\" }),\n Object.freeze({ code: \"10\", text: \"IPV\", system: \"CVX\" }),\n Object.freeze({ code: \"141\", text: \"Influenza, seasonal, injectable\", system: \"CVX\" }),\n Object.freeze({ code: \"21\", text: \"Varicella\", system: \"CVX\" }),\n]);\n","/**\n * Spec-clean HL7 v2 `ORU^R01` (unsolicited observation result) generation, built **through\n * `@cosyte/hl7`'s `buildMessage`**. The parser's structure net requires the\n * result group (`OBR`/`OBX`) for `ORU^R01`; this generator always emits both, plus a fully-populated\n * `PID`, so the message round-trips with **zero warnings**. Patient identity comes from `../safe`;\n * observation codes come from the license-clean example pool (`./example-codes`), never bundled\n * terminology. A `synth` `ORU` is *structurally* valid, not clinically coherent.\n *\n * @module\n */\n\nimport type { Hl7Message, RawField } from \"@cosyte/hl7\";\n\nimport { createRng, type Rng } from \"../rng/rng.js\";\n\nimport { componentsField } from \"./field.js\";\nimport { mshScaffold, patientIdentity, pidSegment, seededTimestamp } from \"./common.js\";\nimport { EXAMPLE_LAB_OBSERVATIONS, EXAMPLE_ORDER_SERVICES } from \"./example-codes.js\";\n\n/** Options for {@link generateOru}. */\nexport interface GenerateOruOptions {\n /** The seed — the same seed yields a byte-identical message. Defaults to `0`. */\n readonly seed?: number;\n}\n\n/** Render one `OBX` result segment (set id `n`) for a numeric example observation. */\nfunction obxSegment(rng: Rng, setId: number): readonly (string | RawField)[] {\n const obs = rng.pick(EXAMPLE_LAB_OBSERVATIONS);\n const value = `${String(rng.int(1, 300))}.${String(rng.int(0, 9))}`;\n const observedAt = seededTimestamp(rng);\n return [\n String(setId), // OBX-1 set id\n \"NM\", // OBX-2 value type (numeric)\n componentsField([obs.code, obs.text, obs.system]), // OBX-3 observation identifier (CE)\n \"\", // OBX-4 observation sub-id\n value, // OBX-5 observation value\n obs.units ?? \"\", // OBX-6 units\n \"\", // OBX-7 reference range\n \"N\", // OBX-8 abnormal flags (normal)\n \"\", // OBX-9\n \"\", // OBX-10\n \"F\", // OBX-11 observation result status (final)\n \"\", // OBX-12\n \"\", // OBX-13\n observedAt, // OBX-14 date/time of the observation\n ];\n}\n\n/**\n * Generate a spec-clean `ORU^R01` {@link Hl7Message} through `@cosyte/hl7`. Deterministic in `seed`.\n *\n * Layout: MSH, `PID` (synthetic identity), `OBR` (order/observation request), and 1–3 `OBX` result\n * rows. The `OBR`/`OBX` result group satisfies the parser's `ORU^R01` structure net, so the message\n * re-parses with **zero warnings** (proven by {@link ./round-trip}).\n *\n * @param options - Seed. See {@link GenerateOruOptions}.\n * @returns A spec-clean `ORU^R01` `Hl7Message`.\n * @example\n * ```ts\n * import { generateOru } from \"@cosyte/synth/hl7\";\n * const msg = generateOru({ seed: 12345 });\n * console.log(msg.toString());\n * ```\n */\nexport function generateOru(options: GenerateOruOptions = {}): Hl7Message {\n const seed = options.seed ?? 0;\n const rng = createRng(seed);\n\n const { message } = mshScaffold(rng, \"ORU^R01\");\n message.addSegment(\"PID\", pidSegment(patientIdentity(rng)));\n\n const service = rng.pick(EXAMPLE_ORDER_SERVICES);\n const placer = rng.digits(8);\n const filler = rng.digits(8);\n message.addSegment(\"OBR\", [\n \"1\", // OBR-1 set id\n placer, // OBR-2 placer order number\n filler, // OBR-3 filler order number\n componentsField([service.code, service.text, service.system]), // OBR-4 universal service id (CE)\n \"\", // OBR-5\n \"\", // OBR-6\n seededTimestamp(rng), // OBR-7 observation date/time\n ]);\n\n const obxCount = rng.int(1, 3);\n for (let i = 1; i <= obxCount; i += 1) {\n message.addSegment(\"OBX\", obxSegment(rng, i));\n }\n\n return message;\n}\n","/**\n * Spec-clean HL7 v2 `ORM^O01` (general order) generation, built **through `@cosyte/hl7`'s\n * `buildMessage`**. The parser's structure net requires the common-order segment\n * (`ORC`) for `ORM^O01`; this generator emits `ORC` + a matching `OBR`, plus a fully-populated `PID`,\n * so the message round-trips with **zero warnings**. Identity comes from `../safe`; the ordered service\n * comes from the license-clean example pool, never bundled terminology.\n *\n * @module\n */\n\nimport type { Hl7Message } from \"@cosyte/hl7\";\n\nimport { createRng } from \"../rng/rng.js\";\n\nimport { componentsField } from \"./field.js\";\nimport { mshScaffold, patientIdentity, pidSegment, seededTimestamp } from \"./common.js\";\nimport { EXAMPLE_ORDER_SERVICES } from \"./example-codes.js\";\n\n/** Options for {@link generateOrm}. */\nexport interface GenerateOrmOptions {\n /** The seed — the same seed yields a byte-identical message. Defaults to `0`. */\n readonly seed?: number;\n}\n\n/**\n * Generate a spec-clean `ORM^O01` {@link Hl7Message} through `@cosyte/hl7`. Deterministic in `seed`.\n *\n * Layout: MSH, `PID` (synthetic identity), `ORC` (common order — control `NW`, new order), and a\n * matching `OBR` (order detail). The `ORC` satisfies the parser's `ORM^O01` structure net, so the\n * message re-parses with **zero warnings** (proven by {@link ./round-trip}).\n *\n * @param options - Seed. See {@link GenerateOrmOptions}.\n * @returns A spec-clean `ORM^O01` `Hl7Message`.\n * @example\n * ```ts\n * import { generateOrm } from \"@cosyte/synth/hl7\";\n * const msg = generateOrm({ seed: 12345 });\n * console.log(msg.toString());\n * ```\n */\nexport function generateOrm(options: GenerateOrmOptions = {}): Hl7Message {\n const seed = options.seed ?? 0;\n const rng = createRng(seed);\n\n const { message } = mshScaffold(rng, \"ORM^O01\");\n message.addSegment(\"PID\", pidSegment(patientIdentity(rng)));\n\n const service = rng.pick(EXAMPLE_ORDER_SERVICES);\n const placer = rng.digits(8);\n const filler = rng.digits(8);\n const orderedAt = seededTimestamp(rng);\n\n message.addSegment(\"ORC\", [\n \"NW\", // ORC-1 order control (new order)\n placer, // ORC-2 placer order number\n filler, // ORC-3 filler order number\n \"\", // ORC-4 placer group number\n \"\", // ORC-5 order status\n \"\", // ORC-6\n \"\", // ORC-7 quantity/timing\n \"\", // ORC-8\n orderedAt, // ORC-9 date/time of transaction\n ]);\n\n message.addSegment(\"OBR\", [\n \"1\", // OBR-1 set id\n placer, // OBR-2 placer order number (matches ORC)\n filler, // OBR-3 filler order number (matches ORC)\n componentsField([service.code, service.text, service.system]), // OBR-4 universal service id (CE)\n ]);\n\n return message;\n}\n","/**\n * Spec-clean HL7 v2 `SIU^S12` (notification of new appointment booking) generation, built **through\n * `@cosyte/hl7`'s `buildMessage`**. The parser's structure net requires the schedule\n * activity segment (`SCH`) for `SIU^S12`; this generator emits `SCH` + `PID` + a resource group\n * (`RGS`/`AIL`), so the message round-trips with **zero warnings**. Identity comes from `../safe`.\n *\n * @module\n */\n\nimport type { Hl7Message } from \"@cosyte/hl7\";\n\nimport { createRng } from \"../rng/rng.js\";\n\nimport { componentsField } from \"./field.js\";\nimport { mshScaffold, patientIdentity, pidSegment, seededTimestamp } from \"./common.js\";\n\n/** Options for {@link generateSiu}. */\nexport interface GenerateSiuOptions {\n /** The seed — the same seed yields a byte-identical message. Defaults to `0`. */\n readonly seed?: number;\n}\n\n/**\n * Generate a spec-clean `SIU^S12` {@link Hl7Message} through `@cosyte/hl7`. Deterministic in `seed`.\n *\n * Layout: MSH, `SCH` (schedule activity — the required group), `PID` (synthetic identity), `RGS`\n * (resource group), `AIL` (location resource). The `SCH` satisfies the parser's `SIU^S12` structure\n * net, so the message re-parses with **zero warnings** (proven by {@link ./round-trip}).\n *\n * @param options - Seed. See {@link GenerateSiuOptions}.\n * @returns A spec-clean `SIU^S12` `Hl7Message`.\n * @example\n * ```ts\n * import { generateSiu } from \"@cosyte/synth/hl7\";\n * const msg = generateSiu({ seed: 12345 });\n * console.log(msg.toString());\n * ```\n */\nexport function generateSiu(options: GenerateSiuOptions = {}): Hl7Message {\n const seed = options.seed ?? 0;\n const rng = createRng(seed);\n\n const { message } = mshScaffold(rng, \"SIU^S12\");\n\n const placerAppt = rng.digits(8);\n const fillerAppt = rng.digits(8);\n const startAt = seededTimestamp(rng);\n const durationMinutes = String(rng.int(15, 90));\n\n message.addSegment(\"SCH\", [\n placerAppt, // SCH-1 placer appointment id\n fillerAppt, // SCH-2 filler appointment id\n \"\", // SCH-3 occurrence number\n \"\", // SCH-4 placer group number\n \"\", // SCH-5 schedule id\n \"\", // SCH-6 event reason\n componentsField([\"ROUTINE\", \"Routine appointment\", \"L\"]), // SCH-7 appointment reason (CE)\n \"\", // SCH-8 appointment type\n durationMinutes, // SCH-9 appointment duration\n componentsField([\"min\", \"minutes\", \"UCUM\"]), // SCH-10 appointment duration units (CE)\n componentsField([\"1\", \"\", startAt, \"\", \"\", \"\", durationMinutes]), // SCH-11 appointment timing quantity (TQ)\n ]);\n\n message.addSegment(\"PID\", pidSegment(patientIdentity(rng)));\n\n message.addSegment(\"RGS\", [\n \"1\", // RGS-1 set id\n \"A\", // RGS-2 segment action code (add)\n ]);\n\n message.addSegment(\"AIL\", [\n \"1\", // AIL-1 set id\n \"A\", // AIL-2 segment action code\n componentsField([\"SYNTHCLINIC\", \"Synthetic Clinic\", \"COSYTE-SYNTH\"]), // AIL-3 location resource id\n ]);\n\n return message;\n}\n","/**\n * Spec-clean HL7 v2 `VXU^V04` (unsolicited vaccination record update) generation, built **through\n * `@cosyte/hl7`'s `buildMessage`**. The parser's structure net requires the patient\n * group (`PID`) for `VXU^V04` (per the CDC IG, `RXA` lives in the optional order group); this generator\n * emits `PID` + `ORC` + `RXA` + `RXR`, so the message round-trips with **zero warnings**. Identity comes\n * from `../safe`; the vaccine code comes from the license-clean example pool, never bundled terminology.\n *\n * @module\n */\n\nimport type { Hl7Message } from \"@cosyte/hl7\";\n\nimport { createRng } from \"../rng/rng.js\";\n\nimport { componentsField } from \"./field.js\";\nimport { mshScaffold, patientIdentity, pidSegment, seededTimestamp } from \"./common.js\";\nimport { EXAMPLE_VACCINES } from \"./example-codes.js\";\n\n/** Options for {@link generateVxu}. */\nexport interface GenerateVxuOptions {\n /** The seed — the same seed yields a byte-identical message. Defaults to `0`. */\n readonly seed?: number;\n}\n\n/**\n * Generate a spec-clean `VXU^V04` {@link Hl7Message} through `@cosyte/hl7`. Deterministic in `seed`.\n *\n * Layout: MSH, `PID` (synthetic identity — the required group), `ORC` (common order), `RXA` (vaccine\n * administration, CVX example code), `RXR` (route). The `PID` satisfies the parser's `VXU^V04`\n * structure net, so the message re-parses with **zero warnings** (proven by {@link ./round-trip}).\n *\n * @param options - Seed. See {@link GenerateVxuOptions}.\n * @returns A spec-clean `VXU^V04` `Hl7Message`.\n * @example\n * ```ts\n * import { generateVxu } from \"@cosyte/synth/hl7\";\n * const msg = generateVxu({ seed: 12345 });\n * console.log(msg.toString());\n * ```\n */\nexport function generateVxu(options: GenerateVxuOptions = {}): Hl7Message {\n const seed = options.seed ?? 0;\n const rng = createRng(seed);\n\n const { message } = mshScaffold(rng, \"VXU^V04\");\n message.addSegment(\"PID\", pidSegment(patientIdentity(rng)));\n\n const placer = rng.digits(8);\n const filler = rng.digits(8);\n message.addSegment(\"ORC\", [\n \"RE\", // ORC-1 order control (observation to follow / record)\n placer, // ORC-2 placer order number\n filler, // ORC-3 filler order number\n ]);\n\n const vaccine = rng.pick(EXAMPLE_VACCINES);\n const administeredAt = seededTimestamp(rng);\n const doseAmount = String(rng.int(1, 5) / 10); // 0.1–0.5 mL, structural only\n\n message.addSegment(\"RXA\", [\n \"0\", // RXA-1 give sub-id counter\n \"1\", // RXA-2 administration sub-id counter\n administeredAt, // RXA-3 date/time start of administration\n administeredAt, // RXA-4 date/time end of administration\n componentsField([vaccine.code, vaccine.text, vaccine.system]), // RXA-5 administered code (CE)\n doseAmount, // RXA-6 administered amount\n componentsField([\"mL\", \"milliliters\", \"UCUM\"]), // RXA-7 administered units (CE)\n \"\", // RXA-8\n \"\", // RXA-9 administration notes\n \"\", // RXA-10\n \"\", // RXA-11\n \"\", // RXA-12\n \"\", // RXA-13\n \"\", // RXA-14\n \"\", // RXA-15 substance lot number\n \"\", // RXA-16\n \"\", // RXA-17\n \"\", // RXA-18\n \"\", // RXA-19\n \"CP\", // RXA-20 completion status (complete)\n ]);\n\n message.addSegment(\"RXR\", [\n componentsField([\"IM\", \"Intramuscular\", \"HL70162\"]), // RXR-1 route (CE)\n componentsField([\"LD\", \"Left Deltoid\", \"HL70163\"]), // RXR-2 administration site (CE)\n ]);\n\n return message;\n}\n","/**\n * The **round-trip-through-the-parser harness** — the headline gate for the synthetic-fixture\n * generator. A generated artifact is \"spec-clean\" only if `@cosyte/hl7` — not\n * `@cosyte/synth`'s own opinion — reads it back cleanly. This harness feeds a generated message\n * straight back into the parser and reports what the parser found, so a false \"spec-clean\" claim\n * cannot hide.\n *\n * @module\n */\n\nimport { parseHL7, type Hl7Message } from \"@cosyte/hl7\";\n\n/** The verdict of one round-trip through `@cosyte/hl7`. */\nexport interface RoundTripResult {\n /** The serialized wire text (the parser's own conservative emit). */\n readonly content: string;\n /** The warning codes the parser emitted on re-parse. Empty ⇒ spec-clean. */\n readonly warnings: readonly string[];\n /** Whether re-serializing the re-parsed message is byte-identical to `content`. */\n readonly byteStable: boolean;\n /** `true` iff the artifact is spec-clean: zero warnings **and** byte-stable. */\n readonly specClean: boolean;\n}\n\n/**\n * Round-trip an `@cosyte/hl7` `Hl7Message` through serialize → parse → serialize and report the\n * verdict. A spec-clean artifact re-parses with **zero warnings** and re-serializes byte-identically.\n *\n * @param message - The message to check (typically from `generateAdt`).\n * @returns The {@link RoundTripResult}.\n * @example\n * ```ts\n * import { generateAdt, roundTrip } from \"@cosyte/synth/hl7\";\n * const { specClean, warnings } = roundTrip(generateAdt({ seed: 1 }));\n * // specClean === true, warnings.length === 0\n * ```\n */\nexport function roundTrip(message: Hl7Message): RoundTripResult {\n const content = message.toString();\n const reparsed = parseHL7(content);\n const warnings = reparsed.warnings.map((w) => String(w.code));\n const byteStable = reparsed.toString() === content;\n return {\n content,\n warnings,\n byteStable,\n specClean: warnings.length === 0 && byteStable,\n };\n}\n","/**\n * `defineSynthProfile` — the growth-loop hook for site/vendor fixture recipes. A profile bundles the\n * value pools and the quirk recipe a fixture set should use, authored through the same public API as\n * the built-ins: a validated, frozen `SynthProfile` carrying a name, optional value overrides, and the\n * quirk names a format's quirk corpus should apply.\n *\n * @module\n */\n\n/** The user-authored spec passed to {@link defineSynthProfile}. */\nexport interface SynthProfileSpec {\n /** A stable, human-readable profile name (e.g. `\"acme-hospital\"`). Required, non-empty. */\n readonly name: string;\n /** Optional given-name pool override (clearly-synthetic names only — see the safety invariant). */\n readonly givenNames?: readonly string[];\n /** Optional family-name pool override (clearly-synthetic names only). */\n readonly familyNames?: readonly string[];\n /**\n * The vendor quirk recipe names this profile requests. Validated against the target format's quirk\n * registry when the profile drives a quirk corpus (an unsupported quirk is a fatal\n * `SYNTH_UNSUPPORTED_QUIRK`, never a silent no-op).\n */\n readonly quirks?: readonly string[];\n}\n\n/** A frozen, validated fixture recipe produced by {@link defineSynthProfile}. */\nexport interface SynthProfile {\n /** The profile name. */\n readonly name: string;\n /** The given-name pool this profile draws from (overrides or the built-in default). */\n readonly givenNames?: readonly string[];\n /** The family-name pool this profile draws from. */\n readonly familyNames?: readonly string[];\n /** The requested quirk recipe names. */\n readonly quirks: readonly string[];\n}\n\n/**\n * Define a reusable, frozen synthetic-fixture profile.\n *\n * @param spec - The profile spec; `name` is required and non-empty.\n * @returns A deep-frozen {@link SynthProfile}.\n * @throws TypeError when `name` is missing or blank.\n * @example\n * ```ts\n * import { defineSynthProfile } from \"@cosyte/synth\";\n * const acme = defineSynthProfile({ name: \"acme-hospital\", quirks: [] });\n * ```\n */\nexport function defineSynthProfile(spec: SynthProfileSpec): SynthProfile {\n if (typeof spec.name !== \"string\" || spec.name.trim().length === 0) {\n throw new TypeError(\"defineSynthProfile: `name` is required and must be a non-empty string.\");\n }\n return Object.freeze({\n name: spec.name,\n ...(spec.givenNames ? { givenNames: Object.freeze([...spec.givenNames]) } : {}),\n ...(spec.familyNames ? { familyNames: Object.freeze([...spec.familyNames]) } : {}),\n quirks: Object.freeze([...(spec.quirks ?? [])]),\n });\n}\n","/**\n * Stable diagnostic codes for `@cosyte/synth` and the {@link SynthError} they travel on.\n *\n * Unlike a parser (which recovers from bad *input* into Tier-2 warnings), a **generator** has no input\n * to tolerate — its reflex is *synthetic-by-construction* and *fail-closed on impossibility*. So the\n * codes here are **fatal**: a caller asked for something the library cannot honor spec-clean, and the\n * only safe answer is to throw, never to silently fabricate a value or a byte workaround. Codes are `key ===\n * value` and part of the public contract —\n * renaming one is a breaking change.\n *\n * @module\n */\n\n/**\n * The stable **fatal** code registry. Additions-only thereafter.\n *\n * @example\n * ```ts\n * import { SYNTH_FATAL_CODES, SynthError } from \"@cosyte/synth\";\n * try {\n * // ...generate...\n * } catch (err) {\n * if (err instanceof SynthError && err.code === SYNTH_FATAL_CODES.SYNTH_UNSUPPORTED_FORMAT) {\n * // handle an unsupported format request\n * }\n * }\n * ```\n */\nexport const SYNTH_FATAL_CODES = {\n /**\n * A format was requested that this build cannot generate through a real parser builder/serializer\n * (e.g. ASTM before `@cosyte/astm`'s serializer ships). Fatal — never a hand-written byte fallback.\n */\n SYNTH_UNSUPPORTED_FORMAT: \"SYNTH_UNSUPPORTED_FORMAT\",\n /**\n * A vendor quirk was requested that the target format's profile system does not support. Fatal —\n * never a silent no-op and never a fabricated quirk.\n */\n SYNTH_UNSUPPORTED_QUIRK: \"SYNTH_UNSUPPORTED_QUIRK\",\n} as const;\n\n/**\n * A value from {@link SYNTH_FATAL_CODES} — the type carried by a thrown {@link SynthError}.\n */\nexport type SynthFatalCode = (typeof SYNTH_FATAL_CODES)[keyof typeof SYNTH_FATAL_CODES];\n\n/**\n * The typed error every fatal `@cosyte/synth` condition throws. Carries a stable\n * {@link SynthFatalCode} so callers branch on `err.code` without matching message text.\n *\n * @example\n * ```ts\n * import { SynthError, SYNTH_FATAL_CODES } from \"@cosyte/synth\";\n * throw new SynthError(SYNTH_FATAL_CODES.SYNTH_UNSUPPORTED_FORMAT, \"astm is not yet generable\");\n * ```\n */\nexport class SynthError extends Error {\n /** The stable fatal code. */\n public readonly code: SynthFatalCode;\n\n /**\n * @param code - The stable {@link SynthFatalCode}.\n * @param message - A human-readable detail (never contains PHI — there is none).\n */\n public constructor(code: SynthFatalCode, message: string) {\n super(message);\n this.name = \"SynthError\";\n this.code = code;\n }\n}\n","/**\n * The **quirk core**. Where the spec-clean generators prove\n * *synthetic-by-construction* through each parser's own builder, the quirk layer proves the mirror\n * property: a **deliberately off-spec** fixture round-trips to **exactly the intended parser warning\n * code(s)** — no more, no fewer. The quirk vocabulary **is the parsers' own profile systems**\n * (`hl7.defineProfile`, `ccda.defineCcdaProfile`, `astm.defineAstmProfile`): a quirk exercises exactly\n * the tolerance the corresponding parser profile encodes, so a quirk fixture is never a fiction — it\n * targets a documented, coded leniency (the **intended-warning contract**).\n *\n * This module is the **format-agnostic** part: the descriptor a quirk carries, the artifact a quirk\n * generator returns, the round-trip verdict shape, and the `SYNTH_UNSUPPORTED_QUIRK` fail-closed. Each\n * format's concrete quirk recipes + transforms live behind its own subpath (`@cosyte/synth/hl7`, …).\n *\n * @module\n */\n\nimport type { SynthFormat } from \"./corpus.js\";\nimport { SYNTH_FATAL_CODES, SynthError } from \"./codes.js\";\nimport type { SynthProfile } from \"./profile.js\";\n\n/**\n * How the parser's matching profile treats a quirk once it is active — the three shapes the parsers'\n * profile systems actually exhibit (verified firsthand against each parser):\n *\n * - `\"suppressed\"` — the profile makes the warning **disappear** (HL7 v2: a `defineProfile`\n * `customSegments` claim suppresses `UNKNOWN_SEGMENT` for a declared Z-segment).\n * - `\"rebadged\"` — the profile **downgrades** the warning to the value-free `PROFILE_QUIRK_APPLIED`\n * marker with `expected: true` (C-CDA `defineCcdaProfile` / ASTM `defineAstmProfile`\n * `profileQuirkApplied`).\n * - `\"bare\"` — no shipped profile tolerates it; the quirk targets a real coded leniency a consumer can\n * tolerate via their own `defineProfile`/`defineAstmProfile`, but no built-in re-badges it.\n */\nexport type QuirkProfileDisposition = \"suppressed\" | \"rebadged\" | \"bare\";\n\n/**\n * The stable, value-free re-badge code the C-CDA and ASTM parsers emit when a profile tolerates a\n * quirk. HL7 v2 has no equivalent (it suppresses instead — see {@link QuirkProfileDisposition}).\n */\nexport const PROFILE_QUIRK_APPLIED = \"PROFILE_QUIRK_APPLIED\";\n\n/**\n * A public, grounded description of one vendor quirk — the metadata that binds a quirk recipe to a real\n * parser warning code and a **publicly-groundable** deviation (cited-public, never a private\n * vendor corpus).\n */\nexport interface QuirkDescriptor {\n /** The quirk recipe name (e.g. `\"unknown-zsegment\"`). Stable; part of the public contract. */\n readonly name: string;\n /** The format this quirk applies to. */\n readonly format: SynthFormat;\n /**\n * The **exact** parser warning code(s) a bare parse (no profile) surfaces for this quirk — the\n * intended-warning contract. A quirk that produces any other code, or none, is a generation bug.\n */\n readonly intendedWarnings: readonly string[];\n /**\n * The **public** grounding for this quirk — the spec clause or the parser's public profile that\n * documents the tolerance. Never a private vendor-attributed corpus.\n */\n readonly grounding: string;\n /** The parser profile that tolerates this quirk (when a built-in public one exists). */\n readonly toleratingProfile?: string;\n /** How {@link toleratingProfile} treats the quirk. */\n readonly disposition: QuirkProfileDisposition;\n}\n\n/** One generated quirk artifact — the off-spec wire text plus the contract it is meant to satisfy. */\nexport interface QuirkArtifact {\n /** The format this artifact belongs to. */\n readonly format: SynthFormat;\n /** The quirk recipe applied. */\n readonly quirk: string;\n /** The underlying spec-clean message kind the quirk was injected into (e.g. `\"ORU^R01\"`). */\n readonly kind: string;\n /** The **quirked** wire text (deterministic in the seed + quirk). */\n readonly content: string;\n /** The exact parser warning code(s) this artifact is meant to round-trip to. */\n readonly intendedWarnings: readonly string[];\n}\n\n/** The verdict of a bare parse under the tolerating profile, if any. */\nexport interface QuirkProfiledVerdict {\n /** The profile applied. */\n readonly profileName: string;\n /** How the profile treats the quirk. */\n readonly disposition: QuirkProfileDisposition;\n /** The warning codes the parser emitted with the profile active. */\n readonly warnings: readonly string[];\n /**\n * `true` iff the profile handled the quirk as its disposition declares: `\"suppressed\"` ⇒ the intended\n * code is gone; `\"rebadged\"` ⇒ the intended code is gone and `PROFILE_QUIRK_APPLIED` is present.\n */\n readonly tolerated: boolean;\n}\n\n/** The verdict of round-tripping a quirk artifact through its parser. */\nexport interface QuirkRoundTripResult {\n /** The quirked wire text that was parsed. */\n readonly content: string;\n /** The warning codes a **bare** parse (no profile) emitted. */\n readonly warnings: readonly string[];\n /** The exact code(s) the quirk is meant to produce. */\n readonly intendedWarnings: readonly string[];\n /**\n * `true` iff the bare parse produced **exactly** the intended code(s) — the intended-warning contract.\n */\n readonly intendedWarningHeld: boolean;\n /** The verdict under the tolerating profile, when a built-in public one exists. */\n readonly withProfile?: QuirkProfiledVerdict;\n}\n\n/**\n * Exact multiset (order-independent) equality of two code lists — the intended-warning comparison.\n *\n * @param a - The first code list.\n * @param b - The second code list.\n * @returns `true` iff the two lists contain the same codes with the same multiplicities.\n * @example\n * ```ts\n * import { sameCodeSet } from \"@cosyte/synth\";\n * sameCodeSet([\"A\", \"B\"], [\"B\", \"A\"]); // true\n * ```\n */\nexport function sameCodeSet(a: readonly string[], b: readonly string[]): boolean {\n if (a.length !== b.length) return false;\n const counts = new Map<string, number>();\n for (const c of a) counts.set(c, (counts.get(c) ?? 0) + 1);\n for (const c of b) {\n const n = counts.get(c);\n if (n === undefined) return false;\n if (n === 1) counts.delete(c);\n else counts.set(c, n - 1);\n }\n return counts.size === 0;\n}\n\n/**\n * Resolve a requested quirk name against a format's registry, or **fail closed**. A quirk the format's\n * profile system does not support is a fatal `SYNTH_UNSUPPORTED_QUIRK` — never a silent no-op and never\n * a fabricated quirk with a made-up warning.\n *\n * @param registry - The format's quirk descriptors, keyed by name.\n * @param format - The format being generated (for the error message).\n * @param name - The requested quirk name.\n * @returns The matching {@link QuirkDescriptor}.\n * @throws SynthError with code `SYNTH_UNSUPPORTED_QUIRK` when `name` is not a supported quirk.\n * @example\n * ```ts\n * import { resolveQuirk } from \"@cosyte/synth\";\n * import { HL7_QUIRKS } from \"@cosyte/synth/hl7\";\n * resolveQuirk(HL7_QUIRKS, \"hl7v2\", \"unknown-zsegment\").intendedWarnings; // [\"UNKNOWN_SEGMENT\"]\n * ```\n */\nexport function resolveQuirk(\n registry: Readonly<Record<string, QuirkDescriptor>>,\n format: SynthFormat,\n name: string,\n): QuirkDescriptor {\n const descriptor = registry[name];\n if (descriptor === undefined) {\n const supported = Object.keys(registry).sort().join(\", \");\n throw new SynthError(\n SYNTH_FATAL_CODES.SYNTH_UNSUPPORTED_QUIRK,\n `${format}: unsupported quirk \"${name}\". The ${format} profile system supports: ${supported}.`,\n );\n }\n return descriptor;\n}\n\n/**\n * Evaluate whether a profiled parse tolerated a quirk as its disposition declares. Shared across the\n * formats so the \"suppressed vs re-badged\" logic lives in exactly one place.\n *\n * @param disposition - The quirk's declared profile disposition.\n * @param intendedWarnings - The bare-parse intended code(s).\n * @param warningsUnderProfile - The code(s) the parser emitted with the profile active.\n * @returns `true` iff the profile handled the quirk correctly for its disposition.\n * @example\n * ```ts\n * import { profileTolerated } from \"@cosyte/synth\";\n * profileTolerated(\"suppressed\", [\"UNKNOWN_SEGMENT\"], []); // true — the profile suppressed it\n * ```\n */\nexport function profileTolerated(\n disposition: QuirkProfileDisposition,\n intendedWarnings: readonly string[],\n warningsUnderProfile: readonly string[],\n): boolean {\n const stillHasIntended = intendedWarnings.some((c) => warningsUnderProfile.includes(c));\n switch (disposition) {\n case \"suppressed\":\n return !stillHasIntended;\n case \"rebadged\":\n return !stillHasIntended && warningsUnderProfile.includes(PROFILE_QUIRK_APPLIED);\n case \"bare\":\n return false;\n }\n}\n\n/**\n * Assert a freshly-generated quirk artifact **actually** round-trips to its intended warning(s), or\n * **fail closed**. This is the generator's self-check on the intended-warning contract: a\n * fixture whose bare parse does not produce exactly the declared code(s) is a *mislabeled* fixture — a\n * golden file that lies about the parser verdict it anchors — and must never be emitted. It is a\n * stronger guard than \"the transform changed some bytes\": a transform can mutate the wrong element (a\n * template a given document type does not key its warning on) and still change bytes while producing no\n * warning. Every format's `generate*Quirk` calls this after transforming, so the contract is enforced at\n * generation time, not merely at round-trip time.\n *\n * @param quirk - The quirk name (for the error message).\n * @param intendedWarnings - The declared intended code(s).\n * @param bareWarnings - The code(s) a bare parse of the generated artifact actually produced.\n * @throws Error when the bare parse did not produce exactly the intended code(s).\n * @example\n * ```ts\n * import { assertIntendedWarnings } from \"@cosyte/synth\";\n * assertIntendedWarnings(\"unknown-zsegment\", [\"UNKNOWN_SEGMENT\"], [\"UNKNOWN_SEGMENT\"]); // ok\n * ```\n */\nexport function assertIntendedWarnings(\n quirk: string,\n intendedWarnings: readonly string[],\n bareWarnings: readonly string[],\n): void {\n if (!sameCodeSet(bareWarnings, intendedWarnings)) {\n throw new Error(\n `quirk \"${quirk}\": the intended-warning contract does not hold — expected exactly ` +\n `[${intendedWarnings.join(\", \")}] but a bare parse produced [${bareWarnings.join(\", \")}]. ` +\n `Refusing to emit a mislabeled fixture.`,\n );\n }\n}\n\n/**\n * Validate the quirk names carried by a {@link SynthProfile} against a format's registry, failing closed\n * on the first unsupported one. Lets a consumer author a fixture recipe with `defineSynthProfile` and\n * have its quirks checked against the *parser's* real tolerance before any fixture is generated.\n *\n * @param profile - The synth profile whose `quirks` to validate.\n * @param registry - The format's quirk descriptors.\n * @param format - The format being generated.\n * @returns The validated quirk names (the profile's, in order).\n * @throws SynthError `SYNTH_UNSUPPORTED_QUIRK` for the first unsupported quirk.\n * @example\n * ```ts\n * import { validateProfileQuirks, defineSynthProfile } from \"@cosyte/synth\";\n * import { HL7_QUIRKS } from \"@cosyte/synth/hl7\";\n * const p = defineSynthProfile({ name: \"site\", quirks: [\"unknown-zsegment\"] });\n * validateProfileQuirks(p, HL7_QUIRKS, \"hl7v2\"); // [\"unknown-zsegment\"]\n * ```\n */\nexport function validateProfileQuirks(\n profile: SynthProfile,\n registry: Readonly<Record<string, QuirkDescriptor>>,\n format: SynthFormat,\n): readonly string[] {\n for (const name of profile.quirks) resolveQuirk(registry, format, name);\n return profile.quirks;\n}\n","/**\n * HL7 v2 **vendor-quirk generation**. A quirk deviates the\n * *structure* of an otherwise spec-clean message so it round-trips through `@cosyte/hl7` to **exactly**\n * one intended, stable warning code — the tolerance a `defineProfile` profile encodes. The deviation is\n * applied **post-serialize**.\n *\n * Two publicly-groundable quirks ship (cited-public, never a private vendor corpus):\n *\n * - **`unknown-zsegment`** → `UNKNOWN_SEGMENT`. HL7 v2.x §2.5 permits site-defined `Z`-segments; a\n * receiver with no profile flags them. `@cosyte/hl7`'s public imaging/PACS profiles (`visage`,\n * `philips`, `va` — each grounded in a downloadable vendor/federal interface spec) declare `ZDS`, so a\n * `defineProfile` that claims the segment **suppresses** the warning.\n * - **`unknown-escape`** → `UNKNOWN_ESCAPE_SEQUENCE`. HL7 v2.x §2.7 escaping — a locally-defined\n * `\\Z..\\` escape is preserved verbatim and flagged. HL7 v2 has no re-badge mechanism, so this is a\n * `\"bare\"` quirk (no built-in profile downgrades it).\n *\n * A quirk **never** introduces a real-looking value — it changes the message *shape*, never the\n * *provenance* of the data, so the synthetic-safety gate still runs and stays zero.\n *\n * @module\n */\n\nimport { parseHL7, profiles as hl7Profiles, type Hl7Message, type Profile } from \"@cosyte/hl7\";\n\nimport { createRng } from \"../rng/rng.js\";\nimport { makeCorpus, type Corpus } from \"../corpus.js\";\nimport { defineSynthProfile, type SynthProfile } from \"../profile.js\";\nimport {\n resolveQuirk,\n sameCodeSet,\n profileTolerated,\n validateProfileQuirks,\n assertIntendedWarnings,\n type QuirkDescriptor,\n type QuirkArtifact,\n type QuirkRoundTripResult,\n} from \"../quirk.js\";\n\nimport { generateAdt } from \"./adt.js\";\nimport { generateOru } from \"./oru.js\";\nimport { generateOrm } from \"./orm.js\";\nimport { generateSiu } from \"./siu.js\";\nimport { generateVxu } from \"./vxu.js\";\n\n/** Every HL7 v2 quirk this package ships. */\nexport type Hl7QuirkName = \"unknown-zsegment\" | \"unknown-escape\";\n\n/** The HL7 v2 message families a quirk can be injected into (the spec-clean base). */\nexport type Hl7QuirkKind =\n | \"ADT^A01\"\n | \"ADT^A04\"\n | \"ADT^A08\"\n | \"ORU^R01\"\n | \"ORM^O01\"\n | \"SIU^S12\"\n | \"VXU^V04\";\n\n/**\n * The HL7 v2 quirk registry — each recipe bound to the exact `@cosyte/hl7` warning code it targets and\n * its public grounding.\n */\nexport const HL7_QUIRKS: Readonly<Record<Hl7QuirkName, QuirkDescriptor>> = Object.freeze({\n \"unknown-zsegment\": Object.freeze({\n name: \"unknown-zsegment\",\n format: \"hl7v2\",\n intendedWarnings: Object.freeze([\"UNKNOWN_SEGMENT\"]),\n grounding:\n \"HL7 v2.x §2.5 site-defined Z-segments; grounded on @cosyte/hl7's public imaging/PACS profiles \" +\n \"(Visage 7 / Philips Vue PACS / VA Radiology interface specs) which declare the ZDS segment.\",\n toleratingProfile: \"visage\",\n disposition: \"suppressed\",\n }),\n \"unknown-escape\": Object.freeze({\n name: \"unknown-escape\",\n format: \"hl7v2\",\n intendedWarnings: Object.freeze([\"UNKNOWN_ESCAPE_SEQUENCE\"]),\n grounding:\n \"HL7 v2.x §2.7 escaping — a locally-defined \\\\Z..\\\\ escape is preserved verbatim and flagged. \" +\n \"HL7 v2 has no profile re-badge, so no built-in profile downgrades it.\",\n disposition: \"bare\",\n }),\n});\n\n/** The tolerating HL7 profile object for a quirk (only the `unknown-zsegment` quirk has one). */\nfunction toleratingProfile(quirk: Hl7QuirkName): Profile | undefined {\n return quirk === \"unknown-zsegment\" ? hl7Profiles.visage : undefined;\n}\n\n/** Split a serialized HL7 message into non-empty segment lines (tolerating any newline convention). */\nfunction segmentsOf(wire: string): string[] {\n return wire.split(/\\r\\n|\\r|\\n/).filter((s) => s.length > 0);\n}\n\n/** The post-serialize transform for each quirk — a pure, deterministic function of the spec-clean wire. */\nfunction applyQuirk(quirk: Hl7QuirkName, wire: string): string {\n const segments = segmentsOf(wire);\n switch (quirk) {\n case \"unknown-zsegment\":\n // A site-defined Z-segment carrying only clearly-synthetic, structural tokens (no PHI locus).\n return [...segments, \"ZDS|1|SYNTHETIC-Z-SEGMENT^COSYTE-SYNTH\"].join(\"\\r\");\n case \"unknown-escape\":\n // An NTE comment whose body carries a locally-defined \\Zff\\ escape — preserved verbatim on parse.\n return [...segments, \"NTE|1||\\\\Zff\\\\\"].join(\"\\r\");\n }\n}\n\n/** Options for {@link generateHl7Quirk}. */\nexport interface GenerateHl7QuirkOptions {\n /** The seed — the same seed + quirk yields a byte-identical message. Defaults to `0`. */\n readonly seed?: number;\n /** The quirk to inject. Required. */\n readonly quirk: Hl7QuirkName;\n /** The spec-clean base message family. Defaults to `\"ORU^R01\"`. */\n readonly kind?: Hl7QuirkKind;\n}\n\n/** Generate the spec-clean base message for a quirk kind. */\nfunction baseMessage(kind: Hl7QuirkKind, seed: number): Hl7Message {\n switch (kind) {\n case \"ADT^A01\":\n return generateAdt({ seed, trigger: \"A01\" });\n case \"ADT^A04\":\n return generateAdt({ seed, trigger: \"A04\" });\n case \"ADT^A08\":\n return generateAdt({ seed, trigger: \"A08\" });\n case \"ORU^R01\":\n return generateOru({ seed });\n case \"ORM^O01\":\n return generateOrm({ seed });\n case \"SIU^S12\":\n return generateSiu({ seed });\n case \"VXU^V04\":\n return generateVxu({ seed });\n }\n}\n\n/**\n * Generate one HL7 v2 **quirk** artifact: a spec-clean message (built through `@cosyte/hl7`) with the\n * requested vendor deviation injected post-serialize. Deterministic in `seed` + `quirk` + `kind`.\n *\n * @param options - Seed, quirk, and base kind. See {@link GenerateHl7QuirkOptions}.\n * @returns The {@link QuirkArtifact} — its `content` round-trips to `intendedWarnings` exactly.\n * @throws SynthError `SYNTH_UNSUPPORTED_QUIRK` if `quirk` is not a supported HL7 quirk.\n * @example\n * ```ts\n * import { generateHl7Quirk, hl7QuirkRoundTrip } from \"@cosyte/synth/hl7\";\n * const artifact = generateHl7Quirk({ seed: 1, quirk: \"unknown-zsegment\" });\n * hl7QuirkRoundTrip(artifact).intendedWarningHeld; // true — exactly UNKNOWN_SEGMENT\n * ```\n */\nexport function generateHl7Quirk(options: GenerateHl7QuirkOptions): QuirkArtifact {\n const seed = options.seed ?? 0;\n const kind = options.kind ?? \"ORU^R01\";\n const descriptor = resolveQuirk(HL7_QUIRKS, \"hl7v2\", options.quirk);\n const content = applyQuirk(options.quirk, baseMessage(kind, seed).toString());\n // Self-check the intended-warning contract at generation time — never emit a mislabeled fixture.\n assertIntendedWarnings(\n descriptor.name,\n descriptor.intendedWarnings,\n parseHL7(content).warnings.map((w) => String(w.code)),\n );\n return Object.freeze({\n format: \"hl7v2\" as const,\n quirk: descriptor.name,\n kind,\n content,\n intendedWarnings: descriptor.intendedWarnings,\n });\n}\n\n/**\n * Round-trip an HL7 v2 quirk artifact through `@cosyte/hl7` and report the intended-warning verdict: a bare\n * parse must produce **exactly** the intended code(s), and — when a built-in public\n * profile tolerates the quirk — the profiled parse must suppress it.\n *\n * @param artifact - The quirk artifact (from {@link generateHl7Quirk}).\n * @returns The {@link QuirkRoundTripResult}.\n * @example\n * ```ts\n * import { generateHl7Quirk, hl7QuirkRoundTrip } from \"@cosyte/synth/hl7\";\n * const rt = hl7QuirkRoundTrip(generateHl7Quirk({ seed: 1, quirk: \"unknown-zsegment\" }));\n * rt.withProfile?.tolerated; // true — the `visage` profile suppresses UNKNOWN_SEGMENT\n * ```\n */\nexport function hl7QuirkRoundTrip(artifact: QuirkArtifact): QuirkRoundTripResult {\n const quirk = artifact.quirk as Hl7QuirkName;\n const descriptor = resolveQuirk(HL7_QUIRKS, \"hl7v2\", quirk);\n const bare = parseHL7(artifact.content).warnings.map((w) => String(w.code));\n const profile = toleratingProfile(quirk);\n const withProfile =\n profile !== undefined && descriptor.toleratingProfile !== undefined\n ? {\n profileName: descriptor.toleratingProfile,\n disposition: descriptor.disposition,\n warnings: parseHL7(artifact.content, profile).warnings.map((w) => String(w.code)),\n tolerated: false,\n }\n : undefined;\n return {\n content: artifact.content,\n warnings: bare,\n intendedWarnings: artifact.intendedWarnings,\n intendedWarningHeld: sameCodeSet(bare, artifact.intendedWarnings),\n ...(withProfile\n ? {\n withProfile: {\n ...withProfile,\n tolerated: profileTolerated(\n descriptor.disposition,\n artifact.intendedWarnings,\n withProfile.warnings,\n ),\n },\n }\n : {}),\n };\n}\n\n/** Options for {@link hl7QuirkCorpus}. */\nexport interface Hl7QuirkCorpusOptions {\n /** The seed for the whole corpus (deterministic). */\n readonly seed: number;\n /** How many quirk artifacts to generate. Defaults to the number of quirks. */\n readonly count?: number;\n /** The quirk names to cycle through. Defaults to every HL7 quirk. Validated; unsupported ⇒ fatal. */\n readonly quirks?: readonly Hl7QuirkName[];\n /** A {@link SynthProfile} whose `quirks` drive the corpus (validated). Takes precedence over `quirks`. */\n readonly profile?: SynthProfile;\n /** The base message family each quirk is injected into. Defaults to `\"ORU^R01\"`. */\n readonly kind?: Hl7QuirkKind;\n}\n\nconst ALL_HL7_QUIRKS: readonly Hl7QuirkName[] = Object.freeze(\n Object.keys(HL7_QUIRKS) as Hl7QuirkName[],\n);\n\n/**\n * Build a reproducible {@link Corpus} of HL7 v2 quirk artifacts. Each artifact's `warnings` record the\n * parser's verdict — the intended code(s) for its quirk (not empty: a quirk corpus is deliberately\n * off-spec) — and the manifest lists the applied quirk names.\n *\n * @param options - Seed, count, and the quirk selection. See {@link Hl7QuirkCorpusOptions}.\n * @returns A deep-frozen {@link Corpus}.\n * @example\n * ```ts\n * import { hl7QuirkCorpus } from \"@cosyte/synth/hl7\";\n * const corpus = hl7QuirkCorpus({ seed: 42 });\n * corpus.manifest.quirks; // [\"unknown-zsegment\", \"unknown-escape\"]\n * ```\n */\nexport function hl7QuirkCorpus(options: Hl7QuirkCorpusOptions): Corpus {\n const quirks: readonly string[] = options.profile\n ? validateProfileQuirks(options.profile, HL7_QUIRKS, \"hl7v2\")\n : (options.quirks ?? ALL_HL7_QUIRKS);\n const names = quirks.length > 0 ? quirks : ALL_HL7_QUIRKS;\n const kind = options.kind ?? \"ORU^R01\";\n const count = options.count ?? names.length;\n const seedStream = createRng(options.seed);\n const artifacts = Array.from({ length: count }, (_unused, i) => {\n const quirk = names[i % names.length] as Hl7QuirkName;\n const artifactSeed = seedStream.nextUint32();\n const artifact = generateHl7Quirk({ seed: artifactSeed, quirk, kind });\n return {\n format: \"hl7v2\" as const,\n kind: `${kind}~${quirk}`,\n content: artifact.content,\n warnings: artifact.intendedWarnings,\n };\n });\n return makeCorpus(options.seed, artifacts, [...new Set(names)]);\n}\n\n/**\n * A ready-made {@link SynthProfile} that requests every built-in HL7 quirk — a convenience for wiring\n * `defineSynthProfile`'s quirk list to the parser's real tolerance.\n *\n * @example\n * ```ts\n * import { hl7QuirkProfile, hl7QuirkCorpus } from \"@cosyte/synth/hl7\";\n * hl7QuirkCorpus({ seed: 1, profile: hl7QuirkProfile });\n * ```\n */\nexport const hl7QuirkProfile: SynthProfile = defineSynthProfile({\n name: \"cosyte-hl7-quirks\",\n quirks: [...ALL_HL7_QUIRKS],\n});\n","/**\n * `@cosyte/synth/hl7` — the HL7 v2 generation surface, exposed as its own subpath so importing the\n * package root does **not** pull `@cosyte/hl7`. This is the **lazy, per-format** boundary: a consumer\n * who only needs HL7 fixtures imports `@cosyte/synth/hl7`; one who needs only the core primitives\n * never loads a parser.\n * `@cosyte/hl7` is an **optional peer dependency** — present only for this subpath.\n *\n * The HL7 v2 message set is complete: `ADT` (A01/A04/A08), `ORU^R01`, `ORM^O01`, `SIU^S12`, and\n * `VXU^V04` — each built through `@cosyte/hl7`'s `buildMessage` and round-tripping with zero warnings.\n *\n * @module\n */\n\nimport type { Hl7Message } from \"@cosyte/hl7\";\n\nimport { createRng } from \"../rng/rng.js\";\nimport { makeCorpus, type Corpus } from \"../corpus.js\";\n\nimport { generateAdt, type AdtTrigger } from \"./adt.js\";\nimport { generateOru } from \"./oru.js\";\nimport { generateOrm } from \"./orm.js\";\nimport { generateSiu } from \"./siu.js\";\nimport { generateVxu } from \"./vxu.js\";\nimport { roundTrip } from \"./round-trip.js\";\n\nexport { generateAdt, type AdtTrigger, type GenerateAdtOptions } from \"./adt.js\";\nexport { generateOru, type GenerateOruOptions } from \"./oru.js\";\nexport { generateOrm, type GenerateOrmOptions } from \"./orm.js\";\nexport { generateSiu, type GenerateSiuOptions } from \"./siu.js\";\nexport { generateVxu, type GenerateVxuOptions } from \"./vxu.js\";\nexport { roundTrip, type RoundTripResult } from \"./round-trip.js\";\nexport { componentsField } from \"./field.js\";\nexport {\n seededTimestamp,\n mshScaffold,\n patientIdentity,\n pidSegment,\n type MessageScaffold,\n type PatientIdentity,\n} from \"./common.js\";\nexport {\n type ExampleCode,\n EXAMPLE_LAB_OBSERVATIONS,\n EXAMPLE_ORDER_SERVICES,\n EXAMPLE_VACCINES,\n} from \"./example-codes.js\";\nexport {\n generateHl7Quirk,\n hl7QuirkRoundTrip,\n hl7QuirkCorpus,\n hl7QuirkProfile,\n HL7_QUIRKS,\n type Hl7QuirkName,\n type Hl7QuirkKind,\n type GenerateHl7QuirkOptions,\n type Hl7QuirkCorpusOptions,\n} from \"./quirk.js\";\n\n/**\n * Every HL7 v2 message kind this subpath generates — the `MSH-9` label used as the corpus `kind`. `ADT`\n * carries its trigger; the other families have a single generated trigger each.\n */\nexport type Hl7MessageKind =\n | \"ADT^A01\"\n | \"ADT^A04\"\n | \"ADT^A08\"\n | \"ORU^R01\"\n | \"ORM^O01\"\n | \"SIU^S12\"\n | \"VXU^V04\";\n\n/** The default message mix for {@link hl7Corpus} — one of every family. */\nconst DEFAULT_MIX: readonly Hl7MessageKind[] = Object.freeze([\n \"ADT^A01\",\n \"ADT^A04\",\n \"ADT^A08\",\n \"ORU^R01\",\n \"ORM^O01\",\n \"SIU^S12\",\n \"VXU^V04\",\n]);\n\n/**\n * Generate one message of the given {@link Hl7MessageKind} from a seed, dispatching to the right\n * family generator. Every kind builds through `@cosyte/hl7` and is deterministic in `seed`.\n *\n * @param kind - The message kind to generate.\n * @param seed - The seed.\n * @returns The generated `Hl7Message`.\n * @example\n * ```ts\n * import { generateHl7 } from \"@cosyte/synth/hl7\";\n * generateHl7(\"ORU^R01\", 42).toString();\n * ```\n */\nexport function generateHl7(kind: Hl7MessageKind, seed: number): Hl7Message {\n switch (kind) {\n case \"ADT^A01\":\n return generateAdt({ seed, trigger: \"A01\" });\n case \"ADT^A04\":\n return generateAdt({ seed, trigger: \"A04\" });\n case \"ADT^A08\":\n return generateAdt({ seed, trigger: \"A08\" });\n case \"ORU^R01\":\n return generateOru({ seed });\n case \"ORM^O01\":\n return generateOrm({ seed });\n case \"SIU^S12\":\n return generateSiu({ seed });\n case \"VXU^V04\":\n return generateVxu({ seed });\n }\n}\n\n/** Options for {@link hl7Corpus}. */\nexport interface Hl7CorpusOptions {\n /** The seed for the whole corpus (deterministic). */\n readonly seed: number;\n /** How many messages to generate. Defaults to `1`. */\n readonly count?: number;\n /**\n * The message kinds to cycle through. Defaults to one of every family\n * (`ADT^A01/A04/A08`, `ORU^R01`, `ORM^O01`, `SIU^S12`, `VXU^V04`).\n */\n readonly mix?: readonly Hl7MessageKind[];\n /**\n * ADT-only convenience: the triggers to cycle through, kept for back-compat. When\n * supplied it takes precedence over `mix` and restricts the corpus to `ADT` messages.\n */\n readonly triggers?: readonly AdtTrigger[];\n}\n\n/**\n * Build a reproducible {@link Corpus} of spec-clean HL7 messages across the families. Each\n * message is generated from a distinct sub-seed derived from the corpus seed (so the set is\n * deterministic) and round-tripped through `@cosyte/hl7`; the per-artifact `warnings` record the\n * parser's verdict (empty ⇒ spec-clean).\n *\n * @param options - Seed, count, and the message mix. See {@link Hl7CorpusOptions}.\n * @returns A deep-frozen {@link Corpus}.\n * @example\n * ```ts\n * import { hl7Corpus } from \"@cosyte/synth/hl7\";\n * const corpus = hl7Corpus({ seed: 42, count: 7 });\n * corpus.artifacts.every((a) => a.warnings.length === 0); // true — spec-clean\n * ```\n */\nexport function hl7Corpus(options: Hl7CorpusOptions): Corpus {\n const { seed, count = 1 } = options;\n const kinds: readonly Hl7MessageKind[] =\n options.triggers !== undefined\n ? options.triggers.map((t): Hl7MessageKind => `ADT^${t}`)\n : (options.mix ?? DEFAULT_MIX);\n // A seed stream derives one deterministic per-message seed from the corpus seed.\n const seedStream = createRng(seed);\n const artifacts = Array.from({ length: count }, (_unused, i) => {\n const kind = kinds[i % kinds.length] ?? \"ADT^A01\";\n const messageSeed = seedStream.nextUint32();\n const rt = roundTrip(generateHl7(kind, messageSeed));\n return {\n format: \"hl7v2\" as const,\n kind,\n content: rt.content,\n warnings: rt.warnings,\n };\n });\n return makeCorpus(seed, artifacts);\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["../../src/rng/splitmix32.ts","../../src/rng/sfc32.ts","../../src/codes.ts","../../src/rng/rng.ts","../../src/corpus.ts","../../src/hl7/field.ts","../../src/safe/reserved.ts","../../src/safe/names-pool.ts","../../src/safe/providers.ts","../../src/safe/index.ts","../../src/hl7/common.ts","../../src/select.ts","../../src/hl7/adt.ts","../../src/hl7/example-codes.ts","../../src/hl7/oru.ts","../../src/hl7/orm.ts","../../src/hl7/siu.ts","../../src/hl7/vxu.ts","../../src/hl7/round-trip.ts","../../src/profile.ts","../../src/quirk.ts","../../src/hl7/quirk.ts","../../src/hl7/index.ts"],"names":["buildMessage","address","phone","parseH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A,KAAa,MAAA,GACjB,QAAQ,QAAA,CAAS,GAAA;AAAA,IACf,CAAC,CAAA,KAAsB,CAAA,IAAA,EAAO,WAAA,CAAYA,aAAAA,EAAc,CAAC,CAAC,CAAA;AAAA,GAC5D,GACA,UAAA,CAAW,SAAA,EAAW,OAAA,CAAQ,KAAK,WAAW,CAAA;AAEpD,EAAA,MAAM,UAAA,GAAa,UAAU,IAAI,CAAA;AACjC,EAAA,MAAM,SAAA,GAAY,MAAM,IAAA,CAAK,EAAE,QAAQ,KAAA,EAAM,EAAG,CAAC,OAAA,EAAS,CAAA,KAAM;AAC9D,IAAA,MAAM,IAAA,GAAO,KAAA,CAAM,CAAA,GAAI,KAAA,CAAM,MAAM,CAAA,IAAK,SAAA;AACxC,IAAA,MAAM,WAAA,GAAc,WAAW,UAAA,EAAW;AAC1C,IAAA,MAAM,EAAA,GAAK,SAAA,CAAU,WAAA,CAAY,IAAA,EAAM,WAAW,CAAC,CAAA;AACnD,IAAA,OAAO;AAAA,MACL,MAAA,EAAQ,OAAA;AAAA,MACR,IAAA;AAAA,MACA,SAAS,EAAA,CAAG,OAAA;AAAA,MACZ,UAAU,EAAA,CAAG;AAAA,KACf;AAAA,EACF,CAAC,CAAA;AACD,EAAA,OAAO,UAAA,CAAW,MAAM,SAAS,CAAA;AACnC","file":"index.cjs","sourcesContent":["/**\n * `splitmix32` — a tiny, well-studied 32-bit mixing PRNG used **only** to expand a single integer\n * seed into the four 32-bit state words that seed {@link ../rng/sfc32.sfc32}. It is not the corpus\n * generator itself (that is `sfc32`); it exists so that a one-number seed deterministically produces a\n * well-distributed 128-bit `sfc32` state, avoiding the poor low-bit behavior of naive\n * `state = seed`-style initialization.\n *\n * Zero-dependency, `Math.random`-free (lint-enforced): the whole point of the library is that a seed —\n * and only the seed — determines the output, on any machine, any run.\n *\n * @module\n */\n\n/**\n * A stateful `splitmix32` step function. Each call advances the internal 32-bit state and returns the\n * next unsigned 32-bit integer. Deterministic for a given seed.\n *\n * @param seed - The 32-bit seed. Coerced to a 32-bit integer via `| 0`.\n * @returns A nullary function returning the next `uint32` in the stream.\n * @example\n * ```ts\n * import { splitmix32 } from \"@cosyte/synth\";\n * const next = splitmix32(12345);\n * const a = next(); // deterministic uint32\n * ```\n */\nexport function splitmix32(seed: number): () => number {\n let a = seed | 0;\n return function next(): number {\n a = (a + 0x9e3779b9) | 0;\n let t = a ^ (a >>> 16);\n t = Math.imul(t, 0x21f0aaad);\n t = t ^ (t >>> 15);\n t = Math.imul(t, 0x735a2d97);\n t = t ^ (t >>> 15);\n return t >>> 0;\n };\n}\n","/**\n * `sfc32` (Small Fast Counter, 32-bit, 128-bit state) — the deterministic, non-cryptographic PRNG that\n * drives every value `@cosyte/synth` generates. Chosen over `mulberry32` (whose author flags that it\n * skips ~1/3 of 32-bit outputs) and over a CSPRNG (`node:crypto`, which is **not seedable** and would\n * defeat reproducibility). A synthetic-fixture generator has **no secrets** — statistical quality plus\n * byte-for-byte reproducibility is exactly the right trade.\n *\n * The state is four 32-bit words. This module exposes the raw step function; {@link ../rng/rng.Rng}\n * wraps it with a seed-expansion ({@link ./splitmix32.splitmix32}) and the ergonomic draw helpers.\n *\n * @module\n */\n\n/**\n * The mutable four-word `sfc32` state. Threaded explicitly (never global) by {@link ../rng/rng.Rng}.\n */\nexport interface Sfc32State {\n /** State word `a`. */\n a: number;\n /** State word `b`. */\n b: number;\n /** State word `c`. */\n c: number;\n /** Counter word `d`. */\n d: number;\n}\n\n/**\n * Advance an {@link Sfc32State} in place by one step and return the next unsigned 32-bit integer.\n *\n * This is the canonical `sfc32` step. The state object is mutated (the counter `d` increments and the\n * mixing words rotate); callers that need reproducible independence hold their own state and never\n * share it — {@link ../rng/rng.Rng} creates a fresh state per seed so two runs from the same seed are\n * identical.\n *\n * @param s - The state to advance. Mutated in place.\n * @returns The next `uint32` in the stream.\n * @example\n * ```ts\n * import { sfc32Next, type Sfc32State } from \"@cosyte/synth\";\n * const s: Sfc32State = { a: 1, b: 2, c: 3, d: 4 };\n * const x = sfc32Next(s); // uint32\n * ```\n */\nexport function sfc32Next(s: Sfc32State): number {\n s.a |= 0;\n s.b |= 0;\n s.c |= 0;\n s.d |= 0;\n const t = (((s.a + s.b) | 0) + s.d) | 0;\n s.d = (s.d + 1) | 0;\n s.a = s.b ^ (s.b >>> 9);\n s.b = (s.c + (s.c << 3)) | 0;\n s.c = (s.c << 21) | (s.c >>> 11);\n s.c = (s.c + t) | 0;\n return t >>> 0;\n}\n","/**\n * Stable diagnostic codes for `@cosyte/synth` and the {@link SynthError} they travel on.\n *\n * Unlike a parser (which recovers from bad *input* into Tier-2 warnings), a **generator** has no input\n * to tolerate — its reflex is *synthetic-by-construction* and *fail-closed on impossibility*. So the\n * codes here are **fatal**: a caller asked for something the library cannot honor spec-clean, and the\n * only safe answer is to throw, never to silently fabricate a value or a byte workaround. Codes are `key ===\n * value` and part of the public contract —\n * renaming one is a breaking change.\n *\n * @module\n */\n\n/**\n * The stable **fatal** code registry. Additions-only thereafter.\n *\n * @example\n * ```ts\n * import { SYNTH_FATAL_CODES, SynthError } from \"@cosyte/synth\";\n * try {\n * // ...generate...\n * } catch (err) {\n * if (err instanceof SynthError && err.code === SYNTH_FATAL_CODES.SYNTH_UNSUPPORTED_FORMAT) {\n * // handle an unsupported format request\n * }\n * }\n * ```\n */\nexport const SYNTH_FATAL_CODES = {\n /**\n * A format was requested that this build cannot generate through a real parser builder/serializer.\n * Fatal — never a hand-written byte fallback.\n *\n * **No code path in this build raises it.** All six formats generate, so it is reserved for a\n * future format that does not, and is kept because removing a published code is a breaking change.\n * An unsupported *kind* within a format that does generate is `SYNTH_UNSUPPORTED_KIND`.\n */\n SYNTH_UNSUPPORTED_FORMAT: \"SYNTH_UNSUPPORTED_FORMAT\",\n /**\n * A vendor quirk was requested that the target format's profile system does not support. Fatal —\n * never a silent no-op and never a fabricated quirk.\n */\n SYNTH_UNSUPPORTED_QUIRK: \"SYNTH_UNSUPPORTED_QUIRK\",\n /**\n * A quirk transform found no structural anchor to mutate, so the fixture would not carry the\n * deviation it is labelled with. Fatal — a golden file that lies about its parser verdict is worse\n * than no golden file.\n */\n SYNTH_QUIRK_ANCHOR_ABSENT: \"SYNTH_QUIRK_ANCHOR_ABSENT\",\n /**\n * A bare parse of a freshly-generated quirk artifact did not produce exactly the declared intended\n * warning code(s). Fatal — never emit a mislabeled fixture.\n */\n SYNTH_INTENDED_WARNING_MISMATCH: \"SYNTH_INTENDED_WARNING_MISMATCH\",\n /** A concept's code-system URI has no OID mapping in the C-CDA example-code table. Fatal. */\n SYNTH_UNMAPPED_CODE_SYSTEM: \"SYNTH_UNMAPPED_CODE_SYSTEM\",\n /** A money value could not be read as an X12 decimal. Fatal — a generator never rounds to a float. */\n SYNTH_INVALID_DECIMAL: \"SYNTH_INVALID_DECIMAL\",\n /** An integer range was requested with its maximum below its minimum. Fatal. */\n SYNTH_INVALID_RANGE: \"SYNTH_INVALID_RANGE\",\n /** A value was drawn from an empty pool. Fatal — never a fabricated substitute. */\n SYNTH_EMPTY_POOL: \"SYNTH_EMPTY_POOL\",\n /** A `defineSynthProfile` spec was not usable (a missing or blank `name`). Fatal. */\n SYNTH_INVALID_PROFILE: \"SYNTH_INVALID_PROFILE\",\n /**\n * A caller-supplied selector (a message kind, a document type, a corpus mix entry, a claim\n * variant, a Bundle type, a resource profile) is not in the closed set that governs it. Fatal —\n * see `resolveKind`: a selector union is erased at run time, and a selector that falls through\n * either mislabels the fixture or hands the value to a peer builder that quotes it back.\n */\n SYNTH_UNSUPPORTED_KIND: \"SYNTH_UNSUPPORTED_KIND\",\n} as const;\n\n/**\n * A value from {@link SYNTH_FATAL_CODES} — the type carried by a thrown {@link SynthError}.\n */\nexport type SynthFatalCode = (typeof SYNTH_FATAL_CODES)[keyof typeof SYNTH_FATAL_CODES];\n\n/**\n * The **frozen message registry** — the only place a {@link SynthError} message can come from.\n *\n * A message here is a fixed string. It never quotes the request that produced it, and there is no\n * parameter through which it could: {@link SynthError} takes a code and nothing else. That is the\n * whole mechanism, and it is deliberately a mechanism rather than a habit. Every one of these\n * messages used to be assembled by interpolating the caller's value into a template, and the reason\n * that was safe was not the design — it was that the caller happened to be passing a quirk name.\n *\n * The trade is real and is accepted: a fatal no longer tells you *which* value it rejected. It tells\n * you which rule refused, on `err.code`, and the stack frame tells you where. The caller already\n * holds the value it passed.\n *\n * @example\n * ```ts\n * import { SYNTH_FATAL_CODES, SYNTH_FATAL_MESSAGES } from \"@cosyte/synth\";\n * SYNTH_FATAL_MESSAGES[SYNTH_FATAL_CODES.SYNTH_EMPTY_POOL]; // => \"A value was drawn from an empty pool.\"\n * ```\n */\nexport const SYNTH_FATAL_MESSAGES: Readonly<Record<SynthFatalCode, string>> = Object.freeze({\n SYNTH_UNSUPPORTED_FORMAT:\n \"The requested format is not generable by this build. A generator has no byte fallback: it \" +\n \"builds through a parser's own serializer or it refuses.\",\n SYNTH_UNSUPPORTED_QUIRK:\n \"The requested vendor quirk is not in the target format's quirk registry. Compare the request \" +\n \"against that format's exported registry (HL7_QUIRKS, CCDA_QUIRKS, ASTM_QUIRKS).\",\n SYNTH_QUIRK_ANCHOR_ABSENT:\n \"The quirk transform found no structural anchor to mutate, so the fixture would not carry the \" +\n \"deviation it is labelled with. Refusing to emit a mislabeled fixture.\",\n SYNTH_INTENDED_WARNING_MISMATCH:\n \"A bare parse of the generated quirk artifact did not produce exactly the declared intended \" +\n \"warning code(s). Refusing to emit a mislabeled fixture.\",\n SYNTH_UNMAPPED_CODE_SYSTEM:\n \"The concept's code-system URI has no OID mapping in the C-CDA example-code table.\",\n SYNTH_INVALID_DECIMAL: \"The value could not be read as an X12 decimal.\",\n SYNTH_INVALID_RANGE: \"An integer range was requested with its maximum below its minimum.\",\n SYNTH_EMPTY_POOL: \"A value was drawn from an empty pool.\",\n SYNTH_INVALID_PROFILE: \"defineSynthProfile requires a non-empty string name.\",\n SYNTH_UNSUPPORTED_KIND:\n \"The requested kind, document type, corpus mix entry, variant or profile is not one this \" +\n \"generator supports. The supported set is the exported union for that option.\",\n});\n\n/**\n * The typed error every fatal `@cosyte/synth` condition throws. Carries a stable\n * {@link SynthFatalCode} so callers branch on `err.code` without matching message text.\n *\n * It takes **no value parameter**. The message is whatever {@link SYNTH_FATAL_MESSAGES} holds for the\n * code, so no caller-supplied string can reach a diagnostic surface by any route — not `message`, not\n * `stack`, not a field on the thrown object.\n *\n * @example\n * ```ts\n * import { SynthError, SYNTH_FATAL_CODES } from \"@cosyte/synth\";\n * throw new SynthError(SYNTH_FATAL_CODES.SYNTH_UNSUPPORTED_FORMAT);\n * ```\n */\nexport class SynthError extends Error {\n /** The stable fatal code. */\n public readonly code: SynthFatalCode;\n\n /**\n * @param code - The stable {@link SynthFatalCode}. The message comes from the frozen registry.\n */\n public constructor(code: SynthFatalCode) {\n super(SYNTH_FATAL_MESSAGES[code]);\n this.name = \"SynthError\";\n this.code = code;\n }\n}\n","/**\n * `Rng` — the seeded, deterministic random source every `@cosyte/synth` provider draws from.\n *\n * **The reproducibility contract.** A seed — and only the seed — determines the output.\n * `createRng(seed)` expands the integer seed through {@link ./splitmix32.splitmix32} into the four\n * `sfc32` state words, then every draw advances that state via {@link ./sfc32.sfc32Next}. Two `Rng`s\n * created from the same seed emit the **identical** sequence on any machine, any run — the property\n * the parsers', `transform`'s, and `deid`'s regression suites depend on.\n *\n * **Explicit, never global.** An `Rng` is a value you thread through a build; there is no ambient\n * shared generator and **`Math.random` is lint-banned** in `src/` (it is not seedable — its seed is\n * engine-chosen and cannot be reset, so a corpus built on it is not reproducible). Because each\n * generation creates a fresh `Rng` from its seed, generations are independent and parallel-safe.\n *\n * The `Rng` object is stateful by nature (a PRNG advances). Immutability in this library lives where it\n * is testable and matters: the generated **artifacts and the `Corpus` are deep-frozen** (see\n * `../corpus.ts`). Determinism, not object-immutability, is the `Rng`'s guarantee.\n *\n * @module\n */\n\nimport { splitmix32 } from \"./splitmix32.js\";\nimport { sfc32Next, type Sfc32State } from \"./sfc32.js\";\nimport { SYNTH_FATAL_CODES, SynthError } from \"../codes.js\";\n\n/**\n * A seeded, deterministic random source. Created via {@link createRng}; passed explicitly to every\n * provider. All draw methods advance the internal state deterministically.\n */\nexport interface Rng {\n /** The integer seed this generator was created from (part of the `Corpus` manifest). */\n readonly seed: number;\n /** The next unsigned 32-bit integer. */\n nextUint32(): number;\n /** The next float in `[0, 1)`. */\n float(): number;\n /**\n * A uniformly-distributed integer in the inclusive range `[min, max]`.\n *\n * @param min - Inclusive lower bound (integer).\n * @param max - Inclusive upper bound (integer, `>= min`).\n */\n int(min: number, max: number): number;\n /** `true` with probability `p` (default `0.5`). */\n bool(p?: number): boolean;\n /**\n * Pick one element from a non-empty array.\n *\n * @param items - A non-empty readonly array.\n */\n pick<T>(items: readonly T[]): T;\n /**\n * A string of `n` decimal digits (`0`–`9`), each drawn uniformly.\n *\n * @param n - The number of digits (`>= 0`).\n */\n digits(n: number): string;\n}\n\n/**\n * The concrete {@link Rng}. Holds the mutable `sfc32` state; every method advances it deterministically.\n */\nclass Sfc32Rng implements Rng {\n public readonly seed: number;\n readonly #state: Sfc32State;\n\n public constructor(seed: number) {\n this.seed = seed | 0;\n // Expand the single seed into four well-distributed state words. Seeding sfc32 directly from the\n // raw seed gives poor low-bit behavior; splitmix32 is the standard fix (bryc / roadmap §5).\n const mix = splitmix32(this.seed);\n this.#state = { a: mix(), b: mix(), c: mix(), d: mix() };\n // A short warm-up so nearby seeds diverge immediately.\n for (let i = 0; i < 8; i += 1) sfc32Next(this.#state);\n }\n\n public nextUint32(): number {\n return sfc32Next(this.#state);\n }\n\n public float(): number {\n return this.nextUint32() / 0x1_0000_0000;\n }\n\n public int(min: number, max: number): number {\n if (max < min) throw new SynthError(SYNTH_FATAL_CODES.SYNTH_INVALID_RANGE);\n const span = max - min + 1;\n return min + Math.floor(this.float() * span);\n }\n\n public bool(p = 0.5): boolean {\n return this.float() < p;\n }\n\n public pick<T>(items: readonly T[]): T {\n if (items.length === 0) throw new SynthError(SYNTH_FATAL_CODES.SYNTH_EMPTY_POOL);\n // `int(0, length-1)` is always in-bounds on a non-empty array, so this access cannot be a hole;\n // the cast discharges `noUncheckedIndexedAccess`'s `T | undefined` without a runtime re-check.\n return items[this.int(0, items.length - 1)] as T;\n }\n\n public digits(n: number): string {\n let out = \"\";\n for (let i = 0; i < n; i += 1) out += String(this.int(0, 9));\n return out;\n }\n}\n\n/**\n * Create a seeded, deterministic {@link Rng}. The same `seed` yields the same sequence everywhere.\n *\n * @param seed - The integer seed. Coerced to a 32-bit integer.\n * @returns A fresh, independent {@link Rng}.\n * @example\n * ```ts\n * import { createRng } from \"@cosyte/synth\";\n * const rng = createRng(12345);\n * rng.int(1, 6); // deterministic for seed 12345\n * ```\n */\nexport function createRng(seed: number): Rng {\n return new Sfc32Rng(seed);\n}\n","/**\n * The `Corpus` abstraction — a seed plus a self-describing manifest of what was generated, so a\n * fixture set is itself reproducible and regenerable. A downstream repo pins a seed\n * and gets a stable fixture set that regenerates identically.\n *\n * Generated artifacts and the `Corpus` are **deep-frozen** — this is where the archetype's immutability\n * invariant lives in a generator: a consumer cannot mutate a shared fixture out from under\n * another test.\n *\n * @module\n */\n\n/** The format an artifact was generated for. */\nexport type SynthFormat = \"hl7v2\" | \"fhir\" | \"ccda\" | \"x12\" | \"ncpdp\" | \"astm\";\n\n/**\n * One generated artifact — the serialized wire text plus the metadata needed to reproduce and check\n * it. `warnings` records what the artifact's own parser reported on the round-trip (zero for a\n * spec-clean artifact).\n */\nexport interface Artifact {\n /** The format this artifact belongs to. */\n readonly format: SynthFormat;\n /** A format-specific kind label (e.g. `\"ADT^A01\"`). */\n readonly kind: string;\n /** The serialized wire text, produced by the parser's own conservative serializer. */\n readonly content: string;\n /** The warning codes the parser emitted when the artifact was round-tripped (empty = spec-clean). */\n readonly warnings: readonly string[];\n}\n\n/** A self-describing manifest of a {@link Corpus}. */\nexport interface CorpusManifest {\n /** The formats present in the corpus. */\n readonly formats: readonly SynthFormat[];\n /** Per-kind artifact counts (e.g. `{ \"ADT^A01\": 3 }`). */\n readonly counts: Readonly<Record<string, number>>;\n /** The quirk names applied. */\n readonly quirks: readonly string[];\n}\n\n/** A reproducible, self-describing set of generated artifacts. */\nexport interface Corpus {\n /** The seed the corpus was generated from — regenerating from it yields byte-identical artifacts. */\n readonly seed: number;\n /** The manifest describing what was generated. */\n readonly manifest: CorpusManifest;\n /** The generated artifacts, in generation order. */\n readonly artifacts: readonly Artifact[];\n}\n\n/**\n * Assemble a deep-frozen {@link Corpus} from a seed and its artifacts, deriving the manifest.\n *\n * @param seed - The seed the artifacts were generated from.\n * @param artifacts - The generated artifacts, in order.\n * @param quirks - The quirk names applied (default none).\n * @returns A deep-frozen, self-describing {@link Corpus}.\n * @example\n * ```ts\n * import { makeCorpus } from \"@cosyte/synth\";\n * const corpus = makeCorpus(1, [{ format: \"hl7v2\", kind: \"ADT^A01\", content, warnings: [] }]);\n * corpus.manifest.counts[\"ADT^A01\"]; // 1\n * ```\n */\nexport function makeCorpus(\n seed: number,\n artifacts: readonly Artifact[],\n quirks: readonly string[] = [],\n): Corpus {\n const counts: Record<string, number> = {};\n const formats = new Set<SynthFormat>();\n const frozenArtifacts = artifacts.map((a) => {\n counts[a.kind] = (counts[a.kind] ?? 0) + 1;\n formats.add(a.format);\n return Object.freeze({ ...a, warnings: Object.freeze([...a.warnings]) });\n });\n const manifest: CorpusManifest = Object.freeze({\n formats: Object.freeze([...formats]),\n counts: Object.freeze(counts),\n quirks: Object.freeze([...quirks]),\n });\n return Object.freeze({\n seed,\n manifest,\n artifacts: Object.freeze(frozenArtifacts),\n });\n}\n","/**\n * Thin helpers that build `@cosyte/hl7` `RawField` objects with **components** for `addSegment`.\n *\n * Why this exists: `Hl7Message.addSegment` accepts a field as either a plain string or a structured\n * `RawField`. A plain string is emitted **verbatim** — a literal `^` in it is escaped to `\\S\\`, not\n * treated as a component separator (the parser re-escapes on serialize, by design). To place true\n * components (a name's family/given, a CX's id/authority/type) we must hand `addSegment` a `RawField`\n * with explicit `components`, so the parser's own conservative serializer lays out the separators.\n * That is the whole point of building *through* the parser.\n *\n * @module\n */\n\nimport type { RawField } from \"@cosyte/hl7\";\n\n/**\n * Build a `RawField` from a flat list of component strings (single repetition, single subcomponent\n * per component). Empty strings become empty components (absent at the wire level).\n *\n * @param components - The component values, in HL7 component order.\n * @returns A `RawField` the hl7 serializer lays out with `^` separators.\n * @example\n * ```ts\n * import { componentsField } from \"@cosyte/synth/hl7\";\n * componentsField([\"Testerson\", \"Quilliam\"]); // family^given\n * ```\n */\nexport function componentsField(components: readonly string[]): RawField {\n return {\n repetitions: [{ components: components.map((c) => ({ subcomponents: [c] })) }],\n isNull: false,\n };\n}\n","/**\n * The reserved / never-collide identifier facts that make a `@cosyte/synth` value **provably\n * synthetic** — the ground truth behind the synthetic-safety invariant.\n *\n * These are **facts**, not copyrighted prose: authoritative ranges published by SSA, NANPA, and the\n * IETF that are guaranteed never to denote a real person or a real routable resource. Every provider\n * draws only from these; the predicates here are the executable half of the CI synthetic-safety gate —\n * they let a test assert that no emitted value falls **outside** a reserved source.\n *\n * Sources:\n * - **SSN** — SSA never issues area numbers `000`, `666`, or `900–999`; the `987-65-4320…4329` block\n * is SSA's explicitly-reserved advertising range. (ssa.gov)\n * - **Phone** — NANP reserves `555-0100…555-0199` as the fictional/non-working line range. (nanpa.com)\n * - **Email/domain** — RFC 2606 / RFC 6761 reserved: `example.com`/`.net`/`.org` and the `.example`,\n * `.test`, `.invalid`, `.localhost` TLDs.\n * - **IP** — RFC 5737 IPv4 TEST-NET-1/2/3 (`192.0.2.0/24`, `198.51.100.0/24`, `203.0.113.0/24`) and\n * RFC 3849 IPv6 documentation prefix `2001:db8::/32`.\n * - **NPI** — a real National Provider Identifier is a 10-digit number whose last digit is a Luhn\n * check digit computed over the `80840` prefix + the 9-digit base (CMS NPI check-digit rule, ISO\n * 7812). A number whose check digit is **wrong** therefore cannot be a NPPES-issued NPI. `synth`\n * emits NPIs with a deliberately-invalid check digit, so no generated NPI can collide with a real\n * provider.\n *\n * @module\n */\n\n/**\n * The synthetic **assigning authority** `@cosyte/synth` mints MRNs / account / member identifiers\n * under. There is **no** reserved MRN range (an MRN is unique only within its assigning-authority /\n * OID namespace), so — a documented design decision — every synthetic identifier\n * is scoped to a namespace that clearly cannot be a real facility's: a `SYNTH`-labelled authority whose\n * OID lives under HL7's designated **example** root `2.16.840.1.113883.19`. A value under this AA can\n * never collide with a real record because the *namespace itself* is synthetic.\n */\nexport const SYNTHETIC_ASSIGNING_AUTHORITY = Object.freeze({\n /** The human-readable assigning-authority namespace id (HL7 HD.1). */\n namespaceId: \"COSYTE-SYNTH\",\n /** The universal id — an OID under HL7's example arc `2.16.840.1.113883.19` (HD.2). */\n universalId: \"2.16.840.1.113883.19.999\",\n /** The universal id type (HD.3). */\n universalIdType: \"ISO\",\n});\n\n/** RFC 2606 / 6761 reserved email domains `@cosyte/synth` draws from. */\nexport const RESERVED_EMAIL_DOMAINS: readonly string[] = Object.freeze([\n \"example.com\",\n \"example.org\",\n \"example.net\",\n]);\n\n/** RFC 5737 IPv4 documentation (TEST-NET) `/24` network prefixes. */\nexport const TEST_NET_V4_PREFIXES: readonly string[] = Object.freeze([\n \"192.0.2\", // TEST-NET-1\n \"198.51.100\", // TEST-NET-2\n \"203.0.113\", // TEST-NET-3\n]);\n\n/** RFC 3849 IPv6 documentation prefix. */\nexport const DOC_V6_PREFIX = \"2001:db8\";\n\n/**\n * The `80840` prefix prepended to a 10-digit NPI before the Luhn check (the CMS NPI check-digit\n * rule — `80840` is the ISO 7812 issuer identifier for the US health-application namespace). A real\n * NPI satisfies `luhn(\"80840\" + npi) ≡ 0 (mod 10)`.\n */\nexport const NPI_LUHN_PREFIX = \"80840\";\n\n/**\n * The Luhn sum (mod 10) of a numeric string, doubling every second digit from the right. Used to\n * verify (or deliberately break) an NPI check digit.\n *\n * @param digits - A string of decimal digits.\n * @returns The Luhn sum modulo 10 (0 ⇒ the string passes the Luhn check).\n * @internal\n */\nexport function luhnMod10(digits: string): number {\n let sum = 0;\n // Standard Luhn: the RIGHTMOST digit is never doubled; doubling starts one position in and\n // alternates. For a full payload+check string this makes a Luhn-valid string sum to 0 (mod 10);\n // for a payload with a `0` placeholder in the check position it yields the complement of the\n // correct check digit.\n let double = false;\n for (let i = digits.length - 1; i >= 0; i -= 1) {\n let d = digits.charCodeAt(i) - 48;\n if (d < 0 || d > 9) continue;\n if (double) {\n d *= 2;\n if (d > 9) d -= 9;\n }\n sum += d;\n double = !double;\n }\n return sum % 10;\n}\n\n/**\n * The correct NPI check digit for a 9-digit base — the value that makes `80840` + base + check pass\n * the Luhn check.\n *\n * @param base9 - The 9-digit NPI base (positions 1–9).\n * @returns The check digit (`0`–`9`) a real NPI would carry for this base.\n * @example\n * ```ts\n * import { npiCheckDigit } from \"@cosyte/synth\";\n * npiCheckDigit(\"123456789\"); // 3 — so 1234567893 is a Luhn-valid NPI shape\n * ```\n */\nexport function npiCheckDigit(base9: string): number {\n // Luhn over \"80840\" + base9 with a trailing 0 check placeholder; the check digit closes the sum.\n const partial = luhnMod10(`${NPI_LUHN_PREFIX}${base9}0`);\n return (10 - partial) % 10;\n}\n\n/**\n * The DEA-registration prefix letters `@cosyte/synth` draws a synthetic DEA number's first character\n * from. A real DEA number is `<registrant-type><last-name-initial>` + 7 digits; the first letter is the\n * registrant type (A/B/F/G/M/P/R/X are the widely-published values; the second letter is the\n * registrant's last-name initial). These letters are a **fact** about the number's shape, not\n * copyrighted prose — they only shape the value; the synthetic guarantee is the deliberately-**invalid\n * checksum** (see {@link dea} / {@link isSyntheticDea}).\n */\nexport const DEA_REGISTRANT_TYPES: readonly string[] = Object.freeze([\n \"A\",\n \"B\",\n \"F\",\n \"G\",\n \"M\",\n \"P\",\n \"R\",\n \"X\",\n]);\n\n/**\n * The correct DEA check digit for a 7-digit numeric base. The published DEA checksum is\n * `(d1 + d3 + d5) + 2·(d2 + d4 + d6)`, whose **units digit** is the 7th (check) digit. A real DEA\n * number satisfies this; a number whose 7th digit differs cannot be a validly-issued DEA registration.\n *\n * @param base6 - The first 6 digits of the DEA number (positions 1–6).\n * @returns The check digit (`0`–`9`) a real DEA number would carry for this base.\n * @example\n * ```ts\n * import { deaCheckDigit } from \"@cosyte/synth\";\n * deaCheckDigit(\"123456\"); // the units digit of (1+3+5) + 2·(2+4+6)\n * ```\n */\nexport function deaCheckDigit(base6: string): number {\n let odd = 0;\n let even = 0;\n for (let i = 0; i < 6; i += 1) {\n const digit = base6.charCodeAt(i) - 48;\n if (i % 2 === 0) odd += digit;\n else even += digit;\n }\n return (odd + 2 * even) % 10;\n}\n\n/**\n * Whether a DEA number (`XX` + 7 digits, case-insensitive) is **provably synthetic** — its check digit\n * (the 7th digit) does **not** match the published DEA checksum, so it cannot be a validly-issued DEA\n * registration. A checksum-valid DEA number (which *could* denote a real prescriber) returns `false`; a\n * value that is not the DEA shape returns `false`.\n *\n * @param value - The candidate DEA number (with or without incidental separators).\n * @returns `true` when the DEA number's checksum is wrong (never a real DEA registration).\n * @example\n * ```ts\n * import { isSyntheticDea } from \"@cosyte/synth\";\n * isSyntheticDea(\"AF1234561\"); // depends on the base — true when the 7th digit is wrong\n * ```\n */\nexport function isSyntheticDea(value: string): boolean {\n const compact = value.replace(/[\\s-]/g, \"\").toUpperCase();\n if (!/^[A-Z]{2}\\d{7}$/.test(compact)) return false;\n const digits = compact.slice(2);\n const check = digits.charCodeAt(6) - 48;\n return deaCheckDigit(digits.slice(0, 6)) !== check;\n}\n\n/**\n * Whether a 10-digit NPI is **provably synthetic** — i.e. its check digit is invalid, so it cannot be\n * a NPPES-issued NPI. A Luhn-valid 10-digit NPI (which *could* denote a real registered provider)\n * returns `false`; a non-10-digit value returns `false` (not an NPI shape).\n *\n * @param value - The candidate NPI (digits only, or with incidental separators).\n * @returns `true` when the NPI's check digit is wrong (never a real NPI).\n * @example\n * ```ts\n * import { isSyntheticNpi } from \"@cosyte/synth\";\n * isSyntheticNpi(\"1234567894\"); // true — invalid check digit (valid would be 1234567893)\n * isSyntheticNpi(\"1234567893\"); // false — Luhn-valid, could be a real NPI\n * ```\n */\nexport function isSyntheticNpi(value: string): boolean {\n const digits = value.replace(/\\D/g, \"\");\n if (digits.length !== 10) return false;\n return luhnMod10(`${NPI_LUHN_PREFIX}${digits}`) !== 0;\n}\n\n/**\n * Whether a `ddd-dd-dddd` (or `ddddddddd`) SSN string is drawn from an SSA never-issued / reserved\n * space — area `000`, `666`, or `900–999`. A real, issuable SSN returns `false`.\n *\n * @param value - The candidate SSN (dashes optional).\n * @returns `true` when the SSN is provably synthetic.\n * @example\n * ```ts\n * import { isSyntheticSsn } from \"@cosyte/synth\";\n * isSyntheticSsn(\"900-12-3456\"); // true (never issued)\n * isSyntheticSsn(\"123456789\"); // false (issuable area 123)\n * ```\n */\nexport function isSyntheticSsn(value: string): boolean {\n const digits = value.replace(/\\D/g, \"\");\n if (digits.length !== 9) return false;\n const area = Number(digits.slice(0, 3));\n return area === 0 || area === 666 || area >= 900;\n}\n\n/**\n * Whether a phone string contains the NANP `555-0100…555-0199` reserved fictional line range.\n *\n * @param value - The candidate phone (any formatting).\n * @returns `true` when the number is in the reserved fictional block.\n * @example\n * ```ts\n * import { isSyntheticPhone } from \"@cosyte/synth\";\n * isSyntheticPhone(\"(202) 555-0142\"); // true\n * ```\n */\nexport function isSyntheticPhone(value: string): boolean {\n const digits = value.replace(/\\D/g, \"\");\n // The reserved guarantee is the 7-digit tail: exchange 555 + line 01NN.\n const tail = digits.slice(-7);\n return /^555 ?01\\d\\d$/.test(tail) || /^55501\\d\\d$/.test(tail);\n}\n\n/**\n * Whether an email's domain is an RFC 2606 / 6761 reserved / test domain.\n *\n * @param value - The candidate email address.\n * @returns `true` when the domain is reserved (never real).\n * @example\n * ```ts\n * import { isSyntheticEmail } from \"@cosyte/synth\";\n * isSyntheticEmail(\"faux.testerson@example.com\"); // true\n * ```\n */\nexport function isSyntheticEmail(value: string): boolean {\n const at = value.lastIndexOf(\"@\");\n if (at < 0) return false;\n const domain = value.slice(at + 1).toLowerCase();\n if (RESERVED_EMAIL_DOMAINS.includes(domain)) return true;\n return /\\.(example|test|invalid|localhost)$/.test(domain);\n}\n\n/**\n * Whether an IP string is in an RFC 5737 (IPv4 TEST-NET) or RFC 3849 (IPv6 documentation) reserved\n * block. A real routable address returns `false`.\n *\n * @param value - The candidate IPv4 or IPv6 address.\n * @returns `true` when the address is a reserved documentation address.\n * @example\n * ```ts\n * import { isSyntheticIp } from \"@cosyte/synth\";\n * isSyntheticIp(\"192.0.2.44\"); // true (TEST-NET-1)\n * isSyntheticIp(\"8.8.8.8\"); // false (real)\n * ```\n */\nexport function isSyntheticIp(value: string): boolean {\n if (value.toLowerCase().startsWith(`${DOC_V6_PREFIX}:`)) return true;\n return TEST_NET_V4_PREFIXES.some((prefix) => value.startsWith(`${prefix}.`));\n}\n","/**\n * The shipped **clearly-fake name pool** — `@cosyte/synth`'s own license-clean synthetic data.\n *\n * Deliberately **not** a `faker`-style realistic-name corpus (which could match a real person at a real\n * address — the exact hazard the synthetic-safety invariant forbids). Every token is\n * an obviously-invented, fixture-flavoured word: a reader can tell at a glance it names no one. The pool\n * is small on purpose — structural coverage, not demographic realism, is the goal.\n *\n * `# synthetic: true`\n *\n * @module\n */\n\n/** Obviously-synthetic given names. None is a plausible real person's name. */\nexport const SYNTHETIC_GIVEN_NAMES: readonly string[] = Object.freeze([\n \"Testina\",\n \"Fixtura\",\n \"Synthos\",\n \"Placeholda\",\n \"Sampleton\",\n \"Prototius\",\n \"Stubbina\",\n \"Exampla\",\n \"Quilliam\",\n \"Fabrica\",\n \"Simula\",\n \"Testry\",\n \"Seedwin\",\n \"Corpora\",\n \"Reprodo\",\n \"Mocktavia\",\n \"Dummett\",\n \"Voidwin\",\n \"Deteria\",\n \"Randomir\",\n]);\n\n/** Obviously-synthetic family names. None is a plausible real surname at a real address. */\nexport const SYNTHETIC_FAMILY_NAMES: readonly string[] = Object.freeze([\n \"Testerson\",\n \"Fauxman\",\n \"Placeholt\",\n \"Mockridge\",\n \"Fixtingham\",\n \"Synthwell\",\n \"Dummerton\",\n \"Examplewood\",\n \"Fabricant\",\n \"Simulacre\",\n \"Nonesuch\",\n \"Seedman\",\n \"Corpusworth\",\n \"Reprodus\",\n \"Voidmark\",\n \"Deterwood\",\n \"Randomson\",\n \"Quillfeather\",\n \"Notreal\",\n \"Genfield\",\n]);\n\n/** Obviously-synthetic street names for structured address fields. */\nexport const SYNTHETIC_STREET_NAMES: readonly string[] = Object.freeze([\n \"Fixture Lane\",\n \"Sample Street\",\n \"Placeholder Avenue\",\n \"Synthetic Way\",\n \"Example Boulevard\",\n \"Testing Terrace\",\n \"Mock Road\",\n \"Prototype Court\",\n]);\n\n/**\n * Obviously-synthetic city names. Combined only ever with a synthetic street + a fake name (the\n * *combination* is what identifies, and the combination is always synthetic).\n */\nexport const SYNTHETIC_CITY_NAMES: readonly string[] = Object.freeze([\n \"Faketon\",\n \"Synthville\",\n \"Exampleburg\",\n \"Testford\",\n \"Mockhaven\",\n \"Fixtureton\",\n]);\n","/**\n * The synthetic-safety provider layer — every identifier, contact point, name, and date\n * `@cosyte/synth` emits is minted here, and **only** from a guaranteed-non-colliding source. There is no code\n * path that returns a value not drawn from a reserved range or the\n * shipped fake-name pool. This is the inverse of a parser's liberality: the generator is *closed-world*\n * on its data sources, so no output *can* be real or plausibly-real PHI.\n *\n * All providers are pure functions of an explicit {@link ../rng/rng.Rng} — same seed, same values.\n *\n * @module\n */\n\nimport type { Rng } from \"../rng/rng.js\";\n\nimport {\n RESERVED_EMAIL_DOMAINS,\n TEST_NET_V4_PREFIXES,\n DOC_V6_PREFIX,\n SYNTHETIC_ASSIGNING_AUTHORITY,\n npiCheckDigit,\n deaCheckDigit,\n DEA_REGISTRANT_TYPES,\n} from \"./reserved.js\";\nimport {\n SYNTHETIC_GIVEN_NAMES,\n SYNTHETIC_FAMILY_NAMES,\n SYNTHETIC_STREET_NAMES,\n SYNTHETIC_CITY_NAMES,\n} from \"./names-pool.js\";\n\n/** A synthetic person name drawn from the shipped fake-name pool. */\nexport interface SyntheticName {\n /** A clearly-fake given name. */\n readonly given: string;\n /** A clearly-fake family name. */\n readonly family: string;\n}\n\n/** A synthetic postal address — synthetic street + city, a fixed non-real ZIP. */\nexport interface SyntheticAddress {\n /** A clearly-fake street line. */\n readonly street: string;\n /** A clearly-fake city. */\n readonly city: string;\n /** A US state abbreviation (structural only; never combined with a real street + name + DOB). */\n readonly state: string;\n /** A reserved non-real ZIP (`00000`). */\n readonly zip: string;\n}\n\n/** A synthetic identifier scoped to the synthetic assigning authority. */\nexport interface SyntheticIdentifier {\n /** The identifier value (digits) — unique only within the synthetic namespace. */\n readonly value: string;\n /** HL7 identifier type code (`MR` = medical record, `AN` = account, `MB` = member). */\n readonly typeCode: \"MR\" | \"AN\" | \"MB\";\n /** The synthetic assigning-authority namespace id. */\n readonly assigningAuthority: string;\n /** The synthetic assigning-authority OID (HL7 example arc). */\n readonly assigningAuthorityOid: string;\n}\n\n/** Which SSN reserved space to draw from. */\nexport type SsnBlock = \"never-issued\" | \"advertising\";\n\n/**\n * A **synthetic SSN** — dashed `AAA-GG-SSSS`. Default draws the SSA never-issued area space\n * (`900–999`); `block: \"advertising\"` draws SSA's reserved advertising block (`987-65-4320…4329`).\n * A value from this function can never be a real SSN.\n *\n * @param rng - The seeded generator.\n * @param block - Which reserved space to draw from. Defaults to `\"never-issued\"`.\n * @returns A dashed synthetic SSN string.\n * @example\n * ```ts\n * import { createRng, ssn } from \"@cosyte/synth\";\n * ssn(createRng(1)); // e.g. a 900-area, never-issued SSN\n * ```\n */\nexport function ssn(rng: Rng, block: SsnBlock = \"never-issued\"): string {\n if (block === \"advertising\") {\n // SSA's explicitly-reserved advertising block: last digit 0..9 within -4320..-4329.\n return `987-65-432${String(rng.int(0, 9))}`;\n }\n const area = rng.int(900, 999); // SSA never issues 900-999.\n const group = rng.digits(2);\n const serial = rng.digits(4);\n return `${String(area)}-${group}-${serial}`;\n}\n\n/**\n * A **synthetic phone** in the NANP reserved fictional block — `(AAA) 555-01NN`. The reserved\n * guarantee is the `555-01NN` tail (exchange 555, line 0100–0199); the area code is any NANP-valid\n * `NXX`. Can never be a working number.\n *\n * @param rng - The seeded generator.\n * @returns A formatted synthetic phone string.\n * @example\n * ```ts\n * import { createRng, phone } from \"@cosyte/synth\";\n * phone(createRng(1)); // e.g. \"(2XX) 555-01NN\"\n * ```\n */\nexport function phone(rng: Rng): string {\n const area = `${String(rng.int(2, 9))}${rng.digits(2)}`; // NXX area code.\n const line = `01${rng.digits(2)}`; // reserved 0100-0199.\n return `(${area}) 555-${line}`;\n}\n\n/**\n * A **synthetic name** drawn from the shipped clearly-fake pool.\n *\n * @param rng - The seeded generator.\n * @returns A {@link SyntheticName}.\n * @example\n * ```ts\n * import { createRng, name } from \"@cosyte/synth\";\n * const { given, family } = name(createRng(1));\n * ```\n */\nexport function name(rng: Rng): SyntheticName {\n return { given: rng.pick(SYNTHETIC_GIVEN_NAMES), family: rng.pick(SYNTHETIC_FAMILY_NAMES) };\n}\n\n/**\n * A **synthetic email** at an RFC 2606 / 6761 reserved domain — `<slug>@example.com`.\n *\n * @param rng - The seeded generator.\n * @param person - Optional name to derive the local-part slug from; otherwise a random slug is used.\n * @returns A synthetic email address.\n * @example\n * ```ts\n * import { createRng, email, name } from \"@cosyte/synth\";\n * email(createRng(1), name(createRng(1))); // \"<given>.<family>@example.com\"\n * ```\n */\nexport function email(rng: Rng, person?: SyntheticName): string {\n const domain = rng.pick(RESERVED_EMAIL_DOMAINS);\n const slug = person ? `${person.given}.${person.family}`.toLowerCase() : `synth${rng.digits(6)}`;\n return `${slug}@${domain}`;\n}\n\n/**\n * A **synthetic IPv4** in an RFC 5737 TEST-NET block — never routable.\n *\n * @param rng - The seeded generator.\n * @returns A TEST-NET IPv4 address string.\n * @example\n * ```ts\n * import { createRng, ipv4 } from \"@cosyte/synth\";\n * ipv4(createRng(1)); // e.g. \"192.0.2.NN\"\n * ```\n */\nexport function ipv4(rng: Rng): string {\n return `${rng.pick(TEST_NET_V4_PREFIXES)}.${String(rng.int(1, 254))}`;\n}\n\n/**\n * A **synthetic IPv6** in the RFC 3849 documentation prefix `2001:db8::/32` — never routable.\n *\n * @param rng - The seeded generator.\n * @returns A documentation-prefix IPv6 address string.\n * @example\n * ```ts\n * import { createRng, ipv6 } from \"@cosyte/synth\";\n * ipv6(createRng(1)); // e.g. \"2001:db8::NNNN\"\n * ```\n */\nexport function ipv6(rng: Rng): string {\n const tail = rng.nextUint32().toString(16).padStart(4, \"0\").slice(-4);\n return `${DOC_V6_PREFIX}::${tail}`;\n}\n\n/**\n * A **deterministic UUIDv4-shaped** surrogate key from the seeded generator. Because it is seeded (not\n * from `node:crypto`, which is not reproducible), the cryptographic non-collision argument is weaker —\n * acceptable because the identifier namespace is synthetic anyway, and noted honestly.\n *\n * @param rng - The seeded generator.\n * @returns A canonical `8-4-4-4-12` lowercase-hex UUID string with version `4` and RFC 4122 variant.\n * @example\n * ```ts\n * import { createRng, uuid } from \"@cosyte/synth\";\n * uuid(createRng(1)); // \"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx\"\n * ```\n */\nexport function uuid(rng: Rng): string {\n const bytes = new Uint8Array(16);\n for (let i = 0; i < 16; i += 1) bytes[i] = rng.int(0, 255);\n bytes[6] = ((bytes[6] ?? 0) & 0x0f) | 0x40; // version 4\n bytes[8] = ((bytes[8] ?? 0) & 0x3f) | 0x80; // variant 10xx\n const hex = Array.from(bytes, (b) => b.toString(16).padStart(2, \"0\"));\n return `${hex.slice(0, 4).join(\"\")}-${hex.slice(4, 6).join(\"\")}-${hex.slice(6, 8).join(\"\")}-${hex.slice(8, 10).join(\"\")}-${hex.slice(10, 16).join(\"\")}`;\n}\n\n/**\n * A **synthetic NPI** — a 10-digit National Provider Identifier with a **deliberately-invalid Luhn\n * check digit**, so it can never be a NPPES-issued NPI (a real NPI must satisfy the `80840`-prefixed\n * Luhn check). The 9-digit base is drawn from the seeded generator; the check digit is\n * set to `(correct + 1) mod 10`, guaranteeing the full value fails validation.\n *\n * @param rng - The seeded generator.\n * @returns A 10-digit NPI-shaped string that is provably not a real NPI.\n * @example\n * ```ts\n * import { createRng, npi, isSyntheticNpi } from \"@cosyte/synth\";\n * isSyntheticNpi(npi(createRng(1))); // true — invalid check digit by construction\n * ```\n */\nexport function npi(rng: Rng): string {\n const base9 = rng.digits(9);\n const wrongCheck = (npiCheckDigit(base9) + 1) % 10;\n return `${base9}${String(wrongCheck)}`;\n}\n\n/**\n * A **synthetic DEA number** — `<registrant-type><initial>` + 7 digits with a **deliberately-invalid\n * checksum**, so it can never be a validly-issued DEA registration (a real DEA number's 7th digit\n * satisfies the published DEA checksum). The first letter is a registrant-type letter, the\n * second is derived from `person` (its family initial) when supplied so the number reads plausibly; the\n * 6-digit base is seeded and the check digit is set to `(correct + 1) mod 10`, guaranteeing the value\n * fails validation. NCPDP carries prescriber DEA, and this is the identity locus a refuter attacks\n * hardest, so — like {@link npi} — non-collision is a construction-level guarantee, not a heuristic.\n *\n * @param rng - The seeded generator.\n * @param person - Optional name whose family initial becomes the DEA's second letter.\n * @returns A DEA-shaped string that is provably not a real DEA registration.\n * @example\n * ```ts\n * import { createRng, dea, isSyntheticDea } from \"@cosyte/synth\";\n * isSyntheticDea(dea(createRng(1))); // true — invalid checksum by construction\n * ```\n */\nexport function dea(rng: Rng, person?: SyntheticName): string {\n const type = rng.pick(DEA_REGISTRANT_TYPES);\n const initialSource = person?.family ?? rng.pick(SYNTHETIC_FAMILY_NAMES);\n const initial = initialSource.slice(0, 1).toUpperCase();\n const base6 = rng.digits(6);\n const wrongCheck = (deaCheckDigit(base6) + 1) % 10;\n return `${type}${initial}${base6}${String(wrongCheck)}`;\n}\n\n/**\n * A **synthetic identifier** (MRN / account / member id) scoped to the synthetic assigning authority.\n * There is no reserved MRN range, so non-collision is guaranteed by the *namespace*, not the value: the\n * identifier lives under a `SYNTH` authority no real facility uses.\n *\n * @param rng - The seeded generator.\n * @param typeCode - The HL7 identifier type: `MR` (default), `AN`, or `MB`.\n * @returns A {@link SyntheticIdentifier}.\n * @example\n * ```ts\n * import { createRng, identifier } from \"@cosyte/synth\";\n * identifier(createRng(1), \"MR\"); // { value, typeCode: \"MR\", assigningAuthority: \"COSYTE-SYNTH\", ... }\n * ```\n */\nexport function identifier(\n rng: Rng,\n typeCode: SyntheticIdentifier[\"typeCode\"] = \"MR\",\n): SyntheticIdentifier {\n return {\n value: rng.digits(8),\n typeCode,\n assigningAuthority: SYNTHETIC_ASSIGNING_AUTHORITY.namespaceId,\n assigningAuthorityOid: SYNTHETIC_ASSIGNING_AUTHORITY.universalId,\n };\n}\n\n/**\n * A **synthetic address** — a fake street + city, a reserved non-real ZIP (`00000`). A real state\n * abbreviation may appear (structural only) but is never combined with a real street + name + DOB.\n *\n * @param rng - The seeded generator.\n * @returns A {@link SyntheticAddress}.\n * @example\n * ```ts\n * import { createRng, address } from \"@cosyte/synth\";\n * address(createRng(1)); // { street, city, state, zip: \"00000\" }\n * ```\n */\nexport function address(rng: Rng): SyntheticAddress {\n const number = rng.int(1, 9999);\n return {\n street: `${String(number)} ${rng.pick(SYNTHETIC_STREET_NAMES)}`,\n city: rng.pick(SYNTHETIC_CITY_NAMES),\n state: rng.pick(US_STATES),\n zip: \"00000\",\n };\n}\n\n/**\n * A **synthetic date** in HL7 `YYYYMMDD` form, drawn uniformly within an inclusive year range. Comes\n * from the seeded generator (never wall-clock), so it is reproducible and implies no real event.\n *\n * @param rng - The seeded generator.\n * @param minYear - Inclusive lower year bound (default `1930`).\n * @param maxYear - Inclusive upper year bound (default `2010`).\n * @returns An `YYYYMMDD` date string (always a valid calendar day).\n * @example\n * ```ts\n * import { createRng, dateYmd } from \"@cosyte/synth\";\n * dateYmd(createRng(1), 1970, 2000); // \"YYYYMMDD\"\n * ```\n */\nexport function dateYmd(rng: Rng, minYear = 1930, maxYear = 2010): string {\n const year = rng.int(minYear, maxYear);\n const month = rng.int(1, 12);\n const daysInMonth = new Date(Date.UTC(year, month, 0)).getUTCDate();\n const day = rng.int(1, daysInMonth);\n return `${String(year).padStart(4, \"0\")}${String(month).padStart(2, \"0\")}${String(day).padStart(2, \"0\")}`;\n}\n\n/** US state abbreviations — structural only (see {@link address}). */\nconst US_STATES: readonly string[] = Object.freeze([\n \"AL\",\n \"AK\",\n \"AZ\",\n \"AR\",\n \"CA\",\n \"CO\",\n \"CT\",\n \"DE\",\n \"FL\",\n \"GA\",\n \"HI\",\n \"ID\",\n \"IL\",\n \"IN\",\n \"IA\",\n \"KS\",\n \"KY\",\n \"LA\",\n \"ME\",\n \"MD\",\n \"MA\",\n \"MI\",\n \"MN\",\n \"MS\",\n \"MO\",\n \"MT\",\n \"NE\",\n \"NV\",\n \"NH\",\n \"NJ\",\n \"NM\",\n \"NY\",\n \"NC\",\n \"ND\",\n \"OH\",\n \"OK\",\n \"OR\",\n \"PA\",\n \"RI\",\n \"SC\",\n \"SD\",\n \"TN\",\n \"TX\",\n \"UT\",\n \"VT\",\n \"VA\",\n \"WA\",\n \"WV\",\n \"WI\",\n \"WY\",\n]);\n","/**\n * The `safe` namespace — the single entry point for every synthetic-by-construction value provider.\n *\n * Grouped under one object so a consumer reads `safe.ssn(rng)` / `safe.phone(rng)` and it is\n * self-evident that the value is drawn from a guaranteed-non-colliding synthetic source.\n * The individual functions and the reserved-range predicates are also exported by name from the\n * package root for direct import.\n *\n * @module\n */\n\nimport {\n ssn,\n phone,\n name,\n email,\n ipv4,\n ipv6,\n uuid,\n identifier,\n address,\n dateYmd,\n npi,\n dea,\n} from \"./providers.js\";\n\nexport * from \"./providers.js\";\nexport * from \"./reserved.js\";\nexport * from \"./names-pool.js\";\n\n/**\n * The synthetic-safety provider namespace. Every function draws only from a reserved range or the\n * shipped fake-name pool — no value it returns can be real or plausibly-real PHI.\n *\n * @example\n * ```ts\n * import { createRng, safe } from \"@cosyte/synth\";\n * const rng = createRng(42);\n * safe.ssn(rng); // never-issued SSN\n * safe.phone(rng); // reserved 555-01NN number\n * ```\n */\nexport const safe = Object.freeze({\n ssn,\n phone,\n name,\n email,\n ipv4,\n ipv6,\n uuid,\n identifier,\n address,\n dateYmd,\n npi,\n dea,\n});\n","/**\n * Shared HL7 v2 building blocks for every message family `@cosyte/synth` generates — the MSH scaffold,\n * the seeded timestamp, and the patient-identity bundle + its `PID` segment. Factored out so `ADT`,\n * `ORU`, `ORM`, `SIU`, and `VXU` all mint identity from the **same** synthetic-safety providers in the\n * **same** draw order, and all emit through `@cosyte/hl7`'s conservative serializer. Nothing here draws a\n * value that is not sourced from `../safe` — the synthetic-by-construction\n * invariant holds by construction for every family.\n *\n * @module\n */\n\nimport { buildMessage, type Hl7Message, type RawField } from \"@cosyte/hl7\";\n\nimport { type Rng } from \"../rng/rng.js\";\nimport {\n safe,\n type SyntheticName,\n type SyntheticAddress,\n type SyntheticIdentifier,\n} from \"../safe/index.js\";\n\nimport { componentsField } from \"./field.js\";\n\n/**\n * A seeded HL7 `YYYYMMDDHHMMSS` timestamp (message/event time; recent-year range). Strict HL7 DTM, so\n * `@cosyte/hl7` parses it back with no `TIMESTAMP_FALLBACK_FORMAT` warning.\n *\n * @param rng - The seeded generator.\n * @returns A 14-digit `YYYYMMDDHHMMSS` timestamp string.\n * @example\n * ```ts\n * import { createRng } from \"@cosyte/synth\";\n * // \"20230714…\"\n * ```\n */\nexport function seededTimestamp(rng: Rng): string {\n const date = safe.dateYmd(rng, 2020, 2025);\n const hh = String(rng.int(0, 23)).padStart(2, \"0\");\n const mm = String(rng.int(0, 59)).padStart(2, \"0\");\n const ss = String(rng.int(0, 59)).padStart(2, \"0\");\n return `${date}${hh}${mm}${ss}`;\n}\n\n/** The MSH scaffold shared by every generated message: the built message plus its seeded MSH values. */\nexport interface MessageScaffold {\n /** The `Hl7Message` with a complete MSH — chain `.addSegment(...)` to append the payload. */\n readonly message: Hl7Message;\n /** The seeded `YYYYMMDDHHMMSS` message timestamp (MSH-7), reused for event/observation times. */\n readonly timestamp: string;\n /** The seeded message control id (MSH-10). */\n readonly controlId: string;\n}\n\n/**\n * Build the MSH scaffold for a message of the given `MSH-9` type through `@cosyte/hl7`'s `buildMessage`,\n * so the delimiters, control id, and header layout are the parser's own conservative emit. Draws the\n * timestamp then the control id from `rng` (a fixed order — the reproducibility contract).\n *\n * @param rng - The seeded generator.\n * @param type - The `MSH-9` message type, e.g. `\"ORU^R01\"`.\n * @returns The {@link MessageScaffold}.\n * @example\n * ```ts\n * import { createRng } from \"@cosyte/synth\";\n * // mshScaffold(createRng(1), \"ORU^R01\").message.addSegment(\"PID\", […]);\n * ```\n */\nexport function mshScaffold(rng: Rng, type: string): MessageScaffold {\n const timestamp = seededTimestamp(rng);\n const controlId = `SYNTH${rng.digits(10)}`;\n const message = buildMessage({\n type,\n sendingApp: \"COSYTE-SYNTH\",\n sendingFacility: \"SYNTH-FAC\",\n receivingApp: \"RECEIVER\",\n receivingFacility: \"RECV-FAC\",\n controlId,\n timestamp,\n version: \"2.5\",\n processingId: \"P\",\n });\n return { message, timestamp, controlId };\n}\n\n/** A complete synthetic patient identity — every field drawn from `../safe`. */\nexport interface PatientIdentity {\n /** Name from the shipped fake-name pool. */\n readonly person: SyntheticName;\n /** Medical-record identifier scoped to the synthetic assigning authority. */\n readonly mrn: SyntheticIdentifier;\n /** Date of birth (`YYYYMMDD`) from the seeded generator. */\n readonly dob: string;\n /** Administrative sex. */\n readonly sex: \"M\" | \"F\";\n /** Synthetic postal address (reserved non-real ZIP). */\n readonly address: SyntheticAddress;\n /** Reserved `555-01xx` phone number. */\n readonly phone: string;\n /** Never-issued SSN as 9 digits (no dashes), for `PID-19`. */\n readonly ssnDigits: string;\n}\n\n/**\n * Mint a complete synthetic {@link PatientIdentity}. Every value comes from a synthetic-safety provider\n * — no code path here can return a real or plausibly-real identifier. The draw order is\n * fixed (name → MRN → DOB → sex → address → phone → SSN) so the same seed yields the same identity.\n *\n * @param rng - The seeded generator.\n * @returns A synthetic {@link PatientIdentity}.\n * @example\n * ```ts\n * import { createRng } from \"@cosyte/synth\";\n * // const id = patientIdentity(createRng(1)); // id.person, id.mrn, …\n * ```\n */\nexport function patientIdentity(rng: Rng): PatientIdentity {\n const person = safe.name(rng);\n const mrn = safe.identifier(rng, \"MR\");\n const dob = safe.dateYmd(rng, 1930, 2010);\n const sex = rng.pick([\"M\", \"F\"] as const);\n const address = safe.address(rng);\n const phone = safe.phone(rng);\n const ssnDigits = safe.ssn(rng).replace(/-/g, \"\");\n return { person, mrn, dob, sex, address, phone, ssnDigits };\n}\n\n/**\n * Lay out a fully-populated `PID` segment from a {@link PatientIdentity} as `addSegment` fields — the\n * PHI-dense segment shared by every family. Components go through {@link componentsField} so the parser\n * lays out the `^` separators (building *through* the parser).\n *\n * @param id - The synthetic identity to render.\n * @returns The `PID` field list for `Hl7Message.addSegment(\"PID\", …)`.\n * @example\n * ```ts\n * // msg.addSegment(\"PID\", pidSegment(patientIdentity(createRng(1))));\n * ```\n */\nexport function pidSegment(id: PatientIdentity): readonly (string | RawField)[] {\n return [\n \"1\", // PID-1 set id\n \"\", // PID-2 (legacy, absent)\n componentsField([id.mrn.value, \"\", \"\", id.mrn.assigningAuthority, id.mrn.typeCode]), // PID-3 CX\n \"\", // PID-4\n componentsField([id.person.family, id.person.given]), // PID-5 XPN\n \"\", // PID-6\n id.dob, // PID-7 DOB\n id.sex, // PID-8 sex\n \"\", // PID-9\n \"\", // PID-10\n componentsField([id.address.street, \"\", id.address.city, id.address.state, id.address.zip]), // PID-11 XAD\n \"\", // PID-12\n id.phone, // PID-13 phone\n \"\", // PID-14\n \"\", // PID-15\n \"\", // PID-16\n \"\", // PID-17\n \"\", // PID-18\n id.ssnDigits, // PID-19 SSN (digits)\n ];\n}\n","/**\n * The **selector chokepoint**. A generator's options are almost all *selectors*: a message kind, a\n * document type, a corpus mix, a claim variant, a Bundle type, a profile. Each is typed as a closed\n * union, and every one of those unions is **erased at run time**, so a JavaScript caller (or a\n * `as never` in someone's test) reaches the branch with any string at all.\n *\n * Three things went wrong when that was left unchecked, and they are all the same bug:\n *\n * 1. **The value reached a diagnostic.** An unrecognised `documentType` travelled into\n * `@cosyte/ccda`'s `buildCcda`, which is entitled to quote it back in its own `TypeError` and\n * does. This package then has a caller-supplied string on an `err.message` and an `err.stack`,\n * through its own public entry point, having taken no care of it.\n * 2. **The value reached the model.** A corpus mix entry becomes an `Artifact.kind` and a\n * `manifest.counts` key, which is precisely the structural-identifier position a downstream\n * package interpolates to describe a location.\n * 3. **The fixture was silently mislabeled.** An exhaustive `switch` over an erased union takes no\n * branch and returns `undefined`, or a trailing `else` quietly generates something else. A corpus\n * whose manifest says it holds one transaction and holds another is a golden file that lies.\n *\n * So a selector is resolved against its own set, once, before anything is generated, and an\n * unrecognised one is a fatal `SYNTH_UNSUPPORTED_KIND`. Like every fatal here it carries a code and a\n * fixed message, and quotes neither the request nor the set.\n *\n * @module\n */\n\nimport { SYNTH_FATAL_CODES, SynthError } from \"./codes.js\";\n\n/**\n * Resolve one caller-supplied selector against the closed set that governs it, or **fail closed**.\n *\n * @param allowed - Every value the selector may take.\n * @param requested - The selector the caller supplied.\n * @returns `requested`, narrowed to the union.\n * @throws SynthError `SYNTH_UNSUPPORTED_KIND` when `requested` is not in `allowed`.\n * @example\n * ```ts\n * import { resolveKind } from \"@cosyte/synth\";\n * resolveKind([\"ccd\", \"referralNote\"] as const, \"ccd\"); // \"ccd\"\n * ```\n */\nexport function resolveKind<T extends string>(allowed: readonly T[], requested: string): T {\n const match = allowed.find((value) => value === requested);\n if (match === undefined) throw new SynthError(SYNTH_FATAL_CODES.SYNTH_UNSUPPORTED_KIND);\n return match;\n}\n\n/**\n * Resolve every entry of a caller-supplied corpus mix, in order, or **fail closed** on the first\n * unrecognised one.\n *\n * It substitutes the default **only** when the caller supplied nothing, which is exactly what the\n * `??` it replaced did. An empty array is a supplied mix and is returned as one. An earlier version\n * of this function also treated `[]` as \"nothing supplied\", on the stated grounds that it matched the\n * previous behaviour; it did not — `??` fires on `undefined` and never on `[]` — and it changed the\n * result of six published entry points, turning an explicit empty selection into \"generate one of\n * everything\". A convenience that fails open is not a convenience.\n *\n * @param allowed - Every kind the corpus may generate.\n * @param requested - The mix the caller supplied, or `undefined` for the default.\n * @param fallback - The default mix, used only when `requested` is `undefined`.\n * @returns The resolved mix.\n * @throws SynthError `SYNTH_UNSUPPORTED_KIND` on the first unrecognised entry.\n * @example\n * ```ts\n * import { resolveMix } from \"@cosyte/synth\";\n * resolveMix([\"Result\", \"Order\"] as const, [\"Order\"], [\"Result\", \"Order\"]); // [\"Order\"]\n * ```\n */\nexport function resolveMix<T extends string>(\n allowed: readonly T[],\n requested: readonly string[] | undefined,\n fallback: readonly T[],\n): readonly T[] {\n if (requested === undefined) return fallback;\n return requested.map((entry) => resolveKind(allowed, entry));\n}\n","/**\n * Spec-clean HL7 v2 `ADT` generation, built **through `@cosyte/hl7`'s `buildMessage`** so MSH\n * delimiters, segment layout, and escaping are the parser's own conservative emit — spec-clean *by\n * construction*. Every PHI-bearing field (name, DOB, SSN, MRN,\n * address, phone) is drawn from the synthetic-safety providers (`../safe`), so no value can be real.\n *\n * `ADT^A01/A04/A08` all require the `PID` (patient) + `PV1` (visit) groups the parser's structure net\n * checks for — so a generated message round-trips through `@cosyte/hl7` with **zero warnings**.\n *\n * @module\n */\n\nimport type { Hl7Message } from \"@cosyte/hl7\";\n\nimport { createRng } from \"../rng/rng.js\";\n\nimport { componentsField } from \"./field.js\";\nimport { mshScaffold, patientIdentity, pidSegment } from \"./common.js\";\nimport { resolveKind } from \"../select.js\";\n\n/** Every value {@link GenerateAdtOptions.trigger} accepts. Erased at run time, so it is resolved. */\nconst ADT_TRIGGERS: readonly AdtTrigger[] = Object.freeze([\"A01\", \"A04\", \"A08\"]);\n\n/** The ADT trigger events this generator produces (all require the PID + PV1 groups). */\nexport type AdtTrigger = \"A01\" | \"A04\" | \"A08\";\n\n/** Options for {@link generateAdt}. */\nexport interface GenerateAdtOptions {\n /** The seed — the same seed yields a byte-identical message. Defaults to `0`. */\n readonly seed?: number;\n /** The ADT trigger event. Defaults to `\"A01\"`. */\n readonly trigger?: AdtTrigger;\n}\n\n/**\n * Generate a spec-clean `ADT` {@link Hl7Message} through `@cosyte/hl7`. Deterministic in `seed`.\n *\n * The message carries a complete MSH (seeded control id + timestamp, so the bytes are reproducible),\n * `EVN`, a fully-populated `PID` (identity from the synthetic providers), and `PV1` (the visit group),\n * so it parses back through `@cosyte/hl7` with **zero warnings** (proven by {@link ./round-trip}).\n *\n * @param options - Seed + trigger. See {@link GenerateAdtOptions}.\n * @returns A spec-clean `ADT` `Hl7Message`.\n * @example\n * ```ts\n * import { generateAdt } from \"@cosyte/synth/hl7\";\n * const msg = generateAdt({ seed: 12345, trigger: \"A01\" });\n * console.log(msg.toString());\n * ```\n */\nexport function generateAdt(options: GenerateAdtOptions = {}): Hl7Message {\n const seed = options.seed ?? 0;\n const trigger = resolveKind(ADT_TRIGGERS, options.trigger ?? \"A01\");\n const rng = createRng(seed);\n\n const { message, timestamp } = mshScaffold(rng, `ADT^${trigger}`);\n message.addSegment(\"EVN\", [trigger, timestamp]);\n message.addSegment(\"PID\", pidSegment(patientIdentity(rng)));\n\n const patientClass = rng.pick([\"I\", \"O\", \"E\"] as const);\n message.addSegment(\"PV1\", [\n \"1\", // PV1-1 set id\n patientClass, // PV1-2 patient class\n componentsField([\"SYNTHWARD\", String(rng.int(1, 999)).padStart(3, \"0\"), \"01\"]), // PV1-3 PL\n ]);\n\n return message;\n}\n","/**\n * A tiny, curated, **license-clean** pool of example codes used to fill coded fields in generated HL7\n * messages (`OBR`/`OBX` observations, `ORC`/`OBR` orders, `RXA` vaccines). These are **public code\n * facts** — the spec examples' own values — not copyrighted terminology tables: `@cosyte/synth` bundles\n * **no** SNOMED/CPT/LOINC/RxNorm content. The pool exists only so a generated message is *structurally*\n * realistic; a consumer who\n * needs their own codes supplies them.\n *\n * Nothing here is PHI — codes and their display text are not identifiers. The synthetic-safety\n * invariant governs identity fields (name/DOB/SSN/MRN/phone/address), which come from `../safe`.\n *\n * @module\n */\n\n/** A coded concept: an identifier code, human-readable text, and its code system (HL7 `CE`/`CWE`). */\nexport interface ExampleCode {\n /** The code value (component 1). */\n readonly code: string;\n /** The human-readable display text (component 2). */\n readonly text: string;\n /** The coding-system id (component 3), e.g. `\"LN\"` (LOINC) or `\"CVX\"`. */\n readonly system: string;\n /** Reporting units (UCUM), where the concept is a measured quantity. */\n readonly units?: string;\n}\n\n/**\n * A handful of common LOINC laboratory-observation example codes (for `OBX`). Public LOINC identifiers\n * used purely as illustrative structural fillers.\n */\nexport const EXAMPLE_LAB_OBSERVATIONS: readonly ExampleCode[] = Object.freeze([\n Object.freeze({ code: \"4548-4\", text: \"Hemoglobin A1c\", system: \"LN\", units: \"%\" }),\n Object.freeze({ code: \"718-7\", text: \"Hemoglobin\", system: \"LN\", units: \"g/dL\" }),\n Object.freeze({ code: \"2345-7\", text: \"Glucose\", system: \"LN\", units: \"mg/dL\" }),\n Object.freeze({ code: \"2951-2\", text: \"Sodium\", system: \"LN\", units: \"mmol/L\" }),\n Object.freeze({ code: \"2823-3\", text: \"Potassium\", system: \"LN\", units: \"mmol/L\" }),\n Object.freeze({ code: \"789-8\", text: \"Erythrocytes\", system: \"LN\", units: \"10*6/uL\" }),\n]);\n\n/**\n * A handful of LOINC panel/service example codes (for the `OBR`/`ORC` universal service id). Public\n * identifiers used as structural fillers.\n */\nexport const EXAMPLE_ORDER_SERVICES: readonly ExampleCode[] = Object.freeze([\n Object.freeze({ code: \"24323-8\", text: \"Comprehensive metabolic panel\", system: \"LN\" }),\n Object.freeze({ code: \"58410-2\", text: \"CBC panel\", system: \"LN\" }),\n Object.freeze({ code: \"24356-8\", text: \"Urinalysis panel\", system: \"LN\" }),\n Object.freeze({ code: \"24331-1\", text: \"Lipid panel\", system: \"LN\" }),\n]);\n\n/**\n * A handful of CDC CVX vaccine example codes (for `RXA-5`). Public CVX identifiers used as structural\n * fillers; `@cosyte/synth` bundles no vaccine terminology.\n */\nexport const EXAMPLE_VACCINES: readonly ExampleCode[] = Object.freeze([\n Object.freeze({ code: \"08\", text: \"Hep B, adolescent or pediatric\", system: \"CVX\" }),\n Object.freeze({ code: \"20\", text: \"DTaP\", system: \"CVX\" }),\n Object.freeze({ code: \"03\", text: \"MMR\", system: \"CVX\" }),\n Object.freeze({ code: \"10\", text: \"IPV\", system: \"CVX\" }),\n Object.freeze({ code: \"141\", text: \"Influenza, seasonal, injectable\", system: \"CVX\" }),\n Object.freeze({ code: \"21\", text: \"Varicella\", system: \"CVX\" }),\n]);\n","/**\n * Spec-clean HL7 v2 `ORU^R01` (unsolicited observation result) generation, built **through\n * `@cosyte/hl7`'s `buildMessage`**. The parser's structure net requires the\n * result group (`OBR`/`OBX`) for `ORU^R01`; this generator always emits both, plus a fully-populated\n * `PID`, so the message round-trips with **zero warnings**. Patient identity comes from `../safe`;\n * observation codes come from the license-clean example pool (`./example-codes`), never bundled\n * terminology. A `synth` `ORU` is *structurally* valid, not clinically coherent.\n *\n * @module\n */\n\nimport type { Hl7Message, RawField } from \"@cosyte/hl7\";\n\nimport { createRng, type Rng } from \"../rng/rng.js\";\n\nimport { componentsField } from \"./field.js\";\nimport { mshScaffold, patientIdentity, pidSegment, seededTimestamp } from \"./common.js\";\nimport { EXAMPLE_LAB_OBSERVATIONS, EXAMPLE_ORDER_SERVICES } from \"./example-codes.js\";\n\n/** Options for {@link generateOru}. */\nexport interface GenerateOruOptions {\n /** The seed — the same seed yields a byte-identical message. Defaults to `0`. */\n readonly seed?: number;\n}\n\n/** Render one `OBX` result segment (set id `n`) for a numeric example observation. */\nfunction obxSegment(rng: Rng, setId: number): readonly (string | RawField)[] {\n const obs = rng.pick(EXAMPLE_LAB_OBSERVATIONS);\n const value = `${String(rng.int(1, 300))}.${String(rng.int(0, 9))}`;\n const observedAt = seededTimestamp(rng);\n return [\n String(setId), // OBX-1 set id\n \"NM\", // OBX-2 value type (numeric)\n componentsField([obs.code, obs.text, obs.system]), // OBX-3 observation identifier (CE)\n \"\", // OBX-4 observation sub-id\n value, // OBX-5 observation value\n obs.units ?? \"\", // OBX-6 units\n \"\", // OBX-7 reference range\n \"N\", // OBX-8 abnormal flags (normal)\n \"\", // OBX-9\n \"\", // OBX-10\n \"F\", // OBX-11 observation result status (final)\n \"\", // OBX-12\n \"\", // OBX-13\n observedAt, // OBX-14 date/time of the observation\n ];\n}\n\n/**\n * Generate a spec-clean `ORU^R01` {@link Hl7Message} through `@cosyte/hl7`. Deterministic in `seed`.\n *\n * Layout: MSH, `PID` (synthetic identity), `OBR` (order/observation request), and 1–3 `OBX` result\n * rows. The `OBR`/`OBX` result group satisfies the parser's `ORU^R01` structure net, so the message\n * re-parses with **zero warnings** (proven by {@link ./round-trip}).\n *\n * @param options - Seed. See {@link GenerateOruOptions}.\n * @returns A spec-clean `ORU^R01` `Hl7Message`.\n * @example\n * ```ts\n * import { generateOru } from \"@cosyte/synth/hl7\";\n * const msg = generateOru({ seed: 12345 });\n * console.log(msg.toString());\n * ```\n */\nexport function generateOru(options: GenerateOruOptions = {}): Hl7Message {\n const seed = options.seed ?? 0;\n const rng = createRng(seed);\n\n const { message } = mshScaffold(rng, \"ORU^R01\");\n message.addSegment(\"PID\", pidSegment(patientIdentity(rng)));\n\n const service = rng.pick(EXAMPLE_ORDER_SERVICES);\n const placer = rng.digits(8);\n const filler = rng.digits(8);\n message.addSegment(\"OBR\", [\n \"1\", // OBR-1 set id\n placer, // OBR-2 placer order number\n filler, // OBR-3 filler order number\n componentsField([service.code, service.text, service.system]), // OBR-4 universal service id (CE)\n \"\", // OBR-5\n \"\", // OBR-6\n seededTimestamp(rng), // OBR-7 observation date/time\n ]);\n\n const obxCount = rng.int(1, 3);\n for (let i = 1; i <= obxCount; i += 1) {\n message.addSegment(\"OBX\", obxSegment(rng, i));\n }\n\n return message;\n}\n","/**\n * Spec-clean HL7 v2 `ORM^O01` (general order) generation, built **through `@cosyte/hl7`'s\n * `buildMessage`**. The parser's structure net requires the common-order segment\n * (`ORC`) for `ORM^O01`; this generator emits `ORC` + a matching `OBR`, plus a fully-populated `PID`,\n * so the message round-trips with **zero warnings**. Identity comes from `../safe`; the ordered service\n * comes from the license-clean example pool, never bundled terminology.\n *\n * @module\n */\n\nimport type { Hl7Message } from \"@cosyte/hl7\";\n\nimport { createRng } from \"../rng/rng.js\";\n\nimport { componentsField } from \"./field.js\";\nimport { mshScaffold, patientIdentity, pidSegment, seededTimestamp } from \"./common.js\";\nimport { EXAMPLE_ORDER_SERVICES } from \"./example-codes.js\";\n\n/** Options for {@link generateOrm}. */\nexport interface GenerateOrmOptions {\n /** The seed — the same seed yields a byte-identical message. Defaults to `0`. */\n readonly seed?: number;\n}\n\n/**\n * Generate a spec-clean `ORM^O01` {@link Hl7Message} through `@cosyte/hl7`. Deterministic in `seed`.\n *\n * Layout: MSH, `PID` (synthetic identity), `ORC` (common order — control `NW`, new order), and a\n * matching `OBR` (order detail). The `ORC` satisfies the parser's `ORM^O01` structure net, so the\n * message re-parses with **zero warnings** (proven by {@link ./round-trip}).\n *\n * @param options - Seed. See {@link GenerateOrmOptions}.\n * @returns A spec-clean `ORM^O01` `Hl7Message`.\n * @example\n * ```ts\n * import { generateOrm } from \"@cosyte/synth/hl7\";\n * const msg = generateOrm({ seed: 12345 });\n * console.log(msg.toString());\n * ```\n */\nexport function generateOrm(options: GenerateOrmOptions = {}): Hl7Message {\n const seed = options.seed ?? 0;\n const rng = createRng(seed);\n\n const { message } = mshScaffold(rng, \"ORM^O01\");\n message.addSegment(\"PID\", pidSegment(patientIdentity(rng)));\n\n const service = rng.pick(EXAMPLE_ORDER_SERVICES);\n const placer = rng.digits(8);\n const filler = rng.digits(8);\n const orderedAt = seededTimestamp(rng);\n\n message.addSegment(\"ORC\", [\n \"NW\", // ORC-1 order control (new order)\n placer, // ORC-2 placer order number\n filler, // ORC-3 filler order number\n \"\", // ORC-4 placer group number\n \"\", // ORC-5 order status\n \"\", // ORC-6\n \"\", // ORC-7 quantity/timing\n \"\", // ORC-8\n orderedAt, // ORC-9 date/time of transaction\n ]);\n\n message.addSegment(\"OBR\", [\n \"1\", // OBR-1 set id\n placer, // OBR-2 placer order number (matches ORC)\n filler, // OBR-3 filler order number (matches ORC)\n componentsField([service.code, service.text, service.system]), // OBR-4 universal service id (CE)\n ]);\n\n return message;\n}\n","/**\n * Spec-clean HL7 v2 `SIU^S12` (notification of new appointment booking) generation, built **through\n * `@cosyte/hl7`'s `buildMessage`**. The parser's structure net requires the schedule\n * activity segment (`SCH`) for `SIU^S12`; this generator emits `SCH` + `PID` + a resource group\n * (`RGS`/`AIL`), so the message round-trips with **zero warnings**. Identity comes from `../safe`.\n *\n * @module\n */\n\nimport type { Hl7Message } from \"@cosyte/hl7\";\n\nimport { createRng } from \"../rng/rng.js\";\n\nimport { componentsField } from \"./field.js\";\nimport { mshScaffold, patientIdentity, pidSegment, seededTimestamp } from \"./common.js\";\n\n/** Options for {@link generateSiu}. */\nexport interface GenerateSiuOptions {\n /** The seed — the same seed yields a byte-identical message. Defaults to `0`. */\n readonly seed?: number;\n}\n\n/**\n * Generate a spec-clean `SIU^S12` {@link Hl7Message} through `@cosyte/hl7`. Deterministic in `seed`.\n *\n * Layout: MSH, `SCH` (schedule activity — the required group), `PID` (synthetic identity), `RGS`\n * (resource group), `AIL` (location resource). The `SCH` satisfies the parser's `SIU^S12` structure\n * net, so the message re-parses with **zero warnings** (proven by {@link ./round-trip}).\n *\n * @param options - Seed. See {@link GenerateSiuOptions}.\n * @returns A spec-clean `SIU^S12` `Hl7Message`.\n * @example\n * ```ts\n * import { generateSiu } from \"@cosyte/synth/hl7\";\n * const msg = generateSiu({ seed: 12345 });\n * console.log(msg.toString());\n * ```\n */\nexport function generateSiu(options: GenerateSiuOptions = {}): Hl7Message {\n const seed = options.seed ?? 0;\n const rng = createRng(seed);\n\n const { message } = mshScaffold(rng, \"SIU^S12\");\n\n const placerAppt = rng.digits(8);\n const fillerAppt = rng.digits(8);\n const startAt = seededTimestamp(rng);\n const durationMinutes = String(rng.int(15, 90));\n\n message.addSegment(\"SCH\", [\n placerAppt, // SCH-1 placer appointment id\n fillerAppt, // SCH-2 filler appointment id\n \"\", // SCH-3 occurrence number\n \"\", // SCH-4 placer group number\n \"\", // SCH-5 schedule id\n \"\", // SCH-6 event reason\n componentsField([\"ROUTINE\", \"Routine appointment\", \"L\"]), // SCH-7 appointment reason (CE)\n \"\", // SCH-8 appointment type\n durationMinutes, // SCH-9 appointment duration\n componentsField([\"min\", \"minutes\", \"UCUM\"]), // SCH-10 appointment duration units (CE)\n componentsField([\"1\", \"\", startAt, \"\", \"\", \"\", durationMinutes]), // SCH-11 appointment timing quantity (TQ)\n ]);\n\n message.addSegment(\"PID\", pidSegment(patientIdentity(rng)));\n\n message.addSegment(\"RGS\", [\n \"1\", // RGS-1 set id\n \"A\", // RGS-2 segment action code (add)\n ]);\n\n message.addSegment(\"AIL\", [\n \"1\", // AIL-1 set id\n \"A\", // AIL-2 segment action code\n componentsField([\"SYNTHCLINIC\", \"Synthetic Clinic\", \"COSYTE-SYNTH\"]), // AIL-3 location resource id\n ]);\n\n return message;\n}\n","/**\n * Spec-clean HL7 v2 `VXU^V04` (unsolicited vaccination record update) generation, built **through\n * `@cosyte/hl7`'s `buildMessage`**. The parser's structure net requires the patient\n * group (`PID`) for `VXU^V04` (per the CDC IG, `RXA` lives in the optional order group); this generator\n * emits `PID` + `ORC` + `RXA` + `RXR`, so the message round-trips with **zero warnings**. Identity comes\n * from `../safe`; the vaccine code comes from the license-clean example pool, never bundled terminology.\n *\n * @module\n */\n\nimport type { Hl7Message } from \"@cosyte/hl7\";\n\nimport { createRng } from \"../rng/rng.js\";\n\nimport { componentsField } from \"./field.js\";\nimport { mshScaffold, patientIdentity, pidSegment, seededTimestamp } from \"./common.js\";\nimport { EXAMPLE_VACCINES } from \"./example-codes.js\";\n\n/** Options for {@link generateVxu}. */\nexport interface GenerateVxuOptions {\n /** The seed — the same seed yields a byte-identical message. Defaults to `0`. */\n readonly seed?: number;\n}\n\n/**\n * Generate a spec-clean `VXU^V04` {@link Hl7Message} through `@cosyte/hl7`. Deterministic in `seed`.\n *\n * Layout: MSH, `PID` (synthetic identity — the required group), `ORC` (common order), `RXA` (vaccine\n * administration, CVX example code), `RXR` (route). The `PID` satisfies the parser's `VXU^V04`\n * structure net, so the message re-parses with **zero warnings** (proven by {@link ./round-trip}).\n *\n * @param options - Seed. See {@link GenerateVxuOptions}.\n * @returns A spec-clean `VXU^V04` `Hl7Message`.\n * @example\n * ```ts\n * import { generateVxu } from \"@cosyte/synth/hl7\";\n * const msg = generateVxu({ seed: 12345 });\n * console.log(msg.toString());\n * ```\n */\nexport function generateVxu(options: GenerateVxuOptions = {}): Hl7Message {\n const seed = options.seed ?? 0;\n const rng = createRng(seed);\n\n const { message } = mshScaffold(rng, \"VXU^V04\");\n message.addSegment(\"PID\", pidSegment(patientIdentity(rng)));\n\n const placer = rng.digits(8);\n const filler = rng.digits(8);\n message.addSegment(\"ORC\", [\n \"RE\", // ORC-1 order control (observation to follow / record)\n placer, // ORC-2 placer order number\n filler, // ORC-3 filler order number\n ]);\n\n const vaccine = rng.pick(EXAMPLE_VACCINES);\n const administeredAt = seededTimestamp(rng);\n const doseAmount = String(rng.int(1, 5) / 10); // 0.1–0.5 mL, structural only\n\n message.addSegment(\"RXA\", [\n \"0\", // RXA-1 give sub-id counter\n \"1\", // RXA-2 administration sub-id counter\n administeredAt, // RXA-3 date/time start of administration\n administeredAt, // RXA-4 date/time end of administration\n componentsField([vaccine.code, vaccine.text, vaccine.system]), // RXA-5 administered code (CE)\n doseAmount, // RXA-6 administered amount\n componentsField([\"mL\", \"milliliters\", \"UCUM\"]), // RXA-7 administered units (CE)\n \"\", // RXA-8\n \"\", // RXA-9 administration notes\n \"\", // RXA-10\n \"\", // RXA-11\n \"\", // RXA-12\n \"\", // RXA-13\n \"\", // RXA-14\n \"\", // RXA-15 substance lot number\n \"\", // RXA-16\n \"\", // RXA-17\n \"\", // RXA-18\n \"\", // RXA-19\n \"CP\", // RXA-20 completion status (complete)\n ]);\n\n message.addSegment(\"RXR\", [\n componentsField([\"IM\", \"Intramuscular\", \"HL70162\"]), // RXR-1 route (CE)\n componentsField([\"LD\", \"Left Deltoid\", \"HL70163\"]), // RXR-2 administration site (CE)\n ]);\n\n return message;\n}\n","/**\n * The **round-trip-through-the-parser harness** — the headline gate for the synthetic-fixture\n * generator. A generated artifact is \"spec-clean\" only if `@cosyte/hl7` — not\n * `@cosyte/synth`'s own opinion — reads it back cleanly. This harness feeds a generated message\n * straight back into the parser and reports what the parser found, so a false \"spec-clean\" claim\n * cannot hide.\n *\n * @module\n */\n\nimport { parseHL7, type Hl7Message } from \"@cosyte/hl7\";\n\n/** The verdict of one round-trip through `@cosyte/hl7`. */\nexport interface RoundTripResult {\n /** The serialized wire text (the parser's own conservative emit). */\n readonly content: string;\n /** The warning codes the parser emitted on re-parse. Empty ⇒ spec-clean. */\n readonly warnings: readonly string[];\n /** Whether re-serializing the re-parsed message is byte-identical to `content`. */\n readonly byteStable: boolean;\n /** `true` iff the artifact is spec-clean: zero warnings **and** byte-stable. */\n readonly specClean: boolean;\n}\n\n/**\n * Round-trip an `@cosyte/hl7` `Hl7Message` through serialize → parse → serialize and report the\n * verdict. A spec-clean artifact re-parses with **zero warnings** and re-serializes byte-identically.\n *\n * @param message - The message to check (typically from `generateAdt`).\n * @returns The {@link RoundTripResult}.\n * @example\n * ```ts\n * import { generateAdt, roundTrip } from \"@cosyte/synth/hl7\";\n * const { specClean, warnings } = roundTrip(generateAdt({ seed: 1 }));\n * // specClean === true, warnings.length === 0\n * ```\n */\nexport function roundTrip(message: Hl7Message): RoundTripResult {\n const content = message.toString();\n const reparsed = parseHL7(content);\n const warnings = reparsed.warnings.map((w) => String(w.code));\n const byteStable = reparsed.toString() === content;\n return {\n content,\n warnings,\n byteStable,\n specClean: warnings.length === 0 && byteStable,\n };\n}\n","/**\n * `defineSynthProfile` — the growth-loop hook for site/vendor fixture recipes. A profile bundles the\n * value pools and the quirk recipe a fixture set should use, authored through the same public API as\n * the built-ins: a validated, frozen `SynthProfile` carrying a name, optional value overrides, and the\n * quirk names a format's quirk corpus should apply.\n *\n * @module\n */\n\nimport { SYNTH_FATAL_CODES, SynthError } from \"./codes.js\";\n\n/** The user-authored spec passed to {@link defineSynthProfile}. */\nexport interface SynthProfileSpec {\n /** A stable, human-readable profile name (e.g. `\"acme-hospital\"`). Required, non-empty. */\n readonly name: string;\n /** Optional given-name pool override (clearly-synthetic names only — see the safety invariant). */\n readonly givenNames?: readonly string[];\n /** Optional family-name pool override (clearly-synthetic names only). */\n readonly familyNames?: readonly string[];\n /**\n * The vendor quirk recipe names this profile requests. Validated against the target format's quirk\n * registry when the profile drives a quirk corpus (an unsupported quirk is a fatal\n * `SYNTH_UNSUPPORTED_QUIRK`, never a silent no-op).\n */\n readonly quirks?: readonly string[];\n}\n\n/** A frozen, validated fixture recipe produced by {@link defineSynthProfile}. */\nexport interface SynthProfile {\n /** The profile name. */\n readonly name: string;\n /** The given-name pool this profile draws from (overrides or the built-in default). */\n readonly givenNames?: readonly string[];\n /** The family-name pool this profile draws from. */\n readonly familyNames?: readonly string[];\n /** The requested quirk recipe names. */\n readonly quirks: readonly string[];\n}\n\n/**\n * Define a reusable, frozen synthetic-fixture profile.\n *\n * @param spec - The profile spec; `name` is required and non-empty.\n * @returns A deep-frozen {@link SynthProfile}.\n * @throws SynthError `SYNTH_INVALID_PROFILE` when `name` is missing or blank.\n * @example\n * ```ts\n * import { defineSynthProfile } from \"@cosyte/synth\";\n * const acme = defineSynthProfile({ name: \"acme-hospital\", quirks: [] });\n * ```\n */\nexport function defineSynthProfile(spec: SynthProfileSpec): SynthProfile {\n if (typeof spec.name !== \"string\" || spec.name.trim().length === 0) {\n throw new SynthError(SYNTH_FATAL_CODES.SYNTH_INVALID_PROFILE);\n }\n return Object.freeze({\n name: spec.name,\n ...(spec.givenNames ? { givenNames: Object.freeze([...spec.givenNames]) } : {}),\n ...(spec.familyNames ? { familyNames: Object.freeze([...spec.familyNames]) } : {}),\n quirks: Object.freeze([...(spec.quirks ?? [])]),\n });\n}\n","/**\n * The **quirk core**. Where the spec-clean generators prove\n * *synthetic-by-construction* through each parser's own builder, the quirk layer proves the mirror\n * property: a **deliberately off-spec** fixture round-trips to **exactly the intended parser warning\n * code(s)** — no more, no fewer. The quirk vocabulary **is the parsers' own profile systems**\n * (`hl7.defineProfile`, `ccda.defineCcdaProfile`, `astm.defineAstmProfile`): a quirk exercises exactly\n * the tolerance the corresponding parser profile encodes, so a quirk fixture is never a fiction — it\n * targets a documented, coded leniency (the **intended-warning contract**).\n *\n * This module is the **format-agnostic** part: the descriptor a quirk carries, the artifact a quirk\n * generator returns, the round-trip verdict shape, and the `SYNTH_UNSUPPORTED_QUIRK` fail-closed. Each\n * format's concrete quirk recipes + transforms live behind its own subpath (`@cosyte/synth/hl7`, …).\n *\n * @module\n */\n\nimport type { SynthFormat } from \"./corpus.js\";\nimport { SYNTH_FATAL_CODES, SynthError } from \"./codes.js\";\nimport type { SynthProfile } from \"./profile.js\";\n\n/**\n * How the parser's matching profile treats a quirk once it is active — the three shapes the parsers'\n * profile systems actually exhibit (verified firsthand against each parser):\n *\n * - `\"suppressed\"` — the profile makes the warning **disappear** (HL7 v2: a `defineProfile`\n * `customSegments` claim suppresses `UNKNOWN_SEGMENT` for a declared Z-segment).\n * - `\"rebadged\"` — the profile **downgrades** the warning to the value-free `PROFILE_QUIRK_APPLIED`\n * marker with `expected: true` (C-CDA `defineCcdaProfile` / ASTM `defineAstmProfile`\n * `profileQuirkApplied`).\n * - `\"bare\"` — no shipped profile tolerates it; the quirk targets a real coded leniency a consumer can\n * tolerate via their own `defineProfile`/`defineAstmProfile`, but no built-in re-badges it.\n */\nexport type QuirkProfileDisposition = \"suppressed\" | \"rebadged\" | \"bare\";\n\n/**\n * The stable, value-free re-badge code the C-CDA and ASTM parsers emit when a profile tolerates a\n * quirk. HL7 v2 has no equivalent (it suppresses instead — see {@link QuirkProfileDisposition}).\n */\nexport const PROFILE_QUIRK_APPLIED = \"PROFILE_QUIRK_APPLIED\";\n\n/**\n * A public, grounded description of one vendor quirk — the metadata that binds a quirk recipe to a real\n * parser warning code and a **publicly-groundable** deviation (cited-public, never a private\n * vendor corpus).\n */\nexport interface QuirkDescriptor {\n /** The quirk recipe name (e.g. `\"unknown-zsegment\"`). Stable; part of the public contract. */\n readonly name: string;\n /** The format this quirk applies to. */\n readonly format: SynthFormat;\n /**\n * The **exact** parser warning code(s) a bare parse (no profile) surfaces for this quirk — the\n * intended-warning contract. A quirk that produces any other code, or none, is a generation bug.\n */\n readonly intendedWarnings: readonly string[];\n /**\n * The **public** grounding for this quirk — the spec clause or the parser's public profile that\n * documents the tolerance. Never a private vendor-attributed corpus.\n */\n readonly grounding: string;\n /** The parser profile that tolerates this quirk (when a built-in public one exists). */\n readonly toleratingProfile?: string;\n /** How {@link toleratingProfile} treats the quirk. */\n readonly disposition: QuirkProfileDisposition;\n}\n\n/** One generated quirk artifact — the off-spec wire text plus the contract it is meant to satisfy. */\nexport interface QuirkArtifact {\n /** The format this artifact belongs to. */\n readonly format: SynthFormat;\n /** The quirk recipe applied. */\n readonly quirk: string;\n /** The underlying spec-clean message kind the quirk was injected into (e.g. `\"ORU^R01\"`). */\n readonly kind: string;\n /** The **quirked** wire text (deterministic in the seed + quirk). */\n readonly content: string;\n /** The exact parser warning code(s) this artifact is meant to round-trip to. */\n readonly intendedWarnings: readonly string[];\n}\n\n/** The verdict of a bare parse under the tolerating profile, if any. */\nexport interface QuirkProfiledVerdict {\n /** The profile applied. */\n readonly profileName: string;\n /** How the profile treats the quirk. */\n readonly disposition: QuirkProfileDisposition;\n /** The warning codes the parser emitted with the profile active. */\n readonly warnings: readonly string[];\n /**\n * `true` iff the profile handled the quirk as its disposition declares: `\"suppressed\"` ⇒ the intended\n * code is gone; `\"rebadged\"` ⇒ the intended code is gone and `PROFILE_QUIRK_APPLIED` is present.\n */\n readonly tolerated: boolean;\n}\n\n/** The verdict of round-tripping a quirk artifact through its parser. */\nexport interface QuirkRoundTripResult {\n /** The quirked wire text that was parsed. */\n readonly content: string;\n /** The warning codes a **bare** parse (no profile) emitted. */\n readonly warnings: readonly string[];\n /** The exact code(s) the quirk is meant to produce. */\n readonly intendedWarnings: readonly string[];\n /**\n * `true` iff the bare parse produced **exactly** the intended code(s) — the intended-warning contract.\n */\n readonly intendedWarningHeld: boolean;\n /** The verdict under the tolerating profile, when a built-in public one exists. */\n readonly withProfile?: QuirkProfiledVerdict;\n}\n\n/**\n * Exact multiset (order-independent) equality of two code lists — the intended-warning comparison.\n *\n * @param a - The first code list.\n * @param b - The second code list.\n * @returns `true` iff the two lists contain the same codes with the same multiplicities.\n * @example\n * ```ts\n * import { sameCodeSet } from \"@cosyte/synth\";\n * sameCodeSet([\"A\", \"B\"], [\"B\", \"A\"]); // true\n * ```\n */\nexport function sameCodeSet(a: readonly string[], b: readonly string[]): boolean {\n if (a.length !== b.length) return false;\n const counts = new Map<string, number>();\n for (const c of a) counts.set(c, (counts.get(c) ?? 0) + 1);\n for (const c of b) {\n const n = counts.get(c);\n if (n === undefined) return false;\n if (n === 1) counts.delete(c);\n else counts.set(c, n - 1);\n }\n return counts.size === 0;\n}\n\n/**\n * Resolve a requested quirk name against a format's registry, or **fail closed**. A quirk the format's\n * profile system does not support is a fatal `SYNTH_UNSUPPORTED_QUIRK` — never a silent no-op and never\n * a fabricated quirk with a made-up warning.\n *\n * The refusal names neither the request nor the registry. `registry`, `format` and `name` are all\n * caller-supplied, and a diagnostic that quotes its input is a diagnostic that can be made to carry\n * anything the caller was holding — which for a fixture generator wired into someone else's pipeline\n * is not a hypothetical. Branch on `err.code`; the supported set is the registry you passed\n * (`HL7_QUIRKS`, `CCDA_QUIRKS`, `ASTM_QUIRKS`), which you can enumerate directly.\n *\n * @param registry - The format's quirk descriptors, keyed by name.\n * @param format - The format being generated.\n * @param name - The requested quirk name.\n * @returns The matching {@link QuirkDescriptor}.\n * @throws SynthError with code `SYNTH_UNSUPPORTED_QUIRK` when `name` is not a supported quirk.\n * @example\n * ```ts\n * import { resolveQuirk } from \"@cosyte/synth\";\n * import { HL7_QUIRKS } from \"@cosyte/synth/hl7\";\n * resolveQuirk(HL7_QUIRKS, \"hl7v2\", \"unknown-zsegment\").intendedWarnings; // [\"UNKNOWN_SEGMENT\"]\n * ```\n */\nexport function resolveQuirk(\n registry: Readonly<Record<string, QuirkDescriptor>>,\n format: SynthFormat,\n name: string,\n): QuirkDescriptor {\n const descriptor = registry[name];\n // `format` is compared, never rendered. A descriptor found under the wrong format's registry is a\n // mislabeled fixture waiting to happen, so the mismatch fails closed on the same code.\n if (descriptor === undefined || descriptor.format !== format) {\n throw new SynthError(SYNTH_FATAL_CODES.SYNTH_UNSUPPORTED_QUIRK);\n }\n return descriptor;\n}\n\n/**\n * Evaluate whether a profiled parse tolerated a quirk as its disposition declares. Shared across the\n * formats so the \"suppressed vs re-badged\" logic lives in exactly one place.\n *\n * @param disposition - The quirk's declared profile disposition.\n * @param intendedWarnings - The bare-parse intended code(s).\n * @param warningsUnderProfile - The code(s) the parser emitted with the profile active.\n * @returns `true` iff the profile handled the quirk correctly for its disposition.\n * @example\n * ```ts\n * import { profileTolerated } from \"@cosyte/synth\";\n * profileTolerated(\"suppressed\", [\"UNKNOWN_SEGMENT\"], []); // true — the profile suppressed it\n * ```\n */\nexport function profileTolerated(\n disposition: QuirkProfileDisposition,\n intendedWarnings: readonly string[],\n warningsUnderProfile: readonly string[],\n): boolean {\n const stillHasIntended = intendedWarnings.some((c) => warningsUnderProfile.includes(c));\n switch (disposition) {\n case \"suppressed\":\n return !stillHasIntended;\n case \"rebadged\":\n return !stillHasIntended && warningsUnderProfile.includes(PROFILE_QUIRK_APPLIED);\n case \"bare\":\n return false;\n }\n}\n\n/**\n * Assert a freshly-generated quirk artifact **actually** round-trips to its intended warning(s), or\n * **fail closed**. This is the generator's self-check on the intended-warning contract: a\n * fixture whose bare parse does not produce exactly the declared code(s) is a *mislabeled* fixture — a\n * golden file that lies about the parser verdict it anchors — and must never be emitted. It is a\n * stronger guard than \"the transform changed some bytes\": a transform can mutate the wrong element (a\n * template a given document type does not key its warning on) and still change bytes while producing no\n * warning. Every format's `generate*Quirk` calls this after transforming, so the contract is enforced at\n * generation time, not merely at round-trip time.\n *\n * It no longer takes the quirk name. That parameter existed for one reason — to be interpolated into\n * the refusal — and a parameter whose only job is to reach a message is the exact shape this package\n * is removing, so it is gone rather than merely unused. The refusal names neither code list either;\n * both are caller-supplied, and the caller reads the comparison back off the arguments it holds.\n *\n * @param intendedWarnings - The declared intended code(s).\n * @param bareWarnings - The code(s) a bare parse of the generated artifact actually produced.\n * @throws SynthError `SYNTH_INTENDED_WARNING_MISMATCH` when the bare parse did not produce exactly\n * the intended code(s).\n * @example\n * ```ts\n * import { assertIntendedWarnings } from \"@cosyte/synth\";\n * assertIntendedWarnings([\"UNKNOWN_SEGMENT\"], [\"UNKNOWN_SEGMENT\"]); // ok\n * ```\n */\nexport function assertIntendedWarnings(\n intendedWarnings: readonly string[],\n bareWarnings: readonly string[],\n): void {\n if (!sameCodeSet(bareWarnings, intendedWarnings)) {\n throw new SynthError(SYNTH_FATAL_CODES.SYNTH_INTENDED_WARNING_MISMATCH);\n }\n}\n\n/**\n * Validate the quirk names carried by a {@link SynthProfile} against a format's registry, failing closed\n * on the first unsupported one. Lets a consumer author a fixture recipe with `defineSynthProfile` and\n * have its quirks checked against the *parser's* real tolerance before any fixture is generated.\n *\n * @param profile - The synth profile whose `quirks` to validate.\n * @param registry - The format's quirk descriptors.\n * @param format - The format being generated.\n * @returns The validated quirk names (the profile's, in order).\n * @throws SynthError `SYNTH_UNSUPPORTED_QUIRK` for the first unsupported quirk.\n * @example\n * ```ts\n * import { validateProfileQuirks, defineSynthProfile } from \"@cosyte/synth\";\n * import { HL7_QUIRKS } from \"@cosyte/synth/hl7\";\n * const p = defineSynthProfile({ name: \"site\", quirks: [\"unknown-zsegment\"] });\n * validateProfileQuirks(p, HL7_QUIRKS, \"hl7v2\"); // [\"unknown-zsegment\"]\n * ```\n */\nexport function validateProfileQuirks(\n profile: SynthProfile,\n registry: Readonly<Record<string, QuirkDescriptor>>,\n format: SynthFormat,\n): readonly string[] {\n for (const name of profile.quirks) resolveQuirk(registry, format, name);\n return profile.quirks;\n}\n","/**\n * HL7 v2 **vendor-quirk generation**. A quirk deviates the\n * *structure* of an otherwise spec-clean message so it round-trips through `@cosyte/hl7` to **exactly**\n * one intended, stable warning code — the tolerance a `defineProfile` profile encodes. The deviation is\n * applied **post-serialize**.\n *\n * Two publicly-groundable quirks ship (cited-public, never a private vendor corpus):\n *\n * - **`unknown-zsegment`** → `UNKNOWN_SEGMENT`. HL7 v2.x §2.5 permits site-defined `Z`-segments; a\n * receiver with no profile flags them. `@cosyte/hl7`'s public imaging/PACS profiles (`visage`,\n * `philips`, `va` — each grounded in a downloadable vendor/federal interface spec) declare `ZDS`, so a\n * `defineProfile` that claims the segment **suppresses** the warning.\n * - **`unknown-escape`** → `UNKNOWN_ESCAPE_SEQUENCE`. HL7 v2.x §2.7 escaping — a locally-defined\n * `\\Z..\\` escape is preserved verbatim and flagged. HL7 v2 has no re-badge mechanism, so this is a\n * `\"bare\"` quirk (no built-in profile downgrades it).\n *\n * A quirk **never** introduces a real-looking value — it changes the message *shape*, never the\n * *provenance* of the data, so the synthetic-safety gate still runs and stays zero.\n *\n * @module\n */\n\nimport { parseHL7, profiles as hl7Profiles, type Hl7Message, type Profile } from \"@cosyte/hl7\";\n\nimport { createRng } from \"../rng/rng.js\";\nimport { makeCorpus, type Corpus } from \"../corpus.js\";\nimport { defineSynthProfile, type SynthProfile } from \"../profile.js\";\nimport {\n resolveQuirk,\n sameCodeSet,\n profileTolerated,\n validateProfileQuirks,\n assertIntendedWarnings,\n type QuirkDescriptor,\n type QuirkArtifact,\n type QuirkRoundTripResult,\n} from \"../quirk.js\";\n\nimport { generateAdt } from \"./adt.js\";\nimport { generateOru } from \"./oru.js\";\nimport { generateOrm } from \"./orm.js\";\nimport { generateSiu } from \"./siu.js\";\nimport { generateVxu } from \"./vxu.js\";\nimport { resolveKind } from \"../select.js\";\n\n/** Every HL7 v2 quirk this package ships. */\nexport type Hl7QuirkName = \"unknown-zsegment\" | \"unknown-escape\";\n\n/** The HL7 v2 message families a quirk can be injected into (the spec-clean base). */\nexport type Hl7QuirkKind =\n | \"ADT^A01\"\n | \"ADT^A04\"\n | \"ADT^A08\"\n | \"ORU^R01\"\n | \"ORM^O01\"\n | \"SIU^S12\"\n | \"VXU^V04\";\n\n/**\n * The HL7 v2 quirk registry — each recipe bound to the exact `@cosyte/hl7` warning code it targets and\n * its public grounding.\n */\nexport const HL7_QUIRKS: Readonly<Record<Hl7QuirkName, QuirkDescriptor>> = Object.freeze({\n \"unknown-zsegment\": Object.freeze({\n name: \"unknown-zsegment\",\n format: \"hl7v2\",\n intendedWarnings: Object.freeze([\"UNKNOWN_SEGMENT\"]),\n grounding:\n \"HL7 v2.x §2.5 site-defined Z-segments; grounded on @cosyte/hl7's public imaging/PACS profiles \" +\n \"(Visage 7 / Philips Vue PACS / VA Radiology interface specs) which declare the ZDS segment.\",\n toleratingProfile: \"visage\",\n disposition: \"suppressed\",\n }),\n \"unknown-escape\": Object.freeze({\n name: \"unknown-escape\",\n format: \"hl7v2\",\n intendedWarnings: Object.freeze([\"UNKNOWN_ESCAPE_SEQUENCE\"]),\n grounding:\n \"HL7 v2.x §2.7 escaping — a locally-defined \\\\Z..\\\\ escape is preserved verbatim and flagged. \" +\n \"HL7 v2 has no profile re-badge, so no built-in profile downgrades it.\",\n disposition: \"bare\",\n }),\n});\n\n/** The tolerating HL7 profile object for a quirk (only the `unknown-zsegment` quirk has one). */\nfunction toleratingProfile(quirk: Hl7QuirkName): Profile | undefined {\n return quirk === \"unknown-zsegment\" ? hl7Profiles.visage : undefined;\n}\n\n/** Split a serialized HL7 message into non-empty segment lines (tolerating any newline convention). */\nfunction segmentsOf(wire: string): string[] {\n return wire.split(/\\r\\n|\\r|\\n/).filter((s) => s.length > 0);\n}\n\n/** The post-serialize transform for each quirk — a pure, deterministic function of the spec-clean wire. */\nfunction applyQuirk(quirk: Hl7QuirkName, wire: string): string {\n const segments = segmentsOf(wire);\n switch (quirk) {\n case \"unknown-zsegment\":\n // A site-defined Z-segment carrying only clearly-synthetic, structural tokens (no PHI locus).\n return [...segments, \"ZDS|1|SYNTHETIC-Z-SEGMENT^COSYTE-SYNTH\"].join(\"\\r\");\n case \"unknown-escape\":\n // An NTE comment whose body carries a locally-defined \\Zff\\ escape — preserved verbatim on parse.\n return [...segments, \"NTE|1||\\\\Zff\\\\\"].join(\"\\r\");\n }\n}\n\n/** Options for {@link generateHl7Quirk}. */\nexport interface GenerateHl7QuirkOptions {\n /** The seed — the same seed + quirk yields a byte-identical message. Defaults to `0`. */\n readonly seed?: number;\n /** The quirk to inject. Required. */\n readonly quirk: Hl7QuirkName;\n /** The spec-clean base message family. Defaults to `\"ORU^R01\"`. */\n readonly kind?: Hl7QuirkKind;\n}\n\n/** Generate the spec-clean base message for a quirk kind. */\n/** Every value {@link Hl7QuirkKind} admits. Erased at run time, so it is resolved, not trusted. */\nconst ALL_QUIRK_KINDS: readonly Hl7QuirkKind[] = Object.freeze([\n \"ADT^A01\",\n \"ADT^A04\",\n \"ADT^A08\",\n \"ORU^R01\",\n \"ORM^O01\",\n \"SIU^S12\",\n \"VXU^V04\",\n]);\n\nfunction baseMessage(kind: Hl7QuirkKind, seed: number): Hl7Message {\n switch (kind) {\n case \"ADT^A01\":\n return generateAdt({ seed, trigger: \"A01\" });\n case \"ADT^A04\":\n return generateAdt({ seed, trigger: \"A04\" });\n case \"ADT^A08\":\n return generateAdt({ seed, trigger: \"A08\" });\n case \"ORU^R01\":\n return generateOru({ seed });\n case \"ORM^O01\":\n return generateOrm({ seed });\n case \"SIU^S12\":\n return generateSiu({ seed });\n case \"VXU^V04\":\n return generateVxu({ seed });\n }\n}\n\n/**\n * Generate one HL7 v2 **quirk** artifact: a spec-clean message (built through `@cosyte/hl7`) with the\n * requested vendor deviation injected post-serialize. Deterministic in `seed` + `quirk` + `kind`.\n *\n * @param options - Seed, quirk, and base kind. See {@link GenerateHl7QuirkOptions}.\n * @returns The {@link QuirkArtifact} — its `content` round-trips to `intendedWarnings` exactly.\n * @throws SynthError `SYNTH_UNSUPPORTED_QUIRK` if `quirk` is not a supported HL7 quirk.\n * @example\n * ```ts\n * import { generateHl7Quirk, hl7QuirkRoundTrip } from \"@cosyte/synth/hl7\";\n * const artifact = generateHl7Quirk({ seed: 1, quirk: \"unknown-zsegment\" });\n * hl7QuirkRoundTrip(artifact).intendedWarningHeld; // true — exactly UNKNOWN_SEGMENT\n * ```\n */\nexport function generateHl7Quirk(options: GenerateHl7QuirkOptions): QuirkArtifact {\n const seed = options.seed ?? 0;\n const kind = resolveKind(ALL_QUIRK_KINDS, options.kind ?? \"ORU^R01\");\n const descriptor = resolveQuirk(HL7_QUIRKS, \"hl7v2\", options.quirk);\n const content = applyQuirk(options.quirk, baseMessage(kind, seed).toString());\n // Self-check the intended-warning contract at generation time — never emit a mislabeled fixture.\n assertIntendedWarnings(\n descriptor.intendedWarnings,\n parseHL7(content).warnings.map((w) => String(w.code)),\n );\n return Object.freeze({\n format: \"hl7v2\" as const,\n quirk: descriptor.name,\n kind,\n content,\n intendedWarnings: descriptor.intendedWarnings,\n });\n}\n\n/**\n * Round-trip an HL7 v2 quirk artifact through `@cosyte/hl7` and report the intended-warning verdict: a bare\n * parse must produce **exactly** the intended code(s), and — when a built-in public\n * profile tolerates the quirk — the profiled parse must suppress it.\n *\n * @param artifact - The quirk artifact (from {@link generateHl7Quirk}).\n * @returns The {@link QuirkRoundTripResult}.\n * @example\n * ```ts\n * import { generateHl7Quirk, hl7QuirkRoundTrip } from \"@cosyte/synth/hl7\";\n * const rt = hl7QuirkRoundTrip(generateHl7Quirk({ seed: 1, quirk: \"unknown-zsegment\" }));\n * rt.withProfile?.tolerated; // true — the `visage` profile suppresses UNKNOWN_SEGMENT\n * ```\n */\nexport function hl7QuirkRoundTrip(artifact: QuirkArtifact): QuirkRoundTripResult {\n const quirk = artifact.quirk as Hl7QuirkName;\n const descriptor = resolveQuirk(HL7_QUIRKS, \"hl7v2\", quirk);\n const bare = parseHL7(artifact.content).warnings.map((w) => String(w.code));\n const profile = toleratingProfile(quirk);\n const withProfile =\n profile !== undefined && descriptor.toleratingProfile !== undefined\n ? {\n profileName: descriptor.toleratingProfile,\n disposition: descriptor.disposition,\n warnings: parseHL7(artifact.content, profile).warnings.map((w) => String(w.code)),\n tolerated: false,\n }\n : undefined;\n return {\n content: artifact.content,\n warnings: bare,\n intendedWarnings: artifact.intendedWarnings,\n intendedWarningHeld: sameCodeSet(bare, artifact.intendedWarnings),\n ...(withProfile\n ? {\n withProfile: {\n ...withProfile,\n tolerated: profileTolerated(\n descriptor.disposition,\n artifact.intendedWarnings,\n withProfile.warnings,\n ),\n },\n }\n : {}),\n };\n}\n\n/** Options for {@link hl7QuirkCorpus}. */\nexport interface Hl7QuirkCorpusOptions {\n /** The seed for the whole corpus (deterministic). */\n readonly seed: number;\n /** How many quirk artifacts to generate. Defaults to the number of quirks. */\n readonly count?: number;\n /** The quirk names to cycle through. Defaults to every HL7 quirk. Validated; unsupported ⇒ fatal. */\n readonly quirks?: readonly Hl7QuirkName[];\n /** A {@link SynthProfile} whose `quirks` drive the corpus (validated). Takes precedence over `quirks`. */\n readonly profile?: SynthProfile;\n /** The base message family each quirk is injected into. Defaults to `\"ORU^R01\"`. */\n readonly kind?: Hl7QuirkKind;\n}\n\nconst ALL_HL7_QUIRKS: readonly Hl7QuirkName[] = Object.freeze(\n Object.keys(HL7_QUIRKS) as Hl7QuirkName[],\n);\n\n/**\n * Build a reproducible {@link Corpus} of HL7 v2 quirk artifacts. Each artifact's `warnings` record the\n * parser's verdict — the intended code(s) for its quirk (not empty: a quirk corpus is deliberately\n * off-spec) — and the manifest lists the applied quirk names.\n *\n * @param options - Seed, count, and the quirk selection. See {@link Hl7QuirkCorpusOptions}.\n * @returns A deep-frozen {@link Corpus}.\n * @example\n * ```ts\n * import { hl7QuirkCorpus } from \"@cosyte/synth/hl7\";\n * const corpus = hl7QuirkCorpus({ seed: 42 });\n * corpus.manifest.quirks; // [\"unknown-zsegment\", \"unknown-escape\"]\n * ```\n */\nexport function hl7QuirkCorpus(options: Hl7QuirkCorpusOptions): Corpus {\n const quirks: readonly string[] = options.profile\n ? validateProfileQuirks(options.profile, HL7_QUIRKS, \"hl7v2\")\n : (options.quirks ?? ALL_HL7_QUIRKS);\n const names = quirks.length > 0 ? quirks : ALL_HL7_QUIRKS;\n // Resolve the WHOLE list here, not lazily per generated artifact. `count` can be below\n // `names.length`, and the tail then never reaches `generateHl7Quirk`'s own `resolveQuirk`\n // while still landing on `manifest.quirks` verbatim. A manifest that names a quirk the\n // corpus does not contain is the same mislabeled-fixture defect the intended-warning\n // contract exists to prevent, and `manifest.quirks` is a derived identifier.\n for (const name of names) resolveQuirk(HL7_QUIRKS, \"hl7v2\", name);\n const kind = options.kind ?? \"ORU^R01\";\n const count = options.count ?? names.length;\n const seedStream = createRng(options.seed);\n const artifacts = Array.from({ length: count }, (_unused, i) => {\n const quirk = names[i % names.length] as Hl7QuirkName;\n const artifactSeed = seedStream.nextUint32();\n const artifact = generateHl7Quirk({ seed: artifactSeed, quirk, kind });\n return {\n format: \"hl7v2\" as const,\n kind: `${kind}~${quirk}`,\n content: artifact.content,\n warnings: artifact.intendedWarnings,\n };\n });\n return makeCorpus(options.seed, artifacts, [...new Set(names)]);\n}\n\n/**\n * A ready-made {@link SynthProfile} that requests every built-in HL7 quirk — a convenience for wiring\n * `defineSynthProfile`'s quirk list to the parser's real tolerance.\n *\n * @example\n * ```ts\n * import { hl7QuirkProfile, hl7QuirkCorpus } from \"@cosyte/synth/hl7\";\n * hl7QuirkCorpus({ seed: 1, profile: hl7QuirkProfile });\n * ```\n */\nexport const hl7QuirkProfile: SynthProfile = defineSynthProfile({\n name: \"cosyte-hl7-quirks\",\n quirks: [...ALL_HL7_QUIRKS],\n});\n","/**\n * `@cosyte/synth/hl7` — the HL7 v2 generation surface, exposed as its own subpath so importing the\n * package root does **not** pull `@cosyte/hl7`. This is the **lazy, per-format** boundary: a consumer\n * who only needs HL7 fixtures imports `@cosyte/synth/hl7`; one who needs only the core primitives\n * never loads a parser.\n * `@cosyte/hl7` is an **optional peer dependency** — present only for this subpath.\n *\n * The HL7 v2 message set is complete: `ADT` (A01/A04/A08), `ORU^R01`, `ORM^O01`, `SIU^S12`, and\n * `VXU^V04` — each built through `@cosyte/hl7`'s `buildMessage` and round-tripping with zero warnings.\n *\n * @module\n */\n\nimport type { Hl7Message } from \"@cosyte/hl7\";\n\nimport { createRng } from \"../rng/rng.js\";\nimport { makeCorpus, type Corpus } from \"../corpus.js\";\n\nimport { generateAdt, type AdtTrigger } from \"./adt.js\";\nimport { generateOru } from \"./oru.js\";\nimport { generateOrm } from \"./orm.js\";\nimport { generateSiu } from \"./siu.js\";\nimport { generateVxu } from \"./vxu.js\";\nimport { roundTrip } from \"./round-trip.js\";\nimport { resolveKind, resolveMix } from \"../select.js\";\n\nexport { generateAdt, type AdtTrigger, type GenerateAdtOptions } from \"./adt.js\";\nexport { generateOru, type GenerateOruOptions } from \"./oru.js\";\nexport { generateOrm, type GenerateOrmOptions } from \"./orm.js\";\nexport { generateSiu, type GenerateSiuOptions } from \"./siu.js\";\nexport { generateVxu, type GenerateVxuOptions } from \"./vxu.js\";\nexport { roundTrip, type RoundTripResult } from \"./round-trip.js\";\nexport { componentsField } from \"./field.js\";\nexport {\n seededTimestamp,\n mshScaffold,\n patientIdentity,\n pidSegment,\n type MessageScaffold,\n type PatientIdentity,\n} from \"./common.js\";\nexport {\n type ExampleCode,\n EXAMPLE_LAB_OBSERVATIONS,\n EXAMPLE_ORDER_SERVICES,\n EXAMPLE_VACCINES,\n} from \"./example-codes.js\";\nexport {\n generateHl7Quirk,\n hl7QuirkRoundTrip,\n hl7QuirkCorpus,\n hl7QuirkProfile,\n HL7_QUIRKS,\n type Hl7QuirkName,\n type Hl7QuirkKind,\n type GenerateHl7QuirkOptions,\n type Hl7QuirkCorpusOptions,\n} from \"./quirk.js\";\n\n/**\n * Every HL7 v2 message kind this subpath generates — the `MSH-9` label used as the corpus `kind`. `ADT`\n * carries its trigger; the other families have a single generated trigger each.\n */\nexport type Hl7MessageKind =\n | \"ADT^A01\"\n | \"ADT^A04\"\n | \"ADT^A08\"\n | \"ORU^R01\"\n | \"ORM^O01\"\n | \"SIU^S12\"\n | \"VXU^V04\";\n\n/** Every kind {@link hl7Corpus} accepts, and the default mix — one of every family. */\nconst ALL_KINDS: readonly Hl7MessageKind[] = Object.freeze([\n \"ADT^A01\",\n \"ADT^A04\",\n \"ADT^A08\",\n \"ORU^R01\",\n \"ORM^O01\",\n \"SIU^S12\",\n \"VXU^V04\",\n]);\nconst DEFAULT_MIX = ALL_KINDS;\n\n/** Every `ADT` trigger the back-compat `triggers` option accepts. */\nconst ADT_TRIGGERS: readonly AdtTrigger[] = Object.freeze([\"A01\", \"A04\", \"A08\"]);\n\n/**\n * Generate one message of the given {@link Hl7MessageKind} from a seed, dispatching to the right\n * family generator. Every kind builds through `@cosyte/hl7` and is deterministic in `seed`.\n *\n * @param kind - The message kind to generate.\n * @param seed - The seed.\n * @returns The generated `Hl7Message`.\n * @example\n * ```ts\n * import { generateHl7 } from \"@cosyte/synth/hl7\";\n * generateHl7(\"ORU^R01\", 42).toString();\n * ```\n */\nexport function generateHl7(kind: Hl7MessageKind, seed: number): Hl7Message {\n switch (resolveKind(ALL_KINDS, kind)) {\n case \"ADT^A01\":\n return generateAdt({ seed, trigger: \"A01\" });\n case \"ADT^A04\":\n return generateAdt({ seed, trigger: \"A04\" });\n case \"ADT^A08\":\n return generateAdt({ seed, trigger: \"A08\" });\n case \"ORU^R01\":\n return generateOru({ seed });\n case \"ORM^O01\":\n return generateOrm({ seed });\n case \"SIU^S12\":\n return generateSiu({ seed });\n case \"VXU^V04\":\n return generateVxu({ seed });\n }\n}\n\n/** Options for {@link hl7Corpus}. */\nexport interface Hl7CorpusOptions {\n /** The seed for the whole corpus (deterministic). */\n readonly seed: number;\n /** How many messages to generate. Defaults to `1`. */\n readonly count?: number;\n /**\n * The message kinds to cycle through. Defaults to one of every family\n * (`ADT^A01/A04/A08`, `ORU^R01`, `ORM^O01`, `SIU^S12`, `VXU^V04`).\n */\n readonly mix?: readonly Hl7MessageKind[];\n /**\n * ADT-only convenience: the triggers to cycle through, kept for back-compat. When\n * supplied it takes precedence over `mix` and restricts the corpus to `ADT` messages.\n */\n readonly triggers?: readonly AdtTrigger[];\n}\n\n/**\n * Build a reproducible {@link Corpus} of spec-clean HL7 messages across the families. Each\n * message is generated from a distinct sub-seed derived from the corpus seed (so the set is\n * deterministic) and round-tripped through `@cosyte/hl7`; the per-artifact `warnings` record the\n * parser's verdict (empty ⇒ spec-clean).\n *\n * @param options - Seed, count, and the message mix. See {@link Hl7CorpusOptions}.\n * @returns A deep-frozen {@link Corpus}.\n * @example\n * ```ts\n * import { hl7Corpus } from \"@cosyte/synth/hl7\";\n * const corpus = hl7Corpus({ seed: 42, count: 7 });\n * corpus.artifacts.every((a) => a.warnings.length === 0); // true — spec-clean\n * ```\n */\nexport function hl7Corpus(options: Hl7CorpusOptions): Corpus {\n const { seed, count = 1 } = options;\n const kinds: readonly Hl7MessageKind[] =\n options.triggers !== undefined\n ? options.triggers.map(\n (t): Hl7MessageKind => `ADT^${resolveKind(ADT_TRIGGERS, t)}` as Hl7MessageKind,\n )\n : resolveMix(ALL_KINDS, options.mix, DEFAULT_MIX);\n // A seed stream derives one deterministic per-message seed from the corpus seed.\n const seedStream = createRng(seed);\n const artifacts = Array.from({ length: count }, (_unused, i) => {\n const kind = kinds[i % kinds.length] ?? \"ADT^A01\";\n const messageSeed = seedStream.nextUint32();\n const rt = roundTrip(generateHl7(kind, messageSeed));\n return {\n format: \"hl7v2\" as const,\n kind,\n content: rt.content,\n warnings: rt.warnings,\n };\n });\n return makeCorpus(seed, artifacts);\n}\n"]}
|