fhir-runtime 0.2.0
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/CHANGELOG.md +211 -0
- package/LICENSE +21 -0
- package/README.md +261 -0
- package/dist/cjs/index.cjs +7368 -0
- package/dist/cjs/index.cjs.map +7 -0
- package/dist/cjs/index.d.ts +4224 -0
- package/dist/cjs/package.json +5 -0
- package/dist/esm/index.d.ts +4224 -0
- package/dist/esm/index.mjs +7250 -0
- package/dist/esm/index.mjs.map +7 -0
- package/dist/esm/package.json +5 -0
- package/dist/index.d.ts +4224 -0
- package/dist/lib/context/bundle-loader.d.ts +124 -0
- package/dist/lib/context/bundle-loader.d.ts.map +1 -0
- package/dist/lib/context/core-definitions/index.d.ts +72 -0
- package/dist/lib/context/core-definitions/index.d.ts.map +1 -0
- package/dist/lib/context/errors.d.ts +114 -0
- package/dist/lib/context/errors.d.ts.map +1 -0
- package/dist/lib/context/fhir-context.d.ts +72 -0
- package/dist/lib/context/fhir-context.d.ts.map +1 -0
- package/dist/lib/context/index.d.ts +21 -0
- package/dist/lib/context/index.d.ts.map +1 -0
- package/dist/lib/context/inheritance-resolver.d.ts +98 -0
- package/dist/lib/context/inheritance-resolver.d.ts.map +1 -0
- package/dist/lib/context/inner-type-extractor.d.ts +80 -0
- package/dist/lib/context/inner-type-extractor.d.ts.map +1 -0
- package/dist/lib/context/loaders/composite-loader.d.ts +47 -0
- package/dist/lib/context/loaders/composite-loader.d.ts.map +1 -0
- package/dist/lib/context/loaders/file-loader.d.ts +47 -0
- package/dist/lib/context/loaders/file-loader.d.ts.map +1 -0
- package/dist/lib/context/loaders/index.d.ts +11 -0
- package/dist/lib/context/loaders/index.d.ts.map +1 -0
- package/dist/lib/context/loaders/memory-loader.d.ts +42 -0
- package/dist/lib/context/loaders/memory-loader.d.ts.map +1 -0
- package/dist/lib/context/registry.d.ts +116 -0
- package/dist/lib/context/registry.d.ts.map +1 -0
- package/dist/lib/context/types.d.ts +266 -0
- package/dist/lib/context/types.d.ts.map +1 -0
- package/dist/lib/fhirpath/atoms.d.ts +228 -0
- package/dist/lib/fhirpath/atoms.d.ts.map +1 -0
- package/dist/lib/fhirpath/cache.d.ts +79 -0
- package/dist/lib/fhirpath/cache.d.ts.map +1 -0
- package/dist/lib/fhirpath/date.d.ts +17 -0
- package/dist/lib/fhirpath/date.d.ts.map +1 -0
- package/dist/lib/fhirpath/functions.d.ts +28 -0
- package/dist/lib/fhirpath/functions.d.ts.map +1 -0
- package/dist/lib/fhirpath/index.d.ts +20 -0
- package/dist/lib/fhirpath/index.d.ts.map +1 -0
- package/dist/lib/fhirpath/lexer/parse.d.ts +100 -0
- package/dist/lib/fhirpath/lexer/parse.d.ts.map +1 -0
- package/dist/lib/fhirpath/lexer/tokenize.d.ts +80 -0
- package/dist/lib/fhirpath/lexer/tokenize.d.ts.map +1 -0
- package/dist/lib/fhirpath/parse.d.ts +101 -0
- package/dist/lib/fhirpath/parse.d.ts.map +1 -0
- package/dist/lib/fhirpath/tokenize.d.ts +20 -0
- package/dist/lib/fhirpath/tokenize.d.ts.map +1 -0
- package/dist/lib/fhirpath/types.d.ts +111 -0
- package/dist/lib/fhirpath/types.d.ts.map +1 -0
- package/dist/lib/fhirpath/utils.d.ts +81 -0
- package/dist/lib/fhirpath/utils.d.ts.map +1 -0
- package/dist/lib/index.d.ts +24 -0
- package/dist/lib/index.d.ts.map +1 -0
- package/dist/lib/model/canonical-profile.d.ts +381 -0
- package/dist/lib/model/canonical-profile.d.ts.map +1 -0
- package/dist/lib/model/element-definition.d.ts +503 -0
- package/dist/lib/model/element-definition.d.ts.map +1 -0
- package/dist/lib/model/index.d.ts +14 -0
- package/dist/lib/model/index.d.ts.map +1 -0
- package/dist/lib/model/primitives.d.ts +464 -0
- package/dist/lib/model/primitives.d.ts.map +1 -0
- package/dist/lib/model/structure-definition.d.ts +263 -0
- package/dist/lib/model/structure-definition.d.ts.map +1 -0
- package/dist/lib/parser/choice-type-parser.d.ts +182 -0
- package/dist/lib/parser/choice-type-parser.d.ts.map +1 -0
- package/dist/lib/parser/index.d.ts +16 -0
- package/dist/lib/parser/index.d.ts.map +1 -0
- package/dist/lib/parser/json-parser.d.ts +171 -0
- package/dist/lib/parser/json-parser.d.ts.map +1 -0
- package/dist/lib/parser/parse-error.d.ts +146 -0
- package/dist/lib/parser/parse-error.d.ts.map +1 -0
- package/dist/lib/parser/primitive-parser.d.ts +136 -0
- package/dist/lib/parser/primitive-parser.d.ts.map +1 -0
- package/dist/lib/parser/serializer.d.ts +64 -0
- package/dist/lib/parser/serializer.d.ts.map +1 -0
- package/dist/lib/parser/structure-definition-parser.d.ts +63 -0
- package/dist/lib/parser/structure-definition-parser.d.ts.map +1 -0
- package/dist/lib/profile/canonical-builder.d.ts +87 -0
- package/dist/lib/profile/canonical-builder.d.ts.map +1 -0
- package/dist/lib/profile/constraint-merger.d.ts +100 -0
- package/dist/lib/profile/constraint-merger.d.ts.map +1 -0
- package/dist/lib/profile/element-merger.d.ts +80 -0
- package/dist/lib/profile/element-merger.d.ts.map +1 -0
- package/dist/lib/profile/element-sorter.d.ts +81 -0
- package/dist/lib/profile/element-sorter.d.ts.map +1 -0
- package/dist/lib/profile/errors.d.ts +150 -0
- package/dist/lib/profile/errors.d.ts.map +1 -0
- package/dist/lib/profile/index.d.ts +27 -0
- package/dist/lib/profile/index.d.ts.map +1 -0
- package/dist/lib/profile/path-utils.d.ts +180 -0
- package/dist/lib/profile/path-utils.d.ts.map +1 -0
- package/dist/lib/profile/slicing-handler.d.ts +121 -0
- package/dist/lib/profile/slicing-handler.d.ts.map +1 -0
- package/dist/lib/profile/snapshot-generator.d.ts +73 -0
- package/dist/lib/profile/snapshot-generator.d.ts.map +1 -0
- package/dist/lib/profile/types.d.ts +220 -0
- package/dist/lib/profile/types.d.ts.map +1 -0
- package/dist/lib/validator/errors.d.ts +83 -0
- package/dist/lib/validator/errors.d.ts.map +1 -0
- package/dist/lib/validator/index.d.ts +23 -0
- package/dist/lib/validator/index.d.ts.map +1 -0
- package/dist/lib/validator/invariant-validator.d.ts +62 -0
- package/dist/lib/validator/invariant-validator.d.ts.map +1 -0
- package/dist/lib/validator/path-extractor.d.ts +123 -0
- package/dist/lib/validator/path-extractor.d.ts.map +1 -0
- package/dist/lib/validator/slicing-validator.d.ts +119 -0
- package/dist/lib/validator/slicing-validator.d.ts.map +1 -0
- package/dist/lib/validator/structure-validator.d.ts +74 -0
- package/dist/lib/validator/structure-validator.d.ts.map +1 -0
- package/dist/lib/validator/types.d.ts +288 -0
- package/dist/lib/validator/types.d.ts.map +1 -0
- package/dist/lib/validator/validation-rules.d.ts +198 -0
- package/dist/lib/validator/validation-rules.d.ts.map +1 -0
- package/dist/tsdoc-metadata.json +11 -0
- package/package.json +76 -0
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,211 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes to this project will be documented in this file.
|
|
4
|
+
|
|
5
|
+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
|
6
|
+
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
7
|
+
|
|
8
|
+
## [0.2.0] - 2026-03-04
|
|
9
|
+
|
|
10
|
+
### Changed
|
|
11
|
+
|
|
12
|
+
- **Package renamed** from `@medxai/fhir-core` to `fhir-runtime`
|
|
13
|
+
- **License changed** from Apache-2.0 to MIT
|
|
14
|
+
- Updated all documentation to reflect new package name and branding
|
|
15
|
+
- Updated package.json metadata (repository, bugs, homepage)
|
|
16
|
+
|
|
17
|
+
### Added
|
|
18
|
+
|
|
19
|
+
#### Testing & Quality Assurance
|
|
20
|
+
|
|
21
|
+
- **US Core IG Verification Suite**
|
|
22
|
+
- 70 US Core StructureDefinitions successfully parsed
|
|
23
|
+
- 55 resource profiles converted to CanonicalProfiles
|
|
24
|
+
- 15 extension definitions processed
|
|
25
|
+
- Official examples validated against declared profiles
|
|
26
|
+
- FHIRPath evaluation on US Core resources
|
|
27
|
+
- Profile-to-example matching verification
|
|
28
|
+
|
|
29
|
+
- **Comprehensive Stress Testing**
|
|
30
|
+
- Malformed input resilience testing
|
|
31
|
+
- Deep nesting stress tests
|
|
32
|
+
- Large payload stress tests (bundle processing)
|
|
33
|
+
- FHIRPath complexity stress tests
|
|
34
|
+
- Memory pressure tests (batch processing)
|
|
35
|
+
- Concurrent safety tests (parallel operations)
|
|
36
|
+
|
|
37
|
+
- **Test Coverage Expansion**
|
|
38
|
+
- Expanded to 2,400+ tests across 45 test files
|
|
39
|
+
- 100% pass rate maintained
|
|
40
|
+
- All 6 modules fully tested
|
|
41
|
+
|
|
42
|
+
#### Documentation
|
|
43
|
+
|
|
44
|
+
- Created new v0.2 API reference (`docs/api/fhir-runtime-api-v0.2.md`)
|
|
45
|
+
- Created new v0.2 capability contract (`docs/specs/engine-capability-contract-v0.2.md`)
|
|
46
|
+
- Updated technical overview with testing section
|
|
47
|
+
- Completely rewrote README.md with:
|
|
48
|
+
- Production-ready presentation
|
|
49
|
+
- Quick start examples
|
|
50
|
+
- Comprehensive testing documentation
|
|
51
|
+
- Architecture diagrams
|
|
52
|
+
- Use cases and performance notes
|
|
53
|
+
|
|
54
|
+
### Fixed
|
|
55
|
+
|
|
56
|
+
- No bug fixes in this release (documentation and testing focus)
|
|
57
|
+
|
|
58
|
+
### Deprecated
|
|
59
|
+
|
|
60
|
+
- Old package name `@medxai/fhir-core` (use `fhir-runtime` instead)
|
|
61
|
+
- v0.1 documentation files (use v0.2 versions)
|
|
62
|
+
|
|
63
|
+
### Security
|
|
64
|
+
|
|
65
|
+
- No security changes in this release
|
|
66
|
+
|
|
67
|
+
---
|
|
68
|
+
|
|
69
|
+
## [0.1.0] - 2026-03-04 (Initial Release as @medxai/fhir-core)
|
|
70
|
+
|
|
71
|
+
### Added
|
|
72
|
+
|
|
73
|
+
#### Core Capabilities
|
|
74
|
+
|
|
75
|
+
- **FHIR R4 JSON Parsing & Serialization**
|
|
76
|
+
- Full support for all FHIR R4 resource types
|
|
77
|
+
- Primitive `_element` split handling
|
|
78
|
+
- Choice type `[x]` dispatch and tagging
|
|
79
|
+
- Null alignment in sparse arrays
|
|
80
|
+
- StructureDefinition-specific parsing (37 ElementDefinition fields)
|
|
81
|
+
|
|
82
|
+
- **Context & Registry Management**
|
|
83
|
+
- StructureDefinition registry with inheritance resolution
|
|
84
|
+
- Pluggable loader architecture (MemoryLoader, FileSystemLoader, CompositeLoader)
|
|
85
|
+
- Bundle loading (profiles-resources, profiles-types)
|
|
86
|
+
- 73 bundled FHIR R4 core definitions
|
|
87
|
+
- InnerType extraction for BackboneElement schemas
|
|
88
|
+
|
|
89
|
+
- **Snapshot Generation**
|
|
90
|
+
- HAPI-semantically-equivalent snapshot generation
|
|
91
|
+
- Base-driven merge algorithm
|
|
92
|
+
- Constraint tightening validation
|
|
93
|
+
- Slicing support (extension, type, value)
|
|
94
|
+
- Circular dependency detection
|
|
95
|
+
- Validated against 35 HAPI-generated fixtures (100% pass rate)
|
|
96
|
+
|
|
97
|
+
- **Profile-Based Validation**
|
|
98
|
+
- 9 structural validation rules:
|
|
99
|
+
- Cardinality (min/max)
|
|
100
|
+
- Required elements
|
|
101
|
+
- Type compatibility
|
|
102
|
+
- Fixed values
|
|
103
|
+
- Pattern values
|
|
104
|
+
- Choice types
|
|
105
|
+
- Reference targets
|
|
106
|
+
- Slicing discriminators
|
|
107
|
+
- FHIRPath invariants
|
|
108
|
+
- Snapshot-driven validation using CanonicalProfile
|
|
109
|
+
- Structured result objects (no-throw contract)
|
|
110
|
+
|
|
111
|
+
- **FHIRPath Expression Engine**
|
|
112
|
+
- 60+ standard FHIRPath functions
|
|
113
|
+
- Pratt parser with operator precedence
|
|
114
|
+
- AST caching (LRU, 128 entries)
|
|
115
|
+
- Support for FHIRPath ยง5.1โ5.9, ยง6.3, ยง6.5
|
|
116
|
+
- FHIR-specific functions (resolve, extension, hasValue)
|
|
117
|
+
- Variable scoping ($this, $index, $total)
|
|
118
|
+
|
|
119
|
+
#### Architecture & Design
|
|
120
|
+
|
|
121
|
+
- **Zero runtime dependencies** โ Pure TypeScript implementation
|
|
122
|
+
- **Structured results over exceptions** โ ParseResult, SnapshotResult, ValidationResult
|
|
123
|
+
- **Deterministic** โ Same input always produces same output
|
|
124
|
+
- **Type-safe** โ Full TypeScript definitions for all FHIR R4 types
|
|
125
|
+
- **Modular architecture** โ 6 independent modules (model, parser, context, profile, validator, fhirpath)
|
|
126
|
+
|
|
127
|
+
#### Package Details
|
|
128
|
+
|
|
129
|
+
- ESM + CJS module formats
|
|
130
|
+
- Full TypeScript type declarations
|
|
131
|
+
- 211 public exports across 6 modules
|
|
132
|
+
- Node.js โฅ18.0.0 support
|
|
133
|
+
- TypeScript 5.9 compatibility
|
|
134
|
+
|
|
135
|
+
---
|
|
136
|
+
|
|
137
|
+
## Version Comparison
|
|
138
|
+
|
|
139
|
+
### API Compatibility
|
|
140
|
+
|
|
141
|
+
- **v0.2.0 is fully compatible with v0.1.0** โ No breaking changes
|
|
142
|
+
- All 211 exports remain unchanged
|
|
143
|
+
- Only package name and license changed
|
|
144
|
+
|
|
145
|
+
### Migration from v0.1.0 to v0.2.0
|
|
146
|
+
|
|
147
|
+
```diff
|
|
148
|
+
- import { parseFhirJson } from '@medxai/fhir-core';
|
|
149
|
+
+ import { parseFhirJson } from 'fhir-runtime';
|
|
150
|
+
```
|
|
151
|
+
|
|
152
|
+
```diff
|
|
153
|
+
- npm install @medxai/fhir-core
|
|
154
|
+
+ npm install fhir-runtime
|
|
155
|
+
```
|
|
156
|
+
|
|
157
|
+
---
|
|
158
|
+
|
|
159
|
+
## Release Notes
|
|
160
|
+
|
|
161
|
+
### v0.2.0 Highlights
|
|
162
|
+
|
|
163
|
+
This release focuses on **production readiness** through extensive testing and documentation improvements:
|
|
164
|
+
|
|
165
|
+
- โ
**2,400+ tests** โ Comprehensive test coverage across all modules
|
|
166
|
+
- โ
**US Core IG verified** โ Real-world Implementation Guide validation
|
|
167
|
+
- โ
**Stress tested** โ Resilience under extreme conditions
|
|
168
|
+
- โ
**Zero dependencies** โ No external runtime dependencies
|
|
169
|
+
- โ
**HAPI-equivalent** โ 100% snapshot fixture compatibility
|
|
170
|
+
|
|
171
|
+
### v0.1.0 Highlights
|
|
172
|
+
|
|
173
|
+
Initial release providing complete FHIR R4 structural capabilities:
|
|
174
|
+
|
|
175
|
+
- โ
**Parsing** โ Full FHIR R4 JSON support
|
|
176
|
+
- โ
**Validation** โ 9 structural rules + FHIRPath invariants
|
|
177
|
+
- โ
**Snapshot generation** โ HAPI-equivalent differential expansion
|
|
178
|
+
- โ
**FHIRPath** โ 60+ functions with Pratt parser
|
|
179
|
+
- โ
**Context management** โ Registry, loaders, inheritance resolution
|
|
180
|
+
|
|
181
|
+
---
|
|
182
|
+
|
|
183
|
+
## Roadmap
|
|
184
|
+
|
|
185
|
+
### Planned for v0.3.0
|
|
186
|
+
|
|
187
|
+
- Terminology service integration (ValueSet expansion, code validation)
|
|
188
|
+
- Additional IG support (more Implementation Guides verified)
|
|
189
|
+
- Performance optimizations
|
|
190
|
+
- Enhanced error messages
|
|
191
|
+
|
|
192
|
+
### Planned for v1.0.0
|
|
193
|
+
|
|
194
|
+
- Stable API freeze
|
|
195
|
+
- Long-term support commitment
|
|
196
|
+
- Production deployment guidelines
|
|
197
|
+
- Enterprise support options
|
|
198
|
+
|
|
199
|
+
---
|
|
200
|
+
|
|
201
|
+
## Links
|
|
202
|
+
|
|
203
|
+
- **Repository**: https://github.com/medxaidev/medxai
|
|
204
|
+
- **Issues**: https://github.com/medxaidev/medxai/issues
|
|
205
|
+
- **Documentation**: [docs/](docs/)
|
|
206
|
+
- **License**: [MIT](LICENSE)
|
|
207
|
+
|
|
208
|
+
---
|
|
209
|
+
|
|
210
|
+
[0.2.0]: https://github.com/medxaidev/medxai/compare/v0.1.0...v0.2.0
|
|
211
|
+
[0.1.0]: https://github.com/medxaidev/medxai/releases/tag/v0.1.0
|
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Jason fang
|
|
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,261 @@
|
|
|
1
|
+
# fhir-runtime
|
|
2
|
+
|
|
3
|
+
> **A production-ready FHIR R4 runtime engine for TypeScript/Node.js**
|
|
4
|
+
|
|
5
|
+
[](https://opensource.org/licenses/MIT)
|
|
6
|
+
[](https://www.typescriptlang.org/)
|
|
7
|
+
[](https://nodejs.org/)
|
|
8
|
+
[]()
|
|
9
|
+
|
|
10
|
+
`fhir-runtime` is a **structural FHIR R4 engine** that provides comprehensive capabilities for parsing, validating, and manipulating FHIR resources โ without requiring a running FHIR server, database, or external terminology service.
|
|
11
|
+
|
|
12
|
+
Designed as a pure runtime layer with **zero dependencies**, it's suitable for embedding in servers, CLIs, web applications, or custom platforms.
|
|
13
|
+
|
|
14
|
+
---
|
|
15
|
+
|
|
16
|
+
## โจ Features
|
|
17
|
+
|
|
18
|
+
### Core Capabilities
|
|
19
|
+
|
|
20
|
+
- **๐ FHIR R4 JSON Parsing** โ Full support for primitives, choice types, extensions
|
|
21
|
+
- **โ
Profile-Based Validation** โ 9 structural validation rules + FHIRPath invariants
|
|
22
|
+
- **๐ธ Snapshot Generation** โ HAPI-equivalent differential expansion
|
|
23
|
+
- **๐งฎ FHIRPath Engine** โ 60+ functions, Pratt parser with AST caching
|
|
24
|
+
- **๐ฆ Bundle Loading** โ Load FHIR specification bundles and IGs
|
|
25
|
+
- **๐ Context Management** โ Registry, loaders, inheritance resolution
|
|
26
|
+
- **๐ฏ InnerType Extraction** โ BackboneElement schema for UI/validation
|
|
27
|
+
|
|
28
|
+
### Quality & Testing
|
|
29
|
+
|
|
30
|
+
- **2,400+ tests** across 45 test files โ 100% passing
|
|
31
|
+
- **US Core IG verified** โ 70 StructureDefinitions, 55 profiles validated
|
|
32
|
+
- **HAPI-equivalent** โ 35/35 snapshot fixtures match HAPI output
|
|
33
|
+
- **Stress tested** โ Malformed input, deep nesting, large payloads, concurrency
|
|
34
|
+
- **Zero dependencies** โ Pure TypeScript, no external runtime deps
|
|
35
|
+
- **Type-safe** โ Full TypeScript definitions for all FHIR R4 types
|
|
36
|
+
|
|
37
|
+
---
|
|
38
|
+
|
|
39
|
+
## ๐ฆ Installation
|
|
40
|
+
|
|
41
|
+
```bash
|
|
42
|
+
npm install fhir-runtime
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
**Requirements:**
|
|
46
|
+
|
|
47
|
+
- Node.js โฅ18.0.0
|
|
48
|
+
- TypeScript โฅ5.0 (for TypeScript projects)
|
|
49
|
+
|
|
50
|
+
---
|
|
51
|
+
|
|
52
|
+
## ๐ Quick Start
|
|
53
|
+
|
|
54
|
+
### Parse a FHIR Resource
|
|
55
|
+
|
|
56
|
+
```typescript
|
|
57
|
+
import { parseFhirJson } from "fhir-runtime";
|
|
58
|
+
|
|
59
|
+
const result = parseFhirJson(`{
|
|
60
|
+
"resourceType": "Patient",
|
|
61
|
+
"id": "example",
|
|
62
|
+
"name": [{ "family": "Doe", "given": ["John"] }]
|
|
63
|
+
}`);
|
|
64
|
+
|
|
65
|
+
if (result.success) {
|
|
66
|
+
console.log(result.data.resourceType); // "Patient"
|
|
67
|
+
console.log(result.data.name[0].family); // "Doe"
|
|
68
|
+
}
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
### Validate Against a Profile
|
|
72
|
+
|
|
73
|
+
```typescript
|
|
74
|
+
import {
|
|
75
|
+
StructureValidator,
|
|
76
|
+
buildCanonicalProfile,
|
|
77
|
+
parseStructureDefinition,
|
|
78
|
+
} from "fhir-runtime";
|
|
79
|
+
|
|
80
|
+
// Load a profile
|
|
81
|
+
const sdResult = parseStructureDefinition(profileJson);
|
|
82
|
+
const profile = buildCanonicalProfile(sdResult.data);
|
|
83
|
+
|
|
84
|
+
// Validate a resource
|
|
85
|
+
const validator = new StructureValidator();
|
|
86
|
+
const result = validator.validate(patientResource, profile);
|
|
87
|
+
|
|
88
|
+
if (!result.valid) {
|
|
89
|
+
result.issues.forEach((issue) => {
|
|
90
|
+
console.error(`${issue.severity}: ${issue.message} at ${issue.path}`);
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
### Generate a Snapshot
|
|
96
|
+
|
|
97
|
+
```typescript
|
|
98
|
+
import { FhirContextImpl, SnapshotGenerator } from "fhir-runtime";
|
|
99
|
+
|
|
100
|
+
const ctx = new FhirContextImpl({ loaders: [] });
|
|
101
|
+
await ctx.preloadCoreDefinitions();
|
|
102
|
+
|
|
103
|
+
const generator = new SnapshotGenerator(ctx, { generateCanonical: true });
|
|
104
|
+
const result = await generator.generate(myProfile);
|
|
105
|
+
|
|
106
|
+
if (result.success) {
|
|
107
|
+
console.log(
|
|
108
|
+
`Generated ${result.structureDefinition.snapshot.element.length} elements`,
|
|
109
|
+
);
|
|
110
|
+
}
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
### Evaluate FHIRPath
|
|
114
|
+
|
|
115
|
+
```typescript
|
|
116
|
+
import { evalFhirPath, evalFhirPathBoolean } from "fhir-runtime";
|
|
117
|
+
|
|
118
|
+
const patient = { resourceType: "Patient", name: [{ given: ["John"] }] };
|
|
119
|
+
|
|
120
|
+
const names = evalFhirPath("Patient.name.given", patient);
|
|
121
|
+
// โ ['John']
|
|
122
|
+
|
|
123
|
+
const hasOfficial = evalFhirPathBoolean(
|
|
124
|
+
"name.where(use='official').exists()",
|
|
125
|
+
patient,
|
|
126
|
+
);
|
|
127
|
+
// โ false
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
---
|
|
131
|
+
|
|
132
|
+
## ๐ Documentation
|
|
133
|
+
|
|
134
|
+
- **[Technical Overview](docs/overview/fhir-runtime-overview.md)** โ Architecture, design principles, capabilities
|
|
135
|
+
- **[API Reference](docs/api/fhir-runtime-api-v0.2.md)** โ Complete API documentation (211 exports)
|
|
136
|
+
- **[Capability Contract](docs/specs/engine-capability-contract-v0.2.md)** โ Behavioral guarantees, error semantics
|
|
137
|
+
|
|
138
|
+
---
|
|
139
|
+
|
|
140
|
+
## ๐งช Testing & Quality
|
|
141
|
+
|
|
142
|
+
### Test Coverage
|
|
143
|
+
|
|
144
|
+
```
|
|
145
|
+
โ
2,400+ tests across 45 test files
|
|
146
|
+
โ
100% pass rate on HAPI snapshot fixtures (35/35)
|
|
147
|
+
โ
All 6 modules fully tested (parser, context, profile, validator, fhirpath, model)
|
|
148
|
+
```
|
|
149
|
+
|
|
150
|
+
### US Core IG Verification
|
|
151
|
+
|
|
152
|
+
```
|
|
153
|
+
โ
70 US Core StructureDefinitions parsed
|
|
154
|
+
โ
55 resource profiles converted to CanonicalProfiles
|
|
155
|
+
โ
15 extension definitions processed
|
|
156
|
+
โ
Official examples validated against declared profiles
|
|
157
|
+
โ
FHIRPath evaluation on US Core resources
|
|
158
|
+
โ
Profile-to-example matching verified
|
|
159
|
+
```
|
|
160
|
+
|
|
161
|
+
### Stress Testing
|
|
162
|
+
|
|
163
|
+
```
|
|
164
|
+
โ
Malformed input resilience โ graceful error handling
|
|
165
|
+
โ
Deep nesting stress โ recursive structure validation
|
|
166
|
+
โ
Large payload stress โ bundle processing performance
|
|
167
|
+
โ
FHIRPath complexity โ complex expression evaluation
|
|
168
|
+
โ
Memory pressure โ batch processing stability
|
|
169
|
+
โ
Concurrent safety โ parallel operation validation
|
|
170
|
+
```
|
|
171
|
+
|
|
172
|
+
---
|
|
173
|
+
|
|
174
|
+
## ๐๏ธ Architecture
|
|
175
|
+
|
|
176
|
+
### Module Structure
|
|
177
|
+
|
|
178
|
+
```
|
|
179
|
+
src/
|
|
180
|
+
โโโ model/ โ FHIR R4 type definitions (branded primitives, enums, complex types)
|
|
181
|
+
โโโ parser/ โ JSON parsing & serialization
|
|
182
|
+
โโโ context/ โ SD registry, loaders, inheritance resolution, bundle loading
|
|
183
|
+
โโโ profile/ โ Snapshot generation, canonical builder, constraint merging
|
|
184
|
+
โโโ validator/ โ Structural validation (9 rules + FHIRPath invariants)
|
|
185
|
+
โโโ fhirpath/ โ FHIRPath expression engine (Pratt parser, 60+ functions)
|
|
186
|
+
```
|
|
187
|
+
|
|
188
|
+
### HAPI FHIR Equivalence
|
|
189
|
+
|
|
190
|
+
| fhir-runtime | HAPI FHIR |
|
|
191
|
+
| -------------------- | ------------------------------------------------- |
|
|
192
|
+
| `FhirContextImpl` | `FhirContext` + `DefaultProfileValidationSupport` |
|
|
193
|
+
| `SnapshotGenerator` | `ProfileUtilities.generateSnapshot()` |
|
|
194
|
+
| `StructureValidator` | `FhirInstanceValidator` |
|
|
195
|
+
| `evalFhirPath()` | `FHIRPathEngine.evaluate()` |
|
|
196
|
+
| `CompositeLoader` | `ValidationSupportChain` |
|
|
197
|
+
|
|
198
|
+
---
|
|
199
|
+
|
|
200
|
+
## ๐ฏ Use Cases
|
|
201
|
+
|
|
202
|
+
- **FHIR Servers** โ Validation layer for REST operations
|
|
203
|
+
- **CLI Tools** โ Parse, validate, generate snapshots, evaluate FHIRPath
|
|
204
|
+
- **Web Applications** โ Client-side FHIR processing without server dependency
|
|
205
|
+
- **IG Publishers** โ Profile validation and snapshot generation
|
|
206
|
+
- **Testing Frameworks** โ FHIR resource validation in test suites
|
|
207
|
+
- **Data Pipelines** โ ETL with FHIR validation and transformation
|
|
208
|
+
|
|
209
|
+
---
|
|
210
|
+
|
|
211
|
+
## ๐ License
|
|
212
|
+
|
|
213
|
+
MIT License - see [LICENSE](LICENSE) file for details.
|
|
214
|
+
|
|
215
|
+
---
|
|
216
|
+
|
|
217
|
+
## ๐ค Contributing
|
|
218
|
+
|
|
219
|
+
Contributions are welcome! This project maintains:
|
|
220
|
+
|
|
221
|
+
- **Zero runtime dependencies** โ Keep it that way
|
|
222
|
+
- **100% test pass rate** โ All tests must pass
|
|
223
|
+
- **Type safety** โ Full TypeScript coverage
|
|
224
|
+
- **HAPI equivalence** โ Snapshot generation must match HAPI output
|
|
225
|
+
|
|
226
|
+
---
|
|
227
|
+
|
|
228
|
+
## ๐ Package Details
|
|
229
|
+
|
|
230
|
+
| Property | Value |
|
|
231
|
+
| ------------------------ | ------------------------------- |
|
|
232
|
+
| Package name | `fhir-runtime` |
|
|
233
|
+
| Version | 0.2.0 |
|
|
234
|
+
| License | MIT |
|
|
235
|
+
| FHIR Version | R4 (4.0.1) |
|
|
236
|
+
| Module formats | ESM + CJS |
|
|
237
|
+
| Runtime dependencies | None (zero dependencies) |
|
|
238
|
+
| Bundled core definitions | 73 FHIR R4 StructureDefinitions |
|
|
239
|
+
| Public exports | 211 symbols across 6 modules |
|
|
240
|
+
| Test coverage | 2,400+ tests across 45 files |
|
|
241
|
+
|
|
242
|
+
---
|
|
243
|
+
|
|
244
|
+
## ๐ Related Projects
|
|
245
|
+
|
|
246
|
+
- **[HAPI FHIR](https://hapifhir.io/)** โ Reference Java implementation
|
|
247
|
+
- **[HL7 FHIR Specification](https://hl7.org/fhir/R4/)** โ Official FHIR R4 spec
|
|
248
|
+
- **[US Core IG](https://www.hl7.org/fhir/us/core/)** โ US Core Implementation Guide
|
|
249
|
+
|
|
250
|
+
---
|
|
251
|
+
|
|
252
|
+
## โก Performance
|
|
253
|
+
|
|
254
|
+
- **Zero dependencies** โ Minimal bundle size, fast installation
|
|
255
|
+
- **AST caching** โ FHIRPath expressions cached (LRU, 128 entries)
|
|
256
|
+
- **Deterministic** โ Same input always produces same output
|
|
257
|
+
- **Memory efficient** โ Streaming bundle loading, lazy evaluation
|
|
258
|
+
|
|
259
|
+
---
|
|
260
|
+
|
|
261
|
+
**Made with โค๏ธ for the FHIR community**
|