# ohs-foundation/kotlin-fhir architecture

> Architecture diagram of the GitHub repository ohs-foundation/kotlin-fhir, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-10-18). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/ohs-foundation/kotlin-fhir
- Repository: https://github.com/ohs-foundation/kotlin-fhir

## Overview

Kotlin FHIR is a multiplatform library for representing FHIR resources across R4, R4B, and R5, with JSON serialization and generated model code. The principal workflow is to use a version-specific model to represent FHIR data and serialize it; generated search-parameter definitions support searching resource fields. A Gradle code-generation plugin produces model sources from FHIR specifications. The excerpts show resource fields, builder conversion, search extractors, and serializer encoding/decoding; links between broader subsystems rely on README statements where noted.

Main entry points: [`fhir-codegen/gradle-plugin/src/main/kotlin/dev/ohs/fhir/codegen/FhirCodegen.kt`](https://github.com/ohs-foundation/kotlin-fhir/blob/main/fhir-codegen/gradle-plugin/src/main/kotlin/dev/ohs/fhir/codegen/FhirCodegen.kt) (Code generator), [`fhir-model-r4/src/commonMain/kotlin/dev/ohs/fhir/model/r4`](https://github.com/ohs-foundation/kotlin-fhir/tree/main/fhir-model-r4/src/commonMain/kotlin/dev/ohs/fhir/model/r4) (Resource models), [`fhir-model-r4b/src/commonMain/kotlin/dev/ohs/fhir/model/r4b`](https://github.com/ohs-foundation/kotlin-fhir/tree/main/fhir-model-r4b/src/commonMain/kotlin/dev/ohs/fhir/model/r4b) (Resource models), [`fhir-model-r5/src/commonMain/kotlin/dev/ohs/fhir/model/r5`](https://github.com/ohs-foundation/kotlin-fhir/tree/main/fhir-model-r5/src/commonMain/kotlin/dev/ohs/fhir/model/r5) (Resource models)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_codegen["Code generation"]
  node_generator["Code generator<br/>[FhirCodegen.kt]"]
end

subgraph group_r4["FHIR R4"]
  node_r4models["Resource models"]
  node_r4search["Search parameters"]
  node_r4serial["JSON serializers"]
end

subgraph group_r4b["FHIR R4B"]
  node_r4bmodels["Resource models"]
  node_r4bsearch["Search parameters"]
  node_r4bserial["JSON serializers"]
end

subgraph group_r5["FHIR R5"]
  node_r5models["Resource models"]
  node_r5search["Search parameters"]
  node_r5serial["JSON serializers"]
end

node_specifications["FHIR specifications"]
node_consumer(("Kotlin application"))

node_specifications -->|"generates from"| node_generator
node_generator -->|"generates models"| node_r4models
node_generator -->|"generates models"| node_r4bmodels
node_generator -->|"generates models"| node_r5models
node_consumer -->|"uses"| node_r4models
node_consumer -->|"uses"| node_r4bmodels
node_consumer -->|"uses"| node_r5models
node_r4models -.->|"serializes as"| node_r4serial
node_r4bmodels -.->|"serializes as"| node_r4bserial
node_r5models -.->|"serializes as"| node_r5serial
node_r4search -->|"extracts fields"| node_r4models
node_r4bsearch -->|"extracts fields"| node_r4bmodels
node_r5search -->|"extracts fields"| node_r5models

click node_generator "https://github.com/ohs-foundation/kotlin-fhir/blob/main/fhir-codegen/gradle-plugin/src/main/kotlin/dev/ohs/fhir/codegen/FhirCodegen.kt"
click node_r4models "https://github.com/ohs-foundation/kotlin-fhir/tree/main/fhir-model-r4/src/commonMain/kotlin/dev/ohs/fhir/model/r4"
click node_r4search "https://github.com/ohs-foundation/kotlin-fhir/tree/main/fhir-model-r4/src/commonMain/kotlin/dev/ohs/fhir/model/r4/search"
click node_r4serial "https://github.com/ohs-foundation/kotlin-fhir/tree/main/fhir-model-r4/src/commonMain/kotlin/dev/ohs/fhir/model/r4/serializers"
click node_r4bmodels "https://github.com/ohs-foundation/kotlin-fhir/tree/main/fhir-model-r4b/src/commonMain/kotlin/dev/ohs/fhir/model/r4b"
click node_r4bsearch "https://github.com/ohs-foundation/kotlin-fhir/tree/main/fhir-model-r4b/src/commonMain/kotlin/dev/ohs/fhir/model/r4b/search"
click node_r4bserial "https://github.com/ohs-foundation/kotlin-fhir/tree/main/fhir-model-r4b/src/commonMain/kotlin/dev/ohs/fhir/model/r4b/serializers"
click node_r5models "https://github.com/ohs-foundation/kotlin-fhir/tree/main/fhir-model-r5/src/commonMain/kotlin/dev/ohs/fhir/model/r5"
click node_r5search "https://github.com/ohs-foundation/kotlin-fhir/tree/main/fhir-model-r5/src/commonMain/kotlin/dev/ohs/fhir/model/r5/search"
click node_r5serial "https://github.com/ohs-foundation/kotlin-fhir/tree/main/fhir-model-r5/src/commonMain/kotlin/dev/ohs/fhir/model/r5/serializers"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_generator toneBlue
class node_r4models,node_r4search,node_r4serial toneAmber
class node_r4bmodels,node_r4bsearch,node_r4bserial toneMint
class node_r5models,node_r5search,node_r5serial toneRose
class node_specifications,node_consumer toneIndigo
```

## Components

### Code generation

- [Code generator](https://github.com/ohs-foundation/kotlin-fhir/blob/main/fhir-codegen/gradle-plugin/src/main/kotlin/dev/ohs/fhir/codegen/FhirCodegen.kt): `fhir-codegen/gradle-plugin/src/main/kotlin/dev/ohs/fhir/codegen/FhirCodegen.kt`

### FHIR R4

- [Resource models](https://github.com/ohs-foundation/kotlin-fhir/tree/main/fhir-model-r4/src/commonMain/kotlin/dev/ohs/fhir/model/r4): `fhir-model-r4/src/commonMain/kotlin/dev/ohs/fhir/model/r4`
- [Search parameters](https://github.com/ohs-foundation/kotlin-fhir/tree/main/fhir-model-r4/src/commonMain/kotlin/dev/ohs/fhir/model/r4/search): `fhir-model-r4/src/commonMain/kotlin/dev/ohs/fhir/model/r4/search`
- [JSON serializers](https://github.com/ohs-foundation/kotlin-fhir/tree/main/fhir-model-r4/src/commonMain/kotlin/dev/ohs/fhir/model/r4/serializers): `fhir-model-r4/src/commonMain/kotlin/dev/ohs/fhir/model/r4/serializers`

### FHIR R4B

- [Resource models](https://github.com/ohs-foundation/kotlin-fhir/tree/main/fhir-model-r4b/src/commonMain/kotlin/dev/ohs/fhir/model/r4b): `fhir-model-r4b/src/commonMain/kotlin/dev/ohs/fhir/model/r4b`
- [Search parameters](https://github.com/ohs-foundation/kotlin-fhir/tree/main/fhir-model-r4b/src/commonMain/kotlin/dev/ohs/fhir/model/r4b/search): `fhir-model-r4b/src/commonMain/kotlin/dev/ohs/fhir/model/r4b/search`
- [JSON serializers](https://github.com/ohs-foundation/kotlin-fhir/tree/main/fhir-model-r4b/src/commonMain/kotlin/dev/ohs/fhir/model/r4b/serializers): `fhir-model-r4b/src/commonMain/kotlin/dev/ohs/fhir/model/r4b/serializers`

### FHIR R5

- [Resource models](https://github.com/ohs-foundation/kotlin-fhir/tree/main/fhir-model-r5/src/commonMain/kotlin/dev/ohs/fhir/model/r5): `fhir-model-r5/src/commonMain/kotlin/dev/ohs/fhir/model/r5`
- [Search parameters](https://github.com/ohs-foundation/kotlin-fhir/tree/main/fhir-model-r5/src/commonMain/kotlin/dev/ohs/fhir/model/r5/search): `fhir-model-r5/src/commonMain/kotlin/dev/ohs/fhir/model/r5/search`
- [JSON serializers](https://github.com/ohs-foundation/kotlin-fhir/tree/main/fhir-model-r5/src/commonMain/kotlin/dev/ohs/fhir/model/r5/serializers): `fhir-model-r5/src/commonMain/kotlin/dev/ohs/fhir/model/r5/serializers`

### Other components

- **FHIR specifications**
- **Kotlin application**

## Connections

- FHIR specifications → Code generator: generates from (evidence: `README.md`)
- Code generator → Resource models: generates models (evidence: `README.md`)
- Code generator → Resource models: generates models (evidence: `README.md`)
- Code generator → Resource models: generates models (evidence: `README.md`)
- Kotlin application → Resource models: uses (evidence: `README.md`)
- Kotlin application → Resource models: uses (evidence: `README.md`)
- Kotlin application → Resource models: uses (evidence: `README.md`)
- Resource models → JSON serializers: serializes as (evidence: `fhir-model-r4/src/commonMain/kotlin/dev/ohs/fhir/model/r4/DateTime.kt`)
- Resource models → JSON serializers: serializes as (evidence: `fhir-model-r4b/src/commonMain/kotlin/dev/ohs/fhir/model/r4b/DateTime.kt`)
- Resource models → JSON serializers: serializes as (evidence: `fhir-model-r5/src/commonMain/kotlin/dev/ohs/fhir/model/r5/serializers/TaskSerializers.kt`)
- Search parameters → Resource models: extracts fields (evidence: `fhir-model-r4/src/commonMain/kotlin/dev/ohs/fhir/model/r4/search/ServiceRequestSearchParams.kt`)
- Search parameters → Resource models: extracts fields (evidence: `fhir-model-r4b/src/commonMain/kotlin/dev/ohs/fhir/model/r4b/search/ServiceRequestSearchParams.kt`)
- Search parameters → Resource models: extracts fields (evidence: `fhir-model-r5/src/commonMain/kotlin/dev/ohs/fhir/model/r5/search/ServiceRequestSearchParams.kt`)
