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