@medplum/agent 3.0.12 → 3.1.0

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 +174 -185
  2. package/package.json +5 -5
@@ -8841,7 +8841,7 @@ var require_dcmjs = __commonJS({
8841
8841
  }
8842
8842
  }, {
8843
8843
  key: "is",
8844
- value: function is2(t) {
8844
+ value: function is(t) {
8845
8845
  return this.value == t;
8846
8846
  }
8847
8847
  }, {
@@ -9673,17 +9673,17 @@ var require_dcmjs = __commonJS({
9673
9673
  key: "readBytes",
9674
9674
  value: function readBytes(stream, length2) {
9675
9675
  var BACKSLASH = String.fromCharCode(VM_DELIMITER);
9676
- var is2 = stream.readAsciiString(length2).trim();
9677
- is2 = is2.replace(/[^0-9.\\\-+e]/gi, "");
9678
- if (is2.indexOf(BACKSLASH) !== -1) {
9679
- var integerStringArray = is2.split(BACKSLASH);
9680
- is2 = integerStringArray.map(function(is3) {
9681
- return is3 === "" ? null : Number(is3);
9676
+ var is = stream.readAsciiString(length2).trim();
9677
+ is = is.replace(/[^0-9.\\\-+e]/gi, "");
9678
+ if (is.indexOf(BACKSLASH) !== -1) {
9679
+ var integerStringArray = is.split(BACKSLASH);
9680
+ is = integerStringArray.map(function(is2) {
9681
+ return is2 === "" ? null : Number(is2);
9682
9682
  });
9683
9683
  } else {
9684
- is2 = [is2 === "" ? null : Number(is2)];
9684
+ is = [is === "" ? null : Number(is)];
9685
9685
  }
9686
- return is2;
9686
+ return is;
9687
9687
  }
9688
9688
  }, {
9689
9689
  key: "formatValue",
@@ -9694,8 +9694,8 @@ var require_dcmjs = __commonJS({
9694
9694
  key: "writeBytes",
9695
9695
  value: function writeBytes(stream, value, writeOptions) {
9696
9696
  var _this12 = this;
9697
- var val = Array.isArray(value) ? value.map(function(is2) {
9698
- return _this12.formatValue(is2);
9697
+ var val = Array.isArray(value) ? value.map(function(is) {
9698
+ return _this12.formatValue(is);
9699
9699
  }) : [this.formatValue(value)];
9700
9700
  return _get(_getPrototypeOf(IntegerString2.prototype), "writeBytes", this).call(this, stream, val, writeOptions);
9701
9701
  }
@@ -39328,7 +39328,7 @@ var Le = class {
39328
39328
  return `${this.operator}(${this.child.toString()})`;
39329
39329
  }
39330
39330
  };
39331
- var Q = class {
39331
+ var G = class {
39332
39332
  constructor(e, t, n) {
39333
39333
  this.operator = e;
39334
39334
  this.left = t;
@@ -39477,12 +39477,12 @@ function Ut(r4) {
39477
39477
  let e;
39478
39478
  return r4 ? (e = jr[r4], e || (e = jr[r4] = /* @__PURE__ */ Object.create(null))) : e = Re, e;
39479
39479
  }
39480
- function Ht(r4, e) {
39480
+ function Wt(r4, e) {
39481
39481
  let t = Array.isArray(r4) ? r4 : r4.entry?.map((n) => n.resource) ?? [];
39482
39482
  for (let n of t)
39483
- Gt(n, e);
39483
+ Ht(n, e);
39484
39484
  }
39485
- function Gt(r4, e) {
39485
+ function Ht(r4, e) {
39486
39486
  if (!r4?.name)
39487
39487
  throw new Error("Failed loading StructureDefinition from bundle");
39488
39488
  if (r4.resourceType !== "StructureDefinition")
@@ -39492,10 +39492,10 @@ function Gt(r4, e) {
39492
39492
  for (let i2 of t.innerTypes)
39493
39493
  i2.parentType = t, n[i2.name] = i2;
39494
39494
  }
39495
- function Wr(r4) {
39495
+ function Qr(r4) {
39496
39496
  return !!Re[r4];
39497
39497
  }
39498
- function Ce(r4, e) {
39498
+ function Pe(r4, e) {
39499
39499
  let t = Ut(e)[r4];
39500
39500
  return !t && e && (t = Ut()[r4]), t;
39501
39501
  }
@@ -39561,8 +39561,8 @@ var Bt = class {
39561
39561
  this.innerTypes.push(this.backboneContext.type), this.backboneContext = this.backboneContext.parent;
39562
39562
  while (this.backboneContext && !pe(this.backboneContext.path, e?.path));
39563
39563
  else
39564
- this.innerTypes.push(this.backboneContext.type), delete this.backboneContext;
39565
- this.slicingContext && !pe(this.slicingContext.path, e?.path) && (this.slicingContext?.current && this.slicingContext.field.slices.push(this.slicingContext.current), delete this.slicingContext);
39564
+ this.innerTypes.push(this.backboneContext.type), this.backboneContext = void 0;
39565
+ this.slicingContext && !pe(this.slicingContext.path, e?.path) && (this.slicingContext?.current && this.slicingContext.field.slices.push(this.slicingContext.current), this.slicingContext = void 0);
39566
39566
  }
39567
39567
  next() {
39568
39568
  let e = this.peek();
@@ -39573,8 +39573,8 @@ var Bt = class {
39573
39573
  let e = this.elements[this.index];
39574
39574
  if (e) {
39575
39575
  if (this.elementIndex[e.path ?? ""] = e, e.contentReference) {
39576
- let t = this.elementIndex[e.contentReference.slice(e.contentReference.indexOf("#") + 1)];
39577
- return t ? { ...t, id: e.id, path: e.path, min: e.min ?? t.min, max: e.max ?? t.max, contentReference: e.contentReference, definition: e.definition } : void 0;
39576
+ let t = e.contentReference.slice(e.contentReference.indexOf("#") + 1), n = this.elementIndex[t];
39577
+ return n ? { ...n, id: e.id, path: e.path, min: e.min ?? n.min, max: e.max ?? n.max, base: n.base ?? { path: t, min: n.min, max: n.max }, contentReference: e.contentReference, definition: e.definition } : void 0;
39578
39578
  }
39579
39579
  return e;
39580
39580
  }
@@ -39591,15 +39591,15 @@ var Bt = class {
39591
39591
  parseElementDefinitionType(e) {
39592
39592
  return (e.type ?? []).map((t) => {
39593
39593
  let n;
39594
- return (t.code === "BackboneElement" || t.code === "Element") && (n = qt(e)), n || (n = Qt(t, "http://hl7.org/fhir/StructureDefinition/structuredefinition-fhir-type")?.valueUrl), n || (n = t.code ?? ""), { code: n, targetProfile: t.targetProfile, profile: t.profile };
39594
+ return (t.code === "BackboneElement" || t.code === "Element") && (n = qt(e)), n || (n = Gt(t, "http://hl7.org/fhir/StructureDefinition/structuredefinition-fhir-type")?.valueUrl), n || (n = t.code ?? ""), { code: n, targetProfile: t.targetProfile, profile: t.profile };
39595
39595
  });
39596
39596
  }
39597
39597
  parseElementDefinition(e) {
39598
- let t = Hr(e.max), n = e.base?.max ? Hr(e.base.max) : t, i2 = { type: "ElementDefinition", value: e };
39599
- return { description: e.definition || "", path: e.path || e.base?.path || "", min: e.min ?? 0, max: t, isArray: n > 1, constraints: (e.constraint ?? []).map((o) => ({ key: o.key ?? "", severity: o.severity ?? "error", expression: o.expression ?? "", description: o.human ?? "" })), type: this.parseElementDefinitionType(e), fixed: Gr(w(i2, "fixed[x]")), pattern: Gr(w(i2, "pattern[x]")), binding: e.binding };
39598
+ let t = Wr(e.max), n = e.base?.max ? Wr(e.base.max) : t, i2 = { type: "ElementDefinition", value: e };
39599
+ return { description: e.definition || "", path: e.path || e.base?.path || "", min: e.min ?? 0, max: t, isArray: n > 1, constraints: (e.constraint ?? []).map((o) => ({ key: o.key ?? "", severity: o.severity ?? "error", expression: o.expression ?? "", description: o.human ?? "" })), type: this.parseElementDefinitionType(e), fixed: Hr(A(i2, "fixed[x]")), pattern: Hr(A(i2, "pattern[x]")), binding: e.binding };
39600
39600
  }
39601
39601
  };
39602
- function Hr(r4) {
39602
+ function Wr(r4) {
39603
39603
  return r4 === "*" ? Number.POSITIVE_INFINITY : Number.parseInt(r4, 10);
39604
39604
  }
39605
39605
  function Lt(r4, e = "") {
@@ -39611,7 +39611,7 @@ function Si(r4, e) {
39611
39611
  function pe(r4, e) {
39612
39612
  return !r4 || !e ? false : e.startsWith(r4 + ".") || e === r4;
39613
39613
  }
39614
- function Gr(r4) {
39614
+ function Hr(r4) {
39615
39615
  return Array.isArray(r4) && r4.length > 0 ? r4[0] : S(r4) ? void 0 : r4;
39616
39616
  }
39617
39617
  function Ei(r4) {
@@ -39622,7 +39622,7 @@ function bi(r4) {
39622
39622
  let e = r4.description;
39623
39623
  return e?.startsWith(`Base StructureDefinition for ${r4.name} Type: `) && (e = e.substring(`Base StructureDefinition for ${r4.name} Type: `.length)), e;
39624
39624
  }
39625
- var Ge = { base64Binary: /^([A-Za-z\d+/]{4})*([A-Za-z\d+/]{2}==|[A-Za-z\d+/]{3}=)?$/, 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: /^[\s\S]+$/, oid: /^urn:oid:[0-2](\.(0|[1-9]\d*))+$/, string: /^[\s\S]+$/, 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: /.*/ };
39625
+ var He = { base64Binary: /^([A-Za-z\d+/]{4})*([A-Za-z\d+/]{2}==|[A-Za-z\d+/]{3}=)?$/, 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: /^[\s\S]+$/, oid: /^urn:oid:[0-2](\.(0|[1-9]\d*))+$/, string: /^[\s\S]+$/, 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: /.*/ };
39626
39626
  function f(r4) {
39627
39627
  return [{ type: l.boolean, value: r4 }];
39628
39628
  }
@@ -39639,13 +39639,13 @@ function L(r4, e) {
39639
39639
  throw new Error(`Expected singleton of type ${e}, but found ${JSON.stringify(r4)}`);
39640
39640
  }
39641
39641
  }
39642
- function w(r4, e, t) {
39642
+ function A(r4, e, t) {
39643
39643
  if (!r4.value)
39644
39644
  return;
39645
39645
  let n = Ye(r4.type, e, t?.profileUrl);
39646
- return n ? Oi(r4, e, n) : Ii(r4, e);
39646
+ return n ? ki(r4, e, n) : Vi(r4, e);
39647
39647
  }
39648
- function Oi(r4, e, t) {
39648
+ function ki(r4, e, t) {
39649
39649
  let n = r4.value, i2 = t.type;
39650
39650
  if (!i2 || i2.length === 0)
39651
39651
  return;
@@ -39653,7 +39653,7 @@ function Oi(r4, e, t) {
39653
39653
  if (t.path.endsWith("[x]")) {
39654
39654
  let c2 = t.path.split(".").pop().replace("[x]", "");
39655
39655
  for (let u2 of i2) {
39656
- let p2 = c2 + P(u2.code);
39656
+ let p2 = c2 + C(u2.code);
39657
39657
  if (o = n[p2], a = n["_" + p2], o !== void 0 || a !== void 0) {
39658
39658
  s = u2.code;
39659
39659
  break;
@@ -39674,7 +39674,7 @@ function Oi(r4, e, t) {
39674
39674
  function Xr(r4, e) {
39675
39675
  return e === "Resource" && _(r4) && (e = r4.resourceType), { type: e, value: r4 };
39676
39676
  }
39677
- function Ii(r4, e) {
39677
+ function Vi(r4, e) {
39678
39678
  let t = r4.value;
39679
39679
  if (!t || typeof t != "object")
39680
39680
  return;
@@ -39683,7 +39683,7 @@ function Ii(r4, e) {
39683
39683
  n = t[e];
39684
39684
  else
39685
39685
  for (let i2 in l) {
39686
- let o = e + P(i2);
39686
+ let o = e + C(i2);
39687
39687
  if (o in t) {
39688
39688
  n = t[o];
39689
39689
  break;
@@ -39716,9 +39716,9 @@ function on(r4, e) {
39716
39716
  return typeof t == "number" && typeof n == "number" ? f(Math.abs(t - n) < 1e-8) : O(t) && O(n) ? f(cn(t, n)) : f(typeof t == "object" && typeof n == "object" ? rr(r4, e) : t === n);
39717
39717
  }
39718
39718
  function tr(r4, e) {
39719
- return r4.length === 0 && e.length === 0 ? f(true) : r4.length !== e.length ? f(false) : (r4.sort(en), e.sort(en), f(r4.every((t, n) => F(ki(t, e[n])))));
39719
+ return r4.length === 0 && e.length === 0 ? f(true) : r4.length !== e.length ? f(false) : (r4.sort(en), e.sort(en), f(r4.every((t, n) => F(Di(t, e[n])))));
39720
39720
  }
39721
- function ki(r4, e) {
39721
+ function Di(r4, e) {
39722
39722
  let { type: t, value: n } = r4, { type: i2, value: o } = e, s = n?.valueOf(), a = o?.valueOf();
39723
39723
  return typeof s == "number" && typeof a == "number" ? f(Math.abs(s - a) < 0.01) : O(s) && O(a) ? f(cn(s, a)) : f(t === "Coding" && i2 === "Coding" ? typeof s != "object" || typeof a != "object" ? false : s.code === a.code && s.system === a.system : typeof s == "object" && typeof a == "object" ? rr({ ...s, id: void 0 }, { ...a, id: void 0 }) : typeof s == "string" && typeof a == "string" ? s.toLowerCase() === a.toLowerCase() : s === a);
39724
39724
  }
@@ -39751,10 +39751,10 @@ function Je(r4, e) {
39751
39751
  }
39752
39752
  }
39753
39753
  function sn(r4) {
39754
- return typeof r4 == "string" && !!Ge.date.exec(r4);
39754
+ return typeof r4 == "string" && !!He.date.exec(r4);
39755
39755
  }
39756
39756
  function Ke(r4) {
39757
- return typeof r4 == "string" && !!Ge.dateTime.exec(r4);
39757
+ return typeof r4 == "string" && !!He.dateTime.exec(r4);
39758
39758
  }
39759
39759
  function an(r4) {
39760
39760
  return !!(r4 && typeof r4 == "object" && ("start" in r4 && Ke(r4.start) || "end" in r4 && Ke(r4.end)));
@@ -39786,15 +39786,15 @@ function nn(r4, e) {
39786
39786
  if (e) {
39787
39787
  if (typeof e != "object")
39788
39788
  throw new Error("Primitive extension must be an object");
39789
- return Vi(r4 ?? {}, e);
39789
+ return Mi(r4 ?? {}, e);
39790
39790
  }
39791
39791
  return r4;
39792
39792
  }
39793
- function Vi(r4, e) {
39793
+ function Mi(r4, e) {
39794
39794
  return delete e.__proto__, delete e.constructor, Object.assign(r4, e);
39795
39795
  }
39796
- function W(r4) {
39797
- let e = X(r4), t = Mi(r4);
39796
+ function Q(r4) {
39797
+ let e = X(r4), t = Fi(r4);
39798
39798
  return t === e ? { reference: e } : { reference: e, display: t };
39799
39799
  }
39800
39800
  function X(r4) {
@@ -39804,17 +39804,17 @@ function Xe(r4) {
39804
39804
  if (r4)
39805
39805
  return Z(r4) ? r4.reference.split("/")[1] : r4.id;
39806
39806
  }
39807
- function Di(r4) {
39807
+ function Ni(r4) {
39808
39808
  return r4.resourceType === "Patient" || r4.resourceType === "Practitioner" || r4.resourceType === "RelatedPerson";
39809
39809
  }
39810
- function Mi(r4) {
39811
- if (Di(r4)) {
39812
- let e = Ni(r4);
39810
+ function Fi(r4) {
39811
+ if (Ni(r4)) {
39812
+ let e = _i(r4);
39813
39813
  if (e)
39814
39814
  return e;
39815
39815
  }
39816
39816
  if (r4.resourceType === "Device") {
39817
- let e = Fi(r4);
39817
+ let e = Li(r4);
39818
39818
  if (e)
39819
39819
  return e;
39820
39820
  }
@@ -39829,19 +39829,19 @@ function Mi(r4) {
39829
39829
  return r4.name;
39830
39830
  if ("code" in r4 && r4.code) {
39831
39831
  let e = r4.code;
39832
- if (Array.isArray(e) && (e = e[0]), Gi(e))
39832
+ if (Array.isArray(e) && (e = e[0]), Qi(e))
39833
39833
  return Ze(e);
39834
- if (Qi(e))
39834
+ if (Ki(e))
39835
39835
  return e.text;
39836
39836
  }
39837
39837
  return X(r4);
39838
39838
  }
39839
- function Ni(r4) {
39839
+ function _i(r4) {
39840
39840
  let e = r4.name;
39841
39841
  if (e && e.length > 0)
39842
39842
  return tt(e[0]);
39843
39843
  }
39844
- function Fi(r4) {
39844
+ function Li(r4) {
39845
39845
  let e = r4.deviceName;
39846
39846
  if (e && e.length > 0)
39847
39847
  return e[0].name;
@@ -39858,28 +39858,28 @@ function et(r4, e) {
39858
39858
  let g2 = Math.floor((n.getTime() - t.getTime()) / (1e3 * 60 * 60 * 24));
39859
39859
  return { years: p2, months: y, days: g2 };
39860
39860
  }
39861
- function Qt(r4, ...e) {
39861
+ function Gt(r4, ...e) {
39862
39862
  let t = r4;
39863
39863
  for (let n = 0; n < e.length && t; n++)
39864
39864
  t = t?.extension?.find((i2) => i2.url === e[n]);
39865
39865
  return t;
39866
39866
  }
39867
39867
  function dn(r4, e) {
39868
- return JSON.stringify(r4, _i, e ? 2 : void 0);
39868
+ return JSON.stringify(r4, Ui, e ? 2 : void 0);
39869
39869
  }
39870
- function _i(r4, e) {
39871
- return !Li(r4) && S(e) ? void 0 : e;
39870
+ function Ui(r4, e) {
39871
+ return !Bi(r4) && S(e) ? void 0 : e;
39872
39872
  }
39873
- function Li(r4) {
39873
+ function Bi(r4) {
39874
39874
  return !!/\d+$/.exec(r4);
39875
39875
  }
39876
39876
  function S(r4) {
39877
39877
  if (r4 == null)
39878
39878
  return true;
39879
39879
  let e = typeof r4;
39880
- return e === "string" || e === "object" ? !H(r4) : false;
39880
+ return e === "string" || e === "object" ? !W(r4) : false;
39881
39881
  }
39882
- function H(r4) {
39882
+ function W(r4) {
39883
39883
  if (r4 == null)
39884
39884
  return false;
39885
39885
  let e = typeof r4;
@@ -39889,18 +39889,18 @@ function b(r4) {
39889
39889
  return r4 !== null && typeof r4 == "object";
39890
39890
  }
39891
39891
  function fn(r4) {
39892
- return r4.every($i);
39893
- }
39894
- function $i(r4) {
39895
- return typeof r4 == "string";
39892
+ return r4.every(Hi);
39896
39893
  }
39897
39894
  function Hi(r4) {
39898
- return b(r4) && "code" in r4 && typeof r4.code == "string";
39895
+ return typeof r4 == "string";
39899
39896
  }
39900
39897
  function Gi(r4) {
39901
- return b(r4) && "coding" in r4 && Array.isArray(r4.coding) && r4.coding.every(Hi);
39898
+ return b(r4) && "code" in r4 && typeof r4.code == "string";
39902
39899
  }
39903
39900
  function Qi(r4) {
39901
+ return b(r4) && "coding" in r4 && Array.isArray(r4.coding) && r4.coding.every(Gi);
39902
+ }
39903
+ function Ki(r4) {
39904
39904
  return b(r4) && "text" in r4 && typeof r4.text == "string";
39905
39905
  }
39906
39906
  var mn = [];
@@ -39918,7 +39918,7 @@ function yn(r4) {
39918
39918
  t[n] = String.fromCharCode(e[n]);
39919
39919
  return window.btoa(t.join(""));
39920
39920
  }
39921
- function P(r4) {
39921
+ function C(r4) {
39922
39922
  return r4 ? r4.charAt(0).toUpperCase() + r4.substring(1) : "";
39923
39923
  }
39924
39924
  var or = (r4) => new Promise((e) => {
@@ -39940,9 +39940,9 @@ function Ze(r4) {
39940
39940
  if (!r4)
39941
39941
  return "";
39942
39942
  let e = he(r4.text);
39943
- return e || (r4.coding ? r4.coding.map((t) => no(t)).join(", ") : "");
39943
+ return e || (r4.coding ? r4.coding.map((t) => oo(t)).join(", ") : "");
39944
39944
  }
39945
- function no(r4) {
39945
+ function oo(r4) {
39946
39946
  return he(r4?.display) ?? he(r4?.code) ?? "";
39947
39947
  }
39948
39948
  function he(r4) {
@@ -39957,17 +39957,17 @@ function cr(r4) {
39957
39957
  }
39958
39958
  function qt(r4) {
39959
39959
  let e = r4.type?.[0]?.code;
39960
- return e === "BackboneElement" || e === "Element" ? ao((r4.base?.path ?? r4.path)?.split(".")) : e;
39960
+ return e === "BackboneElement" || e === "Element" ? uo((r4.base?.path ?? r4.path)?.split(".")) : e;
39961
39961
  }
39962
- function ao(r4) {
39963
- return r4.length === 1 ? r4[0] : r4.map(P).join("");
39962
+ function uo(r4) {
39963
+ return r4.length === 1 ? r4[0] : r4.map(C).join("");
39964
39964
  }
39965
39965
  function Ye(r4, e, t) {
39966
- let n = Ce(r4, t);
39966
+ let n = Pe(r4, t);
39967
39967
  if (n)
39968
- return po(n.elements, e);
39968
+ return mo(n.elements, e);
39969
39969
  }
39970
- function po(r4, e) {
39970
+ function mo(r4, e) {
39971
39971
  let t = r4[e] ?? r4[e + "[x]"];
39972
39972
  if (t)
39973
39973
  return t;
@@ -39999,7 +39999,7 @@ function ye(r4) {
39999
39999
  }
40000
40000
  }
40001
40001
  var we = () => [];
40002
- var A = { empty: (r4, e) => f(e.length === 0 || e.every((t) => S(t.value))), hasValue: (r4, e) => f(e.length !== 0), exists: (r4, e, t) => t ? f(e.filter((n) => F(t.eval(r4, [n]))).length > 0) : f(e.length > 0 && e.every((n) => !S(n.value))), all: (r4, e, t) => f(e.every((n) => F(t.eval(r4, [n])))), allTrue: (r4, e) => {
40002
+ var w = { empty: (r4, e) => f(e.length === 0 || e.every((t) => S(t.value))), hasValue: (r4, e) => f(e.length !== 0), exists: (r4, e, t) => t ? f(e.filter((n) => F(t.eval(r4, [n]))).length > 0) : f(e.length > 0 && e.every((n) => !S(n.value))), all: (r4, e, t) => f(e.every((n) => F(t.eval(r4, [n])))), allTrue: (r4, e) => {
40003
40003
  for (let t of e)
40004
40004
  if (!t.value)
40005
40005
  return f(false);
@@ -40024,7 +40024,7 @@ var A = { empty: (r4, e) => f(e.length === 0 || e.every((t) => S(t.value))), has
40024
40024
  for (let n of e)
40025
40025
  t.some((i2) => i2.value === n.value) || t.push(n);
40026
40026
  return t;
40027
- }, isDistinct: (r4, e) => f(e.length === A.distinct(r4, e).length), where: (r4, e, t) => e.filter((n) => F(t.eval({ parent: r4, variables: { $this: n } }, [n]))), select: (r4, e, t) => e.map((n) => t.eval(r4, [n])).flat(), repeat: we, ofType: (r4, e, t) => e.filter((n) => n.type === t.name), single: (r4, e) => {
40027
+ }, isDistinct: (r4, e) => f(e.length === w.distinct(r4, e).length), where: (r4, e, t) => e.filter((n) => F(t.eval({ parent: r4, variables: { $this: n } }, [n]))), select: (r4, e, t) => e.map((n) => t.eval(r4, [n])).flat(), repeat: we, ofType: (r4, e, t) => e.filter((n) => n.type === t.name), single: (r4, e) => {
40028
40028
  if (e.length > 1)
40029
40029
  throw new Error("Expected input length one for single()");
40030
40030
  return e.length === 0 ? [] : e.slice(0, 1);
@@ -40083,37 +40083,37 @@ var A = { empty: (r4, e) => f(e.length === 0 || e.every((t) => S(t.value))), has
40083
40083
  return f(false);
40084
40084
  }
40085
40085
  return [];
40086
- }, convertsToBoolean: (r4, e) => e.length === 0 ? [] : f(A.toBoolean(r4, e).length === 1), toInteger: (r4, e) => {
40086
+ }, convertsToBoolean: (r4, e) => e.length === 0 ? [] : f(w.toBoolean(r4, e).length === 1), toInteger: (r4, e) => {
40087
40087
  if (e.length === 0)
40088
40088
  return [];
40089
40089
  let [{ value: t }] = q(e, 1);
40090
40090
  return typeof t == "number" ? [{ type: l.integer, value: t }] : typeof t == "string" && /^[+-]?\d+$/.exec(t) ? [{ type: l.integer, value: parseInt(t, 10) }] : typeof t == "boolean" ? [{ type: l.integer, value: t ? 1 : 0 }] : [];
40091
- }, convertsToInteger: (r4, e) => e.length === 0 ? [] : f(A.toInteger(r4, e).length === 1), toDate: (r4, e) => {
40091
+ }, convertsToInteger: (r4, e) => e.length === 0 ? [] : f(w.toInteger(r4, e).length === 1), toDate: (r4, e) => {
40092
40092
  if (e.length === 0)
40093
40093
  return [];
40094
40094
  let [{ value: t }] = q(e, 1);
40095
40095
  return typeof t == "string" && /^\d{4}(-\d{2}(-\d{2})?)?/.exec(t) ? [{ type: l.date, value: ye(t) }] : [];
40096
- }, convertsToDate: (r4, e) => e.length === 0 ? [] : f(A.toDate(r4, e).length === 1), toDateTime: (r4, e) => {
40096
+ }, convertsToDate: (r4, e) => e.length === 0 ? [] : f(w.toDate(r4, e).length === 1), toDateTime: (r4, e) => {
40097
40097
  if (e.length === 0)
40098
40098
  return [];
40099
40099
  let [{ value: t }] = q(e, 1);
40100
40100
  return typeof t == "string" && /^\d{4}(-\d{2}(-\d{2})?)?/.exec(t) ? [{ type: l.dateTime, value: ye(t) }] : [];
40101
- }, convertsToDateTime: (r4, e) => e.length === 0 ? [] : f(A.toDateTime(r4, e).length === 1), toDecimal: (r4, e) => {
40101
+ }, convertsToDateTime: (r4, e) => e.length === 0 ? [] : f(w.toDateTime(r4, e).length === 1), toDecimal: (r4, e) => {
40102
40102
  if (e.length === 0)
40103
40103
  return [];
40104
40104
  let [{ value: t }] = q(e, 1);
40105
40105
  return typeof t == "number" ? [{ type: l.decimal, value: t }] : typeof t == "string" && /^-?\d{1,9}(\.\d{1,9})?$/.exec(t) ? [{ type: l.decimal, value: parseFloat(t) }] : typeof t == "boolean" ? [{ type: l.decimal, value: t ? 1 : 0 }] : [];
40106
- }, convertsToDecimal: (r4, e) => e.length === 0 ? [] : f(A.toDecimal(r4, e).length === 1), toQuantity: (r4, e) => {
40106
+ }, convertsToDecimal: (r4, e) => e.length === 0 ? [] : f(w.toDecimal(r4, e).length === 1), toQuantity: (r4, e) => {
40107
40107
  if (e.length === 0)
40108
40108
  return [];
40109
40109
  let [{ value: t }] = q(e, 1);
40110
40110
  return O(t) ? [{ type: l.Quantity, value: t }] : typeof t == "number" ? [{ type: l.Quantity, value: { value: t, unit: "1" } }] : typeof t == "string" && /^-?\d{1,9}(\.\d{1,9})?/.exec(t) ? [{ type: l.Quantity, value: { value: parseFloat(t), unit: "1" } }] : typeof t == "boolean" ? [{ type: l.Quantity, value: { value: t ? 1 : 0, unit: "1" } }] : [];
40111
- }, convertsToQuantity: (r4, e) => e.length === 0 ? [] : f(A.toQuantity(r4, e).length === 1), toString: (r4, e) => {
40111
+ }, convertsToQuantity: (r4, e) => e.length === 0 ? [] : f(w.toQuantity(r4, e).length === 1), toString: (r4, e) => {
40112
40112
  if (e.length === 0)
40113
40113
  return [];
40114
40114
  let [{ value: t }] = q(e, 1);
40115
40115
  return t == null ? [] : O(t) ? [{ type: l.string, value: `${t.value} '${t.unit}'` }] : [{ type: l.string, value: t.toString() }];
40116
- }, convertsToString: (r4, e) => e.length === 0 ? [] : f(A.toString(r4, e).length === 1), toTime: (r4, e) => {
40116
+ }, convertsToString: (r4, e) => e.length === 0 ? [] : f(w.toString(r4, e).length === 1), toTime: (r4, e) => {
40117
40117
  if (e.length === 0)
40118
40118
  return [];
40119
40119
  let [{ value: t }] = q(e, 1);
@@ -40123,14 +40123,14 @@ var A = { empty: (r4, e) => f(e.length === 0 || e.every((t) => S(t.value))), has
40123
40123
  return [{ type: l.time, value: ye("T" + n[1]) }];
40124
40124
  }
40125
40125
  return [];
40126
- }, convertsToTime: (r4, e) => e.length === 0 ? [] : f(A.toTime(r4, e).length === 1), indexOf: (r4, e, t) => D((n, i2) => n.indexOf(i2), r4, e, t), substring: (r4, e, t, n) => D((i2, o, s) => {
40126
+ }, convertsToTime: (r4, e) => e.length === 0 ? [] : f(w.toTime(r4, e).length === 1), indexOf: (r4, e, t) => D((n, i2) => n.indexOf(i2), r4, e, t), substring: (r4, e, t, n) => D((i2, o, s) => {
40127
40127
  let a = o, c2 = s ? a + s : i2.length;
40128
40128
  return a < 0 || a >= i2.length ? void 0 : i2.substring(a, c2);
40129
40129
  }, r4, e, t, n), startsWith: (r4, e, t) => D((n, i2) => n.startsWith(i2), r4, e, t), endsWith: (r4, e, t) => D((n, i2) => n.endsWith(i2), r4, e, t), contains: (r4, e, t) => D((n, i2) => n.includes(i2), r4, e, t), upper: (r4, e) => D((t) => t.toUpperCase(), r4, e), lower: (r4, e) => D((t) => t.toLowerCase(), r4, e), replace: (r4, e, t, n) => D((i2, o, s) => i2.replaceAll(o, s), r4, e, t, n), matches: (r4, e, t) => D((n, i2) => !!new RegExp(i2).exec(n), r4, e, t), replaceMatches: (r4, e, t, n) => D((i2, o, s) => i2.replaceAll(o, s), r4, e, t, n), length: (r4, e) => D((t) => t.length, r4, e), toChars: (r4, e) => D((t) => t ? t.split("") : void 0, r4, e), abs: (r4, e) => B(Math.abs, r4, e), ceiling: (r4, e) => B(Math.ceil, r4, e), exp: (r4, e) => B(Math.exp, r4, e), floor: (r4, e) => B(Math.floor, r4, e), ln: (r4, e) => B(Math.log, r4, e), log: (r4, e, t) => B((n, i2) => Math.log(n) / Math.log(i2), r4, e, t), power: (r4, e, t) => B(Math.pow, r4, e, t), round: (r4, e) => B(Math.round, r4, e), sqrt: (r4, e) => B(Math.sqrt, r4, e), truncate: (r4, e) => B((t) => t | 0, r4, e), children: we, descendants: we, trace: (r4, e, t) => e, now: () => [{ type: l.dateTime, value: (/* @__PURE__ */ new Date()).toISOString() }], timeOfDay: () => [{ type: l.time, value: (/* @__PURE__ */ new Date()).toISOString().substring(11) }], today: () => [{ type: l.date, value: (/* @__PURE__ */ new Date()).toISOString().substring(0, 10) }], between: (r4, e, t, n, i2) => {
40130
- let o = A.toDateTime(r4, t.eval(r4, e));
40130
+ let o = w.toDateTime(r4, t.eval(r4, e));
40131
40131
  if (o.length === 0)
40132
40132
  throw new Error("Invalid start date");
40133
- let s = A.toDateTime(r4, n.eval(r4, e));
40133
+ let s = w.toDateTime(r4, n.eval(r4, e));
40134
40134
  if (s.length === 0)
40135
40135
  throw new Error("Invalid end date");
40136
40136
  let a = i2.eval(r4, e)[0]?.value;
@@ -40141,7 +40141,7 @@ var A = { empty: (r4, e) => f(e.length === 0 || e.every((t) => S(t.value))), has
40141
40141
  }, is: (r4, e, t) => {
40142
40142
  let n = "";
40143
40143
  return t instanceof j ? n = t.name : t instanceof K && (n = t.left.name + "." + t.right.name), n ? e.map((i2) => ({ type: l.boolean, value: Je(i2, n) })) : [];
40144
- }, not: (r4, e) => A.toBoolean(r4, e).map((t) => ({ type: l.boolean, value: !t.value })), resolve: (r4, e) => e.map((t) => {
40144
+ }, not: (r4, e) => w.toBoolean(r4, e).map((t) => ({ type: l.boolean, value: !t.value })), resolve: (r4, e) => e.map((t) => {
40145
40145
  let n = t.value, i2;
40146
40146
  if (typeof n == "string")
40147
40147
  i2 = n;
@@ -40227,7 +40227,7 @@ var j = class {
40227
40227
  evalValue(e) {
40228
40228
  let t = e.value;
40229
40229
  if (!(!t || typeof t != "object"))
40230
- return _(t) && t.resourceType === this.name ? e : w(e, this.name);
40230
+ return _(t) && t.resourceType === this.name ? e : A(e, this.name);
40231
40231
  }
40232
40232
  toString() {
40233
40233
  return this.name;
@@ -40253,17 +40253,17 @@ var it = class extends Le {
40253
40253
  return this.operator + this.child.toString();
40254
40254
  }
40255
40255
  };
40256
- var re = class extends Q {
40256
+ var re = class extends G {
40257
40257
  constructor(e, t) {
40258
40258
  super("as", e, t);
40259
40259
  }
40260
40260
  eval(e, t) {
40261
- return A.ofType(e, this.left.eval(e, t), this.right);
40261
+ return w.ofType(e, this.left.eval(e, t), this.right);
40262
40262
  }
40263
40263
  };
40264
- var C = class extends Q {
40264
+ var P = class extends G {
40265
40265
  };
40266
- var I = class extends C {
40266
+ var I = class extends P {
40267
40267
  constructor(t, n, i2, o) {
40268
40268
  super(t, n, i2);
40269
40269
  this.impl = o;
@@ -40279,7 +40279,7 @@ var I = class extends C {
40279
40279
  return typeof p2 == "boolean" ? f(p2) : O(s) ? [{ type: l.Quantity, value: { ...s, value: p2 } }] : [x(p2)];
40280
40280
  }
40281
40281
  };
40282
- var ot = class extends Q {
40282
+ var ot = class extends G {
40283
40283
  constructor(e, t) {
40284
40284
  super("&", e, t);
40285
40285
  }
@@ -40288,7 +40288,7 @@ var ot = class extends Q {
40288
40288
  return o.length > 0 && o.every((s) => typeof s.value == "string") ? [{ type: l.string, value: o.map((s) => s.value).join("") }] : o;
40289
40289
  }
40290
40290
  };
40291
- var st = class extends C {
40291
+ var st = class extends P {
40292
40292
  constructor(e, t) {
40293
40293
  super("contains", e, t);
40294
40294
  }
@@ -40297,7 +40297,7 @@ var st = class extends C {
40297
40297
  return f(n.some((o) => o.value === i2[0].value));
40298
40298
  }
40299
40299
  };
40300
- var at = class extends C {
40300
+ var at = class extends P {
40301
40301
  constructor(e, t) {
40302
40302
  super("in", e, t);
40303
40303
  }
@@ -40306,7 +40306,7 @@ var at = class extends C {
40306
40306
  return n ? f(i2.some((o) => o.value === n.value)) : [];
40307
40307
  }
40308
40308
  };
40309
- var K = class extends Q {
40309
+ var K = class extends G {
40310
40310
  constructor(e, t) {
40311
40311
  super(".", e, t);
40312
40312
  }
@@ -40317,7 +40317,7 @@ var K = class extends Q {
40317
40317
  return `${this.left.toString()}.${this.right.toString()}`;
40318
40318
  }
40319
40319
  };
40320
- var ge = class extends Q {
40320
+ var ge = class extends G {
40321
40321
  constructor(e, t) {
40322
40322
  super("|", e, t);
40323
40323
  }
@@ -40326,7 +40326,7 @@ var ge = class extends Q {
40326
40326
  return ze([...n, ...i2]);
40327
40327
  }
40328
40328
  };
40329
- var ct = class extends C {
40329
+ var ct = class extends P {
40330
40330
  constructor(e, t) {
40331
40331
  super("=", e, t);
40332
40332
  }
@@ -40335,7 +40335,7 @@ var ct = class extends C {
40335
40335
  return er(n, i2);
40336
40336
  }
40337
40337
  };
40338
- var ut = class extends C {
40338
+ var ut = class extends P {
40339
40339
  constructor(e, t) {
40340
40340
  super("!=", e, t);
40341
40341
  }
@@ -40344,7 +40344,7 @@ var ut = class extends C {
40344
40344
  return Xt(er(n, i2));
40345
40345
  }
40346
40346
  };
40347
- var lt = class extends C {
40347
+ var lt = class extends P {
40348
40348
  constructor(e, t) {
40349
40349
  super("~", e, t);
40350
40350
  }
@@ -40353,7 +40353,7 @@ var lt = class extends C {
40353
40353
  return tr(n, i2);
40354
40354
  }
40355
40355
  };
40356
- var pt = class extends C {
40356
+ var pt = class extends P {
40357
40357
  constructor(e, t) {
40358
40358
  super("!~", e, t);
40359
40359
  }
@@ -40362,7 +40362,7 @@ var pt = class extends C {
40362
40362
  return Xt(tr(n, i2));
40363
40363
  }
40364
40364
  };
40365
- var ne = class extends C {
40365
+ var ne = class extends P {
40366
40366
  constructor(e, t) {
40367
40367
  super("is", e, t);
40368
40368
  }
@@ -40374,7 +40374,7 @@ var ne = class extends C {
40374
40374
  return f(Je(n[0], i2));
40375
40375
  }
40376
40376
  };
40377
- var dt = class extends C {
40377
+ var dt = class extends P {
40378
40378
  constructor(e, t) {
40379
40379
  super("and", e, t);
40380
40380
  }
@@ -40383,7 +40383,7 @@ var dt = class extends C {
40383
40383
  return n?.value === true && i2?.value === true ? f(true) : n?.value === false || i2?.value === false ? f(false) : [];
40384
40384
  }
40385
40385
  };
40386
- var ft = class extends C {
40386
+ var ft = class extends P {
40387
40387
  constructor(e, t) {
40388
40388
  super("or", e, t);
40389
40389
  }
@@ -40392,7 +40392,7 @@ var ft = class extends C {
40392
40392
  return n?.value === false && i2?.value === false ? f(false) : n?.value || i2?.value ? f(true) : [];
40393
40393
  }
40394
40394
  };
40395
- var mt = class extends C {
40395
+ var mt = class extends P {
40396
40396
  constructor(e, t) {
40397
40397
  super("xor", e, t);
40398
40398
  }
@@ -40401,7 +40401,7 @@ var mt = class extends C {
40401
40401
  return !n || !i2 ? [] : f(n.value !== i2.value);
40402
40402
  }
40403
40403
  };
40404
- var ht = class extends C {
40404
+ var ht = class extends P {
40405
40405
  constructor(e, t) {
40406
40406
  super("implies", e, t);
40407
40407
  }
@@ -40410,13 +40410,13 @@ var ht = class extends C {
40410
40410
  return i2?.value === true || n?.value === false ? f(true) : !n || !i2 ? [] : f(false);
40411
40411
  }
40412
40412
  };
40413
- var G = class {
40413
+ var H = class {
40414
40414
  constructor(e, t) {
40415
40415
  this.name = e;
40416
40416
  this.args = t;
40417
40417
  }
40418
40418
  eval(e, t) {
40419
- let n = A[this.name];
40419
+ let n = w[this.name];
40420
40420
  if (!n)
40421
40421
  throw new Error("Unrecognized function: " + this.name);
40422
40422
  return n(e, t, ...this.args);
@@ -40446,37 +40446,37 @@ var ie = class {
40446
40446
  };
40447
40447
  var Oe = ["!=", "!~", "<=", ">=", "{}", "->"];
40448
40448
  var h = { FunctionCall: 0, Dot: 1, Indexer: 2, UnaryAdd: 3, UnarySubtract: 3, Multiply: 4, Divide: 4, IntegerDivide: 4, Modulo: 4, Add: 5, Subtract: 5, Ampersand: 5, Is: 6, As: 6, Union: 7, GreaterThan: 8, GreaterThanOrEquals: 8, LessThan: 8, LessThanOrEquals: 8, Equals: 9, Equivalent: 9, NotEquals: 9, NotEquivalent: 9, In: 10, Contains: 10, And: 11, Xor: 12, Or: 12, Implies: 13, Arrow: 100, Semicolon: 200 };
40449
- var ho = { parse(r4) {
40449
+ var go = { parse(r4) {
40450
40450
  let e = r4.consumeAndParse();
40451
40451
  if (!r4.match(")"))
40452
40452
  throw new Error("Parse error: expected `)` got `" + r4.peek()?.value + "`");
40453
40453
  return e;
40454
40454
  } };
40455
- var yo = { parse(r4, e) {
40455
+ var xo = { parse(r4, e) {
40456
40456
  let t = r4.consumeAndParse();
40457
40457
  if (!r4.match("]"))
40458
40458
  throw new Error("Parse error: expected `]`");
40459
40459
  return new ie(e, t);
40460
40460
  }, precedence: h.Indexer };
40461
- var go = { parse(r4, e) {
40461
+ var vo = { parse(r4, e) {
40462
40462
  if (!(e instanceof j))
40463
40463
  throw new Error("Unexpected parentheses");
40464
40464
  let t = [];
40465
40465
  for (; !r4.match(")"); )
40466
40466
  t.push(r4.consumeAndParse()), r4.match(",");
40467
- return new G(e.name, t);
40467
+ return new H(e.name, t);
40468
40468
  }, precedence: h.FunctionCall };
40469
- function xo(r4) {
40469
+ function To(r4) {
40470
40470
  let e = r4.split(" "), t = parseFloat(e[0]), n = e[1];
40471
40471
  return n?.startsWith("'") && n.endsWith("'") ? n = n.substring(1, n.length - 1) : n = "{" + n + "}", { value: t, unit: n };
40472
40472
  }
40473
40473
  function Ie() {
40474
- return new Ue().registerPrefix("String", { parse: (r4, e) => new M({ type: l.string, value: e.value }) }).registerPrefix("DateTime", { parse: (r4, e) => new M({ type: l.dateTime, value: ye(e.value) }) }).registerPrefix("Quantity", { parse: (r4, e) => new M({ type: l.Quantity, value: xo(e.value) }) }).registerPrefix("Number", { parse: (r4, e) => new M({ type: e.value.includes(".") ? l.decimal : l.integer, value: parseFloat(e.value) }) }).registerPrefix("true", { parse: () => new M({ type: l.boolean, value: true }) }).registerPrefix("false", { parse: () => new M({ type: l.boolean, value: false }) }).registerPrefix("Symbol", { parse: (r4, e) => new j(e.value) }).registerPrefix("{}", { parse: () => new nt() }).registerPrefix("(", ho).registerInfix("[", yo).registerInfix("(", go).prefix("+", h.UnaryAdd, (r4, e) => new it("+", e, (t) => t)).prefix("-", h.UnarySubtract, (r4, e) => new I("-", e, e, (t, n) => -n)).infixLeft(".", h.Dot, (r4, e, t) => new K(r4, t)).infixLeft("/", h.Divide, (r4, e, t) => new I("/", r4, t, (n, i2) => n / i2)).infixLeft("*", h.Multiply, (r4, e, t) => new I("*", r4, t, (n, i2) => n * i2)).infixLeft("+", h.Add, (r4, e, t) => new I("+", r4, t, (n, i2) => n + i2)).infixLeft("-", h.Subtract, (r4, e, t) => new I("-", r4, t, (n, i2) => n - i2)).infixLeft("|", h.Union, (r4, e, t) => new ge(r4, t)).infixLeft("=", h.Equals, (r4, e, t) => new ct(r4, t)).infixLeft("!=", h.NotEquals, (r4, e, t) => new ut(r4, t)).infixLeft("~", h.Equivalent, (r4, e, t) => new lt(r4, t)).infixLeft("!~", h.NotEquivalent, (r4, e, t) => new pt(r4, t)).infixLeft("<", h.LessThan, (r4, e, t) => new I("<", r4, t, (n, i2) => n < i2)).infixLeft("<=", h.LessThanOrEquals, (r4, e, t) => new I("<=", r4, t, (n, i2) => n <= i2)).infixLeft(">", h.GreaterThan, (r4, e, t) => new I(">", r4, t, (n, i2) => n > i2)).infixLeft(">=", h.GreaterThanOrEquals, (r4, e, t) => new I(">=", r4, t, (n, i2) => n >= i2)).infixLeft("&", h.Ampersand, (r4, e, t) => new ot(r4, t)).infixLeft("and", h.And, (r4, e, t) => new dt(r4, t)).infixLeft("as", h.As, (r4, e, t) => new re(r4, t)).infixLeft("contains", h.Contains, (r4, e, t) => new st(r4, t)).infixLeft("div", h.Divide, (r4, e, t) => new I("div", r4, t, (n, i2) => n / i2 | 0)).infixLeft("in", h.In, (r4, e, t) => new at(r4, t)).infixLeft("is", h.Is, (r4, e, t) => new ne(r4, t)).infixLeft("mod", h.Modulo, (r4, e, t) => new I("mod", r4, t, (n, i2) => n % i2)).infixLeft("or", h.Or, (r4, e, t) => new ft(r4, t)).infixLeft("xor", h.Xor, (r4, e, t) => new mt(r4, t)).infixLeft("implies", h.Implies, (r4, e, t) => new ht(r4, t));
40474
+ return new Ue().registerPrefix("String", { parse: (r4, e) => new M({ type: l.string, value: e.value }) }).registerPrefix("DateTime", { parse: (r4, e) => new M({ type: l.dateTime, value: ye(e.value) }) }).registerPrefix("Quantity", { parse: (r4, e) => new M({ type: l.Quantity, value: To(e.value) }) }).registerPrefix("Number", { parse: (r4, e) => new M({ type: e.value.includes(".") ? l.decimal : l.integer, value: parseFloat(e.value) }) }).registerPrefix("true", { parse: () => new M({ type: l.boolean, value: true }) }).registerPrefix("false", { parse: () => new M({ type: l.boolean, value: false }) }).registerPrefix("Symbol", { parse: (r4, e) => new j(e.value) }).registerPrefix("{}", { parse: () => new nt() }).registerPrefix("(", go).registerInfix("[", xo).registerInfix("(", vo).prefix("+", h.UnaryAdd, (r4, e) => new it("+", e, (t) => t)).prefix("-", h.UnarySubtract, (r4, e) => new I("-", e, e, (t, n) => -n)).infixLeft(".", h.Dot, (r4, e, t) => new K(r4, t)).infixLeft("/", h.Divide, (r4, e, t) => new I("/", r4, t, (n, i2) => n / i2)).infixLeft("*", h.Multiply, (r4, e, t) => new I("*", r4, t, (n, i2) => n * i2)).infixLeft("+", h.Add, (r4, e, t) => new I("+", r4, t, (n, i2) => n + i2)).infixLeft("-", h.Subtract, (r4, e, t) => new I("-", r4, t, (n, i2) => n - i2)).infixLeft("|", h.Union, (r4, e, t) => new ge(r4, t)).infixLeft("=", h.Equals, (r4, e, t) => new ct(r4, t)).infixLeft("!=", h.NotEquals, (r4, e, t) => new ut(r4, t)).infixLeft("~", h.Equivalent, (r4, e, t) => new lt(r4, t)).infixLeft("!~", h.NotEquivalent, (r4, e, t) => new pt(r4, t)).infixLeft("<", h.LessThan, (r4, e, t) => new I("<", r4, t, (n, i2) => n < i2)).infixLeft("<=", h.LessThanOrEquals, (r4, e, t) => new I("<=", r4, t, (n, i2) => n <= i2)).infixLeft(">", h.GreaterThan, (r4, e, t) => new I(">", r4, t, (n, i2) => n > i2)).infixLeft(">=", h.GreaterThanOrEquals, (r4, e, t) => new I(">=", r4, t, (n, i2) => n >= i2)).infixLeft("&", h.Ampersand, (r4, e, t) => new ot(r4, t)).infixLeft("and", h.And, (r4, e, t) => new dt(r4, t)).infixLeft("as", h.As, (r4, e, t) => new re(r4, t)).infixLeft("contains", h.Contains, (r4, e, t) => new st(r4, t)).infixLeft("div", h.Divide, (r4, e, t) => new I("div", r4, t, (n, i2) => n / i2 | 0)).infixLeft("in", h.In, (r4, e, t) => new at(r4, t)).infixLeft("is", h.Is, (r4, e, t) => new ne(r4, t)).infixLeft("mod", h.Modulo, (r4, e, t) => new I("mod", r4, t, (n, i2) => n % i2)).infixLeft("or", h.Or, (r4, e, t) => new ft(r4, t)).infixLeft("xor", h.Xor, (r4, e, t) => new mt(r4, t)).infixLeft("implies", h.Implies, (r4, e, t) => new ht(r4, t));
40475
40475
  }
40476
- var vo = Ie();
40477
- var Cn = ((p2) => (p2.BOOLEAN = "BOOLEAN", p2.NUMBER = "NUMBER", p2.QUANTITY = "QUANTITY", p2.TEXT = "TEXT", p2.REFERENCE = "REFERENCE", p2.CANONICAL = "CANONICAL", p2.DATE = "DATE", p2.DATETIME = "DATETIME", p2.PERIOD = "PERIOD", p2.UUID = "UUID", p2))(Cn || {});
40478
- var Po = ((T) => (T.EQUALS = "eq", T.NOT_EQUALS = "ne", T.GREATER_THAN = "gt", T.LESS_THAN = "lt", T.GREATER_THAN_OR_EQUALS = "ge", T.LESS_THAN_OR_EQUALS = "le", T.STARTS_AFTER = "sa", T.ENDS_BEFORE = "eb", T.APPROXIMATELY = "ap", T.CONTAINS = "contains", T.EXACT = "exact", T.TEXT = "text", T.NOT = "not", T.ABOVE = "above", T.BELOW = "below", T.IN = "in", T.NOT_IN = "not-in", T.OF_TYPE = "of-type", T.MISSING = "missing", T.IDENTIFIER = "identifier", T.ITERATE = "iterate", T))(Po || {});
40479
- var Ko = ((E2) => (E2.READ = "read", E2.VREAD = "vread", E2.UPDATE = "update", E2.PATCH = "patch", E2.DELETE = "delete", E2.HISTORY = "history", E2.HISTORY_INSTANCE = "history-instance", E2.HISTORY_TYPE = "history-type", E2.HISTORY_SYSTEM = "history-system", E2.CREATE = "create", E2.SEARCH = "search", E2.SEARCH_TYPE = "search-type", E2.SEARCH_SYSTEM = "search-system", E2.SEARCH_COMPARTMENT = "search-compartment", E2.CAPABILITIES = "capabilities", E2.TRANSACTION = "transaction", E2.BATCH = "batch", E2.OPERATION = "operation", E2))(Ko || {});
40476
+ var So = Ie();
40477
+ var Pn = ((p2) => (p2.BOOLEAN = "BOOLEAN", p2.NUMBER = "NUMBER", p2.QUANTITY = "QUANTITY", p2.TEXT = "TEXT", p2.REFERENCE = "REFERENCE", p2.CANONICAL = "CANONICAL", p2.DATE = "DATE", p2.DATETIME = "DATETIME", p2.PERIOD = "PERIOD", p2.UUID = "UUID", p2))(Pn || {});
40478
+ var Ao = ((T) => (T.EQUALS = "eq", T.NOT_EQUALS = "ne", T.GREATER_THAN = "gt", T.LESS_THAN = "lt", T.GREATER_THAN_OR_EQUALS = "ge", T.LESS_THAN_OR_EQUALS = "le", T.STARTS_AFTER = "sa", T.ENDS_BEFORE = "eb", T.APPROXIMATELY = "ap", T.CONTAINS = "contains", T.EXACT = "exact", T.TEXT = "text", T.NOT = "not", T.ABOVE = "above", T.BELOW = "below", T.IN = "in", T.NOT_IN = "not-in", T.OF_TYPE = "of-type", T.MISSING = "missing", T.IDENTIFIER = "identifier", T.ITERATE = "iterate", T))(Ao || {});
40479
+ var Jo = ((E2) => (E2.READ = "read", E2.VREAD = "vread", E2.UPDATE = "update", E2.PATCH = "patch", E2.DELETE = "delete", E2.HISTORY = "history", E2.HISTORY_INSTANCE = "history-instance", E2.HISTORY_TYPE = "history-type", E2.HISTORY_SYSTEM = "history-system", E2.CREATE = "create", E2.SEARCH = "search", E2.SEARCH_TYPE = "search-type", E2.SEARCH_SYSTEM = "search-system", E2.SEARCH_COMPARTMENT = "search-compartment", E2.CAPABILITIES = "capabilities", E2.TRANSACTION = "transaction", E2.BATCH = "batch", E2.OPERATION = "operation", E2))(Jo || {});
40480
40480
  function Nn(r4) {
40481
40481
  if (typeof window < "u")
40482
40482
  return window.atob(r4);
@@ -40575,7 +40575,7 @@ var se = class {
40575
40575
  }
40576
40576
  };
40577
40577
  var hr = { "Patient-open": "Patient-open", "Patient-close": "Patient-close", "ImagingStudy-open": "ImagingStudy-open", "ImagingStudy-close": "ImagingStudy-close", "Encounter-open": "Encounter-open", "Encounter-close": "Encounter-close", "DiagnosticReport-open": "DiagnosticReport-open", "DiagnosticReport-close": "DiagnosticReport-close", "DiagnosticReport-select": "DiagnosticReport-select", "DiagnosticReport-update": "DiagnosticReport-update", syncerror: "syncerror" };
40578
- var ns = ["Patient", "Encounter", "ImagingStudy", "DiagnosticReport", "OperationOutcome", "Bundle"];
40578
+ var os = ["Patient", "Encounter", "ImagingStudy", "DiagnosticReport", "OperationOutcome", "Bundle"];
40579
40579
  var yr = ["DiagnosticReport-update"];
40580
40580
  function Bn(r4) {
40581
40581
  return yr.includes(r4);
@@ -40584,9 +40584,9 @@ function qn(r4) {
40584
40584
  if (yr.includes(r4))
40585
40585
  throw new d(m(`'context.version' is required for '${r4}'.`));
40586
40586
  }
40587
- var is = { "Patient-open": { patient: { resourceType: "Patient" }, encounter: { resourceType: "Encounter", optional: true } }, "Patient-close": { patient: { resourceType: "Patient" }, encounter: { resourceType: "Encounter", optional: true } }, "ImagingStudy-open": { study: { resourceType: "ImagingStudy" }, encounter: { resourceType: "Encounter", optional: true }, patient: { resourceType: "Patient", optional: true } }, "ImagingStudy-close": { study: { resourceType: "ImagingStudy" }, encounter: { resourceType: "Encounter", optional: true }, patient: { resourceType: "Patient", optional: true } }, "Encounter-open": { encounter: { resourceType: "Encounter" }, patient: { resourceType: "Patient" } }, "Encounter-close": { encounter: { resourceType: "Encounter" }, patient: { resourceType: "Patient" } }, "DiagnosticReport-open": { report: { resourceType: "DiagnosticReport" }, encounter: { resourceType: "Encounter", optional: true }, study: { resourceType: "ImagingStudy", optional: true, manyAllowed: true }, patient: { resourceType: "Patient" } }, "DiagnosticReport-close": { report: { resourceType: "DiagnosticReport" }, encounter: { resourceType: "Encounter", optional: true }, study: { resourceType: "ImagingStudy", optional: true, manyAllowed: true }, patient: { resourceType: "Patient" } }, "DiagnosticReport-select": { report: { resourceType: "DiagnosticReport" }, select: { resourceType: "*", isArray: true } }, "DiagnosticReport-update": { report: { resourceType: "DiagnosticReport" }, patient: { resourceType: "Patient", optional: true }, study: { resourceType: "ImagingStudy", optional: true }, updates: { resourceType: "Bundle" } }, syncerror: { operationoutcome: { resourceType: "OperationOutcome" } } };
40588
- function os(r4) {
40589
- return ns.includes(r4);
40587
+ var ss = { "Patient-open": { patient: { resourceType: "Patient" }, encounter: { resourceType: "Encounter", optional: true } }, "Patient-close": { patient: { resourceType: "Patient" }, encounter: { resourceType: "Encounter", optional: true } }, "ImagingStudy-open": { study: { resourceType: "ImagingStudy" }, encounter: { resourceType: "Encounter", optional: true }, patient: { resourceType: "Patient", optional: true } }, "ImagingStudy-close": { study: { resourceType: "ImagingStudy" }, encounter: { resourceType: "Encounter", optional: true }, patient: { resourceType: "Patient", optional: true } }, "Encounter-open": { encounter: { resourceType: "Encounter" }, patient: { resourceType: "Patient" } }, "Encounter-close": { encounter: { resourceType: "Encounter" }, patient: { resourceType: "Patient" } }, "DiagnosticReport-open": { report: { resourceType: "DiagnosticReport" }, encounter: { resourceType: "Encounter", optional: true }, study: { resourceType: "ImagingStudy", optional: true, manyAllowed: true }, patient: { resourceType: "Patient" } }, "DiagnosticReport-close": { report: { resourceType: "DiagnosticReport" }, encounter: { resourceType: "Encounter", optional: true }, study: { resourceType: "ImagingStudy", optional: true, manyAllowed: true }, patient: { resourceType: "Patient" } }, "DiagnosticReport-select": { report: { resourceType: "DiagnosticReport" }, select: { resourceType: "*", isArray: true } }, "DiagnosticReport-update": { report: { resourceType: "DiagnosticReport" }, patient: { resourceType: "Patient", optional: true }, study: { resourceType: "ImagingStudy", optional: true }, updates: { resourceType: "Bundle" } }, syncerror: { operationoutcome: { resourceType: "OperationOutcome" } } };
40588
+ function as(r4) {
40589
+ return os.includes(r4);
40590
40590
  }
40591
40591
  function jn(r4) {
40592
40592
  return !!r4.endpoint;
@@ -40617,13 +40617,13 @@ function Un(r4, e, t, n) {
40617
40617
  throw new d(m(`context[${t}] is invalid. Resource must contain a resource type. No resource type found.`));
40618
40618
  let i2 = n.resourceType;
40619
40619
  if (i2 !== "*") {
40620
- if (!os(e.resourceType))
40620
+ if (!as(e.resourceType))
40621
40621
  throw new d(m(`context[${t}] is invalid. Resource must contain a valid FHIRcast resource type. Resource type is not a known resource type.`));
40622
40622
  if (i2 && e.resourceType !== i2)
40623
40623
  throw new d(m(`context[${t}] is invalid. context[${t}] for the '${r4}' event should contain resource of type ${i2}.`));
40624
40624
  }
40625
40625
  }
40626
- function ss(r4, e, t, n, i2) {
40626
+ function cs(r4, e, t, n, i2) {
40627
40627
  if (i2.set(e.key, (i2.get(e.key) ?? 0) + 1), !n.isArray)
40628
40628
  Un(r4, e.resource, t, n);
40629
40629
  else {
@@ -40634,13 +40634,13 @@ function ss(r4, e, t, n, i2) {
40634
40634
  Un(r4, s, t, n);
40635
40635
  }
40636
40636
  }
40637
- function as(r4, e) {
40638
- let t = /* @__PURE__ */ new Map(), n = is[r4];
40637
+ function us(r4, e) {
40638
+ let t = /* @__PURE__ */ new Map(), n = ss[r4];
40639
40639
  for (let i2 = 0; i2 < e.length; i2++) {
40640
40640
  let o = e[i2].key;
40641
40641
  if (!n[o])
40642
40642
  throw new d(m(`Key '${o}' not found for event '${r4}'. Make sure to add only valid keys.`));
40643
- ss(r4, e[i2], i2, n[o], t);
40643
+ cs(r4, e[i2], i2, n[o], t);
40644
40644
  }
40645
40645
  for (let [i2, o] of Object.entries(n)) {
40646
40646
  if (!(o.optional || t.has(i2)))
@@ -40659,7 +40659,7 @@ function xr(r4, e, t, n) {
40659
40659
  if (yr.includes(e) && !n)
40660
40660
  throw new d(m(`The '${e}' event must contain a 'context.versionId'.`));
40661
40661
  let i2 = Array.isArray(t) ? t : [t];
40662
- return as(e, i2), { timestamp: (/* @__PURE__ */ new Date()).toISOString(), id: oe(), event: { "hub.topic": r4, "hub.event": e, context: i2, ...n ? { "context.versionId": n } : {} } };
40662
+ return us(e, i2), { timestamp: (/* @__PURE__ */ new Date()).toISOString(), id: oe(), event: { "hub.topic": r4, "hub.event": e, context: i2, ...n ? { "context.versionId": n } : {} } };
40663
40663
  }
40664
40664
  var xt = class extends se {
40665
40665
  constructor(e) {
@@ -40684,7 +40684,7 @@ var xt = class extends se {
40684
40684
  this.websocket.close();
40685
40685
  }
40686
40686
  };
40687
- function cs(r4) {
40687
+ function ls(r4) {
40688
40688
  let e = r4.replace(/-/g, "+").replace(/_/g, "/"), t = Nn(e), n = Array.from(t).reduce((o, s) => {
40689
40689
  let a = ("00" + s.charCodeAt(0).toString(16)).slice(-2);
40690
40690
  return `${o}%${a}`;
@@ -40696,16 +40696,16 @@ function $n(r4) {
40696
40696
  }
40697
40697
  function Tt(r4) {
40698
40698
  let [e, t, n] = r4.split(".");
40699
- return cs(t);
40699
+ return ls(t);
40700
40700
  }
40701
- function Hn(r4) {
40701
+ function Wn(r4) {
40702
40702
  try {
40703
40703
  return typeof Tt(r4).login_id == "string";
40704
40704
  } catch {
40705
40705
  return false;
40706
40706
  }
40707
40707
  }
40708
- function Gn(r4) {
40708
+ function Hn(r4) {
40709
40709
  try {
40710
40710
  let t = Tt(r4).exp;
40711
40711
  return typeof t == "number" ? t * 1e3 : void 0;
@@ -40727,10 +40727,10 @@ var St = class {
40727
40727
  await this.medplum.delete(`keyvalue/v1/${e}`);
40728
40728
  }
40729
40729
  };
40730
- var us;
40730
+ var ps;
40731
40731
  var k = class {
40732
40732
  constructor(e) {
40733
- this[us] = "ReadablePromise";
40733
+ this[ps] = "ReadablePromise";
40734
40734
  this.status = "pending";
40735
40735
  this.suspender = e.then((t) => (this.status = "success", this.response = t, t), (t) => {
40736
40736
  throw this.status = "error", this.error = t, t;
@@ -40762,7 +40762,7 @@ var k = class {
40762
40762
  return this.suspender.finally(e);
40763
40763
  }
40764
40764
  };
40765
- us = Symbol.toStringTag;
40765
+ ps = Symbol.toStringTag;
40766
40766
  var De = class {
40767
40767
  constructor(e) {
40768
40768
  this.storage = e ?? (typeof localStorage < "u" ? localStorage : new vr());
@@ -40967,37 +40967,26 @@ var Et = class {
40967
40967
  return this.masterSubEmitter || (this.masterSubEmitter = new Me(...Array.from(this.criteriaEntries.keys()))), this.masterSubEmitter;
40968
40968
  }
40969
40969
  };
40970
- var ls = N.FHIR_JSON + ", */*; q=0.1";
40971
- var ps = "https://api.medplum.com/";
40972
- var ds = 1e3;
40973
- var fs = 6e4;
40974
- var ms = 0;
40975
- var hs = "Binary/";
40976
- var Wn = { resourceType: "Device", id: "system", deviceName: [{ type: "model-name", name: "System" }] };
40977
- var ys = ((o) => (o.ClientCredentials = "client_credentials", o.AuthorizationCode = "authorization_code", o.RefreshToken = "refresh_token", o.JwtBearer = "urn:ietf:params:oauth:grant-type:jwt-bearer", o.TokenExchange = "urn:ietf:params:oauth:grant-type:token-exchange", o))(ys || {});
40978
- var gs = ((o) => (o.AccessToken = "urn:ietf:params:oauth:token-type:access_token", o.RefreshToken = "urn:ietf:params:oauth:token-type:refresh_token", o.IdToken = "urn:ietf:params:oauth:token-type:id_token", o.Saml1Token = "urn:ietf:params:oauth:token-type:saml1", o.Saml2Token = "urn:ietf:params:oauth:token-type:saml2", o))(gs || {});
40979
- var xs = ((o) => (o.ClientSecretBasic = "client_secret_basic", o.ClientSecretPost = "client_secret_post", o.ClientSecretJwt = "client_secret_jwt", o.PrivateKeyJwt = "private_key_jwt", o.None = "none", o))(xs || {});
40980
- var vs = ((e) => (e.JwtBearer = "urn:ietf:params:oauth:client-assertion-type:jwt-bearer", e))(vs || {});
40970
+ var ds = N.FHIR_JSON + ", */*; q=0.1";
40971
+ var fs = "https://api.medplum.com/";
40972
+ var ms = 1e3;
40973
+ var hs = 6e4;
40974
+ var ys = 0;
40975
+ var gs = "Binary/";
40976
+ var Qn = { resourceType: "Device", id: "system", deviceName: [{ type: "model-name", name: "System" }] };
40977
+ var xs = ((o) => (o.ClientCredentials = "client_credentials", o.AuthorizationCode = "authorization_code", o.RefreshToken = "refresh_token", o.JwtBearer = "urn:ietf:params:oauth:grant-type:jwt-bearer", o.TokenExchange = "urn:ietf:params:oauth:grant-type:token-exchange", o))(xs || {});
40978
+ var vs = ((o) => (o.AccessToken = "urn:ietf:params:oauth:token-type:access_token", o.RefreshToken = "urn:ietf:params:oauth:token-type:refresh_token", o.IdToken = "urn:ietf:params:oauth:token-type:id_token", o.Saml1Token = "urn:ietf:params:oauth:token-type:saml1", o.Saml2Token = "urn:ietf:params:oauth:token-type:saml2", o))(vs || {});
40979
+ var Ts = ((o) => (o.ClientSecretBasic = "client_secret_basic", o.ClientSecretPost = "client_secret_post", o.ClientSecretJwt = "client_secret_jwt", o.PrivateKeyJwt = "private_key_jwt", o.None = "none", o))(Ts || {});
40980
+ var Ss = ((e) => (e.JwtBearer = "urn:ietf:params:oauth:client-assertion-type:jwt-bearer", e))(Ss || {});
40981
40981
  var bt = class extends Ve {
40982
40982
  constructor(t) {
40983
40983
  super();
40984
40984
  this.initComplete = true;
40985
40985
  if (t?.baseUrl && !t.baseUrl.startsWith("http"))
40986
40986
  throw new Error("Base URL must start with http or https");
40987
- if (this.options = t ?? {}, this.fetch = t?.fetch ?? Ts(), this.storage = t?.storage ?? new De(), this.createPdfImpl = t?.createPdf, this.baseUrl = zn(t?.baseUrl ?? ps), this.fhirBaseUrl = zn(Rt(this.baseUrl, t?.fhirUrlPath ?? "fhir/R4/")), this.authorizeUrl = Rt(this.baseUrl, t?.authorizeUrl ?? "oauth2/authorize"), this.tokenUrl = Rt(this.baseUrl, t?.tokenUrl ?? "oauth2/token"), this.logoutUrl = Rt(this.baseUrl, t?.logoutUrl ?? "oauth2/logout"), this.clientId = t?.clientId ?? "", this.clientSecret = t?.clientSecret ?? "", this.onUnauthenticated = t?.onUnauthenticated, this.cacheTime = t?.cacheTime ?? (typeof window > "u" ? ms : fs), this.cacheTime > 0 ? this.requestCache = new gt(t?.resourceCacheSize ?? ds) : this.requestCache = void 0, t?.autoBatchTime ? (this.autoBatchTime = t.autoBatchTime, this.autoBatchQueue = []) : (this.autoBatchTime = 0, this.autoBatchQueue = void 0), t?.accessToken)
40988
- this.setAccessToken(t.accessToken), this.initPromise = Promise.resolve();
40989
- else if (this.storage.getInitPromise !== void 0) {
40990
- let n = this.storage.getInitPromise(), i2 = new Promise((o, s) => {
40991
- n.then(() => {
40992
- this.attemptResumeActiveLogin().then(o).catch((a) => {
40993
- console.error(a), o();
40994
- }), this.initComplete = true;
40995
- }).catch(s);
40996
- });
40997
- this.initPromise = i2, this.initComplete = false;
40998
- } else
40999
- this.initPromise = this.attemptResumeActiveLogin().catch(console.error);
41000
- this.setupStorageListener();
40987
+ this.options = t ?? {}, this.fetch = t?.fetch ?? Es(), this.storage = t?.storage ?? new De(), this.createPdfImpl = t?.createPdf, this.baseUrl = zn(t?.baseUrl ?? fs), this.fhirBaseUrl = zn(Rt(this.baseUrl, t?.fhirUrlPath ?? "fhir/R4/")), this.authorizeUrl = Rt(this.baseUrl, t?.authorizeUrl ?? "oauth2/authorize"), this.tokenUrl = Rt(this.baseUrl, t?.tokenUrl ?? "oauth2/token"), this.logoutUrl = Rt(this.baseUrl, t?.logoutUrl ?? "oauth2/logout"), this.clientId = t?.clientId ?? "", this.clientSecret = t?.clientSecret ?? "", this.onUnauthenticated = t?.onUnauthenticated, this.cacheTime = t?.cacheTime ?? (typeof window > "u" ? ys : hs), this.cacheTime > 0 ? this.requestCache = new gt(t?.resourceCacheSize ?? ms) : 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.initComplete = false, this.initPromise = this.storage.getInitPromise(), this.initPromise.then(() => {
40988
+ t?.accessToken || this.attemptResumeActiveLogin().catch(console.error), this.initComplete = true;
40989
+ }).catch(console.error)), this.setupStorageListener();
41001
40990
  }
41002
40991
  get isInitialized() {
41003
40992
  return this.initComplete;
@@ -41179,7 +41168,7 @@ var bt = class extends Ve {
41179
41168
  if (!n)
41180
41169
  return;
41181
41170
  if (n === "system")
41182
- return Wn;
41171
+ return Qn;
41183
41172
  let [i2, o] = n.split("/");
41184
41173
  if (!(!i2 || !o))
41185
41174
  return this.getCached(i2, o);
@@ -41192,12 +41181,12 @@ var bt = class extends Ve {
41192
41181
  if (!i2)
41193
41182
  return new k(Promise.reject(new Error("Missing reference")));
41194
41183
  if (i2 === "system")
41195
- return new k(Promise.resolve(Wn));
41184
+ return new k(Promise.resolve(Qn));
41196
41185
  let [o, s] = i2.split("/");
41197
41186
  return !o || !s ? new k(Promise.reject(new Error("Invalid reference"))) : this.readResource(o, s, n);
41198
41187
  }
41199
41188
  requestSchema(t) {
41200
- if (Wr(t))
41189
+ if (Qr(t))
41201
41190
  return Promise.resolve();
41202
41191
  let n = t + "-requestSchema", i2 = this.getCacheEntry(n, void 0);
41203
41192
  if (i2)
@@ -41243,7 +41232,7 @@ var bt = class extends Ve {
41243
41232
  target
41244
41233
  }
41245
41234
  }`.replace(/\s+/g, " "), a = await this.graphql(s);
41246
- Ht(a.data.StructureDefinitionList);
41235
+ Wt(a.data.StructureDefinitionList);
41247
41236
  for (let c2 of a.data.SearchParameterList)
41248
41237
  cr(c2);
41249
41238
  })());
@@ -41260,10 +41249,10 @@ var bt = class extends Ve {
41260
41249
  let a = this.fhirUrl("StructureDefinition", "$expand-profile");
41261
41250
  a.search = new URLSearchParams({ url: t }).toString();
41262
41251
  let c2 = await this.post(a.toString(), {});
41263
- return Er(c2).map((u2) => (Gt(u2, u2.url), u2.url));
41252
+ return Er(c2).map((u2) => (Ht(u2, u2.url), u2.url));
41264
41253
  } else {
41265
41254
  let a = await this.searchOne("StructureDefinition", { url: t, _sort: "-_lastUpdated" });
41266
- return a ? (Ht([a], t), [t]) : (console.warn(`No StructureDefinition found for ${t}!`), []);
41255
+ return a ? (Wt([a], t), [t]) : (console.warn(`No StructureDefinition found for ${t}!`), []);
41267
41256
  }
41268
41257
  })());
41269
41258
  return this.setCacheEntry(i2, s), s;
@@ -41313,12 +41302,12 @@ var bt = class extends Ve {
41313
41302
  async createPdf(t, n, i2, o) {
41314
41303
  if (!this.createPdfImpl)
41315
41304
  throw new Error("PDF creation not enabled");
41316
- let s = bs(t, n, i2, o), a = typeof n == "object" ? n : {}, { docDefinition: c2, tableLayouts: u2, fonts: p2, ...y } = s, g2 = await this.createPdfImpl(c2, u2, p2), ce = { ...y, data: g2, contentType: "application/pdf" };
41305
+ let s = Ps(t, n, i2, o), a = typeof n == "object" ? n : {}, { docDefinition: c2, tableLayouts: u2, fonts: p2, ...y } = s, g2 = await this.createPdfImpl(c2, u2, p2), ce = { ...y, data: g2, contentType: "application/pdf" };
41317
41306
  return this.createBinary(ce, a);
41318
41307
  }
41319
41308
  createComment(t, n, i2) {
41320
41309
  let o = this.getProfile(), s, a;
41321
- return t.resourceType === "Encounter" && (s = W(t), a = t.subject), t.resourceType === "ServiceRequest" && (s = t.encounter, a = t.subject), t.resourceType === "Patient" && (a = W(t)), this.createResource({ resourceType: "Communication", status: "completed", basedOn: [W(t)], encounter: s, subject: a, sender: o ? W(o) : void 0, sent: (/* @__PURE__ */ new Date()).toISOString(), payload: [{ contentString: n }] }, i2);
41310
+ return t.resourceType === "Encounter" && (s = Q(t), a = t.subject), t.resourceType === "ServiceRequest" && (s = t.encounter, a = t.subject), t.resourceType === "Patient" && (a = Q(t)), this.createResource({ resourceType: "Communication", status: "completed", basedOn: [Q(t)], encounter: s, subject: a, sender: o ? Q(o) : void 0, sent: (/* @__PURE__ */ new Date()).toISOString(), payload: [{ contentString: n }] }, i2);
41322
41311
  }
41323
41312
  async updateResource(t, n) {
41324
41313
  if (!t.resourceType)
@@ -41373,7 +41362,7 @@ var bt = class extends Ve {
41373
41362
  return this.accessToken;
41374
41363
  }
41375
41364
  setAccessToken(t, n) {
41376
- this.accessToken = t, this.refreshToken = n, this.sessionDetails = void 0, this.accessTokenExpires = Gn(t), this.medplumServer = Hn(t);
41365
+ this.accessToken = t, this.refreshToken = n, this.sessionDetails = void 0, this.accessTokenExpires = Hn(t), this.medplumServer = Wn(t);
41377
41366
  }
41378
41367
  getLogins() {
41379
41368
  return this.storage.getObject("logins") ?? [];
@@ -41421,13 +41410,13 @@ var bt = class extends Ve {
41421
41410
  async download(t, n = {}) {
41422
41411
  this.refreshPromise && await this.refreshPromise;
41423
41412
  let i2 = t.toString();
41424
- i2.startsWith(hs) && (t = this.fhirUrl(i2));
41413
+ i2.startsWith(gs) && (t = this.fhirUrl(i2));
41425
41414
  let o = n.headers;
41426
41415
  return o || (o = {}, n.headers = o), o.Accept || (o.Accept = "*/*"), this.addFetchOptionsDefaults(n), (await this.fetchWithRetry(t.toString(), n)).blob();
41427
41416
  }
41428
41417
  async createMedia(t, n) {
41429
41418
  let { additionalFields: i2, ...o } = t, s = await this.createResource({ resourceType: "Media", status: "preparation", content: { contentType: t.contentType }, ...i2 });
41430
- o.securityContext || (o.securityContext = W(s));
41419
+ o.securityContext || (o.securityContext = Q(s));
41431
41420
  let a = await this.createAttachment(o, n);
41432
41421
  return this.updateResource({ ...s, status: "completed", content: a });
41433
41422
  }
@@ -41551,7 +41540,7 @@ var bt = class extends Ve {
41551
41540
  }
41552
41541
  }
41553
41542
  addFetchOptionsDefaults(t) {
41554
- this.setRequestHeader(t, "X-Medplum", "extended"), this.setRequestHeader(t, "Accept", ls, true), t.body && this.setRequestHeader(t, "Content-Type", N.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");
41543
+ this.setRequestHeader(t, "X-Medplum", "extended"), this.setRequestHeader(t, "Accept", ds, true), t.body && this.setRequestHeader(t, "Content-Type", N.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");
41555
41544
  }
41556
41545
  setRequestContentType(t, n) {
41557
41546
  this.setRequestHeader(t, "Content-Type", n);
@@ -41706,7 +41695,7 @@ var bt = class extends Ve {
41706
41695
  return this.getSubscriptionManager().getMasterEmitter();
41707
41696
  }
41708
41697
  };
41709
- function Ts() {
41698
+ function Es() {
41710
41699
  if (!globalThis.fetch)
41711
41700
  throw new Error("Fetch not available in this environment");
41712
41701
  return globalThis.fetch.bind(globalThis);
@@ -41734,22 +41723,22 @@ function Er(r4) {
41734
41723
  let e = r4.entry?.map((t) => t.resource) ?? [];
41735
41724
  return Object.assign(e, { bundle: r4 });
41736
41725
  }
41737
- function Ss(r4) {
41726
+ function bs(r4) {
41738
41727
  return b(r4) && "data" in r4 && "contentType" in r4;
41739
41728
  }
41740
41729
  function Yn(r4, e, t, n) {
41741
- return Ss(r4) ? r4 : { data: r4, filename: e, contentType: t, onProgress: n };
41730
+ return bs(r4) ? r4 : { data: r4, filename: e, contentType: t, onProgress: n };
41742
41731
  }
41743
- function Es(r4) {
41732
+ function Rs(r4) {
41744
41733
  return b(r4) && "docDefinition" in r4;
41745
41734
  }
41746
- function bs(r4, e, t, n) {
41747
- return Es(r4) ? r4 : { docDefinition: r4, filename: e, tableLayouts: t, fonts: n };
41735
+ function Ps(r4, e, t, n) {
41736
+ return Rs(r4) ? r4 : { docDefinition: r4, filename: e, tableLayouts: t, fonts: n };
41748
41737
  }
41749
- var Ds = [...Oe, "->", "<<", ">>", "=="];
41750
- var Fs = Ie().registerInfix("->", { precedence: h.Arrow }).registerInfix(";", { precedence: h.Semicolon });
41751
- var Zs = [...Oe, "eq", "ne", "co"];
41752
- var ta = Ie();
41738
+ var Ns = [...Oe, "->", "<<", ">>", "=="];
41739
+ var Ls = Ie().registerInfix("->", { precedence: h.Arrow }).registerInfix(";", { precedence: h.Semicolon });
41740
+ var ea = [...Oe, "eq", "ne", "co"];
41741
+ var na = Ie();
41753
41742
  var Y = class {
41754
41743
  constructor(e = "\r", t = "|", n = "^", i2 = "~", o = "\\", s = "&") {
41755
41744
  this.segmentSeparator = e;
@@ -41790,7 +41779,7 @@ var di = class r {
41790
41779
  }
41791
41780
  buildAck() {
41792
41781
  let e = /* @__PURE__ */ new Date(), t = this.getSegment("MSH"), n = t?.getField(3)?.toString() ?? "", i2 = t?.getField(4)?.toString() ?? "", o = t?.getField(5)?.toString() ?? "", s = t?.getField(6)?.toString() ?? "", a = t?.getField(10)?.toString() ?? "", c2 = t?.getField(12)?.toString() ?? "2.5.1";
41793
- return new r([new _e(["MSH", this.context.getMsh2(), o, s, n, i2, na(e), "", this.buildAckMessageType(t), e.getTime().toString(), "P", c2], this.context), new _e(["MSA", "AA", a, "OK"], this.context)]);
41782
+ return new r([new _e(["MSH", this.context.getMsh2(), o, s, n, i2, oa(e), "", this.buildAckMessageType(t), e.getTime().toString(), "P", c2], this.context), new _e(["MSA", "AA", a, "OK"], this.context)]);
41794
41783
  }
41795
41784
  buildAckMessageType(e) {
41796
41785
  let t = e?.getField(9), n = t?.getComponent(2), i2 = t?.getComponent(3), o = "ACK";
@@ -41851,7 +41840,7 @@ var Ee = class r3 {
41851
41840
  return new r3(e.split(t.repetitionSeparator).map((n) => n.split(t.componentSeparator)), t);
41852
41841
  }
41853
41842
  };
41854
- function na(r4) {
41843
+ function oa(r4) {
41855
41844
  let e = r4 instanceof Date ? r4 : new Date(r4), n = e.toISOString().replace(/[-:T]/g, "").replace(/(\.\d+)?Z$/, ""), i2 = e.getUTCMilliseconds();
41856
41845
  return i2 > 0 && (n += "." + i2.toString()), n;
41857
41846
  }
@@ -41879,7 +41868,7 @@ var fi = class {
41879
41868
  `) }), this.write(JSON.stringify({ level: wr[e], timestamp: (/* @__PURE__ */ new Date()).toISOString(), msg: t, ...n, ...this.metadata })));
41880
41869
  }
41881
41870
  };
41882
- function wd(r4) {
41871
+ function kd(r4) {
41883
41872
  let e = wr[r4.toUpperCase()];
41884
41873
  if (e === void 0)
41885
41874
  throw new Error(`Invalid log level: ${r4}`);
@@ -42100,7 +42089,7 @@ var DcmjsDimseScp = class extends dimse.Scp {
42100
42089
  calledAeTitle: this.association?.getCalledAeTitle()
42101
42090
  },
42102
42091
  dataset: dicomJson,
42103
- binary: binary ? W(binary) : void 0
42092
+ binary: binary ? Q(binary) : void 0
42104
42093
  };
42105
42094
  App.instance.addToWebSocketQueue({
42106
42095
  type: "agent:transmit:request",
@@ -42486,7 +42475,7 @@ async function main(argv) {
42486
42475
  const { baseUrl, clientId, clientSecret, agentId } = args;
42487
42476
  const medplum = new bt({ baseUrl, clientId });
42488
42477
  await medplum.startClientLogin(clientId, clientSecret);
42489
- const app = new App(medplum, agentId, wd(args.logLevel ?? "INFO"));
42478
+ const app = new App(medplum, agentId, kd(args.logLevel ?? "INFO"));
42490
42479
  await app.start();
42491
42480
  process.on("SIGINT", () => {
42492
42481
  console.log("Gracefully shutting down from SIGINT (Crtl-C)");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@medplum/agent",
3
- "version": "3.0.12",
3
+ "version": "3.1.0",
4
4
  "description": "Medplum Agent",
5
5
  "homepage": "https://www.medplum.com/",
6
6
  "bugs": {
@@ -23,15 +23,15 @@
23
23
  "test": "jest"
24
24
  },
25
25
  "dependencies": {
26
- "@medplum/core": "3.0.12",
27
- "@medplum/hl7": "3.0.12",
26
+ "@medplum/core": "3.1.0",
27
+ "@medplum/hl7": "3.1.0",
28
28
  "dcmjs-dimse": "0.1.27",
29
29
  "node-windows": "1.0.0-beta.8",
30
30
  "ws": "8.16.0"
31
31
  },
32
32
  "devDependencies": {
33
- "@medplum/fhirtypes": "3.0.12",
34
- "@medplum/mock": "3.0.12",
33
+ "@medplum/fhirtypes": "3.1.0",
34
+ "@medplum/mock": "3.1.0",
35
35
  "@types/async-eventemitter": "0.2.4",
36
36
  "@types/node-windows": "0.1.6",
37
37
  "@types/ws": "8.5.10",