Skip to main content

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 SAVE to True to put the integration helpers into save mode for that run in the following files:

  • tests/usdm4_fhir/test_package_integration.py
  • tests/usdm4_fhir/m11/test_m11_integration.py
  • tests/usdm4_fhir/soa/test_soa_integration.py

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:

  1. Read the canonical USDM input and _extra.yaml hints from the export side (tests/usdm4_fhir/test_files/m11/export/<version>/<name>_{usdm.json,extra.yaml}).
  2. Run today's exporter against that input.
  3. Stage the generated FHIR bundle in a tempfile.mkdtemp directory.
  4. Run today's importer against that bundle.
  5. Assert the resulting USDM matches the committed tests/usdm4_fhir/test_files/m11/import/<version>/<name>_usdm.json golden.

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.

Metadata

Release files for usdm4-fhir 0.16.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for usdm4-fhir 0.16.0
File Size Uploaded Provenance Actions
usdm4_fhir-0.16.0.tar.gz 68.1 kB Without provenance Details for usdm4_fhir-0.16.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for usdm4-fhir 0.16.0
File Interpreter ABI Platform Actions
usdm4_fhir-0.16.0-py3-none-any.whl Python 3 none any Details for usdm4_fhir-0.16.0-py3-none-any.whl

Total release size: 160.9 kB

Release files / usdm4_fhir-0.16.0.tar.gz

Download URL usdm4_fhir-0.16.0.tar.gz
Size 68.1 kB
Tags Source
SHA-256 checksum
How to use checksums
68aa3eaa97c348c584e7c0646760a7c813c177ba43e1b4f7c499e863525494cc
BLAKE2b-256 checksum
How to use checksums
7ad02edf7389fd8e8c4f4255fd501763f1e3d2ba2f68714783d3c0dcda692196
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.3

Release files / usdm4_fhir-0.16.0-py3-none-any.whl

Download URL usdm4_fhir-0.16.0-py3-none-any.whl
Size 92.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
5624c09916e32f7817c61cf5a3d1f3ee27c72da1411f7db719fd45d65ff38228
BLAKE2b-256 checksum
How to use checksums
f08a3f7812c3b8551912b111d053d65026c75734024da8e09da9b508a67e2a8c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.3

Security for usdm4-fhir 0.16.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page