@cosyte/synth 0.0.1

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.
Files changed (58) hide show
  1. package/CHANGELOG.md +414 -0
  2. package/LICENSE +21 -0
  3. package/README.md +325 -0
  4. package/dist/astm/index.cjs +847 -0
  5. package/dist/astm/index.cjs.map +1 -0
  6. package/dist/astm/index.d.cts +418 -0
  7. package/dist/astm/index.d.ts +418 -0
  8. package/dist/astm/index.mjs +828 -0
  9. package/dist/astm/index.mjs.map +1 -0
  10. package/dist/ccda/index.cjs +1103 -0
  11. package/dist/ccda/index.cjs.map +1 -0
  12. package/dist/ccda/index.d.cts +380 -0
  13. package/dist/ccda/index.d.ts +380 -0
  14. package/dist/ccda/index.mjs +1077 -0
  15. package/dist/ccda/index.mjs.map +1 -0
  16. package/dist/deid/index.cjs +2809 -0
  17. package/dist/deid/index.cjs.map +1 -0
  18. package/dist/deid/index.d.cts +464 -0
  19. package/dist/deid/index.d.ts +464 -0
  20. package/dist/deid/index.mjs +2793 -0
  21. package/dist/deid/index.mjs.map +1 -0
  22. package/dist/example-codes-DeXcnCSK.d.cts +105 -0
  23. package/dist/example-codes-DeXcnCSK.d.ts +105 -0
  24. package/dist/fhir/index.cjs +1429 -0
  25. package/dist/fhir/index.cjs.map +1 -0
  26. package/dist/fhir/index.d.cts +772 -0
  27. package/dist/fhir/index.d.ts +772 -0
  28. package/dist/fhir/index.mjs +1384 -0
  29. package/dist/fhir/index.mjs.map +1 -0
  30. package/dist/hl7/index.cjs +1012 -0
  31. package/dist/hl7/index.cjs.map +1 -0
  32. package/dist/hl7/index.d.cts +548 -0
  33. package/dist/hl7/index.d.ts +548 -0
  34. package/dist/hl7/index.mjs +990 -0
  35. package/dist/hl7/index.mjs.map +1 -0
  36. package/dist/index.cjs +535 -0
  37. package/dist/index.cjs.map +1 -0
  38. package/dist/index.d.cts +407 -0
  39. package/dist/index.d.ts +407 -0
  40. package/dist/index.mjs +488 -0
  41. package/dist/index.mjs.map +1 -0
  42. package/dist/ncpdp/index.cjs +714 -0
  43. package/dist/ncpdp/index.cjs.map +1 -0
  44. package/dist/ncpdp/index.d.cts +432 -0
  45. package/dist/ncpdp/index.d.ts +432 -0
  46. package/dist/ncpdp/index.mjs +695 -0
  47. package/dist/ncpdp/index.mjs.map +1 -0
  48. package/dist/providers-OLz3zAc-.d.cts +343 -0
  49. package/dist/providers-OLz3zAc-.d.ts +343 -0
  50. package/dist/quirk-DmkgoZdh.d.cts +239 -0
  51. package/dist/quirk-JLyO1Ncj.d.ts +239 -0
  52. package/dist/x12/index.cjs +920 -0
  53. package/dist/x12/index.cjs.map +1 -0
  54. package/dist/x12/index.d.cts +484 -0
  55. package/dist/x12/index.d.ts +484 -0
  56. package/dist/x12/index.mjs +892 -0
  57. package/dist/x12/index.mjs.map +1 -0
  58. package/package.json +210 -0
@@ -0,0 +1,548 @@
1
+ import { Hl7Message, RawField } from '@cosyte/hl7';
2
+ import { S as SyntheticName, a as SyntheticIdentifier, b as SyntheticAddress, R as Rng, C as Corpus } from '../providers-OLz3zAc-.js';
3
+ import { Q as QuirkDescriptor, S as SynthProfile, a as QuirkArtifact, b as QuirkRoundTripResult } from '../quirk-JLyO1Ncj.js';
4
+
5
+ /**
6
+ * Spec-clean HL7 v2 `ADT` generation, built **through `@cosyte/hl7`'s `buildMessage`** so MSH
7
+ * delimiters, segment layout, and escaping are the parser's own conservative emit — spec-clean *by
8
+ * construction*. Every PHI-bearing field (name, DOB, SSN, MRN,
9
+ * address, phone) is drawn from the synthetic-safety providers (`../safe`), so no value can be real.
10
+ *
11
+ * `ADT^A01/A04/A08` all require the `PID` (patient) + `PV1` (visit) groups the parser's structure net
12
+ * checks for — so a generated message round-trips through `@cosyte/hl7` with **zero warnings**.
13
+ *
14
+ * @module
15
+ */
16
+
17
+ /** The ADT trigger events this generator produces (all require the PID + PV1 groups). */
18
+ type AdtTrigger = "A01" | "A04" | "A08";
19
+ /** Options for {@link generateAdt}. */
20
+ interface GenerateAdtOptions {
21
+ /** The seed — the same seed yields a byte-identical message. Defaults to `0`. */
22
+ readonly seed?: number;
23
+ /** The ADT trigger event. Defaults to `"A01"`. */
24
+ readonly trigger?: AdtTrigger;
25
+ }
26
+ /**
27
+ * Generate a spec-clean `ADT` {@link Hl7Message} through `@cosyte/hl7`. Deterministic in `seed`.
28
+ *
29
+ * The message carries a complete MSH (seeded control id + timestamp, so the bytes are reproducible),
30
+ * `EVN`, a fully-populated `PID` (identity from the synthetic providers), and `PV1` (the visit group),
31
+ * so it parses back through `@cosyte/hl7` with **zero warnings** (proven by {@link ./round-trip}).
32
+ *
33
+ * @param options - Seed + trigger. See {@link GenerateAdtOptions}.
34
+ * @returns A spec-clean `ADT` `Hl7Message`.
35
+ * @example
36
+ * ```ts
37
+ * import { generateAdt } from "@cosyte/synth/hl7";
38
+ * const msg = generateAdt({ seed: 12345, trigger: "A01" });
39
+ * console.log(msg.toString());
40
+ * ```
41
+ */
42
+ declare function generateAdt(options?: GenerateAdtOptions): Hl7Message;
43
+
44
+ /**
45
+ * Spec-clean HL7 v2 `ORU^R01` (unsolicited observation result) generation, built **through
46
+ * `@cosyte/hl7`'s `buildMessage`**. The parser's structure net requires the
47
+ * result group (`OBR`/`OBX`) for `ORU^R01`; this generator always emits both, plus a fully-populated
48
+ * `PID`, so the message round-trips with **zero warnings**. Patient identity comes from `../safe`;
49
+ * observation codes come from the license-clean example pool (`./example-codes`), never bundled
50
+ * terminology. A `synth` `ORU` is *structurally* valid, not clinically coherent.
51
+ *
52
+ * @module
53
+ */
54
+
55
+ /** Options for {@link generateOru}. */
56
+ interface GenerateOruOptions {
57
+ /** The seed — the same seed yields a byte-identical message. Defaults to `0`. */
58
+ readonly seed?: number;
59
+ }
60
+ /**
61
+ * Generate a spec-clean `ORU^R01` {@link Hl7Message} through `@cosyte/hl7`. Deterministic in `seed`.
62
+ *
63
+ * Layout: MSH, `PID` (synthetic identity), `OBR` (order/observation request), and 1–3 `OBX` result
64
+ * rows. The `OBR`/`OBX` result group satisfies the parser's `ORU^R01` structure net, so the message
65
+ * re-parses with **zero warnings** (proven by {@link ./round-trip}).
66
+ *
67
+ * @param options - Seed. See {@link GenerateOruOptions}.
68
+ * @returns A spec-clean `ORU^R01` `Hl7Message`.
69
+ * @example
70
+ * ```ts
71
+ * import { generateOru } from "@cosyte/synth/hl7";
72
+ * const msg = generateOru({ seed: 12345 });
73
+ * console.log(msg.toString());
74
+ * ```
75
+ */
76
+ declare function generateOru(options?: GenerateOruOptions): Hl7Message;
77
+
78
+ /**
79
+ * Spec-clean HL7 v2 `ORM^O01` (general order) generation, built **through `@cosyte/hl7`'s
80
+ * `buildMessage`**. The parser's structure net requires the common-order segment
81
+ * (`ORC`) for `ORM^O01`; this generator emits `ORC` + a matching `OBR`, plus a fully-populated `PID`,
82
+ * so the message round-trips with **zero warnings**. Identity comes from `../safe`; the ordered service
83
+ * comes from the license-clean example pool, never bundled terminology.
84
+ *
85
+ * @module
86
+ */
87
+
88
+ /** Options for {@link generateOrm}. */
89
+ interface GenerateOrmOptions {
90
+ /** The seed — the same seed yields a byte-identical message. Defaults to `0`. */
91
+ readonly seed?: number;
92
+ }
93
+ /**
94
+ * Generate a spec-clean `ORM^O01` {@link Hl7Message} through `@cosyte/hl7`. Deterministic in `seed`.
95
+ *
96
+ * Layout: MSH, `PID` (synthetic identity), `ORC` (common order — control `NW`, new order), and a
97
+ * matching `OBR` (order detail). The `ORC` satisfies the parser's `ORM^O01` structure net, so the
98
+ * message re-parses with **zero warnings** (proven by {@link ./round-trip}).
99
+ *
100
+ * @param options - Seed. See {@link GenerateOrmOptions}.
101
+ * @returns A spec-clean `ORM^O01` `Hl7Message`.
102
+ * @example
103
+ * ```ts
104
+ * import { generateOrm } from "@cosyte/synth/hl7";
105
+ * const msg = generateOrm({ seed: 12345 });
106
+ * console.log(msg.toString());
107
+ * ```
108
+ */
109
+ declare function generateOrm(options?: GenerateOrmOptions): Hl7Message;
110
+
111
+ /**
112
+ * Spec-clean HL7 v2 `SIU^S12` (notification of new appointment booking) generation, built **through
113
+ * `@cosyte/hl7`'s `buildMessage`**. The parser's structure net requires the schedule
114
+ * activity segment (`SCH`) for `SIU^S12`; this generator emits `SCH` + `PID` + a resource group
115
+ * (`RGS`/`AIL`), so the message round-trips with **zero warnings**. Identity comes from `../safe`.
116
+ *
117
+ * @module
118
+ */
119
+
120
+ /** Options for {@link generateSiu}. */
121
+ interface GenerateSiuOptions {
122
+ /** The seed — the same seed yields a byte-identical message. Defaults to `0`. */
123
+ readonly seed?: number;
124
+ }
125
+ /**
126
+ * Generate a spec-clean `SIU^S12` {@link Hl7Message} through `@cosyte/hl7`. Deterministic in `seed`.
127
+ *
128
+ * Layout: MSH, `SCH` (schedule activity — the required group), `PID` (synthetic identity), `RGS`
129
+ * (resource group), `AIL` (location resource). The `SCH` satisfies the parser's `SIU^S12` structure
130
+ * net, so the message re-parses with **zero warnings** (proven by {@link ./round-trip}).
131
+ *
132
+ * @param options - Seed. See {@link GenerateSiuOptions}.
133
+ * @returns A spec-clean `SIU^S12` `Hl7Message`.
134
+ * @example
135
+ * ```ts
136
+ * import { generateSiu } from "@cosyte/synth/hl7";
137
+ * const msg = generateSiu({ seed: 12345 });
138
+ * console.log(msg.toString());
139
+ * ```
140
+ */
141
+ declare function generateSiu(options?: GenerateSiuOptions): Hl7Message;
142
+
143
+ /**
144
+ * Spec-clean HL7 v2 `VXU^V04` (unsolicited vaccination record update) generation, built **through
145
+ * `@cosyte/hl7`'s `buildMessage`**. The parser's structure net requires the patient
146
+ * group (`PID`) for `VXU^V04` (per the CDC IG, `RXA` lives in the optional order group); this generator
147
+ * emits `PID` + `ORC` + `RXA` + `RXR`, so the message round-trips with **zero warnings**. Identity comes
148
+ * from `../safe`; the vaccine code comes from the license-clean example pool, never bundled terminology.
149
+ *
150
+ * @module
151
+ */
152
+
153
+ /** Options for {@link generateVxu}. */
154
+ interface GenerateVxuOptions {
155
+ /** The seed — the same seed yields a byte-identical message. Defaults to `0`. */
156
+ readonly seed?: number;
157
+ }
158
+ /**
159
+ * Generate a spec-clean `VXU^V04` {@link Hl7Message} through `@cosyte/hl7`. Deterministic in `seed`.
160
+ *
161
+ * Layout: MSH, `PID` (synthetic identity — the required group), `ORC` (common order), `RXA` (vaccine
162
+ * administration, CVX example code), `RXR` (route). The `PID` satisfies the parser's `VXU^V04`
163
+ * structure net, so the message re-parses with **zero warnings** (proven by {@link ./round-trip}).
164
+ *
165
+ * @param options - Seed. See {@link GenerateVxuOptions}.
166
+ * @returns A spec-clean `VXU^V04` `Hl7Message`.
167
+ * @example
168
+ * ```ts
169
+ * import { generateVxu } from "@cosyte/synth/hl7";
170
+ * const msg = generateVxu({ seed: 12345 });
171
+ * console.log(msg.toString());
172
+ * ```
173
+ */
174
+ declare function generateVxu(options?: GenerateVxuOptions): Hl7Message;
175
+
176
+ /**
177
+ * The **round-trip-through-the-parser harness** — the headline gate for the synthetic-fixture
178
+ * generator. A generated artifact is "spec-clean" only if `@cosyte/hl7` — not
179
+ * `@cosyte/synth`'s own opinion — reads it back cleanly. This harness feeds a generated message
180
+ * straight back into the parser and reports what the parser found, so a false "spec-clean" claim
181
+ * cannot hide.
182
+ *
183
+ * @module
184
+ */
185
+
186
+ /** The verdict of one round-trip through `@cosyte/hl7`. */
187
+ interface RoundTripResult {
188
+ /** The serialized wire text (the parser's own conservative emit). */
189
+ readonly content: string;
190
+ /** The warning codes the parser emitted on re-parse. Empty ⇒ spec-clean. */
191
+ readonly warnings: readonly string[];
192
+ /** Whether re-serializing the re-parsed message is byte-identical to `content`. */
193
+ readonly byteStable: boolean;
194
+ /** `true` iff the artifact is spec-clean: zero warnings **and** byte-stable. */
195
+ readonly specClean: boolean;
196
+ }
197
+ /**
198
+ * Round-trip an `@cosyte/hl7` `Hl7Message` through serialize → parse → serialize and report the
199
+ * verdict. A spec-clean artifact re-parses with **zero warnings** and re-serializes byte-identically.
200
+ *
201
+ * @param message - The message to check (typically from `generateAdt`).
202
+ * @returns The {@link RoundTripResult}.
203
+ * @example
204
+ * ```ts
205
+ * import { generateAdt, roundTrip } from "@cosyte/synth/hl7";
206
+ * const { specClean, warnings } = roundTrip(generateAdt({ seed: 1 }));
207
+ * // specClean === true, warnings.length === 0
208
+ * ```
209
+ */
210
+ declare function roundTrip(message: Hl7Message): RoundTripResult;
211
+
212
+ /**
213
+ * Thin helpers that build `@cosyte/hl7` `RawField` objects with **components** for `addSegment`.
214
+ *
215
+ * Why this exists: `Hl7Message.addSegment` accepts a field as either a plain string or a structured
216
+ * `RawField`. A plain string is emitted **verbatim** — a literal `^` in it is escaped to `\S\`, not
217
+ * treated as a component separator (the parser re-escapes on serialize, by design). To place true
218
+ * components (a name's family/given, a CX's id/authority/type) we must hand `addSegment` a `RawField`
219
+ * with explicit `components`, so the parser's own conservative serializer lays out the separators.
220
+ * That is the whole point of building *through* the parser.
221
+ *
222
+ * @module
223
+ */
224
+
225
+ /**
226
+ * Build a `RawField` from a flat list of component strings (single repetition, single subcomponent
227
+ * per component). Empty strings become empty components (absent at the wire level).
228
+ *
229
+ * @param components - The component values, in HL7 component order.
230
+ * @returns A `RawField` the hl7 serializer lays out with `^` separators.
231
+ * @example
232
+ * ```ts
233
+ * import { componentsField } from "@cosyte/synth/hl7";
234
+ * componentsField(["Testerson", "Quilliam"]); // family^given
235
+ * ```
236
+ */
237
+ declare function componentsField(components: readonly string[]): RawField;
238
+
239
+ /**
240
+ * Shared HL7 v2 building blocks for every message family `@cosyte/synth` generates — the MSH scaffold,
241
+ * the seeded timestamp, and the patient-identity bundle + its `PID` segment. Factored out so `ADT`,
242
+ * `ORU`, `ORM`, `SIU`, and `VXU` all mint identity from the **same** synthetic-safety providers in the
243
+ * **same** draw order, and all emit through `@cosyte/hl7`'s conservative serializer. Nothing here draws a
244
+ * value that is not sourced from `../safe` — the synthetic-by-construction
245
+ * invariant holds by construction for every family.
246
+ *
247
+ * @module
248
+ */
249
+
250
+ /**
251
+ * A seeded HL7 `YYYYMMDDHHMMSS` timestamp (message/event time; recent-year range). Strict HL7 DTM, so
252
+ * `@cosyte/hl7` parses it back with no `TIMESTAMP_FALLBACK_FORMAT` warning.
253
+ *
254
+ * @param rng - The seeded generator.
255
+ * @returns A 14-digit `YYYYMMDDHHMMSS` timestamp string.
256
+ * @example
257
+ * ```ts
258
+ * import { createRng } from "@cosyte/synth";
259
+ * // "20230714…"
260
+ * ```
261
+ */
262
+ declare function seededTimestamp(rng: Rng): string;
263
+ /** The MSH scaffold shared by every generated message: the built message plus its seeded MSH values. */
264
+ interface MessageScaffold {
265
+ /** The `Hl7Message` with a complete MSH — chain `.addSegment(...)` to append the payload. */
266
+ readonly message: Hl7Message;
267
+ /** The seeded `YYYYMMDDHHMMSS` message timestamp (MSH-7), reused for event/observation times. */
268
+ readonly timestamp: string;
269
+ /** The seeded message control id (MSH-10). */
270
+ readonly controlId: string;
271
+ }
272
+ /**
273
+ * Build the MSH scaffold for a message of the given `MSH-9` type through `@cosyte/hl7`'s `buildMessage`,
274
+ * so the delimiters, control id, and header layout are the parser's own conservative emit. Draws the
275
+ * timestamp then the control id from `rng` (a fixed order — the reproducibility contract).
276
+ *
277
+ * @param rng - The seeded generator.
278
+ * @param type - The `MSH-9` message type, e.g. `"ORU^R01"`.
279
+ * @returns The {@link MessageScaffold}.
280
+ * @example
281
+ * ```ts
282
+ * import { createRng } from "@cosyte/synth";
283
+ * // mshScaffold(createRng(1), "ORU^R01").message.addSegment("PID", […]);
284
+ * ```
285
+ */
286
+ declare function mshScaffold(rng: Rng, type: string): MessageScaffold;
287
+ /** A complete synthetic patient identity — every field drawn from `../safe`. */
288
+ interface PatientIdentity {
289
+ /** Name from the shipped fake-name pool. */
290
+ readonly person: SyntheticName;
291
+ /** Medical-record identifier scoped to the synthetic assigning authority. */
292
+ readonly mrn: SyntheticIdentifier;
293
+ /** Date of birth (`YYYYMMDD`) from the seeded generator. */
294
+ readonly dob: string;
295
+ /** Administrative sex. */
296
+ readonly sex: "M" | "F";
297
+ /** Synthetic postal address (reserved non-real ZIP). */
298
+ readonly address: SyntheticAddress;
299
+ /** Reserved `555-01xx` phone number. */
300
+ readonly phone: string;
301
+ /** Never-issued SSN as 9 digits (no dashes), for `PID-19`. */
302
+ readonly ssnDigits: string;
303
+ }
304
+ /**
305
+ * Mint a complete synthetic {@link PatientIdentity}. Every value comes from a synthetic-safety provider
306
+ * — no code path here can return a real or plausibly-real identifier. The draw order is
307
+ * fixed (name → MRN → DOB → sex → address → phone → SSN) so the same seed yields the same identity.
308
+ *
309
+ * @param rng - The seeded generator.
310
+ * @returns A synthetic {@link PatientIdentity}.
311
+ * @example
312
+ * ```ts
313
+ * import { createRng } from "@cosyte/synth";
314
+ * // const id = patientIdentity(createRng(1)); // id.person, id.mrn, …
315
+ * ```
316
+ */
317
+ declare function patientIdentity(rng: Rng): PatientIdentity;
318
+ /**
319
+ * Lay out a fully-populated `PID` segment from a {@link PatientIdentity} as `addSegment` fields — the
320
+ * PHI-dense segment shared by every family. Components go through {@link componentsField} so the parser
321
+ * lays out the `^` separators (building *through* the parser).
322
+ *
323
+ * @param id - The synthetic identity to render.
324
+ * @returns The `PID` field list for `Hl7Message.addSegment("PID", …)`.
325
+ * @example
326
+ * ```ts
327
+ * // msg.addSegment("PID", pidSegment(patientIdentity(createRng(1))));
328
+ * ```
329
+ */
330
+ declare function pidSegment(id: PatientIdentity): readonly (string | RawField)[];
331
+
332
+ /**
333
+ * A tiny, curated, **license-clean** pool of example codes used to fill coded fields in generated HL7
334
+ * messages (`OBR`/`OBX` observations, `ORC`/`OBR` orders, `RXA` vaccines). These are **public code
335
+ * facts** — the spec examples' own values — not copyrighted terminology tables: `@cosyte/synth` bundles
336
+ * **no** SNOMED/CPT/LOINC/RxNorm content. The pool exists only so a generated message is *structurally*
337
+ * realistic; a consumer who
338
+ * needs their own codes supplies them.
339
+ *
340
+ * Nothing here is PHI — codes and their display text are not identifiers. The synthetic-safety
341
+ * invariant governs identity fields (name/DOB/SSN/MRN/phone/address), which come from `../safe`.
342
+ *
343
+ * @module
344
+ */
345
+ /** A coded concept: an identifier code, human-readable text, and its code system (HL7 `CE`/`CWE`). */
346
+ interface ExampleCode {
347
+ /** The code value (component 1). */
348
+ readonly code: string;
349
+ /** The human-readable display text (component 2). */
350
+ readonly text: string;
351
+ /** The coding-system id (component 3), e.g. `"LN"` (LOINC) or `"CVX"`. */
352
+ readonly system: string;
353
+ /** Reporting units (UCUM), where the concept is a measured quantity. */
354
+ readonly units?: string;
355
+ }
356
+ /**
357
+ * A handful of common LOINC laboratory-observation example codes (for `OBX`). Public LOINC identifiers
358
+ * used purely as illustrative structural fillers.
359
+ */
360
+ declare const EXAMPLE_LAB_OBSERVATIONS: readonly ExampleCode[];
361
+ /**
362
+ * A handful of LOINC panel/service example codes (for the `OBR`/`ORC` universal service id). Public
363
+ * identifiers used as structural fillers.
364
+ */
365
+ declare const EXAMPLE_ORDER_SERVICES: readonly ExampleCode[];
366
+ /**
367
+ * A handful of CDC CVX vaccine example codes (for `RXA-5`). Public CVX identifiers used as structural
368
+ * fillers; `@cosyte/synth` bundles no vaccine terminology.
369
+ */
370
+ declare const EXAMPLE_VACCINES: readonly ExampleCode[];
371
+
372
+ /**
373
+ * HL7 v2 **vendor-quirk generation**. A quirk deviates the
374
+ * *structure* of an otherwise spec-clean message so it round-trips through `@cosyte/hl7` to **exactly**
375
+ * one intended, stable warning code — the tolerance a `defineProfile` profile encodes. The deviation is
376
+ * applied **post-serialize**.
377
+ *
378
+ * Two publicly-groundable quirks ship (cited-public, never a private vendor corpus):
379
+ *
380
+ * - **`unknown-zsegment`** → `UNKNOWN_SEGMENT`. HL7 v2.x §2.5 permits site-defined `Z`-segments; a
381
+ * receiver with no profile flags them. `@cosyte/hl7`'s public imaging/PACS profiles (`visage`,
382
+ * `philips`, `va` — each grounded in a downloadable vendor/federal interface spec) declare `ZDS`, so a
383
+ * `defineProfile` that claims the segment **suppresses** the warning.
384
+ * - **`unknown-escape`** → `UNKNOWN_ESCAPE_SEQUENCE`. HL7 v2.x §2.7 escaping — a locally-defined
385
+ * `\Z..\` escape is preserved verbatim and flagged. HL7 v2 has no re-badge mechanism, so this is a
386
+ * `"bare"` quirk (no built-in profile downgrades it).
387
+ *
388
+ * A quirk **never** introduces a real-looking value — it changes the message *shape*, never the
389
+ * *provenance* of the data, so the synthetic-safety gate still runs and stays zero.
390
+ *
391
+ * @module
392
+ */
393
+
394
+ /** Every HL7 v2 quirk this package ships. */
395
+ type Hl7QuirkName = "unknown-zsegment" | "unknown-escape";
396
+ /** The HL7 v2 message families a quirk can be injected into (the spec-clean base). */
397
+ type Hl7QuirkKind = "ADT^A01" | "ADT^A04" | "ADT^A08" | "ORU^R01" | "ORM^O01" | "SIU^S12" | "VXU^V04";
398
+ /**
399
+ * The HL7 v2 quirk registry — each recipe bound to the exact `@cosyte/hl7` warning code it targets and
400
+ * its public grounding.
401
+ */
402
+ declare const HL7_QUIRKS: Readonly<Record<Hl7QuirkName, QuirkDescriptor>>;
403
+ /** Options for {@link generateHl7Quirk}. */
404
+ interface GenerateHl7QuirkOptions {
405
+ /** The seed — the same seed + quirk yields a byte-identical message. Defaults to `0`. */
406
+ readonly seed?: number;
407
+ /** The quirk to inject. Required. */
408
+ readonly quirk: Hl7QuirkName;
409
+ /** The spec-clean base message family. Defaults to `"ORU^R01"`. */
410
+ readonly kind?: Hl7QuirkKind;
411
+ }
412
+ /**
413
+ * Generate one HL7 v2 **quirk** artifact: a spec-clean message (built through `@cosyte/hl7`) with the
414
+ * requested vendor deviation injected post-serialize. Deterministic in `seed` + `quirk` + `kind`.
415
+ *
416
+ * @param options - Seed, quirk, and base kind. See {@link GenerateHl7QuirkOptions}.
417
+ * @returns The {@link QuirkArtifact} — its `content` round-trips to `intendedWarnings` exactly.
418
+ * @throws SynthError `SYNTH_UNSUPPORTED_QUIRK` if `quirk` is not a supported HL7 quirk.
419
+ * @example
420
+ * ```ts
421
+ * import { generateHl7Quirk, hl7QuirkRoundTrip } from "@cosyte/synth/hl7";
422
+ * const artifact = generateHl7Quirk({ seed: 1, quirk: "unknown-zsegment" });
423
+ * hl7QuirkRoundTrip(artifact).intendedWarningHeld; // true — exactly UNKNOWN_SEGMENT
424
+ * ```
425
+ */
426
+ declare function generateHl7Quirk(options: GenerateHl7QuirkOptions): QuirkArtifact;
427
+ /**
428
+ * Round-trip an HL7 v2 quirk artifact through `@cosyte/hl7` and report the intended-warning verdict: a bare
429
+ * parse must produce **exactly** the intended code(s), and — when a built-in public
430
+ * profile tolerates the quirk — the profiled parse must suppress it.
431
+ *
432
+ * @param artifact - The quirk artifact (from {@link generateHl7Quirk}).
433
+ * @returns The {@link QuirkRoundTripResult}.
434
+ * @example
435
+ * ```ts
436
+ * import { generateHl7Quirk, hl7QuirkRoundTrip } from "@cosyte/synth/hl7";
437
+ * const rt = hl7QuirkRoundTrip(generateHl7Quirk({ seed: 1, quirk: "unknown-zsegment" }));
438
+ * rt.withProfile?.tolerated; // true — the `visage` profile suppresses UNKNOWN_SEGMENT
439
+ * ```
440
+ */
441
+ declare function hl7QuirkRoundTrip(artifact: QuirkArtifact): QuirkRoundTripResult;
442
+ /** Options for {@link hl7QuirkCorpus}. */
443
+ interface Hl7QuirkCorpusOptions {
444
+ /** The seed for the whole corpus (deterministic). */
445
+ readonly seed: number;
446
+ /** How many quirk artifacts to generate. Defaults to the number of quirks. */
447
+ readonly count?: number;
448
+ /** The quirk names to cycle through. Defaults to every HL7 quirk. Validated; unsupported ⇒ fatal. */
449
+ readonly quirks?: readonly Hl7QuirkName[];
450
+ /** A {@link SynthProfile} whose `quirks` drive the corpus (validated). Takes precedence over `quirks`. */
451
+ readonly profile?: SynthProfile;
452
+ /** The base message family each quirk is injected into. Defaults to `"ORU^R01"`. */
453
+ readonly kind?: Hl7QuirkKind;
454
+ }
455
+ /**
456
+ * Build a reproducible {@link Corpus} of HL7 v2 quirk artifacts. Each artifact's `warnings` record the
457
+ * parser's verdict — the intended code(s) for its quirk (not empty: a quirk corpus is deliberately
458
+ * off-spec) — and the manifest lists the applied quirk names.
459
+ *
460
+ * @param options - Seed, count, and the quirk selection. See {@link Hl7QuirkCorpusOptions}.
461
+ * @returns A deep-frozen {@link Corpus}.
462
+ * @example
463
+ * ```ts
464
+ * import { hl7QuirkCorpus } from "@cosyte/synth/hl7";
465
+ * const corpus = hl7QuirkCorpus({ seed: 42 });
466
+ * corpus.manifest.quirks; // ["unknown-zsegment", "unknown-escape"]
467
+ * ```
468
+ */
469
+ declare function hl7QuirkCorpus(options: Hl7QuirkCorpusOptions): Corpus;
470
+ /**
471
+ * A ready-made {@link SynthProfile} that requests every built-in HL7 quirk — a convenience for wiring
472
+ * `defineSynthProfile`'s quirk list to the parser's real tolerance.
473
+ *
474
+ * @example
475
+ * ```ts
476
+ * import { hl7QuirkProfile, hl7QuirkCorpus } from "@cosyte/synth/hl7";
477
+ * hl7QuirkCorpus({ seed: 1, profile: hl7QuirkProfile });
478
+ * ```
479
+ */
480
+ declare const hl7QuirkProfile: SynthProfile;
481
+
482
+ /**
483
+ * `@cosyte/synth/hl7` — the HL7 v2 generation surface, exposed as its own subpath so importing the
484
+ * package root does **not** pull `@cosyte/hl7`. This is the **lazy, per-format** boundary: a consumer
485
+ * who only needs HL7 fixtures imports `@cosyte/synth/hl7`; one who needs only the core primitives
486
+ * never loads a parser.
487
+ * `@cosyte/hl7` is an **optional peer dependency** — present only for this subpath.
488
+ *
489
+ * The HL7 v2 message set is complete: `ADT` (A01/A04/A08), `ORU^R01`, `ORM^O01`, `SIU^S12`, and
490
+ * `VXU^V04` — each built through `@cosyte/hl7`'s `buildMessage` and round-tripping with zero warnings.
491
+ *
492
+ * @module
493
+ */
494
+
495
+ /**
496
+ * Every HL7 v2 message kind this subpath generates — the `MSH-9` label used as the corpus `kind`. `ADT`
497
+ * carries its trigger; the other families have a single generated trigger each.
498
+ */
499
+ type Hl7MessageKind = "ADT^A01" | "ADT^A04" | "ADT^A08" | "ORU^R01" | "ORM^O01" | "SIU^S12" | "VXU^V04";
500
+ /**
501
+ * Generate one message of the given {@link Hl7MessageKind} from a seed, dispatching to the right
502
+ * family generator. Every kind builds through `@cosyte/hl7` and is deterministic in `seed`.
503
+ *
504
+ * @param kind - The message kind to generate.
505
+ * @param seed - The seed.
506
+ * @returns The generated `Hl7Message`.
507
+ * @example
508
+ * ```ts
509
+ * import { generateHl7 } from "@cosyte/synth/hl7";
510
+ * generateHl7("ORU^R01", 42).toString();
511
+ * ```
512
+ */
513
+ declare function generateHl7(kind: Hl7MessageKind, seed: number): Hl7Message;
514
+ /** Options for {@link hl7Corpus}. */
515
+ interface Hl7CorpusOptions {
516
+ /** The seed for the whole corpus (deterministic). */
517
+ readonly seed: number;
518
+ /** How many messages to generate. Defaults to `1`. */
519
+ readonly count?: number;
520
+ /**
521
+ * The message kinds to cycle through. Defaults to one of every family
522
+ * (`ADT^A01/A04/A08`, `ORU^R01`, `ORM^O01`, `SIU^S12`, `VXU^V04`).
523
+ */
524
+ readonly mix?: readonly Hl7MessageKind[];
525
+ /**
526
+ * ADT-only convenience: the triggers to cycle through, kept for back-compat. When
527
+ * supplied it takes precedence over `mix` and restricts the corpus to `ADT` messages.
528
+ */
529
+ readonly triggers?: readonly AdtTrigger[];
530
+ }
531
+ /**
532
+ * Build a reproducible {@link Corpus} of spec-clean HL7 messages across the families. Each
533
+ * message is generated from a distinct sub-seed derived from the corpus seed (so the set is
534
+ * deterministic) and round-tripped through `@cosyte/hl7`; the per-artifact `warnings` record the
535
+ * parser's verdict (empty ⇒ spec-clean).
536
+ *
537
+ * @param options - Seed, count, and the message mix. See {@link Hl7CorpusOptions}.
538
+ * @returns A deep-frozen {@link Corpus}.
539
+ * @example
540
+ * ```ts
541
+ * import { hl7Corpus } from "@cosyte/synth/hl7";
542
+ * const corpus = hl7Corpus({ seed: 42, count: 7 });
543
+ * corpus.artifacts.every((a) => a.warnings.length === 0); // true — spec-clean
544
+ * ```
545
+ */
546
+ declare function hl7Corpus(options: Hl7CorpusOptions): Corpus;
547
+
548
+ export { type AdtTrigger, EXAMPLE_LAB_OBSERVATIONS, EXAMPLE_ORDER_SERVICES, EXAMPLE_VACCINES, type ExampleCode, type GenerateAdtOptions, type GenerateHl7QuirkOptions, type GenerateOrmOptions, type GenerateOruOptions, type GenerateSiuOptions, type GenerateVxuOptions, HL7_QUIRKS, type Hl7CorpusOptions, type Hl7MessageKind, type Hl7QuirkCorpusOptions, type Hl7QuirkKind, type Hl7QuirkName, type MessageScaffold, type PatientIdentity, type RoundTripResult, componentsField, generateAdt, generateHl7, generateHl7Quirk, generateOrm, generateOru, generateSiu, generateVxu, hl7Corpus, hl7QuirkCorpus, hl7QuirkProfile, hl7QuirkRoundTrip, mshScaffold, patientIdentity, pidSegment, roundTrip, seededTimestamp };