@atomic-ehr/codegen 0.0.4-canary.20251217132509.d94026d → 0.0.4-canary.20251218085438.283b979
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 +160 -293
- package/package.json +1 -1
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Atomic EHR Team
|
|
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
CHANGED
|
@@ -1,26 +1,48 @@
|
|
|
1
|
-
# Atomic
|
|
1
|
+
# Atomic EHR Codegen
|
|
2
2
|
|
|
3
3
|
[](https://www.npmjs.com/package/@atomic-ehr/codegen/v/canary)
|
|
4
4
|
[](https://badge.fury.io/js/%40atomic-ehr%2Fcodegen)
|
|
5
5
|
[](https://github.com/atomic-ehr/codegen/actions/workflows/ci.yml)
|
|
6
6
|
[](https://github.com/atomic-ehr/codegen/actions/workflows/sdk-tests.yml)
|
|
7
7
|
|
|
8
|
-
|
|
8
|
+
<!-- markdown-toc start - Don't edit this section. Run M-x markdown-toc-refresh-toc -->
|
|
9
|
+
**Table of Contents**
|
|
10
|
+
|
|
11
|
+
- [Atomic EHR Codegen](#atomic-ehr-codegen)
|
|
12
|
+
- [Features](#features)
|
|
13
|
+
- [Versions & Release Cycle](#versions--release-cycle)
|
|
14
|
+
- [Installation](#installation)
|
|
15
|
+
- [Quick Start](#quick-start)
|
|
16
|
+
- [Usage Examples](#usage-examples)
|
|
17
|
+
- [Architecture](#architecture)
|
|
18
|
+
- [Input - FHIR packages & resolves canonicals](#input---fhir-packages--resolves-canonicals)
|
|
19
|
+
- [Load Local StructureDefinitions & TGZ Archives](#load-local-structuredefinitions--tgz-archives)
|
|
20
|
+
- [Intermediate - Type Schema](#intermediate---type-schema)
|
|
21
|
+
- [Tree Shaking](#tree-shaking)
|
|
22
|
+
- [Generation](#generation)
|
|
23
|
+
- [Roadmap](#roadmap)
|
|
24
|
+
- [Support](#support)
|
|
25
|
+
|
|
26
|
+
<!-- markdown-toc end -->
|
|
27
|
+
|
|
28
|
+
A powerful, extensible code generation toolkit for FHIR ([Fast Healthcare Interoperability Resources](https://www.hl7.org/fhir/)) that transforms FHIR specifications into strongly-typed code for multiple programming languages.
|
|
9
29
|
|
|
10
30
|
## Features
|
|
11
31
|
|
|
12
32
|
- 🚀 **High-Performance** - Built with Bun runtime for blazing-fast generation
|
|
13
|
-
- 🔧 **Extensible Architecture** - Three-stage pipeline
|
|
14
|
-
-
|
|
33
|
+
- 🔧 **Extensible Architecture** - Three-stage pipeline:
|
|
34
|
+
- FHIR package management & canonical resolution
|
|
35
|
+
- Optimized intermediate FHIR data entities representation via Type Schema
|
|
36
|
+
- Generation for different programming languages
|
|
37
|
+
- 📦 **Multi-Package Support** - Generate from a list of FHIR packages
|
|
15
38
|
- 🎯 **Type-Safe** - Generates fully typed interfaces with proper inheritance
|
|
16
|
-
-
|
|
17
|
-
- 🛠️ **Developer Friendly** - Fluent API, CLI, and configuration file support
|
|
39
|
+
- 🛠️ **Developer Friendly** - Fluent API
|
|
18
40
|
|
|
19
|
-
## Versions
|
|
41
|
+
## Versions & Release Cycle
|
|
20
42
|
|
|
21
43
|
- `canary` channel - Latest development version from `main` branch
|
|
22
|
-
- `latest` channel - Latest stable version (
|
|
23
|
-
-
|
|
44
|
+
- `latest` channel - Latest stable version, changelog: [Releases](https://github.com/atomic-ehr/codegen/releases)
|
|
45
|
+
- All versions: [NPM: @atomic-ehr/codegen](https://www.npmjs.com/package/@atomic-ehr/codegen?activeTab=versions)
|
|
24
46
|
|
|
25
47
|
## Installation
|
|
26
48
|
|
|
@@ -37,334 +59,152 @@ yarn add @atomic-ehr/codegen
|
|
|
37
59
|
|
|
38
60
|
## Quick Start
|
|
39
61
|
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
```typescript
|
|
43
|
-
import { APIBuilder } from '@atomic-ehr/codegen';
|
|
44
|
-
|
|
45
|
-
const builder = new APIBuilder()
|
|
46
|
-
.fromPackage("hl7.fhir.r4.core", "4.0.1")
|
|
47
|
-
.typescript({})
|
|
48
|
-
.outputTo("./examples/typescript-r4/fhir-types");
|
|
62
|
+
1. Write SDK generation script (`generate-types.ts`):
|
|
49
63
|
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
```
|
|
64
|
+
```typescript
|
|
65
|
+
import { APIBuilder } from '@atomic-ehr/codegen';
|
|
53
66
|
|
|
54
|
-
|
|
67
|
+
const builder = new APIBuilder()
|
|
68
|
+
.fromPackage("hl7.fhir.r4.core", "4.0.1")
|
|
69
|
+
.typescript({})
|
|
70
|
+
.outputTo("./examples/typescript-r4/fhir-types");
|
|
55
71
|
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
72
|
+
const report = await builder.generate();
|
|
73
|
+
console.log(report);
|
|
74
|
+
```
|
|
59
75
|
|
|
60
|
-
|
|
76
|
+
2. Run the script with:
|
|
61
77
|
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
78
|
+
- `npm exec tsx generate-types.ts`
|
|
79
|
+
- `bun run generate-types.ts`
|
|
80
|
+
- `pnpm exec tsx generate-types.ts`
|
|
65
81
|
|
|
66
|
-
|
|
67
|
-
bunx atomic-codegen generate --verbose
|
|
82
|
+
### Usage Examples
|
|
68
83
|
|
|
69
|
-
|
|
70
|
-
bunx atomic-codegen typeschema generate hl7.fhir.r4.core@4.0.1 -o schemas.ndjson
|
|
71
|
-
```
|
|
84
|
+
See the [examples/](examples/) directory for working demonstrations:
|
|
72
85
|
|
|
73
|
-
|
|
86
|
+
- **[typescript-r4/](examples/typescript-r4/)** - FHIR R4 type generation with resource creation demo and profile usage
|
|
87
|
+
- **[typescript-ccda/](examples/typescript-ccda/)** - C-CDA on FHIR type generation
|
|
88
|
+
- **[typescript-sql-on-fhir/](examples/typescript-sql-on-fhir/)** - SQL on FHIR ViewDefinition with tree shaking
|
|
89
|
+
- **[python/](examples/python/)** - Python/Pydantic model generation with configurable field formats
|
|
90
|
+
- **[csharp/](examples/csharp/)** - C# class generation with namespace configuration
|
|
91
|
+
- **[local-package-folder/](examples/local-package-folder/)** - Loading unpublished local FHIR packages
|
|
74
92
|
|
|
75
|
-
|
|
93
|
+
For detailed documentation, see [examples/README.md](examples/README.md).
|
|
76
94
|
|
|
77
|
-
|
|
78
|
-
import { defineConfig } from "@atomic-ehr/codegen";
|
|
79
|
-
|
|
80
|
-
export default defineConfig({
|
|
81
|
-
outputDir: "./generated",
|
|
82
|
-
overwrite: true,
|
|
83
|
-
validate: true,
|
|
84
|
-
cache: true,
|
|
85
|
-
packages: ["hl7.fhir.r4.core@4.0.1"],
|
|
86
|
-
typescript: {
|
|
87
|
-
includeDocuments: true,
|
|
88
|
-
namingConvention: "PascalCase",
|
|
89
|
-
includeProfiles: false,
|
|
90
|
-
includeExtensions: false,
|
|
91
|
-
generateIndex: true,
|
|
92
|
-
strictMode: true,
|
|
93
|
-
generateValueSets: true,
|
|
94
|
-
includeValueSetHelpers: true,
|
|
95
|
-
valueSetStrengths: ["required", "preferred"],
|
|
96
|
-
valueSetMode: "custom"
|
|
97
|
-
}
|
|
98
|
-
});
|
|
99
|
-
```
|
|
95
|
+
## Architecture
|
|
100
96
|
|
|
101
|
-
|
|
97
|
+
The toolkit uses a three-stage architecture (details: [link](https://www.health-samurai.io/articles/type-schema-a-pragmatic-approach-to-build-fhir-sdk)):
|
|
102
98
|
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
99
|
+
1. **Input** - FHIR packages & resolves canonicals
|
|
100
|
+
2. **Intermediate representation** - TypeSchema provides a universal representation for FHIR data entities and processing utilities
|
|
101
|
+
3. **Generation** - Generate code for TypeScript, Python, etc.
|
|
106
102
|
|
|
107
|
-
|
|
103
|
+
The `APIBuilder` provides a fluent interface for configuring and generating code:
|
|
108
104
|
|
|
109
|
-
|
|
105
|
+
```typescript
|
|
106
|
+
const builder = new APIBuilder()
|
|
110
107
|
|
|
111
|
-
|
|
112
|
-
|
|
108
|
+
// Input sources (choose one or combine)
|
|
109
|
+
.fromPackage("hl7.fhir.r4.core", "4.0.1") // NPM registry package
|
|
110
|
+
.fromPackageRef("https://...package.tgz") // Remote TGZ file
|
|
111
|
+
.localStructureDefinitions({ ... }) // Loose JSON files
|
|
112
|
+
|
|
113
|
+
// Type Schema processing
|
|
114
|
+
.treeShake({ ... }) // Include only specified types
|
|
115
|
+
|
|
116
|
+
// Code generator (choose one)
|
|
117
|
+
.typescript({ // TypeScript generator
|
|
118
|
+
generateProfile?: boolean,
|
|
119
|
+
withDebugComment?: boolean,
|
|
120
|
+
openResourceTypeSet?: boolean,
|
|
121
|
+
})
|
|
122
|
+
.python({ // Python generator
|
|
123
|
+
allowExtraFields?: boolean,
|
|
124
|
+
fieldFormat?: "snake_case" | "camelCase",
|
|
125
|
+
staticDir?: string,
|
|
126
|
+
})
|
|
127
|
+
.csharp("NameSpace", "staticFilesPath") // C# generator
|
|
128
|
+
|
|
129
|
+
// Output configuration
|
|
130
|
+
.outputTo("./generated/types") // Output directory
|
|
131
|
+
.cleanOutput(true) // Clean before generation
|
|
132
|
+
|
|
133
|
+
// Optional: Optimization & debugging
|
|
134
|
+
.throwException() // Throw on errors (optional)
|
|
135
|
+
.writeTypeSchemas("./schemas") // Export TypeSchema files
|
|
136
|
+
.writeTypeTree("./tree.yaml") // Export dependency tree
|
|
137
|
+
|
|
138
|
+
// Execute generation
|
|
139
|
+
.generate(); // Returns GenerationReport
|
|
113
140
|
```
|
|
114
141
|
|
|
115
|
-
|
|
116
|
-
2. **Intermediate Format** - TypeSchema provides a universal representation for FHIR data entities
|
|
117
|
-
3. **Output Generators** - Generate code for TypeScript, Python, and other languages
|
|
142
|
+
Each method returns the builder instance, allowing method chaining. The `generate()` method executes the pipeline and returns a report with success status and generated file details.
|
|
118
143
|
|
|
119
|
-
|
|
144
|
+
### Input - FHIR packages & resolves canonicals
|
|
120
145
|
|
|
121
|
-
|
|
146
|
+
The input stage leverages [Canonical Manager](https://github.com/atomic-ehr/canonical-manager) to handle FHIR package management and dependency resolution. It processes FHIR packages from multiple sources (registry, local files, TGZ archives) and resolves all canonical URLs to their concrete definitions, ensuring all references between resources are properly linked before transformation.
|
|
122
147
|
|
|
123
|
-
|
|
124
|
-
- `generate.ts` - script to generate types
|
|
125
|
-
- [`examples/local-structure-package.ts`](examples/local-structure-package.ts) - demonstrates loading local profiles, installing dependencies, and tree shaking the output
|
|
126
|
-
- [`examples/local-package-folder/generate.ts`](examples/local-package-folder/generate.ts) - demonstrates pointing the builder at an existing FHIR package folder without publishing it
|
|
148
|
+
The [`Register`](src/typeschema/register.ts) component wraps Canonical Manager specifically for codegen purposes, providing:
|
|
127
149
|
|
|
128
|
-
|
|
150
|
+
- **Multi-package indexing** for fast canonical URL lookups across package boundaries
|
|
151
|
+
- **Package-aware resolution** with automatic dependency tree traversal
|
|
152
|
+
- **FHIR-to-TypeSchema conversion** using the `@atomic-ehr/fhirschema` translator
|
|
153
|
+
- **Element snapshot generation** that merges inherited properties from base resources
|
|
154
|
+
|
|
155
|
+
#### Load Local StructureDefinitions & TGZ Archives
|
|
129
156
|
|
|
130
157
|
Use the new `localPackage` helper to point the builder at an on-disk FHIR package folder (for example, an unpublished implementation guide). If you only have loose StructureDefinition JSON files, group them under a folder and pass it to `localStructureDefinitions`. Canonical Manager handles copying, indexing, and dependency installation in both scenarios, so the API builder only needs to describe where the files live and what upstream packages they depend on.
|
|
131
158
|
|
|
132
159
|
```typescript
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
const builder = new APIBuilder();
|
|
136
|
-
|
|
137
|
-
await builder
|
|
138
|
-
.localPackage({
|
|
139
|
-
package: { name: "example.folder.structures", version: "0.0.1" },
|
|
140
|
-
path: "./packages/example-ig/package",
|
|
141
|
-
dependencies: [{ name: "hl7.fhir.r4.core", version: "4.0.1" }],
|
|
142
|
-
})
|
|
143
|
-
.localStructureDefinitions({
|
|
160
|
+
.localStructureDefinitions({
|
|
144
161
|
package: { name: "example.local.structures", version: "0.0.1" },
|
|
145
162
|
path: "./custom-profiles",
|
|
146
163
|
dependencies: [{ name: "hl7.fhir.r4.core", version: "4.0.1" }],
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
.typescript({ generateIndex: true })
|
|
150
|
-
.treeShake({
|
|
151
|
-
"example.local.structures#0.0.1": {
|
|
152
|
-
"http://example.org/fhir/StructureDefinition/ExampleNotebook": {},
|
|
153
|
-
},
|
|
154
|
-
"hl7.fhir.r4.core#4.0.1": {
|
|
155
|
-
"http://hl7.org/fhir/StructureDefinition/Patient": {},
|
|
156
|
-
},
|
|
157
|
-
})
|
|
158
|
-
.outputTo("./generated/local-profiles")
|
|
159
|
-
.generate();
|
|
164
|
+
})
|
|
165
|
+
.localTgzPackage("./packages/my-custom-ig.tgz")
|
|
160
166
|
```
|
|
161
167
|
|
|
162
168
|
The example above points Canonical Manager at `./custom-profiles`, installs the HL7 R4 core dependency automatically, and then limits generation to the custom `ExampleNotebook` logical model plus the standard R4 `Patient` resource via tree shaking. The `localTgzPackage` helper registers `.tgz` artifacts that Canonical Manager already knows how to unpack.
|
|
163
169
|
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
### Generate with Custom Templates (Draft)
|
|
167
|
-
|
|
168
|
-
```typescript
|
|
169
|
-
import { APIBuilder } from '@atomic-ehr/codegen';
|
|
170
|
-
|
|
171
|
-
const builder = new APIBuilder();
|
|
172
|
-
|
|
173
|
-
await builder
|
|
174
|
-
.fromPackage('hl7.fhir.r4.core', '4.0.1')
|
|
175
|
-
.withTemplate('./templates/custom-interface.hbs')
|
|
176
|
-
.typescript({
|
|
177
|
-
outputDir: './generated',
|
|
178
|
-
customHelpers: {
|
|
179
|
-
upperCase: (str) => str.toUpperCase()
|
|
180
|
-
}
|
|
181
|
-
})
|
|
182
|
-
.generate();
|
|
183
|
-
```
|
|
184
|
-
|
|
185
|
-
### Generate Multiple Output Formats (Draft)
|
|
186
|
-
|
|
187
|
-
```typescript
|
|
188
|
-
import { APIBuilder } from '@atomic-ehr/codegen';
|
|
189
|
-
|
|
190
|
-
const builder = new APIBuilder();
|
|
191
|
-
|
|
192
|
-
// Parse once, generate multiple formats
|
|
193
|
-
const schemas = await builder
|
|
194
|
-
.fromPackage('hl7.fhir.r4.core', '4.0.1')
|
|
195
|
-
.parse();
|
|
196
|
-
|
|
197
|
-
// Generate TypeScript
|
|
198
|
-
await builder
|
|
199
|
-
.fromSchemas(schemas)
|
|
200
|
-
.typescript({ outputDir: './ts-types' })
|
|
201
|
-
.generate();
|
|
202
|
-
|
|
203
|
-
// Generate Python (coming soon)
|
|
204
|
-
await builder
|
|
205
|
-
.fromSchemas(schemas)
|
|
206
|
-
.python({ outputDir: './py-types' })
|
|
207
|
-
.generate();
|
|
208
|
-
```
|
|
209
|
-
|
|
210
|
-
## CLI Commands (Draft)
|
|
211
|
-
|
|
212
|
-
```bash
|
|
213
|
-
# Generate code using configuration file
|
|
214
|
-
atomic-codegen generate # Uses atomic-codegen.config.ts
|
|
215
|
-
atomic-codegen generate --verbose # With detailed output
|
|
216
|
-
atomic-codegen generate --config custom.ts # Custom config file
|
|
217
|
-
|
|
218
|
-
# TypeSchema operations
|
|
219
|
-
atomic-codegen typeschema generate hl7.fhir.r4.core@4.0.1 -o schemas.ndjson
|
|
220
|
-
atomic-codegen typeschema validate schemas.ndjson
|
|
221
|
-
|
|
222
|
-
# Help and debugging
|
|
223
|
-
atomic-codegen --help # Show help
|
|
224
|
-
atomic-codegen --debug generate # Debug mode
|
|
225
|
-
```
|
|
226
|
-
|
|
227
|
-
## Configuration Options (Draft)
|
|
228
|
-
|
|
229
|
-
### Global Configuration Options
|
|
170
|
+
### Intermediate - Type Schema
|
|
230
171
|
|
|
231
|
-
|
|
232
|
-
|--------|------|---------|-------------|
|
|
233
|
-
| `outputDir` | `string` | `./generated` | Base output directory for all generated files |
|
|
234
|
-
| `overwrite` | `boolean` | `false` | Overwrite existing files without prompting |
|
|
235
|
-
| `validate` | `boolean` | `true` | Validate generated TypeSchema before processing |
|
|
236
|
-
| `cache` | `boolean` | `true` | Enable caching for improved performance |
|
|
237
|
-
| `packages` | `string[]` | `[]` | FHIR packages to process (e.g., `"hl7.fhir.r4.core@4.0.1"`) |
|
|
172
|
+
Type Schema serves as a universal intermediate representation that bridges FHIR's complex hierarchical structure with programming language constructs. It transforms FHIR StructureDefinitions into a flattened, code-generation-friendly format that:
|
|
238
173
|
|
|
239
|
-
|
|
174
|
+
- **Unifies** all FHIR elements (Resources, Types, ValueSets) into a consistent structure
|
|
175
|
+
- **Flattens** nested paths for direct field access without complex traversal
|
|
176
|
+
- **Enriches** definitions with resolved references, value set expansions, and type dependencies
|
|
177
|
+
- **Simplifies** FHIR concepts like choice types and extensions for easier code generation
|
|
240
178
|
|
|
241
|
-
|
|
242
|
-
|--------|------|---------|-------------|
|
|
243
|
-
| `outputDir` | `string` | `./generated` | Output directory for generated files |
|
|
244
|
-
| `moduleFormat` | `'esm' \| 'cjs'` | `'esm'` | Module format |
|
|
245
|
-
| `generateIndex` | `boolean` | `true` | Generate index file with exports |
|
|
246
|
-
| `includeDocuments` | `boolean` | `true` | Include JSDoc documentation |
|
|
247
|
-
| `namingConvention` | `'PascalCase' \| 'camelCase'` | `'PascalCase'` | Type naming convention |
|
|
248
|
-
| `includeExtensions` | `boolean` | `false` | Include FHIR extensions |
|
|
249
|
-
| `includeProfiles` | `boolean` | `false` | Include FHIR profiles |
|
|
250
|
-
| `generateValueSets` | `boolean` | `false` | Generate strongly-typed value sets from FHIR bindings |
|
|
251
|
-
| `valueSetStrengths` | `string[]` | `['required']` | Which binding strengths to generate |
|
|
252
|
-
| `includeValueSetHelpers` | `boolean` | `false` | Include validation helper functions |
|
|
253
|
-
| `valueSetDirectory` | `string` | `'valuesets'` | Output directory for value set files |
|
|
179
|
+
This approach enables generating idiomatic code for any programming language while preserving FHIR semantics and constraints. Learn more: [Type Schema specification](https://www.health-samurai.io/articles/type-schema-a-pragmatic-approach-to-build-fhir-sdk).
|
|
254
180
|
|
|
255
|
-
|
|
181
|
+
#### Tree Shaking
|
|
256
182
|
|
|
257
|
-
|
|
183
|
+
Tree shaking optimizes the generated output by including only the resources you explicitly need and their dependencies. Instead of generating types for an entire FHIR package (which can contain hundreds of resources), you can specify exactly which resources to include:
|
|
258
184
|
|
|
259
185
|
```typescript
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
includeValueSetHelpers: true,
|
|
267
|
-
},
|
|
268
|
-
},
|
|
269
|
-
});
|
|
270
|
-
```
|
|
271
|
-
|
|
272
|
-
### Value Set Configuration Options
|
|
273
|
-
|
|
274
|
-
- **generateValueSets**: Enable value set generation
|
|
275
|
-
- **valueSetStrengths**: Control which binding strengths generate types (`'required'`, `'preferred'`, `'extensible'`, `'example'`)
|
|
276
|
-
- **includeValueSetHelpers**: Include runtime validation functions
|
|
277
|
-
- **valueSetDirectory**: Customize output directory name
|
|
278
|
-
|
|
279
|
-
For comprehensive usage examples and migration guides, see [Value Set Documentation](docs/features/value-set-generation.md).
|
|
280
|
-
|
|
281
|
-
## Development
|
|
282
|
-
|
|
283
|
-
### Prerequisites
|
|
284
|
-
|
|
285
|
-
- [Bun](https://bun.sh) runtime (v1.0+)
|
|
286
|
-
- Node.js 18+ (for compatibility)
|
|
287
|
-
|
|
288
|
-
### Setup
|
|
289
|
-
|
|
290
|
-
```bash
|
|
291
|
-
# Clone repository
|
|
292
|
-
git clone https://github.com/your-org/atomic-codegen
|
|
293
|
-
cd atomic-codegen
|
|
294
|
-
|
|
295
|
-
# Install dependencies
|
|
296
|
-
bun install
|
|
297
|
-
|
|
298
|
-
# Run tests
|
|
299
|
-
bun test
|
|
300
|
-
|
|
301
|
-
# Build
|
|
302
|
-
bun run build
|
|
186
|
+
.treeShake({
|
|
187
|
+
"hl7.fhir.r4.core#4.0.1": {
|
|
188
|
+
"http://hl7.org/fhir/StructureDefinition/Patient": {},
|
|
189
|
+
"http://hl7.org/fhir/StructureDefinition/Observation": {},
|
|
190
|
+
}
|
|
191
|
+
})
|
|
303
192
|
```
|
|
304
193
|
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
We welcome contributions! Please see our [Contributing Guide](CONTRIBUTING.md) for details.
|
|
308
|
-
|
|
309
|
-
## License
|
|
310
|
-
|
|
311
|
-
MIT © Atomic Healthcare
|
|
194
|
+
This feature automatically resolves and includes all dependencies (referenced types, base resources, nested types) while excluding unused resources, significantly reducing the size of generated code and improving compilation times.
|
|
312
195
|
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
- 📖 [Documentation](https://docs.atomic-ehr.com/codegen)
|
|
316
|
-
- 🐛 [Issue Tracker](https://github.com/atomic-ehr/codegen/issues)
|
|
196
|
+
### Generation
|
|
317
197
|
|
|
318
|
-
|
|
198
|
+
The generation stage uses a `WriterGenerator` system that transforms Type Schema into target language code. The architecture consists of:
|
|
319
199
|
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
### 🔄 REST Client Generation (Q2 2024)
|
|
323
|
-
```typescript
|
|
324
|
-
// Generate type-safe FHIR clients
|
|
325
|
-
await builder
|
|
326
|
-
.fromPackage('hl7.fhir.r4.core', '4.0.1')
|
|
327
|
-
.restClient({
|
|
328
|
-
clientName: 'MyFHIRClient',
|
|
329
|
-
baseUrl: 'https://api.example.com/fhir',
|
|
330
|
-
authType: 'oauth2'
|
|
331
|
-
})
|
|
332
|
-
.generate();
|
|
333
|
-
|
|
334
|
-
// Use generated client
|
|
335
|
-
const client = new MyFHIRClient();
|
|
336
|
-
const patient = await client.Patient.read('123');
|
|
337
|
-
const bundle = await client.Patient.search({ name: 'Smith' });
|
|
338
|
-
```
|
|
200
|
+
- **Base Writer** (`Writer`): Handles file I/O, indentation, and code formatting primitives
|
|
201
|
+
- **Language Writers** (e.g., `TypeScript`): Implement language-specific generation logic
|
|
339
202
|
|
|
340
|
-
|
|
341
|
-
```typescript
|
|
342
|
-
// Intelligent search builders
|
|
343
|
-
const results = await client.Patient
|
|
344
|
-
.search()
|
|
345
|
-
.name().contains('Smith')
|
|
346
|
-
.birthdate().greaterThan('2000-01-01')
|
|
347
|
-
.address().city().equals('Boston')
|
|
348
|
-
.include('Patient:organization')
|
|
349
|
-
.sort('birthdate', 'desc')
|
|
350
|
-
.execute();
|
|
351
|
-
```
|
|
203
|
+
Writers provide high-level abstractions for common code patterns (blocks, imports, type definitions) while maintaining full control over output formatting. Each language writer traverses the Type Schema index and generates corresponding types, interfaces, or classes following that language's idioms and best practices.
|
|
352
204
|
|
|
353
|
-
|
|
354
|
-
```typescript
|
|
355
|
-
// Type-safe FHIR operations
|
|
356
|
-
const result = await client.Patient
|
|
357
|
-
.operation('$match')
|
|
358
|
-
.withParameters({
|
|
359
|
-
resource: patient,
|
|
360
|
-
onlyCertainMatches: true
|
|
361
|
-
})
|
|
362
|
-
.execute();
|
|
363
|
-
```
|
|
205
|
+
- [Type Schema: Python SDK for FHIR](https://www.health-samurai.io/articles/type-schema-python-sdk-for-fhir)
|
|
364
206
|
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
## Current Roadmap
|
|
207
|
+
## Roadmap
|
|
368
208
|
|
|
369
209
|
- [x] TypeScript generation
|
|
370
210
|
- [x] FHIR R4 core package support
|
|
@@ -373,17 +213,44 @@ See our detailed [**ROADMAP.md**](ROADMAP.md) for the complete development plan.
|
|
|
373
213
|
- [x] **Value Set Generation** - Strongly-typed enums from FHIR bindings
|
|
374
214
|
- [~] **Profile & Extension Support** - Basic parsing (US Core in development)
|
|
375
215
|
- [ ] **Complete Multi-Package Support** - Custom packages and dependencies
|
|
376
|
-
- [ ] **REST Client Generation** - Fetch-based FHIR clients
|
|
377
216
|
- [ ] **Smart Chained Search** - Intelligent search builders
|
|
217
|
+
|
|
218
|
+
```typescript
|
|
219
|
+
// Intelligent search builders
|
|
220
|
+
const results = await client.Patient
|
|
221
|
+
.search()
|
|
222
|
+
.name().contains('Smith')
|
|
223
|
+
.birthdate().greaterThan('2000-01-01')
|
|
224
|
+
.address().city().equals('Boston')
|
|
225
|
+
.include('Patient:organization')
|
|
226
|
+
.sort('birthdate', 'desc')
|
|
227
|
+
.execute();
|
|
228
|
+
```
|
|
229
|
+
|
|
378
230
|
- [ ] **Operation Generation** - Type-safe FHIR operations
|
|
231
|
+
|
|
232
|
+
```typescript
|
|
233
|
+
// Type-safe FHIR operations
|
|
234
|
+
const result = await client.Patient
|
|
235
|
+
.operation('$match')
|
|
236
|
+
.withParameters({
|
|
237
|
+
resource: patient,
|
|
238
|
+
onlyCertainMatches: true
|
|
239
|
+
})
|
|
240
|
+
.execute();
|
|
241
|
+
```
|
|
242
|
+
|
|
379
243
|
- [ ] **Python generation**
|
|
380
244
|
- [ ] **Rust generation**
|
|
381
245
|
- [ ] **GraphQL schema generation**
|
|
382
246
|
- [ ] **OpenAPI specification generation**
|
|
383
247
|
- [ ] **Validation functions**
|
|
384
248
|
- [ ] **Mock data generation**
|
|
385
|
-
|
|
249
|
+
|
|
250
|
+
## Support
|
|
251
|
+
|
|
252
|
+
- 🐛 [Issue Tracker](https://github.com/atomic-ehr/codegen/issues)
|
|
386
253
|
|
|
387
254
|
---
|
|
388
255
|
|
|
389
|
-
Built with ❤️
|
|
256
|
+
Built with ❤️ by the Atomic Healthcare team
|
package/package.json
CHANGED