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
580 changes: 580 additions & 0 deletions pyhealth/datasets/configs/eicu.yaml

Large diffs are not rendered by default.

606 changes: 55 additions & 551 deletions pyhealth/datasets/eicu.py

Large diffs are not rendered by default.

540 changes: 540 additions & 0 deletions test-resources/core/eicudemo/LICENSE.txt

Large diffs are not rendered by default.

33 changes: 33 additions & 0 deletions test-resources/core/eicudemo/SHA256SUMS.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
bcdfcd4f31c790e30fb645dc36414907172405897adff329ad379eed85d12017 LICENSE.txt
607020180f1c7fbbc994a23552d6a4fdc70b86d4abc8e1b36f3ee28e96f15c42 admissionDx.csv.gz
fcf0af0de0efe18ec932199d2fcb308143886df6d50daea869bea48464ea6d68 admissiondrug.csv.gz
be890a4cfaf7a194596583f882f491ced515f1714e3d07fc59413a83af5dad31 allergy.csv.gz
2dc6d63f9807c7e663ffa253998691605d527b702ac1db8cc5dda92308061e78 apacheApsVar.csv.gz
ce799692737f7a712c59aa8fbb9a302cee7c719887f0638caed3ae144b166821 apachePatientResult.csv.gz
99d5a4ab2c5cd07b6ee0a540c86a576e5975ed3b93df8525e3d287d5babf3eae apachePredVar.csv.gz
af0dff697752a0d98200abdbf054a935a577319b26969a27a5287b18790d633e carePlanCareProvider.csv.gz
dfb5eafc8cb6d0c96f6ac289dd49998939df353d919ca0451d74542fd13a2f7f carePlanEOL.csv.gz
f095258743a05717dda031b9a4f00061cffe82e06ae793c0e51f2890e1dcd44e carePlanGeneral.csv.gz
b56d3443683b1b6a29d64da1ffd1de2662aac87b1f49560af720c1bd1325558e carePlanGoal.csv.gz
413ff454d00a3a5b295f4bbd1d8a697a5657c5ac828cbe757a43cd5e664082a8 carePlanInfectiousDisease.csv.gz
58e32f4c0620b22323a46336f9e406d90ce128b4005349b8e40f181f41672617 customLab.csv.gz
c99770c25fdeaee1eb34e490f982bd17459bc8902f951a2ae23adef65e7b1b52 diagnosis.csv.gz
4ed356f9c4e7c8ce80e89241697e94b77f21c2f325cd6ad126794b1e92805ef4 hospital.csv.gz
3b9f024d28682884a820763ac516ae68b247ebf17903fee4f38240c04886d527 infusiondrug.csv.gz
45db8ee0e64a4e3745284bde5828f740175770c45d00ea0c27daff789d18106e intakeOutput.csv.gz
e06852850abeb65211bc22ac43f17121ba41b14656fac862396449af84d8273a lab.csv.gz
480a251570a27932110452f66f248061f712c306663c274f78f90875648cb720 medication.csv.gz
0250a23d70033f27e1954ced50935cefedaaf3fddd5a5cf5bda2d5a6927eb94d microLab.csv.gz
ec67b0cd294a555dc39849a15eea2760e4f8696abbb293094b2003662c997ffa note.csv.gz
1664d3a7a0f9f535a15e2d032c270cfd64bab2d5a08b6bec1b31133893934d09 nurseAssessment.csv.gz
3cfde5dc14cc324e68c9af0807c5572e71fd7e167c5315e6b68cc241e0ff8d47 nurseCare.csv.gz
475000d63d4ef883b2e891d7197997201300bedc13fcf23e67add1abee11dafe nurseCharting.csv.gz
3af6e3101c037347365d81daf73ea487ba12e14a6a10f0b2ed53beed2e30c7d5 pastHistory.csv.gz
15e1eb52169828e3cfff3b67132a087298de4d0365bbb31bb294f6043bffd474 patient.csv.gz
7c11cae91ce2828964b9212bb49e601a0e48911ef7df5480b547621845c9d73f physicalExam.csv.gz
9e260512866498995b49d0f0676795b62115fc1045de3f7daf2e356769259de7 respiratoryCare.csv.gz
21bfe647fea0a229d09ff04c775ec4270d20ae084131a987943da836df534235 respiratoryCharting.csv.gz
0c9beffc86dcdd7c16b02268266a85510d122c4cbca69915245478a567840215 sqlite/eicu_v2_0_1.sqlite3.gz
daefee030fa1ad29593dce880ad86bdfbdbb1e33fcb3e78fa21d71cb01a08628 treatment.csv.gz
c294f46647990cb648b3ebfa589e83f330bdc0c2c922b5e8f23aa0ef99954635 vitalAperiodic.csv.gz
04dc093a2e77cd4c52ac7f2a47a8356fbb7456c7f15deb20d5abb1ca4303231d vitalPeriodic.csv.gz
Binary file added test-resources/core/eicudemo/admissionDx.csv.gz
Binary file not shown.
Binary file not shown.
Binary file added test-resources/core/eicudemo/allergy.csv.gz
Binary file not shown.
Binary file added test-resources/core/eicudemo/apacheApsVar.csv.gz
Binary file not shown.
Binary file not shown.
Binary file added test-resources/core/eicudemo/apachePredVar.csv.gz
Binary file not shown.
Binary file not shown.
Binary file added test-resources/core/eicudemo/carePlanEOL.csv.gz
Binary file not shown.
Binary file not shown.
Binary file added test-resources/core/eicudemo/carePlanGoal.csv.gz
Binary file not shown.
Binary file not shown.
Binary file added test-resources/core/eicudemo/customLab.csv.gz
Binary file not shown.
Binary file added test-resources/core/eicudemo/diagnosis.csv.gz
Binary file not shown.
Binary file added test-resources/core/eicudemo/hospital.csv.gz
Binary file not shown.
Binary file added test-resources/core/eicudemo/infusiondrug.csv.gz
Binary file not shown.
Binary file added test-resources/core/eicudemo/lab.csv.gz
Binary file not shown.
Binary file added test-resources/core/eicudemo/medication.csv.gz
Binary file not shown.
Binary file added test-resources/core/eicudemo/microLab.csv.gz
Binary file not shown.
Binary file added test-resources/core/eicudemo/note.csv.gz
Binary file not shown.
Binary file not shown.
Binary file added test-resources/core/eicudemo/nurseCare.csv.gz
Binary file not shown.
Binary file added test-resources/core/eicudemo/nurseCharting.csv.gz
Binary file not shown.
Binary file added test-resources/core/eicudemo/pastHistory.csv.gz
Binary file not shown.
Binary file added test-resources/core/eicudemo/patient.csv.gz
Binary file not shown.
Binary file added test-resources/core/eicudemo/physicalExam.csv.gz
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file added test-resources/core/eicudemo/treatment.csv.gz
Binary file not shown.
Binary file not shown.
Binary file added test-resources/core/eicudemo/vitalPeriodic.csv.gz
Binary file not shown.
102 changes: 102 additions & 0 deletions tests/core/test_eicu.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
import unittest
import os
from pathlib import Path

from pyhealth.datasets import eICUDataset


class TesteICUDemo(unittest.TestCase):
"""Test eICU dataset with demo data from local test resources."""

def setUp(self):
"""Set up demo dataset path for each test."""
self._setup_dataset_path()
self._load_dataset()

def _setup_dataset_path(self):
"""Get path to local eICU demo dataset in test resources."""
# Get the path to the test-resources/core/mimic3demo directory
test_dir = Path(__file__).parent.parent.parent
self.demo_dataset_path = str(test_dir / "test-resources" / "core" / "eicudemo")

print(f"\n{'='*60}")
print(f"Setting up eICU demo dataset")
print(f"Dataset path: {self.demo_dataset_path}")

# Verify the dataset exists
if not os.path.exists(self.demo_dataset_path):
raise unittest.SkipTest(
f"eICU demo dataset not found at {self.demo_dataset_path}"
)

# List files in the dataset directory
files = os.listdir(self.demo_dataset_path)
print(f"Found {len(files)} files in dataset directory:")
for f in sorted(files):
file_path = os.path.join(self.demo_dataset_path, f)
size = os.path.getsize(file_path) / 1024 #
print(f" - {f} ({size:.1f} KB)")
print(f"{'='*60}\n")

def _load_dataset(self):
"""Load the dataset for testing."""
tables = ["hospital", "admissiondx", "diagnosis", "medication", "lab", "treatment", "physicalExam", "admissiondrug", "allergy", "apacheapsvar",
"apachepatientresult", "apachepredvar", "careplancareprovider", "careplaneol", "careplangeneral","careplangoal",
"careplaninfectiousdisease","customlab","infusiondrug", "intakeoutput","microlab","note",
"nurseassessment","nursecare","nursecharting", "pasthistory",
"respiratorycare", "respiratorycharting",
"vitalPeriodic","vitalAperiodic"]
print(f"Loading eICUDataset with tables: {tables}")
self.dataset = eICUDataset(root=self.demo_dataset_path, tables=tables)
print(f"✓ Dataset loaded successfully")
print(self.dataset)
#print(f" Total patients: {len(self.dataset.patient)}")
print()

def test_stats(self):
"""Test .stats() method execution."""
print(f"\n{'='*60}")
print("TEST: test_stats()")
print(f"{'='*60}")
try:
print("Calling dataset.stats()...")
self.dataset.stats()
print("✓ dataset.stats() executed successfully")
except Exception as e:
print(f"✗ dataset.stats() failed with error: {e}")
self.fail(f"dataset.stats() failed: {e}")

def test_get_events(self):
"""Test get_patient and get_events methods with patient 141764."""
print(f"\n{'='*60}")
print("TEST: test_get_events()")
print(f"{'='*60}")

# Test get_patient method
print("Getting patient 141764...")
patient = self.dataset.get_patient("141764")
self.assertIsNotNone(patient, msg="Patient 141764 should exist in demo dataset")
print(f"✓ Patient 141764 found: {patient}")

# Test get_events method
print("Getting events for patient 141764...")
events = patient.get_events()
self.assertIsNotNone(events, msg="get_events() should not return None")
self.assertIsInstance(events, list, msg="get_events() should return a list")
self.assertGreater(
len(events), 0, msg="get_events() should not return an empty list"
)
print(f"✓ Retrieved {len(events)} events")
# print(f" Event types: {set(e[0] for e in events)}")

# Show sample events
print(f"\nSample events (first 3):")
for i, event in enumerate(events[:3]):
print(f" {i+1}. Type: {event['event_type']}, Time: {event['timestamp']}")
# print(f" {i+1}. Type: {event[0]}, Time: {event[1]}, Data: {event[2]}")

print(f"✓ test_get_events() passed successfully")


if __name__ == "__main__":
unittest.main()