@medplum/agent 2.0.27 → 2.0.29
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.
- package/dist/cjs/index.cjs +3407 -0
- package/dist/cjs/package.json +1 -0
- package/esbuild.mjs +28 -0
- package/package.json +4 -3
- package/src/main.ts +4 -6
|
@@ -0,0 +1,3407 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __commonJS = (cb, mod) => function __require() {
|
|
9
|
+
return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
|
|
10
|
+
};
|
|
11
|
+
var __export = (target, all) => {
|
|
12
|
+
for (var name in all)
|
|
13
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
14
|
+
};
|
|
15
|
+
var __copyProps = (to, from, except, desc) => {
|
|
16
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
17
|
+
for (let key of __getOwnPropNames(from))
|
|
18
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
19
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
20
|
+
}
|
|
21
|
+
return to;
|
|
22
|
+
};
|
|
23
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
24
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
25
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
26
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
27
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
28
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
29
|
+
mod
|
|
30
|
+
));
|
|
31
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
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
|
+
* 
|
|
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(log2, 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
|
+
log2 = log2 || "APPLICATION";
|
|
226
|
+
log2 = eventlogs.indexOf(log2.toUpperCase()) >= 0 ? log2 : "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 " + log2 + " /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
|
+
"&": "&",
|
|
394
|
+
'"': """,
|
|
395
|
+
"'": "'",
|
|
396
|
+
"<": "<",
|
|
397
|
+
">": ">"
|
|
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 st = (/* @__PURE__ */ new Date()).getTime();
|
|
802
|
+
while ((/* @__PURE__ */ new Date()).getTime() <= st + 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
|
+
// src/main.ts
|
|
1511
|
+
var main_exports = {};
|
|
1512
|
+
__export(main_exports, {
|
|
1513
|
+
App: () => App
|
|
1514
|
+
});
|
|
1515
|
+
module.exports = __toCommonJS(main_exports);
|
|
1516
|
+
|
|
1517
|
+
// ../core/dist/esm/index.mjs
|
|
1518
|
+
var Ge = "ok";
|
|
1519
|
+
var ze = "created";
|
|
1520
|
+
var Je = "not-modified";
|
|
1521
|
+
var Ye = "not-found";
|
|
1522
|
+
var he = "accepted";
|
|
1523
|
+
var Ot = { resourceType: "OperationOutcome", id: Ye, issue: [{ severity: "error", code: "not-found", details: { text: "Not found" } }] };
|
|
1524
|
+
function k(r4, e) {
|
|
1525
|
+
return { resourceType: "OperationOutcome", issue: [{ severity: "error", code: "invalid", details: { text: r4 }, expression: e ? [e] : void 0 }] };
|
|
1526
|
+
}
|
|
1527
|
+
function ye(r4) {
|
|
1528
|
+
return typeof r4 == "object" && r4 !== null && r4.resourceType === "OperationOutcome";
|
|
1529
|
+
}
|
|
1530
|
+
function Xe(r4) {
|
|
1531
|
+
return r4.id === Ge || r4.id === ze || r4.id === Je || r4.id === he;
|
|
1532
|
+
}
|
|
1533
|
+
var m = class extends Error {
|
|
1534
|
+
constructor(t, n) {
|
|
1535
|
+
super(Ut(t));
|
|
1536
|
+
this.outcome = t, this.cause = n;
|
|
1537
|
+
}
|
|
1538
|
+
};
|
|
1539
|
+
function Ze(r4) {
|
|
1540
|
+
return r4 instanceof m ? r4.outcome : ye(r4) ? r4 : k(Nr(r4));
|
|
1541
|
+
}
|
|
1542
|
+
function Nr(r4) {
|
|
1543
|
+
return r4 ? typeof r4 == "string" ? r4 : r4 instanceof Error ? r4.message : ye(r4) ? Ut(r4) : typeof r4 == "object" && "code" in r4 && typeof r4.code == "string" ? r4.code : JSON.stringify(r4) : "Unknown error";
|
|
1544
|
+
}
|
|
1545
|
+
function Ut(r4) {
|
|
1546
|
+
let e = r4.issue?.map(Br) ?? [];
|
|
1547
|
+
return e.length > 0 ? e.join("; ") : "Unknown error";
|
|
1548
|
+
}
|
|
1549
|
+
function Br(r4) {
|
|
1550
|
+
let e = r4.details?.text ?? r4.diagnostics ?? "Unknown error";
|
|
1551
|
+
return r4.expression?.length && (e += ` (${r4.expression.join(", ")})`), e;
|
|
1552
|
+
}
|
|
1553
|
+
var Lt = { 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" }] } } } } };
|
|
1554
|
+
function _t(r4, e) {
|
|
1555
|
+
let t = [];
|
|
1556
|
+
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();
|
|
1557
|
+
}
|
|
1558
|
+
function ne(r4) {
|
|
1559
|
+
let e = Bt(r4), t = Yr(r4);
|
|
1560
|
+
return t === e ? { reference: e } : { reference: e, display: t };
|
|
1561
|
+
}
|
|
1562
|
+
function Bt(r4) {
|
|
1563
|
+
return r4.resourceType + "/" + r4.id;
|
|
1564
|
+
}
|
|
1565
|
+
function Jr(r4) {
|
|
1566
|
+
return r4.resourceType === "Patient" || r4.resourceType === "Practitioner" || r4.resourceType === "RelatedPerson";
|
|
1567
|
+
}
|
|
1568
|
+
function Yr(r4) {
|
|
1569
|
+
if (Jr(r4)) {
|
|
1570
|
+
let e = Xr(r4);
|
|
1571
|
+
if (e)
|
|
1572
|
+
return e;
|
|
1573
|
+
}
|
|
1574
|
+
if (r4.resourceType === "Device") {
|
|
1575
|
+
let e = Zr(r4);
|
|
1576
|
+
if (e)
|
|
1577
|
+
return e;
|
|
1578
|
+
}
|
|
1579
|
+
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 : Bt(r4);
|
|
1580
|
+
}
|
|
1581
|
+
function Xr(r4) {
|
|
1582
|
+
let e = r4.name;
|
|
1583
|
+
if (e && e.length > 0)
|
|
1584
|
+
return _t(e[0]);
|
|
1585
|
+
}
|
|
1586
|
+
function Zr(r4) {
|
|
1587
|
+
let e = r4.deviceName;
|
|
1588
|
+
if (e && e.length > 0)
|
|
1589
|
+
return e[0].name;
|
|
1590
|
+
}
|
|
1591
|
+
function ge(r4, e) {
|
|
1592
|
+
let t = new Date(r4);
|
|
1593
|
+
t.setUTCHours(0, 0, 0, 0);
|
|
1594
|
+
let n = e ? new Date(e) : /* @__PURE__ */ new Date();
|
|
1595
|
+
n.setUTCHours(0, 0, 0, 0);
|
|
1596
|
+
let i2 = t.getUTCFullYear(), o = t.getUTCMonth(), s = t.getUTCDate(), a2 = n.getUTCFullYear(), c2 = n.getUTCMonth(), p2 = n.getUTCDate(), l2 = a2 - i2;
|
|
1597
|
+
(c2 < o || c2 === o && p2 < s) && l2--;
|
|
1598
|
+
let re = a2 * 12 + c2 - (i2 * 12 + o);
|
|
1599
|
+
p2 < s && re--;
|
|
1600
|
+
let me = Math.floor((n.getTime() - t.getTime()) / (1e3 * 60 * 60 * 24));
|
|
1601
|
+
return { years: l2, months: re, days: me };
|
|
1602
|
+
}
|
|
1603
|
+
function jt(r4, e) {
|
|
1604
|
+
return JSON.stringify(r4, en, e ? 2 : void 0);
|
|
1605
|
+
}
|
|
1606
|
+
function en(r4, e) {
|
|
1607
|
+
return !tn(r4) && v(e) ? void 0 : e;
|
|
1608
|
+
}
|
|
1609
|
+
function tn(r4) {
|
|
1610
|
+
return !!/\d+$/.exec(r4);
|
|
1611
|
+
}
|
|
1612
|
+
function v(r4) {
|
|
1613
|
+
if (r4 == null)
|
|
1614
|
+
return true;
|
|
1615
|
+
let e = typeof r4;
|
|
1616
|
+
return e === "string" && r4 === "" || e === "object" && Object.keys(r4).length === 0;
|
|
1617
|
+
}
|
|
1618
|
+
function Qt(r4) {
|
|
1619
|
+
return r4.every((e) => typeof e == "string");
|
|
1620
|
+
}
|
|
1621
|
+
var Ht = [];
|
|
1622
|
+
for (let r4 = 0; r4 < 256; r4++)
|
|
1623
|
+
Ht.push(r4.toString(16).padStart(2, "0"));
|
|
1624
|
+
function Wt(r4) {
|
|
1625
|
+
let e = new Uint8Array(r4), t = new Array(e.length);
|
|
1626
|
+
for (let n = 0; n < e.length; n++)
|
|
1627
|
+
t[n] = Ht[e[n]];
|
|
1628
|
+
return t.join("");
|
|
1629
|
+
}
|
|
1630
|
+
function Gt(r4) {
|
|
1631
|
+
let e = new Uint8Array(r4), t = [];
|
|
1632
|
+
for (let n = 0; n < e.length; n++)
|
|
1633
|
+
t[n] = String.fromCharCode(e[n]);
|
|
1634
|
+
return window.btoa(t.join(""));
|
|
1635
|
+
}
|
|
1636
|
+
function S(r4) {
|
|
1637
|
+
return r4.charAt(0).toUpperCase() + r4.substring(1);
|
|
1638
|
+
}
|
|
1639
|
+
var nt = (r4) => new Promise((e) => {
|
|
1640
|
+
setTimeout(e, r4);
|
|
1641
|
+
});
|
|
1642
|
+
var q = ((u) => (u.Address = "Address", u.Age = "Age", u.Annotation = "Annotation", u.Attachment = "Attachment", u.BackboneElement = "BackboneElement", u.CodeableConcept = "CodeableConcept", u.Coding = "Coding", u.ContactDetail = "ContactDetail", u.ContactPoint = "ContactPoint", u.Contributor = "Contributor", u.Count = "Count", u.DataRequirement = "DataRequirement", u.Distance = "Distance", u.Dosage = "Dosage", u.Duration = "Duration", u.Expression = "Expression", u.Extension = "Extension", u.HumanName = "HumanName", u.Identifier = "Identifier", u.MarketingStatus = "MarketingStatus", u.Meta = "Meta", u.Money = "Money", u.Narrative = "Narrative", u.ParameterDefinition = "ParameterDefinition", u.Period = "Period", u.Population = "Population", u.ProdCharacteristic = "ProdCharacteristic", u.ProductShelfLife = "ProductShelfLife", u.Quantity = "Quantity", u.Range = "Range", u.Ratio = "Ratio", u.Reference = "Reference", u.RelatedArtifact = "RelatedArtifact", u.SampledData = "SampledData", u.Signature = "Signature", u.SubstanceAmount = "SubstanceAmount", u.SystemString = "http://hl7.org/fhirpath/System.String", u.Timing = "Timing", u.TriggerDefinition = "TriggerDefinition", u.UsageContext = "UsageContext", u.base64Binary = "base64Binary", u.boolean = "boolean", u.canonical = "canonical", u.code = "code", u.date = "date", u.dateTime = "dateTime", u.decimal = "decimal", u.id = "id", u.instant = "instant", u.integer = "integer", u.markdown = "markdown", u.oid = "oid", u.positiveInt = "positiveInt", u.string = "string", u.time = "time", u.unsignedInt = "unsignedInt", u.uri = "uri", u.url = "url", u.uuid = "uuid", u))(q || {});
|
|
1643
|
+
function it(r4) {
|
|
1644
|
+
if (!r4.name)
|
|
1645
|
+
return;
|
|
1646
|
+
let t = r4.snapshot?.element;
|
|
1647
|
+
t && (t.forEach((n) => pn(r4, n)), t.forEach((n) => fn(r4, n)));
|
|
1648
|
+
}
|
|
1649
|
+
function pn(r4, e) {
|
|
1650
|
+
let t = e.path, n = e.type?.[0]?.code;
|
|
1651
|
+
if (n !== void 0 && n !== "Element" && n !== "BackboneElement")
|
|
1652
|
+
return;
|
|
1653
|
+
let i2 = t.split(".");
|
|
1654
|
+
i2[0] = r4.name;
|
|
1655
|
+
let o = U(i2), s = y.types[o];
|
|
1656
|
+
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 ?? {};
|
|
1657
|
+
}
|
|
1658
|
+
function fn(r4, e) {
|
|
1659
|
+
let n = e.path.split(".");
|
|
1660
|
+
if (n.length === 1)
|
|
1661
|
+
return;
|
|
1662
|
+
n[0] = r4.name;
|
|
1663
|
+
let i2 = U(n.slice(0, n.length - 1)), o = y.types[i2];
|
|
1664
|
+
if (!o)
|
|
1665
|
+
return;
|
|
1666
|
+
let s = n[n.length - 1];
|
|
1667
|
+
o.properties[s] = e;
|
|
1668
|
+
}
|
|
1669
|
+
function ot(r4) {
|
|
1670
|
+
for (let e of r4.base ?? []) {
|
|
1671
|
+
let t = y.types[e];
|
|
1672
|
+
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);
|
|
1673
|
+
}
|
|
1674
|
+
}
|
|
1675
|
+
function U(r4) {
|
|
1676
|
+
return r4.length === 1 ? r4[0] : r4.map(S).join("");
|
|
1677
|
+
}
|
|
1678
|
+
function ie(r4, e) {
|
|
1679
|
+
let t = y.types[r4];
|
|
1680
|
+
if (!t)
|
|
1681
|
+
return;
|
|
1682
|
+
let n = t.properties[e] ?? t.properties[e + "[x]"];
|
|
1683
|
+
if (n) {
|
|
1684
|
+
if (n.contentReference) {
|
|
1685
|
+
let i2 = n.contentReference.substring(1).split("."), o = i2.pop(), s = U(i2);
|
|
1686
|
+
return ie(s, o);
|
|
1687
|
+
}
|
|
1688
|
+
return n;
|
|
1689
|
+
}
|
|
1690
|
+
}
|
|
1691
|
+
function L(r4) {
|
|
1692
|
+
return !!(r4 && typeof r4 == "object" && "resourceType" in r4);
|
|
1693
|
+
}
|
|
1694
|
+
var y = Lt;
|
|
1695
|
+
var gn = ((g2) => (g2.EQUALS = "eq", g2.NOT_EQUALS = "ne", g2.GREATER_THAN = "gt", g2.LESS_THAN = "lt", g2.GREATER_THAN_OR_EQUALS = "ge", g2.LESS_THAN_OR_EQUALS = "le", g2.STARTS_AFTER = "sa", g2.ENDS_BEFORE = "eb", g2.APPROXIMATELY = "ap", g2.CONTAINS = "contains", g2.EXACT = "exact", g2.TEXT = "text", g2.NOT = "not", g2.ABOVE = "above", g2.BELOW = "below", g2.IN = "in", g2.NOT_IN = "not-in", g2.OF_TYPE = "of-type", g2.MISSING = "missing", g2.IDENTIFIER = "identifier", g2.ITERATE = "iterate", g2))(gn || {});
|
|
1696
|
+
var be = class {
|
|
1697
|
+
constructor(e, t) {
|
|
1698
|
+
this.operator = e;
|
|
1699
|
+
this.child = t;
|
|
1700
|
+
}
|
|
1701
|
+
toString() {
|
|
1702
|
+
return `${this.operator}(${this.child.toString()})`;
|
|
1703
|
+
}
|
|
1704
|
+
};
|
|
1705
|
+
var j = class {
|
|
1706
|
+
constructor(e, t, n) {
|
|
1707
|
+
this.operator = e;
|
|
1708
|
+
this.left = t;
|
|
1709
|
+
this.right = n;
|
|
1710
|
+
}
|
|
1711
|
+
toString() {
|
|
1712
|
+
return `${this.left.toString()} ${this.operator} ${this.right.toString()}`;
|
|
1713
|
+
}
|
|
1714
|
+
};
|
|
1715
|
+
var Se = class {
|
|
1716
|
+
constructor() {
|
|
1717
|
+
this.prefixParselets = {};
|
|
1718
|
+
this.infixParselets = {};
|
|
1719
|
+
}
|
|
1720
|
+
registerInfix(e, t) {
|
|
1721
|
+
return this.infixParselets[e] = t, this;
|
|
1722
|
+
}
|
|
1723
|
+
registerPrefix(e, t) {
|
|
1724
|
+
return this.prefixParselets[e] = t, this;
|
|
1725
|
+
}
|
|
1726
|
+
prefix(e, t, n) {
|
|
1727
|
+
return this.registerPrefix(e, { parse(i2, o) {
|
|
1728
|
+
let s = i2.consumeAndParse(t);
|
|
1729
|
+
return n(o, s);
|
|
1730
|
+
} });
|
|
1731
|
+
}
|
|
1732
|
+
infixLeft(e, t, n) {
|
|
1733
|
+
return this.registerInfix(e, { parse(i2, o, s) {
|
|
1734
|
+
let a2 = i2.consumeAndParse(t);
|
|
1735
|
+
return n(o, s, a2);
|
|
1736
|
+
}, precedence: t });
|
|
1737
|
+
}
|
|
1738
|
+
construct(e) {
|
|
1739
|
+
return new at(e, this.prefixParselets, this.infixParselets);
|
|
1740
|
+
}
|
|
1741
|
+
};
|
|
1742
|
+
var at = class {
|
|
1743
|
+
constructor(e, t, n) {
|
|
1744
|
+
this.tokens = e, this.prefixParselets = t, this.infixParselets = n;
|
|
1745
|
+
}
|
|
1746
|
+
hasMore() {
|
|
1747
|
+
return this.tokens.length > 0;
|
|
1748
|
+
}
|
|
1749
|
+
match(e) {
|
|
1750
|
+
return this.peek()?.id !== e ? false : (this.consume(), true);
|
|
1751
|
+
}
|
|
1752
|
+
consumeAndParse(e = 1 / 0) {
|
|
1753
|
+
let t = this.consume(), n = this.prefixParselets[t.id];
|
|
1754
|
+
if (!n)
|
|
1755
|
+
throw Error(`Parse error at "${t.value}" (line ${t.line}, column ${t.column}). No matching prefix parselet.`);
|
|
1756
|
+
let i2 = n.parse(this, t);
|
|
1757
|
+
for (; e > this.getPrecedence(); ) {
|
|
1758
|
+
let o = this.consume();
|
|
1759
|
+
i2 = this.getInfixParselet(o).parse(this, i2, o);
|
|
1760
|
+
}
|
|
1761
|
+
return i2;
|
|
1762
|
+
}
|
|
1763
|
+
getPrecedence() {
|
|
1764
|
+
let e = this.peek();
|
|
1765
|
+
if (!e)
|
|
1766
|
+
return 1 / 0;
|
|
1767
|
+
let t = this.getInfixParselet(e);
|
|
1768
|
+
return t ? t.precedence : 1 / 0;
|
|
1769
|
+
}
|
|
1770
|
+
consume(e, t) {
|
|
1771
|
+
if (!this.tokens.length)
|
|
1772
|
+
throw Error("Cant consume unknown more tokens.");
|
|
1773
|
+
if (e && this.peek()?.id !== e) {
|
|
1774
|
+
let n = this.peek();
|
|
1775
|
+
throw Error(`Expected ${e} but got "${n.id}" at line ${n.line} column ${n.column}.`);
|
|
1776
|
+
}
|
|
1777
|
+
if (t && this.peek()?.value !== t) {
|
|
1778
|
+
let n = this.peek();
|
|
1779
|
+
throw Error(`Expected "${t}" but got "${n.value}" at line ${n.line} column ${n.column}.`);
|
|
1780
|
+
}
|
|
1781
|
+
return this.tokens.shift();
|
|
1782
|
+
}
|
|
1783
|
+
peek() {
|
|
1784
|
+
return this.tokens.length > 0 ? this.tokens[0] : void 0;
|
|
1785
|
+
}
|
|
1786
|
+
removeComments() {
|
|
1787
|
+
this.tokens = this.tokens.filter((e) => e.id !== "Comment");
|
|
1788
|
+
}
|
|
1789
|
+
getInfixParselet(e) {
|
|
1790
|
+
return this.infixParselets[e.id === "Symbol" ? e.value : e.id];
|
|
1791
|
+
}
|
|
1792
|
+
};
|
|
1793
|
+
function X(r4) {
|
|
1794
|
+
if (r4.startsWith("T"))
|
|
1795
|
+
return r4 + "T00:00:00.000Z".substring(r4.length);
|
|
1796
|
+
if (r4.length <= 10)
|
|
1797
|
+
return r4;
|
|
1798
|
+
try {
|
|
1799
|
+
return new Date(r4).toISOString();
|
|
1800
|
+
} catch {
|
|
1801
|
+
return r4;
|
|
1802
|
+
}
|
|
1803
|
+
}
|
|
1804
|
+
function d(r4) {
|
|
1805
|
+
return [{ type: "boolean", value: r4 }];
|
|
1806
|
+
}
|
|
1807
|
+
function x(r4) {
|
|
1808
|
+
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 };
|
|
1809
|
+
}
|
|
1810
|
+
function _(r4) {
|
|
1811
|
+
return r4.length === 0 ? false : !!r4[0].value;
|
|
1812
|
+
}
|
|
1813
|
+
function I(r4, e) {
|
|
1814
|
+
if (r4.length !== 0) {
|
|
1815
|
+
if (r4.length === 1 && (!e || r4[0].type === e))
|
|
1816
|
+
return r4[0];
|
|
1817
|
+
throw new Error(`Expected singleton of type ${e}, but found ${JSON.stringify(r4)}`);
|
|
1818
|
+
}
|
|
1819
|
+
}
|
|
1820
|
+
function E(r4, e) {
|
|
1821
|
+
if (!r4.value)
|
|
1822
|
+
return;
|
|
1823
|
+
let t = ie(r4.type, e);
|
|
1824
|
+
return t ? Dn(r4, e, t) : In(r4, e);
|
|
1825
|
+
}
|
|
1826
|
+
function Dn(r4, e, t) {
|
|
1827
|
+
let n = t.type;
|
|
1828
|
+
if (!n || n.length === 0)
|
|
1829
|
+
return;
|
|
1830
|
+
let i2, o = "undefined";
|
|
1831
|
+
if (n.length === 1)
|
|
1832
|
+
i2 = r4.value[e], o = n[0].code;
|
|
1833
|
+
else
|
|
1834
|
+
for (let s of n) {
|
|
1835
|
+
let a2 = e.replace("[x]", "") + S(s.code);
|
|
1836
|
+
if (a2 in r4.value) {
|
|
1837
|
+
i2 = r4.value[a2], o = s.code;
|
|
1838
|
+
break;
|
|
1839
|
+
}
|
|
1840
|
+
}
|
|
1841
|
+
if (!v(i2))
|
|
1842
|
+
return (o === "Element" || o === "BackboneElement") && (o = U(t.path?.split("."))), Array.isArray(i2) ? i2.map((s) => or(s, o)) : or(i2, o);
|
|
1843
|
+
}
|
|
1844
|
+
function or(r4, e) {
|
|
1845
|
+
return e === "Resource" && L(r4) && (e = r4.resourceType), { type: e, value: r4 };
|
|
1846
|
+
}
|
|
1847
|
+
function In(r4, e) {
|
|
1848
|
+
let t = r4.value;
|
|
1849
|
+
if (!t || typeof t != "object")
|
|
1850
|
+
return;
|
|
1851
|
+
let n;
|
|
1852
|
+
if (e in t)
|
|
1853
|
+
n = t[e];
|
|
1854
|
+
else
|
|
1855
|
+
for (let i2 in q) {
|
|
1856
|
+
let o = e + S(i2);
|
|
1857
|
+
if (o in t) {
|
|
1858
|
+
n = t[o];
|
|
1859
|
+
break;
|
|
1860
|
+
}
|
|
1861
|
+
}
|
|
1862
|
+
if (!v(n))
|
|
1863
|
+
return Array.isArray(n) ? n.map(x) : x(n);
|
|
1864
|
+
}
|
|
1865
|
+
function Re(r4) {
|
|
1866
|
+
let e = [];
|
|
1867
|
+
for (let t of r4) {
|
|
1868
|
+
let n = false;
|
|
1869
|
+
for (let i2 of e)
|
|
1870
|
+
if (_(cr(t, i2))) {
|
|
1871
|
+
n = true;
|
|
1872
|
+
break;
|
|
1873
|
+
}
|
|
1874
|
+
n || e.push(t);
|
|
1875
|
+
}
|
|
1876
|
+
return e;
|
|
1877
|
+
}
|
|
1878
|
+
function ct(r4) {
|
|
1879
|
+
return d(!_(r4));
|
|
1880
|
+
}
|
|
1881
|
+
function ut(r4, e) {
|
|
1882
|
+
return r4.length === 0 || e.length === 0 ? [] : r4.length !== e.length ? d(false) : d(r4.every((t, n) => _(cr(t, e[n]))));
|
|
1883
|
+
}
|
|
1884
|
+
function cr(r4, e) {
|
|
1885
|
+
let t = r4.value, n = e.value;
|
|
1886
|
+
return typeof t == "number" && typeof n == "number" ? d(Math.abs(t - n) < 1e-8) : R(t) && R(n) ? d(ur(t, n)) : d(typeof t == "object" && typeof n == "object" ? lt(r4, e) : t === n);
|
|
1887
|
+
}
|
|
1888
|
+
function dt(r4, e) {
|
|
1889
|
+
return r4.length === 0 && e.length === 0 ? d(true) : r4.length !== e.length ? d(false) : (r4.sort(sr), e.sort(sr), d(r4.every((t, n) => _(On(t, e[n])))));
|
|
1890
|
+
}
|
|
1891
|
+
function On(r4, e) {
|
|
1892
|
+
let t = r4.value, n = e.value;
|
|
1893
|
+
return typeof t == "number" && typeof n == "number" ? d(Math.abs(t - n) < 0.01) : R(t) && R(n) ? d(ur(t, n)) : d(typeof t == "object" && typeof n == "object" ? lt(t, n) : typeof t == "string" && typeof n == "string" ? t.toLowerCase() === n.toLowerCase() : t === n);
|
|
1894
|
+
}
|
|
1895
|
+
function sr(r4, e) {
|
|
1896
|
+
let t = r4.value, n = e.value;
|
|
1897
|
+
return typeof t == "number" && typeof n == "number" ? t - n : typeof t == "string" && typeof n == "string" ? t.localeCompare(n) : 0;
|
|
1898
|
+
}
|
|
1899
|
+
function Ae(r4, e) {
|
|
1900
|
+
let { value: t } = r4;
|
|
1901
|
+
if (t == null)
|
|
1902
|
+
return false;
|
|
1903
|
+
switch (e) {
|
|
1904
|
+
case "Boolean":
|
|
1905
|
+
return typeof t == "boolean";
|
|
1906
|
+
case "Decimal":
|
|
1907
|
+
case "Integer":
|
|
1908
|
+
return typeof t == "number";
|
|
1909
|
+
case "Date":
|
|
1910
|
+
return typeof t == "string" && !!/^\d{4}(-\d{2}(-\d{2})?)?/.exec(t);
|
|
1911
|
+
case "DateTime":
|
|
1912
|
+
return typeof t == "string" && !!/^\d{4}(-\d{2}(-\d{2})?)?T/.exec(t);
|
|
1913
|
+
case "Time":
|
|
1914
|
+
return typeof t == "string" && !!/^T\d/.exec(t);
|
|
1915
|
+
case "Period":
|
|
1916
|
+
return Vn(t);
|
|
1917
|
+
case "Quantity":
|
|
1918
|
+
return R(t);
|
|
1919
|
+
default:
|
|
1920
|
+
return typeof t == "object" && t?.resourceType === e;
|
|
1921
|
+
}
|
|
1922
|
+
}
|
|
1923
|
+
function Vn(r4) {
|
|
1924
|
+
return !!(r4 && typeof r4 == "object" && "start" in r4);
|
|
1925
|
+
}
|
|
1926
|
+
function R(r4) {
|
|
1927
|
+
return !!(r4 && typeof r4 == "object" && "value" in r4 && typeof r4.value == "number");
|
|
1928
|
+
}
|
|
1929
|
+
function ur(r4, e) {
|
|
1930
|
+
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);
|
|
1931
|
+
}
|
|
1932
|
+
function lt(r4, e) {
|
|
1933
|
+
let t = Object.keys(r4), n = Object.keys(e);
|
|
1934
|
+
if (t.length !== n.length)
|
|
1935
|
+
return false;
|
|
1936
|
+
for (let i2 of t) {
|
|
1937
|
+
let o = r4[i2], s = e[i2];
|
|
1938
|
+
if (ar(o) && ar(s)) {
|
|
1939
|
+
if (!lt(o, s))
|
|
1940
|
+
return false;
|
|
1941
|
+
} else if (o !== s)
|
|
1942
|
+
return false;
|
|
1943
|
+
}
|
|
1944
|
+
return true;
|
|
1945
|
+
}
|
|
1946
|
+
function ar(r4) {
|
|
1947
|
+
return r4 !== null && typeof r4 == "object";
|
|
1948
|
+
}
|
|
1949
|
+
var se = () => [];
|
|
1950
|
+
var b = { 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) => {
|
|
1951
|
+
for (let t of e)
|
|
1952
|
+
if (!t.value)
|
|
1953
|
+
return d(false);
|
|
1954
|
+
return d(true);
|
|
1955
|
+
}, anyTrue: (r4, e) => {
|
|
1956
|
+
for (let t of e)
|
|
1957
|
+
if (t.value)
|
|
1958
|
+
return d(true);
|
|
1959
|
+
return d(false);
|
|
1960
|
+
}, allFalse: (r4, e) => {
|
|
1961
|
+
for (let t of e)
|
|
1962
|
+
if (t.value)
|
|
1963
|
+
return d(false);
|
|
1964
|
+
return d(true);
|
|
1965
|
+
}, anyFalse: (r4, e) => {
|
|
1966
|
+
for (let t of e)
|
|
1967
|
+
if (!t.value)
|
|
1968
|
+
return d(true);
|
|
1969
|
+
return d(false);
|
|
1970
|
+
}, subsetOf: se, supersetOf: se, count: (r4, e) => [{ type: "integer", value: e.length }], distinct: (r4, e) => {
|
|
1971
|
+
let t = [];
|
|
1972
|
+
for (let n of e)
|
|
1973
|
+
t.some((i2) => i2.value === n.value) || t.push(n);
|
|
1974
|
+
return t;
|
|
1975
|
+
}, isDistinct: (r4, e) => d(e.length === b.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) => {
|
|
1976
|
+
if (e.length > 1)
|
|
1977
|
+
throw new Error("Expected input length one for single()");
|
|
1978
|
+
return e.length === 0 ? [] : e.slice(0, 1);
|
|
1979
|
+
}, first: (r4, e) => e.length === 0 ? [] : e.slice(0, 1), last: (r4, e) => e.length === 0 ? [] : e.slice(e.length - 1, e.length), tail: (r4, e) => e.length === 0 ? [] : e.slice(1, e.length), skip: (r4, e, t) => {
|
|
1980
|
+
let n = t.eval(r4, e)[0]?.value;
|
|
1981
|
+
if (typeof n != "number")
|
|
1982
|
+
throw new Error("Expected a number for skip(num)");
|
|
1983
|
+
return n >= e.length ? [] : n <= 0 ? e : e.slice(n, e.length);
|
|
1984
|
+
}, take: (r4, e, t) => {
|
|
1985
|
+
let n = t.eval(r4, e)[0]?.value;
|
|
1986
|
+
if (typeof n != "number")
|
|
1987
|
+
throw new Error("Expected a number for take(num)");
|
|
1988
|
+
return n >= e.length ? e : n <= 0 ? [] : e.slice(0, n);
|
|
1989
|
+
}, intersect: (r4, e, t) => {
|
|
1990
|
+
if (!t)
|
|
1991
|
+
return e;
|
|
1992
|
+
let n = t.eval(r4, e), i2 = [];
|
|
1993
|
+
for (let o of e)
|
|
1994
|
+
!i2.some((s) => s.value === o.value) && n.some((s) => s.value === o.value) && i2.push(o);
|
|
1995
|
+
return i2;
|
|
1996
|
+
}, exclude: (r4, e, t) => {
|
|
1997
|
+
if (!t)
|
|
1998
|
+
return e;
|
|
1999
|
+
let n = t.eval(r4, e), i2 = [];
|
|
2000
|
+
for (let o of e)
|
|
2001
|
+
n.some((s) => s.value === o.value) || i2.push(o);
|
|
2002
|
+
return i2;
|
|
2003
|
+
}, union: (r4, e, t) => {
|
|
2004
|
+
if (!t)
|
|
2005
|
+
return e;
|
|
2006
|
+
let n = t.eval(r4, e);
|
|
2007
|
+
return Re([...e, ...n]);
|
|
2008
|
+
}, combine: (r4, e, t) => {
|
|
2009
|
+
if (!t)
|
|
2010
|
+
return e;
|
|
2011
|
+
let n = t.eval(r4, e);
|
|
2012
|
+
return [...e, ...n];
|
|
2013
|
+
}, htmlChecks: (r4, e, t) => [x(true)], iif: (r4, e, t, n, i2) => {
|
|
2014
|
+
let o = t.eval(r4, e);
|
|
2015
|
+
if (o.length > 1 || o.length === 1 && typeof o[0].value != "boolean")
|
|
2016
|
+
throw new Error("Expected criterion to evaluate to a Boolean");
|
|
2017
|
+
return _(o) ? n.eval(r4, e) : i2 ? i2.eval(r4, e) : [];
|
|
2018
|
+
}, toBoolean: (r4, e) => {
|
|
2019
|
+
if (e.length === 0)
|
|
2020
|
+
return [];
|
|
2021
|
+
let [{ value: t }] = V(e, 1);
|
|
2022
|
+
if (typeof t == "boolean")
|
|
2023
|
+
return [{ type: "boolean", value: t }];
|
|
2024
|
+
if (typeof t == "number" && (t === 0 || t === 1))
|
|
2025
|
+
return d(!!t);
|
|
2026
|
+
if (typeof t == "string") {
|
|
2027
|
+
let n = t.toLowerCase();
|
|
2028
|
+
if (["true", "t", "yes", "y", "1", "1.0"].includes(n))
|
|
2029
|
+
return d(true);
|
|
2030
|
+
if (["false", "f", "no", "n", "0", "0.0"].includes(n))
|
|
2031
|
+
return d(false);
|
|
2032
|
+
}
|
|
2033
|
+
return [];
|
|
2034
|
+
}, convertsToBoolean: (r4, e) => e.length === 0 ? [] : d(b.toBoolean(r4, e).length === 1), toInteger: (r4, e) => {
|
|
2035
|
+
if (e.length === 0)
|
|
2036
|
+
return [];
|
|
2037
|
+
let [{ value: t }] = V(e, 1);
|
|
2038
|
+
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 }] : [];
|
|
2039
|
+
}, convertsToInteger: (r4, e) => e.length === 0 ? [] : d(b.toInteger(r4, e).length === 1), toDate: (r4, e) => {
|
|
2040
|
+
if (e.length === 0)
|
|
2041
|
+
return [];
|
|
2042
|
+
let [{ value: t }] = V(e, 1);
|
|
2043
|
+
return typeof t == "string" && /^\d{4}(-\d{2}(-\d{2})?)?/.exec(t) ? [{ type: "date", value: X(t) }] : [];
|
|
2044
|
+
}, convertsToDate: (r4, e) => e.length === 0 ? [] : d(b.toDate(r4, e).length === 1), toDateTime: (r4, e) => {
|
|
2045
|
+
if (e.length === 0)
|
|
2046
|
+
return [];
|
|
2047
|
+
let [{ value: t }] = V(e, 1);
|
|
2048
|
+
return typeof t == "string" && /^\d{4}(-\d{2}(-\d{2})?)?/.exec(t) ? [{ type: "dateTime", value: X(t) }] : [];
|
|
2049
|
+
}, convertsToDateTime: (r4, e) => e.length === 0 ? [] : d(b.toDateTime(r4, e).length === 1), toDecimal: (r4, e) => {
|
|
2050
|
+
if (e.length === 0)
|
|
2051
|
+
return [];
|
|
2052
|
+
let [{ value: t }] = V(e, 1);
|
|
2053
|
+
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 }] : [];
|
|
2054
|
+
}, convertsToDecimal: (r4, e) => e.length === 0 ? [] : d(b.toDecimal(r4, e).length === 1), toQuantity: (r4, e) => {
|
|
2055
|
+
if (e.length === 0)
|
|
2056
|
+
return [];
|
|
2057
|
+
let [{ value: t }] = V(e, 1);
|
|
2058
|
+
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" } }] : [];
|
|
2059
|
+
}, convertsToQuantity: (r4, e) => e.length === 0 ? [] : d(b.toQuantity(r4, e).length === 1), toString: (r4, e) => {
|
|
2060
|
+
if (e.length === 0)
|
|
2061
|
+
return [];
|
|
2062
|
+
let [{ value: t }] = V(e, 1);
|
|
2063
|
+
return t == null ? [] : R(t) ? [{ type: "string", value: `${t.value} '${t.unit}'` }] : [{ type: "string", value: t.toString() }];
|
|
2064
|
+
}, convertsToString: (r4, e) => e.length === 0 ? [] : d(b.toString(r4, e).length === 1), toTime: (r4, e) => {
|
|
2065
|
+
if (e.length === 0)
|
|
2066
|
+
return [];
|
|
2067
|
+
let [{ value: t }] = V(e, 1);
|
|
2068
|
+
if (typeof t == "string") {
|
|
2069
|
+
let n = /^T?(\d{2}(:\d{2}(:\d{2})?)?)/.exec(t);
|
|
2070
|
+
if (n)
|
|
2071
|
+
return [{ type: "time", value: X("T" + n[1]) }];
|
|
2072
|
+
}
|
|
2073
|
+
return [];
|
|
2074
|
+
}, convertsToTime: (r4, e) => e.length === 0 ? [] : d(b.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) => {
|
|
2075
|
+
let a2 = o, c2 = s ? a2 + s : i2.length;
|
|
2076
|
+
return a2 < 0 || a2 >= i2.length ? void 0 : i2.substring(a2, c2);
|
|
2077
|
+
}, 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) => !!n.match(i2), 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) => {
|
|
2078
|
+
let o = b.toDateTime(r4, t.eval(r4, e));
|
|
2079
|
+
if (o.length === 0)
|
|
2080
|
+
throw new Error("Invalid start date");
|
|
2081
|
+
let s = b.toDateTime(r4, n.eval(r4, e));
|
|
2082
|
+
if (s.length === 0)
|
|
2083
|
+
throw new Error("Invalid end date");
|
|
2084
|
+
let a2 = i2.eval(r4, e)[0]?.value;
|
|
2085
|
+
if (a2 !== "years" && a2 !== "months" && a2 !== "days")
|
|
2086
|
+
throw new Error("Invalid units");
|
|
2087
|
+
let c2 = ge(o[0].value, s[0].value);
|
|
2088
|
+
return [{ type: "Quantity", value: { value: c2[a2], unit: a2 } }];
|
|
2089
|
+
}, is: (r4, e, t) => {
|
|
2090
|
+
let n = "";
|
|
2091
|
+
return t instanceof M ? n = t.name : t instanceof Q && (n = t.left.name + "." + t.right.name), n ? e.map((i2) => ({ type: "boolean", value: Ae(i2, n) })) : [];
|
|
2092
|
+
}, not: (r4, e) => b.toBoolean(r4, e).map((t) => ({ type: "boolean", value: !t.value })), resolve: (r4, e) => e.map((t) => {
|
|
2093
|
+
let n = t.value, i2;
|
|
2094
|
+
if (typeof n == "string")
|
|
2095
|
+
i2 = n;
|
|
2096
|
+
else if (typeof n == "object") {
|
|
2097
|
+
let o = n;
|
|
2098
|
+
if (o.resource)
|
|
2099
|
+
return x(o.resource);
|
|
2100
|
+
o.reference ? i2 = o.reference : o.type && o.identifier && (i2 = `${o.type}?identifier=${o.identifier.system}|${o.identifier.value}`);
|
|
2101
|
+
}
|
|
2102
|
+
if (i2?.includes("?")) {
|
|
2103
|
+
let [o] = i2.split("?");
|
|
2104
|
+
return { type: o, value: { resourceType: o } };
|
|
2105
|
+
}
|
|
2106
|
+
if (i2?.includes("/")) {
|
|
2107
|
+
let [o, s] = i2.split("/");
|
|
2108
|
+
return { type: o, value: { resourceType: o, id: s } };
|
|
2109
|
+
}
|
|
2110
|
+
return { type: "BackboneElement", value: void 0 };
|
|
2111
|
+
}).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) => {
|
|
2112
|
+
let n = t.eval(r4, e)[0].value;
|
|
2113
|
+
if (!n.startsWith("http://hl7.org/fhir/StructureDefinition/"))
|
|
2114
|
+
throw new Error("Expected a StructureDefinition URL");
|
|
2115
|
+
let i2 = n.replace("http://hl7.org/fhir/StructureDefinition/", "");
|
|
2116
|
+
return e.map((o) => ({ type: "boolean", value: o.value?.resourceType === i2 }));
|
|
2117
|
+
} };
|
|
2118
|
+
function P(r4, e, t, ...n) {
|
|
2119
|
+
if (t.length === 0)
|
|
2120
|
+
return [];
|
|
2121
|
+
let [{ value: i2 }] = V(t, 1);
|
|
2122
|
+
if (typeof i2 != "string")
|
|
2123
|
+
throw new Error("String function cannot be called with non-string");
|
|
2124
|
+
let o = r4(i2, ...n.map((s) => s?.eval(e, t)[0]?.value));
|
|
2125
|
+
return o === void 0 ? [] : Array.isArray(o) ? o.map(x) : [x(o)];
|
|
2126
|
+
}
|
|
2127
|
+
function O(r4, e, t, ...n) {
|
|
2128
|
+
if (t.length === 0)
|
|
2129
|
+
return [];
|
|
2130
|
+
let [{ value: i2 }] = V(t, 1), o = R(i2), s = o ? i2.value : i2;
|
|
2131
|
+
if (typeof s != "number")
|
|
2132
|
+
throw new Error("Math function cannot be called with non-number");
|
|
2133
|
+
let a2 = r4(s, ...n.map((l2) => l2.eval(e, t)[0]?.value)), c2 = o ? "Quantity" : t[0].type, p2 = o ? { ...i2, value: a2 } : a2;
|
|
2134
|
+
return [{ type: c2, value: p2 }];
|
|
2135
|
+
}
|
|
2136
|
+
function V(r4, e) {
|
|
2137
|
+
if (r4.length !== e)
|
|
2138
|
+
throw new Error(`Expected ${e} arguments`);
|
|
2139
|
+
for (let t of r4)
|
|
2140
|
+
if (t == null)
|
|
2141
|
+
throw new Error("Expected non-null argument");
|
|
2142
|
+
return r4;
|
|
2143
|
+
}
|
|
2144
|
+
var w = class {
|
|
2145
|
+
constructor(e) {
|
|
2146
|
+
this.value = e;
|
|
2147
|
+
}
|
|
2148
|
+
eval() {
|
|
2149
|
+
return [this.value];
|
|
2150
|
+
}
|
|
2151
|
+
toString() {
|
|
2152
|
+
let e = this.value.value;
|
|
2153
|
+
return typeof e == "string" ? `'${e}'` : e.toString();
|
|
2154
|
+
}
|
|
2155
|
+
};
|
|
2156
|
+
var M = class {
|
|
2157
|
+
constructor(e) {
|
|
2158
|
+
this.name = e;
|
|
2159
|
+
}
|
|
2160
|
+
eval(e, t) {
|
|
2161
|
+
if (this.name === "$this")
|
|
2162
|
+
return t;
|
|
2163
|
+
if (this.name.startsWith("%")) {
|
|
2164
|
+
let n = e.variables[this.name.slice(1)];
|
|
2165
|
+
if (!n)
|
|
2166
|
+
throw new Error(`Undefined variable ${this.name}`);
|
|
2167
|
+
return [n];
|
|
2168
|
+
}
|
|
2169
|
+
return t.flatMap((n) => this.evalValue(n)).filter((n) => n?.value !== void 0);
|
|
2170
|
+
}
|
|
2171
|
+
evalValue(e) {
|
|
2172
|
+
let t = e.value;
|
|
2173
|
+
if (!(!t || typeof t != "object"))
|
|
2174
|
+
return L(t) && t.resourceType === this.name ? e : E(e, this.name);
|
|
2175
|
+
}
|
|
2176
|
+
toString() {
|
|
2177
|
+
return this.name;
|
|
2178
|
+
}
|
|
2179
|
+
};
|
|
2180
|
+
var Pe = class {
|
|
2181
|
+
eval() {
|
|
2182
|
+
return [];
|
|
2183
|
+
}
|
|
2184
|
+
toString() {
|
|
2185
|
+
return "{}";
|
|
2186
|
+
}
|
|
2187
|
+
};
|
|
2188
|
+
var Ce = class extends be {
|
|
2189
|
+
constructor(t, n, i2) {
|
|
2190
|
+
super(t, n);
|
|
2191
|
+
this.impl = i2;
|
|
2192
|
+
}
|
|
2193
|
+
eval(t, n) {
|
|
2194
|
+
return this.impl(this.child.eval(t, n));
|
|
2195
|
+
}
|
|
2196
|
+
toString() {
|
|
2197
|
+
return this.operator + this.child.toString();
|
|
2198
|
+
}
|
|
2199
|
+
};
|
|
2200
|
+
var G = class extends j {
|
|
2201
|
+
constructor(e, t) {
|
|
2202
|
+
super("as", e, t);
|
|
2203
|
+
}
|
|
2204
|
+
eval(e, t) {
|
|
2205
|
+
return b.ofType(e, this.left.eval(e, t), this.right);
|
|
2206
|
+
}
|
|
2207
|
+
};
|
|
2208
|
+
var T = class extends j {
|
|
2209
|
+
};
|
|
2210
|
+
var A = class extends T {
|
|
2211
|
+
constructor(t, n, i2, o) {
|
|
2212
|
+
super(t, n, i2);
|
|
2213
|
+
this.impl = o;
|
|
2214
|
+
}
|
|
2215
|
+
eval(t, n) {
|
|
2216
|
+
let i2 = this.left.eval(t, n);
|
|
2217
|
+
if (i2.length !== 1)
|
|
2218
|
+
return [];
|
|
2219
|
+
let o = this.right.eval(t, n);
|
|
2220
|
+
if (o.length !== 1)
|
|
2221
|
+
return [];
|
|
2222
|
+
let s = i2[0].value, a2 = o[0].value, c2 = R(s) ? s.value : s, p2 = R(a2) ? a2.value : a2, l2 = this.impl(c2, p2);
|
|
2223
|
+
return typeof l2 == "boolean" ? d(l2) : R(s) ? [{ type: "Quantity", value: { ...s, value: l2 } }] : [x(l2)];
|
|
2224
|
+
}
|
|
2225
|
+
};
|
|
2226
|
+
var we = class extends j {
|
|
2227
|
+
constructor(e, t) {
|
|
2228
|
+
super("&", e, t);
|
|
2229
|
+
}
|
|
2230
|
+
eval(e, t) {
|
|
2231
|
+
let n = this.left.eval(e, t), i2 = this.right.eval(e, t), o = [...n, ...i2];
|
|
2232
|
+
return o.length > 0 && o.every((s) => typeof s.value == "string") ? [{ type: "string", value: o.map((s) => s.value).join("") }] : o;
|
|
2233
|
+
}
|
|
2234
|
+
};
|
|
2235
|
+
var ke = class extends T {
|
|
2236
|
+
constructor(e, t) {
|
|
2237
|
+
super("contains", e, t);
|
|
2238
|
+
}
|
|
2239
|
+
eval(e, t) {
|
|
2240
|
+
let n = this.left.eval(e, t), i2 = this.right.eval(e, t);
|
|
2241
|
+
return d(n.some((o) => o.value === i2[0].value));
|
|
2242
|
+
}
|
|
2243
|
+
};
|
|
2244
|
+
var De = class extends T {
|
|
2245
|
+
constructor(e, t) {
|
|
2246
|
+
super("in", e, t);
|
|
2247
|
+
}
|
|
2248
|
+
eval(e, t) {
|
|
2249
|
+
let n = I(this.left.eval(e, t)), i2 = this.right.eval(e, t);
|
|
2250
|
+
return n ? d(i2.some((o) => o.value === n.value)) : [];
|
|
2251
|
+
}
|
|
2252
|
+
};
|
|
2253
|
+
var Q = class extends j {
|
|
2254
|
+
constructor(e, t) {
|
|
2255
|
+
super(".", e, t);
|
|
2256
|
+
}
|
|
2257
|
+
eval(e, t) {
|
|
2258
|
+
return this.right.eval(e, this.left.eval(e, t));
|
|
2259
|
+
}
|
|
2260
|
+
toString() {
|
|
2261
|
+
return `${this.left.toString()}.${this.right.toString()}`;
|
|
2262
|
+
}
|
|
2263
|
+
};
|
|
2264
|
+
var Z = class extends j {
|
|
2265
|
+
constructor(e, t) {
|
|
2266
|
+
super("|", e, t);
|
|
2267
|
+
}
|
|
2268
|
+
eval(e, t) {
|
|
2269
|
+
let n = this.left.eval(e, t), i2 = this.right.eval(e, t);
|
|
2270
|
+
return Re([...n, ...i2]);
|
|
2271
|
+
}
|
|
2272
|
+
};
|
|
2273
|
+
var Ie = class extends T {
|
|
2274
|
+
constructor(e, t) {
|
|
2275
|
+
super("=", e, t);
|
|
2276
|
+
}
|
|
2277
|
+
eval(e, t) {
|
|
2278
|
+
let n = this.left.eval(e, t), i2 = this.right.eval(e, t);
|
|
2279
|
+
return ut(n, i2);
|
|
2280
|
+
}
|
|
2281
|
+
};
|
|
2282
|
+
var Oe = class extends T {
|
|
2283
|
+
constructor(e, t) {
|
|
2284
|
+
super("!=", e, t);
|
|
2285
|
+
}
|
|
2286
|
+
eval(e, t) {
|
|
2287
|
+
let n = this.left.eval(e, t), i2 = this.right.eval(e, t);
|
|
2288
|
+
return ct(ut(n, i2));
|
|
2289
|
+
}
|
|
2290
|
+
};
|
|
2291
|
+
var Ve = class extends T {
|
|
2292
|
+
constructor(e, t) {
|
|
2293
|
+
super("~", e, t);
|
|
2294
|
+
}
|
|
2295
|
+
eval(e, t) {
|
|
2296
|
+
let n = this.left.eval(e, t), i2 = this.right.eval(e, t);
|
|
2297
|
+
return dt(n, i2);
|
|
2298
|
+
}
|
|
2299
|
+
};
|
|
2300
|
+
var Ue = class extends T {
|
|
2301
|
+
constructor(e, t) {
|
|
2302
|
+
super("!~", e, t);
|
|
2303
|
+
}
|
|
2304
|
+
eval(e, t) {
|
|
2305
|
+
let n = this.left.eval(e, t), i2 = this.right.eval(e, t);
|
|
2306
|
+
return ct(dt(n, i2));
|
|
2307
|
+
}
|
|
2308
|
+
};
|
|
2309
|
+
var z = class extends T {
|
|
2310
|
+
constructor(e, t) {
|
|
2311
|
+
super("is", e, t);
|
|
2312
|
+
}
|
|
2313
|
+
eval(e, t) {
|
|
2314
|
+
let n = this.left.eval(e, t);
|
|
2315
|
+
if (n.length !== 1)
|
|
2316
|
+
return [];
|
|
2317
|
+
let i2 = this.right.name;
|
|
2318
|
+
return d(Ae(n[0], i2));
|
|
2319
|
+
}
|
|
2320
|
+
};
|
|
2321
|
+
var Le = class extends T {
|
|
2322
|
+
constructor(e, t) {
|
|
2323
|
+
super("and", e, t);
|
|
2324
|
+
}
|
|
2325
|
+
eval(e, t) {
|
|
2326
|
+
let n = I(this.left.eval(e, t), "boolean"), i2 = I(this.right.eval(e, t), "boolean");
|
|
2327
|
+
return n?.value === true && i2?.value === true ? d(true) : n?.value === false || i2?.value === false ? d(false) : [];
|
|
2328
|
+
}
|
|
2329
|
+
};
|
|
2330
|
+
var _e = class extends T {
|
|
2331
|
+
constructor(e, t) {
|
|
2332
|
+
super("or", e, t);
|
|
2333
|
+
}
|
|
2334
|
+
eval(e, t) {
|
|
2335
|
+
let n = I(this.left.eval(e, t), "boolean"), i2 = I(this.right.eval(e, t), "boolean");
|
|
2336
|
+
return n?.value === false && i2?.value === false ? d(false) : n?.value || i2?.value ? d(true) : [];
|
|
2337
|
+
}
|
|
2338
|
+
};
|
|
2339
|
+
var Me = class extends T {
|
|
2340
|
+
constructor(e, t) {
|
|
2341
|
+
super("xor", e, t);
|
|
2342
|
+
}
|
|
2343
|
+
eval(e, t) {
|
|
2344
|
+
let n = I(this.left.eval(e, t), "boolean"), i2 = I(this.right.eval(e, t), "boolean");
|
|
2345
|
+
return !n || !i2 ? [] : d(n.value !== i2.value);
|
|
2346
|
+
}
|
|
2347
|
+
};
|
|
2348
|
+
var Ne = class extends T {
|
|
2349
|
+
constructor(e, t) {
|
|
2350
|
+
super("implies", e, t);
|
|
2351
|
+
}
|
|
2352
|
+
eval(e, t) {
|
|
2353
|
+
let n = I(this.left.eval(e, t), "boolean"), i2 = I(this.right.eval(e, t), "boolean");
|
|
2354
|
+
return i2?.value === true || n?.value === false ? d(true) : !n || !i2 ? [] : d(false);
|
|
2355
|
+
}
|
|
2356
|
+
};
|
|
2357
|
+
var N = class {
|
|
2358
|
+
constructor(e, t) {
|
|
2359
|
+
this.name = e;
|
|
2360
|
+
this.args = t;
|
|
2361
|
+
}
|
|
2362
|
+
eval(e, t) {
|
|
2363
|
+
let n = b[this.name];
|
|
2364
|
+
if (!n)
|
|
2365
|
+
throw new Error("Unrecognized function: " + this.name);
|
|
2366
|
+
return n(e, t, ...this.args);
|
|
2367
|
+
}
|
|
2368
|
+
toString() {
|
|
2369
|
+
return `${this.name}(${this.args.map((e) => e.toString()).join(", ")})`;
|
|
2370
|
+
}
|
|
2371
|
+
};
|
|
2372
|
+
var K = class {
|
|
2373
|
+
constructor(e, t) {
|
|
2374
|
+
this.left = e;
|
|
2375
|
+
this.expr = t;
|
|
2376
|
+
}
|
|
2377
|
+
eval(e, t) {
|
|
2378
|
+
let n = this.expr.eval(e, t);
|
|
2379
|
+
if (n.length !== 1)
|
|
2380
|
+
return [];
|
|
2381
|
+
let i2 = n[0].value;
|
|
2382
|
+
if (typeof i2 != "number")
|
|
2383
|
+
throw new Error("Invalid indexer expression: should return integer}");
|
|
2384
|
+
let o = this.left.eval(e, t);
|
|
2385
|
+
return i2 in o ? [o[i2]] : [];
|
|
2386
|
+
}
|
|
2387
|
+
toString() {
|
|
2388
|
+
return `${this.left.toString()}[${this.expr.toString()}]`;
|
|
2389
|
+
}
|
|
2390
|
+
};
|
|
2391
|
+
var ce = ["!=", "!~", "<=", ">=", "{}", "->"];
|
|
2392
|
+
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 };
|
|
2393
|
+
var Un = { parse(r4) {
|
|
2394
|
+
let e = r4.consumeAndParse();
|
|
2395
|
+
if (!r4.match(")"))
|
|
2396
|
+
throw new Error("Parse error: expected `)` got `" + r4.peek()?.value + "`");
|
|
2397
|
+
return e;
|
|
2398
|
+
} };
|
|
2399
|
+
var Ln = { parse(r4, e) {
|
|
2400
|
+
let t = r4.consumeAndParse();
|
|
2401
|
+
if (!r4.match("]"))
|
|
2402
|
+
throw new Error("Parse error: expected `]`");
|
|
2403
|
+
return new K(e, t);
|
|
2404
|
+
}, precedence: f.Indexer };
|
|
2405
|
+
var _n = { parse(r4, e) {
|
|
2406
|
+
if (!(e instanceof M))
|
|
2407
|
+
throw new Error("Unexpected parentheses");
|
|
2408
|
+
let t = [];
|
|
2409
|
+
for (; !r4.match(")"); )
|
|
2410
|
+
t.push(r4.consumeAndParse()), r4.match(",");
|
|
2411
|
+
return new N(e.name, t);
|
|
2412
|
+
}, precedence: f.FunctionCall };
|
|
2413
|
+
function Mn(r4) {
|
|
2414
|
+
let e = r4.split(" "), t = parseFloat(e[0]), n = e[1];
|
|
2415
|
+
return n?.startsWith("'") && n.endsWith("'") ? n = n.substring(1, n.length - 1) : n = "{" + n + "}", { value: t, unit: n };
|
|
2416
|
+
}
|
|
2417
|
+
function ue() {
|
|
2418
|
+
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: Mn(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 M(e.value) }).registerPrefix("{}", { parse: () => new Pe() }).registerPrefix("(", Un).registerInfix("[", Ln).registerInfix("(", _n).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 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 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 De(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 Me(r4, t)).infixLeft("implies", f.Implies, (r4, e, t) => new Ne(r4, t));
|
|
2419
|
+
}
|
|
2420
|
+
var Nn = ue();
|
|
2421
|
+
var lr = ((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))(lr || {});
|
|
2422
|
+
function gr(r4) {
|
|
2423
|
+
if (typeof window < "u")
|
|
2424
|
+
return window.atob(r4);
|
|
2425
|
+
if (typeof Buffer < "u")
|
|
2426
|
+
return Buffer.from(r4, "base64").toString("binary");
|
|
2427
|
+
throw new Error("Unable to decode base64");
|
|
2428
|
+
}
|
|
2429
|
+
function xr(r4) {
|
|
2430
|
+
if (typeof window < "u")
|
|
2431
|
+
return window.btoa(r4);
|
|
2432
|
+
if (typeof Buffer < "u")
|
|
2433
|
+
return Buffer.from(r4, "binary").toString("base64");
|
|
2434
|
+
throw new Error("Unable to encode base64");
|
|
2435
|
+
}
|
|
2436
|
+
function gt() {
|
|
2437
|
+
let r4 = new Uint32Array(28);
|
|
2438
|
+
return crypto.getRandomValues(r4), Wt(r4.buffer);
|
|
2439
|
+
}
|
|
2440
|
+
async function Tr(r4) {
|
|
2441
|
+
return crypto.subtle.digest("SHA-256", new TextEncoder().encode(r4));
|
|
2442
|
+
}
|
|
2443
|
+
var Fe = class {
|
|
2444
|
+
constructor(e = 10) {
|
|
2445
|
+
this.max = e, this.cache = /* @__PURE__ */ new Map();
|
|
2446
|
+
}
|
|
2447
|
+
clear() {
|
|
2448
|
+
this.cache.clear();
|
|
2449
|
+
}
|
|
2450
|
+
get(e) {
|
|
2451
|
+
let t = this.cache.get(e);
|
|
2452
|
+
return t && (this.cache.delete(e), this.cache.set(e, t)), t;
|
|
2453
|
+
}
|
|
2454
|
+
set(e, t) {
|
|
2455
|
+
this.cache.has(e) ? this.cache.delete(e) : this.cache.size >= this.max && this.cache.delete(this.first()), this.cache.set(e, t);
|
|
2456
|
+
}
|
|
2457
|
+
delete(e) {
|
|
2458
|
+
this.cache.delete(e);
|
|
2459
|
+
}
|
|
2460
|
+
keys() {
|
|
2461
|
+
return this.cache.keys();
|
|
2462
|
+
}
|
|
2463
|
+
first() {
|
|
2464
|
+
return this.cache.keys().next().value;
|
|
2465
|
+
}
|
|
2466
|
+
};
|
|
2467
|
+
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" };
|
|
2468
|
+
var qe = class {
|
|
2469
|
+
constructor() {
|
|
2470
|
+
this.listeners = {};
|
|
2471
|
+
}
|
|
2472
|
+
addEventListener(e, t) {
|
|
2473
|
+
this.listeners[e] || (this.listeners[e] = []), this.listeners[e].push(t);
|
|
2474
|
+
}
|
|
2475
|
+
removeEventListener(e, t) {
|
|
2476
|
+
let n = this.listeners[e];
|
|
2477
|
+
if (n) {
|
|
2478
|
+
for (let i2 = 0; i2 < n.length; i2++)
|
|
2479
|
+
if (n[i2] === t) {
|
|
2480
|
+
n.splice(i2, 1);
|
|
2481
|
+
return;
|
|
2482
|
+
}
|
|
2483
|
+
}
|
|
2484
|
+
}
|
|
2485
|
+
dispatchEvent(e) {
|
|
2486
|
+
let t = this.listeners[e.type];
|
|
2487
|
+
return t && t.forEach((n) => n.call(this, e)), !e.defaultPrevented;
|
|
2488
|
+
}
|
|
2489
|
+
};
|
|
2490
|
+
function ai(r4) {
|
|
2491
|
+
let e = r4.replace(/-/g, "+").replace(/_/g, "/"), t = gr(e), n = Array.from(t).reduce((o, s) => {
|
|
2492
|
+
let a2 = ("00" + s.charCodeAt(0).toString(16)).slice(-2);
|
|
2493
|
+
return `${o}%${a2}`;
|
|
2494
|
+
}, ""), i2 = decodeURIComponent(n);
|
|
2495
|
+
return JSON.parse(i2);
|
|
2496
|
+
}
|
|
2497
|
+
function xt(r4) {
|
|
2498
|
+
let [e, t, n] = r4.split(".");
|
|
2499
|
+
return ai(t);
|
|
2500
|
+
}
|
|
2501
|
+
function Sr(r4) {
|
|
2502
|
+
try {
|
|
2503
|
+
return typeof xt(r4).login_id == "string";
|
|
2504
|
+
} catch {
|
|
2505
|
+
return false;
|
|
2506
|
+
}
|
|
2507
|
+
}
|
|
2508
|
+
var ci;
|
|
2509
|
+
var C = class {
|
|
2510
|
+
constructor(e) {
|
|
2511
|
+
this[ci] = "ReadablePromise";
|
|
2512
|
+
this.status = "pending";
|
|
2513
|
+
this.suspender = e.then((t) => (this.status = "success", this.response = t, t), (t) => {
|
|
2514
|
+
throw this.status = "error", this.error = t, t;
|
|
2515
|
+
});
|
|
2516
|
+
}
|
|
2517
|
+
isPending() {
|
|
2518
|
+
return this.status === "pending";
|
|
2519
|
+
}
|
|
2520
|
+
isOk() {
|
|
2521
|
+
return this.status === "success";
|
|
2522
|
+
}
|
|
2523
|
+
read() {
|
|
2524
|
+
switch (this.status) {
|
|
2525
|
+
case "pending":
|
|
2526
|
+
throw this.suspender;
|
|
2527
|
+
case "error":
|
|
2528
|
+
throw this.error;
|
|
2529
|
+
default:
|
|
2530
|
+
return this.response;
|
|
2531
|
+
}
|
|
2532
|
+
}
|
|
2533
|
+
then(e, t) {
|
|
2534
|
+
return this.suspender.then(e, t);
|
|
2535
|
+
}
|
|
2536
|
+
catch(e) {
|
|
2537
|
+
return this.suspender.catch(e);
|
|
2538
|
+
}
|
|
2539
|
+
finally(e) {
|
|
2540
|
+
return this.suspender.finally(e);
|
|
2541
|
+
}
|
|
2542
|
+
};
|
|
2543
|
+
ci = Symbol.toStringTag;
|
|
2544
|
+
var je = class {
|
|
2545
|
+
constructor() {
|
|
2546
|
+
this.storage = typeof localStorage < "u" ? localStorage : new Tt();
|
|
2547
|
+
}
|
|
2548
|
+
clear() {
|
|
2549
|
+
this.storage.clear();
|
|
2550
|
+
}
|
|
2551
|
+
getString(e) {
|
|
2552
|
+
return this.storage.getItem(e) ?? void 0;
|
|
2553
|
+
}
|
|
2554
|
+
setString(e, t) {
|
|
2555
|
+
t ? this.storage.setItem(e, t) : this.storage.removeItem(e);
|
|
2556
|
+
}
|
|
2557
|
+
getObject(e) {
|
|
2558
|
+
let t = this.getString(e);
|
|
2559
|
+
return t ? JSON.parse(t) : void 0;
|
|
2560
|
+
}
|
|
2561
|
+
setObject(e, t) {
|
|
2562
|
+
this.setString(e, t ? jt(t) : void 0);
|
|
2563
|
+
}
|
|
2564
|
+
};
|
|
2565
|
+
var Tt = class {
|
|
2566
|
+
constructor() {
|
|
2567
|
+
this.data = /* @__PURE__ */ new Map();
|
|
2568
|
+
}
|
|
2569
|
+
get length() {
|
|
2570
|
+
return this.data.size;
|
|
2571
|
+
}
|
|
2572
|
+
clear() {
|
|
2573
|
+
this.data.clear();
|
|
2574
|
+
}
|
|
2575
|
+
getItem(e) {
|
|
2576
|
+
return this.data.get(e) ?? null;
|
|
2577
|
+
}
|
|
2578
|
+
setItem(e, t) {
|
|
2579
|
+
t ? this.data.set(e, t) : this.data.delete(e);
|
|
2580
|
+
}
|
|
2581
|
+
removeItem(e) {
|
|
2582
|
+
this.data.delete(e);
|
|
2583
|
+
}
|
|
2584
|
+
key(e) {
|
|
2585
|
+
return Array.from(this.data.keys())[e];
|
|
2586
|
+
}
|
|
2587
|
+
};
|
|
2588
|
+
var ui = "https://api.medplum.com/";
|
|
2589
|
+
var di = 1e3;
|
|
2590
|
+
var li = 6e4;
|
|
2591
|
+
var Rr = { resourceType: "Device", id: "system", deviceName: [{ name: "System" }] };
|
|
2592
|
+
var pi = ((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))(pi || {});
|
|
2593
|
+
var fi = ((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))(fi || {});
|
|
2594
|
+
var Ar = class extends qe {
|
|
2595
|
+
constructor(t) {
|
|
2596
|
+
super();
|
|
2597
|
+
if (t?.baseUrl && !t.baseUrl.startsWith("http"))
|
|
2598
|
+
throw new Error("Base URL must start with http or https");
|
|
2599
|
+
this.fetch = t?.fetch ?? mi(), this.storage = t?.storage ?? new je(), this.createPdfImpl = t?.createPdf, this.baseUrl = Pr(t?.baseUrl) ?? ui, this.fhirBaseUrl = this.baseUrl + (Pr(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 ?? li, this.cacheTime > 0 ? this.requestCache = new Fe(t?.resourceCacheSize ?? di) : this.requestCache = void 0, t?.autoBatchTime ? (this.autoBatchTime = t.autoBatchTime, this.autoBatchQueue = []) : (this.autoBatchTime = 0, this.autoBatchQueue = void 0);
|
|
2600
|
+
let n = this.getActiveLogin();
|
|
2601
|
+
n && (this.setAccessToken(n.accessToken, n.refreshToken), this.refreshProfile().catch(console.log)), this.setupStorageListener();
|
|
2602
|
+
}
|
|
2603
|
+
getBaseUrl() {
|
|
2604
|
+
return this.baseUrl;
|
|
2605
|
+
}
|
|
2606
|
+
getAuthorizeUrl() {
|
|
2607
|
+
return this.authorizeUrl;
|
|
2608
|
+
}
|
|
2609
|
+
clear() {
|
|
2610
|
+
this.storage.clear(), this.clearActiveLogin();
|
|
2611
|
+
}
|
|
2612
|
+
clearActiveLogin() {
|
|
2613
|
+
this.storage.setString("activeLogin", void 0), this.requestCache?.clear(), this.accessToken = void 0, this.refreshToken = void 0, this.sessionDetails = void 0, this.medplumServer = void 0, this.dispatchEvent({ type: "change" });
|
|
2614
|
+
}
|
|
2615
|
+
invalidateUrl(t) {
|
|
2616
|
+
t = t.toString(), this.requestCache?.delete(t);
|
|
2617
|
+
}
|
|
2618
|
+
invalidateAll() {
|
|
2619
|
+
this.requestCache?.clear();
|
|
2620
|
+
}
|
|
2621
|
+
invalidateSearches(t) {
|
|
2622
|
+
let n = this.fhirBaseUrl + t;
|
|
2623
|
+
if (this.requestCache)
|
|
2624
|
+
for (let i2 of this.requestCache.keys())
|
|
2625
|
+
(i2.endsWith(n) || i2.includes(n + "?")) && this.requestCache.delete(i2);
|
|
2626
|
+
}
|
|
2627
|
+
get(t, n = {}) {
|
|
2628
|
+
t = t.toString();
|
|
2629
|
+
let i2 = this.getCacheEntry(t, n);
|
|
2630
|
+
if (i2)
|
|
2631
|
+
return i2.value;
|
|
2632
|
+
let o;
|
|
2633
|
+
t.startsWith(this.fhirBaseUrl) && this.autoBatchQueue ? o = new Promise((a2, c2) => {
|
|
2634
|
+
this.autoBatchQueue.push({ method: "GET", url: t.replace(this.fhirBaseUrl, ""), options: n, resolve: a2, reject: c2 }), this.autoBatchTimerId || (this.autoBatchTimerId = setTimeout(() => this.executeAutoBatch(), this.autoBatchTime));
|
|
2635
|
+
}) : o = this.request("GET", t, n);
|
|
2636
|
+
let s = new C(o);
|
|
2637
|
+
return this.setCacheEntry(t, s), s;
|
|
2638
|
+
}
|
|
2639
|
+
post(t, n, i2, o = {}) {
|
|
2640
|
+
return t = t.toString(), n && this.setRequestBody(o, n), i2 && this.setRequestContentType(o, i2), this.invalidateUrl(t), this.request("POST", t, o);
|
|
2641
|
+
}
|
|
2642
|
+
put(t, n, i2, o = {}) {
|
|
2643
|
+
return t = t.toString(), n && this.setRequestBody(o, n), i2 && this.setRequestContentType(o, i2), this.invalidateUrl(t), this.request("PUT", t, o);
|
|
2644
|
+
}
|
|
2645
|
+
patch(t, n, i2 = {}) {
|
|
2646
|
+
return t = t.toString(), this.setRequestBody(i2, n), this.setRequestContentType(i2, J.JSON_PATCH), this.invalidateUrl(t), this.request("PATCH", t, i2);
|
|
2647
|
+
}
|
|
2648
|
+
delete(t, n) {
|
|
2649
|
+
return t = t.toString(), this.invalidateUrl(t), this.request("DELETE", t, n);
|
|
2650
|
+
}
|
|
2651
|
+
async startNewUser(t, n) {
|
|
2652
|
+
let { codeChallengeMethod: i2, codeChallenge: o } = await this.startPkce();
|
|
2653
|
+
return this.post("auth/newuser", { ...t, clientId: t.clientId ?? this.clientId, codeChallengeMethod: i2, codeChallenge: o }, void 0, n);
|
|
2654
|
+
}
|
|
2655
|
+
async startNewProject(t, n) {
|
|
2656
|
+
return this.post("auth/newproject", t, void 0, n);
|
|
2657
|
+
}
|
|
2658
|
+
async startNewPatient(t, n) {
|
|
2659
|
+
return this.post("auth/newpatient", t, void 0, n);
|
|
2660
|
+
}
|
|
2661
|
+
async startLogin(t, n) {
|
|
2662
|
+
return this.post("auth/login", { ...await this.ensureCodeChallenge(t), clientId: t.clientId ?? this.clientId, scope: t.scope }, void 0, n);
|
|
2663
|
+
}
|
|
2664
|
+
async startGoogleLogin(t, n) {
|
|
2665
|
+
return this.post("auth/google", { ...await this.ensureCodeChallenge(t), clientId: t.clientId ?? this.clientId, scope: t.scope }, void 0, n);
|
|
2666
|
+
}
|
|
2667
|
+
async ensureCodeChallenge(t) {
|
|
2668
|
+
return t.codeChallenge ? t : { ...t, ...await this.startPkce() };
|
|
2669
|
+
}
|
|
2670
|
+
async signOut() {
|
|
2671
|
+
await this.post(this.logoutUrl, {}), this.clear();
|
|
2672
|
+
}
|
|
2673
|
+
async signInWithRedirect(t) {
|
|
2674
|
+
let i2 = new URLSearchParams(window.location.search).get("code");
|
|
2675
|
+
if (i2)
|
|
2676
|
+
return this.processCode(i2);
|
|
2677
|
+
await this.requestAuthorization(t);
|
|
2678
|
+
}
|
|
2679
|
+
signOutWithRedirect() {
|
|
2680
|
+
window.location.assign(this.logoutUrl);
|
|
2681
|
+
}
|
|
2682
|
+
async signInWithExternalAuth(t, n, i2, o) {
|
|
2683
|
+
let s = await this.ensureCodeChallenge(o);
|
|
2684
|
+
window.location.assign(this.getExternalAuthRedirectUri(t, n, i2, s));
|
|
2685
|
+
}
|
|
2686
|
+
async exchangeExternalAccessToken(t, n) {
|
|
2687
|
+
if (n = n ?? this.clientId, !n)
|
|
2688
|
+
throw new Error("MedplumClient is missing clientId");
|
|
2689
|
+
let i2 = new URLSearchParams();
|
|
2690
|
+
return i2.set("grant_type", "urn:ietf:params:oauth:grant-type:token-exchange"), i2.set("subject_token_type", "urn:ietf:params:oauth:token-type:access_token"), i2.set("client_id", n), i2.set("subject_token", t), this.fetchTokens(i2);
|
|
2691
|
+
}
|
|
2692
|
+
getExternalAuthRedirectUri(t, n, i2, o) {
|
|
2693
|
+
let s = new URL(t);
|
|
2694
|
+
return s.searchParams.set("response_type", "code"), s.searchParams.set("client_id", n), s.searchParams.set("redirect_uri", i2), s.searchParams.set("scope", "openid profile email"), s.searchParams.set("state", JSON.stringify(o)), s.toString();
|
|
2695
|
+
}
|
|
2696
|
+
fhirUrl(...t) {
|
|
2697
|
+
return new URL(this.fhirBaseUrl + t.join("/"));
|
|
2698
|
+
}
|
|
2699
|
+
fhirSearchUrl(t, n) {
|
|
2700
|
+
let i2 = this.fhirUrl(t);
|
|
2701
|
+
return n && (i2.search = new URLSearchParams(n).toString()), i2;
|
|
2702
|
+
}
|
|
2703
|
+
search(t, n, i2) {
|
|
2704
|
+
let o = this.fhirSearchUrl(t, n), s = o.toString() + "-search", a2 = this.getCacheEntry(s, i2);
|
|
2705
|
+
if (a2)
|
|
2706
|
+
return a2.value;
|
|
2707
|
+
let c2 = new C((async () => {
|
|
2708
|
+
let p2 = await this.get(o, i2);
|
|
2709
|
+
if (p2.entry)
|
|
2710
|
+
for (let l2 of p2.entry)
|
|
2711
|
+
this.cacheResource(l2.resource);
|
|
2712
|
+
return p2;
|
|
2713
|
+
})());
|
|
2714
|
+
return this.setCacheEntry(s, c2), c2;
|
|
2715
|
+
}
|
|
2716
|
+
searchOne(t, n, i2) {
|
|
2717
|
+
let o = this.fhirSearchUrl(t, n);
|
|
2718
|
+
o.searchParams.set("_count", "1"), o.searchParams.sort();
|
|
2719
|
+
let s = o.toString() + "-searchOne", a2 = this.getCacheEntry(s, i2);
|
|
2720
|
+
if (a2)
|
|
2721
|
+
return a2.value;
|
|
2722
|
+
let c2 = new C(this.search(t, o.searchParams, i2).then((p2) => p2.entry?.[0]?.resource));
|
|
2723
|
+
return this.setCacheEntry(s, c2), c2;
|
|
2724
|
+
}
|
|
2725
|
+
searchResources(t, n, i2) {
|
|
2726
|
+
let s = this.fhirSearchUrl(t, n).toString() + "-searchResources", a2 = this.getCacheEntry(s, i2);
|
|
2727
|
+
if (a2)
|
|
2728
|
+
return a2.value;
|
|
2729
|
+
let c2 = new C(this.search(t, n, i2).then(wr));
|
|
2730
|
+
return this.setCacheEntry(s, c2), c2;
|
|
2731
|
+
}
|
|
2732
|
+
async *searchResourcePages(t, n, i2) {
|
|
2733
|
+
let o = this.fhirSearchUrl(t, n);
|
|
2734
|
+
for (; o; ) {
|
|
2735
|
+
let s = new URL(o).searchParams, a2 = await this.search(t, s, i2), c2 = a2.link?.find((p2) => p2.relation === "next");
|
|
2736
|
+
if (!a2.entry?.length && !c2)
|
|
2737
|
+
break;
|
|
2738
|
+
yield wr(a2), o = c2?.url ? new URL(c2.url) : void 0;
|
|
2739
|
+
}
|
|
2740
|
+
}
|
|
2741
|
+
searchValueSet(t, n, i2) {
|
|
2742
|
+
let o = this.fhirUrl("ValueSet", "$expand");
|
|
2743
|
+
return o.searchParams.set("url", t), o.searchParams.set("filter", n), this.get(o.toString(), i2);
|
|
2744
|
+
}
|
|
2745
|
+
getCached(t, n) {
|
|
2746
|
+
let i2 = this.requestCache?.get(this.fhirUrl(t, n).toString())?.value;
|
|
2747
|
+
return i2?.isOk() ? i2.read() : void 0;
|
|
2748
|
+
}
|
|
2749
|
+
getCachedReference(t) {
|
|
2750
|
+
let n = t.reference;
|
|
2751
|
+
if (!n)
|
|
2752
|
+
return;
|
|
2753
|
+
if (n === "system")
|
|
2754
|
+
return Rr;
|
|
2755
|
+
let [i2, o] = n.split("/");
|
|
2756
|
+
if (!(!i2 || !o))
|
|
2757
|
+
return this.getCached(i2, o);
|
|
2758
|
+
}
|
|
2759
|
+
readResource(t, n, i2) {
|
|
2760
|
+
return this.get(this.fhirUrl(t, n), i2);
|
|
2761
|
+
}
|
|
2762
|
+
readReference(t, n) {
|
|
2763
|
+
let i2 = t.reference;
|
|
2764
|
+
if (!i2)
|
|
2765
|
+
return new C(Promise.reject(new Error("Missing reference")));
|
|
2766
|
+
if (i2 === "system")
|
|
2767
|
+
return new C(Promise.resolve(Rr));
|
|
2768
|
+
let [o, s] = i2.split("/");
|
|
2769
|
+
return !o || !s ? new C(Promise.reject(new Error("Invalid reference"))) : this.readResource(o, s, n);
|
|
2770
|
+
}
|
|
2771
|
+
getSchema() {
|
|
2772
|
+
return y;
|
|
2773
|
+
}
|
|
2774
|
+
requestSchema(t) {
|
|
2775
|
+
if (t in y.types)
|
|
2776
|
+
return Promise.resolve(y);
|
|
2777
|
+
let n = t + "-requestSchema", i2 = this.getCacheEntry(n, void 0);
|
|
2778
|
+
if (i2)
|
|
2779
|
+
return i2.value;
|
|
2780
|
+
let o = new C((async () => {
|
|
2781
|
+
let s = `{
|
|
2782
|
+
StructureDefinitionList(name: "${t}") {
|
|
2783
|
+
name,
|
|
2784
|
+
description,
|
|
2785
|
+
snapshot {
|
|
2786
|
+
element {
|
|
2787
|
+
id,
|
|
2788
|
+
path,
|
|
2789
|
+
min,
|
|
2790
|
+
max,
|
|
2791
|
+
type {
|
|
2792
|
+
code,
|
|
2793
|
+
targetProfile
|
|
2794
|
+
},
|
|
2795
|
+
binding {
|
|
2796
|
+
valueSet
|
|
2797
|
+
},
|
|
2798
|
+
definition
|
|
2799
|
+
}
|
|
2800
|
+
}
|
|
2801
|
+
}
|
|
2802
|
+
SearchParameterList(base: "${t}", _count: 100) {
|
|
2803
|
+
base,
|
|
2804
|
+
code,
|
|
2805
|
+
type,
|
|
2806
|
+
expression,
|
|
2807
|
+
target
|
|
2808
|
+
}
|
|
2809
|
+
}`.replace(/\s+/g, " "), a2 = await this.graphql(s);
|
|
2810
|
+
for (let c2 of a2.data.StructureDefinitionList)
|
|
2811
|
+
it(c2);
|
|
2812
|
+
for (let c2 of a2.data.SearchParameterList)
|
|
2813
|
+
ot(c2);
|
|
2814
|
+
return y;
|
|
2815
|
+
})());
|
|
2816
|
+
return this.setCacheEntry(n, o), o;
|
|
2817
|
+
}
|
|
2818
|
+
readHistory(t, n, i2) {
|
|
2819
|
+
return this.get(this.fhirUrl(t, n, "_history"), i2);
|
|
2820
|
+
}
|
|
2821
|
+
readVersion(t, n, i2, o) {
|
|
2822
|
+
return this.get(this.fhirUrl(t, n, "_history", i2), o);
|
|
2823
|
+
}
|
|
2824
|
+
readPatientEverything(t, n) {
|
|
2825
|
+
return this.get(this.fhirUrl("Patient", t, "$everything"), n);
|
|
2826
|
+
}
|
|
2827
|
+
createResource(t, n) {
|
|
2828
|
+
if (!t.resourceType)
|
|
2829
|
+
throw new Error("Missing resourceType");
|
|
2830
|
+
return this.invalidateSearches(t.resourceType), this.post(this.fhirUrl(t.resourceType), t, void 0, n);
|
|
2831
|
+
}
|
|
2832
|
+
async createResourceIfNoneExist(t, n, i2) {
|
|
2833
|
+
return await this.searchOne(t.resourceType, n, i2) ?? this.createResource(t, i2);
|
|
2834
|
+
}
|
|
2835
|
+
async createAttachment(t, n, i2, o) {
|
|
2836
|
+
let s = await this.createBinary(t, n, i2, o);
|
|
2837
|
+
return { contentType: i2, url: s.url, title: n };
|
|
2838
|
+
}
|
|
2839
|
+
createBinary(t, n, i2, o) {
|
|
2840
|
+
let s = this.fhirUrl("Binary");
|
|
2841
|
+
return n && s.searchParams.set("_filename", n), o ? this.uploadwithProgress(s, t, i2, o) : this.post(s, t, i2);
|
|
2842
|
+
}
|
|
2843
|
+
uploadwithProgress(t, n, i2, o) {
|
|
2844
|
+
return new Promise((s, a2) => {
|
|
2845
|
+
let c2 = new XMLHttpRequest();
|
|
2846
|
+
c2.responseType = "json", c2.onabort = () => a2(new Error("Request aborted")), c2.onerror = () => a2(new Error("Request error")), o && (c2.upload.onprogress = (p2) => o(p2), c2.upload.onload = (p2) => o(p2)), c2.onload = () => {
|
|
2847
|
+
c2.status >= 200 && c2.status < 300 ? s(c2.response) : a2(new Error(c2.statusText));
|
|
2848
|
+
}, c2.open("POST", t), c2.withCredentials = true, c2.setRequestHeader("Authorization", "Bearer " + this.accessToken), c2.setRequestHeader("Cache-Control", "no-cache, no-store, max-age=0"), c2.setRequestHeader("Content-Type", i2), c2.setRequestHeader("X-Medplum", "extended"), c2.send(n);
|
|
2849
|
+
});
|
|
2850
|
+
}
|
|
2851
|
+
async createPdf(t, n, i2, o) {
|
|
2852
|
+
if (!this.createPdfImpl)
|
|
2853
|
+
throw new Error("PDF creation not enabled");
|
|
2854
|
+
let s = await this.createPdfImpl(t, i2, o);
|
|
2855
|
+
return this.createBinary(s, n, "application/pdf");
|
|
2856
|
+
}
|
|
2857
|
+
createComment(t, n, i2) {
|
|
2858
|
+
let o = this.getProfile(), s, a2;
|
|
2859
|
+
return t.resourceType === "Encounter" && (s = ne(t), a2 = t.subject), t.resourceType === "ServiceRequest" && (s = t.encounter, a2 = t.subject), t.resourceType === "Patient" && (a2 = ne(t)), this.createResource({ resourceType: "Communication", basedOn: [ne(t)], encounter: s, subject: a2, sender: o ? ne(o) : void 0, sent: (/* @__PURE__ */ new Date()).toISOString(), payload: [{ contentString: n }] }, i2);
|
|
2860
|
+
}
|
|
2861
|
+
async updateResource(t, n) {
|
|
2862
|
+
if (!t.resourceType)
|
|
2863
|
+
throw new Error("Missing resourceType");
|
|
2864
|
+
if (!t.id)
|
|
2865
|
+
throw new Error("Missing id");
|
|
2866
|
+
this.invalidateSearches(t.resourceType);
|
|
2867
|
+
let i2 = await this.put(this.fhirUrl(t.resourceType, t.id), t, void 0, n);
|
|
2868
|
+
return i2 || (i2 = t), this.cacheResource(i2), i2;
|
|
2869
|
+
}
|
|
2870
|
+
patchResource(t, n, i2, o) {
|
|
2871
|
+
return this.invalidateSearches(t), this.patch(this.fhirUrl(t, n), i2, o);
|
|
2872
|
+
}
|
|
2873
|
+
deleteResource(t, n, i2) {
|
|
2874
|
+
return this.deleteCacheEntry(this.fhirUrl(t, n).toString()), this.invalidateSearches(t), this.delete(this.fhirUrl(t, n), i2);
|
|
2875
|
+
}
|
|
2876
|
+
validateResource(t, n) {
|
|
2877
|
+
return this.post(this.fhirUrl(t.resourceType, "$validate"), t, void 0, n);
|
|
2878
|
+
}
|
|
2879
|
+
executeBot(t, n, i2, o) {
|
|
2880
|
+
let s;
|
|
2881
|
+
if (typeof t == "string") {
|
|
2882
|
+
let a2 = t;
|
|
2883
|
+
s = this.fhirUrl("Bot", a2, "$execute");
|
|
2884
|
+
} else {
|
|
2885
|
+
let a2 = t;
|
|
2886
|
+
s = this.fhirUrl("Bot", "$execute") + `?identifier=${a2.system}|${a2.value}`;
|
|
2887
|
+
}
|
|
2888
|
+
return this.post(s, n, i2, o);
|
|
2889
|
+
}
|
|
2890
|
+
executeBatch(t, n) {
|
|
2891
|
+
return this.post(this.fhirBaseUrl.slice(0, -1), t, void 0, n);
|
|
2892
|
+
}
|
|
2893
|
+
sendEmail(t, n) {
|
|
2894
|
+
return this.post("email/v1/send", t, J.JSON, n);
|
|
2895
|
+
}
|
|
2896
|
+
graphql(t, n, i2, o) {
|
|
2897
|
+
return this.post(this.fhirUrl("$graphql"), { query: t, operationName: n, variables: i2 }, J.JSON, o);
|
|
2898
|
+
}
|
|
2899
|
+
readResourceGraph(t, n, i2, o) {
|
|
2900
|
+
return this.get(`${this.fhirUrl(t, n)}/$graph?graph=${i2}`, o);
|
|
2901
|
+
}
|
|
2902
|
+
getActiveLogin() {
|
|
2903
|
+
return this.storage.getObject("activeLogin");
|
|
2904
|
+
}
|
|
2905
|
+
async setActiveLogin(t) {
|
|
2906
|
+
this.clearActiveLogin(), this.setAccessToken(t.accessToken, t.refreshToken), this.storage.setObject("activeLogin", t), this.addLogin(t), this.refreshPromise = void 0, await this.refreshProfile();
|
|
2907
|
+
}
|
|
2908
|
+
getAccessToken() {
|
|
2909
|
+
return this.accessToken;
|
|
2910
|
+
}
|
|
2911
|
+
setAccessToken(t, n) {
|
|
2912
|
+
this.accessToken = t, this.refreshToken = n, this.sessionDetails = void 0, this.medplumServer = Sr(t);
|
|
2913
|
+
}
|
|
2914
|
+
getLogins() {
|
|
2915
|
+
return this.storage.getObject("logins") ?? [];
|
|
2916
|
+
}
|
|
2917
|
+
addLogin(t) {
|
|
2918
|
+
let n = this.getLogins().filter((i2) => i2.profile?.reference !== t.profile?.reference);
|
|
2919
|
+
n.push(t), this.storage.setObject("logins", n);
|
|
2920
|
+
}
|
|
2921
|
+
async refreshProfile() {
|
|
2922
|
+
return this.medplumServer ? (this.profilePromise = new Promise((t, n) => {
|
|
2923
|
+
this.get("auth/me").then((i2) => {
|
|
2924
|
+
this.profilePromise = void 0, this.sessionDetails = i2, this.dispatchEvent({ type: "change" }), t(i2.profile);
|
|
2925
|
+
}).catch(n);
|
|
2926
|
+
}), this.profilePromise) : Promise.resolve(void 0);
|
|
2927
|
+
}
|
|
2928
|
+
isLoading() {
|
|
2929
|
+
return !!this.profilePromise;
|
|
2930
|
+
}
|
|
2931
|
+
isSuperAdmin() {
|
|
2932
|
+
return !!this.sessionDetails?.project.superAdmin;
|
|
2933
|
+
}
|
|
2934
|
+
isProjectAdmin() {
|
|
2935
|
+
return !!this.sessionDetails?.membership.admin;
|
|
2936
|
+
}
|
|
2937
|
+
getProject() {
|
|
2938
|
+
return this.sessionDetails?.project;
|
|
2939
|
+
}
|
|
2940
|
+
getProjectMembership() {
|
|
2941
|
+
return this.sessionDetails?.membership;
|
|
2942
|
+
}
|
|
2943
|
+
getProfile() {
|
|
2944
|
+
return this.sessionDetails?.profile;
|
|
2945
|
+
}
|
|
2946
|
+
async getProfileAsync() {
|
|
2947
|
+
return this.profilePromise && await this.profilePromise, this.getProfile();
|
|
2948
|
+
}
|
|
2949
|
+
getUserConfiguration() {
|
|
2950
|
+
return this.sessionDetails?.config;
|
|
2951
|
+
}
|
|
2952
|
+
getAccessPolicy() {
|
|
2953
|
+
return this.sessionDetails?.accessPolicy;
|
|
2954
|
+
}
|
|
2955
|
+
async download(t, n = {}) {
|
|
2956
|
+
return this.refreshPromise && await this.refreshPromise, this.addFetchOptionsDefaults(n), (await this.fetch(t.toString(), n)).blob();
|
|
2957
|
+
}
|
|
2958
|
+
async uploadMedia(t, n, i2, o, s) {
|
|
2959
|
+
let a2 = await this.createBinary(t, i2, n);
|
|
2960
|
+
return this.createResource({ ...o, resourceType: "Media", content: { contentType: n, url: "Binary/" + a2.id, title: i2 } }, s);
|
|
2961
|
+
}
|
|
2962
|
+
async bulkExport(t = "", n, i2, o) {
|
|
2963
|
+
let s = t && `${t}/`, a2 = this.fhirUrl(`${s}$export`);
|
|
2964
|
+
return n && a2.searchParams.set("_type", n), i2 && a2.searchParams.set("_since", i2), this.startAsyncRequest(a2.toString(), o);
|
|
2965
|
+
}
|
|
2966
|
+
async startAsyncRequest(t, n = {}) {
|
|
2967
|
+
this.addFetchOptionsDefaults(n);
|
|
2968
|
+
let i2 = n.headers;
|
|
2969
|
+
i2.Prefer = "respond-async";
|
|
2970
|
+
let o = await this.fetchWithRetry(t, n);
|
|
2971
|
+
if (o.status === 202) {
|
|
2972
|
+
let s = await Cr(o);
|
|
2973
|
+
if (s)
|
|
2974
|
+
return this.pollStatus(s);
|
|
2975
|
+
}
|
|
2976
|
+
return this.parseResponse(o, "POST", t);
|
|
2977
|
+
}
|
|
2978
|
+
getCacheEntry(t, n) {
|
|
2979
|
+
if (!this.requestCache || n?.cache === "no-cache" || n?.cache === "reload")
|
|
2980
|
+
return;
|
|
2981
|
+
let i2 = this.requestCache.get(t);
|
|
2982
|
+
if (!(!i2 || i2.requestTime + this.cacheTime < Date.now()))
|
|
2983
|
+
return i2;
|
|
2984
|
+
}
|
|
2985
|
+
setCacheEntry(t, n) {
|
|
2986
|
+
this.requestCache && this.requestCache.set(t, { requestTime: Date.now(), value: n });
|
|
2987
|
+
}
|
|
2988
|
+
cacheResource(t) {
|
|
2989
|
+
t?.id && this.setCacheEntry(this.fhirUrl(t.resourceType, t.id).toString(), new C(Promise.resolve(t)));
|
|
2990
|
+
}
|
|
2991
|
+
deleteCacheEntry(t) {
|
|
2992
|
+
this.requestCache && this.requestCache.delete(t);
|
|
2993
|
+
}
|
|
2994
|
+
async request(t, n, i2 = {}) {
|
|
2995
|
+
this.refreshPromise && await this.refreshPromise, i2.method = t, this.addFetchOptionsDefaults(i2);
|
|
2996
|
+
let o = await this.fetchWithRetry(n, i2);
|
|
2997
|
+
return this.parseResponse(o, t, n, i2);
|
|
2998
|
+
}
|
|
2999
|
+
async parseResponse(t, n, i2, o = {}) {
|
|
3000
|
+
if (t.status === 401)
|
|
3001
|
+
return this.handleUnauthenticated(n, i2, o);
|
|
3002
|
+
if (t.status === 204 || t.status === 304)
|
|
3003
|
+
return;
|
|
3004
|
+
let a2 = t.headers.get("content-type")?.includes("json");
|
|
3005
|
+
if (t.status === 404 && !a2)
|
|
3006
|
+
throw new m(Ot);
|
|
3007
|
+
let c2;
|
|
3008
|
+
if (a2)
|
|
3009
|
+
try {
|
|
3010
|
+
c2 = await t.json();
|
|
3011
|
+
} catch (p2) {
|
|
3012
|
+
throw console.error("Error parsing response", t.status, p2), p2;
|
|
3013
|
+
}
|
|
3014
|
+
else
|
|
3015
|
+
c2 = await t.text();
|
|
3016
|
+
if (t.status >= 400)
|
|
3017
|
+
throw new m(Ze(c2));
|
|
3018
|
+
return c2;
|
|
3019
|
+
}
|
|
3020
|
+
async fetchWithRetry(t, n) {
|
|
3021
|
+
t.startsWith("http") || (t = new URL(t, this.baseUrl).href);
|
|
3022
|
+
let i2 = 3, o = 200, s;
|
|
3023
|
+
for (let a2 = 0; a2 < i2; a2++) {
|
|
3024
|
+
try {
|
|
3025
|
+
if (s = await this.fetch(t, n), s.status < 500)
|
|
3026
|
+
return s;
|
|
3027
|
+
} catch (c2) {
|
|
3028
|
+
this.retryCatch(a2, i2, c2);
|
|
3029
|
+
}
|
|
3030
|
+
await nt(o);
|
|
3031
|
+
}
|
|
3032
|
+
return s;
|
|
3033
|
+
}
|
|
3034
|
+
async pollStatus(t) {
|
|
3035
|
+
let n = true, i2, o = 2e3;
|
|
3036
|
+
for (; n; ) {
|
|
3037
|
+
let s = {};
|
|
3038
|
+
this.addFetchOptionsDefaults(s);
|
|
3039
|
+
let a2 = await this.fetchWithRetry(t, s);
|
|
3040
|
+
if (a2.status !== 202 && (n = false, i2 = a2, a2.status === 201)) {
|
|
3041
|
+
let c2 = await Cr(a2);
|
|
3042
|
+
c2 && (i2 = await this.fetchWithRetry(c2, s));
|
|
3043
|
+
}
|
|
3044
|
+
await nt(o);
|
|
3045
|
+
}
|
|
3046
|
+
return this.parseResponse(i2, "POST", t);
|
|
3047
|
+
}
|
|
3048
|
+
async executeAutoBatch() {
|
|
3049
|
+
let t = [...this.autoBatchQueue];
|
|
3050
|
+
if (this.autoBatchQueue.length = 0, this.autoBatchTimerId = void 0, t.length === 1) {
|
|
3051
|
+
let o = t[0];
|
|
3052
|
+
try {
|
|
3053
|
+
o.resolve(await this.request(o.method, this.fhirBaseUrl + o.url, o.options));
|
|
3054
|
+
} catch (s) {
|
|
3055
|
+
o.reject(new m(Ze(s)));
|
|
3056
|
+
}
|
|
3057
|
+
return;
|
|
3058
|
+
}
|
|
3059
|
+
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);
|
|
3060
|
+
for (let o = 0; o < t.length; o++) {
|
|
3061
|
+
let s = t[o], a2 = i2.entry?.[o];
|
|
3062
|
+
a2?.response?.outcome && !Xe(a2.response.outcome) ? s.reject(new m(a2.response.outcome)) : s.resolve(a2?.resource);
|
|
3063
|
+
}
|
|
3064
|
+
}
|
|
3065
|
+
addFetchOptionsDefaults(t) {
|
|
3066
|
+
let n = t.headers;
|
|
3067
|
+
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");
|
|
3068
|
+
}
|
|
3069
|
+
setRequestContentType(t, n) {
|
|
3070
|
+
t.headers || (t.headers = {});
|
|
3071
|
+
let i2 = t.headers;
|
|
3072
|
+
i2["Content-Type"] = n;
|
|
3073
|
+
}
|
|
3074
|
+
setRequestBody(t, n) {
|
|
3075
|
+
typeof n == "string" || typeof Blob < "u" && n instanceof Blob || typeof File < "u" && n instanceof File || typeof Uint8Array < "u" && n instanceof Uint8Array ? t.body = n : n && (t.body = JSON.stringify(n));
|
|
3076
|
+
}
|
|
3077
|
+
handleUnauthenticated(t, n, i2) {
|
|
3078
|
+
return this.refresh() ? this.request(t, n, i2) : (this.clearActiveLogin(), this.onUnauthenticated && this.onUnauthenticated(), Promise.reject(new Error("Unauthenticated")));
|
|
3079
|
+
}
|
|
3080
|
+
async startPkce() {
|
|
3081
|
+
let t = gt();
|
|
3082
|
+
sessionStorage.setItem("pkceState", t);
|
|
3083
|
+
let n = gt();
|
|
3084
|
+
sessionStorage.setItem("codeVerifier", n);
|
|
3085
|
+
let i2 = await Tr(n), o = Gt(i2).replaceAll("+", "-").replaceAll("/", "_").replaceAll("=", "");
|
|
3086
|
+
return sessionStorage.setItem("codeChallenge", o), { codeChallengeMethod: "S256", codeChallenge: o };
|
|
3087
|
+
}
|
|
3088
|
+
async requestAuthorization(t) {
|
|
3089
|
+
let n = await this.ensureCodeChallenge(t ?? {}), i2 = new URL(this.authorizeUrl);
|
|
3090
|
+
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 ?? Er()), 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());
|
|
3091
|
+
}
|
|
3092
|
+
processCode(t, n) {
|
|
3093
|
+
let i2 = new URLSearchParams();
|
|
3094
|
+
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 ?? Er()), typeof sessionStorage < "u") {
|
|
3095
|
+
let o = sessionStorage.getItem("codeVerifier");
|
|
3096
|
+
o && i2.set("code_verifier", o);
|
|
3097
|
+
}
|
|
3098
|
+
return this.fetchTokens(i2);
|
|
3099
|
+
}
|
|
3100
|
+
refresh() {
|
|
3101
|
+
if (this.refreshPromise)
|
|
3102
|
+
return this.refreshPromise;
|
|
3103
|
+
if (this.refreshToken) {
|
|
3104
|
+
let t = new URLSearchParams();
|
|
3105
|
+
return t.set("grant_type", "refresh_token"), t.set("client_id", this.clientId), t.set("refresh_token", this.refreshToken), this.refreshPromise = this.fetchTokens(t), this.refreshPromise;
|
|
3106
|
+
}
|
|
3107
|
+
if (this.clientId && this.clientSecret)
|
|
3108
|
+
return this.refreshPromise = this.startClientLogin(this.clientId, this.clientSecret), this.refreshPromise;
|
|
3109
|
+
}
|
|
3110
|
+
async startClientLogin(t, n) {
|
|
3111
|
+
this.clientId = t, this.clientSecret = n;
|
|
3112
|
+
let i2 = new URLSearchParams();
|
|
3113
|
+
return i2.set("grant_type", "client_credentials"), i2.set("client_id", t), i2.set("client_secret", n), this.fetchTokens(i2);
|
|
3114
|
+
}
|
|
3115
|
+
async startJwtBearerLogin(t, n, i2) {
|
|
3116
|
+
this.clientId = t;
|
|
3117
|
+
let o = new URLSearchParams();
|
|
3118
|
+
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);
|
|
3119
|
+
}
|
|
3120
|
+
setBasicAuth(t, n) {
|
|
3121
|
+
this.clientId = t, this.clientSecret = n, this.basicAuth = xr(t + ":" + n);
|
|
3122
|
+
}
|
|
3123
|
+
async invite(t, n) {
|
|
3124
|
+
return this.post("admin/projects/" + t + "/invite", n);
|
|
3125
|
+
}
|
|
3126
|
+
async fetchTokens(t) {
|
|
3127
|
+
let n = { method: "POST", headers: { "Content-Type": J.FORM_URL_ENCODED }, body: t.toString(), credentials: "include" }, i2 = n.headers;
|
|
3128
|
+
this.basicAuth && (i2.Authorization = `Basic ${this.basicAuth}`);
|
|
3129
|
+
let o = await this.fetch(this.tokenUrl, n);
|
|
3130
|
+
if (!o.ok) {
|
|
3131
|
+
this.clearActiveLogin();
|
|
3132
|
+
try {
|
|
3133
|
+
let a2 = await o.json();
|
|
3134
|
+
throw new m(k(a2.error_description));
|
|
3135
|
+
} catch (a2) {
|
|
3136
|
+
throw new m(k("Failed to fetch tokens"), a2);
|
|
3137
|
+
}
|
|
3138
|
+
}
|
|
3139
|
+
let s = await o.json();
|
|
3140
|
+
return await this.verifyTokens(s), this.getProfile();
|
|
3141
|
+
}
|
|
3142
|
+
async verifyTokens(t) {
|
|
3143
|
+
let n = t.access_token, i2 = xt(n);
|
|
3144
|
+
if (Date.now() >= i2.exp * 1e3)
|
|
3145
|
+
throw this.clearActiveLogin(), new Error("Token expired");
|
|
3146
|
+
if (i2.cid) {
|
|
3147
|
+
if (i2.cid !== this.clientId)
|
|
3148
|
+
throw this.clearActiveLogin(), new Error("Token was not issued for this audience");
|
|
3149
|
+
} else if (this.clientId && i2.client_id !== this.clientId)
|
|
3150
|
+
throw this.clearActiveLogin(), new Error("Token was not issued for this audience");
|
|
3151
|
+
return this.setActiveLogin({ accessToken: n, refreshToken: t.refresh_token, project: t.project, profile: t.profile });
|
|
3152
|
+
}
|
|
3153
|
+
setupStorageListener() {
|
|
3154
|
+
try {
|
|
3155
|
+
window.addEventListener("storage", (t) => {
|
|
3156
|
+
(t.key === null || t.key === "activeLogin") && window.location.reload();
|
|
3157
|
+
});
|
|
3158
|
+
} catch {
|
|
3159
|
+
}
|
|
3160
|
+
}
|
|
3161
|
+
retryCatch(t, n, i2) {
|
|
3162
|
+
if (i2.message === "Failed to fetch" && t === 1 && this.dispatchEvent({ type: "offline" }), t >= n - 1)
|
|
3163
|
+
throw i2;
|
|
3164
|
+
}
|
|
3165
|
+
};
|
|
3166
|
+
function mi() {
|
|
3167
|
+
if (!globalThis.fetch)
|
|
3168
|
+
throw new Error("Fetch not available in this environment");
|
|
3169
|
+
return globalThis.fetch.bind(globalThis);
|
|
3170
|
+
}
|
|
3171
|
+
function Er() {
|
|
3172
|
+
return typeof window > "u" ? "" : window.location.protocol + "//" + window.location.host + "/";
|
|
3173
|
+
}
|
|
3174
|
+
function Pr(r4) {
|
|
3175
|
+
return r4 && (r4.endsWith("/") ? r4 : r4 + "/");
|
|
3176
|
+
}
|
|
3177
|
+
async function Cr(r4) {
|
|
3178
|
+
let e = r4.headers.get("content-location");
|
|
3179
|
+
if (e)
|
|
3180
|
+
return e;
|
|
3181
|
+
let t = r4.headers.get("location");
|
|
3182
|
+
if (t)
|
|
3183
|
+
return t;
|
|
3184
|
+
let n = await r4.json();
|
|
3185
|
+
if (ye(n) && n.issue?.[0]?.diagnostics)
|
|
3186
|
+
return n.issue[0].diagnostics;
|
|
3187
|
+
}
|
|
3188
|
+
function wr(r4) {
|
|
3189
|
+
let e = r4.entry?.map((t) => t.resource) ?? [];
|
|
3190
|
+
return Object.assign(e, { bundle: r4 });
|
|
3191
|
+
}
|
|
3192
|
+
var hi = [...ce, "->", "<<", ">>"];
|
|
3193
|
+
var yi = ue().registerInfix("->", { precedence: f.Arrow }).registerInfix(";", { precedence: f.Semicolon });
|
|
3194
|
+
var gi = [...ce, "eq", "ne", "co"];
|
|
3195
|
+
var vi = ue();
|
|
3196
|
+
var H = class {
|
|
3197
|
+
constructor(e = "\r", t = "|", n = "^", i2 = "~", o = "\\", s = "&") {
|
|
3198
|
+
this.segmentSeparator = e;
|
|
3199
|
+
this.fieldSeparator = t;
|
|
3200
|
+
this.componentSeparator = n;
|
|
3201
|
+
this.repetitionSeparator = i2;
|
|
3202
|
+
this.escapeCharacter = o;
|
|
3203
|
+
this.subcomponentSeparator = s;
|
|
3204
|
+
}
|
|
3205
|
+
getMsh1() {
|
|
3206
|
+
return this.fieldSeparator;
|
|
3207
|
+
}
|
|
3208
|
+
getMsh2() {
|
|
3209
|
+
return this.componentSeparator + this.repetitionSeparator + this.escapeCharacter + this.subcomponentSeparator;
|
|
3210
|
+
}
|
|
3211
|
+
};
|
|
3212
|
+
var Ir = class r {
|
|
3213
|
+
constructor(e, t = new H()) {
|
|
3214
|
+
this.context = t, this.segments = e;
|
|
3215
|
+
}
|
|
3216
|
+
get header() {
|
|
3217
|
+
return this.segments[0];
|
|
3218
|
+
}
|
|
3219
|
+
get(e) {
|
|
3220
|
+
return this.getSegment(e);
|
|
3221
|
+
}
|
|
3222
|
+
getAll(e) {
|
|
3223
|
+
return this.getAllSegments(e);
|
|
3224
|
+
}
|
|
3225
|
+
getSegment(e) {
|
|
3226
|
+
return typeof e == "number" ? this.segments[e] : this.segments.find((t) => t.name === e);
|
|
3227
|
+
}
|
|
3228
|
+
getAllSegments(e) {
|
|
3229
|
+
return this.segments.filter((t) => t.name === e);
|
|
3230
|
+
}
|
|
3231
|
+
toString() {
|
|
3232
|
+
return this.segments.map((e) => e.toString()).join(this.context.segmentSeparator);
|
|
3233
|
+
}
|
|
3234
|
+
buildAck() {
|
|
3235
|
+
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() ?? "", a2 = t?.getField(10)?.toString() ?? "", c2 = t?.getField(12)?.toString() ?? "2.5.1";
|
|
3236
|
+
return new r([new pe(["MSH", this.context.getMsh2(), o, s, n, i2, Si(e), "", this.buildAckMessageType(t), e.getTime().toString(), "P", c2], this.context), new pe(["MSA", "AA", a2, "OK"], this.context)]);
|
|
3237
|
+
}
|
|
3238
|
+
buildAckMessageType(e) {
|
|
3239
|
+
let t = e?.getField(9), n = t?.getComponent(2), i2 = t?.getComponent(3), o = "ACK";
|
|
3240
|
+
return n && i2 ? o = `ACK^${n}^ACK` : n && (o = `ACK^${n}`), o;
|
|
3241
|
+
}
|
|
3242
|
+
static parse(e) {
|
|
3243
|
+
if (!e.startsWith("MSH")) {
|
|
3244
|
+
let n = new Error("Invalid HL7 message");
|
|
3245
|
+
throw n.type = "entity.parse.failed", n;
|
|
3246
|
+
}
|
|
3247
|
+
let t = new H("\r", e.charAt(3), e.charAt(4), e.charAt(5), e.charAt(6), e.charAt(7));
|
|
3248
|
+
return new r(e.split(/[\r\n]+/).map((n) => pe.parse(n, t)), t);
|
|
3249
|
+
}
|
|
3250
|
+
};
|
|
3251
|
+
var pe = class r2 {
|
|
3252
|
+
constructor(e, t = new H()) {
|
|
3253
|
+
this.context = t, Qt(e) ? this.fields = e.map((n) => ee.parse(n, t)) : this.fields = e, this.name = this.fields[0].components[0][0];
|
|
3254
|
+
}
|
|
3255
|
+
get(e) {
|
|
3256
|
+
return this.fields[e];
|
|
3257
|
+
}
|
|
3258
|
+
getField(e) {
|
|
3259
|
+
if (this.name === "MSH") {
|
|
3260
|
+
if (e === 1)
|
|
3261
|
+
return new ee([[this.context.getMsh1()]], this.context);
|
|
3262
|
+
if (e === 2)
|
|
3263
|
+
return new ee([[this.context.getMsh2()]], this.context);
|
|
3264
|
+
if (e > 2)
|
|
3265
|
+
return this.fields[e - 1];
|
|
3266
|
+
}
|
|
3267
|
+
return this.fields[e];
|
|
3268
|
+
}
|
|
3269
|
+
getComponent(e, t, n, i2 = 0) {
|
|
3270
|
+
return this.getField(e)?.getComponent(t, n, i2) ?? "";
|
|
3271
|
+
}
|
|
3272
|
+
toString() {
|
|
3273
|
+
return this.fields.map((e) => e.toString()).join(this.context.fieldSeparator);
|
|
3274
|
+
}
|
|
3275
|
+
static parse(e, t = new H()) {
|
|
3276
|
+
return new r2(e.split(t.fieldSeparator).map((n) => ee.parse(n, t)), t);
|
|
3277
|
+
}
|
|
3278
|
+
};
|
|
3279
|
+
var ee = class r3 {
|
|
3280
|
+
constructor(e, t = new H()) {
|
|
3281
|
+
this.context = t, this.components = e;
|
|
3282
|
+
}
|
|
3283
|
+
get(e, t, n = 0) {
|
|
3284
|
+
return this.getComponent(e + 1, t, n);
|
|
3285
|
+
}
|
|
3286
|
+
getComponent(e, t, n = 0) {
|
|
3287
|
+
let i2 = this.components[n][e - 1] ?? "";
|
|
3288
|
+
return t !== void 0 && (i2 = i2.split(this.context.subcomponentSeparator)[t] ?? ""), i2;
|
|
3289
|
+
}
|
|
3290
|
+
toString() {
|
|
3291
|
+
return this.components.map((e) => e.join(this.context.componentSeparator)).join(this.context.repetitionSeparator);
|
|
3292
|
+
}
|
|
3293
|
+
static parse(e, t = new H()) {
|
|
3294
|
+
return new r3(e.split(t.repetitionSeparator).map((n) => n.split(t.componentSeparator)), t);
|
|
3295
|
+
}
|
|
3296
|
+
};
|
|
3297
|
+
function Si(r4) {
|
|
3298
|
+
let e = r4 instanceof Date ? r4 : new Date(r4), n = e.toISOString().replace(/[-:T]/g, "").replace(/(\.\d+)?Z$/, ""), i2 = e.getUTCMilliseconds();
|
|
3299
|
+
return i2 > 0 && (n += "." + i2.toString()), n;
|
|
3300
|
+
}
|
|
3301
|
+
|
|
3302
|
+
// ../hl7/dist/esm/index.mjs
|
|
3303
|
+
var import_net = __toESM(require("net"), 1);
|
|
3304
|
+
var p = class extends EventTarget {
|
|
3305
|
+
addEventListener(n, e, t) {
|
|
3306
|
+
super.addEventListener(n, e, t);
|
|
3307
|
+
}
|
|
3308
|
+
removeEventListener(n, e, t) {
|
|
3309
|
+
super.removeEventListener(n, e, t);
|
|
3310
|
+
}
|
|
3311
|
+
};
|
|
3312
|
+
var v2 = String.fromCharCode(11);
|
|
3313
|
+
var i = String.fromCharCode(28);
|
|
3314
|
+
var a = String.fromCharCode(13);
|
|
3315
|
+
var c = class extends Event {
|
|
3316
|
+
constructor(e, t) {
|
|
3317
|
+
super("message");
|
|
3318
|
+
this.socket = e;
|
|
3319
|
+
this.message = t;
|
|
3320
|
+
}
|
|
3321
|
+
send(e) {
|
|
3322
|
+
this.socket.write(v2 + e.toString() + i + a);
|
|
3323
|
+
}
|
|
3324
|
+
};
|
|
3325
|
+
var l = class extends Event {
|
|
3326
|
+
constructor(e) {
|
|
3327
|
+
super("error");
|
|
3328
|
+
this.error = e;
|
|
3329
|
+
}
|
|
3330
|
+
};
|
|
3331
|
+
var g = class extends p {
|
|
3332
|
+
start(e, t) {
|
|
3333
|
+
let r4 = import_net.default.createServer((o) => {
|
|
3334
|
+
let s = "";
|
|
3335
|
+
o.on("data", (f2) => {
|
|
3336
|
+
try {
|
|
3337
|
+
if (s += f2.toString(), s.endsWith(i + a)) {
|
|
3338
|
+
let h = Ir.parse(s.substring(1, s.length - 2));
|
|
3339
|
+
this.dispatchEvent(new c(o, h)), s = "";
|
|
3340
|
+
}
|
|
3341
|
+
} catch (h) {
|
|
3342
|
+
this.dispatchEvent(new l(h));
|
|
3343
|
+
}
|
|
3344
|
+
}).setEncoding(t ?? "utf-8"), o.on("error", (f2) => {
|
|
3345
|
+
s = "", this.dispatchEvent(new l(f2));
|
|
3346
|
+
});
|
|
3347
|
+
});
|
|
3348
|
+
r4.listen(e), this.server = r4;
|
|
3349
|
+
}
|
|
3350
|
+
stop() {
|
|
3351
|
+
this.server && (this.server.close(), this.server = void 0);
|
|
3352
|
+
}
|
|
3353
|
+
};
|
|
3354
|
+
|
|
3355
|
+
// src/main.ts
|
|
3356
|
+
var import_node_windows = __toESM(require_node_windows());
|
|
3357
|
+
var log = new import_node_windows.EventLogger({
|
|
3358
|
+
source: "MedplumService",
|
|
3359
|
+
eventLog: "SYSTEM"
|
|
3360
|
+
});
|
|
3361
|
+
var App = class {
|
|
3362
|
+
constructor(medplum, bot) {
|
|
3363
|
+
this.medplum = medplum;
|
|
3364
|
+
this.bot = bot;
|
|
3365
|
+
this.log = new import_node_windows.EventLogger({
|
|
3366
|
+
source: "MedplumService",
|
|
3367
|
+
eventLog: "SYSTEM"
|
|
3368
|
+
});
|
|
3369
|
+
this.server = new g();
|
|
3370
|
+
this.server.addEventListener("message", (event) => this.handler(event));
|
|
3371
|
+
}
|
|
3372
|
+
start() {
|
|
3373
|
+
this.log.info("Medplum service starting...");
|
|
3374
|
+
this.server.start(56e3);
|
|
3375
|
+
this.log.info("Medplum service started successfully");
|
|
3376
|
+
}
|
|
3377
|
+
stop() {
|
|
3378
|
+
this.log.info("Medplum service stopping...");
|
|
3379
|
+
this.server.stop();
|
|
3380
|
+
this.log.info("Medplum service stopped successfully");
|
|
3381
|
+
}
|
|
3382
|
+
async handler(event) {
|
|
3383
|
+
try {
|
|
3384
|
+
console.log("Received:");
|
|
3385
|
+
console.log(event.message.toString().replaceAll("\r", "\n"));
|
|
3386
|
+
await this.medplum.post(
|
|
3387
|
+
this.medplum.fhirUrl("Bot", this.bot.id, "$execute"),
|
|
3388
|
+
event.message.toString(),
|
|
3389
|
+
J.HL7_V2
|
|
3390
|
+
);
|
|
3391
|
+
const ack = event.message.buildAck();
|
|
3392
|
+
console.log("Response:");
|
|
3393
|
+
console.log(ack.toString().replaceAll("\r", "\n"));
|
|
3394
|
+
event.send(ack);
|
|
3395
|
+
} catch (err) {
|
|
3396
|
+
console.log("HL7 error", err);
|
|
3397
|
+
log.error(Nr(err));
|
|
3398
|
+
}
|
|
3399
|
+
}
|
|
3400
|
+
};
|
|
3401
|
+
if (typeof require !== "undefined" && require.main === module) {
|
|
3402
|
+
new App(new Ar(), { resourceType: "Bot", id: "00000000-00000000-00000000-00000000" }).start();
|
|
3403
|
+
}
|
|
3404
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
3405
|
+
0 && (module.exports = {
|
|
3406
|
+
App
|
|
3407
|
+
});
|