Cardinality

https://build.fhir.org/conformance-rules.html#cardinality refers to how many of an element there can or must be.

CardinalityDefinitionGleam
1..1One mandatory elementx
0..1One optional elementOption(x)
0..*Any number of elementsList(x)
1..*Any >0 number of elementsList(x)

Gleam’s type system enforces that a 1..1 element must exist, so attempting to decode a JSON that does not have a 1..1 element will fail. Note this is not true for 1..*, although in practice 1..1, 0..1, and 0..* elements are far more common.

For example, a patient may have multiple Communication backbone elements, so the communication field in r4.Patient is a List(PatientCommunication).

PatientCommunication

pub type Patient {
  Patient(
    ...
    communication: List(PatientCommunication),
    ...
  )
}

A communication may optionally (but is not required to) have a preferred element if the patient prefers that language, so the preferred field in r4.PatientCommunication is wrapped in an Option. Whereas a communication must have exactly one language, so the language field is not in an Option.

pub type PatientCommunication {
  PatientCommunication(
    ...
    language: Codeableconcept,
    preferred: Option(Bool),
  )
}
Search Document