Skip to content

Installation

Prerequisites

  • Go 1.23 or later is required. You can check your version with:
go version
  • Your project must use Go modules (go.mod). If you do not have one yet, initialize it:
go mod init your-module-name

Install

Each FHIR version is published as an independent Go module. Install only the version you need.

FHIR R4 (4.0.1)

go get github.com/gofhir/models/r4/v2

FHIR R4B (4.3.0)

go get github.com/gofhir/models/r4b/v2

FHIR R5 (5.0.0)

go get github.com/gofhir/models/r5/v2

R4 Helpers (optional)

The helpers sub-package provides pre-built CodeableConcept values for common observation categories, condition categories, LOINC codes, and UCUM units:

go get github.com/gofhir/models/r4/v2/helpers

Import

After installing, import the package in your Go source files:

import "github.com/gofhir/models/r4/v2"

Or for R4B and R5:

import "github.com/gofhir/models/r4b/v2"
import "github.com/gofhir/models/r5/v2"

All types, builders, code system constants, and serialization functions are exported from the version-specific package. There is no separate sub-package for builders or serialization – everything is in one place.

Using Multiple FHIR Versions

If your application needs to work with more than one FHIR version, you can import multiple packages in the same project. Use Go import aliases to avoid name collisions:

import (
    r4 "github.com/gofhir/models/r4/v2"
    r5 "github.com/gofhir/models/r5/v2"
)

func main() {
    // R4 Patient
    patientR4 := r4.NewPatientBuilder().
        SetId("r4-patient").
        SetActive(true).
        Build()

    // R5 Patient
    patientR5 := r5.NewPatientBuilder().
        SetId("r5-patient").
        SetActive(true).
        Build()

    _, _ = r4.Marshal(patientR4)
    _, _ = r5.Marshal(patientR5)
}

Because each FHIR version is a separate Go module with its own go.mod, dependency versions are resolved independently and never conflict.

Verifying the Installation

Create a simple test file to confirm everything is working:

package main

import (
    "fmt"

    "github.com/gofhir/models/r4/v2"
)

func main() {
    patient := r4.NewPatientBuilder().
        SetId("test").
        Build()
    data, err := r4.Marshal(patient)
    if err != nil {
        panic(err)
    }
    fmt.Println(string(data))
}

Run it:

go run main.go

Expected output:

{"resourceType":"Patient","id":"test"}

Next Steps

Continue to the Quick Start guide to see complete examples of creating, serializing, and deserializing FHIR resources.

Last updated on