Resource Construction
Resource Construction
The gofhir/models library provides three distinct patterns for creating FHIR resources. All three produce the same Go struct types, so you can mix and match patterns within a single project. Choose the one that best fits your coding style and use case.
Overview
| Pattern | Best For | Verbosity | Compile-time Safety |
|---|---|---|---|
| Struct Literals | Full control, one-shot initialization | Medium (requires pointers) | Full |
| Builder Pattern | Step-by-step construction, fluent chains | Low | Full |
Both patterns set fields on the same underlying struct (for example, r4.Patient), so serialization and deserialization work identically regardless of how the resource was created.
Quick Comparison
Struct Literal
active := true
patient := r4.Patient{
Id: &id,
Active: &active,
}Builder Pattern
patient := r4.NewPatientBuilder().
SetId("patient-1").
SetActive(true).
Build()Guides
Last updated on