Type-safe Go structs for every FHIR R4, R4B, and R5 resource.
Build, serialize, and integrate with fluent builders and JSON serialization.
Complete Go structs for every resource and data type in FHIR R4 (4.0.1), R4B (4.3.0), and R5 (5.0.0). Each version is an independent Go module with its own release cycle.
Create FHIR resources your way: direct struct literals or fluent builder chains. Both produce the same type-safe structs.
Serialize and deserialize resources with full FHIR conformance. HTML-safe JSON marshaling preserves narrative XHTML, and polymorphic contained resources are handled automatically.
Install the package for the FHIR version you need:
go get github.com/gofhir/models/r4/v2Create a Patient resource and serialize it to JSON:
package main
import (
"fmt"
"github.com/gofhir/models/r4/v2"
)
func main() {
patient := r4.NewPatientBuilder().
SetId("example").
SetActive(true).
SetGender(r4.AdministrativeGenderMale).
Build()
data, _ := r4.Marshal(patient)
fmt.Println(string(data))
}Output:
{"resourceType":"Patient","id":"example","active":true,"gender":"male"}