Type-safe C# class generation with Aidbox FHIR server integration and comprehensive testing.
This example demonstrates how to generate C# classes from the FHIR R4 specification. It includes:
- Full FHIR R4 resource type definitions as C# classes
- Namespace organization for clean code structure
- Integration tests with Aidbox FHIR server
- Type-safe resource operations (Create, Read, Update, Delete)
From the project root:
cd codegen
bun install
bun run examples/csharp/generate.tsThis will output to ./examples/csharp/generated/
cd examples/csharp
dotnet restorecurl -JO https://aidbox.app/runme && docker compose upThis will start Aidbox FHIR server on http://localhost:8080
Edit generate.ts to customize:
.csharp({
rootNamespace: "FhirTypes",
})- Get your Aidbox credentials from
docker-compose.yaml:- Look for
BOX_ROOT_CLIENT_SECRETvalue - Update the password in
TestSdk.cs:
- Look for
private const string Password = "your-secret-here";- Ensure Aidbox is running:
docker compose upRun all tests:
dotnet testusing FhirTypes;
var patient = new Patient
{
ResourceType = "Patient",
Id = "patient-1",
Name = new List<HumanName>
{
new HumanName
{
Use = "official",
Family = "Doe",
Given = new List<string> { "John" }
}
},
Gender = "male",
BirthDate = "1990-01-01"
};using System.Text.Json;
var options = new JsonSerializerOptions
{
PropertyNamingPolicy = JsonNamingPolicy.CamelCase,
};
var json = JsonSerializer.Serialize(patient, options);
var deserialized = JsonSerializer.Deserialize<Patient>(json, options);