A python package for importing and exporting the CDISC TransCelerate USDM, version 4, using FHIR
Project description
USDM4 FHIR
A Python package for converting between CDISC TransCelerate Unified Study Data Model (USDM), version 4, and HL7 FHIR M11 message bundles.
Supports export (USDM to FHIR) and import (FHIR to USDM) for multiple FHIR profile versions, including PRISM2 and PRISM3 message formats, as well as a Madrid export variant.
Features
- Export USDM4 study definitions to FHIR M11 Bundle JSON (PRISM2, PRISM3, Madrid)
- Import FHIR M11 Bundle JSON back to USDM4 study definitions (PRISM2, PRISM3)
- Schedule of Activities export to FHIR
- Round-trip fidelity testing between USDM and FHIR representations
- Built on fhir.resources (Pydantic-based FHIR R5 models)
Installation
pip install usdm4_fhir
Quick Start
Export: USDM to FHIR
from usdm4_fhir.m11.export.export_prism3 import ExportPRISM3
exporter = ExportPRISM3(study, extra)
fhir_bundle_json = exporter.to_message()
Import: FHIR to USDM
from usdm4_fhir.m11.import_.import_prism3 import ImportPRISM3
importer = ImportPRISM3()
wrapper = await importer.from_message("path/to/fhir_bundle.json")
study = wrapper.study
Dependencies
- usdm4 (>=0.18.0) -- USDM4 API model and assembler
- fhir.resources (==7.1.0) -- FHIR R5 resource models
- d4k_ms_base (>=0.3.0) -- shared microservice base
Development
Setup
git clone https://github.com/data4knowledge/usdm4_fhir.git
cd usdm4_fhir
python -m venv .venv
source .venv/bin/activate
pip install -e ".[test]"
Commands
ruff format # Format code
ruff check # Lint
pytest # Run tests
Regenerating integration test fixtures
The M11, SoA, and package integration tests (tests/usdm4_fhir/m11/test_m11_integration.py, tests/usdm4_fhir/soa/test_soa_integration.py, tests/usdm4_fhir/test_package_integration.py) compare exporter / importer output against committed golden files under tests/usdm4_fhir/test_files/. When you deliberately change exporter output shape — adding a new extension, renaming a field, splitting a single date carrier into typed sub-extensions — those goldens need to be regenerated.
Set UPDATE_FIXTURES=1 to put the integration helpers into save mode for that run:
# Regenerate all integration goldens
UPDATE_FIXTURES=1 pytest tests/
# Or scope to one test file / one test
UPDATE_FIXTURES=1 pytest tests/usdm4_fhir/m11/test_m11_integration.py
UPDATE_FIXTURES=1 pytest tests/usdm4_fhir/m11/test_m11_integration.py::test_from_fhir_prism3_asp8062
The committed source always reads SAVE = os.environ.get("UPDATE_FIXTURES") == "1", so CI cannot rubber-stamp a drifted fixture: no SAVE = True literal can be accidentally committed.
After a regeneration run, inspect the regenerated files via git diff before committing — the diffs are the actual shape change you intended, and a reviewer can scan them to confirm exporter and importer moved together.
How the import tests stay aligned with the exporter
The import-side tests in test_m11_integration.py::run_from_test and test_package_integration.py::run_from_m11_test are live round-trip tests, not static-fixture tests. For each protocol they:
- Read the canonical USDM input and
_extra.yamlhints from the export side (tests/usdm4_fhir/test_files/m11/export/<version>/<name>_{usdm.json,extra.yaml}). - Run today's exporter against that input.
- Stage the generated FHIR bundle in a
tempfile.mkdtempdirectory. - Run today's importer against that bundle.
- Assert the resulting USDM matches the committed
tests/usdm4_fhir/test_files/m11/import/<version>/<name>_usdm.jsongolden.
This makes import / export drift impossible by construction — the import test always sees the exporter's current output shape rather than a frozen FHIR fixture that lags behind the exporter. The two halves cannot disagree silently.
There are no static <name>_fhir.json files under tests/usdm4_fhir/test_files/m11/import/<version>/; if you find one in a future PR, something has regressed.
Build and Publish
python3 -m build --sdist --wheel
twine upload dist/*
Project Structure
src/usdm4_fhir/
factory/ FHIR resource factories (ResearchStudy, PlanDefinition, etc.)
m11/
export/ USDM to FHIR export (PRISM2, PRISM3, Madrid)
import_/ FHIR to USDM import (PRISM2, PRISM3)
utility/ Shared utilities (address service, HTML parsing, tag references)
soa/
export/ Schedule of Activities FHIR export
utility/ Data store
tests/ Integration test suite with round-trip verification
License
This project is licensed under the GNU General Public License v3.0. See LICENSE for details.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file usdm4_fhir-0.15.1.tar.gz.
File metadata
- Download URL: usdm4_fhir-0.15.1.tar.gz
- Upload date:
- Size: 60.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
110f09cea16db090c18923ff1868748ce677cb89ba2591b7416c81150f5ce4b3
|
|
| MD5 |
712d4e59e25a5f1898d09c4da7e670d3
|
|
| BLAKE2b-256 |
3e4c9eeaade0aaee9e6ded50273e9be8c60d7f3e42f7030ecc172d4a1bd7fb27
|
File details
Details for the file usdm4_fhir-0.15.1-py3-none-any.whl.
File metadata
- Download URL: usdm4_fhir-0.15.1-py3-none-any.whl
- Upload date:
- Size: 83.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b7c6e1e12b5b1442f51d0d7bc0cf3fe8455bc66e7710dce7e3600e1351000594
|
|
| MD5 |
1b99d3e7861d10841252e73b02d77709
|
|
| BLAKE2b-256 |
a465fbf2c7cff3a3d7a3e3cb54e530a7a30ef93a9db92d7d90dcb45cb57e2690
|