Download StructureDefinition
bundle and build type definitions from it:
git clone --depth 1 https://github.com/beda-software/fhir-py-types.git
cd fhir-py-types/spec/
sh download_spec_bundle.sh
cd ..
docker compose up
The generated type definitions can then be found in generated/resources.py
.
The build process is based on the standard StructureDefintion
resource (available in JSON format from the FHIR download page, direct link at the time of writing).
The project uses poetry for package management.
Type definitions can be generated by running:
poetry install
poetry run typegen --from-bundles spec/fhir.types.json --from-bundles spec/fhir.resources.json --outfile generated/resources.py
Where spec/fhir.types.json
and spec/fhir.resources.json
are bundles of StructureDefinition
resources.
Type check definitions (the very first type checking process might take a while to complete, consecutive runs should be faster)
poetry run mypy generated/resources.py