@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.
- package/CHANGELOG.md +30 -0
- package/dist/astm/index.cjs +57 -19
- 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 +56 -19
- 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 +216 -125
- package/dist/deid/index.cjs.map +1 -1
- package/dist/deid/index.mjs +203 -113
- 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 +76 -23
- 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 +75 -23
- package/dist/ncpdp/index.mjs.map +1 -1
- package/dist/x12/index.cjs +72 -23
- package/dist/x12/index.cjs.map +1 -1
- package/dist/x12/index.d.cts +8 -1
- package/dist/x12/index.d.ts +8 -1
- package/dist/x12/index.mjs +71 -23
- package/dist/x12/index.mjs.map +1 -1
- package/package.json +20 -15
package/dist/fhir/index.d.cts
CHANGED
|
@@ -397,6 +397,12 @@ interface FhirCorpusOptions {
|
|
|
397
397
|
readonly count?: number;
|
|
398
398
|
/** The resource kinds to cycle through. Defaults to the full US Core clinical spine + a Bundle. */
|
|
399
399
|
readonly mix?: readonly FhirResourceKind[];
|
|
400
|
+
/**
|
|
401
|
+
* Whether each artifact is read back through its parser and the parser's findings recorded as its
|
|
402
|
+
* `warnings`. Defaults to `true`. `false` skips the read, a large share of a corpus's time; every
|
|
403
|
+
* artifact's `warnings` is then empty without having been checked.
|
|
404
|
+
*/
|
|
405
|
+
readonly verify?: boolean;
|
|
400
406
|
}
|
|
401
407
|
/**
|
|
402
408
|
* Build a reproducible {@link Corpus} of spec-clean FHIR resources across the supported kinds. Each
|
package/dist/fhir/index.d.ts
CHANGED
|
@@ -397,6 +397,12 @@ interface FhirCorpusOptions {
|
|
|
397
397
|
readonly count?: number;
|
|
398
398
|
/** The resource kinds to cycle through. Defaults to the full US Core clinical spine + a Bundle. */
|
|
399
399
|
readonly mix?: readonly FhirResourceKind[];
|
|
400
|
+
/**
|
|
401
|
+
* Whether each artifact is read back through its parser and the parser's findings recorded as its
|
|
402
|
+
* `warnings`. Defaults to `true`. `false` skips the read, a large share of a corpus's time; every
|
|
403
|
+
* artifact's `warnings` is then empty without having been checked.
|
|
404
|
+
*/
|
|
405
|
+
readonly verify?: boolean;
|
|
400
406
|
}
|
|
401
407
|
/**
|
|
402
408
|
* Build a reproducible {@link Corpus} of spec-clean FHIR resources across the supported kinds. Each
|
package/dist/fhir/index.mjs
CHANGED
|
@@ -1,6 +1,12 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { createRequire } from 'module';
|
|
2
|
+
import { fileURLToPath } from 'url';
|
|
2
3
|
|
|
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
|
+
});
|
|
4
10
|
|
|
5
11
|
// src/rng/splitmix32.ts
|
|
6
12
|
function splitmix32(seed) {
|
|
@@ -551,42 +557,64 @@ var SYSTEM = Object.freeze({
|
|
|
551
557
|
/** US Core `us-core-provenance-participant-type`, `Provenance.agent.type` (`transmitter`). */
|
|
552
558
|
US_CORE_PROVENANCE_PARTICIPANT_TYPE: "http://hl7.org/fhir/us/core/CodeSystem/us-core-provenance-participant-type"
|
|
553
559
|
});
|
|
560
|
+
function defaultHost() {
|
|
561
|
+
if (typeof import.meta.resolve !== "function") return { require: __require, resolve: void 0 };
|
|
562
|
+
return { require: createRequire(import.meta.url), resolve: (s) => import.meta.resolve(s) };
|
|
563
|
+
}
|
|
564
|
+
function isRequireEsmRefusal(error) {
|
|
565
|
+
return error?.code === "ERR_REQUIRE_ESM";
|
|
566
|
+
}
|
|
567
|
+
function loadPeer(specifier, host) {
|
|
568
|
+
if (host.resolve === void 0) return host.require(specifier);
|
|
569
|
+
const entry = fileURLToPath(host.resolve(specifier));
|
|
570
|
+
try {
|
|
571
|
+
return host.require(entry);
|
|
572
|
+
} catch (error) {
|
|
573
|
+
if (!isRequireEsmRefusal(error)) throw error;
|
|
574
|
+
return host.require(specifier);
|
|
575
|
+
}
|
|
576
|
+
}
|
|
577
|
+
function lazyPeer(specifier, host) {
|
|
578
|
+
let loaded;
|
|
579
|
+
return () => loaded ??= loadPeer(specifier, defaultHost());
|
|
580
|
+
}
|
|
581
|
+
var fhirPeer = lazyPeer("@cosyte/fhir");
|
|
554
582
|
|
|
555
583
|
// src/fhir/builder.ts
|
|
556
584
|
function prop(name2, value) {
|
|
557
585
|
return { name: name2, value };
|
|
558
586
|
}
|
|
559
587
|
function str(value) {
|
|
560
|
-
return primitive(value);
|
|
588
|
+
return fhirPeer().primitive(value);
|
|
561
589
|
}
|
|
562
590
|
function dec(raw) {
|
|
563
|
-
return primitive(decimal(raw));
|
|
591
|
+
return fhirPeer().primitive(fhirPeer().decimal(raw));
|
|
564
592
|
}
|
|
565
593
|
function bool(value) {
|
|
566
|
-
return primitive(value);
|
|
594
|
+
return fhirPeer().primitive(value);
|
|
567
595
|
}
|
|
568
596
|
function coding(concept) {
|
|
569
|
-
return complex([
|
|
597
|
+
return fhirPeer().complex([
|
|
570
598
|
prop("system", str(concept.system)),
|
|
571
599
|
prop("code", str(concept.code)),
|
|
572
600
|
prop("display", str(concept.display))
|
|
573
601
|
]);
|
|
574
602
|
}
|
|
575
603
|
function codeableConcept(concept) {
|
|
576
|
-
return complex([prop("coding", list([coding(concept)]))]);
|
|
604
|
+
return fhirPeer().complex([prop("coding", fhirPeer().list([coding(concept)]))]);
|
|
577
605
|
}
|
|
578
606
|
function reference(ref) {
|
|
579
|
-
return complex([prop("reference", str(ref))]);
|
|
607
|
+
return fhirPeer().complex([prop("reference", str(ref))]);
|
|
580
608
|
}
|
|
581
609
|
function narrative(text) {
|
|
582
610
|
const escaped = text.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">");
|
|
583
|
-
return complex([
|
|
611
|
+
return fhirPeer().complex([
|
|
584
612
|
prop("status", str("generated")),
|
|
585
613
|
prop("div", str(`<div xmlns="http://www.w3.org/1999/xhtml"><p>${escaped}</p></div>`))
|
|
586
614
|
]);
|
|
587
615
|
}
|
|
588
616
|
function meta(profiles) {
|
|
589
|
-
return complex([prop("profile", list(profiles.map((p) => str(p))))]);
|
|
617
|
+
return fhirPeer().complex([prop("profile", fhirPeer().list(profiles.map((p) => str(p))))]);
|
|
590
618
|
}
|
|
591
619
|
function toFhirDate(ymd) {
|
|
592
620
|
return `${ymd.slice(0, 4)}-${ymd.slice(4, 6)}-${ymd.slice(6, 8)}`;
|
|
@@ -603,13 +631,13 @@ function fhirPatientIdentity(rng) {
|
|
|
603
631
|
return { id, person, mrn, birthDate, gender, address: address2, phone: phone2, email: email2 };
|
|
604
632
|
}
|
|
605
633
|
function mrnIdentifier(mrn) {
|
|
606
|
-
return complex([
|
|
634
|
+
return fhirPeer().complex([
|
|
607
635
|
prop(
|
|
608
636
|
"type",
|
|
609
|
-
complex([
|
|
637
|
+
fhirPeer().complex([
|
|
610
638
|
prop(
|
|
611
639
|
"coding",
|
|
612
|
-
list([
|
|
640
|
+
fhirPeer().list([
|
|
613
641
|
coding({
|
|
614
642
|
system: SYSTEM.IDENTIFIER_TYPE,
|
|
615
643
|
code: "MR",
|
|
@@ -905,13 +933,16 @@ function resolveMix(allowed, requested, fallback) {
|
|
|
905
933
|
// src/fhir/patient.ts
|
|
906
934
|
var PATIENT_PROFILES = Object.freeze(["base", "us-core"]);
|
|
907
935
|
function ombExtension(url, category) {
|
|
908
|
-
return complex([
|
|
936
|
+
return fhirPeer().complex([
|
|
909
937
|
prop("url", str(url)),
|
|
910
938
|
prop(
|
|
911
939
|
"extension",
|
|
912
|
-
list([
|
|
913
|
-
complex([
|
|
914
|
-
|
|
940
|
+
fhirPeer().list([
|
|
941
|
+
fhirPeer().complex([
|
|
942
|
+
prop("url", str("ombCategory")),
|
|
943
|
+
prop("valueCoding", coding(category))
|
|
944
|
+
]),
|
|
945
|
+
fhirPeer().complex([prop("url", str("text")), prop("valueString", str(category.display))])
|
|
915
946
|
])
|
|
916
947
|
)
|
|
917
948
|
]);
|
|
@@ -942,24 +973,27 @@ function generatePatient(options = {}) {
|
|
|
942
973
|
props.push(
|
|
943
974
|
prop(
|
|
944
975
|
"extension",
|
|
945
|
-
list([
|
|
976
|
+
fhirPeer().list([
|
|
946
977
|
ombExtension(US_CORE_RACE_EXTENSION, race),
|
|
947
978
|
ombExtension(US_CORE_ETHNICITY_EXTENSION, ethnicity),
|
|
948
|
-
complex([
|
|
979
|
+
fhirPeer().complex([
|
|
980
|
+
prop("url", str(US_CORE_BIRTHSEX_EXTENSION)),
|
|
981
|
+
prop("valueCode", str(birthsex))
|
|
982
|
+
])
|
|
949
983
|
])
|
|
950
984
|
)
|
|
951
985
|
);
|
|
952
986
|
}
|
|
953
|
-
props.push(prop("identifier", list([mrnIdentifier(id.mrn)])));
|
|
987
|
+
props.push(prop("identifier", fhirPeer().list([mrnIdentifier(id.mrn)])));
|
|
954
988
|
props.push(prop("active", bool(true)));
|
|
955
989
|
props.push(
|
|
956
990
|
prop(
|
|
957
991
|
"name",
|
|
958
|
-
list([
|
|
959
|
-
complex([
|
|
992
|
+
fhirPeer().list([
|
|
993
|
+
fhirPeer().complex([
|
|
960
994
|
prop("use", str("official")),
|
|
961
995
|
prop("family", str(id.person.family)),
|
|
962
|
-
prop("given", list([str(id.person.given)]))
|
|
996
|
+
prop("given", fhirPeer().list([str(id.person.given)]))
|
|
963
997
|
])
|
|
964
998
|
])
|
|
965
999
|
)
|
|
@@ -967,13 +1001,13 @@ function generatePatient(options = {}) {
|
|
|
967
1001
|
props.push(
|
|
968
1002
|
prop(
|
|
969
1003
|
"telecom",
|
|
970
|
-
list([
|
|
971
|
-
complex([
|
|
1004
|
+
fhirPeer().list([
|
|
1005
|
+
fhirPeer().complex([
|
|
972
1006
|
prop("system", str("phone")),
|
|
973
1007
|
prop("value", str(id.phone)),
|
|
974
1008
|
prop("use", str("home"))
|
|
975
1009
|
]),
|
|
976
|
-
complex([prop("system", str("email")), prop("value", str(id.email))])
|
|
1010
|
+
fhirPeer().complex([prop("system", str("email")), prop("value", str(id.email))])
|
|
977
1011
|
])
|
|
978
1012
|
)
|
|
979
1013
|
);
|
|
@@ -982,10 +1016,10 @@ function generatePatient(options = {}) {
|
|
|
982
1016
|
props.push(
|
|
983
1017
|
prop(
|
|
984
1018
|
"address",
|
|
985
|
-
list([
|
|
986
|
-
complex([
|
|
1019
|
+
fhirPeer().list([
|
|
1020
|
+
fhirPeer().complex([
|
|
987
1021
|
prop("use", str("home")),
|
|
988
|
-
prop("line", list([str(id.address.street)])),
|
|
1022
|
+
prop("line", fhirPeer().list([str(id.address.street)])),
|
|
989
1023
|
prop("city", str(id.address.city)),
|
|
990
1024
|
prop("state", str(id.address.state)),
|
|
991
1025
|
prop("postalCode", str(id.address.zip))
|
|
@@ -993,8 +1027,10 @@ function generatePatient(options = {}) {
|
|
|
993
1027
|
])
|
|
994
1028
|
)
|
|
995
1029
|
);
|
|
996
|
-
return complex(props);
|
|
1030
|
+
return fhirPeer().complex(props);
|
|
997
1031
|
}
|
|
1032
|
+
|
|
1033
|
+
// src/fhir/condition.ts
|
|
998
1034
|
function generateCondition(options = {}) {
|
|
999
1035
|
const { seed = 0, subject = "Patient/syn-patient-1", usCore = true } = options;
|
|
1000
1036
|
const rng = createRng(seed);
|
|
@@ -1024,7 +1060,7 @@ function generateCondition(options = {}) {
|
|
|
1024
1060
|
props.push(
|
|
1025
1061
|
prop(
|
|
1026
1062
|
"category",
|
|
1027
|
-
list([
|
|
1063
|
+
fhirPeer().list([
|
|
1028
1064
|
codeableConcept({
|
|
1029
1065
|
system: SYSTEM.CONDITION_CATEGORY,
|
|
1030
1066
|
code: "problem-list-item",
|
|
@@ -1035,15 +1071,17 @@ function generateCondition(options = {}) {
|
|
|
1035
1071
|
);
|
|
1036
1072
|
props.push(prop("code", codeableConcept(code)));
|
|
1037
1073
|
props.push(prop("subject", reference(subject)));
|
|
1038
|
-
return complex(props);
|
|
1074
|
+
return fhirPeer().complex(props);
|
|
1039
1075
|
}
|
|
1076
|
+
|
|
1077
|
+
// src/fhir/observation.ts
|
|
1040
1078
|
function drawValue(rng, concept) {
|
|
1041
1079
|
const span = concept.high - concept.low;
|
|
1042
1080
|
const raw = concept.low + rng.float() * span;
|
|
1043
1081
|
return raw.toFixed(concept.decimals);
|
|
1044
1082
|
}
|
|
1045
1083
|
function valueQuantity(rng, concept) {
|
|
1046
|
-
return complex([
|
|
1084
|
+
return fhirPeer().complex([
|
|
1047
1085
|
prop("value", dec(drawValue(rng, concept))),
|
|
1048
1086
|
prop("unit", str(concept.unit)),
|
|
1049
1087
|
prop("system", str(SYSTEM.UCUM)),
|
|
@@ -1065,7 +1103,7 @@ function buildObservation(seed, subject, usCore, profileUrl, category, pool, eff
|
|
|
1065
1103
|
props.push(
|
|
1066
1104
|
prop(
|
|
1067
1105
|
"category",
|
|
1068
|
-
list([
|
|
1106
|
+
fhirPeer().list([
|
|
1069
1107
|
codeableConcept({
|
|
1070
1108
|
system: SYSTEM.OBSERVATION_CATEGORY,
|
|
1071
1109
|
code: category.code,
|
|
@@ -1081,7 +1119,7 @@ function buildObservation(seed, subject, usCore, profileUrl, category, pool, eff
|
|
|
1081
1119
|
const d = String(rng.int(1, 28)).padStart(2, "0");
|
|
1082
1120
|
if (effective) props.push(prop("effectiveDateTime", str(`${String(y)}-${m}-${d}`)));
|
|
1083
1121
|
props.push(prop("valueQuantity", valueQuantity(rng, concept)));
|
|
1084
|
-
return complex(props);
|
|
1122
|
+
return fhirPeer().complex(props);
|
|
1085
1123
|
}
|
|
1086
1124
|
function generateObservationLab(options = {}) {
|
|
1087
1125
|
const { seed = 0, subject = "Patient/syn-patient-1", usCore = true } = options;
|
|
@@ -1107,6 +1145,8 @@ function generateVitalSign(options = {}) {
|
|
|
1107
1145
|
true
|
|
1108
1146
|
);
|
|
1109
1147
|
}
|
|
1148
|
+
|
|
1149
|
+
// src/fhir/medication-request.ts
|
|
1110
1150
|
function generateMedicationRequest(options = {}) {
|
|
1111
1151
|
const {
|
|
1112
1152
|
seed = 0,
|
|
@@ -1131,8 +1171,10 @@ function generateMedicationRequest(options = {}) {
|
|
|
1131
1171
|
props.push(prop("subject", reference(subject)));
|
|
1132
1172
|
props.push(prop("authoredOn", str(`${String(y)}-${m}-${d}`)));
|
|
1133
1173
|
props.push(prop("requester", reference(requester)));
|
|
1134
|
-
return complex(props);
|
|
1174
|
+
return fhirPeer().complex(props);
|
|
1135
1175
|
}
|
|
1176
|
+
|
|
1177
|
+
// src/fhir/encounter.ts
|
|
1136
1178
|
function generateEncounter(options = {}) {
|
|
1137
1179
|
const { seed = 0, subject = "Patient/syn-patient-1", usCore = true } = options;
|
|
1138
1180
|
const rng = createRng(seed);
|
|
@@ -1149,8 +1191,8 @@ function generateEncounter(options = {}) {
|
|
|
1149
1191
|
props.push(
|
|
1150
1192
|
prop(
|
|
1151
1193
|
"identifier",
|
|
1152
|
-
list([
|
|
1153
|
-
complex([
|
|
1194
|
+
fhirPeer().list([
|
|
1195
|
+
fhirPeer().complex([
|
|
1154
1196
|
prop("system", str(`urn:oid:${id.assigningAuthorityOid}`)),
|
|
1155
1197
|
prop("value", str(id.value))
|
|
1156
1198
|
])
|
|
@@ -1159,11 +1201,13 @@ function generateEncounter(options = {}) {
|
|
|
1159
1201
|
);
|
|
1160
1202
|
props.push(prop("status", str("finished")));
|
|
1161
1203
|
props.push(prop("class", coding(cls)));
|
|
1162
|
-
props.push(prop("type", list([codeableConcept(type)])));
|
|
1204
|
+
props.push(prop("type", fhirPeer().list([codeableConcept(type)])));
|
|
1163
1205
|
props.push(prop("subject", reference(subject)));
|
|
1164
|
-
props.push(prop("period", complex([prop("start", str(`${start}T09:00:00Z`))])));
|
|
1165
|
-
return complex(props);
|
|
1206
|
+
props.push(prop("period", fhirPeer().complex([prop("start", str(`${start}T09:00:00Z`))])));
|
|
1207
|
+
return fhirPeer().complex(props);
|
|
1166
1208
|
}
|
|
1209
|
+
|
|
1210
|
+
// src/fhir/immunization.ts
|
|
1167
1211
|
function generateImmunization(options = {}) {
|
|
1168
1212
|
const { seed = 0, patient = "Patient/syn-patient-1", usCore = true } = options;
|
|
1169
1213
|
const rng = createRng(seed);
|
|
@@ -1180,8 +1224,10 @@ function generateImmunization(options = {}) {
|
|
|
1180
1224
|
props.push(prop("patient", reference(patient)));
|
|
1181
1225
|
props.push(prop("occurrenceDateTime", str(occurrence)));
|
|
1182
1226
|
props.push(prop("primarySource", bool(true)));
|
|
1183
|
-
return complex(props);
|
|
1227
|
+
return fhirPeer().complex(props);
|
|
1184
1228
|
}
|
|
1229
|
+
|
|
1230
|
+
// src/fhir/allergy-intolerance.ts
|
|
1185
1231
|
function generateAllergyIntolerance(options = {}) {
|
|
1186
1232
|
const { seed = 0, patient = "Patient/syn-patient-1", usCore = true } = options;
|
|
1187
1233
|
const rng = createRng(seed);
|
|
@@ -1214,11 +1260,17 @@ function generateAllergyIntolerance(options = {}) {
|
|
|
1214
1260
|
props.push(
|
|
1215
1261
|
prop(
|
|
1216
1262
|
"reaction",
|
|
1217
|
-
|
|
1263
|
+
fhirPeer().list([
|
|
1264
|
+
fhirPeer().complex([
|
|
1265
|
+
prop("manifestation", fhirPeer().list([codeableConcept(manifestation)]))
|
|
1266
|
+
])
|
|
1267
|
+
])
|
|
1218
1268
|
)
|
|
1219
1269
|
);
|
|
1220
|
-
return complex(props);
|
|
1270
|
+
return fhirPeer().complex(props);
|
|
1221
1271
|
}
|
|
1272
|
+
|
|
1273
|
+
// src/fhir/procedure.ts
|
|
1222
1274
|
function generateProcedure(options = {}) {
|
|
1223
1275
|
const { seed = 0, subject = "Patient/syn-patient-1", usCore = true } = options;
|
|
1224
1276
|
const rng = createRng(seed);
|
|
@@ -1234,8 +1286,10 @@ function generateProcedure(options = {}) {
|
|
|
1234
1286
|
props.push(prop("code", codeableConcept(code)));
|
|
1235
1287
|
props.push(prop("subject", reference(subject)));
|
|
1236
1288
|
props.push(prop("performedDateTime", str(`${performed}T10:00:00Z`)));
|
|
1237
|
-
return complex(props);
|
|
1289
|
+
return fhirPeer().complex(props);
|
|
1238
1290
|
}
|
|
1291
|
+
|
|
1292
|
+
// src/fhir/provenance.ts
|
|
1239
1293
|
function generateProvenance(options = {}) {
|
|
1240
1294
|
const { seed = 0, target = "Patient/syn-patient-1", usCore = true } = options;
|
|
1241
1295
|
const rng = createRng(seed);
|
|
@@ -1248,19 +1302,19 @@ function generateProvenance(options = {}) {
|
|
|
1248
1302
|
];
|
|
1249
1303
|
if (usCore) props.push(prop("meta", meta([US_CORE_PROFILE.PROVENANCE])));
|
|
1250
1304
|
props.push(prop("text", narrative("Synthetic provenance for a generated fixture.")));
|
|
1251
|
-
props.push(prop("target", list([reference(target)])));
|
|
1305
|
+
props.push(prop("target", fhirPeer().list([reference(target)])));
|
|
1252
1306
|
props.push(prop("recorded", str(`${recorded}T10:00:00Z`)));
|
|
1253
1307
|
props.push(
|
|
1254
1308
|
prop(
|
|
1255
1309
|
"agent",
|
|
1256
|
-
list([
|
|
1257
|
-
complex([
|
|
1310
|
+
fhirPeer().list([
|
|
1311
|
+
fhirPeer().complex([
|
|
1258
1312
|
prop(
|
|
1259
1313
|
"type",
|
|
1260
|
-
complex([
|
|
1314
|
+
fhirPeer().complex([
|
|
1261
1315
|
prop(
|
|
1262
1316
|
"coding",
|
|
1263
|
-
list([
|
|
1317
|
+
fhirPeer().list([
|
|
1264
1318
|
coding({
|
|
1265
1319
|
system: SYSTEM.PROVENANCE_PARTICIPANT_TYPE,
|
|
1266
1320
|
code: "author",
|
|
@@ -1281,8 +1335,10 @@ function generateProvenance(options = {}) {
|
|
|
1281
1335
|
])
|
|
1282
1336
|
)
|
|
1283
1337
|
);
|
|
1284
|
-
return complex(props);
|
|
1338
|
+
return fhirPeer().complex(props);
|
|
1285
1339
|
}
|
|
1340
|
+
|
|
1341
|
+
// src/fhir/diagnostic-report.ts
|
|
1286
1342
|
function generateDiagnosticReport(options = {}) {
|
|
1287
1343
|
const { seed = 0, subject = "Patient/syn-patient-1", results = [], usCore = true } = options;
|
|
1288
1344
|
const rng = createRng(seed);
|
|
@@ -1298,7 +1354,7 @@ function generateDiagnosticReport(options = {}) {
|
|
|
1298
1354
|
props.push(
|
|
1299
1355
|
prop(
|
|
1300
1356
|
"category",
|
|
1301
|
-
list([
|
|
1357
|
+
fhirPeer().list([
|
|
1302
1358
|
codeableConcept({
|
|
1303
1359
|
system: SYSTEM.DIAGNOSTIC_SERVICE_SECTION,
|
|
1304
1360
|
code: "LAB",
|
|
@@ -1312,12 +1368,13 @@ function generateDiagnosticReport(options = {}) {
|
|
|
1312
1368
|
props.push(prop("effectiveDateTime", str(`${day}T08:30:00Z`)));
|
|
1313
1369
|
props.push(prop("issued", str(`${day}T09:00:00.000Z`)));
|
|
1314
1370
|
if (results.length > 0) {
|
|
1315
|
-
props.push(prop("result", list(results.map((r) => reference(r)))));
|
|
1371
|
+
props.push(prop("result", fhirPeer().list(results.map((r) => reference(r)))));
|
|
1316
1372
|
}
|
|
1317
|
-
return complex(props);
|
|
1373
|
+
return fhirPeer().complex(props);
|
|
1318
1374
|
}
|
|
1319
1375
|
|
|
1320
1376
|
// src/corpus.ts
|
|
1377
|
+
var UNCHECKED = Object.freeze([]);
|
|
1321
1378
|
function makeCorpus(seed, artifacts, quirks = []) {
|
|
1322
1379
|
const counts = {};
|
|
1323
1380
|
const formats = /* @__PURE__ */ new Set();
|
|
@@ -1337,11 +1394,13 @@ function makeCorpus(seed, artifacts, quirks = []) {
|
|
|
1337
1394
|
artifacts: Object.freeze(frozenArtifacts)
|
|
1338
1395
|
});
|
|
1339
1396
|
}
|
|
1397
|
+
|
|
1398
|
+
// src/fhir/composition.ts
|
|
1340
1399
|
function section(sec) {
|
|
1341
|
-
return complex([
|
|
1400
|
+
return fhirPeer().complex([
|
|
1342
1401
|
prop("title", str(sec.title)),
|
|
1343
1402
|
prop("code", codeableConcept({ system: SYSTEM.LOINC, code: sec.code, display: sec.title })),
|
|
1344
|
-
prop("entry", list(sec.entries.map((e) => reference(e))))
|
|
1403
|
+
prop("entry", fhirPeer().list(sec.entries.map((e) => reference(e))))
|
|
1345
1404
|
]);
|
|
1346
1405
|
}
|
|
1347
1406
|
function buildComposition(rng, input) {
|
|
@@ -1360,18 +1419,20 @@ function buildComposition(rng, input) {
|
|
|
1360
1419
|
),
|
|
1361
1420
|
prop("subject", reference(input.subject)),
|
|
1362
1421
|
prop("date", str(`${input.date}T09:00:00Z`)),
|
|
1363
|
-
prop("author", list([reference(input.organization)])),
|
|
1422
|
+
prop("author", fhirPeer().list([reference(input.organization)])),
|
|
1364
1423
|
prop("title", str("Synthetic Continuity of Care Document")),
|
|
1365
1424
|
prop("custodian", reference(input.organization)),
|
|
1366
|
-
prop("section", list(input.sections.map((s) => section(s))))
|
|
1425
|
+
prop("section", fhirPeer().list(input.sections.map((s) => section(s))))
|
|
1367
1426
|
];
|
|
1368
|
-
return complex(props);
|
|
1427
|
+
return fhirPeer().complex(props);
|
|
1369
1428
|
}
|
|
1429
|
+
|
|
1430
|
+
// src/fhir/round-trip.ts
|
|
1370
1431
|
function roundTrip(resource, options = {}) {
|
|
1371
|
-
const content = serializeResource(resource);
|
|
1372
|
-
const { resource: reparsed } = parseResource(content);
|
|
1373
|
-
const byteStable = serializeResource(reparsed) === content;
|
|
1374
|
-
const result = validateResource(
|
|
1432
|
+
const content = fhirPeer().serializeResource(resource);
|
|
1433
|
+
const { resource: reparsed } = fhirPeer().parseResource(content);
|
|
1434
|
+
const byteStable = fhirPeer().serializeResource(reparsed) === content;
|
|
1435
|
+
const result = fhirPeer().validateResource(
|
|
1375
1436
|
reparsed,
|
|
1376
1437
|
options.profiles !== void 0 ? { mode: "strict", profiles: options.profiles } : { mode: "strict" }
|
|
1377
1438
|
);
|
|
@@ -1380,6 +1441,13 @@ function roundTrip(resource, options = {}) {
|
|
|
1380
1441
|
const valid = result.valid;
|
|
1381
1442
|
return { content, errors, warnings, byteStable, valid, specClean: valid && byteStable };
|
|
1382
1443
|
}
|
|
1444
|
+
function fhirCorpusArtifact(resource, verify) {
|
|
1445
|
+
const content = fhirPeer().serializeResource(resource);
|
|
1446
|
+
if (!verify) return { content, warnings: UNCHECKED };
|
|
1447
|
+
const { resource: reparsed } = fhirPeer().parseResource(content);
|
|
1448
|
+
const warnings = fhirPeer().validateResource(reparsed, { mode: "strict" }).issues.filter((i) => i.severity === "error" || i.severity === "fatal").map((i) => i.code);
|
|
1449
|
+
return { content, warnings };
|
|
1450
|
+
}
|
|
1383
1451
|
|
|
1384
1452
|
// src/fhir/bundle.ts
|
|
1385
1453
|
var BUNDLE_TYPES = Object.freeze([
|
|
@@ -1393,14 +1461,14 @@ function resourceTypeOf(resource) {
|
|
|
1393
1461
|
}
|
|
1394
1462
|
function buildOrganization(rng) {
|
|
1395
1463
|
const id = safe.identifier(rng, "AN");
|
|
1396
|
-
return complex([
|
|
1464
|
+
return fhirPeer().complex([
|
|
1397
1465
|
prop("resourceType", str("Organization")),
|
|
1398
1466
|
prop("id", str(`syn-org-${rng.digits(8)}`)),
|
|
1399
1467
|
prop("text", narrative("Synthetic health organization.")),
|
|
1400
1468
|
prop(
|
|
1401
1469
|
"identifier",
|
|
1402
|
-
list([
|
|
1403
|
-
complex([
|
|
1470
|
+
fhirPeer().list([
|
|
1471
|
+
fhirPeer().complex([
|
|
1404
1472
|
prop("system", str(`urn:oid:${id.assigningAuthorityOid}`)),
|
|
1405
1473
|
prop("value", str(id.value))
|
|
1406
1474
|
])
|
|
@@ -1513,11 +1581,14 @@ function generateBundle(options = {}) {
|
|
|
1513
1581
|
entryProps.push(
|
|
1514
1582
|
prop(
|
|
1515
1583
|
"request",
|
|
1516
|
-
complex([
|
|
1584
|
+
fhirPeer().complex([
|
|
1585
|
+
prop("method", str("POST")),
|
|
1586
|
+
prop("url", str(resourceTypeOf(member.resource)))
|
|
1587
|
+
])
|
|
1517
1588
|
)
|
|
1518
1589
|
);
|
|
1519
1590
|
}
|
|
1520
|
-
return complex(entryProps);
|
|
1591
|
+
return fhirPeer().complex(entryProps);
|
|
1521
1592
|
});
|
|
1522
1593
|
const props = [
|
|
1523
1594
|
prop("resourceType", str("Bundle")),
|
|
@@ -1528,7 +1599,7 @@ function generateBundle(options = {}) {
|
|
|
1528
1599
|
props.push(
|
|
1529
1600
|
prop(
|
|
1530
1601
|
"identifier",
|
|
1531
|
-
complex([
|
|
1602
|
+
fhirPeer().complex([
|
|
1532
1603
|
prop("system", str(`urn:oid:${id.assigningAuthorityOid}`)),
|
|
1533
1604
|
prop("value", str(`urn:uuid:${safe.uuid(rng)}`))
|
|
1534
1605
|
])
|
|
@@ -1537,8 +1608,8 @@ function generateBundle(options = {}) {
|
|
|
1537
1608
|
}
|
|
1538
1609
|
props.push(prop("type", str(type)));
|
|
1539
1610
|
if (type === "document") props.push(prop("timestamp", str(`${spine.date}T09:00:00.000Z`)));
|
|
1540
|
-
props.push(prop("entry", list(entries)));
|
|
1541
|
-
return complex(props);
|
|
1611
|
+
props.push(prop("entry", fhirPeer().list(entries)));
|
|
1612
|
+
return fhirPeer().complex(props);
|
|
1542
1613
|
}
|
|
1543
1614
|
var ALL_KINDS = Object.freeze([
|
|
1544
1615
|
"Patient",
|
|
@@ -1599,13 +1670,13 @@ function generateKind(kind, seed) {
|
|
|
1599
1670
|
}
|
|
1600
1671
|
}
|
|
1601
1672
|
function fhirCorpus(options) {
|
|
1602
|
-
const { seed, count = 1 } = options;
|
|
1673
|
+
const { seed, count = 1, verify = true } = options;
|
|
1603
1674
|
const kinds = resolveMix(ALL_KINDS, options.mix, DEFAULT_MIX);
|
|
1604
1675
|
const seedStream = createRng(seed);
|
|
1605
1676
|
const artifacts = Array.from({ length: count }, (_unused, i) => {
|
|
1606
1677
|
const kind = kinds[i % kinds.length] ?? "USCorePatient";
|
|
1607
|
-
const rt =
|
|
1608
|
-
return { format: "fhir", kind, content: rt.content, warnings: rt.
|
|
1678
|
+
const rt = fhirCorpusArtifact(generateKind(kind, seedStream.nextUint32()), verify);
|
|
1679
|
+
return { format: "fhir", kind, content: rt.content, warnings: rt.warnings };
|
|
1609
1680
|
});
|
|
1610
1681
|
return makeCorpus(seed, artifacts);
|
|
1611
1682
|
}
|