@metriport/fhir-sdk 1.2.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.
- package/LICENSE +21 -0
- package/README.md +124 -0
- package/dist/__tests__/env-setup.d.ts +2 -0
- package/dist/__tests__/env-setup.d.ts.map +1 -0
- package/dist/__tests__/env-setup.js +37 -0
- package/dist/__tests__/env-setup.js.map +1 -0
- package/dist/__tests__/fhir-bundle-sdk-basic.test.d.ts +2 -0
- package/dist/__tests__/fhir-bundle-sdk-basic.test.d.ts.map +1 -0
- package/dist/__tests__/fhir-bundle-sdk-basic.test.js +19 -0
- package/dist/__tests__/fhir-bundle-sdk-basic.test.js.map +1 -0
- package/dist/__tests__/fhir-bundle-sdk.test.d.ts +2 -0
- package/dist/__tests__/fhir-bundle-sdk.test.d.ts.map +1 -0
- package/dist/__tests__/fhir-bundle-sdk.test.js +433 -0
- package/dist/__tests__/fhir-bundle-sdk.test.js.map +1 -0
- package/dist/__tests__/fixtures/fhir-bundles.d.ts +31 -0
- package/dist/__tests__/fixtures/fhir-bundles.d.ts.map +1 -0
- package/dist/__tests__/fixtures/fhir-bundles.js +369 -0
- package/dist/__tests__/fixtures/fhir-bundles.js.map +1 -0
- package/dist/__tests__/phase1-verification.test.d.ts +2 -0
- package/dist/__tests__/phase1-verification.test.d.ts.map +1 -0
- package/dist/__tests__/phase1-verification.test.js +141 -0
- package/dist/__tests__/phase1-verification.test.js.map +1 -0
- package/dist/__tests__/phase2-verification.test.d.ts +2 -0
- package/dist/__tests__/phase2-verification.test.d.ts.map +1 -0
- package/dist/__tests__/phase2-verification.test.js +234 -0
- package/dist/__tests__/phase2-verification.test.js.map +1 -0
- package/dist/__tests__/phase3-verification.test.d.ts +2 -0
- package/dist/__tests__/phase3-verification.test.d.ts.map +1 -0
- package/dist/__tests__/phase3-verification.test.js +121 -0
- package/dist/__tests__/phase3-verification.test.js.map +1 -0
- package/dist/__tests__/phase4-verification.test.d.ts +2 -0
- package/dist/__tests__/phase4-verification.test.d.ts.map +1 -0
- package/dist/__tests__/phase4-verification.test.js +168 -0
- package/dist/__tests__/phase4-verification.test.js.map +1 -0
- package/dist/__tests__/phase5-verification.test.d.ts +2 -0
- package/dist/__tests__/phase5-verification.test.d.ts.map +1 -0
- package/dist/__tests__/phase5-verification.test.js +200 -0
- package/dist/__tests__/phase5-verification.test.js.map +1 -0
- package/dist/index.d.ts +245 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +681 -0
- package/dist/index.js.map +1 -0
- package/dist/types/smart-resources.d.ts +219 -0
- package/dist/types/smart-resources.d.ts.map +1 -0
- package/dist/types/smart-resources.js +140 -0
- package/dist/types/smart-resources.js.map +1 -0
- package/package.json +69 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 Metriport Inc.
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
# @metriport/fhir-sdk
|
|
2
|
+
|
|
3
|
+
TypeScript SDK for parsing, querying, and manipulating FHIR R4 bundles with smart reference resolution.
|
|
4
|
+
|
|
5
|
+
## Quick Start
|
|
6
|
+
|
|
7
|
+
```typescript
|
|
8
|
+
import { FhirBundleSdk } from "@metriport/fhir-sdk";
|
|
9
|
+
|
|
10
|
+
const sdk = await FhirBundleSdk.create(fhirBundle);
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## Core Functionality
|
|
14
|
+
|
|
15
|
+
### 1. Resource Retrieval
|
|
16
|
+
|
|
17
|
+
#### By ID
|
|
18
|
+
|
|
19
|
+
```typescript
|
|
20
|
+
// Generic
|
|
21
|
+
const resource = sdk.getResourceById<Patient>("patient-123");
|
|
22
|
+
|
|
23
|
+
// Type-specific
|
|
24
|
+
const patient = sdk.getPatientById("patient-123");
|
|
25
|
+
const observation = sdk.getObservationById("obs-456");
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
#### By Type
|
|
29
|
+
|
|
30
|
+
```typescript
|
|
31
|
+
const patients = sdk.getPatients();
|
|
32
|
+
const observations = sdk.getObservations();
|
|
33
|
+
const encounters = sdk.getEncounters();
|
|
34
|
+
const conditions = sdk.getConditions();
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
### 2. Smart Reference Resolution
|
|
38
|
+
|
|
39
|
+
Resources include typed getter methods for convenient and type-safe reference traversal:
|
|
40
|
+
|
|
41
|
+
```typescript
|
|
42
|
+
const observation = sdk.getObservationById("obs-123");
|
|
43
|
+
|
|
44
|
+
// Direct access to referenced resources
|
|
45
|
+
const patient = observation.getSubject<Patient>();
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
### 3. Bundle Export
|
|
49
|
+
|
|
50
|
+
You can export subsets of your bundle or export by resource type to quickly create custom bundles.
|
|
51
|
+
|
|
52
|
+
```typescript
|
|
53
|
+
// Export by resource IDs - great for diff bundles!
|
|
54
|
+
const subset = sdk.exportSubset(["patient-uuid-1", "obs-uuid-1"]);
|
|
55
|
+
|
|
56
|
+
// Export by resource type - great for resource type bundles!
|
|
57
|
+
const observationBundle = sdk.exportByType("Observation");
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
### 4. Validation
|
|
61
|
+
|
|
62
|
+
Validate your bundle to ensure there are no broken references. A broken reference is a reference that points to a resource that does not exist in the bundle.
|
|
63
|
+
|
|
64
|
+
```typescript
|
|
65
|
+
const result = sdk.lookForBrokenReferences();
|
|
66
|
+
console.log(result.hasBrokenReferences); // true if at least one broken reference is found, false otherwise
|
|
67
|
+
console.log(result.brokenReferences); // All broken references in bundle
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
## Example Use Cases
|
|
71
|
+
|
|
72
|
+
### Patient Summary
|
|
73
|
+
|
|
74
|
+
```typescript
|
|
75
|
+
const buildPatientSummary = (patientId: string) => {
|
|
76
|
+
const patient = sdk.getPatientById(patientId);
|
|
77
|
+
const observations = sdk.getObservations().filter(obs => obs.getSubject()?.id === patientId);
|
|
78
|
+
|
|
79
|
+
return {
|
|
80
|
+
name: patient?.name?.[0]?.family,
|
|
81
|
+
observationCount: observations.length,
|
|
82
|
+
recentObs: observations.slice(0, 5),
|
|
83
|
+
};
|
|
84
|
+
};
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
### Reference Traversal
|
|
88
|
+
|
|
89
|
+
```typescript
|
|
90
|
+
// Traverse multiple references in sequence
|
|
91
|
+
const orgName = sdk.getPatients()[0]?.getManagingOrganization()?.name;
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
### Example Use Case: Processing a bundle
|
|
95
|
+
|
|
96
|
+
```typescript
|
|
97
|
+
const processBundle = async (bundle: Bundle) => {
|
|
98
|
+
const sdk = await FhirBundleSdk.create(bundle);
|
|
99
|
+
|
|
100
|
+
const { hasBrokenReferences, brokenReferences } = sdk.lookForBrokenReferences();
|
|
101
|
+
|
|
102
|
+
if (hasBrokenReferences) {
|
|
103
|
+
throw new MetriportError("Broken references found in bundle", {
|
|
104
|
+
brokenReferences,
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
// Process
|
|
109
|
+
const patients = sdk.getPatients();
|
|
110
|
+
const summaries = patients.map(p => ({
|
|
111
|
+
id: p.id,
|
|
112
|
+
name: p.name?.[0]?.family,
|
|
113
|
+
obsCount: sdk.getObservations().filter(obs => obs.getSubject()?.id === p.id).length,
|
|
114
|
+
}));
|
|
115
|
+
|
|
116
|
+
return summaries;
|
|
117
|
+
};
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
## Performance
|
|
121
|
+
|
|
122
|
+
- **getById**: O(1) lookup
|
|
123
|
+
- **getByType**: O(n) where n = resources of that type
|
|
124
|
+
- **Reference resolution**: O(1) traversal
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"env-setup.d.ts","sourceRoot":"","sources":["../../src/__tests__/env-setup.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,37 @@
|
|
|
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 __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
26
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
|
+
};
|
|
28
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
+
const dotenv = __importStar(require("dotenv"));
|
|
30
|
+
const path_1 = __importDefault(require("path"));
|
|
31
|
+
const cwd = process.cwd();
|
|
32
|
+
const paths = [cwd, ...(cwd.includes("packages") ? [] : ["packages", "fhir-sdk"])];
|
|
33
|
+
// regular config so it can load .env if present
|
|
34
|
+
dotenv.config({ path: path_1.default.resolve(...paths, ".env") });
|
|
35
|
+
dotenv.config({ path: path_1.default.resolve(...paths, ".env.test") });
|
|
36
|
+
// Keep dotenv import and config before everything else
|
|
37
|
+
//# sourceMappingURL=env-setup.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"env-setup.js","sourceRoot":"","sources":["../../src/__tests__/env-setup.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,+CAAiC;AACjC,gDAAwB;AACxB,MAAM,GAAG,GAAG,OAAO,CAAC,GAAG,EAAE,CAAC;AAC1B,MAAM,KAAK,GAAG,CAAC,GAAG,EAAE,GAAG,CAAC,GAAG,CAAC,QAAQ,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,UAAU,EAAE,UAAU,CAAC,CAAC,CAAC,CAAC;AACnF,gDAAgD;AAChD,MAAM,CAAC,MAAM,CAAC,EAAE,IAAI,EAAE,cAAI,CAAC,OAAO,CAAC,GAAG,KAAK,EAAE,MAAM,CAAC,EAAE,CAAC,CAAC;AACxD,MAAM,CAAC,MAAM,CAAC,EAAE,IAAI,EAAE,cAAI,CAAC,OAAO,CAAC,GAAG,KAAK,EAAE,WAAW,CAAC,EAAE,CAAC,CAAC;AAC7D,uDAAuD"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fhir-bundle-sdk-basic.test.d.ts","sourceRoot":"","sources":["../../src/__tests__/fhir-bundle-sdk-basic.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const index_1 = require("../index");
|
|
4
|
+
const fhir_bundles_1 = require("./fixtures/fhir-bundles");
|
|
5
|
+
describe("FhirBundleSdk - Basic TDD Tests", () => {
|
|
6
|
+
describe("Bundle Loading and Initialization", () => {
|
|
7
|
+
describe("FR-1.1: SDK constructor accepts a FHIR Bundle object", () => {
|
|
8
|
+
it("should accept a valid FHIR bundle without throwing", async () => {
|
|
9
|
+
await expect(index_1.FhirBundleSdk.create(fhir_bundles_1.validCompleteBundle)).resolves.not.toThrow();
|
|
10
|
+
});
|
|
11
|
+
});
|
|
12
|
+
describe("FR-1.2: SDK constructor throws error if bundle.resourceType !== 'Bundle'", () => {
|
|
13
|
+
it("should throw error for invalid resourceType", async () => {
|
|
14
|
+
await expect(index_1.FhirBundleSdk.create(fhir_bundles_1.invalidBundleWrongType)).rejects.toThrow("Invalid bundle: resourceType must be 'Bundle'");
|
|
15
|
+
});
|
|
16
|
+
});
|
|
17
|
+
});
|
|
18
|
+
});
|
|
19
|
+
//# sourceMappingURL=fhir-bundle-sdk-basic.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fhir-bundle-sdk-basic.test.js","sourceRoot":"","sources":["../../src/__tests__/fhir-bundle-sdk-basic.test.ts"],"names":[],"mappings":";;AAAA,oCAAyC;AACzC,0DAAsF;AAEtF,QAAQ,CAAC,iCAAiC,EAAE,GAAG,EAAE;IAC/C,QAAQ,CAAC,mCAAmC,EAAE,GAAG,EAAE;QACjD,QAAQ,CAAC,sDAAsD,EAAE,GAAG,EAAE;YACpE,EAAE,CAAC,oDAAoD,EAAE,KAAK,IAAI,EAAE;gBAClE,MAAM,MAAM,CAAC,qBAAa,CAAC,MAAM,CAAC,kCAAmB,CAAC,CAAC,CAAC,QAAQ,CAAC,GAAG,CAAC,OAAO,EAAE,CAAC;YACjF,CAAC,CAAC,CAAC;QACL,CAAC,CAAC,CAAC;QAEH,QAAQ,CAAC,0EAA0E,EAAE,GAAG,EAAE;YACxF,EAAE,CAAC,6CAA6C,EAAE,KAAK,IAAI,EAAE;gBAC3D,MAAM,MAAM,CAAC,qBAAa,CAAC,MAAM,CAAC,qCAAsB,CAAC,CAAC,CAAC,OAAO,CAAC,OAAO,CACxE,+CAA+C,CAChD,CAAC;YACJ,CAAC,CAAC,CAAC;QACL,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fhir-bundle-sdk.test.d.ts","sourceRoot":"","sources":["../../src/__tests__/fhir-bundle-sdk.test.ts"],"names":[],"mappings":""}
|