@medplum/agent 2.0.30 → 2.0.32

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.
@@ -30,1483 +30,6 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
30
30
  ));
31
31
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
32
32
 
33
- // ../../node_modules/node-windows/lib/binaries.js
34
- var require_binaries = __commonJS({
35
- "../../node_modules/node-windows/lib/binaries.js"(exports, module2) {
36
- "use strict";
37
- var path = require("path");
38
- var bin = path.join(__dirname, "..", "bin");
39
- var exec = require("child_process").exec;
40
- var params = function(options, callback2) {
41
- callback2 = callback2 || function() {
42
- };
43
- options = options || {};
44
- if (typeof options === "function") {
45
- callback2 = options;
46
- options = {};
47
- }
48
- if (typeof options !== "object") {
49
- throw "Invalid options parameter.";
50
- }
51
- return { options, callback: callback2 };
52
- };
53
- module2.exports = {
54
- /**
55
- * @method elevate
56
- * @member nodewindows
57
- * Elevate is similar to `sudo` on Linux/Mac. It attempts to elevate the privileges of the
58
- * current user to a local administrator. Using this does not require a password, but it
59
- * does require that the current user have administrative privileges. Without these
60
- * privileges, the command will fail with a `access denied` error.
61
- *
62
- * On systems with UAC enabled, this may prompt the user for permission to proceed:
63
- *
64
- * ![UAC Prompt](http://upload.wikimedia.org/wikipedia/en/5/51/Windows_7_UAC.png)
65
- *
66
- * **Syntax**:
67
- *
68
- * `elevate(cmd[,options,callback])`
69
- *
70
- * @param {String} cmd
71
- * The command to execute with elevated privileges. This can be any string that would be typed at the command line.
72
- * @param {Object} [options]
73
- * Any options that will be passed to `require('child_process').exec(cmd,<OPTIONS>,callback)`.
74
- * @param {Function} callback
75
- * The callback function passed to `require('child_process').exec(cmd,options,<CALLBACK>)`.
76
- */
77
- elevate: function(cmd, options, callback2) {
78
- var p2 = params(options, callback2);
79
- exec('"' + path.join(bin, "elevate", "elevate.cmd") + '" ' + cmd, p2.options, p2.callback);
80
- },
81
- /**
82
- * @method sudo
83
- * @member nodewindows
84
- * Sudo acts similarly to `sudo` on Linux/Mac. Unlike _elevate_, it requires a password, but it
85
- * will not prompt the user for permission to proceed. Like _elevate_, this
86
- * _still requires administrative privileges_ for the user, otherwise the command will fail.
87
- * The primary difference between this and _elevate()_ is the prompt.
88
- *
89
- * **Syntax**:
90
- *
91
- * `sudo(cmd,password[,options,callback])`
92
- *
93
- * @param {String} cmd
94
- * The command to execute with elevated privileges. This can be any string that would be typed at the command line.
95
- * @param {String} password
96
- * The password of the user
97
- * @param {Object} [options]
98
- * Any options that will be passed to `require('child_process').exec(cmd,<OPTIONS>,callback)`.
99
- * @param {Function} [callback]
100
- * The callback function passed to `require('child_process').exec(cmd,options,<CALLBACK>)`.
101
- */
102
- sudo: function(cmd, password, options, callback2) {
103
- password = password || "";
104
- if (typeof password !== "string") {
105
- callback2 = options;
106
- options = password;
107
- password = "";
108
- }
109
- var p2 = params(options, callback2);
110
- exec(path.join(bin, "sudowin", "sudo.exe") + " " + (password !== "" ? "-p " + password : "") + cmd, p2.options, p2.callback);
111
- }
112
- };
113
- }
114
- });
115
-
116
- // ../../node_modules/node-windows/lib/cmd.js
117
- var require_cmd = __commonJS({
118
- "../../node_modules/node-windows/lib/cmd.js"(exports, module2) {
119
- "use strict";
120
- var exec = require("child_process").exec;
121
- var bin = require_binaries();
122
- module2.exports = {
123
- /**
124
- * @method isAdminUser
125
- * @member nodewindows
126
- * This asynchronous command determines whether the current user has administrative privileges.
127
- * It passes a boolean value to the callback, returning `true` if the user is an administrator
128
- * or `false` if it is not.
129
- * @param {Function} callback
130
- * @param {Boolean} callback.isAdmin
131
- * Receives true/false as an argument to the callback.
132
- */
133
- isAdminUser: function(callback2) {
134
- exec("NET SESSION", function(err, so, se2) {
135
- if (se2.length !== 0) {
136
- bin.elevate("NET SESSION", function(_err, _so, _se) {
137
- callback2(_se.length === 0);
138
- });
139
- } else {
140
- callback2(true);
141
- }
142
- });
143
- },
144
- /**
145
- * @method kill
146
- * @member nodewindows
147
- * Kill a specific process
148
- * @param {Number} PID
149
- * Process ID
150
- * @param {Boolean} [force=false]
151
- * Force close the process.
152
- * @param {Function} [callback]
153
- */
154
- kill: function(pid, force, callback2) {
155
- if (!pid) {
156
- throw new Error("PID is required for the kill operation.");
157
- }
158
- if (typeof isNaN(pid)) {
159
- throw new Error("PID must be a number.");
160
- }
161
- callback2 = callback2 || function() {
162
- };
163
- if (typeof force == "function") {
164
- callback2 = force;
165
- force = false;
166
- }
167
- exec("taskkill /PID " + pid + (force == true ? " /f" : ""), callback2);
168
- },
169
- /**
170
- * @method list
171
- * @member nodewindows
172
- * List the processes running on the server.
173
- * @param {Function} callback
174
- * Receives the process object as the only callback argument
175
- * @param {Boolean} [verbose=false]
176
- */
177
- list: function(callback2, verbose) {
178
- verbose = typeof verbose == "boolean" ? verbose : false;
179
- exec("tasklist /FO CSV" + (verbose == true ? " /V" : ""), function(err, stdout, stderr) {
180
- var p2 = stdout.split("\r\n");
181
- var proc = [];
182
- var head = null;
183
- while (p2.length > 1) {
184
- var rec = p2.shift();
185
- rec = rec.replace(/\"\,/gi, '";').replace(/\"|\'/gi, "").split(";");
186
- if (head == null) {
187
- head = rec;
188
- for (var i2 = 0; i2 < head.length; i2++) {
189
- head[i2] = head[i2].replace(/ /gi, "");
190
- }
191
- } else {
192
- var tmp = {};
193
- for (var i2 = 0; i2 < rec.length; i2++) {
194
- tmp[head[i2]] = rec[i2].replace(/\"|\'/gi, "");
195
- }
196
- proc.push(tmp);
197
- }
198
- }
199
- callback2(proc);
200
- });
201
- }
202
- };
203
- }
204
- });
205
-
206
- // ../../node_modules/node-windows/lib/eventlog.js
207
- var require_eventlog = __commonJS({
208
- "../../node_modules/node-windows/lib/eventlog.js"(exports, module2) {
209
- "use strict";
210
- var wincmd = require_binaries();
211
- var exec = require("child_process").exec;
212
- var eventlogs = ["APPLICATION", "SYSTEM"];
213
- var validtypes = ["ERROR", "WARNING", "INFORMATION", "SUCCESSAUDIT", "FAILUREAUDIT"];
214
- var write = function(log, src, type, msg, id, callback2) {
215
- var cmd;
216
- if (msg == null) {
217
- return;
218
- }
219
- ;
220
- if (msg.trim().length == 0) {
221
- return;
222
- }
223
- ;
224
- msg = msg.replace(/\r\n|\n\r|\r|\n/g, "\f");
225
- log = log || "APPLICATION";
226
- log = eventlogs.indexOf(log.toUpperCase()) >= 0 ? log : "APPLICATION";
227
- type = (type || "INFORMATION").trim().toUpperCase();
228
- type = (validtypes.indexOf(type.trim().toUpperCase()) >= 0 ? type : "INFORMATION").trim().toUpperCase();
229
- id = typeof id == "number" ? id > 0 ? id : 1e3 : 1e3;
230
- src = (src || "Unknown Application").trim();
231
- cmd = "eventcreate /L " + log + " /T " + type + ' /SO "' + src + '" /D "' + msg + '" /ID ' + id;
232
- exec(cmd, function(err) {
233
- if (err && err.message.indexOf("Access is Denied")) {
234
- wincmd.elevate(cmd, callback2);
235
- } else if (callback2) {
236
- callback2(err);
237
- }
238
- });
239
- };
240
- var logger = function(config) {
241
- config = config || {};
242
- if (typeof config == "string") {
243
- config = {
244
- source: config
245
- };
246
- }
247
- Object.defineProperties(this, {
248
- /**
249
- * @cfg {String} [name=Node.js]
250
- * The source of the log information. This is commonly the title of an application
251
- * or the Node.js script name (i.e. MyApp).
252
- */
253
- source: {
254
- enumerable: true,
255
- writable: true,
256
- configurable: false,
257
- value: config.source || "Node.js"
258
- },
259
- _logname: {
260
- enumerable: false,
261
- writable: true,
262
- configurable: false,
263
- value: config.eventLog || "APPLICATION"
264
- },
265
- /**
266
- * @cfg {String} [eventLog=APPLICATION]
267
- * The event log where messages should be written. This is either `APPLICATION` or `SYSTEM`.
268
- */
269
- eventLog: {
270
- enumerable: true,
271
- get: function() {
272
- return this._logname.toUpperCase();
273
- },
274
- set: function(value) {
275
- if (value) {
276
- this._logname = eventlogs.indexOf(value.toUpperCase()) >= 0 ? value.toUpperCase() : "APPLICATION";
277
- }
278
- }
279
- },
280
- /**
281
- * @method info
282
- * Log an informational message.
283
- * @param {String} message
284
- * The content of the log message.
285
- * @param {Number} [code=1000]
286
- * The event code to assign to the message.
287
- * @param {Function} [callback]
288
- * An optional callback to run when the message is logged.
289
- */
290
- info: {
291
- enumerable: true,
292
- writable: true,
293
- configurable: false,
294
- value: function(message, code, callback2) {
295
- write(this.eventLog, this.source, "INFORMATION", message, code, callback2);
296
- }
297
- },
298
- information: {
299
- enumerable: false,
300
- get: function() {
301
- return this.info;
302
- }
303
- },
304
- /**
305
- * @method error
306
- * Log an error message.
307
- * @param {String} message
308
- * The content of the log message.
309
- * @param {Number} [code=1000]
310
- * The event code to assign to the message.
311
- * @param {Function} [callback]
312
- * An optional callback to run when the message is logged.
313
- */
314
- error: {
315
- enumerable: true,
316
- writable: true,
317
- configurable: false,
318
- value: function(message, code, callback2) {
319
- write(this.eventLog, this.source, "ERROR", message, code, callback2);
320
- }
321
- },
322
- /**
323
- * @method warn
324
- * Log a warning message.
325
- * @param {String} message
326
- * The content of the log message.
327
- * @param {Number} [code=1000]
328
- * The event code to assign to the message.
329
- * @param {Function} [callback]
330
- * An optional callback to run when the message is logged.
331
- */
332
- warn: {
333
- enumerable: true,
334
- writable: true,
335
- configurable: false,
336
- value: function(message, code, callback2) {
337
- write(this.eventLog, this.source, "WARNING", message, code, callback2);
338
- }
339
- },
340
- warning: {
341
- enumerable: false,
342
- get: function() {
343
- return this.warn;
344
- }
345
- },
346
- /**
347
- * @method auditSuccess
348
- * Log an audit success message.
349
- * @param {String} message
350
- * The content of the log message.
351
- * @param {Number} [code=1000]
352
- * The event code to assign to the message.
353
- * @param {Function} [callback]
354
- * An optional callback to run when the message is logged.
355
- */
356
- auditSuccess: {
357
- enumerable: true,
358
- writable: true,
359
- configurable: false,
360
- value: function(message, code, callback2) {
361
- write(this.eventLog, this.source, "SUCCESSAUDIT", message, code, callback2);
362
- }
363
- },
364
- /**
365
- * @method auditFailure
366
- * Log an audit failure message.
367
- * @param {String} message
368
- * The content of the log message.
369
- * @param {Number} [code=1000]
370
- * The event code to assign to the message.
371
- * @param {Function} [callback]
372
- * An optional callback to run when the message is logged.
373
- */
374
- auditFailure: {
375
- enumerable: true,
376
- writable: true,
377
- configurable: false,
378
- value: function(message, code, callback2) {
379
- write(this.eventLog, this.source, "FAILUREAUDIT", message, code, callback2);
380
- }
381
- }
382
- });
383
- };
384
- module2.exports = logger;
385
- }
386
- });
387
-
388
- // ../../node_modules/xml/lib/escapeForXML.js
389
- var require_escapeForXML = __commonJS({
390
- "../../node_modules/xml/lib/escapeForXML.js"(exports, module2) {
391
- "use strict";
392
- var XML_CHARACTER_MAP = {
393
- "&": "&amp;",
394
- '"': "&quot;",
395
- "'": "&apos;",
396
- "<": "&lt;",
397
- ">": "&gt;"
398
- };
399
- function escapeForXML(string) {
400
- return string && string.replace ? string.replace(/([&"<>'])/g, function(str, item) {
401
- return XML_CHARACTER_MAP[item];
402
- }) : string;
403
- }
404
- module2.exports = escapeForXML;
405
- }
406
- });
407
-
408
- // ../../node_modules/xml/lib/xml.js
409
- var require_xml = __commonJS({
410
- "../../node_modules/xml/lib/xml.js"(exports, module2) {
411
- "use strict";
412
- var escapeForXML = require_escapeForXML();
413
- var Stream = require("stream").Stream;
414
- var DEFAULT_INDENT = " ";
415
- function xml(input, options) {
416
- if (typeof options !== "object") {
417
- options = {
418
- indent: options
419
- };
420
- }
421
- var stream = options.stream ? new Stream() : null, output = "", interrupted = false, indent = !options.indent ? "" : options.indent === true ? DEFAULT_INDENT : options.indent, instant = true;
422
- function delay(func) {
423
- if (!instant) {
424
- func();
425
- } else {
426
- process.nextTick(func);
427
- }
428
- }
429
- function append(interrupt, out) {
430
- if (out !== void 0) {
431
- output += out;
432
- }
433
- if (interrupt && !interrupted) {
434
- stream = stream || new Stream();
435
- interrupted = true;
436
- }
437
- if (interrupt && interrupted) {
438
- var data = output;
439
- delay(function() {
440
- stream.emit("data", data);
441
- });
442
- output = "";
443
- }
444
- }
445
- function add(value, last) {
446
- format(append, resolve(value, indent, indent ? 1 : 0), last);
447
- }
448
- function end() {
449
- if (stream) {
450
- var data = output;
451
- delay(function() {
452
- stream.emit("data", data);
453
- stream.emit("end");
454
- stream.readable = false;
455
- stream.emit("close");
456
- });
457
- }
458
- }
459
- function addXmlDeclaration(declaration) {
460
- var encoding = declaration.encoding || "UTF-8", attr = { version: "1.0", encoding };
461
- if (declaration.standalone) {
462
- attr.standalone = declaration.standalone;
463
- }
464
- add({ "?xml": { _attr: attr } });
465
- output = output.replace("/>", "?>");
466
- }
467
- delay(function() {
468
- instant = false;
469
- });
470
- if (options.declaration) {
471
- addXmlDeclaration(options.declaration);
472
- }
473
- if (input && input.forEach) {
474
- input.forEach(function(value, i2) {
475
- var last;
476
- if (i2 + 1 === input.length)
477
- last = end;
478
- add(value, last);
479
- });
480
- } else {
481
- add(input, end);
482
- }
483
- if (stream) {
484
- stream.readable = true;
485
- return stream;
486
- }
487
- return output;
488
- }
489
- function element() {
490
- var input = Array.prototype.slice.call(arguments), self = {
491
- _elem: resolve(input)
492
- };
493
- self.push = function(input2) {
494
- if (!this.append) {
495
- throw new Error("not assigned to a parent!");
496
- }
497
- var that = this;
498
- var indent = this._elem.indent;
499
- format(
500
- this.append,
501
- resolve(
502
- input2,
503
- indent,
504
- this._elem.icount + (indent ? 1 : 0)
505
- ),
506
- function() {
507
- that.append(true);
508
- }
509
- );
510
- };
511
- self.close = function(input2) {
512
- if (input2 !== void 0) {
513
- this.push(input2);
514
- }
515
- if (this.end) {
516
- this.end();
517
- }
518
- };
519
- return self;
520
- }
521
- function create_indent(character, count) {
522
- return new Array(count || 0).join(character || "");
523
- }
524
- function resolve(data, indent, indent_count) {
525
- indent_count = indent_count || 0;
526
- var indent_spaces = create_indent(indent, indent_count);
527
- var name;
528
- var values = data;
529
- var interrupt = false;
530
- if (typeof data === "object") {
531
- var keys = Object.keys(data);
532
- name = keys[0];
533
- values = data[name];
534
- if (values && values._elem) {
535
- values._elem.name = name;
536
- values._elem.icount = indent_count;
537
- values._elem.indent = indent;
538
- values._elem.indents = indent_spaces;
539
- values._elem.interrupt = values;
540
- return values._elem;
541
- }
542
- }
543
- var attributes = [], content = [];
544
- var isStringContent;
545
- function get_attributes(obj) {
546
- var keys2 = Object.keys(obj);
547
- keys2.forEach(function(key) {
548
- attributes.push(attribute(key, obj[key]));
549
- });
550
- }
551
- switch (typeof values) {
552
- case "object":
553
- if (values === null)
554
- break;
555
- if (values._attr) {
556
- get_attributes(values._attr);
557
- }
558
- if (values._cdata) {
559
- content.push(
560
- ("<![CDATA[" + values._cdata).replace(/\]\]>/g, "]]]]><![CDATA[>") + "]]>"
561
- );
562
- }
563
- if (values.forEach) {
564
- isStringContent = false;
565
- content.push("");
566
- values.forEach(function(value) {
567
- if (typeof value == "object") {
568
- var _name = Object.keys(value)[0];
569
- if (_name == "_attr") {
570
- get_attributes(value._attr);
571
- } else {
572
- content.push(resolve(
573
- value,
574
- indent,
575
- indent_count + 1
576
- ));
577
- }
578
- } else {
579
- content.pop();
580
- isStringContent = true;
581
- content.push(escapeForXML(value));
582
- }
583
- });
584
- if (!isStringContent) {
585
- content.push("");
586
- }
587
- }
588
- break;
589
- default:
590
- content.push(escapeForXML(values));
591
- }
592
- return {
593
- name,
594
- interrupt,
595
- attributes,
596
- content,
597
- icount: indent_count,
598
- indents: indent_spaces,
599
- indent
600
- };
601
- }
602
- function format(append, elem, end) {
603
- if (typeof elem != "object") {
604
- return append(false, elem);
605
- }
606
- var len = elem.interrupt ? 1 : elem.content.length;
607
- function proceed() {
608
- while (elem.content.length) {
609
- var value = elem.content.shift();
610
- if (value === void 0)
611
- continue;
612
- if (interrupt(value))
613
- return;
614
- format(append, value);
615
- }
616
- append(false, (len > 1 ? elem.indents : "") + (elem.name ? "</" + elem.name + ">" : "") + (elem.indent && !end ? "\n" : ""));
617
- if (end) {
618
- end();
619
- }
620
- }
621
- function interrupt(value) {
622
- if (value.interrupt) {
623
- value.interrupt.append = append;
624
- value.interrupt.end = proceed;
625
- value.interrupt = false;
626
- append(true);
627
- return true;
628
- }
629
- return false;
630
- }
631
- append(false, elem.indents + (elem.name ? "<" + elem.name : "") + (elem.attributes.length ? " " + elem.attributes.join(" ") : "") + (len ? elem.name ? ">" : "" : elem.name ? "/>" : "") + (elem.indent && len > 1 ? "\n" : ""));
632
- if (!len) {
633
- return append(false, elem.indent ? "\n" : "");
634
- }
635
- if (!interrupt(elem)) {
636
- proceed();
637
- }
638
- }
639
- function attribute(key, value) {
640
- return key + '="' + escapeForXML(value) + '"';
641
- }
642
- module2.exports = xml;
643
- module2.exports.element = module2.exports.Element = element;
644
- }
645
- });
646
-
647
- // ../../node_modules/node-windows/lib/winsw.js
648
- var require_winsw = __commonJS({
649
- "../../node_modules/node-windows/lib/winsw.js"(exports, module2) {
650
- "use strict";
651
- module2.exports = {
652
- /**
653
- * @method generateXml
654
- * Generate the XML for the winsw configuration file.
655
- * @param {Object} config
656
- * The config object must have the following attributes:
657
- *
658
- * - *id* This is is how the service is identified. Alphanumeric, no spaces.
659
- * - *name* The descriptive name of the service.
660
- * - *script* The absolute path of the node.js server script. i.e. in this case
661
- * it's the wrapper script, not the user's server script.
662
- *
663
- * Optional attributes include
664
- *
665
- * - *description* The description that shows up in the service manager.
666
- * - *nodeOptions* Array or space separated string of node options (e.g. '--harmony')
667
- * - *wrapperArgs* additional arguments to pass to wrapper script to control restarts, etc.
668
- * - *logmode* Valid values include `rotate` (default), `reset` (clear log), `roll` (move to .old), and `append`.
669
- * - *logging* Supersedes *logmode*. Object of form `{mode: 'append'}`,
670
- * `{mode: 'reset'}`, `{mode: 'none'}`, `{mode: 'roll-by-time', pattern: 'yyyMMdd'}`,
671
- * or `{mode: 'roll-by-size', sizeThreshold: 10240, keepFiles: 8}` (all attributes optional,
672
- * example shows defaults). See [winsw docs](https://github.com/kohsuke/winsw/tree/winsw-1.17#logging).
673
- * - *logpath* The absolute path to the directory where logs should be stored. Defaults to the current directory.
674
- * - *dependencies* A comma delimited list or array of process dependencies.
675
- * - *env* A key/value object or array of key/value objects containing
676
- * environment variables to pass to the process. The object might look like `{name:'HOME',value:'c:\Windows'}`.
677
- * - *logOnAs* A key/value object that contains the service logon credentials.
678
- * The object might look like `{account:'user', password:'pwd', domain:'MYDOMAIN'}
679
- * If this is not included or does not have all 3 members set then it is not used.
680
- * - *workingdirectory* optional working directory that service should run in.
681
- * If this is not included, the current working directory of the install process
682
- * is used.
683
- */
684
- generateXml: function(config) {
685
- var xml;
686
- function multi(tag, input, splitter) {
687
- if (input === void 0 || input === null) {
688
- return;
689
- }
690
- if (!(input instanceof Array)) {
691
- input = input.split(splitter || ",");
692
- }
693
- input.forEach(function(val) {
694
- var ele = {};
695
- ele[tag] = String(val).trim();
696
- xml.push(ele);
697
- });
698
- }
699
- if (!config || !config.id || !config.name || !config.script) {
700
- throw "WINSW must be configured with a minimum of id, name and script";
701
- }
702
- xml = [
703
- { id: config.id },
704
- { name: config.name },
705
- { description: config.description || "" },
706
- { executable: config.execPath || process.execPath }
707
- ];
708
- multi("argument", config.nodeOptions, " ");
709
- xml.push({ argument: config.script.trim() });
710
- console.log({ loc: "winsw.js ~line 77", xml, config });
711
- multi("argument", config.wrapperArgs, " ");
712
- if (config.logging) {
713
- var logcontent = [{ _attr: { mode: config.logging.mode || "append" } }];
714
- if (config.logging.mode === "roll-by-time") {
715
- logcontent.push({ pattern: config.logging.pattern || "yyyMMdd" });
716
- }
717
- if (config.logging.mode === "roll-by-size") {
718
- logcontent.push({ sizeThreshold: config.logging.sizeThreshold || 10240 });
719
- logcontent.push({ keepFiles: config.logging.keepFiles || 8 });
720
- }
721
- xml.push({ log: logcontent });
722
- } else {
723
- xml.push({ logmode: config.logmode || "rotate" });
724
- }
725
- if (config.logpath) {
726
- xml.push({ logpath: config.logpath });
727
- }
728
- if (config.stopparentfirst) {
729
- xml.push({ stopparentprocessfirst: config.stopparentfirst });
730
- }
731
- if (config.stoptimeout) {
732
- xml.push({ stoptimeout: config.stoptimeout + "sec" });
733
- }
734
- multi("depend", config.dependencies);
735
- if (config.env) {
736
- config.env = config.env instanceof Array == true ? config.env : [config.env];
737
- config.env.forEach(function(env) {
738
- xml.push({ env: { _attr: { name: env.name, value: env.value } } });
739
- });
740
- }
741
- if (config.logOnAs) {
742
- var serviceaccount = [
743
- { domain: config.logOnAs.domain || "NT AUTHORITY" },
744
- { user: config.logOnAs.account || "LocalSystem" },
745
- { password: config.logOnAs.password || "" }
746
- ];
747
- if (config.allowServiceLogon) {
748
- serviceaccount.push({ allowservicelogon: "true" });
749
- }
750
- xml.push({
751
- serviceaccount
752
- });
753
- }
754
- xml.push({ workingdirectory: config.workingdirectory || process.cwd() });
755
- return require_xml()({ service: xml }, { indent: " " }).replace(/\n/g, "\r\n");
756
- },
757
- /**
758
- * Copy install version of winsw.exe to specific renamed version according to
759
- * the service id. Also copy .exe.config file that allows it to run under
760
- * .NET 4+ runtime on newer versions of windows.
761
- * (see https://github.com/kohsuke/winsw#net-runtime-40)
762
- *
763
- * @method createExe
764
- * Create the executable
765
- * @param {String} name
766
- * The alphanumeric string (spaces are stripped) of the `.exe` file. For example, `My App` generates `myapp.exe`
767
- * @param {String} [dir=cwd]
768
- * The output directory where the executable will be saved.
769
- * @param {Function} [callback]
770
- * The callback to fire upon completion.
771
- */
772
- createExe: function(name, dir, callback2) {
773
- var fs = require("fs"), p2 = require("path");
774
- if (typeof dir === "function") {
775
- callback2 = dir;
776
- dir = null;
777
- }
778
- dir = dir || process.cwd();
779
- var exeOrigin = p2.join(__dirname, "..", "bin", "winsw", "winsw.exe"), cfgOrigin = p2.join(__dirname, "..", "bin", "winsw", "winsw.exe.config"), exeDest = p2.join(dir, name.replace(/[^\w]/gi, "").toLowerCase() + ".exe"), cfgDest = p2.join(dir, name.replace(/[^\w]/gi, "").toLowerCase() + ".exe.config"), exeData = fs.readFileSync(exeOrigin, { encoding: "binary" }), cfgData = fs.readFileSync(cfgOrigin, { encoding: "binary" });
780
- fs.writeFileSync(exeDest, exeData, { encoding: "binary" });
781
- fs.writeFileSync(cfgDest, cfgData, { encoding: "binary" });
782
- callback2 && callback2();
783
- }
784
- };
785
- }
786
- });
787
-
788
- // ../../node_modules/node-windows/lib/daemon.js
789
- var require_daemon = __commonJS({
790
- "../../node_modules/node-windows/lib/daemon.js"(exports, module2) {
791
- "use strict";
792
- var exec = require("child_process").exec;
793
- var path = require("path");
794
- var fs = require("fs");
795
- var PermError = "Permission Denied. Requires administrative privileges.";
796
- var wincmd = require_binaries();
797
- var Logger = require_eventlog();
798
- var daemonDir = "daemon";
799
- var wrapper = path.resolve(path.join(__dirname, "./wrapper.js"));
800
- var sleep = function(period) {
801
- var st2 = (/* @__PURE__ */ new Date()).getTime();
802
- while ((/* @__PURE__ */ new Date()).getTime() <= st2 + period * 1e3) {
803
- }
804
- return;
805
- };
806
- var daemon = function(config) {
807
- Object.defineProperties(this, {
808
- _name: {
809
- enumerable: false,
810
- writable: true,
811
- configurable: false,
812
- value: config.name || null
813
- },
814
- _eventlog: {
815
- enumerable: false,
816
- writable: true,
817
- configurable: false,
818
- value: null
819
- },
820
- _xml: {
821
- enumerable: false,
822
- get: function() {
823
- var wrapperArgs = [
824
- "--file",
825
- this.script,
826
- "--scriptoptions=" + this.scriptOptions,
827
- "--log",
828
- this.name + " wrapper",
829
- "--grow",
830
- this.grow,
831
- "--wait",
832
- this.wait,
833
- "--maxrestarts",
834
- this.maxRestarts,
835
- "--abortonerror",
836
- this.abortOnError == true ? "y" : "n",
837
- "--stopparentfirst",
838
- this.stopparentfirst
839
- ];
840
- if (this.maxRetries !== null) {
841
- wrapperArgs.push("--maxretries");
842
- wrapperArgs.push(this.maxRetries);
843
- }
844
- return require_winsw().generateXml({
845
- name: this.name,
846
- id: this._exe,
847
- nodeOptions: this.nodeOptions,
848
- script: wrapper,
849
- scriptOptions: this.scriptOptions,
850
- wrapperArgs,
851
- description: this.description,
852
- logpath: this.logpath,
853
- env: config.env,
854
- execPath: this.execPath,
855
- logOnAs: this.logOnAs,
856
- workingdirectory: this.workingdirectory,
857
- stopparentfirst: this.stopparentfirst,
858
- stoptimeout: this.stoptimeout,
859
- logmode: this.logmode,
860
- logging: config.logging,
861
- allowServiceLogon: config.allowServiceLogon
862
- });
863
- }
864
- },
865
- _exe: {
866
- enumerable: false,
867
- get: function() {
868
- return this.id + ".exe";
869
- }
870
- },
871
- /**
872
- * @cfg {Number} [maxRetries=null]
873
- * The maximum number of restart attempts to make before the service is considered non-responsive/faulty.
874
- * Ignored by default.
875
- */
876
- maxRetries: {
877
- enumerable: true,
878
- writable: false,
879
- configurable: false,
880
- value: config.hasOwnProperty("maxRetries") ? config.maxRetries : null
881
- },
882
- /**
883
- * @cfg {Boolean} [stopparentfirst=false]
884
- * Allow the service to shutdown cleanly.
885
- */
886
- stopparentfirst: {
887
- enumerable: true,
888
- writable: false,
889
- configurable: false,
890
- value: config.stopparentfirst
891
- },
892
- /**
893
- * @cfg {Number} [stoptimeout=30]
894
- * How long to wait in seconds before force killing the application.
895
- * This only takes effect when stopparentfirst is enabled.
896
- */
897
- stoptimeout: {
898
- enumerable: true,
899
- writable: false,
900
- configurable: false,
901
- value: config.hasOwnProperty("stoptimeout") ? config.stoptimeout : 30
902
- },
903
- /**
904
- * @cfg {string} [nodeOptions='--harmony']
905
- * Options to be passed to the node process.
906
- */
907
- nodeOptions: {
908
- enumerable: true,
909
- writable: false,
910
- configurable: false,
911
- value: config.nodeOptions || "--harmony"
912
- },
913
- /**
914
- * @cfg {string} [scriptOptions='']
915
- * Options to be passed to the script.
916
- */
917
- scriptOptions: {
918
- enumerable: true,
919
- writable: false,
920
- configurable: false,
921
- value: config.scriptOptions || ""
922
- },
923
- /**
924
- * @cfg {Number} [maxRestarts=3]
925
- * The maximum number of restarts within a 60 second period before haulting the process.
926
- * This cannot be _disabled_, but it can be rendered ineffective by setting a value of `0`.
927
- */
928
- maxRestarts: {
929
- enumerable: true,
930
- writable: false,
931
- configurable: false,
932
- value: config.hasOwnProperty("maxRestarts") ? config.maxRestarts : 3
933
- },
934
- /**
935
- * @cfg {Boolean} [abortOnError=false]
936
- * Setting this to `true` will force the process to exit if it encounters an error that stops the node.js script from running.
937
- * This does not mean the process will stop if the script throws an error. It will only abort if the
938
- * script throws an error causing the process to exit (i.e. `process.exit(1)`).
939
- */
940
- abortOnError: {
941
- enumerable: true,
942
- writable: false,
943
- configurable: false,
944
- value: config.abortOnError instanceof Boolean ? config.abortOnError : false
945
- },
946
- /**
947
- * @cfg {Number} [wait=1]
948
- * The initial number of seconds to wait before attempting a restart (after the script stops).
949
- */
950
- wait: {
951
- enumerable: true,
952
- writable: false,
953
- configurable: false,
954
- value: !isNaN(config.wait) ? config.wait : 1
955
- },
956
- /**
957
- * @cfg {Number} [grow=.25]
958
- * A number between 0-1 representing the percentage growth rate for the #wait interval.
959
- * Setting this to anything other than `0` allows the process to increase it's wait period
960
- * on every restart attempt. If a process dies fatally, this will prevent the server from
961
- * restarting the process too rapidly (and too strenuously).
962
- */
963
- grow: {
964
- enumerable: true,
965
- writable: false,
966
- configurable: false,
967
- value: !isNaN(config.grow) ? config.grow : 0.25
968
- },
969
- _directory: {
970
- enumerable: false,
971
- writable: true,
972
- configurable: false,
973
- value: config.script !== null ? path.dirname(config.script) : null
974
- },
975
- /**
976
- * Resolves the directory where the script is saved.
977
- */
978
- directory: {
979
- enumerable: false,
980
- writable: false,
981
- configurable: false,
982
- value: function(dir) {
983
- if (this.script == null || this.name == null) {
984
- throw Error("Script and Name are required but were not provided.");
985
- }
986
- if (dir) {
987
- this._directory = path.resolve(dir);
988
- }
989
- return path.resolve(path.join(this._directory, daemonDir));
990
- }
991
- },
992
- /**
993
- * @property {String} root
994
- * The root directory where the process files are stored.
995
- */
996
- root: {
997
- enumerable: true,
998
- get: function() {
999
- return this.directory();
1000
- }
1001
- },
1002
- // Generates the primary logging utility
1003
- log: {
1004
- enumerable: false,
1005
- get: function() {
1006
- if (this._eventlog !== null)
1007
- return this._eventlog;
1008
- if (this.name == null)
1009
- throw "No name was specified for the service";
1010
- this._eventlog = new Logger(this.name + " Monitor");
1011
- return this._eventlog;
1012
- }
1013
- },
1014
- // The path where log files should be stored
1015
- logpath: {
1016
- enumerable: true,
1017
- writable: false,
1018
- configurable: false,
1019
- value: config.logpath || null
1020
- },
1021
- // The log mode. Options are the same as winsw#generateXml
1022
- logmode: {
1023
- enumerable: true,
1024
- writable: false,
1025
- configurable: false,
1026
- value: config.logmode || "rotate"
1027
- },
1028
- // The name of the process
1029
- name: {
1030
- enumerable: false,
1031
- get: function() {
1032
- return this._name;
1033
- },
1034
- set: function(value) {
1035
- this._name = value;
1036
- }
1037
- },
1038
- // The ID for the process
1039
- id: {
1040
- enumerable: true,
1041
- get: function() {
1042
- return this.name.replace(/[^\w]/gi, "").toLowerCase();
1043
- }
1044
- },
1045
- // Description of the service
1046
- description: {
1047
- enumerable: true,
1048
- writable: false,
1049
- configurable: false,
1050
- value: config.description || ""
1051
- },
1052
- /**
1053
- * @property {Object} [user]
1054
- * If you need to specify a specific user or particular credentials to manage a service, the following
1055
- * attributes may be helpful.
1056
- *
1057
- * The `user` attribute is an object with three keys: `domain`,`account`, and `password`.
1058
- * This can be used to identify which user the service library should use to perform system commands.
1059
- * By default, the domain is set to the local computer name, but it can be overridden with an Active Directory
1060
- * or LDAP domain. For example:
1061
- *
1062
- * **app.js**
1063
- *
1064
- * var Service = require('node-windows').Service;
1065
- *
1066
- * // Create a new service object
1067
- * var svc = new Service({
1068
- * name:'Hello World',
1069
- * script: require('path').join(__dirname,'helloworld.js')
1070
- * });
1071
- *
1072
- * svc.user.domain = 'mydomain.local';
1073
- * svc.user.account = 'username';
1074
- * svc.user.password = 'password';
1075
- * ...
1076
- *
1077
- * Both the account and password must be explicitly defined if you want the service module to
1078
- * run commands as a specific user. By default, it will run using the user account that launched
1079
- * the process (i.e. who launched `node app.js`).
1080
- */
1081
- user: {
1082
- enumerable: false,
1083
- writable: true,
1084
- configurable: false,
1085
- value: {
1086
- account: null,
1087
- password: null,
1088
- domain: process.env.COMPUTERNAME
1089
- }
1090
- },
1091
- /**
1092
- * @property {Object} [logOnAs]
1093
- * If you need to specify a specific user or particular credentials for the service log on as once installed, the following
1094
- * attributes may be helpful.
1095
- *
1096
- * The `logOnAs` attribute is an object with four keys: `domain`,`account`, `password`, and `mungeCredentialsAfterInstall`.
1097
- * This can be used to identify which user the service should run as once installed.
1098
- *
1099
- * If no account and password is specified, the logOnAs property is not used and the service will run as the "Local System" account.
1100
- * If account and password is specified, but domain is not specified then the domain is set to the local computer name, but it can be overridden with an Active Directory
1101
- * or LDAP domain. For example:
1102
- *
1103
- * **app.js**
1104
- *
1105
- * var Service = require('node-windows').Service;
1106
- *
1107
- * // Create a new service object
1108
- * var svc = new Service({
1109
- * name:'Hello World',
1110
- * script: require('path').join(__dirname,'helloworld.js')
1111
- * });
1112
- *
1113
- * svc.logOnAs.domain = 'mydomain.local';
1114
- * svc.logOnAs.account = 'username';
1115
- * svc.logOnAs.password = 'password';
1116
- * ...
1117
- *
1118
- * Both the account and password must be explicitly defined if you want the service to log on as that user,
1119
- * otherwise the Local System account will be used.
1120
- */
1121
- logOnAs: {
1122
- enumerable: false,
1123
- writable: true,
1124
- configurable: false,
1125
- value: {
1126
- account: null,
1127
- password: null,
1128
- domain: process.env.COMPUTERNAME,
1129
- mungeCredentialsAfterInstall: true
1130
- }
1131
- },
1132
- /**
1133
- * @property {String} [workingdirectory]
1134
- * The full path to the working directory that the service process
1135
- * should launch from. If this is omitted, it will default to the
1136
- * current processes working directory.
1137
- */
1138
- workingdirectory: {
1139
- enumerable: false,
1140
- writable: true,
1141
- configurable: false,
1142
- value: config.hasOwnProperty("workingDirectory") ? config.workingDirectory : process.cwd()
1143
- },
1144
- // Optionally provide a sudo password.
1145
- sudo: {
1146
- enumerable: false,
1147
- writable: true,
1148
- configurable: false,
1149
- value: {
1150
- password: null
1151
- }
1152
- },
1153
- /**
1154
- * @cfg {String} script
1155
- * The absolute path of the script to launch as a service.
1156
- * @required
1157
- */
1158
- script: {
1159
- enumerable: true,
1160
- writable: true,
1161
- configurable: false,
1162
- value: config.script !== void 0 ? require("path").resolve(config.script) : null
1163
- },
1164
- /**
1165
- * @cfg {String} execPath
1166
- * The absolute path to the executable that will launch the script.
1167
- * If omitted process.execPath is used.
1168
- */
1169
- execPath: {
1170
- enumerable: true,
1171
- writable: true,
1172
- configurable: false,
1173
- value: config.execPath !== void 0 ? require("path").resolve(config.execPath) : null
1174
- },
1175
- /**
1176
- * @method install
1177
- * Install the script as a process.
1178
- * @param {String} [dir=root of script]
1179
- * The directory where the process files will be saved. Defaults to #script path.
1180
- * @param {Function} [callback]
1181
- * The callback to fire when the installation completes.
1182
- */
1183
- /**
1184
- * @event install
1185
- * Fired when the installation process is complete.
1186
- */
1187
- /**
1188
- * @event alreadyinstalled
1189
- * Fired if the script is already known to be a service.
1190
- */
1191
- /**
1192
- * @event invalidinstallation
1193
- * Fired if an installation is detected but missing required files.
1194
- */
1195
- /**
1196
- * @event error
1197
- * Fired in some instances when an error occurs.
1198
- */
1199
- install: {
1200
- enumerable: true,
1201
- writable: false,
1202
- configurable: false,
1203
- value: function(dir) {
1204
- if (this.script == null || this.name == null) {
1205
- throw Error("Script and Name are required but were not provided.");
1206
- }
1207
- if (this.exists) {
1208
- var missing = false;
1209
- if (!fs.existsSync(path.join(this.root, this._exe))) {
1210
- this.log.warn("The main executable is missing or cannot be found (" + path.join(this.root, this._exe) + ")");
1211
- missing = true;
1212
- }
1213
- if (!fs.existsSync(path.join(this.root, this.id + ".xml"))) {
1214
- this.log.warn("The primary configuration file is missing or cannot be found (" + path.join(this.root, this.id + ".xml") + ")");
1215
- missing = true;
1216
- }
1217
- if (missing.length > 0) {
1218
- this.emit("invalidinstallation");
1219
- return;
1220
- }
1221
- this.log.warn("The process cannot be installed again because it already exists.");
1222
- this.emit("alreadyinstalled");
1223
- return;
1224
- }
1225
- var winsw = require_winsw(), me = this;
1226
- if (typeof dir === "function") {
1227
- callback = dir;
1228
- dir = null;
1229
- }
1230
- dir = this.directory(dir);
1231
- fs.exists(dir, function(exists) {
1232
- if (!exists) {
1233
- fs.mkdirSync(dir);
1234
- }
1235
- fs.writeFile(path.resolve(dir, me.id + ".xml"), me._xml, function() {
1236
- winsw.createExe(me.id, dir, function() {
1237
- me.execute('"' + path.resolve(dir, me._exe) + '" install', function() {
1238
- sleep(2);
1239
- me.emit("install");
1240
- });
1241
- });
1242
- });
1243
- });
1244
- }
1245
- },
1246
- /**
1247
- * @method uninstall
1248
- * Uninstall the service.
1249
- * @param {Number} [waitTime]
1250
- * Seconds to wait until winsw.exe finish processing the uninstall command.
1251
- *
1252
- * var Service = require('node-windows').Service;
1253
- *
1254
- * // Create a new service object
1255
- * var svc = new Service({
1256
- * name:'Hello World',
1257
- * script: require('path').join(__dirname,'helloworld.js')
1258
- * });
1259
- *
1260
- * // Listen for the "uninstall" event so we know when it's done.
1261
- * svc.on('uninstall',function(){
1262
- * console.log('Uninstall complete.');
1263
- * console.log('The service exists: ',svc.exists);
1264
- * });
1265
- *
1266
- * // Uninstall the service.
1267
- * svc.uninstall();
1268
- */
1269
- /**
1270
- * @event uninstall
1271
- * Fired when the uninstall is complete.
1272
- */
1273
- /**
1274
- * @event alreadyuninstalled
1275
- * Fired if the script is unknown as a service.
1276
- */
1277
- uninstall: {
1278
- enumerable: true,
1279
- writable: false,
1280
- value: function(waitTime) {
1281
- var me = this;
1282
- waitTime = waitTime || 2;
1283
- if (!this.exists) {
1284
- console.log("Uninstall was skipped because process does not exist or could not be found.");
1285
- this.emit("alreadyuninstalled");
1286
- return;
1287
- }
1288
- var uninstaller = function() {
1289
- me.execute('"' + path.resolve(me.root, me._exe) + '" uninstall', function(error, stdout, stderr) {
1290
- if (error) {
1291
- me.checkPermError(error);
1292
- } else if (stderr.trim().length > 0) {
1293
- console.log("Error: ", stderr);
1294
- } else {
1295
- sleep(waitTime);
1296
- var rm = function(file) {
1297
- if (fs.existsSync(path.join(me.root, file))) {
1298
- fs.unlinkSync(path.join(me.root, file));
1299
- }
1300
- };
1301
- rm(me.id + ".xml");
1302
- rm(me.id + ".wrapper.log");
1303
- rm(me.id + ".out.log");
1304
- rm(me.id + ".err.log");
1305
- rm(me.id + ".exe");
1306
- rm(me.id + ".exe.config");
1307
- var _other_files = fs.readdirSync(me.root).filter(function(file) {
1308
- const regex = /^.+\.((wrapper|out|err)\.log)|(exe|xml)$/g;
1309
- return !regex.exec(file);
1310
- });
1311
- _other_files.forEach(function(f2) {
1312
- rm(f2);
1313
- });
1314
- if (fs.readdirSync(me.root).length === 0) {
1315
- if (me.root !== path.dirname(me.script)) {
1316
- fs.rmdir(me.root, function() {
1317
- sleep(1);
1318
- me.emit("uninstall");
1319
- });
1320
- } else {
1321
- me.emit("uninstall");
1322
- }
1323
- } else {
1324
- me.emit("uninstall");
1325
- }
1326
- }
1327
- });
1328
- };
1329
- this.once("stop", uninstaller);
1330
- this.once("alreadystopped", uninstaller);
1331
- this.stop();
1332
- }
1333
- },
1334
- /**
1335
- * @method start
1336
- * Start an existing method.
1337
- */
1338
- /**
1339
- * @event start
1340
- * Fired when the event has started.
1341
- */
1342
- start: {
1343
- enumerable: true,
1344
- writable: false,
1345
- configurable: false,
1346
- value: function() {
1347
- var me = this;
1348
- if (this.name == null) {
1349
- throw "A name for the service is required.";
1350
- }
1351
- if (!this.exists) {
1352
- throw Error('The service "' + this.name + '" does not exist or could not be found.');
1353
- }
1354
- this.execute('NET START "' + me._exe + '"', function(err, stdout, stderr) {
1355
- if (err) {
1356
- if (err.code == 2) {
1357
- if (err.message.indexOf("already been started") >= 0 && err.message.indexOf("service name is invalid") < 0) {
1358
- me.log.warn("An attempt to start the service failed because the service is already running. The process should be stopped before starting, or the restart method should be used.");
1359
- me.emit("error", err);
1360
- return;
1361
- } else if (err.message.indexOf("service name is invalid") < 0) {
1362
- me.checkPermError(err);
1363
- console.log(err);
1364
- me.emit("error", err);
1365
- return;
1366
- }
1367
- } else {
1368
- me.log.error(err.toString());
1369
- }
1370
- } else {
1371
- me.emit("start");
1372
- }
1373
- });
1374
- }
1375
- },
1376
- /**
1377
- * @method stop
1378
- * Stop the service.
1379
- */
1380
- /**
1381
- * @event stop
1382
- * Fired when the service is stopped.
1383
- */
1384
- stop: {
1385
- enumerable: true,
1386
- writable: false,
1387
- value: function() {
1388
- var me = this;
1389
- me.execute('NET STOP "' + me._exe + '"', function(err, stdout, stderr) {
1390
- if (err) {
1391
- if (err.code == 2) {
1392
- me.log.warn("An attempt to stop the service failed because the service is/was not running.");
1393
- me.emit("alreadystopped");
1394
- } else {
1395
- me.checkPermError(err);
1396
- }
1397
- } else {
1398
- me.log.info(stdout);
1399
- me.emit("stop");
1400
- }
1401
- });
1402
- }
1403
- },
1404
- /**
1405
- * @method restart
1406
- * Restart an existing service
1407
- */
1408
- restart: {
1409
- enumerable: true,
1410
- writable: false,
1411
- value: function(callback2) {
1412
- var me = this;
1413
- this.once("stop", me.start);
1414
- this.stop();
1415
- }
1416
- },
1417
- /**
1418
- * @property {Boolean} exists
1419
- * Determine whether the service exists.
1420
- */
1421
- exists: {
1422
- enumerable: true,
1423
- get: function() {
1424
- if (this.script == null || this.name == null) {
1425
- throw Error("Script and name are required but were not specified.");
1426
- }
1427
- return fs.existsSync(path.join(this.directory(), this.id + ".exe")) && fs.existsSync(path.join(this.directory(), this.id + ".xml"));
1428
- }
1429
- },
1430
- // Execute commands with elevated privileges.
1431
- execute: {
1432
- enumerable: false,
1433
- writable: false,
1434
- configurable: false,
1435
- value: function(cmd, options, callback2) {
1436
- var me = this;
1437
- callback2 = callback2 || function() {
1438
- };
1439
- options = options || {};
1440
- wincmd.isAdminUser(function(isAdmin) {
1441
- if (isAdmin) {
1442
- if (typeof options === "function") {
1443
- callback2 = options;
1444
- options = {};
1445
- }
1446
- if (me.user.account !== null && me.user.password !== null) {
1447
- _cmd = "runas /profile /user:" + me.user.domain + "\\" + me.user.account + " " + cmd;
1448
- exec(cmd, options, callback2);
1449
- } else if (me.sudo.password !== null) {
1450
- wincmd.sudo(cmd, me.sudo.password || "", options, callback2);
1451
- } else {
1452
- wincmd.elevate(cmd, options, callback2);
1453
- }
1454
- } else {
1455
- console.log(PermError);
1456
- throw PermError;
1457
- }
1458
- });
1459
- }
1460
- },
1461
- // Check for permission errors
1462
- checkPermError: {
1463
- enumerable: false,
1464
- writable: false,
1465
- configurable: false,
1466
- value: function(error) {
1467
- if (error.message.indexOf("Administrator access") >= 0 || error.message.indexOf("Access is denied") >= 0) {
1468
- try {
1469
- this.log.error(PermError);
1470
- } catch (e) {
1471
- console.log(PermError);
1472
- }
1473
- } else {
1474
- try {
1475
- this.log.error(error.toString());
1476
- } catch (e) {
1477
- console.log(error.toString());
1478
- }
1479
- }
1480
- process.exit(1);
1481
- }
1482
- }
1483
- });
1484
- };
1485
- var util = require("util");
1486
- var EventEmitter = require("events").EventEmitter;
1487
- util.inherits(daemon, EventEmitter);
1488
- module2.exports = daemon;
1489
- }
1490
- });
1491
-
1492
- // ../../node_modules/node-windows/lib/node-windows.js
1493
- var require_node_windows = __commonJS({
1494
- "../../node_modules/node-windows/lib/node-windows.js"(exports, module2) {
1495
- "use strict";
1496
- if (require("os").platform().indexOf("win32") < 0) {
1497
- throw "node-windows is only supported on Windows.";
1498
- }
1499
- module2.exports = require_binaries();
1500
- var commands = require_cmd();
1501
- for (item in commands) {
1502
- module2.exports[item] = commands[item];
1503
- }
1504
- var item;
1505
- module2.exports.Service = require_daemon();
1506
- module2.exports.EventLogger = require_eventlog();
1507
- }
1508
- });
1509
-
1510
33
  // ../../node_modules/ws/lib/stream.js
1511
34
  var require_stream = __commonJS({
1512
35
  "../../node_modules/ws/lib/stream.js"(exports, module2) {
@@ -1552,41 +75,41 @@ var require_stream = __commonJS({
1552
75
  return;
1553
76
  duplex.push(null);
1554
77
  });
1555
- duplex._destroy = function(err, callback2) {
78
+ duplex._destroy = function(err, callback) {
1556
79
  if (ws.readyState === ws.CLOSED) {
1557
- callback2(err);
80
+ callback(err);
1558
81
  process.nextTick(emitClose, duplex);
1559
82
  return;
1560
83
  }
1561
84
  let called = false;
1562
85
  ws.once("error", function error(err2) {
1563
86
  called = true;
1564
- callback2(err2);
87
+ callback(err2);
1565
88
  });
1566
89
  ws.once("close", function close() {
1567
90
  if (!called)
1568
- callback2(err);
91
+ callback(err);
1569
92
  process.nextTick(emitClose, duplex);
1570
93
  });
1571
94
  if (terminateOnDestroy)
1572
95
  ws.terminate();
1573
96
  };
1574
- duplex._final = function(callback2) {
97
+ duplex._final = function(callback) {
1575
98
  if (ws.readyState === ws.CONNECTING) {
1576
99
  ws.once("open", function open() {
1577
- duplex._final(callback2);
100
+ duplex._final(callback);
1578
101
  });
1579
102
  return;
1580
103
  }
1581
104
  if (ws._socket === null)
1582
105
  return;
1583
106
  if (ws._socket._writableState.finished) {
1584
- callback2();
107
+ callback();
1585
108
  if (duplex._readableState.endEmitted)
1586
109
  duplex.destroy();
1587
110
  } else {
1588
111
  ws._socket.once("finish", function finish() {
1589
- callback2();
112
+ callback();
1590
113
  });
1591
114
  ws.close();
1592
115
  }
@@ -1595,14 +118,14 @@ var require_stream = __commonJS({
1595
118
  if (ws.isPaused)
1596
119
  ws.resume();
1597
120
  };
1598
- duplex._write = function(chunk, encoding, callback2) {
121
+ duplex._write = function(chunk, encoding, callback) {
1599
122
  if (ws.readyState === ws.CONNECTING) {
1600
123
  ws.once("open", function open() {
1601
- duplex._write(chunk, encoding, callback2);
124
+ duplex._write(chunk, encoding, callback);
1602
125
  });
1603
126
  return;
1604
127
  }
1605
- ws.send(chunk, callback2);
128
+ ws.send(chunk, callback);
1606
129
  };
1607
130
  duplex.on("end", duplexOnEnd);
1608
131
  duplex.on("error", duplexOnError);
@@ -1870,11 +393,11 @@ var require_permessage_deflate = __commonJS({
1870
393
  this._inflate = null;
1871
394
  }
1872
395
  if (this._deflate) {
1873
- const callback2 = this._deflate[kCallback];
396
+ const callback = this._deflate[kCallback];
1874
397
  this._deflate.close();
1875
398
  this._deflate = null;
1876
- if (callback2) {
1877
- callback2(
399
+ if (callback) {
400
+ callback(
1878
401
  new Error(
1879
402
  "The deflate stream was closed while data was being processed"
1880
403
  )
@@ -1998,11 +521,11 @@ var require_permessage_deflate = __commonJS({
1998
521
  * @param {Function} callback Callback
1999
522
  * @public
2000
523
  */
2001
- decompress(data, fin, callback2) {
524
+ decompress(data, fin, callback) {
2002
525
  zlibLimiter.add((done) => {
2003
526
  this._decompress(data, fin, (err, result) => {
2004
527
  done();
2005
- callback2(err, result);
528
+ callback(err, result);
2006
529
  });
2007
530
  });
2008
531
  }
@@ -2014,11 +537,11 @@ var require_permessage_deflate = __commonJS({
2014
537
  * @param {Function} callback Callback
2015
538
  * @public
2016
539
  */
2017
- compress(data, fin, callback2) {
540
+ compress(data, fin, callback) {
2018
541
  zlibLimiter.add((done) => {
2019
542
  this._compress(data, fin, (err, result) => {
2020
543
  done();
2021
- callback2(err, result);
544
+ callback(err, result);
2022
545
  });
2023
546
  });
2024
547
  }
@@ -2030,7 +553,7 @@ var require_permessage_deflate = __commonJS({
2030
553
  * @param {Function} callback Callback
2031
554
  * @private
2032
555
  */
2033
- _decompress(data, fin, callback2) {
556
+ _decompress(data, fin, callback) {
2034
557
  const endpoint = this._isServer ? "client" : "server";
2035
558
  if (!this._inflate) {
2036
559
  const key = `${endpoint}_max_window_bits`;
@@ -2045,7 +568,7 @@ var require_permessage_deflate = __commonJS({
2045
568
  this._inflate.on("error", inflateOnError);
2046
569
  this._inflate.on("data", inflateOnData);
2047
570
  }
2048
- this._inflate[kCallback] = callback2;
571
+ this._inflate[kCallback] = callback;
2049
572
  this._inflate.write(data);
2050
573
  if (fin)
2051
574
  this._inflate.write(TRAILER);
@@ -2054,7 +577,7 @@ var require_permessage_deflate = __commonJS({
2054
577
  if (err) {
2055
578
  this._inflate.close();
2056
579
  this._inflate = null;
2057
- callback2(err);
580
+ callback(err);
2058
581
  return;
2059
582
  }
2060
583
  const data2 = bufferUtil.concat(
@@ -2071,7 +594,7 @@ var require_permessage_deflate = __commonJS({
2071
594
  this._inflate.reset();
2072
595
  }
2073
596
  }
2074
- callback2(null, data2);
597
+ callback(null, data2);
2075
598
  });
2076
599
  }
2077
600
  /**
@@ -2082,7 +605,7 @@ var require_permessage_deflate = __commonJS({
2082
605
  * @param {Function} callback Callback
2083
606
  * @private
2084
607
  */
2085
- _compress(data, fin, callback2) {
608
+ _compress(data, fin, callback) {
2086
609
  const endpoint = this._isServer ? "server" : "client";
2087
610
  if (!this._deflate) {
2088
611
  const key = `${endpoint}_max_window_bits`;
@@ -2095,7 +618,7 @@ var require_permessage_deflate = __commonJS({
2095
618
  this._deflate[kBuffers] = [];
2096
619
  this._deflate.on("data", deflateOnData);
2097
620
  }
2098
- this._deflate[kCallback] = callback2;
621
+ this._deflate[kCallback] = callback;
2099
622
  this._deflate.write(data);
2100
623
  this._deflate.flush(zlib.Z_SYNC_FLUSH, () => {
2101
624
  if (!this._deflate) {
@@ -2114,7 +637,7 @@ var require_permessage_deflate = __commonJS({
2114
637
  if (fin && this.params[`${endpoint}_no_context_takeover`]) {
2115
638
  this._deflate.reset();
2116
639
  }
2117
- callback2(null, data2);
640
+ callback(null, data2);
2118
641
  });
2119
642
  }
2120
643
  };
@@ -3226,9 +1749,9 @@ var require_sender = __commonJS({
3226
1749
  cb(err);
3227
1750
  for (let i2 = 0; i2 < this._queue.length; i2++) {
3228
1751
  const params = this._queue[i2];
3229
- const callback2 = params[params.length - 1];
3230
- if (typeof callback2 === "function")
3231
- callback2(err);
1752
+ const callback = params[params.length - 1];
1753
+ if (typeof callback === "function")
1754
+ callback(err);
3232
1755
  }
3233
1756
  return;
3234
1757
  }
@@ -4648,7 +3171,7 @@ var require_websocket_server = __commonJS({
4648
3171
  * class to use. It must be the `WebSocket` class or class that extends it
4649
3172
  * @param {Function} [callback] A listener for the `listening` event
4650
3173
  */
4651
- constructor(options, callback2) {
3174
+ constructor(options, callback) {
4652
3175
  super();
4653
3176
  options = {
4654
3177
  maxPayload: 100 * 1024 * 1024,
@@ -4685,7 +3208,7 @@ var require_websocket_server = __commonJS({
4685
3208
  options.port,
4686
3209
  options.host,
4687
3210
  options.backlog,
4688
- callback2
3211
+ callback
4689
3212
  );
4690
3213
  } else if (options.server) {
4691
3214
  this._server = options.server;
@@ -4996,190 +3519,194 @@ var require_websocket_server = __commonJS({
4996
3519
  // src/main.ts
4997
3520
  var main_exports = {};
4998
3521
  __export(main_exports, {
4999
- App: () => App,
5000
- Connection: () => Connection
3522
+ AgentHl7Channel: () => AgentHl7Channel,
3523
+ AgentHl7ChannelConnection: () => AgentHl7ChannelConnection,
3524
+ App: () => App
5001
3525
  });
5002
3526
  module.exports = __toCommonJS(main_exports);
5003
3527
 
5004
3528
  // ../core/dist/esm/index.mjs
5005
- var ze = "ok";
5006
- var Ke = "created";
5007
- var Ye = "not-modified";
5008
- var Xe = "not-found";
5009
- var he = "accepted";
5010
- var Vt = { resourceType: "OperationOutcome", id: Xe, issue: [{ severity: "error", code: "not-found", details: { text: "Not found" } }] };
5011
- function k(r4, e) {
3529
+ var Ke = "ok";
3530
+ var Je = "created";
3531
+ var Xe = "not-modified";
3532
+ var Ze = "not-found";
3533
+ var me = "accepted";
3534
+ var Ut = { resourceType: "OperationOutcome", id: Ze, issue: [{ severity: "error", code: "not-found", details: { text: "Not found" } }] };
3535
+ function D(r4, e) {
5012
3536
  return { resourceType: "OperationOutcome", issue: [{ severity: "error", code: "invalid", details: { text: r4 }, expression: e ? [e] : void 0 }] };
5013
3537
  }
5014
- function ye(r4) {
3538
+ function he(r4) {
5015
3539
  return typeof r4 == "object" && r4 !== null && r4.resourceType === "OperationOutcome";
5016
3540
  }
5017
- function Ze(r4) {
5018
- return r4.id === ze || r4.id === Ke || r4.id === Ye || r4.id === he;
3541
+ function et(r4) {
3542
+ return r4.id === Ke || r4.id === Je || r4.id === Xe || r4.id === me;
5019
3543
  }
5020
3544
  var m = class extends Error {
5021
3545
  constructor(t, n) {
5022
- super(Lt(t));
3546
+ super(_t(t));
5023
3547
  this.outcome = t, this.cause = n;
5024
3548
  }
5025
3549
  };
5026
- function et(r4) {
5027
- return r4 instanceof m ? r4.outcome : ye(r4) ? r4 : k(jr(r4));
3550
+ function tt(r4) {
3551
+ return r4 instanceof m ? r4.outcome : he(r4) ? r4 : D(Qr(r4));
5028
3552
  }
5029
- function jr(r4) {
5030
- return r4 ? typeof r4 == "string" ? r4 : r4 instanceof Error ? r4.message : ye(r4) ? Lt(r4) : typeof r4 == "object" && "code" in r4 && typeof r4.code == "string" ? r4.code : JSON.stringify(r4) : "Unknown error";
3553
+ function Qr(r4) {
3554
+ return r4 ? typeof r4 == "string" ? r4 : r4 instanceof Error ? r4.message : he(r4) ? _t(r4) : typeof r4 == "object" && "code" in r4 && typeof r4.code == "string" ? r4.code : JSON.stringify(r4) : "Unknown error";
5031
3555
  }
5032
- function Lt(r4) {
5033
- let e = r4.issue?.map($r) ?? [];
3556
+ function _t(r4) {
3557
+ let e = r4.issue?.map(Hr) ?? [];
5034
3558
  return e.length > 0 ? e.join("; ") : "Unknown error";
5035
3559
  }
5036
- function $r(r4) {
3560
+ function Hr(r4) {
5037
3561
  let e = r4.details?.text ?? r4.diagnostics ?? "Unknown error";
5038
3562
  return r4.expression?.length && (e += ` (${r4.expression.join(", ")})`), e;
5039
3563
  }
5040
- var Mt = { types: { Element: { display: "Element", properties: { id: { type: [{ code: "string" }] }, extension: { max: "*", type: [{ code: "Extension" }] } } }, BackboneElement: { display: "BackboneElement", properties: { id: { type: [{ code: "string" }] }, extension: { max: "*", type: [{ code: "Extension" }] }, modifierExtension: { max: "*", type: [{ code: "Extension" }] } } }, Address: { display: "Address", properties: { id: { type: [{ code: "string" }] }, extension: { max: "*", type: [{ code: "Extension" }] }, use: { type: [{ code: "code" }] }, type: { type: [{ code: "code" }] }, text: { type: [{ code: "string" }] }, line: { max: "*", 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: { display: "Age", properties: { id: { type: [{ code: "string" }] }, extension: { max: "*", type: [{ code: "Extension" }] }, value: { type: [{ code: "decimal" }] }, comparator: { type: [{ code: "code" }] }, unit: { type: [{ code: "string" }] }, system: { type: [{ code: "uri" }] }, code: { type: [{ code: "code" }] } } }, Annotation: { display: "Annotation", properties: { id: { type: [{ code: "string" }] }, extension: { max: "*", 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: { display: "Attachment", properties: { id: { type: [{ code: "string" }] }, extension: { max: "*", 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: { display: "CodeableConcept", properties: { id: { type: [{ code: "string" }] }, extension: { max: "*", type: [{ code: "Extension" }] }, coding: { max: "*", type: [{ code: "Coding" }] }, text: { type: [{ code: "string" }] } } }, Coding: { display: "Coding", properties: { id: { type: [{ code: "string" }] }, extension: { max: "*", type: [{ code: "Extension" }] }, system: { type: [{ code: "uri" }] }, version: { type: [{ code: "string" }] }, code: { type: [{ code: "code" }] }, display: { type: [{ code: "string" }] }, userSelected: { type: [{ code: "boolean" }] } } }, ContactDetail: { display: "ContactDetail", properties: { id: { type: [{ code: "string" }] }, extension: { max: "*", type: [{ code: "Extension" }] }, name: { type: [{ code: "string" }] }, telecom: { max: "*", type: [{ code: "ContactPoint" }] } } }, ContactPoint: { display: "ContactPoint", properties: { id: { type: [{ code: "string" }] }, extension: { max: "*", type: [{ code: "Extension" }] }, system: { type: [{ code: "code" }] }, value: { type: [{ code: "string" }] }, use: { type: [{ code: "code" }] }, rank: { type: [{ code: "positiveInt" }] }, period: { type: [{ code: "Period" }] } } }, Contributor: { display: "Contributor", properties: { id: { type: [{ code: "string" }] }, extension: { max: "*", type: [{ code: "Extension" }] }, type: { min: 1, type: [{ code: "code" }] }, name: { min: 1, type: [{ code: "string" }] }, contact: { max: "*", type: [{ code: "ContactDetail" }] } } }, Count: { display: "Count", properties: { id: { type: [{ code: "string" }] }, extension: { max: "*", type: [{ code: "Extension" }] }, value: { type: [{ code: "decimal" }] }, comparator: { type: [{ code: "code" }] }, unit: { type: [{ code: "string" }] }, system: { type: [{ code: "uri" }] }, code: { type: [{ code: "code" }] } } }, DataRequirement: { display: "DataRequirement", properties: { id: { type: [{ code: "string" }] }, extension: { max: "*", type: [{ code: "Extension" }] }, type: { min: 1, type: [{ code: "code" }] }, profile: { max: "*", 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: "*", type: [{ code: "string" }] }, codeFilter: { max: "*", type: [{ code: "Element" }] }, dateFilter: { max: "*", type: [{ code: "Element" }] }, limit: { type: [{ code: "positiveInt" }] }, sort: { max: "*", type: [{ code: "Element" }] } } }, DataRequirementCodeFilter: { display: "DataRequirementCodeFilter", properties: { id: { type: [{ code: "string" }] }, extension: { max: "*", type: [{ code: "Extension" }] }, path: { type: [{ code: "string" }] }, searchParam: { type: [{ code: "string" }] }, valueSet: { type: [{ code: "canonical", targetProfile: ["http://hl7.org/fhir/StructureDefinition/ValueSet"] }] }, code: { max: "*", type: [{ code: "Coding" }] } } }, DataRequirementDateFilter: { display: "DataRequirementDateFilter", properties: { id: { type: [{ code: "string" }] }, extension: { max: "*", type: [{ code: "Extension" }] }, path: { type: [{ code: "string" }] }, searchParam: { type: [{ code: "string" }] }, "value[x]": { type: [{ code: "dateTime" }, { code: "Period" }, { code: "Duration" }] } } }, DataRequirementSort: { display: "DataRequirementSort", properties: { id: { type: [{ code: "string" }] }, extension: { max: "*", type: [{ code: "Extension" }] }, path: { min: 1, type: [{ code: "string" }] }, direction: { min: 1, type: [{ code: "code" }] } } }, Distance: { display: "Distance", properties: { id: { type: [{ code: "string" }] }, extension: { max: "*", type: [{ code: "Extension" }] }, value: { type: [{ code: "decimal" }] }, comparator: { type: [{ code: "code" }] }, unit: { type: [{ code: "string" }] }, system: { type: [{ code: "uri" }] }, code: { type: [{ code: "code" }] } } }, Dosage: { display: "Dosage", properties: { id: { type: [{ code: "string" }] }, extension: { max: "*", type: [{ code: "Extension" }] }, modifierExtension: { max: "*", type: [{ code: "Extension" }] }, sequence: { type: [{ code: "integer" }] }, text: { type: [{ code: "string" }] }, additionalInstruction: { max: "*", 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: "*", type: [{ code: "Element" }] }, maxDosePerPeriod: { type: [{ code: "Ratio" }] }, maxDosePerAdministration: { type: [{ code: "Quantity", profile: ["http://hl7.org/fhir/StructureDefinition/SimpleQuantity"] }] }, maxDosePerLifetime: { type: [{ code: "Quantity", profile: ["http://hl7.org/fhir/StructureDefinition/SimpleQuantity"] }] } } }, DosageDoseAndRate: { display: "DosageDoseAndRate", properties: { id: { type: [{ code: "string" }] }, extension: { max: "*", type: [{ code: "Extension" }] }, type: { type: [{ code: "CodeableConcept" }] }, "dose[x]": { type: [{ code: "Range" }, { code: "Quantity", profile: ["http://hl7.org/fhir/StructureDefinition/SimpleQuantity"] }] }, "rate[x]": { type: [{ code: "Ratio" }, { code: "Range" }, { code: "Quantity", profile: ["http://hl7.org/fhir/StructureDefinition/SimpleQuantity"] }] } } }, Duration: { display: "Duration", properties: { id: { type: [{ code: "string" }] }, extension: { max: "*", type: [{ code: "Extension" }] }, value: { type: [{ code: "decimal" }] }, comparator: { type: [{ code: "code" }] }, unit: { type: [{ code: "string" }] }, system: { type: [{ code: "uri" }] }, code: { type: [{ code: "code" }] } } }, ElementDefinition: { display: "ElementDefinition", properties: { id: { type: [{ code: "string" }] }, extension: { max: "*", type: [{ code: "Extension" }] }, modifierExtension: { max: "*", type: [{ code: "Extension" }] }, path: { min: 1, type: [{ code: "string" }] }, representation: { max: "*", type: [{ code: "code" }] }, sliceName: { type: [{ code: "string" }] }, sliceIsConstraining: { type: [{ code: "boolean" }] }, label: { type: [{ code: "string" }] }, code: { max: "*", type: [{ code: "Coding" }] }, slicing: { type: [{ code: "Element" }] }, short: { type: [{ code: "string" }] }, definition: { type: [{ code: "markdown" }] }, comment: { type: [{ code: "markdown" }] }, requirements: { type: [{ code: "markdown" }] }, alias: { max: "*", type: [{ code: "string" }] }, min: { type: [{ code: "unsignedInt" }] }, max: { type: [{ code: "string" }] }, base: { type: [{ code: "Element" }] }, contentReference: { type: [{ code: "uri" }] }, type: { max: "*", type: [{ code: "Element" }] }, "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: "*", type: [{ code: "Element" }] }, "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: "*", type: [{ code: "id" }] }, constraint: { max: "*", type: [{ code: "Element" }] }, mustSupport: { type: [{ code: "boolean" }] }, isModifier: { type: [{ code: "boolean" }] }, isModifierReason: { type: [{ code: "string" }] }, isSummary: { type: [{ code: "boolean" }] }, binding: { type: [{ code: "Element" }] }, mapping: { max: "*", type: [{ code: "Element" }] } } }, ElementDefinitionSlicing: { display: "ElementDefinitionSlicing", properties: { id: { type: [{ code: "string" }] }, extension: { max: "*", type: [{ code: "Extension" }] }, discriminator: { max: "*", type: [{ code: "Element" }] }, description: { type: [{ code: "string" }] }, ordered: { type: [{ code: "boolean" }] }, rules: { min: 1, type: [{ code: "code" }] } } }, ElementDefinitionSlicingDiscriminator: { display: "ElementDefinitionSlicingDiscriminator", properties: { id: { type: [{ code: "string" }] }, extension: { max: "*", type: [{ code: "Extension" }] }, type: { min: 1, type: [{ code: "code" }] }, path: { min: 1, type: [{ code: "string" }] } } }, ElementDefinitionBase: { display: "ElementDefinitionBase", properties: { id: { type: [{ code: "string" }] }, extension: { max: "*", type: [{ code: "Extension" }] }, path: { min: 1, type: [{ code: "string" }] }, min: { min: 1, type: [{ code: "unsignedInt" }] }, max: { min: 1, type: [{ code: "string" }] } } }, ElementDefinitionType: { display: "ElementDefinitionType", properties: { id: { type: [{ code: "string" }] }, extension: { max: "*", type: [{ code: "Extension" }] }, code: { min: 1, type: [{ code: "uri" }] }, profile: { max: "*", type: [{ code: "canonical", targetProfile: ["http://hl7.org/fhir/StructureDefinition/StructureDefinition", "http://hl7.org/fhir/StructureDefinition/ImplementationGuide"] }] }, targetProfile: { max: "*", type: [{ code: "canonical", targetProfile: ["http://hl7.org/fhir/StructureDefinition/StructureDefinition", "http://hl7.org/fhir/StructureDefinition/ImplementationGuide"] }] }, aggregation: { max: "*", type: [{ code: "code" }] }, versioning: { type: [{ code: "code" }] } } }, ElementDefinitionExample: { display: "ElementDefinitionExample", properties: { id: { type: [{ code: "string" }] }, extension: { max: "*", type: [{ code: "Extension" }] }, label: { min: 1, type: [{ code: "string" }] }, "value[x]": { min: 1, 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" }] } } }, ElementDefinitionConstraint: { display: "ElementDefinitionConstraint", properties: { id: { type: [{ code: "string" }] }, extension: { max: "*", type: [{ code: "Extension" }] }, key: { min: 1, type: [{ code: "id" }] }, requirements: { type: [{ code: "string" }] }, severity: { min: 1, type: [{ code: "code" }] }, human: { min: 1, type: [{ code: "string" }] }, expression: { type: [{ code: "string" }] }, xpath: { type: [{ code: "string" }] }, source: { type: [{ code: "canonical", targetProfile: ["http://hl7.org/fhir/StructureDefinition/StructureDefinition"] }] } } }, ElementDefinitionBinding: { display: "ElementDefinitionBinding", properties: { id: { type: [{ code: "string" }] }, extension: { max: "*", type: [{ code: "Extension" }] }, strength: { min: 1, type: [{ code: "code" }] }, description: { type: [{ code: "string" }] }, valueSet: { type: [{ code: "canonical", targetProfile: ["http://hl7.org/fhir/StructureDefinition/ValueSet"] }] } } }, ElementDefinitionMapping: { display: "ElementDefinitionMapping", properties: { id: { type: [{ code: "string" }] }, extension: { max: "*", type: [{ code: "Extension" }] }, identity: { min: 1, type: [{ code: "id" }] }, language: { type: [{ code: "code" }] }, map: { min: 1, type: [{ code: "string" }] }, comment: { type: [{ code: "string" }] } } }, Expression: { display: "Expression", properties: { id: { type: [{ code: "string" }] }, extension: { max: "*", 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: { display: "Extension", properties: { id: { type: [{ code: "string" }] }, extension: { max: "*", 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: { display: "HumanName", properties: { id: { type: [{ code: "string" }] }, extension: { max: "*", type: [{ code: "Extension" }] }, use: { type: [{ code: "code" }] }, text: { type: [{ code: "string" }] }, family: { type: [{ code: "string" }] }, given: { max: "*", type: [{ code: "string" }] }, prefix: { max: "*", type: [{ code: "string" }] }, suffix: { max: "*", type: [{ code: "string" }] }, period: { type: [{ code: "Period" }] } } }, Identifier: { display: "Identifier", properties: { id: { type: [{ code: "string" }] }, extension: { max: "*", 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: { display: "MarketingStatus", properties: { id: { type: [{ code: "string" }] }, extension: { max: "*", type: [{ code: "Extension" }] }, modifierExtension: { max: "*", 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: { display: "Meta", properties: { id: { type: [{ code: "string" }] }, extension: { max: "*", type: [{ code: "Extension" }] }, versionId: { type: [{ code: "id" }] }, lastUpdated: { type: [{ code: "instant" }] }, source: { type: [{ code: "uri" }] }, profile: { max: "*", type: [{ code: "canonical", targetProfile: ["http://hl7.org/fhir/StructureDefinition/StructureDefinition"] }] }, security: { max: "*", type: [{ code: "Coding" }] }, tag: { max: "*", type: [{ code: "Coding" }] }, project: { type: [{ code: "uri" }] }, author: { type: [{ code: "Reference" }] }, account: { type: [{ code: "Reference" }] }, compartment: { max: "*", type: [{ code: "Reference" }] } } }, Money: { display: "Money", properties: { id: { type: [{ code: "string" }] }, extension: { max: "*", type: [{ code: "Extension" }] }, value: { type: [{ code: "decimal" }] }, currency: { type: [{ code: "code" }] } } }, Narrative: { display: "Narrative", properties: { id: { type: [{ code: "string" }] }, extension: { max: "*", type: [{ code: "Extension" }] }, status: { min: 1, type: [{ code: "code" }] }, div: { min: 1, type: [{ code: "xhtml" }] } } }, ParameterDefinition: { display: "ParameterDefinition", properties: { id: { type: [{ code: "string" }] }, extension: { max: "*", 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: { display: "Period", properties: { id: { type: [{ code: "string" }] }, extension: { max: "*", type: [{ code: "Extension" }] }, start: { type: [{ code: "dateTime" }] }, end: { type: [{ code: "dateTime" }] } } }, Population: { display: "Population", properties: { id: { type: [{ code: "string" }] }, extension: { max: "*", type: [{ code: "Extension" }] }, modifierExtension: { max: "*", type: [{ code: "Extension" }] }, "age[x]": { type: [{ code: "Range" }, { code: "CodeableConcept" }] }, gender: { type: [{ code: "CodeableConcept" }] }, race: { type: [{ code: "CodeableConcept" }] }, physiologicalCondition: { type: [{ code: "CodeableConcept" }] } } }, ProdCharacteristic: { display: "ProdCharacteristic", properties: { id: { type: [{ code: "string" }] }, extension: { max: "*", type: [{ code: "Extension" }] }, modifierExtension: { max: "*", 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: "*", type: [{ code: "string" }] }, imprint: { max: "*", type: [{ code: "string" }] }, image: { max: "*", type: [{ code: "Attachment" }] }, scoring: { type: [{ code: "CodeableConcept" }] } } }, ProductShelfLife: { display: "ProductShelfLife", properties: { id: { type: [{ code: "string" }] }, extension: { max: "*", type: [{ code: "Extension" }] }, modifierExtension: { max: "*", type: [{ code: "Extension" }] }, identifier: { type: [{ code: "Identifier" }] }, type: { min: 1, type: [{ code: "CodeableConcept" }] }, period: { min: 1, type: [{ code: "Quantity" }] }, specialPrecautionsForStorage: { max: "*", type: [{ code: "CodeableConcept" }] } } }, Quantity: { display: "Quantity", properties: { id: { type: [{ code: "string" }] }, extension: { max: "*", 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" }] } } }, Range: { display: "Range", properties: { id: { type: [{ code: "string" }] }, extension: { max: "*", type: [{ code: "Extension" }] }, low: { type: [{ code: "Quantity", profile: ["http://hl7.org/fhir/StructureDefinition/SimpleQuantity"] }] }, high: { type: [{ code: "Quantity", profile: ["http://hl7.org/fhir/StructureDefinition/SimpleQuantity"] }] } } }, Ratio: { display: "Ratio", properties: { id: { type: [{ code: "string" }] }, extension: { max: "*", type: [{ code: "Extension" }] }, numerator: { type: [{ code: "Quantity" }] }, denominator: { type: [{ code: "Quantity" }] } } }, Reference: { display: "Reference", properties: { id: { type: [{ code: "string" }] }, extension: { max: "*", type: [{ code: "Extension" }] }, reference: { type: [{ code: "string" }] }, type: { type: [{ code: "uri" }] }, identifier: { type: [{ code: "Identifier" }] }, display: { type: [{ code: "string" }] } } }, RelatedArtifact: { display: "RelatedArtifact", properties: { id: { type: [{ code: "string" }] }, extension: { max: "*", 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: { display: "SampledData", properties: { id: { type: [{ code: "string" }] }, extension: { max: "*", type: [{ code: "Extension" }] }, origin: { min: 1, type: [{ code: "Quantity", profile: ["http://hl7.org/fhir/StructureDefinition/SimpleQuantity"] }] }, 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: { display: "Signature", properties: { id: { type: [{ code: "string" }] }, extension: { max: "*", type: [{ code: "Extension" }] }, type: { min: 1, max: "*", 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: { display: "SubstanceAmount", properties: { id: { type: [{ code: "string" }] }, extension: { max: "*", type: [{ code: "Extension" }] }, modifierExtension: { max: "*", type: [{ code: "Extension" }] }, "amount[x]": { type: [{ code: "Quantity" }, { code: "Range" }, { code: "string" }] }, amountType: { type: [{ code: "CodeableConcept" }] }, amountText: { type: [{ code: "string" }] }, referenceRange: { type: [{ code: "Element" }] } } }, SubstanceAmountReferenceRange: { display: "SubstanceAmountReferenceRange", properties: { id: { type: [{ code: "string" }] }, extension: { max: "*", type: [{ code: "Extension" }] }, lowLimit: { type: [{ code: "Quantity" }] }, highLimit: { type: [{ code: "Quantity" }] } } }, Timing: { display: "Timing", properties: { id: { type: [{ code: "string" }] }, extension: { max: "*", type: [{ code: "Extension" }] }, modifierExtension: { max: "*", type: [{ code: "Extension" }] }, event: { max: "*", type: [{ code: "dateTime" }] }, repeat: { type: [{ code: "Element" }] }, code: { type: [{ code: "CodeableConcept" }] } } }, TimingRepeat: { display: "TimingRepeat", properties: { id: { type: [{ code: "string" }] }, extension: { max: "*", type: [{ code: "Extension" }] }, "bounds[x]": { type: [{ code: "Duration" }, { code: "Range" }, { code: "Period" }] }, count: { type: [{ code: "positiveInt" }] }, countMax: { type: [{ code: "positiveInt" }] }, duration: { type: [{ code: "decimal" }] }, durationMax: { type: [{ code: "decimal" }] }, durationUnit: { type: [{ code: "code" }] }, frequency: { type: [{ code: "positiveInt" }] }, frequencyMax: { type: [{ code: "positiveInt" }] }, period: { type: [{ code: "decimal" }] }, periodMax: { type: [{ code: "decimal" }] }, periodUnit: { type: [{ code: "code" }] }, dayOfWeek: { max: "*", type: [{ code: "code" }] }, timeOfDay: { max: "*", type: [{ code: "time" }] }, when: { max: "*", type: [{ code: "code" }] }, offset: { type: [{ code: "unsignedInt" }] } } }, TriggerDefinition: { display: "TriggerDefinition", properties: { id: { type: [{ code: "string" }] }, extension: { max: "*", 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: "*", type: [{ code: "DataRequirement" }] }, condition: { type: [{ code: "Expression" }] } } }, UsageContext: { display: "UsageContext", properties: { id: { type: [{ code: "string" }] }, extension: { max: "*", 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"] }] } } }, MetadataResource: { display: "MetadataResource", properties: { id: { type: [{ code: "string" }] }, meta: { type: [{ code: "Meta" }] }, implicitRules: { type: [{ code: "uri" }] }, language: { type: [{ code: "code" }] }, text: { type: [{ code: "Narrative" }] }, contained: { max: "*", type: [{ code: "Resource" }] }, extension: { max: "*", type: [{ code: "Extension" }] }, modifierExtension: { max: "*", 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: "*", type: [{ code: "ContactDetail" }] }, description: { type: [{ code: "markdown" }] }, useContext: { max: "*", type: [{ code: "UsageContext" }] }, jurisdiction: { max: "*", type: [{ code: "CodeableConcept" }] } } }, IdentityProvider: { display: "IdentityProvider", properties: { 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" }] } } } } };
5041
- function Bt(r4, e) {
3564
+ var Bt = { types: { Element: { display: "Element", properties: { id: { type: [{ code: "string" }] }, extension: { max: "*", type: [{ code: "Extension" }] } } }, BackboneElement: { display: "BackboneElement", properties: { id: { type: [{ code: "string" }] }, extension: { max: "*", type: [{ code: "Extension" }] }, modifierExtension: { max: "*", type: [{ code: "Extension" }] } } }, Address: { display: "Address", properties: { id: { type: [{ code: "string" }] }, extension: { max: "*", type: [{ code: "Extension" }] }, use: { type: [{ code: "code" }] }, type: { type: [{ code: "code" }] }, text: { type: [{ code: "string" }] }, line: { max: "*", 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: { display: "Age", properties: { id: { type: [{ code: "string" }] }, extension: { max: "*", type: [{ code: "Extension" }] }, value: { type: [{ code: "decimal" }] }, comparator: { type: [{ code: "code" }] }, unit: { type: [{ code: "string" }] }, system: { type: [{ code: "uri" }] }, code: { type: [{ code: "code" }] } } }, Annotation: { display: "Annotation", properties: { id: { type: [{ code: "string" }] }, extension: { max: "*", 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: { display: "Attachment", properties: { id: { type: [{ code: "string" }] }, extension: { max: "*", 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: { display: "CodeableConcept", properties: { id: { type: [{ code: "string" }] }, extension: { max: "*", type: [{ code: "Extension" }] }, coding: { max: "*", type: [{ code: "Coding" }] }, text: { type: [{ code: "string" }] } } }, Coding: { display: "Coding", properties: { id: { type: [{ code: "string" }] }, extension: { max: "*", type: [{ code: "Extension" }] }, system: { type: [{ code: "uri" }] }, version: { type: [{ code: "string" }] }, code: { type: [{ code: "code" }] }, display: { type: [{ code: "string" }] }, userSelected: { type: [{ code: "boolean" }] } } }, ContactDetail: { display: "ContactDetail", properties: { id: { type: [{ code: "string" }] }, extension: { max: "*", type: [{ code: "Extension" }] }, name: { type: [{ code: "string" }] }, telecom: { max: "*", type: [{ code: "ContactPoint" }] } } }, ContactPoint: { display: "ContactPoint", properties: { id: { type: [{ code: "string" }] }, extension: { max: "*", type: [{ code: "Extension" }] }, system: { type: [{ code: "code" }] }, value: { type: [{ code: "string" }] }, use: { type: [{ code: "code" }] }, rank: { type: [{ code: "positiveInt" }] }, period: { type: [{ code: "Period" }] } } }, Contributor: { display: "Contributor", properties: { id: { type: [{ code: "string" }] }, extension: { max: "*", type: [{ code: "Extension" }] }, type: { min: 1, type: [{ code: "code" }] }, name: { min: 1, type: [{ code: "string" }] }, contact: { max: "*", type: [{ code: "ContactDetail" }] } } }, Count: { display: "Count", properties: { id: { type: [{ code: "string" }] }, extension: { max: "*", type: [{ code: "Extension" }] }, value: { type: [{ code: "decimal" }] }, comparator: { type: [{ code: "code" }] }, unit: { type: [{ code: "string" }] }, system: { type: [{ code: "uri" }] }, code: { type: [{ code: "code" }] } } }, DataRequirement: { display: "DataRequirement", properties: { id: { type: [{ code: "string" }] }, extension: { max: "*", type: [{ code: "Extension" }] }, type: { min: 1, type: [{ code: "code" }] }, profile: { max: "*", 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: "*", type: [{ code: "string" }] }, codeFilter: { max: "*", type: [{ code: "Element" }] }, dateFilter: { max: "*", type: [{ code: "Element" }] }, limit: { type: [{ code: "positiveInt" }] }, sort: { max: "*", type: [{ code: "Element" }] } } }, DataRequirementCodeFilter: { display: "DataRequirementCodeFilter", properties: { id: { type: [{ code: "string" }] }, extension: { max: "*", type: [{ code: "Extension" }] }, path: { type: [{ code: "string" }] }, searchParam: { type: [{ code: "string" }] }, valueSet: { type: [{ code: "canonical", targetProfile: ["http://hl7.org/fhir/StructureDefinition/ValueSet"] }] }, code: { max: "*", type: [{ code: "Coding" }] } } }, DataRequirementDateFilter: { display: "DataRequirementDateFilter", properties: { id: { type: [{ code: "string" }] }, extension: { max: "*", type: [{ code: "Extension" }] }, path: { type: [{ code: "string" }] }, searchParam: { type: [{ code: "string" }] }, "value[x]": { type: [{ code: "dateTime" }, { code: "Period" }, { code: "Duration" }] } } }, DataRequirementSort: { display: "DataRequirementSort", properties: { id: { type: [{ code: "string" }] }, extension: { max: "*", type: [{ code: "Extension" }] }, path: { min: 1, type: [{ code: "string" }] }, direction: { min: 1, type: [{ code: "code" }] } } }, Distance: { display: "Distance", properties: { id: { type: [{ code: "string" }] }, extension: { max: "*", type: [{ code: "Extension" }] }, value: { type: [{ code: "decimal" }] }, comparator: { type: [{ code: "code" }] }, unit: { type: [{ code: "string" }] }, system: { type: [{ code: "uri" }] }, code: { type: [{ code: "code" }] } } }, Dosage: { display: "Dosage", properties: { id: { type: [{ code: "string" }] }, extension: { max: "*", type: [{ code: "Extension" }] }, modifierExtension: { max: "*", type: [{ code: "Extension" }] }, sequence: { type: [{ code: "integer" }] }, text: { type: [{ code: "string" }] }, additionalInstruction: { max: "*", 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: "*", type: [{ code: "Element" }] }, maxDosePerPeriod: { type: [{ code: "Ratio" }] }, maxDosePerAdministration: { type: [{ code: "Quantity", profile: ["http://hl7.org/fhir/StructureDefinition/SimpleQuantity"] }] }, maxDosePerLifetime: { type: [{ code: "Quantity", profile: ["http://hl7.org/fhir/StructureDefinition/SimpleQuantity"] }] } } }, DosageDoseAndRate: { display: "DosageDoseAndRate", properties: { id: { type: [{ code: "string" }] }, extension: { max: "*", type: [{ code: "Extension" }] }, type: { type: [{ code: "CodeableConcept" }] }, "dose[x]": { type: [{ code: "Range" }, { code: "Quantity", profile: ["http://hl7.org/fhir/StructureDefinition/SimpleQuantity"] }] }, "rate[x]": { type: [{ code: "Ratio" }, { code: "Range" }, { code: "Quantity", profile: ["http://hl7.org/fhir/StructureDefinition/SimpleQuantity"] }] } } }, Duration: { display: "Duration", properties: { id: { type: [{ code: "string" }] }, extension: { max: "*", type: [{ code: "Extension" }] }, value: { type: [{ code: "decimal" }] }, comparator: { type: [{ code: "code" }] }, unit: { type: [{ code: "string" }] }, system: { type: [{ code: "uri" }] }, code: { type: [{ code: "code" }] } } }, ElementDefinition: { display: "ElementDefinition", properties: { id: { type: [{ code: "string" }] }, extension: { max: "*", type: [{ code: "Extension" }] }, modifierExtension: { max: "*", type: [{ code: "Extension" }] }, path: { min: 1, type: [{ code: "string" }] }, representation: { max: "*", type: [{ code: "code" }] }, sliceName: { type: [{ code: "string" }] }, sliceIsConstraining: { type: [{ code: "boolean" }] }, label: { type: [{ code: "string" }] }, code: { max: "*", type: [{ code: "Coding" }] }, slicing: { type: [{ code: "Element" }] }, short: { type: [{ code: "string" }] }, definition: { type: [{ code: "markdown" }] }, comment: { type: [{ code: "markdown" }] }, requirements: { type: [{ code: "markdown" }] }, alias: { max: "*", type: [{ code: "string" }] }, min: { type: [{ code: "unsignedInt" }] }, max: { type: [{ code: "string" }] }, base: { type: [{ code: "Element" }] }, contentReference: { type: [{ code: "uri" }] }, type: { max: "*", type: [{ code: "Element" }] }, "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: "*", type: [{ code: "Element" }] }, "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: "*", type: [{ code: "id" }] }, constraint: { max: "*", type: [{ code: "Element" }] }, mustSupport: { type: [{ code: "boolean" }] }, isModifier: { type: [{ code: "boolean" }] }, isModifierReason: { type: [{ code: "string" }] }, isSummary: { type: [{ code: "boolean" }] }, binding: { type: [{ code: "Element" }] }, mapping: { max: "*", type: [{ code: "Element" }] } } }, ElementDefinitionSlicing: { display: "ElementDefinitionSlicing", properties: { id: { type: [{ code: "string" }] }, extension: { max: "*", type: [{ code: "Extension" }] }, discriminator: { max: "*", type: [{ code: "Element" }] }, description: { type: [{ code: "string" }] }, ordered: { type: [{ code: "boolean" }] }, rules: { min: 1, type: [{ code: "code" }] } } }, ElementDefinitionSlicingDiscriminator: { display: "ElementDefinitionSlicingDiscriminator", properties: { id: { type: [{ code: "string" }] }, extension: { max: "*", type: [{ code: "Extension" }] }, type: { min: 1, type: [{ code: "code" }] }, path: { min: 1, type: [{ code: "string" }] } } }, ElementDefinitionBase: { display: "ElementDefinitionBase", properties: { id: { type: [{ code: "string" }] }, extension: { max: "*", type: [{ code: "Extension" }] }, path: { min: 1, type: [{ code: "string" }] }, min: { min: 1, type: [{ code: "unsignedInt" }] }, max: { min: 1, type: [{ code: "string" }] } } }, ElementDefinitionType: { display: "ElementDefinitionType", properties: { id: { type: [{ code: "string" }] }, extension: { max: "*", type: [{ code: "Extension" }] }, code: { min: 1, type: [{ code: "uri" }] }, profile: { max: "*", type: [{ code: "canonical", targetProfile: ["http://hl7.org/fhir/StructureDefinition/StructureDefinition", "http://hl7.org/fhir/StructureDefinition/ImplementationGuide"] }] }, targetProfile: { max: "*", type: [{ code: "canonical", targetProfile: ["http://hl7.org/fhir/StructureDefinition/StructureDefinition", "http://hl7.org/fhir/StructureDefinition/ImplementationGuide"] }] }, aggregation: { max: "*", type: [{ code: "code" }] }, versioning: { type: [{ code: "code" }] } } }, ElementDefinitionExample: { display: "ElementDefinitionExample", properties: { id: { type: [{ code: "string" }] }, extension: { max: "*", type: [{ code: "Extension" }] }, label: { min: 1, type: [{ code: "string" }] }, "value[x]": { min: 1, 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" }] } } }, ElementDefinitionConstraint: { display: "ElementDefinitionConstraint", properties: { id: { type: [{ code: "string" }] }, extension: { max: "*", type: [{ code: "Extension" }] }, key: { min: 1, type: [{ code: "id" }] }, requirements: { type: [{ code: "string" }] }, severity: { min: 1, type: [{ code: "code" }] }, human: { min: 1, type: [{ code: "string" }] }, expression: { type: [{ code: "string" }] }, xpath: { type: [{ code: "string" }] }, source: { type: [{ code: "canonical", targetProfile: ["http://hl7.org/fhir/StructureDefinition/StructureDefinition"] }] } } }, ElementDefinitionBinding: { display: "ElementDefinitionBinding", properties: { id: { type: [{ code: "string" }] }, extension: { max: "*", type: [{ code: "Extension" }] }, strength: { min: 1, type: [{ code: "code" }] }, description: { type: [{ code: "string" }] }, valueSet: { type: [{ code: "canonical", targetProfile: ["http://hl7.org/fhir/StructureDefinition/ValueSet"] }] } } }, ElementDefinitionMapping: { display: "ElementDefinitionMapping", properties: { id: { type: [{ code: "string" }] }, extension: { max: "*", type: [{ code: "Extension" }] }, identity: { min: 1, type: [{ code: "id" }] }, language: { type: [{ code: "code" }] }, map: { min: 1, type: [{ code: "string" }] }, comment: { type: [{ code: "string" }] } } }, Expression: { display: "Expression", properties: { id: { type: [{ code: "string" }] }, extension: { max: "*", 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: { display: "Extension", properties: { id: { type: [{ code: "string" }] }, extension: { max: "*", 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: { display: "HumanName", properties: { id: { type: [{ code: "string" }] }, extension: { max: "*", type: [{ code: "Extension" }] }, use: { type: [{ code: "code" }] }, text: { type: [{ code: "string" }] }, family: { type: [{ code: "string" }] }, given: { max: "*", type: [{ code: "string" }] }, prefix: { max: "*", type: [{ code: "string" }] }, suffix: { max: "*", type: [{ code: "string" }] }, period: { type: [{ code: "Period" }] } } }, Identifier: { display: "Identifier", properties: { id: { type: [{ code: "string" }] }, extension: { max: "*", 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: { display: "MarketingStatus", properties: { id: { type: [{ code: "string" }] }, extension: { max: "*", type: [{ code: "Extension" }] }, modifierExtension: { max: "*", 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: { display: "Meta", properties: { id: { type: [{ code: "string" }] }, extension: { max: "*", type: [{ code: "Extension" }] }, versionId: { type: [{ code: "id" }] }, lastUpdated: { type: [{ code: "instant" }] }, source: { type: [{ code: "uri" }] }, profile: { max: "*", type: [{ code: "canonical", targetProfile: ["http://hl7.org/fhir/StructureDefinition/StructureDefinition"] }] }, security: { max: "*", type: [{ code: "Coding" }] }, tag: { max: "*", type: [{ code: "Coding" }] }, project: { type: [{ code: "uri" }] }, author: { type: [{ code: "Reference" }] }, account: { type: [{ code: "Reference" }] }, compartment: { max: "*", type: [{ code: "Reference" }] } } }, Money: { display: "Money", properties: { id: { type: [{ code: "string" }] }, extension: { max: "*", type: [{ code: "Extension" }] }, value: { type: [{ code: "decimal" }] }, currency: { type: [{ code: "code" }] } } }, Narrative: { display: "Narrative", properties: { id: { type: [{ code: "string" }] }, extension: { max: "*", type: [{ code: "Extension" }] }, status: { min: 1, type: [{ code: "code" }] }, div: { min: 1, type: [{ code: "xhtml" }] } } }, ParameterDefinition: { display: "ParameterDefinition", properties: { id: { type: [{ code: "string" }] }, extension: { max: "*", 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: { display: "Period", properties: { id: { type: [{ code: "string" }] }, extension: { max: "*", type: [{ code: "Extension" }] }, start: { type: [{ code: "dateTime" }] }, end: { type: [{ code: "dateTime" }] } } }, Population: { display: "Population", properties: { id: { type: [{ code: "string" }] }, extension: { max: "*", type: [{ code: "Extension" }] }, modifierExtension: { max: "*", type: [{ code: "Extension" }] }, "age[x]": { type: [{ code: "Range" }, { code: "CodeableConcept" }] }, gender: { type: [{ code: "CodeableConcept" }] }, race: { type: [{ code: "CodeableConcept" }] }, physiologicalCondition: { type: [{ code: "CodeableConcept" }] } } }, ProdCharacteristic: { display: "ProdCharacteristic", properties: { id: { type: [{ code: "string" }] }, extension: { max: "*", type: [{ code: "Extension" }] }, modifierExtension: { max: "*", 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: "*", type: [{ code: "string" }] }, imprint: { max: "*", type: [{ code: "string" }] }, image: { max: "*", type: [{ code: "Attachment" }] }, scoring: { type: [{ code: "CodeableConcept" }] } } }, ProductShelfLife: { display: "ProductShelfLife", properties: { id: { type: [{ code: "string" }] }, extension: { max: "*", type: [{ code: "Extension" }] }, modifierExtension: { max: "*", type: [{ code: "Extension" }] }, identifier: { type: [{ code: "Identifier" }] }, type: { min: 1, type: [{ code: "CodeableConcept" }] }, period: { min: 1, type: [{ code: "Quantity" }] }, specialPrecautionsForStorage: { max: "*", type: [{ code: "CodeableConcept" }] } } }, Quantity: { display: "Quantity", properties: { id: { type: [{ code: "string" }] }, extension: { max: "*", 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" }] } } }, Range: { display: "Range", properties: { id: { type: [{ code: "string" }] }, extension: { max: "*", type: [{ code: "Extension" }] }, low: { type: [{ code: "Quantity", profile: ["http://hl7.org/fhir/StructureDefinition/SimpleQuantity"] }] }, high: { type: [{ code: "Quantity", profile: ["http://hl7.org/fhir/StructureDefinition/SimpleQuantity"] }] } } }, Ratio: { display: "Ratio", properties: { id: { type: [{ code: "string" }] }, extension: { max: "*", type: [{ code: "Extension" }] }, numerator: { type: [{ code: "Quantity" }] }, denominator: { type: [{ code: "Quantity" }] } } }, Reference: { display: "Reference", properties: { id: { type: [{ code: "string" }] }, extension: { max: "*", type: [{ code: "Extension" }] }, reference: { type: [{ code: "string" }] }, type: { type: [{ code: "uri" }] }, identifier: { type: [{ code: "Identifier" }] }, display: { type: [{ code: "string" }] } } }, RelatedArtifact: { display: "RelatedArtifact", properties: { id: { type: [{ code: "string" }] }, extension: { max: "*", 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: { display: "SampledData", properties: { id: { type: [{ code: "string" }] }, extension: { max: "*", type: [{ code: "Extension" }] }, origin: { min: 1, type: [{ code: "Quantity", profile: ["http://hl7.org/fhir/StructureDefinition/SimpleQuantity"] }] }, 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: { display: "Signature", properties: { id: { type: [{ code: "string" }] }, extension: { max: "*", type: [{ code: "Extension" }] }, type: { min: 1, max: "*", 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: { display: "SubstanceAmount", properties: { id: { type: [{ code: "string" }] }, extension: { max: "*", type: [{ code: "Extension" }] }, modifierExtension: { max: "*", type: [{ code: "Extension" }] }, "amount[x]": { type: [{ code: "Quantity" }, { code: "Range" }, { code: "string" }] }, amountType: { type: [{ code: "CodeableConcept" }] }, amountText: { type: [{ code: "string" }] }, referenceRange: { type: [{ code: "Element" }] } } }, SubstanceAmountReferenceRange: { display: "SubstanceAmountReferenceRange", properties: { id: { type: [{ code: "string" }] }, extension: { max: "*", type: [{ code: "Extension" }] }, lowLimit: { type: [{ code: "Quantity" }] }, highLimit: { type: [{ code: "Quantity" }] } } }, Timing: { display: "Timing", properties: { id: { type: [{ code: "string" }] }, extension: { max: "*", type: [{ code: "Extension" }] }, modifierExtension: { max: "*", type: [{ code: "Extension" }] }, event: { max: "*", type: [{ code: "dateTime" }] }, repeat: { type: [{ code: "Element" }] }, code: { type: [{ code: "CodeableConcept" }] } } }, TimingRepeat: { display: "TimingRepeat", properties: { id: { type: [{ code: "string" }] }, extension: { max: "*", type: [{ code: "Extension" }] }, "bounds[x]": { type: [{ code: "Duration" }, { code: "Range" }, { code: "Period" }] }, count: { type: [{ code: "positiveInt" }] }, countMax: { type: [{ code: "positiveInt" }] }, duration: { type: [{ code: "decimal" }] }, durationMax: { type: [{ code: "decimal" }] }, durationUnit: { type: [{ code: "code" }] }, frequency: { type: [{ code: "positiveInt" }] }, frequencyMax: { type: [{ code: "positiveInt" }] }, period: { type: [{ code: "decimal" }] }, periodMax: { type: [{ code: "decimal" }] }, periodUnit: { type: [{ code: "code" }] }, dayOfWeek: { max: "*", type: [{ code: "code" }] }, timeOfDay: { max: "*", type: [{ code: "time" }] }, when: { max: "*", type: [{ code: "code" }] }, offset: { type: [{ code: "unsignedInt" }] } } }, TriggerDefinition: { display: "TriggerDefinition", properties: { id: { type: [{ code: "string" }] }, extension: { max: "*", 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: "*", type: [{ code: "DataRequirement" }] }, condition: { type: [{ code: "Expression" }] } } }, UsageContext: { display: "UsageContext", properties: { id: { type: [{ code: "string" }] }, extension: { max: "*", 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"] }] } } }, MetadataResource: { display: "MetadataResource", properties: { id: { type: [{ code: "string" }] }, meta: { type: [{ code: "Meta" }] }, implicitRules: { type: [{ code: "uri" }] }, language: { type: [{ code: "code" }] }, text: { type: [{ code: "Narrative" }] }, contained: { max: "*", type: [{ code: "Resource" }] }, extension: { max: "*", type: [{ code: "Extension" }] }, modifierExtension: { max: "*", 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: "*", type: [{ code: "ContactDetail" }] }, description: { type: [{ code: "markdown" }] }, useContext: { max: "*", type: [{ code: "UsageContext" }] }, jurisdiction: { max: "*", type: [{ code: "CodeableConcept" }] } } }, IdentityProvider: { display: "IdentityProvider", properties: { 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" }] } } } } };
3565
+ function Ft(r4, e) {
5042
3566
  let t = [];
5043
3567
  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.join(" ").trim();
5044
3568
  }
5045
- function ne(r4) {
5046
- let e = jt(r4), t = rn(r4);
3569
+ function ie(r4) {
3570
+ let e = $t(r4), t = on(r4);
5047
3571
  return t === e ? { reference: e } : { reference: e, display: t };
5048
3572
  }
5049
- function jt(r4) {
3573
+ function $t(r4) {
5050
3574
  return r4.resourceType + "/" + r4.id;
5051
3575
  }
5052
- function tn(r4) {
3576
+ function Ro(r4) {
3577
+ return r4?.reference?.split("/")[1];
3578
+ }
3579
+ function nn(r4) {
5053
3580
  return r4.resourceType === "Patient" || r4.resourceType === "Practitioner" || r4.resourceType === "RelatedPerson";
5054
3581
  }
5055
- function rn(r4) {
5056
- if (tn(r4)) {
5057
- let e = nn(r4);
3582
+ function on(r4) {
3583
+ if (nn(r4)) {
3584
+ let e = sn(r4);
5058
3585
  if (e)
5059
3586
  return e;
5060
3587
  }
5061
3588
  if (r4.resourceType === "Device") {
5062
- let e = on(r4);
3589
+ let e = an(r4);
5063
3590
  if (e)
5064
3591
  return e;
5065
3592
  }
5066
- 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);
3593
+ 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);
5067
3594
  }
5068
- function nn(r4) {
3595
+ function sn(r4) {
5069
3596
  let e = r4.name;
5070
3597
  if (e && e.length > 0)
5071
- return Bt(e[0]);
3598
+ return Ft(e[0]);
5072
3599
  }
5073
- function on(r4) {
3600
+ function an(r4) {
5074
3601
  let e = r4.deviceName;
5075
3602
  if (e && e.length > 0)
5076
3603
  return e[0].name;
5077
3604
  }
5078
- function ge(r4, e) {
3605
+ function ye(r4, e) {
5079
3606
  let t = new Date(r4);
5080
3607
  t.setUTCHours(0, 0, 0, 0);
5081
3608
  let n = e ? new Date(e) : /* @__PURE__ */ new Date();
5082
3609
  n.setUTCHours(0, 0, 0, 0);
5083
3610
  let i2 = t.getUTCFullYear(), o = t.getUTCMonth(), s = t.getUTCDate(), a = n.getUTCFullYear(), c2 = n.getUTCMonth(), p2 = n.getUTCDate(), l2 = a - i2;
5084
3611
  (c2 < o || c2 === o && p2 < s) && l2--;
5085
- let re = a * 12 + c2 - (i2 * 12 + o);
5086
- p2 < s && re--;
5087
- let me = Math.floor((n.getTime() - t.getTime()) / (1e3 * 60 * 60 * 24));
5088
- return { years: l2, months: re, days: me };
3612
+ let ne = a * 12 + c2 - (i2 * 12 + o);
3613
+ p2 < s && ne--;
3614
+ let fe = Math.floor((n.getTime() - t.getTime()) / (1e3 * 60 * 60 * 24));
3615
+ return { years: l2, months: ne, days: fe };
5089
3616
  }
5090
- function Ht(r4, e) {
5091
- return JSON.stringify(r4, sn, e ? 2 : void 0);
3617
+ function Wt(r4, e) {
3618
+ return JSON.stringify(r4, cn, e ? 2 : void 0);
5092
3619
  }
5093
- function sn(r4, e) {
5094
- return !an(r4) && v(e) ? void 0 : e;
3620
+ function cn(r4, e) {
3621
+ return !un(r4) && b(e) ? void 0 : e;
5095
3622
  }
5096
- function an(r4) {
3623
+ function un(r4) {
5097
3624
  return !!/\d+$/.exec(r4);
5098
3625
  }
5099
- function v(r4) {
3626
+ function b(r4) {
5100
3627
  if (r4 == null)
5101
3628
  return true;
5102
3629
  let e = typeof r4;
5103
3630
  return e === "string" && r4 === "" || e === "object" && Object.keys(r4).length === 0;
5104
3631
  }
5105
- function Gt(r4) {
3632
+ function zt(r4) {
5106
3633
  return r4.every((e) => typeof e == "string");
5107
3634
  }
5108
- var zt = [];
3635
+ var Kt = [];
5109
3636
  for (let r4 = 0; r4 < 256; r4++)
5110
- zt.push(r4.toString(16).padStart(2, "0"));
5111
- function Kt(r4) {
3637
+ Kt.push(r4.toString(16).padStart(2, "0"));
3638
+ function Jt(r4) {
5112
3639
  let e = new Uint8Array(r4), t = new Array(e.length);
5113
3640
  for (let n = 0; n < e.length; n++)
5114
- t[n] = zt[e[n]];
3641
+ t[n] = Kt[e[n]];
5115
3642
  return t.join("");
5116
3643
  }
5117
- function Jt(r4) {
3644
+ function Yt(r4) {
5118
3645
  let e = new Uint8Array(r4), t = [];
5119
3646
  for (let n = 0; n < e.length; n++)
5120
3647
  t[n] = String.fromCharCode(e[n]);
5121
3648
  return window.btoa(t.join(""));
5122
3649
  }
5123
- function b(r4) {
3650
+ function S(r4) {
5124
3651
  return r4.charAt(0).toUpperCase() + r4.substring(1);
5125
3652
  }
5126
- var ot = (r4) => new Promise((e) => {
3653
+ var st = (r4) => new Promise((e) => {
5127
3654
  setTimeout(e, r4);
5128
3655
  });
5129
- var q = ((u2) => (u2.Address = "Address", u2.Age = "Age", u2.Annotation = "Annotation", u2.Attachment = "Attachment", u2.BackboneElement = "BackboneElement", u2.CodeableConcept = "CodeableConcept", u2.Coding = "Coding", u2.ContactDetail = "ContactDetail", u2.ContactPoint = "ContactPoint", u2.Contributor = "Contributor", u2.Count = "Count", u2.DataRequirement = "DataRequirement", u2.Distance = "Distance", u2.Dosage = "Dosage", u2.Duration = "Duration", u2.Expression = "Expression", u2.Extension = "Extension", u2.HumanName = "HumanName", u2.Identifier = "Identifier", u2.MarketingStatus = "MarketingStatus", u2.Meta = "Meta", u2.Money = "Money", u2.Narrative = "Narrative", u2.ParameterDefinition = "ParameterDefinition", u2.Period = "Period", u2.Population = "Population", u2.ProdCharacteristic = "ProdCharacteristic", u2.ProductShelfLife = "ProductShelfLife", u2.Quantity = "Quantity", u2.Range = "Range", u2.Ratio = "Ratio", u2.Reference = "Reference", u2.RelatedArtifact = "RelatedArtifact", u2.SampledData = "SampledData", u2.Signature = "Signature", u2.SubstanceAmount = "SubstanceAmount", u2.SystemString = "http://hl7.org/fhirpath/System.String", u2.Timing = "Timing", u2.TriggerDefinition = "TriggerDefinition", u2.UsageContext = "UsageContext", u2.base64Binary = "base64Binary", u2.boolean = "boolean", u2.canonical = "canonical", u2.code = "code", u2.date = "date", u2.dateTime = "dateTime", u2.decimal = "decimal", u2.id = "id", u2.instant = "instant", u2.integer = "integer", u2.markdown = "markdown", u2.oid = "oid", u2.positiveInt = "positiveInt", u2.string = "string", u2.time = "time", u2.unsignedInt = "unsignedInt", u2.uri = "uri", u2.url = "url", u2.uuid = "uuid", u2))(q || {});
5130
- function st(r4) {
3656
+ var j = ((u2) => (u2.Address = "Address", u2.Age = "Age", u2.Annotation = "Annotation", u2.Attachment = "Attachment", u2.BackboneElement = "BackboneElement", u2.CodeableConcept = "CodeableConcept", u2.Coding = "Coding", u2.ContactDetail = "ContactDetail", u2.ContactPoint = "ContactPoint", u2.Contributor = "Contributor", u2.Count = "Count", u2.DataRequirement = "DataRequirement", u2.Distance = "Distance", u2.Dosage = "Dosage", u2.Duration = "Duration", u2.Expression = "Expression", u2.Extension = "Extension", u2.HumanName = "HumanName", u2.Identifier = "Identifier", u2.MarketingStatus = "MarketingStatus", u2.Meta = "Meta", u2.Money = "Money", u2.Narrative = "Narrative", u2.ParameterDefinition = "ParameterDefinition", u2.Period = "Period", u2.Population = "Population", u2.ProdCharacteristic = "ProdCharacteristic", u2.ProductShelfLife = "ProductShelfLife", u2.Quantity = "Quantity", u2.Range = "Range", u2.Ratio = "Ratio", u2.Reference = "Reference", u2.RelatedArtifact = "RelatedArtifact", u2.SampledData = "SampledData", u2.Signature = "Signature", u2.SubstanceAmount = "SubstanceAmount", u2.SystemString = "http://hl7.org/fhirpath/System.String", u2.Timing = "Timing", u2.TriggerDefinition = "TriggerDefinition", u2.UsageContext = "UsageContext", u2.base64Binary = "base64Binary", u2.boolean = "boolean", u2.canonical = "canonical", u2.code = "code", u2.date = "date", u2.dateTime = "dateTime", u2.decimal = "decimal", u2.id = "id", u2.instant = "instant", u2.integer = "integer", u2.markdown = "markdown", u2.oid = "oid", u2.positiveInt = "positiveInt", u2.string = "string", u2.time = "time", u2.unsignedInt = "unsignedInt", u2.uri = "uri", u2.url = "url", u2.uuid = "uuid", u2))(j || {});
3657
+ function at(r4) {
5131
3658
  if (!r4.name)
5132
3659
  return;
5133
3660
  let t = r4.snapshot?.element;
5134
- t && (t.forEach((n) => gn(r4, n)), t.forEach((n) => xn(r4, n)));
3661
+ t && (t.forEach((n) => Tn(r4, n)), t.forEach((n) => vn(r4, n)));
5135
3662
  }
5136
- function gn(r4, e) {
3663
+ function Tn(r4, e) {
5137
3664
  let t = e.path, n = e.type?.[0]?.code;
5138
3665
  if (n !== void 0 && n !== "Element" && n !== "BackboneElement")
5139
3666
  return;
5140
3667
  let i2 = t.split(".");
5141
3668
  i2[0] = r4.name;
5142
- let o = U(i2), s = y.types[o];
5143
- s || (y.types[o] = s = {}), s.parentType = s.parentType ?? U(i2.slice(0, i2.length - 1)), s.display = s.display ?? o, s.structureDefinition = s.structureDefinition ?? r4, s.elementDefinition = s.elementDefinition ?? e, s.description = s.description ?? e.definition, s.properties = s.properties ?? {};
3669
+ let o = L(i2), s = y.types[o];
3670
+ s || (y.types[o] = s = {}), s.parentType = s.parentType ?? L(i2.slice(0, i2.length - 1)), s.display = s.display ?? o, s.structureDefinition = s.structureDefinition ?? r4, s.elementDefinition = s.elementDefinition ?? e, s.description = s.description ?? e.definition, s.properties = s.properties ?? {};
5144
3671
  }
5145
- function xn(r4, e) {
3672
+ function vn(r4, e) {
5146
3673
  let n = e.path.split(".");
5147
3674
  if (n.length === 1)
5148
3675
  return;
5149
3676
  n[0] = r4.name;
5150
- let i2 = U(n.slice(0, n.length - 1)), o = y.types[i2];
3677
+ let i2 = L(n.slice(0, n.length - 1)), o = y.types[i2];
5151
3678
  if (!o)
5152
3679
  return;
5153
3680
  let s = n[n.length - 1];
5154
3681
  o.properties[s] = e;
5155
3682
  }
5156
- function at(r4) {
3683
+ function ct(r4) {
5157
3684
  for (let e of r4.base ?? []) {
5158
3685
  let t = y.types[e];
5159
3686
  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);
5160
3687
  }
5161
3688
  }
5162
- function U(r4) {
5163
- return r4.length === 1 ? r4[0] : r4.map(b).join("");
3689
+ function L(r4) {
3690
+ return r4.length === 1 ? r4[0] : r4.map(S).join("");
5164
3691
  }
5165
- function ie(r4, e) {
3692
+ function oe(r4, e) {
5166
3693
  let t = y.types[r4];
5167
3694
  if (!t)
5168
3695
  return;
5169
3696
  let n = t.properties[e] ?? t.properties[e + "[x]"];
5170
3697
  if (n) {
5171
3698
  if (n.contentReference) {
5172
- let i2 = n.contentReference.substring(1).split("."), o = i2.pop(), s = U(i2);
5173
- return ie(s, o);
3699
+ let i2 = n.contentReference.substring(1).split("."), o = i2.pop(), s = L(i2);
3700
+ return oe(s, o);
5174
3701
  }
5175
3702
  return n;
5176
3703
  }
5177
3704
  }
5178
- function L(r4) {
3705
+ function _(r4) {
5179
3706
  return !!(r4 && typeof r4 == "object" && "resourceType" in r4);
5180
3707
  }
5181
- var y = Mt;
5182
- var Sn = ((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))(Sn || {});
3708
+ var y = Bt;
3709
+ var An = ((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))(An || {});
5183
3710
  var be = class {
5184
3711
  constructor(e, t) {
5185
3712
  this.operator = e;
@@ -5189,7 +3716,7 @@ var be = class {
5189
3716
  return `${this.operator}(${this.child.toString()})`;
5190
3717
  }
5191
3718
  };
5192
- var j = class {
3719
+ var $ = class {
5193
3720
  constructor(e, t, n) {
5194
3721
  this.operator = e;
5195
3722
  this.left = t;
@@ -5223,10 +3750,10 @@ var Se = class {
5223
3750
  }, precedence: t });
5224
3751
  }
5225
3752
  construct(e) {
5226
- return new ut(e, this.prefixParselets, this.infixParselets);
3753
+ return new dt(e, this.prefixParselets, this.infixParselets);
5227
3754
  }
5228
3755
  };
5229
- var ut = class {
3756
+ var dt = class {
5230
3757
  constructor(e, t, n) {
5231
3758
  this.tokens = e, this.prefixParselets = t, this.infixParselets = n;
5232
3759
  }
@@ -5277,7 +3804,7 @@ var ut = class {
5277
3804
  return this.infixParselets[e.id === "Symbol" ? e.value : e.id];
5278
3805
  }
5279
3806
  };
5280
- function X(r4) {
3807
+ function Z(r4) {
5281
3808
  if (r4.startsWith("T"))
5282
3809
  return r4 + "T00:00:00.000Z".substring(r4.length);
5283
3810
  if (r4.length <= 10)
@@ -5291,26 +3818,26 @@ function X(r4) {
5291
3818
  function d(r4) {
5292
3819
  return [{ type: "boolean", value: r4 }];
5293
3820
  }
5294
- function x(r4) {
5295
- return r4 == null ? { type: "undefined", value: void 0 } : Number.isSafeInteger(r4) ? { type: "integer", value: r4 } : typeof r4 == "number" ? { type: "decimal", value: r4 } : typeof r4 == "boolean" ? { type: "boolean", value: r4 } : typeof r4 == "string" ? { type: "string", value: r4 } : R(r4) ? { type: "Quantity", value: r4 } : L(r4) ? { type: r4.resourceType, value: r4 } : { type: "BackboneElement", value: r4 };
3821
+ function T(r4) {
3822
+ return r4 == null ? { type: "undefined", value: void 0 } : Number.isSafeInteger(r4) ? { type: "integer", value: r4 } : typeof r4 == "number" ? { type: "decimal", value: r4 } : typeof r4 == "boolean" ? { type: "boolean", value: r4 } : typeof r4 == "string" ? { type: "string", value: r4 } : A(r4) ? { type: "Quantity", value: r4 } : _(r4) ? { type: r4.resourceType, value: r4 } : { type: "BackboneElement", value: r4 };
5296
3823
  }
5297
- function _(r4) {
3824
+ function N(r4) {
5298
3825
  return r4.length === 0 ? false : !!r4[0].value;
5299
3826
  }
5300
- function D(r4, e) {
3827
+ function O(r4, e) {
5301
3828
  if (r4.length !== 0) {
5302
3829
  if (r4.length === 1 && (!e || r4[0].type === e))
5303
3830
  return r4[0];
5304
3831
  throw new Error(`Expected singleton of type ${e}, but found ${JSON.stringify(r4)}`);
5305
3832
  }
5306
3833
  }
5307
- function E(r4, e) {
3834
+ function P(r4, e) {
5308
3835
  if (!r4.value)
5309
3836
  return;
5310
- let t = ie(r4.type, e);
5311
- return t ? Ln(r4, e, t) : _n(r4, e);
3837
+ let t = oe(r4.type, e);
3838
+ return t ? Nn(r4, e, t) : Mn(r4, e);
5312
3839
  }
5313
- function Ln(r4, e, t) {
3840
+ function Nn(r4, e, t) {
5314
3841
  let n = t.type;
5315
3842
  if (!n || n.length === 0)
5316
3843
  return;
@@ -5318,20 +3845,21 @@ function Ln(r4, e, t) {
5318
3845
  if (n.length === 1)
5319
3846
  i2 = r4.value[e], o = n[0].code;
5320
3847
  else
5321
- for (let s of n) {
5322
- let a = e.replace("[x]", "") + b(s.code);
5323
- if (a in r4.value) {
5324
- i2 = r4.value[a], o = s.code;
3848
+ for (let a of n) {
3849
+ let c2 = e.replace("[x]", "") + S(a.code);
3850
+ if (c2 in r4.value) {
3851
+ i2 = r4.value[c2], o = a.code;
5325
3852
  break;
5326
3853
  }
5327
3854
  }
5328
- if (!v(i2))
5329
- return (o === "Element" || o === "BackboneElement") && (o = U(t.path?.split("."))), Array.isArray(i2) ? i2.map((s) => cr(s, o)) : cr(i2, o);
3855
+ let s = r4.value["_" + e];
3856
+ if (s && (Array.isArray(i2) ? i2 = i2.map((a, c2) => s[c2] ? lr(a ?? {}, s[c2]) : a) : i2 = lr(i2 ?? {}, s)), !b(i2))
3857
+ return (o === "Element" || o === "BackboneElement") && (o = L(t.path?.split("."))), Array.isArray(i2) ? i2.map((a) => cr(a, o)) : cr(i2, o);
5330
3858
  }
5331
3859
  function cr(r4, e) {
5332
- return e === "Resource" && L(r4) && (e = r4.resourceType), { type: e, value: r4 };
3860
+ return e === "Resource" && _(r4) && (e = r4.resourceType), { type: e, value: r4 };
5333
3861
  }
5334
- function _n(r4, e) {
3862
+ function Mn(r4, e) {
5335
3863
  let t = r4.value;
5336
3864
  if (!t || typeof t != "object")
5337
3865
  return;
@@ -5339,22 +3867,22 @@ function _n(r4, e) {
5339
3867
  if (e in t)
5340
3868
  n = t[e];
5341
3869
  else
5342
- for (let i2 in q) {
5343
- let o = e + b(i2);
3870
+ for (let i2 in j) {
3871
+ let o = e + S(i2);
5344
3872
  if (o in t) {
5345
3873
  n = t[o];
5346
3874
  break;
5347
3875
  }
5348
3876
  }
5349
- if (!v(n))
5350
- return Array.isArray(n) ? n.map(x) : x(n);
3877
+ if (!b(n))
3878
+ return Array.isArray(n) ? n.map(T) : T(n);
5351
3879
  }
5352
3880
  function Re(r4) {
5353
3881
  let e = [];
5354
3882
  for (let t of r4) {
5355
3883
  let n = false;
5356
3884
  for (let i2 of e)
5357
- if (_(lr(t, i2))) {
3885
+ if (N(pr(t, i2))) {
5358
3886
  n = true;
5359
3887
  break;
5360
3888
  }
@@ -5362,25 +3890,25 @@ function Re(r4) {
5362
3890
  }
5363
3891
  return e;
5364
3892
  }
5365
- function dt(r4) {
5366
- return d(!_(r4));
3893
+ function lt(r4) {
3894
+ return d(!N(r4));
5367
3895
  }
5368
- function lt(r4, e) {
5369
- return r4.length === 0 || e.length === 0 ? [] : r4.length !== e.length ? d(false) : d(r4.every((t, n) => _(lr(t, e[n]))));
3896
+ function pt(r4, e) {
3897
+ return r4.length === 0 || e.length === 0 ? [] : r4.length !== e.length ? d(false) : d(r4.every((t, n) => N(pr(t, e[n]))));
5370
3898
  }
5371
- function lr(r4, e) {
5372
- let t = r4.value, n = e.value;
5373
- return typeof t == "number" && typeof n == "number" ? d(Math.abs(t - n) < 1e-8) : R(t) && R(n) ? d(pr(t, n)) : d(typeof t == "object" && typeof n == "object" ? ft(r4, e) : t === n);
3899
+ function pr(r4, e) {
3900
+ let t = r4.value?.valueOf(), n = e.value?.valueOf();
3901
+ return typeof t == "number" && typeof n == "number" ? d(Math.abs(t - n) < 1e-8) : A(t) && A(n) ? d(fr(t, n)) : d(typeof t == "object" && typeof n == "object" ? mt(r4, e) : t === n);
5374
3902
  }
5375
- function pt(r4, e) {
5376
- return r4.length === 0 && e.length === 0 ? d(true) : r4.length !== e.length ? d(false) : (r4.sort(ur), e.sort(ur), d(r4.every((t, n) => _(Nn(t, e[n])))));
3903
+ function ft(r4, e) {
3904
+ return r4.length === 0 && e.length === 0 ? d(true) : r4.length !== e.length ? d(false) : (r4.sort(ur), e.sort(ur), d(r4.every((t, n) => N(Bn(t, e[n])))));
5377
3905
  }
5378
- function Nn(r4, e) {
5379
- let t = r4.value, n = e.value;
5380
- return typeof t == "number" && typeof n == "number" ? d(Math.abs(t - n) < 0.01) : R(t) && R(n) ? d(pr(t, n)) : d(typeof t == "object" && typeof n == "object" ? ft(t, n) : typeof t == "string" && typeof n == "string" ? t.toLowerCase() === n.toLowerCase() : t === n);
3906
+ function Bn(r4, e) {
3907
+ let { type: t, value: n } = r4, { type: i2, value: o } = e, s = n?.valueOf(), a = o?.valueOf();
3908
+ return typeof s == "number" && typeof a == "number" ? d(Math.abs(s - a) < 0.01) : A(s) && A(a) ? d(fr(s, a)) : d(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" ? mt({ ...s, id: void 0 }, { ...a, id: void 0 }) : typeof s == "string" && typeof a == "string" ? s.toLowerCase() === a.toLowerCase() : s === a);
5381
3909
  }
5382
3910
  function ur(r4, e) {
5383
- let t = r4.value, n = e.value;
3911
+ let t = r4.value?.valueOf(), n = e.value?.valueOf();
5384
3912
  return typeof t == "number" && typeof n == "number" ? t - n : typeof t == "string" && typeof n == "string" ? t.localeCompare(n) : 0;
5385
3913
  }
5386
3914
  function Ae(r4, e) {
@@ -5400,30 +3928,30 @@ function Ae(r4, e) {
5400
3928
  case "Time":
5401
3929
  return typeof t == "string" && !!/^T\d/.exec(t);
5402
3930
  case "Period":
5403
- return Mn(t);
3931
+ return Fn(t);
5404
3932
  case "Quantity":
5405
- return R(t);
3933
+ return A(t);
5406
3934
  default:
5407
3935
  return typeof t == "object" && t?.resourceType === e;
5408
3936
  }
5409
3937
  }
5410
- function Mn(r4) {
3938
+ function Fn(r4) {
5411
3939
  return !!(r4 && typeof r4 == "object" && "start" in r4);
5412
3940
  }
5413
- function R(r4) {
3941
+ function A(r4) {
5414
3942
  return !!(r4 && typeof r4 == "object" && "value" in r4 && typeof r4.value == "number");
5415
3943
  }
5416
- function pr(r4, e) {
3944
+ function fr(r4, e) {
5417
3945
  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);
5418
3946
  }
5419
- function ft(r4, e) {
3947
+ function mt(r4, e) {
5420
3948
  let t = Object.keys(r4), n = Object.keys(e);
5421
3949
  if (t.length !== n.length)
5422
3950
  return false;
5423
3951
  for (let i2 of t) {
5424
3952
  let o = r4[i2], s = e[i2];
5425
3953
  if (dr(o) && dr(s)) {
5426
- if (!ft(o, s))
3954
+ if (!mt(o, s))
5427
3955
  return false;
5428
3956
  } else if (o !== s)
5429
3957
  return false;
@@ -5433,8 +3961,11 @@ function ft(r4, e) {
5433
3961
  function dr(r4) {
5434
3962
  return r4 !== null && typeof r4 == "object";
5435
3963
  }
3964
+ function lr(r4, e) {
3965
+ return delete e.__proto__, delete e.constructor, Object.assign(r4, e);
3966
+ }
5436
3967
  var se = () => [];
5437
- var S = { empty: (r4, e) => d(e.length === 0), exists: (r4, e, t) => t ? d(e.filter((n) => _(t.eval(r4, [n]))).length > 0) : d(e.length > 0), all: (r4, e, t) => d(e.every((n) => _(t.eval(r4, [n])))), allTrue: (r4, e) => {
3968
+ var R = { empty: (r4, e) => d(e.length === 0), exists: (r4, e, t) => t ? d(e.filter((n) => N(t.eval(r4, [n]))).length > 0) : d(e.length > 0), all: (r4, e, t) => d(e.every((n) => N(t.eval(r4, [n])))), allTrue: (r4, e) => {
5438
3969
  for (let t of e)
5439
3970
  if (!t.value)
5440
3971
  return d(false);
@@ -5459,7 +3990,7 @@ var S = { empty: (r4, e) => d(e.length === 0), exists: (r4, e, t) => t ? d(e.fil
5459
3990
  for (let n of e)
5460
3991
  t.some((i2) => i2.value === n.value) || t.push(n);
5461
3992
  return t;
5462
- }, isDistinct: (r4, e) => d(e.length === S.distinct(r4, e).length), where: (r4, e, t) => e.filter((n) => _(t.eval(r4, [n]))), select: (r4, e, t) => e.map((n) => t.eval(r4, [n])).flat(), repeat: se, ofType: (r4, e, t) => e.filter((n) => n.type === t.name), single: (r4, e) => {
3993
+ }, isDistinct: (r4, e) => d(e.length === R.distinct(r4, e).length), where: (r4, e, t) => e.filter((n) => N(t.eval(r4, [n]))), select: (r4, e, t) => e.map((n) => t.eval(r4, [n])).flat(), repeat: se, ofType: (r4, e, t) => e.filter((n) => n.type === t.name), single: (r4, e) => {
5463
3994
  if (e.length > 1)
5464
3995
  throw new Error("Expected input length one for single()");
5465
3996
  return e.length === 0 ? [] : e.slice(0, 1);
@@ -5497,15 +4028,15 @@ var S = { empty: (r4, e) => d(e.length === 0), exists: (r4, e, t) => t ? d(e.fil
5497
4028
  return e;
5498
4029
  let n = t.eval(r4, e);
5499
4030
  return [...e, ...n];
5500
- }, htmlChecks: (r4, e, t) => [x(true)], iif: (r4, e, t, n, i2) => {
4031
+ }, htmlChecks: (r4, e, t) => [T(true)], iif: (r4, e, t, n, i2) => {
5501
4032
  let o = t.eval(r4, e);
5502
4033
  if (o.length > 1 || o.length === 1 && typeof o[0].value != "boolean")
5503
4034
  throw new Error("Expected criterion to evaluate to a Boolean");
5504
- return _(o) ? n.eval(r4, e) : i2 ? i2.eval(r4, e) : [];
4035
+ return N(o) ? n.eval(r4, e) : i2 ? i2.eval(r4, e) : [];
5505
4036
  }, toBoolean: (r4, e) => {
5506
4037
  if (e.length === 0)
5507
4038
  return [];
5508
- let [{ value: t }] = V(e, 1);
4039
+ let [{ value: t }] = U(e, 1);
5509
4040
  if (typeof t == "boolean")
5510
4041
  return [{ type: "boolean", value: t }];
5511
4042
  if (typeof t == "number" && (t === 0 || t === 1))
@@ -5518,72 +4049,72 @@ var S = { empty: (r4, e) => d(e.length === 0), exists: (r4, e, t) => t ? d(e.fil
5518
4049
  return d(false);
5519
4050
  }
5520
4051
  return [];
5521
- }, convertsToBoolean: (r4, e) => e.length === 0 ? [] : d(S.toBoolean(r4, e).length === 1), toInteger: (r4, e) => {
4052
+ }, convertsToBoolean: (r4, e) => e.length === 0 ? [] : d(R.toBoolean(r4, e).length === 1), toInteger: (r4, e) => {
5522
4053
  if (e.length === 0)
5523
4054
  return [];
5524
- let [{ value: t }] = V(e, 1);
4055
+ let [{ value: t }] = U(e, 1);
5525
4056
  return typeof t == "number" ? [{ type: "integer", value: t }] : typeof t == "string" && /^[+-]?\d+$/.exec(t) ? [{ type: "integer", value: parseInt(t, 10) }] : typeof t == "boolean" ? [{ type: "integer", value: t ? 1 : 0 }] : [];
5526
- }, convertsToInteger: (r4, e) => e.length === 0 ? [] : d(S.toInteger(r4, e).length === 1), toDate: (r4, e) => {
4057
+ }, convertsToInteger: (r4, e) => e.length === 0 ? [] : d(R.toInteger(r4, e).length === 1), toDate: (r4, e) => {
5527
4058
  if (e.length === 0)
5528
4059
  return [];
5529
- let [{ value: t }] = V(e, 1);
5530
- return typeof t == "string" && /^\d{4}(-\d{2}(-\d{2})?)?/.exec(t) ? [{ type: "date", value: X(t) }] : [];
5531
- }, convertsToDate: (r4, e) => e.length === 0 ? [] : d(S.toDate(r4, e).length === 1), toDateTime: (r4, e) => {
4060
+ let [{ value: t }] = U(e, 1);
4061
+ return typeof t == "string" && /^\d{4}(-\d{2}(-\d{2})?)?/.exec(t) ? [{ type: "date", value: Z(t) }] : [];
4062
+ }, convertsToDate: (r4, e) => e.length === 0 ? [] : d(R.toDate(r4, e).length === 1), toDateTime: (r4, e) => {
5532
4063
  if (e.length === 0)
5533
4064
  return [];
5534
- let [{ value: t }] = V(e, 1);
5535
- return typeof t == "string" && /^\d{4}(-\d{2}(-\d{2})?)?/.exec(t) ? [{ type: "dateTime", value: X(t) }] : [];
5536
- }, convertsToDateTime: (r4, e) => e.length === 0 ? [] : d(S.toDateTime(r4, e).length === 1), toDecimal: (r4, e) => {
4065
+ let [{ value: t }] = U(e, 1);
4066
+ return typeof t == "string" && /^\d{4}(-\d{2}(-\d{2})?)?/.exec(t) ? [{ type: "dateTime", value: Z(t) }] : [];
4067
+ }, convertsToDateTime: (r4, e) => e.length === 0 ? [] : d(R.toDateTime(r4, e).length === 1), toDecimal: (r4, e) => {
5537
4068
  if (e.length === 0)
5538
4069
  return [];
5539
- let [{ value: t }] = V(e, 1);
4070
+ let [{ value: t }] = U(e, 1);
5540
4071
  return typeof t == "number" ? [{ type: "decimal", value: t }] : typeof t == "string" && /^-?\d{1,9}(\.\d{1,9})?$/.exec(t) ? [{ type: "decimal", value: parseFloat(t) }] : typeof t == "boolean" ? [{ type: "decimal", value: t ? 1 : 0 }] : [];
5541
- }, convertsToDecimal: (r4, e) => e.length === 0 ? [] : d(S.toDecimal(r4, e).length === 1), toQuantity: (r4, e) => {
4072
+ }, convertsToDecimal: (r4, e) => e.length === 0 ? [] : d(R.toDecimal(r4, e).length === 1), toQuantity: (r4, e) => {
5542
4073
  if (e.length === 0)
5543
4074
  return [];
5544
- let [{ value: t }] = V(e, 1);
5545
- return R(t) ? [{ type: "Quantity", value: t }] : typeof t == "number" ? [{ type: "Quantity", value: { value: t, unit: "1" } }] : typeof t == "string" && /^-?\d{1,9}(\.\d{1,9})?/.exec(t) ? [{ type: "Quantity", value: { value: parseFloat(t), unit: "1" } }] : typeof t == "boolean" ? [{ type: "Quantity", value: { value: t ? 1 : 0, unit: "1" } }] : [];
5546
- }, convertsToQuantity: (r4, e) => e.length === 0 ? [] : d(S.toQuantity(r4, e).length === 1), toString: (r4, e) => {
4075
+ let [{ value: t }] = U(e, 1);
4076
+ return A(t) ? [{ type: "Quantity", value: t }] : typeof t == "number" ? [{ type: "Quantity", value: { value: t, unit: "1" } }] : typeof t == "string" && /^-?\d{1,9}(\.\d{1,9})?/.exec(t) ? [{ type: "Quantity", value: { value: parseFloat(t), unit: "1" } }] : typeof t == "boolean" ? [{ type: "Quantity", value: { value: t ? 1 : 0, unit: "1" } }] : [];
4077
+ }, convertsToQuantity: (r4, e) => e.length === 0 ? [] : d(R.toQuantity(r4, e).length === 1), toString: (r4, e) => {
5547
4078
  if (e.length === 0)
5548
4079
  return [];
5549
- let [{ value: t }] = V(e, 1);
5550
- return t == null ? [] : R(t) ? [{ type: "string", value: `${t.value} '${t.unit}'` }] : [{ type: "string", value: t.toString() }];
5551
- }, convertsToString: (r4, e) => e.length === 0 ? [] : d(S.toString(r4, e).length === 1), toTime: (r4, e) => {
4080
+ let [{ value: t }] = U(e, 1);
4081
+ return t == null ? [] : A(t) ? [{ type: "string", value: `${t.value} '${t.unit}'` }] : [{ type: "string", value: t.toString() }];
4082
+ }, convertsToString: (r4, e) => e.length === 0 ? [] : d(R.toString(r4, e).length === 1), toTime: (r4, e) => {
5552
4083
  if (e.length === 0)
5553
4084
  return [];
5554
- let [{ value: t }] = V(e, 1);
4085
+ let [{ value: t }] = U(e, 1);
5555
4086
  if (typeof t == "string") {
5556
4087
  let n = /^T?(\d{2}(:\d{2}(:\d{2})?)?)/.exec(t);
5557
4088
  if (n)
5558
- return [{ type: "time", value: X("T" + n[1]) }];
4089
+ return [{ type: "time", value: Z("T" + n[1]) }];
5559
4090
  }
5560
4091
  return [];
5561
- }, convertsToTime: (r4, e) => e.length === 0 ? [] : d(S.toTime(r4, e).length === 1), indexOf: (r4, e, t) => P((n, i2) => n.indexOf(i2), r4, e, t), substring: (r4, e, t, n) => P((i2, o, s) => {
4092
+ }, convertsToTime: (r4, e) => e.length === 0 ? [] : d(R.toTime(r4, e).length === 1), indexOf: (r4, e, t) => C((n, i2) => n.indexOf(i2), r4, e, t), substring: (r4, e, t, n) => C((i2, o, s) => {
5562
4093
  let a = o, c2 = s ? a + s : i2.length;
5563
4094
  return a < 0 || a >= i2.length ? void 0 : i2.substring(a, c2);
5564
- }, r4, e, t, n), startsWith: (r4, e, t) => P((n, i2) => n.startsWith(i2), r4, e, t), endsWith: (r4, e, t) => P((n, i2) => n.endsWith(i2), r4, e, t), contains: (r4, e, t) => P((n, i2) => n.includes(i2), r4, e, t), upper: (r4, e) => P((t) => t.toUpperCase(), r4, e), lower: (r4, e) => P((t) => t.toLowerCase(), r4, e), replace: (r4, e, t, n) => P((i2, o, s) => i2.replaceAll(o, s), r4, e, t, n), matches: (r4, e, t) => P((n, i2) => !!new RegExp(i2).exec(n), r4, e, t), replaceMatches: (r4, e, t, n) => P((i2, o, s) => i2.replaceAll(o, s), r4, e, t, n), length: (r4, e) => P((t) => t.length, r4, e), toChars: (r4, e) => P((t) => t ? t.split("") : void 0, r4, e), abs: (r4, e) => O(Math.abs, r4, e), ceiling: (r4, e) => O(Math.ceil, r4, e), exp: (r4, e) => O(Math.exp, r4, e), floor: (r4, e) => O(Math.floor, r4, e), ln: (r4, e) => O(Math.log, r4, e), log: (r4, e, t) => O((n, i2) => Math.log(n) / Math.log(i2), r4, e, t), power: (r4, e, t) => O(Math.pow, r4, e, t), round: (r4, e) => O(Math.round, r4, e), sqrt: (r4, e) => O(Math.sqrt, r4, e), truncate: (r4, e) => O((t) => t | 0, r4, e), children: se, descendants: se, trace: (r4, e, t) => (console.log("trace", e, t), e), now: () => [{ type: "dateTime", value: (/* @__PURE__ */ new Date()).toISOString() }], timeOfDay: () => [{ type: "time", value: (/* @__PURE__ */ new Date()).toISOString().substring(11) }], today: () => [{ type: "date", value: (/* @__PURE__ */ new Date()).toISOString().substring(0, 10) }], between: (r4, e, t, n, i2) => {
5565
- let o = S.toDateTime(r4, t.eval(r4, e));
4095
+ }, r4, e, t, n), startsWith: (r4, e, t) => C((n, i2) => n.startsWith(i2), r4, e, t), endsWith: (r4, e, t) => C((n, i2) => n.endsWith(i2), r4, e, t), contains: (r4, e, t) => C((n, i2) => n.includes(i2), r4, e, t), upper: (r4, e) => C((t) => t.toUpperCase(), r4, e), lower: (r4, e) => C((t) => t.toLowerCase(), r4, e), replace: (r4, e, t, n) => C((i2, o, s) => i2.replaceAll(o, s), r4, e, t, n), matches: (r4, e, t) => C((n, i2) => !!new RegExp(i2).exec(n), r4, e, t), replaceMatches: (r4, e, t, n) => C((i2, o, s) => i2.replaceAll(o, s), r4, e, t, n), length: (r4, e) => C((t) => t.length, r4, e), toChars: (r4, e) => C((t) => t ? t.split("") : void 0, r4, e), abs: (r4, e) => V(Math.abs, r4, e), ceiling: (r4, e) => V(Math.ceil, r4, e), exp: (r4, e) => V(Math.exp, r4, e), floor: (r4, e) => V(Math.floor, r4, e), ln: (r4, e) => V(Math.log, r4, e), log: (r4, e, t) => V((n, i2) => Math.log(n) / Math.log(i2), r4, e, t), power: (r4, e, t) => V(Math.pow, r4, e, t), round: (r4, e) => V(Math.round, r4, e), sqrt: (r4, e) => V(Math.sqrt, r4, e), truncate: (r4, e) => V((t) => t | 0, r4, e), children: se, descendants: se, trace: (r4, e, t) => (console.log("trace", e, t), e), now: () => [{ type: "dateTime", value: (/* @__PURE__ */ new Date()).toISOString() }], timeOfDay: () => [{ type: "time", value: (/* @__PURE__ */ new Date()).toISOString().substring(11) }], today: () => [{ type: "date", value: (/* @__PURE__ */ new Date()).toISOString().substring(0, 10) }], between: (r4, e, t, n, i2) => {
4096
+ let o = R.toDateTime(r4, t.eval(r4, e));
5566
4097
  if (o.length === 0)
5567
4098
  throw new Error("Invalid start date");
5568
- let s = S.toDateTime(r4, n.eval(r4, e));
4099
+ let s = R.toDateTime(r4, n.eval(r4, e));
5569
4100
  if (s.length === 0)
5570
4101
  throw new Error("Invalid end date");
5571
4102
  let a = i2.eval(r4, e)[0]?.value;
5572
4103
  if (a !== "years" && a !== "months" && a !== "days")
5573
4104
  throw new Error("Invalid units");
5574
- let c2 = ge(o[0].value, s[0].value);
4105
+ let c2 = ye(o[0].value, s[0].value);
5575
4106
  return [{ type: "Quantity", value: { value: c2[a], unit: a } }];
5576
4107
  }, is: (r4, e, t) => {
5577
4108
  let n = "";
5578
- return t instanceof N ? n = t.name : t instanceof Q && (n = t.left.name + "." + t.right.name), n ? e.map((i2) => ({ type: "boolean", value: Ae(i2, n) })) : [];
5579
- }, not: (r4, e) => S.toBoolean(r4, e).map((t) => ({ type: "boolean", value: !t.value })), resolve: (r4, e) => e.map((t) => {
4109
+ return t instanceof M ? n = t.name : t instanceof H && (n = t.left.name + "." + t.right.name), n ? e.map((i2) => ({ type: "boolean", value: Ae(i2, n) })) : [];
4110
+ }, not: (r4, e) => R.toBoolean(r4, e).map((t) => ({ type: "boolean", value: !t.value })), resolve: (r4, e) => e.map((t) => {
5580
4111
  let n = t.value, i2;
5581
4112
  if (typeof n == "string")
5582
4113
  i2 = n;
5583
4114
  else if (typeof n == "object") {
5584
4115
  let o = n;
5585
4116
  if (o.resource)
5586
- return x(o.resource);
4117
+ return T(o.resource);
5587
4118
  o.reference ? i2 = o.reference : o.type && o.identifier && (i2 = `${o.type}?identifier=${o.identifier.system}|${o.identifier.value}`);
5588
4119
  }
5589
4120
  if (i2?.includes("?")) {
@@ -5595,32 +4126,32 @@ var S = { empty: (r4, e) => d(e.length === 0), exists: (r4, e, t) => t ? d(e.fil
5595
4126
  return { type: o, value: { resourceType: o, id: s } };
5596
4127
  }
5597
4128
  return { type: "BackboneElement", value: void 0 };
5598
- }).filter((t) => !!t.value), as: (r4, e) => e, type: (r4, e) => e.map(({ value: t }) => typeof t == "boolean" ? { type: "BackboneElement", value: { namespace: "System", name: "Boolean" } } : typeof t == "number" ? { type: "BackboneElement", value: { namespace: "System", name: "Integer" } } : L(t) ? { type: "BackboneElement", value: { namespace: "FHIR", name: t.resourceType } } : { type: "BackboneElement", value: null }), conformsTo: (r4, e, t) => {
4129
+ }).filter((t) => !!t.value), as: (r4, e) => e, type: (r4, e) => e.map(({ value: t }) => typeof t == "boolean" ? { type: "BackboneElement", value: { namespace: "System", name: "Boolean" } } : typeof t == "number" ? { type: "BackboneElement", value: { namespace: "System", name: "Integer" } } : _(t) ? { type: "BackboneElement", value: { namespace: "FHIR", name: t.resourceType } } : { type: "BackboneElement", value: null }), conformsTo: (r4, e, t) => {
5599
4130
  let n = t.eval(r4, e)[0].value;
5600
4131
  if (!n.startsWith("http://hl7.org/fhir/StructureDefinition/"))
5601
4132
  throw new Error("Expected a StructureDefinition URL");
5602
4133
  let i2 = n.replace("http://hl7.org/fhir/StructureDefinition/", "");
5603
4134
  return e.map((o) => ({ type: "boolean", value: o.value?.resourceType === i2 }));
5604
4135
  } };
5605
- function P(r4, e, t, ...n) {
4136
+ function C(r4, e, t, ...n) {
5606
4137
  if (t.length === 0)
5607
4138
  return [];
5608
- let [{ value: i2 }] = V(t, 1);
4139
+ let [{ value: i2 }] = U(t, 1);
5609
4140
  if (typeof i2 != "string")
5610
4141
  throw new Error("String function cannot be called with non-string");
5611
4142
  let o = r4(i2, ...n.map((s) => s?.eval(e, t)[0]?.value));
5612
- return o === void 0 ? [] : Array.isArray(o) ? o.map(x) : [x(o)];
4143
+ return o === void 0 ? [] : Array.isArray(o) ? o.map(T) : [T(o)];
5613
4144
  }
5614
- function O(r4, e, t, ...n) {
4145
+ function V(r4, e, t, ...n) {
5615
4146
  if (t.length === 0)
5616
4147
  return [];
5617
- let [{ value: i2 }] = V(t, 1), o = R(i2), s = o ? i2.value : i2;
4148
+ let [{ value: i2 }] = U(t, 1), o = A(i2), s = o ? i2.value : i2;
5618
4149
  if (typeof s != "number")
5619
4150
  throw new Error("Math function cannot be called with non-number");
5620
4151
  let a = r4(s, ...n.map((l2) => l2.eval(e, t)[0]?.value)), c2 = o ? "Quantity" : t[0].type, p2 = o ? { ...i2, value: a } : a;
5621
4152
  return [{ type: c2, value: p2 }];
5622
4153
  }
5623
- function V(r4, e) {
4154
+ function U(r4, e) {
5624
4155
  if (r4.length !== e)
5625
4156
  throw new Error(`Expected ${e} arguments`);
5626
4157
  for (let t of r4)
@@ -5628,7 +4159,7 @@ function V(r4, e) {
5628
4159
  throw new Error("Expected non-null argument");
5629
4160
  return r4;
5630
4161
  }
5631
- var w = class {
4162
+ var k = class {
5632
4163
  constructor(e) {
5633
4164
  this.value = e;
5634
4165
  }
@@ -5640,7 +4171,7 @@ var w = class {
5640
4171
  return typeof e == "string" ? `'${e}'` : e.toString();
5641
4172
  }
5642
4173
  };
5643
- var N = class {
4174
+ var M = class {
5644
4175
  constructor(e) {
5645
4176
  this.name = e;
5646
4177
  }
@@ -5658,7 +4189,7 @@ var N = class {
5658
4189
  evalValue(e) {
5659
4190
  let t = e.value;
5660
4191
  if (!(!t || typeof t != "object"))
5661
- return L(t) && t.resourceType === this.name ? e : E(e, this.name);
4192
+ return _(t) && t.resourceType === this.name ? e : P(e, this.name);
5662
4193
  }
5663
4194
  toString() {
5664
4195
  return this.name;
@@ -5684,17 +4215,17 @@ var Ce = class extends be {
5684
4215
  return this.operator + this.child.toString();
5685
4216
  }
5686
4217
  };
5687
- var G = class extends j {
4218
+ var z = class extends $ {
5688
4219
  constructor(e, t) {
5689
4220
  super("as", e, t);
5690
4221
  }
5691
4222
  eval(e, t) {
5692
- return S.ofType(e, this.left.eval(e, t), this.right);
4223
+ return R.ofType(e, this.left.eval(e, t), this.right);
5693
4224
  }
5694
4225
  };
5695
- var T = class extends j {
4226
+ var v = class extends $ {
5696
4227
  };
5697
- var A = class extends T {
4228
+ var E = class extends v {
5698
4229
  constructor(t, n, i2, o) {
5699
4230
  super(t, n, i2);
5700
4231
  this.impl = o;
@@ -5706,11 +4237,11 @@ var A = class extends T {
5706
4237
  let o = this.right.eval(t, n);
5707
4238
  if (o.length !== 1)
5708
4239
  return [];
5709
- let s = i2[0].value, a = o[0].value, c2 = R(s) ? s.value : s, p2 = R(a) ? a.value : a, l2 = this.impl(c2, p2);
5710
- return typeof l2 == "boolean" ? d(l2) : R(s) ? [{ type: "Quantity", value: { ...s, value: l2 } }] : [x(l2)];
4240
+ let s = i2[0].value, a = o[0].value, c2 = A(s) ? s.value : s, p2 = A(a) ? a.value : a, l2 = this.impl(c2, p2);
4241
+ return typeof l2 == "boolean" ? d(l2) : A(s) ? [{ type: "Quantity", value: { ...s, value: l2 } }] : [T(l2)];
5711
4242
  }
5712
4243
  };
5713
- var we = class extends j {
4244
+ var we = class extends $ {
5714
4245
  constructor(e, t) {
5715
4246
  super("&", e, t);
5716
4247
  }
@@ -5719,7 +4250,7 @@ var we = class extends j {
5719
4250
  return o.length > 0 && o.every((s) => typeof s.value == "string") ? [{ type: "string", value: o.map((s) => s.value).join("") }] : o;
5720
4251
  }
5721
4252
  };
5722
- var ke = class extends T {
4253
+ var ke = class extends v {
5723
4254
  constructor(e, t) {
5724
4255
  super("contains", e, t);
5725
4256
  }
@@ -5728,16 +4259,16 @@ var ke = class extends T {
5728
4259
  return d(n.some((o) => o.value === i2[0].value));
5729
4260
  }
5730
4261
  };
5731
- var Ie = class extends T {
4262
+ var De = class extends v {
5732
4263
  constructor(e, t) {
5733
4264
  super("in", e, t);
5734
4265
  }
5735
4266
  eval(e, t) {
5736
- let n = D(this.left.eval(e, t)), i2 = this.right.eval(e, t);
4267
+ let n = O(this.left.eval(e, t)), i2 = this.right.eval(e, t);
5737
4268
  return n ? d(i2.some((o) => o.value === n.value)) : [];
5738
4269
  }
5739
4270
  };
5740
- var Q = class extends j {
4271
+ var H = class extends $ {
5741
4272
  constructor(e, t) {
5742
4273
  super(".", e, t);
5743
4274
  }
@@ -5748,7 +4279,7 @@ var Q = class extends j {
5748
4279
  return `${this.left.toString()}.${this.right.toString()}`;
5749
4280
  }
5750
4281
  };
5751
- var Z = class extends j {
4282
+ var ee = class extends $ {
5752
4283
  constructor(e, t) {
5753
4284
  super("|", e, t);
5754
4285
  }
@@ -5757,43 +4288,43 @@ var Z = class extends j {
5757
4288
  return Re([...n, ...i2]);
5758
4289
  }
5759
4290
  };
5760
- var De = class extends T {
4291
+ var Ie = class extends v {
5761
4292
  constructor(e, t) {
5762
4293
  super("=", e, t);
5763
4294
  }
5764
4295
  eval(e, t) {
5765
4296
  let n = this.left.eval(e, t), i2 = this.right.eval(e, t);
5766
- return lt(n, i2);
4297
+ return pt(n, i2);
5767
4298
  }
5768
4299
  };
5769
- var Oe = class extends T {
4300
+ var Oe = class extends v {
5770
4301
  constructor(e, t) {
5771
4302
  super("!=", e, t);
5772
4303
  }
5773
4304
  eval(e, t) {
5774
4305
  let n = this.left.eval(e, t), i2 = this.right.eval(e, t);
5775
- return dt(lt(n, i2));
4306
+ return lt(pt(n, i2));
5776
4307
  }
5777
4308
  };
5778
- var Ve = class extends T {
4309
+ var Ve = class extends v {
5779
4310
  constructor(e, t) {
5780
4311
  super("~", e, t);
5781
4312
  }
5782
4313
  eval(e, t) {
5783
4314
  let n = this.left.eval(e, t), i2 = this.right.eval(e, t);
5784
- return pt(n, i2);
4315
+ return ft(n, i2);
5785
4316
  }
5786
4317
  };
5787
- var Ue = class extends T {
4318
+ var Ue = class extends v {
5788
4319
  constructor(e, t) {
5789
4320
  super("!~", e, t);
5790
4321
  }
5791
4322
  eval(e, t) {
5792
4323
  let n = this.left.eval(e, t), i2 = this.right.eval(e, t);
5793
- return dt(pt(n, i2));
4324
+ return lt(ft(n, i2));
5794
4325
  }
5795
4326
  };
5796
- var z = class extends T {
4327
+ var K = class extends v {
5797
4328
  constructor(e, t) {
5798
4329
  super("is", e, t);
5799
4330
  }
@@ -5805,49 +4336,49 @@ var z = class extends T {
5805
4336
  return d(Ae(n[0], i2));
5806
4337
  }
5807
4338
  };
5808
- var Le = class extends T {
4339
+ var Le = class extends v {
5809
4340
  constructor(e, t) {
5810
4341
  super("and", e, t);
5811
4342
  }
5812
4343
  eval(e, t) {
5813
- let n = D(this.left.eval(e, t), "boolean"), i2 = D(this.right.eval(e, t), "boolean");
4344
+ let n = O(this.left.eval(e, t), "boolean"), i2 = O(this.right.eval(e, t), "boolean");
5814
4345
  return n?.value === true && i2?.value === true ? d(true) : n?.value === false || i2?.value === false ? d(false) : [];
5815
4346
  }
5816
4347
  };
5817
- var _e = class extends T {
4348
+ var _e = class extends v {
5818
4349
  constructor(e, t) {
5819
4350
  super("or", e, t);
5820
4351
  }
5821
4352
  eval(e, t) {
5822
- let n = D(this.left.eval(e, t), "boolean"), i2 = D(this.right.eval(e, t), "boolean");
4353
+ let n = O(this.left.eval(e, t), "boolean"), i2 = O(this.right.eval(e, t), "boolean");
5823
4354
  return n?.value === false && i2?.value === false ? d(false) : n?.value || i2?.value ? d(true) : [];
5824
4355
  }
5825
4356
  };
5826
- var Ne = class extends T {
4357
+ var Ne = class extends v {
5827
4358
  constructor(e, t) {
5828
4359
  super("xor", e, t);
5829
4360
  }
5830
4361
  eval(e, t) {
5831
- let n = D(this.left.eval(e, t), "boolean"), i2 = D(this.right.eval(e, t), "boolean");
4362
+ let n = O(this.left.eval(e, t), "boolean"), i2 = O(this.right.eval(e, t), "boolean");
5832
4363
  return !n || !i2 ? [] : d(n.value !== i2.value);
5833
4364
  }
5834
4365
  };
5835
- var Me = class extends T {
4366
+ var Me = class extends v {
5836
4367
  constructor(e, t) {
5837
4368
  super("implies", e, t);
5838
4369
  }
5839
4370
  eval(e, t) {
5840
- let n = D(this.left.eval(e, t), "boolean"), i2 = D(this.right.eval(e, t), "boolean");
4371
+ let n = O(this.left.eval(e, t), "boolean"), i2 = O(this.right.eval(e, t), "boolean");
5841
4372
  return i2?.value === true || n?.value === false ? d(true) : !n || !i2 ? [] : d(false);
5842
4373
  }
5843
4374
  };
5844
- var M = class {
4375
+ var B = class {
5845
4376
  constructor(e, t) {
5846
4377
  this.name = e;
5847
4378
  this.args = t;
5848
4379
  }
5849
4380
  eval(e, t) {
5850
- let n = S[this.name];
4381
+ let n = R[this.name];
5851
4382
  if (!n)
5852
4383
  throw new Error("Unrecognized function: " + this.name);
5853
4384
  return n(e, t, ...this.args);
@@ -5856,7 +4387,7 @@ var M = class {
5856
4387
  return `${this.name}(${this.args.map((e) => e.toString()).join(", ")})`;
5857
4388
  }
5858
4389
  };
5859
- var K = class {
4390
+ var J = class {
5860
4391
  constructor(e, t) {
5861
4392
  this.left = e;
5862
4393
  this.expr = t;
@@ -5877,54 +4408,55 @@ var K = class {
5877
4408
  };
5878
4409
  var ce = ["!=", "!~", "<=", ">=", "{}", "->"];
5879
4410
  var f = { FunctionCall: 0, Dot: 1, Indexer: 2, UnaryAdd: 3, UnarySubtract: 3, Multiply: 4, Divide: 4, IntegerDivide: 4, Modulo: 4, Add: 5, Subtract: 5, Ampersand: 5, Is: 6, As: 6, Union: 7, GreaterThan: 8, GreaterThanOrEquals: 8, LessThan: 8, LessThanOrEquals: 8, Equals: 9, Equivalent: 9, NotEquals: 9, NotEquivalent: 9, In: 10, Contains: 10, And: 11, Xor: 12, Or: 12, Implies: 13, Arrow: 100, Semicolon: 200 };
5880
- var Bn = { parse(r4) {
4411
+ var qn = { parse(r4) {
5881
4412
  let e = r4.consumeAndParse();
5882
4413
  if (!r4.match(")"))
5883
4414
  throw new Error("Parse error: expected `)` got `" + r4.peek()?.value + "`");
5884
4415
  return e;
5885
4416
  } };
5886
- var Fn = { parse(r4, e) {
4417
+ var jn = { parse(r4, e) {
5887
4418
  let t = r4.consumeAndParse();
5888
4419
  if (!r4.match("]"))
5889
4420
  throw new Error("Parse error: expected `]`");
5890
- return new K(e, t);
4421
+ return new J(e, t);
5891
4422
  }, precedence: f.Indexer };
5892
- var qn = { parse(r4, e) {
5893
- if (!(e instanceof N))
4423
+ var $n = { parse(r4, e) {
4424
+ if (!(e instanceof M))
5894
4425
  throw new Error("Unexpected parentheses");
5895
4426
  let t = [];
5896
4427
  for (; !r4.match(")"); )
5897
4428
  t.push(r4.consumeAndParse()), r4.match(",");
5898
- return new M(e.name, t);
4429
+ return new B(e.name, t);
5899
4430
  }, precedence: f.FunctionCall };
5900
- function jn(r4) {
4431
+ function Qn(r4) {
5901
4432
  let e = r4.split(" "), t = parseFloat(e[0]), n = e[1];
5902
4433
  return n?.startsWith("'") && n.endsWith("'") ? n = n.substring(1, n.length - 1) : n = "{" + n + "}", { value: t, unit: n };
5903
4434
  }
5904
4435
  function ue() {
5905
- return new Se().registerPrefix("String", { parse: (r4, e) => new w({ type: "string", value: e.value }) }).registerPrefix("DateTime", { parse: (r4, e) => new w({ type: "dateTime", value: X(e.value) }) }).registerPrefix("Quantity", { parse: (r4, e) => new w({ type: "Quantity", value: jn(e.value) }) }).registerPrefix("Number", { parse: (r4, e) => new w({ type: "decimal", value: parseFloat(e.value) }) }).registerPrefix("true", { parse: () => new w({ type: "boolean", value: true }) }).registerPrefix("false", { parse: () => new w({ type: "boolean", value: false }) }).registerPrefix("Symbol", { parse: (r4, e) => new N(e.value) }).registerPrefix("{}", { parse: () => new Pe() }).registerPrefix("(", Bn).registerInfix("[", Fn).registerInfix("(", qn).prefix("+", f.UnaryAdd, (r4, e) => new Ce("+", e, (t) => t)).prefix("-", f.UnarySubtract, (r4, e) => new A("-", e, e, (t, n) => -n)).infixLeft(".", f.Dot, (r4, e, t) => new Q(r4, t)).infixLeft("/", f.Divide, (r4, e, t) => new A("/", r4, t, (n, i2) => n / i2)).infixLeft("*", f.Multiply, (r4, e, t) => new A("*", r4, t, (n, i2) => n * i2)).infixLeft("+", f.Add, (r4, e, t) => new A("+", r4, t, (n, i2) => n + i2)).infixLeft("-", f.Subtract, (r4, e, t) => new A("-", r4, t, (n, i2) => n - i2)).infixLeft("|", f.Union, (r4, e, t) => new Z(r4, t)).infixLeft("=", f.Equals, (r4, e, t) => new De(r4, t)).infixLeft("!=", f.NotEquals, (r4, e, t) => new Oe(r4, t)).infixLeft("~", f.Equivalent, (r4, e, t) => new Ve(r4, t)).infixLeft("!~", f.NotEquivalent, (r4, e, t) => new Ue(r4, t)).infixLeft("<", f.LessThan, (r4, e, t) => new A("<", r4, t, (n, i2) => n < i2)).infixLeft("<=", f.LessThanOrEquals, (r4, e, t) => new A("<=", r4, t, (n, i2) => n <= i2)).infixLeft(">", f.GreaterThan, (r4, e, t) => new A(">", r4, t, (n, i2) => n > i2)).infixLeft(">=", f.GreaterThanOrEquals, (r4, e, t) => new A(">=", r4, t, (n, i2) => n >= i2)).infixLeft("&", f.Ampersand, (r4, e, t) => new we(r4, t)).infixLeft("and", f.And, (r4, e, t) => new Le(r4, t)).infixLeft("as", f.As, (r4, e, t) => new G(r4, t)).infixLeft("contains", f.Contains, (r4, e, t) => new ke(r4, t)).infixLeft("div", f.Divide, (r4, e, t) => new A("div", r4, t, (n, i2) => n / i2 | 0)).infixLeft("in", f.In, (r4, e, t) => new Ie(r4, t)).infixLeft("is", f.Is, (r4, e, t) => new z(r4, t)).infixLeft("mod", f.Modulo, (r4, e, t) => new A("mod", r4, t, (n, i2) => n % i2)).infixLeft("or", f.Or, (r4, e, t) => new _e(r4, t)).infixLeft("xor", f.Xor, (r4, e, t) => new Ne(r4, t)).infixLeft("implies", f.Implies, (r4, e, t) => new Me(r4, t));
4436
+ return new Se().registerPrefix("String", { parse: (r4, e) => new k({ type: "string", value: e.value }) }).registerPrefix("DateTime", { parse: (r4, e) => new k({ type: "dateTime", value: Z(e.value) }) }).registerPrefix("Quantity", { parse: (r4, e) => new k({ type: "Quantity", value: Qn(e.value) }) }).registerPrefix("Number", { parse: (r4, e) => new k({ type: "decimal", value: parseFloat(e.value) }) }).registerPrefix("true", { parse: () => new k({ type: "boolean", value: true }) }).registerPrefix("false", { parse: () => new k({ type: "boolean", value: false }) }).registerPrefix("Symbol", { parse: (r4, e) => new M(e.value) }).registerPrefix("{}", { parse: () => new Pe() }).registerPrefix("(", qn).registerInfix("[", jn).registerInfix("(", $n).prefix("+", f.UnaryAdd, (r4, e) => new Ce("+", e, (t) => t)).prefix("-", f.UnarySubtract, (r4, e) => new E("-", e, e, (t, n) => -n)).infixLeft(".", f.Dot, (r4, e, t) => new H(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 ee(r4, t)).infixLeft("=", f.Equals, (r4, e, t) => new Ie(r4, t)).infixLeft("!=", f.NotEquals, (r4, e, t) => new Oe(r4, t)).infixLeft("~", f.Equivalent, (r4, e, t) => new Ve(r4, t)).infixLeft("!~", f.NotEquivalent, (r4, e, t) => new Ue(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 we(r4, t)).infixLeft("and", f.And, (r4, e, t) => new Le(r4, t)).infixLeft("as", f.As, (r4, e, t) => new z(r4, t)).infixLeft("contains", f.Contains, (r4, e, t) => new ke(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 De(r4, t)).infixLeft("is", f.Is, (r4, e, t) => new K(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 _e(r4, t)).infixLeft("xor", f.Xor, (r4, e, t) => new Ne(r4, t)).infixLeft("implies", f.Implies, (r4, e, t) => new Me(r4, t));
5906
4437
  }
5907
- var $n = ue();
5908
- var mr = ((l2) => (l2.BOOLEAN = "BOOLEAN", l2.NUMBER = "NUMBER", l2.QUANTITY = "QUANTITY", l2.TEXT = "TEXT", l2.REFERENCE = "REFERENCE", l2.CANONICAL = "CANONICAL", l2.DATE = "DATE", l2.DATETIME = "DATETIME", l2.PERIOD = "PERIOD", l2.UUID = "UUID", l2))(mr || {});
5909
- function vr(r4) {
4438
+ var Hn = ue();
4439
+ var hr = ((l2) => (l2.BOOLEAN = "BOOLEAN", l2.NUMBER = "NUMBER", l2.QUANTITY = "QUANTITY", l2.TEXT = "TEXT", l2.REFERENCE = "REFERENCE", l2.CANONICAL = "CANONICAL", l2.DATE = "DATE", l2.DATETIME = "DATETIME", l2.PERIOD = "PERIOD", l2.UUID = "UUID", l2))(hr || {});
4440
+ var ci = ((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))(ci || {});
4441
+ function Sr(r4) {
5910
4442
  if (typeof window < "u")
5911
4443
  return window.atob(r4);
5912
4444
  if (typeof Buffer < "u")
5913
4445
  return Buffer.from(r4, "base64").toString("binary");
5914
4446
  throw new Error("Unable to decode base64");
5915
4447
  }
5916
- function br(r4) {
4448
+ function Rr(r4) {
5917
4449
  if (typeof window < "u")
5918
4450
  return window.btoa(r4);
5919
4451
  if (typeof Buffer < "u")
5920
4452
  return Buffer.from(r4, "binary").toString("base64");
5921
4453
  throw new Error("Unable to encode base64");
5922
4454
  }
5923
- function Tt() {
4455
+ function vt() {
5924
4456
  let r4 = new Uint32Array(28);
5925
- return crypto.getRandomValues(r4), Kt(r4.buffer);
4457
+ return crypto.getRandomValues(r4), Jt(r4.buffer);
5926
4458
  }
5927
- async function Sr(r4) {
4459
+ async function Ar(r4) {
5928
4460
  return crypto.subtle.digest("SHA-256", new TextEncoder().encode(r4));
5929
4461
  }
5930
4462
  var Fe = class {
@@ -5951,7 +4483,7 @@ var Fe = class {
5951
4483
  return this.cache.keys().next().value;
5952
4484
  }
5953
4485
  };
5954
- var J = { CSS: "text/css", FAVICON: "image/vnd.microsoft.icon", FHIR_JSON: "application/fhir+json", FORM_URL_ENCODED: "application/x-www-form-urlencoded", HL7_V2: "x-application/hl7-v2+er7", HTML: "text/html", JAVASCRIPT: "text/javascript", JSON: "application/json", JSON_PATCH: "application/json-patch+json", PNG: "image/png", SVG: "image/svg+xml", TEXT: "text/plain", TYPESCRIPT: "text/typescript" };
4486
+ var Y = { CSS: "text/css", FAVICON: "image/vnd.microsoft.icon", FHIR_JSON: "application/fhir+json", FORM_URL_ENCODED: "application/x-www-form-urlencoded", HL7_V2: "x-application/hl7-v2+er7", HTML: "text/html", JAVASCRIPT: "text/javascript", JSON: "application/json", JSON_PATCH: "application/json-patch+json", PNG: "image/png", SVG: "image/svg+xml", TEXT: "text/plain", TYPESCRIPT: "text/typescript" };
5955
4487
  var qe = class {
5956
4488
  constructor() {
5957
4489
  this.listeners = {};
@@ -5974,28 +4506,28 @@ var qe = class {
5974
4506
  return t && t.forEach((n) => n.call(this, e)), !e.defaultPrevented;
5975
4507
  }
5976
4508
  };
5977
- function pi(r4) {
5978
- let e = r4.replace(/-/g, "+").replace(/_/g, "/"), t = vr(e), n = Array.from(t).reduce((o, s) => {
4509
+ function yi(r4) {
4510
+ let e = r4.replace(/-/g, "+").replace(/_/g, "/"), t = Sr(e), n = Array.from(t).reduce((o, s) => {
5979
4511
  let a = ("00" + s.charCodeAt(0).toString(16)).slice(-2);
5980
4512
  return `${o}%${a}`;
5981
4513
  }, ""), i2 = decodeURIComponent(n);
5982
4514
  return JSON.parse(i2);
5983
4515
  }
5984
- function vt(r4) {
4516
+ function bt(r4) {
5985
4517
  let [e, t, n] = r4.split(".");
5986
- return pi(t);
4518
+ return yi(t);
5987
4519
  }
5988
- function Er(r4) {
4520
+ function Cr(r4) {
5989
4521
  try {
5990
- return typeof vt(r4).login_id == "string";
4522
+ return typeof bt(r4).login_id == "string";
5991
4523
  } catch {
5992
4524
  return false;
5993
4525
  }
5994
4526
  }
5995
- var fi;
5996
- var C = class {
4527
+ var gi;
4528
+ var w = class {
5997
4529
  constructor(e) {
5998
- this[fi] = "ReadablePromise";
4530
+ this[gi] = "ReadablePromise";
5999
4531
  this.status = "pending";
6000
4532
  this.suspender = e.then((t) => (this.status = "success", this.response = t, t), (t) => {
6001
4533
  throw this.status = "error", this.error = t, t;
@@ -6027,10 +4559,10 @@ var C = class {
6027
4559
  return this.suspender.finally(e);
6028
4560
  }
6029
4561
  };
6030
- fi = Symbol.toStringTag;
4562
+ gi = Symbol.toStringTag;
6031
4563
  var je = class {
6032
4564
  constructor() {
6033
- this.storage = typeof localStorage < "u" ? localStorage : new bt();
4565
+ this.storage = typeof localStorage < "u" ? localStorage : new St();
6034
4566
  }
6035
4567
  clear() {
6036
4568
  this.storage.clear();
@@ -6046,10 +4578,10 @@ var je = class {
6046
4578
  return t ? JSON.parse(t) : void 0;
6047
4579
  }
6048
4580
  setObject(e, t) {
6049
- this.setString(e, t ? Ht(t) : void 0);
4581
+ this.setString(e, t ? Wt(t) : void 0);
6050
4582
  }
6051
4583
  };
6052
- var bt = class {
4584
+ var St = class {
6053
4585
  constructor() {
6054
4586
  this.data = /* @__PURE__ */ new Map();
6055
4587
  }
@@ -6072,19 +4604,19 @@ var bt = class {
6072
4604
  return Array.from(this.data.keys())[e];
6073
4605
  }
6074
4606
  };
6075
- var mi = "https://api.medplum.com/";
6076
- var hi = 1e3;
6077
- var yi = 6e4;
6078
- var Pr = "Binary/";
6079
- var Cr = { resourceType: "Device", id: "system", deviceName: [{ name: "System" }] };
6080
- var gi = ((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))(gi || {});
6081
- 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 || {});
6082
- var wr = class extends qe {
4607
+ var xi = "https://api.medplum.com/";
4608
+ var Ti = 1e3;
4609
+ var vi = 6e4;
4610
+ var wr = "Binary/";
4611
+ var kr = { resourceType: "Device", id: "system", deviceName: [{ name: "System" }] };
4612
+ var bi = ((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))(bi || {});
4613
+ var Si = ((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))(Si || {});
4614
+ var Dr = class extends qe {
6083
4615
  constructor(t) {
6084
4616
  super();
6085
4617
  if (t?.baseUrl && !t.baseUrl.startsWith("http"))
6086
4618
  throw new Error("Base URL must start with http or https");
6087
- this.fetch = t?.fetch ?? Ti(), this.storage = t?.storage ?? new je(), this.createPdfImpl = t?.createPdf, this.baseUrl = Ir(t?.baseUrl) ?? mi, this.fhirBaseUrl = this.baseUrl + (Ir(t?.fhirUrlPath) ?? "fhir/R4/"), this.clientId = t?.clientId ?? "", this.authorizeUrl = t?.authorizeUrl ?? this.baseUrl + "oauth2/authorize", this.tokenUrl = t?.tokenUrl ?? this.baseUrl + "oauth2/token", this.logoutUrl = t?.logoutUrl ?? this.baseUrl + "oauth2/logout", this.onUnauthenticated = t?.onUnauthenticated, this.cacheTime = t?.cacheTime ?? yi, this.cacheTime > 0 ? this.requestCache = new Fe(t?.resourceCacheSize ?? hi) : this.requestCache = void 0, t?.autoBatchTime ? (this.autoBatchTime = t.autoBatchTime, this.autoBatchQueue = []) : (this.autoBatchTime = 0, this.autoBatchQueue = void 0);
4619
+ this.fetch = t?.fetch ?? Ri(), this.storage = t?.storage ?? new je(), this.createPdfImpl = t?.createPdf, this.baseUrl = Or(t?.baseUrl) ?? xi, this.fhirBaseUrl = this.baseUrl + (Or(t?.fhirUrlPath) ?? "fhir/R4/"), this.clientId = t?.clientId ?? "", this.clientSecret = t?.clientSecret ?? "", this.authorizeUrl = t?.authorizeUrl ?? this.baseUrl + "oauth2/authorize", this.tokenUrl = t?.tokenUrl ?? this.baseUrl + "oauth2/token", this.logoutUrl = t?.logoutUrl ?? this.baseUrl + "oauth2/logout", this.onUnauthenticated = t?.onUnauthenticated, this.cacheTime = t?.cacheTime ?? vi, this.cacheTime > 0 ? this.requestCache = new Fe(t?.resourceCacheSize ?? Ti) : this.requestCache = void 0, t?.autoBatchTime ? (this.autoBatchTime = t.autoBatchTime, this.autoBatchQueue = []) : (this.autoBatchTime = 0, this.autoBatchQueue = void 0);
6088
4620
  let n = this.getActiveLogin();
6089
4621
  n && (this.setAccessToken(n.accessToken, n.refreshToken), this.refreshProfile().catch(console.log)), this.setupStorageListener();
6090
4622
  }
@@ -6121,7 +4653,7 @@ var wr = class extends qe {
6121
4653
  t.startsWith(this.fhirBaseUrl) && this.autoBatchQueue ? o = new Promise((a, c2) => {
6122
4654
  this.autoBatchQueue.push({ method: "GET", url: t.replace(this.fhirBaseUrl, ""), options: n, resolve: a, reject: c2 }), this.autoBatchTimerId || (this.autoBatchTimerId = setTimeout(() => this.executeAutoBatch(), this.autoBatchTime));
6123
4655
  }) : o = this.request("GET", t, n);
6124
- let s = new C(o);
4656
+ let s = new w(o);
6125
4657
  return this.setCacheEntry(t, s), s;
6126
4658
  }
6127
4659
  post(t, n, i2, o = {}) {
@@ -6131,7 +4663,7 @@ var wr = class extends qe {
6131
4663
  return t = t.toString(), n && this.setRequestBody(o, n), i2 && this.setRequestContentType(o, i2), this.invalidateUrl(t), this.request("PUT", t, o);
6132
4664
  }
6133
4665
  patch(t, n, i2 = {}) {
6134
- return t = t.toString(), this.setRequestBody(i2, n), this.setRequestContentType(i2, J.JSON_PATCH), this.invalidateUrl(t), this.request("PATCH", t, i2);
4666
+ return t = t.toString(), this.setRequestBody(i2, n), this.setRequestContentType(i2, Y.JSON_PATCH), this.invalidateUrl(t), this.request("PATCH", t, i2);
6135
4667
  }
6136
4668
  delete(t, n) {
6137
4669
  return t = t.toString(), this.invalidateUrl(t), this.request("DELETE", t, n);
@@ -6192,7 +4724,7 @@ var wr = class extends qe {
6192
4724
  let o = this.fhirSearchUrl(t, n), s = o.toString() + "-search", a = this.getCacheEntry(s, i2);
6193
4725
  if (a)
6194
4726
  return a.value;
6195
- let c2 = new C((async () => {
4727
+ let c2 = new w((async () => {
6196
4728
  let p2 = await this.get(o, i2);
6197
4729
  if (p2.entry)
6198
4730
  for (let l2 of p2.entry)
@@ -6207,14 +4739,14 @@ var wr = class extends qe {
6207
4739
  let s = o.toString() + "-searchOne", a = this.getCacheEntry(s, i2);
6208
4740
  if (a)
6209
4741
  return a.value;
6210
- let c2 = new C(this.search(t, o.searchParams, i2).then((p2) => p2.entry?.[0]?.resource));
4742
+ let c2 = new w(this.search(t, o.searchParams, i2).then((p2) => p2.entry?.[0]?.resource));
6211
4743
  return this.setCacheEntry(s, c2), c2;
6212
4744
  }
6213
4745
  searchResources(t, n, i2) {
6214
4746
  let s = this.fhirSearchUrl(t, n).toString() + "-searchResources", a = this.getCacheEntry(s, i2);
6215
4747
  if (a)
6216
4748
  return a.value;
6217
- let c2 = new C(this.search(t, n, i2).then(Or));
4749
+ let c2 = new w(this.search(t, n, i2).then(Ur));
6218
4750
  return this.setCacheEntry(s, c2), c2;
6219
4751
  }
6220
4752
  async *searchResourcePages(t, n, i2) {
@@ -6223,7 +4755,7 @@ var wr = class extends qe {
6223
4755
  let s = new URL(o).searchParams, a = await this.search(t, s, i2), c2 = a.link?.find((p2) => p2.relation === "next");
6224
4756
  if (!a.entry?.length && !c2)
6225
4757
  break;
6226
- yield Or(a), o = c2?.url ? new URL(c2.url) : void 0;
4758
+ yield Ur(a), o = c2?.url ? new URL(c2.url) : void 0;
6227
4759
  }
6228
4760
  }
6229
4761
  searchValueSet(t, n, i2) {
@@ -6239,7 +4771,7 @@ var wr = class extends qe {
6239
4771
  if (!n)
6240
4772
  return;
6241
4773
  if (n === "system")
6242
- return Cr;
4774
+ return kr;
6243
4775
  let [i2, o] = n.split("/");
6244
4776
  if (!(!i2 || !o))
6245
4777
  return this.getCached(i2, o);
@@ -6250,11 +4782,11 @@ var wr = class extends qe {
6250
4782
  readReference(t, n) {
6251
4783
  let i2 = t.reference;
6252
4784
  if (!i2)
6253
- return new C(Promise.reject(new Error("Missing reference")));
4785
+ return new w(Promise.reject(new Error("Missing reference")));
6254
4786
  if (i2 === "system")
6255
- return new C(Promise.resolve(Cr));
4787
+ return new w(Promise.resolve(kr));
6256
4788
  let [o, s] = i2.split("/");
6257
- return !o || !s ? new C(Promise.reject(new Error("Invalid reference"))) : this.readResource(o, s, n);
4789
+ return !o || !s ? new w(Promise.reject(new Error("Invalid reference"))) : this.readResource(o, s, n);
6258
4790
  }
6259
4791
  getSchema() {
6260
4792
  return y;
@@ -6265,7 +4797,7 @@ var wr = class extends qe {
6265
4797
  let n = t + "-requestSchema", i2 = this.getCacheEntry(n, void 0);
6266
4798
  if (i2)
6267
4799
  return i2.value;
6268
- let o = new C((async () => {
4800
+ let o = new w((async () => {
6269
4801
  let s = `{
6270
4802
  StructureDefinitionList(name: "${t}") {
6271
4803
  name,
@@ -6296,9 +4828,9 @@ var wr = class extends qe {
6296
4828
  }
6297
4829
  }`.replace(/\s+/g, " "), a = await this.graphql(s);
6298
4830
  for (let c2 of a.data.StructureDefinitionList)
6299
- st(c2);
6300
- for (let c2 of a.data.SearchParameterList)
6301
4831
  at(c2);
4832
+ for (let c2 of a.data.SearchParameterList)
4833
+ ct(c2);
6302
4834
  return y;
6303
4835
  })());
6304
4836
  return this.setCacheEntry(n, o), o;
@@ -6344,7 +4876,7 @@ var wr = class extends qe {
6344
4876
  }
6345
4877
  createComment(t, n, i2) {
6346
4878
  let o = this.getProfile(), s, a;
6347
- return t.resourceType === "Encounter" && (s = ne(t), a = t.subject), t.resourceType === "ServiceRequest" && (s = t.encounter, a = t.subject), t.resourceType === "Patient" && (a = ne(t)), this.createResource({ resourceType: "Communication", basedOn: [ne(t)], encounter: s, subject: a, sender: o ? ne(o) : void 0, sent: (/* @__PURE__ */ new Date()).toISOString(), payload: [{ contentString: n }] }, i2);
4879
+ return t.resourceType === "Encounter" && (s = ie(t), a = t.subject), t.resourceType === "ServiceRequest" && (s = t.encounter, a = t.subject), t.resourceType === "Patient" && (a = ie(t)), this.createResource({ resourceType: "Communication", basedOn: [ie(t)], encounter: s, subject: a, sender: o ? ie(o) : void 0, sent: (/* @__PURE__ */ new Date()).toISOString(), payload: [{ contentString: n }] }, i2);
6348
4880
  }
6349
4881
  async updateResource(t, n) {
6350
4882
  if (!t.resourceType)
@@ -6379,10 +4911,10 @@ var wr = class extends qe {
6379
4911
  return this.post(this.fhirBaseUrl.slice(0, -1), t, void 0, n);
6380
4912
  }
6381
4913
  sendEmail(t, n) {
6382
- return this.post("email/v1/send", t, J.JSON, n);
4914
+ return this.post("email/v1/send", t, Y.JSON, n);
6383
4915
  }
6384
4916
  graphql(t, n, i2, o) {
6385
- return this.post(this.fhirUrl("$graphql"), { query: t, operationName: n, variables: i2 }, J.JSON, o);
4917
+ return this.post(this.fhirUrl("$graphql"), { query: t, operationName: n, variables: i2 }, Y.JSON, o);
6386
4918
  }
6387
4919
  readResourceGraph(t, n, i2, o) {
6388
4920
  return this.get(`${this.fhirUrl(t, n)}/$graph?graph=${i2}`, o);
@@ -6397,7 +4929,7 @@ var wr = class extends qe {
6397
4929
  return this.accessToken;
6398
4930
  }
6399
4931
  setAccessToken(t, n) {
6400
- this.accessToken = t, this.refreshToken = n, this.sessionDetails = void 0, this.medplumServer = Er(t);
4932
+ this.accessToken = t, this.refreshToken = n, this.sessionDetails = void 0, this.medplumServer = Cr(t);
6401
4933
  }
6402
4934
  getLogins() {
6403
4935
  return this.storage.getObject("logins") ?? [];
@@ -6442,14 +4974,14 @@ var wr = class extends qe {
6442
4974
  }
6443
4975
  normalizeFetchUrl(t) {
6444
4976
  let n = t.toString();
6445
- return n.startsWith(Pr) && (n = this.fhirUrl(n).toString()), n;
4977
+ return n.startsWith(wr) && (n = this.fhirUrl(n).toString()), n;
6446
4978
  }
6447
4979
  async download(t, n = {}) {
6448
4980
  return this.refreshPromise && await this.refreshPromise, this.addFetchOptionsDefaults(n), (await this.fetch(this.normalizeFetchUrl(t), n)).blob();
6449
4981
  }
6450
4982
  async uploadMedia(t, n, i2, o, s) {
6451
4983
  let a = await this.createBinary(t, i2, n);
6452
- return this.createResource({ ...o, resourceType: "Media", content: { contentType: n, url: Pr + a.id, title: i2 } }, s);
4984
+ return this.createResource({ ...o, resourceType: "Media", content: { contentType: n, url: wr + a.id, title: i2 } }, s);
6453
4985
  }
6454
4986
  async bulkExport(t = "", n, i2, o) {
6455
4987
  let s = t && `${t}/`, a = this.fhirUrl(`${s}$export`);
@@ -6461,7 +4993,7 @@ var wr = class extends qe {
6461
4993
  i2.Prefer = "respond-async";
6462
4994
  let o = await this.fetchWithRetry(t, n);
6463
4995
  if (o.status === 202) {
6464
- let s = await Dr(o);
4996
+ let s = await Vr(o);
6465
4997
  if (s)
6466
4998
  return this.pollStatus(s);
6467
4999
  }
@@ -6478,7 +5010,7 @@ var wr = class extends qe {
6478
5010
  this.requestCache && this.requestCache.set(t, { requestTime: Date.now(), value: n });
6479
5011
  }
6480
5012
  cacheResource(t) {
6481
- t?.id && !t.meta?.tag?.some((n) => n.code === "SUBSETTED") && this.setCacheEntry(this.fhirUrl(t.resourceType, t.id).toString(), new C(Promise.resolve(t)));
5013
+ t?.id && !t.meta?.tag?.some((n) => n.code === "SUBSETTED") && this.setCacheEntry(this.fhirUrl(t.resourceType, t.id).toString(), new w(Promise.resolve(t)));
6482
5014
  }
6483
5015
  deleteCacheEntry(t) {
6484
5016
  this.requestCache && this.requestCache.delete(t);
@@ -6495,7 +5027,7 @@ var wr = class extends qe {
6495
5027
  return;
6496
5028
  let a = t.headers.get("content-type")?.includes("json");
6497
5029
  if (t.status === 404 && !a)
6498
- throw new m(Vt);
5030
+ throw new m(Ut);
6499
5031
  let c2;
6500
5032
  if (a)
6501
5033
  try {
@@ -6506,7 +5038,7 @@ var wr = class extends qe {
6506
5038
  else
6507
5039
  c2 = await t.text();
6508
5040
  if (t.status >= 400)
6509
- throw new m(et(c2));
5041
+ throw new m(tt(c2));
6510
5042
  return c2;
6511
5043
  }
6512
5044
  async fetchWithRetry(t, n) {
@@ -6519,7 +5051,7 @@ var wr = class extends qe {
6519
5051
  } catch (c2) {
6520
5052
  this.retryCatch(a, i2, c2);
6521
5053
  }
6522
- await ot(o);
5054
+ await st(o);
6523
5055
  }
6524
5056
  return s;
6525
5057
  }
@@ -6530,10 +5062,10 @@ var wr = class extends qe {
6530
5062
  this.addFetchOptionsDefaults(s);
6531
5063
  let a = await this.fetchWithRetry(t, s);
6532
5064
  if (a.status !== 202 && (n = false, i2 = a, a.status === 201)) {
6533
- let c2 = await Dr(a);
5065
+ let c2 = await Vr(a);
6534
5066
  c2 && (i2 = await this.fetchWithRetry(c2, s));
6535
5067
  }
6536
- await ot(o);
5068
+ await st(o);
6537
5069
  }
6538
5070
  return this.parseResponse(i2, "POST", t);
6539
5071
  }
@@ -6544,19 +5076,19 @@ var wr = class extends qe {
6544
5076
  try {
6545
5077
  o.resolve(await this.request(o.method, this.fhirBaseUrl + o.url, o.options));
6546
5078
  } catch (s) {
6547
- o.reject(new m(et(s)));
5079
+ o.reject(new m(tt(s)));
6548
5080
  }
6549
5081
  return;
6550
5082
  }
6551
5083
  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);
6552
5084
  for (let o = 0; o < t.length; o++) {
6553
5085
  let s = t[o], a = i2.entry?.[o];
6554
- a?.response?.outcome && !Ze(a.response.outcome) ? s.reject(new m(a.response.outcome)) : s.resolve(a?.resource);
5086
+ a?.response?.outcome && !et(a.response.outcome) ? s.reject(new m(a.response.outcome)) : s.resolve(a?.resource);
6555
5087
  }
6556
5088
  }
6557
5089
  addFetchOptionsDefaults(t) {
6558
5090
  let n = t.headers;
6559
- n || (n = {}, t.headers = n), n.Accept = J.FHIR_JSON, n["X-Medplum"] = "extended", t.body && !n["Content-Type"] && (n["Content-Type"] = J.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");
5091
+ n || (n = {}, t.headers = n), n.Accept = Y.FHIR_JSON, n["X-Medplum"] = "extended", t.body && !n["Content-Type"] && (n["Content-Type"] = Y.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");
6560
5092
  }
6561
5093
  setRequestContentType(t, n) {
6562
5094
  t.headers || (t.headers = {});
@@ -6570,20 +5102,20 @@ var wr = class extends qe {
6570
5102
  return this.refresh() ? this.request(t, n, i2) : (this.clearActiveLogin(), this.onUnauthenticated && this.onUnauthenticated(), Promise.reject(new Error("Unauthenticated")));
6571
5103
  }
6572
5104
  async startPkce() {
6573
- let t = Tt();
5105
+ let t = vt();
6574
5106
  sessionStorage.setItem("pkceState", t);
6575
- let n = Tt();
5107
+ let n = vt();
6576
5108
  sessionStorage.setItem("codeVerifier", n);
6577
- let i2 = await Sr(n), o = Jt(i2).replaceAll("+", "-").replaceAll("/", "_").replaceAll("=", "");
5109
+ let i2 = await Ar(n), o = Yt(i2).replaceAll("+", "-").replaceAll("/", "_").replaceAll("=", "");
6578
5110
  return sessionStorage.setItem("codeChallenge", o), { codeChallengeMethod: "S256", codeChallenge: o };
6579
5111
  }
6580
5112
  async requestAuthorization(t) {
6581
5113
  let n = await this.ensureCodeChallenge(t ?? {}), i2 = new URL(this.authorizeUrl);
6582
- i2.searchParams.set("response_type", "code"), i2.searchParams.set("state", sessionStorage.getItem("pkceState")), i2.searchParams.set("client_id", n.clientId ?? this.clientId), i2.searchParams.set("redirect_uri", n.redirectUri ?? kr()), i2.searchParams.set("code_challenge_method", n.codeChallengeMethod), i2.searchParams.set("code_challenge", n.codeChallenge), i2.searchParams.set("scope", n.scope ?? "openid profile"), window.location.assign(i2.toString());
5114
+ i2.searchParams.set("response_type", "code"), i2.searchParams.set("state", sessionStorage.getItem("pkceState")), i2.searchParams.set("client_id", n.clientId ?? this.clientId), i2.searchParams.set("redirect_uri", n.redirectUri ?? Ir()), i2.searchParams.set("code_challenge_method", n.codeChallengeMethod), i2.searchParams.set("code_challenge", n.codeChallenge), i2.searchParams.set("scope", n.scope ?? "openid profile"), window.location.assign(i2.toString());
6583
5115
  }
6584
5116
  processCode(t, n) {
6585
5117
  let i2 = new URLSearchParams();
6586
- if (i2.set("grant_type", "authorization_code"), i2.set("code", t), i2.set("client_id", n?.clientId ?? this.clientId), i2.set("redirect_uri", n?.redirectUri ?? kr()), typeof sessionStorage < "u") {
5118
+ if (i2.set("grant_type", "authorization_code"), i2.set("code", t), i2.set("client_id", n?.clientId ?? this.clientId), i2.set("redirect_uri", n?.redirectUri ?? Ir()), typeof sessionStorage < "u") {
6587
5119
  let o = sessionStorage.getItem("codeVerifier");
6588
5120
  o && i2.set("code_verifier", o);
6589
5121
  }
@@ -6610,29 +5142,29 @@ var wr = class extends qe {
6610
5142
  return o.set("grant_type", "urn:ietf:params:oauth:grant-type:jwt-bearer"), o.set("client_id", t), o.set("assertion", n), o.set("scope", i2), this.fetchTokens(o);
6611
5143
  }
6612
5144
  setBasicAuth(t, n) {
6613
- this.clientId = t, this.clientSecret = n, this.basicAuth = br(t + ":" + n);
5145
+ this.clientId = t, this.clientSecret = n, this.basicAuth = Rr(t + ":" + n);
6614
5146
  }
6615
5147
  async invite(t, n) {
6616
5148
  return this.post("admin/projects/" + t + "/invite", n);
6617
5149
  }
6618
5150
  async fetchTokens(t) {
6619
- let n = { method: "POST", headers: { "Content-Type": J.FORM_URL_ENCODED }, body: t.toString(), credentials: "include" }, i2 = n.headers;
5151
+ let n = { method: "POST", headers: { "Content-Type": Y.FORM_URL_ENCODED }, body: t.toString(), credentials: "include" }, i2 = n.headers;
6620
5152
  this.basicAuth && (i2.Authorization = `Basic ${this.basicAuth}`);
6621
5153
  let o = await this.fetch(this.tokenUrl, n);
6622
5154
  if (!o.ok) {
6623
5155
  this.clearActiveLogin();
6624
5156
  try {
6625
5157
  let a = await o.json();
6626
- throw new m(k(a.error_description));
5158
+ throw new m(D(a.error_description));
6627
5159
  } catch (a) {
6628
- throw new m(k("Failed to fetch tokens"), a);
5160
+ throw new m(D("Failed to fetch tokens"), a);
6629
5161
  }
6630
5162
  }
6631
5163
  let s = await o.json();
6632
5164
  return await this.verifyTokens(s), this.getProfile();
6633
5165
  }
6634
5166
  async verifyTokens(t) {
6635
- let n = t.access_token, i2 = vt(n);
5167
+ let n = t.access_token, i2 = bt(n);
6636
5168
  if (Date.now() >= i2.exp * 1e3)
6637
5169
  throw this.clearActiveLogin(), new Error("Token expired");
6638
5170
  if (i2.cid) {
@@ -6655,18 +5187,18 @@ var wr = class extends qe {
6655
5187
  throw i2;
6656
5188
  }
6657
5189
  };
6658
- function Ti() {
5190
+ function Ri() {
6659
5191
  if (!globalThis.fetch)
6660
5192
  throw new Error("Fetch not available in this environment");
6661
5193
  return globalThis.fetch.bind(globalThis);
6662
5194
  }
6663
- function kr() {
5195
+ function Ir() {
6664
5196
  return typeof window > "u" ? "" : window.location.protocol + "//" + window.location.host + "/";
6665
5197
  }
6666
- function Ir(r4) {
5198
+ function Or(r4) {
6667
5199
  return r4 && (r4.endsWith("/") ? r4 : r4 + "/");
6668
5200
  }
6669
- async function Dr(r4) {
5201
+ async function Vr(r4) {
6670
5202
  let e = r4.headers.get("content-location");
6671
5203
  if (e)
6672
5204
  return e;
@@ -6674,18 +5206,18 @@ async function Dr(r4) {
6674
5206
  if (t)
6675
5207
  return t;
6676
5208
  let n = await r4.json();
6677
- if (ye(n) && n.issue?.[0]?.diagnostics)
5209
+ if (he(n) && n.issue?.[0]?.diagnostics)
6678
5210
  return n.issue[0].diagnostics;
6679
5211
  }
6680
- function Or(r4) {
5212
+ function Ur(r4) {
6681
5213
  let e = r4.entry?.map((t) => t.resource) ?? [];
6682
5214
  return Object.assign(e, { bundle: r4 });
6683
5215
  }
6684
- var vi = [...ce, "->", "<<", ">>"];
6685
- var bi = ue().registerInfix("->", { precedence: f.Arrow }).registerInfix(";", { precedence: f.Semicolon });
6686
- var Si = [...ce, "eq", "ne", "co"];
6687
- var Ei = ue();
6688
- var H = class {
5216
+ var Ai = [...ce, "->", "<<", ">>"];
5217
+ var Ei = ue().registerInfix("->", { precedence: f.Arrow }).registerInfix(";", { precedence: f.Semicolon });
5218
+ var Pi = [...ce, "eq", "ne", "co"];
5219
+ var ki = ue();
5220
+ var W = class {
6689
5221
  constructor(e = "\r", t = "|", n = "^", i2 = "~", o = "\\", s = "&") {
6690
5222
  this.segmentSeparator = e;
6691
5223
  this.fieldSeparator = t;
@@ -6701,8 +5233,8 @@ var H = class {
6701
5233
  return this.componentSeparator + this.repetitionSeparator + this.escapeCharacter + this.subcomponentSeparator;
6702
5234
  }
6703
5235
  };
6704
- var Lr = class r {
6705
- constructor(e, t = new H()) {
5236
+ var Nr = class r {
5237
+ constructor(e, t = new W()) {
6706
5238
  this.context = t, this.segments = e;
6707
5239
  }
6708
5240
  get header() {
@@ -6725,7 +5257,7 @@ var Lr = class r {
6725
5257
  }
6726
5258
  buildAck() {
6727
5259
  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";
6728
- return new r([new pe(["MSH", this.context.getMsh2(), o, s, n, i2, Ci(e), "", this.buildAckMessageType(t), e.getTime().toString(), "P", c2], this.context), new pe(["MSA", "AA", a, "OK"], this.context)]);
5260
+ return new r([new pe(["MSH", this.context.getMsh2(), o, s, n, i2, Ii(e), "", this.buildAckMessageType(t), e.getTime().toString(), "P", c2], this.context), new pe(["MSA", "AA", a, "OK"], this.context)]);
6729
5261
  }
6730
5262
  buildAckMessageType(e) {
6731
5263
  let t = e?.getField(9), n = t?.getComponent(2), i2 = t?.getComponent(3), o = "ACK";
@@ -6736,13 +5268,13 @@ var Lr = class r {
6736
5268
  let n = new Error("Invalid HL7 message");
6737
5269
  throw n.type = "entity.parse.failed", n;
6738
5270
  }
6739
- let t = new H("\r", e.charAt(3), e.charAt(4), e.charAt(5), e.charAt(6), e.charAt(7));
5271
+ let t = new W("\r", e.charAt(3), e.charAt(4), e.charAt(5), e.charAt(6), e.charAt(7));
6740
5272
  return new r(e.split(/[\r\n]+/).map((n) => pe.parse(n, t)), t);
6741
5273
  }
6742
5274
  };
6743
5275
  var pe = class r2 {
6744
- constructor(e, t = new H()) {
6745
- this.context = t, Gt(e) ? this.fields = e.map((n) => ee.parse(n, t)) : this.fields = e, this.name = this.fields[0].components[0][0];
5276
+ constructor(e, t = new W()) {
5277
+ this.context = t, zt(e) ? this.fields = e.map((n) => te.parse(n, t)) : this.fields = e, this.name = this.fields[0].components[0][0];
6746
5278
  }
6747
5279
  get(e) {
6748
5280
  return this.fields[e];
@@ -6750,9 +5282,9 @@ var pe = class r2 {
6750
5282
  getField(e) {
6751
5283
  if (this.name === "MSH") {
6752
5284
  if (e === 1)
6753
- return new ee([[this.context.getMsh1()]], this.context);
5285
+ return new te([[this.context.getMsh1()]], this.context);
6754
5286
  if (e === 2)
6755
- return new ee([[this.context.getMsh2()]], this.context);
5287
+ return new te([[this.context.getMsh2()]], this.context);
6756
5288
  if (e > 2)
6757
5289
  return this.fields[e - 1];
6758
5290
  }
@@ -6764,12 +5296,12 @@ var pe = class r2 {
6764
5296
  toString() {
6765
5297
  return this.fields.map((e) => e.toString()).join(this.context.fieldSeparator);
6766
5298
  }
6767
- static parse(e, t = new H()) {
6768
- return new r2(e.split(t.fieldSeparator).map((n) => ee.parse(n, t)), t);
5299
+ static parse(e, t = new W()) {
5300
+ return new r2(e.split(t.fieldSeparator).map((n) => te.parse(n, t)), t);
6769
5301
  }
6770
5302
  };
6771
- var ee = class r3 {
6772
- constructor(e, t = new H()) {
5303
+ var te = class r3 {
5304
+ constructor(e, t = new W()) {
6773
5305
  this.context = t, this.components = e;
6774
5306
  }
6775
5307
  get(e, t, n = 0) {
@@ -6782,11 +5314,11 @@ var ee = class r3 {
6782
5314
  toString() {
6783
5315
  return this.components.map((e) => e.join(this.context.componentSeparator)).join(this.context.repetitionSeparator);
6784
5316
  }
6785
- static parse(e, t = new H()) {
5317
+ static parse(e, t = new W()) {
6786
5318
  return new r3(e.split(t.repetitionSeparator).map((n) => n.split(t.componentSeparator)), t);
6787
5319
  }
6788
5320
  };
6789
- function Ci(r4) {
5321
+ function Ii(r4) {
6790
5322
  let e = r4 instanceof Date ? r4 : new Date(r4), n = e.toISOString().replace(/[-:T]/g, "").replace(/(\.\d+)?Z$/, ""), i2 = e.getUTCMilliseconds();
6791
5323
  return i2 > 0 && (n += "." + i2.toString()), n;
6792
5324
  }
@@ -6826,7 +5358,7 @@ var c = class extends i {
6826
5358
  e.on("data", (s) => {
6827
5359
  try {
6828
5360
  if (o += s.toString(), o.endsWith(p + v2)) {
6829
- let r4 = Lr.parse(o.substring(1, o.length - 2));
5361
+ let r4 = Nr.parse(o.substring(1, o.length - 2));
6830
5362
  this.dispatchEvent(new d2(this, r4)), o = "";
6831
5363
  }
6832
5364
  } catch (r4) {
@@ -6868,10 +5400,6 @@ var E2 = class {
6868
5400
  }
6869
5401
  };
6870
5402
 
6871
- // src/main.ts
6872
- var import_fs = require("fs");
6873
- var import_node_windows = __toESM(require_node_windows());
6874
-
6875
5403
  // ../../node_modules/ws/wrapper.mjs
6876
5404
  var import_stream = __toESM(require_stream(), 1);
6877
5405
  var import_receiver = __toESM(require_receiver(), 1);
@@ -6882,50 +5410,70 @@ var wrapper_default = import_websocket.default;
6882
5410
 
6883
5411
  // src/main.ts
6884
5412
  var App = class {
6885
- constructor(medplum, config) {
5413
+ constructor(medplum, agentId) {
6886
5414
  this.medplum = medplum;
6887
- this.config = config;
6888
- this.connections = [];
6889
- if (config.useSystemEventLog) {
6890
- this.log = new import_node_windows.EventLogger({
6891
- source: "MedplumService",
6892
- eventLog: "SYSTEM"
6893
- });
6894
- } else {
6895
- this.log = {
6896
- info: console.log,
6897
- warn: console.warn,
6898
- error: console.error
6899
- };
5415
+ this.agentId = agentId;
5416
+ this.log = {
5417
+ info: console.log,
5418
+ warn: console.warn,
5419
+ error: console.error
5420
+ };
5421
+ this.channels = [];
5422
+ }
5423
+ async start() {
5424
+ this.log.info("Medplum service starting...");
5425
+ const agent = await this.medplum.readResource("Agent", this.agentId);
5426
+ for (const definition of agent.channel) {
5427
+ const endpoint = await this.medplum.readReference(definition.endpoint);
5428
+ const channel = new AgentHl7Channel(this, definition, endpoint);
5429
+ channel.start();
5430
+ this.channels.push(channel);
6900
5431
  }
5432
+ this.log.info("Medplum service started successfully");
5433
+ }
5434
+ stop() {
5435
+ this.log.info("Medplum service stopping...");
5436
+ this.channels.forEach((channel) => channel.stop());
5437
+ this.log.info("Medplum service stopped successfully");
5438
+ }
5439
+ };
5440
+ var AgentHl7Channel = class {
5441
+ constructor(app, definition, endpoint) {
5442
+ this.app = app;
5443
+ this.definition = definition;
5444
+ this.endpoint = endpoint;
5445
+ this.connections = [];
6901
5446
  this.server = new E2((connection) => {
6902
- this.log.info("HL7 connection established");
6903
- this.connections.push(new Connection(this, connection));
5447
+ this.app.log.info("HL7 connection established");
5448
+ this.connections.push(new AgentHl7ChannelConnection(this, connection));
6904
5449
  });
6905
5450
  }
6906
5451
  start() {
6907
- this.log.info("Medplum service starting...");
6908
- this.server.start(56e3);
6909
- this.log.info("Medplum service started successfully");
5452
+ const address = new URL(this.endpoint.address);
5453
+ this.app.log.info(`Channel starting on ${address}`);
5454
+ this.server.start(parseInt(address.port, 10));
5455
+ this.app.log.info("Channel started successfully");
6910
5456
  }
6911
5457
  stop() {
6912
- this.log.info("Medplum service stopping...");
5458
+ this.app.log.info("Channel stopping...");
6913
5459
  for (const connection of this.connections) {
6914
5460
  connection.close();
6915
5461
  }
6916
5462
  this.server.stop();
6917
- this.log.info("Medplum service stopped successfully");
5463
+ this.app.log.info("Channel stopped successfully");
6918
5464
  }
6919
5465
  };
6920
- var Connection = class {
6921
- constructor(app, hl7Connection) {
6922
- this.app = app;
5466
+ var AgentHl7ChannelConnection = class {
5467
+ constructor(channel, hl7Connection) {
5468
+ this.channel = channel;
6923
5469
  this.hl7Connection = hl7Connection;
6924
5470
  this.webSocketQueue = [];
6925
5471
  this.hl7ConnectionQueue = [];
6926
5472
  this.live = false;
5473
+ const app = channel.app;
5474
+ const medplum = app.medplum;
6927
5475
  this.hl7Connection.addEventListener("message", (event) => this.handler(event));
6928
- const webSocketUrl = new URL(this.app.medplum.getBaseUrl());
5476
+ const webSocketUrl = new URL(medplum.getBaseUrl());
6929
5477
  webSocketUrl.protocol = webSocketUrl.protocol === "https:" ? "wss:" : "ws:";
6930
5478
  webSocketUrl.pathname = "/ws/agent";
6931
5479
  console.log("Connecting to WebSocket:", webSocketUrl.href);
@@ -6936,8 +5484,9 @@ var Connection = class {
6936
5484
  this.webSocket.send(
6937
5485
  JSON.stringify({
6938
5486
  type: "connect",
6939
- accessToken: this.app.medplum.getAccessToken(),
6940
- botId: this.app.config.botId
5487
+ accessToken: medplum.getAccessToken(),
5488
+ agentId: channel.app.agentId,
5489
+ botId: Ro(channel.definition.targetReference)
6941
5490
  })
6942
5491
  );
6943
5492
  });
@@ -6953,7 +5502,7 @@ var Connection = class {
6953
5502
  this.trySendToWebSocket();
6954
5503
  break;
6955
5504
  case "transmit":
6956
- this.hl7ConnectionQueue.push(Lr.parse(command.message));
5505
+ this.hl7ConnectionQueue.push(Nr.parse(command.message));
6957
5506
  this.trySendToHl7Connection();
6958
5507
  break;
6959
5508
  }
@@ -6980,6 +5529,7 @@ var Connection = class {
6980
5529
  this.webSocket.send(
6981
5530
  JSON.stringify({
6982
5531
  type: "transmit",
5532
+ forwardedFor: this.hl7Connection.socket.remoteAddress,
6983
5533
  message: msg.toString()
6984
5534
  })
6985
5535
  );
@@ -7001,11 +5551,17 @@ var Connection = class {
7001
5551
  }
7002
5552
  };
7003
5553
  if (typeof require !== "undefined" && require.main === module) {
7004
- const config = JSON.parse((0, import_fs.readFileSync)("medplum.config.json", "utf8"));
7005
- new App(new wr(config), config).start();
5554
+ if (process.argv.length < 6) {
5555
+ console.log("Usage: node medplum-agent.js <baseUrl> <clientId> <clientSecret> <agentId>");
5556
+ process.exit(1);
5557
+ }
5558
+ const [_node, _script, baseUrl, clientId, clientSecret, agentId] = process.argv;
5559
+ const medplum = new Dr({ baseUrl, clientId });
5560
+ medplum.startClientLogin(clientId, clientSecret).then(() => new App(medplum, agentId).start()).catch(console.error);
7006
5561
  }
7007
5562
  // Annotate the CommonJS export names for ESM import in node:
7008
5563
  0 && (module.exports = {
7009
- App,
7010
- Connection
5564
+ AgentHl7Channel,
5565
+ AgentHl7ChannelConnection,
5566
+ App
7011
5567
  });