@health-samurai/aidbox-client 0.0.0-alpha.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (71) hide show
  1. package/README.md +137 -0
  2. package/dist/src/client.d.ts +25 -0
  3. package/dist/src/client.d.ts.map +1 -0
  4. package/dist/src/client.js +981 -0
  5. package/dist/src/fhir-http.d.ts +72 -0
  6. package/dist/src/fhir-http.d.ts.map +1 -0
  7. package/dist/src/fhir-http.js +1 -0
  8. package/dist/src/fhir-types/hl7-fhir-r4-core/BackboneElement.d.ts +5 -0
  9. package/dist/src/fhir-types/hl7-fhir-r4-core/BackboneElement.d.ts.map +1 -0
  10. package/dist/src/fhir-types/hl7-fhir-r4-core/BackboneElement.js +5 -0
  11. package/dist/src/fhir-types/hl7-fhir-r4-core/Bundle.d.ts +53 -0
  12. package/dist/src/fhir-types/hl7-fhir-r4-core/Bundle.d.ts.map +1 -0
  13. package/dist/src/fhir-types/hl7-fhir-r4-core/Bundle.js +10 -0
  14. package/dist/src/fhir-types/hl7-fhir-r4-core/CodeableConcept.d.ts +10 -0
  15. package/dist/src/fhir-types/hl7-fhir-r4-core/CodeableConcept.d.ts.map +1 -0
  16. package/dist/src/fhir-types/hl7-fhir-r4-core/CodeableConcept.js +5 -0
  17. package/dist/src/fhir-types/hl7-fhir-r4-core/Coding.d.ts +15 -0
  18. package/dist/src/fhir-types/hl7-fhir-r4-core/Coding.d.ts.map +1 -0
  19. package/dist/src/fhir-types/hl7-fhir-r4-core/Coding.js +5 -0
  20. package/dist/src/fhir-types/hl7-fhir-r4-core/DomainResource.d.ts +10 -0
  21. package/dist/src/fhir-types/hl7-fhir-r4-core/DomainResource.d.ts.map +1 -0
  22. package/dist/src/fhir-types/hl7-fhir-r4-core/DomainResource.js +10 -0
  23. package/dist/src/fhir-types/hl7-fhir-r4-core/Element.d.ts +5 -0
  24. package/dist/src/fhir-types/hl7-fhir-r4-core/Element.d.ts.map +1 -0
  25. package/dist/src/fhir-types/hl7-fhir-r4-core/Element.js +5 -0
  26. package/dist/src/fhir-types/hl7-fhir-r4-core/Identifier.d.ts +20 -0
  27. package/dist/src/fhir-types/hl7-fhir-r4-core/Identifier.d.ts.map +1 -0
  28. package/dist/src/fhir-types/hl7-fhir-r4-core/Identifier.js +5 -0
  29. package/dist/src/fhir-types/hl7-fhir-r4-core/Meta.d.ts +17 -0
  30. package/dist/src/fhir-types/hl7-fhir-r4-core/Meta.d.ts.map +1 -0
  31. package/dist/src/fhir-types/hl7-fhir-r4-core/Meta.js +5 -0
  32. package/dist/src/fhir-types/hl7-fhir-r4-core/Narrative.d.ts +9 -0
  33. package/dist/src/fhir-types/hl7-fhir-r4-core/Narrative.d.ts.map +1 -0
  34. package/dist/src/fhir-types/hl7-fhir-r4-core/Narrative.js +5 -0
  35. package/dist/src/fhir-types/hl7-fhir-r4-core/OperationOutcome.d.ts +19 -0
  36. package/dist/src/fhir-types/hl7-fhir-r4-core/OperationOutcome.d.ts.map +1 -0
  37. package/dist/src/fhir-types/hl7-fhir-r4-core/OperationOutcome.js +10 -0
  38. package/dist/src/fhir-types/hl7-fhir-r4-core/Period.d.ts +9 -0
  39. package/dist/src/fhir-types/hl7-fhir-r4-core/Period.d.ts.map +1 -0
  40. package/dist/src/fhir-types/hl7-fhir-r4-core/Period.js +5 -0
  41. package/dist/src/fhir-types/hl7-fhir-r4-core/Reference.d.ts +14 -0
  42. package/dist/src/fhir-types/hl7-fhir-r4-core/Reference.d.ts.map +1 -0
  43. package/dist/src/fhir-types/hl7-fhir-r4-core/Reference.js +5 -0
  44. package/dist/src/fhir-types/hl7-fhir-r4-core/Resource.d.ts +14 -0
  45. package/dist/src/fhir-types/hl7-fhir-r4-core/Resource.d.ts.map +1 -0
  46. package/dist/src/fhir-types/hl7-fhir-r4-core/Resource.js +10 -0
  47. package/dist/src/fhir-types/hl7-fhir-r4-core/Signature.d.ts +20 -0
  48. package/dist/src/fhir-types/hl7-fhir-r4-core/Signature.d.ts.map +1 -0
  49. package/dist/src/fhir-types/hl7-fhir-r4-core/Signature.js +5 -0
  50. package/dist/src/fhir-types/hl7-fhir-r4-core/index.d.ts +19 -0
  51. package/dist/src/fhir-types/hl7-fhir-r4-core/index.d.ts.map +1 -0
  52. package/dist/src/fhir-types/hl7-fhir-r4-core/index.js +4 -0
  53. package/dist/src/index.d.ts +8 -0
  54. package/dist/src/index.d.ts.map +1 -0
  55. package/dist/src/index.js +4 -0
  56. package/dist/src/result.d.ts +21 -0
  57. package/dist/src/result.d.ts.map +1 -0
  58. package/dist/src/result.js +36 -0
  59. package/dist/src/types.d.ts +100 -0
  60. package/dist/src/types.d.ts.map +1 -0
  61. package/dist/src/types.js +155 -0
  62. package/dist/src/utils.d.ts +3 -0
  63. package/dist/src/utils.d.ts.map +1 -0
  64. package/dist/src/utils.js +215 -0
  65. package/dist/test/client.test.d.ts +2 -0
  66. package/dist/test/client.test.d.ts.map +1 -0
  67. package/dist/test/fhir-http.test.d.ts +2 -0
  68. package/dist/test/fhir-http.test.d.ts.map +1 -0
  69. package/dist/test/result.test.d.ts +2 -0
  70. package/dist/test/result.test.d.ts.map +1 -0
  71. package/package.json +47 -0
@@ -0,0 +1,981 @@
1
+ function _array_like_to_array(arr, len) {
2
+ if (len == null || len > arr.length) len = arr.length;
3
+ for(var i = 0, arr2 = new Array(len); i < len; i++)arr2[i] = arr[i];
4
+ return arr2;
5
+ }
6
+ function _array_with_holes(arr) {
7
+ if (Array.isArray(arr)) return arr;
8
+ }
9
+ function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
10
+ try {
11
+ var info = gen[key](arg);
12
+ var value = info.value;
13
+ } catch (error) {
14
+ reject(error);
15
+ return;
16
+ }
17
+ if (info.done) {
18
+ resolve(value);
19
+ } else {
20
+ Promise.resolve(value).then(_next, _throw);
21
+ }
22
+ }
23
+ function _async_to_generator(fn) {
24
+ return function() {
25
+ var self = this, args = arguments;
26
+ return new Promise(function(resolve, reject) {
27
+ var gen = fn.apply(self, args);
28
+ function _next(value) {
29
+ asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
30
+ }
31
+ function _throw(err) {
32
+ asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
33
+ }
34
+ _next(undefined);
35
+ });
36
+ };
37
+ }
38
+ function _define_property(obj, key, value) {
39
+ if (key in obj) {
40
+ Object.defineProperty(obj, key, {
41
+ value: value,
42
+ enumerable: true,
43
+ configurable: true,
44
+ writable: true
45
+ });
46
+ } else {
47
+ obj[key] = value;
48
+ }
49
+ return obj;
50
+ }
51
+ function _iterable_to_array_limit(arr, i) {
52
+ var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"];
53
+ if (_i == null) return;
54
+ var _arr = [];
55
+ var _n = true;
56
+ var _d = false;
57
+ var _s, _e;
58
+ try {
59
+ for(_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true){
60
+ _arr.push(_s.value);
61
+ if (i && _arr.length === i) break;
62
+ }
63
+ } catch (err) {
64
+ _d = true;
65
+ _e = err;
66
+ } finally{
67
+ try {
68
+ if (!_n && _i["return"] != null) _i["return"]();
69
+ } finally{
70
+ if (_d) throw _e;
71
+ }
72
+ }
73
+ return _arr;
74
+ }
75
+ function _non_iterable_rest() {
76
+ throw new TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
77
+ }
78
+ function _object_spread(target) {
79
+ for(var i = 1; i < arguments.length; i++){
80
+ var source = arguments[i] != null ? arguments[i] : {};
81
+ var ownKeys = Object.keys(source);
82
+ if (typeof Object.getOwnPropertySymbols === "function") {
83
+ ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym) {
84
+ return Object.getOwnPropertyDescriptor(source, sym).enumerable;
85
+ }));
86
+ }
87
+ ownKeys.forEach(function(key) {
88
+ _define_property(target, key, source[key]);
89
+ });
90
+ }
91
+ return target;
92
+ }
93
+ function _sliced_to_array(arr, i) {
94
+ return _array_with_holes(arr) || _iterable_to_array_limit(arr, i) || _unsupported_iterable_to_array(arr, i) || _non_iterable_rest();
95
+ }
96
+ function _type_of(obj) {
97
+ "@swc/helpers - typeof";
98
+ return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj;
99
+ }
100
+ function _unsupported_iterable_to_array(o, minLen) {
101
+ if (!o) return;
102
+ if (typeof o === "string") return _array_like_to_array(o, minLen);
103
+ var n = Object.prototype.toString.call(o).slice(8, -1);
104
+ if (n === "Object" && o.constructor) n = o.constructor.name;
105
+ if (n === "Map" || n === "Set") return Array.from(n);
106
+ if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _array_like_to_array(o, minLen);
107
+ }
108
+ function _ts_generator(thisArg, body) {
109
+ var f, y, t, _ = {
110
+ label: 0,
111
+ sent: function() {
112
+ if (t[0] & 1) throw t[1];
113
+ return t[1];
114
+ },
115
+ trys: [],
116
+ ops: []
117
+ }, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
118
+ return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() {
119
+ return this;
120
+ }), g;
121
+ function verb(n) {
122
+ return function(v) {
123
+ return step([
124
+ n,
125
+ v
126
+ ]);
127
+ };
128
+ }
129
+ function step(op) {
130
+ if (f) throw new TypeError("Generator is already executing.");
131
+ while(g && (g = 0, op[0] && (_ = 0)), _)try {
132
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
133
+ if (y = 0, t) op = [
134
+ op[0] & 2,
135
+ t.value
136
+ ];
137
+ switch(op[0]){
138
+ case 0:
139
+ case 1:
140
+ t = op;
141
+ break;
142
+ case 4:
143
+ _.label++;
144
+ return {
145
+ value: op[1],
146
+ done: false
147
+ };
148
+ case 5:
149
+ _.label++;
150
+ y = op[1];
151
+ op = [
152
+ 0
153
+ ];
154
+ continue;
155
+ case 7:
156
+ op = _.ops.pop();
157
+ _.trys.pop();
158
+ continue;
159
+ default:
160
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
161
+ _ = 0;
162
+ continue;
163
+ }
164
+ if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
165
+ _.label = op[1];
166
+ break;
167
+ }
168
+ if (op[0] === 6 && _.label < t[1]) {
169
+ _.label = t[1];
170
+ t = op;
171
+ break;
172
+ }
173
+ if (t && _.label < t[2]) {
174
+ _.label = t[2];
175
+ _.ops.push(op);
176
+ break;
177
+ }
178
+ if (t[2]) _.ops.pop();
179
+ _.trys.pop();
180
+ continue;
181
+ }
182
+ op = body.call(thisArg, _);
183
+ } catch (e) {
184
+ op = [
185
+ 6,
186
+ e
187
+ ];
188
+ y = 0;
189
+ } finally{
190
+ f = t = 0;
191
+ }
192
+ if (op[0] & 5) throw op[1];
193
+ return {
194
+ value: op[0] ? op[1] : void 0,
195
+ done: true
196
+ };
197
+ }
198
+ }
199
+ import { Err, Ok } from "./result";
200
+ import { ErrorResponse, RequestError } from "./types";
201
+ import { coerceBody } from "./utils";
202
+ var isInternalErrorResponse = function(resp) {
203
+ return "error" in resp;
204
+ };
205
+ /**
206
+ * Create a client to the FHIR server.
207
+ *
208
+ * ```typescript
209
+ * const client = makeClient({ baseurl: "https://fhir-server.address" })
210
+ *
211
+ * // alternatively, specify different FHIR types:
212
+ * import type { Bundle, OperationOutcome } from "hl7-fhir-r5-core";
213
+ * const client = makeClient<Bundle, OperationOutcome>({ baseurl: "https://fhir-server.address" })
214
+ * ```
215
+ *
216
+ * Main client functions are `request` for typed interactions, and `rawRequest` for manual response processing.
217
+ *
218
+ * This client also provides a set of convenience methods for accessing FHIR operations:
219
+ *
220
+ * - `read`
221
+ * - `search`
222
+ * - `create`
223
+ * - `operation`
224
+ * - `validate`
225
+ *
226
+ */ export function makeClient(param) {
227
+ var baseurl = param.baseurl, _param_onResponse = param.onResponse, onResponse = _param_onResponse === void 0 ? undefined : _param_onResponse;
228
+ var getBaseURL = function() {
229
+ return baseurl;
230
+ };
231
+ // TODO: async response pattern
232
+ var internalRawRequest = function(requestParams) {
233
+ return _async_to_generator(function() {
234
+ var startTime, baseURL, method, url, _requestParams_headers, headers, _requestParams_params, params, body, urlObj, requestHeaders, request, response, responseHeaders, e;
235
+ return _ts_generator(this, function(_state) {
236
+ switch(_state.label){
237
+ case 0:
238
+ startTime = Date.now();
239
+ baseURL = getBaseURL();
240
+ if (!requestParams.url.startsWith("/")) return [
241
+ 2,
242
+ {
243
+ error: new RequestError("url must start with a forward slash", {
244
+ request: requestParams
245
+ }),
246
+ duration: Date.now() - startTime,
247
+ request: requestParams
248
+ }
249
+ ];
250
+ method = requestParams.method, url = requestParams.url, _requestParams_headers = requestParams.headers, headers = _requestParams_headers === void 0 ? {} : _requestParams_headers, _requestParams_params = requestParams.params, params = _requestParams_params === void 0 ? [] : _requestParams_params, body = requestParams.body;
251
+ urlObj = new URL(url, baseURL);
252
+ params.forEach(function(param) {
253
+ var _param = _sliced_to_array(param, 2), key = _param[0], value = _param[1];
254
+ urlObj.searchParams.append(key, value);
255
+ });
256
+ requestHeaders = {
257
+ "content-type": "application/json",
258
+ accept: "application/json"
259
+ };
260
+ Object.entries(headers).forEach(function(param) {
261
+ var _param = _sliced_to_array(param, 2), header = _param[0], value = _param[1];
262
+ requestHeaders[header.toLowerCase()] = value;
263
+ });
264
+ request = {
265
+ method: method,
266
+ url: url,
267
+ params: params,
268
+ headers: requestHeaders,
269
+ body: body !== null && body !== void 0 ? body : ""
270
+ };
271
+ _state.label = 1;
272
+ case 1:
273
+ _state.trys.push([
274
+ 1,
275
+ 3,
276
+ ,
277
+ 4
278
+ ]);
279
+ return [
280
+ 4,
281
+ fetch(urlObj.toString(), {
282
+ method: method,
283
+ headers: requestHeaders,
284
+ body: body || null,
285
+ credentials: "include",
286
+ cache: "no-store"
287
+ })
288
+ ];
289
+ case 2:
290
+ response = _state.sent();
291
+ responseHeaders = {};
292
+ response.headers.forEach(function(value, key) {
293
+ responseHeaders[key] = value;
294
+ });
295
+ return [
296
+ 2,
297
+ {
298
+ response: response,
299
+ responseHeaders: responseHeaders,
300
+ duration: Date.now() - startTime,
301
+ request: request
302
+ }
303
+ ];
304
+ case 3:
305
+ e = _state.sent();
306
+ return [
307
+ 2,
308
+ {
309
+ error: new RequestError(e && (typeof e === "undefined" ? "undefined" : _type_of(e)) === "object" && "message" in e ? "error during request: ".concat(e.message) : "unknown error during request", {
310
+ cause: e,
311
+ request: request
312
+ }),
313
+ duration: Date.now() - startTime,
314
+ request: request
315
+ }
316
+ ];
317
+ case 4:
318
+ return [
319
+ 2
320
+ ];
321
+ }
322
+ });
323
+ })();
324
+ };
325
+ var rawRequest = function(requestParams) {
326
+ return _async_to_generator(function() {
327
+ var result;
328
+ return _ts_generator(this, function(_state) {
329
+ switch(_state.label){
330
+ case 0:
331
+ return [
332
+ 4,
333
+ internalRawRequest(requestParams)
334
+ ];
335
+ case 1:
336
+ result = _state.sent();
337
+ if (isInternalErrorResponse(result)) throw result.error;
338
+ if (onResponse) onResponse(result.response.clone());
339
+ if (!result.response.ok) throw new ErrorResponse("HTTP ".concat(result.response.status, ": ").concat(result.response.statusText), result);
340
+ return [
341
+ 2,
342
+ result
343
+ ];
344
+ }
345
+ });
346
+ })();
347
+ };
348
+ var request = function(params) {
349
+ return _async_to_generator(function() {
350
+ var response, body;
351
+ return _ts_generator(this, function(_state) {
352
+ switch(_state.label){
353
+ case 0:
354
+ return [
355
+ 4,
356
+ internalRawRequest(params)
357
+ ];
358
+ case 1:
359
+ response = _state.sent();
360
+ if (isInternalErrorResponse(response)) throw response.error;
361
+ if (onResponse) onResponse(response.response.clone());
362
+ return [
363
+ 4,
364
+ coerceBody(response)
365
+ ];
366
+ case 2:
367
+ body = _state.sent();
368
+ if (!response.response.ok) {
369
+ if (body.resourceType === "OperationOutcome") return [
370
+ 2,
371
+ Err(_object_spread({
372
+ resource: body
373
+ }, response))
374
+ ];
375
+ throw new ErrorResponse("HTTP ".concat(response.response.status, ": ").concat(response.response.statusText), response);
376
+ }
377
+ return [
378
+ 2,
379
+ Ok(_object_spread({
380
+ resource: body
381
+ }, response))
382
+ ];
383
+ }
384
+ });
385
+ })();
386
+ };
387
+ var fetchUserInfo = function() {
388
+ return _async_to_generator(function() {
389
+ var user;
390
+ return _ts_generator(this, function(_state) {
391
+ switch(_state.label){
392
+ case 0:
393
+ return [
394
+ 4,
395
+ rawRequest({
396
+ url: "/auth/userinfo",
397
+ method: "GET",
398
+ headers: {
399
+ "Content-Type": "application/json",
400
+ Accept: "application/json"
401
+ }
402
+ }).then(function(response) {
403
+ return coerceBody(response);
404
+ })
405
+ ];
406
+ case 1:
407
+ user = _state.sent();
408
+ return [
409
+ 2,
410
+ user
411
+ ];
412
+ }
413
+ });
414
+ })();
415
+ };
416
+ var performLogout = function() {
417
+ return _async_to_generator(function() {
418
+ return _ts_generator(this, function(_state) {
419
+ switch(_state.label){
420
+ case 0:
421
+ return [
422
+ 4,
423
+ rawRequest({
424
+ url: "/auth/logout",
425
+ method: "POST",
426
+ headers: {
427
+ "Content-Type": "application/json",
428
+ Accept: "application/json"
429
+ }
430
+ })
431
+ ];
432
+ case 1:
433
+ return [
434
+ 2,
435
+ _state.sent().response
436
+ ];
437
+ }
438
+ });
439
+ })();
440
+ };
441
+ /// FHIR HTTP methods
442
+ var read = function(opts) {
443
+ return _async_to_generator(function() {
444
+ return _ts_generator(this, function(_state) {
445
+ switch(_state.label){
446
+ case 0:
447
+ return [
448
+ 4,
449
+ request({
450
+ url: "/fhir/".concat(opts.type, "/").concat(opts.id),
451
+ method: "GET"
452
+ })
453
+ ];
454
+ case 1:
455
+ return [
456
+ 2,
457
+ _state.sent()
458
+ ];
459
+ }
460
+ });
461
+ })();
462
+ };
463
+ var vread = function(opts) {
464
+ return _async_to_generator(function() {
465
+ return _ts_generator(this, function(_state) {
466
+ switch(_state.label){
467
+ case 0:
468
+ return [
469
+ 4,
470
+ request({
471
+ url: "/fhir/".concat(opts.type, "/").concat(opts.id, "/_history/").concat(opts.vid),
472
+ method: "GET"
473
+ })
474
+ ];
475
+ case 1:
476
+ return [
477
+ 2,
478
+ _state.sent()
479
+ ];
480
+ }
481
+ });
482
+ })();
483
+ };
484
+ var search = function(opts) {
485
+ return _async_to_generator(function() {
486
+ var url, requestParams;
487
+ return _ts_generator(this, function(_state) {
488
+ switch(_state.label){
489
+ case 0:
490
+ url = [
491
+ "/fhir"
492
+ ];
493
+ if (opts.compartment) url.push(opts.compartment);
494
+ if (opts.compartmentId) url.push(opts.compartmentId);
495
+ if (opts.type) url.push(opts.type);
496
+ // TODO: supports POST to /fhir/.../_search
497
+ requestParams = {
498
+ url: url.join("/"),
499
+ method: "GET",
500
+ headers: {
501
+ "Content-Type": "application/x-www-form-urlencoded"
502
+ },
503
+ params: opts.query
504
+ };
505
+ if (opts.compartmentId && !opts.compartment) throw new RequestError("compartment must be specified if compartment ID is provided", {
506
+ request: requestParams
507
+ });
508
+ return [
509
+ 4,
510
+ request(requestParams)
511
+ ];
512
+ case 1:
513
+ return [
514
+ 2,
515
+ _state.sent()
516
+ ];
517
+ }
518
+ });
519
+ })();
520
+ };
521
+ var create = function(opts) {
522
+ return _async_to_generator(function() {
523
+ return _ts_generator(this, function(_state) {
524
+ switch(_state.label){
525
+ case 0:
526
+ return [
527
+ 4,
528
+ request({
529
+ url: "/fhir/".concat(opts.type, "/"),
530
+ method: "POST",
531
+ body: JSON.stringify(opts.resource)
532
+ })
533
+ ];
534
+ case 1:
535
+ return [
536
+ 2,
537
+ _state.sent()
538
+ ];
539
+ }
540
+ });
541
+ })();
542
+ };
543
+ var conditionalCreate = function(opts) {
544
+ return _async_to_generator(function() {
545
+ return _ts_generator(this, function(_state) {
546
+ switch(_state.label){
547
+ case 0:
548
+ return [
549
+ 4,
550
+ request({
551
+ url: "/fhir/".concat(opts.type, "/"),
552
+ method: "POST",
553
+ headers: {
554
+ "If-None-Exist": opts.searchParameters.map(function(param) {
555
+ var _param = _sliced_to_array(param, 2), name = _param[0], _$param = _param[1];
556
+ return "".concat(name, "=").concat(_$param);
557
+ }).join("&")
558
+ },
559
+ body: JSON.stringify(opts.resource)
560
+ })
561
+ ];
562
+ case 1:
563
+ return [
564
+ 2,
565
+ _state.sent()
566
+ ];
567
+ }
568
+ });
569
+ })();
570
+ };
571
+ var update = function(opts) {
572
+ return _async_to_generator(function() {
573
+ return _ts_generator(this, function(_state) {
574
+ switch(_state.label){
575
+ case 0:
576
+ return [
577
+ 4,
578
+ request({
579
+ url: "/fhir/".concat(opts.type, "/").concat(opts.id),
580
+ method: "PUT",
581
+ body: JSON.stringify(opts.resource)
582
+ })
583
+ ];
584
+ case 1:
585
+ return [
586
+ 2,
587
+ _state.sent()
588
+ ];
589
+ }
590
+ });
591
+ })();
592
+ };
593
+ var conditionalUpdate = function(opts) {
594
+ return _async_to_generator(function() {
595
+ return _ts_generator(this, function(_state) {
596
+ switch(_state.label){
597
+ case 0:
598
+ return [
599
+ 4,
600
+ request({
601
+ url: "/fhir/".concat(opts.type),
602
+ method: "PUT",
603
+ body: JSON.stringify(opts.resource),
604
+ params: opts.searchParameters
605
+ })
606
+ ];
607
+ case 1:
608
+ return [
609
+ 2,
610
+ _state.sent()
611
+ ];
612
+ }
613
+ });
614
+ })();
615
+ };
616
+ var patch = function(opts) {
617
+ return _async_to_generator(function() {
618
+ return _ts_generator(this, function(_state) {
619
+ switch(_state.label){
620
+ case 0:
621
+ return [
622
+ 4,
623
+ request({
624
+ url: "/fhir/".concat(opts.type, "/").concat(opts.id),
625
+ method: "PATCH",
626
+ headers: {
627
+ "Content-Type": "application/json-patch+json"
628
+ },
629
+ body: JSON.stringify(opts.patch)
630
+ })
631
+ ];
632
+ case 1:
633
+ return [
634
+ 2,
635
+ _state.sent()
636
+ ];
637
+ }
638
+ });
639
+ })();
640
+ };
641
+ var conditionalPatch = function(opts) {
642
+ return _async_to_generator(function() {
643
+ return _ts_generator(this, function(_state) {
644
+ switch(_state.label){
645
+ case 0:
646
+ return [
647
+ 4,
648
+ request({
649
+ url: "/fhir/".concat(opts.type),
650
+ method: "PATCH",
651
+ headers: {
652
+ "Content-Type": "application/json-patch+json"
653
+ },
654
+ params: opts.searchParameters,
655
+ body: JSON.stringify(opts.patch)
656
+ })
657
+ ];
658
+ case 1:
659
+ return [
660
+ 2,
661
+ _state.sent()
662
+ ];
663
+ }
664
+ });
665
+ })();
666
+ };
667
+ var deleteOp = function(opts) {
668
+ return _async_to_generator(function() {
669
+ var result, body;
670
+ return _ts_generator(this, function(_state) {
671
+ switch(_state.label){
672
+ case 0:
673
+ return [
674
+ 4,
675
+ rawRequest({
676
+ url: "/fhir/".concat(opts.type, "/").concat(opts.id),
677
+ method: "DELETE"
678
+ })
679
+ ];
680
+ case 1:
681
+ result = _state.sent();
682
+ if (result.response.status === 204) return [
683
+ 2,
684
+ Ok(_object_spread({
685
+ resource: undefined
686
+ }, result))
687
+ ];
688
+ return [
689
+ 4,
690
+ coerceBody(result)
691
+ ];
692
+ case 2:
693
+ body = _state.sent();
694
+ if (!result.response.ok) {
695
+ if (body.resourceType === "OperationOutcome") return [
696
+ 2,
697
+ Err(_object_spread({
698
+ resource: body
699
+ }, result))
700
+ ];
701
+ throw new ErrorResponse("HTTP ".concat(result.response.status, ": ").concat(result.response.statusText), result);
702
+ }
703
+ return [
704
+ 2,
705
+ Ok(_object_spread({
706
+ resource: body
707
+ }, result))
708
+ ];
709
+ }
710
+ });
711
+ })();
712
+ };
713
+ var deleteHistory = function(opts) {
714
+ return _async_to_generator(function() {
715
+ return _ts_generator(this, function(_state) {
716
+ switch(_state.label){
717
+ case 0:
718
+ return [
719
+ 4,
720
+ request({
721
+ url: "/fhir/".concat(opts.type, "/").concat(opts.id, "/_history"),
722
+ method: "DELETE"
723
+ })
724
+ ];
725
+ case 1:
726
+ return [
727
+ 2,
728
+ _state.sent()
729
+ ];
730
+ }
731
+ });
732
+ })();
733
+ };
734
+ var deleteHistoryVersion = function(opts) {
735
+ return _async_to_generator(function() {
736
+ return _ts_generator(this, function(_state) {
737
+ switch(_state.label){
738
+ case 0:
739
+ return [
740
+ 4,
741
+ request({
742
+ url: "/fhir/".concat(opts.type, "/").concat(opts.id, "/_history/").concat(opts.vid),
743
+ method: "DELETE"
744
+ })
745
+ ];
746
+ case 1:
747
+ return [
748
+ 2,
749
+ _state.sent()
750
+ ];
751
+ }
752
+ });
753
+ })();
754
+ };
755
+ var conditionalDelete = function(opts) {
756
+ return _async_to_generator(function() {
757
+ var url, requestParams;
758
+ return _ts_generator(this, function(_state) {
759
+ switch(_state.label){
760
+ case 0:
761
+ url = [
762
+ "/fhir"
763
+ ];
764
+ if (opts.type) url.push(opts.type);
765
+ requestParams = {
766
+ url: url.join("/"),
767
+ method: "DELETE",
768
+ params: opts.searchParameters
769
+ };
770
+ return [
771
+ 4,
772
+ request(requestParams)
773
+ ];
774
+ case 1:
775
+ return [
776
+ 2,
777
+ _state.sent()
778
+ ];
779
+ }
780
+ });
781
+ })();
782
+ };
783
+ var history = function(opts) {
784
+ return _async_to_generator(function() {
785
+ var url, requestParams;
786
+ return _ts_generator(this, function(_state) {
787
+ switch(_state.label){
788
+ case 0:
789
+ url = [
790
+ "/fhir"
791
+ ];
792
+ if (opts.type) url.push(opts.type);
793
+ if (opts.id) url.push(opts.id);
794
+ url.push("_history");
795
+ requestParams = {
796
+ url: url.join("/"),
797
+ method: "GET"
798
+ };
799
+ if (opts.id && !opts.type) throw new RequestError("resource type must be specified if ID is provided", {
800
+ request: requestParams
801
+ });
802
+ return [
803
+ 4,
804
+ request(requestParams)
805
+ ];
806
+ case 1:
807
+ return [
808
+ 2,
809
+ _state.sent()
810
+ ];
811
+ }
812
+ });
813
+ })();
814
+ };
815
+ var capabilities = function(opts) {
816
+ return _async_to_generator(function() {
817
+ return _ts_generator(this, function(_state) {
818
+ switch(_state.label){
819
+ case 0:
820
+ return [
821
+ 4,
822
+ request({
823
+ url: "/fhir/metadata",
824
+ method: "GET",
825
+ params: [
826
+ [
827
+ "mode",
828
+ opts.mode
829
+ ],
830
+ [
831
+ "_format",
832
+ "application/fhir+json"
833
+ ]
834
+ ]
835
+ })
836
+ ];
837
+ case 1:
838
+ return [
839
+ 2,
840
+ _state.sent()
841
+ ];
842
+ }
843
+ });
844
+ })();
845
+ };
846
+ var batch = function(opts) {
847
+ return _async_to_generator(function() {
848
+ return _ts_generator(this, function(_state) {
849
+ switch(_state.label){
850
+ case 0:
851
+ return [
852
+ 4,
853
+ request({
854
+ url: "/fhir",
855
+ method: "POST",
856
+ params: [
857
+ [
858
+ "_format",
859
+ opts.format
860
+ ]
861
+ ],
862
+ body: JSON.stringify(opts.bundle)
863
+ })
864
+ ];
865
+ case 1:
866
+ return [
867
+ 2,
868
+ _state.sent()
869
+ ];
870
+ }
871
+ });
872
+ })();
873
+ };
874
+ var transaction = function(opts) {
875
+ return _async_to_generator(function() {
876
+ return _ts_generator(this, function(_state) {
877
+ switch(_state.label){
878
+ case 0:
879
+ return [
880
+ 4,
881
+ request({
882
+ url: "/fhir",
883
+ method: "POST",
884
+ params: [
885
+ [
886
+ "_format",
887
+ opts.format
888
+ ]
889
+ ],
890
+ body: JSON.stringify(opts.bundle)
891
+ })
892
+ ];
893
+ case 1:
894
+ return [
895
+ 2,
896
+ _state.sent()
897
+ ];
898
+ }
899
+ });
900
+ })();
901
+ };
902
+ var operation = function(opts) {
903
+ return _async_to_generator(function() {
904
+ var url, requestParams;
905
+ return _ts_generator(this, function(_state) {
906
+ switch(_state.label){
907
+ case 0:
908
+ url = [
909
+ "/fhir"
910
+ ];
911
+ if (opts.type) url.push(opts.type);
912
+ if (opts.id) url.push(opts.id);
913
+ url.push(opts.operation);
914
+ requestParams = {
915
+ url: url.join("/"),
916
+ method: "POST"
917
+ };
918
+ if (opts.resource) requestParams.body = JSON.stringify(opts.resource);
919
+ return [
920
+ 4,
921
+ request(requestParams)
922
+ ];
923
+ case 1:
924
+ return [
925
+ 2,
926
+ _state.sent()
927
+ ];
928
+ }
929
+ });
930
+ })();
931
+ };
932
+ var validate = function(opts) {
933
+ return _async_to_generator(function() {
934
+ return _ts_generator(this, function(_state) {
935
+ switch(_state.label){
936
+ case 0:
937
+ return [
938
+ 4,
939
+ operation(_object_spread({
940
+ operation: "$validate"
941
+ }, opts))
942
+ ];
943
+ case 1:
944
+ return [
945
+ 2,
946
+ _state.sent()
947
+ ];
948
+ }
949
+ });
950
+ })();
951
+ };
952
+ return {
953
+ // General
954
+ getBaseURL: getBaseURL,
955
+ rawRequest: rawRequest,
956
+ request: request,
957
+ // Aidbox
958
+ performLogout: performLogout,
959
+ fetchUserInfo: fetchUserInfo,
960
+ // FHIR HTTP
961
+ read: read,
962
+ vread: vread,
963
+ search: search,
964
+ create: create,
965
+ conditionalCreate: conditionalCreate,
966
+ update: update,
967
+ conditionalUpdate: conditionalUpdate,
968
+ patch: patch,
969
+ conditionalPatch: conditionalPatch,
970
+ delete: deleteOp,
971
+ deleteHistory: deleteHistory,
972
+ deleteHistoryVersion: deleteHistoryVersion,
973
+ conditionalDelete: conditionalDelete,
974
+ history: history,
975
+ capabilities: capabilities,
976
+ batch: batch,
977
+ transaction: transaction,
978
+ operation: operation,
979
+ validate: validate
980
+ };
981
+ }