@medplum/fhir-router 2.0.4 → 2.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,4 +1,4 @@
1
- import { badRequest, parseSearchUrl, allOk, getStatus, isOk, getReferenceString, LRUCache, forbidden, getResourceTypes, getResourceTypeSchema, isResourceType, getElementDefinition, buildTypeName, capitalize, getSearchParameters, normalizeErrorString, Operator, parseSearchRequest, notFound, created, deepClone, matchesSearchRequest, globalSchema, evalFhirPath } from '@medplum/core';
1
+ import { OperationOutcomeError, badRequest, normalizeOperationOutcome, parseSearchUrl, getStatus, isOk, getReferenceString, allOk, LRUCache, forbidden, getResourceTypes, getResourceTypeSchema, isResourceTypeSchema, getElementDefinition, buildTypeName, capitalize, getSearchParameters, Operator, parseSearchRequest, notFound, created, deepClone, matchesSearchRequest, globalSchema, evalFhirPath } from '@medplum/core';
2
2
  import DataLoader from 'dataloader';
3
3
  import { applyPatch } from 'rfc6902';
4
4
 
@@ -72,14 +72,14 @@ class BatchProcessor {
72
72
  async processBatch() {
73
73
  const bundleType = this.bundle.type;
74
74
  if (!bundleType) {
75
- throw badRequest('Missing bundle type');
75
+ throw new OperationOutcomeError(badRequest('Missing bundle type'));
76
76
  }
77
77
  if (bundleType !== 'batch' && bundleType !== 'transaction') {
78
- throw badRequest('Unrecognized bundle type');
78
+ throw new OperationOutcomeError(badRequest('Unrecognized bundle type'));
79
79
  }
80
80
  const entries = this.bundle.entry;
81
81
  if (!entries) {
82
- throw badRequest('Missing bundle entry');
82
+ throw new OperationOutcomeError(badRequest('Missing bundle entry'));
83
83
  }
84
84
  const resultEntries = [];
85
85
  for (const entry of entries) {
@@ -88,12 +88,12 @@ class BatchProcessor {
88
88
  resultEntries.push(await __classPrivateFieldGet(this, _BatchProcessor_instances, "m", _BatchProcessor_processBatchEntry).call(this, rewritten));
89
89
  }
90
90
  catch (err) {
91
- resultEntries.push(buildBundleResponse(err));
91
+ resultEntries.push(buildBundleResponse(normalizeOperationOutcome(err)));
92
92
  }
93
93
  }
94
94
  return {
95
95
  resourceType: 'Bundle',
96
- type: 'batch-response',
96
+ type: (bundleType + '-response'),
97
97
  entry: resultEntries,
98
98
  };
99
99
  }
@@ -116,7 +116,11 @@ async function _BatchProcessor_processBatchEntry(entry) {
116
116
  return buildBundleResponse(badRequest('Multiple matches'));
117
117
  }
118
118
  if (entries.length === 1) {
119
- return buildBundleResponse(allOk, entries[0].resource);
119
+ const matchingResource = entries[0].resource;
120
+ if (entry.fullUrl) {
121
+ __classPrivateFieldGet(this, _BatchProcessor_instances, "m", _BatchProcessor_addReplacementId).call(this, entry.fullUrl, matchingResource);
122
+ }
123
+ return buildBundleResponse(allOk, matchingResource);
120
124
  }
121
125
  }
122
126
  let body = entry.resource;
@@ -139,24 +143,24 @@ async function _BatchProcessor_processBatchEntry(entry) {
139
143
  return buildBundleResponse(result[0], result[1]);
140
144
  }, _BatchProcessor_validateEntry = function _BatchProcessor_validateEntry(entry) {
141
145
  if (!entry.request) {
142
- throw badRequest('Missing entry.request');
146
+ throw new OperationOutcomeError(badRequest('Missing entry.request'));
143
147
  }
144
148
  if (!entry.request.method) {
145
- throw badRequest('Missing entry.request.method');
149
+ throw new OperationOutcomeError(badRequest('Missing entry.request.method'));
146
150
  }
147
151
  if (!entry.request.url) {
148
- throw badRequest('Missing entry.request.url');
152
+ throw new OperationOutcomeError(badRequest('Missing entry.request.url'));
149
153
  }
150
154
  }, _BatchProcessor_parsePatchBody = function _BatchProcessor_parsePatchBody(entry) {
151
155
  const patchResource = entry.resource;
152
156
  if (!patchResource) {
153
- throw badRequest('Missing entry.resource');
157
+ throw new OperationOutcomeError(badRequest('Missing entry.resource'));
154
158
  }
155
159
  if (patchResource.resourceType !== 'Binary') {
156
- throw badRequest('Patch resource must be a Binary');
160
+ throw new OperationOutcomeError(badRequest('Patch resource must be a Binary'));
157
161
  }
158
162
  if (!patchResource.data) {
159
- throw badRequest('Missing entry.resource.data');
163
+ throw new OperationOutcomeError(badRequest('Missing entry.resource.data'));
160
164
  }
161
165
  return JSON.parse(Buffer.from(patchResource.data, 'base64').toString('utf8'));
162
166
  }, _BatchProcessor_addReplacementId = function _BatchProcessor_addReplacementId(fullUrl, resource) {
@@ -13527,7 +13531,7 @@ function buildGraphQLFields(resourceType) {
13527
13531
  function buildPropertyFields(resourceType, fields) {
13528
13532
  const schema = getResourceTypeSchema(resourceType);
13529
13533
  const properties = schema.properties;
13530
- if (isResourceType(schema)) {
13534
+ if (isResourceTypeSchema(schema)) {
13531
13535
  fields.resourceType = {
13532
13536
  type: new GraphQLNonNull(GraphQLString),
13533
13537
  description: 'Resource Type',
@@ -13693,7 +13697,7 @@ async function resolveById(_source, args, ctx, info) {
13693
13697
  return await ctx.dataLoader.load({ reference: `${info.fieldName}/${args.id}` });
13694
13698
  }
13695
13699
  catch (err) {
13696
- throw new Error(normalizeErrorString(err));
13700
+ throw new OperationOutcomeError(normalizeOperationOutcome(err), err);
13697
13701
  }
13698
13702
  }
13699
13703
  /**
@@ -13710,7 +13714,7 @@ async function resolveByReference(source, _args, ctx) {
13710
13714
  return await ctx.dataLoader.load(source);
13711
13715
  }
13712
13716
  catch (err) {
13713
- throw new Error(normalizeErrorString(err));
13717
+ throw new OperationOutcomeError(normalizeOperationOutcome(err), err);
13714
13718
  }
13715
13719
  }
13716
13720
  /**
@@ -14018,25 +14022,25 @@ class MemoryRepository {
14018
14022
  try {
14019
14023
  const patchResult = applyPatch(resource, patch).filter(Boolean);
14020
14024
  if (patchResult.length > 0) {
14021
- throw badRequest(patchResult.map((e) => e.message).join('\n'));
14025
+ throw new OperationOutcomeError(badRequest(patchResult.map((e) => e.message).join('\n')));
14022
14026
  }
14023
14027
  }
14024
14028
  catch (err) {
14025
- throw badRequest(normalizeErrorString(err));
14029
+ throw new OperationOutcomeError(normalizeOperationOutcome(err));
14026
14030
  }
14027
14031
  return this.updateResource(resource);
14028
14032
  }
14029
14033
  async readResource(resourceType, id) {
14030
14034
  const resource = __classPrivateFieldGet(this, _MemoryRepository_resources, "f")?.[resourceType]?.[id];
14031
14035
  if (!resource) {
14032
- throw notFound;
14036
+ throw new OperationOutcomeError(notFound);
14033
14037
  }
14034
14038
  return deepClone(resource);
14035
14039
  }
14036
14040
  async readReference(reference) {
14037
14041
  const parts = reference.reference?.split('/');
14038
14042
  if (!parts || parts.length !== 2) {
14039
- throw badRequest('Invalid reference');
14043
+ throw new OperationOutcomeError(badRequest('Invalid reference'));
14040
14044
  }
14041
14045
  return this.readResource(parts[0], parts[1]);
14042
14046
  }
@@ -14057,7 +14061,7 @@ class MemoryRepository {
14057
14061
  await this.readResource(resourceType, id);
14058
14062
  const version = __classPrivateFieldGet(this, _MemoryRepository_history, "f")?.[resourceType]?.[id]?.find((v) => v.meta?.versionId === versionId);
14059
14063
  if (!version) {
14060
- throw notFound;
14064
+ throw new OperationOutcomeError(notFound);
14061
14065
  }
14062
14066
  return deepClone(version);
14063
14067
  }
@@ -14086,7 +14090,7 @@ class MemoryRepository {
14086
14090
  }
14087
14091
  async deleteResource(resourceType, id) {
14088
14092
  if (!__classPrivateFieldGet(this, _MemoryRepository_resources, "f")?.[resourceType]?.[id]) {
14089
- throw notFound;
14093
+ throw new OperationOutcomeError(notFound);
14090
14094
  }
14091
14095
  delete __classPrivateFieldGet(this, _MemoryRepository_resources, "f")[resourceType][id];
14092
14096
  }