Skip to main content

Synthetic patient journey datasets for longitudinal analysis

Project description

tanat-synthea

Synthetic patient journey datasets for longitudinal analysis.

PyPI version CI codecov

Built on Synthea and designed for use with TanaT and FedBioMed. Supports US, French, and UK cohorts out of the box.

Freely reproducible. No registration, no data access agreement.


Installation

pip install tanat-synthea

Single site

from tanat_synthea import PatientJourney

pj = PatientJourney(
    "data/single_site/",
    name="CHU de Lyon",
    country_code="fr",
    state="Auvergne-Rhone-Alpes",
    population=100,
    seed=42,
    age_range="20-80",
)
pj.generate()

# Demographics (one row per patient)
pj.static_data()

# Clinical records (one row per record)
pj.temporal_data(record_types=["encounter", "condition"])

# Raw reference file
pj.load_file("organizations.csv")

Data is generated automatically on first access if it does not exist yet.


Multi-center (federated)

Quickstart - build on demo preset:

from tanat_synthea import FedPatientJourney

# Preset: 3 centers (US / FR / GB), 50 patients each
fpj = FedPatientJourney.demo()
fpj.generate()          # trigger Synthea for all centers

# Per-center access: isolated FL node
for pj in fpj.iter_centers():
    local = pj.temporal_data(record_types=["encounter", "condition"])

Configure each center manually:

fpj = FedPatientJourney([
    # Center 0
    PatientJourney("data/center_0/", name="CHU de Lyon",
                    country_code="fr", state="Auvergne-Rhone-Alpes",
                    population=100, seed=42, age_range="20-80"),
    # Center 1
    PatientJourney("data/center_1/", name="St Thomas' London",
                    country_code="gb", state="Greater London",
                    population=100, seed=123, age_range="40-85"),
    # Center 2
    PatientJourney("data/center_2/", name="Mass General",
                    country_code="us", state="Massachusetts",
                    population=100, seed=777, age_range="20-60"),
])

Or drive the federation from a YAML config:

fpj = FedPatientJourney.from_yaml("configs/demo.yaml")

TanaT integration

tanat-synthea is designed as a data source for TanaT.

from tanat_synthea import PatientJourney
from tanat import build_intervals, build_events
from tanat import TrajectoryPool

pj = PatientJourney("data/single_site/", state="Massachusetts", population=100)
pj.generate()

static   = pj.static_data()
tables   = pj.temporal_data(by_record_type=True)

# Interval sequences from diagnoses
condition_pool = build_intervals(
    tables["condition"],
    id_column="PATIENT",
    start_column="START",
    end_column="STOP",
    static_data=static,
    store_name="conditions",
)

# Event sequences from lab results
observation_pool = build_events(
    tables["observation"],
    id_column="PATIENT",
    time_column="DATE",
    static_data=static,
    store_name="observations",
)

# Combine into trajectories
tpool = (
    TrajectoryPool.builder()
    .add("conditions", condition_pool)
    .add("observations", observation_pool)
    .build("trajectory", exist_ok=True)
)

The same pattern works per-center in a federated setup (see notebooks/fed_patient_journey.ipynb).


CLI

# Generate all centers defined in a config file
tanat-synthea --config configs/demo.yaml

# Single center only
tanat-synthea --config configs/demo.yaml --center 0

# Preview Synthea commands without running them
tanat-synthea --config configs/demo.yaml --dry-run

The Synthea JAR (~190 MB) is downloaded automatically on first run if missing. See configs/demo.yaml for full documentation of available options.


License

MIT License

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

tanat_synthea-0.1.1.tar.gz (29.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

tanat_synthea-0.1.1-py3-none-any.whl (26.7 kB view details)

Uploaded Python 3

File details

Details for the file tanat_synthea-0.1.1.tar.gz.

File metadata

  • Download URL: tanat_synthea-0.1.1.tar.gz
  • Upload date:
  • Size: 29.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.13

File hashes

Hashes for tanat_synthea-0.1.1.tar.gz
Algorithm Hash digest
SHA256 28242f49f82fe2a310ef886884add9f1418d46e3ae13ec0b52553d56bbcb54d9
MD5 9490e35ce0356af4f4f9698d9b61e089
BLAKE2b-256 77db5b665090674f37378bd93f7a72ed5f1851f6d86ebfd153dae42477a7a984

See more details on using hashes here.

File details

Details for the file tanat_synthea-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: tanat_synthea-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 26.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.13

File hashes

Hashes for tanat_synthea-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 104a956fd396f2d2cf7c101e8ffda96bfea72d46bcb68d44f945742f063d12e6
MD5 7c769ee71fd47a9cae44a78aba588806
BLAKE2b-256 23b3e0c887eb0a72f367b2c85063275297281b8323257a8b21f6eb995dd96597

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page