@medplum/mock 1.0.4 → 1.0.6
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/README.md +3 -2
- package/dist/cjs/{index.js → index.cjs} +250 -232
- package/dist/cjs/index.cjs.map +1 -0
- package/dist/{esm/index.min.js → cjs/index.min.cjs} +2 -2
- package/dist/cjs/index.min.cjs.map +1 -0
- package/dist/cjs/mocks/smart.d.ts +2 -0
- package/dist/cjs/repo.d.ts +1 -2
- package/dist/esm/index.min.mjs +2 -0
- package/dist/esm/index.min.mjs.map +1 -0
- package/dist/esm/{index.js → index.mjs} +248 -229
- package/dist/esm/index.mjs.map +1 -0
- package/dist/esm/mocks/smart.d.ts +2 -0
- package/dist/esm/repo.d.ts +1 -2
- package/dist/types/mocks/smart.d.ts +2 -0
- package/dist/types/repo.d.ts +1 -2
- package/package.json +8 -15
- package/rollup.config.mjs +4 -4
- package/dist/cjs/index.js.map +0 -1
- package/dist/cjs/index.min.js +0 -2
- package/dist/cjs/index.min.js.map +0 -1
- package/dist/esm/index.js.map +0 -1
- package/dist/esm/index.min.js.map +0 -1
|
@@ -1,46 +1,8 @@
|
|
|
1
1
|
(function (global, factory) {
|
|
2
|
-
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@medplum/core')) :
|
|
3
|
-
typeof define === 'function' && define.amd ? define(['exports', '@medplum/core'], factory) :
|
|
4
|
-
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory((global.medplum = global.medplum || {}, global.medplum.mock = {}), global.medplum.core));
|
|
5
|
-
})(this, (function (exports, core) { 'use strict';
|
|
6
|
-
|
|
7
|
-
/******************************************************************************
|
|
8
|
-
Copyright (c) Microsoft Corporation.
|
|
9
|
-
|
|
10
|
-
Permission to use, copy, modify, and/or distribute this software for any
|
|
11
|
-
purpose with or without fee is hereby granted.
|
|
12
|
-
|
|
13
|
-
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
14
|
-
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
15
|
-
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
16
|
-
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
17
|
-
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
18
|
-
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
19
|
-
PERFORMANCE OF THIS SOFTWARE.
|
|
20
|
-
***************************************************************************** */
|
|
21
|
-
|
|
22
|
-
function __awaiter(thisArg, _arguments, P, generator) {
|
|
23
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
24
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
25
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
26
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
27
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
28
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
29
|
-
});
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
function __classPrivateFieldGet(receiver, state, kind, f) {
|
|
33
|
-
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
34
|
-
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
35
|
-
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
function __classPrivateFieldSet(receiver, state, value, kind, f) {
|
|
39
|
-
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
40
|
-
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
41
|
-
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
|
42
|
-
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
43
|
-
}
|
|
2
|
+
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@medplum/core'), require('fast-json-patch')) :
|
|
3
|
+
typeof define === 'function' && define.amd ? define(['exports', '@medplum/core', 'fast-json-patch'], factory) :
|
|
4
|
+
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory((global.medplum = global.medplum || {}, global.medplum.mock = {}), global.medplum.core, global["fast-json-patch"]));
|
|
5
|
+
})(this, (function (exports, core, fastJsonPatch) { 'use strict';
|
|
44
6
|
|
|
45
7
|
const ExampleAccessPolicy = {
|
|
46
8
|
resourceType: 'AccessPolicy',
|
|
@@ -516,6 +478,7 @@
|
|
|
516
478
|
const HomerObservation1 = {
|
|
517
479
|
resourceType: 'Observation',
|
|
518
480
|
id: '1',
|
|
481
|
+
status: 'final',
|
|
519
482
|
subject: {
|
|
520
483
|
reference: 'Patient/123',
|
|
521
484
|
display: 'Homer Simpson',
|
|
@@ -528,6 +491,7 @@
|
|
|
528
491
|
const HomerObservation2 = {
|
|
529
492
|
resourceType: 'Observation',
|
|
530
493
|
id: '2',
|
|
494
|
+
status: 'corrected',
|
|
531
495
|
subject: {
|
|
532
496
|
reference: 'Patient/123',
|
|
533
497
|
display: 'Homer Simpson',
|
|
@@ -550,6 +514,7 @@
|
|
|
550
514
|
const HomerObservation3 = {
|
|
551
515
|
resourceType: 'Observation',
|
|
552
516
|
id: '3',
|
|
517
|
+
status: 'final',
|
|
553
518
|
subject: {
|
|
554
519
|
reference: 'Patient/123',
|
|
555
520
|
display: 'Homer Simpson',
|
|
@@ -572,6 +537,7 @@
|
|
|
572
537
|
const HomerObservation4 = {
|
|
573
538
|
resourceType: 'Observation',
|
|
574
539
|
id: '4',
|
|
540
|
+
status: 'final',
|
|
575
541
|
subject: {
|
|
576
542
|
reference: 'Patient/123',
|
|
577
543
|
display: 'Homer Simpson',
|
|
@@ -605,6 +571,7 @@
|
|
|
605
571
|
const HomerObservation5 = {
|
|
606
572
|
resourceType: 'Observation',
|
|
607
573
|
id: '5',
|
|
574
|
+
status: 'final',
|
|
608
575
|
subject: {
|
|
609
576
|
reference: 'Patient/123',
|
|
610
577
|
display: 'Homer Simpson',
|
|
@@ -622,6 +589,7 @@
|
|
|
622
589
|
const HomerObservation6 = {
|
|
623
590
|
resourceType: 'Observation',
|
|
624
591
|
id: '6',
|
|
592
|
+
status: 'final',
|
|
625
593
|
subject: {
|
|
626
594
|
reference: 'Patient/123',
|
|
627
595
|
display: 'Homer Simpson',
|
|
@@ -649,6 +617,7 @@
|
|
|
649
617
|
const HomerObservation7 = {
|
|
650
618
|
resourceType: 'Observation',
|
|
651
619
|
id: '7',
|
|
620
|
+
status: 'final',
|
|
652
621
|
subject: {
|
|
653
622
|
reference: 'Patient/123',
|
|
654
623
|
display: 'Homer Simpson',
|
|
@@ -680,6 +649,7 @@
|
|
|
680
649
|
const HomerObservation8 = {
|
|
681
650
|
resourceType: 'Observation',
|
|
682
651
|
id: '8',
|
|
652
|
+
status: 'final',
|
|
683
653
|
subject: {
|
|
684
654
|
reference: 'Patient/123',
|
|
685
655
|
display: 'Homer Simpson',
|
|
@@ -16538,6 +16508,43 @@
|
|
|
16538
16508
|
],
|
|
16539
16509
|
};
|
|
16540
16510
|
|
|
16511
|
+
const ExampleSmartClientApplication = {
|
|
16512
|
+
resourceType: 'ClientApplication',
|
|
16513
|
+
id: 'smart-client-app',
|
|
16514
|
+
name: 'Inferno Client',
|
|
16515
|
+
description: 'Client application used for Inferno ONC compliance testing',
|
|
16516
|
+
redirectUri: 'https://inferno.healthit.gov/suites/custom/smart/redirect',
|
|
16517
|
+
launchUri: 'https://inferno.healthit.gov/suites/custom/smart/launch',
|
|
16518
|
+
};
|
|
16519
|
+
|
|
16520
|
+
/******************************************************************************
|
|
16521
|
+
Copyright (c) Microsoft Corporation.
|
|
16522
|
+
|
|
16523
|
+
Permission to use, copy, modify, and/or distribute this software for any
|
|
16524
|
+
purpose with or without fee is hereby granted.
|
|
16525
|
+
|
|
16526
|
+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
16527
|
+
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
16528
|
+
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
16529
|
+
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
16530
|
+
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
16531
|
+
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
16532
|
+
PERFORMANCE OF THIS SOFTWARE.
|
|
16533
|
+
***************************************************************************** */
|
|
16534
|
+
|
|
16535
|
+
function __classPrivateFieldGet(receiver, state, kind, f) {
|
|
16536
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
16537
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
16538
|
+
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
16539
|
+
}
|
|
16540
|
+
|
|
16541
|
+
function __classPrivateFieldSet(receiver, state, value, kind, f) {
|
|
16542
|
+
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
16543
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
16544
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
|
16545
|
+
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
16546
|
+
}
|
|
16547
|
+
|
|
16541
16548
|
var _MemoryRepository_resources, _MemoryRepository_history;
|
|
16542
16549
|
class MemoryRepository {
|
|
16543
16550
|
constructor() {
|
|
@@ -16547,7 +16554,6 @@
|
|
|
16547
16554
|
__classPrivateFieldSet(this, _MemoryRepository_history, {}, "f");
|
|
16548
16555
|
}
|
|
16549
16556
|
createResource(resource) {
|
|
16550
|
-
var _a, _b;
|
|
16551
16557
|
const result = core.deepClone(resource);
|
|
16552
16558
|
if (!result.id) {
|
|
16553
16559
|
result.id = this.generateId();
|
|
@@ -16555,10 +16561,10 @@
|
|
|
16555
16561
|
if (!result.meta) {
|
|
16556
16562
|
result.meta = {};
|
|
16557
16563
|
}
|
|
16558
|
-
if (!
|
|
16564
|
+
if (!result.meta?.versionId) {
|
|
16559
16565
|
result.meta.versionId = this.generateId();
|
|
16560
16566
|
}
|
|
16561
|
-
if (!
|
|
16567
|
+
if (!result.meta?.lastUpdated) {
|
|
16562
16568
|
result.meta.lastUpdated = new Date().toISOString();
|
|
16563
16569
|
}
|
|
16564
16570
|
const { resourceType, id } = result;
|
|
@@ -16587,56 +16593,48 @@
|
|
|
16587
16593
|
}
|
|
16588
16594
|
return this.createResource(result);
|
|
16589
16595
|
}
|
|
16590
|
-
patchResource(resourceType, id, patch) {
|
|
16591
|
-
|
|
16592
|
-
|
|
16593
|
-
|
|
16594
|
-
|
|
16595
|
-
|
|
16596
|
-
|
|
16597
|
-
|
|
16598
|
-
|
|
16599
|
-
|
|
16600
|
-
|
|
16601
|
-
|
|
16602
|
-
|
|
16603
|
-
}
|
|
16604
|
-
const patchedResource = patchResult.newDocument;
|
|
16605
|
-
return this.updateResource(patchedResource);
|
|
16606
|
-
});
|
|
16596
|
+
async patchResource(resourceType, id, patch) {
|
|
16597
|
+
const resource = this.readResource(resourceType, id);
|
|
16598
|
+
let patchResult;
|
|
16599
|
+
try {
|
|
16600
|
+
patchResult = fastJsonPatch.applyPatch(resource, patch, true);
|
|
16601
|
+
}
|
|
16602
|
+
catch (err) {
|
|
16603
|
+
const patchError = err;
|
|
16604
|
+
const message = patchError.message?.split('\n')?.[0] || 'JSONPatch error';
|
|
16605
|
+
throw core.badRequest(message);
|
|
16606
|
+
}
|
|
16607
|
+
const patchedResource = patchResult.newDocument;
|
|
16608
|
+
return this.updateResource(patchedResource);
|
|
16607
16609
|
}
|
|
16608
16610
|
readResource(resourceType, id) {
|
|
16609
|
-
|
|
16610
|
-
const resource = (_b = (_a = __classPrivateFieldGet(this, _MemoryRepository_resources, "f")) === null || _a === void 0 ? void 0 : _a[resourceType]) === null || _b === void 0 ? void 0 : _b[id];
|
|
16611
|
+
const resource = __classPrivateFieldGet(this, _MemoryRepository_resources, "f")?.[resourceType]?.[id];
|
|
16611
16612
|
if (!resource) {
|
|
16612
16613
|
throw core.notFound;
|
|
16613
16614
|
}
|
|
16614
16615
|
return core.deepClone(resource);
|
|
16615
16616
|
}
|
|
16616
16617
|
readHistory(resourceType, id) {
|
|
16617
|
-
var _a, _b, _c;
|
|
16618
16618
|
this.readResource(resourceType, id);
|
|
16619
16619
|
return {
|
|
16620
16620
|
resourceType: 'Bundle',
|
|
16621
16621
|
type: 'history',
|
|
16622
|
-
entry: (
|
|
16622
|
+
entry: (__classPrivateFieldGet(this, _MemoryRepository_history, "f")?.[resourceType]?.[id] ?? [])
|
|
16623
16623
|
.reverse()
|
|
16624
16624
|
.map((version) => ({ resource: core.deepClone(version) })),
|
|
16625
16625
|
};
|
|
16626
16626
|
}
|
|
16627
16627
|
readVersion(resourceType, id, versionId) {
|
|
16628
|
-
var _a, _b, _c;
|
|
16629
16628
|
this.readResource(resourceType, id);
|
|
16630
|
-
const version =
|
|
16629
|
+
const version = __classPrivateFieldGet(this, _MemoryRepository_history, "f")?.[resourceType]?.[id]?.find((v) => v.meta?.versionId === versionId);
|
|
16631
16630
|
if (!version) {
|
|
16632
16631
|
throw core.notFound;
|
|
16633
16632
|
}
|
|
16634
16633
|
return core.deepClone(version);
|
|
16635
16634
|
}
|
|
16636
16635
|
search(searchRequest) {
|
|
16637
|
-
var _a;
|
|
16638
16636
|
const { resourceType } = searchRequest;
|
|
16639
|
-
const resources =
|
|
16637
|
+
const resources = __classPrivateFieldGet(this, _MemoryRepository_resources, "f")[resourceType] ?? {};
|
|
16640
16638
|
const result = Object.values(resources).filter((resource) => core.matchesSearchRequest(resource, searchRequest));
|
|
16641
16639
|
return {
|
|
16642
16640
|
resourceType: 'Bundle',
|
|
@@ -16646,8 +16644,7 @@
|
|
|
16646
16644
|
};
|
|
16647
16645
|
}
|
|
16648
16646
|
deleteResource(resourceType, id) {
|
|
16649
|
-
|
|
16650
|
-
if ((_b = (_a = __classPrivateFieldGet(this, _MemoryRepository_resources, "f")) === null || _a === void 0 ? void 0 : _a[resourceType]) === null || _b === void 0 ? void 0 : _b[id]) {
|
|
16647
|
+
if (__classPrivateFieldGet(this, _MemoryRepository_resources, "f")?.[resourceType]?.[id]) {
|
|
16651
16648
|
delete __classPrivateFieldGet(this, _MemoryRepository_resources, "f")[resourceType][id];
|
|
16652
16649
|
}
|
|
16653
16650
|
}
|
|
@@ -16667,7 +16664,7 @@
|
|
|
16667
16664
|
|
|
16668
16665
|
class MockClient extends core.MedplumClient {
|
|
16669
16666
|
constructor(clientOptions) {
|
|
16670
|
-
const mockFetchClient = new MockFetchClient(clientOptions
|
|
16667
|
+
const mockFetchClient = new MockFetchClient(clientOptions?.debug);
|
|
16671
16668
|
super({
|
|
16672
16669
|
baseUrl: 'https://example.com/',
|
|
16673
16670
|
clientId: 'my-client-id',
|
|
@@ -16676,7 +16673,7 @@
|
|
|
16676
16673
|
return mockFetchClient.mockFetch(url, options);
|
|
16677
16674
|
},
|
|
16678
16675
|
});
|
|
16679
|
-
this.debug = !!
|
|
16676
|
+
this.debug = !!clientOptions?.debug;
|
|
16680
16677
|
}
|
|
16681
16678
|
clear() {
|
|
16682
16679
|
super.clear();
|
|
@@ -16712,22 +16709,20 @@
|
|
|
16712
16709
|
}
|
|
16713
16710
|
return super.getActiveLogin();
|
|
16714
16711
|
}
|
|
16715
|
-
createBinary(data, filename, contentType, onProgress) {
|
|
16716
|
-
|
|
16717
|
-
|
|
16718
|
-
|
|
16719
|
-
|
|
16720
|
-
|
|
16721
|
-
|
|
16722
|
-
|
|
16723
|
-
|
|
16724
|
-
|
|
16725
|
-
|
|
16726
|
-
|
|
16727
|
-
|
|
16728
|
-
|
|
16729
|
-
};
|
|
16730
|
-
});
|
|
16712
|
+
async createBinary(data, filename, contentType, onProgress) {
|
|
16713
|
+
if (filename?.endsWith('.exe')) {
|
|
16714
|
+
return Promise.reject(core.badRequest('Invalid file type'));
|
|
16715
|
+
}
|
|
16716
|
+
if (onProgress) {
|
|
16717
|
+
onProgress({ loaded: 0, lengthComputable: false });
|
|
16718
|
+
onProgress({ loaded: 0, total: 100, lengthComputable: true });
|
|
16719
|
+
onProgress({ loaded: 100, total: 100, lengthComputable: true });
|
|
16720
|
+
}
|
|
16721
|
+
return {
|
|
16722
|
+
resourceType: 'Binary',
|
|
16723
|
+
contentType,
|
|
16724
|
+
url: 'https://example.com/binary/123',
|
|
16725
|
+
};
|
|
16731
16726
|
}
|
|
16732
16727
|
}
|
|
16733
16728
|
class MockFetchClient {
|
|
@@ -16736,28 +16731,26 @@
|
|
|
16736
16731
|
this.mockRepo = new MemoryRepository();
|
|
16737
16732
|
this.initMockRepo();
|
|
16738
16733
|
}
|
|
16739
|
-
mockFetch(url, options) {
|
|
16740
|
-
|
|
16741
|
-
|
|
16742
|
-
|
|
16743
|
-
|
|
16744
|
-
|
|
16745
|
-
|
|
16746
|
-
|
|
16747
|
-
|
|
16748
|
-
|
|
16749
|
-
|
|
16750
|
-
|
|
16751
|
-
|
|
16752
|
-
|
|
16753
|
-
|
|
16754
|
-
|
|
16755
|
-
|
|
16756
|
-
|
|
16757
|
-
|
|
16758
|
-
|
|
16759
|
-
json: () => Promise.resolve(response),
|
|
16760
|
-
});
|
|
16734
|
+
async mockFetch(url, options) {
|
|
16735
|
+
const method = options.method || 'GET';
|
|
16736
|
+
const path = url.replace('https://example.com/', '');
|
|
16737
|
+
if (this.debug) {
|
|
16738
|
+
console.log('MockClient', method, path);
|
|
16739
|
+
}
|
|
16740
|
+
const response = await this.mockHandler(method, path, options);
|
|
16741
|
+
if (this.debug && !response) {
|
|
16742
|
+
console.log('MockClient: not found', method, path);
|
|
16743
|
+
}
|
|
16744
|
+
if (this.debug) {
|
|
16745
|
+
console.log('MockClient', JSON.stringify(response, null, 2));
|
|
16746
|
+
}
|
|
16747
|
+
if (response?.resourceType === 'OperationOutcome' && !core.isOk(response)) {
|
|
16748
|
+
return Promise.reject(response);
|
|
16749
|
+
}
|
|
16750
|
+
return Promise.resolve({
|
|
16751
|
+
ok: true,
|
|
16752
|
+
blob: () => Promise.resolve(response),
|
|
16753
|
+
json: () => Promise.resolve(response),
|
|
16761
16754
|
});
|
|
16762
16755
|
}
|
|
16763
16756
|
mockCreatePdf(docDefinition, tableLayouts, fonts) {
|
|
@@ -16769,24 +16762,22 @@
|
|
|
16769
16762
|
}
|
|
16770
16763
|
return Promise.resolve({});
|
|
16771
16764
|
}
|
|
16772
|
-
mockHandler(method, path, options) {
|
|
16773
|
-
|
|
16774
|
-
|
|
16775
|
-
|
|
16776
|
-
|
|
16777
|
-
|
|
16778
|
-
|
|
16779
|
-
|
|
16780
|
-
|
|
16781
|
-
|
|
16782
|
-
|
|
16783
|
-
|
|
16784
|
-
|
|
16785
|
-
|
|
16786
|
-
|
|
16787
|
-
|
|
16788
|
-
}
|
|
16789
|
-
});
|
|
16765
|
+
async mockHandler(method, path, options) {
|
|
16766
|
+
if (path.startsWith('admin/')) {
|
|
16767
|
+
return this.mockAdminHandler(method, path);
|
|
16768
|
+
}
|
|
16769
|
+
else if (path.startsWith('auth/')) {
|
|
16770
|
+
return this.mockAuthHandler(method, path, options);
|
|
16771
|
+
}
|
|
16772
|
+
else if (path.startsWith('oauth2/')) {
|
|
16773
|
+
return this.mockOAuthHandler(method, path, options);
|
|
16774
|
+
}
|
|
16775
|
+
else if (path.startsWith('fhir/R4')) {
|
|
16776
|
+
return this.mockFhirHandler(method, path, options);
|
|
16777
|
+
}
|
|
16778
|
+
else {
|
|
16779
|
+
return null;
|
|
16780
|
+
}
|
|
16790
16781
|
}
|
|
16791
16782
|
mockAdminHandler(_method, path) {
|
|
16792
16783
|
if (path.startsWith('admin/projects/123')) {
|
|
@@ -16827,9 +16818,39 @@
|
|
|
16827
16818
|
}
|
|
16828
16819
|
if (path.startsWith('auth/me')) {
|
|
16829
16820
|
return {
|
|
16830
|
-
profile:
|
|
16821
|
+
profile: DrAliceSmith,
|
|
16822
|
+
security: {
|
|
16823
|
+
mfaEnrolled: false,
|
|
16824
|
+
sessions: [
|
|
16825
|
+
{
|
|
16826
|
+
id: '123',
|
|
16827
|
+
lastUpdated: new Date().toISOString(),
|
|
16828
|
+
authMethod: 'password',
|
|
16829
|
+
remoteAddress: '5.5.5.5',
|
|
16830
|
+
browser: 'Chrome',
|
|
16831
|
+
os: 'Linux',
|
|
16832
|
+
},
|
|
16833
|
+
{
|
|
16834
|
+
id: '456',
|
|
16835
|
+
lastUpdated: new Date().toISOString(),
|
|
16836
|
+
authMethod: 'password',
|
|
16837
|
+
remoteAddress: '6.6.6.6',
|
|
16838
|
+
browser: 'Chrome',
|
|
16839
|
+
os: 'Android',
|
|
16840
|
+
},
|
|
16841
|
+
],
|
|
16842
|
+
},
|
|
16831
16843
|
};
|
|
16832
16844
|
}
|
|
16845
|
+
if (path.startsWith('auth/mfa/status')) {
|
|
16846
|
+
return {
|
|
16847
|
+
enrolled: false,
|
|
16848
|
+
enrollUri: 'otpauth://totp/medplum.com:alice.smith%40example',
|
|
16849
|
+
};
|
|
16850
|
+
}
|
|
16851
|
+
if (path.startsWith('auth/mfa/enroll')) {
|
|
16852
|
+
return core.allOk;
|
|
16853
|
+
}
|
|
16833
16854
|
return null;
|
|
16834
16855
|
}
|
|
16835
16856
|
mockChangePasswordHandler(_method, _path, options) {
|
|
@@ -16982,69 +17003,68 @@
|
|
|
16982
17003
|
this.mockRepo.createResource(ExampleWorkflowTask2);
|
|
16983
17004
|
this.mockRepo.createResource(ExampleWorkflowTask3);
|
|
16984
17005
|
this.mockRepo.createResource(ExampleWorkflowRequestGroup);
|
|
17006
|
+
this.mockRepo.createResource(ExampleSmartClientApplication);
|
|
16985
17007
|
DrAliceSmithSlots.forEach((slot) => this.mockRepo.createResource(slot));
|
|
16986
17008
|
}
|
|
16987
|
-
mockFhirHandler(method, url, options) {
|
|
16988
|
-
|
|
16989
|
-
|
|
16990
|
-
|
|
16991
|
-
|
|
16992
|
-
|
|
16993
|
-
|
|
16994
|
-
|
|
16995
|
-
|
|
16996
|
-
|
|
17009
|
+
async mockFhirHandler(method, url, options) {
|
|
17010
|
+
const path = url.includes('?') ? url.substring(0, url.indexOf('?')) : url;
|
|
17011
|
+
const match = /fhir\/R4\/?([^/]+)?\/?([^/]+)?\/?([^/]+)?\/?([^/]+)?/.exec(path);
|
|
17012
|
+
const resourceType = match?.[1];
|
|
17013
|
+
const id = match?.[2];
|
|
17014
|
+
const operation = match?.[3];
|
|
17015
|
+
const versionId = match?.[4];
|
|
17016
|
+
if (path.startsWith('fhir/R4/ValueSet/$expand')) {
|
|
17017
|
+
return exampleValueSet;
|
|
17018
|
+
}
|
|
17019
|
+
else if (path === 'fhir/R4/$graphql') {
|
|
17020
|
+
return this.mockFhirGraphqlHandler(method, path, options);
|
|
17021
|
+
}
|
|
17022
|
+
else if (path === 'not-found' || id === 'not-found') {
|
|
17023
|
+
return core.notFound;
|
|
17024
|
+
}
|
|
17025
|
+
else if (method === 'POST') {
|
|
17026
|
+
if (resourceType && id && operation) {
|
|
17027
|
+
return core.allOk;
|
|
16997
17028
|
}
|
|
16998
|
-
else if (
|
|
16999
|
-
return this.
|
|
17029
|
+
else if (resourceType) {
|
|
17030
|
+
return this.mockRepo.createResource(JSON.parse(options.body));
|
|
17000
17031
|
}
|
|
17001
|
-
else
|
|
17002
|
-
return
|
|
17032
|
+
else {
|
|
17033
|
+
return this.mockFhirBatchHandler(method, path, options);
|
|
17003
17034
|
}
|
|
17004
|
-
|
|
17005
|
-
|
|
17006
|
-
|
|
17007
|
-
|
|
17008
|
-
else if (resourceType) {
|
|
17009
|
-
return this.mockRepo.createResource(JSON.parse(options.body));
|
|
17010
|
-
}
|
|
17011
|
-
else {
|
|
17012
|
-
return this.mockFhirBatchHandler(method, path, options);
|
|
17013
|
-
}
|
|
17035
|
+
}
|
|
17036
|
+
else if (method === 'GET') {
|
|
17037
|
+
if (resourceType && id && versionId) {
|
|
17038
|
+
return this.mockRepo.readVersion(resourceType, id, versionId);
|
|
17014
17039
|
}
|
|
17015
|
-
else if (
|
|
17016
|
-
|
|
17017
|
-
return this.mockRepo.readVersion(resourceType, id, versionId);
|
|
17018
|
-
}
|
|
17019
|
-
else if (resourceType && id && operation === '_history') {
|
|
17020
|
-
return this.mockRepo.readHistory(resourceType, id);
|
|
17021
|
-
}
|
|
17022
|
-
else if (resourceType && id === '$csv') {
|
|
17023
|
-
return core.allOk;
|
|
17024
|
-
}
|
|
17025
|
-
else if (resourceType && id) {
|
|
17026
|
-
return this.mockRepo.readResource(resourceType, id);
|
|
17027
|
-
}
|
|
17028
|
-
else if (resourceType) {
|
|
17029
|
-
return this.mockRepo.search(core.parseSearchDefinition(url));
|
|
17030
|
-
}
|
|
17040
|
+
else if (resourceType && id && operation === '_history') {
|
|
17041
|
+
return this.mockRepo.readHistory(resourceType, id);
|
|
17031
17042
|
}
|
|
17032
|
-
else if (
|
|
17033
|
-
return
|
|
17043
|
+
else if (resourceType && id === '$csv') {
|
|
17044
|
+
return core.allOk;
|
|
17034
17045
|
}
|
|
17035
|
-
else if (
|
|
17036
|
-
|
|
17037
|
-
return this.mockRepo.patchResource(resourceType, id, JSON.parse(options.body));
|
|
17038
|
-
}
|
|
17046
|
+
else if (resourceType && id) {
|
|
17047
|
+
return this.mockRepo.readResource(resourceType, id);
|
|
17039
17048
|
}
|
|
17040
|
-
else if (
|
|
17041
|
-
|
|
17042
|
-
this.mockRepo.deleteResource(resourceType, id);
|
|
17043
|
-
return core.allOk;
|
|
17044
|
-
}
|
|
17049
|
+
else if (resourceType) {
|
|
17050
|
+
return this.mockRepo.search(core.parseSearchDefinition(url));
|
|
17045
17051
|
}
|
|
17046
|
-
|
|
17047
|
-
|
|
17052
|
+
}
|
|
17053
|
+
else if (method === 'PUT') {
|
|
17054
|
+
return this.mockRepo.updateResource(JSON.parse(options.body));
|
|
17055
|
+
}
|
|
17056
|
+
else if (method === 'PATCH') {
|
|
17057
|
+
if (resourceType && id) {
|
|
17058
|
+
return this.mockRepo.patchResource(resourceType, id, JSON.parse(options.body));
|
|
17059
|
+
}
|
|
17060
|
+
}
|
|
17061
|
+
else if (method === 'DELETE') {
|
|
17062
|
+
if (resourceType && id) {
|
|
17063
|
+
this.mockRepo.deleteResource(resourceType, id);
|
|
17064
|
+
return core.allOk;
|
|
17065
|
+
}
|
|
17066
|
+
}
|
|
17067
|
+
throw core.notFound;
|
|
17048
17068
|
}
|
|
17049
17069
|
mockFhirGraphqlHandler(_method, _path, options) {
|
|
17050
17070
|
const { body } = options;
|
|
@@ -17052,70 +17072,68 @@
|
|
|
17052
17072
|
return {
|
|
17053
17073
|
data: {
|
|
17054
17074
|
ResourceList: [
|
|
17055
|
-
|
|
17075
|
+
{
|
|
17076
|
+
...HomerServiceRequest,
|
|
17077
|
+
ObservationList: [
|
|
17056
17078
|
HomerObservation1,
|
|
17057
17079
|
HomerObservation2,
|
|
17058
17080
|
HomerObservation3,
|
|
17059
17081
|
HomerObservation4,
|
|
17060
17082
|
HomerObservation5,
|
|
17061
17083
|
HomerObservation6,
|
|
17062
|
-
]
|
|
17084
|
+
],
|
|
17085
|
+
},
|
|
17063
17086
|
],
|
|
17064
17087
|
},
|
|
17065
17088
|
};
|
|
17066
17089
|
}
|
|
17067
17090
|
return GraphQLSchemaResponse;
|
|
17068
17091
|
}
|
|
17069
|
-
mockFhirBatchHandler(_method, _path, options) {
|
|
17070
|
-
|
|
17071
|
-
|
|
17072
|
-
|
|
17073
|
-
|
|
17074
|
-
|
|
17075
|
-
|
|
17076
|
-
|
|
17077
|
-
entry.push(yield this.handleBatchEntry(input));
|
|
17078
|
-
}
|
|
17092
|
+
async mockFhirBatchHandler(_method, _path, options) {
|
|
17093
|
+
const { body } = options;
|
|
17094
|
+
const request = JSON.parse(body);
|
|
17095
|
+
let entry;
|
|
17096
|
+
if (request.entry) {
|
|
17097
|
+
entry = [];
|
|
17098
|
+
for (const input of request.entry) {
|
|
17099
|
+
entry.push(await this.handleBatchEntry(input));
|
|
17079
17100
|
}
|
|
17080
|
-
|
|
17081
|
-
|
|
17082
|
-
|
|
17083
|
-
|
|
17084
|
-
|
|
17085
|
-
}
|
|
17101
|
+
}
|
|
17102
|
+
return {
|
|
17103
|
+
resourceType: 'Bundle',
|
|
17104
|
+
type: 'batch-response',
|
|
17105
|
+
entry,
|
|
17106
|
+
};
|
|
17086
17107
|
}
|
|
17087
|
-
handleBatchEntry(input) {
|
|
17088
|
-
|
|
17089
|
-
|
|
17090
|
-
|
|
17091
|
-
|
|
17092
|
-
|
|
17093
|
-
|
|
17094
|
-
|
|
17095
|
-
});
|
|
17096
|
-
if ((resource === null || resource === void 0 ? void 0 : resource.resourceType) === 'OperationOutcome') {
|
|
17097
|
-
return {
|
|
17098
|
-
resource,
|
|
17099
|
-
response: { status: core.getStatus(resource).toString() },
|
|
17100
|
-
};
|
|
17101
|
-
}
|
|
17102
|
-
else if (resource) {
|
|
17103
|
-
return { resource, response: { status: '200' } };
|
|
17104
|
-
}
|
|
17105
|
-
else {
|
|
17106
|
-
return { resource: core.notFound, response: { status: '404' } };
|
|
17107
|
-
}
|
|
17108
|
-
}
|
|
17109
|
-
catch (err) {
|
|
17110
|
-
const outcome = err;
|
|
17108
|
+
async handleBatchEntry(input) {
|
|
17109
|
+
try {
|
|
17110
|
+
const url = 'fhir/R4/' + input.request?.url;
|
|
17111
|
+
const method = input.request?.method;
|
|
17112
|
+
const resource = await this.mockHandler(method, url, {
|
|
17113
|
+
body: input.resource ? JSON.stringify(input.resource) : undefined,
|
|
17114
|
+
});
|
|
17115
|
+
if (resource?.resourceType === 'OperationOutcome') {
|
|
17111
17116
|
return {
|
|
17112
|
-
|
|
17113
|
-
|
|
17114
|
-
outcome,
|
|
17115
|
-
},
|
|
17117
|
+
resource,
|
|
17118
|
+
response: { status: core.getStatus(resource).toString() },
|
|
17116
17119
|
};
|
|
17117
17120
|
}
|
|
17118
|
-
|
|
17121
|
+
else if (resource) {
|
|
17122
|
+
return { resource, response: { status: '200' } };
|
|
17123
|
+
}
|
|
17124
|
+
else {
|
|
17125
|
+
return { resource: core.notFound, response: { status: '404' } };
|
|
17126
|
+
}
|
|
17127
|
+
}
|
|
17128
|
+
catch (err) {
|
|
17129
|
+
const outcome = err;
|
|
17130
|
+
return {
|
|
17131
|
+
response: {
|
|
17132
|
+
status: core.getStatus(outcome).toString(),
|
|
17133
|
+
outcome,
|
|
17134
|
+
},
|
|
17135
|
+
};
|
|
17136
|
+
}
|
|
17119
17137
|
}
|
|
17120
17138
|
}
|
|
17121
17139
|
|
|
@@ -17170,4 +17188,4 @@
|
|
|
17170
17188
|
exports.exampleValueSet = exampleValueSet;
|
|
17171
17189
|
|
|
17172
17190
|
}));
|
|
17173
|
-
//# sourceMappingURL=index.
|
|
17191
|
+
//# sourceMappingURL=index.cjs.map
|