@medplum/agent 5.0.4 → 5.0.5

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 +102 -100
  2. package/package.json +5 -5
@@ -18109,9 +18109,9 @@ var require_dcmjs = __commonJS({
18109
18109
  key: "rgb2XYZ",
18110
18110
  value: function rgb2XYZ(rgb) {
18111
18111
  var R3 = Colors2.invGammaCorrection(rgb[0]);
18112
- var G2 = Colors2.invGammaCorrection(rgb[1]);
18112
+ var G = Colors2.invGammaCorrection(rgb[1]);
18113
18113
  var B3 = Colors2.invGammaCorrection(rgb[2]);
18114
- return [0.41239558896741424 * R3 + 0.3575834307637148 * G2 + 0.18049264738170157 * B3, 0.21258623078559555 * R3 + 0.7151703037034108 * G2 + 0.07220049864333623 * B3, 0.019297215491746945 * R3 + 0.11918386458084854 * G2 + 0.9504971251315798 * B3];
18114
+ return [0.41239558896741424 * R3 + 0.3575834307637148 * G + 0.18049264738170157 * B3, 0.21258623078559555 * R3 + 0.7151703037034108 * G + 0.07220049864333623 * B3, 0.019297215491746945 * R3 + 0.11918386458084854 * G + 0.9504971251315798 * B3];
18115
18115
  }
18116
18116
  }, {
18117
18117
  key: "xyz2LAB",
@@ -37288,9 +37288,9 @@ var require_dcmjs2 = __commonJS({
37288
37288
  key: "rgb2XYZ",
37289
37289
  value: function rgb2XYZ(rgb) {
37290
37290
  var R3 = Colors2.invGammaCorrection(rgb[0]);
37291
- var G2 = Colors2.invGammaCorrection(rgb[1]);
37291
+ var G = Colors2.invGammaCorrection(rgb[1]);
37292
37292
  var B3 = Colors2.invGammaCorrection(rgb[2]);
37293
- return [0.41239558896741424 * R3 + 0.3575834307637148 * G2 + 0.18049264738170157 * B3, 0.21258623078559555 * R3 + 0.7151703037034108 * G2 + 0.07220049864333623 * B3, 0.019297215491746945 * R3 + 0.11918386458084854 * G2 + 0.9504971251315798 * B3];
37293
+ return [0.41239558896741424 * R3 + 0.3575834307637148 * G + 0.18049264738170157 * B3, 0.21258623078559555 * R3 + 0.7151703037034108 * G + 0.07220049864333623 * B3, 0.019297215491746945 * R3 + 0.11918386458084854 * G + 0.9504971251315798 * B3];
37294
37294
  }
37295
37295
  }, {
37296
37296
  key: "xyz2LAB",
@@ -49617,8 +49617,8 @@ var require_dcmjs_dimse_min = __commonJS({
49617
49617
  "use strict";
49618
49618
  e2.exports = s;
49619
49619
  }, 237: (e2, t2, s2) => {
49620
- const { Association: n2, PresentationContext: i2 } = s2(570), { Scp: r8, Server: o3 } = s2(538), { CCancelRequest: a2, CEchoRequest: c3, CEchoResponse: d2, CFindRequest: u2, CFindResponse: h3, CGetRequest: m3, CGetResponse: g2, CMoveRequest: l2, CMoveResponse: p2, CStoreRequest: R3, CStoreResponse: S2, NActionRequest: y2, NActionResponse: f2, NCreateRequest: I2, NCreateResponse: C, NDeleteRequest: P3, NDeleteResponse: v3, NEventReportRequest: x2, NEventReportResponse: A3, NGetRequest: U2, NGetResponse: w3, NSetRequest: D3, NSetResponse: q } = s2(940), { AbortReason: E2, AbortSource: T2, CommandFieldType: b3, PresentationContextResult: O2, Priority: N2, RawPduType: B3, RejectReason: M3, RejectResult: L, RejectSource: F2, SopClass: k2, Status: $2, StorageClass: j2, TransferSyntax: V2, Uid: _2, UserIdentityType: G2 } = s2(492), z2 = s2(422), Q = s2(825), W2 = s2(139), J2 = s2(906), X2 = s2(73), H2 = { association: { Association: n2, PresentationContext: i2 }, Client: z2, constants: { AbortReason: E2, AbortSource: T2, CommandFieldType: b3, PresentationContextResult: O2, Priority: N2, RawPduType: B3, RejectReason: M3, RejectResult: L, RejectSource: F2, SopClass: k2, Status: $2, StorageClass: j2, TransferSyntax: V2, Uid: _2, UserIdentityType: G2 }, Dataset: Q, Implementation: W2, log: s2(547), requests: { CCancelRequest: a2, CEchoRequest: c3, CFindRequest: u2, CGetRequest: m3, CMoveRequest: l2, CStoreRequest: R3, NActionRequest: y2, NCreateRequest: I2, NDeleteRequest: P3, NEventReportRequest: x2, NGetRequest: U2, NSetRequest: D3 }, responses: { CEchoResponse: d2, CFindResponse: h3, CGetResponse: g2, CMoveResponse: p2, CStoreResponse: S2, NActionResponse: f2, NCreateResponse: C, NDeleteResponse: v3, NEventReportResponse: A3, NGetResponse: w3, NSetResponse: q }, Scp: r8, Server: o3, Statistics: J2, Transcoding: X2, version: s2(837) };
49621
- e2.exports = H2;
49620
+ const { Association: n2, PresentationContext: i2 } = s2(570), { Scp: r8, Server: o3 } = s2(538), { CCancelRequest: a2, CEchoRequest: c3, CEchoResponse: d2, CFindRequest: u2, CFindResponse: h3, CGetRequest: m3, CGetResponse: g2, CMoveRequest: l2, CMoveResponse: p2, CStoreRequest: R3, CStoreResponse: S2, NActionRequest: y2, NActionResponse: f2, NCreateRequest: I2, NCreateResponse: C, NDeleteRequest: P3, NDeleteResponse: v3, NEventReportRequest: x2, NEventReportResponse: A3, NGetRequest: U2, NGetResponse: w3, NSetRequest: D3, NSetResponse: q } = s2(940), { AbortReason: E2, AbortSource: T2, CommandFieldType: b3, PresentationContextResult: O2, Priority: N2, RawPduType: B3, RejectReason: M3, RejectResult: L, RejectSource: F2, SopClass: k2, Status: $2, StorageClass: j2, TransferSyntax: V2, Uid: _2, UserIdentityType: G } = s2(492), z2 = s2(422), Q = s2(825), W2 = s2(139), J2 = s2(906), X2 = s2(73), H3 = { association: { Association: n2, PresentationContext: i2 }, Client: z2, constants: { AbortReason: E2, AbortSource: T2, CommandFieldType: b3, PresentationContextResult: O2, Priority: N2, RawPduType: B3, RejectReason: M3, RejectResult: L, RejectSource: F2, SopClass: k2, Status: $2, StorageClass: j2, TransferSyntax: V2, Uid: _2, UserIdentityType: G }, Dataset: Q, Implementation: W2, log: s2(547), requests: { CCancelRequest: a2, CEchoRequest: c3, CFindRequest: u2, CGetRequest: m3, CMoveRequest: l2, CStoreRequest: R3, NActionRequest: y2, NCreateRequest: I2, NDeleteRequest: P3, NEventReportRequest: x2, NGetRequest: U2, NSetRequest: D3 }, responses: { CEchoResponse: d2, CFindResponse: h3, CGetResponse: g2, CMoveResponse: p2, CStoreResponse: S2, NActionResponse: f2, NCreateResponse: C, NDeleteResponse: v3, NEventReportResponse: A3, NGetResponse: w3, NSetResponse: q }, Scp: r8, Server: o3, Statistics: J2, Transcoding: X2, version: s2(837) };
49621
+ e2.exports = H3;
49622
49622
  }, 278: (e2) => {
49623
49623
  "use strict";
49624
49624
  e2.exports = require("net");
@@ -49626,8 +49626,8 @@ var require_dcmjs_dimse_min = __commonJS({
49626
49626
  "use strict";
49627
49627
  e2.exports = n;
49628
49628
  }, 371: (e2, t2, s2) => {
49629
- const { Association: n2 } = s2(570), { AAbort: i2, AAssociateAC: r8, AAssociateRJ: o3, AAssociateRQ: a2, AReleaseRP: c3, AReleaseRQ: d2, PDataTF: u2, Pdv: h3, RawPdu: m3 } = s2(942), { CommandFieldType: g2, RawPduType: l2, Status: p2 } = s2(492), { CCancelRequest: R3, CEchoRequest: S2, CEchoResponse: y2, CFindRequest: f2, CFindResponse: I2, CGetRequest: C, CGetResponse: P3, CMoveRequest: v3, CMoveResponse: x2, Command: A3, CStoreRequest: U2, CStoreResponse: w3, NActionRequest: D3, NActionResponse: q, NCreateRequest: E2, NCreateResponse: T2, NDeleteRequest: b3, NDeleteResponse: O2, NEventReportRequest: N2, NEventReportResponse: B3, NGetRequest: M3, NGetResponse: L, NSetRequest: F2, NSetResponse: k2, Response: $2 } = s2(940), j2 = s2(825), V2 = s2(139), _2 = s2(906), G2 = s2(73), z2 = s2(547), { SmartBuffer: Q } = s2(766), { EOL: W2 } = s2(857), J2 = s2(0), X2 = s2(235);
49630
- class H2 extends J2 {
49629
+ const { Association: n2 } = s2(570), { AAbort: i2, AAssociateAC: r8, AAssociateRJ: o3, AAssociateRQ: a2, AReleaseRP: c3, AReleaseRQ: d2, PDataTF: u2, Pdv: h3, RawPdu: m3 } = s2(942), { CommandFieldType: g2, RawPduType: l2, Status: p2 } = s2(492), { CCancelRequest: R3, CEchoRequest: S2, CEchoResponse: y2, CFindRequest: f2, CFindResponse: I2, CGetRequest: C, CGetResponse: P3, CMoveRequest: v3, CMoveResponse: x2, Command: A3, CStoreRequest: U2, CStoreResponse: w3, NActionRequest: D3, NActionResponse: q, NCreateRequest: E2, NCreateResponse: T2, NDeleteRequest: b3, NDeleteResponse: O2, NEventReportRequest: N2, NEventReportResponse: B3, NGetRequest: M3, NGetResponse: L, NSetRequest: F2, NSetResponse: k2, Response: $2 } = s2(940), j2 = s2(825), V2 = s2(139), _2 = s2(906), G = s2(73), z2 = s2(547), { SmartBuffer: Q } = s2(766), { EOL: W2 } = s2(857), J2 = s2(0), X2 = s2(235);
49630
+ class H3 extends J2 {
49631
49631
  constructor() {
49632
49632
  super();
49633
49633
  }
@@ -49747,7 +49747,7 @@ var require_dcmjs_dimse_min = __commonJS({
49747
49747
  try {
49748
49748
  const t3 = e3.command.getDataset(), s3 = this.association.getPresentationContext(e3.context.getPresentationContextId()).getAcceptedTransferSyntaxUid();
49749
49749
  if (t3 && s3 !== t3.getTransferSyntaxUid()) try {
49750
- const n3 = G2.transcodeDataset(t3, s3, this.datasetTranscodeOptions);
49750
+ const n3 = G.transcodeDataset(t3, s3, this.datasetTranscodeOptions);
49751
49751
  e3.command.setDataset(n3);
49752
49752
  } catch (t4) {
49753
49753
  return z2.error(t4.message), void e3.command.raiseDoneEvent();
@@ -49954,7 +49954,7 @@ var require_dcmjs_dimse_min = __commonJS({
49954
49954
  this.socket.setTimeout(this.connectTimeout), this.socket.on("connect", () => {
49955
49955
  this.connected = true, this.connectedTime = Date.now(), this.emit("connect");
49956
49956
  });
49957
- const e3 = new H2();
49957
+ const e3 = new H3();
49958
49958
  e3.on("pdu", async (e4) => {
49959
49959
  this.lastPduTime = Date.now(), await this._processPdu(e4);
49960
49960
  }), e3.on("error", (e4) => {
@@ -67757,7 +67757,7 @@ function Bn(r7) {
67757
67757
  }
67758
67758
  function Er(r7) {
67759
67759
  let t = (Array.isArray(r7) ? r7 : r7.entry?.map((n) => n.resource) ?? []).filter((n) => n?.resourceType === "StructureDefinition");
67760
- Gn(t);
67760
+ Hn(t);
67761
67761
  for (let n of t) Rr(n);
67762
67762
  }
67763
67763
  function Rr(r7) {
@@ -67948,9 +67948,9 @@ function Bo(r7, e, t) {
67948
67948
  o2 = a.slice();
67949
67949
  for (let d = 0; d < a.length; d++) o2[d] = Mr(void 0, a[d]);
67950
67950
  } else o2 = Mr(o2, a);
67951
- if (!E(o2)) return (s === "Element" || s === "BackboneElement") && (s = t.type[0].code), Array.isArray(o2) ? o2.map((d) => Hn(d, s)) : Hn(o2, s);
67951
+ if (!E(o2)) return (s === "Element" || s === "BackboneElement") && (s = t.type[0].code), Array.isArray(o2) ? o2.map((d) => Gn(d, s)) : Gn(o2, s);
67952
67952
  }
67953
- function Hn(r7, e) {
67953
+ function Gn(r7, e) {
67954
67954
  return e === "Resource" && O(r7) && (e = r7.resourceType), { type: e, value: r7 };
67955
67955
  }
67956
67956
  function Wo(r7, e) {
@@ -67980,7 +67980,7 @@ function yt(r7) {
67980
67980
  let e = [];
67981
67981
  for (let t of r7) {
67982
67982
  let n = false;
67983
- for (let i of e) if (F(He(t, i))) {
67983
+ for (let i of e) if (F(Ge(t, i))) {
67984
67984
  n = true;
67985
67985
  break;
67986
67986
  }
@@ -67992,12 +67992,12 @@ function Kn(r7) {
67992
67992
  return m(!F(r7));
67993
67993
  }
67994
67994
  function Jn(r7, e) {
67995
- return r7.length === 0 || e.length === 0 ? [] : r7.length !== e.length ? m(false) : m(r7.every((t, n) => F(He(t, e[n]))));
67995
+ return r7.length === 0 || e.length === 0 ? [] : r7.length !== e.length ? m(false) : m(r7.every((t, n) => F(Ge(t, e[n]))));
67996
67996
  }
67997
67997
  function Xn(r7, e) {
67998
- return r7.length === 0 || e.length === 0 ? [] : r7.length !== e.length ? m(true) : m(r7.some((t, n) => !F(He(t, e[n]))));
67998
+ return r7.length === 0 || e.length === 0 ? [] : r7.length !== e.length ? m(true) : m(r7.some((t, n) => !F(Ge(t, e[n]))));
67999
67999
  }
68000
- function He(r7, e) {
68000
+ function Ge(r7, e) {
68001
68001
  let t = r7.value?.valueOf(), n = e.value?.valueOf();
68002
68002
  return typeof t == "number" && typeof n == "number" ? m(Math.abs(t - n) < 1e-8) : w(t) && w(n) ? m(ei(t, n)) : m(typeof t == "object" && typeof n == "object" ? Lr(r7, e) : t === n);
68003
68003
  }
@@ -68079,7 +68079,7 @@ function ze(r7, e) {
68079
68079
  return O(r7, e) && "id" in r7 && typeof r7.id == "string";
68080
68080
  }
68081
68081
  function xe(r7) {
68082
- let e = D(r7) ?? "undefined/undefined", t = Go(r7);
68082
+ let e = D(r7) ?? "undefined/undefined", t = Ho(r7);
68083
68083
  return t === e ? { reference: e } : { reference: e, display: t };
68084
68084
  }
68085
68085
  function D(r7) {
@@ -68092,9 +68092,9 @@ function Te(r7) {
68092
68092
  function $o(r7) {
68093
68093
  return r7.resourceType === "Patient" || r7.resourceType === "Practitioner" || r7.resourceType === "RelatedPerson";
68094
68094
  }
68095
- function Go(r7) {
68095
+ function Ho(r7) {
68096
68096
  if ($o(r7)) {
68097
- let e = Ho(r7);
68097
+ let e = Go(r7);
68098
68098
  if (e) return e;
68099
68099
  }
68100
68100
  if (r7.resourceType === "Device") {
@@ -68112,7 +68112,7 @@ function Go(r7) {
68112
68112
  }
68113
68113
  return D(r7) ?? "";
68114
68114
  }
68115
- function Ho(r7) {
68115
+ function Go(r7) {
68116
68116
  let e = r7.name;
68117
68117
  if (e && e.length > 0) return Ke(e[0]);
68118
68118
  }
@@ -68240,14 +68240,14 @@ function $r(r7, e, t) {
68240
68240
  function Et(r7) {
68241
68241
  return r7.sort((e, t) => e.localeCompare(t));
68242
68242
  }
68243
- function Gr(r7) {
68243
+ function Hr(r7) {
68244
68244
  return r7.endsWith("/") ? r7 : r7 + "/";
68245
68245
  }
68246
68246
  function cs(r7) {
68247
68247
  return r7.startsWith("/") ? r7.slice(1) : r7;
68248
68248
  }
68249
68249
  function $(r7, e) {
68250
- return new URL(cs(e), Gr(r7.toString())).toString();
68250
+ return new URL(cs(e), Hr(r7.toString())).toString();
68251
68251
  }
68252
68252
  function di(r7, e) {
68253
68253
  return $(r7, e).toString().replace("http://", "ws://").replace("https://", "wss://");
@@ -68284,8 +68284,8 @@ function mi(r7, e) {
68284
68284
  function Se(r7) {
68285
68285
  return typeof r7 == "string" ? r7 : void 0;
68286
68286
  }
68287
- var p = { 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", Expression: "Expression", Extension: "Extension", HumanName: "HumanName", Identifier: "Identifier", MarketingStatus: "MarketingStatus", Meta: "Meta", Money: "Money", 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", 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" };
68288
- function Gn(r7) {
68287
+ var p = { 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" };
68288
+ function Hn(r7) {
68289
68289
  let e = Array.isArray(r7) ? r7 : r7.entry?.map((t) => t.resource) ?? [];
68290
68290
  for (let t of e) t?.resourceType === "StructureDefinition" && t.kind === "resource" && xi(t.type);
68291
68291
  }
@@ -68459,7 +68459,7 @@ var I = { empty: (r7, e) => m(e.every((t) => E(t.value))), hasValue: (r7, e) =>
68459
68459
  return [{ type: p.Quantity, value: { value: u2[a], unit: a } }];
68460
68460
  }, is: (r7, e, t) => {
68461
68461
  let n = "";
68462
- return t instanceof G ? n = t.name : t instanceof pe && (n = t.left.name + "." + t.right.name), n ? e.map((i) => ({ type: p.boolean, value: gt(i, n) })) : [];
68462
+ return t instanceof H ? n = t.name : t instanceof pe && (n = t.left.name + "." + t.right.name), n ? e.map((i) => ({ type: p.boolean, value: gt(i, n) })) : [];
68463
68463
  }, not: (r7, e) => I.toBoolean(r7, e).map((t) => ({ type: p.boolean, value: !t.value })), resolve: (r7, e) => e.map((t) => {
68464
68464
  let n = t.value, i;
68465
68465
  if (typeof n == "string") i = n;
@@ -68489,7 +68489,7 @@ var I = { empty: (r7, e) => m(e.every((t) => E(t.value))), hasValue: (r7, e) =>
68489
68489
  let n = e[0].value;
68490
68490
  if (!n?.reference) return [];
68491
68491
  let i = "";
68492
- return t instanceof G && (i = t.name), i && !n.reference.startsWith(i + "/") ? [] : [{ type: p.id, value: Te(n) }];
68492
+ return t instanceof H && (i = t.name), i && !n.reference.startsWith(i + "/") ? [] : [{ type: p.id, value: Te(n) }];
68493
68493
  }, extension: (r7, e, t) => {
68494
68494
  let n = t.eval(r7, e)[0].value, i = e?.[0]?.value;
68495
68495
  if (i) {
@@ -68535,7 +68535,7 @@ var B = class {
68535
68535
  return typeof e == "string" ? `'${e}'` : e.toString();
68536
68536
  }
68537
68537
  };
68538
- var G = class {
68538
+ var H = class {
68539
68539
  constructor(e) {
68540
68540
  c(this, "name");
68541
68541
  this.name = e;
@@ -68630,7 +68630,7 @@ var At = class extends P {
68630
68630
  }
68631
68631
  eval(e, t) {
68632
68632
  let n = z(this.left.eval(e, t)), i = this.right.eval(e, t);
68633
- return n ? m(i.some((o2) => He(n, o2)[0].value)) : [];
68633
+ return n ? m(i.some((o2) => Ge(n, o2)[0].value)) : [];
68634
68634
  }
68635
68635
  };
68636
68636
  var pe = class extends oe {
@@ -68782,7 +68782,7 @@ var Os = { parse(r7, e) {
68782
68782
  return new Ce(e, t);
68783
68783
  }, precedence: x.Indexer };
68784
68784
  var Is = { parse(r7, e) {
68785
- if (!(e instanceof G)) throw new Error("Unexpected parentheses");
68785
+ if (!(e instanceof H)) throw new Error("Unexpected parentheses");
68786
68786
  let t = [];
68787
68787
  for (; !r7.match(")"); ) t.push(r7.consumeAndParse()), r7.match(",");
68788
68788
  return new re(e.name, t);
@@ -68792,7 +68792,7 @@ function ks(r7) {
68792
68792
  return n?.startsWith("'") && n.endsWith("'") ? n = n.substring(1, n.length - 1) : n = "{" + n + "}", { value: t, unit: n };
68793
68793
  }
68794
68794
  function Ye() {
68795
- return new at().registerPrefix("String", { parse: (r7, e) => new B({ type: p.string, value: e.value }) }).registerPrefix("DateTime", { parse: (r7, e) => new B({ type: p.dateTime, value: Ne(e.value) }) }).registerPrefix("Quantity", { parse: (r7, e) => new B({ type: p.Quantity, value: ks(e.value) }) }).registerPrefix("Number", { parse: (r7, e) => new B({ type: e.value.includes(".") ? p.decimal : p.integer, value: Number.parseFloat(e.value) }) }).registerPrefix("true", { parse: () => new B({ type: p.boolean, value: true }) }).registerPrefix("false", { parse: () => new B({ type: p.boolean, value: false }) }).registerPrefix("Symbol", { parse: (r7, e) => new G(e.value) }).registerPrefix("{}", { parse: () => new Rt() }).registerPrefix("(", As).registerInfix("[", Os).registerInfix("(", Is).prefix("+", x.UnaryAdd, (r7, e) => new Ct("+", e, (t) => t)).prefix("-", x.UnarySubtract, (r7, e) => new M("-", e, e, (t, n) => -n)).infixLeft(".", x.Dot, (r7, e, t) => new pe(r7, t)).infixLeft("/", x.Divide, (r7, e, t) => new M("/", r7, t, (n, i) => n / i)).infixLeft("*", x.Multiply, (r7, e, t) => new M("*", r7, t, (n, i) => n * i)).infixLeft("+", x.Add, (r7, e, t) => new M("+", r7, t, (n, i) => n + i)).infixLeft("-", x.Subtract, (r7, e, t) => new M("-", r7, t, (n, i) => n - i)).infixLeft("|", x.Union, (r7, e, t) => new Ee(r7, t)).infixLeft("=", x.Equals, (r7, e, t) => new Ot(r7, t)).infixLeft("!=", x.NotEquals, (r7, e, t) => new It(r7, t)).infixLeft("~", x.Equivalent, (r7, e, t) => new kt(r7, t)).infixLeft("!~", x.NotEquivalent, (r7, e, t) => new Vt(r7, t)).infixLeft("<", x.LessThan, (r7, e, t) => new M("<", r7, t, (n, i) => n < i)).infixLeft("<=", x.LessThanOrEquals, (r7, e, t) => new M("<=", r7, t, (n, i) => n <= i)).infixLeft(">", x.GreaterThan, (r7, e, t) => new M(">", r7, t, (n, i) => n > i)).infixLeft(">=", x.GreaterThanOrEquals, (r7, e, t) => new M(">=", r7, t, (n, i) => n >= i)).infixLeft("&", x.Ampersand, (r7, e, t) => new Pt(r7, t)).infixLeft("and", x.And, (r7, e, t) => new Dt(r7, t)).infixLeft("as", x.As, (r7, e, t) => new de(r7, t)).infixLeft("contains", x.Contains, (r7, e, t) => new wt(r7, t)).infixLeft("div", x.Divide, (r7, e, t) => new M("div", r7, t, (n, i) => n / i | 0)).infixLeft("in", x.In, (r7, e, t) => new At(r7, t)).infixLeft("is", x.Is, (r7, e, t) => new Re(r7, t)).infixLeft("mod", x.Modulo, (r7, e, t) => new M("mod", r7, t, (n, i) => n % i)).infixLeft("or", x.Or, (r7, e, t) => new Mt(r7, t)).infixLeft("xor", x.Xor, (r7, e, t) => new _t(r7, t)).infixLeft("implies", x.Implies, (r7, e, t) => new Lt(r7, t));
68795
+ return new at().registerPrefix("String", { parse: (r7, e) => new B({ type: p.string, value: e.value }) }).registerPrefix("DateTime", { parse: (r7, e) => new B({ type: p.dateTime, value: Ne(e.value) }) }).registerPrefix("Quantity", { parse: (r7, e) => new B({ type: p.Quantity, value: ks(e.value) }) }).registerPrefix("Number", { parse: (r7, e) => new B({ type: e.value.includes(".") ? p.decimal : p.integer, value: Number.parseFloat(e.value) }) }).registerPrefix("true", { parse: () => new B({ type: p.boolean, value: true }) }).registerPrefix("false", { parse: () => new B({ type: p.boolean, value: false }) }).registerPrefix("Symbol", { parse: (r7, e) => new H(e.value) }).registerPrefix("{}", { parse: () => new Rt() }).registerPrefix("(", As).registerInfix("[", Os).registerInfix("(", Is).prefix("+", x.UnaryAdd, (r7, e) => new Ct("+", e, (t) => t)).prefix("-", x.UnarySubtract, (r7, e) => new M("-", e, e, (t, n) => -n)).infixLeft(".", x.Dot, (r7, e, t) => new pe(r7, t)).infixLeft("/", x.Divide, (r7, e, t) => new M("/", r7, t, (n, i) => n / i)).infixLeft("*", x.Multiply, (r7, e, t) => new M("*", r7, t, (n, i) => n * i)).infixLeft("+", x.Add, (r7, e, t) => new M("+", r7, t, (n, i) => n + i)).infixLeft("-", x.Subtract, (r7, e, t) => new M("-", r7, t, (n, i) => n - i)).infixLeft("|", x.Union, (r7, e, t) => new Ee(r7, t)).infixLeft("=", x.Equals, (r7, e, t) => new Ot(r7, t)).infixLeft("!=", x.NotEquals, (r7, e, t) => new It(r7, t)).infixLeft("~", x.Equivalent, (r7, e, t) => new kt(r7, t)).infixLeft("!~", x.NotEquivalent, (r7, e, t) => new Vt(r7, t)).infixLeft("<", x.LessThan, (r7, e, t) => new M("<", r7, t, (n, i) => n < i)).infixLeft("<=", x.LessThanOrEquals, (r7, e, t) => new M("<=", r7, t, (n, i) => n <= i)).infixLeft(">", x.GreaterThan, (r7, e, t) => new M(">", r7, t, (n, i) => n > i)).infixLeft(">=", x.GreaterThanOrEquals, (r7, e, t) => new M(">=", r7, t, (n, i) => n >= i)).infixLeft("&", x.Ampersand, (r7, e, t) => new Pt(r7, t)).infixLeft("and", x.And, (r7, e, t) => new Dt(r7, t)).infixLeft("as", x.As, (r7, e, t) => new de(r7, t)).infixLeft("contains", x.Contains, (r7, e, t) => new wt(r7, t)).infixLeft("div", x.Divide, (r7, e, t) => new M("div", r7, t, (n, i) => Math.trunc(n / i))).infixLeft("in", x.In, (r7, e, t) => new At(r7, t)).infixLeft("is", x.Is, (r7, e, t) => new Re(r7, t)).infixLeft("mod", x.Modulo, (r7, e, t) => new M("mod", r7, t, (n, i) => n % i)).infixLeft("or", x.Or, (r7, e, t) => new Mt(r7, t)).infixLeft("xor", x.Xor, (r7, e, t) => new _t(r7, t)).infixLeft("implies", x.Implies, (r7, e, t) => new Lt(r7, t));
68796
68796
  }
68797
68797
  var Vs = Ye();
68798
68798
  var h = { 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" };
@@ -68852,7 +68852,7 @@ async function Vi(r7) {
68852
68852
  }
68853
68853
  function Ae() {
68854
68854
  return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replaceAll(/[xy]/g, (r7) => {
68855
- let e = Math.random() * 16 | 0;
68855
+ let e = Math.trunc(Math.random() * 16);
68856
68856
  return (r7 === "x" ? e : e & 3 | 8).toString(16);
68857
68857
  });
68858
68858
  }
@@ -69147,12 +69147,12 @@ function Ea() {
69147
69147
  function Ra(r7, e) {
69148
69148
  if (!r7) throw new Error(e);
69149
69149
  }
69150
- function Gt(r7) {
69150
+ function Ht(r7) {
69151
69151
  return new r7.constructor(r7.type, r7);
69152
69152
  }
69153
69153
  var Oe = { maxReconnectionDelay: 1e4, minReconnectionDelay: 1e3 + Math.random() * 4e3, minUptime: 5e3, reconnectionDelayGrowFactor: 1.3, connectionTimeout: 4e3, maxRetries: 1 / 0, maxEnqueuedMessages: 1 / 0, startClosed: false, debug: false };
69154
69154
  var ji = false;
69155
- var Ht = class r2 extends Y {
69155
+ var Gt = class r2 extends Y {
69156
69156
  constructor(t, n, i = {}) {
69157
69157
  qi || (Ea(), qi = true);
69158
69158
  super();
@@ -69176,16 +69176,16 @@ var Ht = class r2 extends Y {
69176
69176
  c(this, "_handleOpen", (t2) => {
69177
69177
  this._debug("open event");
69178
69178
  let { minUptime: n2 = Oe.minUptime } = this._options;
69179
- clearTimeout(this._connectTimeout), this._uptimeTimeout = setTimeout(() => this._acceptOpen(), n2), Ra(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(Gt(t2));
69179
+ clearTimeout(this._connectTimeout), this._uptimeTimeout = setTimeout(() => this._acceptOpen(), n2), Ra(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(Ht(t2));
69180
69180
  });
69181
69181
  c(this, "_handleMessage", (t2) => {
69182
- this._debug("message event"), this.onmessage && this.onmessage(t2), this.dispatchEvent(Gt(t2));
69182
+ this._debug("message event"), this.onmessage && this.onmessage(t2), this.dispatchEvent(Ht(t2));
69183
69183
  });
69184
69184
  c(this, "_handleError", (t2) => {
69185
- 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(Gt(t2)), this._connect();
69185
+ 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(Ht(t2)), this._connect();
69186
69186
  });
69187
69187
  c(this, "_handleClose", (t2) => {
69188
- this._debug("close event"), this._clearTimeouts(), this._shouldReconnect && this._connect(), this.onclose && this.onclose(t2), this.dispatchEvent(Gt(t2));
69188
+ this._debug("close event"), this._clearTimeouts(), this._shouldReconnect && this._connect(), this.onclose && this.onclose(t2), this.dispatchEvent(Ht(t2));
69189
69189
  });
69190
69190
  this._url = t, this._protocols = n, this._options = i, this._options.startClosed && (this._shouldReconnect = false), this._options.binaryType ? this._binaryType = this._options.binaryType : this._binaryType = "blob", this._options.debugLogger && (this._debugLogger = this._options.debugLogger), this._connect();
69191
69191
  }
@@ -69369,7 +69369,7 @@ var Qt = class {
69369
69369
  } catch {
69370
69370
  throw new f(g("Not a valid URL"));
69371
69371
  }
69372
- let o2 = n?.ReconnectingWebSocket ? new n.ReconnectingWebSocket(i, void 0, { debug: n?.debug, debugLogger: n?.debugLogger }) : new Ht(i, void 0, { debug: n?.debug, debugLogger: n?.debugLogger });
69372
+ let o2 = n?.ReconnectingWebSocket ? new n.ReconnectingWebSocket(i, void 0, { debug: n?.debug, debugLogger: n?.debugLogger }) : new Gt(i, void 0, { debug: n?.debug, debugLogger: n?.debugLogger });
69373
69373
  this.medplum = e, this.ws = o2, this.masterSubEmitter = new rt(), this.criteriaEntries = /* @__PURE__ */ new Map(), this.criteriaEntriesBySubscriptionId = /* @__PURE__ */ new Map(), this.wsClosed = false, this.pingIntervalMs = n?.pingIntervalMs ?? Ca, this.currentProfile = e.getProfile(), this.setupListeners();
69374
69374
  }
69375
69375
  setupListeners() {
@@ -69528,7 +69528,7 @@ var Qt = class {
69528
69528
  return this.masterSubEmitter || (this.masterSubEmitter = new rt(...Array.from(this.criteriaEntries.keys()))), this.masterSubEmitter;
69529
69529
  }
69530
69530
  };
69531
- var an = "5.0.4-8ba369a";
69531
+ var an = "5.0.5-4470a45";
69532
69532
  var Aa = A.FHIR_JSON + ", */*; q=0.1";
69533
69533
  var Oa = "https://api.medplum.com/";
69534
69534
  var Ia = 1e3;
@@ -69578,7 +69578,7 @@ var zt = class extends Y {
69578
69578
  c(this, "initComplete", true);
69579
69579
  c(this, "keyValueClient");
69580
69580
  if (t?.baseUrl && !t.baseUrl.startsWith("http")) throw new Error("Base URL must start with http or https");
69581
- this.options = t ?? {}, this.fetch = t?.fetch ?? Fa(), this.storage = t?.storage ?? new tt(void 0, t?.storagePrefix), this.createPdfImpl = t?.createPdf, this.baseUrl = Gr(t?.baseUrl ?? Oa), this.fhirBaseUrl = $(this.baseUrl, t?.fhirUrlPath ?? "fhir/R4"), this.authorizeUrl = $(this.baseUrl, t?.authorizeUrl ?? "oauth2/authorize"), this.tokenUrl = $(this.baseUrl, t?.tokenUrl ?? "oauth2/token"), this.logoutUrl = $(this.baseUrl, t?.logoutUrl ?? "oauth2/logout"), this.fhircastHubUrl = $(this.baseUrl, t?.fhircastHubUrl ?? "fhircast/STU3"), 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 ?? Da, this.cacheTime = t?.cacheTime ?? (W() ? ka : Va), this.cacheTime > 0 ? this.requestCache = new ke(t?.resourceCacheSize ?? Ia) : 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(() => {
69581
+ this.options = t ?? {}, this.fetch = t?.fetch ?? Fa(), this.storage = t?.storage ?? new tt(void 0, t?.storagePrefix), this.createPdfImpl = t?.createPdf, this.baseUrl = Hr(t?.baseUrl ?? Oa), this.fhirBaseUrl = $(this.baseUrl, t?.fhirUrlPath ?? "fhir/R4"), this.authorizeUrl = $(this.baseUrl, t?.authorizeUrl ?? "oauth2/authorize"), this.tokenUrl = $(this.baseUrl, t?.tokenUrl ?? "oauth2/token"), this.logoutUrl = $(this.baseUrl, t?.logoutUrl ?? "oauth2/logout"), this.fhircastHubUrl = $(this.baseUrl, t?.fhircastHubUrl ?? "fhircast/STU3"), 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 ?? Da, this.cacheTime = t?.cacheTime ?? (W() ? ka : Va), this.cacheTime > 0 ? this.requestCache = new ke(t?.resourceCacheSize ?? Ia) : 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(() => {
69582
69582
  t?.accessToken || this.attemptResumeActiveLogin().catch(console.error), this.initComplete = true, this.dispatchEvent({ type: "storageInitialized" });
69583
69583
  }).catch((n) => {
69584
69584
  console.error(n), this.initComplete = true, this.dispatchEvent({ type: "storageInitFailed", payload: { error: n } });
@@ -69726,7 +69726,7 @@ var zt = class extends Y {
69726
69726
  searchResources(t, n, i) {
69727
69727
  let s = "searchResources-" + this.fhirSearchUrl(t, n).toString(), a = this.getCacheEntry(s, i);
69728
69728
  if (a) return a.value;
69729
- let u2 = new _(this.search(t, n, i).then(Hi));
69729
+ let u2 = new _(this.search(t, n, i).then(Gi));
69730
69730
  return this.setCacheEntry(s, u2), u2;
69731
69731
  }
69732
69732
  async *searchResourcePages(t, n, i) {
@@ -69736,7 +69736,7 @@ var zt = class extends Y {
69736
69736
  s.has("_count") || s.set("_count", "1000");
69737
69737
  let a = await this.search(t, s, i), u2 = a.link?.find((l2) => l2.relation === "next");
69738
69738
  if (!a.entry?.length && !u2) break;
69739
- yield Hi(a), o2 = u2?.url ? new URL(u2.url) : void 0;
69739
+ yield Gi(a), o2 = u2?.url ? new URL(u2.url) : void 0;
69740
69740
  }
69741
69741
  }
69742
69742
  valueSetExpand(t, n) {
@@ -69869,22 +69869,22 @@ var zt = class extends Y {
69869
69869
  if (a.contentType === A.XML) {
69870
69870
  let d = a.data, y2;
69871
69871
  d instanceof Blob ? y2 = await new Promise((T2, q) => {
69872
- let H2 = new FileReader();
69873
- H2.onload = () => {
69874
- if (!H2.result) {
69872
+ let G = new FileReader();
69873
+ G.onload = () => {
69874
+ if (!G.result) {
69875
69875
  q(new Error("Failed to load file"));
69876
69876
  return;
69877
69877
  }
69878
- T2(H2.result);
69879
- }, H2.readAsText(d, "utf-8");
69878
+ T2(G.result);
69879
+ }, G.readAsText(d, "utf-8");
69880
69880
  }) : ArrayBuffer.isView(d) ? y2 = new TextDecoder().decode(d) : y2 = d, y2.includes("<ClinicalDocument") && y2.includes("urn:hl7-org:v3") && (a = { ...a, contentType: A.CDA_XML });
69881
69881
  }
69882
69882
  let u2 = s ?? (typeof n == "object" ? n : {}), l2 = await this.createBinary(a, u2);
69883
69883
  return { contentType: a.contentType, url: l2.url, title: a.filename };
69884
69884
  }
69885
69885
  createBinary(t, n, i, o2, s) {
69886
- let a = Qi(t, n, i, o2), u2 = s ?? (typeof n == "object" ? n : {}), { data: l2, contentType: d, filename: y2, securityContext: T2, onProgress: q } = a, H2 = this.fhirUrl("Binary");
69887
- return y2 && H2.searchParams.set("_filename", y2), T2?.reference && this.setRequestHeader(u2, "X-Security-Context", T2.reference), q ? this.uploadwithProgress(H2, l2, d, q, u2) : this.post(H2, l2, d, u2);
69886
+ let a = Qi(t, n, i, o2), u2 = s ?? (typeof n == "object" ? n : {}), { data: l2, contentType: d, filename: y2, securityContext: T2, onProgress: q } = a, G = this.fhirUrl("Binary");
69887
+ return y2 && G.searchParams.set("_filename", y2), T2?.reference && this.setRequestHeader(u2, "X-Security-Context", T2.reference), q ? this.uploadwithProgress(G, l2, d, q, u2) : this.post(G, l2, d, u2);
69888
69888
  }
69889
69889
  uploadwithProgress(t, n, i, o2, s) {
69890
69890
  return new Promise((a, u2) => {
@@ -69897,7 +69897,7 @@ var zt = class extends Y {
69897
69897
  l2.status >= 200 && l2.status < 300 ? y2(l2.response) : y2(new f(pt(l2.response || l2.statusText)));
69898
69898
  }, l2.open("POST", t), l2.withCredentials = true, l2.setRequestHeader("Authorization", "Bearer " + this.accessToken), l2.setRequestHeader("Cache-Control", "no-cache, no-store, max-age=0"), l2.setRequestHeader("Content-Type", i), this.options.extendedMode !== false && l2.setRequestHeader("X-Medplum", "extended"), s?.headers) {
69899
69899
  let T2 = s.headers;
69900
- for (let [q, H2] of Object.entries(T2)) l2.setRequestHeader(q, H2);
69900
+ for (let [q, G] of Object.entries(T2)) l2.setRequestHeader(q, G);
69901
69901
  }
69902
69902
  l2.send(n);
69903
69903
  });
@@ -69977,13 +69977,13 @@ var zt = class extends Y {
69977
69977
  n.push(t), this.storage.setObject("logins", n);
69978
69978
  }
69979
69979
  async refreshProfile() {
69980
- return this.medplumServer ? (this.profilePromise = new Promise((t, n) => {
69980
+ if (this.medplumServer) return this.profilePromise = new Promise((t, n) => {
69981
69981
  this.get("auth/me", { cache: "no-cache" }).then((i) => {
69982
69982
  this.profilePromise = void 0;
69983
69983
  let o2 = this.sessionDetails?.profile?.id !== i.profile.id;
69984
69984
  this.sessionDetails = i, o2 && this.dispatchEvent({ type: "change" }), t(i.profile), this.dispatchEvent({ type: "profileRefreshed" });
69985
69985
  }).catch(n);
69986
- }), this.dispatchEvent({ type: "profileRefreshing" }), this.profilePromise) : Promise.resolve(void 0);
69986
+ }), this.dispatchEvent({ type: "profileRefreshing" }), this.profilePromise;
69987
69987
  }
69988
69988
  isLoading() {
69989
69989
  return !this.isInitialized || !!this.profilePromise && !this.sessionDetails?.profile;
@@ -70076,11 +70076,11 @@ var zt = class extends Y {
70076
70076
  if (s.status === 404 && !u2) throw new f(An);
70077
70077
  let l2 = await this.parseBody(s, u2);
70078
70078
  if (s.status === 200 && i.followRedirectOnOk || s.status === 201 && i.followRedirectOnCreated) {
70079
- let d = await Gi(s, l2);
70079
+ let d = await Hi(s, l2);
70080
70080
  if (d) return this.request("GET", d, { ...i, body: void 0 });
70081
70081
  }
70082
70082
  if (s.status === 202 && i.pollStatusOnAccepted) {
70083
- let y2 = await Gi(s, l2) ?? o2.statusUrl;
70083
+ let y2 = await Hi(s, l2) ?? o2.statusUrl;
70084
70084
  if (y2) return this.pollStatus(y2, i, o2);
70085
70085
  }
70086
70086
  if (s.status >= 400) throw new f(pt(l2));
@@ -70185,8 +70185,9 @@ var zt = class extends Y {
70185
70185
  setRequestBody(t, n) {
70186
70186
  typeof n == "string" || typeof Blob < "u" && (n instanceof Blob || n?.constructor.name === "Blob") || typeof File < "u" && (n instanceof File || n?.constructor.name === "File") || typeof Uint8Array < "u" && (n instanceof Uint8Array || n?.constructor.name === "Uint8Array") ? t.body = n : n && (t.body = JSON.stringify(n));
70187
70187
  }
70188
- handleUnauthenticated(t, n, i) {
70189
- return this.refresh() ? this.request(t, n, i) : (this.clear(), this.onUnauthenticated && this.onUnauthenticated(), Promise.reject(new f(Ve)));
70188
+ async handleUnauthenticated(t, n, i) {
70189
+ if (this.refresh()) return this.request(t, n, i);
70190
+ throw this.clear(), this.onUnauthenticated?.(), new f(Ve);
70190
70191
  }
70191
70192
  async startPkce() {
70192
70193
  let t = Yr();
@@ -70269,7 +70270,7 @@ var zt = class extends Y {
70269
70270
  throw this.refreshPromise = void 0, u2;
70270
70271
  }
70271
70272
  if (!s.ok) {
70272
- this.clearActiveLogin();
70273
+ this.clearActiveLogin(), this.onUnauthenticated?.();
70273
70274
  try {
70274
70275
  let u2 = await s.json();
70275
70276
  throw new f(b(u2.error_description));
@@ -70323,14 +70324,14 @@ function Fa() {
70323
70324
  if (!globalThis.fetch) throw new Error("Fetch not available in this environment");
70324
70325
  return globalThis.fetch.bind(globalThis);
70325
70326
  }
70326
- async function Gi(r7, e) {
70327
+ async function Hi(r7, e) {
70327
70328
  let t = r7.headers.get("content-location");
70328
70329
  if (t) return t;
70329
70330
  let n = r7.headers.get("location");
70330
70331
  if (n) return n;
70331
70332
  if (lt(e) && e.issue?.[0]?.diagnostics) return e.issue[0].diagnostics;
70332
70333
  }
70333
- function Hi(r7) {
70334
+ function Gi(r7) {
70334
70335
  let e = r7.entry?.map((t) => t.resource) ?? [];
70335
70336
  return Object.assign(e, { bundle: r7 });
70336
70337
  }
@@ -70545,7 +70546,7 @@ var mo = class r6 {
70545
70546
  this.write(JSON.stringify({ level: Oc[e], timestamp: (/* @__PURE__ */ new Date()).toISOString(), msg: this.prefix ? `${this.prefix}${t}` : t, ...i, ...this.metadata }));
70546
70547
  }
70547
70548
  };
70548
- function Wh(r7) {
70549
+ function qh(r7) {
70549
70550
  let e = je[r7.toUpperCase()];
70550
70551
  if (e === void 0) throw new Error(`Invalid log level: ${r7}`);
70551
70552
  return e;
@@ -70598,7 +70599,7 @@ async function xn(r7, e, t) {
70598
70599
  function $c(r7) {
70599
70600
  return /^\d+\.\d+\.\d+(-[0-9a-z]{7})?$/.test(r7);
70600
70601
  }
70601
- async function lm(r7, e) {
70602
+ async function pm(r7, e) {
70602
70603
  if (!$c(e)) return false;
70603
70604
  try {
70604
70605
  await xn(r7, e);
@@ -70607,7 +70608,7 @@ async function lm(r7, e) {
70607
70608
  }
70608
70609
  return true;
70609
70610
  }
70610
- async function pm(r7) {
70611
+ async function dm(r7) {
70611
70612
  let e = await xn(r7);
70612
70613
  if (!e.tag_name.startsWith("v")) throw new Error(`Invalid release name found. Release tag '${e.tag_name}' did not start with 'v'`);
70613
70614
  return e.tag_name.slice(1);
@@ -70616,7 +70617,7 @@ async function pm(r7) {
70616
70617
  // src/main.ts
70617
70618
  var import_node_child_process3 = require("node:child_process");
70618
70619
  var import_node_fs7 = require("node:fs");
70619
- var import_node_path4 = __toESM(require("node:path"));
70620
+ var import_node_path5 = __toESM(require("node:path"));
70620
70621
 
70621
70622
  // src/agent-main.ts
70622
70623
  var import_node_fs5 = require("node:fs");
@@ -70657,11 +70658,11 @@ var h2 = class extends Event {
70657
70658
  super("close");
70658
70659
  }
70659
70660
  };
70660
- var H = { FIRST: "first", APPLICATION: "application" };
70661
- var y = "utf-8";
70661
+ var H2 = { FIRST: "first", APPLICATION: "application" };
70662
+ var w2 = "utf-8";
70662
70663
  var T = 60 * 1e3;
70663
70664
  var m2 = class extends u {
70664
- constructor(e, t = y, s = false, n = {}) {
70665
+ constructor(e, t = w2, s = false, n = {}) {
70665
70666
  super();
70666
70667
  o(this, "socket");
70667
70668
  o(this, "encoding");
@@ -70697,7 +70698,7 @@ var m2 = class extends u {
70697
70698
  return;
70698
70699
  }
70699
70700
  let p2 = c2.message.getSegment("MSA")?.getField(1)?.toString()?.toUpperCase();
70700
- p2 && (a.returnAck === H.APPLICATION && p2 === "CA" || (a.resolve(c2.message), this.pendingMessages.delete(r7)));
70701
+ p2 && (a.returnAck === H2.APPLICATION && p2 === "CA" || (a.resolve(c2.message), this.pendingMessages.delete(r7)));
70701
70702
  });
70702
70703
  }
70703
70704
  isClosed() {
@@ -70750,18 +70751,19 @@ var m2 = class extends u {
70750
70751
  let r7;
70751
70752
  t?.timeoutMs && (r7 = setTimeout(() => {
70752
70753
  this.pendingMessages.delete(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` }] }));
70753
- }, t.timeoutMs)), this.pendingMessages.set(c2, { message: e, resolve: s, reject: n, returnAck: t?.returnAck ?? H.APPLICATION, timer: r7 }), this.sendImpl(e);
70754
+ }, t.timeoutMs)), this.pendingMessages.set(c2, { message: e, resolve: s, reject: n, returnAck: t?.returnAck ?? H2.APPLICATION, timer: r7 }), this.sendImpl(e);
70754
70755
  });
70755
70756
  }
70756
70757
  async close() {
70757
- if (this.isClosed()) return Promise.resolve();
70758
- if (this.socket.end(), this.socket.destroy(), this.pendingMessages.size) {
70759
- for (let e of this.pendingMessages.values()) e.timer && clearTimeout(e.timer), e.reject(new f({ resourceType: "OperationOutcome", issue: [{ severity: "warning", code: "incomplete", details: { text: "Message was still pending when connection closed" } }] }));
70760
- this.dispatchEvent(new l(new f({ resourceType: "OperationOutcome", issue: [{ severity: "warning", code: "incomplete", details: { text: "Messages were still pending when connection closed" }, diagnostics: `Hl7Connection closed while ${this.pendingMessages.size} messages were pending` }] }))), this.pendingMessages.clear();
70758
+ if (!this.isClosed()) {
70759
+ if (this.socket.end(), this.socket.destroy(), this.pendingMessages.size) {
70760
+ for (let e of this.pendingMessages.values()) e.timer && clearTimeout(e.timer), e.reject(new f({ resourceType: "OperationOutcome", issue: [{ severity: "warning", code: "incomplete", details: { text: "Message was still pending when connection closed" } }] }));
70761
+ this.dispatchEvent(new l(new f({ resourceType: "OperationOutcome", issue: [{ severity: "warning", code: "incomplete", details: { text: "Messages were still pending when connection closed" }, diagnostics: `Hl7Connection closed while ${this.pendingMessages.size} messages were pending` }] }))), this.pendingMessages.clear();
70762
+ }
70763
+ await new Promise((e) => {
70764
+ this.socket.once("close", e);
70765
+ });
70761
70766
  }
70762
- return new Promise((e) => {
70763
- this.socket.once("close", e);
70764
- });
70765
70767
  }
70766
70768
  appendData(e) {
70767
70769
  this.chunks.push(e);
@@ -70770,7 +70772,7 @@ var m2 = class extends u {
70770
70772
  this.chunks = [];
70771
70773
  }
70772
70774
  setEncoding(e) {
70773
- this.encoding = e ?? y;
70775
+ this.encoding = e ?? w2;
70774
70776
  }
70775
70777
  getEncoding() {
70776
70778
  return this.encoding;
@@ -70791,7 +70793,7 @@ var m2 = class extends u {
70791
70793
  return this.pendingMessages.size;
70792
70794
  }
70793
70795
  };
70794
- var w2 = class extends u {
70796
+ var y = class extends u {
70795
70797
  constructor(e) {
70796
70798
  super();
70797
70799
  o(this, "options");
@@ -71791,7 +71793,7 @@ function shouldSendAppLevelAck(options) {
71791
71793
  }
71792
71794
 
71793
71795
  // src/enhanced-hl7-client.ts
71794
- var EnhancedHl7Client = class extends w2 {
71796
+ var EnhancedHl7Client = class extends y {
71795
71797
  constructor(options) {
71796
71798
  super(options);
71797
71799
  __publicField(this, "stats");
@@ -71869,7 +71871,7 @@ var Hl7ClientPool = class {
71869
71871
  }
71870
71872
  closeAndRemoveClient(client) {
71871
71873
  this.log.info(
71872
- `Closing client for remote 'mllp://${client.host}:${client.port}?encoding=${client.encoding ?? y}' and removing it from the pool...`
71874
+ `Closing client for remote 'mllp://${client.host}:${client.port}?encoding=${client.encoding ?? w2}' and removing it from the pool...`
71873
71875
  );
71874
71876
  this.removeClient(client);
71875
71877
  client.close().catch((err) => {
@@ -72064,7 +72066,7 @@ var Hl7ClientPool = class {
72064
72066
  };
72065
72067
 
72066
72068
  // src/logger.ts
72067
- var import_path = require("path");
72069
+ var import_node_path2 = require("node:path");
72068
72070
  var import_winston = __toESM(require_winston());
72069
72071
  var import_winston_daily_rotate_file = __toESM(require_winston_daily_rotate_file());
72070
72072
  var LoggerType = {
@@ -72149,7 +72151,7 @@ function parseLoggerConfigFromArgs(args) {
72149
72151
  let configValue;
72150
72152
  if (settingName === "logLevel") {
72151
72153
  try {
72152
- configValue = Wh(propVal);
72154
+ configValue = qh(propVal);
72153
72155
  } catch (err) {
72154
72156
  warnings.push(`Error while parsing ${propName}: ${De(err)}`);
72155
72157
  }
@@ -72215,7 +72217,7 @@ function createWinstonFromLoggerConfig(config, loggerType) {
72215
72217
  if (process.env.NODE_ENV !== "test") {
72216
72218
  const dailyRotateTransport = new import_winston.default.transports.DailyRotateFile({
72217
72219
  filename: `${loggerType === LoggerType.MAIN ? "medplum-agent-main" : "medplum-agent-channels"}-%DATE%.log`,
72218
- dirname: (0, import_path.normalize)(config.logDir),
72220
+ dirname: (0, import_node_path2.normalize)(config.logDir),
72219
72221
  maxSize: `${config.maxFileSizeMb}m`,
72220
72222
  maxFiles: config.filesToKeep,
72221
72223
  json: true
@@ -72320,7 +72322,7 @@ var WinstonWrapperLogger = class _WinstonWrapperLogger {
72320
72322
  // src/pid.ts
72321
72323
  var import_node_fs2 = __toESM(require("node:fs"));
72322
72324
  var import_node_os2 = require("node:os");
72323
- var import_node_path2 = __toESM(require("node:path"));
72325
+ var import_node_path3 = __toESM(require("node:path"));
72324
72326
  var import_node_process = __toESM(require("node:process"));
72325
72327
  var EXIT_SIGNALS = ["SIGINT", "SIGTERM", "SIGHUP"];
72326
72328
  var pidLogger = new mo((msg) => `[PID]: ${msg}`);
@@ -72342,9 +72344,9 @@ function getPidFilePath(appName) {
72342
72344
  switch ((0, import_node_os2.platform)()) {
72343
72345
  case "linux":
72344
72346
  case "darwin":
72345
- return import_node_path2.default.join((0, import_node_os2.tmpdir)(), "medplum-agent", `${appName}.pid`);
72347
+ return import_node_path3.default.join((0, import_node_os2.tmpdir)(), "medplum-agent", `${appName}.pid`);
72346
72348
  case "win32":
72347
- return import_node_path2.default.join("C:", "ProgramData", "MedplumAgent", "pids", `${appName}.pid`);
72349
+ return import_node_path3.default.join("C:", "ProgramData", "MedplumAgent", "pids", `${appName}.pid`);
72348
72350
  default:
72349
72351
  throw new Error("Invalid OS");
72350
72352
  }
@@ -72421,7 +72423,7 @@ function createPidFile(appName) {
72421
72423
  pidLogger.info("Stale PID file found. Overwriting...");
72422
72424
  import_node_fs2.default.unlinkSync(pidFilePath);
72423
72425
  }
72424
- ensureDirectoryExists(import_node_path2.default.dirname(pidFilePath));
72426
+ ensureDirectoryExists(import_node_path3.default.dirname(pidFilePath));
72425
72427
  import_node_fs2.default.writeFileSync(pidFilePath, pid.toString(), { flag: "wx" });
72426
72428
  pidLogger.info(`PID file created at: ${pidFilePath}`);
72427
72429
  pidFileApps.add(appName);
@@ -72463,14 +72465,14 @@ function registerAgentCleanup() {
72463
72465
  // src/upgrader-utils.ts
72464
72466
  var import_node_fs3 = require("node:fs");
72465
72467
  var import_node_os3 = require("node:os");
72466
- var import_node_path3 = require("node:path");
72468
+ var import_node_path4 = require("node:path");
72467
72469
  var import_node_stream = require("node:stream");
72468
- var UPGRADE_MANIFEST_PATH = (0, import_node_path3.resolve)(__dirname, "upgrade.json");
72469
- var UPGRADER_LOG_PATH = (0, import_node_path3.resolve)(
72470
+ var UPGRADE_MANIFEST_PATH = (0, import_node_path4.resolve)(__dirname, "upgrade.json");
72471
+ var UPGRADER_LOG_PATH = (0, import_node_path4.resolve)(
72470
72472
  __dirname,
72471
72473
  `upgrader-logs-${(/* @__PURE__ */ new Date()).toISOString().replaceAll(/:\s*/g, "-")}.txt`
72472
72474
  );
72473
- var RELEASES_PATH = (0, import_node_path3.resolve)(__dirname);
72475
+ var RELEASES_PATH = (0, import_node_path4.resolve)(__dirname);
72474
72476
  async function downloadRelease(version, path4) {
72475
72477
  const release = await xn("agent-upgrader", version);
72476
72478
  const downloadUrl = parseDownloadUrl(release, (0, import_node_os3.platform)());
@@ -72515,7 +72517,7 @@ function getReleaseBinPath(version) {
72515
72517
  default:
72516
72518
  throw new Error(`Unsupported platform: ${(0, import_node_os3.platform)()}`);
72517
72519
  }
72518
- return (0, import_node_path3.resolve)(RELEASES_PATH, binaryName);
72520
+ return (0, import_node_path4.resolve)(RELEASES_PATH, binaryName);
72519
72521
  }
72520
72522
 
72521
72523
  // src/app.ts
@@ -72652,7 +72654,7 @@ var _App = class _App {
72652
72654
  webSocketUrl.protocol = webSocketUrl.protocol === "https:" ? "wss:" : "ws:";
72653
72655
  webSocketUrl.pathname = "/ws/agent";
72654
72656
  this.log.info(`Connecting to WebSocket: ${webSocketUrl.href}`);
72655
- this.webSocket = new Ht(webSocketUrl.toString(), void 0, {
72657
+ this.webSocket = new Gt(webSocketUrl.toString(), void 0, {
72656
72658
  WebSocket: wrapper_default,
72657
72659
  binaryType: "nodebuffer"
72658
72660
  });
@@ -72826,7 +72828,7 @@ var _App = class _App {
72826
72828
  const pools = Array.from(this.hl7Clients.values());
72827
72829
  const clientStats = Object.fromEntries(
72828
72830
  pools.map((pool) => [
72829
- `mllp://${pool.host}:${pool.port}?encoding=${pool.encoding ?? y}`,
72831
+ `mllp://${pool.host}:${pool.port}?encoding=${pool.encoding ?? w2}`,
72830
72832
  pool.getPoolStats()
72831
72833
  ])
72832
72834
  );
@@ -73153,7 +73155,7 @@ ${result}`);
73153
73155
  return;
73154
73156
  }
73155
73157
  let child;
73156
- if (message.version && !await lm("agent-upgrader", message.version)) {
73158
+ if (message.version && !await pm("agent-upgrader", message.version)) {
73157
73159
  const versionTag = message.version ? `v${message.version}` : "latest";
73158
73160
  const errMsg = `Error during upgrading to version '${versionTag}'. '${message.version}' is not a valid version`;
73159
73161
  this.log.error(errMsg);
@@ -73164,7 +73166,7 @@ ${result}`);
73164
73166
  });
73165
73167
  return;
73166
73168
  }
73167
- const targetVersion = message.version ?? await pm("agent-upgrader");
73169
+ const targetVersion = message.version ?? await dm("agent-upgrader");
73168
73170
  if (an.startsWith(targetVersion)) {
73169
73171
  if (!message?.force) {
73170
73172
  this.log.info(`Attempted to upgrade to version ${targetVersion}, but agent is already on that version`);
@@ -73452,7 +73454,7 @@ async function agentMain(argv) {
73452
73454
  for (const warning of warnings) {
73453
73455
  mainLogger.warn(warning);
73454
73456
  }
73455
- const app = new App(medplum, agentId, args.logLevel ? Wh(args.logLevel) : void 0, {
73457
+ const app = new App(medplum, agentId, args.logLevel ? qh(args.logLevel) : void 0, {
73456
73458
  mainLogger,
73457
73459
  channelLogger
73458
73460
  });
@@ -73497,7 +73499,7 @@ async function upgraderMain(argv) {
73497
73499
  if (argv[3] && !$c(argv[3])) {
73498
73500
  throw new Error("Invalid version specified");
73499
73501
  }
73500
- const version = argv[3] ?? await pm("agent-upgrader");
73502
+ const version = argv[3] ?? await dm("agent-upgrader");
73501
73503
  const binPath = getReleaseBinPath(version);
73502
73504
  if (!(0, import_node_fs6.existsSync)(binPath)) {
73503
73505
  globalLogger.info(`Could not find binary at "${binPath}". Downloading release from GitHub...`);
@@ -73536,8 +73538,8 @@ async function upgraderMain(argv) {
73536
73538
  }
73537
73539
 
73538
73540
  // src/main.ts
73539
- var TEMP_LOG_FILE = import_node_path4.default.join(
73540
- (0, import_node_path4.dirname)(UPGRADE_MANIFEST_PATH),
73541
+ var TEMP_LOG_FILE = import_node_path5.default.join(
73542
+ (0, import_node_path5.dirname)(UPGRADE_MANIFEST_PATH),
73541
73543
  `stop-service-logs-${(/* @__PURE__ */ new Date()).toISOString().replaceAll(/:\s*/g, "-")}.txt`
73542
73544
  );
73543
73545
  async function main(argv) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@medplum/agent",
3
- "version": "5.0.4",
3
+ "version": "5.0.5",
4
4
  "description": "Medplum Agent",
5
5
  "homepage": "https://www.medplum.com/",
6
6
  "bugs": {
@@ -26,8 +26,8 @@
26
26
  "test": "jest --runInBand"
27
27
  },
28
28
  "dependencies": {
29
- "@medplum/core": "5.0.4",
30
- "@medplum/hl7": "5.0.4",
29
+ "@medplum/core": "5.0.5",
30
+ "@medplum/hl7": "5.0.5",
31
31
  "dcmjs-dimse": "0.3.1",
32
32
  "iconv-lite": "0.7.0",
33
33
  "semver": "7.7.3",
@@ -36,8 +36,8 @@
36
36
  "ws": "8.18.3"
37
37
  },
38
38
  "devDependencies": {
39
- "@medplum/fhirtypes": "5.0.4",
40
- "@medplum/mock": "5.0.4",
39
+ "@medplum/fhirtypes": "5.0.5",
40
+ "@medplum/mock": "5.0.5",
41
41
  "@types/async-eventemitter": "0.2.4",
42
42
  "@types/ws": "8.18.1",
43
43
  "mock-socket": "9.3.1",