@metriport/fhir-sdk 0.30.0-alpha.1

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 (155) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +564 -0
  3. package/dist/__tests__/careplan.test.d.ts +2 -0
  4. package/dist/__tests__/careplan.test.d.ts.map +1 -0
  5. package/dist/__tests__/careplan.test.js +544 -0
  6. package/dist/__tests__/careplan.test.js.map +1 -0
  7. package/dist/__tests__/clinical-dates.test.d.ts +2 -0
  8. package/dist/__tests__/clinical-dates.test.d.ts.map +1 -0
  9. package/dist/__tests__/clinical-dates.test.js +341 -0
  10. package/dist/__tests__/clinical-dates.test.js.map +1 -0
  11. package/dist/__tests__/coding-utilities.test.d.ts +2 -0
  12. package/dist/__tests__/coding-utilities.test.d.ts.map +1 -0
  13. package/dist/__tests__/coding-utilities.test.js +482 -0
  14. package/dist/__tests__/coding-utilities.test.js.map +1 -0
  15. package/dist/__tests__/date-range-performance.test.d.ts +2 -0
  16. package/dist/__tests__/date-range-performance.test.d.ts.map +1 -0
  17. package/dist/__tests__/date-range-performance.test.js +218 -0
  18. package/dist/__tests__/date-range-performance.test.js.map +1 -0
  19. package/dist/__tests__/date-range-search.test.d.ts +2 -0
  20. package/dist/__tests__/date-range-search.test.d.ts.map +1 -0
  21. package/dist/__tests__/date-range-search.test.js +215 -0
  22. package/dist/__tests__/date-range-search.test.js.map +1 -0
  23. package/dist/__tests__/env-setup.d.ts +2 -0
  24. package/dist/__tests__/env-setup.d.ts.map +1 -0
  25. package/dist/__tests__/env-setup.js +37 -0
  26. package/dist/__tests__/env-setup.js.map +1 -0
  27. package/dist/__tests__/fhir-bundle-sdk-basic.test.d.ts +2 -0
  28. package/dist/__tests__/fhir-bundle-sdk-basic.test.d.ts.map +1 -0
  29. package/dist/__tests__/fhir-bundle-sdk-basic.test.js +19 -0
  30. package/dist/__tests__/fhir-bundle-sdk-basic.test.js.map +1 -0
  31. package/dist/__tests__/fhir-bundle-sdk.test.d.ts +2 -0
  32. package/dist/__tests__/fhir-bundle-sdk.test.d.ts.map +1 -0
  33. package/dist/__tests__/fhir-bundle-sdk.test.js +953 -0
  34. package/dist/__tests__/fhir-bundle-sdk.test.js.map +1 -0
  35. package/dist/__tests__/fixtures/fhir-bundles.d.ts +31 -0
  36. package/dist/__tests__/fixtures/fhir-bundles.d.ts.map +1 -0
  37. package/dist/__tests__/fixtures/fhir-bundles.js +487 -0
  38. package/dist/__tests__/fixtures/fhir-bundles.js.map +1 -0
  39. package/dist/__tests__/phase1-verification.test.d.ts +2 -0
  40. package/dist/__tests__/phase1-verification.test.d.ts.map +1 -0
  41. package/dist/__tests__/phase1-verification.test.js +141 -0
  42. package/dist/__tests__/phase1-verification.test.js.map +1 -0
  43. package/dist/__tests__/phase2-verification.test.d.ts +2 -0
  44. package/dist/__tests__/phase2-verification.test.d.ts.map +1 -0
  45. package/dist/__tests__/phase2-verification.test.js +234 -0
  46. package/dist/__tests__/phase2-verification.test.js.map +1 -0
  47. package/dist/__tests__/phase3-verification.test.d.ts +2 -0
  48. package/dist/__tests__/phase3-verification.test.d.ts.map +1 -0
  49. package/dist/__tests__/phase3-verification.test.js +121 -0
  50. package/dist/__tests__/phase3-verification.test.js.map +1 -0
  51. package/dist/__tests__/phase4-verification.test.d.ts +2 -0
  52. package/dist/__tests__/phase4-verification.test.d.ts.map +1 -0
  53. package/dist/__tests__/phase4-verification.test.js +168 -0
  54. package/dist/__tests__/phase4-verification.test.js.map +1 -0
  55. package/dist/__tests__/phase5-verification.test.d.ts +2 -0
  56. package/dist/__tests__/phase5-verification.test.d.ts.map +1 -0
  57. package/dist/__tests__/phase5-verification.test.js +397 -0
  58. package/dist/__tests__/phase5-verification.test.js.map +1 -0
  59. package/dist/__tests__/reverse-references.test.d.ts +2 -0
  60. package/dist/__tests__/reverse-references.test.d.ts.map +1 -0
  61. package/dist/__tests__/reverse-references.test.js +294 -0
  62. package/dist/__tests__/reverse-references.test.js.map +1 -0
  63. package/dist/__tests__/type-guards.test.d.ts +2 -0
  64. package/dist/__tests__/type-guards.test.d.ts.map +1 -0
  65. package/dist/__tests__/type-guards.test.js +163 -0
  66. package/dist/__tests__/type-guards.test.js.map +1 -0
  67. package/dist/clinical-dates.d.ts +26 -0
  68. package/dist/clinical-dates.d.ts.map +1 -0
  69. package/dist/clinical-dates.js +571 -0
  70. package/dist/clinical-dates.js.map +1 -0
  71. package/dist/fhir-bundle-sdk.d.ts +233 -0
  72. package/dist/fhir-bundle-sdk.d.ts.map +1 -0
  73. package/dist/fhir-bundle-sdk.js +545 -0
  74. package/dist/fhir-bundle-sdk.js.map +1 -0
  75. package/dist/index.d.ts +8 -0
  76. package/dist/index.d.ts.map +1 -0
  77. package/dist/index.js +23 -0
  78. package/dist/index.js.map +1 -0
  79. package/dist/internal/bundle-operations.d.ts +14 -0
  80. package/dist/internal/bundle-operations.d.ts.map +1 -0
  81. package/dist/internal/bundle-operations.js +55 -0
  82. package/dist/internal/bundle-operations.js.map +1 -0
  83. package/dist/internal/coding-systems.d.ts +48 -0
  84. package/dist/internal/coding-systems.d.ts.map +1 -0
  85. package/dist/internal/coding-systems.js +55 -0
  86. package/dist/internal/coding-systems.js.map +1 -0
  87. package/dist/internal/coding-utilities.d.ts +27 -0
  88. package/dist/internal/coding-utilities.d.ts.map +1 -0
  89. package/dist/internal/coding-utilities.js +297 -0
  90. package/dist/internal/coding-utilities.js.map +1 -0
  91. package/dist/internal/date-extraction.d.ts +12 -0
  92. package/dist/internal/date-extraction.d.ts.map +1 -0
  93. package/dist/internal/date-extraction.js +629 -0
  94. package/dist/internal/date-extraction.js.map +1 -0
  95. package/dist/internal/graph-traversal.d.ts +13 -0
  96. package/dist/internal/graph-traversal.d.ts.map +1 -0
  97. package/dist/internal/graph-traversal.js +89 -0
  98. package/dist/internal/graph-traversal.js.map +1 -0
  99. package/dist/internal/indexing.d.ts +17 -0
  100. package/dist/internal/indexing.d.ts.map +1 -0
  101. package/dist/internal/indexing.js +129 -0
  102. package/dist/internal/indexing.js.map +1 -0
  103. package/dist/internal/llm-context.d.ts +40 -0
  104. package/dist/internal/llm-context.d.ts.map +1 -0
  105. package/dist/internal/llm-context.js +214 -0
  106. package/dist/internal/llm-context.js.map +1 -0
  107. package/dist/internal/reference-resolution.d.ts +29 -0
  108. package/dist/internal/reference-resolution.d.ts.map +1 -0
  109. package/dist/internal/reference-resolution.js +338 -0
  110. package/dist/internal/reference-resolution.js.map +1 -0
  111. package/dist/internal/reference-utils.d.ts +26 -0
  112. package/dist/internal/reference-utils.d.ts.map +1 -0
  113. package/dist/internal/reference-utils.js +89 -0
  114. package/dist/internal/reference-utils.js.map +1 -0
  115. package/dist/internal/transparent-proxy.d.ts +12 -0
  116. package/dist/internal/transparent-proxy.d.ts.map +1 -0
  117. package/dist/internal/transparent-proxy.js +81 -0
  118. package/dist/internal/transparent-proxy.js.map +1 -0
  119. package/dist/internal/validation.d.ts +16 -0
  120. package/dist/internal/validation.d.ts.map +1 -0
  121. package/dist/internal/validation.js +45 -0
  122. package/dist/internal/validation.js.map +1 -0
  123. package/dist/type-guards.d.ts +212 -0
  124. package/dist/type-guards.d.ts.map +1 -0
  125. package/dist/type-guards.js +375 -0
  126. package/dist/type-guards.js.map +1 -0
  127. package/dist/types/coding-fields.d.ts +311 -0
  128. package/dist/types/coding-fields.d.ts.map +1 -0
  129. package/dist/types/coding-fields.js +3 -0
  130. package/dist/types/coding-fields.js.map +1 -0
  131. package/dist/types/sdk-types.d.ts +107 -0
  132. package/dist/types/sdk-types.d.ts.map +1 -0
  133. package/dist/types/sdk-types.js +17 -0
  134. package/dist/types/sdk-types.js.map +1 -0
  135. package/dist/types/smart-resources.d.ts +470 -0
  136. package/dist/types/smart-resources.d.ts.map +1 -0
  137. package/dist/types/smart-resources.js +249 -0
  138. package/dist/types/smart-resources.js.map +1 -0
  139. package/dist/utils/interval-tree/index.d.ts +87 -0
  140. package/dist/utils/interval-tree/index.d.ts.map +1 -0
  141. package/dist/utils/interval-tree/index.js +774 -0
  142. package/dist/utils/interval-tree/index.js.map +1 -0
  143. package/dist/utils/interval-tree/shallowequal/arrays.d.ts +3 -0
  144. package/dist/utils/interval-tree/shallowequal/arrays.d.ts.map +1 -0
  145. package/dist/utils/interval-tree/shallowequal/arrays.js +25 -0
  146. package/dist/utils/interval-tree/shallowequal/arrays.js.map +1 -0
  147. package/dist/utils/interval-tree/shallowequal/index.d.ts +6 -0
  148. package/dist/utils/interval-tree/shallowequal/index.d.ts.map +1 -0
  149. package/dist/utils/interval-tree/shallowequal/index.js +28 -0
  150. package/dist/utils/interval-tree/shallowequal/index.js.map +1 -0
  151. package/dist/utils/interval-tree/shallowequal/objects.d.ts +3 -0
  152. package/dist/utils/interval-tree/shallowequal/objects.d.ts.map +1 -0
  153. package/dist/utils/interval-tree/shallowequal/objects.js +28 -0
  154. package/dist/utils/interval-tree/shallowequal/objects.js.map +1 -0
  155. package/package.json +70 -0
@@ -0,0 +1,545 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.FhirBundleSdk = void 0;
4
+ const sdk_types_1 = require("./types/sdk-types");
5
+ const interval_tree_1 = require("./utils/interval-tree");
6
+ const validation_1 = require("./internal/validation");
7
+ const date_extraction_1 = require("./internal/date-extraction");
8
+ const indexing_1 = require("./internal/indexing");
9
+ const reference_resolution_1 = require("./internal/reference-resolution");
10
+ const bundle_operations_1 = require("./internal/bundle-operations");
11
+ const graph_traversal_1 = require("./internal/graph-traversal");
12
+ const llm_context_1 = require("./internal/llm-context");
13
+ /**
14
+ * FHIR Bundle SDK for parsing, querying, and manipulating FHIR bundles with reference resolution
15
+ */
16
+ class FhirBundleSdk {
17
+ constructor(bundle) {
18
+ this.resourcesById = new Map();
19
+ this.resourcesByFullUrl = new Map();
20
+ this.resourcesByType = new Map();
21
+ // Reverse reference index: maps resource ID to resources that reference it
22
+ this.reverseReferencesById = new Map();
23
+ // Date range index: interval tree for O(log n + k) date range searches
24
+ this.dateRangeIndex = new interval_tree_1.IntervalTree();
25
+ // Smart resource caching to maintain object identity
26
+ this.smartResourceCache = new WeakMap();
27
+ // Array caching for type-specific getters to maintain reference identity
28
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
29
+ this.smartResourceArrayCache = new Map();
30
+ // Circular reference protection
31
+ this.resolutionStack = new Set();
32
+ // FR-1.1, FR-1.4: Initialize bundle and create indexes
33
+ this.bundle = bundle;
34
+ this.bundle.total = bundle.entry?.length ?? 0;
35
+ (0, indexing_1.buildResourceIndexes)(this.bundle, this.resourcesById, this.resourcesByFullUrl, this.resourcesByType, this.reverseReferencesById, this.dateRangeIndex, this.resolutionStack);
36
+ }
37
+ get total() {
38
+ if (!this.bundle.entry) {
39
+ throw new Error("No valid total - bundle property `entry` is undefined");
40
+ }
41
+ return this.bundle.entry.length;
42
+ }
43
+ get entry() {
44
+ if (!this.bundle.entry) {
45
+ console.error("Bundle property `entry` is undefined");
46
+ return [];
47
+ }
48
+ return this.bundle.entry;
49
+ }
50
+ toObject() {
51
+ return this.bundle;
52
+ }
53
+ /**
54
+ * Strip non-clinical metadata from a FHIR resource to reduce noise for LLM consumption.
55
+ * Removes: meta, extension, modifierExtension, text, id, identifier, and all reference fields
56
+ * Returns an immutable copy without mutating the original.
57
+ */
58
+ static stripNonClinicalData(resource) {
59
+ return (0, llm_context_1.stripNonClinicalData)(resource);
60
+ }
61
+ /**
62
+ * Create a new FhirBundleSdk instance (async for backwards compatibility)
63
+ * FR-1.2: Validate bundle resourceType
64
+ */
65
+ static async create(bundle) {
66
+ return FhirBundleSdk.createSync(bundle);
67
+ }
68
+ /**
69
+ * Create a new FhirBundleSdk instance synchronously
70
+ * FR-1.2: Validate bundle resourceType
71
+ */
72
+ static createSync(bundle) {
73
+ // FR-1.2: Validate bundle resourceType
74
+ if (bundle.resourceType !== "Bundle") {
75
+ throw new Error("Invalid bundle: resourceType must be 'Bundle'");
76
+ }
77
+ return new FhirBundleSdk(bundle);
78
+ }
79
+ /**
80
+ * Create a smart resource with reference resolution methods
81
+ * FR-5.1: Resources returned by SDK have additional getter methods for each Reference field
82
+ * FR-5.7: Reference resolution operates in O(1) time complexity per reference
83
+ * FR-5.8: Original reference fields remain unchanged
84
+ */
85
+ createSmartResource(resource) {
86
+ return (0, reference_resolution_1.createSmartResource)(resource, this.smartResourceCache, this.resourcesById, this.resourcesByFullUrl, this.resolutionStack, (targetId, options) => this.getResourcesReferencingId(targetId, options));
87
+ }
88
+ /**
89
+ * FR-2.1: Validate all references in the bundle
90
+ * FR-2.2: Identifies references by Resource/id pattern and fullUrl references
91
+ * FR-2.3: Handles both relative and absolute references
92
+ * FR-2.4: Returns validation result with broken reference details
93
+ */
94
+ lookForBrokenReferences() {
95
+ return (0, validation_1.lookForBrokenReferences)(this.bundle, this.resourcesById, this.resourcesByFullUrl);
96
+ }
97
+ /**
98
+ * FR-3.1: Get resource by ID with type parameter support
99
+ * FR-3.2: Method searches both resource.id and entry.fullUrl for matches
100
+ * FR-3.4: Method returns undefined if resource not found
101
+ * FR-3.5: Lookup operates in O(1) time complexity
102
+ * FR-5.1: Returns smart resource with reference resolution methods
103
+ */
104
+ getResourceById(id) {
105
+ // First try to find by resource.id
106
+ const resourceById = this.resourcesById.get(id);
107
+ if (resourceById) {
108
+ return this.createSmartResource(resourceById);
109
+ }
110
+ // Then try to find by fullUrl
111
+ const resourceByFullUrl = this.resourcesByFullUrl.get(id);
112
+ if (resourceByFullUrl) {
113
+ return this.createSmartResource(resourceByFullUrl);
114
+ }
115
+ // Return undefined if not found (FR-3.4)
116
+ return undefined;
117
+ }
118
+ /**
119
+ * Generic helper method to get a resource by ID with type validation
120
+ */
121
+ getResourceByIdAndType(id, resourceType) {
122
+ const resource = this.getResourceById(id);
123
+ if (resource && resource.resourceType === resourceType) {
124
+ return resource;
125
+ }
126
+ return undefined;
127
+ }
128
+ /**
129
+ * Generic helper method to get all resources of a specific type
130
+ * FR-10.1: Returns references to cached objects, not copies
131
+ */
132
+ getResourcesByType(resourceType) {
133
+ // Check cache first to maintain array reference identity
134
+ const cached = this.smartResourceArrayCache.get(resourceType);
135
+ if (cached) {
136
+ return cached;
137
+ }
138
+ const resources = (this.resourcesByType.get(resourceType) || []);
139
+ const smartResources = resources.map(resource => this.createSmartResource(resource));
140
+ // Cache the array to maintain reference identity
141
+ this.smartResourceArrayCache.set(resourceType, smartResources);
142
+ return smartResources;
143
+ }
144
+ /**
145
+ * FR-6.1: Export subset of resources by their IDs
146
+ * FR-6.4: Exported bundles maintain original bundle metadata but update total count
147
+ * FR-6.5: Exported bundles include only resources that exist in the original bundle
148
+ * FR-6.6: Exported bundles preserve original entry.fullUrl values
149
+ */
150
+ exportSubset(resourceIds) {
151
+ const exportEntries = [];
152
+ for (const resourceId of resourceIds) {
153
+ const resource = this.getResourceById(resourceId);
154
+ if (resource) {
155
+ // Cast to Resource to satisfy type checker - Smart extends Resource
156
+ const plainResource = resource;
157
+ const originalEntry = (0, bundle_operations_1.findOriginalEntry)(this.bundle, plainResource);
158
+ if (originalEntry) {
159
+ exportEntries.push((0, bundle_operations_1.createBundleEntry)(originalEntry, plainResource));
160
+ }
161
+ }
162
+ // FR-6.5: Silently skip resources that don't exist
163
+ }
164
+ return (0, bundle_operations_1.createExportBundle)(this.bundle, exportEntries);
165
+ }
166
+ /**
167
+ * FR-6.2: Export all resources of a specific type
168
+ * FR-6.4: Exported bundles maintain original bundle metadata but update total count
169
+ * FR-6.6: Exported bundles preserve original entry.fullUrl values
170
+ */
171
+ exportByType(resourceType) {
172
+ const resources = this.resourcesByType.get(resourceType) || [];
173
+ const exportEntries = [];
174
+ for (const resource of resources) {
175
+ const originalEntry = (0, bundle_operations_1.findOriginalEntry)(this.bundle, resource);
176
+ if (originalEntry) {
177
+ // Resource is already a plain Resource from our internal maps
178
+ exportEntries.push((0, bundle_operations_1.createBundleEntry)(originalEntry, resource));
179
+ }
180
+ }
181
+ return (0, bundle_operations_1.createExportBundle)(this.bundle, exportEntries);
182
+ }
183
+ /**
184
+ * FR-6.3: Export all resources of specified types
185
+ * FR-6.4: Exported bundles maintain original bundle metadata but update total count
186
+ * FR-6.6: Exported bundles preserve original entry.fullUrl values
187
+ */
188
+ exportByTypes(resourceTypes) {
189
+ const exportEntries = [];
190
+ for (const resourceType of resourceTypes) {
191
+ const resources = this.resourcesByType.get(resourceType) || [];
192
+ for (const resource of resources) {
193
+ const originalEntry = (0, bundle_operations_1.findOriginalEntry)(this.bundle, resource);
194
+ if (originalEntry) {
195
+ exportEntries.push((0, bundle_operations_1.createBundleEntry)(originalEntry, resource));
196
+ }
197
+ }
198
+ }
199
+ return (0, bundle_operations_1.createExportBundle)(this.bundle, exportEntries);
200
+ }
201
+ /**
202
+ * Concatenate entries from another FhirBundleSdk with this bundle
203
+ * Returns a new bundle with combined entries while preserving original metadata
204
+ */
205
+ async concatEntries(otherSdk) {
206
+ const currentEntries = this.bundle.entry || [];
207
+ const otherEntries = otherSdk.bundle.entry || [];
208
+ const combinedEntries = [...currentEntries, ...otherEntries];
209
+ const resultBundle = (0, bundle_operations_1.createExportBundle)(this.bundle, combinedEntries);
210
+ return await FhirBundleSdk.create(resultBundle);
211
+ }
212
+ /**
213
+ * Diff this bundle with another bundle or FhirBundleSdk by comparing resource ids.
214
+ * Returns three FhirBundleSdk instances: common, baseOnly, parameterOnly.
215
+ */
216
+ async diff(other) {
217
+ const baseBundle = this.bundle;
218
+ const parameterBundle = other instanceof FhirBundleSdk ? other.bundle : other;
219
+ const commonEntries = [];
220
+ const baseOnlyEntries = [];
221
+ const parameterOnlyEntries = [];
222
+ // Create maps with resource identifiers (prefer resource.id, fallback to fullUrl)
223
+ const baseResourceIdentifiers = new Map();
224
+ const parameterResourceIdentifiers = new Map();
225
+ // Populate base bundle identifiers
226
+ for (const entry of baseBundle?.entry ?? []) {
227
+ const identifier = (0, sdk_types_1.getResourceIdentifier)(entry);
228
+ if (identifier) {
229
+ baseResourceIdentifiers.set(identifier, entry);
230
+ }
231
+ }
232
+ // Populate parameter bundle identifiers
233
+ for (const entry of parameterBundle?.entry ?? []) {
234
+ const identifier = (0, sdk_types_1.getResourceIdentifier)(entry);
235
+ if (identifier) {
236
+ parameterResourceIdentifiers.set(identifier, entry);
237
+ }
238
+ }
239
+ // Find common and base-only resources
240
+ for (const [identifier, entry] of baseResourceIdentifiers.entries()) {
241
+ if (parameterResourceIdentifiers.has(identifier)) {
242
+ commonEntries.push(entry);
243
+ }
244
+ else {
245
+ baseOnlyEntries.push(entry);
246
+ }
247
+ }
248
+ // Find parameter-only resources
249
+ for (const [identifier, entry] of parameterResourceIdentifiers.entries()) {
250
+ if (!baseResourceIdentifiers.has(identifier)) {
251
+ parameterOnlyEntries.push(entry);
252
+ }
253
+ }
254
+ return {
255
+ common: await FhirBundleSdk.create((0, bundle_operations_1.createExportBundle)(this.bundle, commonEntries)),
256
+ baseOnly: await FhirBundleSdk.create((0, bundle_operations_1.createExportBundle)(this.bundle, baseOnlyEntries)),
257
+ parameterOnly: await FhirBundleSdk.create((0, bundle_operations_1.createExportBundle)(this.bundle, parameterOnlyEntries)),
258
+ };
259
+ }
260
+ /**
261
+ * Walk references from a starting resource using BFS traversal.
262
+ * Discovers all reachable resources up to maxDepth levels.
263
+ *
264
+ * @param startResource - The smart resource to start traversal from
265
+ * @param options - Walk options including maxDepth and includeStartResource
266
+ * @returns WalkResult containing all discovered resources organized by depth
267
+ */
268
+ walkReferences(startResource, options) {
269
+ return (0, graph_traversal_1.walkReferences)(startResource, options);
270
+ }
271
+ /**
272
+ * Generate LLM-friendly context from a starting resource and its related resources.
273
+ * Uses BFS to discover related resources, strips non-clinical data, and formats output.
274
+ *
275
+ * @param startResource - The smart resource to start traversal from
276
+ * @param options - Options for depth, inclusion, and format
277
+ * @returns Formatted string suitable for LLM context
278
+ */
279
+ generateLLMContext(startResource, options) {
280
+ return (0, llm_context_1.generateLLMContext)(startResource, options, (sr, opts) => this.walkReferences(sr, opts));
281
+ }
282
+ /**
283
+ * Get all resources that reference a given resource ID (reverse reference lookup).
284
+ * Operates in O(1) time complexity.
285
+ *
286
+ * @param targetId - The ID of the resource to find references to
287
+ * @param options - Optional filters for resourceType and referenceField
288
+ * @returns Array of smart resources that reference the target resource
289
+ */
290
+ getResourcesReferencingId(targetId, options) {
291
+ const reverseRefs = this.reverseReferencesById.get(targetId) ?? [];
292
+ let filteredRefs = reverseRefs;
293
+ // Apply resource type filter
294
+ if (options?.resourceType) {
295
+ filteredRefs = filteredRefs.filter(ref => ref.sourceResourceType === options.resourceType);
296
+ }
297
+ // Apply reference field filter
298
+ if (options?.referenceField) {
299
+ filteredRefs = filteredRefs.filter(ref => ref.referenceField === options.referenceField);
300
+ }
301
+ // Convert to smart resources
302
+ const smartResources = [];
303
+ for (const ref of filteredRefs) {
304
+ const resource = this.getResourceById(ref.sourceResourceId);
305
+ if (resource) {
306
+ smartResources.push(resource);
307
+ }
308
+ }
309
+ return smartResources;
310
+ }
311
+ /**
312
+ * Get all resources referenced by a given resource (forward reference lookup).
313
+ * Returns all resources that the given resource points to based on REFERENCE_METHOD_MAPPING.
314
+ *
315
+ * @param resource - The smart resource to get references from
316
+ * @returns Array of smart resources referenced by the given resource
317
+ */
318
+ getResourcesReferencedBy(resource) {
319
+ return resource.getReferencedResources();
320
+ }
321
+ /**
322
+ * Search for resources by date range using interval tree.
323
+ * Operates in O(log n + k) time complexity, where k is the number of matching intervals.
324
+ *
325
+ * @param options - Search options including date range and optional filters
326
+ * @returns Array of smart resources that match the date range criteria
327
+ */
328
+ searchByDateRange(options) {
329
+ const { dateFrom, dateTo, resourceTypes, dateFields } = options;
330
+ const fromMs = (0, date_extraction_1.parseDate)(typeof dateFrom === "string" ? dateFrom : dateFrom.toISOString());
331
+ const toMs = (0, date_extraction_1.parseDate)(dateTo
332
+ ? typeof dateTo === "string"
333
+ ? dateTo
334
+ : dateTo.toISOString()
335
+ : new Date().toISOString());
336
+ if (fromMs === undefined) {
337
+ throw new Error("Invalid dateFrom parameter");
338
+ }
339
+ if (toMs === undefined) {
340
+ throw new Error("Invalid dateTo parameter");
341
+ }
342
+ const matchingRecords = this.dateRangeIndex.search(fromMs, toMs);
343
+ let filteredRecords = matchingRecords;
344
+ if (resourceTypes && resourceTypes.length > 0) {
345
+ const resourceTypeSet = new Set(resourceTypes);
346
+ filteredRecords = filteredRecords.filter(record => resourceTypeSet.has(record.resourceType));
347
+ }
348
+ if (dateFields && dateFields.length > 0) {
349
+ const dateFieldSet = new Set(dateFields);
350
+ filteredRecords = filteredRecords.filter(record => dateFieldSet.has(record.dateField));
351
+ }
352
+ const resourceIdSet = new Set(filteredRecords.map(record => record.resourceId));
353
+ const smartResources = [];
354
+ for (const resourceId of resourceIdSet) {
355
+ const resource = this.getResourceById(resourceId);
356
+ if (resource) {
357
+ smartResources.push(resource);
358
+ }
359
+ }
360
+ return smartResources;
361
+ }
362
+ }
363
+ exports.FhirBundleSdk = FhirBundleSdk;
364
+ /**
365
+ * Configuration for dynamically generated resource getter methods.
366
+ *
367
+ * Each entry in this array automatically generates both single and collection getter methods.
368
+ *
369
+ * **Example:**
370
+ * ```typescript
371
+ * {
372
+ * resourceType: 'Patient',
373
+ * singleGetterMethodName: 'getPatientById',
374
+ * collectionGetterMethodName: 'getPatients'
375
+ * }
376
+ * ```
377
+ *
378
+ * **Generates the equivalent of:**
379
+ * ```typescript
380
+ * // Single resource getter
381
+ * getPatientById(id: string): Smart<Patient> | undefined {
382
+ * return this.getResourceByIdAndType<Patient>(id, 'Patient');
383
+ * }
384
+ *
385
+ * // Collection getter
386
+ * getPatients(): Smart<Patient>[] {
387
+ * return this.getResourcesByType<Patient>('Patient');
388
+ * }
389
+ * ```
390
+ *
391
+ * **Usage:**
392
+ * ```typescript
393
+ * const sdk = await FhirBundleSdk.create(bundle);
394
+ * const patient = sdk.getPatientById('patient-123'); // Smart<Patient> | undefined
395
+ * const allPatients = sdk.getPatients(); // Smart<Patient>[]
396
+ * ```
397
+ *
398
+ * To add a new resource type, simply add a new entry to this array and declare
399
+ * the corresponding method signatures in the class body.
400
+ */
401
+ FhirBundleSdk.RESOURCE_METHODS = [
402
+ {
403
+ resourceType: "Patient",
404
+ singleGetterMethodName: "getPatientById",
405
+ collectionGetterMethodName: "getPatients",
406
+ },
407
+ {
408
+ resourceType: "Observation",
409
+ singleGetterMethodName: "getObservationById",
410
+ collectionGetterMethodName: "getObservations",
411
+ },
412
+ {
413
+ resourceType: "Encounter",
414
+ singleGetterMethodName: "getEncounterById",
415
+ collectionGetterMethodName: "getEncounters",
416
+ },
417
+ {
418
+ resourceType: "AllergyIntolerance",
419
+ singleGetterMethodName: "getAllergyIntoleranceById",
420
+ collectionGetterMethodName: "getAllergyIntolerances",
421
+ },
422
+ {
423
+ resourceType: "Condition",
424
+ singleGetterMethodName: "getConditionById",
425
+ collectionGetterMethodName: "getConditions",
426
+ },
427
+ {
428
+ resourceType: "Organization",
429
+ singleGetterMethodName: "getOrganizationById",
430
+ collectionGetterMethodName: "getOrganizations",
431
+ },
432
+ {
433
+ resourceType: "Location",
434
+ singleGetterMethodName: "getLocationById",
435
+ collectionGetterMethodName: "getLocations",
436
+ },
437
+ {
438
+ resourceType: "Practitioner",
439
+ singleGetterMethodName: "getPractitionerById",
440
+ collectionGetterMethodName: "getPractitioners",
441
+ },
442
+ {
443
+ resourceType: "DiagnosticReport",
444
+ singleGetterMethodName: "getDiagnosticReportById",
445
+ collectionGetterMethodName: "getDiagnosticReports",
446
+ },
447
+ {
448
+ resourceType: "Composition",
449
+ singleGetterMethodName: "getCompositionById",
450
+ collectionGetterMethodName: "getCompositions",
451
+ },
452
+ {
453
+ resourceType: "Coverage",
454
+ singleGetterMethodName: "getCoverageById",
455
+ collectionGetterMethodName: "getCoverages",
456
+ },
457
+ {
458
+ resourceType: "DocumentReference",
459
+ singleGetterMethodName: "getDocumentReferenceById",
460
+ collectionGetterMethodName: "getDocumentReferences",
461
+ },
462
+ {
463
+ resourceType: "Immunization",
464
+ singleGetterMethodName: "getImmunizationById",
465
+ collectionGetterMethodName: "getImmunizations",
466
+ },
467
+ {
468
+ resourceType: "Medication",
469
+ singleGetterMethodName: "getMedicationById",
470
+ collectionGetterMethodName: "getMedications",
471
+ },
472
+ {
473
+ resourceType: "MedicationRequest",
474
+ singleGetterMethodName: "getMedicationRequestById",
475
+ collectionGetterMethodName: "getMedicationRequests",
476
+ },
477
+ {
478
+ resourceType: "Procedure",
479
+ singleGetterMethodName: "getProcedureById",
480
+ collectionGetterMethodName: "getProcedures",
481
+ },
482
+ {
483
+ resourceType: "FamilyMemberHistory",
484
+ singleGetterMethodName: "getFamilyMemberHistoryById",
485
+ collectionGetterMethodName: "getFamilyMemberHistories",
486
+ },
487
+ {
488
+ resourceType: "MedicationAdministration",
489
+ singleGetterMethodName: "getMedicationAdministrationById",
490
+ collectionGetterMethodName: "getMedicationAdministrations",
491
+ },
492
+ {
493
+ resourceType: "MedicationDispense",
494
+ singleGetterMethodName: "getMedicationDispenseById",
495
+ collectionGetterMethodName: "getMedicationDispenses",
496
+ },
497
+ {
498
+ resourceType: "MedicationStatement",
499
+ singleGetterMethodName: "getMedicationStatementById",
500
+ collectionGetterMethodName: "getMedicationStatements",
501
+ },
502
+ {
503
+ resourceType: "RelatedPerson",
504
+ singleGetterMethodName: "getRelatedPersonById",
505
+ collectionGetterMethodName: "getRelatedPersons",
506
+ },
507
+ {
508
+ resourceType: "RiskAssessment",
509
+ singleGetterMethodName: "getRiskAssessmentById",
510
+ collectionGetterMethodName: "getRiskAssessments",
511
+ },
512
+ {
513
+ resourceType: "ServiceRequest",
514
+ singleGetterMethodName: "getServiceRequestById",
515
+ collectionGetterMethodName: "getServiceRequests",
516
+ },
517
+ {
518
+ resourceType: "CarePlan",
519
+ singleGetterMethodName: "getCarePlanById",
520
+ collectionGetterMethodName: "getCarePlans",
521
+ },
522
+ ];
523
+ // Static initialization block to generate methods
524
+ (() => {
525
+ // Generate both single and collection getter methods from unified configuration
526
+ for (const { resourceType, singleGetterMethodName, collectionGetterMethodName, } of FhirBundleSdk.RESOURCE_METHODS) {
527
+ // Generate single resource getter (e.g., getPatientById)
528
+ Object.defineProperty(FhirBundleSdk.prototype, singleGetterMethodName, {
529
+ value: function (id) {
530
+ return this.getResourceByIdAndType(id, resourceType);
531
+ },
532
+ writable: false,
533
+ configurable: false,
534
+ });
535
+ // Generate collection getter (e.g., getPatients)
536
+ Object.defineProperty(FhirBundleSdk.prototype, collectionGetterMethodName, {
537
+ value: function () {
538
+ return this.getResourcesByType(resourceType);
539
+ },
540
+ writable: false,
541
+ configurable: false,
542
+ });
543
+ }
544
+ })();
545
+ //# sourceMappingURL=fhir-bundle-sdk.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fhir-bundle-sdk.js","sourceRoot":"","sources":["../src/fhir-bundle-sdk.ts"],"names":[],"mappings":";;;AA8BA,iDAW2B;AAC3B,yDAAqD;AACrD,sDAA+F;AAC/F,gEAAuD;AACvD,kDAA2D;AAC3D,0EAAiG;AACjG,oEAIsC;AACtC,gEAAkF;AAClF,wDAGgC;AAEhC;;GAEG;AACH,MAAa,aAAa;IAkNxB,YAAoB,MAAc;QAhN1B,kBAAa,GAA0B,IAAI,GAAG,EAAE,CAAC;QACjD,uBAAkB,GAA0B,IAAI,GAAG,EAAE,CAAC;QACtD,oBAAe,GAA4B,IAAI,GAAG,EAAE,CAAC;QAE7D,2EAA2E;QACnE,0BAAqB,GAAoC,IAAI,GAAG,EAAE,CAAC;QAE3E,uEAAuE;QAC/D,mBAAc,GAA0C,IAAI,4BAAY,EAAE,CAAC;QAEnF,qDAAqD;QAC7C,uBAAkB,GAAuC,IAAI,OAAO,EAAE,CAAC;QAE/E,yEAAyE;QACzE,8DAA8D;QACtD,4BAAuB,GAA8B,IAAI,GAAG,EAAE,CAAC;QAEvE,gCAAgC;QACxB,oBAAe,GAAG,IAAI,GAAG,EAAU,CAAC;QA+L1C,uDAAuD;QACvD,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,MAAM,CAAC,KAAK,GAAG,MAAM,CAAC,KAAK,EA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IAAI,aAAa,CAAC,gBAAgB,EAAE;QACnC,yDAAyD;QACzD,MAAM,CAAC,cAAc,CAAC,aAAa,CAAC,SAAS,EAAE,sBAAsB,EAAE;YACrE,KAAK,EAAE,UAA+B,EAAU;gBAC9C,OAAO,IAAI,CAAC,sBAAsB,CAAC,EAAE,EAAE,YAAY,CAAC,CAAC;YACvD,CAAC;YACD,QAAQ,EAAE,KAAK;YACf,YAAY,EAAE,KAAK;SACpB,CAAC,CAAC;QAEH,iDAAiD;QACjD,MAAM,CAAC,cAAc,CAAC,aAAa,CAAC,SAAS,EAAE,0BAA0B,EAAE;YACzE,KAAK,EAAE;gBACL,OAAO,IAAI,CAAC,kBAAkB,CAAC,YAAY,CAAC,CAAC;YAC/C,CAAC;YACD,QAAQ,EAAE,KAAK;YACf,YAAY,EAAE,KAAK;SACpB,CAAC,CAAC;KACJ;AACH,CAAC,GAAA,CAAA"}
@@ -0,0 +1,8 @@
1
+ export { FhirBundleSdk } from "./fhir-bundle-sdk";
2
+ export { Smart, SmartCoding, SmartCodeableConcept } from "./types/smart-resources";
3
+ export { ValidationResult, BrokenReference, BundleDiffResult, WalkOptions, LLMContextOptions, WalkResult, ReverseReferenceOptions, DateRangeSearchOptions, } from "./types/sdk-types";
4
+ export type { ObservationCodingFields, ConditionCodingFields, ProcedureCodingFields, AllergyIntoleranceCodingFields, EncounterCodingFields, DiagnosticReportCodingFields, ImmunizationCodingFields, MedicationCodingFields, MedicationRequestCodingFields, MedicationAdministrationCodingFields, MedicationDispenseCodingFields, MedicationStatementCodingFields, FamilyMemberHistoryCodingFields, RelatedPersonCodingFields, RiskAssessmentCodingFields, ServiceRequestCodingFields, CarePlanCodingFields, PatientCodingFields, PractitionerCodingFields, OrganizationCodingFields, LocationCodingFields, CompositionCodingFields, CoverageCodingFields, DocumentReferenceCodingFields, SmartObservation, SmartCondition, SmartProcedure, SmartAllergyIntolerance, SmartEncounter, SmartDiagnosticReport, SmartImmunization, SmartMedication, SmartMedicationRequest, SmartMedicationAdministration, SmartMedicationDispense, SmartMedicationStatement, SmartFamilyMemberHistory, SmartRelatedPerson, SmartRiskAssessment, SmartServiceRequest, SmartCarePlan, SmartPatient, SmartPractitioner, SmartOrganization, SmartLocation, SmartComposition, SmartCoverage, SmartDocumentReference, } from "./types/coding-fields";
5
+ export { getClinicalDateRange, ResourceDateRange } from "./clinical-dates";
6
+ export { AllergyIntolerance, Bundle, CarePlan, CodeableConcept, Coding, Composition, Condition, Coverage, DiagnosticReport, DocumentReference, Encounter, FamilyMemberHistory, Immunization, Location, Medication, MedicationAdministration, MedicationDispense, MedicationRequest, MedicationStatement, Observation, Organization, Patient, Practitioner, Procedure, RelatedPerson, Resource, RiskAssessment, ServiceRequest, } from "@medplum/fhirtypes";
7
+ export * from "./type-guards";
8
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAClD,OAAO,EAAE,KAAK,EAAE,WAAW,EAAE,oBAAoB,EAAE,MAAM,yBAAyB,CAAC;AACnF,OAAO,EACL,gBAAgB,EAChB,eAAe,EACf,gBAAgB,EAChB,WAAW,EACX,iBAAiB,EACjB,UAAU,EACV,uBAAuB,EACvB,sBAAsB,GACvB,MAAM,mBAAmB,CAAC;AAC3B,YAAY,EAEV,uBAAuB,EACvB,qBAAqB,EACrB,qBAAqB,EACrB,8BAA8B,EAC9B,qBAAqB,EACrB,4BAA4B,EAC5B,wBAAwB,EACxB,sBAAsB,EACtB,6BAA6B,EAC7B,oCAAoC,EACpC,8BAA8B,EAC9B,+BAA+B,EAC/B,+BAA+B,EAC/B,yBAAyB,EACzB,0BAA0B,EAC1B,0BAA0B,EAC1B,oBAAoB,EACpB,mBAAmB,EACnB,wBAAwB,EACxB,wBAAwB,EACxB,oBAAoB,EACpB,uBAAuB,EACvB,oBAAoB,EACpB,6BAA6B,EAE7B,gBAAgB,EAChB,cAAc,EACd,cAAc,EACd,uBAAuB,EACvB,cAAc,EACd,qBAAqB,EACrB,iBAAiB,EACjB,eAAe,EACf,sBAAsB,EACtB,6BAA6B,EAC7B,uBAAuB,EACvB,wBAAwB,EACxB,wBAAwB,EACxB,kBAAkB,EAClB,mBAAmB,EACnB,mBAAmB,EACnB,aAAa,EACb,YAAY,EACZ,iBAAiB,EACjB,iBAAiB,EACjB,aAAa,EACb,gBAAgB,EAChB,aAAa,EACb,sBAAsB,GACvB,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EAAE,oBAAoB,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AAE3E,OAAO,EACL,kBAAkB,EAClB,MAAM,EACN,QAAQ,EACR,eAAe,EACf,MAAM,EACN,WAAW,EACX,SAAS,EACT,QAAQ,EACR,gBAAgB,EAChB,iBAAiB,EACjB,SAAS,EACT,mBAAmB,EACnB,YAAY,EACZ,QAAQ,EACR,UAAU,EACV,wBAAwB,EACxB,kBAAkB,EAClB,iBAAiB,EACjB,mBAAmB,EACnB,WAAW,EACX,YAAY,EACZ,OAAO,EACP,YAAY,EACZ,SAAS,EACT,aAAa,EACb,QAAQ,EACR,cAAc,EACd,cAAc,GACf,MAAM,oBAAoB,CAAC;AAE5B,cAAc,eAAe,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,23 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ exports.getClinicalDateRange = exports.FhirBundleSdk = void 0;
18
+ var fhir_bundle_sdk_1 = require("./fhir-bundle-sdk");
19
+ Object.defineProperty(exports, "FhirBundleSdk", { enumerable: true, get: function () { return fhir_bundle_sdk_1.FhirBundleSdk; } });
20
+ var clinical_dates_1 = require("./clinical-dates");
21
+ Object.defineProperty(exports, "getClinicalDateRange", { enumerable: true, get: function () { return clinical_dates_1.getClinicalDateRange; } });
22
+ __exportStar(require("./type-guards"), exports);
23
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAAA,qDAAkD;AAAzC,gHAAA,aAAa,OAAA;AAgEtB,mDAA2E;AAAlE,sHAAA,oBAAoB,OAAA;AAiC7B,gDAA8B"}
@@ -0,0 +1,14 @@
1
+ import { Bundle, BundleEntry, Resource } from "@medplum/fhirtypes";
2
+ /**
3
+ * Create a new bundle entry from an existing entry, preserving fullUrl
4
+ */
5
+ export declare function createBundleEntry(originalEntry: BundleEntry, resource: Resource): BundleEntry;
6
+ /**
7
+ * Create a new bundle with specified entries, maintaining original metadata
8
+ */
9
+ export declare function createExportBundle(originalBundle: Bundle, entries: BundleEntry[]): Bundle;
10
+ /**
11
+ * Find original bundle entry for a given resource
12
+ */
13
+ export declare function findOriginalEntry(bundle: Bundle, resource: Resource): BundleEntry | undefined;
14
+ //# sourceMappingURL=bundle-operations.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"bundle-operations.d.ts","sourceRoot":"","sources":["../../src/internal/bundle-operations.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AAEnE;;GAEG;AACH,wBAAgB,iBAAiB,CAAC,aAAa,EAAE,WAAW,EAAE,QAAQ,EAAE,QAAQ,GAAG,WAAW,CAW7F;AAED;;GAEG;AACH,wBAAgB,kBAAkB,CAAC,cAAc,EAAE,MAAM,EAAE,OAAO,EAAE,WAAW,EAAE,GAAG,MAAM,CAuBzF;AAED;;GAEG;AACH,wBAAgB,iBAAiB,CAAC,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,QAAQ,GAAG,WAAW,GAAG,SAAS,CAS7F"}