@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
@@ -1,6 +1,15 @@
1
1
  'use strict';
2
2
 
3
- var hl7 = require('@cosyte/hl7');
3
+ var module$1 = require('module');
4
+ var url = require('url');
5
+
6
+ var _documentCurrentScript = typeof document !== 'undefined' ? document.currentScript : null;
7
+ var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
8
+ get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
9
+ }) : x)(function(x) {
10
+ if (typeof require !== "undefined") return require.apply(this, arguments);
11
+ throw Error('Dynamic require of "' + x + '" is not supported');
12
+ });
4
13
 
5
14
  // src/rng/splitmix32.ts
6
15
  function splitmix32(seed) {
@@ -150,6 +159,7 @@ function createRng(seed) {
150
159
  }
151
160
 
152
161
  // src/corpus.ts
162
+ var UNCHECKED = Object.freeze([]);
153
163
  function makeCorpus(seed, artifacts, quirks = []) {
154
164
  const counts = {};
155
165
  const formats = /* @__PURE__ */ new Set();
@@ -461,6 +471,30 @@ var safe = Object.freeze({
461
471
  npi,
462
472
  dea
463
473
  });
474
+ function defaultHost() {
475
+ if (typeof undefined !== "function") return { require: __require, resolve: void 0 };
476
+ return { require: module$1.createRequire((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('index.cjs', document.baseURI).href))), resolve: (s) => undefined(s) };
477
+ }
478
+ function isRequireEsmRefusal(error) {
479
+ return error?.code === "ERR_REQUIRE_ESM";
480
+ }
481
+ function loadPeer(specifier, host) {
482
+ if (host.resolve === void 0) return host.require(specifier);
483
+ const entry = url.fileURLToPath(host.resolve(specifier));
484
+ try {
485
+ return host.require(entry);
486
+ } catch (error) {
487
+ if (!isRequireEsmRefusal(error)) throw error;
488
+ return host.require(specifier);
489
+ }
490
+ }
491
+ function lazyPeer(specifier, host) {
492
+ let loaded;
493
+ return () => loaded ??= loadPeer(specifier, defaultHost());
494
+ }
495
+
496
+ // src/peers.ts
497
+ var hl7Peer = lazyPeer("@cosyte/hl7");
464
498
 
465
499
  // src/hl7/common.ts
466
500
  function seededTimestamp(rng) {
@@ -473,7 +507,7 @@ function seededTimestamp(rng) {
473
507
  function mshScaffold(rng, type) {
474
508
  const timestamp = seededTimestamp(rng);
475
509
  const controlId = `SYNTH${rng.digits(10)}`;
476
- const message = hl7.buildMessage({
510
+ const message = hl7Peer().buildMessage({
477
511
  type,
478
512
  sendingApp: "COSYTE-SYNTH",
479
513
  sendingFacility: "SYNTH-FAC",
@@ -826,9 +860,11 @@ function generateVxu(options = {}) {
826
860
  ]);
827
861
  return message;
828
862
  }
863
+
864
+ // src/hl7/round-trip.ts
829
865
  function roundTrip(message) {
830
866
  const content = message.toString();
831
- const reparsed = hl7.parseHL7(content);
867
+ const reparsed = hl7Peer().parseHL7(content);
832
868
  const warnings = reparsed.warnings.map((w) => String(w.code));
833
869
  const byteStable = reparsed.toString() === content;
834
870
  return {
@@ -838,6 +874,14 @@ function roundTrip(message) {
838
874
  specClean: warnings.length === 0 && byteStable
839
875
  };
840
876
  }
877
+ function hl7CorpusArtifact(message, verify) {
878
+ const content = message.toString();
879
+ if (!verify) return { content, warnings: UNCHECKED };
880
+ return {
881
+ content,
882
+ warnings: hl7Peer().parseHL7(content).warnings.map((w) => String(w.code))
883
+ };
884
+ }
841
885
 
842
886
  // src/profile.ts
843
887
  function defineSynthProfile(spec) {
@@ -913,7 +957,7 @@ var HL7_QUIRKS = Object.freeze({
913
957
  })
914
958
  });
915
959
  function toleratingProfile(quirk) {
916
- return quirk === "unknown-zsegment" ? hl7.profiles.visage : void 0;
960
+ return quirk === "unknown-zsegment" ? hl7Peer().profiles.visage : void 0;
917
961
  }
918
962
  function segmentsOf(wire) {
919
963
  return wire.split(/\r\n|\r|\n/).filter((s) => s.length > 0);
@@ -961,7 +1005,7 @@ function generateHl7Quirk(options) {
961
1005
  const content = applyQuirk(options.quirk, baseMessage(kind, seed).toString());
962
1006
  assertIntendedWarnings(
963
1007
  descriptor.intendedWarnings,
964
- hl7.parseHL7(content).warnings.map((w) => String(w.code))
1008
+ hl7Peer().parseHL7(content).warnings.map((w) => String(w.code))
965
1009
  );
966
1010
  return Object.freeze({
967
1011
  format: "hl7v2",
@@ -974,12 +1018,12 @@ function generateHl7Quirk(options) {
974
1018
  function hl7QuirkRoundTrip(artifact) {
975
1019
  const quirk = artifact.quirk;
976
1020
  const descriptor = resolveQuirk(HL7_QUIRKS, "hl7v2", quirk);
977
- const bare = hl7.parseHL7(artifact.content).warnings.map((w) => String(w.code));
1021
+ const bare = hl7Peer().parseHL7(artifact.content).warnings.map((w) => String(w.code));
978
1022
  const profile = toleratingProfile(quirk);
979
1023
  const withProfile = profile !== void 0 && descriptor.toleratingProfile !== void 0 ? {
980
1024
  profileName: descriptor.toleratingProfile,
981
1025
  disposition: descriptor.disposition,
982
- warnings: hl7.parseHL7(artifact.content, profile).warnings.map((w) => String(w.code)),
1026
+ warnings: hl7Peer().parseHL7(artifact.content, profile).warnings.map((w) => String(w.code)),
983
1027
  tolerated: false
984
1028
  } : void 0;
985
1029
  return {
@@ -1058,7 +1102,7 @@ function generateHl7(kind, seed) {
1058
1102
  }
1059
1103
  }
1060
1104
  function hl7Corpus(options) {
1061
- const { seed, count = 1 } = options;
1105
+ const { seed, count = 1, verify = true } = options;
1062
1106
  const kinds = options.triggers !== void 0 ? options.triggers.map(
1063
1107
  (t) => `ADT^${resolveKind(ADT_TRIGGERS2, t)}`
1064
1108
  ) : resolveMix(ALL_KINDS, options.mix, DEFAULT_MIX);
@@ -1066,7 +1110,7 @@ function hl7Corpus(options) {
1066
1110
  const artifacts = Array.from({ length: count }, (_unused, i) => {
1067
1111
  const kind = kinds[i % kinds.length] ?? "ADT^A01";
1068
1112
  const messageSeed = seedStream.nextUint32();
1069
- const rt = roundTrip(generateHl7(kind, messageSeed));
1113
+ const rt = hl7CorpusArtifact(generateHl7(kind, messageSeed), verify);
1070
1114
  return {
1071
1115
  format: "hl7v2",
1072
1116
  kind,