@atomic-ehr/codegen 0.0.4-canary.20251217144707.ef99bf1 → 0.0.4-canary.20251218111944.d18e50d
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/README.md +177 -284
- package/dist/cli/index.js +10 -10
- package/dist/index.d.ts +6 -5
- package/dist/index.js +931 -855
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
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,178 @@ 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
|
-
|
|
170
|
+
### Intermediate - Type Schema
|
|
165
171
|
|
|
166
|
-
|
|
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:
|
|
167
173
|
|
|
168
|
-
|
|
169
|
-
|
|
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
|
|
170
178
|
|
|
171
|
-
|
|
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).
|
|
172
180
|
|
|
173
|
-
|
|
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
|
-
```
|
|
181
|
+
#### Tree Shaking
|
|
184
182
|
|
|
185
|
-
|
|
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:
|
|
186
184
|
|
|
187
185
|
```typescript
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
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
|
|
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
|
+
})
|
|
225
192
|
```
|
|
226
193
|
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
### Global Configuration Options
|
|
230
|
-
|
|
231
|
-
| Option | Type | Default | Description |
|
|
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"`) |
|
|
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.
|
|
238
195
|
|
|
239
|
-
|
|
196
|
+
##### Field-Level Tree Shaking
|
|
240
197
|
|
|
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 |
|
|
254
|
-
|
|
255
|
-
## Value Set Generation
|
|
256
|
-
|
|
257
|
-
Generate strongly-typed TypeScript enums from FHIR value sets for enhanced type safety:
|
|
198
|
+
Beyond resource-level filtering, tree shaking supports fine-grained field selection using `selectFields` (whitelist) or `ignoreFields` (blacklist):
|
|
258
199
|
|
|
259
200
|
```typescript
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
generateValueSets: true,
|
|
265
|
-
valueSetStrengths: ['required', 'preferred'],
|
|
266
|
-
includeValueSetHelpers: true,
|
|
201
|
+
.treeShake({
|
|
202
|
+
"hl7.fhir.r4.core#4.0.1": {
|
|
203
|
+
"http://hl7.org/fhir/StructureDefinition/Patient": {
|
|
204
|
+
selectFields: ["id", "name", "birthDate", "gender"]
|
|
267
205
|
},
|
|
268
|
-
|
|
269
|
-
|
|
206
|
+
"http://hl7.org/fhir/StructureDefinition/Observation": {
|
|
207
|
+
ignoreFields: ["performer", "note"]
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
})
|
|
270
211
|
```
|
|
271
212
|
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
-
|
|
275
|
-
- **
|
|
276
|
-
- **includeValueSetHelpers**: Include runtime validation functions
|
|
277
|
-
- **valueSetDirectory**: Customize output directory name
|
|
213
|
+
**Configuration Rules:**
|
|
214
|
+
- `selectFields`: Only includes the specified fields (whitelist approach)
|
|
215
|
+
- `ignoreFields`: Removes specified fields, keeps everything else (blacklist approach)
|
|
216
|
+
- These options are **mutually exclusive** - you cannot use both in the same rule
|
|
278
217
|
|
|
279
|
-
|
|
218
|
+
**Polymorphic Field Handling:**
|
|
280
219
|
|
|
281
|
-
|
|
220
|
+
FHIR choice types (like `multipleBirth[x]` which can be boolean or integer) are handled intelligently. Selecting/ignoring the base field affects all variants, while targeting specific variants only affects those types.
|
|
282
221
|
|
|
283
|
-
###
|
|
222
|
+
### Generation
|
|
284
223
|
|
|
285
|
-
|
|
286
|
-
- Node.js 18+ (for compatibility)
|
|
224
|
+
The generation stage uses a `WriterGenerator` system that transforms Type Schema into target language code. The architecture consists of:
|
|
287
225
|
|
|
288
|
-
|
|
226
|
+
- **Base Writer** (`Writer`): Handles file I/O, indentation, and code formatting primitives
|
|
227
|
+
- **Language Writers** (e.g., `TypeScript`): Implement language-specific generation logic
|
|
289
228
|
|
|
290
|
-
|
|
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
|
|
303
|
-
```
|
|
229
|
+
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.
|
|
304
230
|
|
|
305
|
-
|
|
231
|
+
- [Type Schema: Python SDK for FHIR](https://www.health-samurai.io/articles/type-schema-python-sdk-for-fhir)
|
|
306
232
|
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
## License
|
|
310
|
-
|
|
311
|
-
MIT © Atomic Healthcare
|
|
312
|
-
|
|
313
|
-
## Support
|
|
314
|
-
|
|
315
|
-
- 📖 [Documentation](https://docs.atomic-ehr.com/codegen)
|
|
316
|
-
- 🐛 [Issue Tracker](https://github.com/atomic-ehr/codegen/issues)
|
|
317
|
-
|
|
318
|
-
## Next Steps: REST Client & Advanced Features
|
|
319
|
-
|
|
320
|
-
We're expanding beyond type generation to create a complete FHIR development toolkit:
|
|
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
|
-
```
|
|
339
|
-
|
|
340
|
-
### 🔍 Smart Chained Search (Q3 2024)
|
|
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
|
-
```
|
|
352
|
-
|
|
353
|
-
### ⚡ Operation Generation (Q4 2024)
|
|
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
|
-
```
|
|
364
|
-
|
|
365
|
-
See our detailed [**ROADMAP.md**](ROADMAP.md) for the complete development plan.
|
|
366
|
-
|
|
367
|
-
## Current Roadmap
|
|
233
|
+
## Roadmap
|
|
368
234
|
|
|
369
235
|
- [x] TypeScript generation
|
|
370
236
|
- [x] FHIR R4 core package support
|
|
@@ -373,17 +239,44 @@ See our detailed [**ROADMAP.md**](ROADMAP.md) for the complete development plan.
|
|
|
373
239
|
- [x] **Value Set Generation** - Strongly-typed enums from FHIR bindings
|
|
374
240
|
- [~] **Profile & Extension Support** - Basic parsing (US Core in development)
|
|
375
241
|
- [ ] **Complete Multi-Package Support** - Custom packages and dependencies
|
|
376
|
-
- [ ] **REST Client Generation** - Fetch-based FHIR clients
|
|
377
242
|
- [ ] **Smart Chained Search** - Intelligent search builders
|
|
243
|
+
|
|
244
|
+
```typescript
|
|
245
|
+
// Intelligent search builders
|
|
246
|
+
const results = await client.Patient
|
|
247
|
+
.search()
|
|
248
|
+
.name().contains('Smith')
|
|
249
|
+
.birthdate().greaterThan('2000-01-01')
|
|
250
|
+
.address().city().equals('Boston')
|
|
251
|
+
.include('Patient:organization')
|
|
252
|
+
.sort('birthdate', 'desc')
|
|
253
|
+
.execute();
|
|
254
|
+
```
|
|
255
|
+
|
|
378
256
|
- [ ] **Operation Generation** - Type-safe FHIR operations
|
|
257
|
+
|
|
258
|
+
```typescript
|
|
259
|
+
// Type-safe FHIR operations
|
|
260
|
+
const result = await client.Patient
|
|
261
|
+
.operation('$match')
|
|
262
|
+
.withParameters({
|
|
263
|
+
resource: patient,
|
|
264
|
+
onlyCertainMatches: true
|
|
265
|
+
})
|
|
266
|
+
.execute();
|
|
267
|
+
```
|
|
268
|
+
|
|
379
269
|
- [ ] **Python generation**
|
|
380
270
|
- [ ] **Rust generation**
|
|
381
271
|
- [ ] **GraphQL schema generation**
|
|
382
272
|
- [ ] **OpenAPI specification generation**
|
|
383
273
|
- [ ] **Validation functions**
|
|
384
274
|
- [ ] **Mock data generation**
|
|
385
|
-
|
|
275
|
+
|
|
276
|
+
## Support
|
|
277
|
+
|
|
278
|
+
- 🐛 [Issue Tracker](https://github.com/atomic-ehr/codegen/issues)
|
|
386
279
|
|
|
387
280
|
---
|
|
388
281
|
|
|
389
|
-
Built with ❤️
|
|
282
|
+
Built with ❤️ by the Atomic Healthcare team
|