Skip to content

Commit a8ff690

Browse files
committed
wip
1 parent 14c0474 commit a8ff690

7 files changed

Lines changed: 193 additions & 865 deletions

File tree

examples/README.md

Lines changed: 89 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -6,44 +6,66 @@ This directory contains working examples demonstrating the capabilities of Atomi
66

77
### TypeScript Generation
88

9-
- **[typescript-r4/](typescript-r4/)** - FHIR R4 core type generation
10-
- `generate.ts` - Generates TypeScript interfaces for FHIR R4 specification
11-
- `demo.ts` - Demonstrates resource creation, profile usage (bodyweight), and bundle composition
12-
- Shows how to use `attach` and `extract` functions for FHIR profiles
9+
- **[typescript-r4/](typescript-r4/)** - FHIR R4 core type generation ✅ Code included
10+
- Full FHIR R4 resource type definitions with profiles and bundles
11+
- Demonstrates `attach` and `extract` functions for FHIR profiles
12+
- Includes demo showing resource creation and bundle composition
1313

14-
- **[typescript-ccda/](typescript-ccda/)** - C-CDA on FHIR type generation
15-
- `generate.ts` - Generates types from HL7 CDA UV Core package (`hl7.cda.uv.core@2.0.1-sd`)
16-
- Exports TypeSchema files and dependency tree
14+
- **[typescript-ccda/](typescript-ccda/)** - C-CDA on FHIR type generation ✅ Code included
15+
- HL7 CDA UV Core package (`hl7.cda.uv.core@2.0.1-sd`)
16+
- Document structure and clinical content models
1717

18-
- **[typescript-sql-on-fhir/](typescript-sql-on-fhir/)** - SQL on FHIR ViewDefinition types
19-
- `generate.ts` - Generates types from remote TGZ package
20-
- Demonstrates tree shaking to include only specific resources
18+
- **[typescript-sql-on-fhir/](typescript-sql-on-fhir/)** - SQL on FHIR ViewDefinition types ✅ Code included
19+
- Remote TGZ package loading from build.fhir.org
20+
- Demonstrates tree shaking to include only ViewDefinition
21+
- Shows SQL-on-FHIR view definition patterns
2122

22-
### Multi-Language Generation
23+
- **[local-package-folder/](local-package-folder/)** - Custom FHIR packages from local files ✅ Code included
24+
- Load unpublished StructureDefinitions from disk
25+
- Combine local and published packages
26+
- Dependency resolution with FHIR R4 core
27+
- Tree shaking for custom logical models
2328

24-
- **[python/](python/)** - Python/Pydantic model generation
25-
- `generate.ts` - Generates Python models with configurable field formats
26-
- Supports `snake_case` or `camelCase` field naming
27-
- Configurable extra field validation
29+
### Python Generation
2830

29-
- **[csharp/](csharp/)** - C# class generation
30-
- `generate.ts` - Generates C# classes with custom namespace
31-
- Includes static files for base functionality
32-
- Includes integration tests with Aidbox FHIR server
31+
- **[python/](python/)** - Python/Pydantic model generation ✅ Code included
32+
- Full FHIR R4 as Pydantic models
33+
- Configurable field formats (`snake_case` or `camelCase`)
34+
- Automatic validation and serialization with Pydantic
35+
- Virtual environment setup instructions
3336

34-
### Local Package Support
37+
### C# Generation
3538

36-
- **[local-package-folder/](local-package-folder/)** - Working with unpublished FHIR packages
37-
- `generate.ts` - Loads local StructureDefinitions from disk
38-
- Demonstrates dependency resolution with FHIR R4 core
39-
- Shows tree shaking for custom logical models
39+
- **[csharp/](csharp/)** - C# class generation ✅ Code included
40+
- Full FHIR R4 as C# classes
41+
- Custom namespace support
42+
- Integration tests with Aidbox FHIR server
4043

41-
## Running Examples
44+
## Prerequisites
4245

43-
Each example contains a `generate.ts` script that can be run with:
46+
- **Bun 1.0+** or Node.js 18+
47+
- **RAM**: 1GB+ minimum, 2GB+ recommended for full R4 package generation
48+
- **Python 3.10+** (for Python example only)
49+
- **.NET 6.0+** (for C# example only)
50+
- **Docker & Docker Compose** (optional, for C# Aidbox integration tests)
51+
52+
## Quick Start
53+
54+
### Setup
55+
56+
From the project root:
57+
58+
```bash
59+
cd codegen
60+
bun install
61+
```
62+
63+
### Generate Types
64+
65+
Run any example with:
4466

4567
```bash
46-
# Using Bun
68+
# Using Bun (recommended)
4769
bun run examples/typescript-r4/generate.ts
4870

4971
# Using Node with tsx
@@ -53,23 +75,52 @@ npx tsx examples/typescript-r4/generate.ts
5375
npx ts-node examples/typescript-r4/generate.ts
5476
```
5577

56-
To run the TypeScript R4 demo after generation:
78+
Replace `typescript-r4` with any example name:
79+
- `typescript-ccda`
80+
- `typescript-sql-on-fhir`
81+
- `local-package-folder`
82+
- `python`
83+
- `csharp`
5784

58-
```bash
59-
bun run examples/typescript-r4/demo.ts
85+
## Generated Output Structure
86+
87+
Each example generates output following this pattern:
88+
89+
```
90+
example/
91+
├── README.md # Example-specific guide
92+
├── generate.ts # Generation script
93+
├── generated/ # Output (created after generation)
94+
│ ├── index.ts/py/cs # Main exports
95+
│ ├── resources/ # FHIR resources
96+
│ ├── types/ # Complex types
97+
│ └── enums/ # Value set enums
98+
└── [language-specific files] # requirements.txt, .csproj, etc.
6099
```
61100

62-
## Prerequisites for C# Example
101+
## Integration Examples
63102

64-
The C# example includes integration tests with Aidbox FHIR server. To run the tests:
103+
Add to your build pipeline
65104

66105
```bash
67-
# Start Aidbox server
68-
docker compose up
106+
#!/bin/bash
107+
# scripts/generate-fhir-types.sh
108+
cd codegen
109+
bun run examples/typescript-r4/generate.ts
110+
```
69111

70-
# In another terminal, run the C# tests
71-
cd examples/csharp
72-
dotnet test
112+
```json
113+
{
114+
"scripts": {
115+
"generate:types": "bash scripts/generate-fhir-types.sh",
116+
"prebuild": "npm run generate:types"
117+
}
118+
}
73119
```
74120

75-
See [examples/csharp/README.md](csharp/README.md) for detailed setup instructions.
121+
## Support
122+
123+
For issues or questions:
124+
- Check main [README.md](../README.md)
125+
- Review [CONTRIBUTING.md](../CONTRIBUTING.md)
126+
- Open an issue on GitHub

examples/csharp/README.md

Lines changed: 32 additions & 108 deletions
Original file line numberDiff line numberDiff line change
@@ -4,26 +4,16 @@ Type-safe C# class generation with Aidbox FHIR server integration and comprehens
44

55
## Overview
66

7-
This example demonstrates how to generate C# classes from the FHIR R4 specification using the Atomic EHR Codegen toolkit. It includes:
7+
This example demonstrates how to generate C# classes from the FHIR R4 specification. It includes:
88

99
- Full FHIR R4 resource type definitions as C# classes
1010
- Namespace organization for clean code structure
1111
- Integration tests with Aidbox FHIR server
12-
- Synchronous client for server communication
1312
- Type-safe resource operations (Create, Read, Update, Delete)
1413

1514
## Setup
1615

17-
### Prerequisites
18-
19-
- .NET 6.0+
20-
- Docker and Docker Compose (for Aidbox integration tests)
21-
- Bun 1.0+ or Node.js 18+ (for generation)
22-
- 2GB+ available RAM (for full R4 package generation)
23-
24-
### Installation
25-
26-
#### 1. Generate C# Types
16+
### Generate C# Types
2717

2818
From the project root:
2919

@@ -33,66 +23,64 @@ bun install
3323
bun run examples/csharp/generate.ts
3424
```
3525

36-
This will:
37-
1. Download the `hl7.fhir.r4.core@4.0.1` package
38-
2. Transform it to TypeSchema format
39-
3. Generate C# classes with namespace `FhirTypes`
40-
4. Output to `./examples/csharp/generated/`
26+
This will output to `./examples/csharp/generated/`
4127

42-
#### 2. Install .NET Dependencies
28+
### Install .NET Dependencies
4329

4430
```bash
4531
cd examples/csharp
4632
dotnet restore
4733
```
4834

49-
#### 3. Start Aidbox Server (for testing)
35+
### Start Aidbox Server (for testing)
5036

5137
```bash
52-
# From examples/csharp directory
5338
curl -JO https://aidbox.app/runme && docker compose up
5439
```
5540

56-
This will:
57-
- Start Aidbox FHIR server on `http://localhost:8080`
58-
- Open license setup at `http://localhost:8888` (first run only)
59-
- Wait until "Aidbox is ready!" message appears
41+
This will start Aidbox FHIR server on `http://localhost:8080`
6042

61-
#### 4. Get Aidbox Credentials
43+
## Configuration
6244

63-
After Aidbox starts:
45+
Edit `generate.ts` to customize:
6446

65-
```bash
66-
# Find the root client secret in docker-compose.yaml
67-
grep "BOX_ROOT_CLIENT_SECRET" docker-compose.yaml
47+
```typescript
48+
.csharp({
49+
rootNamespace: "FhirTypes",
50+
})
6851
```
6952

70-
Update `TestSdk.cs` with the credential:
53+
### Tree Shaking
7154

72-
```csharp
73-
private const string Password = "your-secret-here";
55+
To generate only specific resources:
56+
57+
```typescript
58+
.treeShake({
59+
"hl7.fhir.r4.core#4.0.1": {
60+
"http://hl7.org/fhir/StructureDefinition/Patient": {},
61+
"http://hl7.org/fhir/StructureDefinition/Observation": {},
62+
}
63+
})
7464
```
7565

76-
## Testing Code using Aidbox
66+
## Testing with Aidbox
7767

7868
### Configuration
7969

80-
1. **Get your Aidbox credentials** from `docker-compose.yaml`:
70+
1. Get your Aidbox credentials from `docker-compose.yaml`:
8171
- Look for `BOX_ROOT_CLIENT_SECRET` value
8272
- Update the password in `TestSdk.cs`:
8373

8474
```csharp
8575
private const string Password = "your-secret-here";
8676
```
8777

88-
2. **Ensure Aidbox is running**:
78+
2. Ensure Aidbox is running:
8979

9080
```bash
9181
docker compose up
9282
```
9383

94-
- FHIR server should be accessible at `http://localhost:8080`
95-
9684
### Running Tests
9785

9886
Run all tests:
@@ -103,7 +91,7 @@ dotnet test
10391

10492
### Available Tests
10593

106-
The test suite includes comprehensive CRUD operations:
94+
The test suite includes CRUD operations:
10795

10896
- **TestCreatePatient** - Creates a new patient resource
10997
- **TestReadPatient** - Retrieves an existing patient by ID
@@ -112,52 +100,11 @@ The test suite includes comprehensive CRUD operations:
112100
- **TestSearchPatient** - Searches for patients by name
113101
- **TestJsonSerialization** - Validates JSON serialization/deserialization
114102
- **TestResourceMapping** - Verifies resource type mapping
115-
- **TestEnumFields** - Tests enum field definitions across resources
116-
117-
## Usage
103+
- **TestEnumFields** - Tests enum field definitions
118104

119-
### SDK Generation Configuration
105+
## Using Generated Types
120106

121-
The `generate.ts` script configures code generation using APIBuilder:
122-
123-
```typescript
124-
const builder = new APIBuilder()
125-
.fromPackage("hl7.fhir.r4.core", "4.0.1")
126-
.csharp({
127-
rootNamespace: "FhirTypes",
128-
})
129-
.outputTo("./examples/csharp/generated")
130-
.cleanOutput(true);
131-
132-
const report = await builder.generate();
133-
```
134-
135-
### Customization Options
136-
137-
Modify `generate.ts` to customize generation:
138-
139-
```typescript
140-
.csharp({
141-
rootNamespace: "YourNamespace", // Root namespace for generated classes
142-
})
143-
```
144-
145-
### Advanced: Tree Shaking
146-
147-
To generate only specific resources (reduces output size):
148-
149-
```typescript
150-
.treeShake({
151-
"hl7.fhir.r4.core#4.0.1": {
152-
"http://hl7.org/fhir/StructureDefinition/Patient": {},
153-
"http://hl7.org/fhir/StructureDefinition/Observation": {},
154-
}
155-
})
156-
```
157-
158-
### Working with FHIR Resources
159-
160-
The SDK provides strongly-typed classes for all FHIR resources. Here's an example of creating a Patient:
107+
### Create Resources
161108

162109
```csharp
163110
using FhirTypes;
@@ -194,21 +141,6 @@ var json = JsonSerializer.Serialize(patient, options);
194141
var deserialized = JsonSerializer.Deserialize<Patient>(json, options);
195142
```
196143

197-
## File Structure
198-
199-
```
200-
csharp/
201-
├── README.md # This file
202-
├── generate.ts # Type generation script
203-
├── csharp.csproj # C# project file
204-
├── TestSdk.cs # Integration tests with Aidbox
205-
├── docker-compose.yaml # Aidbox configuration
206-
├── generated/ # Generated types (created after generation)
207-
│ ├── FhirTypes/ # Generated C# classes
208-
│ └── ... # Other generated files
209-
└── obj/ # Build artifacts
210-
```
211-
212144
## Development
213145

214146
### Build the Project
@@ -217,21 +149,13 @@ csharp/
217149
dotnet build
218150
```
219151

220-
### Run Tests
221-
222-
```bash
223-
dotnet test
224-
```
225-
226152
### Run Tests with Output
227153

228154
```bash
229155
dotnet test --verbosity normal
230156
```
231157

232-
## Support
158+
## Next Steps
233159

234-
For issues or questions:
235-
- Check [README.md](../../README.md) for general information
236-
- Review [CONTRIBUTING.md](../../CONTRIBUTING.md) for development setup
237-
- Open an issue on [GitHub](https://github.com/atomic-ehr/codegen/issues)
160+
- See [examples/](../) overview for other language examples
161+
- Check [../../CLAUDE.md](../../CLAUDE.md) for architecture details

0 commit comments

Comments
 (0)