@medplum/mock 0.9.26 → 0.9.27

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/esm/index.js CHANGED
@@ -1,4 +1,4 @@
1
- import { createReference, getReferenceString, evalFhirPath, Operator, MedplumClient, isOk, badRequest, allOk, notFound, parseSearchDefinition, getStatus } from '@medplum/core';
1
+ import { createReference, getReferenceString, evalFhirPath, Operator, MedplumClient, badRequest, isOk, allOk, notFound, parseSearchDefinition, getStatus } from '@medplum/core';
2
2
 
3
3
  const ExampleAccessPolicy = {
4
4
  resourceType: 'AccessPolicy',
@@ -6843,7 +6843,7 @@ class MemoryRepository {
6843
6843
  }
6844
6844
  createResource(resource) {
6845
6845
  var _a, _b;
6846
- const result = resource;
6846
+ const result = JSON.parse(JSON.stringify(resource));
6847
6847
  if (!result.id) {
6848
6848
  result.id = this.generateId();
6849
6849
  }
@@ -6856,7 +6856,7 @@ class MemoryRepository {
6856
6856
  if (!((_b = result.meta) === null || _b === void 0 ? void 0 : _b.lastUpdated)) {
6857
6857
  result.meta.lastUpdated = new Date().toISOString();
6858
6858
  }
6859
- const { resourceType, id } = resource;
6859
+ const { resourceType, id } = result;
6860
6860
  if (!(resourceType in __classPrivateFieldGet(this, _MemoryRepository_resources, "f"))) {
6861
6861
  __classPrivateFieldGet(this, _MemoryRepository_resources, "f")[resourceType] = {};
6862
6862
  }
@@ -6866,10 +6866,22 @@ class MemoryRepository {
6866
6866
  if (!(id in __classPrivateFieldGet(this, _MemoryRepository_history, "f")[resourceType])) {
6867
6867
  __classPrivateFieldGet(this, _MemoryRepository_history, "f")[resourceType][id] = [];
6868
6868
  }
6869
- __classPrivateFieldGet(this, _MemoryRepository_resources, "f")[resourceType][id] = resource;
6869
+ __classPrivateFieldGet(this, _MemoryRepository_resources, "f")[resourceType][id] = result;
6870
6870
  __classPrivateFieldGet(this, _MemoryRepository_history, "f")[resourceType][id].push(result);
6871
6871
  return result;
6872
6872
  }
6873
+ updateResource(resource) {
6874
+ const result = JSON.parse(JSON.stringify(resource));
6875
+ if (result.meta) {
6876
+ if (result.meta.versionId) {
6877
+ delete result.meta.versionId;
6878
+ }
6879
+ if (result.meta.lastUpdated) {
6880
+ delete result.meta.lastUpdated;
6881
+ }
6882
+ }
6883
+ return this.createResource(result);
6884
+ }
6873
6885
  readResource(resourceType, id) {
6874
6886
  var _a, _b;
6875
6887
  return (_b = (_a = __classPrivateFieldGet(this, _MemoryRepository_resources, "f")) === null || _a === void 0 ? void 0 : _a[resourceType]) === null || _b === void 0 ? void 0 : _b[id];
@@ -6961,41 +6973,16 @@ function matchesSearchFilterValue(resource, filter, filterValue) {
6961
6973
 
6962
6974
  class MockClient extends MedplumClient {
6963
6975
  constructor(clientOptions) {
6976
+ const mockFetchClient = new MockFetchClient(clientOptions === null || clientOptions === void 0 ? void 0 : clientOptions.debug);
6964
6977
  super({
6965
6978
  baseUrl: 'https://example.com/',
6966
6979
  clientId: 'my-client-id',
6967
- createPdf: (docDefinition, tableLayouts, fonts) => {
6968
- if (clientOptions === null || clientOptions === void 0 ? void 0 : clientOptions.debug) {
6969
- console.log(`Mock Client: createPdf(`);
6970
- console.log(` ${JSON.stringify(docDefinition, null, 2)},`);
6971
- console.log(` ${JSON.stringify(tableLayouts, null, 2)},`);
6972
- console.log(` ${JSON.stringify(fonts, null, 2)});`);
6973
- }
6974
- return Promise.resolve({});
6975
- },
6980
+ createPdf: (docDefinition, tableLayouts, fonts) => mockFetchClient.mockCreatePdf(docDefinition, tableLayouts, fonts),
6976
6981
  fetch: (url, options) => {
6977
- const method = options.method || 'GET';
6978
- const path = url.replace('https://example.com/', '');
6979
- if (clientOptions === null || clientOptions === void 0 ? void 0 : clientOptions.debug) {
6980
- console.log('MockClient', method, path);
6981
- }
6982
- const response = mockHandler(method, path, options);
6983
- if ((clientOptions === null || clientOptions === void 0 ? void 0 : clientOptions.debug) && !response) {
6984
- console.log('MockClient: not found', method, path);
6985
- }
6986
- if (clientOptions === null || clientOptions === void 0 ? void 0 : clientOptions.debug) {
6987
- console.log('MockClient', JSON.stringify(response, null, 2));
6988
- }
6989
- if ((response === null || response === void 0 ? void 0 : response.resourceType) === 'OperationOutcome' && !isOk(response)) {
6990
- return Promise.reject(response);
6991
- }
6992
- return Promise.resolve({
6993
- ok: true,
6994
- blob: () => Promise.resolve(response),
6995
- json: () => Promise.resolve(response),
6996
- });
6982
+ return mockFetchClient.mockFetch(url, options);
6997
6983
  },
6998
6984
  });
6985
+ this.debug = !!(clientOptions === null || clientOptions === void 0 ? void 0 : clientOptions.debug);
6999
6986
  }
7000
6987
  clear() {
7001
6988
  super.clear();
@@ -7031,313 +7018,349 @@ class MockClient extends MedplumClient {
7031
7018
  });
7032
7019
  }
7033
7020
  }
7034
- function mockHandler(method, path, options) {
7035
- if (path.startsWith('admin/')) {
7036
- return mockAdminHandler(method, path);
7037
- }
7038
- else if (path.startsWith('auth/')) {
7039
- return mockAuthHandler(method, path, options);
7040
- }
7041
- else if (path.startsWith('oauth2/')) {
7042
- return mockOAuthHandler(method, path);
7043
- }
7044
- else if (path.startsWith('fhir/R4')) {
7045
- return mockFhirHandler(method, path, options);
7046
- }
7047
- else {
7048
- return null;
7049
- }
7050
- }
7051
- function mockAdminHandler(_method, path) {
7052
- if (path.startsWith('admin/projects/123')) {
7053
- return {
7054
- project: { id: '123', name: 'Project 123' },
7055
- members: [
7056
- { id: '123', profile: { reference: 'Practitioner/123', display: 'Alice Smith' }, role: 'owner' },
7057
- { id: '888', profile: { reference: 'ClientApplication/123', display: 'Test Client' }, role: 'client' },
7058
- { id: '999', profile: { reference: 'Bot/123', display: 'Test Bot' }, role: 'bot' },
7059
- ],
7060
- };
7061
- }
7062
- return {
7063
- ok: true,
7064
- };
7065
- }
7066
- function mockAuthHandler(method, path, options) {
7067
- if (path.startsWith('auth/changepassword')) {
7068
- return mockChangePasswordHandler(method, path, options);
7069
- }
7070
- if (path.startsWith('auth/login')) {
7071
- return mockLoginHandler(method, path, options);
7021
+ class MockFetchClient {
7022
+ constructor(debug = false) {
7023
+ this.debug = debug;
7024
+ this.mockRepo = new MemoryRepository();
7025
+ this.initMockRepo();
7072
7026
  }
7073
- if (path.startsWith('auth/setpassword')) {
7074
- return mockSetPasswordHandler(method, path, options);
7075
- }
7076
- if (path.startsWith('auth/newuser')) {
7077
- return mockNewUserHandler(method, path, options);
7027
+ mockFetch(url, options) {
7028
+ const method = options.method || 'GET';
7029
+ const path = url.replace('https://example.com/', '');
7030
+ if (this.debug) {
7031
+ console.log('MockClient', method, path);
7032
+ }
7033
+ const response = this.mockHandler(method, path, options);
7034
+ if (this.debug && !response) {
7035
+ console.log('MockClient: not found', method, path);
7036
+ }
7037
+ if (this.debug) {
7038
+ console.log('MockClient', JSON.stringify(response, null, 2));
7039
+ }
7040
+ if ((response === null || response === void 0 ? void 0 : response.resourceType) === 'OperationOutcome' && !isOk(response)) {
7041
+ return Promise.reject(response);
7042
+ }
7043
+ return Promise.resolve({
7044
+ ok: true,
7045
+ blob: () => Promise.resolve(response),
7046
+ json: () => Promise.resolve(response),
7047
+ });
7078
7048
  }
7079
- if (path.startsWith('auth/newproject')) {
7080
- return mockNewProjectHandler();
7049
+ mockCreatePdf(docDefinition, tableLayouts, fonts) {
7050
+ if (this.debug) {
7051
+ console.log(`Mock Client: createPdf(`);
7052
+ console.log(` ${JSON.stringify(docDefinition, null, 2)},`);
7053
+ console.log(` ${JSON.stringify(tableLayouts, null, 2)},`);
7054
+ console.log(` ${JSON.stringify(fonts, null, 2)});`);
7055
+ }
7056
+ return Promise.resolve({});
7081
7057
  }
7082
- if (path.startsWith('auth/resetpassword')) {
7083
- return mockResetPasswordHandler(method, path, options);
7058
+ mockHandler(method, path, options) {
7059
+ if (path.startsWith('admin/')) {
7060
+ return this.mockAdminHandler(method, path);
7061
+ }
7062
+ else if (path.startsWith('auth/')) {
7063
+ return this.mockAuthHandler(method, path, options);
7064
+ }
7065
+ else if (path.startsWith('oauth2/')) {
7066
+ return this.mockOAuthHandler(method, path, options);
7067
+ }
7068
+ else if (path.startsWith('fhir/R4')) {
7069
+ return this.mockFhirHandler(method, path, options);
7070
+ }
7071
+ else {
7072
+ return null;
7073
+ }
7084
7074
  }
7085
- if (path.startsWith('auth/me')) {
7075
+ mockAdminHandler(_method, path) {
7076
+ if (path.startsWith('admin/projects/123')) {
7077
+ return {
7078
+ project: { id: '123', name: 'Project 123' },
7079
+ members: [
7080
+ { id: '123', profile: { reference: 'Practitioner/123', display: 'Alice Smith' }, role: 'owner' },
7081
+ { id: '888', profile: { reference: 'ClientApplication/123', display: 'Test Client' }, role: 'client' },
7082
+ { id: '999', profile: { reference: 'Bot/123', display: 'Test Bot' }, role: 'bot' },
7083
+ ],
7084
+ };
7085
+ }
7086
7086
  return {
7087
- profile: { reference: 'Practitioner/123' },
7087
+ ok: true,
7088
7088
  };
7089
7089
  }
7090
- return null;
7091
- }
7092
- function mockChangePasswordHandler(_method, _path, options) {
7093
- const { body } = options;
7094
- const { oldPassword } = JSON.parse(body);
7095
- if (oldPassword === 'orange') {
7096
- return allOk;
7090
+ mockAuthHandler(method, path, options) {
7091
+ if (path.startsWith('auth/changepassword')) {
7092
+ return this.mockChangePasswordHandler(method, path, options);
7093
+ }
7094
+ if (path.startsWith('auth/login')) {
7095
+ return this.mockLoginHandler(method, path, options);
7096
+ }
7097
+ if (path.startsWith('auth/setpassword')) {
7098
+ return this.mockSetPasswordHandler(method, path, options);
7099
+ }
7100
+ if (path.startsWith('auth/newuser')) {
7101
+ return this.mockNewUserHandler(method, path, options);
7102
+ }
7103
+ if (path.startsWith('auth/newproject') || path.startsWith('auth/newpatient')) {
7104
+ return {
7105
+ code: 'xyz',
7106
+ };
7107
+ }
7108
+ if (path.startsWith('auth/resetpassword')) {
7109
+ return this.mockResetPasswordHandler(method, path, options);
7110
+ }
7111
+ if (path.startsWith('auth/me')) {
7112
+ return {
7113
+ profile: { reference: 'Practitioner/123' },
7114
+ };
7115
+ }
7116
+ return null;
7097
7117
  }
7098
- else {
7099
- return {
7100
- resourceType: 'OperationOutcome',
7101
- issue: [
7102
- {
7103
- expression: ['oldPassword'],
7104
- details: {
7105
- text: 'Incorrect password',
7118
+ mockChangePasswordHandler(_method, _path, options) {
7119
+ const { body } = options;
7120
+ const { oldPassword } = JSON.parse(body);
7121
+ if (oldPassword === 'orange') {
7122
+ return allOk;
7123
+ }
7124
+ else {
7125
+ return {
7126
+ resourceType: 'OperationOutcome',
7127
+ issue: [
7128
+ {
7129
+ expression: ['oldPassword'],
7130
+ details: {
7131
+ text: 'Incorrect password',
7132
+ },
7106
7133
  },
7107
- },
7108
- ],
7109
- };
7110
- }
7111
- }
7112
- function mockLoginHandler(_method, _path, options) {
7113
- const { body } = options;
7114
- const { password } = JSON.parse(body);
7115
- if (password === 'password') {
7116
- return {
7117
- code: 'xyz',
7118
- };
7134
+ ],
7135
+ };
7136
+ }
7119
7137
  }
7120
- else {
7121
- return {
7122
- resourceType: 'OperationOutcome',
7123
- issue: [
7124
- {
7125
- expression: ['password'],
7126
- details: {
7127
- text: 'Invalid password',
7138
+ mockLoginHandler(_method, _path, options) {
7139
+ const { body } = options;
7140
+ const { password } = JSON.parse(body);
7141
+ if (password === 'password') {
7142
+ return {
7143
+ code: 'xyz',
7144
+ };
7145
+ }
7146
+ else {
7147
+ return {
7148
+ resourceType: 'OperationOutcome',
7149
+ issue: [
7150
+ {
7151
+ expression: ['password'],
7152
+ details: {
7153
+ text: 'Invalid password',
7154
+ },
7128
7155
  },
7129
- },
7130
- ],
7131
- };
7132
- }
7133
- }
7134
- function mockSetPasswordHandler(_method, _path, options) {
7135
- const { body } = options;
7136
- const { password } = JSON.parse(body);
7137
- if (password === 'orange') {
7138
- return allOk;
7156
+ ],
7157
+ };
7158
+ }
7139
7159
  }
7140
- else {
7141
- return {
7142
- resourceType: 'OperationOutcome',
7143
- issue: [
7144
- {
7145
- expression: ['password'],
7146
- details: {
7147
- text: 'Invalid password',
7160
+ mockSetPasswordHandler(_method, _path, options) {
7161
+ const { body } = options;
7162
+ const { password } = JSON.parse(body);
7163
+ if (password === 'orange') {
7164
+ return allOk;
7165
+ }
7166
+ else {
7167
+ return {
7168
+ resourceType: 'OperationOutcome',
7169
+ issue: [
7170
+ {
7171
+ expression: ['password'],
7172
+ details: {
7173
+ text: 'Invalid password',
7174
+ },
7148
7175
  },
7149
- },
7150
- ],
7151
- };
7152
- }
7153
- }
7154
- function mockNewUserHandler(_method, _path, options) {
7155
- const { body } = options;
7156
- const { email, password } = JSON.parse(body);
7157
- if (email === 'george@example.com' && password === 'password') {
7158
- return allOk;
7176
+ ],
7177
+ };
7178
+ }
7159
7179
  }
7160
- else {
7161
- return {
7162
- resourceType: 'OperationOutcome',
7163
- issue: [
7164
- {
7165
- details: {
7166
- text: 'Invalid',
7180
+ mockNewUserHandler(_method, _path, options) {
7181
+ const { body } = options;
7182
+ const { email, password } = JSON.parse(body);
7183
+ if (email === 'george@example.com' && password === 'password') {
7184
+ return allOk;
7185
+ }
7186
+ else {
7187
+ return {
7188
+ resourceType: 'OperationOutcome',
7189
+ issue: [
7190
+ {
7191
+ details: {
7192
+ text: 'Invalid',
7193
+ },
7167
7194
  },
7168
- },
7169
- ],
7170
- };
7171
- }
7172
- }
7173
- function mockNewProjectHandler(_method, _path, _options) {
7174
- return {
7175
- code: 'xyz',
7176
- };
7177
- }
7178
- function mockResetPasswordHandler(_method, _path, options) {
7179
- const { body } = options;
7180
- const { email } = JSON.parse(body);
7181
- if (email === 'admin@example.com') {
7182
- return allOk;
7195
+ ],
7196
+ };
7197
+ }
7183
7198
  }
7184
- else {
7185
- return {
7186
- resourceType: 'OperationOutcome',
7187
- issue: [
7188
- {
7189
- expression: ['email'],
7190
- details: {
7191
- text: 'Email not found',
7199
+ mockResetPasswordHandler(_method, _path, options) {
7200
+ const { body } = options;
7201
+ const { email } = JSON.parse(body);
7202
+ if (email === 'admin@example.com') {
7203
+ return allOk;
7204
+ }
7205
+ else {
7206
+ return {
7207
+ resourceType: 'OperationOutcome',
7208
+ issue: [
7209
+ {
7210
+ expression: ['email'],
7211
+ details: {
7212
+ text: 'Email not found',
7213
+ },
7192
7214
  },
7193
- },
7194
- ],
7195
- };
7196
- }
7197
- }
7198
- function mockOAuthHandler(_method, path, _options) {
7199
- if (path.startsWith('oauth2/token')) {
7200
- return {
7201
- access_token: 'header.' + window.btoa(JSON.stringify({ client_id: 'my-client-id' })) + '.signature',
7202
- };
7203
- }
7204
- return null;
7205
- }
7206
- const mockRepo = new MemoryRepository();
7207
- mockRepo.createResource(HomerSimpsonPreviousVersion);
7208
- mockRepo.createResource(HomerSimpson);
7209
- mockRepo.createResource(ExampleAccessPolicy);
7210
- mockRepo.createResource(ExampleStatusValueSet);
7211
- mockRepo.createResource(ExampleUserConfiguration);
7212
- mockRepo.createResource(ExampleBot);
7213
- mockRepo.createResource(ExampleClient);
7214
- mockRepo.createResource(HomerDiagnosticReport);
7215
- mockRepo.createResource(HomerEncounter);
7216
- mockRepo.createResource(HomerCommunication);
7217
- mockRepo.createResource(HomerMedia);
7218
- mockRepo.createResource(HomerObservation1);
7219
- mockRepo.createResource(HomerObservation2);
7220
- mockRepo.createResource(HomerObservation3);
7221
- mockRepo.createResource(HomerObservation4);
7222
- mockRepo.createResource(HomerObservation5);
7223
- mockRepo.createResource(HomerObservation6);
7224
- mockRepo.createResource(HomerSimpsonSpecimen);
7225
- mockRepo.createResource(TestOrganization);
7226
- mockRepo.createResource(DifferentOrganization);
7227
- mockRepo.createResource(ExampleQuestionnaire);
7228
- mockRepo.createResource(ExampleQuestionnaireResponse);
7229
- mockRepo.createResource(HomerServiceRequest);
7230
- mockRepo.createResource(ExampleSubscription);
7231
- mockRepo.createResource(BartSimpson);
7232
- mockRepo.createResource(DrAliceSmithPreviousVersion);
7233
- mockRepo.createResource(DrAliceSmith);
7234
- mockRepo.createResource(DrAliceSmithSchedule);
7235
- mockRepo.createResource(ExampleWorkflowQuestionnaire1);
7236
- mockRepo.createResource(ExampleWorkflowQuestionnaire2);
7237
- mockRepo.createResource(ExampleWorkflowQuestionnaire3);
7238
- mockRepo.createResource(ExampleWorkflowPlanDefinition);
7239
- mockRepo.createResource(ExampleWorkflowQuestionnaireResponse1);
7240
- mockRepo.createResource(ExampleWorkflowTask1);
7241
- mockRepo.createResource(ExampleWorkflowTask2);
7242
- mockRepo.createResource(ExampleWorkflowTask3);
7243
- mockRepo.createResource(ExampleWorkflowRequestGroup);
7244
- DrAliceSmithSlots.forEach((slot) => mockRepo.createResource(slot));
7245
- function mockFhirHandler(method, url, options) {
7246
- const path = url.includes('?') ? url.substring(0, url.indexOf('?')) : url;
7247
- const match = /fhir\/R4\/?([^/]+)?\/?([^/]+)?\/?([^/]+)?\/?([^/]+)?/.exec(path);
7248
- const resourceType = match === null || match === void 0 ? void 0 : match[1];
7249
- const id = match === null || match === void 0 ? void 0 : match[2];
7250
- const operation = match === null || match === void 0 ? void 0 : match[3];
7251
- const versionId = match === null || match === void 0 ? void 0 : match[4];
7252
- if (path.startsWith('fhir/R4/ValueSet/$expand')) {
7253
- return exampleValueSet;
7215
+ ],
7216
+ };
7217
+ }
7254
7218
  }
7255
- else if (path === 'fhir/R4/$graphql') {
7256
- return mockFhirGraphqlHandler(method, path, options);
7219
+ mockOAuthHandler(_method, path, _options) {
7220
+ if (path.startsWith('oauth2/token')) {
7221
+ return {
7222
+ access_token: 'header.' + window.btoa(JSON.stringify({ client_id: 'my-client-id' })) + '.signature',
7223
+ };
7224
+ }
7225
+ return null;
7257
7226
  }
7258
- else if (path === 'not-found' || id === 'not-found') {
7259
- return notFound;
7227
+ initMockRepo() {
7228
+ this.mockRepo.createResource(HomerSimpsonPreviousVersion);
7229
+ this.mockRepo.createResource(HomerSimpson);
7230
+ this.mockRepo.createResource(ExampleAccessPolicy);
7231
+ this.mockRepo.createResource(ExampleStatusValueSet);
7232
+ this.mockRepo.createResource(ExampleUserConfiguration);
7233
+ this.mockRepo.createResource(ExampleBot);
7234
+ this.mockRepo.createResource(ExampleClient);
7235
+ this.mockRepo.createResource(HomerDiagnosticReport);
7236
+ this.mockRepo.createResource(HomerEncounter);
7237
+ this.mockRepo.createResource(HomerCommunication);
7238
+ this.mockRepo.createResource(HomerMedia);
7239
+ this.mockRepo.createResource(HomerObservation1);
7240
+ this.mockRepo.createResource(HomerObservation2);
7241
+ this.mockRepo.createResource(HomerObservation3);
7242
+ this.mockRepo.createResource(HomerObservation4);
7243
+ this.mockRepo.createResource(HomerObservation5);
7244
+ this.mockRepo.createResource(HomerObservation6);
7245
+ this.mockRepo.createResource(HomerSimpsonSpecimen);
7246
+ this.mockRepo.createResource(TestOrganization);
7247
+ this.mockRepo.createResource(DifferentOrganization);
7248
+ this.mockRepo.createResource(ExampleQuestionnaire);
7249
+ this.mockRepo.createResource(ExampleQuestionnaireResponse);
7250
+ this.mockRepo.createResource(HomerServiceRequest);
7251
+ this.mockRepo.createResource(ExampleSubscription);
7252
+ this.mockRepo.createResource(BartSimpson);
7253
+ this.mockRepo.createResource(DrAliceSmithPreviousVersion);
7254
+ this.mockRepo.createResource(DrAliceSmith);
7255
+ this.mockRepo.createResource(DrAliceSmithSchedule);
7256
+ this.mockRepo.createResource(ExampleWorkflowQuestionnaire1);
7257
+ this.mockRepo.createResource(ExampleWorkflowQuestionnaire2);
7258
+ this.mockRepo.createResource(ExampleWorkflowQuestionnaire3);
7259
+ this.mockRepo.createResource(ExampleWorkflowPlanDefinition);
7260
+ this.mockRepo.createResource(ExampleWorkflowQuestionnaireResponse1);
7261
+ this.mockRepo.createResource(ExampleWorkflowTask1);
7262
+ this.mockRepo.createResource(ExampleWorkflowTask2);
7263
+ this.mockRepo.createResource(ExampleWorkflowTask3);
7264
+ this.mockRepo.createResource(ExampleWorkflowRequestGroup);
7265
+ DrAliceSmithSlots.forEach((slot) => this.mockRepo.createResource(slot));
7260
7266
  }
7261
- else if (method === 'POST') {
7262
- if (resourceType && id && operation) {
7263
- return {};
7267
+ mockFhirHandler(method, url, options) {
7268
+ const path = url.includes('?') ? url.substring(0, url.indexOf('?')) : url;
7269
+ const match = /fhir\/R4\/?([^/]+)?\/?([^/]+)?\/?([^/]+)?\/?([^/]+)?/.exec(path);
7270
+ const resourceType = match === null || match === void 0 ? void 0 : match[1];
7271
+ const id = match === null || match === void 0 ? void 0 : match[2];
7272
+ const operation = match === null || match === void 0 ? void 0 : match[3];
7273
+ const versionId = match === null || match === void 0 ? void 0 : match[4];
7274
+ if (path.startsWith('fhir/R4/ValueSet/$expand')) {
7275
+ return exampleValueSet;
7264
7276
  }
7265
- else if (resourceType) {
7266
- return mockRepo.createResource(JSON.parse(options.body));
7277
+ else if (path === 'fhir/R4/$graphql') {
7278
+ return this.mockFhirGraphqlHandler(method, path, options);
7267
7279
  }
7268
- else {
7269
- return mockFhirBatchHandler(method, path, options);
7280
+ else if (path === 'not-found' || id === 'not-found') {
7281
+ return notFound;
7270
7282
  }
7271
- }
7272
- else if (method === 'GET') {
7273
- if (resourceType && id && versionId) {
7274
- return mockRepo.readVersion(resourceType, id, versionId);
7283
+ else if (method === 'POST') {
7284
+ if (resourceType && id && operation) {
7285
+ return {};
7286
+ }
7287
+ else if (resourceType) {
7288
+ return this.mockRepo.createResource(JSON.parse(options.body));
7289
+ }
7290
+ else {
7291
+ return this.mockFhirBatchHandler(method, path, options);
7292
+ }
7275
7293
  }
7276
- else if (resourceType && id && operation === '_history') {
7277
- return mockRepo.readHistory(resourceType, id);
7294
+ else if (method === 'GET') {
7295
+ if (resourceType && id && versionId) {
7296
+ return this.mockRepo.readVersion(resourceType, id, versionId);
7297
+ }
7298
+ else if (resourceType && id && operation === '_history') {
7299
+ return this.mockRepo.readHistory(resourceType, id);
7300
+ }
7301
+ else if (resourceType && id) {
7302
+ return this.mockRepo.readResource(resourceType, id);
7303
+ }
7304
+ else if (resourceType) {
7305
+ return this.mockRepo.search(parseSearchDefinition(url));
7306
+ }
7278
7307
  }
7279
- else if (resourceType && id) {
7280
- return mockRepo.readResource(resourceType, id);
7308
+ else if (method === 'PUT') {
7309
+ return this.mockRepo.updateResource(JSON.parse(options.body));
7281
7310
  }
7282
- else if (resourceType) {
7283
- return mockRepo.search(parseSearchDefinition(url));
7311
+ else if (method === 'DELETE') {
7312
+ if (resourceType && id) {
7313
+ return this.mockRepo.deleteResource(resourceType, id);
7314
+ }
7315
+ else {
7316
+ return notFound;
7317
+ }
7284
7318
  }
7285
7319
  }
7286
- else if (method === 'PUT') {
7287
- return mockRepo.createResource(JSON.parse(options.body));
7288
- }
7289
- else if (method === 'DELETE') {
7290
- if (resourceType && id) {
7291
- return mockRepo.deleteResource(resourceType, id);
7292
- }
7293
- else {
7294
- return notFound;
7320
+ mockFhirGraphqlHandler(_method, _path, options) {
7321
+ const { body } = options;
7322
+ if (body.includes('ResourceList: ServiceRequestList')) {
7323
+ return {
7324
+ data: {
7325
+ ResourceList: [
7326
+ Object.assign(Object.assign({}, HomerServiceRequest), { ObservationList: [
7327
+ HomerObservation1,
7328
+ HomerObservation2,
7329
+ HomerObservation3,
7330
+ HomerObservation4,
7331
+ HomerObservation5,
7332
+ HomerObservation6,
7333
+ ] }),
7334
+ ],
7335
+ },
7336
+ };
7295
7337
  }
7338
+ return GraphQLSchemaResponse;
7296
7339
  }
7297
- }
7298
- function mockFhirGraphqlHandler(_method, _path, options) {
7299
- const { body } = options;
7300
- if (body.includes('ResourceList: ServiceRequestList')) {
7340
+ mockFhirBatchHandler(_method, _path, options) {
7341
+ var _a;
7342
+ const { body } = options;
7343
+ const request = JSON.parse(body);
7301
7344
  return {
7302
- data: {
7303
- ResourceList: [
7304
- Object.assign(Object.assign({}, HomerServiceRequest), { ObservationList: [
7305
- HomerObservation1,
7306
- HomerObservation2,
7307
- HomerObservation3,
7308
- HomerObservation4,
7309
- HomerObservation5,
7310
- HomerObservation6,
7311
- ] }),
7312
- ],
7313
- },
7345
+ resourceType: 'Bundle',
7346
+ type: 'batch-response',
7347
+ entry: (_a = request.entry) === null || _a === void 0 ? void 0 : _a.map((e) => {
7348
+ var _a, _b;
7349
+ const url = 'fhir/R4/' + ((_a = e === null || e === void 0 ? void 0 : e.request) === null || _a === void 0 ? void 0 : _a.url);
7350
+ const method = (_b = e === null || e === void 0 ? void 0 : e.request) === null || _b === void 0 ? void 0 : _b.method;
7351
+ const resource = this.mockHandler(method, url, null);
7352
+ if ((resource === null || resource === void 0 ? void 0 : resource.resourceType) === 'OperationOutcome') {
7353
+ return { resource, response: { status: getStatus(resource).toString() } };
7354
+ }
7355
+ else if (resource) {
7356
+ return { resource, response: { status: '200' } };
7357
+ }
7358
+ else {
7359
+ return { resource: notFound, response: { status: '404' } };
7360
+ }
7361
+ }),
7314
7362
  };
7315
7363
  }
7316
- return GraphQLSchemaResponse;
7317
- }
7318
- function mockFhirBatchHandler(_method, _path, options) {
7319
- var _a;
7320
- const { body } = options;
7321
- const request = JSON.parse(body);
7322
- return {
7323
- resourceType: 'Bundle',
7324
- type: 'batch-response',
7325
- entry: (_a = request.entry) === null || _a === void 0 ? void 0 : _a.map((e) => {
7326
- var _a, _b;
7327
- const url = 'fhir/R4/' + ((_a = e === null || e === void 0 ? void 0 : e.request) === null || _a === void 0 ? void 0 : _a.url);
7328
- const method = (_b = e === null || e === void 0 ? void 0 : e.request) === null || _b === void 0 ? void 0 : _b.method;
7329
- const resource = mockHandler(method, url, null);
7330
- if ((resource === null || resource === void 0 ? void 0 : resource.resourceType) === 'OperationOutcome') {
7331
- return { resource, response: { status: getStatus(resource).toString() } };
7332
- }
7333
- else if (resource) {
7334
- return { resource, response: { status: '200' } };
7335
- }
7336
- else {
7337
- return { resource: notFound, response: { status: '404' } };
7338
- }
7339
- }),
7340
- };
7341
7364
  }
7342
7365
 
7343
7366
  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, HomerCommunication, HomerDiagnosticReport, HomerEncounter, HomerMedia, HomerObservation1, HomerObservation2, HomerObservation3, HomerObservation4, HomerObservation5, HomerObservation6, HomerServiceRequest, HomerSimpson, HomerSimpsonPreviousVersion, HomerSimpsonSpecimen, MockClient, PatientSearchParameters, TestOrganization, exampleValueSet };