Skip to main content

CDSL MEDS Extraction ETL

PyPI - Version codecov tests code-quality python Static Badge license PRs contributors DOI

This pipeline extracts the COVID Data for Shared Learning (CDSL) database v1.0.0 from PhysioNet into the MEDS format. CDSL holds 4,479 patients hospitalized with confirmed or suspected COVID-19 in the Spanish HM Hospitales group (December 2019 – February 2021). It was built from the ETL_MEDS_Template and uses the config-only layout introduced by MEDS-Extract 0.7.

The ETL maps the tabular EHR data and the DICOM metadata table. It never downloads or reads the IMAGES/ tree.

Usage

CDSL is a restricted-access dataset. You need a credentialed PhysioNet account that has completed the required training, signed the data use agreement, and had a project approved by the data contributors.

pip install git+https://github.com/rvandewater/CDSL_MEDS.git
export DATASET_DOWNLOAD_USERNAME=$PHYSIONET_USERNAME
export DATASET_DOWNLOAD_PASSWORD=$PHYSIONET_PASSWORD
meds-extract-download spec=CDSL output_dir=$RAW_INPUT_DIR
MEDS_extract-CDSL spec=CDSL output_dir=$MEDS_OUTPUT_DIR do_download=false input_dir=$RAW_INPUT_DIR

When you run this, the program will:

  1. Download the CDSL tables and DICOM metadata from PhysioNet into $RAW_INPUT_DIR, skipping IMAGES/.
  2. Stage a UTF-8 view of the input in $MEDS_OUTPUT_DIR/.meds_extract_run/pre_meds (see Input encoding). The downloaded files are not modified.
  3. Build the MEDS cohort from the staged files and write it to $MEDS_OUTPUT_DIR (data/ and metadata/). All transformations and metadata extraction are declared in src/CDSL_MEDS/event_configs.yaml.
  4. Fill in the code descriptions that MEDS-Extract cannot attach on its own (see Code metadata).

If you already have the PhysioNet release on disk, skip the first command and point input_dir at the directory that directly contains patient_01.csv.

MEDS_extract-CDSL takes the same arguments as meds-extract-run. To parallelize the stages, pass a runner file:

printf 'parallelize:\n  n_workers: 8\n  launcher: joblib\n' >runner.yaml
MEDS_extract-CDSL spec=CDSL output_dir=$MEDS_OUTPUT_DIR do_download=false \
	input_dir=$RAW_INPUT_DIR stage_runner_fp=runner.yaml

Run meds-extract-run --help for every option.

How this ETL is defined

The whole ETL is one MESSY (MEDS-Extract Specification Syntax YAML) file, src/CDSL_MEDS/event_configs.yaml. It declares:

  • sources:: where the raw data lives (the PhysioNet release, excluding IMAGES/**).
  • etl:: the dataset name and sharding options.
  • One block per raw table: how each row becomes one or more MEDS events, and which dictionary tables describe the resulting codes.

pyproject.toml registers the file with MEDS-Extract's MEDS_extract.pipelines entry-point group under the name CDSL. That registration is what makes spec=CDSL work.

Input encoding

atc7.csv, medication_05.csv and vital_signs_04.csv are Latin-1 encoded, while MEDS-Extract's CSV reader requires UTF-8. src/CDSL_MEDS/pre_meds.py handles this: MEDS_extract-CDSL transcodes those three files into a staging directory, hard-links every other file, and then runs meds-extract-run on the staged copy. Because of this step and the code metadata step that follows the pipeline, run the ETL with MEDS_extract-CDSL rather than meds-extract-run directly.

Events

Table Event codes Notes
patient_01 HOSPITAL_ADMISSION, HOSPITAL_DISCHARGE//{destination}, ICU_ADMISSION, ICU_DISCHARGE, AGE_AT_ADMISSION, SEX//{sex}, INPATIENT_DIAGNOSIS//{diagnosis} Age is the numeric_value. Sex and inpatient diagnosis are placed at hospital admission.
EMERGENCY_DEPARTMENT_VISIT, EMERGENCY_DEPARTMENT//{department}, EMERGENCY_DIAGNOSIS//{diagnosis} Placed at the ED admission time.
MECHANICAL_VENTILATION Emitted at hospital admission when mechvent is Yes.
VITAL//{measurement} The first and last ED vital signs, at their recorded times.
diagnosis_er_02 DIAGNOSIS_ICD10//{code}, PROCEDURE_ICD10PCS//{code} One event per populated diagnosis (12) and procedure (5) slot.
diagnosis_hosp_03 DIAGNOSIS_ICD10//{code}, PROCEDURE_ICD10PCS//{code}, NEOPLASM_ICDO3//{code} One event per populated diagnosis (19), procedure (20) and neoplasm (6) slot.
vital_signs_04 VITAL//{measurement} Blood pressure, temperature, heart rate, oxygen saturation and glucose.
medication_05 MEDICATION//ATC5//{atc5}//ATC7//{atc7}, MEDICATION_END//ATC5//{atc5}//ATC7//{atc7} The daily average dose is the start event's numeric_value; the commercial name is text.
lab_06 LAB//{item}//{unit} numeric_value, text_value and the reference range are kept.
CDSL-1.0.0-dicom-metadata IMAGING//{modality}//{study description}//{body part} Study and image IDs, view and patient position, and spatial resolution are kept.

{measurement} is one of SYSTOLIC_BLOOD_PRESSURE, DIASTOLIC_BLOOD_PRESSURE, TEMPERATURE, HEART_RATE, OXYGEN_SATURATION, BLOOD_GLUCOSE and, for the ED only, URINE_OUTPUT. The measured value is the numeric_value.

A missing discharge destination, ATC7 code or lab unit becomes UNKNOWN in the code. A row with a missing time produces no event. Source row IDs (medication_id, lab_id, vital_sign_id) are kept as columns, so repeated identical measurements are not collapsed.

See docs/MEDS_ETL_MAPPING.md for the table-level mapping in more detail.

Code metadata

The ETL writes a description for every code whose meaning the release itself documents, and no parent_codes: vocabulary parents (ICD-10-CM, ICD-10-PCS, ICD-O-3, ATC), and the official titles of the ICD-10-PCS procedure codes, come from suMEDS (see Enriching code metadata with suMEDS). Descriptions name the CDSL column each value comes from. Spanish source values, such as the ATC names, are kept as they are, not translated.

Code family Route Description
DIAGNOSIS_ICD10//{code} filled after the pipeline (code_descriptions.py) the ICD-10-CM long title from the release's icd10_codes_dict.txt; ICD-O-3 morphology codes (MMMM/B) found in diagnosis columns get a template naming the code
PROCEDURE_ICD10PCS//{code} none in the ETL the CMS ICD-10-PCS title, added by suMEDS
NEOPLASM_ICDO3//{code} filled after the pipeline a template naming the code (ICD-O-3 titles are licensed)
MEDICATION//…, MEDICATION_END//… atc7 join and _self block in event_configs.yaml the ATC7 name from the release's atc7.csv (prefixed "End of medication" for MEDICATION_END); for rows without an ATC7 code, a template naming the ATC5 code
HOSPITAL_DISCHARGE, SEX, INPATIENT_DIAGNOSIS, EMERGENCY_DEPARTMENT, EMERGENCY_DIAGNOSIS, LAB, IMAGING _self templates in event_configs.yaml the code's values with the CDSL columns they come from
literal codes: HOSPITAL_ADMISSION, ICU_ADMISSION, ICU_DISCHARGE, AGE_AT_ADMISSION, EMERGENCY_DEPARTMENT_VISIT, MECHANICAL_VENTILATION, VITAL//… metadata/static_code_descriptions.csv, filled after the pipeline the meaning of the source columns in the CDSL documentation, with the source of each row in the table's source column

Two kinds of codes cannot be described in the config. MEDS-Extract attaches _metadata by joining on a code's components, so a literal code has nothing to join on, and the pre-existing codes.parquet that MEDS-Extract documents for this case is not read by the standard pipeline. The diagnosis, procedure and neoplasm codes come from one event per column of a wide table (dia_ppal, dia_02, ...), so a code seen in two columns has two code templates, which the MEDS-Extract metadata stage rejects. MEDS_extract-CDSL fills both into the finished codes.parquet: it only fills missing descriptions, never adds a code or a parent, can be rerun safely, and validates the file against meds.CodeMetadataSchema.

Sources:

  • The CDSL v1.0.0 documentation on PhysioNet, for the meaning of each column (paraphrased; cdsl-docs: in the source column).
  • The release's own dictionary tables, atc7.csv and icd10_codes_dict.txt, read at ETL time and never copied into this repository. icd10_codes_dict.txt is the CMS ICD-10-CM FY2021 order file with its fields joined by |, as built by the dataset authors' covidhm-code (MIT, CovidHM_V3-code/buildcovidhm/data_wrangling/V3_icd10_data_wrangling.py).

Which ICD-10. The CDSL documentation says only "ICD-10". The dictionary shipped with the release is the US ICD-10-CM (FY2021), and Spain's CIE-10-ES is the Spanish edition of the ICD-10 Clinical Modification (Ministerio de Sanidad), so the suMEDS rules map diagnosis codes to OMOP's ICD10CM vocabulary. CDSL already writes the codes with the dot where OMOP puts it.

Enriching code metadata with suMEDS

Vocabulary work is maintained once, in suMEDS, rather than in every ETL. This package ships the rules for it, src/CDSL_MEDS/sumeds_rules.yaml:

pip install "sumeds>=0.4"
suMEDS-enrich $MEDS_OUTPUT_DIR/metadata/codes.parquet -o codes_enriched.parquet \
	--rules src/CDSL_MEDS/sumeds_rules.yaml
# Optional: validate ATC and ICD-O-3 codes against your own OHDSI Athena download.
suMEDS-enrich $MEDS_OUTPUT_DIR/metadata/codes.parquet -o codes_enriched.parquet \
	--rules src/CDSL_MEDS/sumeds_rules.yaml --athena-csv /path/to/athena

ICD-10-CM and ICD-10-PCS codes are validated against suMEDS's versioned ontology data (sumeds-ontologies, pinned release), built from the CMS and CDC files. The rules add:

  • DIAGNOSIS_ICD10 codes shaped like ICD-10-CM: parents ICD10CM//{code} and its ancestors; the CMS title where the release's dictionary has none.
  • PROCEDURE_ICD10PCS codes: parents ICD10PCS//{code} and its ancestors; the CMS title.
  • ICD-O-3 morphology codes (NEOPLASM_ICDO3, and MMMM/B codes in diagnosis columns): parent ICDO3//{MMMM/B}, the sixth (grade) digit dropped. ICD-O-3 is licensed, so suMEDS only tags these codes unless Athena validates them.
  • MEDICATION and MEDICATION_END: parent ATC//{id_atc7} when the ATC7 code is well formed and lies under the row's ATC5 code, else ATC//{id_atc5}. ATC is licensed too: tagged only, or validated with its ancestors by Athena.
  • Same-dataset parents: a diagnosis or procedure code gets the nearest shorter code of the same family that CDSL contains (DIAGNOSIS_ICD10//J18 for DIAGNOSIS_ICD10//J18.9).

suMEDS fills only missing descriptions, never removes or rewrites existing metadata, and writes parents as VOCABULARY//CODE. The ETL alone no longer emits these parent codes or the ICD-10-PCS descriptions.

Data notes

  • Deidentified dates. Dates are shifted but preserve chronology within a patient, and are emitted as supplied.
  • Pseudotime. diagnosis_er_02 and diagnosis_hosp_03 have no timestamps. Their diagnosis, procedure and neoplasm events use the fixed time 1970-01-01 00:00:00 rather than a guessed admission or discharge time.
  • One admission per subject. patient_id is CDSL's admission identifier and becomes the MEDS subject_id.
  • No units for vitals. The release does not document units for the vital signs, so none are added to the codes. Zero values are kept because the release defines no missing-value sentinel.
  • Unmapped columns. The present-on-admission flags in diagnosis_hosp_03 have no MEDS mapping and are not extracted.
  • Spanish values. Most content is in English, but some columns, such as the medication commercial name, contain Spanish text.

Testing

tests/test_cdsl_etl.py checks that the config loads and excludes IMAGES/, builds a minimal raw fixture from the columns the config needs, runs MEDS_extract-CDSL over it (every code but the ICD-10-PCS procedures described, no parent codes, valid MEDS code metadata), and checks the Latin-1 staging step. tests/test_code_descriptions.py checks that the literal-code table is complete and sourced, that every other code family has a description route, and that the post-pipeline fill keeps existing values. tests/test_sumeds_rules.py loads the rules with suMEDS and checks what example codes built from the config's code templates resolve to. The synthetic ETL workflow also generates raw files straight from the config with MESSY-synth and fails if any event block yields no events.

uv sync --group dev
uv run pytest tests/ -v
uv run pre-commit run --all-files

Summary statistics

tests/regression/full_summary_stats.json is a meds_summary_stats fingerprint of the MEDS dataset this ETL builds from the full CDSL 1.0.0 release: subject, event and measurement counts, digests of the code vocabulary, per-subject, value and time distributions, code-metadata coverage, the splits and the schema. It names no code and reports no cell of fewer than 20 subjects and no minimum or maximum, which is what makes it safe to publish. Because it is committed next to the ETL, its diff shows what an ETL change did to the output, and two ETL versions can be compared without access to the data.

Regenerate it in every pull request that changes the output, from a build of that branch:

# Build the release with this checkout, then summarize it
scripts/summary_stats.sh full --input-dir $RAW_INPUT_DIR
# Or summarize a build of this checkout you already have
scripts/summary_stats.sh full --meds-dir $MEDS_OUTPUT_DIR

Both print how the statistics changed against the committed baseline before overwriting it. Add --compare to check a build without writing anything; it exits 1 when tests/regression/policy.yaml flags an error. Rebuilding the same commit reproduces the baseline exactly, so any finding is a change in the output. CI cannot rebuild the credentialed release, so the Summary stats workflow only warns when a pull request changes src/ without regenerating the baseline. A MEDS-Extract or polars upgrade can also move the output, so check it with --compare.

Citation

If you use this ETL, please cite the CDSL database:

@article{PhysioNet-covid-data-shared-learning-1.0.0,
  author = {Ritoré, Álvaro and Oprescu, Andreea M and {Estirado Bronchalo}, Alberto and {Armengol de la Hoz}, Miguel Ángel},
  title = {{COVID Data for Shared Learning (CDSL): A comprehensive, multimodal COVID-19 dataset from HM Hospitales}},
  journal = {{PhysioNet}},
  year = {2024},
  month = oct,
  note = {Version 1.0.0},
  doi = {10.13026/1176-6c44},
  url = {https://doi.org/10.13026/1176-6c44}
}

And this ETL:

@software{Robin_van_de_Water_rvandewater_CDSL_MEDS_Zenodo_2026,
author = {Robin van de Water},
doi = {10.5281/zenodo.23676596},
license = {["mit"]},
month = oct,
title = {{rvandewater/CDSL\_MEDS: Zenodo}},
url = {https://github.com/rvandewater/CDSL_MEDS/,
year = {2026}
}

See also CITATION.cff.

Metadata

Release files for CDSL-MEDS 0.0.4

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

Source distribution (sdist)

Source distribution for CDSL-MEDS 0.0.4
File Size Uploaded Provenance Actions
cdsl_meds-0.0.4.tar.gz 30.3 kB With provenance Details for cdsl_meds-0.0.4.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for CDSL-MEDS 0.0.4
File Interpreter ABI Platform Actions
cdsl_meds-0.0.4-py3-none-any.whl Python 3 none any Details for cdsl_meds-0.0.4-py3-none-any.whl

Total release size: 50.3 kB

Release files / cdsl_meds-0.0.4.tar.gz

Download URL cdsl_meds-0.0.4.tar.gz
Size 30.3 kB
Tags Source
SHA-256 checksum
How to use checksums
cb7fd962854a4db7290847cdbf157d3b86510eeafce1cf6bfced5e9006ba0859
BLAKE2b-256 checksum
How to use checksums
988dae3a577fbfe379fe07738216a9ecee776049fa427ada3105550c2085004e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 11, 2026.

Transparency log

Release files / cdsl_meds-0.0.4-py3-none-any.whl

Download URL cdsl_meds-0.0.4-py3-none-any.whl
Size 20.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
d1e713fde9bfab7aaf5117503798b9abf569c94e89ffcb181c6c6e60534b25ae
BLAKE2b-256 checksum
How to use checksums
3ff1a67a34d580379148d8cda9ab0fc0a6d24c60a1dde39b815d62b0d6ee836a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 11, 2026.

Transparency log

Security for CDSL-MEDS 0.0.4

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.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for cdsl_meds-0.0.4.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 11, 2026.

Transparency log

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