@cosyte/synth 0.1.5 → 0.1.7

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 (46) hide show
  1. package/CHANGELOG.md +30 -0
  2. package/dist/astm/index.cjs +57 -19
  3. package/dist/astm/index.cjs.map +1 -1
  4. package/dist/astm/index.d.cts +7 -0
  5. package/dist/astm/index.d.ts +7 -0
  6. package/dist/astm/index.mjs +56 -19
  7. package/dist/astm/index.mjs.map +1 -1
  8. package/dist/ccda/index.cjs +76 -26
  9. package/dist/ccda/index.cjs.map +1 -1
  10. package/dist/ccda/index.d.cts +6 -0
  11. package/dist/ccda/index.d.ts +6 -0
  12. package/dist/ccda/index.mjs +63 -14
  13. package/dist/ccda/index.mjs.map +1 -1
  14. package/dist/deid/index.cjs +216 -125
  15. package/dist/deid/index.cjs.map +1 -1
  16. package/dist/deid/index.mjs +203 -113
  17. package/dist/deid/index.mjs.map +1 -1
  18. package/dist/fhir/index.cjs +146 -74
  19. package/dist/fhir/index.cjs.map +1 -1
  20. package/dist/fhir/index.d.cts +6 -0
  21. package/dist/fhir/index.d.ts +6 -0
  22. package/dist/fhir/index.mjs +145 -74
  23. package/dist/fhir/index.mjs.map +1 -1
  24. package/dist/hl7/index.cjs +53 -9
  25. package/dist/hl7/index.cjs.map +1 -1
  26. package/dist/hl7/index.d.cts +6 -0
  27. package/dist/hl7/index.d.ts +6 -0
  28. package/dist/hl7/index.mjs +52 -9
  29. package/dist/hl7/index.mjs.map +1 -1
  30. package/dist/index.cjs +1 -3
  31. package/dist/index.cjs.map +1 -1
  32. package/dist/index.mjs +1 -3
  33. package/dist/index.mjs.map +1 -1
  34. package/dist/ncpdp/index.cjs +76 -23
  35. package/dist/ncpdp/index.cjs.map +1 -1
  36. package/dist/ncpdp/index.d.cts +7 -0
  37. package/dist/ncpdp/index.d.ts +7 -0
  38. package/dist/ncpdp/index.mjs +75 -23
  39. package/dist/ncpdp/index.mjs.map +1 -1
  40. package/dist/x12/index.cjs +72 -23
  41. package/dist/x12/index.cjs.map +1 -1
  42. package/dist/x12/index.d.cts +8 -1
  43. package/dist/x12/index.d.ts +8 -1
  44. package/dist/x12/index.mjs +71 -23
  45. package/dist/x12/index.mjs.map +1 -1
  46. package/package.json +20 -15
@@ -527,6 +527,12 @@ interface Hl7CorpusOptions {
527
527
  * supplied it takes precedence over `mix` and restricts the corpus to `ADT` messages.
528
528
  */
529
529
  readonly triggers?: readonly AdtTrigger[];
530
+ /**
531
+ * Whether each artifact is read back through its parser and the parser's findings recorded as its
532
+ * `warnings`. Defaults to `true`. `false` skips the read, a large share of a corpus's time; every
533
+ * artifact's `warnings` is then empty without having been checked.
534
+ */
535
+ readonly verify?: boolean;
530
536
  }
531
537
  /**
532
538
  * Build a reproducible {@link Corpus} of spec-clean HL7 messages across the families. Each
@@ -527,6 +527,12 @@ interface Hl7CorpusOptions {
527
527
  * supplied it takes precedence over `mix` and restricts the corpus to `ADT` messages.
528
528
  */
529
529
  readonly triggers?: readonly AdtTrigger[];
530
+ /**
531
+ * Whether each artifact is read back through its parser and the parser's findings recorded as its
532
+ * `warnings`. Defaults to `true`. `false` skips the read, a large share of a corpus's time; every
533
+ * artifact's `warnings` is then empty without having been checked.
534
+ */
535
+ readonly verify?: boolean;
530
536
  }
531
537
  /**
532
538
  * Build a reproducible {@link Corpus} of spec-clean HL7 messages across the families. Each
@@ -1,4 +1,12 @@
1
- import { buildMessage, parseHL7, profiles } from '@cosyte/hl7';
1
+ import { createRequire } from 'module';
2
+ import { fileURLToPath } from 'url';
3
+
4
+ var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
5
+ get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
6
+ }) : x)(function(x) {
7
+ if (typeof require !== "undefined") return require.apply(this, arguments);
8
+ throw Error('Dynamic require of "' + x + '" is not supported');
9
+ });
2
10
 
3
11
  // src/rng/splitmix32.ts
4
12
  function splitmix32(seed) {
@@ -148,6 +156,7 @@ function createRng(seed) {
148
156
  }
149
157
 
150
158
  // src/corpus.ts
159
+ var UNCHECKED = Object.freeze([]);
151
160
  function makeCorpus(seed, artifacts, quirks = []) {
152
161
  const counts = {};
153
162
  const formats = /* @__PURE__ */ new Set();
@@ -459,6 +468,30 @@ var safe = Object.freeze({
459
468
  npi,
460
469
  dea
461
470
  });
471
+ function defaultHost() {
472
+ if (typeof import.meta.resolve !== "function") return { require: __require, resolve: void 0 };
473
+ return { require: createRequire(import.meta.url), resolve: (s) => import.meta.resolve(s) };
474
+ }
475
+ function isRequireEsmRefusal(error) {
476
+ return error?.code === "ERR_REQUIRE_ESM";
477
+ }
478
+ function loadPeer(specifier, host) {
479
+ if (host.resolve === void 0) return host.require(specifier);
480
+ const entry = fileURLToPath(host.resolve(specifier));
481
+ try {
482
+ return host.require(entry);
483
+ } catch (error) {
484
+ if (!isRequireEsmRefusal(error)) throw error;
485
+ return host.require(specifier);
486
+ }
487
+ }
488
+ function lazyPeer(specifier, host) {
489
+ let loaded;
490
+ return () => loaded ??= loadPeer(specifier, defaultHost());
491
+ }
492
+
493
+ // src/peers.ts
494
+ var hl7Peer = lazyPeer("@cosyte/hl7");
462
495
 
463
496
  // src/hl7/common.ts
464
497
  function seededTimestamp(rng) {
@@ -471,7 +504,7 @@ function seededTimestamp(rng) {
471
504
  function mshScaffold(rng, type) {
472
505
  const timestamp = seededTimestamp(rng);
473
506
  const controlId = `SYNTH${rng.digits(10)}`;
474
- const message = buildMessage({
507
+ const message = hl7Peer().buildMessage({
475
508
  type,
476
509
  sendingApp: "COSYTE-SYNTH",
477
510
  sendingFacility: "SYNTH-FAC",
@@ -824,9 +857,11 @@ function generateVxu(options = {}) {
824
857
  ]);
825
858
  return message;
826
859
  }
860
+
861
+ // src/hl7/round-trip.ts
827
862
  function roundTrip(message) {
828
863
  const content = message.toString();
829
- const reparsed = parseHL7(content);
864
+ const reparsed = hl7Peer().parseHL7(content);
830
865
  const warnings = reparsed.warnings.map((w) => String(w.code));
831
866
  const byteStable = reparsed.toString() === content;
832
867
  return {
@@ -836,6 +871,14 @@ function roundTrip(message) {
836
871
  specClean: warnings.length === 0 && byteStable
837
872
  };
838
873
  }
874
+ function hl7CorpusArtifact(message, verify) {
875
+ const content = message.toString();
876
+ if (!verify) return { content, warnings: UNCHECKED };
877
+ return {
878
+ content,
879
+ warnings: hl7Peer().parseHL7(content).warnings.map((w) => String(w.code))
880
+ };
881
+ }
839
882
 
840
883
  // src/profile.ts
841
884
  function defineSynthProfile(spec) {
@@ -911,7 +954,7 @@ var HL7_QUIRKS = Object.freeze({
911
954
  })
912
955
  });
913
956
  function toleratingProfile(quirk) {
914
- return quirk === "unknown-zsegment" ? profiles.visage : void 0;
957
+ return quirk === "unknown-zsegment" ? hl7Peer().profiles.visage : void 0;
915
958
  }
916
959
  function segmentsOf(wire) {
917
960
  return wire.split(/\r\n|\r|\n/).filter((s) => s.length > 0);
@@ -959,7 +1002,7 @@ function generateHl7Quirk(options) {
959
1002
  const content = applyQuirk(options.quirk, baseMessage(kind, seed).toString());
960
1003
  assertIntendedWarnings(
961
1004
  descriptor.intendedWarnings,
962
- parseHL7(content).warnings.map((w) => String(w.code))
1005
+ hl7Peer().parseHL7(content).warnings.map((w) => String(w.code))
963
1006
  );
964
1007
  return Object.freeze({
965
1008
  format: "hl7v2",
@@ -972,12 +1015,12 @@ function generateHl7Quirk(options) {
972
1015
  function hl7QuirkRoundTrip(artifact) {
973
1016
  const quirk = artifact.quirk;
974
1017
  const descriptor = resolveQuirk(HL7_QUIRKS, "hl7v2", quirk);
975
- const bare = parseHL7(artifact.content).warnings.map((w) => String(w.code));
1018
+ const bare = hl7Peer().parseHL7(artifact.content).warnings.map((w) => String(w.code));
976
1019
  const profile = toleratingProfile(quirk);
977
1020
  const withProfile = profile !== void 0 && descriptor.toleratingProfile !== void 0 ? {
978
1021
  profileName: descriptor.toleratingProfile,
979
1022
  disposition: descriptor.disposition,
980
- warnings: parseHL7(artifact.content, profile).warnings.map((w) => String(w.code)),
1023
+ warnings: hl7Peer().parseHL7(artifact.content, profile).warnings.map((w) => String(w.code)),
981
1024
  tolerated: false
982
1025
  } : void 0;
983
1026
  return {
@@ -1056,7 +1099,7 @@ function generateHl7(kind, seed) {
1056
1099
  }
1057
1100
  }
1058
1101
  function hl7Corpus(options) {
1059
- const { seed, count = 1 } = options;
1102
+ const { seed, count = 1, verify = true } = options;
1060
1103
  const kinds = options.triggers !== void 0 ? options.triggers.map(
1061
1104
  (t) => `ADT^${resolveKind(ADT_TRIGGERS2, t)}`
1062
1105
  ) : resolveMix(ALL_KINDS, options.mix, DEFAULT_MIX);
@@ -1064,7 +1107,7 @@ function hl7Corpus(options) {
1064
1107
  const artifacts = Array.from({ length: count }, (_unused, i) => {
1065
1108
  const kind = kinds[i % kinds.length] ?? "ADT^A01";
1066
1109
  const messageSeed = seedStream.nextUint32();
1067
- const rt = roundTrip(generateHl7(kind, messageSeed));
1110
+ const rt = hl7CorpusArtifact(generateHl7(kind, messageSeed), verify);
1068
1111
  return {
1069
1112
  format: "hl7v2",
1070
1113
  kind,