@atomic-ehr/codegen 0.0.1 → 0.0.2-canary.20251114095108.8d8e927

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 CHANGED
@@ -5,8 +5,8 @@ A powerful, extensible code generation toolkit for FHIR (Fast Healthcare Interop
5
5
  ## Features
6
6
 
7
7
  - 🚀 **High-Performance** - Built with Bun runtime for blazing-fast generation
8
- - 🔧 **Extensible Architecture** - Three-stage pipeline (Parse → Transform → Generate)
9
- - 📦 **Multi-Package Support** - Generate from FHIR R4 core packages (profiles in development)
8
+ - 🔧 **Extensible Architecture** - Three-stage pipeline (Resolve Canonicals → Transform to Type Schema → Generate)
9
+ - 📦 **Multi-Package Support** - Generate from a list of FHIR packages (profiles in development)
10
10
  - 🎯 **Type-Safe** - Generates fully typed interfaces with proper inheritance
11
11
  - 🔄 **Intermediate Format** - TypeSchema format enables multi-language support
12
12
  - 🛠️ **Developer Friendly** - Fluent API, CLI, and configuration file support
@@ -26,7 +26,27 @@ yarn add @atomic-ehr/codegen
26
26
 
27
27
  ## Quick Start
28
28
 
29
- ### 1. Using the CLI
29
+ ### 1. Using the Fluent API (Primary)
30
+
31
+ ```typescript
32
+ import { APIBuilder } from '@atomic-ehr/codegen';
33
+
34
+ const builder = new APIBuilder()
35
+ .fromPackage("hl7.fhir.r4.core", "4.0.1")
36
+ .typescript({})
37
+ .outputTo("./examples/typescript-r4/fhir-types");
38
+
39
+ const report = await builder.generate();
40
+ console.log(report);
41
+ ```
42
+
43
+ Run the script by:
44
+
45
+ - `npm exec tsx scripts/generate-types.ts`
46
+ - `pnpm exec tsx scripts/generate-types.ts`
47
+ - `bun run scripts/generate-types.ts`
48
+
49
+ ### 2. Using the CLI (Draft)
30
50
 
31
51
  ```bash
32
52
  # Generate using configuration file
@@ -39,37 +59,7 @@ bunx atomic-codegen generate --verbose
39
59
  bunx atomic-codegen typeschema generate hl7.fhir.r4.core@4.0.1 -o schemas.ndjson
40
60
  ```
41
61
 
42
- ### 2. Using the Fluent API
43
-
44
- ```typescript
45
- import { APIBuilder } from '@atomic-ehr/codegen';
46
-
47
- // Create builder instance
48
- const builder = new APIBuilder();
49
-
50
- // Generate FHIR R4 TypeScript types
51
- await builder
52
- .fromPackage('hl7.fhir.r4.core', '4.0.1')
53
- .typescript({
54
- outputDir: './generated/types',
55
- generateIndex: true,
56
- includeExtensions: false,
57
- })
58
- .generate();
59
-
60
- // Generate with additional configuration
61
- await builder
62
- .fromPackage('hl7.fhir.r4.core', '4.0.1')
63
- .typescript({
64
- outputDir: './generated/fhir',
65
- generateIndex: true,
66
- includeDocuments: true,
67
- namingConvention: 'PascalCase'
68
- })
69
- .generate();
70
- ```
71
-
72
- ### 3. Using Configuration File
62
+ ### 3. Using Configuration File (Draft)
73
63
 
74
64
  Create `atomic-codegen.config.ts`:
75
65
 
@@ -105,19 +95,24 @@ bunx atomic-codegen generate
105
95
 
106
96
  ## Architecture
107
97
 
108
- The toolkit uses a three-stage architecture:
98
+ The toolkit uses a three-stage architecture (details: [link](https://www.health-samurai.io/articles/type-schema-a-pragmatic-approach-to-build-fhir-sdk)):
109
99
 
110
100
  ```
111
- FHIR PackageTypeSchema Parser TypeSchema Format Code Generators → Output
101
+ Resolve CanonicalsTransform to Type SchemaGenerate
112
102
  ```
113
103
 
114
- 1. **Input Layer** - Parses FHIR packages and profiles into TypeSchema format
115
- 2. **Intermediate Format** - TypeSchema provides a universal representation
104
+ 1. **Input Layer** - Parses FHIR packages and profiles, resolves canonicals and transforms them into TypeSchema format
105
+ 2. **Intermediate Format** - TypeSchema provides a universal representation for FHIR data entities
116
106
  3. **Output Generators** - Generate code for TypeScript, Python, and other languages
117
107
 
118
108
  ## Usage Examples
119
109
 
120
- ### Generate Types for a Custom Profile
110
+ Actual examples of type generation and usage can be found here: [examples/typescript-r4](examples/typescript-r4):
111
+
112
+ - `demo.ts` - a simple script which creates resources and demonstrates how to work with profiles.
113
+ - `generate.ts` - script to generate types.
114
+
115
+ ### Generate Types for a Custom Profile (Draft)
121
116
 
122
117
  ```typescript
123
118
  import { APIBuilder } from '@atomic-ehr/codegen';
@@ -135,7 +130,7 @@ await builder
135
130
  .generate();
136
131
  ```
137
132
 
138
- ### Generate with Custom Templates
133
+ ### Generate with Custom Templates (Draft)
139
134
 
140
135
  ```typescript
141
136
  import { APIBuilder } from '@atomic-ehr/codegen';
@@ -154,7 +149,7 @@ await builder
154
149
  .generate();
155
150
  ```
156
151
 
157
- ### Generate Multiple Output Formats
152
+ ### Generate Multiple Output Formats (Draft)
158
153
 
159
154
  ```typescript
160
155
  import { APIBuilder } from '@atomic-ehr/codegen';
@@ -179,52 +174,7 @@ await builder
179
174
  .generate();
180
175
  ```
181
176
 
182
- ### Working with Generated Types
183
-
184
- ```typescript
185
- // Import generated types
186
- import { Patient, Observation, Bundle } from './generated/types';
187
-
188
- // Use with type safety
189
- const patient: Patient = {
190
- resourceType: 'Patient',
191
- id: '123',
192
- name: [{
193
- given: ['John'],
194
- family: 'Doe'
195
- }],
196
- birthDate: '1990-01-01'
197
- };
198
-
199
- // Type-safe resource references
200
- const observation: Observation = {
201
- resourceType: 'Observation',
202
- status: 'final',
203
- code: {
204
- coding: [{
205
- system: 'http://loinc.org',
206
- code: '85354-9',
207
- display: 'Blood pressure'
208
- }]
209
- },
210
- subject: {
211
- reference: 'Patient/123',
212
- type: 'Patient' // Type-checked!
213
- }
214
- };
215
-
216
- // Work with bundles
217
- const bundle: Bundle = {
218
- resourceType: 'Bundle',
219
- type: 'collection',
220
- entry: [
221
- { resource: patient },
222
- { resource: observation }
223
- ]
224
- };
225
- ```
226
-
227
- ## CLI Commands
177
+ ## CLI Commands (Draft)
228
178
 
229
179
  ```bash
230
180
  # Generate code using configuration file
@@ -241,7 +191,7 @@ atomic-codegen --help # Show help
241
191
  atomic-codegen --debug generate # Debug mode
242
192
  ```
243
193
 
244
- ## Configuration Options
194
+ ## Configuration Options (Draft)
245
195
 
246
196
  ### Global Configuration Options
247
197
 
@@ -268,6 +218,7 @@ atomic-codegen --debug generate # Debug mode
268
218
  | `valueSetStrengths` | `string[]` | `['required']` | Which binding strengths to generate |
269
219
  | `includeValueSetHelpers` | `boolean` | `false` | Include validation helper functions |
270
220
  | `valueSetDirectory` | `string` | `'valuesets'` | Output directory for value set files |
221
+
271
222
  ## Value Set Generation
272
223
 
273
224
  Generate strongly-typed TypeScript enums from FHIR value sets for enhanced type safety:
@@ -285,48 +236,6 @@ export default defineConfig({
285
236
  });
286
237
  ```
287
238
 
288
- ### Generated Structure
289
-
290
- ```
291
- generated/
292
- ├── types/
293
- │ ├── Patient.ts # Uses value set types
294
- │ └── Address.ts # Uses value set types
295
- └── valuesets/
296
- ├── AdministrativeGender.ts
297
- ├── AddressUse.ts
298
- └── index.ts # Re-exports all value sets
299
- ```
300
-
301
- ### Type-Safe Usage
302
-
303
- ```typescript
304
- // Import generated types
305
- import { Patient } from './generated/types/Patient.js';
306
- import { AdministrativeGender } from './generated/valuesets/index.js';
307
-
308
- // Type-safe patient creation
309
- const patient: Patient = {
310
- resourceType: 'Patient',
311
- gender: 'male', // Type-safe! Only valid values accepted
312
- // gender: 'invalid', // ❌ Compile error
313
- };
314
- ```
315
-
316
- ### Runtime Validation
317
-
318
- ```typescript
319
- import { isValidAdministrativeGender } from './generated/valuesets/AdministrativeGender.js';
320
-
321
- function validateGender(input: string) {
322
- if (isValidAdministrativeGender(input)) {
323
- // input is now typed as AdministrativeGender
324
- return input;
325
- }
326
- throw new Error(`Invalid gender: ${input}`);
327
- }
328
- ```
329
-
330
239
  ### Value Set Configuration Options
331
240
 
332
241
  - **generateValueSets**: Enable value set generation
@@ -335,71 +244,6 @@ function validateGender(input: string) {
335
244
  - **valueSetDirectory**: Customize output directory name
336
245
 
337
246
  For comprehensive usage examples and migration guides, see [Value Set Documentation](docs/features/value-set-generation.md).
338
- ## Advanced Features
339
-
340
- ### Custom Type Mappings
341
-
342
- ```typescript
343
- const builder = new APIBuilder();
344
-
345
- await builder
346
- .fromPackage('hl7.fhir.r4.core', '4.0.1')
347
- .withTypeMappings({
348
- 'date': 'Date', // Map FHIR date to JS Date
349
- 'instant': 'Date', // Map FHIR instant to JS Date
350
- 'decimal': 'BigNumber' // Use BigNumber for decimals
351
- })
352
- .typescript({ outputDir: './generated' })
353
- .generate();
354
- ```
355
-
356
- ### Selective Generation
357
-
358
- ```typescript
359
- const builder = new APIBuilder();
360
-
361
- // Generate only specific resources
362
- await builder
363
- .fromPackage('hl7.fhir.r4.core', '4.0.1')
364
- .filter({
365
- resources: ['Patient', 'Observation', 'Encounter'],
366
- excludeExtensions: true,
367
- excludeProfiles: true
368
- })
369
- .typescript({ outputDir: './generated' })
370
- .generate();
371
- ```
372
-
373
- ### Plugin System
374
-
375
- ```typescript
376
- import { APIBuilder, Plugin } from '@atomic-ehr/codegen';
377
-
378
- // Create custom plugin
379
- const validatorPlugin: Plugin = {
380
- name: 'validator-plugin',
381
- transform: (schema) => {
382
- // Add validation metadata
383
- return {
384
- ...schema,
385
- validation: generateValidationRules(schema)
386
- };
387
- },
388
- generate: (schema, options) => {
389
- // Generate validator functions
390
- return generateValidators(schema, options);
391
- }
392
- };
393
-
394
- // Use plugin
395
- const builder = new APIBuilder();
396
-
397
- await builder
398
- .fromPackage('hl7.fhir.r4.core', '4.0.1')
399
- .use(validatorPlugin)
400
- .typescript({ outputDir: './generated' })
401
- .generate();
402
- ```
403
247
 
404
248
  ## Development
405
249
 
@@ -425,21 +269,6 @@ bun test
425
269
  bun run build
426
270
  ```
427
271
 
428
- ### Project Structure
429
-
430
- ```
431
- atomic-codegen/
432
- ├── src/
433
- │ ├── api/ # High-level API
434
- │ ├── cli/ # CLI implementation
435
- │ ├── typeschema/ # TypeSchema parser/transformer
436
- │ ├── generators/ # Code generators
437
- │ └── config.ts # Configuration system
438
- ├── test/ # Test suites
439
- ├── examples/ # Usage examples
440
- └── docs/ # Documentation
441
- ```
442
-
443
272
  ## Contributing
444
273
 
445
274
  We welcome contributions! Please see our [Contributing Guide](CONTRIBUTING.md) for details.