@medplum/core 2.0.3 → 2.0.5

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 (82) hide show
  1. package/dist/cjs/index.cjs +477 -209
  2. package/dist/cjs/index.cjs.map +1 -1
  3. package/dist/cjs/index.min.cjs +1 -1
  4. package/dist/esm/client.mjs +18 -21
  5. package/dist/esm/client.mjs.map +1 -1
  6. package/dist/esm/index.min.mjs +1 -1
  7. package/dist/esm/index.mjs +6 -5
  8. package/dist/esm/index.mjs.map +1 -1
  9. package/dist/esm/outcomes.mjs +17 -2
  10. package/dist/esm/outcomes.mjs.map +1 -1
  11. package/dist/esm/{searchparams.mjs → search/details.mjs} +9 -11
  12. package/dist/esm/search/details.mjs.map +1 -0
  13. package/dist/esm/{match.mjs → search/match.mjs} +16 -11
  14. package/dist/esm/search/match.mjs.map +1 -0
  15. package/dist/esm/search/parse.mjs +218 -0
  16. package/dist/esm/search/parse.mjs.map +1 -0
  17. package/dist/esm/{search.mjs → search/search.mjs} +0 -3
  18. package/dist/esm/search/search.mjs.map +1 -0
  19. package/dist/esm/types.mjs +63 -25
  20. package/dist/esm/types.mjs.map +1 -1
  21. package/dist/{esm → types}/client.d.ts +5 -3
  22. package/dist/{esm → types}/index.d.ts +4 -3
  23. package/dist/{esm → types}/outcomes.d.ts +7 -1
  24. package/dist/types/search/parse.d.ts +17 -0
  25. package/dist/{cjs → types}/types.d.ts +30 -7
  26. package/package.json +4 -4
  27. package/tsconfig.build.json +9 -0
  28. package/dist/cjs/client.d.ts +0 -1216
  29. package/dist/cjs/index.d.ts +0 -13
  30. package/dist/cjs/outcomes.d.ts +0 -31
  31. package/dist/esm/cache.d.ts +0 -34
  32. package/dist/esm/crypto.d.ts +0 -9
  33. package/dist/esm/eventtarget.d.ts +0 -13
  34. package/dist/esm/fhirlexer/index.d.ts +0 -2
  35. package/dist/esm/fhirlexer/parse.d.ts +0 -47
  36. package/dist/esm/fhirlexer/tokenize.d.ts +0 -14
  37. package/dist/esm/fhirmapper/parse.d.ts +0 -7
  38. package/dist/esm/fhirmapper/tokenize.d.ts +0 -2
  39. package/dist/esm/fhirpath/atoms.d.ts +0 -120
  40. package/dist/esm/fhirpath/date.d.ts +0 -1
  41. package/dist/esm/fhirpath/functions.d.ts +0 -6
  42. package/dist/esm/fhirpath/index.d.ts +0 -4
  43. package/dist/esm/fhirpath/parse.d.ts +0 -64
  44. package/dist/esm/fhirpath/tokenize.d.ts +0 -4
  45. package/dist/esm/fhirpath/utils.d.ts +0 -95
  46. package/dist/esm/format.d.ts +0 -118
  47. package/dist/esm/hl7.d.ts +0 -136
  48. package/dist/esm/jwt.d.ts +0 -5
  49. package/dist/esm/match.d.ts +0 -9
  50. package/dist/esm/match.mjs.map +0 -1
  51. package/dist/esm/readablepromise.d.ts +0 -48
  52. package/dist/esm/search.d.ts +0 -66
  53. package/dist/esm/search.mjs.map +0 -1
  54. package/dist/esm/searchparams.d.ts +0 -33
  55. package/dist/esm/searchparams.mjs.map +0 -1
  56. package/dist/esm/storage.d.ts +0 -47
  57. package/dist/esm/types.d.ts +0 -177
  58. package/dist/esm/utils.d.ts +0 -259
  59. /package/dist/{cjs → types}/cache.d.ts +0 -0
  60. /package/dist/{cjs → types}/crypto.d.ts +0 -0
  61. /package/dist/{cjs → types}/eventtarget.d.ts +0 -0
  62. /package/dist/{cjs → types}/fhirlexer/index.d.ts +0 -0
  63. /package/dist/{cjs → types}/fhirlexer/parse.d.ts +0 -0
  64. /package/dist/{cjs → types}/fhirlexer/tokenize.d.ts +0 -0
  65. /package/dist/{cjs → types}/fhirmapper/parse.d.ts +0 -0
  66. /package/dist/{cjs → types}/fhirmapper/tokenize.d.ts +0 -0
  67. /package/dist/{cjs → types}/fhirpath/atoms.d.ts +0 -0
  68. /package/dist/{cjs → types}/fhirpath/date.d.ts +0 -0
  69. /package/dist/{cjs → types}/fhirpath/functions.d.ts +0 -0
  70. /package/dist/{cjs → types}/fhirpath/index.d.ts +0 -0
  71. /package/dist/{cjs → types}/fhirpath/parse.d.ts +0 -0
  72. /package/dist/{cjs → types}/fhirpath/tokenize.d.ts +0 -0
  73. /package/dist/{cjs → types}/fhirpath/utils.d.ts +0 -0
  74. /package/dist/{cjs → types}/format.d.ts +0 -0
  75. /package/dist/{cjs → types}/hl7.d.ts +0 -0
  76. /package/dist/{cjs → types}/jwt.d.ts +0 -0
  77. /package/dist/{cjs → types}/readablepromise.d.ts +0 -0
  78. /package/dist/{cjs/searchparams.d.ts → types/search/details.d.ts} +0 -0
  79. /package/dist/{cjs → types/search}/match.d.ts +0 -0
  80. /package/dist/{cjs → types/search}/search.d.ts +0 -0
  81. /package/dist/{cjs → types}/storage.d.ts +0 -0
  82. /package/dist/{cjs → types}/utils.d.ts +0 -0
@@ -68,23 +68,6 @@ var PropertyType;
68
68
  PropertyType["url"] = "url";
69
69
  PropertyType["uuid"] = "uuid";
70
70
  })(PropertyType || (PropertyType = {}));
71
- /**
72
- * Creates a new empty IndexedStructureDefinition.
73
- * @returns The empty IndexedStructureDefinition.
74
- * @deprecated Use globalSchema
75
- */
76
- function createSchema() {
77
- return { types: {} };
78
- }
79
- function createTypeSchema(typeName, structureDefinition, elementDefinition) {
80
- return {
81
- structureDefinition,
82
- elementDefinition,
83
- display: typeName,
84
- description: elementDefinition.definition,
85
- properties: {},
86
- };
87
- }
88
71
  /**
89
72
  * Indexes a bundle of StructureDefinitions for faster lookup.
90
73
  * @param bundle A FHIR bundle StructureDefinition resources.
@@ -132,8 +115,16 @@ function indexType(structureDefinition, elementDefinition) {
132
115
  }
133
116
  const parts = path.split('.');
134
117
  const typeName = buildTypeName(parts);
135
- globalSchema.types[typeName] = createTypeSchema(typeName, structureDefinition, elementDefinition);
136
- globalSchema.types[typeName].parentType = buildTypeName(parts.slice(0, parts.length - 1));
118
+ let typeSchema = globalSchema.types[typeName];
119
+ if (!typeSchema) {
120
+ globalSchema.types[typeName] = typeSchema = {};
121
+ }
122
+ typeSchema.parentType = typeSchema.parentType || buildTypeName(parts.slice(0, parts.length - 1));
123
+ typeSchema.display = typeSchema.display || typeName;
124
+ typeSchema.structureDefinition = typeSchema.structureDefinition || structureDefinition;
125
+ typeSchema.elementDefinition = typeSchema.elementDefinition || elementDefinition;
126
+ typeSchema.description = typeSchema.description || elementDefinition.definition;
127
+ typeSchema.properties = typeSchema.properties || {};
137
128
  }
138
129
  /**
139
130
  * Indexes PropertySchema from an ElementDefinition.
@@ -248,15 +239,54 @@ function buildTypeName(components) {
248
239
  }
249
240
  return components.map(capitalize).join('');
250
241
  }
242
+ /**
243
+ * Returns true if the type schema is a DomainResource.
244
+ * @param typeSchema The type schema to check.
245
+ * @returns True if the type schema is a DomainResource.
246
+ */
247
+ function isResourceType(typeSchema) {
248
+ return typeSchema.structureDefinition?.baseDefinition === 'http://hl7.org/fhir/StructureDefinition/DomainResource';
249
+ }
250
+ /**
251
+ * Returns an array of all resource types.
252
+ * Note that this is based on globalSchema, and will only return resource types that are currently in memory.
253
+ * @returns An array of all resource types.
254
+ */
255
+ function getResourceTypes() {
256
+ const result = [];
257
+ for (const [resourceType, typeSchema] of Object.entries(globalSchema.types)) {
258
+ if (isResourceType(typeSchema)) {
259
+ result.push(resourceType);
260
+ }
261
+ }
262
+ return result;
263
+ }
264
+ /**
265
+ * Returns the type schema for the resource type.
266
+ * @param resourceType The resource type.
267
+ * @returns The type schema for the resource type.
268
+ */
269
+ function getResourceTypeSchema(resourceType) {
270
+ return globalSchema.types[resourceType];
271
+ }
272
+ /**
273
+ * Returns the search parameters for the resource type indexed by search code.
274
+ * @param resourceType The resource type.
275
+ * @returns The search parameters for the resource type indexed by search code.
276
+ */
277
+ function getSearchParameters(resourceType) {
278
+ return globalSchema.types[resourceType].searchParams;
279
+ }
280
+ /**
281
+ * Returns a human friendly display name for a FHIR element definition path.
282
+ * @param path The FHIR element definition path.
283
+ * @returns The best guess of the display name.
284
+ */
251
285
  function getPropertyDisplayName(path) {
252
286
  // Get the property name, which is the remainder after the last period
253
287
  // For example, for path "Patient.birthDate"
254
288
  // the property name is "birthDate"
255
289
  const propertyName = path.replaceAll('[x]', '').split('.').pop();
256
- // Special case for ID
257
- if (propertyName === 'id') {
258
- return 'ID';
259
- }
260
290
  // Split by capital letters
261
291
  // Capitalize the first letter of each word
262
292
  // Join together with spaces in between
@@ -265,11 +295,19 @@ function getPropertyDisplayName(path) {
265
295
  // the display name is "Birth Date".
266
296
  return propertyName
267
297
  .split(/(?=[A-Z])/)
268
- .map(capitalize)
298
+ .map(capitalizeDisplayWord)
269
299
  .join(' ')
270
300
  .replace('_', ' ')
271
301
  .replace(/\s+/g, ' ');
272
302
  }
303
+ const capitalizedWords = new Set(['ID', 'PKCE', 'JWKS', 'URI', 'URL']);
304
+ function capitalizeDisplayWord(word) {
305
+ const upper = word.toUpperCase();
306
+ if (capitalizedWords.has(upper)) {
307
+ return upper;
308
+ }
309
+ return upper.charAt(0) + word.slice(1);
310
+ }
273
311
  /**
274
312
  * Returns an element definition by type and property name.
275
313
  * Handles content references.
@@ -301,5 +339,5 @@ function getElementDefinition(typeName, propertyName) {
301
339
  */
302
340
  const globalSchema = baseSchema;
303
341
 
304
- export { PropertyType, buildTypeName, createSchema, getElementDefinition, getElementDefinitionTypeName, getPropertyDisplayName, globalSchema, indexSearchParameter, indexSearchParameterBundle, indexStructureDefinition, indexStructureDefinitionBundle };
342
+ export { PropertyType, buildTypeName, getElementDefinition, getElementDefinitionTypeName, getPropertyDisplayName, getResourceTypeSchema, getResourceTypes, getSearchParameters, globalSchema, indexSearchParameter, indexSearchParameterBundle, indexStructureDefinition, indexStructureDefinitionBundle, isResourceType };
305
343
  //# 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 './searchparams';\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 * Creates a new empty IndexedStructureDefinition.\n * @returns The empty IndexedStructureDefinition.\n * @deprecated Use globalSchema\n */\nexport function createSchema(): IndexedStructureDefinition {\n return { types: {} };\n}\n\nfunction createTypeSchema(\n typeName: string,\n structureDefinition: StructureDefinition,\n elementDefinition: ElementDefinition\n): TypeSchema {\n return {\n structureDefinition,\n elementDefinition,\n display: typeName,\n description: elementDefinition.definition,\n properties: {},\n };\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 globalSchema.types[typeName] = createTypeSchema(typeName, structureDefinition, elementDefinition);\n globalSchema.types[typeName].parentType = buildTypeName(parts.slice(0, parts.length - 1));\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\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 // Special case for ID\n if (propertyName === 'id') {\n return 'ID';\n }\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(capitalize)\n .join(' ')\n .replace('_', ' ')\n .replace(/\\s+/g, ' ');\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,CA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;AAQD,IAAA,OAAO,YAAY;SAChB,KAAK,CAAC,WAAW,CAAC;SAClB,GAAG,CAAC,UAAU,CAAC;SACf,IAAI,CAAC,GAAG,CAAC;AACT,SAAA,OAAO,CAAC,GAAG,EAAE,GAAG,CAAC;AACjB,SAAA,OAAO,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;AAC1B,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 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,CAAA;AACnC,IAAA,YAAA,CAAA,iBAAA,CAAA,GAAA,iBAAmC,CAAA;AACnC,IAAA,YAAA,CAAA,QAAA,CAAA,GAAA,QAAiB,CAAA;AACjB,IAAA,YAAA,CAAA,eAAA,CAAA,GAAA,eAA+B,CAAA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AAU,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;;;;"}
@@ -84,7 +84,7 @@ export interface MedplumClientOptions {
84
84
  *
85
85
  * Default is window.fetch (if available).
86
86
  *
87
- * For nodejs applications, consider the 'node-fetch' package.
87
+ * For Node.js applications, consider the 'node-fetch' package.
88
88
  */
89
89
  fetch?: FetchLike;
90
90
  /**
@@ -105,7 +105,7 @@ export interface MedplumClientOptions {
105
105
  * </script>
106
106
  * ```
107
107
  *
108
- * In nodejs applications:
108
+ * In Node.js applications:
109
109
  *
110
110
  * ```ts
111
111
  * import type { CustomTableLayout, TDocumentDefinitions, TFontDictionary } from 'pdfmake/interfaces';
@@ -282,7 +282,7 @@ export interface MailOptions {
282
282
  /**
283
283
  * The MedplumClient class provides a client for the Medplum FHIR server.
284
284
  *
285
- * The client can be used in the browser, in a NodeJS application, or in a Medplum Bot.
285
+ * The client can be used in the browser, in a Node.js application, or in a Medplum Bot.
286
286
  *
287
287
  * The client provides helpful methods for common operations such as:
288
288
  * 1) Authenticating
@@ -1193,6 +1193,7 @@ export declare class MedplumClient extends EventTarget {
1193
1193
  /**
1194
1194
  * Starts a new PKCE flow.
1195
1195
  * These PKCE values are stateful, and must survive redirects and page refreshes.
1196
+ * @category Authentication
1196
1197
  */
1197
1198
  startPkce(): Promise<{
1198
1199
  codeChallengeMethod: string;
@@ -1202,6 +1203,7 @@ export declare class MedplumClient extends EventTarget {
1202
1203
  * Processes an OAuth authorization code.
1203
1204
  * See: https://openid.net/specs/openid-connect-core-1_0.html#TokenRequest
1204
1205
  * @param code The authorization code received by URL parameter.
1206
+ * @category Authentication
1205
1207
  */
1206
1208
  processCode(code: string): Promise<ProfileResource>;
1207
1209
  /**
@@ -4,10 +4,11 @@ export * from './fhirpath';
4
4
  export * from './format';
5
5
  export * from './hl7';
6
6
  export * from './jwt';
7
- export * from './match';
8
7
  export * from './outcomes';
9
8
  export * from './readablepromise';
10
- export * from './search';
11
- export * from './searchparams';
9
+ export * from './search/details';
10
+ export * from './search/match';
11
+ export * from './search/parse';
12
+ export * from './search/search';
12
13
  export * from './types';
13
14
  export * from './utils';
@@ -21,8 +21,14 @@ export declare function getStatus(outcome: OperationOutcome): number;
21
21
  export declare function assertOk<T>(outcome: OperationOutcome, resource: T | undefined): asserts resource is T;
22
22
  export declare class OperationOutcomeError extends Error {
23
23
  readonly outcome: OperationOutcome;
24
- constructor(outcome: OperationOutcome);
24
+ constructor(outcome: OperationOutcome, cause?: unknown);
25
25
  }
26
+ /**
27
+ * Normalizes an error object into an OperationOutcome.
28
+ * @param error The error value which could be a string, Error, OperationOutcome, or other unknown type.
29
+ * @returns The normalized OperationOutcome.
30
+ */
31
+ export declare function normalizeOperationOutcome(error: unknown): OperationOutcome;
26
32
  /**
27
33
  * Normalizes an error object into a displayable error string.
28
34
  * @param error The error value which could be a string, Error, OperationOutcome, or other unknown type.
@@ -0,0 +1,17 @@
1
+ /// <reference types="node" />
2
+ import { ResourceType } from '@medplum/fhirtypes';
3
+ import { URL } from 'url';
4
+ import { SearchRequest } from './search';
5
+ /**
6
+ * Parses a search URL into a search request.
7
+ * @param resourceType The FHIR resource type.
8
+ * @param query The collection of query string parameters.
9
+ * @returns A parsed SearchRequest.
10
+ */
11
+ export declare function parseSearchRequest(resourceType: ResourceType, query: Record<string, string[] | string | undefined>): SearchRequest;
12
+ /**
13
+ * Parses a search URL into a search request.
14
+ * @param url The search URL.
15
+ * @returns A parsed SearchRequest.
16
+ */
17
+ export declare function parseSearchUrl(url: URL): SearchRequest;
@@ -1,5 +1,5 @@
1
1
  import { Bundle, ElementDefinition, SearchParameter, StructureDefinition } from '@medplum/fhirtypes';
2
- import { SearchParameterDetails } from './searchparams';
2
+ import { SearchParameterDetails } from './search/details';
3
3
  export interface TypedValue {
4
4
  readonly type: string;
5
5
  readonly value: any;
@@ -124,12 +124,6 @@ export interface TypeSchema {
124
124
  description?: string;
125
125
  parentType?: string;
126
126
  }
127
- /**
128
- * Creates a new empty IndexedStructureDefinition.
129
- * @returns The empty IndexedStructureDefinition.
130
- * @deprecated Use globalSchema
131
- */
132
- export declare function createSchema(): IndexedStructureDefinition;
133
127
  /**
134
128
  * Indexes a bundle of StructureDefinitions for faster lookup.
135
129
  * @param bundle A FHIR bundle StructureDefinition resources.
@@ -162,6 +156,35 @@ export declare function indexSearchParameter(searchParam: SearchParameter): void
162
156
  */
163
157
  export declare function getElementDefinitionTypeName(elementDefinition: ElementDefinition): string;
164
158
  export declare function buildTypeName(components: string[]): string;
159
+ /**
160
+ * Returns true if the type schema is a DomainResource.
161
+ * @param typeSchema The type schema to check.
162
+ * @returns True if the type schema is a DomainResource.
163
+ */
164
+ export declare function isResourceType(typeSchema: TypeSchema): boolean;
165
+ /**
166
+ * Returns an array of all resource types.
167
+ * Note that this is based on globalSchema, and will only return resource types that are currently in memory.
168
+ * @returns An array of all resource types.
169
+ */
170
+ export declare function getResourceTypes(): string[];
171
+ /**
172
+ * Returns the type schema for the resource type.
173
+ * @param resourceType The resource type.
174
+ * @returns The type schema for the resource type.
175
+ */
176
+ export declare function getResourceTypeSchema(resourceType: string): TypeSchema;
177
+ /**
178
+ * Returns the search parameters for the resource type indexed by search code.
179
+ * @param resourceType The resource type.
180
+ * @returns The search parameters for the resource type indexed by search code.
181
+ */
182
+ export declare function getSearchParameters(resourceType: string): Record<string, SearchParameter> | undefined;
183
+ /**
184
+ * Returns a human friendly display name for a FHIR element definition path.
185
+ * @param path The FHIR element definition path.
186
+ * @returns The best guess of the display name.
187
+ */
165
188
  export declare function getPropertyDisplayName(path: string): string;
166
189
  /**
167
190
  * Returns an element definition by type and property name.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@medplum/core",
3
- "version": "2.0.3",
3
+ "version": "2.0.5",
4
4
  "description": "Medplum TS/JS Library",
5
5
  "author": "Medplum <hello@medplum.com>",
6
6
  "license": "Apache-2.0",
@@ -12,8 +12,7 @@
12
12
  },
13
13
  "scripts": {
14
14
  "clean": "rimraf dist",
15
- "build": "npm run clean && npm run rollup",
16
- "rollup": "rollup --config rollup.config.mjs",
15
+ "build": "npm run clean && tsc --project tsconfig.build.json && rollup --config rollup.config.mjs",
17
16
  "test": "jest"
18
17
  },
19
18
  "devDependencies": {
@@ -28,13 +27,14 @@
28
27
  "optional": true
29
28
  }
30
29
  },
30
+ "types": "dist/types/index.d.ts",
31
31
  "main": "dist/cjs/index.cjs",
32
32
  "module": "dist/esm/index.mjs",
33
33
  "exports": {
34
+ "types": "./dist/types/index.d.ts",
34
35
  "require": "./dist/cjs/index.cjs",
35
36
  "import": "./dist/esm/index.mjs"
36
37
  },
37
- "types": "dist/esm/index.d.ts",
38
38
  "sideEffects": false,
39
39
  "keywords": [
40
40
  "medplum",
@@ -0,0 +1,9 @@
1
+ {
2
+ "extends": "./tsconfig.json",
3
+ "compilerOptions": {
4
+ "outDir": "dist/types",
5
+ "noEmit": false,
6
+ "emitDeclarationOnly": true
7
+ },
8
+ "exclude": ["**/*.test.ts"]
9
+ }