@metriport/fhir-sdk 1.6.0 → 1.6.2
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.
- package/dist/__tests__/careplan.test.js +22 -24
- package/dist/__tests__/careplan.test.js.map +1 -1
- package/dist/__tests__/clinical-dates.test.js +23 -25
- package/dist/__tests__/clinical-dates.test.js.map +1 -1
- package/dist/__tests__/coding-utilities.test.js +7 -9
- package/dist/__tests__/coding-utilities.test.js.map +1 -1
- package/dist/__tests__/date-range-performance.test.js +2 -4
- package/dist/__tests__/date-range-performance.test.js.map +1 -1
- package/dist/__tests__/date-range-search.test.js +13 -15
- package/dist/__tests__/date-range-search.test.js.map +1 -1
- package/dist/__tests__/env-setup.js +4 -32
- package/dist/__tests__/env-setup.js.map +1 -1
- package/dist/__tests__/fhir-bundle-sdk-basic.test.js +4 -6
- package/dist/__tests__/fhir-bundle-sdk-basic.test.js.map +1 -1
- package/dist/__tests__/fhir-bundle-sdk.test.js +85 -87
- package/dist/__tests__/fhir-bundle-sdk.test.js.map +1 -1
- package/dist/__tests__/fixtures/fhir-bundles.d.ts +1 -1
- package/dist/__tests__/fixtures/fhir-bundles.d.ts.map +1 -1
- package/dist/__tests__/fixtures/fhir-bundles.js +11 -17
- package/dist/__tests__/fixtures/fhir-bundles.js.map +1 -1
- package/dist/__tests__/phase1-verification.test.js +10 -12
- package/dist/__tests__/phase1-verification.test.js.map +1 -1
- package/dist/__tests__/phase2-verification.test.js +14 -16
- package/dist/__tests__/phase2-verification.test.js.map +1 -1
- package/dist/__tests__/phase3-verification.test.js +15 -17
- package/dist/__tests__/phase3-verification.test.js.map +1 -1
- package/dist/__tests__/phase4-verification.test.js +27 -29
- package/dist/__tests__/phase4-verification.test.js.map +1 -1
- package/dist/__tests__/phase5-verification.test.js +38 -40
- package/dist/__tests__/phase5-verification.test.js.map +1 -1
- package/dist/__tests__/reverse-references.test.js +29 -31
- package/dist/__tests__/reverse-references.test.js.map +1 -1
- package/dist/__tests__/type-guards.test.js +16 -18
- package/dist/__tests__/type-guards.test.js.map +1 -1
- package/dist/clinical-dates.js +1 -5
- package/dist/clinical-dates.js.map +1 -1
- package/dist/fhir-bundle-sdk.js +34 -38
- package/dist/fhir-bundle-sdk.js.map +1 -1
- package/dist/index.js +4 -22
- package/dist/index.js.map +1 -1
- package/dist/internal/bundle-operations.js +3 -9
- package/dist/internal/bundle-operations.js.map +1 -1
- package/dist/internal/coding-systems.d.ts +12 -12
- package/dist/internal/coding-systems.js +15 -18
- package/dist/internal/coding-systems.js.map +1 -1
- package/dist/internal/coding-utilities.js +15 -23
- package/dist/internal/coding-utilities.js.map +1 -1
- package/dist/internal/date-extraction.js +2 -7
- package/dist/internal/date-extraction.js.map +1 -1
- package/dist/internal/graph-traversal.js +3 -7
- package/dist/internal/graph-traversal.js.map +1 -1
- package/dist/internal/indexing.js +9 -15
- package/dist/internal/indexing.js.map +1 -1
- package/dist/internal/llm-context.js +8 -17
- package/dist/internal/llm-context.js.map +1 -1
- package/dist/internal/reference-resolution.js +25 -32
- package/dist/internal/reference-resolution.js.map +1 -1
- package/dist/internal/reference-utils.js +4 -11
- package/dist/internal/reference-utils.js.map +1 -1
- package/dist/internal/transparent-proxy.js +10 -14
- package/dist/internal/transparent-proxy.js.map +1 -1
- package/dist/internal/validation.js +4 -8
- package/dist/internal/validation.js.map +1 -1
- package/dist/type-guards.js +26 -55
- package/dist/type-guards.js.map +1 -1
- package/dist/types/coding-fields.js +1 -2
- package/dist/types/sdk-types.js +1 -5
- package/dist/types/sdk-types.js.map +1 -1
- package/dist/types/smart-resources.js +5 -10
- package/dist/types/smart-resources.js.map +1 -1
- package/dist/utils/interval-tree/index.js +10 -19
- package/dist/utils/interval-tree/index.js.map +1 -1
- package/dist/utils/interval-tree/shallowequal/arrays.js +1 -4
- package/dist/utils/interval-tree/shallowequal/arrays.js.map +1 -1
- package/dist/utils/interval-tree/shallowequal/index.js +5 -13
- package/dist/utils/interval-tree/shallowequal/index.js.map +1 -1
- package/dist/utils/interval-tree/shallowequal/objects.js +1 -4
- package/dist/utils/interval-tree/shallowequal/objects.js.map +1 -1
- package/package.json +3 -2
|
@@ -1,48 +1,46 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
const index_1 = require("../index");
|
|
4
|
-
const fhir_bundles_1 = require("./fixtures/fhir-bundles");
|
|
1
|
+
import { FhirBundleSdk } from "../index";
|
|
2
|
+
import { validCompleteBundle, bundleWithBrokenReferences, bundleWithFullUrlReferences, emptyBundle, patientsOnlyBundle, invalidBundleWrongType, mixedResourceTypesBundle, CONSTANT_TIME_EXPECTED_THRESHOLD_MS, } from "./fixtures/fhir-bundles";
|
|
5
3
|
describe("FhirBundleSdk", () => {
|
|
6
4
|
describe("Bundle Loading and Initialization", () => {
|
|
7
5
|
describe("FR-1.1: SDK constructor accepts a FHIR Bundle object", () => {
|
|
8
6
|
it("should accept a valid FHIR bundle", async () => {
|
|
9
|
-
await expect(
|
|
7
|
+
await expect(FhirBundleSdk.create(validCompleteBundle)).resolves.not.toThrow();
|
|
10
8
|
});
|
|
11
9
|
});
|
|
12
10
|
describe("FR-1.2: SDK constructor throws error if bundle.resourceType !== 'Bundle'", () => {
|
|
13
11
|
it("should throw error for invalid resourceType", async () => {
|
|
14
|
-
await expect(
|
|
12
|
+
await expect(FhirBundleSdk.create(invalidBundleWrongType)).rejects.toThrow();
|
|
15
13
|
});
|
|
16
14
|
});
|
|
17
15
|
describe("FR-1.4: SDK constructor creates internal indexes for O(1) resource lookup", () => {
|
|
18
16
|
it("should create internal indexes during construction", async () => {
|
|
19
|
-
const sdk = await
|
|
17
|
+
const sdk = await FhirBundleSdk.create(validCompleteBundle);
|
|
20
18
|
const start = performance.now();
|
|
21
19
|
const patient = sdk.getResourceById("patient-123");
|
|
22
20
|
const end = performance.now();
|
|
23
21
|
expect(patient).toBeDefined();
|
|
24
22
|
expect(patient?.resourceType).toBe("Patient");
|
|
25
|
-
expect(end - start).toBeLessThan(
|
|
23
|
+
expect(end - start).toBeLessThan(CONSTANT_TIME_EXPECTED_THRESHOLD_MS);
|
|
26
24
|
});
|
|
27
25
|
});
|
|
28
26
|
});
|
|
29
27
|
describe("Reference Validation", () => {
|
|
30
28
|
describe("FR-2.1: lookForBrokenReferences() method returns validation result", () => {
|
|
31
29
|
it("should return validation result for valid bundle", async () => {
|
|
32
|
-
const sdk = await
|
|
30
|
+
const sdk = await FhirBundleSdk.create(validCompleteBundle);
|
|
33
31
|
const result = sdk.lookForBrokenReferences();
|
|
34
32
|
expect(result).toBeDefined();
|
|
35
33
|
expect(typeof result.hasBrokenReferences).toBe("boolean");
|
|
36
34
|
expect(Array.isArray(result.brokenReferences)).toBe(true);
|
|
37
35
|
});
|
|
38
36
|
it("should return true for valid references", async () => {
|
|
39
|
-
const sdk = await
|
|
37
|
+
const sdk = await FhirBundleSdk.create(validCompleteBundle);
|
|
40
38
|
const result = sdk.lookForBrokenReferences();
|
|
41
39
|
expect(result.hasBrokenReferences).toBe(false);
|
|
42
40
|
expect(result.brokenReferences).toHaveLength(0);
|
|
43
41
|
});
|
|
44
42
|
it("should return false for invalid references", async () => {
|
|
45
|
-
const sdk = await
|
|
43
|
+
const sdk = await FhirBundleSdk.create(bundleWithBrokenReferences);
|
|
46
44
|
const result = sdk.lookForBrokenReferences();
|
|
47
45
|
expect(result.hasBrokenReferences).toBe(true);
|
|
48
46
|
expect(result.brokenReferences.length).toBeGreaterThan(0);
|
|
@@ -50,32 +48,32 @@ describe("FhirBundleSdk", () => {
|
|
|
50
48
|
});
|
|
51
49
|
describe("FR-2.2: Validation identifies references by Resource/id pattern and fullUrl references", () => {
|
|
52
50
|
it("should identify Resource/id pattern references", async () => {
|
|
53
|
-
const sdk = await
|
|
51
|
+
const sdk = await FhirBundleSdk.create(bundleWithBrokenReferences);
|
|
54
52
|
const result = sdk.lookForBrokenReferences();
|
|
55
53
|
const brokenSubjectRef = result.brokenReferences.find(ref => ref.reference === "Patient/nonexistent-patient");
|
|
56
54
|
expect(brokenSubjectRef).toBeDefined();
|
|
57
55
|
});
|
|
58
56
|
it("should validate fullUrl references", async () => {
|
|
59
|
-
const sdk = await
|
|
57
|
+
const sdk = await FhirBundleSdk.create(bundleWithFullUrlReferences);
|
|
60
58
|
const result = sdk.lookForBrokenReferences();
|
|
61
59
|
expect(result.hasBrokenReferences).toBe(false);
|
|
62
60
|
});
|
|
63
61
|
});
|
|
64
62
|
describe("FR-2.3: Validation handles both relative and absolute references", () => {
|
|
65
63
|
it("should handle relative references (Patient/123)", async () => {
|
|
66
|
-
const sdk = await
|
|
64
|
+
const sdk = await FhirBundleSdk.create(validCompleteBundle);
|
|
67
65
|
const result = sdk.lookForBrokenReferences();
|
|
68
66
|
expect(result.hasBrokenReferences).toBe(false);
|
|
69
67
|
});
|
|
70
68
|
it("should handle absolute references (urn:uuid:123)", async () => {
|
|
71
|
-
const sdk = await
|
|
69
|
+
const sdk = await FhirBundleSdk.create(bundleWithFullUrlReferences);
|
|
72
70
|
const result = sdk.lookForBrokenReferences();
|
|
73
71
|
expect(result.hasBrokenReferences).toBe(false);
|
|
74
72
|
});
|
|
75
73
|
});
|
|
76
74
|
describe("FR-2.4: Validation result includes list of broken references with details", () => {
|
|
77
75
|
it("should provide detailed broken reference information", async () => {
|
|
78
|
-
const sdk = await
|
|
76
|
+
const sdk = await FhirBundleSdk.create(bundleWithBrokenReferences);
|
|
79
77
|
const result = sdk.lookForBrokenReferences();
|
|
80
78
|
expect(result.brokenReferences.length).toBeGreaterThan(0);
|
|
81
79
|
const brokenRef = result.brokenReferences[0];
|
|
@@ -92,7 +90,7 @@ describe("FhirBundleSdk", () => {
|
|
|
92
90
|
describe("Resource Retrieval by ID", () => {
|
|
93
91
|
describe("FR-3.1: getResourceById<T>(id: string): T | undefined returns resource matching the ID", () => {
|
|
94
92
|
it("should return resource by ID", async () => {
|
|
95
|
-
const sdk = await
|
|
93
|
+
const sdk = await FhirBundleSdk.create(validCompleteBundle);
|
|
96
94
|
const patient = sdk.getResourceById("patient-123");
|
|
97
95
|
expect(patient).toBeDefined();
|
|
98
96
|
expect(patient?.id).toBe("patient-123");
|
|
@@ -101,19 +99,19 @@ describe("FhirBundleSdk", () => {
|
|
|
101
99
|
});
|
|
102
100
|
describe("FR-3.2: Method searches both resource.id and entry.fullUrl for matches", () => {
|
|
103
101
|
it("should find resource by resource.id", async () => {
|
|
104
|
-
const sdk = await
|
|
102
|
+
const sdk = await FhirBundleSdk.create(validCompleteBundle);
|
|
105
103
|
const patient = sdk.getResourceById("patient-123");
|
|
106
104
|
expect(patient?.id).toBe("patient-123");
|
|
107
105
|
});
|
|
108
106
|
it("should find resource by fullUrl", async () => {
|
|
109
|
-
const sdk = await
|
|
107
|
+
const sdk = await FhirBundleSdk.create(validCompleteBundle);
|
|
110
108
|
const patient = sdk.getResourceById("urn:uuid:patient-123");
|
|
111
109
|
expect(patient?.id).toBe("patient-123");
|
|
112
110
|
});
|
|
113
111
|
});
|
|
114
112
|
describe("FR-3.3: Method supports type parameter for proper TypeScript return typing", () => {
|
|
115
113
|
it("should return properly typed resource", async () => {
|
|
116
|
-
const sdk = await
|
|
114
|
+
const sdk = await FhirBundleSdk.create(validCompleteBundle);
|
|
117
115
|
const patient = sdk.getResourceById("patient-123");
|
|
118
116
|
// TypeScript should infer this as Patient | undefined
|
|
119
117
|
expect(patient?.name).toBeDefined();
|
|
@@ -122,26 +120,26 @@ describe("FhirBundleSdk", () => {
|
|
|
122
120
|
});
|
|
123
121
|
describe("FR-3.4: Method returns undefined if resource not found", () => {
|
|
124
122
|
it("should return undefined for nonexistent resource", async () => {
|
|
125
|
-
const sdk = await
|
|
123
|
+
const sdk = await FhirBundleSdk.create(validCompleteBundle);
|
|
126
124
|
const result = sdk.getResourceById("nonexistent-id");
|
|
127
125
|
expect(result).toBeUndefined();
|
|
128
126
|
});
|
|
129
127
|
});
|
|
130
128
|
describe("FR-3.5: Lookup operates in O(1) time complexity", () => {
|
|
131
129
|
it("should perform lookup in O(1) time", async () => {
|
|
132
|
-
const sdk = await
|
|
130
|
+
const sdk = await FhirBundleSdk.create(validCompleteBundle);
|
|
133
131
|
const start = performance.now();
|
|
134
132
|
sdk.getResourceById("patient-123");
|
|
135
133
|
const end = performance.now();
|
|
136
134
|
// O(1) lookup should be very fast
|
|
137
|
-
expect(end - start).toBeLessThan(
|
|
135
|
+
expect(end - start).toBeLessThan(CONSTANT_TIME_EXPECTED_THRESHOLD_MS);
|
|
138
136
|
});
|
|
139
137
|
});
|
|
140
138
|
});
|
|
141
139
|
describe("Type-Specific Resource Getters", () => {
|
|
142
140
|
describe("FR-4.1: getPatients(): Patient[] returns all Patient resources", () => {
|
|
143
141
|
it("should return all patients", async () => {
|
|
144
|
-
const sdk = await
|
|
142
|
+
const sdk = await FhirBundleSdk.create(validCompleteBundle);
|
|
145
143
|
const patients = sdk.getPatients();
|
|
146
144
|
expect(Array.isArray(patients)).toBe(true);
|
|
147
145
|
expect(patients).toHaveLength(1);
|
|
@@ -150,7 +148,7 @@ describe("FhirBundleSdk", () => {
|
|
|
150
148
|
});
|
|
151
149
|
describe("FR-4.2: getObservations(): Observation[] returns all Observation resources", () => {
|
|
152
150
|
it("should return all observations", async () => {
|
|
153
|
-
const sdk = await
|
|
151
|
+
const sdk = await FhirBundleSdk.create(validCompleteBundle);
|
|
154
152
|
const observations = sdk.getObservations();
|
|
155
153
|
expect(Array.isArray(observations)).toBe(true);
|
|
156
154
|
expect(observations).toHaveLength(1);
|
|
@@ -159,7 +157,7 @@ describe("FhirBundleSdk", () => {
|
|
|
159
157
|
});
|
|
160
158
|
describe("FR-4.3: getEncounters(): Encounter[] returns all Encounter resources", () => {
|
|
161
159
|
it("should return all encounters", async () => {
|
|
162
|
-
const sdk = await
|
|
160
|
+
const sdk = await FhirBundleSdk.create(validCompleteBundle);
|
|
163
161
|
const encounters = sdk.getEncounters();
|
|
164
162
|
expect(Array.isArray(encounters)).toBe(true);
|
|
165
163
|
expect(encounters).toHaveLength(1);
|
|
@@ -168,7 +166,7 @@ describe("FhirBundleSdk", () => {
|
|
|
168
166
|
});
|
|
169
167
|
describe("FR-4.4: getPractitioners(): Practitioner[] returns all Practitioner resources", () => {
|
|
170
168
|
it("should return all practitioners", async () => {
|
|
171
|
-
const sdk = await
|
|
169
|
+
const sdk = await FhirBundleSdk.create(validCompleteBundle);
|
|
172
170
|
const practitioners = sdk.getPractitioners();
|
|
173
171
|
expect(Array.isArray(practitioners)).toBe(true);
|
|
174
172
|
expect(practitioners).toHaveLength(1);
|
|
@@ -177,7 +175,7 @@ describe("FhirBundleSdk", () => {
|
|
|
177
175
|
});
|
|
178
176
|
describe("FR-4.5: getDiagnosticReports(): DiagnosticReport[] returns all DiagnosticReport resources", () => {
|
|
179
177
|
it("should return all diagnostic reports", async () => {
|
|
180
|
-
const sdk = await
|
|
178
|
+
const sdk = await FhirBundleSdk.create(validCompleteBundle);
|
|
181
179
|
const reports = sdk.getDiagnosticReports();
|
|
182
180
|
expect(Array.isArray(reports)).toBe(true);
|
|
183
181
|
expect(reports).toHaveLength(1);
|
|
@@ -186,7 +184,7 @@ describe("FhirBundleSdk", () => {
|
|
|
186
184
|
});
|
|
187
185
|
describe("FR-4.6: All type-specific getters return empty array if no resources of that type exist", () => {
|
|
188
186
|
it("should return empty array when no resources exist", async () => {
|
|
189
|
-
const sdk = await
|
|
187
|
+
const sdk = await FhirBundleSdk.create(emptyBundle);
|
|
190
188
|
expect(sdk.getPatients()).toEqual([]);
|
|
191
189
|
expect(sdk.getObservations()).toEqual([]);
|
|
192
190
|
expect(sdk.getEncounters()).toEqual([]);
|
|
@@ -194,7 +192,7 @@ describe("FhirBundleSdk", () => {
|
|
|
194
192
|
expect(sdk.getDiagnosticReports()).toEqual([]);
|
|
195
193
|
});
|
|
196
194
|
it("should return empty array for missing resource types", async () => {
|
|
197
|
-
const sdk = await
|
|
195
|
+
const sdk = await FhirBundleSdk.create(patientsOnlyBundle);
|
|
198
196
|
expect(sdk.getPatients()).toHaveLength(3);
|
|
199
197
|
expect(sdk.getObservations()).toEqual([]);
|
|
200
198
|
expect(sdk.getEncounters()).toEqual([]);
|
|
@@ -204,7 +202,7 @@ describe("FhirBundleSdk", () => {
|
|
|
204
202
|
});
|
|
205
203
|
describe("FR-4.7: All methods use @medplum/fhirtypes for return type definitions", () => {
|
|
206
204
|
it("should return properly typed resources", async () => {
|
|
207
|
-
const sdk = await
|
|
205
|
+
const sdk = await FhirBundleSdk.create(validCompleteBundle);
|
|
208
206
|
const patients = sdk.getPatients();
|
|
209
207
|
const observations = sdk.getObservations();
|
|
210
208
|
const encounters = sdk.getEncounters();
|
|
@@ -222,7 +220,7 @@ describe("FhirBundleSdk", () => {
|
|
|
222
220
|
describe("Smart Reference Resolution", () => {
|
|
223
221
|
describe("FR-5.1: Resources returned by SDK have additional getter methods for each Reference field", () => {
|
|
224
222
|
it("should add getter methods for reference fields", async () => {
|
|
225
|
-
const sdk = await
|
|
223
|
+
const sdk = await FhirBundleSdk.create(validCompleteBundle);
|
|
226
224
|
const observations = sdk.getObservations();
|
|
227
225
|
const observation = observations[0];
|
|
228
226
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
@@ -235,7 +233,7 @@ describe("FhirBundleSdk", () => {
|
|
|
235
233
|
});
|
|
236
234
|
describe("FR-5.2: For Observation.subject reference, SDK adds getSubject() method", () => {
|
|
237
235
|
it("should resolve subject reference to Patient", async () => {
|
|
238
|
-
const sdk = await
|
|
236
|
+
const sdk = await FhirBundleSdk.create(validCompleteBundle);
|
|
239
237
|
const observations = sdk.getObservations();
|
|
240
238
|
const observation = observations[0];
|
|
241
239
|
const subject = observation?.getSubject();
|
|
@@ -246,7 +244,7 @@ describe("FhirBundleSdk", () => {
|
|
|
246
244
|
});
|
|
247
245
|
describe("FR-5.3: For Observation.encounter reference, SDK adds getEncounter() method", () => {
|
|
248
246
|
it("should resolve encounter reference to Encounter", async () => {
|
|
249
|
-
const sdk = await
|
|
247
|
+
const sdk = await FhirBundleSdk.create(validCompleteBundle);
|
|
250
248
|
const observations = sdk.getObservations();
|
|
251
249
|
const observation = observations[0];
|
|
252
250
|
const encounter = observation?.getEncounter();
|
|
@@ -257,7 +255,7 @@ describe("FhirBundleSdk", () => {
|
|
|
257
255
|
});
|
|
258
256
|
describe("FR-5.4: For Observation.performer reference array, SDK adds getPerformer() method", () => {
|
|
259
257
|
it("should resolve performer references to array of resources", async () => {
|
|
260
|
-
const sdk = await
|
|
258
|
+
const sdk = await FhirBundleSdk.create(validCompleteBundle);
|
|
261
259
|
const observations = sdk.getObservations();
|
|
262
260
|
const observation = observations[0];
|
|
263
261
|
const performers = observation?.getPerformers();
|
|
@@ -269,13 +267,13 @@ describe("FhirBundleSdk", () => {
|
|
|
269
267
|
});
|
|
270
268
|
describe("FR-5.5: Reference resolution methods handle both resource.id and fullUrl matching", () => {
|
|
271
269
|
it("should resolve references by resource.id", async () => {
|
|
272
|
-
const sdk = await
|
|
270
|
+
const sdk = await FhirBundleSdk.create(validCompleteBundle);
|
|
273
271
|
const observations = sdk.getObservations();
|
|
274
272
|
const subject = observations[0]?.getSubject();
|
|
275
273
|
expect(subject?.id).toBe("patient-123");
|
|
276
274
|
});
|
|
277
275
|
it("should resolve references by fullUrl", async () => {
|
|
278
|
-
const sdk = await
|
|
276
|
+
const sdk = await FhirBundleSdk.create(bundleWithFullUrlReferences);
|
|
279
277
|
const observations = sdk.getObservations();
|
|
280
278
|
const subject = observations[0]?.getSubject();
|
|
281
279
|
expect(subject?.id).toBe("patient-fullurl");
|
|
@@ -283,7 +281,7 @@ describe("FhirBundleSdk", () => {
|
|
|
283
281
|
});
|
|
284
282
|
describe("FR-5.6: Reference resolution methods return undefined for unresolvable references", () => {
|
|
285
283
|
it("should return undefined for broken references", async () => {
|
|
286
|
-
const sdk = await
|
|
284
|
+
const sdk = await FhirBundleSdk.create(bundleWithBrokenReferences);
|
|
287
285
|
const observations = sdk.getObservations();
|
|
288
286
|
const observation = observations[0];
|
|
289
287
|
expect(observation?.getSubject()).toBeUndefined();
|
|
@@ -293,19 +291,19 @@ describe("FhirBundleSdk", () => {
|
|
|
293
291
|
});
|
|
294
292
|
describe("FR-5.7: Reference resolution operates in O(1) time complexity per reference", () => {
|
|
295
293
|
it("should resolve references in O(1) time", async () => {
|
|
296
|
-
const sdk = await
|
|
294
|
+
const sdk = await FhirBundleSdk.create(validCompleteBundle);
|
|
297
295
|
const observations = sdk.getObservations();
|
|
298
296
|
const observation = observations[0];
|
|
299
297
|
const start = performance.now();
|
|
300
298
|
observation?.getSubject();
|
|
301
299
|
const end = performance.now();
|
|
302
300
|
// O(1) resolution should be very fast
|
|
303
|
-
expect(end - start).toBeLessThan(
|
|
301
|
+
expect(end - start).toBeLessThan(CONSTANT_TIME_EXPECTED_THRESHOLD_MS);
|
|
304
302
|
});
|
|
305
303
|
});
|
|
306
304
|
describe("FR-5.8: Original reference fields remain unchanged", () => {
|
|
307
305
|
it("should preserve original reference fields", async () => {
|
|
308
|
-
const sdk = await
|
|
306
|
+
const sdk = await FhirBundleSdk.create(validCompleteBundle);
|
|
309
307
|
const observations = sdk.getObservations();
|
|
310
308
|
const observation = observations[0];
|
|
311
309
|
expect(observation?.subject?.reference).toBe("Patient/patient-123");
|
|
@@ -317,7 +315,7 @@ describe("FhirBundleSdk", () => {
|
|
|
317
315
|
describe("Bundle Export Functionality", () => {
|
|
318
316
|
describe("FR-6.1: exportSubset(resourceIds: string[]): Bundle creates new bundle with specified resources", () => {
|
|
319
317
|
it("should export subset of resources by ID", async () => {
|
|
320
|
-
const sdk = await
|
|
318
|
+
const sdk = await FhirBundleSdk.create(validCompleteBundle);
|
|
321
319
|
const subset = sdk.exportSubset(["patient-123", "observation-001"]);
|
|
322
320
|
expect(subset.resourceType).toBe("Bundle");
|
|
323
321
|
expect(subset.type).toBe("collection");
|
|
@@ -327,7 +325,7 @@ describe("FhirBundleSdk", () => {
|
|
|
327
325
|
});
|
|
328
326
|
describe("FR-6.2: exportByType(resourceType: string): Bundle creates new bundle with all resources of specified type", () => {
|
|
329
327
|
it("should export all resources of specified type", async () => {
|
|
330
|
-
const sdk = await
|
|
328
|
+
const sdk = await FhirBundleSdk.create(mixedResourceTypesBundle);
|
|
331
329
|
const patientBundle = sdk.exportByType("Patient");
|
|
332
330
|
expect(patientBundle.resourceType).toBe("Bundle");
|
|
333
331
|
expect(patientBundle.type).toBe("collection");
|
|
@@ -340,7 +338,7 @@ describe("FhirBundleSdk", () => {
|
|
|
340
338
|
});
|
|
341
339
|
describe("FR-6.3: exportByTypes(resourceTypes: string[]): Bundle creates new bundle with all resources of specified types", () => {
|
|
342
340
|
it("should export all resources of specified types", async () => {
|
|
343
|
-
const sdk = await
|
|
341
|
+
const sdk = await FhirBundleSdk.create(mixedResourceTypesBundle);
|
|
344
342
|
const bundle = sdk.exportByTypes(["Patient", "Observation"]);
|
|
345
343
|
expect(bundle.resourceType).toBe("Bundle");
|
|
346
344
|
expect(bundle.type).toBe("collection");
|
|
@@ -350,7 +348,7 @@ describe("FhirBundleSdk", () => {
|
|
|
350
348
|
});
|
|
351
349
|
describe("FR-6.4: Exported bundles maintain original bundle metadata but update total count", () => {
|
|
352
350
|
it("should maintain metadata and update total", async () => {
|
|
353
|
-
const sdk = await
|
|
351
|
+
const sdk = await FhirBundleSdk.create(validCompleteBundle);
|
|
354
352
|
const subset = sdk.exportSubset(["patient-123"]);
|
|
355
353
|
expect(subset.resourceType).toBe("Bundle");
|
|
356
354
|
expect(subset.type).toBe("collection");
|
|
@@ -360,7 +358,7 @@ describe("FhirBundleSdk", () => {
|
|
|
360
358
|
});
|
|
361
359
|
describe("FR-6.5: Exported bundles include only resources that exist in the original bundle", () => {
|
|
362
360
|
it("should ignore nonexistent resource IDs", async () => {
|
|
363
|
-
const sdk = await
|
|
361
|
+
const sdk = await FhirBundleSdk.create(validCompleteBundle);
|
|
364
362
|
const subset = sdk.exportSubset(["patient-123", "nonexistent-id"]);
|
|
365
363
|
expect(subset.entry).toHaveLength(1);
|
|
366
364
|
expect(subset.total).toBe(1);
|
|
@@ -368,7 +366,7 @@ describe("FhirBundleSdk", () => {
|
|
|
368
366
|
});
|
|
369
367
|
describe("FR-6.6: Exported bundles preserve original entry.fullUrl values", () => {
|
|
370
368
|
it("should preserve fullUrl values", async () => {
|
|
371
|
-
const sdk = await
|
|
369
|
+
const sdk = await FhirBundleSdk.create(validCompleteBundle);
|
|
372
370
|
const subset = sdk.exportSubset(["patient-123"]);
|
|
373
371
|
expect(subset.entry?.[0]?.fullUrl).toBe("urn:uuid:patient-123");
|
|
374
372
|
});
|
|
@@ -377,7 +375,7 @@ describe("FhirBundleSdk", () => {
|
|
|
377
375
|
describe("Error Handling", () => {
|
|
378
376
|
describe("FR-7.1: All methods handle malformed resource references gracefully", () => {
|
|
379
377
|
it("should handle malformed references without throwing", async () => {
|
|
380
|
-
const sdk = await
|
|
378
|
+
const sdk = await FhirBundleSdk.create(bundleWithBrokenReferences);
|
|
381
379
|
expect(() => {
|
|
382
380
|
const observations = sdk.getObservations();
|
|
383
381
|
observations[0]?.getSubject();
|
|
@@ -386,12 +384,12 @@ describe("FhirBundleSdk", () => {
|
|
|
386
384
|
});
|
|
387
385
|
describe("FR-7.2: SDK throws descriptive errors for invalid bundle structure during initialization", () => {
|
|
388
386
|
it("should throw descriptive error for invalid bundle", async () => {
|
|
389
|
-
await expect(
|
|
387
|
+
await expect(FhirBundleSdk.create(invalidBundleWrongType)).rejects.toThrow("Invalid bundle: resourceType must be 'Bundle'");
|
|
390
388
|
});
|
|
391
389
|
});
|
|
392
390
|
describe("FR-7.3: Reference resolution methods never throw errors, only return undefined for invalid references", () => {
|
|
393
391
|
it("should return undefined instead of throwing for invalid references", async () => {
|
|
394
|
-
const sdk = await
|
|
392
|
+
const sdk = await FhirBundleSdk.create(bundleWithBrokenReferences);
|
|
395
393
|
const observations = sdk.getObservations();
|
|
396
394
|
expect(() => observations[0]?.getSubject()).not.toThrow();
|
|
397
395
|
expect(observations[0]?.getSubject()).toBeUndefined();
|
|
@@ -401,38 +399,38 @@ describe("FhirBundleSdk", () => {
|
|
|
401
399
|
describe("Performance Requirements", () => {
|
|
402
400
|
describe("FR-9.1: Resource lookup by ID completes in O(1) time", () => {
|
|
403
401
|
it("should perform ID lookup in O(1) time", async () => {
|
|
404
|
-
const sdk = await
|
|
402
|
+
const sdk = await FhirBundleSdk.create(validCompleteBundle);
|
|
405
403
|
const start = performance.now();
|
|
406
404
|
sdk.getResourceById("patient-123");
|
|
407
405
|
const end = performance.now();
|
|
408
|
-
expect(end - start).toBeLessThan(
|
|
406
|
+
expect(end - start).toBeLessThan(CONSTANT_TIME_EXPECTED_THRESHOLD_MS);
|
|
409
407
|
});
|
|
410
408
|
});
|
|
411
409
|
describe("FR-9.2: Type-specific getters complete in O(n) time where n is number of resources of that type", () => {
|
|
412
410
|
it("should perform type-specific queries efficiently", async () => {
|
|
413
|
-
const sdk = await
|
|
411
|
+
const sdk = await FhirBundleSdk.create(mixedResourceTypesBundle);
|
|
414
412
|
const start = performance.now();
|
|
415
413
|
const patients = sdk.getPatients();
|
|
416
414
|
const end = performance.now();
|
|
417
415
|
expect(patients).toHaveLength(2);
|
|
418
|
-
expect(end - start).toBeLessThan(
|
|
416
|
+
expect(end - start).toBeLessThan(CONSTANT_TIME_EXPECTED_THRESHOLD_MS * 2); // Should be fast for small bundles
|
|
419
417
|
});
|
|
420
418
|
});
|
|
421
419
|
describe("FR-9.4: Reference resolution per reference completes in O(1) time", () => {
|
|
422
420
|
it("should resolve references in O(1) time", async () => {
|
|
423
|
-
const sdk = await
|
|
421
|
+
const sdk = await FhirBundleSdk.create(validCompleteBundle);
|
|
424
422
|
const observations = sdk.getObservations();
|
|
425
423
|
const start = performance.now();
|
|
426
424
|
observations[0]?.getSubject();
|
|
427
425
|
const end = performance.now();
|
|
428
|
-
expect(end - start).toBeLessThan(
|
|
426
|
+
expect(end - start).toBeLessThan(CONSTANT_TIME_EXPECTED_THRESHOLD_MS);
|
|
429
427
|
});
|
|
430
428
|
});
|
|
431
429
|
});
|
|
432
430
|
describe("Reference Walking (BFS)", () => {
|
|
433
431
|
describe("Basic single-level traversal", () => {
|
|
434
432
|
it("should walk references from an Observation to related resources", async () => {
|
|
435
|
-
const sdk = await
|
|
433
|
+
const sdk = await FhirBundleSdk.create(validCompleteBundle);
|
|
436
434
|
const observation = sdk.getObservationById("observation-001");
|
|
437
435
|
if (observation === undefined) {
|
|
438
436
|
throw new Error("Observation not found");
|
|
@@ -453,7 +451,7 @@ describe("FhirBundleSdk", () => {
|
|
|
453
451
|
expect(resourceIds).toContain("practitioner-456"); // performer
|
|
454
452
|
});
|
|
455
453
|
it("should organize resources by depth level", async () => {
|
|
456
|
-
const sdk = await
|
|
454
|
+
const sdk = await FhirBundleSdk.create(validCompleteBundle);
|
|
457
455
|
const observation = sdk.getObservationById("observation-001");
|
|
458
456
|
if (observation === undefined) {
|
|
459
457
|
throw new Error("Observation not found");
|
|
@@ -476,7 +474,7 @@ describe("FhirBundleSdk", () => {
|
|
|
476
474
|
expect(depth1.length).toBeGreaterThan(0);
|
|
477
475
|
});
|
|
478
476
|
it("should report the depth reached", async () => {
|
|
479
|
-
const sdk = await
|
|
477
|
+
const sdk = await FhirBundleSdk.create(validCompleteBundle);
|
|
480
478
|
const observation = sdk.getObservationById("observation-001");
|
|
481
479
|
if (observation === undefined) {
|
|
482
480
|
throw new Error("Observation not found");
|
|
@@ -488,7 +486,7 @@ describe("FhirBundleSdk", () => {
|
|
|
488
486
|
});
|
|
489
487
|
describe("Multi-level traversal", () => {
|
|
490
488
|
it("should traverse multiple levels from DiagnosticReport", async () => {
|
|
491
|
-
const sdk = await
|
|
489
|
+
const sdk = await FhirBundleSdk.create(validCompleteBundle);
|
|
492
490
|
const diagnosticReport = sdk.getDiagnosticReportById("diagnostic-report-002");
|
|
493
491
|
if (diagnosticReport === undefined) {
|
|
494
492
|
throw new Error("DiagnosticReport not found");
|
|
@@ -504,7 +502,7 @@ describe("FhirBundleSdk", () => {
|
|
|
504
502
|
});
|
|
505
503
|
describe("Include start resource option", () => {
|
|
506
504
|
it("should include start resource by default", async () => {
|
|
507
|
-
const sdk = await
|
|
505
|
+
const sdk = await FhirBundleSdk.create(validCompleteBundle);
|
|
508
506
|
const observation = sdk.getObservationById("observation-001");
|
|
509
507
|
if (observation === undefined) {
|
|
510
508
|
throw new Error("Observation not found");
|
|
@@ -513,7 +511,7 @@ describe("FhirBundleSdk", () => {
|
|
|
513
511
|
expect(result.allResources.map(r => r.id)).toContain("observation-001");
|
|
514
512
|
});
|
|
515
513
|
it("should exclude start resource when includeStartResource is false", async () => {
|
|
516
|
-
const sdk = await
|
|
514
|
+
const sdk = await FhirBundleSdk.create(validCompleteBundle);
|
|
517
515
|
const observation = sdk.getObservationById("observation-001");
|
|
518
516
|
if (observation === undefined) {
|
|
519
517
|
throw new Error("Observation not found");
|
|
@@ -526,7 +524,7 @@ describe("FhirBundleSdk", () => {
|
|
|
526
524
|
});
|
|
527
525
|
describe("Max depth limiting", () => {
|
|
528
526
|
it("should respect maxDepth of 0 (only start resource)", async () => {
|
|
529
|
-
const sdk = await
|
|
527
|
+
const sdk = await FhirBundleSdk.create(validCompleteBundle);
|
|
530
528
|
const observation = sdk.getObservationById("observation-001");
|
|
531
529
|
if (observation === undefined) {
|
|
532
530
|
throw new Error("Observation not found");
|
|
@@ -540,7 +538,7 @@ describe("FhirBundleSdk", () => {
|
|
|
540
538
|
expect(result.resourcesByDepth.size).toBe(1);
|
|
541
539
|
});
|
|
542
540
|
it("should respect maxDepth of 1 (start + direct references)", async () => {
|
|
543
|
-
const sdk = await
|
|
541
|
+
const sdk = await FhirBundleSdk.create(validCompleteBundle);
|
|
544
542
|
const observation = sdk.getObservationById("observation-001");
|
|
545
543
|
if (observation === undefined) {
|
|
546
544
|
throw new Error("Observation not found");
|
|
@@ -557,7 +555,7 @@ describe("FhirBundleSdk", () => {
|
|
|
557
555
|
expect(result.resourcesByDepth.has(2)).toBe(false);
|
|
558
556
|
});
|
|
559
557
|
it("should respect maxDepth of 2 from DiagnosticReport", async () => {
|
|
560
|
-
const sdk = await
|
|
558
|
+
const sdk = await FhirBundleSdk.create(validCompleteBundle);
|
|
561
559
|
const diagnosticReport = sdk.getDiagnosticReportById("diagnostic-report-002");
|
|
562
560
|
if (diagnosticReport === undefined) {
|
|
563
561
|
throw new Error("DiagnosticReport not found");
|
|
@@ -577,7 +575,7 @@ describe("FhirBundleSdk", () => {
|
|
|
577
575
|
expect(allResourceIds).toContain("patient-123");
|
|
578
576
|
});
|
|
579
577
|
it("should handle Infinity maxDepth (default)", async () => {
|
|
580
|
-
const sdk = await
|
|
578
|
+
const sdk = await FhirBundleSdk.create(validCompleteBundle);
|
|
581
579
|
const observation = sdk.getObservationById("observation-001");
|
|
582
580
|
if (observation === undefined) {
|
|
583
581
|
throw new Error("Observation not found");
|
|
@@ -612,7 +610,7 @@ describe("FhirBundleSdk", () => {
|
|
|
612
610
|
},
|
|
613
611
|
],
|
|
614
612
|
};
|
|
615
|
-
const sdk = await
|
|
613
|
+
const sdk = await FhirBundleSdk.create(circularBundle);
|
|
616
614
|
const org1 = sdk.getOrganizationById("org-1");
|
|
617
615
|
// Should complete without hanging
|
|
618
616
|
if (org1 === undefined) {
|
|
@@ -628,7 +626,7 @@ describe("FhirBundleSdk", () => {
|
|
|
628
626
|
});
|
|
629
627
|
describe("Array reference handling", () => {
|
|
630
628
|
it("should handle array references correctly", async () => {
|
|
631
|
-
const sdk = await
|
|
629
|
+
const sdk = await FhirBundleSdk.create(validCompleteBundle);
|
|
632
630
|
const observation = sdk.getObservationById("observation-001");
|
|
633
631
|
if (observation === undefined) {
|
|
634
632
|
throw new Error("Observation not found");
|
|
@@ -639,7 +637,7 @@ describe("FhirBundleSdk", () => {
|
|
|
639
637
|
expect(result.allResources.map(r => r.id)).toContain(practitionerId);
|
|
640
638
|
});
|
|
641
639
|
it("should handle DiagnosticReport result array", async () => {
|
|
642
|
-
const sdk = await
|
|
640
|
+
const sdk = await FhirBundleSdk.create(validCompleteBundle);
|
|
643
641
|
const diagnosticReport = sdk.getDiagnosticReportById("diagnostic-report-002");
|
|
644
642
|
if (diagnosticReport === undefined) {
|
|
645
643
|
throw new Error("DiagnosticReport not found");
|
|
@@ -664,7 +662,7 @@ describe("FhirBundleSdk", () => {
|
|
|
664
662
|
},
|
|
665
663
|
],
|
|
666
664
|
};
|
|
667
|
-
const sdk = await
|
|
665
|
+
const sdk = await FhirBundleSdk.create(bundleWithIsolatedPatient);
|
|
668
666
|
const patient = sdk.getPatientById("patient-isolated");
|
|
669
667
|
if (patient === undefined) {
|
|
670
668
|
throw new Error("Patient not found");
|
|
@@ -675,7 +673,7 @@ describe("FhirBundleSdk", () => {
|
|
|
675
673
|
expect(result.allResources[0]?.id).toBe("patient-isolated");
|
|
676
674
|
});
|
|
677
675
|
it("should handle resources with broken references", async () => {
|
|
678
|
-
const sdk = await
|
|
676
|
+
const sdk = await FhirBundleSdk.create(bundleWithBrokenReferences);
|
|
679
677
|
const observation = sdk.getObservationById("observation-broken");
|
|
680
678
|
// Should not throw, just return what's reachable
|
|
681
679
|
if (observation === undefined) {
|
|
@@ -686,7 +684,7 @@ describe("FhirBundleSdk", () => {
|
|
|
686
684
|
expect(result.startResource.id).toBe("observation-broken");
|
|
687
685
|
});
|
|
688
686
|
it("should handle empty options", async () => {
|
|
689
|
-
const sdk = await
|
|
687
|
+
const sdk = await FhirBundleSdk.create(validCompleteBundle);
|
|
690
688
|
const observation = sdk.getObservationById("observation-001");
|
|
691
689
|
if (observation === undefined) {
|
|
692
690
|
throw new Error("Observation not found");
|
|
@@ -710,7 +708,7 @@ describe("FhirBundleSdk", () => {
|
|
|
710
708
|
},
|
|
711
709
|
name: [{ family: "Smith", given: ["John"] }],
|
|
712
710
|
};
|
|
713
|
-
const cleaned =
|
|
711
|
+
const cleaned = FhirBundleSdk.stripNonClinicalData(patient);
|
|
714
712
|
expect(cleaned.meta).toBeUndefined();
|
|
715
713
|
expect(cleaned.name).toEqual([{ family: "Smith", given: ["John"] }]);
|
|
716
714
|
expect(cleaned.id).toBeUndefined();
|
|
@@ -727,7 +725,7 @@ describe("FhirBundleSdk", () => {
|
|
|
727
725
|
],
|
|
728
726
|
name: [{ family: "Smith", given: ["John"] }],
|
|
729
727
|
};
|
|
730
|
-
const cleaned =
|
|
728
|
+
const cleaned = FhirBundleSdk.stripNonClinicalData(patient);
|
|
731
729
|
expect(cleaned.extension).toBeUndefined();
|
|
732
730
|
expect(cleaned.name).toEqual([{ family: "Smith", given: ["John"] }]);
|
|
733
731
|
});
|
|
@@ -744,7 +742,7 @@ describe("FhirBundleSdk", () => {
|
|
|
744
742
|
div: "<div>Some narrative</div>",
|
|
745
743
|
},
|
|
746
744
|
};
|
|
747
|
-
const cleaned =
|
|
745
|
+
const cleaned = FhirBundleSdk.stripNonClinicalData(observation);
|
|
748
746
|
expect(cleaned.text).toBeUndefined();
|
|
749
747
|
expect(cleaned.code).toBeDefined();
|
|
750
748
|
expect(cleaned.status).toBe("final");
|
|
@@ -758,7 +756,7 @@ describe("FhirBundleSdk", () => {
|
|
|
758
756
|
},
|
|
759
757
|
name: [{ family: "Smith", given: ["John"] }],
|
|
760
758
|
};
|
|
761
|
-
const cleaned =
|
|
759
|
+
const cleaned = FhirBundleSdk.stripNonClinicalData(patient);
|
|
762
760
|
// Original should be unchanged
|
|
763
761
|
expect(patient.meta).toBeDefined();
|
|
764
762
|
expect(patient.id).toBe("patient-123");
|
|
@@ -783,7 +781,7 @@ describe("FhirBundleSdk", () => {
|
|
|
783
781
|
},
|
|
784
782
|
],
|
|
785
783
|
};
|
|
786
|
-
const cleaned =
|
|
784
|
+
const cleaned = FhirBundleSdk.stripNonClinicalData(patient);
|
|
787
785
|
expect(cleaned.name?.[0]?.extension).toBeUndefined();
|
|
788
786
|
expect(cleaned.name?.[0]?.family).toBe("Smith");
|
|
789
787
|
});
|
|
@@ -793,7 +791,7 @@ describe("FhirBundleSdk", () => {
|
|
|
793
791
|
id: "patient-123",
|
|
794
792
|
name: [{ family: "Smith", given: ["John"] }],
|
|
795
793
|
};
|
|
796
|
-
const cleaned =
|
|
794
|
+
const cleaned = FhirBundleSdk.stripNonClinicalData(patient);
|
|
797
795
|
expect(cleaned.id).toBeUndefined();
|
|
798
796
|
expect(cleaned.name).toEqual([{ family: "Smith", given: ["John"] }]);
|
|
799
797
|
});
|
|
@@ -809,7 +807,7 @@ describe("FhirBundleSdk", () => {
|
|
|
809
807
|
],
|
|
810
808
|
name: [{ family: "Smith", given: ["John"] }],
|
|
811
809
|
};
|
|
812
|
-
const cleaned =
|
|
810
|
+
const cleaned = FhirBundleSdk.stripNonClinicalData(patient);
|
|
813
811
|
expect(cleaned.identifier).toBeUndefined();
|
|
814
812
|
expect(cleaned.name).toEqual([{ family: "Smith", given: ["John"] }]);
|
|
815
813
|
});
|
|
@@ -826,7 +824,7 @@ describe("FhirBundleSdk", () => {
|
|
|
826
824
|
performer: [{ reference: "Practitioner/practitioner-789" }],
|
|
827
825
|
basedOn: [{ reference: "ServiceRequest/sr-001" }],
|
|
828
826
|
};
|
|
829
|
-
const cleaned =
|
|
827
|
+
const cleaned = FhirBundleSdk.stripNonClinicalData(observation);
|
|
830
828
|
// All reference fields should be removed
|
|
831
829
|
expect(cleaned.subject).toBeUndefined();
|
|
832
830
|
expect(cleaned.encounter).toBeUndefined();
|
|
@@ -839,7 +837,7 @@ describe("FhirBundleSdk", () => {
|
|
|
839
837
|
});
|
|
840
838
|
describe("generateLLMContext", () => {
|
|
841
839
|
it("should generate structured text format by default", async () => {
|
|
842
|
-
const sdk = await
|
|
840
|
+
const sdk = await FhirBundleSdk.create(validCompleteBundle);
|
|
843
841
|
const observation = sdk.getObservationById("observation-001");
|
|
844
842
|
if (observation === undefined) {
|
|
845
843
|
throw new Error("Observation not found");
|
|
@@ -850,7 +848,7 @@ describe("FhirBundleSdk", () => {
|
|
|
850
848
|
expect(context).toContain("DIRECTLY REFERENCED");
|
|
851
849
|
});
|
|
852
850
|
it("should respect maxDepth option", async () => {
|
|
853
|
-
const sdk = await
|
|
851
|
+
const sdk = await FhirBundleSdk.create(validCompleteBundle);
|
|
854
852
|
const observation = sdk.getObservationById("observation-001");
|
|
855
853
|
if (observation === undefined) {
|
|
856
854
|
throw new Error("Observation not found");
|
|
@@ -860,7 +858,7 @@ describe("FhirBundleSdk", () => {
|
|
|
860
858
|
expect(context).not.toContain("DIRECTLY REFERENCED");
|
|
861
859
|
});
|
|
862
860
|
it("should generate JSON format when specified", async () => {
|
|
863
|
-
const sdk = await
|
|
861
|
+
const sdk = await FhirBundleSdk.create(validCompleteBundle);
|
|
864
862
|
const observation = sdk.getObservationById("observation-001");
|
|
865
863
|
if (observation === undefined) {
|
|
866
864
|
throw new Error("Observation not found");
|
|
@@ -897,7 +895,7 @@ describe("FhirBundleSdk", () => {
|
|
|
897
895
|
},
|
|
898
896
|
],
|
|
899
897
|
};
|
|
900
|
-
const sdk = await
|
|
898
|
+
const sdk = await FhirBundleSdk.create(bundleWithMeta);
|
|
901
899
|
const observation = sdk.getObservationById("obs-with-meta");
|
|
902
900
|
if (observation === undefined) {
|
|
903
901
|
throw new Error("Observation not found");
|
|
@@ -909,7 +907,7 @@ describe("FhirBundleSdk", () => {
|
|
|
909
907
|
expect(parsed.primaryResource.code).toBeDefined();
|
|
910
908
|
});
|
|
911
909
|
it("should group resources by type at each depth", async () => {
|
|
912
|
-
const sdk = await
|
|
910
|
+
const sdk = await FhirBundleSdk.create(validCompleteBundle);
|
|
913
911
|
const diagnosticReport = sdk.getDiagnosticReportById("diagnostic-report-002");
|
|
914
912
|
if (diagnosticReport === undefined) {
|
|
915
913
|
throw new Error("DiagnosticReport not found");
|
|
@@ -920,7 +918,7 @@ describe("FhirBundleSdk", () => {
|
|
|
920
918
|
expect(context).toMatch(/--- \w+ \(\d+\) ---/);
|
|
921
919
|
});
|
|
922
920
|
it("should handle includeStartResource option", async () => {
|
|
923
|
-
const sdk = await
|
|
921
|
+
const sdk = await FhirBundleSdk.create(validCompleteBundle);
|
|
924
922
|
const observation = sdk.getObservationById("observation-001");
|
|
925
923
|
if (observation === undefined) {
|
|
926
924
|
throw new Error("Observation not found");
|
|
@@ -937,7 +935,7 @@ describe("FhirBundleSdk", () => {
|
|
|
937
935
|
});
|
|
938
936
|
it("should log resource counts to console", async () => {
|
|
939
937
|
const consoleSpy = jest.spyOn(console, "log").mockImplementation();
|
|
940
|
-
const sdk = await
|
|
938
|
+
const sdk = await FhirBundleSdk.create(validCompleteBundle);
|
|
941
939
|
const observation = sdk.getObservationById("observation-001");
|
|
942
940
|
if (observation === undefined) {
|
|
943
941
|
throw new Error("Observation not found");
|