@cosyte/synth 0.1.5 → 0.1.6
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 +12 -0
- package/dist/astm/index.cjs +55 -18
- package/dist/astm/index.cjs.map +1 -1
- package/dist/astm/index.d.cts +7 -0
- package/dist/astm/index.d.ts +7 -0
- package/dist/astm/index.mjs +54 -18
- package/dist/astm/index.mjs.map +1 -1
- package/dist/ccda/index.cjs +76 -26
- package/dist/ccda/index.cjs.map +1 -1
- package/dist/ccda/index.d.cts +6 -0
- package/dist/ccda/index.d.ts +6 -0
- package/dist/ccda/index.mjs +63 -14
- package/dist/ccda/index.mjs.map +1 -1
- package/dist/deid/index.cjs +207 -118
- package/dist/deid/index.cjs.map +1 -1
- package/dist/deid/index.mjs +194 -106
- package/dist/deid/index.mjs.map +1 -1
- package/dist/fhir/index.cjs +146 -74
- package/dist/fhir/index.cjs.map +1 -1
- package/dist/fhir/index.d.cts +6 -0
- package/dist/fhir/index.d.ts +6 -0
- package/dist/fhir/index.mjs +145 -74
- package/dist/fhir/index.mjs.map +1 -1
- package/dist/hl7/index.cjs +53 -9
- package/dist/hl7/index.cjs.map +1 -1
- package/dist/hl7/index.d.cts +6 -0
- package/dist/hl7/index.d.ts +6 -0
- package/dist/hl7/index.mjs +52 -9
- package/dist/hl7/index.mjs.map +1 -1
- package/dist/index.cjs +1 -3
- package/dist/index.cjs.map +1 -1
- package/dist/index.mjs +1 -3
- package/dist/index.mjs.map +1 -1
- package/dist/ncpdp/index.cjs +74 -22
- package/dist/ncpdp/index.cjs.map +1 -1
- package/dist/ncpdp/index.d.cts +7 -0
- package/dist/ncpdp/index.d.ts +7 -0
- package/dist/ncpdp/index.mjs +73 -22
- package/dist/ncpdp/index.mjs.map +1 -1
- package/dist/x12/index.cjs +65 -17
- package/dist/x12/index.cjs.map +1 -1
- package/dist/x12/index.d.cts +6 -0
- package/dist/x12/index.d.ts +6 -0
- package/dist/x12/index.mjs +64 -17
- package/dist/x12/index.mjs.map +1 -1
- package/package.json +20 -15
package/dist/hl7/index.cjs
CHANGED
|
@@ -1,6 +1,15 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
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 =
|
|
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 =
|
|
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" ?
|
|
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
|
-
|
|
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 =
|
|
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:
|
|
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 =
|
|
1113
|
+
const rt = hl7CorpusArtifact(generateHl7(kind, messageSeed), verify);
|
|
1070
1114
|
return {
|
|
1071
1115
|
format: "hl7v2",
|
|
1072
1116
|
kind,
|