ValueSets
BabelFHIR-TS generates typed ValueSet modules for every ValueSet binding resolved from the StructureDefinitions in your Implementation Guide. These modules provide code unions, runtime validators, random pickers, and a central registry.
Generated Files
ValueSet files are emitted in a valuesets/ directory:
valuesets/
ValueSet-AdministrativeGender.ts
ValueSet-ConditionClinicalStatusCodes.ts
ValueSet-USCoreRace.ts
...
ValueSetRegistry.tsPer-ValueSet Module
Each ValueSet-<Name>.ts file exports:
Code Union Type
A string literal union of all valid codes:
export type AdministrativeGenderCode = "male" | "female" | "other" | "unknown";Concept Array
An array of concept objects with code, system, and display:
export interface AdministrativeGenderConcept {
code: string;
system: string;
display?: string;
}
export const AdministrativeGenderConcepts: AdministrativeGenderConcept[] = [
{ code: "male", system: "http://hl7.org/fhir/administrative-gender", display: "Male" },
{ code: "female", system: "http://hl7.org/fhir/administrative-gender", display: "Female" },
// ...
];Codes Array
A convenience array of just the code strings:
export const AdministrativeGenderCodes = AdministrativeGenderConcepts.map(c => c.code);Validation Helper
Check if a string is a valid code:
export function isValidAdministrativeGenderCode(code: string): code is AdministrativeGenderCode {
return AdministrativeGenderConcepts.some(c => c.code === code);
}Concept Lookup
Get concept details (system + display) by code:
export function getAdministrativeGenderConcept(code: string): AdministrativeGenderConcept | undefined {
return AdministrativeGenderConcepts.find(c => c.code === code);
}Random Pickers
For test data generation:
export function randomAdministrativeGenderCode(): AdministrativeGenderCode {
return AdministrativeGenderCodes[Math.floor(Math.random() * AdministrativeGenderCodes.length)];
}
export function randomAdministrativeGenderConcept(): AdministrativeGenderConcept {
return AdministrativeGenderConcepts[Math.floor(Math.random() * AdministrativeGenderConcepts.length)];
}ValueSet Registry
The ValueSetRegistry.ts file provides a central entry point for all resolved ValueSets:
Registry Object
import { getValueSet, ValueSetUrlMap, getRandomCodeByUrl, getRandomConceptByUrl } from "./valuesets/ValueSetRegistry";Lookup by Name
import { getValueSet } from "./valuesets/ValueSetRegistry";
const vs = getValueSet("AdministrativeGender");
// Access all exports from ValueSet-AdministrativeGender.tsLookup by URL
import { ValueSetUrlMap, getRandomCodeByUrl, getRandomConceptByUrl } from "./valuesets/ValueSetRegistry";
// Map from canonical URL to registry name
const name = ValueSetUrlMap["http://hl7.org/fhir/ValueSet/administrative-gender"];
// "AdministrativeGender"
// Get a random code from a ValueSet by its canonical URL
const code = getRandomCodeByUrl("http://hl7.org/fhir/ValueSet/administrative-gender");
// e.g., "female"
// Get a random concept (code + system + display) by URL
const concept = getRandomConceptByUrl("http://hl7.org/fhir/ValueSet/administrative-gender|4.0.1");
// { code: "male", system: "http://hl7.org/fhir/administrative-gender", display: "Male" }The URL lookup automatically strips version suffixes (e.g., |4.0.1) for matching.
Multi-Language Display
When --display-language is used with multiple languages, ValueSet modules include additional display map exports. See Multi-Language Display Terms for details.
Empty ValueSets
ValueSets that have no explicitly enumerated codes (e.g., defined by filters or external terminology) are noted in a comment but don't generate code arrays or helpers. Runtime validation for these ValueSets requires a terminology server (see Validator Runtime Options).
Package Export
The valuesets/ directory is exposed via a subpath export:
// Import a specific ValueSet
import { AdministrativeGenderCode } from "my-ig-generated/valuesets/ValueSet-AdministrativeGender";
// Import the registry
import { getRandomCodeByUrl } from "my-ig-generated/valuesets/ValueSetRegistry";