@medplum/mock 1.0.5 → 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} +201 -231
- package/dist/cjs/index.cjs.map +1 -0
- package/dist/cjs/index.min.cjs +2 -0
- package/dist/cjs/index.min.cjs.map +1 -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} +199 -228
- package/dist/esm/index.mjs.map +1 -0
- package/dist/esm/repo.d.ts +1 -2
- 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 +0 -2
- package/dist/esm/index.min.js.map +0 -1
package/README.md
CHANGED
|
@@ -17,6 +17,7 @@ npm install @medplum/mock
|
|
|
17
17
|
```
|
|
18
18
|
|
|
19
19
|
Note the following peer dependencies:
|
|
20
|
+
|
|
20
21
|
- [@medplum/core](https://www.npmjs.com/package/@medplum/core)
|
|
21
22
|
|
|
22
23
|
## Usage
|
|
@@ -33,7 +34,7 @@ Read a `Patient` resource:
|
|
|
33
34
|
const patient = await client.readResource('Patient', '123');
|
|
34
35
|
```
|
|
35
36
|
|
|
36
|
-
`MockClient` is API compatible with `MedplumClient` in [@medplum/core](https://www.npmjs.com/package/@medplum/core).
|
|
37
|
+
`MockClient` is API compatible with `MedplumClient` in [@medplum/core](https://www.npmjs.com/package/@medplum/core). Please refer to `MedplumClient` for full documentation on client capabilities.
|
|
37
38
|
|
|
38
39
|
## About Medplum
|
|
39
40
|
|
|
@@ -41,4 +42,4 @@ Medplum is a healthcare platform that helps you quickly develop high-quality com
|
|
|
41
42
|
|
|
42
43
|
## License
|
|
43
44
|
|
|
44
|
-
Apache 2.0. Copyright © Medplum
|
|
45
|
+
Apache 2.0. Copyright © Medplum 2023
|
|
@@ -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',
|
|
@@ -16555,6 +16517,34 @@
|
|
|
16555
16517
|
launchUri: 'https://inferno.healthit.gov/suites/custom/smart/launch',
|
|
16556
16518
|
};
|
|
16557
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
|
+
|
|
16558
16548
|
var _MemoryRepository_resources, _MemoryRepository_history;
|
|
16559
16549
|
class MemoryRepository {
|
|
16560
16550
|
constructor() {
|
|
@@ -16564,7 +16554,6 @@
|
|
|
16564
16554
|
__classPrivateFieldSet(this, _MemoryRepository_history, {}, "f");
|
|
16565
16555
|
}
|
|
16566
16556
|
createResource(resource) {
|
|
16567
|
-
var _a, _b;
|
|
16568
16557
|
const result = core.deepClone(resource);
|
|
16569
16558
|
if (!result.id) {
|
|
16570
16559
|
result.id = this.generateId();
|
|
@@ -16572,10 +16561,10 @@
|
|
|
16572
16561
|
if (!result.meta) {
|
|
16573
16562
|
result.meta = {};
|
|
16574
16563
|
}
|
|
16575
|
-
if (!
|
|
16564
|
+
if (!result.meta?.versionId) {
|
|
16576
16565
|
result.meta.versionId = this.generateId();
|
|
16577
16566
|
}
|
|
16578
|
-
if (!
|
|
16567
|
+
if (!result.meta?.lastUpdated) {
|
|
16579
16568
|
result.meta.lastUpdated = new Date().toISOString();
|
|
16580
16569
|
}
|
|
16581
16570
|
const { resourceType, id } = result;
|
|
@@ -16604,56 +16593,48 @@
|
|
|
16604
16593
|
}
|
|
16605
16594
|
return this.createResource(result);
|
|
16606
16595
|
}
|
|
16607
|
-
patchResource(resourceType, id, patch) {
|
|
16608
|
-
|
|
16609
|
-
|
|
16610
|
-
|
|
16611
|
-
|
|
16612
|
-
|
|
16613
|
-
|
|
16614
|
-
|
|
16615
|
-
|
|
16616
|
-
|
|
16617
|
-
|
|
16618
|
-
|
|
16619
|
-
|
|
16620
|
-
}
|
|
16621
|
-
const patchedResource = patchResult.newDocument;
|
|
16622
|
-
return this.updateResource(patchedResource);
|
|
16623
|
-
});
|
|
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);
|
|
16624
16609
|
}
|
|
16625
16610
|
readResource(resourceType, id) {
|
|
16626
|
-
|
|
16627
|
-
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];
|
|
16628
16612
|
if (!resource) {
|
|
16629
16613
|
throw core.notFound;
|
|
16630
16614
|
}
|
|
16631
16615
|
return core.deepClone(resource);
|
|
16632
16616
|
}
|
|
16633
16617
|
readHistory(resourceType, id) {
|
|
16634
|
-
var _a, _b, _c;
|
|
16635
16618
|
this.readResource(resourceType, id);
|
|
16636
16619
|
return {
|
|
16637
16620
|
resourceType: 'Bundle',
|
|
16638
16621
|
type: 'history',
|
|
16639
|
-
entry: (
|
|
16622
|
+
entry: (__classPrivateFieldGet(this, _MemoryRepository_history, "f")?.[resourceType]?.[id] ?? [])
|
|
16640
16623
|
.reverse()
|
|
16641
16624
|
.map((version) => ({ resource: core.deepClone(version) })),
|
|
16642
16625
|
};
|
|
16643
16626
|
}
|
|
16644
16627
|
readVersion(resourceType, id, versionId) {
|
|
16645
|
-
var _a, _b, _c;
|
|
16646
16628
|
this.readResource(resourceType, id);
|
|
16647
|
-
const version =
|
|
16629
|
+
const version = __classPrivateFieldGet(this, _MemoryRepository_history, "f")?.[resourceType]?.[id]?.find((v) => v.meta?.versionId === versionId);
|
|
16648
16630
|
if (!version) {
|
|
16649
16631
|
throw core.notFound;
|
|
16650
16632
|
}
|
|
16651
16633
|
return core.deepClone(version);
|
|
16652
16634
|
}
|
|
16653
16635
|
search(searchRequest) {
|
|
16654
|
-
var _a;
|
|
16655
16636
|
const { resourceType } = searchRequest;
|
|
16656
|
-
const resources =
|
|
16637
|
+
const resources = __classPrivateFieldGet(this, _MemoryRepository_resources, "f")[resourceType] ?? {};
|
|
16657
16638
|
const result = Object.values(resources).filter((resource) => core.matchesSearchRequest(resource, searchRequest));
|
|
16658
16639
|
return {
|
|
16659
16640
|
resourceType: 'Bundle',
|
|
@@ -16663,8 +16644,7 @@
|
|
|
16663
16644
|
};
|
|
16664
16645
|
}
|
|
16665
16646
|
deleteResource(resourceType, id) {
|
|
16666
|
-
|
|
16667
|
-
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]) {
|
|
16668
16648
|
delete __classPrivateFieldGet(this, _MemoryRepository_resources, "f")[resourceType][id];
|
|
16669
16649
|
}
|
|
16670
16650
|
}
|
|
@@ -16684,7 +16664,7 @@
|
|
|
16684
16664
|
|
|
16685
16665
|
class MockClient extends core.MedplumClient {
|
|
16686
16666
|
constructor(clientOptions) {
|
|
16687
|
-
const mockFetchClient = new MockFetchClient(clientOptions
|
|
16667
|
+
const mockFetchClient = new MockFetchClient(clientOptions?.debug);
|
|
16688
16668
|
super({
|
|
16689
16669
|
baseUrl: 'https://example.com/',
|
|
16690
16670
|
clientId: 'my-client-id',
|
|
@@ -16693,7 +16673,7 @@
|
|
|
16693
16673
|
return mockFetchClient.mockFetch(url, options);
|
|
16694
16674
|
},
|
|
16695
16675
|
});
|
|
16696
|
-
this.debug = !!
|
|
16676
|
+
this.debug = !!clientOptions?.debug;
|
|
16697
16677
|
}
|
|
16698
16678
|
clear() {
|
|
16699
16679
|
super.clear();
|
|
@@ -16729,22 +16709,20 @@
|
|
|
16729
16709
|
}
|
|
16730
16710
|
return super.getActiveLogin();
|
|
16731
16711
|
}
|
|
16732
|
-
createBinary(data, filename, contentType, onProgress) {
|
|
16733
|
-
|
|
16734
|
-
|
|
16735
|
-
|
|
16736
|
-
|
|
16737
|
-
|
|
16738
|
-
|
|
16739
|
-
|
|
16740
|
-
|
|
16741
|
-
|
|
16742
|
-
|
|
16743
|
-
|
|
16744
|
-
|
|
16745
|
-
|
|
16746
|
-
};
|
|
16747
|
-
});
|
|
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
|
+
};
|
|
16748
16726
|
}
|
|
16749
16727
|
}
|
|
16750
16728
|
class MockFetchClient {
|
|
@@ -16753,28 +16731,26 @@
|
|
|
16753
16731
|
this.mockRepo = new MemoryRepository();
|
|
16754
16732
|
this.initMockRepo();
|
|
16755
16733
|
}
|
|
16756
|
-
mockFetch(url, options) {
|
|
16757
|
-
|
|
16758
|
-
|
|
16759
|
-
|
|
16760
|
-
|
|
16761
|
-
|
|
16762
|
-
|
|
16763
|
-
|
|
16764
|
-
|
|
16765
|
-
|
|
16766
|
-
|
|
16767
|
-
|
|
16768
|
-
|
|
16769
|
-
|
|
16770
|
-
|
|
16771
|
-
|
|
16772
|
-
|
|
16773
|
-
|
|
16774
|
-
|
|
16775
|
-
|
|
16776
|
-
json: () => Promise.resolve(response),
|
|
16777
|
-
});
|
|
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),
|
|
16778
16754
|
});
|
|
16779
16755
|
}
|
|
16780
16756
|
mockCreatePdf(docDefinition, tableLayouts, fonts) {
|
|
@@ -16786,24 +16762,22 @@
|
|
|
16786
16762
|
}
|
|
16787
16763
|
return Promise.resolve({});
|
|
16788
16764
|
}
|
|
16789
|
-
mockHandler(method, path, options) {
|
|
16790
|
-
|
|
16791
|
-
|
|
16792
|
-
|
|
16793
|
-
|
|
16794
|
-
|
|
16795
|
-
|
|
16796
|
-
|
|
16797
|
-
|
|
16798
|
-
|
|
16799
|
-
|
|
16800
|
-
|
|
16801
|
-
|
|
16802
|
-
|
|
16803
|
-
|
|
16804
|
-
|
|
16805
|
-
}
|
|
16806
|
-
});
|
|
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
|
+
}
|
|
16807
16781
|
}
|
|
16808
16782
|
mockAdminHandler(_method, path) {
|
|
16809
16783
|
if (path.startsWith('admin/projects/123')) {
|
|
@@ -17032,67 +17006,65 @@
|
|
|
17032
17006
|
this.mockRepo.createResource(ExampleSmartClientApplication);
|
|
17033
17007
|
DrAliceSmithSlots.forEach((slot) => this.mockRepo.createResource(slot));
|
|
17034
17008
|
}
|
|
17035
|
-
mockFhirHandler(method, url, options) {
|
|
17036
|
-
|
|
17037
|
-
|
|
17038
|
-
|
|
17039
|
-
|
|
17040
|
-
|
|
17041
|
-
|
|
17042
|
-
|
|
17043
|
-
|
|
17044
|
-
|
|
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;
|
|
17045
17028
|
}
|
|
17046
|
-
else if (
|
|
17047
|
-
return this.
|
|
17029
|
+
else if (resourceType) {
|
|
17030
|
+
return this.mockRepo.createResource(JSON.parse(options.body));
|
|
17048
17031
|
}
|
|
17049
|
-
else
|
|
17050
|
-
return
|
|
17032
|
+
else {
|
|
17033
|
+
return this.mockFhirBatchHandler(method, path, options);
|
|
17051
17034
|
}
|
|
17052
|
-
|
|
17053
|
-
|
|
17054
|
-
|
|
17055
|
-
|
|
17056
|
-
else if (resourceType) {
|
|
17057
|
-
return this.mockRepo.createResource(JSON.parse(options.body));
|
|
17058
|
-
}
|
|
17059
|
-
else {
|
|
17060
|
-
return this.mockFhirBatchHandler(method, path, options);
|
|
17061
|
-
}
|
|
17035
|
+
}
|
|
17036
|
+
else if (method === 'GET') {
|
|
17037
|
+
if (resourceType && id && versionId) {
|
|
17038
|
+
return this.mockRepo.readVersion(resourceType, id, versionId);
|
|
17062
17039
|
}
|
|
17063
|
-
else if (
|
|
17064
|
-
|
|
17065
|
-
return this.mockRepo.readVersion(resourceType, id, versionId);
|
|
17066
|
-
}
|
|
17067
|
-
else if (resourceType && id && operation === '_history') {
|
|
17068
|
-
return this.mockRepo.readHistory(resourceType, id);
|
|
17069
|
-
}
|
|
17070
|
-
else if (resourceType && id === '$csv') {
|
|
17071
|
-
return core.allOk;
|
|
17072
|
-
}
|
|
17073
|
-
else if (resourceType && id) {
|
|
17074
|
-
return this.mockRepo.readResource(resourceType, id);
|
|
17075
|
-
}
|
|
17076
|
-
else if (resourceType) {
|
|
17077
|
-
return this.mockRepo.search(core.parseSearchDefinition(url));
|
|
17078
|
-
}
|
|
17040
|
+
else if (resourceType && id && operation === '_history') {
|
|
17041
|
+
return this.mockRepo.readHistory(resourceType, id);
|
|
17079
17042
|
}
|
|
17080
|
-
else if (
|
|
17081
|
-
return
|
|
17043
|
+
else if (resourceType && id === '$csv') {
|
|
17044
|
+
return core.allOk;
|
|
17082
17045
|
}
|
|
17083
|
-
else if (
|
|
17084
|
-
|
|
17085
|
-
return this.mockRepo.patchResource(resourceType, id, JSON.parse(options.body));
|
|
17086
|
-
}
|
|
17046
|
+
else if (resourceType && id) {
|
|
17047
|
+
return this.mockRepo.readResource(resourceType, id);
|
|
17087
17048
|
}
|
|
17088
|
-
else if (
|
|
17089
|
-
|
|
17090
|
-
this.mockRepo.deleteResource(resourceType, id);
|
|
17091
|
-
return core.allOk;
|
|
17092
|
-
}
|
|
17049
|
+
else if (resourceType) {
|
|
17050
|
+
return this.mockRepo.search(core.parseSearchDefinition(url));
|
|
17093
17051
|
}
|
|
17094
|
-
|
|
17095
|
-
|
|
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;
|
|
17096
17068
|
}
|
|
17097
17069
|
mockFhirGraphqlHandler(_method, _path, options) {
|
|
17098
17070
|
const { body } = options;
|
|
@@ -17100,70 +17072,68 @@
|
|
|
17100
17072
|
return {
|
|
17101
17073
|
data: {
|
|
17102
17074
|
ResourceList: [
|
|
17103
|
-
|
|
17075
|
+
{
|
|
17076
|
+
...HomerServiceRequest,
|
|
17077
|
+
ObservationList: [
|
|
17104
17078
|
HomerObservation1,
|
|
17105
17079
|
HomerObservation2,
|
|
17106
17080
|
HomerObservation3,
|
|
17107
17081
|
HomerObservation4,
|
|
17108
17082
|
HomerObservation5,
|
|
17109
17083
|
HomerObservation6,
|
|
17110
|
-
]
|
|
17084
|
+
],
|
|
17085
|
+
},
|
|
17111
17086
|
],
|
|
17112
17087
|
},
|
|
17113
17088
|
};
|
|
17114
17089
|
}
|
|
17115
17090
|
return GraphQLSchemaResponse;
|
|
17116
17091
|
}
|
|
17117
|
-
mockFhirBatchHandler(_method, _path, options) {
|
|
17118
|
-
|
|
17119
|
-
|
|
17120
|
-
|
|
17121
|
-
|
|
17122
|
-
|
|
17123
|
-
|
|
17124
|
-
|
|
17125
|
-
entry.push(yield this.handleBatchEntry(input));
|
|
17126
|
-
}
|
|
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));
|
|
17127
17100
|
}
|
|
17128
|
-
|
|
17129
|
-
|
|
17130
|
-
|
|
17131
|
-
|
|
17132
|
-
|
|
17133
|
-
}
|
|
17101
|
+
}
|
|
17102
|
+
return {
|
|
17103
|
+
resourceType: 'Bundle',
|
|
17104
|
+
type: 'batch-response',
|
|
17105
|
+
entry,
|
|
17106
|
+
};
|
|
17134
17107
|
}
|
|
17135
|
-
handleBatchEntry(input) {
|
|
17136
|
-
|
|
17137
|
-
|
|
17138
|
-
|
|
17139
|
-
|
|
17140
|
-
|
|
17141
|
-
|
|
17142
|
-
|
|
17143
|
-
});
|
|
17144
|
-
if ((resource === null || resource === void 0 ? void 0 : resource.resourceType) === 'OperationOutcome') {
|
|
17145
|
-
return {
|
|
17146
|
-
resource,
|
|
17147
|
-
response: { status: core.getStatus(resource).toString() },
|
|
17148
|
-
};
|
|
17149
|
-
}
|
|
17150
|
-
else if (resource) {
|
|
17151
|
-
return { resource, response: { status: '200' } };
|
|
17152
|
-
}
|
|
17153
|
-
else {
|
|
17154
|
-
return { resource: core.notFound, response: { status: '404' } };
|
|
17155
|
-
}
|
|
17156
|
-
}
|
|
17157
|
-
catch (err) {
|
|
17158
|
-
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') {
|
|
17159
17116
|
return {
|
|
17160
|
-
|
|
17161
|
-
|
|
17162
|
-
outcome,
|
|
17163
|
-
},
|
|
17117
|
+
resource,
|
|
17118
|
+
response: { status: core.getStatus(resource).toString() },
|
|
17164
17119
|
};
|
|
17165
17120
|
}
|
|
17166
|
-
|
|
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
|
+
}
|
|
17167
17137
|
}
|
|
17168
17138
|
}
|
|
17169
17139
|
|
|
@@ -17218,4 +17188,4 @@
|
|
|
17218
17188
|
exports.exampleValueSet = exampleValueSet;
|
|
17219
17189
|
|
|
17220
17190
|
}));
|
|
17221
|
-
//# sourceMappingURL=index.
|
|
17191
|
+
//# sourceMappingURL=index.cjs.map
|