@medplum/agent 5.1.17 → 5.1.18

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 (2) hide show
  1. package/dist/cjs/index.cjs +360 -313
  2. package/package.json +6 -6
@@ -7,7 +7,11 @@ var __getProtoOf = Object.getPrototypeOf;
7
7
  var __hasOwnProp = Object.prototype.hasOwnProperty;
8
8
  var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
9
9
  var __commonJS = (cb, mod) => function __require() {
10
- return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
10
+ try {
11
+ return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
12
+ } catch (e) {
13
+ throw mod = 0, e;
14
+ }
11
15
  };
12
16
  var __export = (target, all) => {
13
17
  for (var name in all)
@@ -4927,6 +4931,7 @@ var require_range = __commonJS({
4927
4931
  return comp;
4928
4932
  };
4929
4933
  var isX = (id) => !id || id.toLowerCase() === "x" || id === "*";
4934
+ var invalidXRangeOrder = (M2, m3, p2) => isX(M2) && !isX(m3) || isX(m3) && p2 && !isX(p2);
4930
4935
  var replaceTildes = (comp, options) => {
4931
4936
  return comp.trim().split(/\s+/).map((c2) => replaceTilde(c2, options)).join(" ");
4932
4937
  };
@@ -4986,9 +4991,9 @@ var require_range = __commonJS({
4986
4991
  debug("no pr");
4987
4992
  if (M2 === "0") {
4988
4993
  if (m3 === "0") {
4989
- ret = `>=${M2}.${m3}.${p2}${z2} <${M2}.${m3}.${+p2 + 1}-0`;
4994
+ ret = `>=${M2}.${m3}.${p2} <${M2}.${m3}.${+p2 + 1}-0`;
4990
4995
  } else {
4991
- ret = `>=${M2}.${m3}.${p2}${z2} <${M2}.${+m3 + 1}.0-0`;
4996
+ ret = `>=${M2}.${m3}.${p2} <${M2}.${+m3 + 1}.0-0`;
4992
4997
  }
4993
4998
  } else {
4994
4999
  ret = `>=${M2}.${m3}.${p2} <${+M2 + 1}.0.0-0`;
@@ -5007,6 +5012,9 @@ var require_range = __commonJS({
5007
5012
  const r6 = options.loose ? re2[t.XRANGELOOSE] : re2[t.XRANGE];
5008
5013
  return comp.replace(r6, (ret, gtlt, M2, m3, p2, pr) => {
5009
5014
  debug("xRange", comp, ret, gtlt, M2, m3, p2, pr);
5015
+ if (invalidXRangeOrder(M2, m3, p2)) {
5016
+ return comp;
5017
+ }
5010
5018
  const xM = isX(M2);
5011
5019
  const xm = xM || isX(m3);
5012
5020
  const xp = xm || isX(p2);
@@ -19965,12 +19973,12 @@ var require_dcmjs = __commonJS({
19965
19973
  value: function xyz2LAB(xyz) {
19966
19974
  var whitePoint = Colors3.d65WhitePointXYZ();
19967
19975
  var X = xyz[0] / whitePoint[0];
19968
- var Y = xyz[1] / whitePoint[1];
19969
- var Z2 = xyz[2] / whitePoint[2];
19976
+ var Y2 = xyz[1] / whitePoint[1];
19977
+ var Z = xyz[2] / whitePoint[2];
19970
19978
  X = Colors3.labf(X);
19971
- Y = Colors3.labf(Y);
19972
- Z2 = Colors3.labf(Z2);
19973
- return [116 * Y - 16, 500 * (X - Y), 200 * (Y - Z2)];
19979
+ Y2 = Colors3.labf(Y2);
19980
+ Z = Colors3.labf(Z);
19981
+ return [116 * Y2 - 16, 500 * (X - Y2), 200 * (Y2 - Z)];
19974
19982
  }
19975
19983
  }, {
19976
19984
  key: "lab2RGB",
@@ -35853,8 +35861,8 @@ var require_dcmjs_dimse_min = __commonJS({
35853
35861
  }
35854
35862
  };
35855
35863
  }, 371(e2, t2, s2) {
35856
- const { Association: n2 } = s2(570), { AAbort: i2, AAssociateAC: r7, AAssociateRJ: o3, AAssociateRQ: a2, AReleaseRP: c3, AReleaseRQ: d3, PDataTF: u2, Pdv: h2, RawPdu: m3 } = s2(942), { CommandFieldType: g2, RawPduType: l, Status: p2 } = s2(492), { CCancelRequest: R3, CEchoRequest: S3, CEchoResponse: y3, CFindRequest: f2, CFindResponse: I2, CGetRequest: C3, CGetResponse: P2, CMoveRequest: v2, CMoveResponse: x2, Command: A3, CStoreRequest: U2, CStoreResponse: w, NActionRequest: D2, NActionResponse: q, NCreateRequest: E2, NCreateResponse: T2, NDeleteRequest: b3, NDeleteResponse: O3, NEventReportRequest: N3, NEventReportResponse: B3, NGetRequest: M2, NGetResponse: L2, NSetRequest: F2, NSetResponse: k2, Response: $2 } = s2(940), V2 = s2(825), j2 = s2(139), _2 = s2(906), G2 = s2(73), z2 = s2(547), { SmartBuffer: Q3 } = s2(766), { EOL: W3 } = s2(857), J = s2(0), X = s2(235);
35857
- class H2 extends J {
35864
+ const { Association: n2 } = s2(570), { AAbort: i2, AAssociateAC: r7, AAssociateRJ: o3, AAssociateRQ: a2, AReleaseRP: c3, AReleaseRQ: d3, PDataTF: u2, Pdv: h2, RawPdu: m3 } = s2(942), { CommandFieldType: g2, RawPduType: l, Status: p2 } = s2(492), { CCancelRequest: R3, CEchoRequest: S3, CEchoResponse: y3, CFindRequest: f2, CFindResponse: I2, CGetRequest: C3, CGetResponse: P2, CMoveRequest: v2, CMoveResponse: x2, Command: A3, CStoreRequest: U2, CStoreResponse: w, NActionRequest: D2, NActionResponse: q, NCreateRequest: E2, NCreateResponse: T2, NDeleteRequest: b3, NDeleteResponse: O3, NEventReportRequest: N3, NEventReportResponse: B3, NGetRequest: M2, NGetResponse: L2, NSetRequest: F2, NSetResponse: k2, Response: $2 } = s2(940), V2 = s2(825), j2 = s2(139), _2 = s2(906), G2 = s2(73), z2 = s2(547), { SmartBuffer: Q3 } = s2(766), { EOL: W3 } = s2(857), J2 = s2(0), X = s2(235);
35865
+ class H2 extends J2 {
35858
35866
  constructor() {
35859
35867
  super();
35860
35868
  }
@@ -35887,7 +35895,7 @@ var require_dcmjs_dimse_min = __commonJS({
35887
35895
  }
35888
35896
  }
35889
35897
  }
35890
- e2.exports = class extends J {
35898
+ e2.exports = class extends J2 {
35891
35899
  constructor(e3, t3) {
35892
35900
  super(), this.messageId = 0, this.socket = e3, this.requests = [], this.pending = [], this.dimseStream = void 0, this.dimseStoreStream = void 0, this.dimse = void 0, t3 = t3 || {}, this.connectTimeout = t3.connectTimeout || 18e4, this.associationTimeout = t3.associationTimeout || 6e4, this.pduTimeout = t3.pduTimeout || 6e4, this.logCommandDatasets = t3.logCommandDatasets || false, this.logDatasets = t3.logDatasets || false, this.datasetReadOptions = t3.datasetReadOptions || {}, this.datasetWriteOptions = t3.datasetWriteOptions || {}, this.datasetNameMap = t3.datasetNameMap || {}, this.datasetTranscodeOptions = t3.datasetTranscodeOptions || {}, this.logId = "", this.connected = false, this.connectedTime = void 0, this.lastPduTime = void 0, this.timeoutIntervalId = void 0, this.statistics = new _2(), this._wrapSocket();
35893
35901
  }
@@ -36830,7 +36838,7 @@ var require_dcmjs_dimse_min = __commonJS({
36830
36838
  }
36831
36839
  };
36832
36840
  }, 237(e2, t2, s2) {
36833
- const { Association: n2, PresentationContext: i2 } = s2(570), { Scp: r7, Server: o3 } = s2(538), { CCancelRequest: a2, CEchoRequest: c3, CEchoResponse: d3, CFindRequest: u2, CFindResponse: h2, CGetRequest: m3, CGetResponse: g2, CMoveRequest: l, CMoveResponse: p2, CStoreRequest: R3, CStoreResponse: S3, NActionRequest: y3, NActionResponse: f2, NCreateRequest: I2, NCreateResponse: C3, NDeleteRequest: P2, NDeleteResponse: v2, NEventReportRequest: x2, NEventReportResponse: A3, NGetRequest: U2, NGetResponse: w, NSetRequest: D2, NSetResponse: q } = s2(940), { AbortReason: E2, AbortSource: T2, CommandFieldType: b3, PresentationContextResult: O3, Priority: N3, RawPduType: B3, RejectReason: M2, RejectResult: L2, RejectSource: F2, SopClass: k2, Status: $2, StorageClass: V2, TransferSyntax: j2, Uid: _2, UserIdentityType: G2 } = s2(492), z2 = s2(422), Q3 = s2(825), W3 = s2(139), J = s2(906), X = s2(73), H2 = { association: { Association: n2, PresentationContext: i2 }, Client: z2, constants: { AbortReason: E2, AbortSource: T2, CommandFieldType: b3, PresentationContextResult: O3, Priority: N3, RawPduType: B3, RejectReason: M2, RejectResult: L2, RejectSource: F2, SopClass: k2, Status: $2, StorageClass: V2, TransferSyntax: j2, Uid: _2, UserIdentityType: G2 }, Dataset: Q3, Implementation: W3, log: s2(547), requests: { CCancelRequest: a2, CEchoRequest: c3, CFindRequest: u2, CGetRequest: m3, CMoveRequest: l, CStoreRequest: R3, NActionRequest: y3, NCreateRequest: I2, NDeleteRequest: P2, NEventReportRequest: x2, NGetRequest: U2, NSetRequest: D2 }, responses: { CEchoResponse: d3, CFindResponse: h2, CGetResponse: g2, CMoveResponse: p2, CStoreResponse: S3, NActionResponse: f2, NCreateResponse: C3, NDeleteResponse: v2, NEventReportResponse: A3, NGetResponse: w, NSetResponse: q }, Scp: r7, Server: o3, Statistics: J, Transcoding: X, version: s2(837) };
36841
+ const { Association: n2, PresentationContext: i2 } = s2(570), { Scp: r7, Server: o3 } = s2(538), { CCancelRequest: a2, CEchoRequest: c3, CEchoResponse: d3, CFindRequest: u2, CFindResponse: h2, CGetRequest: m3, CGetResponse: g2, CMoveRequest: l, CMoveResponse: p2, CStoreRequest: R3, CStoreResponse: S3, NActionRequest: y3, NActionResponse: f2, NCreateRequest: I2, NCreateResponse: C3, NDeleteRequest: P2, NDeleteResponse: v2, NEventReportRequest: x2, NEventReportResponse: A3, NGetRequest: U2, NGetResponse: w, NSetRequest: D2, NSetResponse: q } = s2(940), { AbortReason: E2, AbortSource: T2, CommandFieldType: b3, PresentationContextResult: O3, Priority: N3, RawPduType: B3, RejectReason: M2, RejectResult: L2, RejectSource: F2, SopClass: k2, Status: $2, StorageClass: V2, TransferSyntax: j2, Uid: _2, UserIdentityType: G2 } = s2(492), z2 = s2(422), Q3 = s2(825), W3 = s2(139), J2 = s2(906), X = s2(73), H2 = { association: { Association: n2, PresentationContext: i2 }, Client: z2, constants: { AbortReason: E2, AbortSource: T2, CommandFieldType: b3, PresentationContextResult: O3, Priority: N3, RawPduType: B3, RejectReason: M2, RejectResult: L2, RejectSource: F2, SopClass: k2, Status: $2, StorageClass: V2, TransferSyntax: j2, Uid: _2, UserIdentityType: G2 }, Dataset: Q3, Implementation: W3, log: s2(547), requests: { CCancelRequest: a2, CEchoRequest: c3, CFindRequest: u2, CGetRequest: m3, CMoveRequest: l, CStoreRequest: R3, NActionRequest: y3, NCreateRequest: I2, NDeleteRequest: P2, NEventReportRequest: x2, NGetRequest: U2, NSetRequest: D2 }, responses: { CEchoResponse: d3, CFindResponse: h2, CGetResponse: g2, CMoveResponse: p2, CStoreResponse: S3, NActionResponse: f2, NCreateResponse: C3, NDeleteResponse: v2, NEventReportResponse: A3, NGetResponse: w, NSetResponse: q }, Scp: r7, Server: o3, Statistics: J2, Transcoding: X, version: s2(837) };
36834
36842
  e2.exports = H2;
36835
36843
  }, 547(e2, t2, s2) {
36836
36844
  const n2 = s2(360), i2 = s2(707);
@@ -45883,11 +45891,11 @@ var require_http = __commonJS({
45883
45891
  _doBatch(options, callback, auth, path4) {
45884
45892
  this.batchOptions.push(options);
45885
45893
  if (this.batchOptions.length === 1) {
45886
- const me = this;
45894
+ const me2 = this;
45887
45895
  this.batchCallback = callback;
45888
45896
  this.batchTimeoutID = setTimeout(function() {
45889
- me.batchTimeoutID = -1;
45890
- me._doBatchRequest(me.batchCallback, auth, path4);
45897
+ me2.batchTimeoutID = -1;
45898
+ me2._doBatchRequest(me2.batchCallback, auth, path4);
45891
45899
  }, this.batchInterval);
45892
45900
  }
45893
45901
  if (this.batchOptions.length === this.batchCount) {
@@ -52773,7 +52781,7 @@ module.exports = __toCommonJS(main_exports);
52773
52781
  var Lo = Object.defineProperty;
52774
52782
  var No = (r6, e, t) => e in r6 ? Lo(r6, e, { enumerable: true, configurable: true, writable: true, value: t }) : r6[e] = t;
52775
52783
  var c = (r6, e, t) => No(r6, typeof e != "symbol" ? e + "" : e, t);
52776
- var K = class {
52784
+ var Y = class {
52777
52785
  constructor(e = 10) {
52778
52786
  c(this, "max");
52779
52787
  c(this, "cache");
@@ -52898,7 +52906,7 @@ var fr = class {
52898
52906
  return this.infixParselets[e.id === "Symbol" ? e.value : e.id];
52899
52907
  }
52900
52908
  };
52901
- function oe(r6) {
52909
+ function se(r6) {
52902
52910
  if (r6 !== void 0) return Array.isArray(r6) ? r6 : [r6];
52903
52911
  }
52904
52912
  var ft = "http://hl7.org";
@@ -52909,11 +52917,11 @@ var yr = "not-found";
52909
52917
  var vr = "unauthorized";
52910
52918
  var gt = "accepted";
52911
52919
  var Fn = { resourceType: "OperationOutcome", id: yr, issue: [{ severity: "error", code: "not-found", details: { text: "Not found" } }] };
52912
- var Ne = { resourceType: "OperationOutcome", id: vr, issue: [{ severity: "error", code: "login", details: { text: "Unauthorized" } }] };
52913
- var Un = { ...Ne, issue: [...Ne.issue, { severity: "error", code: "expired", details: { text: "Token expired" } }] };
52914
- var Tr = { ...Ne, issue: [...Ne.issue, { severity: "error", code: "invalid", details: { text: "Token not issued for this audience" } }] };
52920
+ var Fe = { resourceType: "OperationOutcome", id: vr, issue: [{ severity: "error", code: "login", details: { text: "Unauthorized" } }] };
52921
+ var Un = { ...Fe, issue: [...Fe.issue, { severity: "error", code: "expired", details: { text: "Token expired" } }] };
52922
+ var Tr = { ...Fe, issue: [...Fe.issue, { severity: "error", code: "invalid", details: { text: "Token not issued for this audience" } }] };
52915
52923
  function P(r6, e) {
52916
- return { resourceType: "OperationOutcome", issue: [{ severity: "error", code: "invalid", details: { text: r6 }, ...e ? { expression: oe(e) } : void 0 }] };
52924
+ return { resourceType: "OperationOutcome", issue: [{ severity: "error", code: "invalid", details: { text: r6 }, ...e ? { expression: se(e) } : void 0 }] };
52917
52925
  }
52918
52926
  function T(r6, e, t, n) {
52919
52927
  return { resourceType: "OperationOutcome", issue: [{ severity: "error", code: t ?? "structure", details: { text: r6 }, ...e ? { expression: e } : void 0, ...n ? { diagnostics: n } : void 0 }] };
@@ -52935,9 +52943,9 @@ var f = class extends Error {
52935
52943
  }
52936
52944
  };
52937
52945
  function yt(r6) {
52938
- return r6 instanceof f ? r6.outcome : ze(r6) ? r6 : P(Se(r6));
52946
+ return r6 instanceof f ? r6.outcome : ze(r6) ? r6 : P(be(r6));
52939
52947
  }
52940
- function Se(r6) {
52948
+ function be(r6) {
52941
52949
  return r6 ? typeof r6 == "string" ? r6 : Sr(r6) ? r6.message : ze(r6) ? Bn(r6) : typeof r6 == "object" && "code" in r6 && typeof r6.code == "string" ? r6.code : JSON.stringify(r6) : "Unknown error";
52942
52950
  }
52943
52951
  function Bn(r6) {
@@ -52961,7 +52969,7 @@ var $n = { Element: { elements: { id: { type: [{ code: "string" }] }, extension:
52961
52969
  function Pr(r6) {
52962
52970
  return new Rr(r6).parse();
52963
52971
  }
52964
- var Ee = jn($n);
52972
+ var Re = jn($n);
52965
52973
  var Ar = /* @__PURE__ */ Object.create(null);
52966
52974
  var Hn = /* @__PURE__ */ Object.create(null);
52967
52975
  var jo = { "http://hl7.org/fhir/StructureDefinition/MoneyQuantity": "MoneyQuantity", "http://hl7.org/fhir/StructureDefinition/SimpleQuantity": "SimpleQuantity", "http://hl7.org/fhir/uv/sql-on-fhir/StructureDefinition/ViewDefinition": "ViewDefinition" };
@@ -52978,19 +52986,19 @@ function Or(r6) {
52978
52986
  if (!r6?.name) throw new Error("Failed loading StructureDefinition from bundle");
52979
52987
  if (r6.resourceType !== "StructureDefinition") return;
52980
52988
  let e = Pr(r6), t = jo[r6.url], n, i;
52981
- t ? (n = Ee, i = t) : r6.url === `http://hl7.org/fhir/StructureDefinition/${r6.type}` || r6.url === `https://medplum.com/fhir/StructureDefinition/${r6.type}` || r6.type?.startsWith("http://") || r6.type?.startsWith("https://") ? (n = Ee, i = r6.type) : (n = Jn(r6.url), i = r6.type), n[i] = e;
52989
+ t ? (n = Re, i = t) : r6.url === `http://hl7.org/fhir/StructureDefinition/${r6.type}` || r6.url === `https://medplum.com/fhir/StructureDefinition/${r6.type}` || r6.type?.startsWith("http://") || r6.type?.startsWith("https://") ? (n = Re, i = r6.type) : (n = Jn(r6.url), i = r6.type), n[i] = e;
52982
52990
  for (let o2 of e.innerTypes) o2.parentType = e, n[o2.name] = o2;
52983
52991
  Ar[r6.url] = e;
52984
52992
  }
52985
52993
  function Yn(r6) {
52986
- return !!Ee[r6];
52994
+ return !!Re[r6];
52987
52995
  }
52988
- function Re(r6, e) {
52996
+ function Ce(r6, e) {
52989
52997
  if (e) {
52990
52998
  let t = Jn(e)[r6];
52991
52999
  if (t) return t;
52992
53000
  }
52993
- return Ee[r6];
53001
+ return Re[r6];
52994
53002
  }
52995
53003
  function Xn(r6) {
52996
53004
  return !!Ar[r6];
@@ -53039,12 +53047,12 @@ var Rr = class {
53039
53047
  return this.checkFieldExit(), this.innerTypes.length > 0 && (this.resourceSchema.innerTypes = this.innerTypes), this.resourceSchema;
53040
53048
  }
53041
53049
  checkFieldEnter(e, t) {
53042
- this.isInnerType(e) && this.enterInnerType(e), this.slicingContext && !Fe(this.slicingContext.path, e?.path) && (this.slicingContext = void 0), e.slicing && !this.slicingContext && this.enterSlice(e, t);
53050
+ this.isInnerType(e) && this.enterInnerType(e), this.slicingContext && !Ue(this.slicingContext.path, e?.path) && (this.slicingContext = void 0), e.slicing && !this.slicingContext && this.enterSlice(e, t);
53043
53051
  }
53044
53052
  enterInnerType(e) {
53045
- for (; this.backboneContext && !Fe(this.backboneContext?.path, e.path); ) this.innerTypes.push(this.backboneContext.type), this.backboneContext = this.backboneContext.parent;
53053
+ for (; this.backboneContext && !Ue(this.backboneContext?.path, e.path); ) this.innerTypes.push(this.backboneContext.type), this.backboneContext = this.backboneContext.parent;
53046
53054
  let t = Cr(e);
53047
- this.backboneContext = { type: { name: t, type: t, path: e.path, title: e.label, description: e.definition, elements: {}, constraints: this.parseElementDefinition(e).constraints, innerTypes: [] }, path: e.path, parent: Fe(this.backboneContext?.path, e.path) ? this.backboneContext : this.backboneContext?.parent };
53055
+ this.backboneContext = { type: { name: t, type: t, path: e.path, title: e.label, description: e.definition, elements: {}, constraints: this.parseElementDefinition(e).constraints, innerTypes: [] }, path: e.path, parent: Ue(this.backboneContext?.path, e.path) ? this.backboneContext : this.backboneContext?.parent };
53048
53056
  }
53049
53057
  enterSlice(e, t) {
53050
53058
  Go(e) && !this.peek()?.sliceName || (t.slicing = { discriminator: (e.slicing?.discriminator ?? []).map((n) => {
@@ -53053,9 +53061,9 @@ var Rr = class {
53053
53061
  }), slices: [], ordered: e.slicing?.ordered ?? false, rule: e.slicing?.rules }, this.slicingContext = { field: t.slicing, path: e.path ?? "" });
53054
53062
  }
53055
53063
  checkFieldExit(e = void 0) {
53056
- if (this.backboneContext && !Fe(this.backboneContext.path, e?.path)) if (this.backboneContext.parent) do
53064
+ if (this.backboneContext && !Ue(this.backboneContext.path, e?.path)) if (this.backboneContext.parent) do
53057
53065
  this.innerTypes.push(this.backboneContext.type), this.backboneContext = this.backboneContext.parent;
53058
- while (this.backboneContext && !Fe(this.backboneContext.path, e?.path));
53066
+ while (this.backboneContext && !Ue(this.backboneContext.path, e?.path));
53059
53067
  else this.innerTypes.push(this.backboneContext.type), this.backboneContext = void 0;
53060
53068
  }
53061
53069
  next() {
@@ -53074,7 +53082,7 @@ var Rr = class {
53074
53082
  }
53075
53083
  isInnerType(e) {
53076
53084
  let t = this.peek();
53077
- return !!(Fe(e?.path, t?.path) && e.type?.some((n) => ["BackboneElement", "Element"].includes(n.code)));
53085
+ return !!(Ue(e?.path, t?.path) && e.type?.some((n) => ["BackboneElement", "Element"].includes(n.code)));
53078
53086
  }
53079
53087
  parseSliceStart(e) {
53080
53088
  if (!this.slicingContext) throw new Error(`Invalid slice start before discriminator: ${e.sliceName} (${e.id})`);
@@ -53083,7 +53091,7 @@ var Rr = class {
53083
53091
  parseElementDefinitionType(e) {
53084
53092
  return (e.type ?? []).map((t) => {
53085
53093
  let n;
53086
- return (t.code === "BackboneElement" || t.code === "Element") && (n = Cr(e)), n || (n = pe(t, "http://hl7.org/fhir/StructureDefinition/structuredefinition-fhir-type")?.valueUrl), n || (n = t.code ?? ""), { code: n, targetProfile: t.targetProfile, profile: t.profile };
53094
+ return (t.code === "BackboneElement" || t.code === "Element") && (n = Cr(e)), n || (n = fe(t, "http://hl7.org/fhir/StructureDefinition/structuredefinition-fhir-type")?.valueUrl), n || (n = t.code ?? ""), { code: n, targetProfile: t.targetProfile, profile: t.profile };
53087
53095
  });
53088
53096
  }
53089
53097
  parseElementDefinition(e) {
@@ -53100,7 +53108,7 @@ function Er(r6, e = "") {
53100
53108
  function Ho(r6, e) {
53101
53109
  return r6 ? e && r6.startsWith(e) ? r6.substring(e.length + 1) : r6 : "";
53102
53110
  }
53103
- function Fe(r6, e) {
53111
+ function Ue(r6, e) {
53104
53112
  return !r6 || !e ? false : e.startsWith(r6 + ".") || e === r6;
53105
53113
  }
53106
53114
  function zn(r6) {
@@ -53122,7 +53130,7 @@ function zo(r6, e, t) {
53122
53130
  let n = e ? e + "." : "";
53123
53131
  return r6 === void 0 ? { type: "undefined", value: void 0, path: `${n}${t}` } : Array.isArray(r6) ? r6.map((i, o2) => ({ ...i, path: `${n}${t}[${o2}]` })) : { ...r6, path: `${n}${t}` };
53124
53132
  }
53125
- var Jo = new K(1e3);
53133
+ var Jo = new Y(1e3);
53126
53134
  var Tt = { canonical: /^\S*$/, code: /^[^\s]+( [^\s]+)*$/, date: /^(\d(\d(\d[1-9]|[1-9]0)|[1-9]00)|[1-9]000)(-(0[1-9]|1[0-2])(-(0[1-9]|[1-2]\d|3[0-1]))?)?$/, dateTime: /^(\d(\d(\d[1-9]|[1-9]0)|[1-9]00)|[1-9]000)(-(0[1-9]|1[0-2])(-(0[1-9]|[1-2]\d|3[0-1])(T([01]\d|2[0-3])(:[0-5]\d:([0-5]\d|60)(\.\d{1,9})?)?)?)?(Z|[+-]((0\d|1[0-3]):[0-5]\d|14:00)?)?)?$/, id: /^[A-Za-z0-9\-.]{1,64}$/, instant: /^(\d(\d(\d[1-9]|[1-9]0)|[1-9]00)|[1-9]000)-(0[1-9]|1[0-2])-(0[1-9]|[1-2]\d|3[0-1])T([01]\d|2[0-3]):[0-5]\d:([0-5]\d|60)(\.\d{1,9})?(Z|[+-]((0\d|1[0-3]):[0-5]\d|14:00))$/, markdown: /^[\r\n\t\u0020-\uFFFF]+$/, oid: /^urn:oid:[0-2](\.(0|[1-9]\d*))+$/, string: /^[\r\n\t\u0020-\uFFFF]+$/, time: /^([01]\d|2[0-3]):[0-5]\d:([0-5]\d|60)(\.\d{1,9})?$/, uri: /^\S*$/, url: /^\S*$/, uuid: /^urn:uuid:[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/, xhtml: /.*/ };
53127
53135
  function h(r6) {
53128
53136
  return [{ type: d.boolean, value: r6 }];
@@ -53240,7 +53248,7 @@ function Et(r6, e) {
53240
53248
  case "Date":
53241
53249
  return ai(t);
53242
53250
  case "DateTime":
53243
- return Be(t);
53251
+ return We(t);
53244
53252
  case "Time":
53245
53253
  return typeof t == "string" && !!/^T\d/.exec(t);
53246
53254
  case "Period":
@@ -53254,11 +53262,11 @@ function Et(r6, e) {
53254
53262
  function ai(r6) {
53255
53263
  return typeof r6 == "string" && !!Tt.date.exec(r6);
53256
53264
  }
53257
- function Be(r6) {
53265
+ function We(r6) {
53258
53266
  return typeof r6 == "string" && !!Tt.dateTime.exec(r6);
53259
53267
  }
53260
53268
  function ci(r6) {
53261
- return !!(r6 && typeof r6 == "object" && ("start" in r6 && Be(r6.start) || "end" in r6 && Be(r6.end)));
53269
+ return !!(r6 && typeof r6 == "object" && ("start" in r6 && We(r6.start) || "end" in r6 && We(r6.end)));
53262
53270
  }
53263
53271
  function V(r6) {
53264
53272
  return !!(r6 && typeof r6 == "object" && "value" in r6 && typeof r6.value == "number");
@@ -53293,16 +53301,16 @@ function cs(r6, e) {
53293
53301
  function Xe(r6, e) {
53294
53302
  return I(r6, e) && "id" in r6 && typeof r6.id == "string";
53295
53303
  }
53296
- function Ce(r6) {
53304
+ function Pe(r6) {
53297
53305
  let e = O(r6) ?? "undefined/undefined", t = ls(r6);
53298
53306
  return t === e ? { reference: e } : { reference: e, display: t };
53299
53307
  }
53300
53308
  function O(r6) {
53301
- if (Q(r6)) return r6.reference;
53309
+ if (z(r6)) return r6.reference;
53302
53310
  if (Xe(r6)) return `${r6.resourceType}/${r6.id}`;
53303
53311
  }
53304
- function Pe(r6) {
53305
- if (r6) return Q(r6) ? r6.reference.split("/")[1] : r6.id;
53312
+ function Ae(r6) {
53313
+ if (r6) return z(r6) ? r6.reference.split("/")[1] : r6.id;
53306
53314
  }
53307
53315
  function us(r6) {
53308
53316
  return r6.resourceType === "Patient" || r6.resourceType === "Practitioner" || r6.resourceType === "RelatedPerson";
@@ -53347,7 +53355,7 @@ function Pt(r6, e) {
53347
53355
  let v2 = Math.floor((n.getTime() - t.getTime()) / (1e3 * 60 * 60 * 24));
53348
53356
  return { years: p2, months: g2, days: v2 };
53349
53357
  }
53350
- function pe(r6, ...e) {
53358
+ function fe(r6, ...e) {
53351
53359
  let t = r6;
53352
53360
  for (let n = 0; n < e.length && t; n++) t = t?.extension?.find((i) => i.url === e[n]);
53353
53361
  return t;
@@ -53380,19 +53388,19 @@ function ms(r6) {
53380
53388
  function A(r6) {
53381
53389
  if (r6 == null) return true;
53382
53390
  let e = typeof r6;
53383
- return e === "string" || e === "object" ? !se(r6) : false;
53391
+ return e === "string" || e === "object" ? !ae(r6) : false;
53384
53392
  }
53385
- function se(r6) {
53393
+ function ae(r6) {
53386
53394
  if (r6 == null) return false;
53387
53395
  let e = typeof r6;
53388
53396
  return e === "string" && r6 !== "" || e === "object" && ("length" in r6 && r6.length > 0 || Object.keys(r6).length > 0);
53389
53397
  }
53390
- function fe(r6, e, t) {
53398
+ function me(r6, e, t) {
53391
53399
  return r6 === e || A(r6) && A(e) ? true : A(r6) || A(e) ? false : Array.isArray(r6) && Array.isArray(e) ? hs(r6, e) : Array.isArray(r6) || Array.isArray(e) ? false : C(r6) && C(e) ? gs(r6, e, t) : (C(r6) || C(e), false);
53392
53400
  }
53393
53401
  function hs(r6, e) {
53394
53402
  if (r6.length !== e.length) return false;
53395
- for (let t = 0; t < r6.length; t++) if (!fe(r6[t], e[t])) return false;
53403
+ for (let t = 0; t < r6.length; t++) if (!me(r6[t], e[t])) return false;
53396
53404
  return true;
53397
53405
  }
53398
53406
  function gs(r6, e, t) {
@@ -53402,7 +53410,7 @@ function gs(r6, e, t) {
53402
53410
  t === "meta" && (n.delete("versionId"), n.delete("lastUpdated"), n.delete("author"));
53403
53411
  for (let i of n) {
53404
53412
  let o2 = r6[i], s = e[i];
53405
- if (!fe(o2, s, i)) return false;
53413
+ if (!me(o2, s, i)) return false;
53406
53414
  }
53407
53415
  return true;
53408
53416
  }
@@ -53443,7 +53451,7 @@ var Kr = (r6, e) => new Promise((t, n) => {
53443
53451
  clearTimeout(i), n(e.signal?.reason);
53444
53452
  }, { once: true });
53445
53453
  });
53446
- function qe(r6, e, t) {
53454
+ function je(r6, e, t) {
53447
53455
  let n = [];
53448
53456
  for (let i = 0; i < t - 1; i++) {
53449
53457
  let o2 = r6.indexOf(e);
@@ -53471,7 +53479,7 @@ function Si(r6) {
53471
53479
  return typeof r6 == "object" && !Array.isArray(r6) && !(r6 instanceof URLSearchParams) && (r6 = Object.fromEntries(Object.entries(r6).filter((e) => e[1] !== void 0))), new URLSearchParams(r6).toString();
53472
53480
  }
53473
53481
  var ws = /^(([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9\-_]*[a-zA-Z0-9])\.)*([A-Za-z0-9]|[A-Za-z0-9][A-Za-z0-9\-_]*[A-Za-z0-9])$/;
53474
- function Cd(r6) {
53482
+ function Ad(r6) {
53475
53483
  return ws.test(r6);
53476
53484
  }
53477
53485
  var y = Object.freeze([]);
@@ -53479,25 +53487,25 @@ function Ze(r6, e) {
53479
53487
  if (!r6) return "";
53480
53488
  let t = [];
53481
53489
  if (r6.prefix && e?.prefix !== false && t.push(...r6.prefix), r6.given && t.push(...r6.given), r6.family && t.push(r6.family), r6.suffix && e?.suffix !== false && t.push(...r6.suffix), r6.use && (e?.all || e?.use) && t.push("[" + r6.use + "]"), t.length === 0) {
53482
- let n = we(r6.text);
53490
+ let n = Oe(r6.text);
53483
53491
  if (n) return n;
53484
53492
  }
53485
53493
  return t.join(" ").trim();
53486
53494
  }
53487
53495
  function Ye(r6) {
53488
53496
  if (!r6) return "";
53489
- let e = we(r6.text);
53497
+ let e = Oe(r6.text);
53490
53498
  return e || (r6.coding ? r6.coding.map((t) => Ei(t)).join(", ") : "");
53491
53499
  }
53492
53500
  function Ei(r6, e) {
53493
- let t = we(r6?.display);
53501
+ let t = Oe(r6?.display);
53494
53502
  if (t) {
53495
- let n = e ? we(r6?.code) : void 0;
53503
+ let n = e ? Oe(r6?.code) : void 0;
53496
53504
  return `${t}${n ? " (" + n + ")" : ""}`;
53497
53505
  }
53498
- return we(r6?.code) ?? "";
53506
+ return Oe(r6?.code) ?? "";
53499
53507
  }
53500
- function we(r6) {
53508
+ function Oe(r6) {
53501
53509
  return typeof r6 == "string" ? r6 : void 0;
53502
53510
  }
53503
53511
  var d = { Address: "Address", Age: "Age", Annotation: "Annotation", Attachment: "Attachment", BackboneElement: "BackboneElement", CodeableConcept: "CodeableConcept", Coding: "Coding", ContactDetail: "ContactDetail", ContactPoint: "ContactPoint", Contributor: "Contributor", Count: "Count", DataRequirement: "DataRequirement", Distance: "Distance", Dosage: "Dosage", Duration: "Duration", Element: "Element", ElementDefinition: "ElementDefinition", Expression: "Expression", Extension: "Extension", HumanName: "HumanName", Identifier: "Identifier", MarketingStatus: "MarketingStatus", Meta: "Meta", Money: "Money", MoneyQuantity: "MoneyQuantity", Narrative: "Narrative", ParameterDefinition: "ParameterDefinition", Period: "Period", Population: "Population", ProdCharacteristic: "ProdCharacteristic", ProductShelfLife: "ProductShelfLife", Quantity: "Quantity", Range: "Range", Ratio: "Ratio", Reference: "Reference", RelatedArtifact: "RelatedArtifact", SampledData: "SampledData", Signature: "Signature", SimpleQuantity: "SimpleQuantity", SubstanceAmount: "SubstanceAmount", SystemString: "http://hl7.org/fhirpath/System.String", Timing: "Timing", TriggerDefinition: "TriggerDefinition", UsageContext: "UsageContext", base64Binary: "base64Binary", boolean: "boolean", canonical: "canonical", code: "code", date: "date", dateTime: "dateTime", decimal: "decimal", id: "id", instant: "instant", integer: "integer", markdown: "markdown", oid: "oid", positiveInt: "positiveInt", string: "string", time: "time", unsignedInt: "unsignedInt", uri: "uri", url: "url", uuid: "uuid", xhtml: "xhtml" };
@@ -53523,7 +53531,7 @@ function Us(r6) {
53523
53531
  return r6.length === 1 ? r6[0] : r6.map(N).join("");
53524
53532
  }
53525
53533
  function Ct(r6, e, t) {
53526
- let n = Re(r6, t);
53534
+ let n = Ce(r6, t);
53527
53535
  if (n) return Ai(n.elements, e);
53528
53536
  }
53529
53537
  function Ai(r6, e) {
@@ -53540,11 +53548,11 @@ function Ai(r6, e) {
53540
53548
  function I(r6, e) {
53541
53549
  return !(!r6 || typeof r6 != "object" || !("resourceType" in r6) || e && r6.resourceType !== e);
53542
53550
  }
53543
- function Q(r6, e) {
53551
+ function z(r6, e) {
53544
53552
  return r6 && typeof r6 == "object" && "reference" in r6 && typeof r6.reference == "string" ? e ? r6.reference.match(new RegExp(`^${e}(/|\\?)`)) !== null : true : false;
53545
53553
  }
53546
53554
  var $ = { types: {} };
53547
- function je(r6) {
53555
+ function $e(r6) {
53548
53556
  if (r6.startsWith("T")) return r6 + "T00:00:00.000Z".substring(r6.length);
53549
53557
  if (r6.length <= 10) return r6;
53550
53558
  try {
@@ -53553,7 +53561,7 @@ function je(r6) {
53553
53561
  return r6;
53554
53562
  }
53555
53563
  }
53556
- var ae = () => [];
53564
+ var ce = () => [];
53557
53565
  var _ = { empty: (r6, e) => h(e.every((t) => A(t.value))), hasValue: (r6, e) => h(e.length !== 0), exists: (r6, e, t) => t ? h(e.some((n) => j(t.eval(r6, [n])))) : h(e.length > 0 && e.every((n) => !A(n.value))), all: (r6, e, t) => h(e.every((n) => j(t.eval(r6, [n])))), allTrue: (r6, e) => {
53558
53566
  for (let t of e) if (!t.value) return h(false);
53559
53567
  return h(true);
@@ -53568,16 +53576,16 @@ var _ = { empty: (r6, e) => h(e.every((t) => A(t.value))), hasValue: (r6, e) =>
53568
53576
  return h(false);
53569
53577
  }, subsetOf: (r6, e, t) => {
53570
53578
  if (e.length === 0) return h(true);
53571
- let n = t.eval(r6, Oe(r6));
53579
+ let n = t.eval(r6, Ie(r6));
53572
53580
  return n.length === 0 ? h(false) : h(e.every((i) => n.some((o2) => o2.value === i.value)));
53573
53581
  }, supersetOf: (r6, e, t) => {
53574
- let n = t.eval(r6, Oe(r6));
53582
+ let n = t.eval(r6, Ie(r6));
53575
53583
  return n.length === 0 ? h(true) : e.length === 0 ? h(false) : h(n.every((i) => e.some((o2) => o2.value === i.value)));
53576
53584
  }, count: (r6, e) => [{ type: d.integer, value: e.length }], distinct: (r6, e) => {
53577
53585
  let t = [];
53578
53586
  for (let n of e) t.some((i) => i.value === n.value) || t.push(n);
53579
53587
  return t;
53580
- }, isDistinct: (r6, e) => h(e.length === _.distinct(r6, e).length), where: (r6, e, t) => e.filter((n) => j(t.eval(r6, [n]))), select: (r6, e, t) => e.flatMap((n) => t.eval({ parent: r6, variables: { $this: n } }, [n])), repeat: ae, ofType: (r6, e, t) => e.filter((n) => n.type === t.name), single: (r6, e) => {
53588
+ }, isDistinct: (r6, e) => h(e.length === _.distinct(r6, e).length), where: (r6, e, t) => e.filter((n) => j(t.eval(r6, [n]))), select: (r6, e, t) => e.flatMap((n) => t.eval({ parent: r6, variables: { $this: n } }, [n])), repeat: ce, ofType: (r6, e, t) => e.filter((n) => n.type === t.name), single: (r6, e) => {
53581
53589
  if (e.length > 1) throw new Error("Expected input length one for single()");
53582
53590
  return e.length === 0 ? [] : e.slice(0, 1);
53583
53591
  }, first: (r6, e) => e.length === 0 ? [] : e.slice(0, 1), last: (r6, e) => e.length === 0 ? [] : e.slice(-1, e.length), tail: (r6, e) => e.length === 0 ? [] : e.slice(1, e.length), skip: (r6, e, t) => {
@@ -53590,21 +53598,21 @@ var _ = { empty: (r6, e) => h(e.every((t) => A(t.value))), hasValue: (r6, e) =>
53590
53598
  return n <= 0 ? [] : e.slice(0, n);
53591
53599
  }, intersect: (r6, e, t) => {
53592
53600
  if (!t) return e;
53593
- let n = t.eval(r6, Oe(r6)), i = [];
53601
+ let n = t.eval(r6, Ie(r6)), i = [];
53594
53602
  for (let o2 of e) !i.some((s) => s.value === o2.value) && n.some((s) => s.value === o2.value) && i.push(o2);
53595
53603
  return i;
53596
53604
  }, exclude: (r6, e, t) => {
53597
53605
  if (!t) return e;
53598
- let n = t.eval(r6, Oe(r6)), i = [];
53606
+ let n = t.eval(r6, Ie(r6)), i = [];
53599
53607
  for (let o2 of e) n.some((s) => s.value === o2.value) || i.push(o2);
53600
53608
  return i;
53601
53609
  }, union: (r6, e, t) => {
53602
53610
  if (!t) return e;
53603
- let n = t.eval(r6, Oe(r6));
53611
+ let n = t.eval(r6, Ie(r6));
53604
53612
  return bt([...e, ...n]);
53605
53613
  }, combine: (r6, e, t) => {
53606
53614
  if (!t) return e;
53607
- let n = t.eval(r6, Oe(r6));
53615
+ let n = t.eval(r6, Ie(r6));
53608
53616
  return [...e, ...n];
53609
53617
  }, htmlChecks: (r6, e, t) => [b(true)], iif: (r6, e, t, n, i) => {
53610
53618
  let o2 = t.eval(r6, e);
@@ -53612,7 +53620,7 @@ var _ = { empty: (r6, e) => h(e.every((t) => A(t.value))), hasValue: (r6, e) =>
53612
53620
  return j(o2) ? n.eval(r6, e) : i ? i.eval(r6, e) : [];
53613
53621
  }, toBoolean: (r6, e) => {
53614
53622
  if (e.length === 0) return [];
53615
- let [{ value: t }] = ee(e, 1);
53623
+ let [{ value: t }] = te(e, 1);
53616
53624
  if (typeof t == "boolean") return [{ type: d.boolean, value: t }];
53617
53625
  if (typeof t == "number" && (t === 0 || t === 1)) return h(!!t);
53618
53626
  if (typeof t == "string") {
@@ -53623,48 +53631,48 @@ var _ = { empty: (r6, e) => h(e.every((t) => A(t.value))), hasValue: (r6, e) =>
53623
53631
  return [];
53624
53632
  }, convertsToBoolean: (r6, e) => e.length === 0 ? [] : h(_.toBoolean(r6, e).length === 1), toInteger: (r6, e) => {
53625
53633
  if (e.length === 0) return [];
53626
- let [{ value: t }] = ee(e, 1);
53634
+ let [{ value: t }] = te(e, 1);
53627
53635
  return typeof t == "number" ? [{ type: d.integer, value: t }] : typeof t == "string" && /^[+-]?\d+$/.exec(t) ? [{ type: d.integer, value: Number.parseInt(t, 10) }] : typeof t == "boolean" ? [{ type: d.integer, value: t ? 1 : 0 }] : [];
53628
53636
  }, convertsToInteger: (r6, e) => e.length === 0 ? [] : h(_.toInteger(r6, e).length === 1), toDate: (r6, e) => {
53629
53637
  if (e.length === 0) return [];
53630
- let [{ value: t }] = ee(e, 1);
53631
- return typeof t == "string" && /^\d{4}(-\d{2}(-\d{2})?)?/.exec(t) ? [{ type: d.date, value: je(t) }] : [];
53638
+ let [{ value: t }] = te(e, 1);
53639
+ return typeof t == "string" && /^\d{4}(-\d{2}(-\d{2})?)?/.exec(t) ? [{ type: d.date, value: $e(t) }] : [];
53632
53640
  }, convertsToDate: (r6, e) => e.length === 0 ? [] : h(_.toDate(r6, e).length === 1), toDateTime: (r6, e) => {
53633
53641
  if (e.length === 0) return [];
53634
- let [{ value: t }] = ee(e, 1);
53635
- return typeof t == "string" && /^\d{4}(-\d{2}(-\d{2})?)?/.exec(t) ? [{ type: d.dateTime, value: je(t) }] : [];
53642
+ let [{ value: t }] = te(e, 1);
53643
+ return typeof t == "string" && /^\d{4}(-\d{2}(-\d{2})?)?/.exec(t) ? [{ type: d.dateTime, value: $e(t) }] : [];
53636
53644
  }, convertsToDateTime: (r6, e) => e.length === 0 ? [] : h(_.toDateTime(r6, e).length === 1), toDecimal: (r6, e) => {
53637
53645
  if (e.length === 0) return [];
53638
- let [{ value: t }] = ee(e, 1);
53646
+ let [{ value: t }] = te(e, 1);
53639
53647
  return typeof t == "number" ? [{ type: d.decimal, value: t }] : typeof t == "string" && /^-?\d{1,9}(\.\d{1,9})?$/.exec(t) ? [{ type: d.decimal, value: Number.parseFloat(t) }] : typeof t == "boolean" ? [{ type: d.decimal, value: t ? 1 : 0 }] : [];
53640
53648
  }, convertsToDecimal: (r6, e) => e.length === 0 ? [] : h(_.toDecimal(r6, e).length === 1), toQuantity: (r6, e) => {
53641
53649
  if (e.length === 0) return [];
53642
- let [{ value: t }] = ee(e, 1);
53650
+ let [{ value: t }] = te(e, 1);
53643
53651
  return V(t) ? [{ type: d.Quantity, value: t }] : typeof t == "number" ? [{ type: d.Quantity, value: { value: t, unit: "1" } }] : typeof t == "string" && /^-?\d{1,9}(\.\d{1,9})?/.exec(t) ? [{ type: d.Quantity, value: { value: Number.parseFloat(t), unit: "1" } }] : typeof t == "boolean" ? [{ type: d.Quantity, value: { value: t ? 1 : 0, unit: "1" } }] : [];
53644
53652
  }, convertsToQuantity: (r6, e) => e.length === 0 ? [] : h(_.toQuantity(r6, e).length === 1), toString: (r6, e) => {
53645
53653
  if (e.length === 0) return [];
53646
- let [{ value: t }] = ee(e, 1);
53654
+ let [{ value: t }] = te(e, 1);
53647
53655
  return t == null ? [] : V(t) ? [{ type: d.string, value: `${t.value} '${t.unit}'` }] : [{ type: d.string, value: t.toString() }];
53648
53656
  }, convertsToString: (r6, e) => e.length === 0 ? [] : h(_.toString(r6, e).length === 1), toTime: (r6, e) => {
53649
53657
  if (e.length === 0) return [];
53650
- let [{ value: t }] = ee(e, 1);
53658
+ let [{ value: t }] = te(e, 1);
53651
53659
  if (typeof t == "string") {
53652
53660
  let n = /^T?(\d{2}(:\d{2}(:\d{2})?)?)/.exec(t);
53653
- if (n) return [{ type: d.time, value: je("T" + n[1]) }];
53661
+ if (n) return [{ type: d.time, value: $e("T" + n[1]) }];
53654
53662
  }
53655
53663
  return [];
53656
53664
  }, convertsToTime: (r6, e) => e.length === 0 ? [] : h(_.toTime(r6, e).length === 1), indexOf: (r6, e, t) => H((n, i) => n.indexOf(i), r6, e, t), substring: (r6, e, t, n) => H((i, o2, s) => {
53657
53665
  let a = o2, u2 = s ? a + s : i.length;
53658
53666
  return a < 0 || a >= i.length ? void 0 : i.substring(a, u2);
53659
- }, r6, e, t, n), startsWith: (r6, e, t) => H((n, i) => n.startsWith(i), r6, e, t), endsWith: (r6, e, t) => H((n, i) => n.endsWith(i), r6, e, t), contains: (r6, e, t) => H((n, i) => n.includes(i), r6, e, t), upper: (r6, e) => H((t) => t.toUpperCase(), r6, e), lower: (r6, e) => H((t) => t.toLowerCase(), r6, e), replace: (r6, e, t, n) => H((i, o2, s) => i.replaceAll(o2, s), r6, e, t, n), matches: (r6, e, t) => H((n, i) => !!new RegExp(i).exec(n), r6, e, t), replaceMatches: (r6, e, t, n) => H((i, o2, s) => i.replaceAll(new RegExp(o2, "g"), s.replaceAll(/\$\{(\w+)\}/g, "$<$1>")), r6, e, t, n), length: (r6, e) => H((t) => t.length, r6, e), toChars: (r6, e) => H((t) => t ? t.split("") : void 0, r6, e), encode: ae, decode: ae, escape: ae, unescape: ae, trim: ae, split: ae, join: (r6, e, t) => {
53660
- let n = t?.eval(r6, Oe(r6))[0]?.value ?? "";
53667
+ }, r6, e, t, n), startsWith: (r6, e, t) => H((n, i) => n.startsWith(i), r6, e, t), endsWith: (r6, e, t) => H((n, i) => n.endsWith(i), r6, e, t), contains: (r6, e, t) => H((n, i) => n.includes(i), r6, e, t), upper: (r6, e) => H((t) => t.toUpperCase(), r6, e), lower: (r6, e) => H((t) => t.toLowerCase(), r6, e), replace: (r6, e, t, n) => H((i, o2, s) => i.replaceAll(o2, s), r6, e, t, n), matches: (r6, e, t) => H((n, i) => !!new RegExp(i).exec(n), r6, e, t), replaceMatches: (r6, e, t, n) => H((i, o2, s) => i.replaceAll(new RegExp(o2, "g"), s.replaceAll(/\$\{(\w+)\}/g, "$<$1>")), r6, e, t, n), length: (r6, e) => H((t) => t.length, r6, e), toChars: (r6, e) => H((t) => t ? t.split("") : void 0, r6, e), encode: ce, decode: ce, escape: ce, unescape: ce, trim: ce, split: ce, join: (r6, e, t) => {
53668
+ let n = t?.eval(r6, Ie(r6))[0]?.value ?? "";
53661
53669
  if (typeof n != "string") throw new TypeError("Separator must be a string.");
53662
53670
  return [{ type: d.string, value: e.map((i) => i.value?.toString() ?? "").join(n) }];
53663
- }, abs: (r6, e) => Z(Math.abs, r6, e), ceiling: (r6, e) => Z(Math.ceil, r6, e), exp: (r6, e) => Z(Math.exp, r6, e), floor: (r6, e) => Z(Math.floor, r6, e), ln: (r6, e) => Z(Math.log, r6, e), log: (r6, e, t) => Z((n, i) => Math.log(n) / Math.log(i), r6, e, t), power: (r6, e, t) => Z(Math.pow, r6, e, t), round: (r6, e, ...t) => Z((n, i = 0) => {
53671
+ }, abs: (r6, e) => ee(Math.abs, r6, e), ceiling: (r6, e) => ee(Math.ceil, r6, e), exp: (r6, e) => ee(Math.exp, r6, e), floor: (r6, e) => ee(Math.floor, r6, e), ln: (r6, e) => ee(Math.log, r6, e), log: (r6, e, t) => ee((n, i) => Math.log(n) / Math.log(i), r6, e, t), power: (r6, e, t) => ee(Math.pow, r6, e, t), round: (r6, e, ...t) => ee((n, i = 0) => {
53664
53672
  if (typeof i != "number" || i < 0) throw new Error("Invalid precision provided to round()");
53665
53673
  let o2 = Math.pow(10, i);
53666
53674
  return Math.round(n * o2) / o2;
53667
- }, r6, e, ...t), sqrt: (r6, e) => Z(Math.sqrt, r6, e), truncate: (r6, e) => Z((t) => Math.trunc(t), r6, e), children: ae, descendants: ae, trace: (r6, e, t) => e, now: () => [{ type: d.dateTime, value: (/* @__PURE__ */ new Date()).toISOString() }], timeOfDay: () => [{ type: d.time, value: (/* @__PURE__ */ new Date()).toISOString().substring(11) }], today: () => [{ type: d.date, value: (/* @__PURE__ */ new Date()).toISOString().substring(0, 10) }], between: (r6, e, t, n, i) => {
53675
+ }, r6, e, ...t), sqrt: (r6, e) => ee(Math.sqrt, r6, e), truncate: (r6, e) => ee((t) => Math.trunc(t), r6, e), children: ce, descendants: ce, trace: (r6, e, t) => e, now: () => [{ type: d.dateTime, value: (/* @__PURE__ */ new Date()).toISOString() }], timeOfDay: () => [{ type: d.time, value: (/* @__PURE__ */ new Date()).toISOString().substring(11) }], today: () => [{ type: d.date, value: (/* @__PURE__ */ new Date()).toISOString().substring(0, 10) }], between: (r6, e, t, n, i) => {
53668
53676
  let o2 = _.toDateTime(r6, t.eval(r6, e));
53669
53677
  if (o2.length === 0) throw new Error("Invalid start date");
53670
53678
  let s = _.toDateTime(r6, n.eval(r6, e));
@@ -53675,7 +53683,7 @@ var _ = { empty: (r6, e) => h(e.every((t) => A(t.value))), hasValue: (r6, e) =>
53675
53683
  return [{ type: d.Quantity, value: { value: u2[a], unit: a } }];
53676
53684
  }, is: (r6, e, t) => {
53677
53685
  let n = "";
53678
- return t instanceof B ? n = t.name : t instanceof te && (n = t.left.name + "." + t.right.name), n ? e.map((i) => ({ type: d.boolean, value: Et(i, n) })) : [];
53686
+ return t instanceof B ? n = t.name : t instanceof re && (n = t.left.name + "." + t.right.name), n ? e.map((i) => ({ type: d.boolean, value: Et(i, n) })) : [];
53679
53687
  }, not: (r6, e) => _.toBoolean(r6, e).map((t) => ({ type: d.boolean, value: !t.value })), resolve: (r6, e) => e.map((t) => {
53680
53688
  let n = t.value, i;
53681
53689
  if (typeof n == "string") i = n;
@@ -53708,35 +53716,35 @@ var _ = { empty: (r6, e) => h(e.every((t) => A(t.value))), hasValue: (r6, e) =>
53708
53716
  let n = e[0].value;
53709
53717
  if (!n?.reference) return [];
53710
53718
  let i = "";
53711
- return t instanceof B && (i = t.name), i && !n.reference.startsWith(i + "/") ? [] : [{ type: d.id, value: Pe(n) }];
53719
+ return t instanceof B && (i = t.name), i && !n.reference.startsWith(i + "/") ? [] : [{ type: d.id, value: Ae(n) }];
53712
53720
  }, extension: (r6, e, t) => {
53713
53721
  let n = t.eval(r6, e)[0].value, i = e?.[0]?.value;
53714
53722
  if (i) {
53715
- let o2 = pe(i, n);
53723
+ let o2 = fe(i, n);
53716
53724
  if (o2) return [{ type: d.Extension, value: o2 }];
53717
53725
  }
53718
53726
  return [];
53719
53727
  } };
53720
53728
  function H(r6, e, t, ...n) {
53721
53729
  if (t.length === 0) return [];
53722
- let [{ value: i }] = ee(t, 1);
53730
+ let [{ value: i }] = te(t, 1);
53723
53731
  if (typeof i != "string") throw new TypeError("String function cannot be called with non-string");
53724
53732
  let o2 = n.map((a) => a?.eval(e, t)[0]?.value), s = r6(i, ...o2);
53725
53733
  return s === void 0 ? [] : Array.isArray(s) ? s.map(b) : [b(s)];
53726
53734
  }
53727
- function Z(r6, e, t, ...n) {
53735
+ function ee(r6, e, t, ...n) {
53728
53736
  if (t.length === 0) return [];
53729
- let [{ value: i }] = ee(t, 1), o2 = V(i), s = o2 ? i.value : i;
53737
+ let [{ value: i }] = te(t, 1), o2 = V(i), s = o2 ? i.value : i;
53730
53738
  if (typeof s != "number") throw new TypeError("Math function cannot be called with non-number");
53731
53739
  let a = r6(s, ...n.map((p2) => p2.eval(e, t)[0]?.value)), u2 = o2 ? d.Quantity : t[0].type, l = o2 ? { ...i, value: a } : a;
53732
53740
  return [{ type: u2, value: l }];
53733
53741
  }
53734
- function ee(r6, e) {
53742
+ function te(r6, e) {
53735
53743
  if (r6.length !== e) throw new Error(`Expected ${e} arguments`);
53736
53744
  for (let t of r6) if (t == null) throw new Error("Expected non-null argument");
53737
53745
  return r6;
53738
53746
  }
53739
- function Oe(r6) {
53747
+ function Ie(r6) {
53740
53748
  let e = r6;
53741
53749
  for (; e.parent?.variables.$this; ) e = e.parent;
53742
53750
  return [e.variables.$this];
@@ -53800,7 +53808,7 @@ var kt = class extends dt {
53800
53808
  return this.operator + this.child.toString();
53801
53809
  }
53802
53810
  };
53803
- var ye = class extends R {
53811
+ var xe = class extends R {
53804
53812
  constructor(e, t) {
53805
53813
  super("as", e, t);
53806
53814
  }
@@ -53851,7 +53859,7 @@ var Mt = class extends R {
53851
53859
  return n ? h(i.some((o2) => Ke(n, o2)[0].value)) : [];
53852
53860
  }
53853
53861
  };
53854
- var te = class extends R {
53862
+ var re = class extends R {
53855
53863
  constructor(e, t) {
53856
53864
  super(".", e, t);
53857
53865
  }
@@ -53862,7 +53870,7 @@ var te = class extends R {
53862
53870
  return `${this.left.toString()}.${this.right.toString()}`;
53863
53871
  }
53864
53872
  };
53865
- var Ie = class extends R {
53873
+ var ke = class extends R {
53866
53874
  constructor(e, t) {
53867
53875
  super("|", e, t);
53868
53876
  }
@@ -53907,7 +53915,7 @@ var Ft = class extends R {
53907
53915
  return ii(Br(n, i));
53908
53916
  }
53909
53917
  };
53910
- var ke = class extends R {
53918
+ var Ve = class extends R {
53911
53919
  constructor(e, t) {
53912
53920
  super("is", e, t);
53913
53921
  }
@@ -53954,7 +53962,7 @@ var qt = class extends R {
53954
53962
  return i?.value === true || n?.value === false ? h(true) : !n || !i ? [] : h(false);
53955
53963
  }
53956
53964
  };
53957
- var re = class {
53965
+ var ne = class {
53958
53966
  constructor(e, t) {
53959
53967
  c(this, "name");
53960
53968
  c(this, "args");
@@ -53969,7 +53977,7 @@ var re = class {
53969
53977
  return `${this.name}(${this.args.map((e) => e.toString()).join(", ")})`;
53970
53978
  }
53971
53979
  };
53972
- var Ve = class {
53980
+ var De = class {
53973
53981
  constructor(e, t) {
53974
53982
  c(this, "left");
53975
53983
  c(this, "expr");
@@ -53997,51 +54005,51 @@ var Gs = { parse(r6) {
53997
54005
  var Qs = { parse(r6, e) {
53998
54006
  let t = r6.consumeAndParse();
53999
54007
  if (!r6.match("]")) throw new Error("Parse error: expected `]`");
54000
- return new Ve(e, t);
54008
+ return new De(e, t);
54001
54009
  }, precedence: S.Indexer };
54002
54010
  var zs = { parse(r6, e) {
54003
54011
  if (!(e instanceof B)) throw new Error("Unexpected parentheses");
54004
54012
  let t = [];
54005
54013
  for (; !r6.match(")"); ) t.push(r6.consumeAndParse()), r6.match(",");
54006
- return new re(e.name, t);
54014
+ return new ne(e.name, t);
54007
54015
  }, precedence: S.FunctionCall };
54008
54016
  function Js(r6) {
54009
54017
  let e = r6.split(" "), t = Number.parseFloat(e[0]), n = e[1];
54010
54018
  return n?.startsWith("'") && n.endsWith("'") ? n = n.substring(1, n.length - 1) : n = "{" + n + "}", { value: t, unit: n };
54011
54019
  }
54012
54020
  function rt() {
54013
- return new pt().registerPrefix("String", { parse: (r6, e) => new G({ type: d.string, value: e.value }) }).registerPrefix("DateTime", { parse: (r6, e) => new G({ type: d.dateTime, value: je(e.value) }) }).registerPrefix("Quantity", { parse: (r6, e) => new G({ type: d.Quantity, value: Js(e.value) }) }).registerPrefix("Number", { parse: (r6, e) => new G({ type: e.value.includes(".") ? d.decimal : d.integer, value: Number.parseFloat(e.value) }) }).registerPrefix("true", { parse: () => new G({ type: d.boolean, value: true }) }).registerPrefix("false", { parse: () => new G({ type: d.boolean, value: false }) }).registerPrefix("Symbol", { parse: (r6, e) => new B(e.value) }).registerPrefix("{}", { parse: () => new It() }).registerPrefix("(", Gs).registerInfix("[", Qs).registerInfix("(", zs).prefix("+", S.UnaryAdd, (r6, e) => new kt("+", e, (t) => t)).prefix("-", S.UnarySubtract, (r6, e) => new F("-", e, e, (t, n) => -n)).infixLeft(".", S.Dot, (r6, e, t) => new te(r6, t)).infixLeft("/", S.Divide, (r6, e, t) => new F("/", r6, t, (n, i) => n / i)).infixLeft("*", S.Multiply, (r6, e, t) => new F("*", r6, t, (n, i) => n * i)).infixLeft("+", S.Add, (r6, e, t) => new F("+", r6, t, (n, i) => n + i)).infixLeft("-", S.Subtract, (r6, e, t) => new F("-", r6, t, (n, i) => n - i)).infixLeft("|", S.Union, (r6, e, t) => new Ie(r6, t)).infixLeft("=", S.Equals, (r6, e, t) => new _t(r6, t)).infixLeft("!=", S.NotEquals, (r6, e, t) => new Lt(r6, t)).infixLeft("~", S.Equivalent, (r6, e, t) => new Nt(r6, t)).infixLeft("!~", S.NotEquivalent, (r6, e, t) => new Ft(r6, t)).infixLeft("<", S.LessThan, (r6, e, t) => new F("<", r6, t, (n, i) => n < i)).infixLeft("<=", S.LessThanOrEquals, (r6, e, t) => new F("<=", r6, t, (n, i) => n <= i)).infixLeft(">", S.GreaterThan, (r6, e, t) => new F(">", r6, t, (n, i) => n > i)).infixLeft(">=", S.GreaterThanOrEquals, (r6, e, t) => new F(">=", r6, t, (n, i) => n >= i)).infixLeft("&", S.Ampersand, (r6, e, t) => new Vt(r6, t)).infixLeft("and", S.And, (r6, e, t) => new Ut(r6, t)).infixLeft("as", S.As, (r6, e, t) => new ye(r6, t)).infixLeft("contains", S.Contains, (r6, e, t) => new Dt(r6, t)).infixLeft("div", S.Divide, (r6, e, t) => new F("div", r6, t, (n, i) => Math.trunc(n / i))).infixLeft("in", S.In, (r6, e, t) => new Mt(r6, t)).infixLeft("is", S.Is, (r6, e, t) => new ke(r6, t)).infixLeft("mod", S.Modulo, (r6, e, t) => new F("mod", r6, t, (n, i) => n % i)).infixLeft("or", S.Or, (r6, e, t) => new Bt(r6, t)).infixLeft("xor", S.Xor, (r6, e, t) => new Wt(r6, t)).infixLeft("implies", S.Implies, (r6, e, t) => new qt(r6, t));
54021
+ return new pt().registerPrefix("String", { parse: (r6, e) => new G({ type: d.string, value: e.value }) }).registerPrefix("DateTime", { parse: (r6, e) => new G({ type: d.dateTime, value: $e(e.value) }) }).registerPrefix("Quantity", { parse: (r6, e) => new G({ type: d.Quantity, value: Js(e.value) }) }).registerPrefix("Number", { parse: (r6, e) => new G({ type: e.value.includes(".") ? d.decimal : d.integer, value: Number.parseFloat(e.value) }) }).registerPrefix("true", { parse: () => new G({ type: d.boolean, value: true }) }).registerPrefix("false", { parse: () => new G({ type: d.boolean, value: false }) }).registerPrefix("Symbol", { parse: (r6, e) => new B(e.value) }).registerPrefix("{}", { parse: () => new It() }).registerPrefix("(", Gs).registerInfix("[", Qs).registerInfix("(", zs).prefix("+", S.UnaryAdd, (r6, e) => new kt("+", e, (t) => t)).prefix("-", S.UnarySubtract, (r6, e) => new F("-", e, e, (t, n) => -n)).infixLeft(".", S.Dot, (r6, e, t) => new re(r6, t)).infixLeft("/", S.Divide, (r6, e, t) => new F("/", r6, t, (n, i) => n / i)).infixLeft("*", S.Multiply, (r6, e, t) => new F("*", r6, t, (n, i) => n * i)).infixLeft("+", S.Add, (r6, e, t) => new F("+", r6, t, (n, i) => n + i)).infixLeft("-", S.Subtract, (r6, e, t) => new F("-", r6, t, (n, i) => n - i)).infixLeft("|", S.Union, (r6, e, t) => new ke(r6, t)).infixLeft("=", S.Equals, (r6, e, t) => new _t(r6, t)).infixLeft("!=", S.NotEquals, (r6, e, t) => new Lt(r6, t)).infixLeft("~", S.Equivalent, (r6, e, t) => new Nt(r6, t)).infixLeft("!~", S.NotEquivalent, (r6, e, t) => new Ft(r6, t)).infixLeft("<", S.LessThan, (r6, e, t) => new F("<", r6, t, (n, i) => n < i)).infixLeft("<=", S.LessThanOrEquals, (r6, e, t) => new F("<=", r6, t, (n, i) => n <= i)).infixLeft(">", S.GreaterThan, (r6, e, t) => new F(">", r6, t, (n, i) => n > i)).infixLeft(">=", S.GreaterThanOrEquals, (r6, e, t) => new F(">=", r6, t, (n, i) => n >= i)).infixLeft("&", S.Ampersand, (r6, e, t) => new Vt(r6, t)).infixLeft("and", S.And, (r6, e, t) => new Ut(r6, t)).infixLeft("as", S.As, (r6, e, t) => new xe(r6, t)).infixLeft("contains", S.Contains, (r6, e, t) => new Dt(r6, t)).infixLeft("div", S.Divide, (r6, e, t) => new F("div", r6, t, (n, i) => Math.trunc(n / i))).infixLeft("in", S.In, (r6, e, t) => new Mt(r6, t)).infixLeft("is", S.Is, (r6, e, t) => new Ve(r6, t)).infixLeft("mod", S.Modulo, (r6, e, t) => new F("mod", r6, t, (n, i) => n % i)).infixLeft("or", S.Or, (r6, e, t) => new Bt(r6, t)).infixLeft("xor", S.Xor, (r6, e, t) => new Wt(r6, t)).infixLeft("implies", S.Implies, (r6, e, t) => new qt(r6, t));
54014
54022
  }
54015
54023
  var Ks = rt();
54016
54024
  var m = { EQUALS: "eq", NOT_EQUALS: "ne", GREATER_THAN: "gt", LESS_THAN: "lt", GREATER_THAN_OR_EQUALS: "ge", LESS_THAN_OR_EQUALS: "le", STARTS_AFTER: "sa", ENDS_BEFORE: "eb", APPROXIMATELY: "ap", CONTAINS: "contains", STARTS_WITH: "sw", EXACT: "exact", TEXT: "text", NOT: "not", ABOVE: "above", BELOW: "below", IN: "in", NOT_IN: "not-in", OF_TYPE: "of-type", MISSING: "missing", PRESENT: "present", IDENTIFIER: "identifier", ITERATE: "iterate" };
54017
54025
  var en = { contains: m.CONTAINS, exact: m.EXACT, above: m.ABOVE, below: m.BELOW, text: m.TEXT, not: m.NOT, in: m.IN, "not-in": m.NOT_IN, "of-type": m.OF_TYPE, missing: m.MISSING, identifier: m.IDENTIFIER, iterate: m.ITERATE };
54018
54026
  var tn = { eq: m.EQUALS, ne: m.NOT_EQUALS, lt: m.LESS_THAN, le: m.LESS_THAN_OR_EQUALS, gt: m.GREATER_THAN, ge: m.GREATER_THAN_OR_EQUALS, sa: m.STARTS_AFTER, eb: m.ENDS_BEFORE, ap: m.APPROXIMATELY, sw: m.STARTS_WITH };
54019
54027
  var ia = [m.MISSING, m.PRESENT];
54020
- var fa = new K(1e3);
54021
- var Me = { READ: "read", VREAD: "vread", UPDATE: "update", DELETE: "delete", HISTORY: "history", CREATE: "create", SEARCH: "search" };
54022
- var Pa = [Me.READ, Me.VREAD, Me.HISTORY, Me.SEARCH];
54023
- var af = { FIRST: "first", APPLICATION: "application" };
54024
- function z() {
54028
+ var fa = new Y(1e3);
54029
+ var _e = { READ: "read", VREAD: "vread", UPDATE: "update", DELETE: "delete", HISTORY: "history", CREATE: "create", SEARCH: "search" };
54030
+ var Pa = [_e.READ, _e.VREAD, _e.HISTORY, _e.SEARCH];
54031
+ var uf = { FIRST: "first", APPLICATION: "application" };
54032
+ function J() {
54025
54033
  return typeof window < "u";
54026
54034
  }
54027
54035
  function rn() {
54028
54036
  return typeof Buffer < "u" ? Buffer : void 0;
54029
54037
  }
54030
- var ce = { assign(r6) {
54031
- z() && globalThis.location.assign(r6);
54038
+ var ue = { assign(r6) {
54039
+ J() && globalThis.location.assign(r6);
54032
54040
  }, reload() {
54033
- z() && globalThis.location.reload();
54041
+ J() && globalThis.location.reload();
54034
54042
  }, getSearch() {
54035
- return z() ? globalThis.location.search : "";
54043
+ return J() ? globalThis.location.search : "";
54036
54044
  }, getPathname() {
54037
- return z() ? globalThis.location.pathname : "";
54045
+ return J() ? globalThis.location.pathname : "";
54038
54046
  }, getLocation() {
54039
- return z() ? globalThis.location.toString() : "";
54047
+ return J() ? globalThis.location.toString() : "";
54040
54048
  }, getOrigin() {
54041
- return z() ? globalThis.location.protocol + "//" + globalThis.location.host + "/" : "";
54049
+ return J() ? globalThis.location.protocol + "//" + globalThis.location.host + "/" : "";
54042
54050
  } };
54043
54051
  function Oa(r6) {
54044
- if (z()) {
54052
+ if (J()) {
54045
54053
  let t = window.atob(r6), n = Uint8Array.from(t, (i) => i.codePointAt(0));
54046
54054
  return new window.TextDecoder().decode(n);
54047
54055
  }
@@ -54050,7 +54058,7 @@ function Oa(r6) {
54050
54058
  throw new Error("Unable to decode base64");
54051
54059
  }
54052
54060
  function Gt(r6) {
54053
- if (z()) {
54061
+ if (J()) {
54054
54062
  let t = new window.TextEncoder().encode(r6), n = String.fromCodePoint.apply(null, t);
54055
54063
  return window.btoa(n);
54056
54064
  }
@@ -54070,7 +54078,7 @@ function nn() {
54070
54078
  async function qi(r6) {
54071
54079
  return crypto.subtle.digest("SHA-256", new TextEncoder().encode(r6));
54072
54080
  }
54073
- function ne() {
54081
+ function ie() {
54074
54082
  return typeof crypto < "u" && "randomUUID" in crypto ? crypto.randomUUID() : "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replaceAll(/[xy]/g, (r6) => {
54075
54083
  let e = Math.trunc(Math.random() * 16);
54076
54084
  return (r6 === "x" ? e : e & 3 | 8).toString(16);
@@ -54106,7 +54114,7 @@ var on = class {
54106
54114
  return this.listeners[e]?.length ?? 0;
54107
54115
  }
54108
54116
  };
54109
- var ie = class {
54117
+ var oe = class {
54110
54118
  constructor() {
54111
54119
  c(this, "emitter", new on());
54112
54120
  }
@@ -54166,7 +54174,7 @@ function ja(r6, e, t, n) {
54166
54174
  }
54167
54175
  function $a(r6, e, t, n, i) {
54168
54176
  if (i.set(e.key, (i.get(e.key) ?? 0) + 1), n.reference) {
54169
- if (!Q(e.reference)) throw new f(T(`context[${t}] is invalid. Expected key '${e.key}' to be a reference.`));
54177
+ if (!z(e.reference)) throw new f(T(`context[${t}] is invalid. Expected key '${e.key}' to be a reference.`));
54170
54178
  } else ja(r6, e.resource, t, n);
54171
54179
  }
54172
54180
  function Ha(r6, e) {
@@ -54187,9 +54195,9 @@ function un(r6, e, t, n) {
54187
54195
  if (typeof t != "object") throw new f(T("context must be a context object or array of context objects."));
54188
54196
  if (an.includes(e) && !n) throw new f(T(`The '${e}' event must contain a 'context.versionId'.`));
54189
54197
  let i = Array.isArray(t) ? t : [t];
54190
- return Ha(e, i), { timestamp: (/* @__PURE__ */ new Date()).toISOString(), id: ne(), event: { "hub.topic": r6, "hub.event": e, context: i, ...n ? { "context.versionId": n } : {} } };
54198
+ return Ha(e, i), { timestamp: (/* @__PURE__ */ new Date()).toISOString(), id: ie(), event: { "hub.topic": r6, "hub.event": e, context: i, ...n ? { "context.versionId": n } : {} } };
54191
54199
  }
54192
- var Qt = class extends ie {
54200
+ var Qt = class extends oe {
54193
54201
  constructor(t) {
54194
54202
  super();
54195
54203
  c(this, "subRequest");
@@ -54343,18 +54351,18 @@ var ln = class {
54343
54351
  return Array.from(this.data.keys())[e];
54344
54352
  }
54345
54353
  };
54346
- var He = { Event: typeof globalThis.Event < "u" ? globalThis.Event : void 0, ErrorEvent: void 0, CloseEvent: void 0 };
54354
+ var Q = { Event: typeof globalThis.Event < "u" ? globalThis.Event : void 0, ErrorEvent: void 0, CloseEvent: void 0 };
54347
54355
  var Xi = false;
54348
54356
  function Qa() {
54349
54357
  if (typeof globalThis.Event > "u") throw new Error("Unable to lazy init events for ReconnectingWebSocket. globalThis.Event is not defined yet");
54350
- He.Event = globalThis.Event, He.ErrorEvent = class extends Event {
54358
+ Q.Event = globalThis.Event, Q.ErrorEvent = class extends Event {
54351
54359
  constructor(t, n) {
54352
54360
  super("error", n);
54353
54361
  c(this, "message");
54354
54362
  c(this, "error");
54355
54363
  this.message = t.message, this.error = t;
54356
54364
  }
54357
- }, He.CloseEvent = class extends Event {
54365
+ }, Q.CloseEvent = class extends Event {
54358
54366
  constructor(t = 1e3, n = "", i) {
54359
54367
  super("close", i);
54360
54368
  c(this, "code");
@@ -54367,12 +54375,26 @@ function Qa() {
54367
54375
  function za(r6, e) {
54368
54376
  if (!r6) throw new Error(e);
54369
54377
  }
54378
+ function Ja() {
54379
+ }
54370
54380
  function Yt(r6) {
54381
+ if (r6 instanceof Q.CloseEvent) {
54382
+ let e = r6;
54383
+ return new Q.CloseEvent(e.code, e.reason, void 0);
54384
+ }
54385
+ if (r6 instanceof Q.ErrorEvent) {
54386
+ let e = r6;
54387
+ return new Q.ErrorEvent(e.error ?? new Error(e.message), void 0);
54388
+ }
54371
54389
  return new r6.constructor(r6.type, r6);
54372
54390
  }
54373
- var _e = { maxReconnectionDelay: 1e4, minReconnectionDelay: 1e3 + Math.random() * 4e3, minUptime: 5e3, reconnectionDelayGrowFactor: 1.3, connectionTimeout: 4e3, maxRetries: 1 / 0, maxEnqueuedMessages: 1 / 0, startClosed: false, debug: false };
54391
+ function Ka(r6, e) {
54392
+ let t = r6;
54393
+ return t.error instanceof Error ? new Q.ErrorEvent(t.error, e) : new Q.ErrorEvent(new Error(t.message || "WebSocket error"), e);
54394
+ }
54395
+ var Le = { maxReconnectionDelay: 1e4, minReconnectionDelay: 1e3 + Math.random() * 4e3, minUptime: 5e3, reconnectionDelayGrowFactor: 1.3, connectionTimeout: 4e3, maxRetries: 1 / 0, maxEnqueuedMessages: 1 / 0, startClosed: false, debug: false };
54374
54396
  var Zi = false;
54375
- var Xt = class r extends ie {
54397
+ var Xt = class r extends oe {
54376
54398
  constructor(t, n, i = {}) {
54377
54399
  Xi || (Qa(), Xi = true);
54378
54400
  super();
@@ -54395,14 +54417,15 @@ var Xt = class r extends ie {
54395
54417
  c(this, "onopen", null);
54396
54418
  c(this, "_handleOpen", (t2) => {
54397
54419
  this._debug("open event");
54398
- let { minUptime: n2 = _e.minUptime } = this._options;
54420
+ let { minUptime: n2 = Le.minUptime } = this._options;
54399
54421
  clearTimeout(this._connectTimeout), this._uptimeTimeout = setTimeout(() => this._acceptOpen(), n2), za(this._ws, "WebSocket is not defined"), this._ws.binaryType = this._binaryType, this._messageQueue.forEach((i2) => this._ws?.send(i2)), this._messageQueue = [], this.onopen && this.onopen(t2), this.dispatchEvent(Yt(t2));
54400
54422
  });
54401
54423
  c(this, "_handleMessage", (t2) => {
54402
54424
  this._debug("message event"), this.onmessage && this.onmessage(t2), this.dispatchEvent(Yt(t2));
54403
54425
  });
54404
54426
  c(this, "_handleError", (t2) => {
54405
- this._debug("error event", t2.message), this._disconnect(void 0, t2.message === "TIMEOUT" ? "timeout" : void 0), this.onerror && this.onerror(t2), this._debug("exec error listeners"), this.dispatchEvent(Yt(t2)), this._connect();
54427
+ let n2 = Ka(t2, this);
54428
+ this._debug("error event", n2.message), this._disconnect(void 0, n2.message === "TIMEOUT" ? "timeout" : void 0), this.onerror && this.onerror(n2), this._debug("exec error listeners"), this.dispatchEvent(Yt(n2)), this._connect();
54406
54429
  });
54407
54430
  c(this, "_handleClose", (t2) => {
54408
54431
  this._debug("close event"), this._clearTimeouts(), this._shouldReconnect && this._connect(), this.onclose && this.onclose(t2), this.dispatchEvent(Yt(t2));
@@ -54477,7 +54500,7 @@ var Xt = class r extends ie {
54477
54500
  send(t) {
54478
54501
  if (this._ws?.readyState === this.OPEN) this._debug("send", t), this._ws.send(t);
54479
54502
  else {
54480
- let { maxEnqueuedMessages: n = _e.maxEnqueuedMessages } = this._options;
54503
+ let { maxEnqueuedMessages: n = Le.maxEnqueuedMessages } = this._options;
54481
54504
  this._messageQueue.length < n && (this._debug("enqueue", t), this._messageQueue.push(t));
54482
54505
  }
54483
54506
  }
@@ -54485,7 +54508,7 @@ var Xt = class r extends ie {
54485
54508
  this._options.debug && this._debugLogger("RWS>", ...t);
54486
54509
  }
54487
54510
  _getNextDelay() {
54488
- let { reconnectionDelayGrowFactor: t = _e.reconnectionDelayGrowFactor, minReconnectionDelay: n = _e.minReconnectionDelay, maxReconnectionDelay: i = _e.maxReconnectionDelay } = this._options, o2 = 0;
54511
+ let { reconnectionDelayGrowFactor: t = Le.reconnectionDelayGrowFactor, minReconnectionDelay: n = Le.minReconnectionDelay, maxReconnectionDelay: i = Le.maxReconnectionDelay } = this._options, o2 = 0;
54489
54512
  return this._retryCount > 0 && (o2 = n * Math.pow(t, this._retryCount - 1), o2 > i && (o2 = i)), this._debug("next delay", o2), o2;
54490
54513
  }
54491
54514
  _wait() {
@@ -54496,9 +54519,9 @@ var Xt = class r extends ie {
54496
54519
  _connect() {
54497
54520
  if (this._connectLock || !this._shouldReconnect) return;
54498
54521
  this._connectLock = true;
54499
- let { maxRetries: t = _e.maxRetries, connectionTimeout: n = _e.connectionTimeout } = this._options;
54522
+ let { maxRetries: t = Le.maxRetries, connectionTimeout: n = Le.connectionTimeout } = this._options;
54500
54523
  if (this._retryCount >= t) {
54501
- this._debug("max retries reached", this._retryCount, ">=", t);
54524
+ this._connectLock = false, this._debug("max retries reached", this._retryCount, ">=", t);
54502
54525
  return;
54503
54526
  }
54504
54527
  this._retryCount++, this._debug("connect", this._retryCount), this._removeListeners(), this._wait().then(() => {
@@ -54510,19 +54533,19 @@ var Xt = class r extends ie {
54510
54533
  let i = this._options.WebSocket || WebSocket;
54511
54534
  this._debug("connect", { url: this._url, protocols: this._protocols }), this._ws = this._protocols ? new i(this._url, this._protocols) : new i(this._url), this._ws.binaryType = this._binaryType, this._connectLock = false, this._addListeners(), this._connectTimeout = setTimeout(() => this._handleTimeout(), n);
54512
54535
  }).catch((i) => {
54513
- this._connectLock = false, this._handleError(new He.ErrorEvent(Error(i.message), this));
54536
+ this._connectLock = false, this._handleError(new Q.ErrorEvent(Error(i.message), this));
54514
54537
  });
54515
54538
  }
54516
54539
  _handleTimeout() {
54517
- this._debug("timeout event"), this._handleError(new He.ErrorEvent(Error("TIMEOUT"), this));
54540
+ this._debug("timeout event"), this._handleError(new Q.ErrorEvent(Error("TIMEOUT"), this));
54518
54541
  }
54519
54542
  _disconnect(t = 1e3, n) {
54520
- if (this._clearTimeouts(), !!this._ws) {
54521
- this._removeListeners();
54522
- try {
54523
- this._ws.close(t, n), this._handleClose(new He.CloseEvent(t, n, this));
54524
- } catch {
54525
- }
54543
+ if (this._clearTimeouts(), !this._ws) return;
54544
+ let i = this._ws;
54545
+ this._removeListeners(), i.addEventListener("error", Ja);
54546
+ try {
54547
+ i.close(t, n), this._handleClose(new Q.CloseEvent(t, n, this));
54548
+ } catch {
54526
54549
  }
54527
54550
  }
54528
54551
  _acceptOpen() {
@@ -54538,8 +54561,8 @@ var Xt = class r extends ie {
54538
54561
  clearTimeout(this._connectTimeout), clearTimeout(this._uptimeTimeout);
54539
54562
  }
54540
54563
  };
54541
- var Ja = [WebSocket.CLOSING, WebSocket.CLOSED];
54542
- var at = class extends ie {
54564
+ var Ya = [WebSocket.CLOSING, WebSocket.CLOSED];
54565
+ var at = class extends oe {
54543
54566
  constructor(...t) {
54544
54567
  super();
54545
54568
  c(this, "criteria");
@@ -54611,7 +54634,7 @@ var Zt = class {
54611
54634
  return;
54612
54635
  }
54613
54636
  if (o2.type === "handshake") {
54614
- let a = Pe(o2.subscription), u2 = { type: "connect", payload: { subscriptionId: a } };
54637
+ let a = Ae(o2.subscription), u2 = { type: "connect", payload: { subscriptionId: a } };
54615
54638
  this.masterSubEmitter?.dispatchEvent(u2);
54616
54639
  let l = this.criteriaEntriesBySubscriptionId.get(a);
54617
54640
  if (!l) {
@@ -54622,7 +54645,7 @@ var Zt = class {
54622
54645
  return;
54623
54646
  }
54624
54647
  this.masterSubEmitter?.dispatchEvent({ type: "message", payload: i });
54625
- let s = this.criteriaEntriesBySubscriptionId.get(Pe(o2.subscription));
54648
+ let s = this.criteriaEntriesBySubscriptionId.get(Ae(o2.subscription));
54626
54649
  if (!s) {
54627
54650
  console.warn("Received notification for criteria the SubscriptionManager is not listening for");
54628
54651
  return;
@@ -54635,7 +54658,7 @@ var Zt = class {
54635
54658
  for (let o2 of this.getAllCriteriaEmitters()) o2.dispatchEvent({ ...i });
54636
54659
  }
54637
54660
  }), e.addEventListener("error", (t) => {
54638
- let n = { type: "error", payload: new f({ resourceType: "OperationOutcome", issue: [{ severity: "error", code: "exception", details: { text: "WebSocket connection closed due to an error" }, diagnostics: t.error ? Se(t.error) : t.message }] }) };
54661
+ let n = { type: "error", payload: new f({ resourceType: "OperationOutcome", issue: [{ severity: "error", code: "exception", details: { text: "WebSocket connection closed due to an error" }, diagnostics: t.error ? be(t.error) : t.message }] }) };
54639
54662
  this.masterSubEmitter?.dispatchEvent(n);
54640
54663
  for (let i of this.getAllCriteriaEmitters()) i.dispatchEvent({ ...n });
54641
54664
  }), e.addEventListener("close", () => {
@@ -54681,7 +54704,7 @@ var Zt = class {
54681
54704
  let n = this.criteriaEntries.get(e);
54682
54705
  if (n) {
54683
54706
  if (!t) return n.bareCriteria;
54684
- for (let i of n.criteriaWithProps) if (fe(t, i.subscriptionProps)) return i;
54707
+ for (let i of n.criteriaWithProps) if (me(t, i.subscriptionProps)) return i;
54685
54708
  }
54686
54709
  }
54687
54710
  getAllCriteriaEmitters() {
@@ -54700,7 +54723,7 @@ var Zt = class {
54700
54723
  let s = this.criteriaEntries.get(t);
54701
54724
  n ? s.criteriaWithProps = s.criteriaWithProps.filter((a) => {
54702
54725
  let u2 = a.subscriptionProps;
54703
- return !fe(n, u2);
54726
+ return !me(n, u2);
54704
54727
  }) : s.bareCriteria = void 0, !s.bareCriteria && s.criteriaWithProps.length === 0 && (this.criteriaEntries.delete(t), this.masterSubEmitter?._removeCriteria(t)), i && this.criteriaEntriesBySubscriptionId.delete(i), o2 && this.sendUnbind(o2);
54705
54728
  }
54706
54729
  async subscribeToCriteria(e) {
@@ -54727,7 +54750,7 @@ var Zt = class {
54727
54750
  if (this.isStale(e, t)) return;
54728
54751
  e.token = i, e.tokenExpiry = new Date(s).getTime(), this.criteriaEntriesBySubscriptionId.set(e.subscriptionId, e), this.sendBind(i);
54729
54752
  } catch (n) {
54730
- console.error(Se(n)), e.generation === t && !this.isEntryGettingRemoved(e) && (e.state = e.state === "refreshing" ? "active" : "idle"), this.emitError(e, n);
54753
+ console.error(be(n)), e.generation === t && !this.isEntryGettingRemoved(e) && (e.state = e.state === "refreshing" ? "active" : "idle"), this.emitError(e, n);
54731
54754
  }
54732
54755
  }
54733
54756
  checkTokenExpirations() {
@@ -54780,7 +54803,7 @@ var Zt = class {
54780
54803
  return this.masterSubEmitter || (this.masterSubEmitter = new at(...Array.from(this.criteriaEntries.keys()))), this.masterSubEmitter;
54781
54804
  }
54782
54805
  async reconnectIfNeeded() {
54783
- Ja.includes(this.getWebSocket().readyState) && await new Promise((e) => {
54806
+ Ya.includes(this.getWebSocket().readyState) && await new Promise((e) => {
54784
54807
  let t = () => {
54785
54808
  this.getWebSocket().removeEventListener("open", t), e();
54786
54809
  };
@@ -54791,20 +54814,20 @@ var Zt = class {
54791
54814
  function st(r6) {
54792
54815
  return r6.bareCriteria ? [r6.bareCriteria, ...r6.criteriaWithProps] : r6.criteriaWithProps;
54793
54816
  }
54794
- var Ka = new K(1e3);
54795
- var pn = "5.1.17-3a68674";
54796
- var Za = k.FHIR_JSON + ", */*; q=0.1";
54797
- var ec = "https://api.medplum.com/";
54798
- var tc = 1e3;
54799
- var rc = 6e4;
54800
- var nc = 0;
54801
- var ic = 3e5;
54802
- var oc = "Binary/";
54817
+ var Xa = new Y(1e3);
54818
+ var pn = "5.1.18-97e1dd8";
54819
+ var tc = k.FHIR_JSON + ", */*; q=0.1";
54820
+ var rc = "https://api.medplum.com/";
54821
+ var nc = 1e3;
54822
+ var ic = 6e4;
54823
+ var oc = 0;
54824
+ var sc = 3e5;
54825
+ var ac = "Binary/";
54803
54826
  var eo = { resourceType: "Device", id: "system", deviceName: [{ type: "model-name", name: "System" }] };
54804
54827
  var Ge = { ClientCredentials: "client_credentials", AuthorizationCode: "authorization_code", RefreshToken: "refresh_token", JwtBearer: "urn:ietf:params:oauth:grant-type:jwt-bearer", TokenExchange: "urn:ietf:params:oauth:grant-type:token-exchange", PreAuthorizedCode: "urn:ietf:params:oauth:grant-type:pre-authorized_code" };
54805
- var sc = { AccessToken: "urn:ietf:params:oauth:token-type:access_token", RefreshToken: "urn:ietf:params:oauth:token-type:refresh_token", IdToken: "urn:ietf:params:oauth:token-type:id_token", Saml1Token: "urn:ietf:params:oauth:token-type:saml1", Saml2Token: "urn:ietf:params:oauth:token-type:saml2" };
54806
- var ac = { JwtBearer: "urn:ietf:params:oauth:client-assertion-type:jwt-bearer" };
54807
- var er = class extends ie {
54828
+ var cc = { AccessToken: "urn:ietf:params:oauth:token-type:access_token", RefreshToken: "urn:ietf:params:oauth:token-type:refresh_token", IdToken: "urn:ietf:params:oauth:token-type:id_token", Saml1Token: "urn:ietf:params:oauth:token-type:saml1", Saml2Token: "urn:ietf:params:oauth:token-type:saml2" };
54829
+ var uc = { JwtBearer: "urn:ietf:params:oauth:client-assertion-type:jwt-bearer" };
54830
+ var er = class extends oe {
54808
54831
  constructor(t) {
54809
54832
  super();
54810
54833
  c(this, "options");
@@ -54846,7 +54869,7 @@ var er = class extends ie {
54846
54869
  c(this, "keyValueClient");
54847
54870
  c(this, "logLevel");
54848
54871
  if (t?.baseUrl && !t.baseUrl.startsWith("http")) throw new Error("Base URL must start with http or https");
54849
- this.options = t ?? {}, this.fetch = t?.fetch ?? cc(), this.storage = t?.storage ?? new ot(void 0, t?.storagePrefix), this.createPdfImpl = t?.createPdf, this.baseUrl = Yr(t?.baseUrl ?? ec), this.fhirBaseUrl = U(this.baseUrl, t?.fhirUrlPath ?? "fhir/R4"), this.authorizeUrl = U(this.baseUrl, t?.authorizeUrl ?? "oauth2/authorize"), this.tokenUrl = U(this.baseUrl, t?.tokenUrl ?? "oauth2/token"), this.logoutUrl = U(this.baseUrl, t?.logoutUrl ?? "oauth2/logout"), this.fhircastHubUrl = U(this.baseUrl, t?.fhircastHubUrl ?? "fhircast/STU3"), this.cdsServicesUrl = U(this.baseUrl, t?.cdsServicesUrl ?? "cds-services"), this.clientId = t?.clientId ?? "", this.clientSecret = t?.clientSecret ?? "", this.credentialsInHeader = t?.authCredentialsMethod === "header", this.defaultHeaders = t?.defaultHeaders ?? {}, this.onUnauthenticated = t?.onUnauthenticated, this.refreshGracePeriod = t?.refreshGracePeriod ?? ic, this.logLevel = this.initializeLogLevel(t), this.maxRetries = t?.maxRetries ?? 2, this.maxRetryTime = t?.maxRetryTime ?? 2e3, this.cacheTime = t?.cacheTime ?? (z() ? rc : nc), this.cacheTime > 0 ? this.requestCache = new K(t?.resourceCacheSize ?? tc) : this.requestCache = void 0, t?.autoBatchTime ? (this.autoBatchTime = t.autoBatchTime, this.autoBatchQueue = []) : (this.autoBatchTime = 0, this.autoBatchQueue = void 0), t?.accessToken && this.setAccessToken(t.accessToken), this.storage.getInitPromise === void 0 ? (t?.accessToken || this.attemptResumeActiveLogin().catch(console.error), this.initPromise = Promise.resolve(), this.dispatchEvent({ type: "storageInitialized" })) : (this.initComplete = false, this.initPromise = this.storage.getInitPromise(), this.initPromise.then(() => {
54872
+ this.options = t ?? {}, this.fetch = t?.fetch ?? lc(), this.storage = t?.storage ?? new ot(void 0, t?.storagePrefix), this.createPdfImpl = t?.createPdf, this.baseUrl = Yr(t?.baseUrl ?? rc), this.fhirBaseUrl = U(this.baseUrl, t?.fhirUrlPath ?? "fhir/R4"), this.authorizeUrl = U(this.baseUrl, t?.authorizeUrl ?? "oauth2/authorize"), this.tokenUrl = U(this.baseUrl, t?.tokenUrl ?? "oauth2/token"), this.logoutUrl = U(this.baseUrl, t?.logoutUrl ?? "oauth2/logout"), this.fhircastHubUrl = U(this.baseUrl, t?.fhircastHubUrl ?? "fhircast/STU3"), this.cdsServicesUrl = U(this.baseUrl, t?.cdsServicesUrl ?? "cds-services"), this.clientId = t?.clientId ?? "", this.clientSecret = t?.clientSecret ?? "", this.credentialsInHeader = t?.authCredentialsMethod === "header", this.defaultHeaders = t?.defaultHeaders ?? {}, this.onUnauthenticated = t?.onUnauthenticated, this.refreshGracePeriod = t?.refreshGracePeriod ?? sc, this.logLevel = this.initializeLogLevel(t), this.maxRetries = t?.maxRetries ?? 2, this.maxRetryTime = t?.maxRetryTime ?? 2e3, this.cacheTime = t?.cacheTime ?? (J() ? ic : oc), this.cacheTime > 0 ? this.requestCache = new Y(t?.resourceCacheSize ?? nc) : this.requestCache = void 0, t?.autoBatchTime ? (this.autoBatchTime = t.autoBatchTime, this.autoBatchQueue = []) : (this.autoBatchTime = 0, this.autoBatchQueue = void 0), t?.accessToken && this.setAccessToken(t.accessToken), this.storage.getInitPromise === void 0 ? (t?.accessToken || this.attemptResumeActiveLogin().catch(console.error), this.initPromise = Promise.resolve(), this.dispatchEvent({ type: "storageInitialized" })) : (this.initComplete = false, this.initPromise = this.storage.getInitPromise(), this.initPromise.then(() => {
54850
54873
  t?.accessToken || this.attemptResumeActiveLogin().catch(console.error), this.initComplete = true, this.dispatchEvent({ type: "storageInitialized" });
54851
54874
  }).catch((n) => {
54852
54875
  console.error(n), this.initComplete = true, this.dispatchEvent({ type: "storageInitFailed", payload: { error: n } });
@@ -54948,7 +54971,7 @@ var er = class extends ie {
54948
54971
  await this.post(this.logoutUrl, {}), this.clear();
54949
54972
  }
54950
54973
  async signInWithRedirect(t) {
54951
- let i = new URLSearchParams(ce.getSearch()).get("code");
54974
+ let i = new URLSearchParams(ue.getSearch()).get("code");
54952
54975
  if (!i) {
54953
54976
  await this.requestAuthorization(t);
54954
54977
  return;
@@ -54956,15 +54979,15 @@ var er = class extends ie {
54956
54979
  return this.processCode(i);
54957
54980
  }
54958
54981
  signOutWithRedirect() {
54959
- ce.assign(this.logoutUrl);
54982
+ ue.assign(this.logoutUrl);
54960
54983
  }
54961
54984
  async signInWithExternalAuth(t, n, i, o2, s = true) {
54962
54985
  let a = o2;
54963
- s && (a = await this.ensureCodeChallenge(o2)), ce.assign(this.getExternalAuthRedirectUri(t, n, i, a, s));
54986
+ s && (a = await this.ensureCodeChallenge(o2)), ue.assign(this.getExternalAuthRedirectUri(t, n, i, a, s));
54964
54987
  }
54965
54988
  async exchangeExternalAccessToken(t, n, i) {
54966
54989
  if (n = n ?? this.clientId, !n) throw new Error("MedplumClient is missing clientId");
54967
- let o2 = { grant_type: Ge.TokenExchange, subject_token_type: sc.AccessToken, client_id: n, subject_token: t };
54990
+ let o2 = { grant_type: Ge.TokenExchange, subject_token_type: cc.AccessToken, client_id: n, subject_token: t };
54968
54991
  return i && (o2.membership_id = i), this.fetchTokens(o2);
54969
54992
  }
54970
54993
  getExternalAuthRedirectUri(t, n, i, o2, s = true) {
@@ -55147,22 +55170,22 @@ var er = class extends ie {
55147
55170
  if (a.contentType === k.XML) {
55148
55171
  let p2 = a.data, g2;
55149
55172
  p2 instanceof Blob ? g2 = await new Promise((v2, M2) => {
55150
- let J = new FileReader();
55151
- J.onload = () => {
55152
- if (!J.result) {
55173
+ let K = new FileReader();
55174
+ K.onload = () => {
55175
+ if (!K.result) {
55153
55176
  M2(new Error("Failed to load file"));
55154
55177
  return;
55155
55178
  }
55156
- v2(J.result);
55157
- }, J.readAsText(p2, "utf-8");
55179
+ v2(K.result);
55180
+ }, K.readAsText(p2, "utf-8");
55158
55181
  }) : ArrayBuffer.isView(p2) ? g2 = new TextDecoder().decode(p2) : g2 = p2, g2.includes("<ClinicalDocument") && g2.includes("urn:hl7-org:v3") && (a = { ...a, contentType: k.CDA_XML });
55159
55182
  }
55160
55183
  let u2 = s ?? (typeof n == "object" ? n : {}), l = await this.createBinary(a, u2);
55161
55184
  return { contentType: a.contentType, url: l.url, title: a.filename };
55162
55185
  }
55163
55186
  createBinary(t, n, i, o2, s) {
55164
- let a = no(t, n, i, o2), u2 = s ?? (typeof n == "object" ? n : {}), { data: l, contentType: p2, filename: g2, securityContext: v2, onProgress: M2 } = a, J = this.fhirUrl("Binary");
55165
- return g2 && J.searchParams.set("_filename", g2), v2?.reference && this.setRequestHeader(u2, "X-Security-Context", v2.reference), M2 ? this.uploadwithProgress(J, l, p2, M2, u2) : this.post(J, l, p2, u2);
55187
+ let a = no(t, n, i, o2), u2 = s ?? (typeof n == "object" ? n : {}), { data: l, contentType: p2, filename: g2, securityContext: v2, onProgress: M2 } = a, K = this.fhirUrl("Binary");
55188
+ return g2 && K.searchParams.set("_filename", g2), v2?.reference && this.setRequestHeader(u2, "X-Security-Context", v2.reference), M2 ? this.uploadwithProgress(K, l, p2, M2, u2) : this.post(K, l, p2, u2);
55166
55189
  }
55167
55190
  uploadwithProgress(t, n, i, o2, s) {
55168
55191
  return new Promise((a, u2) => {
@@ -55175,19 +55198,19 @@ var er = class extends ie {
55175
55198
  l.status >= 200 && l.status < 300 ? g2(l.response) : g2(new f(yt(l.response || l.statusText)));
55176
55199
  }, l.open("POST", t), l.withCredentials = true, l.setRequestHeader("Authorization", "Bearer " + this.accessToken), l.setRequestHeader("Cache-Control", "no-cache, no-store, max-age=0"), l.setRequestHeader("Content-Type", i), this.options.extendedMode !== false && l.setRequestHeader("X-Medplum", "extended"), s?.headers) {
55177
55200
  let v2 = s.headers;
55178
- for (let [M2, J] of Object.entries(v2)) l.setRequestHeader(M2, J);
55201
+ for (let [M2, K] of Object.entries(v2)) l.setRequestHeader(M2, K);
55179
55202
  }
55180
55203
  l.send(n);
55181
55204
  });
55182
55205
  }
55183
55206
  async createPdf(t, n, i, o2) {
55184
55207
  if (!this.createPdfImpl) throw new Error("PDF creation not enabled");
55185
- let s = dc(t, n, i, o2), a = typeof n == "object" ? n : {}, { docDefinition: u2, tableLayouts: l, fonts: p2, ...g2 } = s, v2 = await this.createPdfImpl(u2, l, p2), M2 = { ...g2, data: v2, contentType: "application/pdf" };
55208
+ let s = fc(t, n, i, o2), a = typeof n == "object" ? n : {}, { docDefinition: u2, tableLayouts: l, fonts: p2, ...g2 } = s, v2 = await this.createPdfImpl(u2, l, p2), M2 = { ...g2, data: v2, contentType: "application/pdf" };
55186
55209
  return this.createBinary(M2, a);
55187
55210
  }
55188
55211
  createComment(t, n, i) {
55189
55212
  let o2 = this.getProfile(), s, a;
55190
- return t.resourceType === "Encounter" && (s = Ce(t), a = t.subject), t.resourceType === "ServiceRequest" && (s = t.encounter, a = t.subject), t.resourceType === "Patient" && (a = Ce(t)), this.createResource({ resourceType: "Communication", status: "completed", basedOn: [Ce(t)], encounter: s, subject: a, sender: o2 ? Ce(o2) : void 0, sent: (/* @__PURE__ */ new Date()).toISOString(), payload: [{ contentString: n }] }, i);
55213
+ return t.resourceType === "Encounter" && (s = Pe(t), a = t.subject), t.resourceType === "ServiceRequest" && (s = t.encounter, a = t.subject), t.resourceType === "Patient" && (a = Pe(t)), this.createResource({ resourceType: "Communication", status: "completed", basedOn: [Pe(t)], encounter: s, subject: a, sender: o2 ? Pe(o2) : void 0, sent: (/* @__PURE__ */ new Date()).toISOString(), payload: [{ contentString: n }] }, i);
55191
55214
  }
55192
55215
  async updateResource(t, n) {
55193
55216
  if (!t.resourceType) throw new Error("Missing resourceType");
@@ -55230,7 +55253,7 @@ var er = class extends ie {
55230
55253
  }
55231
55254
  pushToAgent(t, n, i, o2, s, a) {
55232
55255
  let { waitTimeout: u2, returnAck: l, ...p2 } = a ?? {};
55233
- return this.post(this.fhirUrl("Agent", Pe(t), "$push"), { destination: typeof n == "string" ? n : O(n), body: i, contentType: o2, waitForResponse: s, ...u2 !== void 0 ? { waitTimeout: u2 } : void 0, ...l !== void 0 ? { returnAck: l } : void 0 }, k.FHIR_JSON, p2);
55256
+ return this.post(this.fhirUrl("Agent", Ae(t), "$push"), { destination: typeof n == "string" ? n : O(n), body: i, contentType: o2, waitForResponse: s, ...u2 !== void 0 ? { waitTimeout: u2 } : void 0, ...l !== void 0 ? { returnAck: l } : void 0 }, k.FHIR_JSON, p2);
55234
55257
  }
55235
55258
  getCdsServices(t) {
55236
55259
  return this.get(this.cdsServicesUrl, t);
@@ -55308,13 +55331,13 @@ var er = class extends ie {
55308
55331
  async downloadResponse(t, n = {}) {
55309
55332
  this.refreshPromise && await this.refreshPromise;
55310
55333
  let i = t.toString();
55311
- i.startsWith(oc) && (t = this.fhirUrl(i));
55334
+ i.startsWith(ac) && (t = this.fhirUrl(i));
55312
55335
  let o2 = n.headers;
55313
55336
  return o2 || (o2 = {}, n.headers = o2), o2.Accept || (o2.Accept = "*/*"), this.addFetchOptionsDefaults(n), this.fetchWithRetry(t.toString(), n);
55314
55337
  }
55315
55338
  async createMedia(t, n) {
55316
55339
  let { additionalFields: i, ...o2 } = t, s = await this.createResource({ resourceType: "Media", status: "preparation", content: { contentType: t.contentType }, ...i });
55317
- o2.securityContext || (o2.securityContext = Ce(s));
55340
+ o2.securityContext || (o2.securityContext = Pe(s));
55318
55341
  let a = await this.createAttachment(o2, n);
55319
55342
  return this.updateResource({ ...s, status: "completed", content: a });
55320
55343
  }
@@ -55323,7 +55346,7 @@ var er = class extends ie {
55323
55346
  }
55324
55347
  async createDocumentReference(t, n) {
55325
55348
  let { additionalFields: i, ...o2 } = t, s = await this.createResource({ resourceType: "DocumentReference", status: "current", content: [{ attachment: { contentType: t.contentType } }], ...i });
55326
- o2.securityContext || (o2.securityContext = Ce(s));
55349
+ o2.securityContext || (o2.securityContext = Pe(s));
55327
55350
  let a = await this.createAttachment(o2, n);
55328
55351
  return this.updateResource({ ...s, content: [{ attachment: a }] });
55329
55352
  }
@@ -55404,7 +55427,7 @@ var er = class extends ie {
55404
55427
  for (let o2 = 0; o2 <= i; o2++) try {
55405
55428
  this.logLevel !== "none" && this.logRequest(t, n);
55406
55429
  let s = await this.fetch(t, n);
55407
- if (this.logLevel !== "none" && this.logResponse(s), this.setCurrentRateLimit(s), o2 >= i || !pc(s)) return s;
55430
+ if (this.logLevel !== "none" && this.logResponse(s), this.setCurrentRateLimit(s), o2 >= i || !mc(s)) return s;
55408
55431
  let a = this.getRetryDelay(o2), u2 = n.maxRetryTime ?? this.maxRetryTime;
55409
55432
  if (a > u2) return s;
55410
55433
  await Kr(a, { signal: n.signal });
@@ -55473,7 +55496,7 @@ var er = class extends ie {
55473
55496
  addFetchOptionsDefaults(t) {
55474
55497
  Object.entries(this.defaultHeaders).forEach(([n, i]) => {
55475
55498
  this.setRequestHeader(t, n, i);
55476
- }), this.setRequestHeader(t, "Accept", Za, true), this.options.extendedMode !== false && this.setRequestHeader(t, "X-Medplum", "extended"), t.body && this.setRequestHeader(t, "Content-Type", k.FHIR_JSON, true), this.accessToken ? this.setRequestHeader(t, "Authorization", "Bearer " + this.accessToken) : this.basicAuth && this.setRequestHeader(t, "Authorization", "Basic " + this.basicAuth), t.cache || (t.cache = "no-cache"), t.credentials || (t.credentials = "include");
55499
+ }), this.setRequestHeader(t, "Accept", tc, true), this.options.extendedMode !== false && this.setRequestHeader(t, "X-Medplum", "extended"), t.body && this.setRequestHeader(t, "Content-Type", k.FHIR_JSON, true), this.accessToken ? this.setRequestHeader(t, "Authorization", "Bearer " + this.accessToken) : this.basicAuth && this.setRequestHeader(t, "Authorization", "Basic " + this.basicAuth), t.cache || (t.cache = "no-cache"), t.credentials || (t.credentials = "include");
55477
55500
  }
55478
55501
  setRequestContentType(t, n) {
55479
55502
  this.setRequestHeader(t, "Content-Type", n);
@@ -55498,7 +55521,7 @@ var er = class extends ie {
55498
55521
  }
55499
55522
  handleUnauthenticated(t, n) {
55500
55523
  if (this.refresh()) return this.request(t, n);
55501
- throw this.clear(), this.onUnauthenticated?.(), new f(Ne);
55524
+ throw this.clear(), this.onUnauthenticated?.(), new f(Fe);
55502
55525
  }
55503
55526
  async startPkce() {
55504
55527
  let t = nn();
@@ -55514,10 +55537,10 @@ var er = class extends ie {
55514
55537
  }
55515
55538
  async requestAuthorization(t) {
55516
55539
  let n = await this.ensureCodeChallenge(t ?? {}), i = new URL(this.authorizeUrl);
55517
- i.searchParams.set("response_type", "code"), i.searchParams.set("state", this.storage.getString("pkceState")), i.searchParams.set("client_id", n.clientId ?? this.clientId), i.searchParams.set("redirect_uri", n.redirectUri ?? ce.getOrigin()), i.searchParams.set("code_challenge_method", n.codeChallengeMethod), i.searchParams.set("code_challenge", n.codeChallenge), i.searchParams.set("scope", n.scope ?? "openid profile"), ce.assign(i.toString());
55540
+ i.searchParams.set("response_type", "code"), i.searchParams.set("state", this.storage.getString("pkceState")), i.searchParams.set("client_id", n.clientId ?? this.clientId), i.searchParams.set("redirect_uri", n.redirectUri ?? ue.getOrigin()), i.searchParams.set("code_challenge_method", n.codeChallengeMethod), i.searchParams.set("code_challenge", n.codeChallenge), i.searchParams.set("scope", n.scope ?? "openid profile"), ue.assign(i.toString());
55518
55541
  }
55519
55542
  processCode(t, n) {
55520
- let i = { grant_type: Ge.AuthorizationCode, code: t, client_id: n?.clientId ?? this.clientId ?? "", redirect_uri: n?.redirectUri ?? ce.getOrigin() }, o2 = this.storage.getString("codeVerifier");
55543
+ let i = { grant_type: Ge.AuthorizationCode, code: t, client_id: n?.clientId ?? this.clientId ?? "", redirect_uri: n?.redirectUri ?? ue.getOrigin() }, o2 = this.storage.getString("codeVerifier");
55521
55544
  return o2 && (i.code_verifier = o2), this.fetchTokens(i);
55522
55545
  }
55523
55546
  refreshIfExpired(t) {
@@ -55543,7 +55566,7 @@ var er = class extends ie {
55543
55566
  return this.clientId = t, this.fetchTokens({ grant_type: Ge.JwtBearer, client_id: t, assertion: n, scope: i });
55544
55567
  }
55545
55568
  async startJwtAssertionLogin(t) {
55546
- return this.fetchTokens({ grant_type: Ge.ClientCredentials, client_assertion_type: ac.JwtBearer, client_assertion: t });
55569
+ return this.fetchTokens({ grant_type: Ge.ClientCredentials, client_assertion_type: uc.JwtBearer, client_assertion: t });
55547
55570
  }
55548
55571
  setBasicAuth(t, n) {
55549
55572
  this.clientId = t, this.clientSecret = n, this.basicAuth = Gt(t + ":" + n);
@@ -55619,10 +55642,10 @@ var er = class extends ie {
55619
55642
  setupStorageListener() {
55620
55643
  try {
55621
55644
  window.addEventListener("storage", (t) => {
55622
- if (t.key === null) ce.reload();
55645
+ if (t.key === null) ue.reload();
55623
55646
  else if (t.key === this.storage.makeKey("activeLogin")) {
55624
55647
  let n = t.oldValue ? JSON.parse(t.oldValue) : void 0, i = t.newValue ? JSON.parse(t.newValue) : void 0;
55625
- n?.profile.reference !== i?.profile.reference || !this.checkSessionDetailsMatchLogin(i) ? ce.reload() : i ? this.setAccessToken(i.accessToken, i.refreshToken) : this.clear();
55648
+ n?.profile.reference !== i?.profile.reference || !this.checkSessionDetailsMatchLogin(i) ? ue.reload() : i ? this.setAccessToken(i.accessToken, i.refreshToken) : this.clear();
55626
55649
  }
55627
55650
  });
55628
55651
  } catch {
@@ -55641,7 +55664,7 @@ var er = class extends ie {
55641
55664
  return this.getSubscriptionManager().getMasterEmitter();
55642
55665
  }
55643
55666
  };
55644
- function cc() {
55667
+ function lc() {
55645
55668
  if (!globalThis.fetch) throw new Error("Fetch not available in this environment");
55646
55669
  return globalThis.fetch.bind(globalThis);
55647
55670
  }
@@ -55656,29 +55679,29 @@ function ro(r6) {
55656
55679
  let e = r6.entry?.map((t) => t.resource) ?? [];
55657
55680
  return Object.assign(e, { bundle: r6 });
55658
55681
  }
55659
- function uc(r6) {
55682
+ function dc(r6) {
55660
55683
  return C(r6) && "data" in r6 && "contentType" in r6;
55661
55684
  }
55662
55685
  function no(r6, e, t, n) {
55663
- return uc(r6) ? r6 : { data: r6, filename: e, contentType: t, onProgress: n };
55686
+ return dc(r6) ? r6 : { data: r6, filename: e, contentType: t, onProgress: n };
55664
55687
  }
55665
- function lc(r6) {
55688
+ function pc(r6) {
55666
55689
  return C(r6) && "docDefinition" in r6;
55667
55690
  }
55668
- function dc(r6, e, t, n) {
55669
- return lc(r6) ? r6 : { docDefinition: r6, filename: e, tableLayouts: t, fonts: n };
55691
+ function fc(r6, e, t, n) {
55692
+ return pc(r6) ? r6 : { docDefinition: r6, filename: e, tableLayouts: t, fonts: n };
55670
55693
  }
55671
- function pc(r6) {
55694
+ function mc(r6) {
55672
55695
  return r6.status === 429 || r6.status >= 500;
55673
55696
  }
55674
- var Rc = [...tt, "->", "<<", ">>", "=="];
55675
- var Ac = rt().registerInfix("->", { precedence: S.Arrow }).registerInfix(";", { precedence: S.Semicolon });
55676
- var Hc = " ".repeat(2);
55677
- var Qc = [...tt, "eq", "ne", "co"];
55678
- var zc = { eq: m.EXACT, ne: m.NOT_EQUALS, co: m.CONTAINS, sw: m.STARTS_WITH, ew: void 0, gt: m.GREATER_THAN, lt: m.LESS_THAN, ge: m.GREATER_THAN_OR_EQUALS, le: m.LESS_THAN_OR_EQUALS, ap: m.APPROXIMATELY, sa: m.STARTS_AFTER, eb: m.ENDS_BEFORE, pr: m.PRESENT, po: void 0, ss: void 0, sb: void 0, in: m.IN, ni: m.NOT_IN, re: m.EQUALS, identifier: m.IDENTIFIER };
55679
- var Kc = rt();
55680
- var Yc = { AA: "OK", AE: "Application Error", AR: "Application Reject", CA: "Commit Accept", CE: "Commit Error", CR: "Commit Reject" };
55681
- var Te = class {
55697
+ var Pc = [...tt, "->", "<<", ">>", "=="];
55698
+ var Oc = rt().registerInfix("->", { precedence: S.Arrow }).registerInfix(";", { precedence: S.Semicolon });
55699
+ var Qc = " ".repeat(2);
55700
+ var Jc = [...tt, "eq", "ne", "co"];
55701
+ var Kc = { eq: m.EXACT, ne: m.NOT_EQUALS, co: m.CONTAINS, sw: m.STARTS_WITH, ew: void 0, gt: m.GREATER_THAN, lt: m.LESS_THAN, ge: m.GREATER_THAN_OR_EQUALS, le: m.LESS_THAN_OR_EQUALS, ap: m.APPROXIMATELY, sa: m.STARTS_AFTER, eb: m.ENDS_BEFORE, pr: m.PRESENT, po: void 0, ss: void 0, sb: void 0, in: m.IN, ni: m.NOT_IN, re: m.EQUALS, identifier: m.IDENTIFIER };
55702
+ var Xc = rt();
55703
+ var Zc = { AA: "OK", AE: "Application Error", AR: "Application Reject", CA: "Commit Accept", CE: "Commit Error", CR: "Commit Reject" };
55704
+ var Se = class {
55682
55705
  constructor(e = "\r", t = "|", n = "^", i = "~", o2 = "\\", s = "&") {
55683
55706
  c(this, "segmentSeparator");
55684
55707
  c(this, "fieldSeparator");
@@ -55696,7 +55719,7 @@ var Te = class {
55696
55719
  }
55697
55720
  };
55698
55721
  var Ro = class r2 {
55699
- constructor(e, t = new Te()) {
55722
+ constructor(e, t = new Se()) {
55700
55723
  c(this, "context");
55701
55724
  c(this, "_segments");
55702
55725
  c(this, "segmentsByName");
@@ -55745,7 +55768,7 @@ var Ro = class r2 {
55745
55768
  }
55746
55769
  buildAck(e) {
55747
55770
  let t = /* @__PURE__ */ new Date(), n = this.getSegment("MSH"), i = n?.getField(3)?.toString() ?? "", o2 = n?.getField(4)?.toString() ?? "", s = n?.getField(5)?.toString() ?? "", a = n?.getField(6)?.toString() ?? "", u2 = n?.getField(10)?.toString() ?? "", l = n?.getField(12)?.toString() ?? "2.5.1", p2 = e?.ackCode ?? "AA";
55748
- return new r2([new lt(["MSH", this.context.getMsh2(), s, a, i, o2, Zc(t), "", this.buildAckMessageType(n), t.getTime().toString(), "P", l], this.context), new lt(["MSA", p2, u2, Yc[p2]], this.context), ...e?.errSegment ? [e.errSegment] : []]);
55771
+ return new r2([new lt(["MSH", this.context.getMsh2(), s, a, i, o2, tu(t), "", this.buildAckMessageType(n), t.getTime().toString(), "P", l], this.context), new lt(["MSA", p2, u2, Zc[p2]], this.context), ...e?.errSegment ? [e.errSegment] : []]);
55749
55772
  }
55750
55773
  buildAckMessageType(e) {
55751
55774
  let t = e?.getField(9), n = t?.getComponent(2), i = t?.getComponent(3), o2 = "ACK";
@@ -55756,7 +55779,7 @@ var Ro = class r2 {
55756
55779
  let i = new Error("Invalid HL7 message");
55757
55780
  throw i.type = "entity.parse.failed", i;
55758
55781
  }
55759
- let t = new Te("\r", e.charAt(3), e.charAt(4), e.charAt(5), e.charAt(6), e.charAt(7)), n = new r2(e.split(/[\r\n]+/), t);
55782
+ let t = new Se("\r", e.charAt(3), e.charAt(4), e.charAt(5), e.charAt(6), e.charAt(7)), n = new r2(e.split(/[\r\n]+/), t);
55760
55783
  return n.cachedString = e, n;
55761
55784
  }
55762
55785
  setSegment(e, t) {
@@ -55791,7 +55814,7 @@ function Co(r6) {
55791
55814
  return e;
55792
55815
  }
55793
55816
  var lt = class r3 {
55794
- constructor(e, t = new Te()) {
55817
+ constructor(e, t = new Se()) {
55795
55818
  c(this, "context");
55796
55819
  c(this, "name");
55797
55820
  c(this, "_fields");
@@ -55814,8 +55837,8 @@ var lt = class r3 {
55814
55837
  }
55815
55838
  getField(e) {
55816
55839
  if (this.name === "MSH") {
55817
- if (e === 1) return new ue([[this.context.getMsh1()]], this.context);
55818
- if (e === 2) return new ue([[this.context.getMsh2()]], this.context);
55840
+ if (e === 1) return new le([[this.context.getMsh1()]], this.context);
55841
+ if (e === 2) return new le([[this.context.getMsh2()]], this.context);
55819
55842
  if (e > 2) return this.parseField(e - 1);
55820
55843
  }
55821
55844
  return this.parseField(e);
@@ -55824,7 +55847,7 @@ var lt = class r3 {
55824
55847
  let t = this._fields[e];
55825
55848
  if (t === void 0) return;
55826
55849
  if (typeof t != "string") return t;
55827
- let n = ue.parse(t, this.context);
55850
+ let n = le.parse(t, this.context);
55828
55851
  return n.onModified = () => {
55829
55852
  this.cachedString = void 0, this.onModified?.();
55830
55853
  }, this._fields[e] = n, n;
@@ -55835,7 +55858,7 @@ var lt = class r3 {
55835
55858
  toString() {
55836
55859
  return this.cachedString ??= this._fields.map((e) => typeof e == "string" ? e : e.toString()).join(this.context.fieldSeparator), this.cachedString;
55837
55860
  }
55838
- static parse(e, t = new Te()) {
55861
+ static parse(e, t = new Se()) {
55839
55862
  let n = new r3(e.split(t.fieldSeparator), t);
55840
55863
  return n.cachedString = e, n;
55841
55864
  }
@@ -55844,12 +55867,12 @@ var lt = class r3 {
55844
55867
  if (e === 1 || e === 2) return false;
55845
55868
  if (e > 2) {
55846
55869
  let n = e - 1;
55847
- for (; this._fields.length <= n; ) this._fields.push(new ue([[""]], this.context));
55848
- return this._fields[n] = typeof t == "string" ? ue.parse(t, this.context) : t, this.invalidateCache(), true;
55870
+ for (; this._fields.length <= n; ) this._fields.push(new le([[""]], this.context));
55871
+ return this._fields[n] = typeof t == "string" ? le.parse(t, this.context) : t, this.invalidateCache(), true;
55849
55872
  }
55850
55873
  }
55851
- for (; this._fields.length <= e; ) this._fields.push(new ue([[""]], this.context));
55852
- return this._fields[e] = typeof t == "string" ? ue.parse(t, this.context) : t, this.invalidateCache(), true;
55874
+ for (; this._fields.length <= e; ) this._fields.push(new le([[""]], this.context));
55875
+ return this._fields[e] = typeof t == "string" ? le.parse(t, this.context) : t, this.invalidateCache(), true;
55853
55876
  }
55854
55877
  setComponent(e, t, n, i, o2 = 0) {
55855
55878
  let s = this.getField(e);
@@ -55865,8 +55888,8 @@ var lt = class r3 {
55865
55888
  for (let t of this._fields) typeof t != "string" && (t.onModified = e);
55866
55889
  }
55867
55890
  };
55868
- var ue = class r4 {
55869
- constructor(e, t = new Te()) {
55891
+ var le = class r4 {
55892
+ constructor(e, t = new Se()) {
55870
55893
  c(this, "context");
55871
55894
  c(this, "components");
55872
55895
  c(this, "onModified");
@@ -55883,7 +55906,7 @@ var ue = class r4 {
55883
55906
  toString() {
55884
55907
  return this.cachedString ??= this.components.map((e) => e.join(this.context.componentSeparator)).join(this.context.repetitionSeparator), this.cachedString;
55885
55908
  }
55886
- static parse(e, t = new Te()) {
55909
+ static parse(e, t = new Se()) {
55887
55910
  let n = new r4(e.split(t.repetitionSeparator).map((i) => i.split(t.componentSeparator)), t);
55888
55911
  return n.cachedString = e, n;
55889
55912
  }
@@ -55905,12 +55928,12 @@ var ue = class r4 {
55905
55928
  this.cachedString = void 0, this.onModified?.();
55906
55929
  }
55907
55930
  };
55908
- function Zc(r6) {
55931
+ function tu(r6) {
55909
55932
  let e = r6 instanceof Date ? r6 : new Date(r6), n = e.toISOString().replaceAll(/[-:T]/g, "").replace(/(\.\d+)?Z$/, ""), i = e.getUTCMilliseconds();
55910
55933
  return i > 0 && (n += "." + i.toString()), n;
55911
55934
  }
55912
55935
  var Qe = { NONE: 0, ERROR: 1, WARN: 2, INFO: 3, DEBUG: 4 };
55913
- var eu = ["NONE", "ERROR", "WARN", "INFO", "DEBUG"];
55936
+ var ru = ["NONE", "ERROR", "WARN", "INFO", "DEBUG"];
55914
55937
  var Po = class r5 {
55915
55938
  constructor(e, t = {}, n = Qe.INFO, i = {}) {
55916
55939
  c(this, "write");
@@ -55948,10 +55971,10 @@ var Po = class r5 {
55948
55971
  i = { ...n };
55949
55972
  for (let [o2, s] of Object.entries(i)) s instanceof Error && (i[o2] = lr(s));
55950
55973
  }
55951
- this.write(JSON.stringify({ level: eu[e], timestamp: (/* @__PURE__ */ new Date()).toISOString(), msg: this.prefix ? `${this.prefix}${t}` : t, ...i, ...this.metadata }));
55974
+ this.write(JSON.stringify({ level: ru[e], timestamp: (/* @__PURE__ */ new Date()).toISOString(), msg: this.prefix ? `${this.prefix}${t}` : t, ...i, ...this.metadata }));
55952
55975
  }
55953
55976
  };
55954
- function Jh(r6) {
55977
+ function Yh(r6) {
55955
55978
  let e = Qe[r6.toUpperCase()];
55956
55979
  if (e === void 0) throw new Error(`Invalid log level: ${r6}`);
55957
55980
  return e;
@@ -55970,9 +55993,9 @@ function lr(r6, e = 0, t = 10) {
55970
55993
  return n;
55971
55994
  }
55972
55995
  var Cn = `${ft}/fhir/StructureDefinition/patient-preferredPharmacy`;
55973
- var bu = "https://meta.medplum.com/releases";
55996
+ var Ru = "https://meta.medplum.com/releases";
55974
55997
  var An = /* @__PURE__ */ new Map();
55975
- function Eu(r6) {
55998
+ function Cu(r6) {
55976
55999
  let e = r6;
55977
56000
  if (!e.tag_name?.startsWith("v")) throw new Error("Manifest missing valid tag_name starting with a 'v' (eg. v5.1.15)");
55978
56001
  let t = e.assets;
@@ -55985,7 +56008,7 @@ function Eu(r6) {
55985
56008
  async function wn(r6, e, t) {
55986
56009
  let n = e ? An.get(e) : void 0;
55987
56010
  if (!n) {
55988
- let i = e ? `v${e}` : "latest", o2 = new URL(`${bu}/${i}.json`);
56011
+ let i = e ? `v${e}` : "latest", o2 = new URL(`${Ru}/${i}.json`);
55989
56012
  if (o2.searchParams.set("a", r6), o2.searchParams.set("c", pn), t) for (let [u2, l] of Object.entries(t)) o2.searchParams.set(u2, l);
55990
56013
  let s = await fetch(o2.toString());
55991
56014
  if (s.status !== 200) {
@@ -55993,20 +56016,20 @@ async function wn(r6, e, t) {
55993
56016
  try {
55994
56017
  u2 = (await s.json()).message;
55995
56018
  } catch (l) {
55996
- console.error(`Failed to parse message from body: ${Se(l)}`);
56019
+ console.error(`Failed to parse message from body: ${be(l)}`);
55997
56020
  }
55998
56021
  throw new Error(`Received status code ${s.status} while fetching manifest for version '${e ?? "latest"}'. Message: ${u2}`);
55999
56022
  }
56000
56023
  let a = await s.json();
56001
- Eu(a), n = a, An.set(n.tag_name.slice(1), n);
56024
+ Cu(a), n = a, An.set(n.tag_name.slice(1), n);
56002
56025
  }
56003
56026
  return n;
56004
56027
  }
56005
- function Ru(r6) {
56028
+ function Pu(r6) {
56006
56029
  return /^\d+\.\d+\.\d+(-[0-9a-z]{7})?$/.test(r6);
56007
56030
  }
56008
- async function Gg(r6, e) {
56009
- if (!Ru(e)) return false;
56031
+ async function zg(r6, e) {
56032
+ if (!Pu(e)) return false;
56010
56033
  try {
56011
56034
  await wn(r6, e);
56012
56035
  } catch {
@@ -56014,7 +56037,7 @@ async function Gg(r6, e) {
56014
56037
  }
56015
56038
  return true;
56016
56039
  }
56017
- async function Qg(r6) {
56040
+ async function Jg(r6) {
56018
56041
  let e = await wn(r6);
56019
56042
  if (!e.tag_name.startsWith("v")) throw new Error(`Invalid release name found. Release tag '${e.tag_name}' did not start with 'v'`);
56020
56043
  return e.tag_name.slice(1);
@@ -56126,7 +56149,7 @@ var v = class extends m2 {
56126
56149
  return;
56127
56150
  }
56128
56151
  let l = c2.message.getSegment("MSA")?.getField(1)?.toString()?.toUpperCase();
56129
- l && (h2.returnAck === af.APPLICATION && l === "CA" || (h2.timer && clearTimeout(h2.timer), h2.resolve(c2.message), this.deletePendingMessage(a)));
56152
+ l && (h2.returnAck === uf.APPLICATION && l === "CA" || (h2.timer && clearTimeout(h2.timer), h2.resolve(c2.message), this.deletePendingMessage(a)));
56130
56153
  });
56131
56154
  }
56132
56155
  isClosed() {
@@ -56179,7 +56202,7 @@ var v = class extends m2 {
56179
56202
  let r6;
56180
56203
  t?.timeoutMs && (r6 = setTimeout(() => {
56181
56204
  this.deletePendingMessage(c2), n(new f({ resourceType: "OperationOutcome", issue: [{ severity: "error", code: "timeout", details: { text: "Client timeout" }, diagnostics: `Request timed out after waiting ${t.timeoutMs} milliseconds for response` }] }));
56182
- }, t.timeoutMs)), this.setPendingMessage(c2, { message: e, resolve: s, reject: n, returnAck: t?.returnAck ?? af.APPLICATION, timer: r6 }), this.sendImpl(e);
56205
+ }, t.timeoutMs)), this.setPendingMessage(c2, { message: e, resolve: s, reject: n, returnAck: t?.returnAck ?? uf.APPLICATION, timer: r6 }), this.sendImpl(e);
56183
56206
  });
56184
56207
  }
56185
56208
  async close() {
@@ -56627,7 +56650,7 @@ var ByteStreamChannelConnection = class {
56627
56650
  }
56628
56651
  } catch (err2) {
56629
56652
  this.channel.log.error(`Byte stream error occurred - check channel logs`);
56630
- this.channel.channelLog.error(`Byte stream error: ${Se(err2)}`);
56653
+ this.channel.channelLog.error(`Byte stream error: ${be(err2)}`);
56631
56654
  }
56632
56655
  }
56633
56656
  write(data2) {
@@ -56644,6 +56667,7 @@ var DEFAULT_PING_TIMEOUT = 3600;
56644
56667
  var DEFAULT_LOG_LIMIT = 20;
56645
56668
  var MAX_LOG_LIMIT = 1e3;
56646
56669
  var MAX_MISSED_HEARTBEATS = 1;
56670
+ var MAX_NOT_LIVE_HEARTBEATS = 2;
56647
56671
  var DEFAULT_MAX_CLIENTS_PER_REMOTE = 5;
56648
56672
  var CLIENT_RELEASE_COUNTDOWN_MS = 1e4;
56649
56673
  var HEARTBEAT_PERIOD_MS = 1e4;
@@ -66437,12 +66461,12 @@ var Colors = /* @__PURE__ */ (function() {
66437
66461
  value: function xyz2LAB(xyz) {
66438
66462
  var whitePoint = Colors2.d65WhitePointXYZ();
66439
66463
  var X = xyz[0] / whitePoint[0];
66440
- var Y = xyz[1] / whitePoint[1];
66441
- var Z2 = xyz[2] / whitePoint[2];
66464
+ var Y2 = xyz[1] / whitePoint[1];
66465
+ var Z = xyz[2] / whitePoint[2];
66442
66466
  X = Colors2.labf(X);
66443
- Y = Colors2.labf(Y);
66444
- Z2 = Colors2.labf(Z2);
66445
- return [116 * Y - 16, 500 * (X - Y), 200 * (Y - Z2)];
66467
+ Y2 = Colors2.labf(Y2);
66468
+ Z = Colors2.labf(Z);
66469
+ return [116 * Y2 - 16, 500 * (X - Y2), 200 * (Y2 - Z)];
66446
66470
  }
66447
66471
  }, {
66448
66472
  key: "lab2RGB",
@@ -73325,7 +73349,7 @@ var AgentDicomChannel = class extends BaseChannel {
73325
73349
  calledAeTitle: this.association?.getCalledAeTitle()
73326
73350
  },
73327
73351
  dataset: dicomJson2,
73328
- binary: binary ? Ce(binary) : void 0
73352
+ binary: binary ? Pe(binary) : void 0
73329
73353
  };
73330
73354
  App.instance.addToWebSocketQueue({
73331
73355
  type: "agent:transmit:request",
@@ -73339,7 +73363,7 @@ var AgentDicomChannel = class extends BaseChannel {
73339
73363
  response2.setStatus(dimse.constants.Status.Success);
73340
73364
  } catch (err2) {
73341
73365
  _DcmjsDimseScp.channel.log.error(`DICOM error - check channel logs`);
73342
- _DcmjsDimseScp.channel.channelLog.error(`DICOM error: ${Se(err2)}`);
73366
+ _DcmjsDimseScp.channel.channelLog.error(`DICOM error: ${be(err2)}`);
73343
73367
  response2.setStatus(dimse.constants.Status.ProcessingFailure);
73344
73368
  }
73345
73369
  return response2;
@@ -73782,12 +73806,12 @@ var AgentHl7ChannelConnection = class {
73782
73806
  }
73783
73807
  } catch (err2) {
73784
73808
  this.channel.log.error(`HL7 error occurred - check channel logs`);
73785
- this.channel.channelLog.error(`HL7 error: ${Se(err2)}`);
73809
+ this.channel.channelLog.error(`HL7 error: ${be(err2)}`);
73786
73810
  }
73787
73811
  }
73788
73812
  async handleError(event) {
73789
- this.channel.log.error(`HL7 connection error: ${Se(event.error)}`);
73790
- this.channel.channelLog.error(`HL7 connection error: ${Se(event.error)}`);
73813
+ this.channel.log.error(`HL7 connection error: ${be(event.error)}`);
73814
+ this.channel.channelLog.error(`HL7 connection error: ${be(event.error)}`);
73791
73815
  }
73792
73816
  handleEnhancedAckSent(event) {
73793
73817
  const hl7Message = event.message;
@@ -74182,13 +74206,13 @@ var Hl7ClientPool = class {
74182
74206
  this.closeAndRemoveClient(client);
74183
74207
  if (this.keepAlive) {
74184
74208
  this.log.error(
74185
- `Persistent connection to remote 'mllp://${this.host}:${this.port}' encountered error: '${Se(event.error)}' - Closing connection...`
74209
+ `Persistent connection to remote 'mllp://${this.host}:${this.port}' encountered error: '${be(event.error)}' - Closing connection...`
74186
74210
  );
74187
74211
  }
74188
74212
  });
74189
74213
  client.addEventListener("warning", (event) => {
74190
74214
  this.log.warn(
74191
- `Connection to remote 'mllp://${this.host}:${this.port}' warning: '${Se(event.error)}'`
74215
+ `Connection to remote 'mllp://${this.host}:${this.port}' warning: '${be(event.error)}'`
74192
74216
  );
74193
74217
  });
74194
74218
  return client;
@@ -74250,7 +74274,7 @@ function cleanupLoggerConfig(config, configPathRoot = "config") {
74250
74274
  warnings.push(`${configPathRoot}.filesToKeep must be a valid integer`);
74251
74275
  config.filesToKeep = void 0;
74252
74276
  }
74253
- if (typeof config.logLevel !== "undefined" && !(typeof config.logLevel === "number" && eu[config.logLevel] !== void 0)) {
74277
+ if (typeof config.logLevel !== "undefined" && !(typeof config.logLevel === "number" && ru[config.logLevel] !== void 0)) {
74254
74278
  warnings.push(`${configPathRoot}.logLevel must be a valid log level between LogLevel.NONE and LogLevel.DEBUG`);
74255
74279
  config.logLevel = void 0;
74256
74280
  }
@@ -74288,16 +74312,16 @@ function parseLoggerConfigFromArgs(args) {
74288
74312
  if (!propName.startsWith("logger.") || propVal === void 0) {
74289
74313
  continue;
74290
74314
  }
74291
- const [_2, configType, settingName] = qe(propName, ".", 3);
74315
+ const [_2, configType, settingName] = je(propName, ".", 3);
74292
74316
  if (!LOGGER_CONFIG_KEYS.includes(settingName)) {
74293
74317
  warnings.push(`${propName} is not a valid setting name`);
74294
74318
  }
74295
74319
  let configValue;
74296
74320
  if (settingName === "logLevel") {
74297
74321
  try {
74298
- configValue = Jh(propVal);
74322
+ configValue = Yh(propVal);
74299
74323
  } catch (err2) {
74300
- warnings.push(`Error while parsing ${propName}: ${Se(err2)}`);
74324
+ warnings.push(`Error while parsing ${propName}: ${be(err2)}`);
74301
74325
  }
74302
74326
  } else if (LOGGER_CONFIG_INTEGER_KEYS.includes(settingName)) {
74303
74327
  try {
@@ -74698,8 +74722,9 @@ var _App = class _App {
74698
74722
  __publicField(this, "heartbeatPeriod", HEARTBEAT_PERIOD_MS);
74699
74723
  // 10 seconds
74700
74724
  __publicField(this, "heartbeatTimer");
74701
- __publicField(this, "heartbeatEmitter", new ie());
74725
+ __publicField(this, "heartbeatEmitter", new oe());
74702
74726
  __publicField(this, "outstandingHeartbeats", 0);
74727
+ __publicField(this, "notLiveHeartbeats", 0);
74703
74728
  __publicField(this, "webSocket");
74704
74729
  __publicField(this, "webSocketWorker");
74705
74730
  __publicField(this, "live", false);
@@ -74732,7 +74757,7 @@ var _App = class _App {
74732
74757
  this.medplum.addEventListener("change", () => {
74733
74758
  if (!this.webSocket) {
74734
74759
  this.connectWebSocket().catch((err2) => {
74735
- this.log.error(Se(err2));
74760
+ this.log.error(be(err2));
74736
74761
  });
74737
74762
  } else {
74738
74763
  this.startWebSocketWorker();
@@ -74804,27 +74829,42 @@ var _App = class _App {
74804
74829
  }
74805
74830
  async startWebSocket() {
74806
74831
  await this.connectWebSocket();
74807
- this.heartbeatTimer = setInterval(() => this.heartbeat(), this.heartbeatPeriod);
74832
+ this.heartbeatTimer = setInterval(() => {
74833
+ this.heartbeat().catch((err2) => {
74834
+ this.log.error(`Error during heartbeat: ${be(err2)}`);
74835
+ });
74836
+ }, this.heartbeatPeriod);
74808
74837
  }
74809
74838
  async heartbeat() {
74810
74839
  this.heartbeatEmitter.dispatchEvent({ type: "heartbeat" });
74811
74840
  if (!this.webSocket) {
74812
74841
  this.log.warn("WebSocket not connected");
74813
74842
  this.connectWebSocket().catch((err2) => {
74814
- this.log.error(Se(err2));
74843
+ this.log.error(be(err2));
74815
74844
  });
74816
74845
  return;
74817
74846
  }
74818
- if (this.live) {
74819
- if (this.outstandingHeartbeats > MAX_MISSED_HEARTBEATS) {
74820
- this.outstandingHeartbeats = 0;
74847
+ if (!this.live) {
74848
+ this.notLiveHeartbeats += 1;
74849
+ if (this.notLiveHeartbeats > MAX_NOT_LIVE_HEARTBEATS) {
74850
+ this.notLiveHeartbeats = 0;
74851
+ this.log.warn("Not connected to Medplum server after multiple heartbeat periods. Attempting to reconnect...");
74821
74852
  this.webSocket.reconnect();
74822
- this.log.info("Disconnected from Medplum server. Attempting to reconnect...");
74823
- return;
74824
74853
  }
74825
- this.outstandingHeartbeats += 1;
74826
- await this.sendToWebSocket({ type: "agent:heartbeat:request" });
74827
- this.lastHeartbeatSentTime = Date.now();
74854
+ return;
74855
+ }
74856
+ this.notLiveHeartbeats = 0;
74857
+ if (this.outstandingHeartbeats > MAX_MISSED_HEARTBEATS) {
74858
+ this.outstandingHeartbeats = 0;
74859
+ this.webSocket.reconnect();
74860
+ this.log.info("Disconnected from Medplum server. Attempting to reconnect...");
74861
+ return;
74862
+ }
74863
+ this.outstandingHeartbeats += 1;
74864
+ await this.sendToWebSocket({ type: "agent:heartbeat:request" });
74865
+ this.lastHeartbeatSentTime = Date.now();
74866
+ if (this.webSocketQueue.length > 0) {
74867
+ this.startWebSocketWorker();
74828
74868
  }
74829
74869
  }
74830
74870
  async connectWebSocket() {
@@ -74842,11 +74882,15 @@ var _App = class _App {
74842
74882
  }
74843
74883
  });
74844
74884
  this.webSocket.addEventListener("open", async () => {
74845
- await this.sendToWebSocket({
74846
- type: "agent:connect:request",
74847
- accessToken: this.medplum.getAccessToken(),
74848
- agentId: this.agentId
74849
- });
74885
+ try {
74886
+ await this.sendToWebSocket({
74887
+ type: "agent:connect:request",
74888
+ accessToken: this.medplum.getAccessToken(),
74889
+ agentId: this.agentId
74890
+ });
74891
+ } catch (err2) {
74892
+ this.log.error(`Error sending connect request: ${be(err2)}`);
74893
+ }
74850
74894
  });
74851
74895
  this.webSocket.addEventListener("close", () => {
74852
74896
  if (!this.shutdown && this.live) {
@@ -74866,6 +74910,8 @@ var _App = class _App {
74866
74910
  case "connected":
74867
74911
  case "agent:connect:response":
74868
74912
  this.live = true;
74913
+ this.notLiveHeartbeats = 0;
74914
+ this.outstandingHeartbeats = 0;
74869
74915
  this.startWebSocketWorker();
74870
74916
  this.log.info("Successfully connected to Medplum server");
74871
74917
  break;
@@ -74923,7 +74969,7 @@ var _App = class _App {
74923
74969
  } catch (err2) {
74924
74970
  await this.sendToWebSocket({
74925
74971
  type: "agent:error",
74926
- body: Se(err2),
74972
+ body: be(err2),
74927
74973
  callback: command.callback
74928
74974
  });
74929
74975
  }
@@ -74951,7 +74997,7 @@ var _App = class _App {
74951
74997
  }
74952
74998
  }
74953
74999
  } catch (err2) {
74954
- const errMsg = `WebSocket error on incoming message: ${Se(err2)}`;
75000
+ const errMsg = `WebSocket error on incoming message: ${be(err2)}`;
74955
75001
  this.log.error(errMsg);
74956
75002
  try {
74957
75003
  await this.sendToWebSocket({
@@ -74960,7 +75006,7 @@ var _App = class _App {
74960
75006
  callback: command?.callback
74961
75007
  });
74962
75008
  } catch (sendErr) {
74963
- this.log.error(`Failed to send agent:error response: ${Se(sendErr)}`);
75009
+ this.log.error(`Failed to send agent:error response: ${be(sendErr)}`);
74964
75010
  }
74965
75011
  }
74966
75012
  });
@@ -74996,7 +75042,7 @@ var _App = class _App {
74996
75042
  const results = await Promise.allSettled(Array.from(this.hl7Clients.values()).map((pool) => pool.closeAll()));
74997
75043
  for (const result of results) {
74998
75044
  if (result.status === "rejected") {
74999
- this.log.error(Se(result.reason));
75045
+ this.log.error(be(result.reason));
75000
75046
  }
75001
75047
  }
75002
75048
  this.hl7Clients.clear();
@@ -75122,7 +75168,7 @@ var _App = class _App {
75122
75168
  }
75123
75169
  } catch (err2) {
75124
75170
  errors.push(err2);
75125
- this.log.error(Se(err2));
75171
+ this.log.error(be(err2));
75126
75172
  }
75127
75173
  }
75128
75174
  if (errors.length) {
@@ -75140,7 +75186,7 @@ var _App = class _App {
75140
75186
  (err2) => ({
75141
75187
  severity: "error",
75142
75188
  code: "invalid",
75143
- details: { text: Se(err2) }
75189
+ details: { text: be(err2) }
75144
75190
  })
75145
75191
  )
75146
75192
  ]
@@ -75161,7 +75207,7 @@ var _App = class _App {
75161
75207
  return;
75162
75208
  }
75163
75209
  for (const err2 of errors) {
75164
- this.log.error(Se(err2));
75210
+ this.log.error(be(err2));
75165
75211
  }
75166
75212
  throw new f({
75167
75213
  resourceType: "OperationOutcome",
@@ -75177,7 +75223,7 @@ var _App = class _App {
75177
75223
  (err2) => ({
75178
75224
  severity: "error",
75179
75225
  code: "invalid",
75180
- details: { text: Se(err2) }
75226
+ details: { text: be(err2) }
75181
75227
  })
75182
75228
  )
75183
75229
  ]
@@ -75205,7 +75251,7 @@ var _App = class _App {
75205
75251
  parsedEndpoint = new URL(endpoint.address);
75206
75252
  } catch (err2) {
75207
75253
  throw new Error(
75208
- `Error while validating endpoint address for channel '${channel.name}': ${Se(err2)}`
75254
+ `Error while validating endpoint address for channel '${channel.name}': ${be(err2)}`
75209
75255
  );
75210
75256
  }
75211
75257
  if (seenPorts.has(parsedEndpoint.port)) {
@@ -75246,7 +75292,7 @@ var _App = class _App {
75246
75292
  const channelType = getChannelType(endpoint);
75247
75293
  return this.createChannel(channelType, definition, endpoint);
75248
75294
  } catch (err2) {
75249
- this.log.error(Se(err2));
75295
+ this.log.error(be(err2));
75250
75296
  return void 0;
75251
75297
  }
75252
75298
  }
@@ -75307,9 +75353,11 @@ var _App = class _App {
75307
75353
  if (this.webSocketWorker) {
75308
75354
  return;
75309
75355
  }
75310
- this.webSocketWorker = this.trySendToWebSocket().then(() => {
75356
+ this.webSocketWorker = this.trySendToWebSocket().catch((err2) => {
75357
+ this.log.error(`WebSocket worker error: ${be(err2)}`);
75358
+ }).finally(() => {
75311
75359
  this.webSocketWorker = void 0;
75312
- }).catch((err2) => console.log("WebSocket worker error", err2));
75360
+ });
75313
75361
  }
75314
75362
  async trySendToWebSocket() {
75315
75363
  if (this.live) {
@@ -75319,14 +75367,13 @@ var _App = class _App {
75319
75367
  try {
75320
75368
  await this.sendToWebSocket(msg);
75321
75369
  } catch (err2) {
75322
- this.log.error(`WebSocket error while attempting to send message: ${Se(err2)}`);
75370
+ this.log.error(`WebSocket error while attempting to send message: ${be(err2)}`);
75323
75371
  this.webSocketQueue.unshift(msg);
75324
75372
  throw err2;
75325
75373
  }
75326
75374
  }
75327
75375
  }
75328
75376
  }
75329
- this.webSocketWorker = void 0;
75330
75377
  }
75331
75378
  trySendToHl7Connection() {
75332
75379
  while (this.hl7Queue.length > 0) {
@@ -75356,7 +75403,7 @@ IPv6 is currently unsupported.`;
75356
75403
  this.log.error(errMsg);
75357
75404
  throw new Error(errMsg);
75358
75405
  }
75359
- if (!((0, import_node_net4.isIPv4)(message.remote) || Cd(message.remote))) {
75406
+ if (!((0, import_node_net4.isIPv4)(message.remote) || Ad(message.remote))) {
75360
75407
  const errMsg = `Attempted to ping an invalid host.
75361
75408
 
75362
75409
  "${message.remote}" is not a valid IPv4 address or a resolvable hostname.`;
@@ -75395,7 +75442,7 @@ ${result}`);
75395
75442
  body: result
75396
75443
  });
75397
75444
  } catch (err2) {
75398
- this.log.error(`Error during ping attempt to ${message.remote ?? "NO_HOST_GIVEN"}: ${Se(err2)}`);
75445
+ this.log.error(`Error during ping attempt to ${message.remote ?? "NO_HOST_GIVEN"}: ${be(err2)}`);
75399
75446
  this.addToWebSocketQueue({
75400
75447
  type: "agent:transmit:response",
75401
75448
  channel: message.channel,
@@ -75403,7 +75450,7 @@ ${result}`);
75403
75450
  remote: message.remote,
75404
75451
  callback: message.callback,
75405
75452
  statusCode: 400,
75406
- body: Se(err2)
75453
+ body: be(err2)
75407
75454
  });
75408
75455
  }
75409
75456
  }
@@ -75431,7 +75478,7 @@ ${result}`);
75431
75478
  return;
75432
75479
  }
75433
75480
  let child;
75434
- if (message.version && !await Gg("agent-upgrader", message.version)) {
75481
+ if (message.version && !await zg("agent-upgrader", message.version)) {
75435
75482
  const versionTag = message.version ? `v${message.version}` : "latest";
75436
75483
  const errMsg = `Error during upgrading to version '${versionTag}'. '${message.version}' is not a valid version`;
75437
75484
  this.log.error(errMsg);
@@ -75442,7 +75489,7 @@ ${result}`);
75442
75489
  });
75443
75490
  return;
75444
75491
  }
75445
- const targetVersion = message.version ?? await Qg("agent-upgrader");
75492
+ const targetVersion = message.version ?? await Jg("agent-upgrader");
75446
75493
  if (pn.startsWith(targetVersion)) {
75447
75494
  if (!message?.force) {
75448
75495
  this.log.info(`Attempted to upgrade to version ${targetVersion}, but agent is already on that version`);
@@ -75482,7 +75529,7 @@ ${result}`);
75482
75529
  parseDownloadUrl(release, (0, import_node_os4.platform)());
75483
75530
  } catch (err2) {
75484
75531
  const versionTag = message.version ? `v${message.version}` : "latest";
75485
- const errMsg = `Error during upgrading to version '${versionTag}': ${Se(err2)}`;
75532
+ const errMsg = `Error during upgrading to version '${versionTag}': ${be(err2)}`;
75486
75533
  this.log.error(errMsg);
75487
75534
  await this.sendToWebSocket({
75488
75535
  type: "agent:error",
@@ -75516,13 +75563,13 @@ ${result}`);
75516
75563
  }
75517
75564
  });
75518
75565
  child.on("error", (err2) => {
75519
- this.log.error(Se(err2));
75566
+ this.log.error(be(err2));
75520
75567
  reject(err2);
75521
75568
  });
75522
75569
  });
75523
75570
  } catch (err2) {
75524
75571
  const versionTag = message.version ? `v${message.version}` : "latest";
75525
- const errMsg = `Error during upgrading to version '${versionTag}': ${Se(err2)}`;
75572
+ const errMsg = `Error during upgrading to version '${versionTag}': ${be(err2)}`;
75526
75573
  this.log.error(errMsg);
75527
75574
  await this.sendToWebSocket({
75528
75575
  type: "agent:error",
@@ -75546,7 +75593,7 @@ ${result}`);
75546
75593
  child.disconnect();
75547
75594
  } catch (err2) {
75548
75595
  this.log.error(
75549
- `Error while stopping agent or messaging child process as part of upgrade: ${Se(err2)}`
75596
+ `Error while stopping agent or messaging child process as part of upgrade: ${be(err2)}`
75550
75597
  );
75551
75598
  import_node_process2.default.exit(1);
75552
75599
  }
@@ -75560,10 +75607,10 @@ ${result}`);
75560
75607
  callback: command.callback
75561
75608
  });
75562
75609
  } catch (err2) {
75563
- this.log.error(Se(err2));
75610
+ this.log.error(be(err2));
75564
75611
  await this.sendToWebSocket({
75565
75612
  type: "agent:error",
75566
- body: Se(err2),
75613
+ body: be(err2),
75567
75614
  callback: command.callback
75568
75615
  });
75569
75616
  }
@@ -75588,10 +75635,10 @@ ${result}`);
75588
75635
  callback: command.callback
75589
75636
  });
75590
75637
  } catch (err2) {
75591
- this.log.error(Se(err2));
75638
+ this.log.error(be(err2));
75592
75639
  await this.sendToWebSocket({
75593
75640
  type: "agent:error",
75594
- body: Se(err2),
75641
+ body: be(err2),
75595
75642
  callback: command.callback
75596
75643
  });
75597
75644
  }
@@ -75632,7 +75679,7 @@ ${result}`);
75632
75679
  try {
75633
75680
  msgReturnAck = this.parseReturnAck(message.returnAck);
75634
75681
  } catch (err2) {
75635
- this.log.error(Se(err2));
75682
+ this.log.error(be(err2));
75636
75683
  this.addToWebSocketQueue({
75637
75684
  type: "agent:transmit:response",
75638
75685
  channel: message.channel,
@@ -75640,7 +75687,7 @@ ${result}`);
75640
75687
  callback: message.callback,
75641
75688
  contentType: k.TEXT,
75642
75689
  statusCode: 400,
75643
- body: Se(err2)
75690
+ body: be(err2)
75644
75691
  });
75645
75692
  return;
75646
75693
  }
@@ -75648,9 +75695,9 @@ ${result}`);
75648
75695
  try {
75649
75696
  defaultReturnAck = this.parseReturnAck(address.searchParams.get("defaultReturnAck"));
75650
75697
  } catch (err2) {
75651
- this.log.warn(`${Se(err2)} - falling back to default return ACK behavior of 'first'.`);
75698
+ this.log.warn(`${be(err2)} - falling back to default return ACK behavior of 'first'.`);
75652
75699
  }
75653
- const returnAck = msgReturnAck ?? defaultReturnAck ?? af.FIRST;
75700
+ const returnAck = msgReturnAck ?? defaultReturnAck ?? uf.FIRST;
75654
75701
  let pool;
75655
75702
  if (this.hl7Clients.has(message.remote)) {
75656
75703
  pool = this.hl7Clients.get(message.remote);
@@ -75693,7 +75740,7 @@ ${result}`);
75693
75740
  try {
75694
75741
  client = pool.getClient();
75695
75742
  } catch (err2) {
75696
- this.log.error(`Failed to get client from pool: ${Se(err2)}`);
75743
+ this.log.error(`Failed to get client from pool: ${be(err2)}`);
75697
75744
  this.addToWebSocketQueue({
75698
75745
  type: "agent:transmit:response",
75699
75746
  channel: message.channel,
@@ -75701,7 +75748,7 @@ ${result}`);
75701
75748
  callback: message.callback,
75702
75749
  contentType: k.TEXT,
75703
75750
  statusCode: 400,
75704
- body: Se(err2)
75751
+ body: be(err2)
75705
75752
  });
75706
75753
  return;
75707
75754
  }
@@ -75717,7 +75764,7 @@ ${result}`);
75717
75764
  body: response2.toString()
75718
75765
  });
75719
75766
  }).catch((err2) => {
75720
- this.log.error(`HL7 error: ${Se(err2)}`);
75767
+ this.log.error(`HL7 error: ${be(err2)}`);
75721
75768
  this.addToWebSocketQueue({
75722
75769
  type: "agent:transmit:response",
75723
75770
  channel: message.channel,
@@ -75725,7 +75772,7 @@ ${result}`);
75725
75772
  callback: message.callback,
75726
75773
  contentType: k.TEXT,
75727
75774
  statusCode: 400,
75728
- body: Se(err2)
75775
+ body: be(err2)
75729
75776
  });
75730
75777
  forceClose = true;
75731
75778
  }).finally(() => {
@@ -75753,10 +75800,10 @@ ${result}`);
75753
75800
  }
75754
75801
  const normalizedValue = rawValue.toLowerCase();
75755
75802
  if (normalizedValue === "application") {
75756
- return af.APPLICATION;
75803
+ return uf.APPLICATION;
75757
75804
  }
75758
75805
  if (normalizedValue === "first") {
75759
- return af.FIRST;
75806
+ return uf.FIRST;
75760
75807
  }
75761
75808
  throw new Error(`Invalid value for returnAck; expected: 'first' or 'application', received: ${rawValue}`);
75762
75809
  }
@@ -75804,7 +75851,7 @@ async function agentMain(argv) {
75804
75851
  await medplum.startClientLogin(clientId, clientSecret);
75805
75852
  loggedIn = true;
75806
75853
  } catch (err2) {
75807
- console.error("Failed to login", { err: Se(err2) });
75854
+ console.error("Failed to login", { err: be(err2) });
75808
75855
  console.log("Retrying login in 10 seconds...");
75809
75856
  await Kr(RETRY_WAIT_DURATION_MS);
75810
75857
  }
@@ -75819,7 +75866,7 @@ async function agentMain(argv) {
75819
75866
  for (const warning of warnings) {
75820
75867
  mainLogger.warn(warning);
75821
75868
  }
75822
- const app = new App(medplum, agentId, args.logLevel ? Jh(args.logLevel) : void 0, {
75869
+ const app = new App(medplum, agentId, args.logLevel ? Yh(args.logLevel) : void 0, {
75823
75870
  mainLogger,
75824
75871
  channelLogger
75825
75872
  });
@@ -75865,10 +75912,10 @@ async function upgraderMain(argv) {
75865
75912
  rejectOnTimeout = () => reject(new Error("Timed out while waiting for IPC to disconnect"));
75866
75913
  import_node_process3.default.once("disconnect", resolve2);
75867
75914
  });
75868
- if (argv[3] && !Ru(argv[3])) {
75915
+ if (argv[3] && !Pu(argv[3])) {
75869
75916
  throw new Error("Invalid version specified");
75870
75917
  }
75871
- version = argv[3] ?? await Qg("agent-upgrader");
75918
+ version = argv[3] ?? await Jg("agent-upgrader");
75872
75919
  binPath = getReleaseBinPath(version);
75873
75920
  if (!(0, import_node_fs6.existsSync)(binPath)) {
75874
75921
  globalLogger.info(`Could not find binary at "${binPath}". Downloading release from GitHub...`);
@@ -75876,7 +75923,7 @@ async function upgraderMain(argv) {
75876
75923
  globalLogger.info("Release successfully downloaded");
75877
75924
  }
75878
75925
  } catch (err2) {
75879
- import_node_process3.default.send({ type: "ERROR", err: Se(err2) });
75926
+ import_node_process3.default.send({ type: "ERROR", err: be(err2) });
75880
75927
  throw err2;
75881
75928
  }
75882
75929
  import_node_process3.default.send({ type: "STARTED" });
@@ -75897,7 +75944,7 @@ async function upgraderMain(argv) {
75897
75944
  (0, import_node_child_process2.spawnSync)(`"${binPath}" /S`, { windowsHide: true, shell: true });
75898
75945
  globalLogger.info(`Agent version ${version} successfully installed`);
75899
75946
  } catch (err2) {
75900
- globalLogger.error(`Error while attempting to run installer: ${Se(err2)}`);
75947
+ globalLogger.error(`Error while attempting to run installer: ${be(err2)}`);
75901
75948
  globalLogger.error("Failed to run installer, attempting to restart agent service...");
75902
75949
  try {
75903
75950
  (0, import_node_child_process2.execSync)('net start "Medplum Agent"');
@@ -75947,10 +75994,10 @@ ${allAgentServices.join("\r\n")}\r
75947
75994
  } catch (err2) {
75948
75995
  (0, import_node_fs7.appendFileSync)(logFileFd, `Failed to stop service: ${serviceName}\r
75949
75996
  `, { encoding: "utf-8" });
75950
- (0, import_node_fs7.appendFileSync)(logFileFd, `${Se(err2)}\r
75997
+ (0, import_node_fs7.appendFileSync)(logFileFd, `${be(err2)}\r
75951
75998
  `, { encoding: "utf-8" });
75952
75999
  console.error(`Failed to stop service: ${serviceName}`);
75953
- console.error(Se(err2));
76000
+ console.error(be(err2));
75954
76001
  }
75955
76002
  try {
75956
76003
  (0, import_node_child_process3.execSync)(`sc.exe delete ${serviceName}`);
@@ -75960,10 +76007,10 @@ ${allAgentServices.join("\r\n")}\r
75960
76007
  } catch (err2) {
75961
76008
  (0, import_node_fs7.appendFileSync)(logFileFd, `Failed to delete service: ${serviceName}\r
75962
76009
  `, { encoding: "utf-8" });
75963
- (0, import_node_fs7.appendFileSync)(logFileFd, `${Se(err2)}\r
76010
+ (0, import_node_fs7.appendFileSync)(logFileFd, `${be(err2)}\r
75964
76011
  `, { encoding: "utf-8" });
75965
76012
  console.error(`Failed to delete service: ${serviceName}`);
75966
- console.error(Se(err2));
76013
+ console.error(be(err2));
75967
76014
  }
75968
76015
  }
75969
76016
  (0, import_node_fs7.closeSync)(logFileFd);