fhir
Type-safe FHIR resources and client
FHIR® (Fast Healthcare Interoperability Resources) is a standard for health care data exchange, published by HL7®. Gleam is simple and type-safe, making FHIR resource features like cardinality and choice types easy to work with.
Features
- Supports R4, R4B, R5
- Gleam types for FHIR data types and resources
- Primitive types to represent valid FHIR date, dateTime, instant, time
- JSON encoder and to_json functions
- Enums for valuesets with required binding
- Sans-io request/response for Create, Read, Update, Delete, Search
- Client layers over sans-io for easy use on Erlang target and Lustre apps
- Primitive extensions, optionally generated for each type
- Standard extension on all complex type, and optionally type safe extension generation for specific extension
Quick Start
gleam new hello_fhir && cd hello_fhir && gleam add fhir
//In hello_fhir.gleam
import fhir/r4us
import fhir/r4us_httpc
import fhir/r4us_valuesets
import gleam/option.{Some}
pub fn main() {
let joe =
r4us.Patient(
..r4us.patient_new(),
identifier: [
r4us.Identifier(
..r4us.identifier_new(),
system: Some("https://fhir.nhs.uk/Id/nhs-number"),
value: Some("0123456789"),
),
],
name: [
r4us.Humanname(
..r4us.humanname_new(),
given: ["Joe"],
family: Some("Armstrong"),
),
],
gender: Some(r4us_valuesets.AdministrativegenderMale),
marital_status: Some(
r4us.Codeableconcept(..r4us.codeableconcept_new(), coding: [
r4us.Coding(
..r4us.coding_new(),
system: Some(
"http://terminology.hl7.org/CodeSystem/v3-MaritalStatus",
),
code: Some("M"),
display: Some("Married"),
),
]),
),
)
echo joe
let assert Ok(client) =
r4us_httpc.fhirclient_new("https://r4.smarthealthit.org/")
// https://r4.smarthealthit.org/ might be down
// if `let assert Ok(created)` errors try these alternatives:
// fhirclient_new("https://hapi.fhir.org/baseR4")
// fhirclient_new("https://server.fire.ly")
let assert Ok(created) = r4us_httpc.patient_create(joe, client)
let assert Some(id) = created.id
let assert Ok(read) = r4us_httpc.patient_read(id, client)
echo read
let rip =
r4us.Patient(..read, deceased: Some(r4us.PatientDeceasedBoolean(True)))
let assert Ok(updated) = r4us_httpc.patient_update(rip, client)
echo updated
let assert Ok(_) = r4us_httpc.patient_delete(updated, client)
}
gleam run
FHIR Versions and HTTP client layers
The base fhir package provides R4 resources and sansio only. gleam add works for r4 packages, as they are published on hex.pm. Other versions are only available as source on github, so they need to be added as github link in gleam.toml (ideally with the commit sha ref).
| resources and sansio | httpc client | rsvp client | |
|---|---|---|---|
| r4 | gleam add fhir | gleam add fhir_client_httpc | gleam add fhir_client_rsvp |
| r4b | https://github.com/PotatoEMR/fhir_r4b | https://github.com/PotatoEMR/fhir_r4b_client_httpc | https://github.com/PotatoEMR/fhir_r4b_client_rsvp |
| r5 | https://github.com/PotatoEMR/fhir_r5 | https://github.com/PotatoEMR/fhir_r5_client_httpc | https://github.com/PotatoEMR/fhir_r5_client_rsvp |
| r4 with US Core types | https://github.com/PotatoEMR/fhir_r4us | https://github.com/PotatoEMR/fhir_r4us_client_httpc | https://github.com/PotatoEMR/fhir_r4us_client_rsvp |
| r4 with primitive extensions | https://github.com/PotatoEMR/fhir_r4p | https://github.com/PotatoEMR/fhir_r4p_client_httpc | https://github.com/PotatoEMR/fhir_r4p_client_rsvp |
AI use
AI in parts of codegen (which creates Gleam code from FHIR data) and some tests. No AI in API design or documentation.
Other FHIR Docs
These pages provide only an intro to FHIR and the Gleam implementation. For comprehensive information, see the FHIR docs, e.g. for R4 AllergyIntolerance.
Gleam FHIR is not a mature project. Applications with real users and regulations are probably better off with a mature FHIR SDK such as https://docs.fire.ly/. These Gleam FHIR pages are modelled on their .NET SDK documentation.
https://chat.fhir.org/ is a public FHIR chatroom with many questions and answers, for instance in the implementers channel.