@medplum/core 2.0.5 → 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.
Files changed (45) hide show
  1. package/dist/cjs/index.cjs +871 -26
  2. package/dist/cjs/index.cjs.map +1 -1
  3. package/dist/cjs/index.min.cjs +1 -1
  4. package/dist/esm/client.mjs +7 -6
  5. package/dist/esm/client.mjs.map +1 -1
  6. package/dist/esm/fhirlexer/tokenize.mjs +13 -4
  7. package/dist/esm/fhirlexer/tokenize.mjs.map +1 -1
  8. package/dist/esm/fhirmapper/parse.mjs +317 -0
  9. package/dist/esm/fhirmapper/parse.mjs.map +1 -0
  10. package/dist/esm/fhirmapper/tokenize.mjs +15 -0
  11. package/dist/esm/fhirmapper/tokenize.mjs.map +1 -0
  12. package/dist/esm/fhirpath/atoms.mjs +2 -2
  13. package/dist/esm/fhirpath/atoms.mjs.map +1 -1
  14. package/dist/esm/fhirpath/functions.mjs +2 -2
  15. package/dist/esm/fhirpath/functions.mjs.map +1 -1
  16. package/dist/esm/fhirpath/utils.mjs +4 -4
  17. package/dist/esm/fhirpath/utils.mjs.map +1 -1
  18. package/dist/esm/filter/parse.mjs +51 -0
  19. package/dist/esm/filter/parse.mjs.map +1 -0
  20. package/dist/esm/filter/tokenize.mjs +18 -0
  21. package/dist/esm/filter/tokenize.mjs.map +1 -0
  22. package/dist/esm/filter/types.mjs +34 -0
  23. package/dist/esm/filter/types.mjs.map +1 -0
  24. package/dist/esm/index.min.mjs +1 -1
  25. package/dist/esm/index.mjs +8 -2
  26. package/dist/esm/index.mjs.map +1 -1
  27. package/dist/esm/node_modules/tslib/tslib.es6.mjs.map +1 -1
  28. package/dist/esm/outcomes.mjs +15 -1
  29. package/dist/esm/outcomes.mjs.map +1 -1
  30. package/dist/esm/schema.mjs +397 -0
  31. package/dist/esm/schema.mjs.map +1 -0
  32. package/dist/esm/types.mjs +34 -8
  33. package/dist/esm/types.mjs.map +1 -1
  34. package/dist/types/client.d.ts +20 -8
  35. package/dist/types/fhirlexer/tokenize.d.ts +5 -1
  36. package/dist/types/fhirmapper/index.d.ts +1 -0
  37. package/dist/types/filter/index.d.ts +2 -0
  38. package/dist/types/filter/parse.d.ts +7 -0
  39. package/dist/types/filter/tokenize.d.ts +2 -0
  40. package/dist/types/filter/types.d.ts +31 -0
  41. package/dist/types/index.d.ts +4 -0
  42. package/dist/types/outcomes.d.ts +1 -0
  43. package/dist/types/schema.d.ts +120 -0
  44. package/dist/types/types.d.ts +19 -5
  45. package/package.json +1 -1
@@ -0,0 +1 @@
1
+ {"version":3,"file":"schema.mjs","sources":["../../src/schema.ts"],"sourcesContent":["import { ElementDefinition, OperationOutcomeIssue, Resource } from '@medplum/fhirtypes';\nimport { getTypedPropertyValue, toTypedValue } from './fhirpath';\nimport { OperationOutcomeError, validationError } from './outcomes';\nimport { globalSchema, PropertyType, TypedValue } from './types';\nimport { capitalize, getExtensionValue, isEmpty, isLowerCase } from './utils';\n\n/*\n * This file provides schema validation utilities for FHIR JSON objects.\n *\n * See: [JSON Representation of Resources](https://hl7.org/fhir/json.html)\n * See: [FHIR Data Types](https://www.hl7.org/fhir/datatypes.html)\n */\n\nconst fhirTypeToJsType: Record<string, string> = {\n base64Binary: 'string',\n boolean: 'boolean',\n canonical: 'string',\n code: 'string',\n date: 'string',\n dateTime: 'string',\n decimal: 'number',\n id: 'string',\n instant: 'string',\n integer: 'number',\n markdown: 'string',\n oid: 'string',\n positiveInt: 'number',\n string: 'string',\n time: 'string',\n unsignedInt: 'number',\n uri: 'string',\n url: 'string',\n uuid: 'string',\n xhtml: 'string',\n 'http://hl7.org/fhirpath/System.String': 'string',\n};\n\nconst baseResourceProperties = new Set<string>([\n // Resource\n 'resourceType',\n 'id',\n 'meta',\n 'implicitRules',\n 'language',\n\n // DomainResource\n 'text',\n 'contained',\n 'extension',\n 'modifierExtension',\n]);\n\n/**\n * Returns true if the given string is a valid FHIR resource type.\n *\n * ```ts\n * isResourceType('Patient'); // true\n * isResourceType('XYZ'); // false\n * ```\n *\n * Note that this depends on globalSchema, which is populated by the StructureDefinition loader.\n *\n * In a server context, you can load all schema definitions:\n *\n * ```ts\n * import { indexStructureDefinitionBundle } from '@medplum/core';\n * import { readJson } from '@medplum/definitions';\n * import { Bundle } from '@medplum/fhirtypes';\n *\n * indexStructureDefinitionBundle(readJson('fhir/r4/profiles-resources.json') as Bundle);\n * ```\n *\n * In a client context, you can load the schema definitions using MedplumClient:\n *\n * ```ts\n * import { MedplumClient } from '@medplum/core';\n *\n * const medplum = new MedplumClient();\n * await medplum.requestSchema('Patient');\n * ```\n *\n * @param resourceType The candidate resource type string.\n * @returns True if the resource type is a valid FHIR resource type.\n */\nexport function isResourceType(resourceType: string): boolean {\n const typeSchema = globalSchema.types[resourceType];\n return (\n typeSchema &&\n typeSchema.structureDefinition.id === resourceType &&\n typeSchema.structureDefinition.kind === 'resource'\n );\n}\n\n/**\n * Validates that the given string is a valid FHIR resource type.\n * On success, silently returns void.\n * On failure, throws an OperationOutcomeError.\n *\n * ```ts\n * validateResourceType('Patient'); // nothing\n * validateResourceType('XYZ'); // throws OperationOutcomeError\n * ```\n *\n * Note that this depends on globalSchema, which is populated by the StructureDefinition loader.\n *\n * In a server context, you can load all schema definitions:\n *\n * ```ts\n * import { indexStructureDefinitionBundle } from '@medplum/core';\n * import { readJson } from '@medplum/definitions';\n * import { Bundle } from '@medplum/fhirtypes';\n *\n * indexStructureDefinitionBundle(readJson('fhir/r4/profiles-resources.json') as Bundle);\n * ```\n *\n * In a client context, you can load the schema definitions using MedplumClient:\n *\n * ```ts\n * import { MedplumClient } from '@medplum/core';\n *\n * const medplum = new MedplumClient();\n * await medplum.requestSchema('Patient');\n * ```\n *\n * @param resourceType The candidate resource type string.\n * @returns True if the resource type is a valid FHIR resource type.\n */\nexport function validateResourceType(resourceType: string): void {\n if (!resourceType) {\n throw new OperationOutcomeError(validationError('Resource type is null'));\n }\n if (!isResourceType(resourceType)) {\n throw new OperationOutcomeError(validationError('Unknown resource type'));\n }\n}\n\n/**\n * Validates a candidate FHIR resource object.\n * On success, silently returns void.\n * On failure, throws an OperationOutcomeError with issues for each violation.\n *\n * ```ts\n * validateResource({ resourceType: 'Patient' }); // nothing\n * validateResource({ resourceType: 'XYZ' }); // throws OperationOutcomeError\n * ```\n *\n * Note that this depends on globalSchema, which is populated by the StructureDefinition loader.\n *\n * In a server context, you can load all schema definitions:\n *\n * ```ts\n * import { indexStructureDefinitionBundle } from '@medplum/core';\n * import { readJson } from '@medplum/definitions';\n * import { Bundle } from '@medplum/fhirtypes';\n *\n * indexStructureDefinitionBundle(readJson('fhir/r4/profiles-resources.json') as Bundle);\n * ```\n *\n * In a client context, you can load the schema definitions using MedplumClient:\n *\n * ```ts\n * import { MedplumClient } from '@medplum/core';\n *\n * const medplum = new MedplumClient();\n * await medplum.requestSchema('Patient');\n * ```\n *\n * @param resourceType The candidate resource type string.\n * @returns True if the resource type is a valid FHIR resource type.\n */\nexport function validateResource<T extends Resource>(resource: T): void {\n new FhirSchemaValidator(resource).validate();\n}\n\nexport class FhirSchemaValidator<T extends Resource> {\n readonly #issues: OperationOutcomeIssue[];\n readonly #root: T;\n\n constructor(root: T) {\n this.#issues = [];\n this.#root = root;\n }\n\n validate(): void {\n const resource = this.#root;\n if (!resource) {\n throw new OperationOutcomeError(validationError('Resource is null'));\n }\n\n const resourceType = resource.resourceType;\n if (!resourceType) {\n throw new OperationOutcomeError(validationError('Missing resource type'));\n }\n\n // Check for \"null\" once for the entire object hierarchy\n checkForNull(resource, '', this.#issues);\n\n this.#validateObject(toTypedValue(resource), resourceType);\n\n if (this.#issues.length > 0) {\n throw new OperationOutcomeError({\n resourceType: 'OperationOutcome',\n issue: this.#issues,\n });\n }\n }\n\n #validateObject(typedValue: TypedValue, path: string): void {\n const definition = globalSchema.types[typedValue.type];\n if (!definition) {\n throw new OperationOutcomeError(validationError('Unknown type: ' + typedValue.type));\n }\n\n const propertyDefinitions = definition.properties;\n this.#checkProperties(path, propertyDefinitions, typedValue);\n this.#checkAdditionalProperties(path, typedValue, propertyDefinitions);\n }\n\n #checkProperties(path: string, propertyDefinitions: Record<string, ElementDefinition>, typedValue: TypedValue): void {\n for (const [key, elementDefinition] of Object.entries(propertyDefinitions)) {\n this.#checkProperty(path + '.' + key, elementDefinition, typedValue);\n }\n }\n\n #checkProperty(path: string, elementDefinition: ElementDefinition, typedValue: TypedValue): void {\n const propertyName = path.split('.').pop() as string;\n const value = getTypedPropertyValue(typedValue, propertyName);\n\n if (isEmpty(value)) {\n if (elementDefinition.min !== undefined && elementDefinition.min > 0) {\n this.#issues.push(createStructureIssue(path, 'Missing required property'));\n }\n return;\n }\n\n if (elementDefinition.max === '*') {\n if (!Array.isArray(value)) {\n this.#issues.push(createStructureIssue(path, 'Expected array for property'));\n return;\n }\n for (const item of value) {\n this.#checkPropertyValue(path, elementDefinition, item);\n }\n } else {\n this.#checkPropertyValue(path, elementDefinition, value as TypedValue);\n }\n }\n\n #checkPropertyValue(path: string, elementDefinition: ElementDefinition, typedValue: TypedValue): void {\n if (typedValue.value === null) {\n // Null handled separately\n return;\n }\n\n if (isLowerCase(typedValue.type.charAt(0))) {\n this.#validatePrimitiveType(elementDefinition, typedValue);\n } else {\n this.#validateObject(typedValue, path);\n }\n }\n\n #validatePrimitiveType(elementDefinition: ElementDefinition, typedValue: TypedValue): void {\n const { type, value } = typedValue;\n\n if (value === null) {\n // Null handled separately, so this code should never be reached\n // Leaving this check in place for now, in case we change the null handling\n return;\n }\n\n // First, make sure the value is the correct JS type\n const expectedType = fhirTypeToJsType[typedValue.type];\n if (typeof value !== expectedType) {\n this.#createIssue(elementDefinition, 'Invalid type for ' + type);\n return;\n }\n\n // Then, perform additional checks for specialty types\n if (expectedType === 'string') {\n this.#validateString(elementDefinition, type as PropertyType, value as string);\n } else if (expectedType === 'number') {\n this.#validateNumber(elementDefinition, type as PropertyType, value as number);\n }\n }\n\n #validateString(elementDefinition: ElementDefinition, type: PropertyType, value: string): void {\n if (!value.trim()) {\n this.#createIssue(elementDefinition, 'Invalid empty string');\n return;\n }\n\n // Try to get the regex\n const valueDefinition = globalSchema.types[type]?.properties?.['value'];\n if (valueDefinition?.type) {\n const regex = getExtensionValue(valueDefinition.type[0], 'http://hl7.org/fhir/StructureDefinition/regex');\n if (regex) {\n if (!value.match(new RegExp(regex))) {\n this.#createIssue(elementDefinition, 'Invalid ' + type + ' format');\n }\n }\n }\n }\n\n #validateNumber(elementDefinition: ElementDefinition, type: PropertyType, value: number): void {\n if (isNaN(value) || !isFinite(value)) {\n this.#createIssue(elementDefinition, 'Invalid ' + type + ' value');\n return;\n }\n\n if (isIntegerType(type) && !Number.isInteger(value)) {\n this.#createIssue(elementDefinition, 'Number is not an integer');\n }\n\n if (type === PropertyType.positiveInt && value <= 0) {\n this.#createIssue(elementDefinition, 'Number is less than or equal to zero');\n }\n\n if (type === PropertyType.unsignedInt && value < 0) {\n this.#createIssue(elementDefinition, 'Number is negative');\n }\n }\n\n #checkAdditionalProperties(\n path: string,\n typedValue: TypedValue,\n propertyDefinitions: Record<string, ElementDefinition>\n ): void {\n const object = typedValue.value as Record<string, unknown>;\n for (const key of Object.keys(object)) {\n this.#checkAdditionalProperty(path, key, typedValue, propertyDefinitions);\n }\n }\n\n /**\n * Checks if the given property is allowed on the given object.\n * @param path The path of the current object.\n * @param key The key of a property to check.\n * @param typedValue The current object.\n * @param propertyDefinitions The property definitions of the current object.\n */\n #checkAdditionalProperty(\n path: string,\n key: string,\n typedValue: TypedValue,\n propertyDefinitions: Record<string, ElementDefinition>\n ): void {\n if (\n !baseResourceProperties.has(key) &&\n !(key in propertyDefinitions) &&\n !isChoiceOfType(key, typedValue, propertyDefinitions) &&\n !this.#checkPrimitiveElement(path, key, typedValue)\n ) {\n const expression = `${path}.${key}`;\n this.#issues.push(createStructureIssue(expression, `Invalid additional property \"${expression}\"`));\n }\n }\n\n /**\n * Checks the element for a primitive.\n *\n * FHIR elements with primitive data types are represented in two parts:\n * 1) A JSON property with the name of the element, which has a JSON type of number, boolean, or string\n * 2) a JSON property with _ prepended to the name of the element, which, if present, contains the value's id and/or extensions\n *\n * See: https://hl7.org/fhir/json.html#primitive\n *\n * @param path The path to the property\n * @param key\n * @param typedValue\n */\n #checkPrimitiveElement(path: string, key: string, typedValue: TypedValue): boolean {\n // Primitive element starts with underscore\n if (!key.startsWith('_')) {\n return false;\n }\n\n // Validate the non-underscore property exists\n const primitiveKey = key.slice(1);\n if (!(primitiveKey in typedValue.value)) {\n return false;\n }\n\n // Then validate the element\n this.#validateObject({ type: 'Element', value: typedValue.value[key] }, path);\n return true;\n }\n\n #createIssue(elementDefinition: ElementDefinition, message: string): void {\n this.#issues.push(createStructureIssue(elementDefinition.path as string, message));\n }\n}\n\nfunction isIntegerType(propertyType: PropertyType): boolean {\n return (\n propertyType === PropertyType.integer ||\n propertyType === PropertyType.positiveInt ||\n propertyType === PropertyType.unsignedInt\n );\n}\n\nfunction isChoiceOfType(\n key: string,\n typedValue: TypedValue,\n propertyDefinitions: Record<string, ElementDefinition>\n): boolean {\n for (const propertyName of Object.keys(propertyDefinitions)) {\n if (!propertyName.endsWith('[x]')) {\n continue;\n }\n const basePropertyName = propertyName.replace('[x]', '');\n if (!key.startsWith(basePropertyName)) {\n continue;\n }\n let typedPropertyValue = getTypedPropertyValue(typedValue, propertyName);\n if (!typedPropertyValue) {\n continue;\n }\n if (Array.isArray(typedPropertyValue)) {\n // At present, there are no choice types that are arrays in the FHIR spec\n // Leaving this here to make TypeScript happy, and in case that changes\n typedPropertyValue = typedPropertyValue[0];\n }\n if (typedPropertyValue && key === basePropertyName + capitalize(typedPropertyValue.type)) {\n return true;\n }\n }\n return false;\n}\n\n/**\n * Recursively checks for null values in an object.\n *\n * Note that \"null\" is a special value in JSON that is not allowed in FHIR.\n *\n * @param value Input value of any type.\n * @param path Path string to the value for OperationOutcome.\n * @param issues Output list of issues.\n */\nexport function checkForNull(value: unknown, path: string, issues: OperationOutcomeIssue[]): void {\n if (value === null) {\n issues.push(createStructureIssue(path, 'Invalid null value'));\n } else if (Array.isArray(value)) {\n checkArrayForNull(value, path, issues);\n } else if (typeof value === 'object') {\n checkObjectForNull(value as Record<string, unknown>, path, issues);\n }\n}\n\nfunction checkArrayForNull(array: unknown[], path: string, issues: OperationOutcomeIssue[]): void {\n for (let i = 0; i < array.length; i++) {\n if (array[i] === undefined) {\n issues.push(createStructureIssue(`${path}[${i}]`, 'Invalid undefined value'));\n } else {\n checkForNull(array[i], `${path}[${i}]`, issues);\n }\n }\n}\n\nfunction checkObjectForNull(obj: Record<string, unknown>, path: string, issues: OperationOutcomeIssue[]): void {\n for (const [key, value] of Object.entries(obj)) {\n checkForNull(value, `${path}${path ? '.' : ''}${key}`, issues);\n }\n}\n\nexport function createStructureIssue(expression: string, details: string): OperationOutcomeIssue {\n return {\n severity: 'error',\n code: 'structure',\n details: {\n text: details,\n },\n expression: [expression],\n };\n}\n"],"names":[],"mappings":";;;;;;;;;;;AAMA;;;;;AAKG;AAEH,MAAM,gBAAgB,GAA2B;AAC/C,IAAA,YAAY,EAAE,QAAQ;AACtB,IAAA,OAAO,EAAE,SAAS;AAClB,IAAA,SAAS,EAAE,QAAQ;AACnB,IAAA,IAAI,EAAE,QAAQ;AACd,IAAA,IAAI,EAAE,QAAQ;AACd,IAAA,QAAQ,EAAE,QAAQ;AAClB,IAAA,OAAO,EAAE,QAAQ;AACjB,IAAA,EAAE,EAAE,QAAQ;AACZ,IAAA,OAAO,EAAE,QAAQ;AACjB,IAAA,OAAO,EAAE,QAAQ;AACjB,IAAA,QAAQ,EAAE,QAAQ;AAClB,IAAA,GAAG,EAAE,QAAQ;AACb,IAAA,WAAW,EAAE,QAAQ;AACrB,IAAA,MAAM,EAAE,QAAQ;AAChB,IAAA,IAAI,EAAE,QAAQ;AACd,IAAA,WAAW,EAAE,QAAQ;AACrB,IAAA,GAAG,EAAE,QAAQ;AACb,IAAA,GAAG,EAAE,QAAQ;AACb,IAAA,IAAI,EAAE,QAAQ;AACd,IA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I,EAAE,OAAO;AACd,SAAA;QACD,UAAU,EAAE,CAAC,UAAU,CAAC;KACzB,CAAC;AACJ;;;;"}
@@ -96,7 +96,7 @@ function indexStructureDefinition(structureDefinition) {
96
96
  // First pass, build types
97
97
  elements.forEach((element) => indexType(structureDefinition, element));
98
98
  // Second pass, build properties
99
- elements.forEach((element) => indexProperty(element));
99
+ elements.forEach((element) => indexProperty(structureDefinition, element));
100
100
  }
101
101
  }
102
102
  /**
@@ -114,6 +114,9 @@ function indexType(structureDefinition, elementDefinition) {
114
114
  return;
115
115
  }
116
116
  const parts = path.split('.');
117
+ // Force the first part to be the type name
118
+ // This is necessary for "SimpleQuantity" and "MoneyQuantity"
119
+ parts[0] = structureDefinition.name;
117
120
  const typeName = buildTypeName(parts);
118
121
  let typeSchema = globalSchema.types[typeName];
119
122
  if (!typeSchema) {
@@ -131,12 +134,15 @@ function indexType(structureDefinition, elementDefinition) {
131
134
  * @param element The input ElementDefinition.
132
135
  * @see {@link IndexedStructureDefinition} for more details on indexed StructureDefinitions.
133
136
  */
134
- function indexProperty(element) {
137
+ function indexProperty(structureDefinition, element) {
135
138
  const path = element.path;
136
139
  const parts = path.split('.');
137
140
  if (parts.length === 1) {
138
141
  return;
139
142
  }
143
+ // Force the first part to be the type name
144
+ // This is necessary for "SimpleQuantity" and "MoneyQuantity"
145
+ parts[0] = structureDefinition.name;
140
146
  const typeName = buildTypeName(parts.slice(0, parts.length - 1));
141
147
  const typeSchema = globalSchema.types[typeName];
142
148
  if (!typeSchema) {
@@ -240,12 +246,16 @@ function buildTypeName(components) {
240
246
  return components.map(capitalize).join('');
241
247
  }
242
248
  /**
243
- * Returns true if the type schema is a DomainResource.
249
+ * Returns true if the type schema is a non-abstract FHIR resource.
244
250
  * @param typeSchema The type schema to check.
245
- * @returns True if the type schema is a DomainResource.
251
+ * @returns True if the type schema is a non-abstract FHIR resource.
246
252
  */
247
- function isResourceType(typeSchema) {
248
- return typeSchema.structureDefinition?.baseDefinition === 'http://hl7.org/fhir/StructureDefinition/DomainResource';
253
+ function isResourceTypeSchema(typeSchema) {
254
+ const structureDefinition = typeSchema.structureDefinition;
255
+ return (structureDefinition &&
256
+ structureDefinition.name === typeSchema.elementDefinition?.path &&
257
+ structureDefinition.kind === 'resource' &&
258
+ !structureDefinition.abstract);
249
259
  }
250
260
  /**
251
261
  * Returns an array of all resource types.
@@ -255,7 +265,7 @@ function isResourceType(typeSchema) {
255
265
  function getResourceTypes() {
256
266
  const result = [];
257
267
  for (const [resourceType, typeSchema] of Object.entries(globalSchema.types)) {
258
- if (isResourceType(typeSchema)) {
268
+ if (isResourceTypeSchema(typeSchema)) {
259
269
  result.push(resourceType);
260
270
  }
261
271
  }
@@ -334,10 +344,26 @@ function getElementDefinition(typeName, propertyName) {
334
344
  }
335
345
  return property;
336
346
  }
347
+ /**
348
+ * Typeguard to validate that an object is a FHIR resource
349
+ * @param value The object to check
350
+ * @returns True if the input is of type 'object' and contains property 'resourceType'
351
+ */
352
+ function isResource(value) {
353
+ return !!(value && typeof value === 'object' && 'resourceType' in value);
354
+ }
355
+ /**
356
+ * Typeguard to validate that an object is a FHIR resource
357
+ * @param value The object to check
358
+ * @returns True if the input is of type 'object' and contains property 'reference'
359
+ */
360
+ function isReference(value) {
361
+ return !!(value && typeof value === 'object' && 'reference' in value);
362
+ }
337
363
  /**
338
364
  * Global schema singleton.
339
365
  */
340
366
  const globalSchema = baseSchema;
341
367
 
342
- export { PropertyType, buildTypeName, getElementDefinition, getElementDefinitionTypeName, getPropertyDisplayName, getResourceTypeSchema, getResourceTypes, getSearchParameters, globalSchema, indexSearchParameter, indexSearchParameterBundle, indexStructureDefinition, indexStructureDefinitionBundle, isResourceType };
368
+ export { PropertyType, buildTypeName, getElementDefinition, getElementDefinitionTypeName, getPropertyDisplayName, getResourceTypeSchema, getResourceTypes, getSearchParameters, globalSchema, indexSearchParameter, indexSearchParameterBundle, indexStructureDefinition, indexStructureDefinitionBundle, isReference, isResource, isResourceTypeSchema };
343
369
  //# sourceMappingURL=types.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"types.mjs","sources":["../../src/types.ts"],"sourcesContent":["import {\n Bundle,\n BundleEntry,\n ElementDefinition,\n Resource,\n SearchParameter,\n StructureDefinition,\n} from '@medplum/fhirtypes';\nimport baseSchema from './base-schema.json';\nimport { SearchParameterDetails } from './search/details';\nimport { capitalize } from './utils';\n\nexport interface TypedValue {\n readonly type: string;\n readonly value: any;\n}\n\n/**\n * List of property types.\n * http://www.hl7.org/fhir/valueset-defined-types.html\n * The list here includes additions found from StructureDefinition resources.\n */\nexport enum PropertyType {\n Address = 'Address',\n Age = 'Age',\n Annotation = 'Annotation',\n Attachment = 'Attachment',\n BackboneElement = 'BackboneElement',\n CodeableConcept = 'CodeableConcept',\n Coding = 'Coding',\n ContactDetail = 'ContactDetail',\n ContactPoint = 'ContactPoint',\n Contributor = 'Contributor',\n Count = 'Count',\n DataRequirement = 'DataRequirement',\n Distance = 'Distance',\n Dosage = 'Dosage',\n Duration = 'Duration',\n Expression = 'Expression',\n Extension = 'Extension',\n HumanName = 'HumanName',\n Identifier = 'Identifier',\n MarketingStatus = 'MarketingStatus',\n Meta = 'Meta',\n Money = 'Money',\n Narrative = 'Narrative',\n ParameterDefinition = 'ParameterDefinition',\n Period = 'Period',\n Population = 'Population',\n ProdCharacteristic = 'ProdCharacteristic',\n ProductShelfLife = 'ProductShelfLife',\n Quantity = 'Quantity',\n Range = 'Range',\n Ratio = 'Ratio',\n Reference = 'Reference',\n RelatedArtifact = 'RelatedArtifact',\n SampledData = 'SampledData',\n Signature = 'Signature',\n SubstanceAmount = 'SubstanceAmount',\n SystemString = 'http://hl7.org/fhirpath/System.String',\n Timing = 'Timing',\n TriggerDefinition = 'TriggerDefinition',\n UsageContext = 'UsageContext',\n base64Binary = 'base64Binary',\n boolean = 'boolean',\n canonical = 'canonical',\n code = 'code',\n date = 'date',\n dateTime = 'dateTime',\n decimal = 'decimal',\n id = 'id',\n instant = 'instant',\n integer = 'integer',\n markdown = 'markdown',\n oid = 'oid',\n positiveInt = 'positiveInt',\n string = 'string',\n time = 'time',\n unsignedInt = 'unsignedInt',\n uri = 'uri',\n url = 'url',\n uuid = 'uuid',\n}\n\n/**\n * An IndexedStructureDefinition is a lookup-optimized version of a StructureDefinition.\n *\n * StructureDefinition resources contain schema information for other resource types.\n * These schemas can be used to automatically generate user interface elements for\n * resources.\n *\n * However, a StructureDefinition resource is not optimized for realtime lookups. All\n * resource types, sub types, and property definitions are stored in a flat array of\n * ElementDefinition objects. Therefore, to lookup the schema for a property (i.e., \"Patient.name\")\n * requires a linear scan of all ElementDefinition objects\n *\n * A StructureDefinition resource contains information about one or more types.\n * For example, the \"Patient\" StructureDefinition includes \"Patient\", \"Patient_Contact\",\n * \"Patient_Communication\", and \"Patient_Link\". This is inefficient.\n *\n * Instead, we create an indexed version of the StructureDefinition, called IndexedStructureDefinition.\n * In an IndexedStructureDefinition, retrieving a property definition is a hashtable lookup.\n *\n * The hierarchy is:\n * IndexedStructureDefinition - top level for one resource type\n * TypeSchema - one per resource type and all contained BackboneElements\n * PropertySchema - one per property/field\n */\nexport interface IndexedStructureDefinition {\n types: { [resourceType: string]: TypeSchema };\n}\n\n/**\n * An indexed TypeSchema.\n *\n * Example: The IndexedStructureDefinition for \"Patient\" would include the following TypeSchemas:\n * 1) Patient\n * 2) Patient_Contact\n * 3) Patient_Communication\n * 4) Patient_Link\n */\nexport interface TypeSchema {\n structureDefinition: StructureDefinition;\n elementDefinition: ElementDefinition;\n display: string;\n properties: { [name: string]: ElementDefinition };\n searchParams?: { [code: string]: SearchParameter };\n searchParamsDetails?: { [code: string]: SearchParameterDetails };\n description?: string;\n parentType?: string;\n}\n\n/**\n * Indexes a bundle of StructureDefinitions for faster lookup.\n * @param bundle A FHIR bundle StructureDefinition resources.\n * @see {@link IndexedStructureDefinition} for more details on indexed StructureDefinitions.\n */\nexport function indexStructureDefinitionBundle(bundle: Bundle): void {\n for (const entry of bundle.entry as BundleEntry[]) {\n const resource = entry.resource as Resource;\n if (resource.resourceType === 'StructureDefinition') {\n indexStructureDefinition(resource);\n }\n }\n}\n\n/**\n * Indexes a StructureDefinition for fast lookup.\n * @param structureDefinition The original StructureDefinition.\n * @see {@link IndexedStructureDefinition} for more details on indexed StructureDefinitions.\n */\nexport function indexStructureDefinition(structureDefinition: StructureDefinition): void {\n const typeName = structureDefinition.name;\n if (!typeName) {\n return;\n }\n\n const elements = structureDefinition.snapshot?.element;\n if (elements) {\n // First pass, build types\n elements.forEach((element) => indexType(structureDefinition, element));\n\n // Second pass, build properties\n elements.forEach((element) => indexProperty(element));\n }\n}\n\n/**\n * Indexes TypeSchema from an ElementDefinition.\n * In the common case, there will be many ElementDefinition instances per TypeSchema.\n * Only the first occurrence is saved.\n * @param structureDefinition The parent type structure definition.\n * @param elementDefinition The element definition.\n * @see {@link IndexedStructureDefinition} for more details on indexed StructureDefinitions.\n */\nfunction indexType(structureDefinition: StructureDefinition, elementDefinition: ElementDefinition): void {\n const path = elementDefinition.path as string;\n const typeCode = elementDefinition.type?.[0]?.code;\n if (typeCode !== undefined && typeCode !== 'Element' && typeCode !== 'BackboneElement') {\n return;\n }\n const parts = path.split('.');\n const typeName = buildTypeName(parts);\n let typeSchema = globalSchema.types[typeName];\n\n if (!typeSchema) {\n globalSchema.types[typeName] = typeSchema = {} as TypeSchema;\n }\n\n typeSchema.parentType = typeSchema.parentType || buildTypeName(parts.slice(0, parts.length - 1));\n typeSchema.display = typeSchema.display || typeName;\n typeSchema.structureDefinition = typeSchema.structureDefinition || structureDefinition;\n typeSchema.elementDefinition = typeSchema.elementDefinition || elementDefinition;\n typeSchema.description = typeSchema.description || elementDefinition.definition;\n typeSchema.properties = typeSchema.properties || {};\n}\n\n/**\n * Indexes PropertySchema from an ElementDefinition.\n * @param element The input ElementDefinition.\n * @see {@link IndexedStructureDefinition} for more details on indexed StructureDefinitions.\n */\nfunction indexProperty(element: ElementDefinition): void {\n const path = element.path as string;\n const parts = path.split('.');\n if (parts.length === 1) {\n return;\n }\n const typeName = buildTypeName(parts.slice(0, parts.length - 1));\n const typeSchema = globalSchema.types[typeName];\n if (!typeSchema) {\n return;\n }\n const key = parts[parts.length - 1];\n typeSchema.properties[key] = element;\n}\n\n/**\n * Indexes a bundle of SearchParameter resources for faster lookup.\n * @param bundle A FHIR bundle SearchParameter resources.\n * @see {@link IndexedStructureDefinition} for more details on indexed StructureDefinitions.\n */\nexport function indexSearchParameterBundle(bundle: Bundle<SearchParameter>): void {\n for (const entry of bundle.entry as BundleEntry[]) {\n const resource = entry.resource as SearchParameter;\n if (resource.resourceType === 'SearchParameter') {\n indexSearchParameter(resource);\n }\n }\n}\n\n/**\n * Indexes a SearchParameter resource for fast lookup.\n * Indexes by SearchParameter.code, which is the query string parameter name.\n * @param searchParam The SearchParameter resource.\n * @see {@link IndexedStructureDefinition} for more details on indexed StructureDefinitions.\n */\nexport function indexSearchParameter(searchParam: SearchParameter): void {\n if (!searchParam.base) {\n return;\n }\n\n for (const resourceType of searchParam.base) {\n const typeSchema = globalSchema.types[resourceType];\n if (!typeSchema) {\n continue;\n }\n\n if (!typeSchema.searchParams) {\n typeSchema.searchParams = {\n _id: {\n base: [resourceType],\n code: '_id',\n type: 'token',\n expression: resourceType + '.id',\n } as SearchParameter,\n _lastUpdated: {\n base: [resourceType],\n code: '_lastUpdated',\n type: 'date',\n expression: resourceType + '.meta.lastUpdated',\n } as SearchParameter,\n _compartment: {\n base: [resourceType],\n code: '_compartment',\n type: 'reference',\n expression: resourceType + '.meta.compartment',\n } as SearchParameter,\n _profile: {\n base: [resourceType],\n code: '_profile',\n type: 'uri',\n expression: resourceType + '.meta.profile',\n } as SearchParameter,\n _security: {\n base: [resourceType],\n code: '_security',\n type: 'token',\n expression: resourceType + '.meta.security',\n } as SearchParameter,\n _source: {\n base: [resourceType],\n code: '_source',\n type: 'uri',\n expression: resourceType + '.meta.source',\n } as SearchParameter,\n _tag: {\n base: [resourceType],\n code: '_tag',\n type: 'token',\n expression: resourceType + '.meta.tag',\n } as SearchParameter,\n };\n }\n\n typeSchema.searchParams[searchParam.code as string] = searchParam;\n }\n}\n\n/**\n * Returns the type name for an ElementDefinition.\n * @param elementDefinition The element definition.\n * @returns The Medplum type name.\n */\nexport function getElementDefinitionTypeName(elementDefinition: ElementDefinition): string {\n const code = elementDefinition.type?.[0]?.code as string;\n return code === 'BackboneElement' || code === 'Element'\n ? buildTypeName(elementDefinition.path?.split('.') as string[])\n : code;\n}\n\nexport function buildTypeName(components: string[]): string {\n if (components.length === 1) {\n return components[0];\n }\n return components.map(capitalize).join('');\n}\n\n/**\n * Returns true if the type schema is a DomainResource.\n * @param typeSchema The type schema to check.\n * @returns True if the type schema is a DomainResource.\n */\nexport function isResourceType(typeSchema: TypeSchema): boolean {\n return typeSchema.structureDefinition?.baseDefinition === 'http://hl7.org/fhir/StructureDefinition/DomainResource';\n}\n\n/**\n * Returns an array of all resource types.\n * Note that this is based on globalSchema, and will only return resource types that are currently in memory.\n * @returns An array of all resource types.\n */\nexport function getResourceTypes(): string[] {\n const result: string[] = [];\n for (const [resourceType, typeSchema] of Object.entries(globalSchema.types)) {\n if (isResourceType(typeSchema)) {\n result.push(resourceType);\n }\n }\n return result;\n}\n\n/**\n * Returns the type schema for the resource type.\n * @param resourceType The resource type.\n * @returns The type schema for the resource type.\n */\nexport function getResourceTypeSchema(resourceType: string): TypeSchema {\n return globalSchema.types[resourceType];\n}\n\n/**\n * Returns the search parameters for the resource type indexed by search code.\n * @param resourceType The resource type.\n * @returns The search parameters for the resource type indexed by search code.\n */\nexport function getSearchParameters(resourceType: string): Record<string, SearchParameter> | undefined {\n return globalSchema.types[resourceType].searchParams;\n}\n\n/**\n * Returns a human friendly display name for a FHIR element definition path.\n * @param path The FHIR element definition path.\n * @returns The best guess of the display name.\n */\nexport function getPropertyDisplayName(path: string): string {\n // Get the property name, which is the remainder after the last period\n // For example, for path \"Patient.birthDate\"\n // the property name is \"birthDate\"\n const propertyName = path.replaceAll('[x]', '').split('.').pop() as string;\n\n // Split by capital letters\n // Capitalize the first letter of each word\n // Join together with spaces in between\n // Then normalize whitespace to single space character\n // For example, for property name \"birthDate\",\n // the display name is \"Birth Date\".\n return propertyName\n .split(/(?=[A-Z])/)\n .map(capitalizeDisplayWord)\n .join(' ')\n .replace('_', ' ')\n .replace(/\\s+/g, ' ');\n}\n\nconst capitalizedWords = new Set(['ID', 'PKCE', 'JWKS', 'URI', 'URL']);\n\nfunction capitalizeDisplayWord(word: string): string {\n const upper = word.toUpperCase();\n if (capitalizedWords.has(upper)) {\n return upper;\n }\n return upper.charAt(0) + word.slice(1);\n}\n\n/**\n * Returns an element definition by type and property name.\n * Handles content references.\n * @param typeName The type name.\n * @param propertyName The property name.\n * @returns The element definition if found.\n */\nexport function getElementDefinition(typeName: string, propertyName: string): ElementDefinition | undefined {\n const typeSchema = globalSchema.types[typeName];\n if (!typeSchema) {\n return undefined;\n }\n\n const property = typeSchema.properties[propertyName] ?? typeSchema.properties[propertyName + '[x]'];\n if (!property) {\n return undefined;\n }\n\n if (property.contentReference) {\n // Content references start with a \"#\"\n // Remove the \"#\" character\n const contentReference = property.contentReference.substring(1).split('.');\n const referencePropertyName = contentReference.pop() as string;\n const referenceTypeName = buildTypeName(contentReference);\n return getElementDefinition(referenceTypeName, referencePropertyName);\n }\n\n return property;\n}\n\n/**\n * Global schema singleton.\n */\nexport const globalSchema = baseSchema as unknown as IndexedStructureDefinition;\n"],"names":[],"mappings":";;;AAiBA;;;;AAIG;IACS,aA4DX;AA5DD,CAAA,UAAY,YAAY,EAAA;AACtB,IAAA,YAAA,CAAA,SAAA,CAAA,GAAA,SAAmB,CAAA;AACnB,IAAA,YAAA,CAAA,KAAA,CAAA,GAAA,KAAW,CAAA;AACX,IAAA,YAAA,CAAA,YAAA,CAAA,GAAA,YAAyB,CAAA;AACzB,IAAA,YAAA,CAAA,YAAA,CAAA,GAAA,YAAyB,CAAA;AACzB,IAAA,YAAA,CAAA,iBAAA,CAAA,GAAA,iBAAmC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,CAAC;AACzC,CAAC;AAED;;;;;;AAMG;AACa,SAAA,oBAAoB,CAAC,QAAgB,EAAE,YAAoB,EAAA;IACzE,MAAM,UAAU,GAAG,YAAY,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC;IAChD,IAAI,CAAC,UAAU,EAAE;AACf,QAAA,OAAO,SAAS,CAAC;AAClB,KAAA;AAED,IAAA,MAAM,QAAQ,GAAG,UAAU,CAAC,UAAU,CAAC,YAAY,CAAC,IAAI,UAAU,CAAC,UAAU,CAAC,YAAY,GAAG,KAAK,CAAC,CAAC;IACpG,IAAI,CAAC,QAAQ,EAAE;AACb,QAAA,OAAO,SAAS,CAAC;AAClB,KAAA;IAED,IAAI,QAAQ,CAAC,gBAAgB,EAAE;;;AAG7B,QAAA,MAAM,gBAAgB,GAAG,QAAQ,CAAC,gBAAgB,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;AAC3E,QAAA,MAAM,qBAAqB,GAAG,gBAAgB,CAAC,GAAG,EAAY,CAAC;AAC/D,QAAA,MAAM,iBAAiB,GAAG,aAAa,CAAC,gBAAgB,CAAC,CAAC;AAC1D,QAAA,OAAO,oBAAoB,CAAC,iBAAiB,EAAE,qBAAqB,CAAC,CAAC;AACvE,KAAA;AAED,IAAA,OAAO,QAAQ,CAAC;AAClB,CAAC;AAED;;AAEG;AACI,MAAM,YAAY,GAAG;;;;"}
1
+ {"version":3,"file":"types.mjs","sources":["../../src/types.ts"],"sourcesContent":["import {\n Bundle,\n BundleEntry,\n ElementDefinition,\n Reference,\n Resource,\n ResourceType,\n SearchParameter,\n StructureDefinition,\n} from '@medplum/fhirtypes';\nimport baseSchema from './base-schema.json';\nimport { SearchParameterDetails } from './search/details';\nimport { capitalize } from './utils';\n\nexport interface TypedValue {\n readonly type: string;\n readonly value: any;\n}\n\n/**\n * List of property types.\n * http://www.hl7.org/fhir/valueset-defined-types.html\n * The list here includes additions found from StructureDefinition resources.\n */\nexport enum PropertyType {\n Address = 'Address',\n Age = 'Age',\n Annotation = 'Annotation',\n Attachment = 'Attachment',\n BackboneElement = 'BackboneElement',\n CodeableConcept = 'CodeableConcept',\n Coding = 'Coding',\n ContactDetail = 'ContactDetail',\n ContactPoint = 'ContactPoint',\n Contributor = 'Contributor',\n Count = 'Count',\n DataRequirement = 'DataRequirement',\n Distance = 'Distance',\n Dosage = 'Dosage',\n Duration = 'Duration',\n Expression = 'Expression',\n Extension = 'Extension',\n HumanName = 'HumanName',\n Identifier = 'Identifier',\n MarketingStatus = 'MarketingStatus',\n Meta = 'Meta',\n Money = 'Money',\n Narrative = 'Narrative',\n ParameterDefinition = 'ParameterDefinition',\n Period = 'Period',\n Population = 'Population',\n ProdCharacteristic = 'ProdCharacteristic',\n ProductShelfLife = 'ProductShelfLife',\n Quantity = 'Quantity',\n Range = 'Range',\n Ratio = 'Ratio',\n Reference = 'Reference',\n RelatedArtifact = 'RelatedArtifact',\n SampledData = 'SampledData',\n Signature = 'Signature',\n SubstanceAmount = 'SubstanceAmount',\n SystemString = 'http://hl7.org/fhirpath/System.String',\n Timing = 'Timing',\n TriggerDefinition = 'TriggerDefinition',\n UsageContext = 'UsageContext',\n base64Binary = 'base64Binary',\n boolean = 'boolean',\n canonical = 'canonical',\n code = 'code',\n date = 'date',\n dateTime = 'dateTime',\n decimal = 'decimal',\n id = 'id',\n instant = 'instant',\n integer = 'integer',\n markdown = 'markdown',\n oid = 'oid',\n positiveInt = 'positiveInt',\n string = 'string',\n time = 'time',\n unsignedInt = 'unsignedInt',\n uri = 'uri',\n url = 'url',\n uuid = 'uuid',\n}\n\n/**\n * An IndexedStructureDefinition is a lookup-optimized version of a StructureDefinition.\n *\n * StructureDefinition resources contain schema information for other resource types.\n * These schemas can be used to automatically generate user interface elements for\n * resources.\n *\n * However, a StructureDefinition resource is not optimized for realtime lookups. All\n * resource types, sub types, and property definitions are stored in a flat array of\n * ElementDefinition objects. Therefore, to lookup the schema for a property (i.e., \"Patient.name\")\n * requires a linear scan of all ElementDefinition objects\n *\n * A StructureDefinition resource contains information about one or more types.\n * For example, the \"Patient\" StructureDefinition includes \"Patient\", \"Patient_Contact\",\n * \"Patient_Communication\", and \"Patient_Link\". This is inefficient.\n *\n * Instead, we create an indexed version of the StructureDefinition, called IndexedStructureDefinition.\n * In an IndexedStructureDefinition, retrieving a property definition is a hashtable lookup.\n *\n * The hierarchy is:\n * IndexedStructureDefinition - top level for one resource type\n * TypeSchema - one per resource type and all contained BackboneElements\n * PropertySchema - one per property/field\n */\nexport interface IndexedStructureDefinition {\n types: { [resourceType: string]: TypeSchema };\n}\n\n/**\n * An indexed TypeSchema.\n *\n * Example: The IndexedStructureDefinition for \"Patient\" would include the following TypeSchemas:\n * 1) Patient\n * 2) Patient_Contact\n * 3) Patient_Communication\n * 4) Patient_Link\n */\nexport interface TypeSchema {\n structureDefinition: StructureDefinition;\n elementDefinition: ElementDefinition;\n display: string;\n properties: { [name: string]: ElementDefinition };\n searchParams?: { [code: string]: SearchParameter };\n searchParamsDetails?: { [code: string]: SearchParameterDetails };\n description?: string;\n parentType?: string;\n}\n\n/**\n * Indexes a bundle of StructureDefinitions for faster lookup.\n * @param bundle A FHIR bundle StructureDefinition resources.\n * @see {@link IndexedStructureDefinition} for more details on indexed StructureDefinitions.\n */\nexport function indexStructureDefinitionBundle(bundle: Bundle): void {\n for (const entry of bundle.entry as BundleEntry[]) {\n const resource = entry.resource as Resource;\n if (resource.resourceType === 'StructureDefinition') {\n indexStructureDefinition(resource);\n }\n }\n}\n\n/**\n * Indexes a StructureDefinition for fast lookup.\n * @param structureDefinition The original StructureDefinition.\n * @see {@link IndexedStructureDefinition} for more details on indexed StructureDefinitions.\n */\nexport function indexStructureDefinition(structureDefinition: StructureDefinition): void {\n const typeName = structureDefinition.name;\n if (!typeName) {\n return;\n }\n\n const elements = structureDefinition.snapshot?.element;\n if (elements) {\n // First pass, build types\n elements.forEach((element) => indexType(structureDefinition, element));\n\n // Second pass, build properties\n elements.forEach((element) => indexProperty(structureDefinition, element));\n }\n}\n\n/**\n * Indexes TypeSchema from an ElementDefinition.\n * In the common case, there will be many ElementDefinition instances per TypeSchema.\n * Only the first occurrence is saved.\n * @param structureDefinition The parent type structure definition.\n * @param elementDefinition The element definition.\n * @see {@link IndexedStructureDefinition} for more details on indexed StructureDefinitions.\n */\nfunction indexType(structureDefinition: StructureDefinition, elementDefinition: ElementDefinition): void {\n const path = elementDefinition.path as string;\n const typeCode = elementDefinition.type?.[0]?.code;\n if (typeCode !== undefined && typeCode !== 'Element' && typeCode !== 'BackboneElement') {\n return;\n }\n\n const parts = path.split('.');\n\n // Force the first part to be the type name\n // This is necessary for \"SimpleQuantity\" and \"MoneyQuantity\"\n parts[0] = structureDefinition.name as string;\n\n const typeName = buildTypeName(parts);\n let typeSchema = globalSchema.types[typeName];\n\n if (!typeSchema) {\n globalSchema.types[typeName] = typeSchema = {} as TypeSchema;\n }\n\n typeSchema.parentType = typeSchema.parentType || buildTypeName(parts.slice(0, parts.length - 1));\n typeSchema.display = typeSchema.display || typeName;\n typeSchema.structureDefinition = typeSchema.structureDefinition || structureDefinition;\n typeSchema.elementDefinition = typeSchema.elementDefinition || elementDefinition;\n typeSchema.description = typeSchema.description || elementDefinition.definition;\n typeSchema.properties = typeSchema.properties || {};\n}\n\n/**\n * Indexes PropertySchema from an ElementDefinition.\n * @param element The input ElementDefinition.\n * @see {@link IndexedStructureDefinition} for more details on indexed StructureDefinitions.\n */\nfunction indexProperty(structureDefinition: StructureDefinition, element: ElementDefinition): void {\n const path = element.path as string;\n const parts = path.split('.');\n if (parts.length === 1) {\n return;\n }\n\n // Force the first part to be the type name\n // This is necessary for \"SimpleQuantity\" and \"MoneyQuantity\"\n parts[0] = structureDefinition.name as string;\n\n const typeName = buildTypeName(parts.slice(0, parts.length - 1));\n const typeSchema = globalSchema.types[typeName];\n if (!typeSchema) {\n return;\n }\n const key = parts[parts.length - 1];\n typeSchema.properties[key] = element;\n}\n\n/**\n * Indexes a bundle of SearchParameter resources for faster lookup.\n * @param bundle A FHIR bundle SearchParameter resources.\n * @see {@link IndexedStructureDefinition} for more details on indexed StructureDefinitions.\n */\nexport function indexSearchParameterBundle(bundle: Bundle<SearchParameter>): void {\n for (const entry of bundle.entry as BundleEntry[]) {\n const resource = entry.resource as SearchParameter;\n if (resource.resourceType === 'SearchParameter') {\n indexSearchParameter(resource);\n }\n }\n}\n\n/**\n * Indexes a SearchParameter resource for fast lookup.\n * Indexes by SearchParameter.code, which is the query string parameter name.\n * @param searchParam The SearchParameter resource.\n * @see {@link IndexedStructureDefinition} for more details on indexed StructureDefinitions.\n */\nexport function indexSearchParameter(searchParam: SearchParameter): void {\n if (!searchParam.base) {\n return;\n }\n\n for (const resourceType of searchParam.base) {\n const typeSchema = globalSchema.types[resourceType];\n if (!typeSchema) {\n continue;\n }\n\n if (!typeSchema.searchParams) {\n typeSchema.searchParams = {\n _id: {\n base: [resourceType],\n code: '_id',\n type: 'token',\n expression: resourceType + '.id',\n } as SearchParameter,\n _lastUpdated: {\n base: [resourceType],\n code: '_lastUpdated',\n type: 'date',\n expression: resourceType + '.meta.lastUpdated',\n } as SearchParameter,\n _compartment: {\n base: [resourceType],\n code: '_compartment',\n type: 'reference',\n expression: resourceType + '.meta.compartment',\n } as SearchParameter,\n _profile: {\n base: [resourceType],\n code: '_profile',\n type: 'uri',\n expression: resourceType + '.meta.profile',\n } as SearchParameter,\n _security: {\n base: [resourceType],\n code: '_security',\n type: 'token',\n expression: resourceType + '.meta.security',\n } as SearchParameter,\n _source: {\n base: [resourceType],\n code: '_source',\n type: 'uri',\n expression: resourceType + '.meta.source',\n } as SearchParameter,\n _tag: {\n base: [resourceType],\n code: '_tag',\n type: 'token',\n expression: resourceType + '.meta.tag',\n } as SearchParameter,\n };\n }\n\n typeSchema.searchParams[searchParam.code as string] = searchParam;\n }\n}\n\n/**\n * Returns the type name for an ElementDefinition.\n * @param elementDefinition The element definition.\n * @returns The Medplum type name.\n */\nexport function getElementDefinitionTypeName(elementDefinition: ElementDefinition): string {\n const code = elementDefinition.type?.[0]?.code as string;\n return code === 'BackboneElement' || code === 'Element'\n ? buildTypeName(elementDefinition.path?.split('.') as string[])\n : code;\n}\n\nexport function buildTypeName(components: string[]): string {\n if (components.length === 1) {\n return components[0];\n }\n return components.map(capitalize).join('');\n}\n\n/**\n * Returns true if the type schema is a non-abstract FHIR resource.\n * @param typeSchema The type schema to check.\n * @returns True if the type schema is a non-abstract FHIR resource.\n */\nexport function isResourceTypeSchema(typeSchema: TypeSchema): boolean {\n const structureDefinition = typeSchema.structureDefinition;\n return (\n structureDefinition &&\n structureDefinition.name === typeSchema.elementDefinition?.path &&\n structureDefinition.kind === 'resource' &&\n !structureDefinition.abstract\n );\n}\n\n/**\n * Returns an array of all resource types.\n * Note that this is based on globalSchema, and will only return resource types that are currently in memory.\n * @returns An array of all resource types.\n */\nexport function getResourceTypes(): ResourceType[] {\n const result: ResourceType[] = [];\n for (const [resourceType, typeSchema] of Object.entries(globalSchema.types)) {\n if (isResourceTypeSchema(typeSchema)) {\n result.push(resourceType as ResourceType);\n }\n }\n return result;\n}\n\n/**\n * Returns the type schema for the resource type.\n * @param resourceType The resource type.\n * @returns The type schema for the resource type.\n */\nexport function getResourceTypeSchema(resourceType: string): TypeSchema {\n return globalSchema.types[resourceType];\n}\n\n/**\n * Returns the search parameters for the resource type indexed by search code.\n * @param resourceType The resource type.\n * @returns The search parameters for the resource type indexed by search code.\n */\nexport function getSearchParameters(resourceType: string): Record<string, SearchParameter> | undefined {\n return globalSchema.types[resourceType].searchParams;\n}\n\n/**\n * Returns a human friendly display name for a FHIR element definition path.\n * @param path The FHIR element definition path.\n * @returns The best guess of the display name.\n */\nexport function getPropertyDisplayName(path: string): string {\n // Get the property name, which is the remainder after the last period\n // For example, for path \"Patient.birthDate\"\n // the property name is \"birthDate\"\n const propertyName = path.replaceAll('[x]', '').split('.').pop() as string;\n\n // Split by capital letters\n // Capitalize the first letter of each word\n // Join together with spaces in between\n // Then normalize whitespace to single space character\n // For example, for property name \"birthDate\",\n // the display name is \"Birth Date\".\n return propertyName\n .split(/(?=[A-Z])/)\n .map(capitalizeDisplayWord)\n .join(' ')\n .replace('_', ' ')\n .replace(/\\s+/g, ' ');\n}\n\nconst capitalizedWords = new Set(['ID', 'PKCE', 'JWKS', 'URI', 'URL']);\n\nfunction capitalizeDisplayWord(word: string): string {\n const upper = word.toUpperCase();\n if (capitalizedWords.has(upper)) {\n return upper;\n }\n return upper.charAt(0) + word.slice(1);\n}\n\n/**\n * Returns an element definition by type and property name.\n * Handles content references.\n * @param typeName The type name.\n * @param propertyName The property name.\n * @returns The element definition if found.\n */\nexport function getElementDefinition(typeName: string, propertyName: string): ElementDefinition | undefined {\n const typeSchema = globalSchema.types[typeName];\n if (!typeSchema) {\n return undefined;\n }\n\n const property = typeSchema.properties[propertyName] ?? typeSchema.properties[propertyName + '[x]'];\n if (!property) {\n return undefined;\n }\n\n if (property.contentReference) {\n // Content references start with a \"#\"\n // Remove the \"#\" character\n const contentReference = property.contentReference.substring(1).split('.');\n const referencePropertyName = contentReference.pop() as string;\n const referenceTypeName = buildTypeName(contentReference);\n return getElementDefinition(referenceTypeName, referencePropertyName);\n }\n\n return property;\n}\n\n/**\n * Typeguard to validate that an object is a FHIR resource\n * @param value The object to check\n * @returns True if the input is of type 'object' and contains property 'resourceType'\n */\nexport function isResource<T extends Resource = Resource>(\n value: T | Reference<T> | string | undefined | null\n): value is T {\n return !!(value && typeof value === 'object' && 'resourceType' in value);\n}\n\n/**\n * Typeguard to validate that an object is a FHIR resource\n * @param value The object to check\n * @returns True if the input is of type 'object' and contains property 'reference'\n */\nexport function isReference<T extends Resource>(\n value: T | Reference<T> | string | undefined | null\n): value is Reference<T> & { reference: string } {\n return !!(value && typeof value === 'object' && 'reference' in value);\n}\n\n/**\n * Global schema singleton.\n */\nexport const globalSchema = baseSchema as unknown as IndexedStructureDefinition;\n"],"names":[],"mappings":";;;AAmBA;;;;AAIG;IACS,aA4DX;AA5DD,C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C3E,QAAA,MAAM,qBAAqB,GAAG,gBAAgB,CAAC,GAAG,EAAY,CAAC;AAC/D,QAAA,MAAM,iBAAiB,GAAG,aAAa,CAAC,gBAAgB,CAAC,CAAC;AAC1D,QAAA,OAAO,oBAAoB,CAAC,iBAAiB,EAAE,qBAAqB,CAAC,CAAC;AACvE,KAAA;AAED,IAAA,OAAO,QAAQ,CAAC;AAClB,CAAC;AAED;;;;AAIG;AACG,SAAU,UAAU,CACxB,KAAmD,EAAA;AAEnD,IAAA,OAAO,CAAC,EAAE,KAAK,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,cAAc,IAAI,KAAK,CAAC,CAAC;AAC3E,CAAC;AAED;;;;AAIG;AACG,SAAU,WAAW,CACzB,KAAmD,EAAA;AAEnD,IAAA,OAAO,CAAC,EAAE,KAAK,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,WAAW,IAAI,KAAK,CAAC,CAAC;AACxE,CAAC;AAED;;AAEG;AACI,MAAM,YAAY,GAAG;;;;"}
@@ -139,6 +139,17 @@ export interface MedplumClientOptions {
139
139
  export interface FetchLike {
140
140
  (url: string, options?: any): Promise<any>;
141
141
  }
142
+ /**
143
+ * QueryTypes defines the different ways to specify FHIR search parameters.
144
+ *
145
+ * Can be any valid input to the URLSearchParams() constructor.
146
+ *
147
+ * TypeScript definitions for URLSearchParams do not match runtime behavior.
148
+ * The official spec only accepts string values.
149
+ * Web browsers and Node.js automatically coerce values to strings.
150
+ * See: https://github.com/microsoft/TypeScript/issues/32951
151
+ */
152
+ export type QueryTypes = URLSearchParams | string[][] | Record<string, any> | string | undefined;
142
153
  export interface CreatePdfFunction {
143
154
  (docDefinition: TDocumentDefinitions, tableLayouts?: {
144
155
  [name: string]: CustomTableLayout;
@@ -542,10 +553,11 @@ export declare class MedplumClient extends EventTarget {
542
553
  * Builds a FHIR search URL from a search query or structured query object.
543
554
  * @category HTTP
544
555
  * @category Search
545
- * @param query The FHIR search query or structured query object.
556
+ * @param resourceType The FHIR resource type.
557
+ * @param query The FHIR search query or structured query object. Can be any valid input to the URLSearchParams() constructor.
546
558
  * @returns The well-formed FHIR URL.
547
559
  */
548
- fhirSearchUrl(resourceType: ResourceType, query: URLSearchParams | string | undefined): URL;
560
+ fhirSearchUrl(resourceType: ResourceType, query: QueryTypes): URL;
549
561
  /**
550
562
  * Sends a FHIR search request.
551
563
  *
@@ -590,11 +602,11 @@ export declare class MedplumClient extends EventTarget {
590
602
  *
591
603
  * @category Search
592
604
  * @param resourceType The FHIR resource type.
593
- * @param query The search query as either a string or a structured search object.
605
+ * @param query Optional FHIR search query or structured query object. Can be any valid input to the URLSearchParams() constructor.
594
606
  * @param options Optional fetch options.
595
607
  * @returns Promise to the search result bundle.
596
608
  */
597
- search<K extends ResourceType>(resourceType: K, query?: URLSearchParams | string, options?: RequestInit): ReadablePromise<Bundle<ExtractResource<K>>>;
609
+ search<K extends ResourceType>(resourceType: K, query?: QueryTypes, options?: RequestInit): ReadablePromise<Bundle<ExtractResource<K>>>;
598
610
  /**
599
611
  * Sends a FHIR search request for a single resource.
600
612
  *
@@ -613,11 +625,11 @@ export declare class MedplumClient extends EventTarget {
613
625
  *
614
626
  * @category Search
615
627
  * @param resourceType The FHIR resource type.
616
- * @param query The search query as either a string or a structured search object.
628
+ * @param query Optional FHIR search query or structured query object. Can be any valid input to the URLSearchParams() constructor.
617
629
  * @param options Optional fetch options.
618
630
  * @returns Promise to the search result bundle.
619
631
  */
620
- searchOne<K extends ResourceType>(resourceType: K, query?: URLSearchParams | string, options?: RequestInit): ReadablePromise<ExtractResource<K> | undefined>;
632
+ searchOne<K extends ResourceType>(resourceType: K, query?: QueryTypes, options?: RequestInit): ReadablePromise<ExtractResource<K> | undefined>;
621
633
  /**
622
634
  * Sends a FHIR search request for an array of resources.
623
635
  *
@@ -636,11 +648,11 @@ export declare class MedplumClient extends EventTarget {
636
648
  *
637
649
  * @category Search
638
650
  * @param resourceType The FHIR resource type.
639
- * @param query The search query as either a string or a structured search object.
651
+ * @param query Optional FHIR search query or structured query object. Can be any valid input to the URLSearchParams() constructor.
640
652
  * @param options Optional fetch options.
641
653
  * @returns Promise to the search result bundle.
642
654
  */
643
- searchResources<K extends ResourceType>(resourceType: K, query?: URLSearchParams | string, options?: RequestInit): ReadablePromise<ExtractResource<K>[]>;
655
+ searchResources<K extends ResourceType>(resourceType: K, query?: QueryTypes, options?: RequestInit): ReadablePromise<ExtractResource<K>[]>;
644
656
  /**
645
657
  * Searches a ValueSet resource using the "expand" operation.
646
658
  * See: https://www.hl7.org/fhir/operation-valueset-expand.html
@@ -7,8 +7,12 @@ export interface Token extends Marker {
7
7
  id: string;
8
8
  value: string;
9
9
  }
10
+ export interface TokenizerOptions {
11
+ dateTimeLiterals?: boolean;
12
+ symbolRegex?: RegExp;
13
+ }
10
14
  export declare class Tokenizer {
11
15
  #private;
12
- constructor(str: string, keywords: string[], operators: string[]);
16
+ constructor(str: string, keywords: string[], operators: string[], options?: TokenizerOptions);
13
17
  tokenize(): Token[];
14
18
  }
@@ -0,0 +1 @@
1
+ export * from './parse';
@@ -0,0 +1,2 @@
1
+ export * from './parse';
2
+ export * from './types';
@@ -0,0 +1,7 @@
1
+ import { FhirFilterExpression } from './types';
2
+ /**
3
+ * Parses a FHIR _filter parameter expression into an AST.
4
+ * @param input The FHIR _filter parameter expression.
5
+ * @returns The AST representing the filters.
6
+ */
7
+ export declare function parseFilterParameter(input: string): FhirFilterExpression;
@@ -0,0 +1,2 @@
1
+ import { Token } from '../fhirlexer';
2
+ export declare function tokenize(str: string): Token[];
@@ -0,0 +1,31 @@
1
+ /**
2
+ * The FhirFilterExpression type is the base type of all filter expressions.
3
+ */
4
+ export type FhirFilterExpression = FhirFilterComparison | FhirFilterNegation | FhirFilterConnective;
5
+ /**
6
+ * The FhirFilterComparison class represents a comparison expression.
7
+ */
8
+ export declare class FhirFilterComparison {
9
+ readonly path: string;
10
+ readonly operator: string;
11
+ readonly value: string;
12
+ constructor(path: string, operator: string, value: string);
13
+ }
14
+ /**
15
+ * The FhirFilterNegation class represents a negation expression.
16
+ * It contains a single child expression.
17
+ */
18
+ export declare class FhirFilterNegation {
19
+ readonly child: FhirFilterExpression;
20
+ constructor(child: FhirFilterExpression);
21
+ }
22
+ /**
23
+ * The FhirFilterConnective class represents a connective expression.
24
+ * It contains a list of child expressions.
25
+ */
26
+ export declare class FhirFilterConnective {
27
+ readonly keyword: 'and' | 'or';
28
+ readonly left: FhirFilterExpression;
29
+ readonly right: FhirFilterExpression;
30
+ constructor(keyword: 'and' | 'or', left: FhirFilterExpression, right: FhirFilterExpression);
31
+ }
@@ -1,11 +1,15 @@
1
1
  export * from './cache';
2
2
  export * from './client';
3
+ export * from './fhirlexer';
4
+ export * from './fhirmapper';
3
5
  export * from './fhirpath';
6
+ export * from './filter';
4
7
  export * from './format';
5
8
  export * from './hl7';
6
9
  export * from './jwt';
7
10
  export * from './outcomes';
8
11
  export * from './readablepromise';
12
+ export * from './schema';
9
13
  export * from './search/details';
10
14
  export * from './search/match';
11
15
  export * from './search/parse';
@@ -8,6 +8,7 @@ export declare const forbidden: OperationOutcome;
8
8
  export declare const gone: OperationOutcome;
9
9
  export declare const tooManyRequests: OperationOutcome;
10
10
  export declare function badRequest(details: string, expression?: string): OperationOutcome;
11
+ export declare function validationError(details: string): OperationOutcome;
11
12
  export declare function isOperationOutcome(value: unknown): value is OperationOutcome;
12
13
  export declare function isOk(outcome: OperationOutcome): boolean;
13
14
  export declare function isNotFound(outcome: OperationOutcome): boolean;
@@ -0,0 +1,120 @@
1
+ import { OperationOutcomeIssue, Resource } from '@medplum/fhirtypes';
2
+ /**
3
+ * Returns true if the given string is a valid FHIR resource type.
4
+ *
5
+ * ```ts
6
+ * isResourceType('Patient'); // true
7
+ * isResourceType('XYZ'); // false
8
+ * ```
9
+ *
10
+ * Note that this depends on globalSchema, which is populated by the StructureDefinition loader.
11
+ *
12
+ * In a server context, you can load all schema definitions:
13
+ *
14
+ * ```ts
15
+ * import { indexStructureDefinitionBundle } from '@medplum/core';
16
+ * import { readJson } from '@medplum/definitions';
17
+ * import { Bundle } from '@medplum/fhirtypes';
18
+ *
19
+ * indexStructureDefinitionBundle(readJson('fhir/r4/profiles-resources.json') as Bundle);
20
+ * ```
21
+ *
22
+ * In a client context, you can load the schema definitions using MedplumClient:
23
+ *
24
+ * ```ts
25
+ * import { MedplumClient } from '@medplum/core';
26
+ *
27
+ * const medplum = new MedplumClient();
28
+ * await medplum.requestSchema('Patient');
29
+ * ```
30
+ *
31
+ * @param resourceType The candidate resource type string.
32
+ * @returns True if the resource type is a valid FHIR resource type.
33
+ */
34
+ export declare function isResourceType(resourceType: string): boolean;
35
+ /**
36
+ * Validates that the given string is a valid FHIR resource type.
37
+ * On success, silently returns void.
38
+ * On failure, throws an OperationOutcomeError.
39
+ *
40
+ * ```ts
41
+ * validateResourceType('Patient'); // nothing
42
+ * validateResourceType('XYZ'); // throws OperationOutcomeError
43
+ * ```
44
+ *
45
+ * Note that this depends on globalSchema, which is populated by the StructureDefinition loader.
46
+ *
47
+ * In a server context, you can load all schema definitions:
48
+ *
49
+ * ```ts
50
+ * import { indexStructureDefinitionBundle } from '@medplum/core';
51
+ * import { readJson } from '@medplum/definitions';
52
+ * import { Bundle } from '@medplum/fhirtypes';
53
+ *
54
+ * indexStructureDefinitionBundle(readJson('fhir/r4/profiles-resources.json') as Bundle);
55
+ * ```
56
+ *
57
+ * In a client context, you can load the schema definitions using MedplumClient:
58
+ *
59
+ * ```ts
60
+ * import { MedplumClient } from '@medplum/core';
61
+ *
62
+ * const medplum = new MedplumClient();
63
+ * await medplum.requestSchema('Patient');
64
+ * ```
65
+ *
66
+ * @param resourceType The candidate resource type string.
67
+ * @returns True if the resource type is a valid FHIR resource type.
68
+ */
69
+ export declare function validateResourceType(resourceType: string): void;
70
+ /**
71
+ * Validates a candidate FHIR resource object.
72
+ * On success, silently returns void.
73
+ * On failure, throws an OperationOutcomeError with issues for each violation.
74
+ *
75
+ * ```ts
76
+ * validateResource({ resourceType: 'Patient' }); // nothing
77
+ * validateResource({ resourceType: 'XYZ' }); // throws OperationOutcomeError
78
+ * ```
79
+ *
80
+ * Note that this depends on globalSchema, which is populated by the StructureDefinition loader.
81
+ *
82
+ * In a server context, you can load all schema definitions:
83
+ *
84
+ * ```ts
85
+ * import { indexStructureDefinitionBundle } from '@medplum/core';
86
+ * import { readJson } from '@medplum/definitions';
87
+ * import { Bundle } from '@medplum/fhirtypes';
88
+ *
89
+ * indexStructureDefinitionBundle(readJson('fhir/r4/profiles-resources.json') as Bundle);
90
+ * ```
91
+ *
92
+ * In a client context, you can load the schema definitions using MedplumClient:
93
+ *
94
+ * ```ts
95
+ * import { MedplumClient } from '@medplum/core';
96
+ *
97
+ * const medplum = new MedplumClient();
98
+ * await medplum.requestSchema('Patient');
99
+ * ```
100
+ *
101
+ * @param resourceType The candidate resource type string.
102
+ * @returns True if the resource type is a valid FHIR resource type.
103
+ */
104
+ export declare function validateResource<T extends Resource>(resource: T): void;
105
+ export declare class FhirSchemaValidator<T extends Resource> {
106
+ #private;
107
+ constructor(root: T);
108
+ validate(): void;
109
+ }
110
+ /**
111
+ * Recursively checks for null values in an object.
112
+ *
113
+ * Note that "null" is a special value in JSON that is not allowed in FHIR.
114
+ *
115
+ * @param value Input value of any type.
116
+ * @param path Path string to the value for OperationOutcome.
117
+ * @param issues Output list of issues.
118
+ */
119
+ export declare function checkForNull(value: unknown, path: string, issues: OperationOutcomeIssue[]): void;
120
+ export declare function createStructureIssue(expression: string, details: string): OperationOutcomeIssue;
@@ -1,4 +1,4 @@
1
- import { Bundle, ElementDefinition, SearchParameter, StructureDefinition } from '@medplum/fhirtypes';
1
+ import { Bundle, ElementDefinition, Reference, Resource, ResourceType, SearchParameter, StructureDefinition } from '@medplum/fhirtypes';
2
2
  import { SearchParameterDetails } from './search/details';
3
3
  export interface TypedValue {
4
4
  readonly type: string;
@@ -157,17 +157,17 @@ export declare function indexSearchParameter(searchParam: SearchParameter): void
157
157
  export declare function getElementDefinitionTypeName(elementDefinition: ElementDefinition): string;
158
158
  export declare function buildTypeName(components: string[]): string;
159
159
  /**
160
- * Returns true if the type schema is a DomainResource.
160
+ * Returns true if the type schema is a non-abstract FHIR resource.
161
161
  * @param typeSchema The type schema to check.
162
- * @returns True if the type schema is a DomainResource.
162
+ * @returns True if the type schema is a non-abstract FHIR resource.
163
163
  */
164
- export declare function isResourceType(typeSchema: TypeSchema): boolean;
164
+ export declare function isResourceTypeSchema(typeSchema: TypeSchema): boolean;
165
165
  /**
166
166
  * Returns an array of all resource types.
167
167
  * Note that this is based on globalSchema, and will only return resource types that are currently in memory.
168
168
  * @returns An array of all resource types.
169
169
  */
170
- export declare function getResourceTypes(): string[];
170
+ export declare function getResourceTypes(): ResourceType[];
171
171
  /**
172
172
  * Returns the type schema for the resource type.
173
173
  * @param resourceType The resource type.
@@ -194,6 +194,20 @@ export declare function getPropertyDisplayName(path: string): string;
194
194
  * @returns The element definition if found.
195
195
  */
196
196
  export declare function getElementDefinition(typeName: string, propertyName: string): ElementDefinition | undefined;
197
+ /**
198
+ * Typeguard to validate that an object is a FHIR resource
199
+ * @param value The object to check
200
+ * @returns True if the input is of type 'object' and contains property 'resourceType'
201
+ */
202
+ export declare function isResource<T extends Resource = Resource>(value: T | Reference<T> | string | undefined | null): value is T;
203
+ /**
204
+ * Typeguard to validate that an object is a FHIR resource
205
+ * @param value The object to check
206
+ * @returns True if the input is of type 'object' and contains property 'reference'
207
+ */
208
+ export declare function isReference<T extends Resource>(value: T | Reference<T> | string | undefined | null): value is Reference<T> & {
209
+ reference: string;
210
+ };
197
211
  /**
198
212
  * Global schema singleton.
199
213
  */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@medplum/core",
3
- "version": "2.0.5",
3
+ "version": "2.0.6",
4
4
  "description": "Medplum TS/JS Library",
5
5
  "author": "Medplum <hello@medplum.com>",
6
6
  "license": "Apache-2.0",