Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/api/datasets.rst
Original file line number Diff line number Diff line change
Expand Up @@ -643,6 +643,7 @@ Available Datasets
datasets/pyhealth.datasets.MIMIC4EDDataset
datasets/pyhealth.datasets.KiTS23Dataset
datasets/pyhealth.datasets.MIMIC4ImaGenomeDataset
datasets/pyhealth.datasets.MedModMIMIC4Dataset
datasets/pyhealth.datasets.BrainTumorMRIDataset
datasets/pyhealth.datasets.FHIRDataset
datasets/pyhealth.datasets.MEDSDataset
Expand Down
26 changes: 26 additions & 0 deletions docs/api/datasets/pyhealth.datasets.MedModMIMIC4Dataset.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
pyhealth.datasets.MedModMIMIC4Dataset
=====================================

MIMIC-IV v1.0 and MIMIC-CXR-JPG 2.0.0 as used by MedMod (Elsharief et al.,
"MedMod: Multimodal Benchmark for Medical Prediction Tasks with Electronic
Health Records and Chest X-Ray Scans", CHIL 2025, PMLR 287;
`paper <https://proceedings.mlr.press/v287/elsharief25a.html>`__,
`code <https://github.com/nyuad-cai/MedMod>`__) for in-hospital mortality,
with MedMod's fixed train / val / test split. Use it with
:class:`~pyhealth.tasks.MedModInHospitalMortality`.

Access to `MIMIC-IV v1.0 <https://physionet.org/content/mimiciv/1.0/>`__
and `MIMIC-CXR-JPG 2.0.0 <https://physionet.org/content/mimic-cxr-jpg/2.0.0/>`__
needs PhysioNet credentialing.

.. autoclass:: pyhealth.datasets.MedModMIMIC4Dataset
:members:
:undoc-members:
:show-inheritance:

.. autoclass:: pyhealth.datasets.MedModSplit
:members:
:undoc-members:
:show-inheritance:

.. autofunction:: pyhealth.datasets.split_by_medmod
1 change: 1 addition & 0 deletions docs/api/tasks.rst
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,7 @@ Available Tasks
EHR Generation <tasks/pyhealth.tasks.generate_ehr>
Length of Stay Prediction <tasks/pyhealth.tasks.length_of_stay_prediction>
Length of Stay Prediction (StageNet MIMIC-IV) <tasks/pyhealth.tasks.length_of_stay_stagenet_mimic4>
MedMod In-Hospital Mortality (MIMIC-IV + CXR) <tasks/pyhealth.tasks.MedModInHospitalMortality>
Medical Transcriptions Classification <tasks/pyhealth.tasks.MedicalTranscriptionsClassification>
MPF Clinical Prediction (FHIR) <tasks/pyhealth.tasks.mpf_clinical_prediction>
Mortality Prediction (Next Visit) <tasks/pyhealth.tasks.mortality_prediction>
Expand Down
86 changes: 86 additions & 0 deletions docs/api/tasks/pyhealth.tasks.MedModInHospitalMortality.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
pyhealth.tasks.MedModInHospitalMortality
========================================

In-hospital mortality from the first 48 hours of an ICU stay and the latest
chest X-ray in that window, reproducing MedMod (Elsharief et al., 2025) and its
released code: one sample per ICU stay with ``ehr`` (48 x 76), ``image_path``
and ``label``. Use it with :class:`~pyhealth.datasets.MedModMIMIC4Dataset`.

.. autoclass:: pyhealth.tasks.MedModInHospitalMortality
:members:
:undoc-members:
:show-inheritance:

.. autoclass:: pyhealth.processors.medmod_ehr_processor.MedModEHRProcessor
:members:
:undoc-members:
:show-inheritance:

Per-model settings

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[low] Task API page is much longer than comparable pages

The 'Per-model settings' and 'Paper vs code' sections, with file:line citations into the MedMod and MedFuse repositories and CI-level experiment numbers, add a lot to an API reference page. Keep the short 'hours_zero' and 'normalizer' explanation on the page, and move the paper-vs-code table and experiment results to the PR description or a short note. Comparable task pages in docs/api/tasks/ do not carry this detail.

------------------

MedMod's models read their data through two code paths. Both use the same
cohort, labels and split. They differ in the EHR rows at Hours == 0, which the
task sets with ``hours_zero``, and in the image transform. The task returns
``image_path`` and applies no image transform: the "Image transform" column is
what the model's own image loader applies.

.. list-table::
:header-rows: 1

* - Model
- ``hours_zero``
- Image transform
- Why
* - Early Fusion
- ``"keep"``
- ImageNet-normalized
- MedMod's supervised ``fusion_main.py:13-16`` imports ``datasets.*`` and
``ehr_utils.*``, which exist only in MedFuse; MedFuse's
``datasets/ehr_dataset.py`` keeps every row and
``datasets/cxr_dataset.py`` normalizes.
* - ConVIRT (pretraining, linear evaluation)
- ``"drop"``
- pixels in [0, 1]
- MedMod's ``src/data/datasets.py:137-163`` keeps 0 < t only; the ConVIRT
scripts pass ``--transforms_cxr simclrv2``.

Paper vs code
-------------

Where MedMod's paper and released code disagree, the task follows the code,
which produced the reported numbers. The bin width and the normalizer remain
settings of the task (``timestep``, ``normalizer``).

.. list-table::
:header-rows: 1

* - Rule
- MedMod paper
- Released code
- Default here
* - Bin width
- §3.2.2 "every two hours" (MedFuse §4.1.1 too)
- 1 h (``--timestep`` default 1.0, ``src/parser.py:30``)
- 1 h (``timestep``)
* - Normalizer
- §3.2.2 "task-specific", computed on the dataset
- the phenotyping file ``ph_ts1.0`` (an ``is`` comparison in ``ehr_funcs``)
- ``ph_ts1.0``; ``normalizer=None`` fits one on the train split
* - Split
- §3.2.4 random 70/10/20 by patient
- fixed subject lists
- the fixed lists, which reproduce Table 2

Two checks on the real data (image-paired test set, 1,241 stays):

- MedFuse's released EHR checkpoint (``checkpoints/mortality/uni_ehr_all``),
evaluated frozen: test AUROC 0.833 (95% CI 0.802-0.860) with 1 h +
``ph_ts1.0``, against 0.735 with 1 h + a normalizer fitted on the train split
and 0.719 with 2 h + fitted; MedFuse reports 0.825 (0.793-0.852). So a model
that uses MedFuse's encoders frozen needs the code's settings. MedFuse split
with the same subject lists, so its training data holds none of these test
patients.
- MedMod's EHR LSTM trained from scratch (5 seeds): 1 h vs 2 h with the same
normalizer makes no difference (Δ AUROC +0.000 ± 0.006); ``ph_ts1.0`` scores
0.009 higher than a fitted normalizer (0.816 vs 0.807; paper Table 3: 0.829).
5 changes: 5 additions & 0 deletions pyhealth/datasets/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,11 @@ def __init__(self, *args, **kwargs):
)
from .gold_test_split import GoldTestSplit as GoldTestSplit
from .mimic4_imagenome import MIMIC4ImaGenomeDataset as MIMIC4ImaGenomeDataset
from .medmod_mimic4 import (
MedModMIMIC4Dataset as MedModMIMIC4Dataset,
MedModSplit as MedModSplit,
split_by_medmod as split_by_medmod,
)
from .eegbci import EEGBCIDataset as EEGBCIDataset # noqa: E402
from .ahepa_dementia import AHEPADementiaDataset as AHEPADementiaDataset
from .bciiv2a import BCICompetitionIV2aDataset as BCICompetitionIV2aDataset
Expand Down
99 changes: 99 additions & 0 deletions pyhealth/datasets/configs/mimic4_ehr_v1.0.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
# PyHealth table config for MIMIC-IV v1.0 (core/ + hosp/ + icu/, `ethnicity`).
#
# Adapted from PyHealth's v2.2 config (pyhealth/datasets/configs/mimic4_ehr.yaml)
# for the tables the MedMod IHM task reads. Changes from v2.2:
# * patients, admissions: hosp/ -> core/ (v1.0 layout)
# * admissions: `race` -> `ethnicity` (MedMod reads `ethnicity`, mimic3csv.py:27)
# * icustays: add `los` (create_ihm.py:34 uses icustays.los, in days)
# * diagnoses_icd: extra inner join with hosp/d_icd_diagnoses on icd_code
# only (not icd_version), as MedMod does in mimic3csv.py:44-48; a diagnosis
# with no match is dropped
# * labevents: no join with d_labitems (the task needs only itemid/value)
# * chartevents, labevents: no valueuom (see the note at the end)
# PyHealth tries both .csv and .csv.gz (_csv_tsv_gz_path in base_dataset.py), so
# either works.
# Column lists were written from memory of the v1.0 schema and confirmed by a
# full run on the real v1.0 files (2026-11-09): PyHealth selects every listed
# attribute, so a missing column would have failed the load.
version: "1.0"
tables:
patients:
file_path: "core/patients.csv.gz"
patient_id: "subject_id"
timestamp: null
attributes:
- "gender"
- "anchor_age"
- "anchor_year"
- "anchor_year_group"
- "dod"

admissions:
file_path: "core/admissions.csv.gz"
patient_id: "subject_id"
timestamp: "admittime"
attributes:
- "hadm_id"
- "admission_type"
- "dischtime"
- "deathtime"
- "ethnicity"
- "hospital_expire_flag"

icustays:
file_path: "icu/icustays.csv.gz"
patient_id: "subject_id"
timestamp: "intime"
attributes:
- "hadm_id"
- "stay_id"
- "first_careunit"
- "last_careunit"
- "outtime"
- "los"

diagnoses_icd:
file_path: "hosp/diagnoses_icd.csv.gz"
patient_id: "subject_id"
join:
- file_path: "core/admissions.csv.gz"
"on": "hadm_id"
how: "inner"
columns:
- "dischtime"
- file_path: "hosp/d_icd_diagnoses.csv.gz"
"on": "icd_code"
how: "inner"
columns:
- "long_title"
timestamp: "dischtime"
attributes:
- "hadm_id"
- "icd_code"
- "icd_version"
- "seq_num"
- "long_title"

labevents:
file_path: "hosp/labevents.csv.gz"
patient_id: "subject_id"
timestamp: "charttime"
attributes:
- "hadm_id"
- "itemid"
- "value"
- "valuenum"

chartevents:
file_path: "icu/chartevents.csv.gz"
patient_id: "subject_id"
timestamp: "charttime"
attributes:
- "hadm_id"
- "stay_id"
- "itemid"
- "value"
- "valuenum"
# valueuom is left out of both event tables: MedMod never reads units for
# chartevents/labevents (it stores valuenum in that slot, mimic3csv.py:220), and
# every column kept here is carried through PyHealth's disk-heavy sort.
11 changes: 11 additions & 0 deletions pyhealth/datasets/medmod/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
"""MedMod (Elsharief et al., 2025) in-hospital mortality: the parts behind
``MedModMIMIC4Dataset`` and ``MedModInHospitalMortality``.

* ``extraction``: cohort, labels, value cleaning, time series and CXR pairing,
one subject at a time, following MedMod's code line by line.
* ``discretizer``: MedMod's Discretizer and Normalizer.
* ``downloads``: MedMod's subject lists and item map, downloaded from MedMod's
GitHub (pinned commit, SHA-256 checked) on first use.
* ``files/``: MedMod's discretizer config and normalizer (Apache-2.0, see
``files/NOTICE``).
"""
Loading
Loading