@medplum/mock 0.9.29 → 0.9.32
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/index.js +436 -161
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/index.min.js +1 -1
- package/dist/cjs/index.min.js.map +1 -1
- package/dist/cjs/mocks/types.d.ts +2 -18
- package/dist/cjs/repo.d.ts +3 -2
- package/dist/esm/index.js +433 -159
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/index.min.js +1 -1
- package/dist/esm/index.min.js.map +1 -1
- package/dist/esm/mocks/types.d.ts +2 -18
- package/dist/esm/repo.d.ts +3 -2
- package/dist/types/mocks/types.d.ts +2 -18
- package/dist/types/repo.d.ts +3 -2
- package/package.json +4 -4
package/dist/cjs/index.js
CHANGED
|
@@ -1,8 +1,46 @@
|
|
|
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'
|
|
4
|
-
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory((global.medplum = global.medplum || {}, global.medplum.mock = {}), global.medplum.core
|
|
5
|
-
})(this, (function (exports, core
|
|
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
|
+
}
|
|
6
44
|
|
|
7
45
|
const ExampleAccessPolicy = {
|
|
8
46
|
resourceType: 'AccessPolicy',
|
|
@@ -6718,10 +6756,256 @@
|
|
|
6718
6756
|
]
|
|
6719
6757
|
}
|
|
6720
6758
|
},
|
|
6759
|
+
{
|
|
6760
|
+
resourceType: "StructureDefinition",
|
|
6761
|
+
id: "Project",
|
|
6762
|
+
name: "Project",
|
|
6763
|
+
type: "Project",
|
|
6764
|
+
snapshot: {
|
|
6765
|
+
element: [
|
|
6766
|
+
{
|
|
6767
|
+
id: "Project.id",
|
|
6768
|
+
path: "Project.id",
|
|
6769
|
+
min: 0,
|
|
6770
|
+
max: "1",
|
|
6771
|
+
type: [
|
|
6772
|
+
{
|
|
6773
|
+
code: "string"
|
|
6774
|
+
}
|
|
6775
|
+
]
|
|
6776
|
+
},
|
|
6777
|
+
{
|
|
6778
|
+
id: "Project.meta",
|
|
6779
|
+
path: "Project.meta",
|
|
6780
|
+
min: 0,
|
|
6781
|
+
max: "1",
|
|
6782
|
+
type: [
|
|
6783
|
+
{
|
|
6784
|
+
code: "Meta"
|
|
6785
|
+
}
|
|
6786
|
+
]
|
|
6787
|
+
},
|
|
6788
|
+
{
|
|
6789
|
+
id: "Project.implicitRules",
|
|
6790
|
+
path: "Project.implicitRules",
|
|
6791
|
+
min: 0,
|
|
6792
|
+
max: "1",
|
|
6793
|
+
type: [
|
|
6794
|
+
{
|
|
6795
|
+
code: "uri"
|
|
6796
|
+
}
|
|
6797
|
+
]
|
|
6798
|
+
},
|
|
6799
|
+
{
|
|
6800
|
+
id: "Project.language",
|
|
6801
|
+
path: "Project.language",
|
|
6802
|
+
min: 0,
|
|
6803
|
+
max: "1",
|
|
6804
|
+
type: [
|
|
6805
|
+
{
|
|
6806
|
+
code: "code"
|
|
6807
|
+
}
|
|
6808
|
+
]
|
|
6809
|
+
},
|
|
6810
|
+
{
|
|
6811
|
+
id: "Project.name",
|
|
6812
|
+
path: "Project.name",
|
|
6813
|
+
min: 0,
|
|
6814
|
+
max: "1",
|
|
6815
|
+
type: [
|
|
6816
|
+
{
|
|
6817
|
+
code: "string"
|
|
6818
|
+
}
|
|
6819
|
+
]
|
|
6820
|
+
},
|
|
6821
|
+
{
|
|
6822
|
+
id: "Project.description",
|
|
6823
|
+
path: "Project.description",
|
|
6824
|
+
min: 0,
|
|
6825
|
+
max: "1",
|
|
6826
|
+
type: [
|
|
6827
|
+
{
|
|
6828
|
+
code: "string"
|
|
6829
|
+
}
|
|
6830
|
+
]
|
|
6831
|
+
},
|
|
6832
|
+
{
|
|
6833
|
+
id: "Project.superAdmin",
|
|
6834
|
+
path: "Project.superAdmin",
|
|
6835
|
+
min: 0,
|
|
6836
|
+
max: "1",
|
|
6837
|
+
type: [
|
|
6838
|
+
{
|
|
6839
|
+
code: "boolean"
|
|
6840
|
+
}
|
|
6841
|
+
]
|
|
6842
|
+
},
|
|
6843
|
+
{
|
|
6844
|
+
id: "Project.owner",
|
|
6845
|
+
path: "Project.owner",
|
|
6846
|
+
min: 0,
|
|
6847
|
+
max: "1",
|
|
6848
|
+
type: [
|
|
6849
|
+
{
|
|
6850
|
+
code: "Reference",
|
|
6851
|
+
targetProfile: [
|
|
6852
|
+
"https://medplum.com/fhir/StructureDefinition/User"
|
|
6853
|
+
]
|
|
6854
|
+
}
|
|
6855
|
+
]
|
|
6856
|
+
},
|
|
6857
|
+
{
|
|
6858
|
+
id: "Project.features",
|
|
6859
|
+
path: "Project.features",
|
|
6860
|
+
min: 0,
|
|
6861
|
+
max: "*",
|
|
6862
|
+
type: [
|
|
6863
|
+
{
|
|
6864
|
+
code: "code"
|
|
6865
|
+
}
|
|
6866
|
+
]
|
|
6867
|
+
},
|
|
6868
|
+
{
|
|
6869
|
+
id: "Project.defaultPatientAccessPolicy",
|
|
6870
|
+
path: "Project.defaultPatientAccessPolicy",
|
|
6871
|
+
min: 0,
|
|
6872
|
+
max: "1",
|
|
6873
|
+
type: [
|
|
6874
|
+
{
|
|
6875
|
+
code: "Reference",
|
|
6876
|
+
targetProfile: [
|
|
6877
|
+
"https://medplum.com/fhir/StructureDefinition/AccessPolicy"
|
|
6878
|
+
]
|
|
6879
|
+
}
|
|
6880
|
+
]
|
|
6881
|
+
},
|
|
6882
|
+
{
|
|
6883
|
+
id: "Project.secret",
|
|
6884
|
+
path: "Project.secret",
|
|
6885
|
+
min: 0,
|
|
6886
|
+
max: "*",
|
|
6887
|
+
type: [
|
|
6888
|
+
{
|
|
6889
|
+
code: "BackboneElement"
|
|
6890
|
+
}
|
|
6891
|
+
]
|
|
6892
|
+
},
|
|
6893
|
+
{
|
|
6894
|
+
id: "Project.secret.name",
|
|
6895
|
+
path: "Project.secret.name",
|
|
6896
|
+
min: 1,
|
|
6897
|
+
max: "1",
|
|
6898
|
+
type: [
|
|
6899
|
+
{
|
|
6900
|
+
code: "string"
|
|
6901
|
+
}
|
|
6902
|
+
]
|
|
6903
|
+
},
|
|
6904
|
+
{
|
|
6905
|
+
id: "Project.secret.value[x]",
|
|
6906
|
+
path: "Project.secret.value[x]",
|
|
6907
|
+
min: 1,
|
|
6908
|
+
max: "1",
|
|
6909
|
+
type: [
|
|
6910
|
+
{
|
|
6911
|
+
code: "string"
|
|
6912
|
+
},
|
|
6913
|
+
{
|
|
6914
|
+
code: "boolean"
|
|
6915
|
+
},
|
|
6916
|
+
{
|
|
6917
|
+
code: "decimal"
|
|
6918
|
+
},
|
|
6919
|
+
{
|
|
6920
|
+
code: "integer"
|
|
6921
|
+
}
|
|
6922
|
+
]
|
|
6923
|
+
},
|
|
6924
|
+
{
|
|
6925
|
+
id: "Project.site",
|
|
6926
|
+
path: "Project.site",
|
|
6927
|
+
min: 0,
|
|
6928
|
+
max: "*",
|
|
6929
|
+
type: [
|
|
6930
|
+
{
|
|
6931
|
+
code: "BackboneElement"
|
|
6932
|
+
}
|
|
6933
|
+
]
|
|
6934
|
+
},
|
|
6935
|
+
{
|
|
6936
|
+
id: "Project.site.name",
|
|
6937
|
+
path: "Project.site.name",
|
|
6938
|
+
min: 1,
|
|
6939
|
+
max: "1",
|
|
6940
|
+
type: [
|
|
6941
|
+
{
|
|
6942
|
+
code: "string"
|
|
6943
|
+
}
|
|
6944
|
+
]
|
|
6945
|
+
},
|
|
6946
|
+
{
|
|
6947
|
+
id: "Project.site.domain",
|
|
6948
|
+
path: "Project.site.domain",
|
|
6949
|
+
min: 1,
|
|
6950
|
+
max: "*",
|
|
6951
|
+
type: [
|
|
6952
|
+
{
|
|
6953
|
+
code: "string"
|
|
6954
|
+
}
|
|
6955
|
+
]
|
|
6956
|
+
},
|
|
6957
|
+
{
|
|
6958
|
+
id: "Project.site.googleClientId",
|
|
6959
|
+
path: "Project.site.googleClientId",
|
|
6960
|
+
min: 0,
|
|
6961
|
+
max: "1",
|
|
6962
|
+
type: [
|
|
6963
|
+
{
|
|
6964
|
+
code: "string"
|
|
6965
|
+
}
|
|
6966
|
+
]
|
|
6967
|
+
},
|
|
6968
|
+
{
|
|
6969
|
+
id: "Project.site.googleClientSecret",
|
|
6970
|
+
path: "Project.site.googleClientSecret",
|
|
6971
|
+
min: 0,
|
|
6972
|
+
max: "1",
|
|
6973
|
+
type: [
|
|
6974
|
+
{
|
|
6975
|
+
code: "string"
|
|
6976
|
+
}
|
|
6977
|
+
]
|
|
6978
|
+
},
|
|
6979
|
+
{
|
|
6980
|
+
id: "Project.site.recaptchaSiteKey",
|
|
6981
|
+
path: "Project.site.recaptchaSiteKey",
|
|
6982
|
+
min: 0,
|
|
6983
|
+
max: "1",
|
|
6984
|
+
type: [
|
|
6985
|
+
{
|
|
6986
|
+
code: "string"
|
|
6987
|
+
}
|
|
6988
|
+
]
|
|
6989
|
+
},
|
|
6990
|
+
{
|
|
6991
|
+
id: "Project.site.recaptchaSecretKey",
|
|
6992
|
+
path: "Project.site.recaptchaSecretKey",
|
|
6993
|
+
min: 0,
|
|
6994
|
+
max: "1",
|
|
6995
|
+
type: [
|
|
6996
|
+
{
|
|
6997
|
+
code: "string"
|
|
6998
|
+
}
|
|
6999
|
+
]
|
|
7000
|
+
}
|
|
7001
|
+
]
|
|
7002
|
+
}
|
|
7003
|
+
},
|
|
6721
7004
|
{
|
|
6722
7005
|
resourceType: "StructureDefinition",
|
|
6723
7006
|
id: "Bot",
|
|
6724
7007
|
name: "Bot",
|
|
7008
|
+
type: "Bot",
|
|
6725
7009
|
snapshot: {
|
|
6726
7010
|
element: [
|
|
6727
7011
|
{
|
|
@@ -7099,34 +7383,6 @@
|
|
|
7099
7383
|
],
|
|
7100
7384
|
};
|
|
7101
7385
|
|
|
7102
|
-
/******************************************************************************
|
|
7103
|
-
Copyright (c) Microsoft Corporation.
|
|
7104
|
-
|
|
7105
|
-
Permission to use, copy, modify, and/or distribute this software for any
|
|
7106
|
-
purpose with or without fee is hereby granted.
|
|
7107
|
-
|
|
7108
|
-
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
7109
|
-
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
7110
|
-
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
7111
|
-
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
7112
|
-
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
7113
|
-
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
7114
|
-
PERFORMANCE OF THIS SOFTWARE.
|
|
7115
|
-
***************************************************************************** */
|
|
7116
|
-
|
|
7117
|
-
function __classPrivateFieldGet(receiver, state, kind, f) {
|
|
7118
|
-
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
7119
|
-
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");
|
|
7120
|
-
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
7121
|
-
}
|
|
7122
|
-
|
|
7123
|
-
function __classPrivateFieldSet(receiver, state, value, kind, f) {
|
|
7124
|
-
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
7125
|
-
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
7126
|
-
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");
|
|
7127
|
-
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
7128
|
-
}
|
|
7129
|
-
|
|
7130
7386
|
var _MemoryRepository_resources, _MemoryRepository_history;
|
|
7131
7387
|
class MemoryRepository {
|
|
7132
7388
|
constructor() {
|
|
@@ -7178,18 +7434,21 @@
|
|
|
7178
7434
|
}
|
|
7179
7435
|
patchResource(resourceType, id, patch) {
|
|
7180
7436
|
var _a, _b;
|
|
7181
|
-
|
|
7182
|
-
|
|
7183
|
-
|
|
7184
|
-
|
|
7185
|
-
|
|
7186
|
-
|
|
7187
|
-
|
|
7188
|
-
|
|
7189
|
-
|
|
7190
|
-
|
|
7191
|
-
|
|
7192
|
-
|
|
7437
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
7438
|
+
const resource = this.readResource(resourceType, id);
|
|
7439
|
+
let patchResult;
|
|
7440
|
+
try {
|
|
7441
|
+
const { applyPatch } = yield import('fast-json-patch');
|
|
7442
|
+
patchResult = applyPatch(resource, patch, true);
|
|
7443
|
+
}
|
|
7444
|
+
catch (err) {
|
|
7445
|
+
const patchError = err;
|
|
7446
|
+
const message = ((_b = (_a = patchError.message) === null || _a === void 0 ? void 0 : _a.split('\n')) === null || _b === void 0 ? void 0 : _b[0]) || 'JSONPatch error';
|
|
7447
|
+
throw core.badRequest(message);
|
|
7448
|
+
}
|
|
7449
|
+
const patchedResource = patchResult.newDocument;
|
|
7450
|
+
return this.updateResource(patchedResource);
|
|
7451
|
+
});
|
|
7193
7452
|
}
|
|
7194
7453
|
readResource(resourceType, id) {
|
|
7195
7454
|
var _a, _b;
|
|
@@ -7357,25 +7616,27 @@
|
|
|
7357
7616
|
this.initMockRepo();
|
|
7358
7617
|
}
|
|
7359
7618
|
mockFetch(url, options) {
|
|
7360
|
-
|
|
7361
|
-
|
|
7362
|
-
|
|
7363
|
-
|
|
7364
|
-
|
|
7365
|
-
|
|
7366
|
-
|
|
7367
|
-
|
|
7368
|
-
|
|
7369
|
-
|
|
7370
|
-
|
|
7371
|
-
|
|
7372
|
-
|
|
7373
|
-
|
|
7374
|
-
|
|
7375
|
-
|
|
7376
|
-
|
|
7377
|
-
|
|
7378
|
-
|
|
7619
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
7620
|
+
const method = options.method || 'GET';
|
|
7621
|
+
const path = url.replace('https://example.com/', '');
|
|
7622
|
+
if (this.debug) {
|
|
7623
|
+
console.log('MockClient', method, path);
|
|
7624
|
+
}
|
|
7625
|
+
const response = yield this.mockHandler(method, path, options);
|
|
7626
|
+
if (this.debug && !response) {
|
|
7627
|
+
console.log('MockClient: not found', method, path);
|
|
7628
|
+
}
|
|
7629
|
+
if (this.debug) {
|
|
7630
|
+
console.log('MockClient', JSON.stringify(response, null, 2));
|
|
7631
|
+
}
|
|
7632
|
+
if ((response === null || response === void 0 ? void 0 : response.resourceType) === 'OperationOutcome' && !core.isOk(response)) {
|
|
7633
|
+
return Promise.reject(response);
|
|
7634
|
+
}
|
|
7635
|
+
return Promise.resolve({
|
|
7636
|
+
ok: true,
|
|
7637
|
+
blob: () => Promise.resolve(response),
|
|
7638
|
+
json: () => Promise.resolve(response),
|
|
7639
|
+
});
|
|
7379
7640
|
});
|
|
7380
7641
|
}
|
|
7381
7642
|
mockCreatePdf(docDefinition, tableLayouts, fonts) {
|
|
@@ -7388,21 +7649,23 @@
|
|
|
7388
7649
|
return Promise.resolve({});
|
|
7389
7650
|
}
|
|
7390
7651
|
mockHandler(method, path, options) {
|
|
7391
|
-
|
|
7392
|
-
|
|
7393
|
-
|
|
7394
|
-
|
|
7395
|
-
|
|
7396
|
-
|
|
7397
|
-
|
|
7398
|
-
|
|
7399
|
-
|
|
7400
|
-
|
|
7401
|
-
|
|
7402
|
-
|
|
7403
|
-
|
|
7404
|
-
|
|
7405
|
-
|
|
7652
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
7653
|
+
if (path.startsWith('admin/')) {
|
|
7654
|
+
return this.mockAdminHandler(method, path);
|
|
7655
|
+
}
|
|
7656
|
+
else if (path.startsWith('auth/')) {
|
|
7657
|
+
return this.mockAuthHandler(method, path, options);
|
|
7658
|
+
}
|
|
7659
|
+
else if (path.startsWith('oauth2/')) {
|
|
7660
|
+
return this.mockOAuthHandler(method, path, options);
|
|
7661
|
+
}
|
|
7662
|
+
else if (path.startsWith('fhir/R4')) {
|
|
7663
|
+
return this.mockFhirHandler(method, path, options);
|
|
7664
|
+
}
|
|
7665
|
+
else {
|
|
7666
|
+
return null;
|
|
7667
|
+
}
|
|
7668
|
+
});
|
|
7406
7669
|
}
|
|
7407
7670
|
mockAdminHandler(_method, path) {
|
|
7408
7671
|
if (path.startsWith('admin/projects/123')) {
|
|
@@ -7597,64 +7860,66 @@
|
|
|
7597
7860
|
DrAliceSmithSlots.forEach((slot) => this.mockRepo.createResource(slot));
|
|
7598
7861
|
}
|
|
7599
7862
|
mockFhirHandler(method, url, options) {
|
|
7600
|
-
|
|
7601
|
-
|
|
7602
|
-
|
|
7603
|
-
|
|
7604
|
-
|
|
7605
|
-
|
|
7606
|
-
|
|
7607
|
-
|
|
7608
|
-
|
|
7609
|
-
else if (path === 'fhir/R4/$graphql') {
|
|
7610
|
-
return this.mockFhirGraphqlHandler(method, path, options);
|
|
7611
|
-
}
|
|
7612
|
-
else if (path === 'not-found' || id === 'not-found') {
|
|
7613
|
-
return core.notFound;
|
|
7614
|
-
}
|
|
7615
|
-
else if (method === 'POST') {
|
|
7616
|
-
if (resourceType && id && operation) {
|
|
7617
|
-
return core.allOk;
|
|
7618
|
-
}
|
|
7619
|
-
else if (resourceType) {
|
|
7620
|
-
return this.mockRepo.createResource(JSON.parse(options.body));
|
|
7863
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
7864
|
+
const path = url.includes('?') ? url.substring(0, url.indexOf('?')) : url;
|
|
7865
|
+
const match = /fhir\/R4\/?([^/]+)?\/?([^/]+)?\/?([^/]+)?\/?([^/]+)?/.exec(path);
|
|
7866
|
+
const resourceType = match === null || match === void 0 ? void 0 : match[1];
|
|
7867
|
+
const id = match === null || match === void 0 ? void 0 : match[2];
|
|
7868
|
+
const operation = match === null || match === void 0 ? void 0 : match[3];
|
|
7869
|
+
const versionId = match === null || match === void 0 ? void 0 : match[4];
|
|
7870
|
+
if (path.startsWith('fhir/R4/ValueSet/$expand')) {
|
|
7871
|
+
return exampleValueSet;
|
|
7621
7872
|
}
|
|
7622
|
-
else {
|
|
7623
|
-
return this.
|
|
7624
|
-
}
|
|
7625
|
-
}
|
|
7626
|
-
else if (method === 'GET') {
|
|
7627
|
-
if (resourceType && id && versionId) {
|
|
7628
|
-
return this.mockRepo.readVersion(resourceType, id, versionId);
|
|
7873
|
+
else if (path === 'fhir/R4/$graphql') {
|
|
7874
|
+
return this.mockFhirGraphqlHandler(method, path, options);
|
|
7629
7875
|
}
|
|
7630
|
-
else if (
|
|
7631
|
-
return
|
|
7876
|
+
else if (path === 'not-found' || id === 'not-found') {
|
|
7877
|
+
return core.notFound;
|
|
7632
7878
|
}
|
|
7633
|
-
else if (
|
|
7634
|
-
|
|
7879
|
+
else if (method === 'POST') {
|
|
7880
|
+
if (resourceType && id && operation) {
|
|
7881
|
+
return core.allOk;
|
|
7882
|
+
}
|
|
7883
|
+
else if (resourceType) {
|
|
7884
|
+
return this.mockRepo.createResource(JSON.parse(options.body));
|
|
7885
|
+
}
|
|
7886
|
+
else {
|
|
7887
|
+
return this.mockFhirBatchHandler(method, path, options);
|
|
7888
|
+
}
|
|
7635
7889
|
}
|
|
7636
|
-
else if (
|
|
7637
|
-
|
|
7890
|
+
else if (method === 'GET') {
|
|
7891
|
+
if (resourceType && id && versionId) {
|
|
7892
|
+
return this.mockRepo.readVersion(resourceType, id, versionId);
|
|
7893
|
+
}
|
|
7894
|
+
else if (resourceType && id && operation === '_history') {
|
|
7895
|
+
return this.mockRepo.readHistory(resourceType, id);
|
|
7896
|
+
}
|
|
7897
|
+
else if (resourceType && id === '$csv') {
|
|
7898
|
+
return core.allOk;
|
|
7899
|
+
}
|
|
7900
|
+
else if (resourceType && id) {
|
|
7901
|
+
return this.mockRepo.readResource(resourceType, id);
|
|
7902
|
+
}
|
|
7903
|
+
else if (resourceType) {
|
|
7904
|
+
return this.mockRepo.search(core.parseSearchDefinition(url));
|
|
7905
|
+
}
|
|
7638
7906
|
}
|
|
7639
|
-
else if (
|
|
7640
|
-
return this.mockRepo.
|
|
7907
|
+
else if (method === 'PUT') {
|
|
7908
|
+
return this.mockRepo.updateResource(JSON.parse(options.body));
|
|
7641
7909
|
}
|
|
7642
|
-
|
|
7643
|
-
|
|
7644
|
-
|
|
7645
|
-
|
|
7646
|
-
else if (method === 'PATCH') {
|
|
7647
|
-
if (resourceType && id) {
|
|
7648
|
-
return this.mockRepo.patchResource(resourceType, id, JSON.parse(options.body));
|
|
7910
|
+
else if (method === 'PATCH') {
|
|
7911
|
+
if (resourceType && id) {
|
|
7912
|
+
return this.mockRepo.patchResource(resourceType, id, JSON.parse(options.body));
|
|
7913
|
+
}
|
|
7649
7914
|
}
|
|
7650
|
-
|
|
7651
|
-
|
|
7652
|
-
|
|
7653
|
-
|
|
7654
|
-
|
|
7915
|
+
else if (method === 'DELETE') {
|
|
7916
|
+
if (resourceType && id) {
|
|
7917
|
+
this.mockRepo.deleteResource(resourceType, id);
|
|
7918
|
+
return core.allOk;
|
|
7919
|
+
}
|
|
7655
7920
|
}
|
|
7656
|
-
|
|
7657
|
-
|
|
7921
|
+
throw core.notFound;
|
|
7922
|
+
});
|
|
7658
7923
|
}
|
|
7659
7924
|
mockFhirGraphqlHandler(_method, _path, options) {
|
|
7660
7925
|
const { body } = options;
|
|
@@ -7677,45 +7942,55 @@
|
|
|
7677
7942
|
return GraphQLSchemaResponse;
|
|
7678
7943
|
}
|
|
7679
7944
|
mockFhirBatchHandler(_method, _path, options) {
|
|
7680
|
-
|
|
7681
|
-
|
|
7682
|
-
|
|
7683
|
-
|
|
7684
|
-
|
|
7685
|
-
|
|
7686
|
-
|
|
7687
|
-
|
|
7945
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
7946
|
+
const { body } = options;
|
|
7947
|
+
const request = JSON.parse(body);
|
|
7948
|
+
let entry;
|
|
7949
|
+
if (request.entry) {
|
|
7950
|
+
entry = [];
|
|
7951
|
+
for (const input of request.entry) {
|
|
7952
|
+
entry.push(yield this.handleBatchEntry(input));
|
|
7953
|
+
}
|
|
7954
|
+
}
|
|
7955
|
+
return {
|
|
7956
|
+
resourceType: 'Bundle',
|
|
7957
|
+
type: 'batch-response',
|
|
7958
|
+
entry,
|
|
7959
|
+
};
|
|
7960
|
+
});
|
|
7688
7961
|
}
|
|
7689
7962
|
handleBatchEntry(input) {
|
|
7690
7963
|
var _a, _b;
|
|
7691
|
-
|
|
7692
|
-
|
|
7693
|
-
|
|
7694
|
-
|
|
7695
|
-
|
|
7696
|
-
|
|
7697
|
-
|
|
7964
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
7965
|
+
try {
|
|
7966
|
+
const url = 'fhir/R4/' + ((_a = input.request) === null || _a === void 0 ? void 0 : _a.url);
|
|
7967
|
+
const method = (_b = input.request) === null || _b === void 0 ? void 0 : _b.method;
|
|
7968
|
+
const resource = yield this.mockHandler(method, url, {
|
|
7969
|
+
body: input.resource ? JSON.stringify(input.resource) : undefined,
|
|
7970
|
+
});
|
|
7971
|
+
if ((resource === null || resource === void 0 ? void 0 : resource.resourceType) === 'OperationOutcome') {
|
|
7972
|
+
return {
|
|
7973
|
+
resource,
|
|
7974
|
+
response: { status: core.getStatus(resource).toString() },
|
|
7975
|
+
};
|
|
7976
|
+
}
|
|
7977
|
+
else if (resource) {
|
|
7978
|
+
return { resource, response: { status: '200' } };
|
|
7979
|
+
}
|
|
7980
|
+
else {
|
|
7981
|
+
return { resource: core.notFound, response: { status: '404' } };
|
|
7982
|
+
}
|
|
7983
|
+
}
|
|
7984
|
+
catch (err) {
|
|
7985
|
+
const outcome = err;
|
|
7698
7986
|
return {
|
|
7699
|
-
|
|
7700
|
-
|
|
7987
|
+
response: {
|
|
7988
|
+
status: core.getStatus(outcome).toString(),
|
|
7989
|
+
outcome,
|
|
7990
|
+
},
|
|
7701
7991
|
};
|
|
7702
7992
|
}
|
|
7703
|
-
|
|
7704
|
-
return { resource, response: { status: '200' } };
|
|
7705
|
-
}
|
|
7706
|
-
else {
|
|
7707
|
-
return { resource: core.notFound, response: { status: '404' } };
|
|
7708
|
-
}
|
|
7709
|
-
}
|
|
7710
|
-
catch (err) {
|
|
7711
|
-
const outcome = err;
|
|
7712
|
-
return {
|
|
7713
|
-
response: {
|
|
7714
|
-
status: core.getStatus(outcome).toString(),
|
|
7715
|
-
outcome,
|
|
7716
|
-
},
|
|
7717
|
-
};
|
|
7718
|
-
}
|
|
7993
|
+
});
|
|
7719
7994
|
}
|
|
7720
7995
|
}
|
|
7721
7996
|
|