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