@medplum/agent 2.1.5 → 2.1.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -878,6 +878,7 @@ var require_receiver = __commonJS({
878
878
  var { isValidStatusCode, isValidUTF8 } = require_validation();
879
879
  var FastBuffer = Buffer[Symbol.species];
880
880
  var promise = Promise.resolve();
881
+ var queueTask = typeof queueMicrotask === "function" ? queueMicrotask : queueMicrotaskShim;
881
882
  var GET_INFO = 0;
882
883
  var GET_PAYLOAD_LENGTH_16 = 1;
883
884
  var GET_PAYLOAD_LENGTH_64 = 2;
@@ -1006,7 +1007,7 @@ var require_receiver = __commonJS({
1006
1007
  return;
1007
1008
  default:
1008
1009
  this._loop = false;
1009
- promise.then(() => {
1010
+ queueTask(() => {
1010
1011
  this._state = GET_INFO;
1011
1012
  this.startLoop(cb);
1012
1013
  });
@@ -1403,6 +1404,15 @@ var require_receiver = __commonJS({
1403
1404
  err[kStatusCode] = statusCode;
1404
1405
  return err;
1405
1406
  }
1407
+ function queueMicrotaskShim(cb) {
1408
+ promise.then(cb).catch(throwErrorNextTick);
1409
+ }
1410
+ function throwError(err) {
1411
+ throw err;
1412
+ }
1413
+ function throwErrorNextTick(err) {
1414
+ process.nextTick(throwError, err);
1415
+ }
1406
1416
  }
1407
1417
  });
1408
1418
 
@@ -3513,7 +3523,7 @@ var require_websocket_server = __commonJS({
3513
3523
  socket.once("finish", socket.destroy);
3514
3524
  socket.end(
3515
3525
  `HTTP/1.1 ${code} ${http.STATUS_CODES[code]}\r
3516
- ` + Object.keys(headers).map((h2) => `${h2}: ${headers[h2]}`).join("\r\n") + "\r\n\r\n" + message
3526
+ ` + Object.keys(headers).map((h3) => `${h3}: ${headers[h3]}`).join("\r\n") + "\r\n\r\n" + message
3517
3527
  );
3518
3528
  }
3519
3529
  function abortHandshakeOrEmitwsClientError(server, req, socket, code, message) {
@@ -3538,76 +3548,132 @@ __export(main_exports, {
3538
3548
  module.exports = __toCommonJS(main_exports);
3539
3549
 
3540
3550
  // ../core/dist/esm/index.mjs
3541
- var Ze = "ok";
3542
- var et = "created";
3543
- var rt = "not-modified";
3544
- var nt = "not-found";
3545
- var he = "accepted";
3546
- var Ht = { resourceType: "OperationOutcome", id: nt, issue: [{ severity: "error", code: "not-found", details: { text: "Not found" } }] };
3547
- function O(r4, e) {
3548
- return { resourceType: "OperationOutcome", issue: [{ severity: "error", code: "invalid", details: { text: r4 }, expression: e ? [e] : void 0 }] };
3549
- }
3550
- function h(r4) {
3551
- return { resourceType: "OperationOutcome", issue: [{ severity: "error", code: "structure", details: { text: r4 } }] };
3552
- }
3553
- function ye(r4) {
3554
- return typeof r4 == "object" && r4 !== null && r4.resourceType === "OperationOutcome";
3555
- }
3556
- function it(r4) {
3557
- return r4.id === Ze || r4.id === et || r4.id === rt || r4.id === he;
3558
- }
3559
- var d = class extends Error {
3560
- constructor(t, n) {
3561
- super(Wt(t));
3562
- this.outcome = t, this.cause = n;
3551
+ var he = class {
3552
+ constructor(e, t) {
3553
+ this.operator = e;
3554
+ this.child = t;
3555
+ }
3556
+ toString() {
3557
+ return `${this.operator}(${this.child.toString()})`;
3558
+ }
3559
+ };
3560
+ var $ = class {
3561
+ constructor(e, t, n) {
3562
+ this.operator = e;
3563
+ this.left = t;
3564
+ this.right = n;
3565
+ }
3566
+ toString() {
3567
+ return `${this.left.toString()} ${this.operator} ${this.right.toString()}`;
3568
+ }
3569
+ };
3570
+ var ye = class {
3571
+ constructor() {
3572
+ this.prefixParselets = {};
3573
+ this.infixParselets = {};
3574
+ }
3575
+ registerInfix(e, t) {
3576
+ return this.infixParselets[e] = t, this;
3577
+ }
3578
+ registerPrefix(e, t) {
3579
+ return this.prefixParselets[e] = t, this;
3580
+ }
3581
+ prefix(e, t, n) {
3582
+ return this.registerPrefix(e, { parse(i2, o) {
3583
+ let s = i2.consumeAndParse(t);
3584
+ return n(o, s);
3585
+ } });
3586
+ }
3587
+ infixLeft(e, t, n) {
3588
+ return this.registerInfix(e, { parse(i2, o, s) {
3589
+ let a = i2.consumeAndParse(t);
3590
+ return n(o, s, a);
3591
+ }, precedence: t });
3592
+ }
3593
+ construct(e) {
3594
+ return new et(e, this.prefixParselets, this.infixParselets);
3595
+ }
3596
+ };
3597
+ var et = class {
3598
+ constructor(e, t, n) {
3599
+ this.tokens = e, this.prefixParselets = t, this.infixParselets = n;
3600
+ }
3601
+ hasMore() {
3602
+ return this.tokens.length > 0;
3603
+ }
3604
+ match(e) {
3605
+ return this.peek()?.id !== e ? false : (this.consume(), true);
3606
+ }
3607
+ consumeAndParse(e = 1 / 0) {
3608
+ let t = this.consume(), n = this.prefixParselets[t.id];
3609
+ if (!n)
3610
+ throw Error(`Parse error at "${t.value}" (line ${t.line}, column ${t.column}). No matching prefix parselet.`);
3611
+ let i2 = n.parse(this, t);
3612
+ for (; e > this.getPrecedence(); ) {
3613
+ let o = this.consume();
3614
+ i2 = this.getInfixParselet(o).parse(this, i2, o);
3615
+ }
3616
+ return i2;
3617
+ }
3618
+ getPrecedence() {
3619
+ let e = this.peek();
3620
+ if (!e)
3621
+ return 1 / 0;
3622
+ let t = this.getInfixParselet(e);
3623
+ return t ? t.precedence : 1 / 0;
3624
+ }
3625
+ consume(e, t) {
3626
+ if (!this.tokens.length)
3627
+ throw Error("Cant consume unknown more tokens.");
3628
+ if (e && this.peek()?.id !== e) {
3629
+ let n = this.peek();
3630
+ throw Error(`Expected ${e} but got "${n.id}" at line ${n.line} column ${n.column}.`);
3631
+ }
3632
+ if (t && this.peek()?.value !== t) {
3633
+ let n = this.peek();
3634
+ throw Error(`Expected "${t}" but got "${n.value}" at line ${n.line} column ${n.column}.`);
3635
+ }
3636
+ return this.tokens.shift();
3637
+ }
3638
+ peek() {
3639
+ return this.tokens.length > 0 ? this.tokens[0] : void 0;
3640
+ }
3641
+ removeComments() {
3642
+ this.tokens = this.tokens.filter((e) => e.id !== "Comment");
3643
+ }
3644
+ getInfixParselet(e) {
3645
+ return this.infixParselets[e.id === "Symbol" ? e.value : e.id];
3563
3646
  }
3564
3647
  };
3565
- function ot(r4) {
3566
- return r4 instanceof d ? r4.outcome : ye(r4) ? r4 : O(un(r4));
3567
- }
3568
- function un(r4) {
3569
- return r4 ? typeof r4 == "string" ? r4 : r4 instanceof Error ? r4.message : ye(r4) ? Wt(r4) : typeof r4 == "object" && "code" in r4 && typeof r4.code == "string" ? r4.code : JSON.stringify(r4) : "Unknown error";
3570
- }
3571
- function Wt(r4) {
3572
- let e = r4.issue?.map(ln) ?? [];
3573
- return e.length > 0 ? e.join("; ") : "Unknown error";
3574
- }
3575
- function ln(r4) {
3576
- let e;
3577
- return r4.details?.text ? r4.diagnostics ? e = `${r4.details.text} (${r4.diagnostics})` : e = r4.details.text : r4.diagnostics ? e = r4.diagnostics : e = "Unknown error", r4.expression?.length && (e += ` (${r4.expression.join(", ")})`), e;
3578
- }
3579
3648
  function K(r4) {
3580
- let e = Jt(r4), t = pn(r4);
3649
+ let e = $t(r4), t = ln(r4);
3581
3650
  return t === e ? { reference: e } : { reference: e, display: t };
3582
3651
  }
3583
- function Jt(r4) {
3652
+ function $t(r4) {
3584
3653
  return r4.resourceType + "/" + r4.id;
3585
3654
  }
3586
- function _o(r4) {
3587
- return r4?.reference?.split("/")[1];
3588
- }
3589
- function dn(r4) {
3655
+ function un(r4) {
3590
3656
  return r4.resourceType === "Patient" || r4.resourceType === "Practitioner" || r4.resourceType === "RelatedPerson";
3591
3657
  }
3592
- function pn(r4) {
3593
- if (dn(r4)) {
3594
- let e = fn(r4);
3658
+ function ln(r4) {
3659
+ if (un(r4)) {
3660
+ let e = dn(r4);
3595
3661
  if (e)
3596
3662
  return e;
3597
3663
  }
3598
3664
  if (r4.resourceType === "Device") {
3599
- let e = mn(r4);
3665
+ let e = pn(r4);
3600
3666
  if (e)
3601
3667
  return e;
3602
3668
  }
3603
- return r4.resourceType === "Observation" && "code" in r4 && r4.code?.text ? r4.code.text : r4.resourceType === "User" && r4.email ? r4.email : "name" in r4 && r4.name && typeof r4.name == "string" ? r4.name : Jt(r4);
3669
+ return r4.resourceType === "Observation" && "code" in r4 && r4.code?.text ? r4.code.text : r4.resourceType === "User" && r4.email ? r4.email : "name" in r4 && r4.name && typeof r4.name == "string" ? r4.name : $t(r4);
3604
3670
  }
3605
- function fn(r4) {
3671
+ function dn(r4) {
3606
3672
  let e = r4.name;
3607
3673
  if (e && e.length > 0)
3608
3674
  return be(e[0]);
3609
3675
  }
3610
- function mn(r4) {
3676
+ function pn(r4) {
3611
3677
  let e = r4.deviceName;
3612
3678
  if (e && e.length > 0)
3613
3679
  return e[0].name;
@@ -3624,13 +3690,13 @@ function ge(r4, e) {
3624
3690
  let cn = Math.floor((n.getTime() - t.getTime()) / (1e3 * 60 * 60 * 24));
3625
3691
  return { years: p2, months: q, days: cn };
3626
3692
  }
3627
- function Zt(r4, e) {
3628
- return JSON.stringify(r4, hn, e ? 2 : void 0);
3693
+ function Qt(r4, e) {
3694
+ return JSON.stringify(r4, fn, e ? 2 : void 0);
3629
3695
  }
3630
- function hn(r4, e) {
3631
- return !yn(r4) && b(e) ? void 0 : e;
3696
+ function fn(r4, e) {
3697
+ return !mn(r4) && b(e) ? void 0 : e;
3632
3698
  }
3633
- function yn(r4) {
3699
+ function mn(r4) {
3634
3700
  return !!/\d+$/.exec(r4);
3635
3701
  }
3636
3702
  function b(r4) {
@@ -3639,19 +3705,19 @@ function b(r4) {
3639
3705
  let e = typeof r4;
3640
3706
  return e === "string" && r4 === "" || e === "object" && Object.keys(r4).length === 0;
3641
3707
  }
3642
- function er(r4) {
3708
+ function Wt(r4) {
3643
3709
  return r4.every((e) => typeof e == "string");
3644
3710
  }
3645
- var tr = [];
3711
+ var Gt = [];
3646
3712
  for (let r4 = 0; r4 < 256; r4++)
3647
- tr.push(r4.toString(16).padStart(2, "0"));
3648
- function rr(r4) {
3713
+ Gt.push(r4.toString(16).padStart(2, "0"));
3714
+ function Kt(r4) {
3649
3715
  let e = new Uint8Array(r4), t = new Array(e.length);
3650
3716
  for (let n = 0; n < e.length; n++)
3651
- t[n] = tr[e[n]];
3717
+ t[n] = Gt[e[n]];
3652
3718
  return t.join("");
3653
3719
  }
3654
- function nr(r4) {
3720
+ function zt(r4) {
3655
3721
  let e = new Uint8Array(r4), t = [];
3656
3722
  for (let n = 0; n < e.length; n++)
3657
3723
  t[n] = String.fromCharCode(e[n]);
@@ -3660,34 +3726,34 @@ function nr(r4) {
3660
3726
  function A(r4) {
3661
3727
  return r4.charAt(0).toUpperCase() + r4.substring(1);
3662
3728
  }
3663
- var ut = (r4) => new Promise((e) => {
3729
+ var nt = (r4) => new Promise((e) => {
3664
3730
  setTimeout(e, r4);
3665
3731
  });
3666
3732
  function be(r4, e) {
3667
3733
  let t = [];
3668
3734
  return r4.prefix && e?.prefix !== false && t.push(...r4.prefix), r4.given && t.push(...r4.given), r4.family && t.push(r4.family), r4.suffix && e?.suffix !== false && t.push(...r4.suffix), r4.use && (e?.all || e?.use) && t.push("[" + r4.use + "]"), t.length === 0 && r4.text ? r4.text : t.join(" ").trim();
3669
3735
  }
3670
- function Fn(r4) {
3736
+ function Un(r4) {
3671
3737
  let e = r4.max && r4.max === Number.MAX_SAFE_INTEGER ? Number.POSITIVE_INFINITY : r4.max;
3672
3738
  return { path: "", description: "", type: r4.type ?? [], min: r4.min ?? 0, max: e ?? 1, isArray: !!e && e > 1, constraints: [] };
3673
3739
  }
3674
- function ar(r4) {
3740
+ function Zt(r4) {
3675
3741
  let e = /* @__PURE__ */ Object.create(null);
3676
3742
  for (let [t, n] of Object.entries(r4))
3677
- e[t] = { name: t, elements: Object.fromEntries(Object.entries(n.elements).map(([i2, o]) => [i2, Fn(o)])), constraints: [], innerTypes: [] };
3743
+ e[t] = { name: t, elements: Object.fromEntries(Object.entries(n.elements).map(([i2, o]) => [i2, Un(o)])), constraints: [], innerTypes: [] };
3678
3744
  return e;
3679
3745
  }
3680
- var cr = { Element: { elements: { id: { type: [{ code: "string" }] }, extension: { max: 9007199254740991, type: [{ code: "Extension" }] } } }, BackboneElement: { elements: { id: { type: [{ code: "string" }] }, extension: { max: 9007199254740991, type: [{ code: "Extension" }] }, modifierExtension: { max: 9007199254740991, type: [{ code: "Extension" }] } } }, Address: { elements: { id: { type: [{ code: "string" }] }, extension: { max: 9007199254740991, type: [{ code: "Extension" }] }, use: { type: [{ code: "code" }] }, type: { type: [{ code: "code" }] }, text: { type: [{ code: "string" }] }, line: { max: 9007199254740991, type: [{ code: "string" }] }, city: { type: [{ code: "string" }] }, district: { type: [{ code: "string" }] }, state: { type: [{ code: "string" }] }, postalCode: { type: [{ code: "string" }] }, country: { type: [{ code: "string" }] }, period: { type: [{ code: "Period" }] } } }, Age: { elements: { id: { type: [{ code: "string" }] }, extension: { max: 9007199254740991, type: [{ code: "Extension" }] }, value: { type: [{ code: "decimal" }] }, comparator: { type: [{ code: "code" }] }, unit: { type: [{ code: "string" }] }, system: { type: [{ code: "uri" }] }, code: { type: [{ code: "code" }] } } }, Annotation: { elements: { id: { type: [{ code: "string" }] }, extension: { max: 9007199254740991, type: [{ code: "Extension" }] }, "author[x]": { type: [{ code: "Reference", targetProfile: ["http://hl7.org/fhir/StructureDefinition/Practitioner", "http://hl7.org/fhir/StructureDefinition/Patient", "http://hl7.org/fhir/StructureDefinition/RelatedPerson", "http://hl7.org/fhir/StructureDefinition/Organization"] }, { code: "string" }] }, time: { type: [{ code: "dateTime" }] }, text: { min: 1, type: [{ code: "markdown" }] } } }, Attachment: { elements: { id: { type: [{ code: "string" }] }, extension: { max: 9007199254740991, type: [{ code: "Extension" }] }, contentType: { type: [{ code: "code" }] }, language: { type: [{ code: "code" }] }, data: { type: [{ code: "base64Binary" }] }, url: { type: [{ code: "url" }] }, size: { type: [{ code: "unsignedInt" }] }, hash: { type: [{ code: "base64Binary" }] }, title: { type: [{ code: "string" }] }, creation: { type: [{ code: "dateTime" }] } } }, CodeableConcept: { elements: { id: { type: [{ code: "string" }] }, extension: { max: 9007199254740991, type: [{ code: "Extension" }] }, coding: { max: 9007199254740991, type: [{ code: "Coding" }] }, text: { type: [{ code: "string" }] } } }, Coding: { elements: { id: { type: [{ code: "string" }] }, extension: { max: 9007199254740991, type: [{ code: "Extension" }] }, system: { type: [{ code: "uri" }] }, version: { type: [{ code: "string" }] }, code: { type: [{ code: "code" }] }, display: { type: [{ code: "string" }] }, userSelected: { type: [{ code: "boolean" }] } } }, ContactDetail: { elements: { id: { type: [{ code: "string" }] }, extension: { max: 9007199254740991, type: [{ code: "Extension" }] }, name: { type: [{ code: "string" }] }, telecom: { max: 9007199254740991, type: [{ code: "ContactPoint" }] } } }, ContactPoint: { elements: { id: { type: [{ code: "string" }] }, extension: { max: 9007199254740991, type: [{ code: "Extension" }] }, system: { type: [{ code: "code" }] }, value: { type: [{ code: "string" }] }, use: { type: [{ code: "code" }] }, rank: { type: [{ code: "positiveInt" }] }, period: { type: [{ code: "Period" }] } } }, Contributor: { elements: { id: { type: [{ code: "string" }] }, extension: { max: 9007199254740991, type: [{ code: "Extension" }] }, type: { min: 1, type: [{ code: "code" }] }, name: { min: 1, type: [{ code: "string" }] }, contact: { max: 9007199254740991, type: [{ code: "ContactDetail" }] } } }, Count: { elements: { id: { type: [{ code: "string" }] }, extension: { max: 9007199254740991, type: [{ code: "Extension" }] }, value: { type: [{ code: "decimal" }] }, comparator: { type: [{ code: "code" }] }, unit: { type: [{ code: "string" }] }, system: { type: [{ code: "uri" }] }, code: { type: [{ code: "code" }] } } }, DataRequirement: { elements: { id: { type: [{ code: "string" }] }, extension: { max: 9007199254740991, type: [{ code: "Extension" }] }, type: { min: 1, type: [{ code: "code" }] }, profile: { max: 9007199254740991, type: [{ code: "canonical", targetProfile: ["http://hl7.org/fhir/StructureDefinition/StructureDefinition"] }] }, "subject[x]": { type: [{ code: "CodeableConcept" }, { code: "Reference", targetProfile: ["http://hl7.org/fhir/StructureDefinition/Group"] }] }, mustSupport: { max: 9007199254740991, type: [{ code: "string" }] }, codeFilter: { max: 9007199254740991, type: [{ code: "DataRequirementCodeFilter" }] }, dateFilter: { max: 9007199254740991, type: [{ code: "DataRequirementDateFilter" }] }, limit: { type: [{ code: "positiveInt" }] }, sort: { max: 9007199254740991, type: [{ code: "DataRequirementSort" }] } } }, Distance: { elements: { id: { type: [{ code: "string" }] }, extension: { max: 9007199254740991, type: [{ code: "Extension" }] }, value: { type: [{ code: "decimal" }] }, comparator: { type: [{ code: "code" }] }, unit: { type: [{ code: "string" }] }, system: { type: [{ code: "uri" }] }, code: { type: [{ code: "code" }] } } }, Dosage: { elements: { id: { type: [{ code: "string" }] }, extension: { max: 9007199254740991, type: [{ code: "Extension" }] }, modifierExtension: { max: 9007199254740991, type: [{ code: "Extension" }] }, sequence: { type: [{ code: "integer" }] }, text: { type: [{ code: "string" }] }, additionalInstruction: { max: 9007199254740991, type: [{ code: "CodeableConcept" }] }, patientInstruction: { type: [{ code: "string" }] }, timing: { type: [{ code: "Timing" }] }, "asNeeded[x]": { type: [{ code: "boolean" }, { code: "CodeableConcept" }] }, site: { type: [{ code: "CodeableConcept" }] }, route: { type: [{ code: "CodeableConcept" }] }, method: { type: [{ code: "CodeableConcept" }] }, doseAndRate: { max: 9007199254740991, type: [{ code: "DosageDoseAndRate" }] }, maxDosePerPeriod: { type: [{ code: "Ratio" }] }, maxDosePerAdministration: { type: [{ code: "Quantity" }] }, maxDosePerLifetime: { type: [{ code: "Quantity" }] } } }, Duration: { elements: { id: { type: [{ code: "string" }] }, extension: { max: 9007199254740991, type: [{ code: "Extension" }] }, value: { type: [{ code: "decimal" }] }, comparator: { type: [{ code: "code" }] }, unit: { type: [{ code: "string" }] }, system: { type: [{ code: "uri" }] }, code: { type: [{ code: "code" }] } } }, ElementDefinition: { elements: { id: { type: [{ code: "string" }] }, extension: { max: 9007199254740991, type: [{ code: "Extension" }] }, modifierExtension: { max: 9007199254740991, type: [{ code: "Extension" }] }, path: { min: 1, type: [{ code: "string" }] }, representation: { max: 9007199254740991, type: [{ code: "code" }] }, sliceName: { type: [{ code: "string" }] }, sliceIsConstraining: { type: [{ code: "boolean" }] }, label: { type: [{ code: "string" }] }, code: { max: 9007199254740991, type: [{ code: "Coding" }] }, slicing: { type: [{ code: "ElementDefinitionSlicing" }] }, short: { type: [{ code: "string" }] }, definition: { type: [{ code: "markdown" }] }, comment: { type: [{ code: "markdown" }] }, requirements: { type: [{ code: "markdown" }] }, alias: { max: 9007199254740991, type: [{ code: "string" }] }, min: { type: [{ code: "unsignedInt" }] }, max: { type: [{ code: "string" }] }, base: { type: [{ code: "ElementDefinitionBase" }] }, contentReference: { type: [{ code: "uri" }] }, type: { max: 9007199254740991, type: [{ code: "ElementDefinitionType" }] }, "defaultValue[x]": { type: [{ code: "base64Binary" }, { code: "boolean" }, { code: "canonical" }, { code: "code" }, { code: "date" }, { code: "dateTime" }, { code: "decimal" }, { code: "id" }, { code: "instant" }, { code: "integer" }, { code: "markdown" }, { code: "oid" }, { code: "positiveInt" }, { code: "string" }, { code: "time" }, { code: "unsignedInt" }, { code: "uri" }, { code: "url" }, { code: "uuid" }, { code: "Address" }, { code: "Age" }, { code: "Annotation" }, { code: "Attachment" }, { code: "CodeableConcept" }, { code: "Coding" }, { code: "ContactPoint" }, { code: "Count" }, { code: "Distance" }, { code: "Duration" }, { code: "HumanName" }, { code: "Identifier" }, { code: "Money" }, { code: "Period" }, { code: "Quantity" }, { code: "Range" }, { code: "Ratio" }, { code: "Reference" }, { code: "SampledData" }, { code: "Signature" }, { code: "Timing" }, { code: "ContactDetail" }, { code: "Contributor" }, { code: "DataRequirement" }, { code: "Expression" }, { code: "ParameterDefinition" }, { code: "RelatedArtifact" }, { code: "TriggerDefinition" }, { code: "UsageContext" }, { code: "Dosage" }, { code: "Meta" }] }, meaningWhenMissing: { type: [{ code: "markdown" }] }, orderMeaning: { type: [{ code: "string" }] }, "fixed[x]": { type: [{ code: "base64Binary" }, { code: "boolean" }, { code: "canonical" }, { code: "code" }, { code: "date" }, { code: "dateTime" }, { code: "decimal" }, { code: "id" }, { code: "instant" }, { code: "integer" }, { code: "markdown" }, { code: "oid" }, { code: "positiveInt" }, { code: "string" }, { code: "time" }, { code: "unsignedInt" }, { code: "uri" }, { code: "url" }, { code: "uuid" }, { code: "Address" }, { code: "Age" }, { code: "Annotation" }, { code: "Attachment" }, { code: "CodeableConcept" }, { code: "Coding" }, { code: "ContactPoint" }, { code: "Count" }, { code: "Distance" }, { code: "Duration" }, { code: "HumanName" }, { code: "Identifier" }, { code: "Money" }, { code: "Period" }, { code: "Quantity" }, { code: "Range" }, { code: "Ratio" }, { code: "Reference" }, { code: "SampledData" }, { code: "Signature" }, { code: "Timing" }, { code: "ContactDetail" }, { code: "Contributor" }, { code: "DataRequirement" }, { code: "Expression" }, { code: "ParameterDefinition" }, { code: "RelatedArtifact" }, { code: "TriggerDefinition" }, { code: "UsageContext" }, { code: "Dosage" }, { code: "Meta" }] }, "pattern[x]": { type: [{ code: "base64Binary" }, { code: "boolean" }, { code: "canonical" }, { code: "code" }, { code: "date" }, { code: "dateTime" }, { code: "decimal" }, { code: "id" }, { code: "instant" }, { code: "integer" }, { code: "markdown" }, { code: "oid" }, { code: "positiveInt" }, { code: "string" }, { code: "time" }, { code: "unsignedInt" }, { code: "uri" }, { code: "url" }, { code: "uuid" }, { code: "Address" }, { code: "Age" }, { code: "Annotation" }, { code: "Attachment" }, { code: "CodeableConcept" }, { code: "Coding" }, { code: "ContactPoint" }, { code: "Count" }, { code: "Distance" }, { code: "Duration" }, { code: "HumanName" }, { code: "Identifier" }, { code: "Money" }, { code: "Period" }, { code: "Quantity" }, { code: "Range" }, { code: "Ratio" }, { code: "Reference" }, { code: "SampledData" }, { code: "Signature" }, { code: "Timing" }, { code: "ContactDetail" }, { code: "Contributor" }, { code: "DataRequirement" }, { code: "Expression" }, { code: "ParameterDefinition" }, { code: "RelatedArtifact" }, { code: "TriggerDefinition" }, { code: "UsageContext" }, { code: "Dosage" }, { code: "Meta" }] }, example: { max: 9007199254740991, type: [{ code: "ElementDefinitionExample" }] }, "minValue[x]": { type: [{ code: "date" }, { code: "dateTime" }, { code: "instant" }, { code: "time" }, { code: "decimal" }, { code: "integer" }, { code: "positiveInt" }, { code: "unsignedInt" }, { code: "Quantity" }] }, "maxValue[x]": { type: [{ code: "date" }, { code: "dateTime" }, { code: "instant" }, { code: "time" }, { code: "decimal" }, { code: "integer" }, { code: "positiveInt" }, { code: "unsignedInt" }, { code: "Quantity" }] }, maxLength: { type: [{ code: "integer" }] }, condition: { max: 9007199254740991, type: [{ code: "id" }] }, constraint: { max: 9007199254740991, type: [{ code: "ElementDefinitionConstraint" }] }, mustSupport: { type: [{ code: "boolean" }] }, isModifier: { type: [{ code: "boolean" }] }, isModifierReason: { type: [{ code: "string" }] }, isSummary: { type: [{ code: "boolean" }] }, binding: { type: [{ code: "ElementDefinitionBinding" }] }, mapping: { max: 9007199254740991, type: [{ code: "ElementDefinitionMapping" }] } } }, Expression: { elements: { id: { type: [{ code: "string" }] }, extension: { max: 9007199254740991, type: [{ code: "Extension" }] }, description: { type: [{ code: "string" }] }, name: { type: [{ code: "id" }] }, language: { min: 1, type: [{ code: "code" }] }, expression: { type: [{ code: "string" }] }, reference: { type: [{ code: "uri" }] } } }, Extension: { elements: { id: { type: [{ code: "string" }] }, extension: { max: 9007199254740991, type: [{ code: "Extension" }] }, url: { min: 1, type: [{ code: "string" }] }, "value[x]": { type: [{ code: "base64Binary" }, { code: "boolean" }, { code: "canonical" }, { code: "code" }, { code: "date" }, { code: "dateTime" }, { code: "decimal" }, { code: "id" }, { code: "instant" }, { code: "integer" }, { code: "markdown" }, { code: "oid" }, { code: "positiveInt" }, { code: "string" }, { code: "time" }, { code: "unsignedInt" }, { code: "uri" }, { code: "url" }, { code: "uuid" }, { code: "Address" }, { code: "Age" }, { code: "Annotation" }, { code: "Attachment" }, { code: "CodeableConcept" }, { code: "Coding" }, { code: "ContactPoint" }, { code: "Count" }, { code: "Distance" }, { code: "Duration" }, { code: "HumanName" }, { code: "Identifier" }, { code: "Money" }, { code: "Period" }, { code: "Quantity" }, { code: "Range" }, { code: "Ratio" }, { code: "Reference" }, { code: "SampledData" }, { code: "Signature" }, { code: "Timing" }, { code: "ContactDetail" }, { code: "Contributor" }, { code: "DataRequirement" }, { code: "Expression" }, { code: "ParameterDefinition" }, { code: "RelatedArtifact" }, { code: "TriggerDefinition" }, { code: "UsageContext" }, { code: "Dosage" }, { code: "Meta" }] } } }, HumanName: { elements: { id: { type: [{ code: "string" }] }, extension: { max: 9007199254740991, type: [{ code: "Extension" }] }, use: { type: [{ code: "code" }] }, text: { type: [{ code: "string" }] }, family: { type: [{ code: "string" }] }, given: { max: 9007199254740991, type: [{ code: "string" }] }, prefix: { max: 9007199254740991, type: [{ code: "string" }] }, suffix: { max: 9007199254740991, type: [{ code: "string" }] }, period: { type: [{ code: "Period" }] } } }, Identifier: { elements: { id: { type: [{ code: "string" }] }, extension: { max: 9007199254740991, type: [{ code: "Extension" }] }, use: { type: [{ code: "code" }] }, type: { type: [{ code: "CodeableConcept" }] }, system: { type: [{ code: "uri" }] }, value: { type: [{ code: "string" }] }, period: { type: [{ code: "Period" }] }, assigner: { type: [{ code: "Reference", targetProfile: ["http://hl7.org/fhir/StructureDefinition/Organization"] }] } } }, MarketingStatus: { elements: { id: { type: [{ code: "string" }] }, extension: { max: 9007199254740991, type: [{ code: "Extension" }] }, modifierExtension: { max: 9007199254740991, type: [{ code: "Extension" }] }, country: { min: 1, type: [{ code: "CodeableConcept" }] }, jurisdiction: { type: [{ code: "CodeableConcept" }] }, status: { min: 1, type: [{ code: "CodeableConcept" }] }, dateRange: { min: 1, type: [{ code: "Period" }] }, restoreDate: { type: [{ code: "dateTime" }] } } }, Meta: { elements: { id: { type: [{ code: "string" }] }, extension: { max: 9007199254740991, type: [{ code: "Extension" }] }, versionId: { type: [{ code: "id" }] }, lastUpdated: { type: [{ code: "instant" }] }, source: { type: [{ code: "uri" }] }, profile: { max: 9007199254740991, type: [{ code: "canonical", targetProfile: ["http://hl7.org/fhir/StructureDefinition/StructureDefinition"] }] }, security: { max: 9007199254740991, type: [{ code: "Coding" }] }, tag: { max: 9007199254740991, type: [{ code: "Coding" }] }, project: { type: [{ code: "uri" }] }, author: { type: [{ code: "Reference" }] }, account: { type: [{ code: "Reference" }] }, compartment: { max: 9007199254740991, type: [{ code: "Reference" }] } } }, Money: { elements: { id: { type: [{ code: "string" }] }, extension: { max: 9007199254740991, type: [{ code: "Extension" }] }, value: { type: [{ code: "decimal" }] }, currency: { type: [{ code: "code" }] } } }, Narrative: { elements: { id: { type: [{ code: "string" }] }, extension: { max: 9007199254740991, type: [{ code: "Extension" }] }, status: { min: 1, type: [{ code: "code" }] }, div: { min: 1, type: [{ code: "xhtml" }] } } }, ParameterDefinition: { elements: { id: { type: [{ code: "string" }] }, extension: { max: 9007199254740991, type: [{ code: "Extension" }] }, name: { type: [{ code: "code" }] }, use: { min: 1, type: [{ code: "code" }] }, min: { type: [{ code: "integer" }] }, max: { type: [{ code: "string" }] }, documentation: { type: [{ code: "string" }] }, type: { min: 1, type: [{ code: "code" }] }, profile: { type: [{ code: "canonical", targetProfile: ["http://hl7.org/fhir/StructureDefinition/StructureDefinition"] }] } } }, Period: { elements: { id: { type: [{ code: "string" }] }, extension: { max: 9007199254740991, type: [{ code: "Extension" }] }, start: { type: [{ code: "dateTime" }] }, end: { type: [{ code: "dateTime" }] } } }, Population: { elements: { id: { type: [{ code: "string" }] }, extension: { max: 9007199254740991, type: [{ code: "Extension" }] }, modifierExtension: { max: 9007199254740991, type: [{ code: "Extension" }] }, "age[x]": { type: [{ code: "Range" }, { code: "CodeableConcept" }] }, gender: { type: [{ code: "CodeableConcept" }] }, race: { type: [{ code: "CodeableConcept" }] }, physiologicalCondition: { type: [{ code: "CodeableConcept" }] } } }, ProdCharacteristic: { elements: { id: { type: [{ code: "string" }] }, extension: { max: 9007199254740991, type: [{ code: "Extension" }] }, modifierExtension: { max: 9007199254740991, type: [{ code: "Extension" }] }, height: { type: [{ code: "Quantity" }] }, width: { type: [{ code: "Quantity" }] }, depth: { type: [{ code: "Quantity" }] }, weight: { type: [{ code: "Quantity" }] }, nominalVolume: { type: [{ code: "Quantity" }] }, externalDiameter: { type: [{ code: "Quantity" }] }, shape: { type: [{ code: "string" }] }, color: { max: 9007199254740991, type: [{ code: "string" }] }, imprint: { max: 9007199254740991, type: [{ code: "string" }] }, image: { max: 9007199254740991, type: [{ code: "Attachment" }] }, scoring: { type: [{ code: "CodeableConcept" }] } } }, ProductShelfLife: { elements: { id: { type: [{ code: "string" }] }, extension: { max: 9007199254740991, type: [{ code: "Extension" }] }, modifierExtension: { max: 9007199254740991, type: [{ code: "Extension" }] }, identifier: { type: [{ code: "Identifier" }] }, type: { min: 1, type: [{ code: "CodeableConcept" }] }, period: { min: 1, type: [{ code: "Quantity" }] }, specialPrecautionsForStorage: { max: 9007199254740991, type: [{ code: "CodeableConcept" }] } } }, Quantity: { elements: { id: { type: [{ code: "string" }] }, extension: { max: 9007199254740991, type: [{ code: "Extension" }] }, value: { type: [{ code: "decimal" }] }, comparator: { type: [{ code: "code" }] }, unit: { type: [{ code: "string" }] }, system: { type: [{ code: "uri" }] }, code: { type: [{ code: "code" }] } } }, Range: { elements: { id: { type: [{ code: "string" }] }, extension: { max: 9007199254740991, type: [{ code: "Extension" }] }, low: { type: [{ code: "Quantity" }] }, high: { type: [{ code: "Quantity" }] } } }, Ratio: { elements: { id: { type: [{ code: "string" }] }, extension: { max: 9007199254740991, type: [{ code: "Extension" }] }, numerator: { type: [{ code: "Quantity" }] }, denominator: { type: [{ code: "Quantity" }] } } }, Reference: { elements: { id: { type: [{ code: "string" }] }, extension: { max: 9007199254740991, type: [{ code: "Extension" }] }, reference: { type: [{ code: "string" }] }, type: { type: [{ code: "uri" }] }, identifier: { type: [{ code: "Identifier" }] }, display: { type: [{ code: "string" }] } } }, RelatedArtifact: { elements: { id: { type: [{ code: "string" }] }, extension: { max: 9007199254740991, type: [{ code: "Extension" }] }, type: { min: 1, type: [{ code: "code" }] }, label: { type: [{ code: "string" }] }, display: { type: [{ code: "string" }] }, citation: { type: [{ code: "markdown" }] }, url: { type: [{ code: "url" }] }, document: { type: [{ code: "Attachment" }] }, resource: { type: [{ code: "canonical", targetProfile: ["http://hl7.org/fhir/StructureDefinition/Resource"] }] } } }, SampledData: { elements: { id: { type: [{ code: "string" }] }, extension: { max: 9007199254740991, type: [{ code: "Extension" }] }, origin: { min: 1, type: [{ code: "Quantity" }] }, period: { min: 1, type: [{ code: "decimal" }] }, factor: { type: [{ code: "decimal" }] }, lowerLimit: { type: [{ code: "decimal" }] }, upperLimit: { type: [{ code: "decimal" }] }, dimensions: { min: 1, type: [{ code: "positiveInt" }] }, data: { type: [{ code: "string" }] } } }, Signature: { elements: { id: { type: [{ code: "string" }] }, extension: { max: 9007199254740991, type: [{ code: "Extension" }] }, type: { min: 1, max: 9007199254740991, type: [{ code: "Coding" }] }, when: { min: 1, type: [{ code: "instant" }] }, who: { min: 1, type: [{ code: "Reference", targetProfile: ["http://hl7.org/fhir/StructureDefinition/Practitioner", "http://hl7.org/fhir/StructureDefinition/PractitionerRole", "http://hl7.org/fhir/StructureDefinition/RelatedPerson", "http://hl7.org/fhir/StructureDefinition/Patient", "http://hl7.org/fhir/StructureDefinition/Device", "http://hl7.org/fhir/StructureDefinition/Organization"] }] }, onBehalfOf: { type: [{ code: "Reference", targetProfile: ["http://hl7.org/fhir/StructureDefinition/Practitioner", "http://hl7.org/fhir/StructureDefinition/PractitionerRole", "http://hl7.org/fhir/StructureDefinition/RelatedPerson", "http://hl7.org/fhir/StructureDefinition/Patient", "http://hl7.org/fhir/StructureDefinition/Device", "http://hl7.org/fhir/StructureDefinition/Organization"] }] }, targetFormat: { type: [{ code: "code" }] }, sigFormat: { type: [{ code: "code" }] }, data: { type: [{ code: "base64Binary" }] } } }, SubstanceAmount: { elements: { id: { type: [{ code: "string" }] }, extension: { max: 9007199254740991, type: [{ code: "Extension" }] }, modifierExtension: { max: 9007199254740991, type: [{ code: "Extension" }] }, "amount[x]": { type: [{ code: "Quantity" }, { code: "Range" }, { code: "string" }] }, amountType: { type: [{ code: "CodeableConcept" }] }, amountText: { type: [{ code: "string" }] }, referenceRange: { type: [{ code: "SubstanceAmountReferenceRange" }] } } }, Timing: { elements: { id: { type: [{ code: "string" }] }, extension: { max: 9007199254740991, type: [{ code: "Extension" }] }, modifierExtension: { max: 9007199254740991, type: [{ code: "Extension" }] }, event: { max: 9007199254740991, type: [{ code: "dateTime" }] }, repeat: { type: [{ code: "TimingRepeat" }] }, code: { type: [{ code: "CodeableConcept" }] } } }, TriggerDefinition: { elements: { id: { type: [{ code: "string" }] }, extension: { max: 9007199254740991, type: [{ code: "Extension" }] }, type: { min: 1, type: [{ code: "code" }] }, name: { type: [{ code: "string" }] }, "timing[x]": { type: [{ code: "Timing" }, { code: "Reference", targetProfile: ["http://hl7.org/fhir/StructureDefinition/Schedule"] }, { code: "date" }, { code: "dateTime" }] }, data: { max: 9007199254740991, type: [{ code: "DataRequirement" }] }, condition: { type: [{ code: "Expression" }] } } }, UsageContext: { elements: { id: { type: [{ code: "string" }] }, extension: { max: 9007199254740991, type: [{ code: "Extension" }] }, code: { min: 1, type: [{ code: "Coding" }] }, "value[x]": { min: 1, type: [{ code: "CodeableConcept" }, { code: "Quantity" }, { code: "Range" }, { code: "Reference", targetProfile: ["http://hl7.org/fhir/StructureDefinition/PlanDefinition", "http://hl7.org/fhir/StructureDefinition/ResearchStudy", "http://hl7.org/fhir/StructureDefinition/InsurancePlan", "http://hl7.org/fhir/StructureDefinition/HealthcareService", "http://hl7.org/fhir/StructureDefinition/Group", "http://hl7.org/fhir/StructureDefinition/Location", "http://hl7.org/fhir/StructureDefinition/Organization"] }] } } }, MoneyQuantity: { elements: { id: { type: [{ code: "string" }] }, extension: { max: 9007199254740991, type: [{ code: "Extension" }] }, value: { type: [{ code: "decimal" }] }, comparator: { type: [{ code: "code" }] }, unit: { type: [{ code: "string" }] }, system: { type: [{ code: "uri" }] }, code: { type: [{ code: "code" }] } } }, SimpleQuantity: { elements: { id: { type: [{ code: "string" }] }, extension: { max: 9007199254740991, type: [{ code: "Extension" }] }, value: { type: [{ code: "decimal" }] }, comparator: { max: 0, type: [{ code: "code" }] }, unit: { type: [{ code: "string" }] }, system: { type: [{ code: "uri" }] }, code: { type: [{ code: "code" }] } } }, MetadataResource: { elements: { id: { type: [{ code: "string" }] }, meta: { type: [{ code: "Meta" }] }, implicitRules: { type: [{ code: "uri" }] }, language: { type: [{ code: "code" }] }, text: { type: [{ code: "Narrative" }] }, contained: { max: 9007199254740991, type: [{ code: "Resource" }] }, extension: { max: 9007199254740991, type: [{ code: "Extension" }] }, modifierExtension: { max: 9007199254740991, type: [{ code: "Extension" }] }, url: { type: [{ code: "uri" }] }, version: { type: [{ code: "string" }] }, name: { type: [{ code: "string" }] }, title: { type: [{ code: "string" }] }, status: { min: 1, type: [{ code: "code" }] }, experimental: { type: [{ code: "boolean" }] }, date: { type: [{ code: "dateTime" }] }, publisher: { type: [{ code: "string" }] }, contact: { max: 9007199254740991, type: [{ code: "ContactDetail" }] }, description: { type: [{ code: "markdown" }] }, useContext: { max: 9007199254740991, type: [{ code: "UsageContext" }] }, jurisdiction: { max: 9007199254740991, type: [{ code: "CodeableConcept" }] } } }, IdentityProvider: { elements: { authorizeUrl: { min: 1, type: [{ code: "string" }] }, tokenUrl: { min: 1, type: [{ code: "string" }] }, userInfoUrl: { min: 1, type: [{ code: "string" }] }, clientId: { min: 1, type: [{ code: "string" }] }, clientSecret: { min: 1, type: [{ code: "string" }] }, useSubject: { type: [{ code: "boolean" }] } } } };
3746
+ var er = { Element: { elements: { id: { type: [{ code: "string" }] }, extension: { max: 9007199254740991, type: [{ code: "Extension" }] } } }, BackboneElement: { elements: { id: { type: [{ code: "string" }] }, extension: { max: 9007199254740991, type: [{ code: "Extension" }] }, modifierExtension: { max: 9007199254740991, type: [{ code: "Extension" }] } } }, Address: { elements: { id: { type: [{ code: "string" }] }, extension: { max: 9007199254740991, type: [{ code: "Extension" }] }, use: { type: [{ code: "code" }] }, type: { type: [{ code: "code" }] }, text: { type: [{ code: "string" }] }, line: { max: 9007199254740991, type: [{ code: "string" }] }, city: { type: [{ code: "string" }] }, district: { type: [{ code: "string" }] }, state: { type: [{ code: "string" }] }, postalCode: { type: [{ code: "string" }] }, country: { type: [{ code: "string" }] }, period: { type: [{ code: "Period" }] } } }, Age: { elements: { id: { type: [{ code: "string" }] }, extension: { max: 9007199254740991, type: [{ code: "Extension" }] }, value: { type: [{ code: "decimal" }] }, comparator: { type: [{ code: "code" }] }, unit: { type: [{ code: "string" }] }, system: { type: [{ code: "uri" }] }, code: { type: [{ code: "code" }] } } }, Annotation: { elements: { id: { type: [{ code: "string" }] }, extension: { max: 9007199254740991, type: [{ code: "Extension" }] }, "author[x]": { type: [{ code: "Reference", targetProfile: ["http://hl7.org/fhir/StructureDefinition/Practitioner", "http://hl7.org/fhir/StructureDefinition/Patient", "http://hl7.org/fhir/StructureDefinition/RelatedPerson", "http://hl7.org/fhir/StructureDefinition/Organization"] }, { code: "string" }] }, time: { type: [{ code: "dateTime" }] }, text: { min: 1, type: [{ code: "markdown" }] } } }, Attachment: { elements: { id: { type: [{ code: "string" }] }, extension: { max: 9007199254740991, type: [{ code: "Extension" }] }, contentType: { type: [{ code: "code" }] }, language: { type: [{ code: "code" }] }, data: { type: [{ code: "base64Binary" }] }, url: { type: [{ code: "url" }] }, size: { type: [{ code: "unsignedInt" }] }, hash: { type: [{ code: "base64Binary" }] }, title: { type: [{ code: "string" }] }, creation: { type: [{ code: "dateTime" }] } } }, CodeableConcept: { elements: { id: { type: [{ code: "string" }] }, extension: { max: 9007199254740991, type: [{ code: "Extension" }] }, coding: { max: 9007199254740991, type: [{ code: "Coding" }] }, text: { type: [{ code: "string" }] } } }, Coding: { elements: { id: { type: [{ code: "string" }] }, extension: { max: 9007199254740991, type: [{ code: "Extension" }] }, system: { type: [{ code: "uri" }] }, version: { type: [{ code: "string" }] }, code: { type: [{ code: "code" }] }, display: { type: [{ code: "string" }] }, userSelected: { type: [{ code: "boolean" }] } } }, ContactDetail: { elements: { id: { type: [{ code: "string" }] }, extension: { max: 9007199254740991, type: [{ code: "Extension" }] }, name: { type: [{ code: "string" }] }, telecom: { max: 9007199254740991, type: [{ code: "ContactPoint" }] } } }, ContactPoint: { elements: { id: { type: [{ code: "string" }] }, extension: { max: 9007199254740991, type: [{ code: "Extension" }] }, system: { type: [{ code: "code" }] }, value: { type: [{ code: "string" }] }, use: { type: [{ code: "code" }] }, rank: { type: [{ code: "positiveInt" }] }, period: { type: [{ code: "Period" }] } } }, Contributor: { elements: { id: { type: [{ code: "string" }] }, extension: { max: 9007199254740991, type: [{ code: "Extension" }] }, type: { min: 1, type: [{ code: "code" }] }, name: { min: 1, type: [{ code: "string" }] }, contact: { max: 9007199254740991, type: [{ code: "ContactDetail" }] } } }, Count: { elements: { id: { type: [{ code: "string" }] }, extension: { max: 9007199254740991, type: [{ code: "Extension" }] }, value: { type: [{ code: "decimal" }] }, comparator: { type: [{ code: "code" }] }, unit: { type: [{ code: "string" }] }, system: { type: [{ code: "uri" }] }, code: { type: [{ code: "code" }] } } }, DataRequirement: { elements: { id: { type: [{ code: "string" }] }, extension: { max: 9007199254740991, type: [{ code: "Extension" }] }, type: { min: 1, type: [{ code: "code" }] }, profile: { max: 9007199254740991, type: [{ code: "canonical", targetProfile: ["http://hl7.org/fhir/StructureDefinition/StructureDefinition"] }] }, "subject[x]": { type: [{ code: "CodeableConcept" }, { code: "Reference", targetProfile: ["http://hl7.org/fhir/StructureDefinition/Group"] }] }, mustSupport: { max: 9007199254740991, type: [{ code: "string" }] }, codeFilter: { max: 9007199254740991, type: [{ code: "DataRequirementCodeFilter" }] }, dateFilter: { max: 9007199254740991, type: [{ code: "DataRequirementDateFilter" }] }, limit: { type: [{ code: "positiveInt" }] }, sort: { max: 9007199254740991, type: [{ code: "DataRequirementSort" }] } } }, Distance: { elements: { id: { type: [{ code: "string" }] }, extension: { max: 9007199254740991, type: [{ code: "Extension" }] }, value: { type: [{ code: "decimal" }] }, comparator: { type: [{ code: "code" }] }, unit: { type: [{ code: "string" }] }, system: { type: [{ code: "uri" }] }, code: { type: [{ code: "code" }] } } }, Dosage: { elements: { id: { type: [{ code: "string" }] }, extension: { max: 9007199254740991, type: [{ code: "Extension" }] }, modifierExtension: { max: 9007199254740991, type: [{ code: "Extension" }] }, sequence: { type: [{ code: "integer" }] }, text: { type: [{ code: "string" }] }, additionalInstruction: { max: 9007199254740991, type: [{ code: "CodeableConcept" }] }, patientInstruction: { type: [{ code: "string" }] }, timing: { type: [{ code: "Timing" }] }, "asNeeded[x]": { type: [{ code: "boolean" }, { code: "CodeableConcept" }] }, site: { type: [{ code: "CodeableConcept" }] }, route: { type: [{ code: "CodeableConcept" }] }, method: { type: [{ code: "CodeableConcept" }] }, doseAndRate: { max: 9007199254740991, type: [{ code: "DosageDoseAndRate" }] }, maxDosePerPeriod: { type: [{ code: "Ratio" }] }, maxDosePerAdministration: { type: [{ code: "Quantity" }] }, maxDosePerLifetime: { type: [{ code: "Quantity" }] } } }, Duration: { elements: { id: { type: [{ code: "string" }] }, extension: { max: 9007199254740991, type: [{ code: "Extension" }] }, value: { type: [{ code: "decimal" }] }, comparator: { type: [{ code: "code" }] }, unit: { type: [{ code: "string" }] }, system: { type: [{ code: "uri" }] }, code: { type: [{ code: "code" }] } } }, ElementDefinition: { elements: { id: { type: [{ code: "string" }] }, extension: { max: 9007199254740991, type: [{ code: "Extension" }] }, modifierExtension: { max: 9007199254740991, type: [{ code: "Extension" }] }, path: { min: 1, type: [{ code: "string" }] }, representation: { max: 9007199254740991, type: [{ code: "code" }] }, sliceName: { type: [{ code: "string" }] }, sliceIsConstraining: { type: [{ code: "boolean" }] }, label: { type: [{ code: "string" }] }, code: { max: 9007199254740991, type: [{ code: "Coding" }] }, slicing: { type: [{ code: "ElementDefinitionSlicing" }] }, short: { type: [{ code: "string" }] }, definition: { type: [{ code: "markdown" }] }, comment: { type: [{ code: "markdown" }] }, requirements: { type: [{ code: "markdown" }] }, alias: { max: 9007199254740991, type: [{ code: "string" }] }, min: { type: [{ code: "unsignedInt" }] }, max: { type: [{ code: "string" }] }, base: { type: [{ code: "ElementDefinitionBase" }] }, contentReference: { type: [{ code: "uri" }] }, type: { max: 9007199254740991, type: [{ code: "ElementDefinitionType" }] }, "defaultValue[x]": { type: [{ code: "base64Binary" }, { code: "boolean" }, { code: "canonical" }, { code: "code" }, { code: "date" }, { code: "dateTime" }, { code: "decimal" }, { code: "id" }, { code: "instant" }, { code: "integer" }, { code: "markdown" }, { code: "oid" }, { code: "positiveInt" }, { code: "string" }, { code: "time" }, { code: "unsignedInt" }, { code: "uri" }, { code: "url" }, { code: "uuid" }, { code: "Address" }, { code: "Age" }, { code: "Annotation" }, { code: "Attachment" }, { code: "CodeableConcept" }, { code: "Coding" }, { code: "ContactPoint" }, { code: "Count" }, { code: "Distance" }, { code: "Duration" }, { code: "HumanName" }, { code: "Identifier" }, { code: "Money" }, { code: "Period" }, { code: "Quantity" }, { code: "Range" }, { code: "Ratio" }, { code: "Reference" }, { code: "SampledData" }, { code: "Signature" }, { code: "Timing" }, { code: "ContactDetail" }, { code: "Contributor" }, { code: "DataRequirement" }, { code: "Expression" }, { code: "ParameterDefinition" }, { code: "RelatedArtifact" }, { code: "TriggerDefinition" }, { code: "UsageContext" }, { code: "Dosage" }, { code: "Meta" }] }, meaningWhenMissing: { type: [{ code: "markdown" }] }, orderMeaning: { type: [{ code: "string" }] }, "fixed[x]": { type: [{ code: "base64Binary" }, { code: "boolean" }, { code: "canonical" }, { code: "code" }, { code: "date" }, { code: "dateTime" }, { code: "decimal" }, { code: "id" }, { code: "instant" }, { code: "integer" }, { code: "markdown" }, { code: "oid" }, { code: "positiveInt" }, { code: "string" }, { code: "time" }, { code: "unsignedInt" }, { code: "uri" }, { code: "url" }, { code: "uuid" }, { code: "Address" }, { code: "Age" }, { code: "Annotation" }, { code: "Attachment" }, { code: "CodeableConcept" }, { code: "Coding" }, { code: "ContactPoint" }, { code: "Count" }, { code: "Distance" }, { code: "Duration" }, { code: "HumanName" }, { code: "Identifier" }, { code: "Money" }, { code: "Period" }, { code: "Quantity" }, { code: "Range" }, { code: "Ratio" }, { code: "Reference" }, { code: "SampledData" }, { code: "Signature" }, { code: "Timing" }, { code: "ContactDetail" }, { code: "Contributor" }, { code: "DataRequirement" }, { code: "Expression" }, { code: "ParameterDefinition" }, { code: "RelatedArtifact" }, { code: "TriggerDefinition" }, { code: "UsageContext" }, { code: "Dosage" }, { code: "Meta" }] }, "pattern[x]": { type: [{ code: "base64Binary" }, { code: "boolean" }, { code: "canonical" }, { code: "code" }, { code: "date" }, { code: "dateTime" }, { code: "decimal" }, { code: "id" }, { code: "instant" }, { code: "integer" }, { code: "markdown" }, { code: "oid" }, { code: "positiveInt" }, { code: "string" }, { code: "time" }, { code: "unsignedInt" }, { code: "uri" }, { code: "url" }, { code: "uuid" }, { code: "Address" }, { code: "Age" }, { code: "Annotation" }, { code: "Attachment" }, { code: "CodeableConcept" }, { code: "Coding" }, { code: "ContactPoint" }, { code: "Count" }, { code: "Distance" }, { code: "Duration" }, { code: "HumanName" }, { code: "Identifier" }, { code: "Money" }, { code: "Period" }, { code: "Quantity" }, { code: "Range" }, { code: "Ratio" }, { code: "Reference" }, { code: "SampledData" }, { code: "Signature" }, { code: "Timing" }, { code: "ContactDetail" }, { code: "Contributor" }, { code: "DataRequirement" }, { code: "Expression" }, { code: "ParameterDefinition" }, { code: "RelatedArtifact" }, { code: "TriggerDefinition" }, { code: "UsageContext" }, { code: "Dosage" }, { code: "Meta" }] }, example: { max: 9007199254740991, type: [{ code: "ElementDefinitionExample" }] }, "minValue[x]": { type: [{ code: "date" }, { code: "dateTime" }, { code: "instant" }, { code: "time" }, { code: "decimal" }, { code: "integer" }, { code: "positiveInt" }, { code: "unsignedInt" }, { code: "Quantity" }] }, "maxValue[x]": { type: [{ code: "date" }, { code: "dateTime" }, { code: "instant" }, { code: "time" }, { code: "decimal" }, { code: "integer" }, { code: "positiveInt" }, { code: "unsignedInt" }, { code: "Quantity" }] }, maxLength: { type: [{ code: "integer" }] }, condition: { max: 9007199254740991, type: [{ code: "id" }] }, constraint: { max: 9007199254740991, type: [{ code: "ElementDefinitionConstraint" }] }, mustSupport: { type: [{ code: "boolean" }] }, isModifier: { type: [{ code: "boolean" }] }, isModifierReason: { type: [{ code: "string" }] }, isSummary: { type: [{ code: "boolean" }] }, binding: { type: [{ code: "ElementDefinitionBinding" }] }, mapping: { max: 9007199254740991, type: [{ code: "ElementDefinitionMapping" }] } } }, Expression: { elements: { id: { type: [{ code: "string" }] }, extension: { max: 9007199254740991, type: [{ code: "Extension" }] }, description: { type: [{ code: "string" }] }, name: { type: [{ code: "id" }] }, language: { min: 1, type: [{ code: "code" }] }, expression: { type: [{ code: "string" }] }, reference: { type: [{ code: "uri" }] } } }, Extension: { elements: { id: { type: [{ code: "string" }] }, extension: { max: 9007199254740991, type: [{ code: "Extension" }] }, url: { min: 1, type: [{ code: "string" }] }, "value[x]": { type: [{ code: "base64Binary" }, { code: "boolean" }, { code: "canonical" }, { code: "code" }, { code: "date" }, { code: "dateTime" }, { code: "decimal" }, { code: "id" }, { code: "instant" }, { code: "integer" }, { code: "markdown" }, { code: "oid" }, { code: "positiveInt" }, { code: "string" }, { code: "time" }, { code: "unsignedInt" }, { code: "uri" }, { code: "url" }, { code: "uuid" }, { code: "Address" }, { code: "Age" }, { code: "Annotation" }, { code: "Attachment" }, { code: "CodeableConcept" }, { code: "Coding" }, { code: "ContactPoint" }, { code: "Count" }, { code: "Distance" }, { code: "Duration" }, { code: "HumanName" }, { code: "Identifier" }, { code: "Money" }, { code: "Period" }, { code: "Quantity" }, { code: "Range" }, { code: "Ratio" }, { code: "Reference" }, { code: "SampledData" }, { code: "Signature" }, { code: "Timing" }, { code: "ContactDetail" }, { code: "Contributor" }, { code: "DataRequirement" }, { code: "Expression" }, { code: "ParameterDefinition" }, { code: "RelatedArtifact" }, { code: "TriggerDefinition" }, { code: "UsageContext" }, { code: "Dosage" }, { code: "Meta" }] } } }, HumanName: { elements: { id: { type: [{ code: "string" }] }, extension: { max: 9007199254740991, type: [{ code: "Extension" }] }, use: { type: [{ code: "code" }] }, text: { type: [{ code: "string" }] }, family: { type: [{ code: "string" }] }, given: { max: 9007199254740991, type: [{ code: "string" }] }, prefix: { max: 9007199254740991, type: [{ code: "string" }] }, suffix: { max: 9007199254740991, type: [{ code: "string" }] }, period: { type: [{ code: "Period" }] } } }, Identifier: { elements: { id: { type: [{ code: "string" }] }, extension: { max: 9007199254740991, type: [{ code: "Extension" }] }, use: { type: [{ code: "code" }] }, type: { type: [{ code: "CodeableConcept" }] }, system: { type: [{ code: "uri" }] }, value: { type: [{ code: "string" }] }, period: { type: [{ code: "Period" }] }, assigner: { type: [{ code: "Reference", targetProfile: ["http://hl7.org/fhir/StructureDefinition/Organization"] }] } } }, MarketingStatus: { elements: { id: { type: [{ code: "string" }] }, extension: { max: 9007199254740991, type: [{ code: "Extension" }] }, modifierExtension: { max: 9007199254740991, type: [{ code: "Extension" }] }, country: { min: 1, type: [{ code: "CodeableConcept" }] }, jurisdiction: { type: [{ code: "CodeableConcept" }] }, status: { min: 1, type: [{ code: "CodeableConcept" }] }, dateRange: { min: 1, type: [{ code: "Period" }] }, restoreDate: { type: [{ code: "dateTime" }] } } }, Meta: { elements: { id: { type: [{ code: "string" }] }, extension: { max: 9007199254740991, type: [{ code: "Extension" }] }, versionId: { type: [{ code: "id" }] }, lastUpdated: { type: [{ code: "instant" }] }, source: { type: [{ code: "uri" }] }, profile: { max: 9007199254740991, type: [{ code: "canonical", targetProfile: ["http://hl7.org/fhir/StructureDefinition/StructureDefinition"] }] }, security: { max: 9007199254740991, type: [{ code: "Coding" }] }, tag: { max: 9007199254740991, type: [{ code: "Coding" }] }, project: { type: [{ code: "uri" }] }, author: { type: [{ code: "Reference" }] }, account: { type: [{ code: "Reference" }] }, compartment: { max: 9007199254740991, type: [{ code: "Reference" }] } } }, Money: { elements: { id: { type: [{ code: "string" }] }, extension: { max: 9007199254740991, type: [{ code: "Extension" }] }, value: { type: [{ code: "decimal" }] }, currency: { type: [{ code: "code" }] } } }, Narrative: { elements: { id: { type: [{ code: "string" }] }, extension: { max: 9007199254740991, type: [{ code: "Extension" }] }, status: { min: 1, type: [{ code: "code" }] }, div: { min: 1, type: [{ code: "xhtml" }] } } }, ParameterDefinition: { elements: { id: { type: [{ code: "string" }] }, extension: { max: 9007199254740991, type: [{ code: "Extension" }] }, name: { type: [{ code: "code" }] }, use: { min: 1, type: [{ code: "code" }] }, min: { type: [{ code: "integer" }] }, max: { type: [{ code: "string" }] }, documentation: { type: [{ code: "string" }] }, type: { min: 1, type: [{ code: "code" }] }, profile: { type: [{ code: "canonical", targetProfile: ["http://hl7.org/fhir/StructureDefinition/StructureDefinition"] }] } } }, Period: { elements: { id: { type: [{ code: "string" }] }, extension: { max: 9007199254740991, type: [{ code: "Extension" }] }, start: { type: [{ code: "dateTime" }] }, end: { type: [{ code: "dateTime" }] } } }, Population: { elements: { id: { type: [{ code: "string" }] }, extension: { max: 9007199254740991, type: [{ code: "Extension" }] }, modifierExtension: { max: 9007199254740991, type: [{ code: "Extension" }] }, "age[x]": { type: [{ code: "Range" }, { code: "CodeableConcept" }] }, gender: { type: [{ code: "CodeableConcept" }] }, race: { type: [{ code: "CodeableConcept" }] }, physiologicalCondition: { type: [{ code: "CodeableConcept" }] } } }, ProdCharacteristic: { elements: { id: { type: [{ code: "string" }] }, extension: { max: 9007199254740991, type: [{ code: "Extension" }] }, modifierExtension: { max: 9007199254740991, type: [{ code: "Extension" }] }, height: { type: [{ code: "Quantity" }] }, width: { type: [{ code: "Quantity" }] }, depth: { type: [{ code: "Quantity" }] }, weight: { type: [{ code: "Quantity" }] }, nominalVolume: { type: [{ code: "Quantity" }] }, externalDiameter: { type: [{ code: "Quantity" }] }, shape: { type: [{ code: "string" }] }, color: { max: 9007199254740991, type: [{ code: "string" }] }, imprint: { max: 9007199254740991, type: [{ code: "string" }] }, image: { max: 9007199254740991, type: [{ code: "Attachment" }] }, scoring: { type: [{ code: "CodeableConcept" }] } } }, ProductShelfLife: { elements: { id: { type: [{ code: "string" }] }, extension: { max: 9007199254740991, type: [{ code: "Extension" }] }, modifierExtension: { max: 9007199254740991, type: [{ code: "Extension" }] }, identifier: { type: [{ code: "Identifier" }] }, type: { min: 1, type: [{ code: "CodeableConcept" }] }, period: { min: 1, type: [{ code: "Quantity" }] }, specialPrecautionsForStorage: { max: 9007199254740991, type: [{ code: "CodeableConcept" }] } } }, Quantity: { elements: { id: { type: [{ code: "string" }] }, extension: { max: 9007199254740991, type: [{ code: "Extension" }] }, value: { type: [{ code: "decimal" }] }, comparator: { type: [{ code: "code" }] }, unit: { type: [{ code: "string" }] }, system: { type: [{ code: "uri" }] }, code: { type: [{ code: "code" }] } } }, Range: { elements: { id: { type: [{ code: "string" }] }, extension: { max: 9007199254740991, type: [{ code: "Extension" }] }, low: { type: [{ code: "Quantity" }] }, high: { type: [{ code: "Quantity" }] } } }, Ratio: { elements: { id: { type: [{ code: "string" }] }, extension: { max: 9007199254740991, type: [{ code: "Extension" }] }, numerator: { type: [{ code: "Quantity" }] }, denominator: { type: [{ code: "Quantity" }] } } }, Reference: { elements: { id: { type: [{ code: "string" }] }, extension: { max: 9007199254740991, type: [{ code: "Extension" }] }, reference: { type: [{ code: "string" }] }, type: { type: [{ code: "uri" }] }, identifier: { type: [{ code: "Identifier" }] }, display: { type: [{ code: "string" }] } } }, RelatedArtifact: { elements: { id: { type: [{ code: "string" }] }, extension: { max: 9007199254740991, type: [{ code: "Extension" }] }, type: { min: 1, type: [{ code: "code" }] }, label: { type: [{ code: "string" }] }, display: { type: [{ code: "string" }] }, citation: { type: [{ code: "markdown" }] }, url: { type: [{ code: "url" }] }, document: { type: [{ code: "Attachment" }] }, resource: { type: [{ code: "canonical", targetProfile: ["http://hl7.org/fhir/StructureDefinition/Resource"] }] } } }, SampledData: { elements: { id: { type: [{ code: "string" }] }, extension: { max: 9007199254740991, type: [{ code: "Extension" }] }, origin: { min: 1, type: [{ code: "Quantity" }] }, period: { min: 1, type: [{ code: "decimal" }] }, factor: { type: [{ code: "decimal" }] }, lowerLimit: { type: [{ code: "decimal" }] }, upperLimit: { type: [{ code: "decimal" }] }, dimensions: { min: 1, type: [{ code: "positiveInt" }] }, data: { type: [{ code: "string" }] } } }, Signature: { elements: { id: { type: [{ code: "string" }] }, extension: { max: 9007199254740991, type: [{ code: "Extension" }] }, type: { min: 1, max: 9007199254740991, type: [{ code: "Coding" }] }, when: { min: 1, type: [{ code: "instant" }] }, who: { min: 1, type: [{ code: "Reference", targetProfile: ["http://hl7.org/fhir/StructureDefinition/Practitioner", "http://hl7.org/fhir/StructureDefinition/PractitionerRole", "http://hl7.org/fhir/StructureDefinition/RelatedPerson", "http://hl7.org/fhir/StructureDefinition/Patient", "http://hl7.org/fhir/StructureDefinition/Device", "http://hl7.org/fhir/StructureDefinition/Organization"] }] }, onBehalfOf: { type: [{ code: "Reference", targetProfile: ["http://hl7.org/fhir/StructureDefinition/Practitioner", "http://hl7.org/fhir/StructureDefinition/PractitionerRole", "http://hl7.org/fhir/StructureDefinition/RelatedPerson", "http://hl7.org/fhir/StructureDefinition/Patient", "http://hl7.org/fhir/StructureDefinition/Device", "http://hl7.org/fhir/StructureDefinition/Organization"] }] }, targetFormat: { type: [{ code: "code" }] }, sigFormat: { type: [{ code: "code" }] }, data: { type: [{ code: "base64Binary" }] } } }, SubstanceAmount: { elements: { id: { type: [{ code: "string" }] }, extension: { max: 9007199254740991, type: [{ code: "Extension" }] }, modifierExtension: { max: 9007199254740991, type: [{ code: "Extension" }] }, "amount[x]": { type: [{ code: "Quantity" }, { code: "Range" }, { code: "string" }] }, amountType: { type: [{ code: "CodeableConcept" }] }, amountText: { type: [{ code: "string" }] }, referenceRange: { type: [{ code: "SubstanceAmountReferenceRange" }] } } }, Timing: { elements: { id: { type: [{ code: "string" }] }, extension: { max: 9007199254740991, type: [{ code: "Extension" }] }, modifierExtension: { max: 9007199254740991, type: [{ code: "Extension" }] }, event: { max: 9007199254740991, type: [{ code: "dateTime" }] }, repeat: { type: [{ code: "TimingRepeat" }] }, code: { type: [{ code: "CodeableConcept" }] } } }, TriggerDefinition: { elements: { id: { type: [{ code: "string" }] }, extension: { max: 9007199254740991, type: [{ code: "Extension" }] }, type: { min: 1, type: [{ code: "code" }] }, name: { type: [{ code: "string" }] }, "timing[x]": { type: [{ code: "Timing" }, { code: "Reference", targetProfile: ["http://hl7.org/fhir/StructureDefinition/Schedule"] }, { code: "date" }, { code: "dateTime" }] }, data: { max: 9007199254740991, type: [{ code: "DataRequirement" }] }, condition: { type: [{ code: "Expression" }] } } }, UsageContext: { elements: { id: { type: [{ code: "string" }] }, extension: { max: 9007199254740991, type: [{ code: "Extension" }] }, code: { min: 1, type: [{ code: "Coding" }] }, "value[x]": { min: 1, type: [{ code: "CodeableConcept" }, { code: "Quantity" }, { code: "Range" }, { code: "Reference", targetProfile: ["http://hl7.org/fhir/StructureDefinition/PlanDefinition", "http://hl7.org/fhir/StructureDefinition/ResearchStudy", "http://hl7.org/fhir/StructureDefinition/InsurancePlan", "http://hl7.org/fhir/StructureDefinition/HealthcareService", "http://hl7.org/fhir/StructureDefinition/Group", "http://hl7.org/fhir/StructureDefinition/Location", "http://hl7.org/fhir/StructureDefinition/Organization"] }] } } }, MoneyQuantity: { elements: { id: { type: [{ code: "string" }] }, extension: { max: 9007199254740991, type: [{ code: "Extension" }] }, value: { type: [{ code: "decimal" }] }, comparator: { type: [{ code: "code" }] }, unit: { type: [{ code: "string" }] }, system: { type: [{ code: "uri" }] }, code: { type: [{ code: "code" }] } } }, SimpleQuantity: { elements: { id: { type: [{ code: "string" }] }, extension: { max: 9007199254740991, type: [{ code: "Extension" }] }, value: { type: [{ code: "decimal" }] }, comparator: { max: 0, type: [{ code: "code" }] }, unit: { type: [{ code: "string" }] }, system: { type: [{ code: "uri" }] }, code: { type: [{ code: "code" }] } } }, MetadataResource: { elements: { id: { type: [{ code: "string" }] }, meta: { type: [{ code: "Meta" }] }, implicitRules: { type: [{ code: "uri" }] }, language: { type: [{ code: "code" }] }, text: { type: [{ code: "Narrative" }] }, contained: { max: 9007199254740991, type: [{ code: "Resource" }] }, extension: { max: 9007199254740991, type: [{ code: "Extension" }] }, modifierExtension: { max: 9007199254740991, type: [{ code: "Extension" }] }, url: { type: [{ code: "uri" }] }, version: { type: [{ code: "string" }] }, name: { type: [{ code: "string" }] }, title: { type: [{ code: "string" }] }, status: { min: 1, type: [{ code: "code" }] }, experimental: { type: [{ code: "boolean" }] }, date: { type: [{ code: "dateTime" }] }, publisher: { type: [{ code: "string" }] }, contact: { max: 9007199254740991, type: [{ code: "ContactDetail" }] }, description: { type: [{ code: "markdown" }] }, useContext: { max: 9007199254740991, type: [{ code: "UsageContext" }] }, jurisdiction: { max: 9007199254740991, type: [{ code: "CodeableConcept" }] } } }, IdentityProvider: { elements: { authorizeUrl: { min: 1, type: [{ code: "string" }] }, tokenUrl: { min: 1, type: [{ code: "string" }] }, userInfoUrl: { min: 1, type: [{ code: "string" }] }, clientId: { min: 1, type: [{ code: "string" }] }, clientSecret: { min: 1, type: [{ code: "string" }] }, useSubject: { type: [{ code: "boolean" }] } } } };
3681
3747
  function l(r4) {
3682
3748
  return [{ type: u.boolean, value: r4 }];
3683
3749
  }
3684
3750
  function T(r4) {
3685
- return r4 == null ? { type: "undefined", value: void 0 } : Number.isSafeInteger(r4) ? { type: u.integer, value: r4 } : typeof r4 == "number" ? { type: u.decimal, value: r4 } : typeof r4 == "boolean" ? { type: u.boolean, value: r4 } : typeof r4 == "string" ? { type: u.string, value: r4 } : R(r4) ? { type: u.Quantity, value: r4 } : _(r4) ? { type: r4.resourceType, value: r4 } : { type: u.BackboneElement, value: r4 };
3751
+ return r4 == null ? { type: "undefined", value: void 0 } : Number.isSafeInteger(r4) ? { type: u.integer, value: r4 } : typeof r4 == "number" ? { type: u.decimal, value: r4 } : typeof r4 == "boolean" ? { type: u.boolean, value: r4 } : typeof r4 == "string" ? { type: u.string, value: r4 } : R(r4) ? { type: u.Quantity, value: r4 } : V(r4) ? { type: r4.resourceType, value: r4 } : { type: u.BackboneElement, value: r4 };
3686
3752
  }
3687
3753
  function N(r4) {
3688
3754
  return r4.length === 0 ? false : !!r4[0].value;
3689
3755
  }
3690
- function V(r4, e) {
3756
+ function D(r4, e) {
3691
3757
  if (r4.length !== 0) {
3692
3758
  if (r4.length === 1 && (!e || r4[0].type === e))
3693
3759
  return r4[0];
@@ -3698,9 +3764,9 @@ function w(r4, e) {
3698
3764
  if (!r4.value)
3699
3765
  return;
3700
3766
  let t = Ae(r4.type, e);
3701
- return t ? Mn(r4, e, t) : Bn(r4, e);
3767
+ return t ? Fn(r4, e, t) : Nn(r4, e);
3702
3768
  }
3703
- function Mn(r4, e, t) {
3769
+ function Fn(r4, e, t) {
3704
3770
  let n = t.type;
3705
3771
  if (!n || n.length === 0)
3706
3772
  return;
@@ -3716,13 +3782,13 @@ function Mn(r4, e, t) {
3716
3782
  }
3717
3783
  }
3718
3784
  let s = r4.value["_" + e];
3719
- if (s && (Array.isArray(i2) ? i2 = i2.map((a, c2) => s[c2] ? pr(a ?? {}, s[c2]) : a) : i2 = pr(i2 ?? {}, s)), !b(i2))
3720
- return (o === "Element" || o === "BackboneElement") && (o = t.type[0].code), Array.isArray(i2) ? i2.map((a) => ur(a, o)) : ur(i2, o);
3785
+ if (s && (Array.isArray(i2) ? i2 = i2.map((a, c2) => s[c2] ? ir(a ?? {}, s[c2]) : a) : i2 = ir(i2 ?? {}, s)), !b(i2))
3786
+ return (o === "Element" || o === "BackboneElement") && (o = t.type[0].code), Array.isArray(i2) ? i2.map((a) => tr(a, o)) : tr(i2, o);
3721
3787
  }
3722
- function ur(r4, e) {
3723
- return e === "Resource" && _(r4) && (e = r4.resourceType), { type: e, value: r4 };
3788
+ function tr(r4, e) {
3789
+ return e === "Resource" && V(r4) && (e = r4.resourceType), { type: e, value: r4 };
3724
3790
  }
3725
- function Bn(r4, e) {
3791
+ function Nn(r4, e) {
3726
3792
  let t = r4.value;
3727
3793
  if (!t || typeof t != "object")
3728
3794
  return;
@@ -3745,7 +3811,7 @@ function Re(r4) {
3745
3811
  for (let t of r4) {
3746
3812
  let n = false;
3747
3813
  for (let i2 of e)
3748
- if (N(fr(t, i2))) {
3814
+ if (N(or(t, i2))) {
3749
3815
  n = true;
3750
3816
  break;
3751
3817
  }
@@ -3753,24 +3819,24 @@ function Re(r4) {
3753
3819
  }
3754
3820
  return e;
3755
3821
  }
3756
- function pt(r4) {
3822
+ function st(r4) {
3757
3823
  return l(!N(r4));
3758
3824
  }
3759
- function ft(r4, e) {
3760
- return r4.length === 0 || e.length === 0 ? [] : r4.length !== e.length ? l(false) : l(r4.every((t, n) => N(fr(t, e[n]))));
3825
+ function at(r4, e) {
3826
+ return r4.length === 0 || e.length === 0 ? [] : r4.length !== e.length ? l(false) : l(r4.every((t, n) => N(or(t, e[n]))));
3761
3827
  }
3762
- function fr(r4, e) {
3828
+ function or(r4, e) {
3763
3829
  let t = r4.value?.valueOf(), n = e.value?.valueOf();
3764
- return typeof t == "number" && typeof n == "number" ? l(Math.abs(t - n) < 1e-8) : R(t) && R(n) ? l(mr(t, n)) : l(typeof t == "object" && typeof n == "object" ? ht(r4, e) : t === n);
3830
+ return typeof t == "number" && typeof n == "number" ? l(Math.abs(t - n) < 1e-8) : R(t) && R(n) ? l(sr(t, n)) : l(typeof t == "object" && typeof n == "object" ? ut(r4, e) : t === n);
3765
3831
  }
3766
- function mt(r4, e) {
3767
- return r4.length === 0 && e.length === 0 ? l(true) : r4.length !== e.length ? l(false) : (r4.sort(lr), e.sort(lr), l(r4.every((t, n) => N(qn(t, e[n])))));
3832
+ function ct(r4, e) {
3833
+ return r4.length === 0 && e.length === 0 ? l(true) : r4.length !== e.length ? l(false) : (r4.sort(rr), e.sort(rr), l(r4.every((t, n) => N(Mn(t, e[n])))));
3768
3834
  }
3769
- function qn(r4, e) {
3835
+ function Mn(r4, e) {
3770
3836
  let { type: t, value: n } = r4, { type: i2, value: o } = e, s = n?.valueOf(), a = o?.valueOf();
3771
- return typeof s == "number" && typeof a == "number" ? l(Math.abs(s - a) < 0.01) : R(s) && R(a) ? l(mr(s, a)) : l(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" ? ht({ ...s, id: void 0 }, { ...a, id: void 0 }) : typeof s == "string" && typeof a == "string" ? s.toLowerCase() === a.toLowerCase() : s === a);
3837
+ return typeof s == "number" && typeof a == "number" ? l(Math.abs(s - a) < 0.01) : R(s) && R(a) ? l(sr(s, a)) : l(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" ? ut({ ...s, id: void 0 }, { ...a, id: void 0 }) : typeof s == "string" && typeof a == "string" ? s.toLowerCase() === a.toLowerCase() : s === a);
3772
3838
  }
3773
- function lr(r4, e) {
3839
+ function rr(r4, e) {
3774
3840
  let t = r4.value?.valueOf(), n = e.value?.valueOf();
3775
3841
  return typeof t == "number" && typeof n == "number" ? t - n : typeof t == "string" && typeof n == "string" ? t.localeCompare(n) : 0;
3776
3842
  }
@@ -3791,46 +3857,84 @@ function Ee(r4, e) {
3791
3857
  case "Time":
3792
3858
  return typeof t == "string" && !!/^T\d/.exec(t);
3793
3859
  case "Period":
3794
- return $n(t);
3860
+ return Bn(t);
3795
3861
  case "Quantity":
3796
3862
  return R(t);
3797
3863
  default:
3798
3864
  return typeof t == "object" && t?.resourceType === e;
3799
3865
  }
3800
3866
  }
3801
- function $n(r4) {
3867
+ function Bn(r4) {
3802
3868
  return !!(r4 && typeof r4 == "object" && "start" in r4);
3803
3869
  }
3804
3870
  function R(r4) {
3805
3871
  return !!(r4 && typeof r4 == "object" && "value" in r4 && typeof r4.value == "number");
3806
3872
  }
3807
- function mr(r4, e) {
3873
+ function sr(r4, e) {
3808
3874
  return Math.abs(r4.value - e.value) < 0.01 && (r4.unit === e.unit || r4.code === e.code || r4.unit === e.code || r4.code === e.unit);
3809
3875
  }
3810
- function ht(r4, e) {
3876
+ function ut(r4, e) {
3811
3877
  let t = Object.keys(r4), n = Object.keys(e);
3812
3878
  if (t.length !== n.length)
3813
3879
  return false;
3814
3880
  for (let i2 of t) {
3815
3881
  let o = r4[i2], s = e[i2];
3816
- if (dr(o) && dr(s)) {
3817
- if (!ht(o, s))
3882
+ if (nr(o) && nr(s)) {
3883
+ if (!ut(o, s))
3818
3884
  return false;
3819
3885
  } else if (o !== s)
3820
3886
  return false;
3821
3887
  }
3822
3888
  return true;
3823
3889
  }
3824
- function dr(r4) {
3890
+ function nr(r4) {
3825
3891
  return r4 !== null && typeof r4 == "object";
3826
3892
  }
3827
- function pr(r4, e) {
3893
+ function ir(r4, e) {
3828
3894
  return delete e.__proto__, delete e.constructor, Object.assign(r4, e);
3829
3895
  }
3830
- function Tt(r4) {
3831
- return new gt(r4).parse();
3896
+ var lt = "ok";
3897
+ var Pe = "created";
3898
+ var pt = "not-modified";
3899
+ var ft = "not-found";
3900
+ var Ce = "accepted";
3901
+ var lr = { resourceType: "OperationOutcome", id: ft, issue: [{ severity: "error", code: "not-found", details: { text: "Not found" } }] };
3902
+ function _(r4, e) {
3903
+ return { resourceType: "OperationOutcome", issue: [{ severity: "error", code: "invalid", details: { text: r4 }, expression: e ? [e] : void 0 }] };
3904
+ }
3905
+ function h(r4) {
3906
+ return { resourceType: "OperationOutcome", issue: [{ severity: "error", code: "structure", details: { text: r4 } }] };
3907
+ }
3908
+ function we(r4) {
3909
+ return typeof r4 == "object" && r4 !== null && r4.resourceType === "OperationOutcome";
3910
+ }
3911
+ function mt(r4) {
3912
+ return r4.id === lt || r4.id === Pe || r4.id === pt || r4.id === Ce;
3913
+ }
3914
+ var d = class extends Error {
3915
+ constructor(t, n) {
3916
+ super(pr(t));
3917
+ this.outcome = t, this.cause = n;
3918
+ }
3919
+ };
3920
+ function ht(r4) {
3921
+ return r4 instanceof d ? r4.outcome : we(r4) ? r4 : _(qn(r4));
3922
+ }
3923
+ function qn(r4) {
3924
+ return r4 ? typeof r4 == "string" ? r4 : r4 instanceof Error ? r4.message : we(r4) ? pr(r4) : typeof r4 == "object" && "code" in r4 && typeof r4.code == "string" ? r4.code : JSON.stringify(r4) : "Unknown error";
3832
3925
  }
3833
- var j = ar(cr);
3926
+ function pr(r4) {
3927
+ let e = r4.issue?.map($n) ?? [];
3928
+ return e.length > 0 ? e.join("; ") : "Unknown error";
3929
+ }
3930
+ function $n(r4) {
3931
+ let e;
3932
+ return r4.details?.text ? r4.diagnostics ? e = `${r4.details.text} (${r4.diagnostics})` : e = r4.details.text : r4.diagnostics ? e = r4.diagnostics : e = "Unknown error", r4.expression?.length && (e += ` (${r4.expression.join(", ")})`), e;
3933
+ }
3934
+ function vt(r4) {
3935
+ return new xt(r4).parse();
3936
+ }
3937
+ var H = Zt(er);
3834
3938
  function xr(r4) {
3835
3939
  let e = Array.isArray(r4) ? r4 : r4.entry?.map((t) => t.resource) ?? [];
3836
3940
  for (let t of e)
@@ -3841,18 +3945,18 @@ function jn(r4) {
3841
3945
  throw new Error("Failed loading StructureDefinition from bundle");
3842
3946
  if (r4.resourceType !== "StructureDefinition")
3843
3947
  return;
3844
- let e = Tt(r4);
3845
- j[r4.name] = e;
3948
+ let e = vt(r4);
3949
+ H[r4.name] = e;
3846
3950
  for (let t of e.innerTypes)
3847
- t.parentType = e, j[t.name] = t;
3951
+ t.parentType = e, H[t.name] = t;
3848
3952
  }
3849
3953
  function vr(r4) {
3850
- return !!j[r4];
3954
+ return !!H[r4];
3851
3955
  }
3852
3956
  function Sr(r4) {
3853
- return j[r4];
3957
+ return H[r4];
3854
3958
  }
3855
- var gt = class {
3959
+ var xt = class {
3856
3960
  constructor(e) {
3857
3961
  if (!e.snapshot?.element || e.snapshot.element.length === 0)
3858
3962
  throw new Error(`No snapshot defined for StructureDefinition '${e.name}'`);
@@ -3865,7 +3969,7 @@ var gt = class {
3865
3969
  this.parseSliceStart(e);
3866
3970
  else if (e.id?.includes(":")) {
3867
3971
  if (this.slicingContext?.current) {
3868
- let t = yt(e, this.slicingContext.path);
3972
+ let t = gt(e, this.slicingContext.path);
3869
3973
  this.slicingContext.current.elements[t] = this.parseElementDefinition(e);
3870
3974
  }
3871
3975
  } else {
@@ -3874,13 +3978,13 @@ var gt = class {
3874
3978
  let n = this.backboneContext;
3875
3979
  for (; n; ) {
3876
3980
  if (e.path?.startsWith(n.path + ".")) {
3877
- n.type.elements[yt(e, n.path)] = t;
3981
+ n.type.elements[gt(e, n.path)] = t;
3878
3982
  break;
3879
3983
  }
3880
3984
  n = n.parent;
3881
3985
  }
3882
3986
  if (!n) {
3883
- let i2 = yt(e, this.root.path);
3987
+ let i2 = gt(e, this.root.path);
3884
3988
  e.isSummary && this.resourceSchema.summaryProperties?.add(i2.replace("[x]", "")), t.min > 0 && this.resourceSchema.mandatoryProperties?.add(i2.replace("[x]", "")), this.resourceSchema.elements[i2] = t;
3885
3989
  }
3886
3990
  this.checkFieldExit(e);
@@ -3895,7 +3999,7 @@ var gt = class {
3895
3999
  enterInnerType(e) {
3896
4000
  for (; this.backboneContext && !ee(this.backboneContext?.path, e.path); )
3897
4001
  this.innerTypes.push(this.backboneContext.type), this.backboneContext = this.backboneContext.parent;
3898
- this.backboneContext = { type: { name: xt(e), description: e.definition, elements: {}, constraints: this.parseElementDefinition(e).constraints, innerTypes: [] }, path: e.path ?? "", parent: ee(this.backboneContext?.path, e.path) ? this.backboneContext : this.backboneContext?.parent };
4002
+ this.backboneContext = { type: { name: Tt(e), description: e.definition, elements: {}, constraints: this.parseElementDefinition(e).constraints, innerTypes: [] }, path: e.path ?? "", parent: ee(this.backboneContext?.path, e.path) ? this.backboneContext : this.backboneContext?.parent };
3899
4003
  }
3900
4004
  enterSlice(e, t) {
3901
4005
  Wn(e) && !this.peek()?.sliceName || (t.slicing = { discriminator: (e.slicing?.discriminator ?? []).map((n) => {
@@ -3940,13 +4044,13 @@ var gt = class {
3940
4044
  }
3941
4045
  parseElementDefinition(e) {
3942
4046
  let t = yr(e.max), n = e.base?.max ? yr(e.base.max) : t, i2 = { type: "ElementDefinition", value: e };
3943
- 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: (e.type ?? []).map((o) => ({ code: ["BackboneElement", "Element"].includes(o.code) ? xt(e) : o.code ?? "", targetProfile: o.targetProfile })), fixed: gr(w(i2, "fixed")), pattern: gr(w(i2, "pattern")), binding: e.binding };
4047
+ 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: (e.type ?? []).map((o) => ({ code: ["BackboneElement", "Element"].includes(o.code) ? Tt(e) : o.code ?? "", targetProfile: o.targetProfile })), fixed: gr(w(i2, "fixed")), pattern: gr(w(i2, "pattern")), binding: e.binding };
3944
4048
  }
3945
4049
  };
3946
4050
  function yr(r4) {
3947
4051
  return r4 === "*" ? Number.POSITIVE_INFINITY : Number.parseInt(r4, 10);
3948
4052
  }
3949
- function yt(r4, e = "") {
4053
+ function gt(r4, e = "") {
3950
4054
  return Qn(r4.path, e);
3951
4055
  }
3952
4056
  function Qn(r4, e) {
@@ -3963,13 +4067,13 @@ function Wn(r4) {
3963
4067
  return !!(r4.type?.some((t) => t.code === "Extension") && e?.length === 1 && e[0].type === "value" && e[0].path === "url");
3964
4068
  }
3965
4069
  var u = { 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" };
3966
- function St(r4) {
4070
+ function bt(r4) {
3967
4071
  for (let e of r4.base ?? []) {
3968
4072
  let t = I.types[e];
3969
4073
  t || (t = { searchParamsDetails: {} }, I.types[e] = t), t.searchParams || (t.searchParams = { _id: { base: [e], code: "_id", type: "token", expression: e + ".id" }, _lastUpdated: { base: [e], code: "_lastUpdated", type: "date", expression: e + ".meta.lastUpdated" }, _compartment: { base: [e], code: "_compartment", type: "reference", expression: e + ".meta.compartment" }, _profile: { base: [e], code: "_profile", type: "uri", expression: e + ".meta.profile" }, _security: { base: [e], code: "_security", type: "token", expression: e + ".meta.security" }, _source: { base: [e], code: "_source", type: "uri", expression: e + ".meta.source" }, _tag: { base: [e], code: "_tag", type: "token", expression: e + ".meta.tag" } }), t.searchParams[r4.code] = r4;
3970
4074
  }
3971
4075
  }
3972
- function xt(r4) {
4076
+ function Tt(r4) {
3973
4077
  let e = r4.type?.[0]?.code;
3974
4078
  return e === "BackboneElement" || e === "Element" ? Gn((r4.base?.path ?? r4.path)?.split(".")) : e;
3975
4079
  }
@@ -3981,107 +4085,10 @@ function Ae(r4, e) {
3981
4085
  if (t)
3982
4086
  return t.elements[e] ?? t.elements[e + "[x]"];
3983
4087
  }
3984
- function _(r4) {
4088
+ function V(r4) {
3985
4089
  return !!(r4 && typeof r4 == "object" && "resourceType" in r4);
3986
4090
  }
3987
4091
  var I = { types: {} };
3988
- var Pe = class {
3989
- constructor(e, t) {
3990
- this.operator = e;
3991
- this.child = t;
3992
- }
3993
- toString() {
3994
- return `${this.operator}(${this.child.toString()})`;
3995
- }
3996
- };
3997
- var H = class {
3998
- constructor(e, t, n) {
3999
- this.operator = e;
4000
- this.left = t;
4001
- this.right = n;
4002
- }
4003
- toString() {
4004
- return `${this.left.toString()} ${this.operator} ${this.right.toString()}`;
4005
- }
4006
- };
4007
- var Ce = class {
4008
- constructor() {
4009
- this.prefixParselets = {};
4010
- this.infixParselets = {};
4011
- }
4012
- registerInfix(e, t) {
4013
- return this.infixParselets[e] = t, this;
4014
- }
4015
- registerPrefix(e, t) {
4016
- return this.prefixParselets[e] = t, this;
4017
- }
4018
- prefix(e, t, n) {
4019
- return this.registerPrefix(e, { parse(i2, o) {
4020
- let s = i2.consumeAndParse(t);
4021
- return n(o, s);
4022
- } });
4023
- }
4024
- infixLeft(e, t, n) {
4025
- return this.registerInfix(e, { parse(i2, o, s) {
4026
- let a = i2.consumeAndParse(t);
4027
- return n(o, s, a);
4028
- }, precedence: t });
4029
- }
4030
- construct(e) {
4031
- return new bt(e, this.prefixParselets, this.infixParselets);
4032
- }
4033
- };
4034
- var bt = class {
4035
- constructor(e, t, n) {
4036
- this.tokens = e, this.prefixParselets = t, this.infixParselets = n;
4037
- }
4038
- hasMore() {
4039
- return this.tokens.length > 0;
4040
- }
4041
- match(e) {
4042
- return this.peek()?.id !== e ? false : (this.consume(), true);
4043
- }
4044
- consumeAndParse(e = 1 / 0) {
4045
- let t = this.consume(), n = this.prefixParselets[t.id];
4046
- if (!n)
4047
- throw Error(`Parse error at "${t.value}" (line ${t.line}, column ${t.column}). No matching prefix parselet.`);
4048
- let i2 = n.parse(this, t);
4049
- for (; e > this.getPrecedence(); ) {
4050
- let o = this.consume();
4051
- i2 = this.getInfixParselet(o).parse(this, i2, o);
4052
- }
4053
- return i2;
4054
- }
4055
- getPrecedence() {
4056
- let e = this.peek();
4057
- if (!e)
4058
- return 1 / 0;
4059
- let t = this.getInfixParselet(e);
4060
- return t ? t.precedence : 1 / 0;
4061
- }
4062
- consume(e, t) {
4063
- if (!this.tokens.length)
4064
- throw Error("Cant consume unknown more tokens.");
4065
- if (e && this.peek()?.id !== e) {
4066
- let n = this.peek();
4067
- throw Error(`Expected ${e} but got "${n.id}" at line ${n.line} column ${n.column}.`);
4068
- }
4069
- if (t && this.peek()?.value !== t) {
4070
- let n = this.peek();
4071
- throw Error(`Expected "${t}" but got "${n.value}" at line ${n.line} column ${n.column}.`);
4072
- }
4073
- return this.tokens.shift();
4074
- }
4075
- peek() {
4076
- return this.tokens.length > 0 ? this.tokens[0] : void 0;
4077
- }
4078
- removeComments() {
4079
- this.tokens = this.tokens.filter((e) => e.id !== "Comment");
4080
- }
4081
- getInfixParselet(e) {
4082
- return this.infixParselets[e.id === "Symbol" ? e.value : e.id];
4083
- }
4084
- };
4085
4092
  function re(r4) {
4086
4093
  if (r4.startsWith("T"))
4087
4094
  return r4 + "T00:00:00.000Z".substring(r4.length);
@@ -4255,7 +4262,7 @@ var S = { empty: (r4, e) => l(e.length === 0), exists: (r4, e, t) => t ? l(e.fil
4255
4262
  return { type: o, value: { resourceType: o, id: s } };
4256
4263
  }
4257
4264
  return { type: u.BackboneElement, value: void 0 };
4258
- }).filter((t) => !!t.value), as: (r4, e) => e, type: (r4, e) => e.map(({ value: t }) => typeof t == "boolean" ? { type: u.BackboneElement, value: { namespace: "System", name: "Boolean" } } : typeof t == "number" ? { type: u.BackboneElement, value: { namespace: "System", name: "Integer" } } : _(t) ? { type: u.BackboneElement, value: { namespace: "FHIR", name: t.resourceType } } : { type: u.BackboneElement, value: null }), conformsTo: (r4, e, t) => {
4265
+ }).filter((t) => !!t.value), as: (r4, e) => e, type: (r4, e) => e.map(({ value: t }) => typeof t == "boolean" ? { type: u.BackboneElement, value: { namespace: "System", name: "Boolean" } } : typeof t == "number" ? { type: u.BackboneElement, value: { namespace: "System", name: "Integer" } } : V(t) ? { type: u.BackboneElement, value: { namespace: "FHIR", name: t.resourceType } } : { type: u.BackboneElement, value: null }), conformsTo: (r4, e, t) => {
4259
4266
  let n = t.eval(r4, e)[0].value;
4260
4267
  if (!n.startsWith("http://hl7.org/fhir/StructureDefinition/"))
4261
4268
  throw new Error("Expected a StructureDefinition URL");
@@ -4318,13 +4325,13 @@ var M = class {
4318
4325
  evalValue(e) {
4319
4326
  let t = e.value;
4320
4327
  if (!(!t || typeof t != "object"))
4321
- return _(t) && t.resourceType === this.name ? e : w(e, this.name);
4328
+ return V(t) && t.resourceType === this.name ? e : w(e, this.name);
4322
4329
  }
4323
4330
  toString() {
4324
4331
  return this.name;
4325
4332
  }
4326
4333
  };
4327
- var Ie = class {
4334
+ var ke = class {
4328
4335
  eval() {
4329
4336
  return [];
4330
4337
  }
@@ -4332,7 +4339,7 @@ var Ie = class {
4332
4339
  return "{}";
4333
4340
  }
4334
4341
  };
4335
- var ke = class extends Pe {
4342
+ var Oe = class extends he {
4336
4343
  constructor(t, n, i2) {
4337
4344
  super(t, n);
4338
4345
  this.impl = i2;
@@ -4344,7 +4351,7 @@ var ke = class extends Pe {
4344
4351
  return this.operator + this.child.toString();
4345
4352
  }
4346
4353
  };
4347
- var J = class extends H {
4354
+ var J = class extends $ {
4348
4355
  constructor(e, t) {
4349
4356
  super("as", e, t);
4350
4357
  }
@@ -4352,7 +4359,7 @@ var J = class extends H {
4352
4359
  return S.ofType(e, this.left.eval(e, t), this.right);
4353
4360
  }
4354
4361
  };
4355
- var v = class extends H {
4362
+ var v = class extends $ {
4356
4363
  };
4357
4364
  var E = class extends v {
4358
4365
  constructor(t, n, i2, o) {
@@ -4370,7 +4377,7 @@ var E = class extends v {
4370
4377
  return typeof p2 == "boolean" ? l(p2) : R(s) ? [{ type: u.Quantity, value: { ...s, value: p2 } }] : [T(p2)];
4371
4378
  }
4372
4379
  };
4373
- var Oe = class extends H {
4380
+ var De = class extends $ {
4374
4381
  constructor(e, t) {
4375
4382
  super("&", e, t);
4376
4383
  }
@@ -4379,7 +4386,7 @@ var Oe = class extends H {
4379
4386
  return o.length > 0 && o.every((s) => typeof s.value == "string") ? [{ type: u.string, value: o.map((s) => s.value).join("") }] : o;
4380
4387
  }
4381
4388
  };
4382
- var De = class extends v {
4389
+ var Ve = class extends v {
4383
4390
  constructor(e, t) {
4384
4391
  super("contains", e, t);
4385
4392
  }
@@ -4388,16 +4395,16 @@ var De = class extends v {
4388
4395
  return l(n.some((o) => o.value === i2[0].value));
4389
4396
  }
4390
4397
  };
4391
- var Ve = class extends v {
4398
+ var _e = class extends v {
4392
4399
  constructor(e, t) {
4393
4400
  super("in", e, t);
4394
4401
  }
4395
4402
  eval(e, t) {
4396
- let n = V(this.left.eval(e, t)), i2 = this.right.eval(e, t);
4403
+ let n = D(this.left.eval(e, t)), i2 = this.right.eval(e, t);
4397
4404
  return n ? l(i2.some((o) => o.value === n.value)) : [];
4398
4405
  }
4399
4406
  };
4400
- var Q = class extends H {
4407
+ var Q = class extends $ {
4401
4408
  constructor(e, t) {
4402
4409
  super(".", e, t);
4403
4410
  }
@@ -4408,7 +4415,7 @@ var Q = class extends H {
4408
4415
  return `${this.left.toString()}.${this.right.toString()}`;
4409
4416
  }
4410
4417
  };
4411
- var ne = class extends H {
4418
+ var ne = class extends $ {
4412
4419
  constructor(e, t) {
4413
4420
  super("|", e, t);
4414
4421
  }
@@ -4417,40 +4424,40 @@ var ne = class extends H {
4417
4424
  return Re([...n, ...i2]);
4418
4425
  }
4419
4426
  };
4420
- var _e = class extends v {
4427
+ var Ue = class extends v {
4421
4428
  constructor(e, t) {
4422
4429
  super("=", e, t);
4423
4430
  }
4424
4431
  eval(e, t) {
4425
4432
  let n = this.left.eval(e, t), i2 = this.right.eval(e, t);
4426
- return ft(n, i2);
4433
+ return at(n, i2);
4427
4434
  }
4428
4435
  };
4429
- var Ue = class extends v {
4436
+ var Le = class extends v {
4430
4437
  constructor(e, t) {
4431
4438
  super("!=", e, t);
4432
4439
  }
4433
4440
  eval(e, t) {
4434
4441
  let n = this.left.eval(e, t), i2 = this.right.eval(e, t);
4435
- return pt(ft(n, i2));
4442
+ return st(at(n, i2));
4436
4443
  }
4437
4444
  };
4438
- var Le = class extends v {
4445
+ var Fe = class extends v {
4439
4446
  constructor(e, t) {
4440
4447
  super("~", e, t);
4441
4448
  }
4442
4449
  eval(e, t) {
4443
4450
  let n = this.left.eval(e, t), i2 = this.right.eval(e, t);
4444
- return mt(n, i2);
4451
+ return ct(n, i2);
4445
4452
  }
4446
4453
  };
4447
- var Fe = class extends v {
4454
+ var Ne = class extends v {
4448
4455
  constructor(e, t) {
4449
4456
  super("!~", e, t);
4450
4457
  }
4451
4458
  eval(e, t) {
4452
4459
  let n = this.left.eval(e, t), i2 = this.right.eval(e, t);
4453
- return pt(mt(n, i2));
4460
+ return st(ct(n, i2));
4454
4461
  }
4455
4462
  };
4456
4463
  var Y = class extends v {
@@ -4465,39 +4472,39 @@ var Y = class extends v {
4465
4472
  return l(Ee(n[0], i2));
4466
4473
  }
4467
4474
  };
4468
- var Ne = class extends v {
4475
+ var Me = class extends v {
4469
4476
  constructor(e, t) {
4470
4477
  super("and", e, t);
4471
4478
  }
4472
4479
  eval(e, t) {
4473
- let n = V(this.left.eval(e, t), "boolean"), i2 = V(this.right.eval(e, t), "boolean");
4480
+ let n = D(this.left.eval(e, t), "boolean"), i2 = D(this.right.eval(e, t), "boolean");
4474
4481
  return n?.value === true && i2?.value === true ? l(true) : n?.value === false || i2?.value === false ? l(false) : [];
4475
4482
  }
4476
4483
  };
4477
- var Me = class extends v {
4484
+ var Be = class extends v {
4478
4485
  constructor(e, t) {
4479
4486
  super("or", e, t);
4480
4487
  }
4481
4488
  eval(e, t) {
4482
- let n = V(this.left.eval(e, t), "boolean"), i2 = V(this.right.eval(e, t), "boolean");
4489
+ let n = D(this.left.eval(e, t), "boolean"), i2 = D(this.right.eval(e, t), "boolean");
4483
4490
  return n?.value === false && i2?.value === false ? l(false) : n?.value || i2?.value ? l(true) : [];
4484
4491
  }
4485
4492
  };
4486
- var Be = class extends v {
4493
+ var qe = class extends v {
4487
4494
  constructor(e, t) {
4488
4495
  super("xor", e, t);
4489
4496
  }
4490
4497
  eval(e, t) {
4491
- let n = V(this.left.eval(e, t), "boolean"), i2 = V(this.right.eval(e, t), "boolean");
4498
+ let n = D(this.left.eval(e, t), "boolean"), i2 = D(this.right.eval(e, t), "boolean");
4492
4499
  return !n || !i2 ? [] : l(n.value !== i2.value);
4493
4500
  }
4494
4501
  };
4495
- var qe = class extends v {
4502
+ var $e = class extends v {
4496
4503
  constructor(e, t) {
4497
4504
  super("implies", e, t);
4498
4505
  }
4499
4506
  eval(e, t) {
4500
- let n = V(this.left.eval(e, t), "boolean"), i2 = V(this.right.eval(e, t), "boolean");
4507
+ let n = D(this.left.eval(e, t), "boolean"), i2 = D(this.right.eval(e, t), "boolean");
4501
4508
  return i2?.value === true || n?.value === false ? l(true) : !n || !i2 ? [] : l(false);
4502
4509
  }
4503
4510
  };
@@ -4562,11 +4569,11 @@ function ti(r4) {
4562
4569
  return n?.startsWith("'") && n.endsWith("'") ? n = n.substring(1, n.length - 1) : n = "{" + n + "}", { value: t, unit: n };
4563
4570
  }
4564
4571
  function ue() {
4565
- return new Ce().registerPrefix("String", { parse: (r4, e) => new k({ type: u.string, value: e.value }) }).registerPrefix("DateTime", { parse: (r4, e) => new k({ type: u.dateTime, value: re(e.value) }) }).registerPrefix("Quantity", { parse: (r4, e) => new k({ type: u.Quantity, value: ti(e.value) }) }).registerPrefix("Number", { parse: (r4, e) => new k({ type: u.decimal, value: parseFloat(e.value) }) }).registerPrefix("true", { parse: () => new k({ type: u.boolean, value: true }) }).registerPrefix("false", { parse: () => new k({ type: u.boolean, value: false }) }).registerPrefix("Symbol", { parse: (r4, e) => new M(e.value) }).registerPrefix("{}", { parse: () => new Ie() }).registerPrefix("(", Xn).registerInfix("[", Zn).registerInfix("(", ei).prefix("+", f.UnaryAdd, (r4, e) => new ke("+", e, (t) => t)).prefix("-", f.UnarySubtract, (r4, e) => new E("-", e, e, (t, n) => -n)).infixLeft(".", f.Dot, (r4, e, t) => new Q(r4, t)).infixLeft("/", f.Divide, (r4, e, t) => new E("/", r4, t, (n, i2) => n / i2)).infixLeft("*", f.Multiply, (r4, e, t) => new E("*", r4, t, (n, i2) => n * i2)).infixLeft("+", f.Add, (r4, e, t) => new E("+", r4, t, (n, i2) => n + i2)).infixLeft("-", f.Subtract, (r4, e, t) => new E("-", r4, t, (n, i2) => n - i2)).infixLeft("|", f.Union, (r4, e, t) => new ne(r4, t)).infixLeft("=", f.Equals, (r4, e, t) => new _e(r4, t)).infixLeft("!=", f.NotEquals, (r4, e, t) => new Ue(r4, t)).infixLeft("~", f.Equivalent, (r4, e, t) => new Le(r4, t)).infixLeft("!~", f.NotEquivalent, (r4, e, t) => new Fe(r4, t)).infixLeft("<", f.LessThan, (r4, e, t) => new E("<", r4, t, (n, i2) => n < i2)).infixLeft("<=", f.LessThanOrEquals, (r4, e, t) => new E("<=", r4, t, (n, i2) => n <= i2)).infixLeft(">", f.GreaterThan, (r4, e, t) => new E(">", r4, t, (n, i2) => n > i2)).infixLeft(">=", f.GreaterThanOrEquals, (r4, e, t) => new E(">=", r4, t, (n, i2) => n >= i2)).infixLeft("&", f.Ampersand, (r4, e, t) => new Oe(r4, t)).infixLeft("and", f.And, (r4, e, t) => new Ne(r4, t)).infixLeft("as", f.As, (r4, e, t) => new J(r4, t)).infixLeft("contains", f.Contains, (r4, e, t) => new De(r4, t)).infixLeft("div", f.Divide, (r4, e, t) => new E("div", r4, t, (n, i2) => n / i2 | 0)).infixLeft("in", f.In, (r4, e, t) => new Ve(r4, t)).infixLeft("is", f.Is, (r4, e, t) => new Y(r4, t)).infixLeft("mod", f.Modulo, (r4, e, t) => new E("mod", r4, t, (n, i2) => n % i2)).infixLeft("or", f.Or, (r4, e, t) => new Me(r4, t)).infixLeft("xor", f.Xor, (r4, e, t) => new Be(r4, t)).infixLeft("implies", f.Implies, (r4, e, t) => new qe(r4, t));
4572
+ return new ye().registerPrefix("String", { parse: (r4, e) => new k({ type: u.string, value: e.value }) }).registerPrefix("DateTime", { parse: (r4, e) => new k({ type: u.dateTime, value: re(e.value) }) }).registerPrefix("Quantity", { parse: (r4, e) => new k({ type: u.Quantity, value: ti(e.value) }) }).registerPrefix("Number", { parse: (r4, e) => new k({ type: u.decimal, value: parseFloat(e.value) }) }).registerPrefix("true", { parse: () => new k({ type: u.boolean, value: true }) }).registerPrefix("false", { parse: () => new k({ type: u.boolean, value: false }) }).registerPrefix("Symbol", { parse: (r4, e) => new M(e.value) }).registerPrefix("{}", { parse: () => new ke() }).registerPrefix("(", Xn).registerInfix("[", Zn).registerInfix("(", ei).prefix("+", f.UnaryAdd, (r4, e) => new Oe("+", e, (t) => t)).prefix("-", f.UnarySubtract, (r4, e) => new E("-", e, e, (t, n) => -n)).infixLeft(".", f.Dot, (r4, e, t) => new Q(r4, t)).infixLeft("/", f.Divide, (r4, e, t) => new E("/", r4, t, (n, i2) => n / i2)).infixLeft("*", f.Multiply, (r4, e, t) => new E("*", r4, t, (n, i2) => n * i2)).infixLeft("+", f.Add, (r4, e, t) => new E("+", r4, t, (n, i2) => n + i2)).infixLeft("-", f.Subtract, (r4, e, t) => new E("-", r4, t, (n, i2) => n - i2)).infixLeft("|", f.Union, (r4, e, t) => new ne(r4, t)).infixLeft("=", f.Equals, (r4, e, t) => new Ue(r4, t)).infixLeft("!=", f.NotEquals, (r4, e, t) => new Le(r4, t)).infixLeft("~", f.Equivalent, (r4, e, t) => new Fe(r4, t)).infixLeft("!~", f.NotEquivalent, (r4, e, t) => new Ne(r4, t)).infixLeft("<", f.LessThan, (r4, e, t) => new E("<", r4, t, (n, i2) => n < i2)).infixLeft("<=", f.LessThanOrEquals, (r4, e, t) => new E("<=", r4, t, (n, i2) => n <= i2)).infixLeft(">", f.GreaterThan, (r4, e, t) => new E(">", r4, t, (n, i2) => n > i2)).infixLeft(">=", f.GreaterThanOrEquals, (r4, e, t) => new E(">=", r4, t, (n, i2) => n >= i2)).infixLeft("&", f.Ampersand, (r4, e, t) => new De(r4, t)).infixLeft("and", f.And, (r4, e, t) => new Me(r4, t)).infixLeft("as", f.As, (r4, e, t) => new J(r4, t)).infixLeft("contains", f.Contains, (r4, e, t) => new Ve(r4, t)).infixLeft("div", f.Divide, (r4, e, t) => new E("div", r4, t, (n, i2) => n / i2 | 0)).infixLeft("in", f.In, (r4, e, t) => new _e(r4, t)).infixLeft("is", f.Is, (r4, e, t) => new Y(r4, t)).infixLeft("mod", f.Modulo, (r4, e, t) => new E("mod", r4, t, (n, i2) => n % i2)).infixLeft("or", f.Or, (r4, e, t) => new Be(r4, t)).infixLeft("xor", f.Xor, (r4, e, t) => new qe(r4, t)).infixLeft("implies", f.Implies, (r4, e, t) => new $e(r4, t));
4566
4573
  }
4567
4574
  var ri = ue();
4568
- var ni = ((g) => (g.EQUALS = "eq", g.NOT_EQUALS = "ne", g.GREATER_THAN = "gt", g.LESS_THAN = "lt", g.GREATER_THAN_OR_EQUALS = "ge", g.LESS_THAN_OR_EQUALS = "le", g.STARTS_AFTER = "sa", g.ENDS_BEFORE = "eb", g.APPROXIMATELY = "ap", g.CONTAINS = "contains", g.EXACT = "exact", g.TEXT = "text", g.NOT = "not", g.ABOVE = "above", g.BELOW = "below", g.IN = "in", g.NOT_IN = "not-in", g.OF_TYPE = "of-type", g.MISSING = "missing", g.IDENTIFIER = "identifier", g.ITERATE = "iterate", g))(ni || {});
4569
- var Dr = ((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))(Dr || {});
4575
+ var Cr = ((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))(Cr || {});
4576
+ var ui = ((g2) => (g2.EQUALS = "eq", g2.NOT_EQUALS = "ne", g2.GREATER_THAN = "gt", g2.LESS_THAN = "lt", g2.GREATER_THAN_OR_EQUALS = "ge", g2.LESS_THAN_OR_EQUALS = "le", g2.STARTS_AFTER = "sa", g2.ENDS_BEFORE = "eb", g2.APPROXIMATELY = "ap", g2.CONTAINS = "contains", g2.EXACT = "exact", g2.TEXT = "text", g2.NOT = "not", g2.ABOVE = "above", g2.BELOW = "below", g2.IN = "in", g2.NOT_IN = "not-in", g2.OF_TYPE = "of-type", g2.MISSING = "missing", g2.IDENTIFIER = "identifier", g2.ITERATE = "iterate", g2))(ui || {});
4570
4577
  var ki = ((x) => (x.READ = "read", x.VREAD = "vread", x.UPDATE = "update", x.PATCH = "patch", x.DELETE = "delete", x.HISTORY = "history", x.HISTORY_INSTANCE = "history-instance", x.HISTORY_TYPE = "history-type", x.HISTORY_SYSTEM = "history-system", x.CREATE = "create", x.SEARCH = "search", x.SEARCH_TYPE = "search-type", x.SEARCH_SYSTEM = "search-system", x.SEARCH_COMPARTMENT = "search-compartment", x.CAPABILITIES = "capabilities", x.TRANSACTION = "transaction", x.BATCH = "batch", x.OPERATION = "operation", x))(ki || {});
4571
4578
  function Mr(r4) {
4572
4579
  if (typeof window < "u")
@@ -4584,7 +4591,7 @@ function Br(r4) {
4584
4591
  }
4585
4592
  function It() {
4586
4593
  let r4 = new Uint32Array(28);
4587
- return crypto.getRandomValues(r4), rr(r4.buffer);
4594
+ return crypto.getRandomValues(r4), Kt(r4.buffer);
4588
4595
  }
4589
4596
  async function qr(r4) {
4590
4597
  return crypto.subtle.digest("SHA-256", new TextEncoder().encode(r4));
@@ -4595,7 +4602,7 @@ function pe() {
4595
4602
  return (r4 === "x" ? e : e & 3 | 8).toString(16);
4596
4603
  });
4597
4604
  }
4598
- var He = class {
4605
+ var Qe = class {
4599
4606
  constructor(e = 10) {
4600
4607
  this.max = e, this.cache = /* @__PURE__ */ new Map();
4601
4608
  }
@@ -4645,7 +4652,7 @@ var fe = class {
4645
4652
  return !e.defaultPrevented;
4646
4653
  }
4647
4654
  };
4648
- var Qe = class {
4655
+ var We = class {
4649
4656
  constructor() {
4650
4657
  this.emitter = new fe();
4651
4658
  }
@@ -4671,12 +4678,12 @@ function jr(r4) {
4671
4678
  return !!r4.endpoint;
4672
4679
  }
4673
4680
  function Ot(r4) {
4674
- if (!Ge(r4))
4681
+ if (!Ke(r4))
4675
4682
  throw new d(h("subscriptionRequest must be an object conforming to SubscriptionRequest type."));
4676
4683
  let { channelType: e, mode: t, topic: n, events: i2 } = r4, o = { "hub.channel.type": e, "hub.mode": t, "hub.topic": n, "hub.events": i2.join(",") };
4677
4684
  return jr(r4) && (o.endpoint = r4.endpoint), new URLSearchParams(o).toString();
4678
4685
  }
4679
- function Ge(r4) {
4686
+ function Ke(r4) {
4680
4687
  if (typeof r4 != "object")
4681
4688
  return false;
4682
4689
  let { channelType: e, mode: t, topic: n, events: i2 } = r4;
@@ -4723,12 +4730,12 @@ function Hr(r4, e, t) {
4723
4730
  let n = Array.isArray(t) ? t : [t];
4724
4731
  return Qi(e, n), { timestamp: (/* @__PURE__ */ new Date()).toISOString(), id: pe(), event: { "hub.topic": r4, "hub.event": e, context: n } };
4725
4732
  }
4726
- var We = class extends Qe {
4733
+ var Ge = class extends We {
4727
4734
  constructor(t) {
4728
4735
  super();
4729
4736
  if (this.subRequest = t, !t.endpoint)
4730
4737
  throw new d(h("Subscription request should contain an endpoint."));
4731
- if (!Ge(t))
4738
+ if (!Ke(t))
4732
4739
  throw new d(h("Subscription request failed validation."));
4733
4740
  let n = new WebSocket(t.endpoint);
4734
4741
  n.addEventListener("open", () => {
@@ -4804,7 +4811,7 @@ var C = class {
4804
4811
  }
4805
4812
  };
4806
4813
  Gi = Symbol.toStringTag;
4807
- var Ke = class {
4814
+ var ze = class {
4808
4815
  constructor() {
4809
4816
  this.storage = typeof localStorage < "u" ? localStorage : new Vt();
4810
4817
  }
@@ -4822,7 +4829,7 @@ var Ke = class {
4822
4829
  return t ? JSON.parse(t) : void 0;
4823
4830
  }
4824
4831
  setObject(e, t) {
4825
- this.setString(e, t ? Zt(t) : void 0);
4832
+ this.setString(e, t ? Qt(t) : void 0);
4826
4833
  }
4827
4834
  };
4828
4835
  var Vt = class {
@@ -4848,22 +4855,27 @@ var Vt = class {
4848
4855
  return Array.from(this.data.keys())[e];
4849
4856
  }
4850
4857
  };
4851
- var Ki = "https://api.medplum.com/";
4852
- var zi = 1e3;
4853
- var Ji = 6e4;
4858
+ var Ki = F.FHIR_JSON + ", */*; q=0.1";
4859
+ var zi = "https://api.medplum.com/";
4860
+ var Ji = 1e3;
4861
+ var Yi = 6e4;
4854
4862
  var Gr = "Binary/";
4855
4863
  var Kr = { resourceType: "Device", id: "system", deviceName: [{ name: "System" }] };
4856
- var Yi = ((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))(Yi || {});
4857
- var Xi = ((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))(Xi || {});
4858
- var Zi = ((e) => (e.JwtBearer = "urn:ietf:params:oauth:client-assertion-type:jwt-bearer", e))(Zi || {});
4864
+ var Xi = ((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))(Xi || {});
4865
+ var Zi = ((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))(Zi || {});
4866
+ var eo = ((e) => (e.JwtBearer = "urn:ietf:params:oauth:client-assertion-type:jwt-bearer", e))(eo || {});
4859
4867
  var zr = class extends fe {
4860
4868
  constructor(t) {
4861
4869
  super();
4862
4870
  if (t?.baseUrl && !t.baseUrl.startsWith("http"))
4863
4871
  throw new Error("Base URL must start with http or https");
4864
- this.options = t ?? {}, this.fetch = t?.fetch ?? eo(), this.storage = t?.storage ?? new Ke(), this.createPdfImpl = t?.createPdf, this.baseUrl = Yr(t?.baseUrl ?? Ki), this.fhirBaseUrl = Yr(ze(this.baseUrl, t?.fhirUrlPath ?? "fhir/R4/")), this.authorizeUrl = ze(this.baseUrl, t?.authorizeUrl ?? "oauth2/authorize"), this.tokenUrl = ze(this.baseUrl, t?.tokenUrl ?? "oauth2/token"), this.logoutUrl = ze(this.baseUrl, t?.logoutUrl ?? "oauth2/logout"), this.clientId = t?.clientId ?? "", this.clientSecret = t?.clientSecret ?? "", this.onUnauthenticated = t?.onUnauthenticated, this.cacheTime = t?.cacheTime ?? Ji, this.cacheTime > 0 ? this.requestCache = new He(t?.resourceCacheSize ?? zi) : this.requestCache = void 0, t?.autoBatchTime ? (this.autoBatchTime = t.autoBatchTime, this.autoBatchQueue = []) : (this.autoBatchTime = 0, this.autoBatchQueue = void 0);
4865
- let n = this.getActiveLogin();
4866
- n && (this.setAccessToken(n.accessToken, n.refreshToken), this.refreshProfile().catch(console.log)), this.setupStorageListener();
4872
+ if (this.options = t ?? {}, this.fetch = t?.fetch ?? to(), this.storage = t?.storage ?? new ze(), this.createPdfImpl = t?.createPdf, this.baseUrl = Yr(t?.baseUrl ?? zi), this.fhirBaseUrl = Yr(Je(this.baseUrl, t?.fhirUrlPath ?? "fhir/R4/")), this.authorizeUrl = Je(this.baseUrl, t?.authorizeUrl ?? "oauth2/authorize"), this.tokenUrl = Je(this.baseUrl, t?.tokenUrl ?? "oauth2/token"), this.logoutUrl = Je(this.baseUrl, t?.logoutUrl ?? "oauth2/logout"), this.clientId = t?.clientId ?? "", this.clientSecret = t?.clientSecret ?? "", this.onUnauthenticated = t?.onUnauthenticated, this.cacheTime = t?.cacheTime ?? Yi, this.cacheTime > 0 ? this.requestCache = new Qe(t?.resourceCacheSize ?? Ji) : this.requestCache = void 0, t?.autoBatchTime ? (this.autoBatchTime = t.autoBatchTime, this.autoBatchQueue = []) : (this.autoBatchTime = 0, this.autoBatchQueue = void 0), t?.accessToken)
4873
+ this.setAccessToken(t.accessToken);
4874
+ else {
4875
+ let n = this.getActiveLogin();
4876
+ n && (this.setAccessToken(n.accessToken, n.refreshToken), this.refreshProfile().catch(console.log));
4877
+ }
4878
+ this.setupStorageListener();
4867
4879
  }
4868
4880
  getBaseUrl() {
4869
4881
  return this.baseUrl;
@@ -5091,7 +5103,7 @@ var zr = class extends fe {
5091
5103
  }`.replace(/\s+/g, " "), a = await this.graphql(s);
5092
5104
  xr(a.data.StructureDefinitionList);
5093
5105
  for (let c2 of a.data.SearchParameterList)
5094
- St(c2);
5106
+ bt(c2);
5095
5107
  })());
5096
5108
  return this.setCacheEntry(n, o), o;
5097
5109
  }
@@ -5242,7 +5254,7 @@ var zr = class extends fe {
5242
5254
  }
5243
5255
  async uploadMedia(t, n, i2, o, s) {
5244
5256
  let a = await this.createBinary(t, i2, n);
5245
- return this.createResource({ ...o, resourceType: "Media", content: { contentType: n, url: Gr + a.id, title: i2 } }, s);
5257
+ return this.createResource({ resourceType: "Media", status: "completed", content: { contentType: n, url: Gr + a.id, title: i2 }, ...o }, s);
5246
5258
  }
5247
5259
  async bulkExport(t = "", n, i2, o) {
5248
5260
  let s = t && `${t}/`, a = this.fhirUrl(`${s}$export`);
@@ -5288,7 +5300,7 @@ var zr = class extends fe {
5288
5300
  return;
5289
5301
  let a = t.headers.get("content-type")?.includes("json");
5290
5302
  if (t.status === 404 && !a)
5291
- throw new d(Ht);
5303
+ throw new d(lr);
5292
5304
  let c2 = t.headers.get("content-location"), m2 = o.redirect ?? this.options.redirect;
5293
5305
  if (t.status === 201 && c2 && m2 === "follow")
5294
5306
  return this.request("GET", c2, { ...o, body: void 0 });
@@ -5302,7 +5314,7 @@ var zr = class extends fe {
5302
5314
  else
5303
5315
  p2 = await t.text();
5304
5316
  if (t.status >= 400)
5305
- throw new d(ot(p2));
5317
+ throw new d(ht(p2));
5306
5318
  return p2;
5307
5319
  }
5308
5320
  async fetchWithRetry(t, n) {
@@ -5315,7 +5327,7 @@ var zr = class extends fe {
5315
5327
  } catch (c2) {
5316
5328
  this.retryCatch(a, i2, c2);
5317
5329
  }
5318
- await ut(o);
5330
+ await nt(o);
5319
5331
  }
5320
5332
  return s;
5321
5333
  }
@@ -5339,7 +5351,7 @@ var zr = class extends fe {
5339
5351
  let c2 = await Xr(a);
5340
5352
  c2 && (i2 = await this.fetchWithRetry(c2, s));
5341
5353
  }
5342
- await ut(o);
5354
+ await nt(o);
5343
5355
  }
5344
5356
  return this.parseResponse(i2, "POST", t);
5345
5357
  }
@@ -5350,19 +5362,19 @@ var zr = class extends fe {
5350
5362
  try {
5351
5363
  o.resolve(await this.request(o.method, this.fhirBaseUrl + o.url, o.options));
5352
5364
  } catch (s) {
5353
- o.reject(new d(ot(s)));
5365
+ o.reject(new d(ht(s)));
5354
5366
  }
5355
5367
  return;
5356
5368
  }
5357
5369
  let n = { resourceType: "Bundle", type: "batch", entry: t.map((o) => ({ request: { method: o.method, url: o.url }, resource: o.options.body ? JSON.parse(o.options.body) : void 0 })) }, i2 = await this.post(this.fhirBaseUrl.slice(0, -1), n);
5358
5370
  for (let o = 0; o < t.length; o++) {
5359
5371
  let s = t[o], a = i2.entry?.[o];
5360
- a?.response?.outcome && !it(a.response.outcome) ? s.reject(new d(a.response.outcome)) : s.resolve(a?.resource);
5372
+ a?.response?.outcome && !mt(a.response.outcome) ? s.reject(new d(a.response.outcome)) : s.resolve(a?.resource);
5361
5373
  }
5362
5374
  }
5363
5375
  addFetchOptionsDefaults(t) {
5364
5376
  let n = t.headers;
5365
- n || (n = {}, t.headers = n), n.Accept = F.FHIR_JSON, n["X-Medplum"] = "extended", t.body && !n["Content-Type"] && (n["Content-Type"] = F.FHIR_JSON), this.accessToken ? n.Authorization = "Bearer " + this.accessToken : this.basicAuth && (n.Authorization = "Basic " + this.basicAuth), t.cache || (t.cache = "no-cache"), t.credentials || (t.credentials = "include");
5377
+ n || (n = {}, t.headers = n), n.Accept || (n.Accept = Ki), n["X-Medplum"] = "extended", t.body && !n["Content-Type"] && (n["Content-Type"] = F.FHIR_JSON), this.accessToken ? n.Authorization = "Bearer " + this.accessToken : this.basicAuth && (n.Authorization = "Basic " + this.basicAuth), t.cache || (t.cache = "no-cache"), t.credentials || (t.credentials = "include");
5366
5378
  }
5367
5379
  setRequestContentType(t, n) {
5368
5380
  t.headers || (t.headers = {});
@@ -5380,7 +5392,7 @@ var zr = class extends fe {
5380
5392
  sessionStorage.setItem("pkceState", t);
5381
5393
  let n = It();
5382
5394
  sessionStorage.setItem("codeVerifier", n);
5383
- let i2 = await qr(n), o = nr(i2).replaceAll("+", "-").replaceAll("/", "_").replaceAll("=", "");
5395
+ let i2 = await qr(n), o = zt(i2).replaceAll("+", "-").replaceAll("/", "_").replaceAll("=", "");
5384
5396
  return sessionStorage.setItem("codeChallenge", o), { codeChallengeMethod: "S256", codeChallenge: o };
5385
5397
  }
5386
5398
  async requestAuthorization(t) {
@@ -5433,14 +5445,14 @@ var zr = class extends fe {
5433
5445
  return i2.endpoint = s, i2;
5434
5446
  }
5435
5447
  async fhircastUnsubscribe(t) {
5436
- if (!Ge(t))
5448
+ if (!Ke(t))
5437
5449
  throw new d(h("Invalid topic or subscriptionRequest. SubscriptionRequest must be an object."));
5438
5450
  if (!(t.endpoint && typeof t.endpoint == "string" && t.endpoint.startsWith("ws")))
5439
5451
  throw new d(h("Provided subscription request must have an endpoint in order to unsubscribe."));
5440
5452
  t.mode = "unsubscribe", await this.post("/fhircast/STU2", Ot(t), F.FORM_URL_ENCODED);
5441
5453
  }
5442
5454
  fhircastConnect(t) {
5443
- return new We(t);
5455
+ return new Ge(t);
5444
5456
  }
5445
5457
  async fhircastPublish(t, n, i2) {
5446
5458
  return this.post(`/fhircast/STU2/${t}`, Hr(t, n, i2), F.JSON);
@@ -5456,9 +5468,9 @@ var zr = class extends fe {
5456
5468
  this.clearActiveLogin();
5457
5469
  try {
5458
5470
  let a = await o.json();
5459
- throw new d(O(a.error_description));
5471
+ throw new d(_(a.error_description));
5460
5472
  } catch (a) {
5461
- throw new d(O("Failed to fetch tokens"), a);
5473
+ throw new d(_("Failed to fetch tokens"), a);
5462
5474
  }
5463
5475
  }
5464
5476
  let s = await o.json();
@@ -5491,7 +5503,7 @@ var zr = class extends fe {
5491
5503
  throw i2;
5492
5504
  }
5493
5505
  };
5494
- function eo() {
5506
+ function to() {
5495
5507
  if (!globalThis.fetch)
5496
5508
  throw new Error("Fetch not available in this environment");
5497
5509
  return globalThis.fetch.bind(globalThis);
@@ -5502,7 +5514,7 @@ function Jr() {
5502
5514
  function Yr(r4) {
5503
5515
  return r4.endsWith("/") ? r4 : r4 + "/";
5504
5516
  }
5505
- function ze(r4, e) {
5517
+ function Je(r4, e) {
5506
5518
  return new URL(e, r4).toString();
5507
5519
  }
5508
5520
  async function Xr(r4) {
@@ -5513,17 +5525,17 @@ async function Xr(r4) {
5513
5525
  if (t)
5514
5526
  return t;
5515
5527
  let n = await r4.json();
5516
- if (ye(n) && n.issue?.[0]?.diagnostics)
5528
+ if (we(n) && n.issue?.[0]?.diagnostics)
5517
5529
  return n.issue[0].diagnostics;
5518
5530
  }
5519
5531
  function Zr(r4) {
5520
5532
  let e = r4.entry?.map((t) => t.resource) ?? [];
5521
5533
  return Object.assign(e, { bundle: r4 });
5522
5534
  }
5523
- var to = [...ce, "->", "<<", ">>"];
5524
- var ro = ue().registerInfix("->", { precedence: f.Arrow }).registerInfix(";", { precedence: f.Semicolon });
5525
- var no = [...ce, "eq", "ne", "co"];
5526
- var so = ue();
5535
+ var ro = [...ce, "->", "<<", ">>"];
5536
+ var no = ue().registerInfix("->", { precedence: f.Arrow }).registerInfix(";", { precedence: f.Semicolon });
5537
+ var io = [...ce, "eq", "ne", "co"];
5538
+ var ao = ue();
5527
5539
  var G = class {
5528
5540
  constructor(e = "\r", t = "|", n = "^", i2 = "~", o = "\\", s = "&") {
5529
5541
  this.segmentSeparator = e;
@@ -5564,7 +5576,7 @@ var nn = class r {
5564
5576
  }
5565
5577
  buildAck() {
5566
5578
  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";
5567
- return new r([new me(["MSH", this.context.getMsh2(), o, s, n, i2, co(e), "", this.buildAckMessageType(t), e.getTime().toString(), "P", c2], this.context), new me(["MSA", "AA", a, "OK"], this.context)]);
5579
+ return new r([new me(["MSH", this.context.getMsh2(), o, s, n, i2, uo(e), "", this.buildAckMessageType(t), e.getTime().toString(), "P", c2], this.context), new me(["MSA", "AA", a, "OK"], this.context)]);
5568
5580
  }
5569
5581
  buildAckMessageType(e) {
5570
5582
  let t = e?.getField(9), n = t?.getComponent(2), i2 = t?.getComponent(3), o = "ACK";
@@ -5581,7 +5593,7 @@ var nn = class r {
5581
5593
  };
5582
5594
  var me = class r2 {
5583
5595
  constructor(e, t = new G()) {
5584
- this.context = t, er(e) ? this.fields = e.map((n) => oe.parse(n, t)) : this.fields = e, this.name = this.fields[0].components[0][0];
5596
+ this.context = t, Wt(e) ? this.fields = e.map((n) => oe.parse(n, t)) : this.fields = e, this.name = this.fields[0].components[0][0];
5585
5597
  }
5586
5598
  get(e) {
5587
5599
  return this.fields[e];
@@ -5625,13 +5637,14 @@ var oe = class r3 {
5625
5637
  return new r3(e.split(t.repetitionSeparator).map((n) => n.split(t.componentSeparator)), t);
5626
5638
  }
5627
5639
  };
5628
- function co(r4) {
5640
+ function uo(r4) {
5629
5641
  let e = r4 instanceof Date ? r4 : new Date(r4), n = e.toISOString().replace(/[-:T]/g, "").replace(/(\.\d+)?Z$/, ""), i2 = e.getUTCMilliseconds();
5630
5642
  return i2 > 0 && (n += "." + i2.toString()), n;
5631
5643
  }
5632
5644
 
5633
5645
  // ../hl7/dist/esm/index.mjs
5634
- var import_net = __toESM(require("net"), 1);
5646
+ var import_net = require("net");
5647
+ var import_net2 = __toESM(require("net"), 1);
5635
5648
  var i = class extends EventTarget {
5636
5649
  addEventListener(n, e, t) {
5637
5650
  super.addEventListener(n, e, t);
@@ -5691,12 +5704,34 @@ var c = class extends i {
5691
5704
  this.socket.end(), this.socket.destroy();
5692
5705
  }
5693
5706
  };
5707
+ var h2 = class extends i {
5708
+ constructor(e) {
5709
+ super();
5710
+ this.options = e, this.host = this.options.host, this.port = this.options.port;
5711
+ }
5712
+ connect() {
5713
+ return this.connection ? Promise.resolve(this.connection) : new Promise((e) => {
5714
+ let t = (0, import_net.connect)({ host: this.host, port: this.port }, () => {
5715
+ this.connection = new c(t), e(this.connection);
5716
+ });
5717
+ });
5718
+ }
5719
+ async send(e) {
5720
+ return (await this.connect()).send(e);
5721
+ }
5722
+ async sendAndWait(e) {
5723
+ return (await this.connect()).sendAndWait(e);
5724
+ }
5725
+ close() {
5726
+ this.connection && (this.connection.close(), delete this.connection);
5727
+ }
5728
+ };
5694
5729
  var E2 = class {
5695
5730
  constructor(n) {
5696
5731
  this.handler = n;
5697
5732
  }
5698
5733
  start(n, e) {
5699
- let t = import_net.default.createServer((o) => {
5734
+ let t = import_net2.default.createServer((o) => {
5700
5735
  let s = new c(o, e);
5701
5736
  this.handler(s);
5702
5737
  });
@@ -5720,80 +5755,28 @@ var App = class {
5720
5755
  constructor(medplum, agentId) {
5721
5756
  this.medplum = medplum;
5722
5757
  this.agentId = agentId;
5758
+ this.webSocketQueue = [];
5759
+ this.channels = /* @__PURE__ */ new Map();
5760
+ this.hl7Queue = [];
5761
+ this.live = false;
5723
5762
  this.log = {
5724
5763
  info: console.log,
5725
5764
  warn: console.warn,
5726
5765
  error: console.error
5727
5766
  };
5728
- this.channels = [];
5729
- }
5730
- async start() {
5731
- this.log.info("Medplum service starting...");
5732
- const agent = await this.medplum.readResource("Agent", this.agentId);
5733
- for (const definition of agent.channel) {
5734
- const endpoint = await this.medplum.readReference(definition.endpoint);
5735
- const channel = new AgentHl7Channel(this, definition, endpoint);
5736
- channel.start();
5737
- this.channels.push(channel);
5738
- }
5739
- this.log.info("Medplum service started successfully");
5740
- }
5741
- stop() {
5742
- this.log.info("Medplum service stopping...");
5743
- this.channels.forEach((channel) => channel.stop());
5744
- this.log.info("Medplum service stopped successfully");
5745
- }
5746
- };
5747
- var AgentHl7Channel = class {
5748
- constructor(app, definition, endpoint) {
5749
- this.app = app;
5750
- this.definition = definition;
5751
- this.endpoint = endpoint;
5752
- this.connections = [];
5753
- this.server = new E2((connection) => {
5754
- this.app.log.info("HL7 connection established");
5755
- this.connections.push(new AgentHl7ChannelConnection(this, connection));
5756
- });
5757
- }
5758
- start() {
5759
- const address = new URL(this.endpoint.address);
5760
- this.app.log.info(`Channel starting on ${address}`);
5761
- this.server.start(parseInt(address.port, 10));
5762
- this.app.log.info("Channel started successfully");
5763
- }
5764
- stop() {
5765
- this.app.log.info("Channel stopping...");
5766
- for (const connection of this.connections) {
5767
- connection.close();
5768
- }
5769
- this.server.stop();
5770
- this.app.log.info("Channel stopped successfully");
5771
- }
5772
- };
5773
- var AgentHl7ChannelConnection = class {
5774
- constructor(channel, hl7Connection) {
5775
- this.channel = channel;
5776
- this.hl7Connection = hl7Connection;
5777
- this.webSocketQueue = [];
5778
- this.hl7ConnectionQueue = [];
5779
- this.live = false;
5780
- const app = channel.app;
5781
- const medplum = app.medplum;
5782
- this.hl7Connection.addEventListener("message", (event) => this.handler(event));
5783
5767
  const webSocketUrl = new URL(medplum.getBaseUrl());
5784
5768
  webSocketUrl.protocol = webSocketUrl.protocol === "https:" ? "wss:" : "ws:";
5785
5769
  webSocketUrl.pathname = "/ws/agent";
5786
- console.log("Connecting to WebSocket:", webSocketUrl.href);
5770
+ this.log.info(`Connecting to WebSocket: ${webSocketUrl.href}`);
5787
5771
  this.webSocket = new wrapper_default(webSocketUrl);
5788
5772
  this.webSocket.binaryType = "nodebuffer";
5789
- this.webSocket.addEventListener("error", console.error);
5773
+ this.webSocket.addEventListener("error", (err) => this.log.error(err.message));
5790
5774
  this.webSocket.addEventListener("open", () => {
5791
5775
  this.webSocket.send(
5792
5776
  JSON.stringify({
5793
5777
  type: "connect",
5794
5778
  accessToken: medplum.getAccessToken(),
5795
- agentId: channel.app.agentId,
5796
- botId: _o(channel.definition.targetReference)
5779
+ agentId
5797
5780
  })
5798
5781
  );
5799
5782
  });
@@ -5801,7 +5784,7 @@ var AgentHl7ChannelConnection = class {
5801
5784
  try {
5802
5785
  const data = e.data;
5803
5786
  const str = data.toString("utf8");
5804
- console.log("Received from WebSocket:", str.replaceAll("\r", "\n"));
5787
+ this.log.info(`Received from WebSocket: ${str.replaceAll("\r", "\n")}`);
5805
5788
  const command = JSON.parse(str);
5806
5789
  switch (command.type) {
5807
5790
  case "connected":
@@ -5809,24 +5792,40 @@ var AgentHl7ChannelConnection = class {
5809
5792
  this.trySendToWebSocket();
5810
5793
  break;
5811
5794
  case "transmit":
5812
- this.hl7ConnectionQueue.push(nn.parse(command.message));
5813
- this.trySendToHl7Connection();
5795
+ this.addToHl7Queue(command);
5796
+ break;
5797
+ case "push":
5798
+ this.pushMessage(command);
5814
5799
  break;
5815
5800
  }
5816
5801
  } catch (err) {
5817
- console.log("WebSocket error", err);
5802
+ this.log.error(`WebSocket error: ${qn(err)}`);
5818
5803
  }
5819
5804
  });
5820
5805
  }
5821
- async handler(event) {
5822
- try {
5823
- console.log("Received:");
5824
- console.log(event.message.toString().replaceAll("\r", "\n"));
5825
- this.webSocketQueue.push(event.message);
5826
- this.trySendToWebSocket();
5827
- } catch (err) {
5828
- console.log("HL7 error", err);
5806
+ async start() {
5807
+ this.log.info("Medplum service starting...");
5808
+ const agent = await this.medplum.readResource("Agent", this.agentId);
5809
+ for (const definition of agent.channel) {
5810
+ const endpoint = await this.medplum.readReference(definition.endpoint);
5811
+ const channel = new AgentHl7Channel(this, definition, endpoint);
5812
+ channel.start();
5813
+ this.channels.set(definition.name, channel);
5829
5814
  }
5815
+ this.log.info("Medplum service started successfully");
5816
+ }
5817
+ stop() {
5818
+ this.log.info("Medplum service stopping...");
5819
+ this.channels.forEach((channel) => channel.stop());
5820
+ this.log.info("Medplum service stopped successfully");
5821
+ }
5822
+ addToWebSocketQueue(message) {
5823
+ this.webSocketQueue.push(message);
5824
+ this.trySendToWebSocket();
5825
+ }
5826
+ addToHl7Queue(message) {
5827
+ this.hl7Queue.push(message);
5828
+ this.trySendToHl7Connection();
5830
5829
  }
5831
5830
  trySendToWebSocket() {
5832
5831
  if (this.live) {
@@ -5836,8 +5835,8 @@ var AgentHl7ChannelConnection = class {
5836
5835
  this.webSocket.send(
5837
5836
  JSON.stringify({
5838
5837
  type: "transmit",
5839
- forwardedFor: this.hl7Connection.socket.remoteAddress,
5840
- message: msg.toString()
5838
+ accessToken: this.medplum.getAccessToken(),
5839
+ ...msg
5841
5840
  })
5842
5841
  );
5843
5842
  }
@@ -5845,16 +5844,82 @@ var AgentHl7ChannelConnection = class {
5845
5844
  }
5846
5845
  }
5847
5846
  trySendToHl7Connection() {
5848
- while (this.hl7ConnectionQueue.length > 0) {
5849
- const msg = this.hl7ConnectionQueue.shift();
5847
+ while (this.hl7Queue.length > 0) {
5848
+ const msg = this.hl7Queue.shift();
5850
5849
  if (msg) {
5851
- this.hl7Connection.send(msg);
5850
+ const channel = this.channels.get(msg.channel);
5851
+ if (channel) {
5852
+ const connection = channel.connections.get(msg.remote);
5853
+ if (connection) {
5854
+ connection.hl7Connection.send(nn.parse(msg.body));
5855
+ }
5856
+ }
5852
5857
  }
5853
5858
  }
5854
5859
  }
5860
+ pushMessage(message) {
5861
+ const address = new URL(message.remote);
5862
+ const client = new h2({
5863
+ host: address.hostname,
5864
+ port: parseInt(address.port, 10)
5865
+ });
5866
+ client.sendAndWait(nn.parse(message.body)).then((response) => {
5867
+ this.log.info(`Response: ${response.toString().replaceAll("\r", "\n")}`);
5868
+ }).catch((err) => {
5869
+ this.log.error(`HL7 error: ${qn(err)}`);
5870
+ }).finally(() => {
5871
+ client.close();
5872
+ });
5873
+ }
5874
+ };
5875
+ var AgentHl7Channel = class {
5876
+ constructor(app, definition, endpoint) {
5877
+ this.app = app;
5878
+ this.definition = definition;
5879
+ this.endpoint = endpoint;
5880
+ this.connections = /* @__PURE__ */ new Map();
5881
+ this.server = new E2((connection) => this.handleNewConnection(connection));
5882
+ }
5883
+ start() {
5884
+ const address = new URL(this.endpoint.address);
5885
+ this.app.log.info(`Channel starting on ${address}`);
5886
+ this.server.start(parseInt(address.port, 10));
5887
+ this.app.log.info("Channel started successfully");
5888
+ }
5889
+ stop() {
5890
+ this.app.log.info("Channel stopping...");
5891
+ this.connections.forEach((connection) => connection.close());
5892
+ this.server.stop();
5893
+ this.app.log.info("Channel stopped successfully");
5894
+ }
5895
+ handleNewConnection(connection) {
5896
+ const c2 = new AgentHl7ChannelConnection(this, connection);
5897
+ this.app.log.info(`HL7 connection established: ${c2.remote}`);
5898
+ this.connections.set(c2.remote, c2);
5899
+ }
5900
+ };
5901
+ var AgentHl7ChannelConnection = class {
5902
+ constructor(channel, hl7Connection) {
5903
+ this.channel = channel;
5904
+ this.hl7Connection = hl7Connection;
5905
+ this.remote = `${hl7Connection.socket.remoteAddress}:${hl7Connection.socket.remotePort}`;
5906
+ this.hl7Connection.addEventListener("message", (event) => this.handler(event));
5907
+ }
5908
+ async handler(event) {
5909
+ try {
5910
+ this.channel.app.log.info("Received:");
5911
+ this.channel.app.log.info(event.message.toString().replaceAll("\r", "\n"));
5912
+ this.channel.app.addToWebSocketQueue({
5913
+ channel: this.channel.definition.name,
5914
+ remote: this.remote,
5915
+ body: event.message.toString()
5916
+ });
5917
+ } catch (err) {
5918
+ this.channel.app.log.error(`HL7 error: ${qn(err)}`);
5919
+ }
5920
+ }
5855
5921
  close() {
5856
5922
  this.hl7Connection.close();
5857
- this.webSocket.close();
5858
5923
  }
5859
5924
  };
5860
5925
  if (typeof require !== "undefined" && require.main === module) {