oscadev
06/08/2025, 6:14 PMcody
06/09/2025, 3:36 PM@medplum/fhirtypes package provides type definitions that align with the official FHIR specification. How it does this varies based on the underlying FHIR data type:
For code fields: We provide inline string literal types. For example, the Coverage.status field is typed as 'active' | 'cancelled' | 'draft' | 'entered-in-error', giving you type safety for that fixed set of values.
For CodeableConcept fields: For more complex fields like Coverage.relationship, we don't bake the allowed values into the TypeScript type. This is because these fields are bound to formal ValueSets, which are often more flexible than a simple enum.
You can see the official FHIR R4 documentation for the Coverage resource here: https://hl7.org/fhir/R4/coverage.html
The relationship field specifically points to the subscriber-relationship ValueSet: https://hl7.org/fhir/R4/valueset-subscriber-relationship.html
If you look at that ValueSet documentation, you'll notice the binding strength is marked as "Extensible." This is an important detail: it means that while a preferred set of codes is defined (e.g., 'child', 'parent', 'spouse'), other valid codes can also be used. A hardcoded enum in our types would be incomplete and incorrectly flag valid, extended codes as errors.
We have discussed improving this with TypeScript generics (e.g., CodeableConcept<'child' | 'parent'>) to offer better IDE autocompletion. However, due to the "extensible" nature of this specific ValueSet, such a generic type would be too rigid and wouldn't solve the core issue.
Recommendations:
Programmatic Approach (Source of Truth): The standard, FHIR-compliant way to get these values is to use the ValueSet/$expand operation on the terminology service. This will dynamically fetch the full, current set of codes the server supports for that field.
Quick Reference: For a quick check of the most common options, navigating to the resource editor in the Medplum App (e.g., https://app.medplum.com/Coverage/[id]/edit) and inspecting the dropdown is a very handy shortcut. (which uses ValueSet/$expand behind the scenes).
Hope this helps