@medplum/core 0.9.34 → 0.9.35

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.
@@ -511,7 +511,7 @@ export declare class MedplumClient extends EventTarget {
511
511
  * ```json
512
512
  * {
513
513
  * "resourceType": "Bundle",
514
- * "type": "searchest",
514
+ * "type": "searchset",
515
515
  * "total": 1,
516
516
  * "entry": [
517
517
  * {
package/dist/cjs/index.js CHANGED
@@ -6087,17 +6087,16 @@
6087
6087
  for (const entry of bundle.entry) {
6088
6088
  const resource = entry.resource;
6089
6089
  if (resource.resourceType === 'StructureDefinition') {
6090
- indexStructureDefinition(globalSchema, resource);
6090
+ indexStructureDefinition(resource);
6091
6091
  }
6092
6092
  }
6093
6093
  }
6094
6094
  /**
6095
6095
  * Indexes a StructureDefinition for fast lookup.
6096
6096
  * See comments on IndexedStructureDefinition for more details.
6097
- * @param schema The output IndexedStructureDefinition.
6098
6097
  * @param structureDefinition The original StructureDefinition.
6099
6098
  */
6100
- function indexStructureDefinition(schema, structureDefinition) {
6099
+ function indexStructureDefinition(structureDefinition) {
6101
6100
  var _a;
6102
6101
  const typeName = structureDefinition.name;
6103
6102
  if (!typeName) {
@@ -6106,9 +6105,9 @@
6106
6105
  const elements = (_a = structureDefinition.snapshot) === null || _a === void 0 ? void 0 : _a.element;
6107
6106
  if (elements) {
6108
6107
  // First pass, build types
6109
- elements.forEach((element) => indexType(schema, structureDefinition, element));
6108
+ elements.forEach((element) => indexType(structureDefinition, element));
6110
6109
  // Second pass, build properties
6111
- elements.forEach((element) => indexProperty(schema, element));
6110
+ elements.forEach((element) => indexProperty(element));
6112
6111
  }
6113
6112
  }
6114
6113
  /**
@@ -6118,7 +6117,7 @@
6118
6117
  * @param schema The output IndexedStructureDefinition.
6119
6118
  * @param element The input ElementDefinition.
6120
6119
  */
6121
- function indexType(schema, structureDefinition, elementDefinition) {
6120
+ function indexType(structureDefinition, elementDefinition) {
6122
6121
  var _a, _b;
6123
6122
  const path = elementDefinition.path;
6124
6123
  const typeCode = (_b = (_a = elementDefinition.type) === null || _a === void 0 ? void 0 : _a[0]) === null || _b === void 0 ? void 0 : _b.code;
@@ -6127,22 +6126,22 @@
6127
6126
  }
6128
6127
  const parts = path.split('.');
6129
6128
  const typeName = buildTypeName(parts);
6130
- schema.types[typeName] = createTypeSchema(typeName, structureDefinition, elementDefinition);
6131
- schema.types[typeName].parentType = buildTypeName(parts.slice(0, parts.length - 1));
6129
+ globalSchema.types[typeName] = createTypeSchema(typeName, structureDefinition, elementDefinition);
6130
+ globalSchema.types[typeName].parentType = buildTypeName(parts.slice(0, parts.length - 1));
6132
6131
  }
6133
6132
  /**
6134
6133
  * Indexes PropertySchema from an ElementDefinition.
6135
6134
  * @param schema The output IndexedStructureDefinition.
6136
6135
  * @param element The input ElementDefinition.
6137
6136
  */
6138
- function indexProperty(schema, element) {
6137
+ function indexProperty(element) {
6139
6138
  const path = element.path;
6140
6139
  const parts = path.split('.');
6141
6140
  if (parts.length === 1) {
6142
6141
  return;
6143
6142
  }
6144
6143
  const typeName = buildTypeName(parts.slice(0, parts.length - 1));
6145
- const typeSchema = schema.types[typeName];
6144
+ const typeSchema = globalSchema.types[typeName];
6146
6145
  if (!typeSchema) {
6147
6146
  return;
6148
6147
  }
@@ -6155,17 +6154,23 @@
6155
6154
  * @param schema The output IndexedStructureDefinition.
6156
6155
  * @param searchParam The SearchParameter resource.
6157
6156
  */
6158
- function indexSearchParameter(schema, searchParam) {
6157
+ function indexSearchParameter(searchParam) {
6159
6158
  if (!searchParam.base) {
6160
6159
  return;
6161
6160
  }
6162
6161
  for (const resourceType of searchParam.base) {
6163
- const typeSchema = schema.types[resourceType];
6162
+ const typeSchema = globalSchema.types[resourceType];
6164
6163
  if (!typeSchema) {
6165
6164
  continue;
6166
6165
  }
6167
6166
  if (!typeSchema.searchParams) {
6168
6167
  typeSchema.searchParams = {
6168
+ _id: {
6169
+ base: [resourceType],
6170
+ code: '_id',
6171
+ type: 'token',
6172
+ expression: resourceType + '.id',
6173
+ },
6169
6174
  _lastUpdated: {
6170
6175
  base: [resourceType],
6171
6176
  code: '_lastUpdated',
@@ -6205,6 +6210,33 @@
6205
6210
  .replace('_', ' ')
6206
6211
  .replace(/\s+/g, ' ');
6207
6212
  }
6213
+ /**
6214
+ * Returns an element definition by type and property name.
6215
+ * Handles content references.
6216
+ * @param typeName The type name.
6217
+ * @param propertyName The property name.
6218
+ * @returns The element definition if found.
6219
+ */
6220
+ function getElementDefinition(typeName, propertyName) {
6221
+ var _a;
6222
+ const typeSchema = globalSchema.types[typeName];
6223
+ if (!typeSchema) {
6224
+ return undefined;
6225
+ }
6226
+ const property = (_a = typeSchema.properties[propertyName]) !== null && _a !== void 0 ? _a : typeSchema.properties[propertyName + '[x]'];
6227
+ if (!property) {
6228
+ return undefined;
6229
+ }
6230
+ if (property.contentReference) {
6231
+ // Content references start with a "#"
6232
+ // Remove the "#" character
6233
+ const contentReference = property.contentReference.substring(1).split('.');
6234
+ const referencePropertyName = contentReference.pop();
6235
+ const referenceTypeName = buildTypeName(contentReference);
6236
+ return getElementDefinition(referenceTypeName, referencePropertyName);
6237
+ }
6238
+ return property;
6239
+ }
6208
6240
  /**
6209
6241
  * Global schema singleton.
6210
6242
  */
@@ -6617,7 +6649,7 @@
6617
6649
  * ```json
6618
6650
  * {
6619
6651
  * "resourceType": "Bundle",
6620
- * "type": "searchest",
6652
+ * "type": "searchset",
6621
6653
  * "total": 1,
6622
6654
  * "entry": [
6623
6655
  * {
@@ -6860,10 +6892,10 @@
6860
6892
  }`.replace(/\s+/g, ' ');
6861
6893
  const response = (yield this.graphql(query));
6862
6894
  for (const structureDefinition of response.data.StructureDefinitionList) {
6863
- indexStructureDefinition(globalSchema, structureDefinition);
6895
+ indexStructureDefinition(structureDefinition);
6864
6896
  }
6865
6897
  for (const searchParameter of response.data.SearchParameterList) {
6866
- indexSearchParameter(globalSchema, searchParameter);
6898
+ indexSearchParameter(searchParameter);
6867
6899
  }
6868
6900
  return globalSchema;
6869
6901
  });
@@ -7531,6 +7563,7 @@
7531
7563
  options.headers = {};
7532
7564
  }
7533
7565
  const headers = options.headers;
7566
+ headers['X-Medplum'] = 'extended';
7534
7567
  if (!headers['Content-Type']) {
7535
7568
  headers['Content-Type'] = FHIR_CONTENT_TYPE;
7536
7569
  }
@@ -7761,9 +7794,9 @@
7761
7794
  if (!(input === null || input === void 0 ? void 0 : input.value)) {
7762
7795
  return undefined;
7763
7796
  }
7764
- const typeSchema = globalSchema.types[input.type];
7765
- if (typeSchema) {
7766
- const typedResult = getTypedPropertyValueWithSchema(input, path, typeSchema);
7797
+ const elementDefinition = getElementDefinition(input.type, path);
7798
+ if (elementDefinition) {
7799
+ const typedResult = getTypedPropertyValueWithSchema(input, path, elementDefinition);
7767
7800
  if (typedResult) {
7768
7801
  return typedResult;
7769
7802
  }
@@ -7774,24 +7807,18 @@
7774
7807
  * Returns the value of the property and the property type using a type schema.
7775
7808
  * @param input The base context (FHIR resource or backbone element).
7776
7809
  * @param path The property path.
7777
- * @param typeSchema The input type schema.
7810
+ * @param property The property element definition.
7778
7811
  * @returns The value of the property and the property type.
7779
7812
  */
7780
- function getTypedPropertyValueWithSchema(input, path, typeSchema) {
7813
+ function getTypedPropertyValueWithSchema(input, path, property) {
7781
7814
  var _a;
7782
- const property = (_a = typeSchema.properties[path]) !== null && _a !== void 0 ? _a : typeSchema.properties[path + '[x]'];
7783
- if (!property) {
7784
- return undefined;
7785
- }
7786
7815
  const types = property.type;
7787
7816
  if (!types || types.length === 0) {
7788
7817
  return undefined;
7789
7818
  }
7790
- let propertyName = undefined;
7791
7819
  let resultValue = undefined;
7792
7820
  let resultType = 'undefined';
7793
7821
  if (types.length === 1) {
7794
- propertyName = path;
7795
7822
  resultValue = input.value[path];
7796
7823
  resultType = types[0].code;
7797
7824
  }
@@ -7799,7 +7826,6 @@
7799
7826
  for (const type of types) {
7800
7827
  const path2 = path.replace('[x]', '') + capitalize(type.code);
7801
7828
  if (path2 in input.value) {
7802
- propertyName = path2;
7803
7829
  resultValue = input.value[path2];
7804
7830
  resultType = type.code;
7805
7831
  break;
@@ -7809,16 +7835,22 @@
7809
7835
  if (isEmpty(resultValue)) {
7810
7836
  return undefined;
7811
7837
  }
7812
- if (resultType === 'BackboneElement') {
7813
- resultType = buildTypeName([input.type, propertyName]);
7838
+ if (resultType === 'Element' || resultType === 'BackboneElement') {
7839
+ resultType = buildTypeName((_a = property.path) === null || _a === void 0 ? void 0 : _a.split('.'));
7814
7840
  }
7815
7841
  if (Array.isArray(resultValue)) {
7816
- return resultValue.map((element) => ({ value: element, type: resultType }));
7842
+ return resultValue.map((element) => toTypedValueWithType(element, resultType));
7817
7843
  }
7818
7844
  else {
7819
- return { value: resultValue, type: resultType };
7845
+ return toTypedValueWithType(resultValue, resultType);
7820
7846
  }
7821
7847
  }
7848
+ function toTypedValueWithType(value, type) {
7849
+ if (type === 'Resource' && typeof value === 'object' && 'resourceType' in value) {
7850
+ type = value.resourceType;
7851
+ }
7852
+ return { type, value };
7853
+ }
7822
7854
  /**
7823
7855
  * Returns the value of the property and the property type using a type schema.
7824
7856
  * Note that because the type schema is not available, this function may be inaccurate.
@@ -10443,7 +10475,7 @@
10443
10475
  issue: [
10444
10476
  {
10445
10477
  severity: 'information',
10446
- code: 'information',
10478
+ code: 'informational',
10447
10479
  details: {
10448
10480
  text: 'All OK',
10449
10481
  },
@@ -10456,7 +10488,7 @@
10456
10488
  issue: [
10457
10489
  {
10458
10490
  severity: 'information',
10459
- code: 'information',
10491
+ code: 'informational',
10460
10492
  details: {
10461
10493
  text: 'Created',
10462
10494
  },
@@ -10469,7 +10501,7 @@
10469
10501
  issue: [
10470
10502
  {
10471
10503
  severity: 'information',
10472
- code: 'information',
10504
+ code: 'informational',
10473
10505
  details: {
10474
10506
  text: 'Not Modified',
10475
10507
  },
@@ -10860,17 +10892,32 @@
10860
10892
  * 2) The "token" type includes enums and booleans.
10861
10893
  * 3) Arrays/multiple values are not reflected at all.
10862
10894
  *
10863
- * @param structureDefinitions Collection of StructureDefinition resources indexed by name.
10864
10895
  * @param resourceType The root resource type.
10865
10896
  * @param searchParam The search parameter.
10866
10897
  * @returns The search parameter type details.
10867
10898
  */
10868
- function getSearchParameterDetails(structureDefinitions, resourceType, searchParam) {
10899
+ function getSearchParameterDetails(resourceType, searchParam) {
10900
+ var _a, _b;
10901
+ let result = (_b = (_a = globalSchema.types[resourceType]) === null || _a === void 0 ? void 0 : _a.searchParamsDetails) === null || _b === void 0 ? void 0 : _b[searchParam.code];
10902
+ if (!result) {
10903
+ result = buildSearchParamterDetails(resourceType, searchParam);
10904
+ }
10905
+ return result;
10906
+ }
10907
+ function setSearchParamterDetails(resourceType, code, details) {
10908
+ const typeSchema = globalSchema.types[resourceType];
10909
+ if (!typeSchema.searchParamsDetails) {
10910
+ typeSchema.searchParamsDetails = {};
10911
+ }
10912
+ typeSchema.searchParamsDetails[code] = details;
10913
+ }
10914
+ function buildSearchParamterDetails(resourceType, searchParam) {
10869
10915
  var _a, _b, _c, _d, _e, _f, _g;
10870
10916
  if (searchParam.code === '_lastUpdated') {
10871
10917
  return { columnName: 'lastUpdated', type: exports.SearchParameterType.DATETIME };
10872
10918
  }
10873
- const columnName = convertCodeToColumnName(searchParam.code);
10919
+ const code = searchParam.code;
10920
+ const columnName = convertCodeToColumnName(code);
10874
10921
  const expression = (_a = getExpressionForResourceType(resourceType, searchParam.expression)) === null || _a === void 0 ? void 0 : _a.split('.');
10875
10922
  if (!expression) {
10876
10923
  // This happens on compound types
@@ -10885,7 +10932,7 @@
10885
10932
  for (let i = 1; i < expression.length; i++) {
10886
10933
  const propertyName = expression[i];
10887
10934
  elementDefinition =
10888
- (_d = (_c = (_b = structureDefinitions.types[baseType]) === null || _b === void 0 ? void 0 : _b.properties) === null || _c === void 0 ? void 0 : _c[propertyName]) !== null && _d !== void 0 ? _d : (_f = (_e = structureDefinitions.types[baseType]) === null || _e === void 0 ? void 0 : _e.properties) === null || _f === void 0 ? void 0 : _f[propertyName + '[x]'];
10935
+ (_d = (_c = (_b = globalSchema.types[baseType]) === null || _b === void 0 ? void 0 : _b.properties) === null || _c === void 0 ? void 0 : _c[propertyName]) !== null && _d !== void 0 ? _d : (_f = (_e = globalSchema.types[baseType]) === null || _e === void 0 ? void 0 : _e.properties) === null || _f === void 0 ? void 0 : _f[propertyName + '[x]'];
10889
10936
  if (!elementDefinition) {
10890
10937
  throw new Error(`Element definition not found for ${resourceType} ${searchParam.code}`);
10891
10938
  }
@@ -10908,7 +10955,9 @@
10908
10955
  }
10909
10956
  }
10910
10957
  const type = getSearchParameterType(searchParam, propertyType);
10911
- return { columnName, type, elementDefinition, array };
10958
+ const result = { columnName, type, elementDefinition, array };
10959
+ setSearchParamterDetails(resourceType, code, result);
10960
+ return result;
10912
10961
  }
10913
10962
  /**
10914
10963
  * Converts a hyphen-delimited code to camelCase string.
@@ -11051,6 +11100,7 @@
11051
11100
  exports.getCodeBySystem = getCodeBySystem;
11052
11101
  exports.getDateProperty = getDateProperty;
11053
11102
  exports.getDisplayString = getDisplayString;
11103
+ exports.getElementDefinition = getElementDefinition;
11054
11104
  exports.getExpressionForResourceType = getExpressionForResourceType;
11055
11105
  exports.getExtensionValue = getExtensionValue;
11056
11106
  exports.getIdentifier = getIdentifier;