@cosyte/synth 0.1.7 → 0.1.9

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.
@@ -655,11 +655,14 @@ declare function reference(ref: string): FhirComplex;
655
655
  */
656
656
  declare function narrative(text: string): FhirComplex;
657
657
  /**
658
- * A `meta.profile` element pinning the resource to one or more canonical profile URLs (US Core
659
- * conformance is claimed via `meta.profile`). No version is pinned, so validating against any supplied
660
- * version of the named profile never raises a version-mismatch.
661
- *
662
- * @param profiles - The canonical profile URLs to claim.
658
+ * A resource's `meta`: the `HTEST` security label in `meta.security`, which says the resource is test
659
+ * data, on every resource this package generates, plus a `meta.profile` pinning the resource to one or
660
+ * more canonical profile URLs when any are given (US Core conformance is claimed via `meta.profile`).
661
+ * No version is pinned, so validating against any supplied version of the named profile never raises
662
+ * a version-mismatch.
663
+ *
664
+ * @param profiles - The canonical profile URLs to claim. Empty for none: `meta.profile` is then left
665
+ * out and `meta` carries only the security label.
663
666
  * @returns A `meta` `FhirComplex`.
664
667
  * @example
665
668
  * ```ts
@@ -655,11 +655,14 @@ declare function reference(ref: string): FhirComplex;
655
655
  */
656
656
  declare function narrative(text: string): FhirComplex;
657
657
  /**
658
- * A `meta.profile` element pinning the resource to one or more canonical profile URLs (US Core
659
- * conformance is claimed via `meta.profile`). No version is pinned, so validating against any supplied
660
- * version of the named profile never raises a version-mismatch.
661
- *
662
- * @param profiles - The canonical profile URLs to claim.
658
+ * A resource's `meta`: the `HTEST` security label in `meta.security`, which says the resource is test
659
+ * data, on every resource this package generates, plus a `meta.profile` pinning the resource to one or
660
+ * more canonical profile URLs when any are given (US Core conformance is claimed via `meta.profile`).
661
+ * No version is pinned, so validating against any supplied version of the named profile never raises
662
+ * a version-mismatch.
663
+ *
664
+ * @param profiles - The canonical profile URLs to claim. Empty for none: `meta.profile` is then left
665
+ * out and `meta` carries only the security label.
663
666
  * @returns A `meta` `FhirComplex`.
664
667
  * @example
665
668
  * ```ts
@@ -566,7 +566,12 @@ function isRequireEsmRefusal(error) {
566
566
  }
567
567
  function loadPeer(specifier, host) {
568
568
  if (host.resolve === void 0) return host.require(specifier);
569
- const entry = fileURLToPath(host.resolve(specifier));
569
+ let entry;
570
+ try {
571
+ entry = fileURLToPath(host.resolve(specifier));
572
+ } catch {
573
+ return host.require(specifier);
574
+ }
570
575
  try {
571
576
  return host.require(entry);
572
577
  } catch (error) {
@@ -613,8 +618,18 @@ function narrative(text) {
613
618
  prop("div", str(`<div xmlns="http://www.w3.org/1999/xhtml"><p>${escaped}</p></div>`))
614
619
  ]);
615
620
  }
621
+ var TEST_DATA_LABEL = Object.freeze({
622
+ system: "http://terminology.hl7.org/CodeSystem/v3-ActReason",
623
+ code: "HTEST",
624
+ display: "test health data"
625
+ });
616
626
  function meta(profiles) {
617
- return fhirPeer().complex([prop("profile", fhirPeer().list(profiles.map((p) => str(p))))]);
627
+ const props = [];
628
+ if (profiles.length > 0) {
629
+ props.push(prop("profile", fhirPeer().list(profiles.map((p) => str(p)))));
630
+ }
631
+ props.push(prop("security", fhirPeer().list([coding(TEST_DATA_LABEL)])));
632
+ return fhirPeer().complex(props);
618
633
  }
619
634
  function toFhirDate(ymd) {
620
635
  return `${ymd.slice(0, 4)}-${ymd.slice(4, 6)}-${ymd.slice(6, 8)}`;
@@ -957,7 +972,7 @@ function generatePatient(options = {}) {
957
972
  prop("resourceType", str("Patient")),
958
973
  prop("id", str(`syn-patient-${id.id}`))
959
974
  ];
960
- if (usCore) props.push(prop("meta", meta([US_CORE_PROFILE.PATIENT])));
975
+ props.push(prop("meta", meta(usCore ? [US_CORE_PROFILE.PATIENT] : [])));
961
976
  props.push(
962
977
  prop(
963
978
  "text",
@@ -1039,7 +1054,7 @@ function generateCondition(options = {}) {
1039
1054
  prop("resourceType", str("Condition")),
1040
1055
  prop("id", str(`syn-cond-${rng.digits(8)}`))
1041
1056
  ];
1042
- if (usCore) props.push(prop("meta", meta([US_CORE_PROFILE.CONDITION])));
1057
+ props.push(prop("meta", meta(usCore ? [US_CORE_PROFILE.CONDITION] : [])));
1043
1058
  props.push(prop("text", narrative(`Synthetic condition: ${code.display}.`)));
1044
1059
  props.push(
1045
1060
  prop(
@@ -1095,7 +1110,7 @@ function buildObservation(seed, subject, usCore, profileUrl, category, pool, eff
1095
1110
  prop("resourceType", str("Observation")),
1096
1111
  prop("id", str(`syn-obs-${rng.digits(8)}`))
1097
1112
  ];
1098
- if (usCore) props.push(prop("meta", meta([profileUrl])));
1113
+ props.push(prop("meta", meta(usCore ? [profileUrl] : [])));
1099
1114
  props.push(
1100
1115
  prop("text", narrative(`Synthetic ${category.display.toLowerCase()}: ${concept.display}.`))
1101
1116
  );
@@ -1163,7 +1178,7 @@ function generateMedicationRequest(options = {}) {
1163
1178
  prop("resourceType", str("MedicationRequest")),
1164
1179
  prop("id", str(`syn-medreq-${rng.digits(8)}`))
1165
1180
  ];
1166
- if (usCore) props.push(prop("meta", meta([US_CORE_PROFILE.MEDICATION_REQUEST])));
1181
+ props.push(prop("meta", meta(usCore ? [US_CORE_PROFILE.MEDICATION_REQUEST] : [])));
1167
1182
  props.push(prop("text", narrative(`Synthetic medication order: ${med.display}.`)));
1168
1183
  props.push(prop("status", str("active")));
1169
1184
  props.push(prop("intent", str("order")));
@@ -1186,7 +1201,7 @@ function generateEncounter(options = {}) {
1186
1201
  prop("resourceType", str("Encounter")),
1187
1202
  prop("id", str(`syn-enc-${rng.digits(8)}`))
1188
1203
  ];
1189
- if (usCore) props.push(prop("meta", meta([US_CORE_PROFILE.ENCOUNTER])));
1204
+ props.push(prop("meta", meta(usCore ? [US_CORE_PROFILE.ENCOUNTER] : [])));
1190
1205
  props.push(prop("text", narrative(`Synthetic encounter: ${type.display}.`)));
1191
1206
  props.push(
1192
1207
  prop(
@@ -1217,7 +1232,7 @@ function generateImmunization(options = {}) {
1217
1232
  prop("resourceType", str("Immunization")),
1218
1233
  prop("id", str(`syn-imm-${rng.digits(8)}`))
1219
1234
  ];
1220
- if (usCore) props.push(prop("meta", meta([US_CORE_PROFILE.IMMUNIZATION])));
1235
+ props.push(prop("meta", meta(usCore ? [US_CORE_PROFILE.IMMUNIZATION] : [])));
1221
1236
  props.push(prop("text", narrative(`Synthetic immunization: ${vaccine.display}.`)));
1222
1237
  props.push(prop("status", str("completed")));
1223
1238
  props.push(prop("vaccineCode", codeableConcept(vaccine)));
@@ -1237,7 +1252,7 @@ function generateAllergyIntolerance(options = {}) {
1237
1252
  prop("resourceType", str("AllergyIntolerance")),
1238
1253
  prop("id", str(`syn-allergy-${rng.digits(8)}`))
1239
1254
  ];
1240
- if (usCore) props.push(prop("meta", meta([US_CORE_PROFILE.ALLERGY_INTOLERANCE])));
1255
+ props.push(prop("meta", meta(usCore ? [US_CORE_PROFILE.ALLERGY_INTOLERANCE] : [])));
1241
1256
  props.push(prop("text", narrative(`Synthetic allergy: ${allergen.display}.`)));
1242
1257
  props.push(
1243
1258
  prop(
@@ -1280,7 +1295,7 @@ function generateProcedure(options = {}) {
1280
1295
  prop("resourceType", str("Procedure")),
1281
1296
  prop("id", str(`syn-proc-${rng.digits(8)}`))
1282
1297
  ];
1283
- if (usCore) props.push(prop("meta", meta([US_CORE_PROFILE.PROCEDURE])));
1298
+ props.push(prop("meta", meta(usCore ? [US_CORE_PROFILE.PROCEDURE] : [])));
1284
1299
  props.push(prop("text", narrative(`Synthetic procedure: ${code.display}.`)));
1285
1300
  props.push(prop("status", str("completed")));
1286
1301
  props.push(prop("code", codeableConcept(code)));
@@ -1300,7 +1315,7 @@ function generateProvenance(options = {}) {
1300
1315
  prop("resourceType", str("Provenance")),
1301
1316
  prop("id", str(`syn-prov-${rng.digits(8)}`))
1302
1317
  ];
1303
- if (usCore) props.push(prop("meta", meta([US_CORE_PROFILE.PROVENANCE])));
1318
+ props.push(prop("meta", meta(usCore ? [US_CORE_PROFILE.PROVENANCE] : [])));
1304
1319
  props.push(prop("text", narrative("Synthetic provenance for a generated fixture.")));
1305
1320
  props.push(prop("target", fhirPeer().list([reference(target)])));
1306
1321
  props.push(prop("recorded", str(`${recorded}T10:00:00Z`)));
@@ -1348,7 +1363,7 @@ function generateDiagnosticReport(options = {}) {
1348
1363
  prop("resourceType", str("DiagnosticReport")),
1349
1364
  prop("id", str(`syn-dr-${rng.digits(8)}`))
1350
1365
  ];
1351
- if (usCore) props.push(prop("meta", meta([US_CORE_PROFILE.DIAGNOSTIC_REPORT_LAB])));
1366
+ props.push(prop("meta", meta(usCore ? [US_CORE_PROFILE.DIAGNOSTIC_REPORT_LAB] : [])));
1352
1367
  props.push(prop("text", narrative(`Synthetic laboratory report: ${code.display}.`)));
1353
1368
  props.push(prop("status", str("final")));
1354
1369
  props.push(
@@ -1407,6 +1422,7 @@ function buildComposition(rng, input) {
1407
1422
  const props = [
1408
1423
  prop("resourceType", str("Composition")),
1409
1424
  prop("id", str(`syn-comp-${rng.digits(8)}`)),
1425
+ prop("meta", meta([])),
1410
1426
  prop("text", narrative("Synthetic continuity-of-care document summary.")),
1411
1427
  prop("status", str("final")),
1412
1428
  prop(
@@ -1464,6 +1480,7 @@ function buildOrganization(rng) {
1464
1480
  return fhirPeer().complex([
1465
1481
  prop("resourceType", str("Organization")),
1466
1482
  prop("id", str(`syn-org-${rng.digits(8)}`)),
1483
+ prop("meta", meta([])),
1467
1484
  prop("text", narrative("Synthetic health organization.")),
1468
1485
  prop(
1469
1486
  "identifier",
@@ -1592,7 +1609,8 @@ function generateBundle(options = {}) {
1592
1609
  });
1593
1610
  const props = [
1594
1611
  prop("resourceType", str("Bundle")),
1595
- prop("id", str(`syn-bundle-${rng.digits(8)}`))
1612
+ prop("id", str(`syn-bundle-${rng.digits(8)}`)),
1613
+ prop("meta", meta([]))
1596
1614
  ];
1597
1615
  if (type === "document") {
1598
1616
  const id = safe.identifier(rng, "AN");