@medplum/mock 1.0.5 → 2.0.0

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 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). Please refer to `MedplumClient` for full documentation on client capabilities.
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 2022
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 (!((_a = result.meta) === null || _a === void 0 ? void 0 : _a.versionId)) {
16564
+ if (!result.meta?.versionId) {
16576
16565
  result.meta.versionId = this.generateId();
16577
16566
  }
16578
- if (!((_b = result.meta) === null || _b === void 0 ? void 0 : _b.lastUpdated)) {
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
- var _a, _b;
16609
- return __awaiter(this, void 0, void 0, function* () {
16610
- const resource = this.readResource(resourceType, id);
16611
- let patchResult;
16612
- try {
16613
- const { applyPatch } = yield import('fast-json-patch');
16614
- patchResult = applyPatch(resource, patch, true);
16615
- }
16616
- catch (err) {
16617
- const patchError = err;
16618
- 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';
16619
- throw core.badRequest(message);
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
- var _a, _b;
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: ((_c = (_b = (_a = __classPrivateFieldGet(this, _MemoryRepository_history, "f")) === null || _a === void 0 ? void 0 : _a[resourceType]) === null || _b === void 0 ? void 0 : _b[id]) !== null && _c !== void 0 ? _c : [])
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 = (_c = (_b = (_a = __classPrivateFieldGet(this, _MemoryRepository_history, "f")) === null || _a === void 0 ? void 0 : _a[resourceType]) === null || _b === void 0 ? void 0 : _b[id]) === null || _c === void 0 ? void 0 : _c.find((v) => { var _a; return ((_a = v.meta) === null || _a === void 0 ? void 0 : _a.versionId) === versionId; });
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 = (_a = __classPrivateFieldGet(this, _MemoryRepository_resources, "f")[resourceType]) !== null && _a !== void 0 ? _a : {};
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
- var _a, _b;
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 === null || clientOptions === void 0 ? void 0 : clientOptions.debug);
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 = !!(clientOptions === null || clientOptions === void 0 ? void 0 : clientOptions.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
- return __awaiter(this, void 0, void 0, function* () {
16734
- if (filename === null || filename === void 0 ? void 0 : filename.endsWith('.exe')) {
16735
- return Promise.reject(core.badRequest('Invalid file type'));
16736
- }
16737
- if (onProgress) {
16738
- onProgress({ loaded: 0, lengthComputable: false });
16739
- onProgress({ loaded: 0, total: 100, lengthComputable: true });
16740
- onProgress({ loaded: 100, total: 100, lengthComputable: true });
16741
- }
16742
- return {
16743
- resourceType: 'Binary',
16744
- contentType,
16745
- url: 'https://example.com/binary/123',
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
- return __awaiter(this, void 0, void 0, function* () {
16758
- const method = options.method || 'GET';
16759
- const path = url.replace('https://example.com/', '');
16760
- if (this.debug) {
16761
- console.log('MockClient', method, path);
16762
- }
16763
- const response = yield this.mockHandler(method, path, options);
16764
- if (this.debug && !response) {
16765
- console.log('MockClient: not found', method, path);
16766
- }
16767
- if (this.debug) {
16768
- console.log('MockClient', JSON.stringify(response, null, 2));
16769
- }
16770
- if ((response === null || response === void 0 ? void 0 : response.resourceType) === 'OperationOutcome' && !core.isOk(response)) {
16771
- return Promise.reject(response);
16772
- }
16773
- return Promise.resolve({
16774
- ok: true,
16775
- blob: () => Promise.resolve(response),
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
- return __awaiter(this, void 0, void 0, function* () {
16791
- if (path.startsWith('admin/')) {
16792
- return this.mockAdminHandler(method, path);
16793
- }
16794
- else if (path.startsWith('auth/')) {
16795
- return this.mockAuthHandler(method, path, options);
16796
- }
16797
- else if (path.startsWith('oauth2/')) {
16798
- return this.mockOAuthHandler(method, path, options);
16799
- }
16800
- else if (path.startsWith('fhir/R4')) {
16801
- return this.mockFhirHandler(method, path, options);
16802
- }
16803
- else {
16804
- return null;
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')) {
@@ -16821,6 +16795,9 @@
16821
16795
  };
16822
16796
  }
16823
16797
  mockAuthHandler(method, path, options) {
16798
+ if (path.startsWith('auth/method')) {
16799
+ return {};
16800
+ }
16824
16801
  if (path.startsWith('auth/changepassword')) {
16825
16802
  return this.mockChangePasswordHandler(method, path, options);
16826
16803
  }
@@ -17032,67 +17009,65 @@
17032
17009
  this.mockRepo.createResource(ExampleSmartClientApplication);
17033
17010
  DrAliceSmithSlots.forEach((slot) => this.mockRepo.createResource(slot));
17034
17011
  }
17035
- mockFhirHandler(method, url, options) {
17036
- return __awaiter(this, void 0, void 0, function* () {
17037
- const path = url.includes('?') ? url.substring(0, url.indexOf('?')) : url;
17038
- const match = /fhir\/R4\/?([^/]+)?\/?([^/]+)?\/?([^/]+)?\/?([^/]+)?/.exec(path);
17039
- const resourceType = match === null || match === void 0 ? void 0 : match[1];
17040
- const id = match === null || match === void 0 ? void 0 : match[2];
17041
- const operation = match === null || match === void 0 ? void 0 : match[3];
17042
- const versionId = match === null || match === void 0 ? void 0 : match[4];
17043
- if (path.startsWith('fhir/R4/ValueSet/$expand')) {
17044
- return exampleValueSet;
17012
+ async mockFhirHandler(method, url, options) {
17013
+ const path = url.includes('?') ? url.substring(0, url.indexOf('?')) : url;
17014
+ const match = /fhir\/R4\/?([^/]+)?\/?([^/]+)?\/?([^/]+)?\/?([^/]+)?/.exec(path);
17015
+ const resourceType = match?.[1];
17016
+ const id = match?.[2];
17017
+ const operation = match?.[3];
17018
+ const versionId = match?.[4];
17019
+ if (path.startsWith('fhir/R4/ValueSet/$expand')) {
17020
+ return exampleValueSet;
17021
+ }
17022
+ else if (path === 'fhir/R4/$graphql') {
17023
+ return this.mockFhirGraphqlHandler(method, path, options);
17024
+ }
17025
+ else if (path === 'not-found' || id === 'not-found') {
17026
+ return core.notFound;
17027
+ }
17028
+ else if (method === 'POST') {
17029
+ if (resourceType && id && operation) {
17030
+ return core.allOk;
17045
17031
  }
17046
- else if (path === 'fhir/R4/$graphql') {
17047
- return this.mockFhirGraphqlHandler(method, path, options);
17032
+ else if (resourceType) {
17033
+ return this.mockRepo.createResource(JSON.parse(options.body));
17048
17034
  }
17049
- else if (path === 'not-found' || id === 'not-found') {
17050
- return core.notFound;
17035
+ else {
17036
+ return this.mockFhirBatchHandler(method, path, options);
17051
17037
  }
17052
- else if (method === 'POST') {
17053
- if (resourceType && id && operation) {
17054
- return core.allOk;
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
- }
17038
+ }
17039
+ else if (method === 'GET') {
17040
+ if (resourceType && id && versionId) {
17041
+ return this.mockRepo.readVersion(resourceType, id, versionId);
17062
17042
  }
17063
- else if (method === 'GET') {
17064
- if (resourceType && id && versionId) {
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
- }
17043
+ else if (resourceType && id && operation === '_history') {
17044
+ return this.mockRepo.readHistory(resourceType, id);
17079
17045
  }
17080
- else if (method === 'PUT') {
17081
- return this.mockRepo.updateResource(JSON.parse(options.body));
17046
+ else if (resourceType && id === '$csv') {
17047
+ return core.allOk;
17082
17048
  }
17083
- else if (method === 'PATCH') {
17084
- if (resourceType && id) {
17085
- return this.mockRepo.patchResource(resourceType, id, JSON.parse(options.body));
17086
- }
17049
+ else if (resourceType && id) {
17050
+ return this.mockRepo.readResource(resourceType, id);
17087
17051
  }
17088
- else if (method === 'DELETE') {
17089
- if (resourceType && id) {
17090
- this.mockRepo.deleteResource(resourceType, id);
17091
- return core.allOk;
17092
- }
17052
+ else if (resourceType) {
17053
+ return this.mockRepo.search(core.parseSearchDefinition(url));
17093
17054
  }
17094
- throw core.notFound;
17095
- });
17055
+ }
17056
+ else if (method === 'PUT') {
17057
+ return this.mockRepo.updateResource(JSON.parse(options.body));
17058
+ }
17059
+ else if (method === 'PATCH') {
17060
+ if (resourceType && id) {
17061
+ return this.mockRepo.patchResource(resourceType, id, JSON.parse(options.body));
17062
+ }
17063
+ }
17064
+ else if (method === 'DELETE') {
17065
+ if (resourceType && id) {
17066
+ this.mockRepo.deleteResource(resourceType, id);
17067
+ return core.allOk;
17068
+ }
17069
+ }
17070
+ throw core.notFound;
17096
17071
  }
17097
17072
  mockFhirGraphqlHandler(_method, _path, options) {
17098
17073
  const { body } = options;
@@ -17100,70 +17075,68 @@
17100
17075
  return {
17101
17076
  data: {
17102
17077
  ResourceList: [
17103
- Object.assign(Object.assign({}, HomerServiceRequest), { ObservationList: [
17078
+ {
17079
+ ...HomerServiceRequest,
17080
+ ObservationList: [
17104
17081
  HomerObservation1,
17105
17082
  HomerObservation2,
17106
17083
  HomerObservation3,
17107
17084
  HomerObservation4,
17108
17085
  HomerObservation5,
17109
17086
  HomerObservation6,
17110
- ] }),
17087
+ ],
17088
+ },
17111
17089
  ],
17112
17090
  },
17113
17091
  };
17114
17092
  }
17115
17093
  return GraphQLSchemaResponse;
17116
17094
  }
17117
- mockFhirBatchHandler(_method, _path, options) {
17118
- return __awaiter(this, void 0, void 0, function* () {
17119
- const { body } = options;
17120
- const request = JSON.parse(body);
17121
- let entry;
17122
- if (request.entry) {
17123
- entry = [];
17124
- for (const input of request.entry) {
17125
- entry.push(yield this.handleBatchEntry(input));
17126
- }
17095
+ async mockFhirBatchHandler(_method, _path, options) {
17096
+ const { body } = options;
17097
+ const request = JSON.parse(body);
17098
+ let entry;
17099
+ if (request.entry) {
17100
+ entry = [];
17101
+ for (const input of request.entry) {
17102
+ entry.push(await this.handleBatchEntry(input));
17127
17103
  }
17128
- return {
17129
- resourceType: 'Bundle',
17130
- type: 'batch-response',
17131
- entry,
17132
- };
17133
- });
17104
+ }
17105
+ return {
17106
+ resourceType: 'Bundle',
17107
+ type: 'batch-response',
17108
+ entry,
17109
+ };
17134
17110
  }
17135
- handleBatchEntry(input) {
17136
- var _a, _b;
17137
- return __awaiter(this, void 0, void 0, function* () {
17138
- try {
17139
- const url = 'fhir/R4/' + ((_a = input.request) === null || _a === void 0 ? void 0 : _a.url);
17140
- const method = (_b = input.request) === null || _b === void 0 ? void 0 : _b.method;
17141
- const resource = yield this.mockHandler(method, url, {
17142
- body: input.resource ? JSON.stringify(input.resource) : undefined,
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;
17111
+ async handleBatchEntry(input) {
17112
+ try {
17113
+ const url = 'fhir/R4/' + input.request?.url;
17114
+ const method = input.request?.method;
17115
+ const resource = await this.mockHandler(method, url, {
17116
+ body: input.resource ? JSON.stringify(input.resource) : undefined,
17117
+ });
17118
+ if (resource?.resourceType === 'OperationOutcome') {
17159
17119
  return {
17160
- response: {
17161
- status: core.getStatus(outcome).toString(),
17162
- outcome,
17163
- },
17120
+ resource,
17121
+ response: { status: core.getStatus(resource).toString() },
17164
17122
  };
17165
17123
  }
17166
- });
17124
+ else if (resource) {
17125
+ return { resource, response: { status: '200' } };
17126
+ }
17127
+ else {
17128
+ return { resource: core.notFound, response: { status: '404' } };
17129
+ }
17130
+ }
17131
+ catch (err) {
17132
+ const outcome = err;
17133
+ return {
17134
+ response: {
17135
+ status: core.getStatus(outcome).toString(),
17136
+ outcome,
17137
+ },
17138
+ };
17139
+ }
17167
17140
  }
17168
17141
  }
17169
17142
 
@@ -17218,4 +17191,4 @@
17218
17191
  exports.exampleValueSet = exampleValueSet;
17219
17192
 
17220
17193
  }));
17221
- //# sourceMappingURL=index.js.map
17194
+ //# sourceMappingURL=index.cjs.map