@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,8 +1,15 @@
1
1
  'use strict';
2
2
 
3
- var fhir = require('@cosyte/fhir');
3
+ var module$1 = require('module');
4
+ var url = require('url');
4
5
 
5
- // src/fhir/patient.ts
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
+ });
6
13
 
7
14
  // src/rng/splitmix32.ts
8
15
  function splitmix32(seed) {
@@ -553,42 +560,64 @@ var SYSTEM = Object.freeze({
553
560
  /** US Core `us-core-provenance-participant-type`, `Provenance.agent.type` (`transmitter`). */
554
561
  US_CORE_PROVENANCE_PARTICIPANT_TYPE: "http://hl7.org/fhir/us/core/CodeSystem/us-core-provenance-participant-type"
555
562
  });
563
+ function defaultHost() {
564
+ if (typeof undefined !== "function") return { require: __require, resolve: void 0 };
565
+ 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) };
566
+ }
567
+ function isRequireEsmRefusal(error) {
568
+ return error?.code === "ERR_REQUIRE_ESM";
569
+ }
570
+ function loadPeer(specifier, host) {
571
+ if (host.resolve === void 0) return host.require(specifier);
572
+ const entry = url.fileURLToPath(host.resolve(specifier));
573
+ try {
574
+ return host.require(entry);
575
+ } catch (error) {
576
+ if (!isRequireEsmRefusal(error)) throw error;
577
+ return host.require(specifier);
578
+ }
579
+ }
580
+ function lazyPeer(specifier, host) {
581
+ let loaded;
582
+ return () => loaded ??= loadPeer(specifier, defaultHost());
583
+ }
584
+ var fhirPeer = lazyPeer("@cosyte/fhir");
556
585
 
557
586
  // src/fhir/builder.ts
558
587
  function prop(name2, value) {
559
588
  return { name: name2, value };
560
589
  }
561
590
  function str(value) {
562
- return fhir.primitive(value);
591
+ return fhirPeer().primitive(value);
563
592
  }
564
593
  function dec(raw) {
565
- return fhir.primitive(fhir.decimal(raw));
594
+ return fhirPeer().primitive(fhirPeer().decimal(raw));
566
595
  }
567
596
  function bool(value) {
568
- return fhir.primitive(value);
597
+ return fhirPeer().primitive(value);
569
598
  }
570
599
  function coding(concept) {
571
- return fhir.complex([
600
+ return fhirPeer().complex([
572
601
  prop("system", str(concept.system)),
573
602
  prop("code", str(concept.code)),
574
603
  prop("display", str(concept.display))
575
604
  ]);
576
605
  }
577
606
  function codeableConcept(concept) {
578
- return fhir.complex([prop("coding", fhir.list([coding(concept)]))]);
607
+ return fhirPeer().complex([prop("coding", fhirPeer().list([coding(concept)]))]);
579
608
  }
580
609
  function reference(ref) {
581
- return fhir.complex([prop("reference", str(ref))]);
610
+ return fhirPeer().complex([prop("reference", str(ref))]);
582
611
  }
583
612
  function narrative(text) {
584
613
  const escaped = text.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;");
585
- return fhir.complex([
614
+ return fhirPeer().complex([
586
615
  prop("status", str("generated")),
587
616
  prop("div", str(`<div xmlns="http://www.w3.org/1999/xhtml"><p>${escaped}</p></div>`))
588
617
  ]);
589
618
  }
590
619
  function meta(profiles) {
591
- return fhir.complex([prop("profile", fhir.list(profiles.map((p) => str(p))))]);
620
+ return fhirPeer().complex([prop("profile", fhirPeer().list(profiles.map((p) => str(p))))]);
592
621
  }
593
622
  function toFhirDate(ymd) {
594
623
  return `${ymd.slice(0, 4)}-${ymd.slice(4, 6)}-${ymd.slice(6, 8)}`;
@@ -605,13 +634,13 @@ function fhirPatientIdentity(rng) {
605
634
  return { id, person, mrn, birthDate, gender, address: address2, phone: phone2, email: email2 };
606
635
  }
607
636
  function mrnIdentifier(mrn) {
608
- return fhir.complex([
637
+ return fhirPeer().complex([
609
638
  prop(
610
639
  "type",
611
- fhir.complex([
640
+ fhirPeer().complex([
612
641
  prop(
613
642
  "coding",
614
- fhir.list([
643
+ fhirPeer().list([
615
644
  coding({
616
645
  system: SYSTEM.IDENTIFIER_TYPE,
617
646
  code: "MR",
@@ -907,13 +936,16 @@ function resolveMix(allowed, requested, fallback) {
907
936
  // src/fhir/patient.ts
908
937
  var PATIENT_PROFILES = Object.freeze(["base", "us-core"]);
909
938
  function ombExtension(url, category) {
910
- return fhir.complex([
939
+ return fhirPeer().complex([
911
940
  prop("url", str(url)),
912
941
  prop(
913
942
  "extension",
914
- fhir.list([
915
- fhir.complex([prop("url", str("ombCategory")), prop("valueCoding", coding(category))]),
916
- fhir.complex([prop("url", str("text")), prop("valueString", str(category.display))])
943
+ fhirPeer().list([
944
+ fhirPeer().complex([
945
+ prop("url", str("ombCategory")),
946
+ prop("valueCoding", coding(category))
947
+ ]),
948
+ fhirPeer().complex([prop("url", str("text")), prop("valueString", str(category.display))])
917
949
  ])
918
950
  )
919
951
  ]);
@@ -944,24 +976,27 @@ function generatePatient(options = {}) {
944
976
  props.push(
945
977
  prop(
946
978
  "extension",
947
- fhir.list([
979
+ fhirPeer().list([
948
980
  ombExtension(US_CORE_RACE_EXTENSION, race),
949
981
  ombExtension(US_CORE_ETHNICITY_EXTENSION, ethnicity),
950
- fhir.complex([prop("url", str(US_CORE_BIRTHSEX_EXTENSION)), prop("valueCode", str(birthsex))])
982
+ fhirPeer().complex([
983
+ prop("url", str(US_CORE_BIRTHSEX_EXTENSION)),
984
+ prop("valueCode", str(birthsex))
985
+ ])
951
986
  ])
952
987
  )
953
988
  );
954
989
  }
955
- props.push(prop("identifier", fhir.list([mrnIdentifier(id.mrn)])));
990
+ props.push(prop("identifier", fhirPeer().list([mrnIdentifier(id.mrn)])));
956
991
  props.push(prop("active", bool(true)));
957
992
  props.push(
958
993
  prop(
959
994
  "name",
960
- fhir.list([
961
- fhir.complex([
995
+ fhirPeer().list([
996
+ fhirPeer().complex([
962
997
  prop("use", str("official")),
963
998
  prop("family", str(id.person.family)),
964
- prop("given", fhir.list([str(id.person.given)]))
999
+ prop("given", fhirPeer().list([str(id.person.given)]))
965
1000
  ])
966
1001
  ])
967
1002
  )
@@ -969,13 +1004,13 @@ function generatePatient(options = {}) {
969
1004
  props.push(
970
1005
  prop(
971
1006
  "telecom",
972
- fhir.list([
973
- fhir.complex([
1007
+ fhirPeer().list([
1008
+ fhirPeer().complex([
974
1009
  prop("system", str("phone")),
975
1010
  prop("value", str(id.phone)),
976
1011
  prop("use", str("home"))
977
1012
  ]),
978
- fhir.complex([prop("system", str("email")), prop("value", str(id.email))])
1013
+ fhirPeer().complex([prop("system", str("email")), prop("value", str(id.email))])
979
1014
  ])
980
1015
  )
981
1016
  );
@@ -984,10 +1019,10 @@ function generatePatient(options = {}) {
984
1019
  props.push(
985
1020
  prop(
986
1021
  "address",
987
- fhir.list([
988
- fhir.complex([
1022
+ fhirPeer().list([
1023
+ fhirPeer().complex([
989
1024
  prop("use", str("home")),
990
- prop("line", fhir.list([str(id.address.street)])),
1025
+ prop("line", fhirPeer().list([str(id.address.street)])),
991
1026
  prop("city", str(id.address.city)),
992
1027
  prop("state", str(id.address.state)),
993
1028
  prop("postalCode", str(id.address.zip))
@@ -995,8 +1030,10 @@ function generatePatient(options = {}) {
995
1030
  ])
996
1031
  )
997
1032
  );
998
- return fhir.complex(props);
1033
+ return fhirPeer().complex(props);
999
1034
  }
1035
+
1036
+ // src/fhir/condition.ts
1000
1037
  function generateCondition(options = {}) {
1001
1038
  const { seed = 0, subject = "Patient/syn-patient-1", usCore = true } = options;
1002
1039
  const rng = createRng(seed);
@@ -1026,7 +1063,7 @@ function generateCondition(options = {}) {
1026
1063
  props.push(
1027
1064
  prop(
1028
1065
  "category",
1029
- fhir.list([
1066
+ fhirPeer().list([
1030
1067
  codeableConcept({
1031
1068
  system: SYSTEM.CONDITION_CATEGORY,
1032
1069
  code: "problem-list-item",
@@ -1037,15 +1074,17 @@ function generateCondition(options = {}) {
1037
1074
  );
1038
1075
  props.push(prop("code", codeableConcept(code)));
1039
1076
  props.push(prop("subject", reference(subject)));
1040
- return fhir.complex(props);
1077
+ return fhirPeer().complex(props);
1041
1078
  }
1079
+
1080
+ // src/fhir/observation.ts
1042
1081
  function drawValue(rng, concept) {
1043
1082
  const span = concept.high - concept.low;
1044
1083
  const raw = concept.low + rng.float() * span;
1045
1084
  return raw.toFixed(concept.decimals);
1046
1085
  }
1047
1086
  function valueQuantity(rng, concept) {
1048
- return fhir.complex([
1087
+ return fhirPeer().complex([
1049
1088
  prop("value", dec(drawValue(rng, concept))),
1050
1089
  prop("unit", str(concept.unit)),
1051
1090
  prop("system", str(SYSTEM.UCUM)),
@@ -1067,7 +1106,7 @@ function buildObservation(seed, subject, usCore, profileUrl, category, pool, eff
1067
1106
  props.push(
1068
1107
  prop(
1069
1108
  "category",
1070
- fhir.list([
1109
+ fhirPeer().list([
1071
1110
  codeableConcept({
1072
1111
  system: SYSTEM.OBSERVATION_CATEGORY,
1073
1112
  code: category.code,
@@ -1083,7 +1122,7 @@ function buildObservation(seed, subject, usCore, profileUrl, category, pool, eff
1083
1122
  const d = String(rng.int(1, 28)).padStart(2, "0");
1084
1123
  if (effective) props.push(prop("effectiveDateTime", str(`${String(y)}-${m}-${d}`)));
1085
1124
  props.push(prop("valueQuantity", valueQuantity(rng, concept)));
1086
- return fhir.complex(props);
1125
+ return fhirPeer().complex(props);
1087
1126
  }
1088
1127
  function generateObservationLab(options = {}) {
1089
1128
  const { seed = 0, subject = "Patient/syn-patient-1", usCore = true } = options;
@@ -1109,6 +1148,8 @@ function generateVitalSign(options = {}) {
1109
1148
  true
1110
1149
  );
1111
1150
  }
1151
+
1152
+ // src/fhir/medication-request.ts
1112
1153
  function generateMedicationRequest(options = {}) {
1113
1154
  const {
1114
1155
  seed = 0,
@@ -1133,8 +1174,10 @@ function generateMedicationRequest(options = {}) {
1133
1174
  props.push(prop("subject", reference(subject)));
1134
1175
  props.push(prop("authoredOn", str(`${String(y)}-${m}-${d}`)));
1135
1176
  props.push(prop("requester", reference(requester)));
1136
- return fhir.complex(props);
1177
+ return fhirPeer().complex(props);
1137
1178
  }
1179
+
1180
+ // src/fhir/encounter.ts
1138
1181
  function generateEncounter(options = {}) {
1139
1182
  const { seed = 0, subject = "Patient/syn-patient-1", usCore = true } = options;
1140
1183
  const rng = createRng(seed);
@@ -1151,8 +1194,8 @@ function generateEncounter(options = {}) {
1151
1194
  props.push(
1152
1195
  prop(
1153
1196
  "identifier",
1154
- fhir.list([
1155
- fhir.complex([
1197
+ fhirPeer().list([
1198
+ fhirPeer().complex([
1156
1199
  prop("system", str(`urn:oid:${id.assigningAuthorityOid}`)),
1157
1200
  prop("value", str(id.value))
1158
1201
  ])
@@ -1161,11 +1204,13 @@ function generateEncounter(options = {}) {
1161
1204
  );
1162
1205
  props.push(prop("status", str("finished")));
1163
1206
  props.push(prop("class", coding(cls)));
1164
- props.push(prop("type", fhir.list([codeableConcept(type)])));
1207
+ props.push(prop("type", fhirPeer().list([codeableConcept(type)])));
1165
1208
  props.push(prop("subject", reference(subject)));
1166
- props.push(prop("period", fhir.complex([prop("start", str(`${start}T09:00:00Z`))])));
1167
- return fhir.complex(props);
1209
+ props.push(prop("period", fhirPeer().complex([prop("start", str(`${start}T09:00:00Z`))])));
1210
+ return fhirPeer().complex(props);
1168
1211
  }
1212
+
1213
+ // src/fhir/immunization.ts
1169
1214
  function generateImmunization(options = {}) {
1170
1215
  const { seed = 0, patient = "Patient/syn-patient-1", usCore = true } = options;
1171
1216
  const rng = createRng(seed);
@@ -1182,8 +1227,10 @@ function generateImmunization(options = {}) {
1182
1227
  props.push(prop("patient", reference(patient)));
1183
1228
  props.push(prop("occurrenceDateTime", str(occurrence)));
1184
1229
  props.push(prop("primarySource", bool(true)));
1185
- return fhir.complex(props);
1230
+ return fhirPeer().complex(props);
1186
1231
  }
1232
+
1233
+ // src/fhir/allergy-intolerance.ts
1187
1234
  function generateAllergyIntolerance(options = {}) {
1188
1235
  const { seed = 0, patient = "Patient/syn-patient-1", usCore = true } = options;
1189
1236
  const rng = createRng(seed);
@@ -1216,11 +1263,17 @@ function generateAllergyIntolerance(options = {}) {
1216
1263
  props.push(
1217
1264
  prop(
1218
1265
  "reaction",
1219
- fhir.list([fhir.complex([prop("manifestation", fhir.list([codeableConcept(manifestation)]))])])
1266
+ fhirPeer().list([
1267
+ fhirPeer().complex([
1268
+ prop("manifestation", fhirPeer().list([codeableConcept(manifestation)]))
1269
+ ])
1270
+ ])
1220
1271
  )
1221
1272
  );
1222
- return fhir.complex(props);
1273
+ return fhirPeer().complex(props);
1223
1274
  }
1275
+
1276
+ // src/fhir/procedure.ts
1224
1277
  function generateProcedure(options = {}) {
1225
1278
  const { seed = 0, subject = "Patient/syn-patient-1", usCore = true } = options;
1226
1279
  const rng = createRng(seed);
@@ -1236,8 +1289,10 @@ function generateProcedure(options = {}) {
1236
1289
  props.push(prop("code", codeableConcept(code)));
1237
1290
  props.push(prop("subject", reference(subject)));
1238
1291
  props.push(prop("performedDateTime", str(`${performed}T10:00:00Z`)));
1239
- return fhir.complex(props);
1292
+ return fhirPeer().complex(props);
1240
1293
  }
1294
+
1295
+ // src/fhir/provenance.ts
1241
1296
  function generateProvenance(options = {}) {
1242
1297
  const { seed = 0, target = "Patient/syn-patient-1", usCore = true } = options;
1243
1298
  const rng = createRng(seed);
@@ -1250,19 +1305,19 @@ function generateProvenance(options = {}) {
1250
1305
  ];
1251
1306
  if (usCore) props.push(prop("meta", meta([US_CORE_PROFILE.PROVENANCE])));
1252
1307
  props.push(prop("text", narrative("Synthetic provenance for a generated fixture.")));
1253
- props.push(prop("target", fhir.list([reference(target)])));
1308
+ props.push(prop("target", fhirPeer().list([reference(target)])));
1254
1309
  props.push(prop("recorded", str(`${recorded}T10:00:00Z`)));
1255
1310
  props.push(
1256
1311
  prop(
1257
1312
  "agent",
1258
- fhir.list([
1259
- fhir.complex([
1313
+ fhirPeer().list([
1314
+ fhirPeer().complex([
1260
1315
  prop(
1261
1316
  "type",
1262
- fhir.complex([
1317
+ fhirPeer().complex([
1263
1318
  prop(
1264
1319
  "coding",
1265
- fhir.list([
1320
+ fhirPeer().list([
1266
1321
  coding({
1267
1322
  system: SYSTEM.PROVENANCE_PARTICIPANT_TYPE,
1268
1323
  code: "author",
@@ -1283,8 +1338,10 @@ function generateProvenance(options = {}) {
1283
1338
  ])
1284
1339
  )
1285
1340
  );
1286
- return fhir.complex(props);
1341
+ return fhirPeer().complex(props);
1287
1342
  }
1343
+
1344
+ // src/fhir/diagnostic-report.ts
1288
1345
  function generateDiagnosticReport(options = {}) {
1289
1346
  const { seed = 0, subject = "Patient/syn-patient-1", results = [], usCore = true } = options;
1290
1347
  const rng = createRng(seed);
@@ -1300,7 +1357,7 @@ function generateDiagnosticReport(options = {}) {
1300
1357
  props.push(
1301
1358
  prop(
1302
1359
  "category",
1303
- fhir.list([
1360
+ fhirPeer().list([
1304
1361
  codeableConcept({
1305
1362
  system: SYSTEM.DIAGNOSTIC_SERVICE_SECTION,
1306
1363
  code: "LAB",
@@ -1314,12 +1371,13 @@ function generateDiagnosticReport(options = {}) {
1314
1371
  props.push(prop("effectiveDateTime", str(`${day}T08:30:00Z`)));
1315
1372
  props.push(prop("issued", str(`${day}T09:00:00.000Z`)));
1316
1373
  if (results.length > 0) {
1317
- props.push(prop("result", fhir.list(results.map((r) => reference(r)))));
1374
+ props.push(prop("result", fhirPeer().list(results.map((r) => reference(r)))));
1318
1375
  }
1319
- return fhir.complex(props);
1376
+ return fhirPeer().complex(props);
1320
1377
  }
1321
1378
 
1322
1379
  // src/corpus.ts
1380
+ var UNCHECKED = Object.freeze([]);
1323
1381
  function makeCorpus(seed, artifacts, quirks = []) {
1324
1382
  const counts = {};
1325
1383
  const formats = /* @__PURE__ */ new Set();
@@ -1339,11 +1397,13 @@ function makeCorpus(seed, artifacts, quirks = []) {
1339
1397
  artifacts: Object.freeze(frozenArtifacts)
1340
1398
  });
1341
1399
  }
1400
+
1401
+ // src/fhir/composition.ts
1342
1402
  function section(sec) {
1343
- return fhir.complex([
1403
+ return fhirPeer().complex([
1344
1404
  prop("title", str(sec.title)),
1345
1405
  prop("code", codeableConcept({ system: SYSTEM.LOINC, code: sec.code, display: sec.title })),
1346
- prop("entry", fhir.list(sec.entries.map((e) => reference(e))))
1406
+ prop("entry", fhirPeer().list(sec.entries.map((e) => reference(e))))
1347
1407
  ]);
1348
1408
  }
1349
1409
  function buildComposition(rng, input) {
@@ -1362,18 +1422,20 @@ function buildComposition(rng, input) {
1362
1422
  ),
1363
1423
  prop("subject", reference(input.subject)),
1364
1424
  prop("date", str(`${input.date}T09:00:00Z`)),
1365
- prop("author", fhir.list([reference(input.organization)])),
1425
+ prop("author", fhirPeer().list([reference(input.organization)])),
1366
1426
  prop("title", str("Synthetic Continuity of Care Document")),
1367
1427
  prop("custodian", reference(input.organization)),
1368
- prop("section", fhir.list(input.sections.map((s) => section(s))))
1428
+ prop("section", fhirPeer().list(input.sections.map((s) => section(s))))
1369
1429
  ];
1370
- return fhir.complex(props);
1430
+ return fhirPeer().complex(props);
1371
1431
  }
1432
+
1433
+ // src/fhir/round-trip.ts
1372
1434
  function roundTrip(resource, options = {}) {
1373
- const content = fhir.serializeResource(resource);
1374
- const { resource: reparsed } = fhir.parseResource(content);
1375
- const byteStable = fhir.serializeResource(reparsed) === content;
1376
- const result = fhir.validateResource(
1435
+ const content = fhirPeer().serializeResource(resource);
1436
+ const { resource: reparsed } = fhirPeer().parseResource(content);
1437
+ const byteStable = fhirPeer().serializeResource(reparsed) === content;
1438
+ const result = fhirPeer().validateResource(
1377
1439
  reparsed,
1378
1440
  options.profiles !== void 0 ? { mode: "strict", profiles: options.profiles } : { mode: "strict" }
1379
1441
  );
@@ -1382,6 +1444,13 @@ function roundTrip(resource, options = {}) {
1382
1444
  const valid = result.valid;
1383
1445
  return { content, errors, warnings, byteStable, valid, specClean: valid && byteStable };
1384
1446
  }
1447
+ function fhirCorpusArtifact(resource, verify) {
1448
+ const content = fhirPeer().serializeResource(resource);
1449
+ if (!verify) return { content, warnings: UNCHECKED };
1450
+ const { resource: reparsed } = fhirPeer().parseResource(content);
1451
+ const warnings = fhirPeer().validateResource(reparsed, { mode: "strict" }).issues.filter((i) => i.severity === "error" || i.severity === "fatal").map((i) => i.code);
1452
+ return { content, warnings };
1453
+ }
1385
1454
 
1386
1455
  // src/fhir/bundle.ts
1387
1456
  var BUNDLE_TYPES = Object.freeze([
@@ -1395,14 +1464,14 @@ function resourceTypeOf(resource) {
1395
1464
  }
1396
1465
  function buildOrganization(rng) {
1397
1466
  const id = safe.identifier(rng, "AN");
1398
- return fhir.complex([
1467
+ return fhirPeer().complex([
1399
1468
  prop("resourceType", str("Organization")),
1400
1469
  prop("id", str(`syn-org-${rng.digits(8)}`)),
1401
1470
  prop("text", narrative("Synthetic health organization.")),
1402
1471
  prop(
1403
1472
  "identifier",
1404
- fhir.list([
1405
- fhir.complex([
1473
+ fhirPeer().list([
1474
+ fhirPeer().complex([
1406
1475
  prop("system", str(`urn:oid:${id.assigningAuthorityOid}`)),
1407
1476
  prop("value", str(id.value))
1408
1477
  ])
@@ -1515,11 +1584,14 @@ function generateBundle(options = {}) {
1515
1584
  entryProps.push(
1516
1585
  prop(
1517
1586
  "request",
1518
- fhir.complex([prop("method", str("POST")), prop("url", str(resourceTypeOf(member.resource)))])
1587
+ fhirPeer().complex([
1588
+ prop("method", str("POST")),
1589
+ prop("url", str(resourceTypeOf(member.resource)))
1590
+ ])
1519
1591
  )
1520
1592
  );
1521
1593
  }
1522
- return fhir.complex(entryProps);
1594
+ return fhirPeer().complex(entryProps);
1523
1595
  });
1524
1596
  const props = [
1525
1597
  prop("resourceType", str("Bundle")),
@@ -1530,7 +1602,7 @@ function generateBundle(options = {}) {
1530
1602
  props.push(
1531
1603
  prop(
1532
1604
  "identifier",
1533
- fhir.complex([
1605
+ fhirPeer().complex([
1534
1606
  prop("system", str(`urn:oid:${id.assigningAuthorityOid}`)),
1535
1607
  prop("value", str(`urn:uuid:${safe.uuid(rng)}`))
1536
1608
  ])
@@ -1539,8 +1611,8 @@ function generateBundle(options = {}) {
1539
1611
  }
1540
1612
  props.push(prop("type", str(type)));
1541
1613
  if (type === "document") props.push(prop("timestamp", str(`${spine.date}T09:00:00.000Z`)));
1542
- props.push(prop("entry", fhir.list(entries)));
1543
- return fhir.complex(props);
1614
+ props.push(prop("entry", fhirPeer().list(entries)));
1615
+ return fhirPeer().complex(props);
1544
1616
  }
1545
1617
  var ALL_KINDS = Object.freeze([
1546
1618
  "Patient",
@@ -1601,13 +1673,13 @@ function generateKind(kind, seed) {
1601
1673
  }
1602
1674
  }
1603
1675
  function fhirCorpus(options) {
1604
- const { seed, count = 1 } = options;
1676
+ const { seed, count = 1, verify = true } = options;
1605
1677
  const kinds = resolveMix(ALL_KINDS, options.mix, DEFAULT_MIX);
1606
1678
  const seedStream = createRng(seed);
1607
1679
  const artifacts = Array.from({ length: count }, (_unused, i) => {
1608
1680
  const kind = kinds[i % kinds.length] ?? "USCorePatient";
1609
- const rt = roundTrip(generateKind(kind, seedStream.nextUint32()));
1610
- return { format: "fhir", kind, content: rt.content, warnings: rt.errors };
1681
+ const rt = fhirCorpusArtifact(generateKind(kind, seedStream.nextUint32()), verify);
1682
+ return { format: "fhir", kind, content: rt.content, warnings: rt.warnings };
1611
1683
  });
1612
1684
  return makeCorpus(seed, artifacts);
1613
1685
  }