haste-codegen
The code generators behind Haste Health's FHIR model. From FHIR StructureDefinition, OperationDefinition and SearchParameter resources it produces the Rust types in haste-fhir-model, the typed operation bindings in haste-fhir-generated-ops, the single-valued search parameter table the server's search index relies on, and FHIR TestScript resources from example data. Rust output is a proc_macro2::TokenStream; generated doc comments are rewritten so they pass clippy's doc_markdown lint under -Dclippy::pedantic.
It is a library. The haste-health generate commands drive it, and the scripts in backend/scripts (types_build.sh, operation_build.sh, search_param_cardinality_build.sh, testscript_build.sh) run those commands with the repository's artifact inputs. haste-fhir-profiling reuses its StructureDefinition traversal.
Install
Usage
Generate the Rust types for a set of StructureDefinition files or directories:
use rust_types;
let inputs = vec!;
// `None` generates every tier; "primitive-type", "complex-type" or "resource" restricts it.
let generated = generate.await?;
write?;
write?;
write?;
Walk a StructureDefinition snapshot bottom-up, children before their parent:
use traversal;
let element_count = traversal?;
API
| Module | What it does |
|---|---|
type_gen::rust_types |
generate(files, level): structs and enums for resources, data types and terminology, as GeneratedTypes. |
type_gen::operation_definitions |
generate_operation_definitions_from_files(files): typed Input and Output bindings for each OperationDefinition. |
search_param_cardinality |
Resolves each SearchParameter expression against the snapshots to decide whether it can yield more than one value; generate_lookup emits the is_single_valued table. |
testscript_gen |
generate_testscripts(files): for each file of example resources, a TestScript that creates them as fixtures, asserts the created type and deletes them by tag in teardown. |
traversal |
traversal and ele_index_to_child_indices for walking snapshot elements. |
utilities |
FHIR to Rust name and type conversion, element extraction, and loading of definition files (utilities::load). |
Links
- API reference
- Source
- Rust SDK overview
- CLI reference for the
generatecommands - TypeScript equivalent: @haste-health/codegen
Part of Haste Health, licensed under Apache-2.0.