@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/ccda/index.d.cts
CHANGED
|
@@ -362,6 +362,12 @@ interface CcdaCorpusOptions {
|
|
|
362
362
|
readonly count?: number;
|
|
363
363
|
/** The document types to cycle through. Defaults to one CCD + one Referral Note. */
|
|
364
364
|
readonly mix?: readonly CcdaCorpusKind[];
|
|
365
|
+
/**
|
|
366
|
+
* Whether each artifact is read back through its parser and the parser's findings recorded as its
|
|
367
|
+
* `warnings`. Defaults to `true`. `false` skips the read, a large share of a corpus's time; every
|
|
368
|
+
* artifact's `warnings` is then empty without having been checked.
|
|
369
|
+
*/
|
|
370
|
+
readonly verify?: boolean;
|
|
365
371
|
}
|
|
366
372
|
/**
|
|
367
373
|
* Build a reproducible {@link Corpus} of spec-clean C-CDA documents. Each document is generated from a
|
package/dist/ccda/index.d.ts
CHANGED
|
@@ -362,6 +362,12 @@ interface CcdaCorpusOptions {
|
|
|
362
362
|
readonly count?: number;
|
|
363
363
|
/** The document types to cycle through. Defaults to one CCD + one Referral Note. */
|
|
364
364
|
readonly mix?: readonly CcdaCorpusKind[];
|
|
365
|
+
/**
|
|
366
|
+
* Whether each artifact is read back through its parser and the parser's findings recorded as its
|
|
367
|
+
* `warnings`. Defaults to `true`. `false` skips the read, a large share of a corpus's time; every
|
|
368
|
+
* artifact's `warnings` is then empty without having been checked.
|
|
369
|
+
*/
|
|
370
|
+
readonly verify?: boolean;
|
|
365
371
|
}
|
|
366
372
|
/**
|
|
367
373
|
* Build a reproducible {@link Corpus} of spec-clean C-CDA documents. Each document is generated from a
|
package/dist/ccda/index.mjs
CHANGED
|
@@ -1,4 +1,12 @@
|
|
|
1
|
-
import {
|
|
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();
|
|
@@ -758,6 +767,16 @@ Object.freeze([
|
|
|
758
767
|
]);
|
|
759
768
|
|
|
760
769
|
// src/ccda/example-codes.ts
|
|
770
|
+
var LOINC_OID = "2.16.840.1.113883.6.1";
|
|
771
|
+
var SNOMED_CT_OID = "2.16.840.1.113883.6.96";
|
|
772
|
+
var RXNORM_OID = "2.16.840.1.113883.6.88";
|
|
773
|
+
var CVX_OID = "2.16.840.1.113883.12.292";
|
|
774
|
+
var NCI_ROUTE_OID = "2.16.840.1.113883.3.26.1.1";
|
|
775
|
+
var LOINC = LOINC_OID;
|
|
776
|
+
var SNOMED_CT = SNOMED_CT_OID;
|
|
777
|
+
var RXNORM = RXNORM_OID;
|
|
778
|
+
var CVX = CVX_OID;
|
|
779
|
+
var NCI_ROUTE = NCI_ROUTE_OID;
|
|
761
780
|
var URI_TO_OID = Object.freeze({
|
|
762
781
|
"http://loinc.org": LOINC,
|
|
763
782
|
"http://snomed.info/sct": SNOMED_CT,
|
|
@@ -834,6 +853,28 @@ function resolveMix(allowed, requested, fallback) {
|
|
|
834
853
|
if (requested === void 0) return fallback;
|
|
835
854
|
return requested.map((entry) => resolveKind(allowed, entry));
|
|
836
855
|
}
|
|
856
|
+
function defaultHost() {
|
|
857
|
+
if (typeof import.meta.resolve !== "function") return { require: __require, resolve: void 0 };
|
|
858
|
+
return { require: createRequire(import.meta.url), resolve: (s) => import.meta.resolve(s) };
|
|
859
|
+
}
|
|
860
|
+
function isRequireEsmRefusal(error) {
|
|
861
|
+
return error?.code === "ERR_REQUIRE_ESM";
|
|
862
|
+
}
|
|
863
|
+
function loadPeer(specifier, host) {
|
|
864
|
+
if (host.resolve === void 0) return host.require(specifier);
|
|
865
|
+
const entry = fileURLToPath(host.resolve(specifier));
|
|
866
|
+
try {
|
|
867
|
+
return host.require(entry);
|
|
868
|
+
} catch (error) {
|
|
869
|
+
if (!isRequireEsmRefusal(error)) throw error;
|
|
870
|
+
return host.require(specifier);
|
|
871
|
+
}
|
|
872
|
+
}
|
|
873
|
+
function lazyPeer(specifier, host) {
|
|
874
|
+
let loaded;
|
|
875
|
+
return () => loaded ??= loadPeer(specifier, defaultHost());
|
|
876
|
+
}
|
|
877
|
+
var ccdaPeer = lazyPeer("@cosyte/ccda");
|
|
837
878
|
|
|
838
879
|
// src/ccda/ccd.ts
|
|
839
880
|
var CCDA_DOCUMENT_TYPES = Object.freeze(["ccd", "referralNote"]);
|
|
@@ -922,7 +963,7 @@ function generateCcda(options = {}) {
|
|
|
922
963
|
const { seed = 0 } = options;
|
|
923
964
|
const documentType = resolveKind(CCDA_DOCUMENT_TYPES, options.documentType ?? "ccd");
|
|
924
965
|
const rng = createRng(seed);
|
|
925
|
-
return buildCcda(buildInit(rng, documentType));
|
|
966
|
+
return ccdaPeer().buildCcda(buildInit(rng, documentType));
|
|
926
967
|
}
|
|
927
968
|
function generateCcd(options = {}) {
|
|
928
969
|
return generateCcda({ ...options, documentType: "ccd" });
|
|
@@ -930,11 +971,13 @@ function generateCcd(options = {}) {
|
|
|
930
971
|
function generateReferralNote(options = {}) {
|
|
931
972
|
return generateCcda({ ...options, documentType: "referralNote" });
|
|
932
973
|
}
|
|
974
|
+
|
|
975
|
+
// src/ccda/round-trip.ts
|
|
933
976
|
function roundTrip(doc) {
|
|
934
|
-
const content = serializeCcda(doc);
|
|
935
|
-
const reparsed = parseCcda(content);
|
|
977
|
+
const content = ccdaPeer().serializeCcda(doc);
|
|
978
|
+
const reparsed = ccdaPeer().parseCcda(content);
|
|
936
979
|
const warnings = reparsed.warnings.map((w) => String(w.code));
|
|
937
|
-
const byteStable = serializeCcda(reparsed) === content;
|
|
980
|
+
const byteStable = ccdaPeer().serializeCcda(reparsed) === content;
|
|
938
981
|
return {
|
|
939
982
|
content,
|
|
940
983
|
warnings,
|
|
@@ -942,6 +985,14 @@ function roundTrip(doc) {
|
|
|
942
985
|
specClean: warnings.length === 0 && byteStable
|
|
943
986
|
};
|
|
944
987
|
}
|
|
988
|
+
function ccdaCorpusArtifact(doc, verify) {
|
|
989
|
+
const content = ccdaPeer().serializeCcda(doc);
|
|
990
|
+
if (!verify) return { content, warnings: UNCHECKED };
|
|
991
|
+
return {
|
|
992
|
+
content,
|
|
993
|
+
warnings: ccdaPeer().parseCcda(content).warnings.map((w) => String(w.code))
|
|
994
|
+
};
|
|
995
|
+
}
|
|
945
996
|
|
|
946
997
|
// src/profile.ts
|
|
947
998
|
function defineSynthProfile(spec) {
|
|
@@ -1026,7 +1077,7 @@ var CCDA_QUIRKS = Object.freeze({
|
|
|
1026
1077
|
})
|
|
1027
1078
|
});
|
|
1028
1079
|
function toleratingProfile(quirk) {
|
|
1029
|
-
return quirk === "template-extension-absent" ? ccdaProfiles.legacyR11 : ccdaProfiles.smartScorecard;
|
|
1080
|
+
return quirk === "template-extension-absent" ? ccdaPeer().ccdaProfiles.legacyR11 : ccdaPeer().ccdaProfiles.smartScorecard;
|
|
1030
1081
|
}
|
|
1031
1082
|
var DOC_TEMPLATE_ROOTS = [
|
|
1032
1083
|
"2.16.840.1.113883.10.20.22.1.1",
|
|
@@ -1066,11 +1117,11 @@ function generateCcdaQuirk(options) {
|
|
|
1066
1117
|
const seed = options.seed ?? 0;
|
|
1067
1118
|
const documentType = options.documentType ?? "ccd";
|
|
1068
1119
|
const descriptor = resolveQuirk(CCDA_QUIRKS, "ccda", options.quirk);
|
|
1069
|
-
const clean = serializeCcda(generateCcda({ seed, documentType }));
|
|
1120
|
+
const clean = ccdaPeer().serializeCcda(generateCcda({ seed, documentType }));
|
|
1070
1121
|
const content = injectCcdaQuirk(options.quirk, clean);
|
|
1071
1122
|
assertIntendedWarnings(
|
|
1072
1123
|
descriptor.intendedWarnings,
|
|
1073
|
-
parseCcda(content).warnings.map((w) => String(w.code))
|
|
1124
|
+
ccdaPeer().parseCcda(content).warnings.map((w) => String(w.code))
|
|
1074
1125
|
);
|
|
1075
1126
|
return Object.freeze({
|
|
1076
1127
|
format: "ccda",
|
|
@@ -1083,11 +1134,9 @@ function generateCcdaQuirk(options) {
|
|
|
1083
1134
|
function ccdaQuirkRoundTrip(artifact) {
|
|
1084
1135
|
const quirk = artifact.quirk;
|
|
1085
1136
|
const descriptor = resolveQuirk(CCDA_QUIRKS, "ccda", quirk);
|
|
1086
|
-
const bare = parseCcda(artifact.content).warnings.map((w) => String(w.code));
|
|
1137
|
+
const bare = ccdaPeer().parseCcda(artifact.content).warnings.map((w) => String(w.code));
|
|
1087
1138
|
const profile = toleratingProfile(quirk);
|
|
1088
|
-
const profiledWarnings = parseCcda(artifact.content, { profile }).warnings.map(
|
|
1089
|
-
(w) => String(w.code)
|
|
1090
|
-
);
|
|
1139
|
+
const profiledWarnings = ccdaPeer().parseCcda(artifact.content, { profile }).warnings.map((w) => String(w.code));
|
|
1091
1140
|
return {
|
|
1092
1141
|
content: artifact.content,
|
|
1093
1142
|
warnings: bare,
|
|
@@ -1138,13 +1187,13 @@ var ccdaQuirkProfile = defineSynthProfile({
|
|
|
1138
1187
|
var ALL_KINDS = Object.freeze(["ccd", "referralNote"]);
|
|
1139
1188
|
var DEFAULT_MIX = ALL_KINDS;
|
|
1140
1189
|
function ccdaCorpus(options) {
|
|
1141
|
-
const { seed, count = 1 } = options;
|
|
1190
|
+
const { seed, count = 1, verify = true } = options;
|
|
1142
1191
|
const mix = resolveMix(ALL_KINDS, options.mix, DEFAULT_MIX);
|
|
1143
1192
|
const seedStream = createRng(seed);
|
|
1144
1193
|
const artifacts = Array.from({ length: count }, (_unused, i) => {
|
|
1145
1194
|
const documentType = mix[i % mix.length] ?? "ccd";
|
|
1146
1195
|
const docSeed = seedStream.nextUint32();
|
|
1147
|
-
const rt =
|
|
1196
|
+
const rt = ccdaCorpusArtifact(generateCcda({ seed: docSeed, documentType }), verify);
|
|
1148
1197
|
return {
|
|
1149
1198
|
format: "ccda",
|
|
1150
1199
|
kind: documentType,
|