@@ -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
2818From the project root:
2919
@@ -33,66 +23,64 @@ bun install
3323bun 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
4531cd examples/csharp
4632dotnet restore
4733```
4834
49- #### 3. Start Aidbox Server (for testing)
35+ ### Start Aidbox Server (for testing)
5036
5137``` bash
52- # From examples/csharp directory
5338curl -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
8575private const string Password = " your-secret-here" ;
8676```
8777
88- 2 . ** Ensure Aidbox is running** :
78+ 2 . Ensure Aidbox is running:
8979
9080``` bash
9181docker compose up
9282```
9383
94- - FHIR server should be accessible at ` http://localhost:8080 `
95-
9684### Running Tests
9785
9886Run 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
163110using FhirTypes ;
@@ -194,21 +141,6 @@ var json = JsonSerializer.Serialize(patient, options);
194141var 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/
217149dotnet build
218150```
219151
220- ### Run Tests
221-
222- ``` bash
223- dotnet test
224- ```
225-
226152### Run Tests with Output
227153
228154``` bash
229155dotnet 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