From 81ae4b0954f07172bb2701e11bc544d9737cae25 Mon Sep 17 00:00:00 2001 From: John Wu Date: Fri, 19 Dec 2025 14:46:04 -0600 Subject: [PATCH 1/4] init commit, will need to debug and clean later --- docs/api/tasks.rst | 1 + docs/api/tasks/pyhealth.tasks.dka.rst | 8 + .../benchmark_perf/benchmark_workers_12.py | 188 ++++ examples/clinical_tasks/dka_mimic4.py | 390 ++++++++ examples/timeseries_mimic4.ipynb | 938 +++++++++--------- pyhealth/tasks/__init__.py | 1 + pyhealth/tasks/dka.py | 497 ++++++++++ tests/core/test_mimic4_dka.py | 240 +++++ tests/core/test_mimic4_los.py | 179 ++++ 9 files changed, 1969 insertions(+), 473 deletions(-) create mode 100644 docs/api/tasks/pyhealth.tasks.dka.rst create mode 100644 examples/benchmark_perf/benchmark_workers_12.py create mode 100644 examples/clinical_tasks/dka_mimic4.py create mode 100644 pyhealth/tasks/dka.py create mode 100644 tests/core/test_mimic4_dka.py create mode 100644 tests/core/test_mimic4_los.py diff --git a/docs/api/tasks.rst b/docs/api/tasks.rst index 934886e2d..706e6a3a7 100644 --- a/docs/api/tasks.rst +++ b/docs/api/tasks.rst @@ -79,6 +79,7 @@ Available Tasks MIMIC-III ICD-9 Coding Cardiology Detection COVID-19 CXR Classification + DKA Prediction (MIMIC-IV) Drug Recommendation EEG Abnormal EEG Events diff --git a/docs/api/tasks/pyhealth.tasks.dka.rst b/docs/api/tasks/pyhealth.tasks.dka.rst new file mode 100644 index 000000000..814a2297a --- /dev/null +++ b/docs/api/tasks/pyhealth.tasks.dka.rst @@ -0,0 +1,8 @@ +pyhealth.tasks.dka +================== + +.. autoclass:: pyhealth.tasks.dka.DKAPredictionMIMIC4 + :members: + :undoc-members: + :show-inheritance: + diff --git a/examples/benchmark_perf/benchmark_workers_12.py b/examples/benchmark_perf/benchmark_workers_12.py new file mode 100644 index 000000000..01302fa02 --- /dev/null +++ b/examples/benchmark_perf/benchmark_workers_12.py @@ -0,0 +1,188 @@ +"""Benchmark script for MIMIC-IV mortality prediction with num_workers=4. + +This benchmark measures: +1. Time to load base dataset +2. Time to process task with num_workers=4 +3. Total processing time +4. Cache sizes +5. Peak memory usage (with optional memory limit) +""" + +import time +import os +import threading +from pathlib import Path +import psutil +from pyhealth.datasets import MIMIC4Dataset +from pyhealth.tasks import MortalityPredictionStageNetMIMIC4 + +try: + import resource + + HAS_RESOURCE = True +except ImportError: + HAS_RESOURCE = False + + +PEAK_MEM_USAGE = 0 +SELF_PROC = psutil.Process(os.getpid()) + + +def track_mem(): + """Background thread to track peak memory usage.""" + global PEAK_MEM_USAGE + while True: + m = SELF_PROC.memory_info().rss + if m > PEAK_MEM_USAGE: + PEAK_MEM_USAGE = m + time.sleep(0.1) + + +def set_memory_limit(max_memory_gb): + """Set hard memory limit for the process. + + Args: + max_memory_gb: Maximum memory in GB (e.g., 8 for 8GB) + + Note: + If limit is exceeded, the process will raise MemoryError. + Only works on Unix-like systems (Linux, macOS). + """ + if not HAS_RESOURCE: + print( + "Warning: resource module not available (Windows?). " + "Memory limit not enforced." + ) + return + + max_memory_bytes = int(max_memory_gb * 1024**3) + try: + resource.setrlimit(resource.RLIMIT_AS, (max_memory_bytes, max_memory_bytes)) + print(f"✓ Memory limit set to {max_memory_gb} GB") + except Exception as e: + print(f"Warning: Failed to set memory limit: {e}") + + +def get_directory_size(path): + """Calculate total size of a directory in bytes.""" + total = 0 + try: + for entry in Path(path).rglob("*"): + if entry.is_file(): + total += entry.stat().st_size + except Exception as e: + print(f"Error calculating size for {path}: {e}") + return total + + +def format_size(size_bytes): + """Format bytes to human-readable size.""" + for unit in ["B", "KB", "MB", "GB", "TB"]: + if size_bytes < 1024.0: + return f"{size_bytes:.2f} {unit}" + size_bytes /= 1024.0 + return f"{size_bytes:.2f} PB" + + +def main(): + """Main benchmark function.""" + # Configuration + dev = False # Set to True for development/testing + enable_memory_limit = False # Set to True to enforce memory limit + max_memory_gb = 32 # Memory limit in GB (if enable_memory_limit=True) + + # Apply memory limit if enabled + if enable_memory_limit: + set_memory_limit(max_memory_gb) + + # Start memory tracking thread + mem_thread = threading.Thread(target=track_mem, daemon=True) + mem_thread.start() + + print("=" * 80) + print(f"BENCHMARK: num_workers=4, dev={dev}") + if enable_memory_limit: + print(f"Memory Limit: {max_memory_gb} GB (ENFORCED)") + else: + print("Memory Limit: None (unrestricted)") + print("=" * 80) + + # Define cache directories based on dev mode + cache_root = "/shared/rsaas/pyhealth/" + if dev: + cache_root += "_dev" + + # Track total time + total_start = time.time() # STEP 1: Load MIMIC-IV base dataset + print("\n[1/2] Loading MIMIC-IV base dataset...") + dataset_start = time.time() + + base_dataset = MIMIC4Dataset( + ehr_root="/srv/local/data/physionet.org/files/mimiciv/2.2/", + ehr_tables=[ + "patients", + "admissions", + "diagnoses_icd", + "procedures_icd", + "labevents", + ], + dev=dev, + cache_dir=f"{cache_root}/base_dataset", + ) + + dataset_time = time.time() - dataset_start + print(f"✓ Dataset loaded in {dataset_time:.2f} seconds") + + # STEP 2: Apply StageNet mortality prediction task with num_workers=12 + print("\n[2/2] Applying mortality prediction task (num_workers=12)...") + task_start = time.time() + + sample_dataset = base_dataset.set_task( + MortalityPredictionStageNetMIMIC4(), + num_workers=12, + cache_dir=f"{cache_root}/task_samples", + ) + + task_time = time.time() - task_start + print(f"✓ Task processing completed in {task_time:.2f} seconds") + + # Measure cache sizes + print("\n[3/3] Measuring cache sizes...") + base_cache_dir = f"{cache_root}/base_dataset" + task_cache_dir = f"{cache_root}/task_samples" + + base_cache_size = get_directory_size(base_cache_dir) + task_cache_size = get_directory_size(task_cache_dir) + total_cache_size = base_cache_size + task_cache_size + + print(f"✓ Base dataset cache: {format_size(base_cache_size)}") + print(f"✓ Task samples cache: {format_size(task_cache_size)}") + print(f"✓ Total cache size: {format_size(total_cache_size)}") + + # Total time and peak memory + total_time = time.time() - total_start + peak_mem = PEAK_MEM_USAGE + + # Print summary + print("\n" + "=" * 80) + print("BENCHMARK RESULTS") + print("=" * 80) + print("Configuration:") + print(" - num_workers: 4") + print(f" - dev mode: {dev}") + print(f" - Total samples: {len(sample_dataset)}") + print("\nTiming:") + print(f" - Dataset loading: {dataset_time:.2f}s") + print(f" - Task processing: {task_time:.2f}s") + print(f" - Total time: {total_time:.2f}s") + print("\nCache Sizes:") + print(f" - Base dataset cache: {format_size(base_cache_size)}") + print(f" - Task samples cache: {format_size(task_cache_size)}") + print(f" - Total cache: {format_size(total_cache_size)}") + print("\nMemory:") + print(f" - Peak memory usage: {format_size(peak_mem)}") + print("=" * 80) + + +if __name__ == "__main__": + main() diff --git a/examples/clinical_tasks/dka_mimic4.py b/examples/clinical_tasks/dka_mimic4.py new file mode 100644 index 000000000..d17201978 --- /dev/null +++ b/examples/clinical_tasks/dka_mimic4.py @@ -0,0 +1,390 @@ +""" +Example of using StageNet for DKA (Diabetic Ketoacidosis) prediction on MIMIC-IV. + +This example demonstrates: +1. Loading MIMIC-IV data with relevant tables for DKA prediction +2. Applying the DKAPredictionMIMIC4 task +3. Creating a SampleDataset with StageNet processors +4. Training a StageNet model for DKA prediction +5. Testing with synthetic hold-out set (unseen codes, varying lengths) + +Target Population: + - Patients with Type 1 Diabetes Mellitus (T1DM) + - Predicts DKA occurrence within 90 days of T1DM diagnosis +""" + +import os +import random +import numpy as np +import torch + +from pyhealth.datasets import ( + MIMIC4Dataset, + get_dataloader, + split_by_patient, + SampleDataset, +) +from pyhealth.datasets.utils import save_processors, load_processors +from pyhealth.models import StageNet +from pyhealth.tasks import DKAPredictionMIMIC4 +from pyhealth.trainer import Trainer + + +def generate_holdout_set( + sample_dataset: SampleDataset, num_samples: int = 10, seed: int = 42 +) -> SampleDataset: + """Generate synthetic hold-out set with unseen codes and varying lengths. + + This function creates synthetic samples to test the processor's ability to: + 1. Handle completely unseen tokens (mapped to ) + 2. Handle sequence lengths larger than training but within padding + + Args: + sample_dataset: Original SampleDataset with fitted processors + num_samples: Number of synthetic samples to generate + seed: Random seed for reproducibility + + Returns: + SampleDataset with synthetic samples using fitted processors + """ + random.seed(seed) + np.random.seed(seed) + + # Get the fitted processors + diagnoses_processor = sample_dataset.input_processors["diagnoses"] + + # Get max nested length from diagnoses processor + max_diag_len = diagnoses_processor._max_nested_len + # Handle both old and new processor versions + padding = getattr(diagnoses_processor, "_padding", 0) + + print("\n=== Hold-out Set Generation ===") + print(f"Diagnoses max nested length: {max_diag_len}") + print(f"Padding: {padding}") + print(f"Observed max (without padding): {max_diag_len - padding}") + + synthetic_samples = [] + + # DKA-relevant ICD codes for synthetic samples + synthetic_t1dm_codes = [ + "E1010", "E1011", "E1065", "E1100", "E1122", + "25001", "25003", "25011", "25013", + ] + synthetic_other_codes = [ + "I10", "N179", "J189", "K219", "R509", "I509", + ] + + for i in range(num_samples): + # Generate random number of visits (1-5) + num_visits = random.randint(1, 5) + + # Generate diagnosis codes + diagnoses_list = [] + diagnoses_times_list = [] + + for visit_idx in range(num_visits): + # Generate sequence length + observed_max = max_diag_len - padding + seq_len = random.randint(max(1, observed_max - 2), max(observed_max, 3)) + + # Mix of known and unseen codes + visit_codes = [] + for j in range(seq_len): + if random.random() < 0.3: + # 30% chance of T1DM-related code + visit_codes.append(random.choice(synthetic_t1dm_codes)) + elif random.random() < 0.5: + # 35% chance of other known code + visit_codes.append(random.choice(synthetic_other_codes)) + else: + # 35% chance of unseen code + visit_codes.append(f"NEWCODE_{i}_{visit_idx}_{j}") + + diagnoses_list.append(visit_codes) + + # Generate time intervals (hours from previous visit) + if visit_idx == 0: + diagnoses_times_list.append(0.0) + else: + diagnoses_times_list.append(random.uniform(24.0, 720.0)) + + # Generate lab data (6-dimensional vectors for DKA task) + # Categories: glucose, bicarbonate, anion_gap, potassium, sodium, chloride + num_lab_timestamps = random.randint(3, 10) + lab_values_list = [] + lab_times_list = [] + + for ts_idx in range(num_lab_timestamps): + # Generate 6D vector with realistic ranges + lab_vector = [] + # glucose (mg/dL) + lab_vector.append( + random.uniform(70.0, 500.0) if random.random() < 0.9 else None + ) + # bicarbonate (mEq/L) + lab_vector.append( + random.uniform(10.0, 30.0) if random.random() < 0.85 else None + ) + # anion_gap (mEq/L) + lab_vector.append( + random.uniform(8.0, 30.0) if random.random() < 0.7 else None + ) + # potassium (mEq/L) + lab_vector.append( + random.uniform(3.0, 6.5) if random.random() < 0.9 else None + ) + # sodium (mEq/L) + lab_vector.append( + random.uniform(130.0, 150.0) if random.random() < 0.9 else None + ) + # chloride (mEq/L) + lab_vector.append( + random.uniform(95.0, 110.0) if random.random() < 0.85 else None + ) + + lab_values_list.append(lab_vector) + lab_times_list.append(random.uniform(0.0, 48.0)) + + # Create sample in the expected format (before processing) + synthetic_sample = { + "patient_id": f"HOLDOUT_PATIENT_{i}", + "record_id": f"HOLDOUT_PATIENT_{i}", + "diagnoses": (diagnoses_times_list, diagnoses_list), + "labs": (lab_times_list, lab_values_list), + "label": random.randint(0, 1), + } + + synthetic_samples.append(synthetic_sample) + + # Create a new SampleDataset with the FITTED processors + holdout_dataset = SampleDataset( + samples=synthetic_samples, + input_schema=sample_dataset.input_schema, + output_schema=sample_dataset.output_schema, + dataset_name=f"{sample_dataset.dataset_name}_holdout", + task_name=sample_dataset.task_name, + input_processors=sample_dataset.input_processors, + output_processors=sample_dataset.output_processors, + ) + + print(f"Generated {len(holdout_dataset)} synthetic samples") + sample_seq_lens = [len(s["diagnoses"][1]) for s in synthetic_samples[:3]] + print(f"Sample diagnosis sequence lengths: {sample_seq_lens}") + sample_codes_per_visit = [ + [len(visit) for visit in s["diagnoses"][1]] for s in synthetic_samples[:3] + ] + print(f"Sample codes per visit: {sample_codes_per_visit}") + + return holdout_dataset + + +def main(): + """Main function to run DKA prediction pipeline.""" + + # Configuration + MIMIC4_ROOT = "/srv/local/data/physionet.org/files/mimiciv/2.2/" + PROCESSOR_DIR = "../../output/processors/stagenet_dka_mimic4" + CACHE_DIR = "../../mimic4_dka_stagenet_cache" + DEVICE = "cuda:0" if torch.cuda.is_available() else "cpu" + + print("=" * 60) + print("DKA PREDICTION WITH STAGENET ON MIMIC-IV") + print("=" * 60) + + # STEP 1: Load MIMIC-IV base dataset + print("\n=== Step 1: Loading MIMIC-IV Dataset ===") + base_dataset = MIMIC4Dataset( + ehr_root=MIMIC4_ROOT, + ehr_tables=[ + "patients", + "admissions", + "diagnoses_icd", + "procedures_icd", + "labevents", + ], + # dev=True, # Uncomment for faster development iteration + ) + + print(f"Dataset loaded with {len(base_dataset.patients)} patients") + + # STEP 2: Apply DKA prediction task + print("\n=== Step 2: Applying DKA Prediction Task ===") + + # Create task with 90-day DKA window and padding for unseen sequences + dka_task = DKAPredictionMIMIC4(dka_window_days=90, padding=20) + + print(f"Task: {dka_task.task_name}") + print(f"DKA window: {dka_task.dka_window_days} days") + print(f"Input schema: {list(dka_task.input_schema.keys())}") + print(f"Output schema: {list(dka_task.output_schema.keys())}") + + # Check for pre-fitted processors + if os.path.exists(os.path.join(PROCESSOR_DIR, "input_processors.pkl")): + print("\nLoading pre-fitted processors...") + input_processors, output_processors = load_processors(PROCESSOR_DIR) + + sample_dataset = base_dataset.set_task( + dka_task, + num_workers=4, + cache_dir=CACHE_DIR, + input_processors=input_processors, + output_processors=output_processors, + ) + else: + print("\nFitting new processors...") + sample_dataset = base_dataset.set_task( + dka_task, + num_workers=4, + cache_dir=CACHE_DIR, + ) + + # Save processors for future runs + print("Saving processors...") + os.makedirs(PROCESSOR_DIR, exist_ok=True) + save_processors(sample_dataset, PROCESSOR_DIR) + + print(f"\nTotal samples: {len(sample_dataset)}") + + # Count label distribution + label_counts = {0: 0, 1: 0} + for sample in sample_dataset.samples: + label_counts[sample["label"]] += 1 + + print(f"Label distribution:") + print(f" No DKA (0): {label_counts[0]} ({100*label_counts[0]/len(sample_dataset):.1f}%)") + print(f" Has DKA (1): {label_counts[1]} ({100*label_counts[1]/len(sample_dataset):.1f}%)") + + # Inspect a sample + sample = sample_dataset.samples[0] + print("\nSample structure:") + print(f" Patient ID: {sample['patient_id']}") + print(f" Diagnoses: {len(sample['diagnoses'][1])} admission(s)") + print(f" Labs: {len(sample['labs'][0])} timestep(s)") + print(f" Label: {sample['label']}") + + # STEP 3: Split dataset + print("\n=== Step 3: Splitting Dataset ===") + train_dataset, val_dataset, test_dataset = split_by_patient( + sample_dataset, [0.8, 0.1, 0.1] + ) + + print(f"Train: {len(train_dataset)} samples") + print(f"Validation: {len(val_dataset)} samples") + print(f"Test: {len(test_dataset)} samples") + + # Create dataloaders + train_loader = get_dataloader(train_dataset, batch_size=256, shuffle=True) + val_loader = get_dataloader(val_dataset, batch_size=256, shuffle=False) + test_loader = get_dataloader(test_dataset, batch_size=256, shuffle=False) + + # STEP 4: Initialize StageNet model + print("\n=== Step 4: Initializing StageNet Model ===") + model = StageNet( + dataset=sample_dataset, + embedding_dim=128, + chunk_size=128, + levels=3, + dropout=0.3, + ) + + num_params = sum(p.numel() for p in model.parameters()) + print(f"Model parameters: {num_params:,}") + + # STEP 5: Train the model + print("\n=== Step 5: Training Model ===") + trainer = Trainer( + model=model, + device=DEVICE, + metrics=["pr_auc", "roc_auc", "accuracy", "f1"], + ) + + trainer.train( + train_dataloader=train_loader, + val_dataloader=val_loader, + epochs=20, + monitor="roc_auc", + optimizer_params={"lr": 1e-4}, + ) + + # STEP 6: Evaluate on test set + print("\n=== Step 6: Evaluation ===") + results = trainer.evaluate(test_loader) + print("\nTest Results:") + for metric, value in results.items(): + print(f" {metric}: {value:.4f}") + + # STEP 7: Inspect model predictions + print("\n=== Step 7: Sample Predictions ===") + sample_batch = next(iter(test_loader)) + with torch.no_grad(): + output = model(**sample_batch) + + print(f"Predicted probabilities: {output['y_prob'][:5]}") + print(f"True labels: {output['y_true'][:5]}") + + # STEP 8: Test with synthetic hold-out set + print("\n" + "=" * 60) + print("TESTING PROCESSOR ROBUSTNESS WITH SYNTHETIC HOLD-OUT SET") + print("=" * 60) + + holdout_dataset = generate_holdout_set( + sample_dataset=sample_dataset, num_samples=50, seed=42 + ) + + holdout_loader = get_dataloader(holdout_dataset, batch_size=16, shuffle=False) + + # Inspect processed samples + print("\n=== Inspecting Processed Hold-out Samples ===") + holdout_batch = next(iter(holdout_loader)) + + print(f"Batch size: {len(holdout_batch['patient_id'])}") + print(f"Diagnoses tensor shape: {holdout_batch['diagnoses'][1].shape}") + + # Check for unknown tokens + diagnoses_processor = sample_dataset.input_processors["diagnoses"] + unk_token_idx = diagnoses_processor.code_vocab[""] + pad_token_idx = diagnoses_processor.code_vocab[""] + + print(f"\n token index: {unk_token_idx}") + print(f" token index: {pad_token_idx}") + + # Count unknown and padding tokens + diag_values = holdout_batch["diagnoses"][1] + num_unk = (diag_values == unk_token_idx).sum().item() + num_pad = (diag_values == pad_token_idx).sum().item() + total_tokens = diag_values.numel() + + print("\nToken statistics in hold-out batch:") + print(f" Total tokens: {total_tokens}") + print(f" Unknown tokens: {num_unk} ({100*num_unk/total_tokens:.1f}%)") + print(f" Padding tokens: {num_pad} ({100*num_pad/total_tokens:.1f}%)") + + # Run model inference on hold-out set + print("\n=== Model Inference on Hold-out Set ===") + with torch.no_grad(): + holdout_output = model(**holdout_batch) + + print(f"Predictions shape: {holdout_output['y_prob'].shape}") + print(f"Sample predictions: {holdout_output['y_prob'][:5]}") + + print("\n" + "=" * 60) + print("HOLD-OUT SET TEST COMPLETED SUCCESSFULLY!") + print("=" * 60) + + # STEP 9: Processor information + print("\n=== Processor Information ===") + print(f"Processors saved at: {PROCESSOR_DIR}") + print(f"\nDiagnoses Processor:") + print(f" Vocabulary size: {diagnoses_processor.size()}") + print(f" Max nested length: {diagnoses_processor._max_nested_len}") + + labs_processor = sample_dataset.input_processors["labs"] + print(f"\nLabs Processor:") + print(f" Feature dimension: {labs_processor.size}") + + return results + + +if __name__ == "__main__": + main() + diff --git a/examples/timeseries_mimic4.ipynb b/examples/timeseries_mimic4.ipynb index c3ed8555c..3700a33b1 100644 --- a/examples/timeseries_mimic4.ipynb +++ b/examples/timeseries_mimic4.ipynb @@ -2,7 +2,7 @@ "cells": [ { "cell_type": "code", - "execution_count": 5, + "execution_count": 1, "id": "8f384611", "metadata": {}, "outputs": [ @@ -10,16 +10,79 @@ "name": "stdout", "output_type": "stream", "text": [ - "Memory usage Starting MIMIC4Dataset init: 3723.0 MB\n", + "Memory usage Starting MIMIC4Dataset init: 772.4 MB\n", "Initializing mimic4 dataset from /srv/local/data/physionet.org/files/mimiciv/2.2/|None|None (dev mode: True)\n", "Initializing MIMIC4EHRDataset with tables: ['diagnoses_icd', 'procedures_icd', 'labevents', 'prescriptions'] (dev mode: True)\n", "Using default EHR config: /home/johnwu3/projects/PyHealth_Branch_Testing/PyHealth/pyhealth/datasets/configs/mimic4_ehr.yaml\n", - "Memory usage Before initializing mimic4_ehr: 3723.0 MB\n", + "Memory usage Before initializing mimic4_ehr: 772.4 MB\n", "Initializing mimic4_ehr dataset from /srv/local/data/physionet.org/files/mimiciv/2.2/ (dev mode: True)\n", - "Memory usage After initializing mimic4_ehr: 3723.0 MB\n", - "Memory usage After EHR dataset initialization: 3723.0 MB\n", - "Memory usage Completed MIMIC4Dataset init: 3723.0 MB\n", + "Memory usage After initializing mimic4_ehr: 772.5 MB\n", + "Memory usage After EHR dataset initialization: 772.5 MB\n", + "Memory usage Completed MIMIC4Dataset init: 772.5 MB\n", "Setting task InHospitalMortalityMIMIC4 for mimic4 base dataset...\n", + "Combining data from ehr dataset\n", + "Scanning table: diagnoses_icd from /srv/local/data/physionet.org/files/mimiciv/2.2/hosp/diagnoses_icd.csv.gz\n", + "Joining with table: /srv/local/data/physionet.org/files/mimiciv/2.2/hosp/admissions.csv.gz\n", + "Scanning table: procedures_icd from /srv/local/data/physionet.org/files/mimiciv/2.2/hosp/procedures_icd.csv.gz\n", + "Joining with table: /srv/local/data/physionet.org/files/mimiciv/2.2/hosp/admissions.csv.gz\n", + "Scanning table: labevents from /srv/local/data/physionet.org/files/mimiciv/2.2/hosp/labevents.csv.gz\n", + "Joining with table: /srv/local/data/physionet.org/files/mimiciv/2.2/hosp/d_labitems.csv.gz\n", + "Scanning table: prescriptions from /srv/local/data/physionet.org/files/mimiciv/2.2/hosp/prescriptions.csv.gz\n", + "Scanning table: patients from /srv/local/data/physionet.org/files/mimiciv/2.2/hosp/patients.csv.gz\n", + "Scanning table: admissions from /srv/local/data/physionet.org/files/mimiciv/2.2/hosp/admissions.csv.gz\n", + "Scanning table: icustays from /srv/local/data/physionet.org/files/mimiciv/2.2/icu/icustays.csv.gz\n", + "Creating combined dataframe\n", + "Dev mode enabled: limiting to 1000 patients\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2025-12-18 20:49:34,422 - distributed.shuffle._worker_plugin - ERROR - [Errno 39] Directory not empty: PosixPath('/home/johnwu3/projects/PyHealth_Branch_Testing/PyHealth/benchmark_cache/mimic4_ehr_with_prescr/dask_scratch/dask-scratch-space/worker-89c2re6g/shuffle-8936a2b693236eda400883caa2af525d-2')\n", + "Traceback (most recent call last):\n", + " File \"/home/johnwu3/miniconda3/envs/pyhealth312/lib/python3.12/site-packages/distributed/utils.py\", line 825, in wrapper\n", + " return await func(*args, **kwargs)\n", + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^\n", + " File \"/home/johnwu3/miniconda3/envs/pyhealth312/lib/python3.12/site-packages/distributed/shuffle/_worker_plugin.py\", line 76, in close\n", + " await shuffle_run.close()\n", + " File \"/home/johnwu3/miniconda3/envs/pyhealth312/lib/python3.12/site-packages/distributed/shuffle/_core.py\", line 311, in close\n", + " await self._disk_buffer.close()\n", + " File \"/home/johnwu3/miniconda3/envs/pyhealth312/lib/python3.12/site-packages/distributed/shuffle/_disk.py\", line 228, in close\n", + " shutil.rmtree(self.directory)\n", + " File \"/home/johnwu3/miniconda3/envs/pyhealth312/lib/python3.12/shutil.py\", line 759, in rmtree\n", + " _rmtree_safe_fd(stack, onexc)\n", + " File \"/home/johnwu3/miniconda3/envs/pyhealth312/lib/python3.12/shutil.py\", line 703, in _rmtree_safe_fd\n", + " onexc(func, path, err)\n", + " File \"/home/johnwu3/miniconda3/envs/pyhealth312/lib/python3.12/shutil.py\", line 662, in _rmtree_safe_fd\n", + " os.rmdir(name, dir_fd=dirfd)\n", + "OSError: [Errno 39] Directory not empty: PosixPath('/home/johnwu3/projects/PyHealth_Branch_Testing/PyHealth/benchmark_cache/mimic4_ehr_with_prescr/dask_scratch/dask-scratch-space/worker-89c2re6g/shuffle-8936a2b693236eda400883caa2af525d-2')\n", + "Task exception was never retrieved\n", + "future: exception=OSError(39, 'Directory not empty')>\n", + "Traceback (most recent call last):\n", + " File \"/home/johnwu3/miniconda3/envs/pyhealth312/lib/python3.12/site-packages/distributed/utils.py\", line 825, in wrapper\n", + " return await func(*args, **kwargs)\n", + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^\n", + " File \"/home/johnwu3/miniconda3/envs/pyhealth312/lib/python3.12/site-packages/distributed/shuffle/_worker_plugin.py\", line 76, in close\n", + " await shuffle_run.close()\n", + " File \"/home/johnwu3/miniconda3/envs/pyhealth312/lib/python3.12/site-packages/distributed/shuffle/_core.py\", line 311, in close\n", + " await self._disk_buffer.close()\n", + " File \"/home/johnwu3/miniconda3/envs/pyhealth312/lib/python3.12/site-packages/distributed/shuffle/_disk.py\", line 228, in close\n", + " shutil.rmtree(self.directory)\n", + " File \"/home/johnwu3/miniconda3/envs/pyhealth312/lib/python3.12/shutil.py\", line 759, in rmtree\n", + " _rmtree_safe_fd(stack, onexc)\n", + " File \"/home/johnwu3/miniconda3/envs/pyhealth312/lib/python3.12/shutil.py\", line 703, in _rmtree_safe_fd\n", + " onexc(func, path, err)\n", + " File \"/home/johnwu3/miniconda3/envs/pyhealth312/lib/python3.12/shutil.py\", line 662, in _rmtree_safe_fd\n", + " os.rmdir(name, dir_fd=dirfd)\n", + "OSError: [Errno 39] Directory not empty: PosixPath('/home/johnwu3/projects/PyHealth_Branch_Testing/PyHealth/benchmark_cache/mimic4_ehr_with_prescr/dask_scratch/dask-scratch-space/worker-89c2re6g/shuffle-8936a2b693236eda400883caa2af525d-2')\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Caching event dataframe to ../benchmark_cache/mimic4_ehr_with_prescr/global_event_df.parquet...\n", "Applying task transformations on data...\n" ] }, @@ -27,13 +90,13 @@ "name": "stderr", "output_type": "stream", "text": [ - "100%|██████████| 1000/1000 [00:31<00:00, 31.69it/s]\n" + "100%|██████████| 1000/1000 [00:30<00:00, 33.20it/s]\n" ] }, { "data": { "application/vnd.jupyter.widget-view+json": { - "model_id": "54eed30b33da4237a78d382f3e761b68", + "model_id": "469efd6561a345b69921e8a464a6f6f8", "version_major": 2, "version_minor": 0 }, @@ -49,14 +112,28 @@ "output_type": "stream", "text": [ "\n", - "Fitting processors on the dataset...\n", + "Fitting processors on the dataset...\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "/tmp/ipykernel_1324622/2254465948.py:13: UserWarning: A newer version of litdata is available (0.2.59). Please consider upgrading with `pip install -U litdata`. Not all functionalities of the platform can be guaranteed to work with the current version.\n", + " samples = dataset.set_task(task, num_workers=4, cache_dir=\"../benchmark_cache/mimic4_ihm_w_pre2/\")\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ "Label mortality vocab: {0: 0, 1: 1}\n", "Processing samples and saving to ../benchmark_cache/mimic4_ihm_w_pre2...\n", "Create an account on https://lightning.ai/ to optimize your data faster using multiple nodes and large machines.\n", "Setting multiprocessing start_method to fork. Tip: Libraries relying on lock can hang with `fork`. To use `spawn` in notebooks, move your code to files and import it within the notebook.\n", "Storing the files under /home/johnwu3/projects/PyHealth_Branch_Testing/PyHealth/benchmark_cache/mimic4_ihm_w_pre2\n", "Setup started with fast_dev_run=False.\n", - "Setup finished in 0.008 seconds. Found 1824 items to process.\n", + "Setup finished in 0.021 seconds. Found 1824 items to process.\n", "Starting 4 workers with 1824 items. The progress bar is only updated when a worker finishes.\n", "Workers are ready ! Starting data processing...\n" ] @@ -64,7 +141,7 @@ { "data": { "application/vnd.jupyter.widget-view+json": { - "model_id": "148d7acc833b4cd2aaf57e8e1f05adc8", + "model_id": "de4b312fdd274c6d9a4f82ca36f10f03", "version_major": 2, "version_minor": 0 }, @@ -80,16 +157,16 @@ "output_type": "stream", "text": [ "Rank 0 inferred the following `['str', 'str', 'tensor', 'no_header_tensor:1']` data format.\n", - "Rank 2 inferred the following `['str', 'str', 'tensor', 'no_header_tensor:1']` data format.\n", "Rank 1 inferred the following `['str', 'str', 'tensor', 'no_header_tensor:1']` data format.\n", + "Rank 2 inferred the following `['str', 'str', 'tensor', 'no_header_tensor:1']` data format.\n", "Rank 3 inferred the following `['str', 'str', 'tensor', 'no_header_tensor:1']` data format.\n", "Worker 0 is terminating.\n", - "Worker 2 is terminating.\n", "Worker 1 is terminating.\n", + "Worker 2 is terminating.\n", + "Worker 0 is done.\n", "Worker 3 is terminating.\n", - "Worker 2 is done.\n", "Worker 1 is done.\n", - "Worker 0 is done.\n", + "Worker 2 is done.\n", "Worker 3 is done.\n", "Workers are finished.\n", "Finished data processing!\n", @@ -145,7 +222,7 @@ }, { "cell_type": "code", - "execution_count": 6, + "execution_count": 2, "id": "ca618021", "metadata": {}, "outputs": [ @@ -159,399 +236,314 @@ { "data": { "text/plain": [ - "[Event(event_type='patients', timestamp=datetime.datetime(2025, 12, 18, 12, 2, 11, 324654), attr_dict={'gender': 'M', 'anchor_age': '73', 'anchor_year': '2137', 'anchor_year_group': '2008 - 2010', 'dod': None}),\n", - " Event(event_type='labevents', timestamp=datetime.datetime(2136, 6, 21, 12, 25), attr_dict={'itemid': '51006', 'label': 'Urea Nitrogen', 'fluid': 'Blood', 'category': 'Chemistry', 'value': '16', 'valuenum': '16', 'valueuom': 'mg/dL', 'flag': None, 'storetime': '2136-06-21 17:20:00'}),\n", - " Event(event_type='labevents', timestamp=datetime.datetime(2136, 6, 21, 12, 25), attr_dict={'itemid': '50983', 'label': 'Sodium', 'fluid': 'Blood', 'category': 'Chemistry', 'value': '144', 'valuenum': '144', 'valueuom': 'mEq/L', 'flag': None, 'storetime': '2136-06-21 17:20:00'}),\n", - " Event(event_type='labevents', timestamp=datetime.datetime(2136, 6, 21, 12, 25), attr_dict={'itemid': '50974', 'label': 'Prostate Specific Antigen', 'fluid': 'Blood', 'category': 'Chemistry', 'value': '___', 'valuenum': '7.4', 'valueuom': 'ng/mL', 'flag': 'abnormal', 'storetime': '2136-06-22 01:51:00'}),\n", - " Event(event_type='labevents', timestamp=datetime.datetime(2136, 6, 21, 12, 25), attr_dict={'itemid': '50971', 'label': 'Potassium', 'fluid': 'Blood', 'category': 'Chemistry', 'value': '4.3', 'valuenum': '4.3', 'valueuom': 'mEq/L', 'flag': None, 'storetime': '2136-06-21 17:20:00'}),\n", - " Event(event_type='labevents', timestamp=datetime.datetime(2136, 6, 21, 12, 25), attr_dict={'itemid': '50963', 'label': 'NTproBNP', 'fluid': 'Blood', 'category': 'Chemistry', 'value': '___', 'valuenum': '127', 'valueuom': 'pg/mL', 'flag': None, 'storetime': '2136-06-21 20:11:00'}),\n", - " Event(event_type='labevents', timestamp=datetime.datetime(2136, 6, 21, 12, 25), attr_dict={'itemid': '50920', 'label': 'Estimated GFR (MDRD equation)', 'fluid': 'Blood', 'category': 'Chemistry', 'value': None, 'valuenum': None, 'valueuom': None, 'flag': None, 'storetime': '2136-06-21 17:20:00'}),\n", - " Event(event_type='labevents', timestamp=datetime.datetime(2136, 6, 21, 12, 25), attr_dict={'itemid': '50912', 'label': 'Creatinine', 'fluid': 'Blood', 'category': 'Chemistry', 'value': '0.8', 'valuenum': '0.8', 'valueuom': 'mg/dL', 'flag': None, 'storetime': '2136-06-21 17:20:00'}),\n", - " Event(event_type='labevents', timestamp=datetime.datetime(2136, 6, 21, 12, 25), attr_dict={'itemid': '50902', 'label': 'Chloride', 'fluid': 'Blood', 'category': 'Chemistry', 'value': '107', 'valuenum': '107', 'valueuom': 'mEq/L', 'flag': None, 'storetime': '2136-06-21 17:20:00'}),\n", - " Event(event_type='labevents', timestamp=datetime.datetime(2136, 6, 21, 12, 25), attr_dict={'itemid': '50882', 'label': 'Bicarbonate', 'fluid': 'Blood', 'category': 'Chemistry', 'value': '28', 'valuenum': '28', 'valueuom': 'mEq/L', 'flag': None, 'storetime': '2136-06-21 17:20:00'}),\n", - " Event(event_type='labevents', timestamp=datetime.datetime(2136, 6, 21, 12, 25), attr_dict={'itemid': '50868', 'label': 'Anion Gap', 'fluid': 'Blood', 'category': 'Chemistry', 'value': '13', 'valuenum': '13', 'valueuom': 'mEq/L', 'flag': None, 'storetime': '2136-06-21 17:20:00'}),\n", - " Event(event_type='labevents', timestamp=datetime.datetime(2136, 11, 15, 12, 10), attr_dict={'itemid': '50974', 'label': 'Prostate Specific Antigen', 'fluid': 'Blood', 'category': 'Chemistry', 'value': '___', 'valuenum': '6.6', 'valueuom': 'ng/mL', 'flag': 'abnormal', 'storetime': '2136-11-15 20:28:00'}),\n", - " Event(event_type='labevents', timestamp=datetime.datetime(2137, 2, 21, 11, 40), attr_dict={'itemid': '50974', 'label': 'Prostate Specific Antigen', 'fluid': 'Blood', 'category': 'Chemistry', 'value': '___', 'valuenum': '6.7', 'valueuom': 'ng/mL', 'flag': 'abnormal', 'storetime': '2137-02-21 15:09:00'}),\n", - " Event(event_type='labevents', timestamp=datetime.datetime(2137, 4, 17, 1, 4), attr_dict={'itemid': '50911', 'label': 'Creatine Kinase, MB Isoenzyme', 'fluid': 'Blood', 'category': 'Chemistry', 'value': '4', 'valuenum': '4', 'valueuom': 'ng/mL', 'flag': None, 'storetime': '2137-04-17 02:36:00'}),\n", - " Event(event_type='labevents', timestamp=datetime.datetime(2137, 4, 17, 1, 4), attr_dict={'itemid': '50910', 'label': 'Creatine Kinase (CK)', 'fluid': 'Blood', 'category': 'Chemistry', 'value': '153', 'valuenum': '153', 'valueuom': 'IU/L', 'flag': None, 'storetime': '2137-04-17 02:03:00'}),\n", - " Event(event_type='labevents', timestamp=datetime.datetime(2137, 4, 17, 1, 4), attr_dict={'itemid': '50902', 'label': 'Chloride', 'fluid': 'Blood', 'category': 'Chemistry', 'value': '108', 'valuenum': '108', 'valueuom': 'mEq/L', 'flag': None, 'storetime': '2137-04-17 02:03:00'}),\n", - " Event(event_type='labevents', timestamp=datetime.datetime(2137, 4, 17, 1, 4), attr_dict={'itemid': '50882', 'label': 'Bicarbonate', 'fluid': 'Blood', 'category': 'Chemistry', 'value': '29', 'valuenum': '29', 'valueuom': 'mEq/L', 'flag': None, 'storetime': '2137-04-17 02:03:00'}),\n", - " Event(event_type='labevents', timestamp=datetime.datetime(2137, 4, 17, 1, 4), attr_dict={'itemid': '50868', 'label': 'Anion Gap', 'fluid': 'Blood', 'category': 'Chemistry', 'value': '13', 'valuenum': '13', 'valueuom': 'mEq/L', 'flag': None, 'storetime': '2137-04-17 02:03:00'}),\n", - " Event(event_type='labevents', timestamp=datetime.datetime(2137, 4, 17, 1, 4), attr_dict={'itemid': '51301', 'label': 'White Blood Cells', 'fluid': 'Blood', 'category': 'Hematology', 'value': '8.2', 'valuenum': '8.2', 'valueuom': 'K/uL', 'flag': None, 'storetime': '2137-04-17 01:35:00'}),\n", - " Event(event_type='labevents', timestamp=datetime.datetime(2137, 4, 17, 1, 4), attr_dict={'itemid': '51279', 'label': 'Red Blood Cells', 'fluid': 'Blood', 'category': 'Hematology', 'value': '4.18', 'valuenum': '4.18', 'valueuom': 'm/uL', 'flag': 'abnormal', 'storetime': '2137-04-17 01:35:00'}),\n", - " Event(event_type='labevents', timestamp=datetime.datetime(2137, 4, 17, 1, 4), attr_dict={'itemid': '51277', 'label': 'RDW', 'fluid': 'Blood', 'category': 'Hematology', 'value': '15.4', 'valuenum': '15.4', 'valueuom': '%', 'flag': None, 'storetime': '2137-04-17 01:35:00'}),\n", - " Event(event_type='labevents', timestamp=datetime.datetime(2137, 4, 17, 1, 4), attr_dict={'itemid': '51265', 'label': 'Platelet Count', 'fluid': 'Blood', 'category': 'Hematology', 'value': '222', 'valuenum': '222', 'valueuom': 'K/uL', 'flag': None, 'storetime': '2137-04-17 01:35:00'}),\n", - " Event(event_type='labevents', timestamp=datetime.datetime(2137, 4, 17, 1, 4), attr_dict={'itemid': '50912', 'label': 'Creatinine', 'fluid': 'Blood', 'category': 'Chemistry', 'value': '1.3', 'valuenum': '1.3', 'valueuom': 'mg/dL', 'flag': 'abnormal', 'storetime': '2137-04-17 02:03:00'}),\n", - " Event(event_type='labevents', timestamp=datetime.datetime(2137, 4, 17, 1, 4), attr_dict={'itemid': '51256', 'label': 'Neutrophils', 'fluid': 'Blood', 'category': 'Hematology', 'value': '73.5', 'valuenum': '73.5', 'valueuom': '%', 'flag': 'abnormal', 'storetime': '2137-04-17 01:35:00'}),\n", - " Event(event_type='labevents', timestamp=datetime.datetime(2137, 4, 17, 1, 4), attr_dict={'itemid': '51250', 'label': 'MCV', 'fluid': 'Blood', 'category': 'Hematology', 'value': '92', 'valuenum': '92', 'valueuom': 'fL', 'flag': None, 'storetime': '2137-04-17 01:35:00'}),\n", - " Event(event_type='labevents', timestamp=datetime.datetime(2137, 4, 17, 1, 4), attr_dict={'itemid': '51249', 'label': 'MCHC', 'fluid': 'Blood', 'category': 'Hematology', 'value': '33.3', 'valuenum': '33.3', 'valueuom': '%', 'flag': None, 'storetime': '2137-04-17 01:35:00'}),\n", - " Event(event_type='labevents', timestamp=datetime.datetime(2137, 4, 17, 1, 4), attr_dict={'itemid': '51248', 'label': 'MCH', 'fluid': 'Blood', 'category': 'Hematology', 'value': '30.4', 'valuenum': '30.4', 'valueuom': 'pg', 'flag': None, 'storetime': '2137-04-17 01:35:00'}),\n", - " Event(event_type='labevents', timestamp=datetime.datetime(2137, 4, 17, 1, 4), attr_dict={'itemid': '51244', 'label': 'Lymphocytes', 'fluid': 'Blood', 'category': 'Hematology', 'value': '18.2', 'valuenum': '18.2', 'valueuom': '%', 'flag': None, 'storetime': '2137-04-17 01:35:00'}),\n", - " Event(event_type='labevents', timestamp=datetime.datetime(2137, 4, 17, 1, 4), attr_dict={'itemid': '51222', 'label': 'Hemoglobin', 'fluid': 'Blood', 'category': 'Hematology', 'value': '12.7', 'valuenum': '12.7', 'valueuom': 'g/dL', 'flag': 'abnormal', 'storetime': '2137-04-17 01:35:00'}),\n", - " Event(event_type='labevents', timestamp=datetime.datetime(2137, 4, 17, 1, 4), attr_dict={'itemid': '51221', 'label': 'Hematocrit', 'fluid': 'Blood', 'category': 'Hematology', 'value': '38.2', 'valuenum': '38.2', 'valueuom': '%', 'flag': 'abnormal', 'storetime': '2137-04-17 01:35:00'}),\n", - " Event(event_type='labevents', timestamp=datetime.datetime(2137, 4, 17, 1, 4), attr_dict={'itemid': '51200', 'label': 'Eosinophils', 'fluid': 'Blood', 'category': 'Hematology', 'value': '1.0', 'valuenum': '1', 'valueuom': '%', 'flag': None, 'storetime': '2137-04-17 01:35:00'}),\n", - " Event(event_type='labevents', timestamp=datetime.datetime(2137, 4, 17, 1, 4), attr_dict={'itemid': '51146', 'label': 'Basophils', 'fluid': 'Blood', 'category': 'Hematology', 'value': '0.3', 'valuenum': '0.3', 'valueuom': '%', 'flag': None, 'storetime': '2137-04-17 01:35:00'}),\n", - " Event(event_type='labevents', timestamp=datetime.datetime(2137, 4, 17, 1, 4), attr_dict={'itemid': '51003', 'label': 'Troponin T', 'fluid': 'Blood', 'category': 'Chemistry', 'value': None, 'valuenum': None, 'valueuom': 'ng/mL', 'flag': None, 'storetime': '2137-04-17 02:03:00'}),\n", - " Event(event_type='labevents', timestamp=datetime.datetime(2137, 4, 17, 1, 4), attr_dict={'itemid': '51254', 'label': 'Monocytes', 'fluid': 'Blood', 'category': 'Hematology', 'value': '7.0', 'valuenum': '7', 'valueuom': '%', 'flag': None, 'storetime': '2137-04-17 01:35:00'}),\n", - " Event(event_type='labevents', timestamp=datetime.datetime(2137, 4, 17, 1, 4), attr_dict={'itemid': '50915', 'label': 'D-Dimer', 'fluid': 'Blood', 'category': 'Chemistry', 'value': '384', 'valuenum': '384', 'valueuom': 'ng/mL', 'flag': None, 'storetime': '2137-04-17 03:25:00'}),\n", - " Event(event_type='labevents', timestamp=datetime.datetime(2137, 4, 17, 1, 4), attr_dict={'itemid': '50920', 'label': 'Estimated GFR (MDRD equation)', 'fluid': 'Blood', 'category': 'Chemistry', 'value': None, 'valuenum': None, 'valueuom': None, 'flag': None, 'storetime': '2137-04-17 02:03:00'}),\n", - " Event(event_type='labevents', timestamp=datetime.datetime(2137, 4, 17, 1, 4), attr_dict={'itemid': '50971', 'label': 'Potassium', 'fluid': 'Blood', 'category': 'Chemistry', 'value': '4.3', 'valuenum': '4.3', 'valueuom': 'mEq/L', 'flag': None, 'storetime': '2137-04-17 02:03:00'}),\n", - " Event(event_type='labevents', timestamp=datetime.datetime(2137, 4, 17, 1, 4), attr_dict={'itemid': '50931', 'label': 'Glucose', 'fluid': 'Blood', 'category': 'Chemistry', 'value': '153', 'valuenum': '153', 'valueuom': 'mg/dL', 'flag': 'abnormal', 'storetime': '2137-04-17 02:03:00'}),\n", - " Event(event_type='labevents', timestamp=datetime.datetime(2137, 4, 17, 1, 4), attr_dict={'itemid': '51006', 'label': 'Urea Nitrogen', 'fluid': 'Blood', 'category': 'Chemistry', 'value': '25', 'valuenum': '25', 'valueuom': 'mg/dL', 'flag': 'abnormal', 'storetime': '2137-04-17 02:03:00'}),\n", - " Event(event_type='labevents', timestamp=datetime.datetime(2137, 4, 17, 1, 4), attr_dict={'itemid': '50983', 'label': 'Sodium', 'fluid': 'Blood', 'category': 'Chemistry', 'value': '146', 'valuenum': '146', 'valueuom': 'mEq/L', 'flag': 'abnormal', 'storetime': '2137-04-17 02:03:00'}),\n", - " Event(event_type='labevents', timestamp=datetime.datetime(2137, 4, 17, 1, 4), attr_dict={'itemid': '50887', 'label': 'Blue Top Hold', 'fluid': 'Blood', 'category': 'Chemistry', 'value': 'HOLD. DISCARD GREATER THAN 24 HRS OLD.', 'valuenum': None, 'valueuom': None, 'flag': None, 'storetime': None}),\n", - " Event(event_type='labevents', timestamp=datetime.datetime(2137, 4, 17, 1, 4), attr_dict={'itemid': '50933', 'label': 'Green Top Hold (plasma)', 'fluid': 'Blood', 'category': 'Chemistry', 'value': 'HOLD. DISCARD GREATER THAN 4 HOURS OLD.', 'valuenum': None, 'valueuom': None, 'flag': None, 'storetime': None}),\n", - " Event(event_type='admissions', timestamp=datetime.datetime(2137, 4, 17, 4, 52), attr_dict={'hadm_id': '22303827', 'admission_type': 'EU OBSERVATION', 'admission_location': 'EMERGENCY ROOM', 'insurance': 'Other', 'language': 'ENGLISH', 'marital_status': 'MARRIED', 'race': 'WHITE', 'discharge_location': None, 'dischtime': '2137-04-17 16:14:00', 'hospital_expire_flag': '0'}),\n", - " Event(event_type='labevents', timestamp=datetime.datetime(2137, 4, 17, 6, 55), attr_dict={'itemid': '51003', 'label': 'Troponin T', 'fluid': 'Blood', 'category': 'Chemistry', 'value': None, 'valuenum': None, 'valueuom': 'ng/mL', 'flag': None, 'storetime': '2137-04-17 09:03:00'}),\n", - " Event(event_type='labevents', timestamp=datetime.datetime(2137, 4, 17, 6, 55), attr_dict={'itemid': '50910', 'label': 'Creatine Kinase (CK)', 'fluid': 'Blood', 'category': 'Chemistry', 'value': '133', 'valuenum': '133', 'valueuom': 'IU/L', 'flag': None, 'storetime': '2137-04-17 07:55:00'}),\n", - " Event(event_type='labevents', timestamp=datetime.datetime(2137, 4, 17, 6, 55), attr_dict={'itemid': '50911', 'label': 'Creatine Kinase, MB Isoenzyme', 'fluid': 'Blood', 'category': 'Chemistry', 'value': '3', 'valuenum': '3', 'valueuom': 'ng/mL', 'flag': None, 'storetime': '2137-04-17 09:03:00'}),\n", - " Event(event_type='diagnoses_icd', timestamp=datetime.datetime(2137, 4, 17, 16, 14), attr_dict={'hadm_id': '22303827', 'icd_code': '185', 'icd_version': '9', 'seq_num': '8'}),\n", - " Event(event_type='diagnoses_icd', timestamp=datetime.datetime(2137, 4, 17, 16, 14), attr_dict={'hadm_id': '22303827', 'icd_code': '4280', 'icd_version': '9', 'seq_num': '7'}),\n", - " Event(event_type='diagnoses_icd', timestamp=datetime.datetime(2137, 4, 17, 16, 14), attr_dict={'hadm_id': '22303827', 'icd_code': '496', 'icd_version': '9', 'seq_num': '6'}),\n", - " Event(event_type='diagnoses_icd', timestamp=datetime.datetime(2137, 4, 17, 16, 14), attr_dict={'hadm_id': '22303827', 'icd_code': '27651', 'icd_version': '9', 'seq_num': '5'}),\n", - " Event(event_type='diagnoses_icd', timestamp=datetime.datetime(2137, 4, 17, 16, 14), attr_dict={'hadm_id': '22303827', 'icd_code': 'V4582', 'icd_version': '9', 'seq_num': '4'}),\n", - " Event(event_type='diagnoses_icd', timestamp=datetime.datetime(2137, 4, 17, 16, 14), attr_dict={'hadm_id': '22303827', 'icd_code': '41401', 'icd_version': '9', 'seq_num': '3'}),\n", - " Event(event_type='diagnoses_icd', timestamp=datetime.datetime(2137, 4, 17, 16, 14), attr_dict={'hadm_id': '22303827', 'icd_code': '78904', 'icd_version': '9', 'seq_num': '2'}),\n", - " Event(event_type='diagnoses_icd', timestamp=datetime.datetime(2137, 4, 17, 16, 14), attr_dict={'hadm_id': '22303827', 'icd_code': '78659', 'icd_version': '9', 'seq_num': '1'}),\n", - " Event(event_type='procedures_icd', timestamp=datetime.datetime(2137, 4, 17, 16, 14), attr_dict={'hadm_id': '22303827', 'icd_code': '8744', 'icd_version': '9', 'seq_num': '4'}),\n", - " Event(event_type='procedures_icd', timestamp=datetime.datetime(2137, 4, 17, 16, 14), attr_dict={'hadm_id': '22303827', 'icd_code': '8952', 'icd_version': '9', 'seq_num': '3'}),\n", - " Event(event_type='procedures_icd', timestamp=datetime.datetime(2137, 4, 17, 16, 14), attr_dict={'hadm_id': '22303827', 'icd_code': '9205', 'icd_version': '9', 'seq_num': '2'}),\n", - " Event(event_type='procedures_icd', timestamp=datetime.datetime(2137, 4, 17, 16, 14), attr_dict={'hadm_id': '22303827', 'icd_code': '8938', 'icd_version': '9', 'seq_num': '1'}),\n", - " Event(event_type='labevents', timestamp=datetime.datetime(2137, 6, 28, 14, 50), attr_dict={'itemid': '50974', 'label': 'Prostate Specific Antigen', 'fluid': 'Blood', 'category': 'Chemistry', 'value': '___', 'valuenum': '5.5', 'valueuom': 'ng/mL', 'flag': 'abnormal', 'storetime': '2137-06-28 20:18:00'}),\n", - " Event(event_type='labevents', timestamp=datetime.datetime(2137, 10, 2, 15, 8), attr_dict={'itemid': '50974', 'label': 'Prostate Specific Antigen', 'fluid': 'Blood', 'category': 'Chemistry', 'value': '___', 'valuenum': '5', 'valueuom': 'ng/mL', 'flag': 'abnormal', 'storetime': '2137-10-02 17:02:00'}),\n", - " Event(event_type='labevents', timestamp=datetime.datetime(2138, 1, 22, 14, 20), attr_dict={'itemid': '50974', 'label': 'Prostate Specific Antigen', 'fluid': 'Blood', 'category': 'Chemistry', 'value': '___', 'valuenum': '4', 'valueuom': 'ng/mL', 'flag': None, 'storetime': '2138-01-22 19:49:00'}),\n", - " Event(event_type='labevents', timestamp=datetime.datetime(2138, 4, 21, 13, 0), attr_dict={'itemid': '50974', 'label': 'Prostate Specific Antigen', 'fluid': 'Blood', 'category': 'Chemistry', 'value': '___', 'valuenum': '3.3', 'valueuom': 'ng/mL', 'flag': None, 'storetime': '2138-04-21 21:36:00'}),\n", - " Event(event_type='labevents', timestamp=datetime.datetime(2138, 11, 19, 10, 15), attr_dict={'itemid': '51108', 'label': 'Urine Volume', 'fluid': 'Urine', 'category': 'Chemistry', 'value': '1400', 'valuenum': '1400', 'valueuom': 'mL', 'flag': None, 'storetime': None}),\n", - " Event(event_type='labevents', timestamp=datetime.datetime(2138, 11, 19, 10, 15), attr_dict={'itemid': '51094', 'label': 'pH', 'fluid': 'Urine', 'category': 'Chemistry', 'value': '5', 'valuenum': '5', 'valueuom': None, 'flag': None, 'storetime': None}),\n", - " Event(event_type='labevents', timestamp=datetime.datetime(2138, 11, 19, 10, 15), attr_dict={'itemid': '51087', 'label': 'Length of Urine Collection', 'fluid': 'Urine', 'category': 'Chemistry', 'value': '24', 'valuenum': '24', 'valueuom': None, 'flag': None, 'storetime': None}),\n", - " Event(event_type='labevents', timestamp=datetime.datetime(2138, 11, 19, 10, 15), attr_dict={'itemid': '51082', 'label': 'Creatinine, Urine', 'fluid': 'Urine', 'category': 'Chemistry', 'value': '112', 'valuenum': '112', 'valueuom': 'mg/dL', 'flag': None, 'storetime': '2138-11-19 16:08:00'}),\n", - " Event(event_type='labevents', timestamp=datetime.datetime(2138, 11, 19, 10, 15), attr_dict={'itemid': '51077', 'label': 'Calcium, Urine', 'fluid': 'Urine', 'category': 'Chemistry', 'value': '___', 'valuenum': '17.4', 'valueuom': 'mg/dL', 'flag': None, 'storetime': '2138-11-19 16:08:00'}),\n", - " Event(event_type='labevents', timestamp=datetime.datetime(2138, 11, 19, 10, 15), attr_dict={'itemid': '51067', 'label': '24 hr Creatinine', 'fluid': 'Urine', 'category': 'Chemistry', 'value': '___', 'valuenum': '1568', 'valueuom': 'mg/24hr', 'flag': None, 'storetime': '2138-11-19 16:08:00'}),\n", - " Event(event_type='labevents', timestamp=datetime.datetime(2138, 11, 19, 10, 15), attr_dict={'itemid': '51066', 'label': '24 hr Calcium', 'fluid': 'Urine', 'category': 'Chemistry', 'value': '___', 'valuenum': '244', 'valueuom': 'mg/24hr', 'flag': None, 'storetime': '2138-11-19 16:08:00'}),\n", - " Event(event_type='labevents', timestamp=datetime.datetime(2138, 11, 19, 10, 25), attr_dict={'itemid': '50862', 'label': 'Albumin', 'fluid': 'Blood', 'category': 'Chemistry', 'value': '4.2', 'valuenum': '4.2', 'valueuom': 'g/dL', 'flag': None, 'storetime': '2138-11-19 19:24:00'}),\n", - " Event(event_type='labevents', timestamp=datetime.datetime(2138, 11, 19, 10, 25), attr_dict={'itemid': '50861', 'label': 'Alanine Aminotransferase (ALT)', 'fluid': 'Blood', 'category': 'Chemistry', 'value': '16', 'valuenum': '16', 'valueuom': 'IU/L', 'flag': None, 'storetime': '2138-11-19 19:24:00'}),\n", - " Event(event_type='labevents', timestamp=datetime.datetime(2138, 11, 19, 10, 25), attr_dict={'itemid': '50974', 'label': 'Prostate Specific Antigen', 'fluid': 'Blood', 'category': 'Chemistry', 'value': '___', 'valuenum': '3', 'valueuom': 'ng/mL', 'flag': None, 'storetime': '2138-11-19 20:56:00'}),\n", - " Event(event_type='labevents', timestamp=datetime.datetime(2138, 11, 19, 10, 25), attr_dict={'itemid': '50965', 'label': 'Parathyroid Hormone', 'fluid': 'Blood', 'category': 'Chemistry', 'value': '76', 'valuenum': '76', 'valueuom': 'pg/mL', 'flag': 'abnormal', 'storetime': '2138-11-19 19:10:00'}),\n", - " Event(event_type='labevents', timestamp=datetime.datetime(2138, 11, 19, 10, 25), attr_dict={'itemid': '50863', 'label': 'Alkaline Phosphatase', 'fluid': 'Blood', 'category': 'Chemistry', 'value': '118', 'valuenum': '118', 'valueuom': 'IU/L', 'flag': None, 'storetime': '2138-11-19 19:24:00'}),\n", - " Event(event_type='labevents', timestamp=datetime.datetime(2138, 11, 19, 10, 25), attr_dict={'itemid': '50868', 'label': 'Anion Gap', 'fluid': 'Blood', 'category': 'Chemistry', 'value': '13', 'valuenum': '13', 'valueuom': 'mEq/L', 'flag': None, 'storetime': '2138-11-19 19:24:00'}),\n", - " Event(event_type='labevents', timestamp=datetime.datetime(2138, 11, 19, 10, 25), attr_dict={'itemid': '50893', 'label': 'Calcium, Total', 'fluid': 'Blood', 'category': 'Chemistry', 'value': '9.3', 'valuenum': '9.3', 'valueuom': 'mg/dL', 'flag': None, 'storetime': '2138-11-19 19:24:00'}),\n", - " Event(event_type='labevents', timestamp=datetime.datetime(2138, 11, 19, 10, 25), attr_dict={'itemid': '50882', 'label': 'Bicarbonate', 'fluid': 'Blood', 'category': 'Chemistry', 'value': '29', 'valuenum': '29', 'valueuom': 'mEq/L', 'flag': None, 'storetime': '2138-11-19 19:24:00'}),\n", - " Event(event_type='labevents', timestamp=datetime.datetime(2138, 11, 19, 10, 25), attr_dict={'itemid': '50920', 'label': 'Estimated GFR (MDRD equation)', 'fluid': 'Blood', 'category': 'Chemistry', 'value': None, 'valuenum': None, 'valueuom': None, 'flag': None, 'storetime': '2138-11-19 19:24:00'}),\n", - " Event(event_type='labevents', timestamp=datetime.datetime(2138, 11, 19, 10, 25), attr_dict={'itemid': '50926', 'label': 'Follicle Stimulating Hormone', 'fluid': 'Blood', 'category': 'Chemistry', 'value': '___', 'valuenum': '9.4', 'valueuom': 'mIU/mL', 'flag': None, 'storetime': '2138-11-19 19:24:00'}),\n", - " Event(event_type='labevents', timestamp=datetime.datetime(2138, 11, 19, 10, 25), attr_dict={'itemid': '50930', 'label': 'Globulin', 'fluid': 'Blood', 'category': 'Chemistry', 'value': '2.3', 'valuenum': '2.3', 'valueuom': 'g/dL', 'flag': None, 'storetime': '2138-11-19 19:24:00'}),\n", - " Event(event_type='labevents', timestamp=datetime.datetime(2138, 11, 19, 10, 25), attr_dict={'itemid': '50958', 'label': 'Luteinizing Hormone', 'fluid': 'Blood', 'category': 'Chemistry', 'value': '___', 'valuenum': '3.7', 'valueuom': 'mIU/mL', 'flag': None, 'storetime': '2138-11-19 19:24:00'}),\n", - " Event(event_type='labevents', timestamp=datetime.datetime(2138, 11, 19, 10, 25), attr_dict={'itemid': '50902', 'label': 'Chloride', 'fluid': 'Blood', 'category': 'Chemistry', 'value': '105', 'valuenum': '105', 'valueuom': 'mEq/L', 'flag': None, 'storetime': '2138-11-19 19:24:00'}),\n", - " Event(event_type='labevents', timestamp=datetime.datetime(2138, 11, 19, 10, 25), attr_dict={'itemid': '50894', 'label': 'Calculated Free Testosterone', 'fluid': 'Blood', 'category': 'Chemistry', 'value': '108', 'valuenum': '108', 'valueuom': 'pg/mL', 'flag': None, 'storetime': '2138-11-19 19:24:00'}),\n", - " Event(event_type='labevents', timestamp=datetime.datetime(2138, 11, 19, 10, 25), attr_dict={'itemid': '50960', 'label': 'Magnesium', 'fluid': 'Blood', 'category': 'Chemistry', 'value': '2.2', 'valuenum': '2.2', 'valueuom': 'mg/dL', 'flag': None, 'storetime': '2138-11-19 19:24:00'}),\n", - " Event(event_type='labevents', timestamp=datetime.datetime(2138, 11, 19, 10, 25), attr_dict={'itemid': '50971', 'label': 'Potassium', 'fluid': 'Blood', 'category': 'Chemistry', 'value': '4.3', 'valuenum': '4.3', 'valueuom': 'mEq/L', 'flag': None, 'storetime': '2138-11-19 19:24:00'}),\n", - " Event(event_type='labevents', timestamp=datetime.datetime(2138, 11, 19, 10, 25), attr_dict={'itemid': '50975', 'label': 'Protein Electrophoresis', 'fluid': 'Blood', 'category': 'Chemistry', 'value': None, 'valuenum': None, 'valueuom': None, 'flag': None, 'storetime': '2138-11-20 15:11:00'}),\n", - " Event(event_type='labevents', timestamp=datetime.datetime(2138, 11, 19, 10, 25), attr_dict={'itemid': '50976', 'label': 'Protein, Total', 'fluid': 'Blood', 'category': 'Chemistry', 'value': '6.5', 'valuenum': '6.5', 'valueuom': 'g/dL', 'flag': None, 'storetime': '2138-11-19 19:24:00'}),\n", - " Event(event_type='labevents', timestamp=datetime.datetime(2138, 11, 19, 10, 25), attr_dict={'itemid': '50982', 'label': 'Sex Hormone Binding Globulin', 'fluid': 'Blood', 'category': 'Chemistry', 'value': '66', 'valuenum': '66', 'valueuom': 'nmol/L', 'flag': 'abnormal', 'storetime': '2138-11-19 19:24:00'}),\n", - " Event(event_type='labevents', timestamp=datetime.datetime(2138, 11, 19, 10, 25), attr_dict={'itemid': '50983', 'label': 'Sodium', 'fluid': 'Blood', 'category': 'Chemistry', 'value': '143', 'valuenum': '143', 'valueuom': 'mEq/L', 'flag': None, 'storetime': '2138-11-19 19:24:00'}),\n", - " Event(event_type='labevents', timestamp=datetime.datetime(2138, 11, 19, 10, 25), attr_dict={'itemid': '50988', 'label': 'Testosterone', 'fluid': 'Blood', 'category': 'Chemistry', 'value': '765', 'valuenum': '765', 'valueuom': 'ng/dL', 'flag': None, 'storetime': '2138-11-19 19:24:00'}),\n", - " Event(event_type='labevents', timestamp=datetime.datetime(2138, 11, 19, 10, 25), attr_dict={'itemid': '50993', 'label': 'Thyroid Stimulating Hormone', 'fluid': 'Blood', 'category': 'Chemistry', 'value': '1.1', 'valuenum': '1.1', 'valueuom': 'uIU/mL', 'flag': None, 'storetime': '2138-11-19 19:24:00'}),\n", - " Event(event_type='labevents', timestamp=datetime.datetime(2138, 11, 19, 10, 25), attr_dict={'itemid': '50970', 'label': 'Phosphate', 'fluid': 'Blood', 'category': 'Chemistry', 'value': '3.2', 'valuenum': '3.2', 'valueuom': 'mg/dL', 'flag': None, 'storetime': '2138-11-19 19:24:00'}),\n", - " Event(event_type='labevents', timestamp=datetime.datetime(2138, 11, 19, 10, 25), attr_dict={'itemid': '50912', 'label': 'Creatinine', 'fluid': 'Blood', 'category': 'Chemistry', 'value': '1.0', 'valuenum': '1', 'valueuom': 'mg/dL', 'flag': None, 'storetime': '2138-11-19 19:24:00'}),\n", - " Event(event_type='labevents', timestamp=datetime.datetime(2138, 11, 19, 10, 25), attr_dict={'itemid': '51006', 'label': 'Urea Nitrogen', 'fluid': 'Blood', 'category': 'Chemistry', 'value': '18', 'valuenum': '18', 'valueuom': 'mg/dL', 'flag': None, 'storetime': '2138-11-19 19:24:00'}),\n", - " Event(event_type='labevents', timestamp=datetime.datetime(2139, 2, 4, 10, 50), attr_dict={'itemid': '50852', 'label': '% Hemoglobin A1c', 'fluid': 'Blood', 'category': 'Chemistry', 'value': '___', 'valuenum': '6.4', 'valueuom': '%', 'flag': 'abnormal', 'storetime': '2139-02-04 19:57:00'}),\n", - " Event(event_type='labevents', timestamp=datetime.datetime(2139, 2, 4, 10, 50), attr_dict={'itemid': '51250', 'label': 'MCV', 'fluid': 'Blood', 'category': 'Hematology', 'value': '94', 'valuenum': '94', 'valueuom': 'fL', 'flag': None, 'storetime': '2139-02-04 18:46:00'}),\n", - " Event(event_type='labevents', timestamp=datetime.datetime(2139, 2, 4, 10, 50), attr_dict={'itemid': '51249', 'label': 'MCHC', 'fluid': 'Blood', 'category': 'Hematology', 'value': '32.5', 'valuenum': '32.5', 'valueuom': '%', 'flag': None, 'storetime': '2139-02-04 18:46:00'}),\n", - " Event(event_type='labevents', timestamp=datetime.datetime(2139, 2, 4, 10, 50), attr_dict={'itemid': '51248', 'label': 'MCH', 'fluid': 'Blood', 'category': 'Hematology', 'value': '30.7', 'valuenum': '30.7', 'valueuom': 'pg', 'flag': None, 'storetime': '2139-02-04 18:46:00'}),\n", - " Event(event_type='labevents', timestamp=datetime.datetime(2139, 2, 4, 10, 50), attr_dict={'itemid': '51265', 'label': 'Platelet Count', 'fluid': 'Blood', 'category': 'Hematology', 'value': '315', 'valuenum': '315', 'valueuom': 'K/uL', 'flag': None, 'storetime': '2139-02-04 18:46:00'}),\n", - " Event(event_type='labevents', timestamp=datetime.datetime(2139, 2, 4, 10, 50), attr_dict={'itemid': '51613', 'label': 'eAG', 'fluid': 'Blood', 'category': 'Chemistry', 'value': '___', 'valuenum': '137', 'valueuom': 'mg/dL', 'flag': 'abnormal', 'storetime': '2139-02-04 19:57:00'}),\n", - " Event(event_type='labevents', timestamp=datetime.datetime(2139, 2, 4, 10, 50), attr_dict={'itemid': '51222', 'label': 'Hemoglobin', 'fluid': 'Blood', 'category': 'Hematology', 'value': '13.1', 'valuenum': '13.1', 'valueuom': 'g/dL', 'flag': 'abnormal', 'storetime': '2139-02-04 18:46:00'}),\n", - " Event(event_type='labevents', timestamp=datetime.datetime(2139, 2, 4, 10, 50), attr_dict={'itemid': '51221', 'label': 'Hematocrit', 'fluid': 'Blood', 'category': 'Hematology', 'value': '40.3', 'valuenum': '40.3', 'valueuom': '%', 'flag': None, 'storetime': '2139-02-04 18:46:00'}),\n", - " Event(event_type='labevents', timestamp=datetime.datetime(2139, 2, 4, 10, 50), attr_dict={'itemid': '51277', 'label': 'RDW', 'fluid': 'Blood', 'category': 'Hematology', 'value': '14.7', 'valuenum': '14.7', 'valueuom': '%', 'flag': None, 'storetime': '2139-02-04 18:46:00'}),\n", - " Event(event_type='labevents', timestamp=datetime.datetime(2139, 2, 4, 10, 50), attr_dict={'itemid': '51301', 'label': 'White Blood Cells', 'fluid': 'Blood', 'category': 'Hematology', 'value': '8.2', 'valuenum': '8.2', 'valueuom': 'K/uL', 'flag': None, 'storetime': '2139-02-04 18:46:00'}),\n", - " Event(event_type='labevents', timestamp=datetime.datetime(2139, 2, 4, 10, 50), attr_dict={'itemid': '50965', 'label': 'Parathyroid Hormone', 'fluid': 'Blood', 'category': 'Chemistry', 'value': '69', 'valuenum': '69', 'valueuom': 'pg/mL', 'flag': 'abnormal', 'storetime': '2139-02-04 20:36:00'}),\n", - " Event(event_type='labevents', timestamp=datetime.datetime(2139, 2, 4, 10, 50), attr_dict={'itemid': '51006', 'label': 'Urea Nitrogen', 'fluid': 'Blood', 'category': 'Chemistry', 'value': '25', 'valuenum': '25', 'valueuom': 'mg/dL', 'flag': 'abnormal', 'storetime': '2139-02-04 21:09:00'}),\n", - " Event(event_type='labevents', timestamp=datetime.datetime(2139, 2, 4, 10, 50), attr_dict={'itemid': '51000', 'label': 'Triglycerides', 'fluid': 'Blood', 'category': 'Chemistry', 'value': '___', 'valuenum': '72', 'valueuom': 'mg/dL', 'flag': None, 'storetime': '2139-02-04 21:09:00'}),\n", - " Event(event_type='labevents', timestamp=datetime.datetime(2139, 2, 4, 10, 50), attr_dict={'itemid': '50983', 'label': 'Sodium', 'fluid': 'Blood', 'category': 'Chemistry', 'value': '143', 'valuenum': '143', 'valueuom': 'mEq/L', 'flag': None, 'storetime': '2139-02-04 21:09:00'}),\n", - " Event(event_type='labevents', timestamp=datetime.datetime(2139, 2, 4, 10, 50), attr_dict={'itemid': '50971', 'label': 'Potassium', 'fluid': 'Blood', 'category': 'Chemistry', 'value': '4.8', 'valuenum': '4.8', 'valueuom': 'mEq/L', 'flag': None, 'storetime': '2139-02-04 21:09:00'}),\n", - " Event(event_type='labevents', timestamp=datetime.datetime(2139, 2, 4, 10, 50), attr_dict={'itemid': '50970', 'label': 'Phosphate', 'fluid': 'Blood', 'category': 'Chemistry', 'value': '3.4', 'valuenum': '3.4', 'valueuom': 'mg/dL', 'flag': None, 'storetime': '2139-02-04 21:09:00'}),\n", - " Event(event_type='labevents', timestamp=datetime.datetime(2139, 2, 4, 10, 50), attr_dict={'itemid': '50931', 'label': 'Glucose', 'fluid': 'Blood', 'category': 'Chemistry', 'value': '___', 'valuenum': '127', 'valueuom': 'mg/dL', 'flag': 'abnormal', 'storetime': '2139-02-04 21:09:00'}),\n", - " Event(event_type='labevents', timestamp=datetime.datetime(2139, 2, 4, 10, 50), attr_dict={'itemid': '50920', 'label': 'Estimated GFR (MDRD equation)', 'fluid': 'Blood', 'category': 'Chemistry', 'value': None, 'valuenum': None, 'valueuom': None, 'flag': None, 'storetime': '2139-02-04 21:09:00'}),\n", - " Event(event_type='labevents', timestamp=datetime.datetime(2139, 2, 4, 10, 50), attr_dict={'itemid': '50912', 'label': 'Creatinine', 'fluid': 'Blood', 'category': 'Chemistry', 'value': '1.0', 'valuenum': '1', 'valueuom': 'mg/dL', 'flag': None, 'storetime': '2139-02-04 21:09:00'}),\n", - " Event(event_type='labevents', timestamp=datetime.datetime(2139, 2, 4, 10, 50), attr_dict={'itemid': '50907', 'label': 'Cholesterol, Total', 'fluid': 'Blood', 'category': 'Chemistry', 'value': '154', 'valuenum': '154', 'valueuom': 'mg/dL', 'flag': None, 'storetime': '2139-02-04 21:09:00'}),\n", - " Event(event_type='labevents', timestamp=datetime.datetime(2139, 2, 4, 10, 50), attr_dict={'itemid': '50905', 'label': 'Cholesterol, LDL, Calculated', 'fluid': 'Blood', 'category': 'Chemistry', 'value': '85', 'valuenum': '85', 'valueuom': 'mg/dL', 'flag': None, 'storetime': '2139-02-04 21:09:00'}),\n", - " Event(event_type='labevents', timestamp=datetime.datetime(2139, 2, 4, 10, 50), attr_dict={'itemid': '50904', 'label': 'Cholesterol, HDL', 'fluid': 'Blood', 'category': 'Chemistry', 'value': '55', 'valuenum': '55', 'valueuom': 'mg/dL', 'flag': None, 'storetime': '2139-02-04 21:09:00'}),\n", - " Event(event_type='labevents', timestamp=datetime.datetime(2139, 2, 4, 10, 50), attr_dict={'itemid': '50903', 'label': 'Cholesterol Ratio (Total/HDL)', 'fluid': 'Blood', 'category': 'Chemistry', 'value': '2.8', 'valuenum': '2.8', 'valueuom': 'Ratio', 'flag': None, 'storetime': '2139-02-04 21:09:00'}),\n", - " Event(event_type='labevents', timestamp=datetime.datetime(2139, 2, 4, 10, 50), attr_dict={'itemid': '50902', 'label': 'Chloride', 'fluid': 'Blood', 'category': 'Chemistry', 'value': '105', 'valuenum': '105', 'valueuom': 'mEq/L', 'flag': None, 'storetime': '2139-02-04 21:09:00'}),\n", - " Event(event_type='labevents', timestamp=datetime.datetime(2139, 2, 4, 10, 50), attr_dict={'itemid': '50893', 'label': 'Calcium, Total', 'fluid': 'Blood', 'category': 'Chemistry', 'value': '9.5', 'valuenum': '9.5', 'valueuom': 'mg/dL', 'flag': None, 'storetime': '2139-02-04 21:09:00'}),\n", - " Event(event_type='labevents', timestamp=datetime.datetime(2139, 2, 4, 10, 50), attr_dict={'itemid': '50882', 'label': 'Bicarbonate', 'fluid': 'Blood', 'category': 'Chemistry', 'value': '27', 'valuenum': '27', 'valueuom': 'mEq/L', 'flag': None, 'storetime': '2139-02-04 21:09:00'}),\n", - " Event(event_type='labevents', timestamp=datetime.datetime(2139, 2, 4, 10, 50), attr_dict={'itemid': '50878', 'label': 'Asparate Aminotransferase (AST)', 'fluid': 'Blood', 'category': 'Chemistry', 'value': '16', 'valuenum': '16', 'valueuom': 'IU/L', 'flag': None, 'storetime': '2139-02-04 21:09:00'}),\n", - " Event(event_type='labevents', timestamp=datetime.datetime(2139, 2, 4, 10, 50), attr_dict={'itemid': '50868', 'label': 'Anion Gap', 'fluid': 'Blood', 'category': 'Chemistry', 'value': '16', 'valuenum': '16', 'valueuom': 'mEq/L', 'flag': None, 'storetime': '2139-02-04 21:09:00'}),\n", - " Event(event_type='labevents', timestamp=datetime.datetime(2139, 2, 4, 10, 50), attr_dict={'itemid': '50861', 'label': 'Alanine Aminotransferase (ALT)', 'fluid': 'Blood', 'category': 'Chemistry', 'value': '17', 'valuenum': '17', 'valueuom': 'IU/L', 'flag': None, 'storetime': '2139-02-04 21:09:00'}),\n", - " Event(event_type='labevents', timestamp=datetime.datetime(2139, 2, 4, 10, 50), attr_dict={'itemid': '51279', 'label': 'Red Blood Cells', 'fluid': 'Blood', 'category': 'Hematology', 'value': '4.27', 'valuenum': '4.27', 'valueuom': 'm/uL', 'flag': 'abnormal', 'storetime': '2139-02-04 18:46:00'}),\n", - " Event(event_type='labevents', timestamp=datetime.datetime(2139, 4, 1, 11, 30), attr_dict={'itemid': '51000', 'label': 'Triglycerides', 'fluid': 'Blood', 'category': 'Chemistry', 'value': '___', 'valuenum': '84', 'valueuom': 'mg/dL', 'flag': None, 'storetime': '2139-04-01 17:49:00'}),\n", - " Event(event_type='labevents', timestamp=datetime.datetime(2139, 4, 1, 11, 30), attr_dict={'itemid': '50974', 'label': 'Prostate Specific Antigen', 'fluid': 'Blood', 'category': 'Chemistry', 'value': '___', 'valuenum': '3.6', 'valueuom': 'ng/mL', 'flag': None, 'storetime': '2139-04-01 17:49:00'}),\n", - " Event(event_type='labevents', timestamp=datetime.datetime(2139, 4, 1, 11, 30), attr_dict={'itemid': '50907', 'label': 'Cholesterol, Total', 'fluid': 'Blood', 'category': 'Chemistry', 'value': '152', 'valuenum': '152', 'valueuom': 'mg/dL', 'flag': None, 'storetime': '2139-04-01 17:49:00'}),\n", - " Event(event_type='labevents', timestamp=datetime.datetime(2139, 4, 1, 11, 30), attr_dict={'itemid': '50905', 'label': 'Cholesterol, LDL, Calculated', 'fluid': 'Blood', 'category': 'Chemistry', 'value': '87', 'valuenum': '87', 'valueuom': 'mg/dL', 'flag': None, 'storetime': '2139-04-01 17:49:00'}),\n", - " Event(event_type='labevents', timestamp=datetime.datetime(2139, 4, 1, 11, 30), attr_dict={'itemid': '50904', 'label': 'Cholesterol, HDL', 'fluid': 'Blood', 'category': 'Chemistry', 'value': '48', 'valuenum': '48', 'valueuom': 'mg/dL', 'flag': None, 'storetime': '2139-04-01 17:49:00'}),\n", - " Event(event_type='labevents', timestamp=datetime.datetime(2139, 4, 1, 11, 30), attr_dict={'itemid': '50903', 'label': 'Cholesterol Ratio (Total/HDL)', 'fluid': 'Blood', 'category': 'Chemistry', 'value': '3.2', 'valuenum': '3.2', 'valueuom': 'Ratio', 'flag': None, 'storetime': '2139-04-01 17:49:00'}),\n", - " Event(event_type='labevents', timestamp=datetime.datetime(2139, 4, 1, 11, 30), attr_dict={'itemid': '50878', 'label': 'Asparate Aminotransferase (AST)', 'fluid': 'Blood', 'category': 'Chemistry', 'value': '20', 'valuenum': '20', 'valueuom': 'IU/L', 'flag': None, 'storetime': '2139-04-01 17:49:00'}),\n", - " Event(event_type='labevents', timestamp=datetime.datetime(2139, 4, 1, 11, 30), attr_dict={'itemid': '50861', 'label': 'Alanine Aminotransferase (ALT)', 'fluid': 'Blood', 'category': 'Chemistry', 'value': '18', 'valuenum': '18', 'valueuom': 'IU/L', 'flag': None, 'storetime': '2139-04-01 17:49:00'}),\n", - " Event(event_type='labevents', timestamp=datetime.datetime(2139, 4, 15, 13, 35), attr_dict={'itemid': '50912', 'label': 'Creatinine', 'fluid': 'Blood', 'category': 'Chemistry', 'value': '1.0', 'valuenum': '1', 'valueuom': 'mg/dL', 'flag': None, 'storetime': '2139-04-15 19:03:00'}),\n", - " Event(event_type='labevents', timestamp=datetime.datetime(2139, 4, 15, 13, 35), attr_dict={'itemid': '50920', 'label': 'Estimated GFR (MDRD equation)', 'fluid': 'Blood', 'category': 'Chemistry', 'value': None, 'valuenum': None, 'valueuom': None, 'flag': None, 'storetime': '2139-04-15 19:03:00'}),\n", - " Event(event_type='labevents', timestamp=datetime.datetime(2139, 4, 15, 13, 35), attr_dict={'itemid': '50893', 'label': 'Calcium, Total', 'fluid': 'Blood', 'category': 'Chemistry', 'value': '8.9', 'valuenum': '8.9', 'valueuom': 'mg/dL', 'flag': None, 'storetime': '2139-04-15 19:03:00'}),\n", - " Event(event_type='labevents', timestamp=datetime.datetime(2139, 4, 15, 13, 35), attr_dict={'itemid': '50862', 'label': 'Albumin', 'fluid': 'Blood', 'category': 'Chemistry', 'value': '3.8', 'valuenum': '3.8', 'valueuom': 'g/dL', 'flag': None, 'storetime': '2139-04-15 19:03:00'}),\n", - " Event(event_type='labevents', timestamp=datetime.datetime(2139, 7, 29, 11, 21), attr_dict={'itemid': '50905', 'label': 'Cholesterol, LDL, Calculated', 'fluid': 'Blood', 'category': 'Chemistry', 'value': '108', 'valuenum': '108', 'valueuom': 'mg/dL', 'flag': None, 'storetime': '2139-07-29 16:17:00'}),\n", - " Event(event_type='labevents', timestamp=datetime.datetime(2139, 7, 29, 11, 21), attr_dict={'itemid': '50904', 'label': 'Cholesterol, HDL', 'fluid': 'Blood', 'category': 'Chemistry', 'value': '51', 'valuenum': '51', 'valueuom': 'mg/dL', 'flag': None, 'storetime': '2139-07-29 16:17:00'}),\n", - " Event(event_type='labevents', timestamp=datetime.datetime(2139, 7, 29, 11, 21), attr_dict={'itemid': '50903', 'label': 'Cholesterol Ratio (Total/HDL)', 'fluid': 'Blood', 'category': 'Chemistry', 'value': '3.4', 'valuenum': '3.4', 'valueuom': 'Ratio', 'flag': None, 'storetime': '2139-07-29 16:17:00'}),\n", - " Event(event_type='labevents', timestamp=datetime.datetime(2139, 7, 29, 11, 21), attr_dict={'itemid': '50902', 'label': 'Chloride', 'fluid': 'Blood', 'category': 'Chemistry', 'value': '107', 'valuenum': '107', 'valueuom': 'mEq/L', 'flag': None, 'storetime': '2139-07-29 16:17:00'}),\n", - " Event(event_type='labevents', timestamp=datetime.datetime(2139, 7, 29, 11, 21), attr_dict={'itemid': '50882', 'label': 'Bicarbonate', 'fluid': 'Blood', 'category': 'Chemistry', 'value': '28', 'valuenum': '28', 'valueuom': 'mEq/L', 'flag': None, 'storetime': '2139-07-29 16:17:00'}),\n", - " Event(event_type='labevents', timestamp=datetime.datetime(2139, 7, 29, 11, 21), attr_dict={'itemid': '50878', 'label': 'Asparate Aminotransferase (AST)', 'fluid': 'Blood', 'category': 'Chemistry', 'value': '17', 'valuenum': '17', 'valueuom': 'IU/L', 'flag': None, 'storetime': '2139-07-29 16:17:00'}),\n", - " Event(event_type='labevents', timestamp=datetime.datetime(2139, 7, 29, 11, 21), attr_dict={'itemid': '50868', 'label': 'Anion Gap', 'fluid': 'Blood', 'category': 'Chemistry', 'value': '12', 'valuenum': '12', 'valueuom': 'mEq/L', 'flag': None, 'storetime': '2139-07-29 16:17:00'}),\n", - " Event(event_type='labevents', timestamp=datetime.datetime(2139, 7, 29, 11, 21), attr_dict={'itemid': '50861', 'label': 'Alanine Aminotransferase (ALT)', 'fluid': 'Blood', 'category': 'Chemistry', 'value': '19', 'valuenum': '19', 'valueuom': 'IU/L', 'flag': None, 'storetime': '2139-07-29 16:17:00'}),\n", - " Event(event_type='labevents', timestamp=datetime.datetime(2139, 7, 29, 11, 21), attr_dict={'itemid': '50907', 'label': 'Cholesterol, Total', 'fluid': 'Blood', 'category': 'Chemistry', 'value': '175', 'valuenum': '175', 'valueuom': 'mg/dL', 'flag': None, 'storetime': '2139-07-29 16:17:00'}),\n", - " Event(event_type='labevents', timestamp=datetime.datetime(2139, 7, 29, 11, 21), attr_dict={'itemid': '51613', 'label': 'eAG', 'fluid': 'Blood', 'category': 'Chemistry', 'value': '___', 'valuenum': '157', 'valueuom': 'mg/dL', 'flag': 'abnormal', 'storetime': '2139-07-29 15:07:00'}),\n", - " Event(event_type='labevents', timestamp=datetime.datetime(2139, 7, 29, 11, 21), attr_dict={'itemid': '50852', 'label': '% Hemoglobin A1c', 'fluid': 'Blood', 'category': 'Chemistry', 'value': '___', 'valuenum': '7.1', 'valueuom': '%', 'flag': 'abnormal', 'storetime': '2139-07-29 15:07:00'}),\n", - " Event(event_type='labevents', timestamp=datetime.datetime(2139, 7, 29, 11, 21), attr_dict={'itemid': '50912', 'label': 'Creatinine', 'fluid': 'Blood', 'category': 'Chemistry', 'value': '1.0', 'valuenum': '1', 'valueuom': 'mg/dL', 'flag': None, 'storetime': '2139-07-29 16:17:00'}),\n", - " Event(event_type='labevents', timestamp=datetime.datetime(2139, 7, 29, 11, 21), attr_dict={'itemid': '50971', 'label': 'Potassium', 'fluid': 'Blood', 'category': 'Chemistry', 'value': '4.3', 'valuenum': '4.3', 'valueuom': 'mEq/L', 'flag': None, 'storetime': '2139-07-29 16:17:00'}),\n", - " Event(event_type='labevents', timestamp=datetime.datetime(2139, 7, 29, 11, 21), attr_dict={'itemid': '50931', 'label': 'Glucose', 'fluid': 'Blood', 'category': 'Chemistry', 'value': '___', 'valuenum': '115', 'valueuom': 'mg/dL', 'flag': 'abnormal', 'storetime': '2139-07-29 16:37:00'}),\n", - " Event(event_type='labevents', timestamp=datetime.datetime(2139, 7, 29, 11, 21), attr_dict={'itemid': '52220', 'label': 'wbcp', 'fluid': 'Blood', 'category': 'Hematology', 'value': '7', 'valuenum': '7', 'valueuom': '%', 'flag': None, 'storetime': '2139-07-29 18:27:00'}),\n", - " Event(event_type='labevents', timestamp=datetime.datetime(2139, 7, 29, 11, 21), attr_dict={'itemid': '51301', 'label': 'White Blood Cells', 'fluid': 'Blood', 'category': 'Hematology', 'value': '6.7', 'valuenum': '6.7', 'valueuom': 'K/uL', 'flag': None, 'storetime': '2139-07-29 18:27:00'}),\n", - " Event(event_type='labevents', timestamp=datetime.datetime(2139, 7, 29, 11, 21), attr_dict={'itemid': '51279', 'label': 'Red Blood Cells', 'fluid': 'Blood', 'category': 'Hematology', 'value': '3.99', 'valuenum': '3.99', 'valueuom': 'm/uL', 'flag': 'abnormal', 'storetime': '2139-07-29 18:27:00'}),\n", - " Event(event_type='labevents', timestamp=datetime.datetime(2139, 7, 29, 11, 21), attr_dict={'itemid': '50920', 'label': 'Estimated GFR (MDRD equation)', 'fluid': 'Blood', 'category': 'Chemistry', 'value': None, 'valuenum': None, 'valueuom': None, 'flag': None, 'storetime': '2139-07-29 16:17:00'}),\n", - " Event(event_type='labevents', timestamp=datetime.datetime(2139, 7, 29, 11, 21), attr_dict={'itemid': '51277', 'label': 'RDW', 'fluid': 'Blood', 'category': 'Hematology', 'value': '14.8', 'valuenum': '14.8', 'valueuom': '%', 'flag': None, 'storetime': '2139-07-29 18:27:00'}),\n", - " Event(event_type='labevents', timestamp=datetime.datetime(2139, 7, 29, 11, 21), attr_dict={'itemid': '51250', 'label': 'MCV', 'fluid': 'Blood', 'category': 'Hematology', 'value': '95', 'valuenum': '95', 'valueuom': 'fL', 'flag': None, 'storetime': '2139-07-29 18:27:00'}),\n", - " Event(event_type='labevents', timestamp=datetime.datetime(2139, 7, 29, 11, 21), attr_dict={'itemid': '51249', 'label': 'MCHC', 'fluid': 'Blood', 'category': 'Hematology', 'value': '33.9', 'valuenum': '33.9', 'valueuom': '%', 'flag': None, 'storetime': '2139-07-29 18:27:00'}),\n", - " Event(event_type='labevents', timestamp=datetime.datetime(2139, 7, 29, 11, 21), attr_dict={'itemid': '51248', 'label': 'MCH', 'fluid': 'Blood', 'category': 'Hematology', 'value': '32.0', 'valuenum': '32', 'valueuom': 'pg', 'flag': None, 'storetime': '2139-07-29 18:27:00'}),\n", - " Event(event_type='labevents', timestamp=datetime.datetime(2139, 7, 29, 11, 21), attr_dict={'itemid': '51222', 'label': 'Hemoglobin', 'fluid': 'Blood', 'category': 'Hematology', 'value': '12.8', 'valuenum': '12.8', 'valueuom': 'g/dL', 'flag': 'abnormal', 'storetime': '2139-07-29 18:27:00'}),\n", - " Event(event_type='labevents', timestamp=datetime.datetime(2139, 7, 29, 11, 21), attr_dict={'itemid': '51221', 'label': 'Hematocrit', 'fluid': 'Blood', 'category': 'Hematology', 'value': '37.7', 'valuenum': '37.7', 'valueuom': '%', 'flag': 'abnormal', 'storetime': '2139-07-29 18:27:00'}),\n", - " Event(event_type='labevents', timestamp=datetime.datetime(2139, 7, 29, 11, 21), attr_dict={'itemid': '51006', 'label': 'Urea Nitrogen', 'fluid': 'Blood', 'category': 'Chemistry', 'value': '23', 'valuenum': '23', 'valueuom': 'mg/dL', 'flag': 'abnormal', 'storetime': '2139-07-29 16:17:00'}),\n", - " Event(event_type='labevents', timestamp=datetime.datetime(2139, 7, 29, 11, 21), attr_dict={'itemid': '51000', 'label': 'Triglycerides', 'fluid': 'Blood', 'category': 'Chemistry', 'value': '___', 'valuenum': '82', 'valueuom': 'mg/dL', 'flag': None, 'storetime': '2139-07-29 16:17:00'}),\n", - " Event(event_type='labevents', timestamp=datetime.datetime(2139, 7, 29, 11, 21), attr_dict={'itemid': '50983', 'label': 'Sodium', 'fluid': 'Blood', 'category': 'Chemistry', 'value': '143', 'valuenum': '143', 'valueuom': 'mEq/L', 'flag': None, 'storetime': '2139-07-29 16:17:00'}),\n", - " Event(event_type='labevents', timestamp=datetime.datetime(2139, 7, 29, 11, 21), attr_dict={'itemid': '50974', 'label': 'Prostate Specific Antigen', 'fluid': 'Blood', 'category': 'Chemistry', 'value': '___', 'valuenum': '4.4', 'valueuom': 'ng/mL', 'flag': 'abnormal', 'storetime': '2139-07-29 16:17:00'}),\n", - " Event(event_type='labevents', timestamp=datetime.datetime(2139, 7, 29, 11, 21), attr_dict={'itemid': '51265', 'label': 'Platelet Count', 'fluid': 'Blood', 'category': 'Hematology', 'value': '246', 'valuenum': '246', 'valueuom': 'K/uL', 'flag': None, 'storetime': '2139-07-29 18:27:00'}),\n", - " Event(event_type='labevents', timestamp=datetime.datetime(2139, 7, 29, 11, 21), attr_dict={'itemid': '50893', 'label': 'Calcium, Total', 'fluid': 'Blood', 'category': 'Chemistry', 'value': '8.6', 'valuenum': '8.6', 'valueuom': 'mg/dL', 'flag': None, 'storetime': '2139-07-29 16:17:00'}),\n", - " Event(event_type='labevents', timestamp=datetime.datetime(2139, 10, 28, 14, 23), attr_dict={'itemid': '50974', 'label': 'Prostate Specific Antigen', 'fluid': 'Blood', 'category': 'Chemistry', 'value': '___', 'valuenum': '2.9', 'valueuom': 'ng/mL', 'flag': None, 'storetime': '2139-10-28 22:43:00'}),\n", - " Event(event_type='labevents', timestamp=datetime.datetime(2139, 12, 23, 12, 26), attr_dict={'itemid': '52220', 'label': 'wbcp', 'fluid': 'Blood', 'category': 'Hematology', 'value': '8', 'valuenum': '8', 'valueuom': '%', 'flag': None, 'storetime': '2139-12-23 20:47:00'}),\n", - " Event(event_type='labevents', timestamp=datetime.datetime(2139, 12, 23, 12, 26), attr_dict={'itemid': '51301', 'label': 'White Blood Cells', 'fluid': 'Blood', 'category': 'Hematology', 'value': '7.8', 'valuenum': '7.8', 'valueuom': 'K/uL', 'flag': None, 'storetime': '2139-12-23 20:47:00'}),\n", - " Event(event_type='labevents', timestamp=datetime.datetime(2139, 12, 23, 12, 26), attr_dict={'itemid': '51279', 'label': 'Red Blood Cells', 'fluid': 'Blood', 'category': 'Hematology', 'value': '4.54', 'valuenum': '4.54', 'valueuom': 'm/uL', 'flag': 'abnormal', 'storetime': '2139-12-23 20:47:00'}),\n", - " Event(event_type='labevents', timestamp=datetime.datetime(2139, 12, 23, 12, 26), attr_dict={'itemid': '51277', 'label': 'RDW', 'fluid': 'Blood', 'category': 'Hematology', 'value': '15.3', 'valuenum': '15.3', 'valueuom': '%', 'flag': None, 'storetime': '2139-12-23 20:47:00'}),\n", - " Event(event_type='labevents', timestamp=datetime.datetime(2139, 12, 23, 12, 26), attr_dict={'itemid': '51265', 'label': 'Platelet Count', 'fluid': 'Blood', 'category': 'Hematology', 'value': '249', 'valuenum': '249', 'valueuom': 'K/uL', 'flag': None, 'storetime': '2139-12-23 20:47:00'}),\n", - " Event(event_type='labevents', timestamp=datetime.datetime(2139, 12, 23, 12, 26), attr_dict={'itemid': '51250', 'label': 'MCV', 'fluid': 'Blood', 'category': 'Hematology', 'value': '94', 'valuenum': '94', 'valueuom': 'fL', 'flag': None, 'storetime': '2139-12-23 20:47:00'}),\n", - " Event(event_type='labevents', timestamp=datetime.datetime(2139, 12, 23, 12, 26), attr_dict={'itemid': '51249', 'label': 'MCHC', 'fluid': 'Blood', 'category': 'Hematology', 'value': '31.9', 'valuenum': '31.9', 'valueuom': '%', 'flag': None, 'storetime': '2139-12-23 20:47:00'}),\n", - " Event(event_type='labevents', timestamp=datetime.datetime(2139, 12, 23, 12, 26), attr_dict={'itemid': '51248', 'label': 'MCH', 'fluid': 'Blood', 'category': 'Hematology', 'value': '30.1', 'valuenum': '30.1', 'valueuom': 'pg', 'flag': None, 'storetime': '2139-12-23 20:47:00'}),\n", - " Event(event_type='labevents', timestamp=datetime.datetime(2139, 12, 23, 12, 26), attr_dict={'itemid': '51222', 'label': 'Hemoglobin', 'fluid': 'Blood', 'category': 'Hematology', 'value': '13.7', 'valuenum': '13.7', 'valueuom': 'g/dL', 'flag': 'abnormal', 'storetime': '2139-12-23 20:47:00'}),\n", - " Event(event_type='labevents', timestamp=datetime.datetime(2139, 12, 23, 12, 26), attr_dict={'itemid': '51221', 'label': 'Hematocrit', 'fluid': 'Blood', 'category': 'Hematology', 'value': '42.8', 'valuenum': '42.8', 'valueuom': '%', 'flag': None, 'storetime': '2139-12-23 20:47:00'}),\n", - " Event(event_type='labevents', timestamp=datetime.datetime(2139, 12, 23, 12, 26), attr_dict={'itemid': '51006', 'label': 'Urea Nitrogen', 'fluid': 'Blood', 'category': 'Chemistry', 'value': '24', 'valuenum': '24', 'valueuom': 'mg/dL', 'flag': 'abnormal', 'storetime': '2139-12-23 19:02:00'}),\n", - " Event(event_type='labevents', timestamp=datetime.datetime(2139, 12, 23, 12, 26), attr_dict={'itemid': '51000', 'label': 'Triglycerides', 'fluid': 'Blood', 'category': 'Chemistry', 'value': '___', 'valuenum': '113', 'valueuom': 'mg/dL', 'flag': None, 'storetime': '2139-12-23 19:02:00'}),\n", - " Event(event_type='labevents', timestamp=datetime.datetime(2139, 12, 23, 12, 26), attr_dict={'itemid': '50983', 'label': 'Sodium', 'fluid': 'Blood', 'category': 'Chemistry', 'value': '144', 'valuenum': '144', 'valueuom': 'mEq/L', 'flag': None, 'storetime': '2139-12-23 19:02:00'}),\n", - " Event(event_type='labevents', timestamp=datetime.datetime(2139, 12, 23, 12, 26), attr_dict={'itemid': '50971', 'label': 'Potassium', 'fluid': 'Blood', 'category': 'Chemistry', 'value': '4.7', 'valuenum': '4.7', 'valueuom': 'mEq/L', 'flag': None, 'storetime': '2139-12-23 19:02:00'}),\n", - " Event(event_type='labevents', timestamp=datetime.datetime(2139, 12, 23, 12, 26), attr_dict={'itemid': '50920', 'label': 'Estimated GFR (MDRD equation)', 'fluid': 'Blood', 'category': 'Chemistry', 'value': None, 'valuenum': None, 'valueuom': None, 'flag': None, 'storetime': '2139-12-23 19:02:00'}),\n", - " Event(event_type='labevents', timestamp=datetime.datetime(2139, 12, 23, 12, 26), attr_dict={'itemid': '50912', 'label': 'Creatinine', 'fluid': 'Blood', 'category': 'Chemistry', 'value': '0.9', 'valuenum': '0.9', 'valueuom': 'mg/dL', 'flag': None, 'storetime': '2139-12-23 19:02:00'}),\n", - " Event(event_type='labevents', timestamp=datetime.datetime(2139, 12, 23, 12, 26), attr_dict={'itemid': '50907', 'label': 'Cholesterol, Total', 'fluid': 'Blood', 'category': 'Chemistry', 'value': '183', 'valuenum': '183', 'valueuom': 'mg/dL', 'flag': None, 'storetime': '2139-12-23 19:02:00'}),\n", - " Event(event_type='labevents', timestamp=datetime.datetime(2139, 12, 23, 12, 26), attr_dict={'itemid': '50905', 'label': 'Cholesterol, LDL, Calculated', 'fluid': 'Blood', 'category': 'Chemistry', 'value': '113', 'valuenum': '113', 'valueuom': 'mg/dL', 'flag': None, 'storetime': '2139-12-23 19:02:00'}),\n", - " Event(event_type='labevents', timestamp=datetime.datetime(2139, 12, 23, 12, 26), attr_dict={'itemid': '50904', 'label': 'Cholesterol, HDL', 'fluid': 'Blood', 'category': 'Chemistry', 'value': '47', 'valuenum': '47', 'valueuom': 'mg/dL', 'flag': None, 'storetime': '2139-12-23 19:02:00'}),\n", - " Event(event_type='labevents', timestamp=datetime.datetime(2139, 12, 23, 12, 26), attr_dict={'itemid': '50903', 'label': 'Cholesterol Ratio (Total/HDL)', 'fluid': 'Blood', 'category': 'Chemistry', 'value': '3.9', 'valuenum': '3.9', 'valueuom': 'Ratio', 'flag': None, 'storetime': '2139-12-23 19:02:00'}),\n", - " Event(event_type='labevents', timestamp=datetime.datetime(2139, 12, 23, 12, 26), attr_dict={'itemid': '50902', 'label': 'Chloride', 'fluid': 'Blood', 'category': 'Chemistry', 'value': '105', 'valuenum': '105', 'valueuom': 'mEq/L', 'flag': None, 'storetime': '2139-12-23 19:02:00'}),\n", - " Event(event_type='labevents', timestamp=datetime.datetime(2139, 12, 23, 12, 26), attr_dict={'itemid': '50893', 'label': 'Calcium, Total', 'fluid': 'Blood', 'category': 'Chemistry', 'value': '9.1', 'valuenum': '9.1', 'valueuom': 'mg/dL', 'flag': None, 'storetime': '2139-12-23 19:02:00'}),\n", - " Event(event_type='labevents', timestamp=datetime.datetime(2139, 12, 23, 12, 26), attr_dict={'itemid': '50882', 'label': 'Bicarbonate', 'fluid': 'Blood', 'category': 'Chemistry', 'value': '29', 'valuenum': '29', 'valueuom': 'mEq/L', 'flag': None, 'storetime': '2139-12-23 19:02:00'}),\n", - " Event(event_type='labevents', timestamp=datetime.datetime(2139, 12, 23, 12, 26), attr_dict={'itemid': '50868', 'label': 'Anion Gap', 'fluid': 'Blood', 'category': 'Chemistry', 'value': '15', 'valuenum': '15', 'valueuom': 'mEq/L', 'flag': None, 'storetime': '2139-12-23 19:02:00'}),\n", - " Event(event_type='labevents', timestamp=datetime.datetime(2139, 12, 23, 12, 26), attr_dict={'itemid': '50878', 'label': 'Asparate Aminotransferase (AST)', 'fluid': 'Blood', 'category': 'Chemistry', 'value': '16', 'valuenum': '16', 'valueuom': 'IU/L', 'flag': None, 'storetime': '2139-12-23 19:02:00'}),\n", - " Event(event_type='labevents', timestamp=datetime.datetime(2139, 12, 23, 12, 26), attr_dict={'itemid': '50861', 'label': 'Alanine Aminotransferase (ALT)', 'fluid': 'Blood', 'category': 'Chemistry', 'value': '13', 'valuenum': '13', 'valueuom': 'IU/L', 'flag': None, 'storetime': '2139-12-23 19:02:00'}),\n", - " Event(event_type='labevents', timestamp=datetime.datetime(2139, 12, 23, 12, 26), attr_dict={'itemid': '50931', 'label': 'Glucose', 'fluid': 'Blood', 'category': 'Chemistry', 'value': '___', 'valuenum': '119', 'valueuom': 'mg/dL', 'flag': 'abnormal', 'storetime': '2139-12-23 19:24:00'}),\n", - " Event(event_type='labevents', timestamp=datetime.datetime(2139, 12, 23, 12, 26), attr_dict={'itemid': '51613', 'label': 'eAG', 'fluid': 'Blood', 'category': 'Chemistry', 'value': '___', 'valuenum': '134', 'valueuom': 'mg/dL', 'flag': 'abnormal', 'storetime': '2139-12-23 18:36:00'}),\n", - " Event(event_type='labevents', timestamp=datetime.datetime(2139, 12, 23, 12, 26), attr_dict={'itemid': '50852', 'label': '% Hemoglobin A1c', 'fluid': 'Blood', 'category': 'Chemistry', 'value': '___', 'valuenum': '6.3', 'valueuom': '%', 'flag': 'abnormal', 'storetime': '2139-12-23 18:36:00'}),\n", - " Event(event_type='prescriptions', timestamp=datetime.datetime(2140, 3, 20, 10, 0), attr_dict={'hadm_id': '29372295', 'drug': 'Omeprazole', 'ndc': '00904568461', 'prod_strength': '20mg Cap', 'dose_val_rx': '40', 'dose_unit_rx': 'mg', 'route': 'PO', 'stoptime': '2140-03-22 21:00:00'}),\n", - " Event(event_type='prescriptions', timestamp=datetime.datetime(2140, 3, 20, 10, 0), attr_dict={'hadm_id': '29372295', 'drug': 'Allopurinol', 'ndc': '62584071301', 'prod_strength': '300mg Tab', 'dose_val_rx': '300', 'dose_unit_rx': 'mg', 'route': 'PO/NG', 'stoptime': '2140-03-22 21:00:00'}),\n", - " Event(event_type='prescriptions', timestamp=datetime.datetime(2140, 3, 20, 10, 0), attr_dict={'hadm_id': '29372295', 'drug': 'Tiotropium Bromide', 'ndc': '00597007575', 'prod_strength': '18mcg Capsule-Inhalation Device', 'dose_val_rx': '1', 'dose_unit_rx': 'CAP', 'route': 'IH', 'stoptime': '2140-03-22 21:00:00'}),\n", - " Event(event_type='prescriptions', timestamp=datetime.datetime(2140, 3, 20, 10, 0), attr_dict={'hadm_id': '29372295', 'drug': 'Diltiazem Extended-Release', 'ndc': '00258368890', 'prod_strength': '180 mg ER Cap', 'dose_val_rx': '360', 'dose_unit_rx': 'mg', 'route': 'PO', 'stoptime': '2140-03-22 21:00:00'}),\n", - " Event(event_type='prescriptions', timestamp=datetime.datetime(2140, 3, 20, 10, 0), attr_dict={'hadm_id': '29372295', 'drug': 'Pravastatin', 'ndc': '51079045820', 'prod_strength': '20mg Tablet', 'dose_val_rx': '80', 'dose_unit_rx': 'mg', 'route': 'PO', 'stoptime': '2140-03-22 21:00:00'}),\n", - " Event(event_type='prescriptions', timestamp=datetime.datetime(2140, 3, 20, 10, 0), attr_dict={'hadm_id': '29372295', 'drug': 'Finasteride', 'ndc': '51079052020', 'prod_strength': '5mg Tablet', 'dose_val_rx': '5', 'dose_unit_rx': 'mg', 'route': 'PO', 'stoptime': '2140-03-22 21:00:00'}),\n", - " Event(event_type='prescriptions', timestamp=datetime.datetime(2140, 3, 20, 10, 0), attr_dict={'hadm_id': '29372295', 'drug': 'Aspirin', 'ndc': '00904404073', 'prod_strength': '81mg Tab', 'dose_val_rx': '162', 'dose_unit_rx': 'mg', 'route': 'PO/NG', 'stoptime': '2140-03-22 21:00:00'}),\n", - " Event(event_type='labevents', timestamp=datetime.datetime(2140, 3, 20, 14, 0), attr_dict={'itemid': '51006', 'label': 'Urea Nitrogen', 'fluid': 'Blood', 'category': 'Chemistry', 'value': '23', 'valuenum': '23', 'valueuom': 'mg/dL', 'flag': 'abnormal', 'storetime': '2140-03-20 14:43:00'}),\n", - " Event(event_type='labevents', timestamp=datetime.datetime(2140, 3, 20, 14, 0), attr_dict={'itemid': '50971', 'label': 'Potassium', 'fluid': 'Blood', 'category': 'Chemistry', 'value': '___', 'valuenum': '4.7', 'valueuom': 'mEq/L', 'flag': None, 'storetime': '2140-03-20 14:43:00'}),\n", - " Event(event_type='labevents', timestamp=datetime.datetime(2140, 3, 20, 14, 0), attr_dict={'itemid': '51146', 'label': 'Basophils', 'fluid': 'Blood', 'category': 'Hematology', 'value': '0.4', 'valuenum': '0.4', 'valueuom': '%', 'flag': None, 'storetime': '2140-03-20 14:17:00'}),\n", - " Event(event_type='labevents', timestamp=datetime.datetime(2140, 3, 20, 14, 0), attr_dict={'itemid': '50983', 'label': 'Sodium', 'fluid': 'Blood', 'category': 'Chemistry', 'value': '140', 'valuenum': '140', 'valueuom': 'mEq/L', 'flag': None, 'storetime': '2140-03-20 14:43:00'}),\n", - " Event(event_type='labevents', timestamp=datetime.datetime(2140, 3, 20, 14, 0), attr_dict={'itemid': '51200', 'label': 'Eosinophils', 'fluid': 'Blood', 'category': 'Hematology', 'value': '1.3', 'valuenum': '1.3', 'valueuom': '%', 'flag': None, 'storetime': '2140-03-20 14:17:00'}),\n", - " Event(event_type='labevents', timestamp=datetime.datetime(2140, 3, 20, 14, 0), attr_dict={'itemid': '51222', 'label': 'Hemoglobin', 'fluid': 'Blood', 'category': 'Hematology', 'value': '13.8', 'valuenum': '13.8', 'valueuom': 'g/dL', 'flag': 'abnormal', 'storetime': '2140-03-20 14:17:00'}),\n", - " Event(event_type='labevents', timestamp=datetime.datetime(2140, 3, 20, 14, 0), attr_dict={'itemid': '50931', 'label': 'Glucose', 'fluid': 'Blood', 'category': 'Chemistry', 'value': '___', 'valuenum': '125', 'valueuom': 'mg/dL', 'flag': 'abnormal', 'storetime': '2140-03-20 14:43:00'}),\n", - " Event(event_type='labevents', timestamp=datetime.datetime(2140, 3, 20, 14, 0), attr_dict={'itemid': '50920', 'label': 'Estimated GFR (MDRD equation)', 'fluid': 'Blood', 'category': 'Chemistry', 'value': None, 'valuenum': None, 'valueuom': None, 'flag': None, 'storetime': '2140-03-20 14:43:00'}),\n", - " Event(event_type='labevents', timestamp=datetime.datetime(2140, 3, 20, 14, 0), attr_dict={'itemid': '50912', 'label': 'Creatinine', 'fluid': 'Blood', 'category': 'Chemistry', 'value': '0.7', 'valuenum': '0.7', 'valueuom': 'mg/dL', 'flag': None, 'storetime': '2140-03-20 14:43:00'}),\n", - " Event(event_type='labevents', timestamp=datetime.datetime(2140, 3, 20, 14, 0), attr_dict={'itemid': '50902', 'label': 'Chloride', 'fluid': 'Blood', 'category': 'Chemistry', 'value': '108', 'valuenum': '108', 'valueuom': 'mEq/L', 'flag': None, 'storetime': '2140-03-20 14:43:00'}),\n", - " Event(event_type='labevents', timestamp=datetime.datetime(2140, 3, 20, 14, 0), attr_dict={'itemid': '50882', 'label': 'Bicarbonate', 'fluid': 'Blood', 'category': 'Chemistry', 'value': '24', 'valuenum': '24', 'valueuom': 'mEq/L', 'flag': None, 'storetime': '2140-03-20 14:43:00'}),\n", - " Event(event_type='labevents', timestamp=datetime.datetime(2140, 3, 20, 14, 0), attr_dict={'itemid': '50868', 'label': 'Anion Gap', 'fluid': 'Blood', 'category': 'Chemistry', 'value': '13', 'valuenum': '13', 'valueuom': 'mEq/L', 'flag': None, 'storetime': '2140-03-20 14:43:00'}),\n", - " Event(event_type='labevents', timestamp=datetime.datetime(2140, 3, 20, 14, 0), attr_dict={'itemid': '50887', 'label': 'Blue Top Hold', 'fluid': 'Blood', 'category': 'Chemistry', 'value': 'HOLD. DISCARD GREATER THAN 24 HRS OLD.', 'valuenum': None, 'valueuom': None, 'flag': None, 'storetime': None}),\n", - " Event(event_type='labevents', timestamp=datetime.datetime(2140, 3, 20, 14, 0), attr_dict={'itemid': '51003', 'label': 'Troponin T', 'fluid': 'Blood', 'category': 'Chemistry', 'value': None, 'valuenum': None, 'valueuom': 'ng/mL', 'flag': None, 'storetime': '2140-03-20 16:13:00'}),\n", - " Event(event_type='labevents', timestamp=datetime.datetime(2140, 3, 20, 14, 0), attr_dict={'itemid': '50955', 'label': 'Light Green Top Hold', 'fluid': 'Blood', 'category': 'Chemistry', 'value': '___', 'valuenum': None, 'valueuom': None, 'flag': None, 'storetime': None}),\n", - " Event(event_type='labevents', timestamp=datetime.datetime(2140, 3, 20, 14, 0), attr_dict={'itemid': '50933', 'label': 'Green Top Hold (plasma)', 'fluid': 'Blood', 'category': 'Chemistry', 'value': 'HOLD. DISCARD GREATER THAN 4 HOURS OLD.', 'valuenum': None, 'valueuom': None, 'flag': None, 'storetime': None}),\n", - " Event(event_type='labevents', timestamp=datetime.datetime(2140, 3, 20, 14, 0), attr_dict={'itemid': '51301', 'label': 'White Blood Cells', 'fluid': 'Blood', 'category': 'Hematology', 'value': '8.8', 'valuenum': '8.8', 'valueuom': 'K/uL', 'flag': None, 'storetime': '2140-03-20 14:17:00'}),\n", - " Event(event_type='labevents', timestamp=datetime.datetime(2140, 3, 20, 14, 0), attr_dict={'itemid': '51279', 'label': 'Red Blood Cells', 'fluid': 'Blood', 'category': 'Hematology', 'value': '4.34', 'valuenum': '4.34', 'valueuom': 'm/uL', 'flag': 'abnormal', 'storetime': '2140-03-20 14:17:00'}),\n", - " Event(event_type='labevents', timestamp=datetime.datetime(2140, 3, 20, 14, 0), attr_dict={'itemid': '51277', 'label': 'RDW', 'fluid': 'Blood', 'category': 'Hematology', 'value': '14.9', 'valuenum': '14.9', 'valueuom': '%', 'flag': None, 'storetime': '2140-03-20 14:17:00'}),\n", - " Event(event_type='labevents', timestamp=datetime.datetime(2140, 3, 20, 14, 0), attr_dict={'itemid': '51265', 'label': 'Platelet Count', 'fluid': 'Blood', 'category': 'Hematology', 'value': '260', 'valuenum': '260', 'valueuom': 'K/uL', 'flag': None, 'storetime': '2140-03-20 14:17:00'}),\n", - " Event(event_type='labevents', timestamp=datetime.datetime(2140, 3, 20, 14, 0), attr_dict={'itemid': '51256', 'label': 'Neutrophils', 'fluid': 'Blood', 'category': 'Hematology', 'value': '66.8', 'valuenum': '66.8', 'valueuom': '%', 'flag': None, 'storetime': '2140-03-20 14:17:00'}),\n", - " Event(event_type='labevents', timestamp=datetime.datetime(2140, 3, 20, 14, 0), attr_dict={'itemid': '51254', 'label': 'Monocytes', 'fluid': 'Blood', 'category': 'Hematology', 'value': '8.3', 'valuenum': '8.3', 'valueuom': '%', 'flag': None, 'storetime': '2140-03-20 14:17:00'}),\n", - " Event(event_type='labevents', timestamp=datetime.datetime(2140, 3, 20, 14, 0), attr_dict={'itemid': '51250', 'label': 'MCV', 'fluid': 'Blood', 'category': 'Hematology', 'value': '97', 'valuenum': '97', 'valueuom': 'fL', 'flag': None, 'storetime': '2140-03-20 14:17:00'}),\n", - " Event(event_type='labevents', timestamp=datetime.datetime(2140, 3, 20, 14, 0), attr_dict={'itemid': '51249', 'label': 'MCHC', 'fluid': 'Blood', 'category': 'Hematology', 'value': '32.9', 'valuenum': '32.9', 'valueuom': '%', 'flag': None, 'storetime': '2140-03-20 14:17:00'}),\n", - " Event(event_type='labevents', timestamp=datetime.datetime(2140, 3, 20, 14, 0), attr_dict={'itemid': '51248', 'label': 'MCH', 'fluid': 'Blood', 'category': 'Hematology', 'value': '31.8', 'valuenum': '31.8', 'valueuom': 'pg', 'flag': None, 'storetime': '2140-03-20 14:17:00'}),\n", - " Event(event_type='labevents', timestamp=datetime.datetime(2140, 3, 20, 14, 0), attr_dict={'itemid': '51244', 'label': 'Lymphocytes', 'fluid': 'Blood', 'category': 'Hematology', 'value': '23.2', 'valuenum': '23.2', 'valueuom': '%', 'flag': None, 'storetime': '2140-03-20 14:17:00'}),\n", - " Event(event_type='labevents', timestamp=datetime.datetime(2140, 3, 20, 14, 0), attr_dict={'itemid': '51221', 'label': 'Hematocrit', 'fluid': 'Blood', 'category': 'Hematology', 'value': '42.0', 'valuenum': '42', 'valueuom': '%', 'flag': None, 'storetime': '2140-03-20 14:17:00'}),\n", - " Event(event_type='admissions', timestamp=datetime.datetime(2140, 3, 20, 17, 38), attr_dict={'hadm_id': '29372295', 'admission_type': 'EU OBSERVATION', 'admission_location': 'EMERGENCY ROOM', 'insurance': 'Medicare', 'language': 'ENGLISH', 'marital_status': 'MARRIED', 'race': 'WHITE', 'discharge_location': None, 'dischtime': '2140-03-22 17:10:00', 'hospital_expire_flag': '0'}),\n", - " Event(event_type='labevents', timestamp=datetime.datetime(2140, 3, 20, 18, 0), attr_dict={'itemid': '51487', 'label': 'Nitrite', 'fluid': 'Urine', 'category': 'Hematology', 'value': None, 'valuenum': None, 'valueuom': None, 'flag': None, 'storetime': '2140-03-20 18:31:00'}),\n", - " Event(event_type='labevents', timestamp=datetime.datetime(2140, 3, 20, 18, 0), attr_dict={'itemid': '51466', 'label': 'Blood', 'fluid': 'Urine', 'category': 'Hematology', 'value': None, 'valuenum': None, 'valueuom': None, 'flag': None, 'storetime': '2140-03-20 18:31:00'}),\n", - " Event(event_type='labevents', timestamp=datetime.datetime(2140, 3, 20, 18, 0), attr_dict={'itemid': '51486', 'label': 'Leukocytes', 'fluid': 'Urine', 'category': 'Hematology', 'value': None, 'valuenum': None, 'valueuom': None, 'flag': None, 'storetime': '2140-03-20 18:31:00'}),\n", - " Event(event_type='labevents', timestamp=datetime.datetime(2140, 3, 20, 18, 0), attr_dict={'itemid': '51484', 'label': 'Ketone', 'fluid': 'Urine', 'category': 'Hematology', 'value': None, 'valuenum': None, 'valueuom': 'mg/dL', 'flag': None, 'storetime': '2140-03-20 18:31:00'}),\n", - " Event(event_type='labevents', timestamp=datetime.datetime(2140, 3, 20, 18, 0), attr_dict={'itemid': '51478', 'label': 'Glucose', 'fluid': 'Urine', 'category': 'Hematology', 'value': None, 'valuenum': None, 'valueuom': 'mg/dL', 'flag': None, 'storetime': '2140-03-20 18:31:00'}),\n", - " Event(event_type='labevents', timestamp=datetime.datetime(2140, 3, 20, 18, 0), attr_dict={'itemid': '51492', 'label': 'Protein', 'fluid': 'Urine', 'category': 'Hematology', 'value': None, 'valuenum': None, 'valueuom': 'mg/dL', 'flag': None, 'storetime': '2140-03-20 18:31:00'}),\n", - " Event(event_type='labevents', timestamp=datetime.datetime(2140, 3, 20, 18, 0), attr_dict={'itemid': '51498', 'label': 'Specific Gravity', 'fluid': 'Urine', 'category': 'Hematology', 'value': '1.015', 'valuenum': '1.015', 'valueuom': ' ', 'flag': None, 'storetime': '2140-03-20 18:31:00'}),\n", - " Event(event_type='labevents', timestamp=datetime.datetime(2140, 3, 20, 18, 0), attr_dict={'itemid': '51491', 'label': 'pH', 'fluid': 'Urine', 'category': 'Hematology', 'value': '6.5', 'valuenum': '6.5', 'valueuom': 'units', 'flag': None, 'storetime': '2140-03-20 18:31:00'}),\n", - " Event(event_type='labevents', timestamp=datetime.datetime(2140, 3, 20, 18, 0), attr_dict={'itemid': '51464', 'label': 'Bilirubin', 'fluid': 'Urine', 'category': 'Hematology', 'value': None, 'valuenum': None, 'valueuom': 'mg/dL', 'flag': None, 'storetime': '2140-03-20 18:31:00'}),\n", - " Event(event_type='labevents', timestamp=datetime.datetime(2140, 3, 20, 18, 0), attr_dict={'itemid': '51508', 'label': 'Urine Color', 'fluid': 'Urine', 'category': 'Hematology', 'value': None, 'valuenum': None, 'valueuom': None, 'flag': None, 'storetime': '2140-03-20 18:31:00'}),\n", - " Event(event_type='labevents', timestamp=datetime.datetime(2140, 3, 20, 18, 0), attr_dict={'itemid': '51514', 'label': 'Urobilinogen', 'fluid': 'Urine', 'category': 'Hematology', 'value': None, 'valuenum': None, 'valueuom': 'mg/dL', 'flag': None, 'storetime': '2140-03-20 18:31:00'}),\n", - " Event(event_type='labevents', timestamp=datetime.datetime(2140, 3, 20, 18, 0), attr_dict={'itemid': '51506', 'label': 'Urine Appearance', 'fluid': 'Urine', 'category': 'Hematology', 'value': None, 'valuenum': None, 'valueuom': None, 'flag': None, 'storetime': '2140-03-20 18:31:00'}),\n", - " Event(event_type='prescriptions', timestamp=datetime.datetime(2140, 3, 20, 20, 0), attr_dict={'hadm_id': '29372295', 'drug': 'Fluticasone-Salmeterol Diskus (500/50) ', 'ndc': '00173069700', 'prod_strength': '500/50mcg Diskus', 'dose_val_rx': '1', 'dose_unit_rx': 'INH', 'route': 'IH', 'stoptime': '2140-03-22 21:00:00'}),\n", - " Event(event_type='prescriptions', timestamp=datetime.datetime(2140, 3, 20, 20, 0), attr_dict={'hadm_id': '29372295', 'drug': 'PrednisoLONE Acetate 1% Ophth. Susp.', 'ndc': '61314063705', 'prod_strength': '1% Ophthalmic Suspension', 'dose_val_rx': '1', 'dose_unit_rx': 'DROP', 'route': 'BOTH EYES', 'stoptime': '2140-03-22 21:00:00'}),\n", - " Event(event_type='prescriptions', timestamp=datetime.datetime(2140, 3, 20, 20, 0), attr_dict={'hadm_id': '29372295', 'drug': 'Heparin', 'ndc': '63323026201', 'prod_strength': '5000 Units / mL- 1mL Vial', 'dose_val_rx': '5000', 'dose_unit_rx': 'UNIT', 'route': 'SC', 'stoptime': '2140-03-22 21:00:00'}),\n", - " Event(event_type='prescriptions', timestamp=datetime.datetime(2140, 3, 20, 20, 0), attr_dict={'hadm_id': '29372295', 'drug': 'Influenza Virus Vaccine', 'ndc': '33332001201', 'prod_strength': '0.5 mL Syringe', 'dose_val_rx': '0.5', 'dose_unit_rx': 'mL', 'route': 'IM', 'stoptime': '2140-03-22 08:00:00'}),\n", - " Event(event_type='prescriptions', timestamp=datetime.datetime(2140, 3, 20, 21, 0), attr_dict={'hadm_id': '29372295', 'drug': 'Doxazosin', 'ndc': '00904552461', 'prod_strength': '4mg Tablet', 'dose_val_rx': '8', 'dose_unit_rx': 'mg', 'route': 'PO/NG', 'stoptime': '2140-03-22 21:00:00'}),\n", - " Event(event_type='prescriptions', timestamp=datetime.datetime(2140, 3, 20, 21, 0), attr_dict={'hadm_id': '29372295', 'drug': 'Albuterol Inhaler', 'ndc': '00173068254', 'prod_strength': '8 g Inhaler', 'dose_val_rx': '2', 'dose_unit_rx': 'PUFF', 'route': 'IH', 'stoptime': '2140-03-22 21:00:00'}),\n", - " Event(event_type='prescriptions', timestamp=datetime.datetime(2140, 3, 20, 21, 0), attr_dict={'hadm_id': '29372295', 'drug': 'Lorazepam', 'ndc': '68084008901', 'prod_strength': '1mg Tablet', 'dose_val_rx': '1', 'dose_unit_rx': 'mg', 'route': 'PO/NG', 'stoptime': '2140-03-22 21:00:00'}),\n", - " Event(event_type='prescriptions', timestamp=datetime.datetime(2140, 3, 20, 21, 0), attr_dict={'hadm_id': '29372295', 'drug': 'Oxycodone-Acetaminophen (5mg-325mg)', 'ndc': '00406051262', 'prod_strength': '5mg/325mg Tablet', 'dose_val_rx': '1-2', 'dose_unit_rx': 'TAB', 'route': 'PO/NG', 'stoptime': '2140-03-22 21:00:00'}),\n", - " Event(event_type='prescriptions', timestamp=datetime.datetime(2140, 3, 20, 21, 0), attr_dict={'hadm_id': '29372295', 'drug': 'Sodium Chloride 0.9% Flush', 'ndc': '0', 'prod_strength': 'Syringe', 'dose_val_rx': '3', 'dose_unit_rx': 'mL', 'route': 'IV', 'stoptime': '2140-03-22 21:00:00'}),\n", - " Event(event_type='prescriptions', timestamp=datetime.datetime(2140, 3, 20, 21, 0), attr_dict={'hadm_id': '29372295', 'drug': 'Vitamin D', 'ndc': '00223197101', 'prod_strength': '50,000 Unit Capsule', 'dose_val_rx': '50,000', 'dose_unit_rx': 'UNIT', 'route': 'PO/NG', 'stoptime': '2140-03-22 21:00:00'}),\n", - " Event(event_type='prescriptions', timestamp=datetime.datetime(2140, 3, 20, 21, 0), attr_dict={'hadm_id': '29372295', 'drug': 'Polyethylene Glycol', 'ndc': '11523726808', 'prod_strength': '17g Packet', 'dose_val_rx': '17', 'dose_unit_rx': 'g', 'route': 'PO/NG', 'stoptime': '2140-03-22 21:00:00'}),\n", - " Event(event_type='prescriptions', timestamp=datetime.datetime(2140, 3, 20, 21, 0), attr_dict={'hadm_id': '29372295', 'drug': 'Albuterol 0.083% Neb Soln', 'ndc': '49502069724', 'prod_strength': '0.083%;3mL Vial', 'dose_val_rx': '1', 'dose_unit_rx': 'NEB', 'route': 'IH', 'stoptime': '2140-03-22 21:00:00'}),\n", - " Event(event_type='prescriptions', timestamp=datetime.datetime(2140, 3, 20, 22, 0), attr_dict={'hadm_id': '29372295', 'drug': 'Doxazosin', 'ndc': '00904552461', 'prod_strength': '4mg Tablet', 'dose_val_rx': '8', 'dose_unit_rx': 'mg', 'route': 'PO/NG', 'stoptime': '2140-03-20 20:00:00'}),\n", - " Event(event_type='prescriptions', timestamp=datetime.datetime(2140, 3, 20, 22, 0), attr_dict={'hadm_id': '29372295', 'drug': 'Tobramycin-Dexamethasone Ophth Oint', 'ndc': '00065064835', 'prod_strength': '3.5g Tube', 'dose_val_rx': '1', 'dose_unit_rx': 'Appl', 'route': 'BOTH EYES', 'stoptime': '2140-03-21 21:00:00'}),\n", - " Event(event_type='prescriptions', timestamp=datetime.datetime(2140, 3, 20, 23, 0), attr_dict={'hadm_id': '29372295', 'drug': 'Docusate Sodium', 'ndc': '00904224461', 'prod_strength': '100mg Capsule', 'dose_val_rx': '100', 'dose_unit_rx': 'mg', 'route': 'PO/NG', 'stoptime': '2140-03-22 21:00:00'}),\n", - " Event(event_type='prescriptions', timestamp=datetime.datetime(2140, 3, 20, 23, 0), attr_dict={'hadm_id': '29372295', 'drug': 'Senna', 'ndc': '00904516561', 'prod_strength': '1 Tablet', 'dose_val_rx': '1', 'dose_unit_rx': 'TAB', 'route': 'PO/NG', 'stoptime': '2140-03-22 21:00:00'}),\n", - " Event(event_type='labevents', timestamp=datetime.datetime(2140, 3, 20, 23, 38), attr_dict={'itemid': '50910', 'label': 'Creatine Kinase (CK)', 'fluid': 'Blood', 'category': 'Chemistry', 'value': '___', 'valuenum': '63', 'valueuom': 'IU/L', 'flag': None, 'storetime': '2140-03-21 00:45:00'}),\n", - " Event(event_type='labevents', timestamp=datetime.datetime(2140, 3, 20, 23, 38), attr_dict={'itemid': '50911', 'label': 'Creatine Kinase, MB Isoenzyme', 'fluid': 'Blood', 'category': 'Chemistry', 'value': '2', 'valuenum': '2', 'valueuom': 'ng/mL', 'flag': None, 'storetime': '2140-03-21 00:45:00'}),\n", - " Event(event_type='labevents', timestamp=datetime.datetime(2140, 3, 20, 23, 38), attr_dict={'itemid': '51003', 'label': 'Troponin T', 'fluid': 'Blood', 'category': 'Chemistry', 'value': None, 'valuenum': None, 'valueuom': 'ng/mL', 'flag': None, 'storetime': '2140-03-21 00:45:00'}),\n", - " Event(event_type='labevents', timestamp=datetime.datetime(2140, 3, 21, 5, 45), attr_dict={'itemid': '50912', 'label': 'Creatinine', 'fluid': 'Blood', 'category': 'Chemistry', 'value': '0.7', 'valuenum': '0.7', 'valueuom': 'mg/dL', 'flag': None, 'storetime': '2140-03-21 07:35:00'}),\n", - " Event(event_type='labevents', timestamp=datetime.datetime(2140, 3, 21, 5, 45), attr_dict={'itemid': '51003', 'label': 'Troponin T', 'fluid': 'Blood', 'category': 'Chemistry', 'value': None, 'valuenum': None, 'valueuom': 'ng/mL', 'flag': None, 'storetime': '2140-03-21 07:35:00'}),\n", - " Event(event_type='labevents', timestamp=datetime.datetime(2140, 3, 21, 5, 45), attr_dict={'itemid': '51221', 'label': 'Hematocrit', 'fluid': 'Blood', 'category': 'Hematology', 'value': '37.1', 'valuenum': '37.1', 'valueuom': '%', 'flag': 'abnormal', 'storetime': '2140-03-21 06:54:00'}),\n", - " Event(event_type='labevents', timestamp=datetime.datetime(2140, 3, 21, 5, 45), attr_dict={'itemid': '51222', 'label': 'Hemoglobin', 'fluid': 'Blood', 'category': 'Hematology', 'value': '12.3', 'valuenum': '12.3', 'valueuom': 'g/dL', 'flag': 'abnormal', 'storetime': '2140-03-21 06:54:00'}),\n", - " Event(event_type='labevents', timestamp=datetime.datetime(2140, 3, 21, 5, 45), attr_dict={'itemid': '51248', 'label': 'MCH', 'fluid': 'Blood', 'category': 'Hematology', 'value': '31.1', 'valuenum': '31.1', 'valueuom': 'pg', 'flag': None, 'storetime': '2140-03-21 06:54:00'}),\n", - " Event(event_type='labevents', timestamp=datetime.datetime(2140, 3, 21, 5, 45), attr_dict={'itemid': '51249', 'label': 'MCHC', 'fluid': 'Blood', 'category': 'Hematology', 'value': '33.0', 'valuenum': '33', 'valueuom': '%', 'flag': None, 'storetime': '2140-03-21 06:54:00'}),\n", - " Event(event_type='labevents', timestamp=datetime.datetime(2140, 3, 21, 5, 45), attr_dict={'itemid': '51250', 'label': 'MCV', 'fluid': 'Blood', 'category': 'Hematology', 'value': '94', 'valuenum': '94', 'valueuom': 'fL', 'flag': None, 'storetime': '2140-03-21 06:54:00'}),\n", - " Event(event_type='labevents', timestamp=datetime.datetime(2140, 3, 21, 5, 45), attr_dict={'itemid': '51265', 'label': 'Platelet Count', 'fluid': 'Blood', 'category': 'Hematology', 'value': '264', 'valuenum': '264', 'valueuom': 'K/uL', 'flag': None, 'storetime': '2140-03-21 06:54:00'}),\n", - " Event(event_type='labevents', timestamp=datetime.datetime(2140, 3, 21, 5, 45), attr_dict={'itemid': '51277', 'label': 'RDW', 'fluid': 'Blood', 'category': 'Hematology', 'value': '14.8', 'valuenum': '14.8', 'valueuom': '%', 'flag': None, 'storetime': '2140-03-21 06:54:00'}),\n", - " Event(event_type='labevents', timestamp=datetime.datetime(2140, 3, 21, 5, 45), attr_dict={'itemid': '51006', 'label': 'Urea Nitrogen', 'fluid': 'Blood', 'category': 'Chemistry', 'value': '25', 'valuenum': '25', 'valueuom': 'mg/dL', 'flag': 'abnormal', 'storetime': '2140-03-21 07:35:00'}),\n", - " Event(event_type='labevents', timestamp=datetime.datetime(2140, 3, 21, 5, 45), attr_dict={'itemid': '51279', 'label': 'Red Blood Cells', 'fluid': 'Blood', 'category': 'Hematology', 'value': '3.95', 'valuenum': '3.95', 'valueuom': 'm/uL', 'flag': 'abnormal', 'storetime': '2140-03-21 06:54:00'}),\n", - " Event(event_type='labevents', timestamp=datetime.datetime(2140, 3, 21, 5, 45), attr_dict={'itemid': '51237', 'label': 'INR(PT)', 'fluid': 'Blood', 'category': 'Hematology', 'value': '1.0', 'valuenum': '1', 'valueuom': None, 'flag': None, 'storetime': '2140-03-21 07:00:00'}),\n", - " Event(event_type='labevents', timestamp=datetime.datetime(2140, 3, 21, 5, 45), attr_dict={'itemid': '51274', 'label': 'PT', 'fluid': 'Blood', 'category': 'Hematology', 'value': '11.2', 'valuenum': '11.2', 'valueuom': 'sec', 'flag': None, 'storetime': '2140-03-21 07:00:00'}),\n", - " Event(event_type='labevents', timestamp=datetime.datetime(2140, 3, 21, 5, 45), attr_dict={'itemid': '51275', 'label': 'PTT', 'fluid': 'Blood', 'category': 'Hematology', 'value': '29.4', 'valuenum': '29.4', 'valueuom': 'sec', 'flag': None, 'storetime': '2140-03-21 07:00:00'}),\n", - " Event(event_type='labevents', timestamp=datetime.datetime(2140, 3, 21, 5, 45), attr_dict={'itemid': '50868', 'label': 'Anion Gap', 'fluid': 'Blood', 'category': 'Chemistry', 'value': '10', 'valuenum': '10', 'valueuom': 'mEq/L', 'flag': None, 'storetime': '2140-03-21 07:35:00'}),\n", - " Event(event_type='labevents', timestamp=datetime.datetime(2140, 3, 21, 5, 45), attr_dict={'itemid': '50882', 'label': 'Bicarbonate', 'fluid': 'Blood', 'category': 'Chemistry', 'value': '28', 'valuenum': '28', 'valueuom': 'mEq/L', 'flag': None, 'storetime': '2140-03-21 07:35:00'}),\n", - " Event(event_type='labevents', timestamp=datetime.datetime(2140, 3, 21, 5, 45), attr_dict={'itemid': '50893', 'label': 'Calcium, Total', 'fluid': 'Blood', 'category': 'Chemistry', 'value': '8.5', 'valuenum': '8.5', 'valueuom': 'mg/dL', 'flag': None, 'storetime': '2140-03-21 07:35:00'}),\n", - " Event(event_type='labevents', timestamp=datetime.datetime(2140, 3, 21, 5, 45), attr_dict={'itemid': '50902', 'label': 'Chloride', 'fluid': 'Blood', 'category': 'Chemistry', 'value': '107', 'valuenum': '107', 'valueuom': 'mEq/L', 'flag': None, 'storetime': '2140-03-21 07:35:00'}),\n", - " Event(event_type='labevents', timestamp=datetime.datetime(2140, 3, 21, 5, 45), attr_dict={'itemid': '50910', 'label': 'Creatine Kinase (CK)', 'fluid': 'Blood', 'category': 'Chemistry', 'value': '___', 'valuenum': '52', 'valueuom': 'IU/L', 'flag': None, 'storetime': '2140-03-21 07:35:00'}),\n", - " Event(event_type='labevents', timestamp=datetime.datetime(2140, 3, 21, 5, 45), attr_dict={'itemid': '50911', 'label': 'Creatine Kinase, MB Isoenzyme', 'fluid': 'Blood', 'category': 'Chemistry', 'value': '2', 'valuenum': '2', 'valueuom': 'ng/mL', 'flag': None, 'storetime': '2140-03-21 07:35:00'}),\n", - " Event(event_type='labevents', timestamp=datetime.datetime(2140, 3, 21, 5, 45), attr_dict={'itemid': '50931', 'label': 'Glucose', 'fluid': 'Blood', 'category': 'Chemistry', 'value': '___', 'valuenum': '117', 'valueuom': 'mg/dL', 'flag': 'abnormal', 'storetime': '2140-03-21 07:35:00'}),\n", - " Event(event_type='labevents', timestamp=datetime.datetime(2140, 3, 21, 5, 45), attr_dict={'itemid': '50960', 'label': 'Magnesium', 'fluid': 'Blood', 'category': 'Chemistry', 'value': '1.9', 'valuenum': '1.9', 'valueuom': 'mg/dL', 'flag': None, 'storetime': '2140-03-21 07:35:00'}),\n", - " Event(event_type='labevents', timestamp=datetime.datetime(2140, 3, 21, 5, 45), attr_dict={'itemid': '50970', 'label': 'Phosphate', 'fluid': 'Blood', 'category': 'Chemistry', 'value': '3.0', 'valuenum': '3', 'valueuom': 'mg/dL', 'flag': None, 'storetime': '2140-03-21 07:35:00'}),\n", - " Event(event_type='labevents', timestamp=datetime.datetime(2140, 3, 21, 5, 45), attr_dict={'itemid': '50971', 'label': 'Potassium', 'fluid': 'Blood', 'category': 'Chemistry', 'value': '4.2', 'valuenum': '4.2', 'valueuom': 'mEq/L', 'flag': None, 'storetime': '2140-03-21 07:35:00'}),\n", - " Event(event_type='labevents', timestamp=datetime.datetime(2140, 3, 21, 5, 45), attr_dict={'itemid': '50983', 'label': 'Sodium', 'fluid': 'Blood', 'category': 'Chemistry', 'value': '141', 'valuenum': '141', 'valueuom': 'mEq/L', 'flag': None, 'storetime': '2140-03-21 07:35:00'}),\n", - " Event(event_type='labevents', timestamp=datetime.datetime(2140, 3, 21, 5, 45), attr_dict={'itemid': '51301', 'label': 'White Blood Cells', 'fluid': 'Blood', 'category': 'Hematology', 'value': '7.3', 'valuenum': '7.3', 'valueuom': 'K/uL', 'flag': None, 'storetime': '2140-03-21 06:54:00'}),\n", - " Event(event_type='prescriptions', timestamp=datetime.datetime(2140, 3, 21, 10, 0), attr_dict={'hadm_id': '29372295', 'drug': 'Simethicone', 'ndc': '00182864389', 'prod_strength': '80mg Tablet', 'dose_val_rx': '40-80', 'dose_unit_rx': 'mg', 'route': 'PO/NG', 'stoptime': '2140-03-22 21:00:00'}),\n", - " Event(event_type='labevents', timestamp=datetime.datetime(2140, 3, 22, 5, 20), attr_dict={'itemid': '50882', 'label': 'Bicarbonate', 'fluid': 'Blood', 'category': 'Chemistry', 'value': '26', 'valuenum': '26', 'valueuom': 'mEq/L', 'flag': None, 'storetime': '2140-03-22 07:07:00'}),\n", - " Event(event_type='labevents', timestamp=datetime.datetime(2140, 3, 22, 5, 20), attr_dict={'itemid': '50893', 'label': 'Calcium, Total', 'fluid': 'Blood', 'category': 'Chemistry', 'value': '8.6', 'valuenum': '8.6', 'valueuom': 'mg/dL', 'flag': None, 'storetime': '2140-03-22 07:07:00'}),\n", - " Event(event_type='labevents', timestamp=datetime.datetime(2140, 3, 22, 5, 20), attr_dict={'itemid': '50902', 'label': 'Chloride', 'fluid': 'Blood', 'category': 'Chemistry', 'value': '108', 'valuenum': '108', 'valueuom': 'mEq/L', 'flag': None, 'storetime': '2140-03-22 07:07:00'}),\n", - " Event(event_type='labevents', timestamp=datetime.datetime(2140, 3, 22, 5, 20), attr_dict={'itemid': '50912', 'label': 'Creatinine', 'fluid': 'Blood', 'category': 'Chemistry', 'value': '0.7', 'valuenum': '0.7', 'valueuom': 'mg/dL', 'flag': None, 'storetime': '2140-03-22 07:07:00'}),\n", - " Event(event_type='labevents', timestamp=datetime.datetime(2140, 3, 22, 5, 20), attr_dict={'itemid': '50931', 'label': 'Glucose', 'fluid': 'Blood', 'category': 'Chemistry', 'value': '___', 'valuenum': '113', 'valueuom': 'mg/dL', 'flag': 'abnormal', 'storetime': '2140-03-22 07:07:00'}),\n", - " Event(event_type='labevents', timestamp=datetime.datetime(2140, 3, 22, 5, 20), attr_dict={'itemid': '50868', 'label': 'Anion Gap', 'fluid': 'Blood', 'category': 'Chemistry', 'value': '11', 'valuenum': '11', 'valueuom': 'mEq/L', 'flag': None, 'storetime': '2140-03-22 07:07:00'}),\n", - " Event(event_type='labevents', timestamp=datetime.datetime(2140, 3, 22, 5, 20), attr_dict={'itemid': '50960', 'label': 'Magnesium', 'fluid': 'Blood', 'category': 'Chemistry', 'value': '2.0', 'valuenum': '2', 'valueuom': 'mg/dL', 'flag': None, 'storetime': '2140-03-22 07:07:00'}),\n", - " Event(event_type='labevents', timestamp=datetime.datetime(2140, 3, 22, 5, 20), attr_dict={'itemid': '50970', 'label': 'Phosphate', 'fluid': 'Blood', 'category': 'Chemistry', 'value': '3.6', 'valuenum': '3.6', 'valueuom': 'mg/dL', 'flag': None, 'storetime': '2140-03-22 07:07:00'}),\n", - " Event(event_type='labevents', timestamp=datetime.datetime(2140, 3, 22, 5, 20), attr_dict={'itemid': '50983', 'label': 'Sodium', 'fluid': 'Blood', 'category': 'Chemistry', 'value': '141', 'valuenum': '141', 'valueuom': 'mEq/L', 'flag': None, 'storetime': '2140-03-22 07:07:00'}),\n", - " Event(event_type='labevents', timestamp=datetime.datetime(2140, 3, 22, 5, 20), attr_dict={'itemid': '51301', 'label': 'White Blood Cells', 'fluid': 'Blood', 'category': 'Hematology', 'value': '7.1', 'valuenum': '7.1', 'valueuom': 'K/uL', 'flag': None, 'storetime': '2140-03-22 06:35:00'}),\n", - " Event(event_type='labevents', timestamp=datetime.datetime(2140, 3, 22, 5, 20), attr_dict={'itemid': '51279', 'label': 'Red Blood Cells', 'fluid': 'Blood', 'category': 'Hematology', 'value': '3.95', 'valuenum': '3.95', 'valueuom': 'm/uL', 'flag': 'abnormal', 'storetime': '2140-03-22 06:35:00'}),\n", - " Event(event_type='labevents', timestamp=datetime.datetime(2140, 3, 22, 5, 20), attr_dict={'itemid': '51277', 'label': 'RDW', 'fluid': 'Blood', 'category': 'Hematology', 'value': '14.6', 'valuenum': '14.6', 'valueuom': '%', 'flag': None, 'storetime': '2140-03-22 06:35:00'}),\n", - " Event(event_type='labevents', timestamp=datetime.datetime(2140, 3, 22, 5, 20), attr_dict={'itemid': '51265', 'label': 'Platelet Count', 'fluid': 'Blood', 'category': 'Hematology', 'value': '268', 'valuenum': '268', 'valueuom': 'K/uL', 'flag': None, 'storetime': '2140-03-22 06:35:00'}),\n", - " Event(event_type='labevents', timestamp=datetime.datetime(2140, 3, 22, 5, 20), attr_dict={'itemid': '51250', 'label': 'MCV', 'fluid': 'Blood', 'category': 'Hematology', 'value': '95', 'valuenum': '95', 'valueuom': 'fL', 'flag': None, 'storetime': '2140-03-22 06:35:00'}),\n", - " Event(event_type='labevents', timestamp=datetime.datetime(2140, 3, 22, 5, 20), attr_dict={'itemid': '51249', 'label': 'MCHC', 'fluid': 'Blood', 'category': 'Hematology', 'value': '33.3', 'valuenum': '33.3', 'valueuom': '%', 'flag': None, 'storetime': '2140-03-22 06:35:00'}),\n", - " Event(event_type='labevents', timestamp=datetime.datetime(2140, 3, 22, 5, 20), attr_dict={'itemid': '51248', 'label': 'MCH', 'fluid': 'Blood', 'category': 'Hematology', 'value': '31.5', 'valuenum': '31.5', 'valueuom': 'pg', 'flag': None, 'storetime': '2140-03-22 06:35:00'}),\n", - " Event(event_type='labevents', timestamp=datetime.datetime(2140, 3, 22, 5, 20), attr_dict={'itemid': '51222', 'label': 'Hemoglobin', 'fluid': 'Blood', 'category': 'Hematology', 'value': '12.5', 'valuenum': '12.5', 'valueuom': 'g/dL', 'flag': 'abnormal', 'storetime': '2140-03-22 06:35:00'}),\n", - " Event(event_type='labevents', timestamp=datetime.datetime(2140, 3, 22, 5, 20), attr_dict={'itemid': '51221', 'label': 'Hematocrit', 'fluid': 'Blood', 'category': 'Hematology', 'value': '37.4', 'valuenum': '37.4', 'valueuom': '%', 'flag': 'abnormal', 'storetime': '2140-03-22 06:35:00'}),\n", - " Event(event_type='labevents', timestamp=datetime.datetime(2140, 3, 22, 5, 20), attr_dict={'itemid': '51275', 'label': 'PTT', 'fluid': 'Blood', 'category': 'Hematology', 'value': '29.3', 'valuenum': '29.3', 'valueuom': 'sec', 'flag': None, 'storetime': '2140-03-22 06:45:00'}),\n", - " Event(event_type='labevents', timestamp=datetime.datetime(2140, 3, 22, 5, 20), attr_dict={'itemid': '51274', 'label': 'PT', 'fluid': 'Blood', 'category': 'Hematology', 'value': '10.5', 'valuenum': '10.5', 'valueuom': 'sec', 'flag': None, 'storetime': '2140-03-22 06:45:00'}),\n", - " Event(event_type='labevents', timestamp=datetime.datetime(2140, 3, 22, 5, 20), attr_dict={'itemid': '51237', 'label': 'INR(PT)', 'fluid': 'Blood', 'category': 'Hematology', 'value': '1.0', 'valuenum': '1', 'valueuom': None, 'flag': None, 'storetime': '2140-03-22 06:45:00'}),\n", - " Event(event_type='labevents', timestamp=datetime.datetime(2140, 3, 22, 5, 20), attr_dict={'itemid': '51006', 'label': 'Urea Nitrogen', 'fluid': 'Blood', 'category': 'Chemistry', 'value': '24', 'valuenum': '24', 'valueuom': 'mg/dL', 'flag': 'abnormal', 'storetime': '2140-03-22 07:07:00'}),\n", - " Event(event_type='labevents', timestamp=datetime.datetime(2140, 3, 22, 5, 20), attr_dict={'itemid': '50971', 'label': 'Potassium', 'fluid': 'Blood', 'category': 'Chemistry', 'value': '4.2', 'valuenum': '4.2', 'valueuom': 'mEq/L', 'flag': None, 'storetime': '2140-03-22 07:07:00'}),\n", - " Event(event_type='diagnoses_icd', timestamp=datetime.datetime(2140, 3, 22, 17, 10), attr_dict={'hadm_id': '29372295', 'icd_code': '78659', 'icd_version': '9', 'seq_num': '1'}),\n", - " Event(event_type='diagnoses_icd', timestamp=datetime.datetime(2140, 3, 22, 17, 10), attr_dict={'hadm_id': '29372295', 'icd_code': '2749', 'icd_version': '9', 'seq_num': '9'}),\n", - " Event(event_type='diagnoses_icd', timestamp=datetime.datetime(2140, 3, 22, 17, 10), attr_dict={'hadm_id': '29372295', 'icd_code': '71590', 'icd_version': '9', 'seq_num': '8'}),\n", - " Event(event_type='diagnoses_icd', timestamp=datetime.datetime(2140, 3, 22, 17, 10), attr_dict={'hadm_id': '29372295', 'icd_code': '53081', 'icd_version': '9', 'seq_num': '7'}),\n", - " Event(event_type='diagnoses_icd', timestamp=datetime.datetime(2140, 3, 22, 17, 10), attr_dict={'hadm_id': '29372295', 'icd_code': 'V1046', 'icd_version': '9', 'seq_num': '6'}),\n", - " Event(event_type='diagnoses_icd', timestamp=datetime.datetime(2140, 3, 22, 17, 10), attr_dict={'hadm_id': '29372295', 'icd_code': '60000', 'icd_version': '9', 'seq_num': '5'}),\n", - " Event(event_type='diagnoses_icd', timestamp=datetime.datetime(2140, 3, 22, 17, 10), attr_dict={'hadm_id': '29372295', 'icd_code': '496', 'icd_version': '9', 'seq_num': '4'}),\n", - " Event(event_type='diagnoses_icd', timestamp=datetime.datetime(2140, 3, 22, 17, 10), attr_dict={'hadm_id': '29372295', 'icd_code': '412', 'icd_version': '9', 'seq_num': '3'}),\n", - " Event(event_type='diagnoses_icd', timestamp=datetime.datetime(2140, 3, 22, 17, 10), attr_dict={'hadm_id': '29372295', 'icd_code': '41401', 'icd_version': '9', 'seq_num': '2'}),\n", - " Event(event_type='labevents', timestamp=datetime.datetime(2140, 5, 25, 12, 48), attr_dict={'itemid': '50907', 'label': 'Cholesterol, Total', 'fluid': 'Blood', 'category': 'Chemistry', 'value': '161', 'valuenum': '161', 'valueuom': 'mg/dL', 'flag': None, 'storetime': '2140-05-25 19:27:00'}),\n", - " Event(event_type='labevents', timestamp=datetime.datetime(2140, 5, 25, 12, 48), attr_dict={'itemid': '50905', 'label': 'Cholesterol, LDL, Calculated', 'fluid': 'Blood', 'category': 'Chemistry', 'value': '81', 'valuenum': '81', 'valueuom': 'mg/dL', 'flag': None, 'storetime': '2140-05-25 19:27:00'}),\n", - " Event(event_type='labevents', timestamp=datetime.datetime(2140, 5, 25, 12, 48), attr_dict={'itemid': '50904', 'label': 'Cholesterol, HDL', 'fluid': 'Blood', 'category': 'Chemistry', 'value': '62', 'valuenum': '62', 'valueuom': 'mg/dL', 'flag': None, 'storetime': '2140-05-25 19:27:00'}),\n", - " Event(event_type='labevents', timestamp=datetime.datetime(2140, 5, 25, 12, 48), attr_dict={'itemid': '50903', 'label': 'Cholesterol Ratio (Total/HDL)', 'fluid': 'Blood', 'category': 'Chemistry', 'value': '2.6', 'valuenum': '2.6', 'valueuom': 'Ratio', 'flag': None, 'storetime': '2140-05-25 19:27:00'}),\n", - " Event(event_type='labevents', timestamp=datetime.datetime(2140, 5, 25, 12, 48), attr_dict={'itemid': '50902', 'label': 'Chloride', 'fluid': 'Blood', 'category': 'Chemistry', 'value': '105', 'valuenum': '105', 'valueuom': 'mEq/L', 'flag': None, 'storetime': '2140-05-25 19:27:00'}),\n", - " Event(event_type='labevents', timestamp=datetime.datetime(2140, 5, 25, 12, 48), attr_dict={'itemid': '50882', 'label': 'Bicarbonate', 'fluid': 'Blood', 'category': 'Chemistry', 'value': '29', 'valuenum': '29', 'valueuom': 'mEq/L', 'flag': None, 'storetime': '2140-05-25 19:27:00'}),\n", - " Event(event_type='labevents', timestamp=datetime.datetime(2140, 5, 25, 12, 48), attr_dict={'itemid': '50878', 'label': 'Asparate Aminotransferase (AST)', 'fluid': 'Blood', 'category': 'Chemistry', 'value': '13', 'valuenum': '13', 'valueuom': 'IU/L', 'flag': None, 'storetime': '2140-05-25 19:27:00'}),\n", - " Event(event_type='labevents', timestamp=datetime.datetime(2140, 5, 25, 12, 48), attr_dict={'itemid': '50868', 'label': 'Anion Gap', 'fluid': 'Blood', 'category': 'Chemistry', 'value': '13', 'valuenum': '13', 'valueuom': 'mEq/L', 'flag': None, 'storetime': '2140-05-25 19:27:00'}),\n", - " Event(event_type='labevents', timestamp=datetime.datetime(2140, 5, 25, 12, 48), attr_dict={'itemid': '50912', 'label': 'Creatinine', 'fluid': 'Blood', 'category': 'Chemistry', 'value': '1.0', 'valuenum': '1', 'valueuom': 'mg/dL', 'flag': None, 'storetime': '2140-05-25 19:27:00'}),\n", - " Event(event_type='labevents', timestamp=datetime.datetime(2140, 5, 25, 12, 48), attr_dict={'itemid': '50920', 'label': 'Estimated GFR (MDRD equation)', 'fluid': 'Blood', 'category': 'Chemistry', 'value': None, 'valuenum': None, 'valueuom': None, 'flag': None, 'storetime': '2140-05-25 19:27:00'}),\n", - " Event(event_type='labevents', timestamp=datetime.datetime(2140, 5, 25, 12, 48), attr_dict={'itemid': '50974', 'label': 'Prostate Specific Antigen', 'fluid': 'Blood', 'category': 'Chemistry', 'value': '___', 'valuenum': '3', 'valueuom': 'ng/mL', 'flag': None, 'storetime': '2140-05-25 19:27:00'}),\n", - " Event(event_type='labevents', timestamp=datetime.datetime(2140, 5, 25, 12, 48), attr_dict={'itemid': '51613', 'label': 'eAG', 'fluid': 'Blood', 'category': 'Chemistry', 'value': '___', 'valuenum': '151', 'valueuom': 'mg/dL', 'flag': 'abnormal', 'storetime': '2140-05-25 19:32:00'}),\n", - " Event(event_type='labevents', timestamp=datetime.datetime(2140, 5, 25, 12, 48), attr_dict={'itemid': '50852', 'label': '% Hemoglobin A1c', 'fluid': 'Blood', 'category': 'Chemistry', 'value': '___', 'valuenum': '6.9', 'valueuom': '%', 'flag': 'abnormal', 'storetime': '2140-05-25 19:32:00'}),\n", - " Event(event_type='labevents', timestamp=datetime.datetime(2140, 5, 25, 12, 48), attr_dict={'itemid': '50931', 'label': 'Glucose', 'fluid': 'Blood', 'category': 'Chemistry', 'value': '___', 'valuenum': '168', 'valueuom': 'mg/dL', 'flag': 'abnormal', 'storetime': '2140-05-25 19:18:00'}),\n", - " Event(event_type='labevents', timestamp=datetime.datetime(2140, 5, 25, 12, 48), attr_dict={'itemid': '51301', 'label': 'White Blood Cells', 'fluid': 'Blood', 'category': 'Hematology', 'value': '9.2', 'valuenum': '9.2', 'valueuom': 'K/uL', 'flag': None, 'storetime': '2140-05-25 19:05:00'}),\n", - " Event(event_type='labevents', timestamp=datetime.datetime(2140, 5, 25, 12, 48), attr_dict={'itemid': '51279', 'label': 'Red Blood Cells', 'fluid': 'Blood', 'category': 'Hematology', 'value': '4.34', 'valuenum': '4.34', 'valueuom': 'm/uL', 'flag': 'abnormal', 'storetime': '2140-05-25 19:05:00'}),\n", - " Event(event_type='labevents', timestamp=datetime.datetime(2140, 5, 25, 12, 48), attr_dict={'itemid': '51277', 'label': 'RDW', 'fluid': 'Blood', 'category': 'Hematology', 'value': '14.5', 'valuenum': '14.5', 'valueuom': '%', 'flag': None, 'storetime': '2140-05-25 19:05:00'}),\n", - " Event(event_type='labevents', timestamp=datetime.datetime(2140, 5, 25, 12, 48), attr_dict={'itemid': '51265', 'label': 'Platelet Count', 'fluid': 'Blood', 'category': 'Hematology', 'value': '254', 'valuenum': '254', 'valueuom': 'K/uL', 'flag': None, 'storetime': '2140-05-25 19:05:00'}),\n", - " Event(event_type='labevents', timestamp=datetime.datetime(2140, 5, 25, 12, 48), attr_dict={'itemid': '51250', 'label': 'MCV', 'fluid': 'Blood', 'category': 'Hematology', 'value': '95', 'valuenum': '95', 'valueuom': 'fL', 'flag': None, 'storetime': '2140-05-25 19:05:00'}),\n", - " Event(event_type='labevents', timestamp=datetime.datetime(2140, 5, 25, 12, 48), attr_dict={'itemid': '51249', 'label': 'MCHC', 'fluid': 'Blood', 'category': 'Hematology', 'value': '31.2', 'valuenum': '31.2', 'valueuom': '%', 'flag': None, 'storetime': '2140-05-25 19:05:00'}),\n", - " Event(event_type='labevents', timestamp=datetime.datetime(2140, 5, 25, 12, 48), attr_dict={'itemid': '51248', 'label': 'MCH', 'fluid': 'Blood', 'category': 'Hematology', 'value': '29.6', 'valuenum': '29.6', 'valueuom': 'pg', 'flag': None, 'storetime': '2140-05-25 19:05:00'}),\n", - " Event(event_type='labevents', timestamp=datetime.datetime(2140, 5, 25, 12, 48), attr_dict={'itemid': '51222', 'label': 'Hemoglobin', 'fluid': 'Blood', 'category': 'Hematology', 'value': '12.8', 'valuenum': '12.8', 'valueuom': 'g/dL', 'flag': 'abnormal', 'storetime': '2140-05-25 19:05:00'}),\n", - " Event(event_type='labevents', timestamp=datetime.datetime(2140, 5, 25, 12, 48), attr_dict={'itemid': '51221', 'label': 'Hematocrit', 'fluid': 'Blood', 'category': 'Hematology', 'value': '41.2', 'valuenum': '41.2', 'valueuom': '%', 'flag': None, 'storetime': '2140-05-25 19:05:00'}),\n", - " Event(event_type='labevents', timestamp=datetime.datetime(2140, 5, 25, 12, 48), attr_dict={'itemid': '51006', 'label': 'Urea Nitrogen', 'fluid': 'Blood', 'category': 'Chemistry', 'value': '23', 'valuenum': '23', 'valueuom': 'mg/dL', 'flag': 'abnormal', 'storetime': '2140-05-25 19:27:00'}),\n", - " Event(event_type='labevents', timestamp=datetime.datetime(2140, 5, 25, 12, 48), attr_dict={'itemid': '51000', 'label': 'Triglycerides', 'fluid': 'Blood', 'category': 'Chemistry', 'value': '___', 'valuenum': '90', 'valueuom': 'mg/dL', 'flag': None, 'storetime': '2140-05-25 19:27:00'}),\n", - " Event(event_type='labevents', timestamp=datetime.datetime(2140, 5, 25, 12, 48), attr_dict={'itemid': '50983', 'label': 'Sodium', 'fluid': 'Blood', 'category': 'Chemistry', 'value': '142', 'valuenum': '142', 'valueuom': 'mEq/L', 'flag': None, 'storetime': '2140-05-25 19:27:00'}),\n", - " Event(event_type='labevents', timestamp=datetime.datetime(2140, 5, 25, 12, 48), attr_dict={'itemid': '50971', 'label': 'Potassium', 'fluid': 'Blood', 'category': 'Chemistry', 'value': '5.1', 'valuenum': '5.1', 'valueuom': 'mEq/L', 'flag': None, 'storetime': '2140-05-25 19:27:00'}),\n", - " Event(event_type='labevents', timestamp=datetime.datetime(2140, 8, 17, 13, 40), attr_dict={'itemid': '51613', 'label': 'eAG', 'fluid': 'Blood', 'category': 'Chemistry', 'value': '___', 'valuenum': '128', 'valueuom': 'mg/dL', 'flag': 'abnormal', 'storetime': '2140-08-17 20:23:00'}),\n", - " Event(event_type='labevents', timestamp=datetime.datetime(2140, 8, 17, 13, 40), attr_dict={'itemid': '50852', 'label': '% Hemoglobin A1c', 'fluid': 'Blood', 'category': 'Chemistry', 'value': '___', 'valuenum': '6.1', 'valueuom': '%', 'flag': 'abnormal', 'storetime': '2140-08-17 20:23:00'}),\n", - " Event(event_type='labevents', timestamp=datetime.datetime(2140, 8, 17, 13, 40), attr_dict={'itemid': '50931', 'label': 'Glucose', 'fluid': 'Blood', 'category': 'Chemistry', 'value': '___', 'valuenum': '118', 'valueuom': 'mg/dL', 'flag': 'abnormal', 'storetime': '2140-08-17 19:56:00'}),\n", - " Event(event_type='labevents', timestamp=datetime.datetime(2140, 8, 17, 13, 40), attr_dict={'itemid': '50965', 'label': 'Parathyroid Hormone', 'fluid': 'Blood', 'category': 'Chemistry', 'value': '90', 'valuenum': '90', 'valueuom': 'pg/mL', 'flag': 'abnormal', 'storetime': '2140-08-17 20:10:00'}),\n", - " Event(event_type='labevents', timestamp=datetime.datetime(2140, 8, 17, 13, 40), attr_dict={'itemid': '50970', 'label': 'Phosphate', 'fluid': 'Blood', 'category': 'Chemistry', 'value': '3.4', 'valuenum': '3.4', 'valueuom': 'mg/dL', 'flag': None, 'storetime': '2140-08-17 19:53:00'}),\n", - " Event(event_type='labevents', timestamp=datetime.datetime(2140, 8, 17, 13, 40), attr_dict={'itemid': '50963', 'label': 'NTproBNP', 'fluid': 'Blood', 'category': 'Chemistry', 'value': '___', 'valuenum': '236', 'valueuom': 'pg/mL', 'flag': None, 'storetime': '2140-08-17 23:07:00'}),\n", - " Event(event_type='labevents', timestamp=datetime.datetime(2140, 8, 17, 13, 40), attr_dict={'itemid': '50893', 'label': 'Calcium, Total', 'fluid': 'Blood', 'category': 'Chemistry', 'value': '9.7', 'valuenum': '9.7', 'valueuom': 'mg/dL', 'flag': None, 'storetime': '2140-08-17 19:53:00'}),\n", - " Event(event_type='labevents', timestamp=datetime.datetime(2140, 8, 17, 13, 40), attr_dict={'itemid': '50853', 'label': '25-OH Vitamin D', 'fluid': 'Blood', 'category': 'Chemistry', 'value': '___', 'valuenum': '52', 'valueuom': 'ng/mL', 'flag': None, 'storetime': '2140-08-19 14:50:00'}),\n", - " Event(event_type='labevents', timestamp=datetime.datetime(2140, 8, 29, 13, 10), attr_dict={'itemid': '51006', 'label': 'Urea Nitrogen', 'fluid': 'Blood', 'category': 'Chemistry', 'value': '27', 'valuenum': '27', 'valueuom': 'mg/dL', 'flag': 'abnormal', 'storetime': '2140-08-29 19:18:00'}),\n", - " Event(event_type='labevents', timestamp=datetime.datetime(2140, 8, 29, 13, 10), attr_dict={'itemid': '50920', 'label': 'Estimated GFR (MDRD equation)', 'fluid': 'Blood', 'category': 'Chemistry', 'value': None, 'valuenum': None, 'valueuom': None, 'flag': None, 'storetime': '2140-08-29 19:18:00'}),\n", - " Event(event_type='labevents', timestamp=datetime.datetime(2140, 8, 29, 13, 10), attr_dict={'itemid': '50912', 'label': 'Creatinine', 'fluid': 'Blood', 'category': 'Chemistry', 'value': '1.0', 'valuenum': '1', 'valueuom': 'mg/dL', 'flag': None, 'storetime': '2140-08-29 19:18:00'}),\n", - " Event(event_type='labevents', timestamp=datetime.datetime(2140, 10, 31, 10, 10), attr_dict={'itemid': '50931', 'label': 'Glucose', 'fluid': 'Blood', 'category': 'Chemistry', 'value': '___', 'valuenum': '109', 'valueuom': 'mg/dL', 'flag': 'abnormal', 'storetime': '2140-10-31 16:28:00'}),\n", - " Event(event_type='labevents', timestamp=datetime.datetime(2140, 10, 31, 10, 10), attr_dict={'itemid': '50907', 'label': 'Cholesterol, Total', 'fluid': 'Blood', 'category': 'Chemistry', 'value': '178', 'valuenum': '178', 'valueuom': 'mg/dL', 'flag': None, 'storetime': '2140-10-31 17:52:00'}),\n", - " Event(event_type='labevents', timestamp=datetime.datetime(2140, 10, 31, 10, 10), attr_dict={'itemid': '50905', 'label': 'Cholesterol, LDL, Calculated', 'fluid': 'Blood', 'category': 'Chemistry', 'value': '111', 'valuenum': '111', 'valueuom': 'mg/dL', 'flag': None, 'storetime': '2140-10-31 17:52:00'}),\n", - " Event(event_type='labevents', timestamp=datetime.datetime(2140, 10, 31, 10, 10), attr_dict={'itemid': '50904', 'label': 'Cholesterol, HDL', 'fluid': 'Blood', 'category': 'Chemistry', 'value': '50', 'valuenum': '50', 'valueuom': 'mg/dL', 'flag': None, 'storetime': '2140-10-31 17:52:00'}),\n", - " Event(event_type='labevents', timestamp=datetime.datetime(2140, 10, 31, 10, 10), attr_dict={'itemid': '50903', 'label': 'Cholesterol Ratio (Total/HDL)', 'fluid': 'Blood', 'category': 'Chemistry', 'value': '3.6', 'valuenum': '3.6', 'valueuom': 'Ratio', 'flag': None, 'storetime': '2140-10-31 17:52:00'}),\n", - " Event(event_type='labevents', timestamp=datetime.datetime(2140, 10, 31, 10, 10), attr_dict={'itemid': '50902', 'label': 'Chloride', 'fluid': 'Blood', 'category': 'Chemistry', 'value': '107', 'valuenum': '107', 'valueuom': 'mEq/L', 'flag': None, 'storetime': '2140-10-31 17:52:00'}),\n", - " Event(event_type='labevents', timestamp=datetime.datetime(2140, 10, 31, 10, 10), attr_dict={'itemid': '50882', 'label': 'Bicarbonate', 'fluid': 'Blood', 'category': 'Chemistry', 'value': '30', 'valuenum': '30', 'valueuom': 'mEq/L', 'flag': None, 'storetime': '2140-10-31 17:52:00'}),\n", - " Event(event_type='labevents', timestamp=datetime.datetime(2140, 10, 31, 10, 10), attr_dict={'itemid': '50868', 'label': 'Anion Gap', 'fluid': 'Blood', 'category': 'Chemistry', 'value': '15', 'valuenum': '15', 'valueuom': 'mEq/L', 'flag': None, 'storetime': '2140-10-31 17:52:00'}),\n", - " Event(event_type='labevents', timestamp=datetime.datetime(2140, 10, 31, 10, 10), attr_dict={'itemid': '51301', 'label': 'White Blood Cells', 'fluid': 'Blood', 'category': 'Hematology', 'value': '7.7', 'valuenum': '7.7', 'valueuom': 'K/uL', 'flag': None, 'storetime': '2140-10-31 16:33:00'}),\n", - " Event(event_type='labevents', timestamp=datetime.datetime(2140, 10, 31, 10, 10), attr_dict={'itemid': '51279', 'label': 'Red Blood Cells', 'fluid': 'Blood', 'category': 'Hematology', 'value': '4.46', 'valuenum': '4.46', 'valueuom': 'm/uL', 'flag': 'abnormal', 'storetime': '2140-10-31 16:33:00'}),\n", - " Event(event_type='labevents', timestamp=datetime.datetime(2140, 10, 31, 10, 10), attr_dict={'itemid': '50912', 'label': 'Creatinine', 'fluid': 'Blood', 'category': 'Chemistry', 'value': '0.9', 'valuenum': '0.9', 'valueuom': 'mg/dL', 'flag': None, 'storetime': '2140-10-31 17:52:00'}),\n", - " Event(event_type='labevents', timestamp=datetime.datetime(2140, 10, 31, 10, 10), attr_dict={'itemid': '51277', 'label': 'RDW', 'fluid': 'Blood', 'category': 'Hematology', 'value': '15.0', 'valuenum': '15', 'valueuom': '%', 'flag': None, 'storetime': '2140-10-31 16:33:00'}),\n", - " Event(event_type='labevents', timestamp=datetime.datetime(2140, 10, 31, 10, 10), attr_dict={'itemid': '51250', 'label': 'MCV', 'fluid': 'Blood', 'category': 'Hematology', 'value': '97', 'valuenum': '97', 'valueuom': 'fL', 'flag': None, 'storetime': '2140-10-31 16:33:00'}),\n", - " Event(event_type='labevents', timestamp=datetime.datetime(2140, 10, 31, 10, 10), attr_dict={'itemid': '51249', 'label': 'MCHC', 'fluid': 'Blood', 'category': 'Hematology', 'value': '31.7', 'valuenum': '31.7', 'valueuom': '%', 'flag': None, 'storetime': '2140-10-31 16:33:00'}),\n", - " Event(event_type='labevents', timestamp=datetime.datetime(2140, 10, 31, 10, 10), attr_dict={'itemid': '51248', 'label': 'MCH', 'fluid': 'Blood', 'category': 'Hematology', 'value': '30.6', 'valuenum': '30.6', 'valueuom': 'pg', 'flag': None, 'storetime': '2140-10-31 16:33:00'}),\n", - " Event(event_type='labevents', timestamp=datetime.datetime(2140, 10, 31, 10, 10), attr_dict={'itemid': '51222', 'label': 'Hemoglobin', 'fluid': 'Blood', 'category': 'Hematology', 'value': '13.7', 'valuenum': '13.7', 'valueuom': 'g/dL', 'flag': 'abnormal', 'storetime': '2140-10-31 16:33:00'}),\n", - " Event(event_type='labevents', timestamp=datetime.datetime(2140, 10, 31, 10, 10), attr_dict={'itemid': '51221', 'label': 'Hematocrit', 'fluid': 'Blood', 'category': 'Hematology', 'value': '43.0', 'valuenum': '43', 'valueuom': '%', 'flag': None, 'storetime': '2140-10-31 16:33:00'}),\n", - " Event(event_type='labevents', timestamp=datetime.datetime(2140, 10, 31, 10, 10), attr_dict={'itemid': '51613', 'label': 'eAG', 'fluid': 'Blood', 'category': 'Chemistry', 'value': '___', 'valuenum': '128', 'valueuom': 'mg/dL', 'flag': 'abnormal', 'storetime': '2140-10-31 21:08:00'}),\n", - " Event(event_type='labevents', timestamp=datetime.datetime(2140, 10, 31, 10, 10), attr_dict={'itemid': '50852', 'label': '% Hemoglobin A1c', 'fluid': 'Blood', 'category': 'Chemistry', 'value': '___', 'valuenum': '6.1', 'valueuom': '%', 'flag': 'abnormal', 'storetime': '2140-10-31 21:08:00'}),\n", - " Event(event_type='labevents', timestamp=datetime.datetime(2140, 10, 31, 10, 10), attr_dict={'itemid': '51265', 'label': 'Platelet Count', 'fluid': 'Blood', 'category': 'Hematology', 'value': '274', 'valuenum': '274', 'valueuom': 'K/uL', 'flag': None, 'storetime': '2140-10-31 16:33:00'}),\n", - " Event(event_type='labevents', timestamp=datetime.datetime(2140, 10, 31, 10, 10), attr_dict={'itemid': '50920', 'label': 'Estimated GFR (MDRD equation)', 'fluid': 'Blood', 'category': 'Chemistry', 'value': None, 'valuenum': None, 'valueuom': None, 'flag': None, 'storetime': '2140-10-31 17:52:00'}),\n", - " Event(event_type='labevents', timestamp=datetime.datetime(2140, 10, 31, 10, 10), attr_dict={'itemid': '50971', 'label': 'Potassium', 'fluid': 'Blood', 'category': 'Chemistry', 'value': '4.7', 'valuenum': '4.7', 'valueuom': 'mEq/L', 'flag': None, 'storetime': '2140-10-31 17:52:00'}),\n", - " Event(event_type='labevents', timestamp=datetime.datetime(2140, 10, 31, 10, 10), attr_dict={'itemid': '50974', 'label': 'Prostate Specific Antigen', 'fluid': 'Blood', 'category': 'Chemistry', 'value': '___', 'valuenum': '4.7', 'valueuom': 'ng/mL', 'flag': 'abnormal', 'storetime': '2140-10-31 17:52:00'}),\n", - " Event(event_type='labevents', timestamp=datetime.datetime(2140, 10, 31, 10, 10), attr_dict={'itemid': '51006', 'label': 'Urea Nitrogen', 'fluid': 'Blood', 'category': 'Chemistry', 'value': '23', 'valuenum': '23', 'valueuom': 'mg/dL', 'flag': 'abnormal', 'storetime': '2140-10-31 17:52:00'}),\n", - " Event(event_type='labevents', timestamp=datetime.datetime(2140, 10, 31, 10, 10), attr_dict={'itemid': '51000', 'label': 'Triglycerides', 'fluid': 'Blood', 'category': 'Chemistry', 'value': '___', 'valuenum': '85', 'valueuom': 'mg/dL', 'flag': None, 'storetime': '2140-10-31 17:52:00'}),\n", - " Event(event_type='labevents', timestamp=datetime.datetime(2140, 10, 31, 10, 10), attr_dict={'itemid': '50983', 'label': 'Sodium', 'fluid': 'Blood', 'category': 'Chemistry', 'value': '147', 'valuenum': '147', 'valueuom': 'mEq/L', 'flag': 'abnormal', 'storetime': '2140-10-31 17:52:00'}),\n", - " Event(event_type='labevents', timestamp=datetime.datetime(2141, 1, 12, 12, 18), attr_dict={'itemid': '50970', 'label': 'Phosphate', 'fluid': 'Blood', 'category': 'Chemistry', 'value': '3.1', 'valuenum': '3.1', 'valueuom': 'mg/dL', 'flag': None, 'storetime': '2141-01-12 20:19:00'}),\n", - " Event(event_type='labevents', timestamp=datetime.datetime(2141, 1, 12, 12, 18), attr_dict={'itemid': '50893', 'label': 'Calcium, Total', 'fluid': 'Blood', 'category': 'Chemistry', 'value': '9.0', 'valuenum': '9', 'valueuom': 'mg/dL', 'flag': None, 'storetime': '2141-01-12 20:19:00'}),\n", - " Event(event_type='labevents', timestamp=datetime.datetime(2141, 1, 12, 12, 18), attr_dict={'itemid': '50862', 'label': 'Albumin', 'fluid': 'Blood', 'category': 'Chemistry', 'value': '3.9', 'valuenum': '3.9', 'valueuom': 'g/dL', 'flag': None, 'storetime': '2141-01-12 20:19:00'}),\n", - " Event(event_type='labevents', timestamp=datetime.datetime(2141, 1, 12, 12, 18), attr_dict={'itemid': '50853', 'label': '25-OH Vitamin D', 'fluid': 'Blood', 'category': 'Chemistry', 'value': '___', 'valuenum': '32', 'valueuom': 'ng/mL', 'flag': None, 'storetime': '2141-01-13 09:48:00'}),\n", - " Event(event_type='labevents', timestamp=datetime.datetime(2141, 1, 12, 12, 18), attr_dict={'itemid': '50965', 'label': 'Parathyroid Hormone', 'fluid': 'Blood', 'category': 'Chemistry', 'value': '84', 'valuenum': '84', 'valueuom': 'pg/mL', 'flag': 'abnormal', 'storetime': '2141-01-12 20:44:00'})]" + "[Event(event_type='patients', timestamp=datetime.datetime(2025, 12, 18, 21, 8, 17, 423997), attr_dict={'gender': 'F', 'anchor_age': '56', 'anchor_year': '2154', 'anchor_year_group': '2011 - 2013', 'dod': None}),\n", + " Event(event_type='labevents', timestamp=datetime.datetime(2155, 11, 24, 7, 59), attr_dict={'itemid': '50887', 'label': 'Blue Top Hold', 'fluid': 'Blood', 'category': 'Chemistry', 'value': 'HOLD. DISCARD GREATER THAN 24 HRS OLD.', 'valuenum': None, 'valueuom': None, 'flag': None, 'storetime': None}),\n", + " Event(event_type='labevents', timestamp=datetime.datetime(2155, 11, 24, 7, 59), attr_dict={'itemid': '50933', 'label': 'Green Top Hold (plasma)', 'fluid': 'Blood', 'category': 'Chemistry', 'value': 'HOLD. DISCARD GREATER THAN 4 HOURS OLD.', 'valuenum': None, 'valueuom': None, 'flag': None, 'storetime': None}),\n", + " Event(event_type='labevents', timestamp=datetime.datetime(2155, 11, 24, 7, 59), attr_dict={'itemid': '51301', 'label': 'White Blood Cells', 'fluid': 'Blood', 'category': 'Hematology', 'value': '10.8', 'valuenum': '10.8', 'valueuom': 'K/uL', 'flag': None, 'storetime': '2155-11-24 08:31:00'}),\n", + " Event(event_type='labevents', timestamp=datetime.datetime(2155, 11, 24, 7, 59), attr_dict={'itemid': '51279', 'label': 'Red Blood Cells', 'fluid': 'Blood', 'category': 'Hematology', 'value': '4.04', 'valuenum': '4.04', 'valueuom': 'm/uL', 'flag': 'abnormal', 'storetime': '2155-11-24 08:31:00'}),\n", + " Event(event_type='labevents', timestamp=datetime.datetime(2155, 11, 24, 7, 59), attr_dict={'itemid': '50856', 'label': 'Acetaminophen', 'fluid': 'Blood', 'category': 'Chemistry', 'value': None, 'valuenum': None, 'valueuom': 'ug/mL', 'flag': None, 'storetime': '2155-11-24 08:41:00'}),\n", + " Event(event_type='labevents', timestamp=datetime.datetime(2155, 11, 24, 7, 59), attr_dict={'itemid': '50868', 'label': 'Anion Gap', 'fluid': 'Blood', 'category': 'Chemistry', 'value': '18', 'valuenum': '18', 'valueuom': 'mEq/L', 'flag': None, 'storetime': '2155-11-24 08:41:00'}),\n", + " Event(event_type='labevents', timestamp=datetime.datetime(2155, 11, 24, 7, 59), attr_dict={'itemid': '50879', 'label': 'Barbiturate Screen', 'fluid': 'Blood', 'category': 'Chemistry', 'value': 'NEG', 'valuenum': None, 'valueuom': None, 'flag': None, 'storetime': '2155-11-24 08:41:00'}),\n", + " Event(event_type='labevents', timestamp=datetime.datetime(2155, 11, 24, 7, 59), attr_dict={'itemid': '50880', 'label': 'Benzodiazepine Screen', 'fluid': 'Blood', 'category': 'Chemistry', 'value': 'NEG', 'valuenum': None, 'valueuom': None, 'flag': None, 'storetime': '2155-11-24 08:41:00'}),\n", + " Event(event_type='labevents', timestamp=datetime.datetime(2155, 11, 24, 7, 59), attr_dict={'itemid': '50882', 'label': 'Bicarbonate', 'fluid': 'Blood', 'category': 'Chemistry', 'value': '20', 'valuenum': '20', 'valueuom': 'mEq/L', 'flag': 'abnormal', 'storetime': '2155-11-24 08:41:00'}),\n", + " Event(event_type='labevents', timestamp=datetime.datetime(2155, 11, 24, 7, 59), attr_dict={'itemid': '50902', 'label': 'Chloride', 'fluid': 'Blood', 'category': 'Chemistry', 'value': '110', 'valuenum': '110', 'valueuom': 'mEq/L', 'flag': 'abnormal', 'storetime': '2155-11-24 08:41:00'}),\n", + " Event(event_type='labevents', timestamp=datetime.datetime(2155, 11, 24, 7, 59), attr_dict={'itemid': '50912', 'label': 'Creatinine', 'fluid': 'Blood', 'category': 'Chemistry', 'value': '1.4', 'valuenum': '1.4', 'valueuom': 'mg/dL', 'flag': 'abnormal', 'storetime': '2155-11-24 08:41:00'}),\n", + " Event(event_type='labevents', timestamp=datetime.datetime(2155, 11, 24, 7, 59), attr_dict={'itemid': '50920', 'label': 'Estimated GFR (MDRD equation)', 'fluid': 'Blood', 'category': 'Chemistry', 'value': None, 'valuenum': None, 'valueuom': None, 'flag': None, 'storetime': '2155-11-24 08:41:00'}),\n", + " Event(event_type='labevents', timestamp=datetime.datetime(2155, 11, 24, 7, 59), attr_dict={'itemid': '50922', 'label': 'Ethanol', 'fluid': 'Blood', 'category': 'Chemistry', 'value': None, 'valuenum': None, 'valueuom': 'mg/dL', 'flag': None, 'storetime': '2155-11-24 08:41:00'}),\n", + " Event(event_type='labevents', timestamp=datetime.datetime(2155, 11, 24, 7, 59), attr_dict={'itemid': '50931', 'label': 'Glucose', 'fluid': 'Blood', 'category': 'Chemistry', 'value': '___', 'valuenum': '131', 'valueuom': 'mg/dL', 'flag': 'abnormal', 'storetime': '2155-11-24 08:41:00'}),\n", + " Event(event_type='labevents', timestamp=datetime.datetime(2155, 11, 24, 7, 59), attr_dict={'itemid': '50971', 'label': 'Potassium', 'fluid': 'Blood', 'category': 'Chemistry', 'value': '3.5', 'valuenum': '3.5', 'valueuom': 'mEq/L', 'flag': None, 'storetime': '2155-11-24 08:41:00'}),\n", + " Event(event_type='labevents', timestamp=datetime.datetime(2155, 11, 24, 7, 59), attr_dict={'itemid': '50981', 'label': 'Salicylate', 'fluid': 'Blood', 'category': 'Chemistry', 'value': None, 'valuenum': None, 'valueuom': 'mg/dL', 'flag': None, 'storetime': '2155-11-24 08:41:00'}),\n", + " Event(event_type='labevents', timestamp=datetime.datetime(2155, 11, 24, 7, 59), attr_dict={'itemid': '50983', 'label': 'Sodium', 'fluid': 'Blood', 'category': 'Chemistry', 'value': '144', 'valuenum': '144', 'valueuom': 'mEq/L', 'flag': None, 'storetime': '2155-11-24 08:41:00'}),\n", + " Event(event_type='labevents', timestamp=datetime.datetime(2155, 11, 24, 7, 59), attr_dict={'itemid': '50999', 'label': 'Tricyclic Antidepressant Screen', 'fluid': 'Blood', 'category': 'Chemistry', 'value': 'NEG', 'valuenum': None, 'valueuom': None, 'flag': None, 'storetime': '2155-11-24 08:41:00'}),\n", + " Event(event_type='labevents', timestamp=datetime.datetime(2155, 11, 24, 7, 59), attr_dict={'itemid': '51006', 'label': 'Urea Nitrogen', 'fluid': 'Blood', 'category': 'Chemistry', 'value': '17', 'valuenum': '17', 'valueuom': 'mg/dL', 'flag': None, 'storetime': '2155-11-24 08:41:00'}),\n", + " Event(event_type='labevents', timestamp=datetime.datetime(2155, 11, 24, 7, 59), attr_dict={'itemid': '51146', 'label': 'Basophils', 'fluid': 'Blood', 'category': 'Hematology', 'value': '0.4', 'valuenum': '0.4', 'valueuom': '%', 'flag': None, 'storetime': '2155-11-24 08:31:00'}),\n", + " Event(event_type='labevents', timestamp=datetime.datetime(2155, 11, 24, 7, 59), attr_dict={'itemid': '51200', 'label': 'Eosinophils', 'fluid': 'Blood', 'category': 'Hematology', 'value': '1.7', 'valuenum': '1.7', 'valueuom': '%', 'flag': None, 'storetime': '2155-11-24 08:31:00'}),\n", + " Event(event_type='labevents', timestamp=datetime.datetime(2155, 11, 24, 7, 59), attr_dict={'itemid': '51221', 'label': 'Hematocrit', 'fluid': 'Blood', 'category': 'Hematology', 'value': '34.6', 'valuenum': '34.6', 'valueuom': '%', 'flag': 'abnormal', 'storetime': '2155-11-24 08:31:00'}),\n", + " Event(event_type='labevents', timestamp=datetime.datetime(2155, 11, 24, 7, 59), attr_dict={'itemid': '51222', 'label': 'Hemoglobin', 'fluid': 'Blood', 'category': 'Hematology', 'value': '11.5', 'valuenum': '11.5', 'valueuom': 'g/dL', 'flag': 'abnormal', 'storetime': '2155-11-24 08:31:00'}),\n", + " Event(event_type='labevents', timestamp=datetime.datetime(2155, 11, 24, 7, 59), attr_dict={'itemid': '51244', 'label': 'Lymphocytes', 'fluid': 'Blood', 'category': 'Hematology', 'value': '10.2', 'valuenum': '10.2', 'valueuom': '%', 'flag': 'abnormal', 'storetime': '2155-11-24 08:31:00'}),\n", + " Event(event_type='labevents', timestamp=datetime.datetime(2155, 11, 24, 7, 59), attr_dict={'itemid': '51248', 'label': 'MCH', 'fluid': 'Blood', 'category': 'Hematology', 'value': '28.5', 'valuenum': '28.5', 'valueuom': 'pg', 'flag': None, 'storetime': '2155-11-24 08:31:00'}),\n", + " Event(event_type='labevents', timestamp=datetime.datetime(2155, 11, 24, 7, 59), attr_dict={'itemid': '51249', 'label': 'MCHC', 'fluid': 'Blood', 'category': 'Hematology', 'value': '33.3', 'valuenum': '33.3', 'valueuom': '%', 'flag': None, 'storetime': '2155-11-24 08:31:00'}),\n", + " Event(event_type='labevents', timestamp=datetime.datetime(2155, 11, 24, 7, 59), attr_dict={'itemid': '51250', 'label': 'MCV', 'fluid': 'Blood', 'category': 'Hematology', 'value': '86', 'valuenum': '86', 'valueuom': 'fL', 'flag': None, 'storetime': '2155-11-24 08:31:00'}),\n", + " Event(event_type='labevents', timestamp=datetime.datetime(2155, 11, 24, 7, 59), attr_dict={'itemid': '51254', 'label': 'Monocytes', 'fluid': 'Blood', 'category': 'Hematology', 'value': '3.2', 'valuenum': '3.2', 'valueuom': '%', 'flag': None, 'storetime': '2155-11-24 08:31:00'}),\n", + " Event(event_type='labevents', timestamp=datetime.datetime(2155, 11, 24, 7, 59), attr_dict={'itemid': '51256', 'label': 'Neutrophils', 'fluid': 'Blood', 'category': 'Hematology', 'value': '84.4', 'valuenum': '84.4', 'valueuom': '%', 'flag': 'abnormal', 'storetime': '2155-11-24 08:31:00'}),\n", + " Event(event_type='labevents', timestamp=datetime.datetime(2155, 11, 24, 7, 59), attr_dict={'itemid': '51265', 'label': 'Platelet Count', 'fluid': 'Blood', 'category': 'Hematology', 'value': '241', 'valuenum': '241', 'valueuom': 'K/uL', 'flag': None, 'storetime': '2155-11-24 08:31:00'}),\n", + " Event(event_type='labevents', timestamp=datetime.datetime(2155, 11, 24, 7, 59), attr_dict={'itemid': '51277', 'label': 'RDW', 'fluid': 'Blood', 'category': 'Hematology', 'value': '13.9', 'valuenum': '13.9', 'valueuom': '%', 'flag': None, 'storetime': '2155-11-24 08:31:00'}),\n", + " Event(event_type='labevents', timestamp=datetime.datetime(2155, 11, 26, 12, 45), attr_dict={'itemid': '50868', 'label': 'Anion Gap', 'fluid': 'Blood', 'category': 'Chemistry', 'value': '14', 'valuenum': '14', 'valueuom': 'mEq/L', 'flag': None, 'storetime': '2155-11-26 17:18:00'}),\n", + " Event(event_type='labevents', timestamp=datetime.datetime(2155, 11, 26, 12, 45), attr_dict={'itemid': '50882', 'label': 'Bicarbonate', 'fluid': 'Blood', 'category': 'Chemistry', 'value': '25', 'valuenum': '25', 'valueuom': 'mEq/L', 'flag': None, 'storetime': '2155-11-26 17:18:00'}),\n", + " Event(event_type='labevents', timestamp=datetime.datetime(2155, 11, 26, 12, 45), attr_dict={'itemid': '50902', 'label': 'Chloride', 'fluid': 'Blood', 'category': 'Chemistry', 'value': '106', 'valuenum': '106', 'valueuom': 'mEq/L', 'flag': None, 'storetime': '2155-11-26 17:18:00'}),\n", + " Event(event_type='labevents', timestamp=datetime.datetime(2155, 11, 26, 12, 45), attr_dict={'itemid': '50912', 'label': 'Creatinine', 'fluid': 'Blood', 'category': 'Chemistry', 'value': '1.0', 'valuenum': '1', 'valueuom': 'mg/dL', 'flag': None, 'storetime': '2155-11-26 17:18:00'}),\n", + " Event(event_type='labevents', timestamp=datetime.datetime(2155, 11, 26, 12, 45), attr_dict={'itemid': '50971', 'label': 'Potassium', 'fluid': 'Blood', 'category': 'Chemistry', 'value': '4.2', 'valuenum': '4.2', 'valueuom': 'mEq/L', 'flag': None, 'storetime': '2155-11-26 17:18:00'}),\n", + " Event(event_type='labevents', timestamp=datetime.datetime(2155, 11, 26, 12, 45), attr_dict={'itemid': '50983', 'label': 'Sodium', 'fluid': 'Blood', 'category': 'Chemistry', 'value': '141', 'valuenum': '141', 'valueuom': 'mEq/L', 'flag': None, 'storetime': '2155-11-26 17:18:00'}),\n", + " Event(event_type='labevents', timestamp=datetime.datetime(2155, 11, 26, 12, 45), attr_dict={'itemid': '51006', 'label': 'Urea Nitrogen', 'fluid': 'Blood', 'category': 'Chemistry', 'value': '11', 'valuenum': '11', 'valueuom': 'mg/dL', 'flag': None, 'storetime': '2155-11-26 17:18:00'}),\n", + " Event(event_type='labevents', timestamp=datetime.datetime(2156, 1, 21, 17, 4), attr_dict={'itemid': '51463', 'label': 'Bacteria', 'fluid': 'Urine', 'category': 'Hematology', 'value': None, 'valuenum': None, 'valueuom': None, 'flag': None, 'storetime': '2156-01-21 22:19:00'}),\n", + " Event(event_type='labevents', timestamp=datetime.datetime(2156, 1, 21, 17, 4), attr_dict={'itemid': '51464', 'label': 'Bilirubin', 'fluid': 'Urine', 'category': 'Hematology', 'value': None, 'valuenum': None, 'valueuom': 'mg/dL', 'flag': None, 'storetime': '2156-01-21 22:19:00'}),\n", + " Event(event_type='labevents', timestamp=datetime.datetime(2156, 1, 21, 17, 4), attr_dict={'itemid': '51466', 'label': 'Blood', 'fluid': 'Urine', 'category': 'Hematology', 'value': None, 'valuenum': None, 'valueuom': None, 'flag': None, 'storetime': '2156-01-21 22:19:00'}),\n", + " Event(event_type='labevents', timestamp=datetime.datetime(2156, 1, 21, 17, 4), attr_dict={'itemid': '51476', 'label': 'Epithelial Cells', 'fluid': 'Urine', 'category': 'Hematology', 'value': '9', 'valuenum': '9', 'valueuom': '#/hpf', 'flag': None, 'storetime': '2156-01-21 22:19:00'}),\n", + " Event(event_type='labevents', timestamp=datetime.datetime(2156, 1, 21, 17, 4), attr_dict={'itemid': '51478', 'label': 'Glucose', 'fluid': 'Urine', 'category': 'Hematology', 'value': None, 'valuenum': None, 'valueuom': 'mg/dL', 'flag': None, 'storetime': '2156-01-21 22:19:00'}),\n", + " Event(event_type='labevents', timestamp=datetime.datetime(2156, 1, 21, 17, 4), attr_dict={'itemid': '51484', 'label': 'Ketone', 'fluid': 'Urine', 'category': 'Hematology', 'value': None, 'valuenum': None, 'valueuom': 'mg/dL', 'flag': None, 'storetime': '2156-01-21 22:19:00'}),\n", + " Event(event_type='labevents', timestamp=datetime.datetime(2156, 1, 21, 17, 4), attr_dict={'itemid': '51487', 'label': 'Nitrite', 'fluid': 'Urine', 'category': 'Hematology', 'value': None, 'valuenum': None, 'valueuom': None, 'flag': None, 'storetime': '2156-01-21 22:19:00'}),\n", + " Event(event_type='labevents', timestamp=datetime.datetime(2156, 1, 21, 17, 4), attr_dict={'itemid': '51491', 'label': 'pH', 'fluid': 'Urine', 'category': 'Hematology', 'value': '6.0', 'valuenum': '6', 'valueuom': 'units', 'flag': None, 'storetime': '2156-01-21 22:19:00'}),\n", + " Event(event_type='labevents', timestamp=datetime.datetime(2156, 1, 21, 17, 4), attr_dict={'itemid': '51492', 'label': 'Protein', 'fluid': 'Urine', 'category': 'Hematology', 'value': None, 'valuenum': None, 'valueuom': 'mg/dL', 'flag': None, 'storetime': '2156-01-21 22:19:00'}),\n", + " Event(event_type='labevents', timestamp=datetime.datetime(2156, 1, 21, 17, 4), attr_dict={'itemid': '51493', 'label': 'RBC', 'fluid': 'Urine', 'category': 'Hematology', 'value': '1', 'valuenum': '1', 'valueuom': '#/hpf', 'flag': None, 'storetime': '2156-01-21 22:19:00'}),\n", + " Event(event_type='labevents', timestamp=datetime.datetime(2156, 1, 21, 17, 4), attr_dict={'itemid': '51498', 'label': 'Specific Gravity', 'fluid': 'Urine', 'category': 'Hematology', 'value': '1.016', 'valuenum': '1.016', 'valueuom': ' ', 'flag': None, 'storetime': '2156-01-21 22:19:00'}),\n", + " Event(event_type='labevents', timestamp=datetime.datetime(2156, 1, 21, 17, 4), attr_dict={'itemid': '51506', 'label': 'Urine Appearance', 'fluid': 'Urine', 'category': 'Hematology', 'value': None, 'valuenum': None, 'valueuom': None, 'flag': None, 'storetime': '2156-01-21 22:19:00'}),\n", + " Event(event_type='labevents', timestamp=datetime.datetime(2156, 1, 21, 17, 4), attr_dict={'itemid': '51508', 'label': 'Urine Color', 'fluid': 'Urine', 'category': 'Hematology', 'value': None, 'valuenum': None, 'valueuom': None, 'flag': None, 'storetime': '2156-01-21 22:19:00'}),\n", + " Event(event_type='labevents', timestamp=datetime.datetime(2156, 1, 21, 17, 4), attr_dict={'itemid': '51512', 'label': 'Urine Mucous', 'fluid': 'Urine', 'category': 'Hematology', 'value': None, 'valuenum': None, 'valueuom': None, 'flag': None, 'storetime': '2156-01-21 22:19:00'}),\n", + " Event(event_type='labevents', timestamp=datetime.datetime(2156, 1, 21, 17, 4), attr_dict={'itemid': '51514', 'label': 'Urobilinogen', 'fluid': 'Urine', 'category': 'Hematology', 'value': None, 'valuenum': None, 'valueuom': 'mg/dL', 'flag': None, 'storetime': '2156-01-21 22:19:00'}),\n", + " Event(event_type='labevents', timestamp=datetime.datetime(2156, 1, 21, 17, 4), attr_dict={'itemid': '51516', 'label': 'WBC', 'fluid': 'Urine', 'category': 'Hematology', 'value': '2', 'valuenum': '2', 'valueuom': '#/hpf', 'flag': None, 'storetime': '2156-01-21 22:19:00'}),\n", + " Event(event_type='labevents', timestamp=datetime.datetime(2156, 1, 21, 17, 4), attr_dict={'itemid': '51519', 'label': 'Yeast', 'fluid': 'Urine', 'category': 'Hematology', 'value': 'NONE', 'valuenum': None, 'valueuom': None, 'flag': None, 'storetime': '2156-01-21 22:19:00'}),\n", + " Event(event_type='labevents', timestamp=datetime.datetime(2156, 1, 21, 17, 4), attr_dict={'itemid': '51486', 'label': 'Leukocytes', 'fluid': 'Urine', 'category': 'Hematology', 'value': None, 'valuenum': None, 'valueuom': None, 'flag': None, 'storetime': '2156-01-21 22:19:00'}),\n", + " Event(event_type='labevents', timestamp=datetime.datetime(2156, 1, 21, 17, 16), attr_dict={'itemid': '50903', 'label': 'Cholesterol Ratio (Total/HDL)', 'fluid': 'Blood', 'category': 'Chemistry', 'value': '2.1', 'valuenum': '2.1', 'valueuom': 'Ratio', 'flag': None, 'storetime': '2156-01-21 21:17:00'}),\n", + " Event(event_type='labevents', timestamp=datetime.datetime(2156, 1, 21, 17, 16), attr_dict={'itemid': '50904', 'label': 'Cholesterol, HDL', 'fluid': 'Blood', 'category': 'Chemistry', 'value': '81', 'valuenum': '81', 'valueuom': 'mg/dL', 'flag': None, 'storetime': '2156-01-21 21:17:00'}),\n", + " Event(event_type='labevents', timestamp=datetime.datetime(2156, 1, 21, 17, 16), attr_dict={'itemid': '50905', 'label': 'Cholesterol, LDL, Calculated', 'fluid': 'Blood', 'category': 'Chemistry', 'value': '67', 'valuenum': '67', 'valueuom': 'mg/dL', 'flag': None, 'storetime': '2156-01-21 21:17:00'}),\n", + " Event(event_type='labevents', timestamp=datetime.datetime(2156, 1, 21, 17, 16), attr_dict={'itemid': '50907', 'label': 'Cholesterol, Total', 'fluid': 'Blood', 'category': 'Chemistry', 'value': '168', 'valuenum': '168', 'valueuom': 'mg/dL', 'flag': None, 'storetime': '2156-01-21 21:17:00'}),\n", + " Event(event_type='labevents', timestamp=datetime.datetime(2156, 1, 21, 17, 16), attr_dict={'itemid': '50924', 'label': 'Ferritin', 'fluid': 'Blood', 'category': 'Chemistry', 'value': '90', 'valuenum': '90', 'valueuom': 'ng/mL', 'flag': None, 'storetime': '2156-01-21 21:17:00'}),\n", + " Event(event_type='labevents', timestamp=datetime.datetime(2156, 1, 21, 17, 16), attr_dict={'itemid': '50952', 'label': 'Iron', 'fluid': 'Blood', 'category': 'Chemistry', 'value': '53', 'valuenum': '53', 'valueuom': 'ug/dL', 'flag': None, 'storetime': '2156-01-21 21:17:00'}),\n", + " Event(event_type='labevents', timestamp=datetime.datetime(2156, 1, 21, 17, 16), attr_dict={'itemid': '50953', 'label': 'Iron Binding Capacity, Total', 'fluid': 'Blood', 'category': 'Chemistry', 'value': '334', 'valuenum': '334', 'valueuom': 'ug/dL', 'flag': None, 'storetime': '2156-01-21 21:17:00'}),\n", + " Event(event_type='labevents', timestamp=datetime.datetime(2156, 1, 21, 17, 16), attr_dict={'itemid': '50998', 'label': 'Transferrin', 'fluid': 'Blood', 'category': 'Chemistry', 'value': '257', 'valuenum': '257', 'valueuom': 'mg/dL', 'flag': None, 'storetime': '2156-01-21 21:17:00'}),\n", + " Event(event_type='labevents', timestamp=datetime.datetime(2156, 1, 21, 17, 16), attr_dict={'itemid': '51000', 'label': 'Triglycerides', 'fluid': 'Blood', 'category': 'Chemistry', 'value': '___', 'valuenum': '98', 'valueuom': 'mg/dL', 'flag': None, 'storetime': '2156-01-21 21:17:00'}),\n", + " Event(event_type='labevents', timestamp=datetime.datetime(2156, 1, 21, 17, 16), attr_dict={'itemid': '51283', 'label': 'Reticulocyte Count, Automated', 'fluid': 'Blood', 'category': 'Hematology', 'value': '1.3', 'valuenum': '1.3', 'valueuom': '%', 'flag': None, 'storetime': '2156-01-21 20:26:00'}),\n", + " Event(event_type='labevents', timestamp=datetime.datetime(2156, 1, 21, 17, 16), attr_dict={'itemid': '50852', 'label': '% Hemoglobin A1c', 'fluid': 'Blood', 'category': 'Chemistry', 'value': '___', 'valuenum': '6', 'valueuom': '%', 'flag': 'abnormal', 'storetime': '2156-01-21 20:27:00'}),\n", + " Event(event_type='labevents', timestamp=datetime.datetime(2156, 1, 21, 17, 16), attr_dict={'itemid': '51613', 'label': 'eAG', 'fluid': 'Blood', 'category': 'Chemistry', 'value': '___', 'valuenum': '126', 'valueuom': 'mg/dL', 'flag': 'abnormal', 'storetime': '2156-01-21 20:27:00'}),\n", + " Event(event_type='labevents', timestamp=datetime.datetime(2156, 1, 21, 17, 16), attr_dict={'itemid': '50906', 'label': 'Cholesterol, LDL, Measured', 'fluid': 'Blood', 'category': 'Chemistry', 'value': '81', 'valuenum': '81', 'valueuom': 'mg/dL', 'flag': None, 'storetime': '2156-01-21 21:17:00'}),\n", + " Event(event_type='admissions', timestamp=datetime.datetime(2156, 4, 16, 10, 45), attr_dict={'hadm_id': '28106518', 'admission_type': 'AMBULATORY OBSERVATION', 'admission_location': 'PACU', 'insurance': 'Medicaid', 'language': 'ENGLISH', 'marital_status': 'SINGLE', 'race': 'BLACK/AFRICAN AMERICAN', 'discharge_location': 'HOME', 'dischtime': '2156-04-17 12:55:00', 'hospital_expire_flag': '0'}),\n", + " Event(event_type='prescriptions', timestamp=datetime.datetime(2156, 4, 16, 18, 0), attr_dict={'hadm_id': '28106518', 'drug': 'Sodium Chloride 0.9% Flush', 'ndc': '0', 'prod_strength': '10 mL Syringe', 'dose_val_rx': '3', 'dose_unit_rx': 'mL', 'route': 'IV', 'stoptime': '2156-04-17 17:00:00'}),\n", + " Event(event_type='prescriptions', timestamp=datetime.datetime(2156, 4, 16, 18, 0), attr_dict={'hadm_id': '28106518', 'drug': 'Acetaminophen', 'ndc': '00121065721', 'prod_strength': '650mg UD Cup', 'dose_val_rx': '325-650', 'dose_unit_rx': 'mg', 'route': 'PO/NG', 'stoptime': '2156-04-17 17:00:00'}),\n", + " Event(event_type='prescriptions', timestamp=datetime.datetime(2156, 4, 16, 18, 0), attr_dict={'hadm_id': '28106518', 'drug': 'Diazepam', 'ndc': '51079028520', 'prod_strength': '5 mg Tab', 'dose_val_rx': '5', 'dose_unit_rx': 'mg', 'route': 'PO/NG', 'stoptime': '2156-04-17 17:00:00'}),\n", + " Event(event_type='prescriptions', timestamp=datetime.datetime(2156, 4, 16, 18, 0), attr_dict={'hadm_id': '28106518', 'drug': 'Acetaminophen', 'ndc': '51079000220', 'prod_strength': '325mg Tablet', 'dose_val_rx': '325-650', 'dose_unit_rx': 'mg', 'route': 'PO/NG', 'stoptime': '2156-04-17 17:00:00'}),\n", + " Event(event_type='prescriptions', timestamp=datetime.datetime(2156, 4, 16, 18, 0), attr_dict={'hadm_id': '28106518', 'drug': 'Morphine Sulfate', 'ndc': '00409189001', 'prod_strength': '2 mg Syringe', 'dose_val_rx': '2-4', 'dose_unit_rx': 'mg', 'route': 'IV', 'stoptime': '2156-04-17 17:00:00'}),\n", + " Event(event_type='prescriptions', timestamp=datetime.datetime(2156, 4, 16, 18, 0), attr_dict={'hadm_id': '28106518', 'drug': 'Influenza Virus Vaccine', 'ndc': '49281001350', 'prod_strength': '0.5 mL Syringe', 'dose_val_rx': '0.5', 'dose_unit_rx': 'mL', 'route': 'IM', 'stoptime': '2156-04-17 17:00:00'}),\n", + " Event(event_type='prescriptions', timestamp=datetime.datetime(2156, 4, 16, 18, 0), attr_dict={'hadm_id': '28106518', 'drug': 'Sodium Chloride 0.9%', 'ndc': '00338004904', 'prod_strength': 'Floor Stock Bag', 'dose_val_rx': '1000', 'dose_unit_rx': 'mL', 'route': 'IV', 'stoptime': '2156-04-17 17:00:00'}),\n", + " Event(event_type='prescriptions', timestamp=datetime.datetime(2156, 4, 16, 18, 0), attr_dict={'hadm_id': '28106518', 'drug': 'OxycoDONE (Immediate Release) ', 'ndc': '00406055262', 'prod_strength': '5mg Tablet', 'dose_val_rx': '5-10', 'dose_unit_rx': 'mg', 'route': 'PO/NG', 'stoptime': '2156-04-17 17:00:00'}),\n", + " Event(event_type='prescriptions', timestamp=datetime.datetime(2156, 4, 16, 20, 0), attr_dict={'hadm_id': '28106518', 'drug': 'Docusate Sodium', 'ndc': '00904224461', 'prod_strength': '100mg Capsule', 'dose_val_rx': '100', 'dose_unit_rx': 'mg', 'route': 'PO/NG', 'stoptime': '2156-04-17 17:00:00'}),\n", + " Event(event_type='prescriptions', timestamp=datetime.datetime(2156, 4, 16, 20, 0), attr_dict={'hadm_id': '28106518', 'drug': 'Docusate Sodium', 'ndc': '00121054410', 'prod_strength': '100mg / 10 mL', 'dose_val_rx': '100', 'dose_unit_rx': 'mg', 'route': 'PO/NG', 'stoptime': '2156-04-17 17:00:00'}),\n", + " Event(event_type='prescriptions', timestamp=datetime.datetime(2156, 4, 16, 22, 0), attr_dict={'hadm_id': '28106518', 'drug': 'Senna', 'ndc': '00904516561', 'prod_strength': '8.6 mg Tablet', 'dose_val_rx': '8.6', 'dose_unit_rx': 'mg', 'route': 'PO/NG', 'stoptime': '2156-04-17 17:00:00'}),\n", + " Event(event_type='diagnoses_icd', timestamp=datetime.datetime(2156, 4, 17, 12, 55), attr_dict={'hadm_id': '28106518', 'icd_code': '72210', 'icd_version': '9', 'seq_num': '1'}),\n", + " Event(event_type='procedures_icd', timestamp=datetime.datetime(2156, 4, 17, 12, 55), attr_dict={'hadm_id': '28106518', 'icd_code': '8051', 'icd_version': '9', 'seq_num': '1'}),\n", + " Event(event_type='diagnoses_icd', timestamp=datetime.datetime(2156, 4, 17, 12, 55), attr_dict={'hadm_id': '28106518', 'icd_code': '72740', 'icd_version': '9', 'seq_num': '4'}),\n", + " Event(event_type='diagnoses_icd', timestamp=datetime.datetime(2156, 4, 17, 12, 55), attr_dict={'hadm_id': '28106518', 'icd_code': '27800', 'icd_version': '9', 'seq_num': '2'}),\n", + " Event(event_type='diagnoses_icd', timestamp=datetime.datetime(2156, 4, 17, 12, 55), attr_dict={'hadm_id': '28106518', 'icd_code': 'V0481', 'icd_version': '9', 'seq_num': '3'}),\n", + " Event(event_type='labevents', timestamp=datetime.datetime(2156, 10, 13, 17, 40), attr_dict={'itemid': '50912', 'label': 'Creatinine', 'fluid': 'Blood', 'category': 'Chemistry', 'value': '1.2', 'valuenum': '1.2', 'valueuom': 'mg/dL', 'flag': 'abnormal', 'storetime': '2156-10-13 20:46:00'}),\n", + " Event(event_type='labevents', timestamp=datetime.datetime(2156, 10, 13, 17, 40), attr_dict={'itemid': '50920', 'label': 'Estimated GFR (MDRD equation)', 'fluid': 'Blood', 'category': 'Chemistry', 'value': None, 'valuenum': None, 'valueuom': None, 'flag': None, 'storetime': '2156-10-13 20:46:00'}),\n", + " Event(event_type='labevents', timestamp=datetime.datetime(2156, 10, 13, 17, 40), attr_dict={'itemid': '51006', 'label': 'Urea Nitrogen', 'fluid': 'Blood', 'category': 'Chemistry', 'value': '10', 'valuenum': '10', 'valueuom': 'mg/dL', 'flag': None, 'storetime': '2156-10-13 20:46:00'}),\n", + " Event(event_type='labevents', timestamp=datetime.datetime(2156, 12, 14, 11, 39), attr_dict={'itemid': '50912', 'label': 'Creatinine', 'fluid': 'Blood', 'category': 'Chemistry', 'value': '1.0', 'valuenum': '1', 'valueuom': 'mg/dL', 'flag': None, 'storetime': '2156-12-14 18:08:00'}),\n", + " Event(event_type='labevents', timestamp=datetime.datetime(2156, 12, 14, 11, 39), attr_dict={'itemid': '50920', 'label': 'Estimated GFR (MDRD equation)', 'fluid': 'Blood', 'category': 'Chemistry', 'value': None, 'valuenum': None, 'valueuom': None, 'flag': None, 'storetime': '2156-12-14 18:08:00'}),\n", + " Event(event_type='labevents', timestamp=datetime.datetime(2156, 12, 14, 11, 39), attr_dict={'itemid': '50943', 'label': 'Hepatitis C Virus Antibody', 'fluid': 'Blood', 'category': 'Chemistry', 'value': None, 'valuenum': None, 'valueuom': None, 'flag': None, 'storetime': '2156-12-15 11:09:00'}),\n", + " Event(event_type='labevents', timestamp=datetime.datetime(2156, 12, 14, 11, 39), attr_dict={'itemid': '50971', 'label': 'Potassium', 'fluid': 'Blood', 'category': 'Chemistry', 'value': '3.9', 'valuenum': '3.9', 'valueuom': 'mEq/L', 'flag': None, 'storetime': '2156-12-14 18:08:00'}),\n", + " Event(event_type='labevents', timestamp=datetime.datetime(2156, 12, 14, 11, 39), attr_dict={'itemid': '50983', 'label': 'Sodium', 'fluid': 'Blood', 'category': 'Chemistry', 'value': '142', 'valuenum': '142', 'valueuom': 'mEq/L', 'flag': None, 'storetime': '2156-12-14 18:08:00'}),\n", + " Event(event_type='labevents', timestamp=datetime.datetime(2156, 12, 14, 11, 39), attr_dict={'itemid': '50993', 'label': 'Thyroid Stimulating Hormone', 'fluid': 'Blood', 'category': 'Chemistry', 'value': '13', 'valuenum': '13', 'valueuom': 'uIU/mL', 'flag': 'abnormal', 'storetime': '2156-12-14 18:08:00'}),\n", + " Event(event_type='labevents', timestamp=datetime.datetime(2156, 12, 14, 11, 39), attr_dict={'itemid': '50995', 'label': 'Thyroxine (T4), Free', 'fluid': 'Blood', 'category': 'Chemistry', 'value': '0.82', 'valuenum': '0.82', 'valueuom': 'ng/dL', 'flag': 'abnormal', 'storetime': '2156-12-14 18:08:00'}),\n", + " Event(event_type='labevents', timestamp=datetime.datetime(2156, 12, 14, 11, 39), attr_dict={'itemid': '51006', 'label': 'Urea Nitrogen', 'fluid': 'Blood', 'category': 'Chemistry', 'value': '12', 'valuenum': '12', 'valueuom': 'mg/dL', 'flag': None, 'storetime': '2156-12-14 18:08:00'}),\n", + " Event(event_type='labevents', timestamp=datetime.datetime(2156, 12, 14, 11, 39), attr_dict={'itemid': '50902', 'label': 'Chloride', 'fluid': 'Blood', 'category': 'Chemistry', 'value': '105', 'valuenum': '105', 'valueuom': 'mEq/L', 'flag': None, 'storetime': '2156-12-14 18:08:00'}),\n", + " Event(event_type='labevents', timestamp=datetime.datetime(2156, 12, 14, 11, 39), attr_dict={'itemid': '50893', 'label': 'Calcium, Total', 'fluid': 'Blood', 'category': 'Chemistry', 'value': '9.0', 'valuenum': '9', 'valueuom': 'mg/dL', 'flag': None, 'storetime': '2156-12-14 18:08:00'}),\n", + " Event(event_type='labevents', timestamp=datetime.datetime(2156, 12, 14, 11, 39), attr_dict={'itemid': '50882', 'label': 'Bicarbonate', 'fluid': 'Blood', 'category': 'Chemistry', 'value': '23', 'valuenum': '23', 'valueuom': 'mEq/L', 'flag': None, 'storetime': '2156-12-14 18:08:00'}),\n", + " Event(event_type='labevents', timestamp=datetime.datetime(2156, 12, 14, 11, 39), attr_dict={'itemid': '50868', 'label': 'Anion Gap', 'fluid': 'Blood', 'category': 'Chemistry', 'value': '18', 'valuenum': '18', 'valueuom': 'mEq/L', 'flag': None, 'storetime': '2156-12-14 18:08:00'}),\n", + " Event(event_type='labevents', timestamp=datetime.datetime(2156, 12, 14, 11, 39), attr_dict={'itemid': '50852', 'label': '% Hemoglobin A1c', 'fluid': 'Blood', 'category': 'Chemistry', 'value': '___', 'valuenum': '6.3', 'valueuom': '%', 'flag': 'abnormal', 'storetime': '2156-12-14 16:33:00'}),\n", + " Event(event_type='labevents', timestamp=datetime.datetime(2156, 12, 14, 11, 39), attr_dict={'itemid': '51613', 'label': 'eAG', 'fluid': 'Blood', 'category': 'Chemistry', 'value': '___', 'valuenum': '134', 'valueuom': 'mg/dL', 'flag': 'abnormal', 'storetime': '2156-12-14 16:33:00'}),\n", + " Event(event_type='labevents', timestamp=datetime.datetime(2156, 12, 14, 11, 39), attr_dict={'itemid': '51146', 'label': 'Basophils', 'fluid': 'Blood', 'category': 'Hematology', 'value': '0.5', 'valuenum': '0.5', 'valueuom': '%', 'flag': None, 'storetime': '2156-12-14 17:39:00'}),\n", + " Event(event_type='labevents', timestamp=datetime.datetime(2156, 12, 14, 11, 39), attr_dict={'itemid': '51200', 'label': 'Eosinophils', 'fluid': 'Blood', 'category': 'Hematology', 'value': '1.6', 'valuenum': '1.6', 'valueuom': '%', 'flag': None, 'storetime': '2156-12-14 17:39:00'}),\n", + " Event(event_type='labevents', timestamp=datetime.datetime(2156, 12, 14, 11, 39), attr_dict={'itemid': '51221', 'label': 'Hematocrit', 'fluid': 'Blood', 'category': 'Hematology', 'value': '37.7', 'valuenum': '37.7', 'valueuom': '%', 'flag': None, 'storetime': '2156-12-14 17:39:00'}),\n", + " Event(event_type='labevents', timestamp=datetime.datetime(2156, 12, 14, 11, 39), attr_dict={'itemid': '51222', 'label': 'Hemoglobin', 'fluid': 'Blood', 'category': 'Hematology', 'value': '12.5', 'valuenum': '12.5', 'valueuom': 'g/dL', 'flag': None, 'storetime': '2156-12-14 17:39:00'}),\n", + " Event(event_type='labevents', timestamp=datetime.datetime(2156, 12, 14, 11, 39), attr_dict={'itemid': '51244', 'label': 'Lymphocytes', 'fluid': 'Blood', 'category': 'Hematology', 'value': '28.1', 'valuenum': '28.1', 'valueuom': '%', 'flag': None, 'storetime': '2156-12-14 17:39:00'}),\n", + " Event(event_type='labevents', timestamp=datetime.datetime(2156, 12, 14, 11, 39), attr_dict={'itemid': '51248', 'label': 'MCH', 'fluid': 'Blood', 'category': 'Hematology', 'value': '27.6', 'valuenum': '27.6', 'valueuom': 'pg', 'flag': None, 'storetime': '2156-12-14 17:39:00'}),\n", + " Event(event_type='labevents', timestamp=datetime.datetime(2156, 12, 14, 11, 39), attr_dict={'itemid': '51249', 'label': 'MCHC', 'fluid': 'Blood', 'category': 'Hematology', 'value': '33.2', 'valuenum': '33.2', 'valueuom': '%', 'flag': None, 'storetime': '2156-12-14 17:39:00'}),\n", + " Event(event_type='labevents', timestamp=datetime.datetime(2156, 12, 14, 11, 39), attr_dict={'itemid': '51250', 'label': 'MCV', 'fluid': 'Blood', 'category': 'Hematology', 'value': '83', 'valuenum': '83', 'valueuom': 'fL', 'flag': None, 'storetime': '2156-12-14 17:39:00'}),\n", + " Event(event_type='labevents', timestamp=datetime.datetime(2156, 12, 14, 11, 39), attr_dict={'itemid': '51254', 'label': 'Monocytes', 'fluid': 'Blood', 'category': 'Hematology', 'value': '3.2', 'valuenum': '3.2', 'valueuom': '%', 'flag': None, 'storetime': '2156-12-14 17:39:00'}),\n", + " Event(event_type='labevents', timestamp=datetime.datetime(2156, 12, 14, 11, 39), attr_dict={'itemid': '51256', 'label': 'Neutrophils', 'fluid': 'Blood', 'category': 'Hematology', 'value': '65.7', 'valuenum': '65.7', 'valueuom': '%', 'flag': None, 'storetime': '2156-12-14 17:39:00'}),\n", + " Event(event_type='labevents', timestamp=datetime.datetime(2156, 12, 14, 11, 39), attr_dict={'itemid': '51265', 'label': 'Platelet Count', 'fluid': 'Blood', 'category': 'Hematology', 'value': '278', 'valuenum': '278', 'valueuom': 'K/uL', 'flag': None, 'storetime': '2156-12-14 17:39:00'}),\n", + " Event(event_type='labevents', timestamp=datetime.datetime(2156, 12, 14, 11, 39), attr_dict={'itemid': '51277', 'label': 'RDW', 'fluid': 'Blood', 'category': 'Hematology', 'value': '14.7', 'valuenum': '14.7', 'valueuom': '%', 'flag': None, 'storetime': '2156-12-14 17:39:00'}),\n", + " Event(event_type='labevents', timestamp=datetime.datetime(2156, 12, 14, 11, 39), attr_dict={'itemid': '51279', 'label': 'Red Blood Cells', 'fluid': 'Blood', 'category': 'Hematology', 'value': '4.54', 'valuenum': '4.54', 'valueuom': 'm/uL', 'flag': None, 'storetime': '2156-12-14 17:39:00'}),\n", + " Event(event_type='labevents', timestamp=datetime.datetime(2156, 12, 14, 11, 39), attr_dict={'itemid': '51301', 'label': 'White Blood Cells', 'fluid': 'Blood', 'category': 'Hematology', 'value': '7.2', 'valuenum': '7.2', 'valueuom': 'K/uL', 'flag': None, 'storetime': '2156-12-14 17:39:00'}),\n", + " Event(event_type='labevents', timestamp=datetime.datetime(2156, 12, 14, 15, 30), attr_dict={'itemid': '51463', 'label': 'Bacteria', 'fluid': 'Urine', 'category': 'Hematology', 'value': None, 'valuenum': None, 'valueuom': None, 'flag': None, 'storetime': '2156-12-14 16:45:00'}),\n", + " Event(event_type='labevents', timestamp=datetime.datetime(2156, 12, 14, 15, 30), attr_dict={'itemid': '51464', 'label': 'Bilirubin', 'fluid': 'Urine', 'category': 'Hematology', 'value': None, 'valuenum': None, 'valueuom': 'mg/dL', 'flag': None, 'storetime': '2156-12-14 16:45:00'}),\n", + " Event(event_type='labevents', timestamp=datetime.datetime(2156, 12, 14, 15, 30), attr_dict={'itemid': '51466', 'label': 'Blood', 'fluid': 'Urine', 'category': 'Hematology', 'value': None, 'valuenum': None, 'valueuom': None, 'flag': None, 'storetime': '2156-12-14 16:45:00'}),\n", + " Event(event_type='labevents', timestamp=datetime.datetime(2156, 12, 14, 15, 30), attr_dict={'itemid': '51476', 'label': 'Epithelial Cells', 'fluid': 'Urine', 'category': 'Hematology', 'value': '21', 'valuenum': '21', 'valueuom': '#/hpf', 'flag': None, 'storetime': '2156-12-14 16:45:00'}),\n", + " Event(event_type='labevents', timestamp=datetime.datetime(2156, 12, 14, 15, 30), attr_dict={'itemid': '51478', 'label': 'Glucose', 'fluid': 'Urine', 'category': 'Hematology', 'value': None, 'valuenum': None, 'valueuom': 'mg/dL', 'flag': None, 'storetime': '2156-12-14 16:45:00'}),\n", + " Event(event_type='labevents', timestamp=datetime.datetime(2156, 12, 14, 15, 30), attr_dict={'itemid': '51486', 'label': 'Leukocytes', 'fluid': 'Urine', 'category': 'Hematology', 'value': None, 'valuenum': None, 'valueuom': None, 'flag': None, 'storetime': '2156-12-14 16:45:00'}),\n", + " Event(event_type='labevents', timestamp=datetime.datetime(2156, 12, 14, 15, 30), attr_dict={'itemid': '51487', 'label': 'Nitrite', 'fluid': 'Urine', 'category': 'Hematology', 'value': None, 'valuenum': None, 'valueuom': None, 'flag': None, 'storetime': '2156-12-14 16:45:00'}),\n", + " Event(event_type='labevents', timestamp=datetime.datetime(2156, 12, 14, 15, 30), attr_dict={'itemid': '51491', 'label': 'pH', 'fluid': 'Urine', 'category': 'Hematology', 'value': '6.0', 'valuenum': '6', 'valueuom': 'units', 'flag': None, 'storetime': '2156-12-14 16:45:00'}),\n", + " Event(event_type='labevents', timestamp=datetime.datetime(2156, 12, 14, 15, 30), attr_dict={'itemid': '51492', 'label': 'Protein', 'fluid': 'Urine', 'category': 'Hematology', 'value': None, 'valuenum': None, 'valueuom': 'mg/dL', 'flag': None, 'storetime': '2156-12-14 16:45:00'}),\n", + " Event(event_type='labevents', timestamp=datetime.datetime(2156, 12, 14, 15, 30), attr_dict={'itemid': '51493', 'label': 'RBC', 'fluid': 'Urine', 'category': 'Hematology', 'value': '2', 'valuenum': '2', 'valueuom': '#/hpf', 'flag': None, 'storetime': '2156-12-14 16:45:00'}),\n", + " Event(event_type='labevents', timestamp=datetime.datetime(2156, 12, 14, 15, 30), attr_dict={'itemid': '51498', 'label': 'Specific Gravity', 'fluid': 'Urine', 'category': 'Hematology', 'value': '1.018', 'valuenum': '1.018', 'valueuom': ' ', 'flag': None, 'storetime': '2156-12-14 16:45:00'}),\n", + " Event(event_type='labevents', timestamp=datetime.datetime(2156, 12, 14, 15, 30), attr_dict={'itemid': '51506', 'label': 'Urine Appearance', 'fluid': 'Urine', 'category': 'Hematology', 'value': None, 'valuenum': None, 'valueuom': None, 'flag': None, 'storetime': '2156-12-14 16:45:00'}),\n", + " Event(event_type='labevents', timestamp=datetime.datetime(2156, 12, 14, 15, 30), attr_dict={'itemid': '51508', 'label': 'Urine Color', 'fluid': 'Urine', 'category': 'Hematology', 'value': None, 'valuenum': None, 'valueuom': None, 'flag': None, 'storetime': '2156-12-14 16:45:00'}),\n", + " Event(event_type='labevents', timestamp=datetime.datetime(2156, 12, 14, 15, 30), attr_dict={'itemid': '51514', 'label': 'Urobilinogen', 'fluid': 'Urine', 'category': 'Hematology', 'value': None, 'valuenum': None, 'valueuom': 'mg/dL', 'flag': None, 'storetime': '2156-12-14 16:45:00'}),\n", + " Event(event_type='labevents', timestamp=datetime.datetime(2156, 12, 14, 15, 30), attr_dict={'itemid': '51516', 'label': 'WBC', 'fluid': 'Urine', 'category': 'Hematology', 'value': '6', 'valuenum': '6', 'valueuom': '#/hpf', 'flag': 'abnormal', 'storetime': '2156-12-14 16:45:00'}),\n", + " Event(event_type='labevents', timestamp=datetime.datetime(2156, 12, 14, 15, 30), attr_dict={'itemid': '51519', 'label': 'Yeast', 'fluid': 'Urine', 'category': 'Hematology', 'value': 'NONE', 'valuenum': None, 'valueuom': None, 'flag': None, 'storetime': '2156-12-14 16:45:00'}),\n", + " Event(event_type='labevents', timestamp=datetime.datetime(2156, 12, 14, 15, 30), attr_dict={'itemid': '51484', 'label': 'Ketone', 'fluid': 'Urine', 'category': 'Hematology', 'value': None, 'valuenum': None, 'valueuom': 'mg/dL', 'flag': None, 'storetime': '2156-12-14 16:45:00'}),\n", + " Event(event_type='labevents', timestamp=datetime.datetime(2157, 1, 26, 11, 26), attr_dict={'itemid': '50995', 'label': 'Thyroxine (T4), Free', 'fluid': 'Blood', 'category': 'Chemistry', 'value': '1.2', 'valuenum': '1.2', 'valueuom': 'ng/dL', 'flag': None, 'storetime': '2157-01-26 15:57:00'}),\n", + " Event(event_type='labevents', timestamp=datetime.datetime(2157, 1, 26, 11, 26), attr_dict={'itemid': '50993', 'label': 'Thyroid Stimulating Hormone', 'fluid': 'Blood', 'category': 'Chemistry', 'value': '7.6', 'valuenum': '7.6', 'valueuom': 'uIU/mL', 'flag': 'abnormal', 'storetime': '2157-01-26 15:57:00'}),\n", + " Event(event_type='labevents', timestamp=datetime.datetime(2157, 3, 17, 12, 23), attr_dict={'itemid': '50995', 'label': 'Thyroxine (T4), Free', 'fluid': 'Blood', 'category': 'Chemistry', 'value': '1.1', 'valuenum': '1.1', 'valueuom': 'ng/dL', 'flag': None, 'storetime': '2157-03-17 14:54:00'}),\n", + " Event(event_type='labevents', timestamp=datetime.datetime(2157, 3, 17, 12, 23), attr_dict={'itemid': '50993', 'label': 'Thyroid Stimulating Hormone', 'fluid': 'Blood', 'category': 'Chemistry', 'value': '7.0', 'valuenum': '7', 'valueuom': 'uIU/mL', 'flag': 'abnormal', 'storetime': '2157-03-17 14:54:00'}),\n", + " Event(event_type='labevents', timestamp=datetime.datetime(2157, 3, 17, 12, 23), attr_dict={'itemid': '51613', 'label': 'eAG', 'fluid': 'Blood', 'category': 'Chemistry', 'value': '___', 'valuenum': '120', 'valueuom': 'mg/dL', 'flag': None, 'storetime': '2157-03-17 14:02:00'}),\n", + " Event(event_type='labevents', timestamp=datetime.datetime(2157, 3, 17, 12, 23), attr_dict={'itemid': '50852', 'label': '% Hemoglobin A1c', 'fluid': 'Blood', 'category': 'Chemistry', 'value': '___', 'valuenum': '5.8', 'valueuom': '%', 'flag': None, 'storetime': '2157-03-17 14:02:00'}),\n", + " Event(event_type='labevents', timestamp=datetime.datetime(2157, 6, 7, 14, 24), attr_dict={'itemid': '50912', 'label': 'Creatinine', 'fluid': 'Blood', 'category': 'Chemistry', 'value': '1.2', 'valuenum': '1.2', 'valueuom': 'mg/dL', 'flag': 'abnormal', 'storetime': '2157-06-07 18:20:00'}),\n", + " Event(event_type='labevents', timestamp=datetime.datetime(2157, 6, 7, 14, 24), attr_dict={'itemid': '50920', 'label': 'Estimated GFR (MDRD equation)', 'fluid': 'Blood', 'category': 'Chemistry', 'value': None, 'valuenum': None, 'valueuom': None, 'flag': None, 'storetime': '2157-06-07 18:20:00'}),\n", + " Event(event_type='labevents', timestamp=datetime.datetime(2157, 6, 7, 14, 24), attr_dict={'itemid': '51006', 'label': 'Urea Nitrogen', 'fluid': 'Blood', 'category': 'Chemistry', 'value': '12', 'valuenum': '12', 'valueuom': 'mg/dL', 'flag': None, 'storetime': '2157-06-07 18:20:00'}),\n", + " Event(event_type='labevents', timestamp=datetime.datetime(2157, 6, 13, 12, 10), attr_dict={'itemid': '50993', 'label': 'Thyroid Stimulating Hormone', 'fluid': 'Blood', 'category': 'Chemistry', 'value': '14', 'valuenum': '14', 'valueuom': 'uIU/mL', 'flag': 'abnormal', 'storetime': '2157-06-13 19:42:00'}),\n", + " Event(event_type='labevents', timestamp=datetime.datetime(2157, 6, 13, 12, 10), attr_dict={'itemid': '50995', 'label': 'Thyroxine (T4), Free', 'fluid': 'Blood', 'category': 'Chemistry', 'value': '1.4', 'valuenum': '1.4', 'valueuom': 'ng/dL', 'flag': None, 'storetime': '2157-06-13 19:42:00'}),\n", + " Event(event_type='labevents', timestamp=datetime.datetime(2157, 7, 13, 11, 13), attr_dict={'itemid': '50902', 'label': 'Chloride', 'fluid': 'Blood', 'category': 'Chemistry', 'value': '105', 'valuenum': '105', 'valueuom': 'mEq/L', 'flag': None, 'storetime': '2157-07-13 16:57:00'}),\n", + " Event(event_type='labevents', timestamp=datetime.datetime(2157, 7, 13, 11, 13), attr_dict={'itemid': '50912', 'label': 'Creatinine', 'fluid': 'Blood', 'category': 'Chemistry', 'value': '1.1', 'valuenum': '1.1', 'valueuom': 'mg/dL', 'flag': None, 'storetime': '2157-07-13 16:57:00'}),\n", + " Event(event_type='labevents', timestamp=datetime.datetime(2157, 7, 13, 11, 13), attr_dict={'itemid': '50920', 'label': 'Estimated GFR (MDRD equation)', 'fluid': 'Blood', 'category': 'Chemistry', 'value': None, 'valuenum': None, 'valueuom': None, 'flag': None, 'storetime': '2157-07-13 16:57:00'}),\n", + " Event(event_type='labevents', timestamp=datetime.datetime(2157, 7, 13, 11, 13), attr_dict={'itemid': '50971', 'label': 'Potassium', 'fluid': 'Blood', 'category': 'Chemistry', 'value': '4.3', 'valuenum': '4.3', 'valueuom': 'mEq/L', 'flag': None, 'storetime': '2157-07-13 16:57:00'}),\n", + " Event(event_type='labevents', timestamp=datetime.datetime(2157, 7, 13, 11, 13), attr_dict={'itemid': '50983', 'label': 'Sodium', 'fluid': 'Blood', 'category': 'Chemistry', 'value': '142', 'valuenum': '142', 'valueuom': 'mEq/L', 'flag': None, 'storetime': '2157-07-13 16:57:00'}),\n", + " Event(event_type='labevents', timestamp=datetime.datetime(2157, 7, 13, 11, 13), attr_dict={'itemid': '50993', 'label': 'Thyroid Stimulating Hormone', 'fluid': 'Blood', 'category': 'Chemistry', 'value': '2.9', 'valuenum': '2.9', 'valueuom': 'uIU/mL', 'flag': None, 'storetime': '2157-07-13 16:57:00'}),\n", + " Event(event_type='labevents', timestamp=datetime.datetime(2157, 7, 13, 11, 13), attr_dict={'itemid': '51006', 'label': 'Urea Nitrogen', 'fluid': 'Blood', 'category': 'Chemistry', 'value': '13', 'valuenum': '13', 'valueuom': 'mg/dL', 'flag': None, 'storetime': '2157-07-13 16:57:00'}),\n", + " Event(event_type='labevents', timestamp=datetime.datetime(2157, 9, 13, 7, 55), attr_dict={'itemid': '50887', 'label': 'Blue Top Hold', 'fluid': 'Blood', 'category': 'Chemistry', 'value': 'HOLD. DISCARD GREATER THAN 24 HRS OLD.', 'valuenum': None, 'valueuom': None, 'flag': None, 'storetime': None}),\n", + " Event(event_type='labevents', timestamp=datetime.datetime(2157, 9, 13, 7, 55), attr_dict={'itemid': '51006', 'label': 'Urea Nitrogen', 'fluid': 'Blood', 'category': 'Chemistry', 'value': '10', 'valuenum': '10', 'valueuom': 'mg/dL', 'flag': None, 'storetime': '2157-09-13 10:20:00'}),\n", + " Event(event_type='labevents', timestamp=datetime.datetime(2157, 9, 13, 7, 55), attr_dict={'itemid': '50954', 'label': 'Lactate Dehydrogenase (LD)', 'fluid': 'Blood', 'category': 'Chemistry', 'value': '195', 'valuenum': '195', 'valueuom': 'IU/L', 'flag': None, 'storetime': '2157-09-13 10:20:00'}),\n", + " Event(event_type='labevents', timestamp=datetime.datetime(2157, 9, 13, 7, 55), attr_dict={'itemid': '50920', 'label': 'Estimated GFR (MDRD equation)', 'fluid': 'Blood', 'category': 'Chemistry', 'value': None, 'valuenum': None, 'valueuom': None, 'flag': None, 'storetime': '2157-09-13 10:20:00'}),\n", + " Event(event_type='labevents', timestamp=datetime.datetime(2157, 9, 13, 7, 55), attr_dict={'itemid': '51221', 'label': 'Hematocrit', 'fluid': 'Blood', 'category': 'Hematology', 'value': '33.6', 'valuenum': '33.6', 'valueuom': '%', 'flag': 'abnormal', 'storetime': '2157-09-13 09:45:00'}),\n", + " Event(event_type='labevents', timestamp=datetime.datetime(2157, 9, 13, 7, 55), attr_dict={'itemid': '51222', 'label': 'Hemoglobin', 'fluid': 'Blood', 'category': 'Hematology', 'value': '10.9', 'valuenum': '10.9', 'valueuom': 'g/dL', 'flag': 'abnormal', 'storetime': '2157-09-13 09:45:00'}),\n", + " Event(event_type='labevents', timestamp=datetime.datetime(2157, 9, 13, 7, 55), attr_dict={'itemid': '51248', 'label': 'MCH', 'fluid': 'Blood', 'category': 'Hematology', 'value': '27.0', 'valuenum': '27', 'valueuom': 'pg', 'flag': None, 'storetime': '2157-09-13 09:45:00'}),\n", + " Event(event_type='labevents', timestamp=datetime.datetime(2157, 9, 13, 7, 55), attr_dict={'itemid': '51249', 'label': 'MCHC', 'fluid': 'Blood', 'category': 'Hematology', 'value': '32.4', 'valuenum': '32.4', 'valueuom': 'g/dL', 'flag': None, 'storetime': '2157-09-13 09:45:00'}),\n", + " Event(event_type='labevents', timestamp=datetime.datetime(2157, 9, 13, 7, 55), attr_dict={'itemid': '51250', 'label': 'MCV', 'fluid': 'Blood', 'category': 'Hematology', 'value': '83', 'valuenum': '83', 'valueuom': 'fL', 'flag': None, 'storetime': '2157-09-13 09:45:00'}),\n", + " Event(event_type='labevents', timestamp=datetime.datetime(2157, 9, 13, 7, 55), attr_dict={'itemid': '51265', 'label': 'Platelet Count', 'fluid': 'Blood', 'category': 'Hematology', 'value': '266', 'valuenum': '266', 'valueuom': 'K/uL', 'flag': None, 'storetime': '2157-09-13 09:45:00'}),\n", + " Event(event_type='labevents', timestamp=datetime.datetime(2157, 9, 13, 7, 55), attr_dict={'itemid': '51277', 'label': 'RDW', 'fluid': 'Blood', 'category': 'Hematology', 'value': '14.8', 'valuenum': '14.8', 'valueuom': '%', 'flag': None, 'storetime': '2157-09-13 09:45:00'}),\n", + " Event(event_type='labevents', timestamp=datetime.datetime(2157, 9, 13, 7, 55), attr_dict={'itemid': '51279', 'label': 'Red Blood Cells', 'fluid': 'Blood', 'category': 'Hematology', 'value': '4.04', 'valuenum': '4.04', 'valueuom': 'm/uL', 'flag': None, 'storetime': '2157-09-13 09:45:00'}),\n", + " Event(event_type='labevents', timestamp=datetime.datetime(2157, 9, 13, 7, 55), attr_dict={'itemid': '51301', 'label': 'White Blood Cells', 'fluid': 'Blood', 'category': 'Hematology', 'value': '7.0', 'valuenum': '7', 'valueuom': 'K/uL', 'flag': None, 'storetime': '2157-09-13 09:45:00'}),\n", + " Event(event_type='labevents', timestamp=datetime.datetime(2157, 9, 13, 7, 55), attr_dict={'itemid': '52172', 'label': 'RDW-SD', 'fluid': 'Blood', 'category': 'Hematology', 'value': '45.3', 'valuenum': '45.3', 'valueuom': 'fL', 'flag': None, 'storetime': '2157-09-13 09:45:00'}),\n", + " Event(event_type='labevents', timestamp=datetime.datetime(2157, 9, 13, 7, 55), attr_dict={'itemid': '50932', 'label': 'Gray Top Hold (plasma)', 'fluid': 'Blood', 'category': 'Chemistry', 'value': 'HOLD. DISCARD AFTER THREE DAYS .', 'valuenum': None, 'valueuom': None, 'flag': None, 'storetime': None}),\n", + " Event(event_type='labevents', timestamp=datetime.datetime(2157, 9, 13, 7, 55), attr_dict={'itemid': '50861', 'label': 'Alanine Aminotransferase (ALT)', 'fluid': 'Blood', 'category': 'Chemistry', 'value': '13', 'valuenum': '13', 'valueuom': 'IU/L', 'flag': None, 'storetime': '2157-09-13 10:20:00'}),\n", + " Event(event_type='labevents', timestamp=datetime.datetime(2157, 9, 13, 7, 55), attr_dict={'itemid': '50885', 'label': 'Bilirubin, Total', 'fluid': 'Blood', 'category': 'Chemistry', 'value': '0.2', 'valuenum': '0.2', 'valueuom': 'mg/dL', 'flag': None, 'storetime': '2157-09-13 10:20:00'}),\n", + " Event(event_type='labevents', timestamp=datetime.datetime(2157, 9, 13, 7, 55), attr_dict={'itemid': '50912', 'label': 'Creatinine', 'fluid': 'Blood', 'category': 'Chemistry', 'value': '1.0', 'valuenum': '1', 'valueuom': 'mg/dL', 'flag': None, 'storetime': '2157-09-13 10:20:00'}),\n", + " Event(event_type='labevents', timestamp=datetime.datetime(2157, 9, 26, 10, 0), attr_dict={'itemid': '51133', 'label': 'Absolute Lymphocyte Count', 'fluid': 'Blood', 'category': 'Hematology', 'value': '2.71', 'valuenum': '2.71', 'valueuom': 'K/uL', 'flag': None, 'storetime': '2157-09-26 13:49:00'}),\n", + " Event(event_type='labevents', timestamp=datetime.datetime(2157, 9, 26, 10, 0), attr_dict={'itemid': '51146', 'label': 'Basophils', 'fluid': 'Blood', 'category': 'Hematology', 'value': '0.5', 'valuenum': '0.5', 'valueuom': '%', 'flag': None, 'storetime': '2157-09-26 13:49:00'}),\n", + " Event(event_type='labevents', timestamp=datetime.datetime(2157, 9, 26, 10, 0), attr_dict={'itemid': '51200', 'label': 'Eosinophils', 'fluid': 'Blood', 'category': 'Hematology', 'value': '2.6', 'valuenum': '2.6', 'valueuom': '%', 'flag': None, 'storetime': '2157-09-26 13:49:00'}),\n", + " Event(event_type='labevents', timestamp=datetime.datetime(2157, 9, 26, 10, 0), attr_dict={'itemid': '51221', 'label': 'Hematocrit', 'fluid': 'Blood', 'category': 'Hematology', 'value': '33.2', 'valuenum': '33.2', 'valueuom': '%', 'flag': 'abnormal', 'storetime': '2157-09-26 13:49:00'}),\n", + " Event(event_type='labevents', timestamp=datetime.datetime(2157, 9, 26, 10, 0), attr_dict={'itemid': '51222', 'label': 'Hemoglobin', 'fluid': 'Blood', 'category': 'Hematology', 'value': '10.9', 'valuenum': '10.9', 'valueuom': 'g/dL', 'flag': 'abnormal', 'storetime': '2157-09-26 13:49:00'}),\n", + " Event(event_type='labevents', timestamp=datetime.datetime(2157, 9, 26, 10, 0), attr_dict={'itemid': '51244', 'label': 'Lymphocytes', 'fluid': 'Blood', 'category': 'Hematology', 'value': '23.1', 'valuenum': '23.1', 'valueuom': '%', 'flag': None, 'storetime': '2157-09-26 13:49:00'}),\n", + " Event(event_type='labevents', timestamp=datetime.datetime(2157, 9, 26, 10, 0), attr_dict={'itemid': '51248', 'label': 'MCH', 'fluid': 'Blood', 'category': 'Hematology', 'value': '27.0', 'valuenum': '27', 'valueuom': 'pg', 'flag': None, 'storetime': '2157-09-26 13:49:00'}),\n", + " Event(event_type='labevents', timestamp=datetime.datetime(2157, 9, 26, 10, 0), attr_dict={'itemid': '51249', 'label': 'MCHC', 'fluid': 'Blood', 'category': 'Hematology', 'value': '32.8', 'valuenum': '32.8', 'valueuom': 'g/dL', 'flag': None, 'storetime': '2157-09-26 13:49:00'}),\n", + " Event(event_type='labevents', timestamp=datetime.datetime(2157, 9, 26, 10, 0), attr_dict={'itemid': '51250', 'label': 'MCV', 'fluid': 'Blood', 'category': 'Hematology', 'value': '82', 'valuenum': '82', 'valueuom': 'fL', 'flag': None, 'storetime': '2157-09-26 13:49:00'}),\n", + " Event(event_type='labevents', timestamp=datetime.datetime(2157, 9, 26, 10, 0), attr_dict={'itemid': '51254', 'label': 'Monocytes', 'fluid': 'Blood', 'category': 'Hematology', 'value': '4.3', 'valuenum': '4.3', 'valueuom': '%', 'flag': 'abnormal', 'storetime': '2157-09-26 13:49:00'}),\n", + " Event(event_type='labevents', timestamp=datetime.datetime(2157, 9, 26, 10, 0), attr_dict={'itemid': '51256', 'label': 'Neutrophils', 'fluid': 'Blood', 'category': 'Hematology', 'value': '69.0', 'valuenum': '69', 'valueuom': '%', 'flag': None, 'storetime': '2157-09-26 13:49:00'}),\n", + " Event(event_type='labevents', timestamp=datetime.datetime(2157, 9, 26, 10, 0), attr_dict={'itemid': '51265', 'label': 'Platelet Count', 'fluid': 'Blood', 'category': 'Hematology', 'value': '360', 'valuenum': '360', 'valueuom': 'K/uL', 'flag': None, 'storetime': '2157-09-26 13:49:00'}),\n", + " Event(event_type='labevents', timestamp=datetime.datetime(2157, 9, 26, 10, 0), attr_dict={'itemid': '51282', 'label': 'Reticulocyte Count, Absolute', 'fluid': 'Blood', 'category': 'Hematology', 'value': '0.04', 'valuenum': '0.04', 'valueuom': 'm/uL', 'flag': None, 'storetime': '2157-09-26 13:49:00'}),\n", + " Event(event_type='labevents', timestamp=datetime.datetime(2157, 9, 26, 10, 0), attr_dict={'itemid': '51283', 'label': 'Reticulocyte Count, Automated', 'fluid': 'Blood', 'category': 'Hematology', 'value': '1.1', 'valuenum': '1.1', 'valueuom': '%', 'flag': None, 'storetime': '2157-09-26 13:49:00'}),\n", + " Event(event_type='labevents', timestamp=datetime.datetime(2157, 9, 26, 10, 0), attr_dict={'itemid': '51301', 'label': 'White Blood Cells', 'fluid': 'Blood', 'category': 'Hematology', 'value': '11.7', 'valuenum': '11.7', 'valueuom': 'K/uL', 'flag': 'abnormal', 'storetime': '2157-09-26 13:49:00'}),\n", + " Event(event_type='labevents', timestamp=datetime.datetime(2157, 9, 26, 10, 0), attr_dict={'itemid': '52069', 'label': 'Absolute Basophil Count', 'fluid': 'Blood', 'category': 'Hematology', 'value': '0.06', 'valuenum': '0.06', 'valueuom': 'K/uL', 'flag': None, 'storetime': '2157-09-26 13:49:00'}),\n", + " Event(event_type='labevents', timestamp=datetime.datetime(2157, 9, 26, 10, 0), attr_dict={'itemid': '52073', 'label': 'Absolute Eosinophil Count', 'fluid': 'Blood', 'category': 'Hematology', 'value': '0.31', 'valuenum': '0.31', 'valueuom': 'K/uL', 'flag': None, 'storetime': '2157-09-26 13:49:00'}),\n", + " Event(event_type='labevents', timestamp=datetime.datetime(2157, 9, 26, 10, 0), attr_dict={'itemid': '52074', 'label': 'Absolute Monocyte Count', 'fluid': 'Blood', 'category': 'Hematology', 'value': '0.51', 'valuenum': '0.51', 'valueuom': 'K/uL', 'flag': None, 'storetime': '2157-09-26 13:49:00'}),\n", + " Event(event_type='labevents', timestamp=datetime.datetime(2157, 9, 26, 10, 0), attr_dict={'itemid': '52075', 'label': 'Absolute Neutrophil Count', 'fluid': 'Blood', 'category': 'Hematology', 'value': '8.08', 'valuenum': '8.08', 'valueuom': 'K/uL', 'flag': 'abnormal', 'storetime': '2157-09-26 13:49:00'}),\n", + " Event(event_type='labevents', timestamp=datetime.datetime(2157, 9, 26, 10, 0), attr_dict={'itemid': '52135', 'label': 'Immature Granulocytes', 'fluid': 'Blood', 'category': 'Hematology', 'value': '0.5', 'valuenum': '0.5', 'valueuom': '%', 'flag': None, 'storetime': '2157-09-26 13:49:00'}),\n", + " Event(event_type='labevents', timestamp=datetime.datetime(2157, 9, 26, 10, 0), attr_dict={'itemid': '52172', 'label': 'RDW-SD', 'fluid': 'Blood', 'category': 'Hematology', 'value': '43.2', 'valuenum': '43.2', 'valueuom': 'fL', 'flag': None, 'storetime': '2157-09-26 13:49:00'}),\n", + " Event(event_type='labevents', timestamp=datetime.datetime(2157, 9, 26, 10, 0), attr_dict={'itemid': '50902', 'label': 'Chloride', 'fluid': 'Blood', 'category': 'Chemistry', 'value': '103', 'valuenum': '103', 'valueuom': 'mEq/L', 'flag': None, 'storetime': '2157-09-26 14:06:00'}),\n", + " Event(event_type='labevents', timestamp=datetime.datetime(2157, 9, 26, 10, 0), attr_dict={'itemid': '50912', 'label': 'Creatinine', 'fluid': 'Blood', 'category': 'Chemistry', 'value': '1.1', 'valuenum': '1.1', 'valueuom': 'mg/dL', 'flag': None, 'storetime': '2157-09-26 14:06:00'}),\n", + " Event(event_type='labevents', timestamp=datetime.datetime(2157, 9, 26, 10, 0), attr_dict={'itemid': '50920', 'label': 'Estimated GFR (MDRD equation)', 'fluid': 'Blood', 'category': 'Chemistry', 'value': None, 'valuenum': None, 'valueuom': None, 'flag': None, 'storetime': '2157-09-26 14:06:00'}),\n", + " Event(event_type='labevents', timestamp=datetime.datetime(2157, 9, 26, 10, 0), attr_dict={'itemid': '51279', 'label': 'Red Blood Cells', 'fluid': 'Blood', 'category': 'Hematology', 'value': '4.03', 'valuenum': '4.03', 'valueuom': 'm/uL', 'flag': None, 'storetime': '2157-09-26 13:49:00'}),\n", + " Event(event_type='labevents', timestamp=datetime.datetime(2157, 9, 26, 10, 0), attr_dict={'itemid': '50924', 'label': 'Ferritin', 'fluid': 'Blood', 'category': 'Chemistry', 'value': '90', 'valuenum': '90', 'valueuom': 'ng/mL', 'flag': None, 'storetime': '2157-09-26 14:06:00'}),\n", + " Event(event_type='labevents', timestamp=datetime.datetime(2157, 9, 26, 10, 0), attr_dict={'itemid': '50925', 'label': 'Folate', 'fluid': 'Blood', 'category': 'Chemistry', 'value': '8.5', 'valuenum': '8.5', 'valueuom': 'ng/mL', 'flag': None, 'storetime': '2157-09-26 14:06:00'}),\n", + " Event(event_type='labevents', timestamp=datetime.datetime(2157, 9, 26, 10, 0), attr_dict={'itemid': '50953', 'label': 'Iron Binding Capacity, Total', 'fluid': 'Blood', 'category': 'Chemistry', 'value': '269', 'valuenum': '269', 'valueuom': 'ug/dL', 'flag': None, 'storetime': '2157-09-26 14:06:00'}),\n", + " Event(event_type='labevents', timestamp=datetime.datetime(2157, 9, 26, 10, 0), attr_dict={'itemid': '50971', 'label': 'Potassium', 'fluid': 'Blood', 'category': 'Chemistry', 'value': '3.5', 'valuenum': '3.5', 'valueuom': 'mEq/L', 'flag': None, 'storetime': '2157-09-26 14:06:00'}),\n", + " Event(event_type='labevents', timestamp=datetime.datetime(2157, 9, 26, 10, 0), attr_dict={'itemid': '50983', 'label': 'Sodium', 'fluid': 'Blood', 'category': 'Chemistry', 'value': '140', 'valuenum': '140', 'valueuom': 'mEq/L', 'flag': None, 'storetime': '2157-09-26 14:06:00'}),\n", + " Event(event_type='labevents', timestamp=datetime.datetime(2157, 9, 26, 10, 0), attr_dict={'itemid': '50993', 'label': 'Thyroid Stimulating Hormone', 'fluid': 'Blood', 'category': 'Chemistry', 'value': '4.6', 'valuenum': '4.6', 'valueuom': 'uIU/mL', 'flag': 'abnormal', 'storetime': '2157-09-26 14:06:00'}),\n", + " Event(event_type='labevents', timestamp=datetime.datetime(2157, 9, 26, 10, 0), attr_dict={'itemid': '50998', 'label': 'Transferrin', 'fluid': 'Blood', 'category': 'Chemistry', 'value': '207', 'valuenum': '207', 'valueuom': 'mg/dL', 'flag': None, 'storetime': '2157-09-26 14:06:00'}),\n", + " Event(event_type='labevents', timestamp=datetime.datetime(2157, 9, 26, 10, 0), attr_dict={'itemid': '51006', 'label': 'Urea Nitrogen', 'fluid': 'Blood', 'category': 'Chemistry', 'value': '9', 'valuenum': '9', 'valueuom': 'mg/dL', 'flag': None, 'storetime': '2157-09-26 14:06:00'}),\n", + " Event(event_type='labevents', timestamp=datetime.datetime(2157, 9, 26, 10, 0), attr_dict={'itemid': '51010', 'label': 'Vitamin B12', 'fluid': 'Blood', 'category': 'Chemistry', 'value': '387', 'valuenum': '387', 'valueuom': 'pg/mL', 'flag': None, 'storetime': '2157-09-26 14:06:00'}),\n", + " Event(event_type='labevents', timestamp=datetime.datetime(2157, 9, 26, 10, 0), attr_dict={'itemid': '51463', 'label': 'Bacteria', 'fluid': 'Urine', 'category': 'Hematology', 'value': None, 'valuenum': None, 'valueuom': None, 'flag': None, 'storetime': '2157-09-26 13:14:00'}),\n", + " Event(event_type='labevents', timestamp=datetime.datetime(2157, 9, 26, 10, 0), attr_dict={'itemid': '51464', 'label': 'Bilirubin', 'fluid': 'Urine', 'category': 'Hematology', 'value': None, 'valuenum': None, 'valueuom': 'mg/dL', 'flag': None, 'storetime': '2157-09-26 13:14:00'}),\n", + " Event(event_type='labevents', timestamp=datetime.datetime(2157, 9, 26, 10, 0), attr_dict={'itemid': '51466', 'label': 'Blood', 'fluid': 'Urine', 'category': 'Hematology', 'value': None, 'valuenum': None, 'valueuom': None, 'flag': None, 'storetime': '2157-09-26 13:14:00'}),\n", + " Event(event_type='labevents', timestamp=datetime.datetime(2157, 9, 26, 10, 0), attr_dict={'itemid': '51476', 'label': 'Epithelial Cells', 'fluid': 'Urine', 'category': 'Hematology', 'value': '2', 'valuenum': '2', 'valueuom': '#/hpf', 'flag': None, 'storetime': '2157-09-26 13:14:00'}),\n", + " Event(event_type='labevents', timestamp=datetime.datetime(2157, 9, 26, 10, 0), attr_dict={'itemid': '51478', 'label': 'Glucose', 'fluid': 'Urine', 'category': 'Hematology', 'value': None, 'valuenum': None, 'valueuom': 'mg/dL', 'flag': None, 'storetime': '2157-09-26 13:14:00'}),\n", + " Event(event_type='labevents', timestamp=datetime.datetime(2157, 9, 26, 10, 0), attr_dict={'itemid': '51484', 'label': 'Ketone', 'fluid': 'Urine', 'category': 'Hematology', 'value': None, 'valuenum': None, 'valueuom': 'mg/dL', 'flag': None, 'storetime': '2157-09-26 13:14:00'}),\n", + " Event(event_type='labevents', timestamp=datetime.datetime(2157, 9, 26, 10, 0), attr_dict={'itemid': '51486', 'label': 'Leukocytes', 'fluid': 'Urine', 'category': 'Hematology', 'value': None, 'valuenum': None, 'valueuom': None, 'flag': None, 'storetime': '2157-09-26 13:14:00'}),\n", + " Event(event_type='labevents', timestamp=datetime.datetime(2157, 9, 26, 10, 0), attr_dict={'itemid': '51487', 'label': 'Nitrite', 'fluid': 'Urine', 'category': 'Hematology', 'value': None, 'valuenum': None, 'valueuom': None, 'flag': None, 'storetime': '2157-09-26 13:14:00'}),\n", + " Event(event_type='labevents', timestamp=datetime.datetime(2157, 9, 26, 10, 0), attr_dict={'itemid': '51491', 'label': 'pH', 'fluid': 'Urine', 'category': 'Hematology', 'value': '6.0', 'valuenum': '6', 'valueuom': 'units', 'flag': None, 'storetime': '2157-09-26 13:14:00'}),\n", + " Event(event_type='labevents', timestamp=datetime.datetime(2157, 9, 26, 10, 0), attr_dict={'itemid': '51492', 'label': 'Protein', 'fluid': 'Urine', 'category': 'Hematology', 'value': None, 'valuenum': None, 'valueuom': 'mg/dL', 'flag': None, 'storetime': '2157-09-26 13:14:00'}),\n", + " Event(event_type='labevents', timestamp=datetime.datetime(2157, 9, 26, 10, 0), attr_dict={'itemid': '51493', 'label': 'RBC', 'fluid': 'Urine', 'category': 'Hematology', 'value': None, 'valuenum': None, 'valueuom': '#/hpf', 'flag': None, 'storetime': '2157-09-26 13:14:00'}),\n", + " Event(event_type='labevents', timestamp=datetime.datetime(2157, 9, 26, 10, 0), attr_dict={'itemid': '51498', 'label': 'Specific Gravity', 'fluid': 'Urine', 'category': 'Hematology', 'value': '1.021', 'valuenum': '1.021', 'valueuom': ' ', 'flag': None, 'storetime': '2157-09-26 13:14:00'}),\n", + " Event(event_type='labevents', timestamp=datetime.datetime(2157, 9, 26, 10, 0), attr_dict={'itemid': '51506', 'label': 'Urine Appearance', 'fluid': 'Urine', 'category': 'Hematology', 'value': None, 'valuenum': None, 'valueuom': None, 'flag': None, 'storetime': '2157-09-26 13:14:00'}),\n", + " Event(event_type='labevents', timestamp=datetime.datetime(2157, 9, 26, 10, 0), attr_dict={'itemid': '51508', 'label': 'Urine Color', 'fluid': 'Urine', 'category': 'Hematology', 'value': None, 'valuenum': None, 'valueuom': None, 'flag': None, 'storetime': '2157-09-26 13:14:00'}),\n", + " Event(event_type='labevents', timestamp=datetime.datetime(2157, 9, 26, 10, 0), attr_dict={'itemid': '51514', 'label': 'Urobilinogen', 'fluid': 'Urine', 'category': 'Hematology', 'value': None, 'valuenum': None, 'valueuom': 'mg/dL', 'flag': None, 'storetime': '2157-09-26 13:14:00'}),\n", + " Event(event_type='labevents', timestamp=datetime.datetime(2157, 9, 26, 10, 0), attr_dict={'itemid': '51516', 'label': 'WBC', 'fluid': 'Urine', 'category': 'Hematology', 'value': '1', 'valuenum': '1', 'valueuom': '#/hpf', 'flag': None, 'storetime': '2157-09-26 13:14:00'}),\n", + " Event(event_type='labevents', timestamp=datetime.datetime(2157, 9, 26, 10, 0), attr_dict={'itemid': '51519', 'label': 'Yeast', 'fluid': 'Urine', 'category': 'Hematology', 'value': 'NONE', 'valuenum': None, 'valueuom': None, 'flag': None, 'storetime': '2157-09-26 13:14:00'}),\n", + " Event(event_type='labevents', timestamp=datetime.datetime(2157, 9, 26, 10, 0), attr_dict={'itemid': '50919', 'label': 'EDTA Hold', 'fluid': 'Blood', 'category': 'Chemistry', 'value': None, 'valuenum': None, 'valueuom': None, 'flag': None, 'storetime': None}),\n", + " Event(event_type='labevents', timestamp=datetime.datetime(2157, 9, 26, 10, 0), attr_dict={'itemid': '50952', 'label': 'Iron', 'fluid': 'Blood', 'category': 'Chemistry', 'value': '18', 'valuenum': '18', 'valueuom': 'ug/dL', 'flag': 'abnormal', 'storetime': '2157-09-26 14:06:00'}),\n", + " Event(event_type='labevents', timestamp=datetime.datetime(2157, 9, 26, 10, 0), attr_dict={'itemid': '51277', 'label': 'RDW', 'fluid': 'Blood', 'category': 'Hematology', 'value': '14.3', 'valuenum': '14.3', 'valueuom': '%', 'flag': None, 'storetime': '2157-09-26 13:49:00'}),\n", + " Event(event_type='admissions', timestamp=datetime.datetime(2157, 9, 29, 9, 15), attr_dict={'hadm_id': '28766070', 'admission_type': 'DIRECT OBSERVATION', 'admission_location': 'PHYSICIAN REFERRAL', 'insurance': 'Medicaid', 'language': 'ENGLISH', 'marital_status': 'SINGLE', 'race': 'BLACK/AFRICAN AMERICAN', 'discharge_location': None, 'dischtime': '2157-10-01 13:10:00', 'hospital_expire_flag': '0'}),\n", + " Event(event_type='prescriptions', timestamp=datetime.datetime(2157, 9, 29, 20, 0), attr_dict={'hadm_id': '28766070', 'drug': 'Gabapentin', 'ndc': '63739037510', 'prod_strength': '300mg Capsule', 'dose_val_rx': '600', 'dose_unit_rx': 'mg', 'route': 'PO/NG', 'stoptime': '2157-10-01 17:00:00'}),\n", + " Event(event_type='prescriptions', timestamp=datetime.datetime(2157, 9, 29, 20, 0), attr_dict={'hadm_id': '28766070', 'drug': 'Docusate Sodium', 'ndc': '00904224461', 'prod_strength': '100mg Capsule', 'dose_val_rx': '100', 'dose_unit_rx': 'mg', 'route': 'PO/NG', 'stoptime': '2157-10-01 17:00:00'}),\n", + " Event(event_type='prescriptions', timestamp=datetime.datetime(2157, 9, 29, 21, 0), attr_dict={'hadm_id': '28766070', 'drug': 'Sodium Chloride 0.9% Flush', 'ndc': '0', 'prod_strength': '10 mL Syringe', 'dose_val_rx': '3', 'dose_unit_rx': 'mL', 'route': 'IV', 'stoptime': '2157-10-01 17:00:00'}),\n", + " Event(event_type='prescriptions', timestamp=datetime.datetime(2157, 9, 29, 21, 0), attr_dict={'hadm_id': '28766070', 'drug': 'Senna', 'ndc': '00904516561', 'prod_strength': '8.6 mg Tablet', 'dose_val_rx': '8.6', 'dose_unit_rx': 'mg', 'route': 'PO/NG', 'stoptime': '2157-10-01 17:00:00'}),\n", + " Event(event_type='prescriptions', timestamp=datetime.datetime(2157, 9, 29, 21, 0), attr_dict={'hadm_id': '28766070', 'drug': 'Bisacodyl', 'ndc': '00536338101', 'prod_strength': '5 mg Tab', 'dose_val_rx': '10', 'dose_unit_rx': 'mg', 'route': 'PO', 'stoptime': '2157-10-01 17:00:00'}),\n", + " Event(event_type='prescriptions', timestamp=datetime.datetime(2157, 9, 29, 21, 0), attr_dict={'hadm_id': '28766070', 'drug': 'Morphine Sulfate', 'ndc': '00409189001', 'prod_strength': '2 mg Syringe', 'dose_val_rx': '1-2', 'dose_unit_rx': 'mg', 'route': 'IV', 'stoptime': '2157-10-01 17:00:00'}),\n", + " Event(event_type='prescriptions', timestamp=datetime.datetime(2157, 9, 29, 21, 0), attr_dict={'hadm_id': '28766070', 'drug': 'Acetaminophen', 'ndc': '51079000220', 'prod_strength': '325mg Tablet', 'dose_val_rx': '325-650', 'dose_unit_rx': 'mg', 'route': 'PO/NG', 'stoptime': '2157-10-01 17:00:00'}),\n", + " Event(event_type='prescriptions', timestamp=datetime.datetime(2157, 9, 29, 21, 0), attr_dict={'hadm_id': '28766070', 'drug': 'Bisacodyl', 'ndc': '00574705050', 'prod_strength': '10mg Suppository', 'dose_val_rx': '10', 'dose_unit_rx': 'mg', 'route': 'PR', 'stoptime': '2157-10-01 17:00:00'}),\n", + " Event(event_type='prescriptions', timestamp=datetime.datetime(2157, 9, 29, 21, 0), attr_dict={'hadm_id': '28766070', 'drug': 'OxycoDONE (Immediate Release) ', 'ndc': '68084035401', 'prod_strength': '5mg Tablet', 'dose_val_rx': '5-10', 'dose_unit_rx': 'mg', 'route': 'PO/NG', 'stoptime': '2157-10-01 17:00:00'}),\n", + " Event(event_type='prescriptions', timestamp=datetime.datetime(2157, 9, 29, 21, 0), attr_dict={'hadm_id': '28766070', 'drug': 'Sodium Chloride 0.9%', 'ndc': '00338004904', 'prod_strength': 'Floor Stock Bag', 'dose_val_rx': '1000', 'dose_unit_rx': 'mL', 'route': 'IV', 'stoptime': '2157-10-01 17:00:00'}),\n", + " Event(event_type='prescriptions', timestamp=datetime.datetime(2157, 9, 29, 21, 0), attr_dict={'hadm_id': '28766070', 'drug': 'Ondansetron', 'ndc': '00641607825', 'prod_strength': '2mg/mL-2mL', 'dose_val_rx': '4', 'dose_unit_rx': 'mg', 'route': 'IV', 'stoptime': '2157-10-01 17:00:00'}),\n", + " Event(event_type='prescriptions', timestamp=datetime.datetime(2157, 9, 29, 21, 0), attr_dict={'hadm_id': '28766070', 'drug': 'HydrALAzine', 'ndc': '17478093415', 'prod_strength': '20mg/mL Vial', 'dose_val_rx': '10-20', 'dose_unit_rx': 'mg', 'route': 'IV', 'stoptime': '2157-10-01 17:00:00'}),\n", + " Event(event_type='prescriptions', timestamp=datetime.datetime(2157, 9, 29, 21, 0), attr_dict={'hadm_id': '28766070', 'drug': 'CefazoLIN', 'ndc': '00264310511', 'prod_strength': '2g Duplex Bag', 'dose_val_rx': '2', 'dose_unit_rx': 'g', 'route': 'IV', 'stoptime': '2157-09-30 20:00:00'}),\n", + " Event(event_type='prescriptions', timestamp=datetime.datetime(2157, 9, 29, 21, 0), attr_dict={'hadm_id': '28766070', 'drug': 'Diazepam', 'ndc': '51079028520', 'prod_strength': '5 mg Tab', 'dose_val_rx': '5', 'dose_unit_rx': 'mg', 'route': 'PO/NG', 'stoptime': '2157-10-01 17:00:00'}),\n", + " Event(event_type='prescriptions', timestamp=datetime.datetime(2157, 9, 29, 21, 0), attr_dict={'hadm_id': '28766070', 'drug': 'Iso-Osmotic Dextrose', 'ndc': '0', 'prod_strength': '50 mL Bag', 'dose_val_rx': '50', 'dose_unit_rx': 'mL', 'route': 'IV', 'stoptime': '2157-09-30 20:00:00'}),\n", + " Event(event_type='labevents', timestamp=datetime.datetime(2157, 9, 30, 6, 30), attr_dict={'itemid': '50970', 'label': 'Phosphate', 'fluid': 'Blood', 'category': 'Chemistry', 'value': '3.9', 'valuenum': '3.9', 'valueuom': 'mg/dL', 'flag': None, 'storetime': '2157-09-30 09:29:00'}),\n", + " Event(event_type='labevents', timestamp=datetime.datetime(2157, 9, 30, 6, 30), attr_dict={'itemid': '50971', 'label': 'Potassium', 'fluid': 'Blood', 'category': 'Chemistry', 'value': '4.3', 'valuenum': '4.3', 'valueuom': 'mEq/L', 'flag': None, 'storetime': '2157-09-30 09:29:00'}),\n", + " Event(event_type='labevents', timestamp=datetime.datetime(2157, 9, 30, 6, 30), attr_dict={'itemid': '50983', 'label': 'Sodium', 'fluid': 'Blood', 'category': 'Chemistry', 'value': '142', 'valuenum': '142', 'valueuom': 'mEq/L', 'flag': None, 'storetime': '2157-09-30 09:29:00'}),\n", + " Event(event_type='labevents', timestamp=datetime.datetime(2157, 9, 30, 6, 30), attr_dict={'itemid': '51006', 'label': 'Urea Nitrogen', 'fluid': 'Blood', 'category': 'Chemistry', 'value': '9', 'valuenum': '9', 'valueuom': 'mg/dL', 'flag': None, 'storetime': '2157-09-30 09:29:00'}),\n", + " Event(event_type='labevents', timestamp=datetime.datetime(2157, 9, 30, 6, 30), attr_dict={'itemid': '51237', 'label': 'INR(PT)', 'fluid': 'Blood', 'category': 'Hematology', 'value': '1.2', 'valuenum': '1.2', 'valueuom': None, 'flag': 'abnormal', 'storetime': '2157-09-30 08:54:00'}),\n", + " Event(event_type='labevents', timestamp=datetime.datetime(2157, 9, 30, 6, 30), attr_dict={'itemid': '51274', 'label': 'PT', 'fluid': 'Blood', 'category': 'Hematology', 'value': '12.6', 'valuenum': '12.6', 'valueuom': 'sec', 'flag': 'abnormal', 'storetime': '2157-09-30 08:54:00'}),\n", + " Event(event_type='labevents', timestamp=datetime.datetime(2157, 9, 30, 6, 30), attr_dict={'itemid': '51275', 'label': 'PTT', 'fluid': 'Blood', 'category': 'Hematology', 'value': '29.2', 'valuenum': '29.2', 'valueuom': 'sec', 'flag': None, 'storetime': '2157-09-30 08:54:00'}),\n", + " Event(event_type='labevents', timestamp=datetime.datetime(2157, 9, 30, 6, 30), attr_dict={'itemid': '51221', 'label': 'Hematocrit', 'fluid': 'Blood', 'category': 'Hematology', 'value': '30.4', 'valuenum': '30.4', 'valueuom': '%', 'flag': 'abnormal', 'storetime': '2157-09-30 08:52:00'}),\n", + " Event(event_type='labevents', timestamp=datetime.datetime(2157, 9, 30, 6, 30), attr_dict={'itemid': '51222', 'label': 'Hemoglobin', 'fluid': 'Blood', 'category': 'Hematology', 'value': '9.8', 'valuenum': '9.8', 'valueuom': 'g/dL', 'flag': 'abnormal', 'storetime': '2157-09-30 08:52:00'}),\n", + " Event(event_type='labevents', timestamp=datetime.datetime(2157, 9, 30, 6, 30), attr_dict={'itemid': '51248', 'label': 'MCH', 'fluid': 'Blood', 'category': 'Hematology', 'value': '26.8', 'valuenum': '26.8', 'valueuom': 'pg', 'flag': None, 'storetime': '2157-09-30 08:52:00'}),\n", + " Event(event_type='labevents', timestamp=datetime.datetime(2157, 9, 30, 6, 30), attr_dict={'itemid': '51249', 'label': 'MCHC', 'fluid': 'Blood', 'category': 'Hematology', 'value': '32.2', 'valuenum': '32.2', 'valueuom': 'g/dL', 'flag': None, 'storetime': '2157-09-30 08:52:00'}),\n", + " Event(event_type='labevents', timestamp=datetime.datetime(2157, 9, 30, 6, 30), attr_dict={'itemid': '51250', 'label': 'MCV', 'fluid': 'Blood', 'category': 'Hematology', 'value': '83', 'valuenum': '83', 'valueuom': 'fL', 'flag': None, 'storetime': '2157-09-30 08:52:00'}),\n", + " Event(event_type='labevents', timestamp=datetime.datetime(2157, 9, 30, 6, 30), attr_dict={'itemid': '50960', 'label': 'Magnesium', 'fluid': 'Blood', 'category': 'Chemistry', 'value': '2.0', 'valuenum': '2', 'valueuom': 'mg/dL', 'flag': None, 'storetime': '2157-09-30 09:29:00'}),\n", + " Event(event_type='labevents', timestamp=datetime.datetime(2157, 9, 30, 6, 30), attr_dict={'itemid': '51265', 'label': 'Platelet Count', 'fluid': 'Blood', 'category': 'Hematology', 'value': '404', 'valuenum': '404', 'valueuom': 'K/uL', 'flag': 'abnormal', 'storetime': '2157-09-30 08:52:00'}),\n", + " Event(event_type='labevents', timestamp=datetime.datetime(2157, 9, 30, 6, 30), attr_dict={'itemid': '51279', 'label': 'Red Blood Cells', 'fluid': 'Blood', 'category': 'Hematology', 'value': '3.65', 'valuenum': '3.65', 'valueuom': 'm/uL', 'flag': 'abnormal', 'storetime': '2157-09-30 08:52:00'}),\n", + " Event(event_type='labevents', timestamp=datetime.datetime(2157, 9, 30, 6, 30), attr_dict={'itemid': '51301', 'label': 'White Blood Cells', 'fluid': 'Blood', 'category': 'Hematology', 'value': '12.4', 'valuenum': '12.4', 'valueuom': 'K/uL', 'flag': 'abnormal', 'storetime': '2157-09-30 08:52:00'}),\n", + " Event(event_type='labevents', timestamp=datetime.datetime(2157, 9, 30, 6, 30), attr_dict={'itemid': '52172', 'label': 'RDW-SD', 'fluid': 'Blood', 'category': 'Hematology', 'value': '43.9', 'valuenum': '43.9', 'valueuom': 'fL', 'flag': None, 'storetime': '2157-09-30 08:52:00'}),\n", + " Event(event_type='labevents', timestamp=datetime.datetime(2157, 9, 30, 6, 30), attr_dict={'itemid': '51277', 'label': 'RDW', 'fluid': 'Blood', 'category': 'Hematology', 'value': '14.5', 'valuenum': '14.5', 'valueuom': '%', 'flag': None, 'storetime': '2157-09-30 08:52:00'}),\n", + " Event(event_type='labevents', timestamp=datetime.datetime(2157, 9, 30, 6, 30), attr_dict={'itemid': '50931', 'label': 'Glucose', 'fluid': 'Blood', 'category': 'Chemistry', 'value': '___', 'valuenum': '111', 'valueuom': 'mg/dL', 'flag': 'abnormal', 'storetime': '2157-09-30 09:29:00'}),\n", + " Event(event_type='labevents', timestamp=datetime.datetime(2157, 9, 30, 6, 30), attr_dict={'itemid': '50912', 'label': 'Creatinine', 'fluid': 'Blood', 'category': 'Chemistry', 'value': '1.1', 'valuenum': '1.1', 'valueuom': 'mg/dL', 'flag': None, 'storetime': '2157-09-30 09:29:00'}),\n", + " Event(event_type='labevents', timestamp=datetime.datetime(2157, 9, 30, 6, 30), attr_dict={'itemid': '50902', 'label': 'Chloride', 'fluid': 'Blood', 'category': 'Chemistry', 'value': '105', 'valuenum': '105', 'valueuom': 'mEq/L', 'flag': None, 'storetime': '2157-09-30 09:29:00'}),\n", + " Event(event_type='labevents', timestamp=datetime.datetime(2157, 9, 30, 6, 30), attr_dict={'itemid': '50868', 'label': 'Anion Gap', 'fluid': 'Blood', 'category': 'Chemistry', 'value': '15', 'valuenum': '15', 'valueuom': 'mEq/L', 'flag': None, 'storetime': '2157-09-30 09:29:00'}),\n", + " Event(event_type='labevents', timestamp=datetime.datetime(2157, 9, 30, 6, 30), attr_dict={'itemid': '50882', 'label': 'Bicarbonate', 'fluid': 'Blood', 'category': 'Chemistry', 'value': '26', 'valuenum': '26', 'valueuom': 'mEq/L', 'flag': None, 'storetime': '2157-09-30 09:29:00'}),\n", + " Event(event_type='labevents', timestamp=datetime.datetime(2157, 9, 30, 6, 30), attr_dict={'itemid': '50893', 'label': 'Calcium, Total', 'fluid': 'Blood', 'category': 'Chemistry', 'value': '9.1', 'valuenum': '9.1', 'valueuom': 'mg/dL', 'flag': None, 'storetime': '2157-09-30 09:29:00'}),\n", + " Event(event_type='prescriptions', timestamp=datetime.datetime(2157, 9, 30, 8, 0), attr_dict={'hadm_id': '28766070', 'drug': 'Levothyroxine Sodium', 'ndc': '00074662411', 'prod_strength': '100mcg Tablet', 'dose_val_rx': '100', 'dose_unit_rx': 'mcg', 'route': 'PO/NG', 'stoptime': '2157-10-01 17:00:00'}),\n", + " Event(event_type='prescriptions', timestamp=datetime.datetime(2157, 9, 30, 8, 0), attr_dict={'hadm_id': '28766070', 'drug': 'Gabapentin', 'ndc': '63739037510', 'prod_strength': '300mg Capsule', 'dose_val_rx': '600', 'dose_unit_rx': 'mg', 'route': 'PO/NG', 'stoptime': '2157-09-29 21:00:00'}),\n", + " Event(event_type='prescriptions', timestamp=datetime.datetime(2157, 9, 30, 8, 0), attr_dict={'hadm_id': '28766070', 'drug': 'Docusate Sodium', 'ndc': '00904224461', 'prod_strength': '100mg Capsule', 'dose_val_rx': '100', 'dose_unit_rx': 'mg', 'route': 'PO/NG', 'stoptime': '2157-09-29 21:00:00'}),\n", + " Event(event_type='prescriptions', timestamp=datetime.datetime(2157, 9, 30, 18, 0), attr_dict={'hadm_id': '28766070', 'drug': 'Heparin', 'ndc': '63323026201', 'prod_strength': '5000 Units / mL- 1mL Vial', 'dose_val_rx': '5000', 'dose_unit_rx': 'UNIT', 'route': 'SC', 'stoptime': '2157-10-01 17:00:00'}),\n", + " Event(event_type='procedures_icd', timestamp=datetime.datetime(2157, 10, 1, 13, 10), attr_dict={'hadm_id': '28766070', 'icd_code': '8051', 'icd_version': '9', 'seq_num': '3'}),\n", + " Event(event_type='diagnoses_icd', timestamp=datetime.datetime(2157, 10, 1, 13, 10), attr_dict={'hadm_id': '28766070', 'icd_code': '72210', 'icd_version': '9', 'seq_num': '1'}),\n", + " Event(event_type='diagnoses_icd', timestamp=datetime.datetime(2157, 10, 1, 13, 10), attr_dict={'hadm_id': '28766070', 'icd_code': '72740', 'icd_version': '9', 'seq_num': '2'}),\n", + " Event(event_type='diagnoses_icd', timestamp=datetime.datetime(2157, 10, 1, 13, 10), attr_dict={'hadm_id': '28766070', 'icd_code': '2449', 'icd_version': '9', 'seq_num': '3'}),\n", + " Event(event_type='diagnoses_icd', timestamp=datetime.datetime(2157, 10, 1, 13, 10), attr_dict={'hadm_id': '28766070', 'icd_code': '79029', 'icd_version': '9', 'seq_num': '4'}),\n", + " Event(event_type='diagnoses_icd', timestamp=datetime.datetime(2157, 10, 1, 13, 10), attr_dict={'hadm_id': '28766070', 'icd_code': '2859', 'icd_version': '9', 'seq_num': '5'}),\n", + " Event(event_type='diagnoses_icd', timestamp=datetime.datetime(2157, 10, 1, 13, 10), attr_dict={'hadm_id': '28766070', 'icd_code': '27800', 'icd_version': '9', 'seq_num': '6'}),\n", + " Event(event_type='diagnoses_icd', timestamp=datetime.datetime(2157, 10, 1, 13, 10), attr_dict={'hadm_id': '28766070', 'icd_code': 'V8539', 'icd_version': '9', 'seq_num': '7'}),\n", + " Event(event_type='procedures_icd', timestamp=datetime.datetime(2157, 10, 1, 13, 10), attr_dict={'hadm_id': '28766070', 'icd_code': '0309', 'icd_version': '9', 'seq_num': '2'}),\n", + " Event(event_type='procedures_icd', timestamp=datetime.datetime(2157, 10, 1, 13, 10), attr_dict={'hadm_id': '28766070', 'icd_code': '8339', 'icd_version': '9', 'seq_num': '1'}),\n", + " Event(event_type='diagnoses_icd', timestamp=datetime.datetime(2157, 10, 1, 13, 10), attr_dict={'hadm_id': '28766070', 'icd_code': 'V1582', 'icd_version': '9', 'seq_num': '8'}),\n", + " Event(event_type='labevents', timestamp=datetime.datetime(2157, 12, 8, 14, 55), attr_dict={'itemid': '50924', 'label': 'Ferritin', 'fluid': 'Blood', 'category': 'Chemistry', 'value': '30', 'valuenum': '30', 'valueuom': 'ng/mL', 'flag': None, 'storetime': '2157-12-08 21:13:00'}),\n", + " Event(event_type='labevents', timestamp=datetime.datetime(2157, 12, 8, 14, 55), attr_dict={'itemid': '50993', 'label': 'Thyroid Stimulating Hormone', 'fluid': 'Blood', 'category': 'Chemistry', 'value': '12', 'valuenum': '12', 'valueuom': 'uIU/mL', 'flag': 'abnormal', 'storetime': '2157-12-08 21:13:00'}),\n", + " Event(event_type='labevents', timestamp=datetime.datetime(2157, 12, 8, 14, 55), attr_dict={'itemid': '50995', 'label': 'Thyroxine (T4), Free', 'fluid': 'Blood', 'category': 'Chemistry', 'value': '1.1', 'valuenum': '1.1', 'valueuom': 'ng/dL', 'flag': None, 'storetime': '2157-12-08 21:13:00'}),\n", + " Event(event_type='labevents', timestamp=datetime.datetime(2157, 12, 8, 14, 55), attr_dict={'itemid': '51221', 'label': 'Hematocrit', 'fluid': 'Blood', 'category': 'Hematology', 'value': '34.7', 'valuenum': '34.7', 'valueuom': '%', 'flag': None, 'storetime': '2157-12-08 18:16:00'}),\n", + " Event(event_type='labevents', timestamp=datetime.datetime(2157, 12, 8, 14, 55), attr_dict={'itemid': '51222', 'label': 'Hemoglobin', 'fluid': 'Blood', 'category': 'Hematology', 'value': '11.1', 'valuenum': '11.1', 'valueuom': 'g/dL', 'flag': 'abnormal', 'storetime': '2157-12-08 18:16:00'}),\n", + " Event(event_type='labevents', timestamp=datetime.datetime(2157, 12, 8, 14, 55), attr_dict={'itemid': '51248', 'label': 'MCH', 'fluid': 'Blood', 'category': 'Hematology', 'value': '26.5', 'valuenum': '26.5', 'valueuom': 'pg', 'flag': None, 'storetime': '2157-12-08 18:16:00'}),\n", + " Event(event_type='labevents', timestamp=datetime.datetime(2157, 12, 8, 14, 55), attr_dict={'itemid': '51249', 'label': 'MCHC', 'fluid': 'Blood', 'category': 'Hematology', 'value': '32.0', 'valuenum': '32', 'valueuom': 'g/dL', 'flag': None, 'storetime': '2157-12-08 18:16:00'}),\n", + " Event(event_type='labevents', timestamp=datetime.datetime(2157, 12, 8, 14, 55), attr_dict={'itemid': '51250', 'label': 'MCV', 'fluid': 'Blood', 'category': 'Hematology', 'value': '83', 'valuenum': '83', 'valueuom': 'fL', 'flag': None, 'storetime': '2157-12-08 18:16:00'}),\n", + " Event(event_type='labevents', timestamp=datetime.datetime(2157, 12, 8, 14, 55), attr_dict={'itemid': '51265', 'label': 'Platelet Count', 'fluid': 'Blood', 'category': 'Hematology', 'value': '375', 'valuenum': '375', 'valueuom': 'K/uL', 'flag': None, 'storetime': '2157-12-08 18:16:00'}),\n", + " Event(event_type='labevents', timestamp=datetime.datetime(2157, 12, 8, 14, 55), attr_dict={'itemid': '51277', 'label': 'RDW', 'fluid': 'Blood', 'category': 'Hematology', 'value': '16.3', 'valuenum': '16.3', 'valueuom': '%', 'flag': 'abnormal', 'storetime': '2157-12-08 18:16:00'}),\n", + " Event(event_type='labevents', timestamp=datetime.datetime(2157, 12, 8, 14, 55), attr_dict={'itemid': '51279', 'label': 'Red Blood Cells', 'fluid': 'Blood', 'category': 'Hematology', 'value': '4.19', 'valuenum': '4.19', 'valueuom': 'm/uL', 'flag': None, 'storetime': '2157-12-08 18:16:00'}),\n", + " Event(event_type='labevents', timestamp=datetime.datetime(2157, 12, 8, 14, 55), attr_dict={'itemid': '51283', 'label': 'Reticulocyte Count, Automated', 'fluid': 'Blood', 'category': 'Hematology', 'value': '1.3', 'valuenum': '1.3', 'valueuom': '%', 'flag': None, 'storetime': '2157-12-08 19:20:00'}),\n", + " Event(event_type='labevents', timestamp=datetime.datetime(2157, 12, 8, 14, 55), attr_dict={'itemid': '51301', 'label': 'White Blood Cells', 'fluid': 'Blood', 'category': 'Hematology', 'value': '8.0', 'valuenum': '8', 'valueuom': 'K/uL', 'flag': None, 'storetime': '2157-12-08 18:16:00'}),\n", + " Event(event_type='labevents', timestamp=datetime.datetime(2157, 12, 8, 14, 55), attr_dict={'itemid': '52172', 'label': 'RDW-SD', 'fluid': 'Blood', 'category': 'Hematology', 'value': '48.7', 'valuenum': '48.7', 'valueuom': 'fL', 'flag': 'abnormal', 'storetime': '2157-12-08 18:16:00'}),\n", + " Event(event_type='labevents', timestamp=datetime.datetime(2157, 12, 8, 14, 55), attr_dict={'itemid': '51282', 'label': 'Reticulocyte Count, Absolute', 'fluid': 'Blood', 'category': 'Hematology', 'value': '0.06', 'valuenum': '0.06', 'valueuom': 'm/uL', 'flag': None, 'storetime': '2157-12-08 19:20:00'}),\n", + " Event(event_type='labevents', timestamp=datetime.datetime(2158, 1, 5, 14, 12), attr_dict={'itemid': '51989', 'label': 'Oxycodone', 'fluid': 'Urine', 'category': 'Chemistry', 'value': 'NEG', 'valuenum': None, 'valueuom': None, 'flag': None, 'storetime': '2158-01-05 18:14:00'}),\n", + " Event(event_type='labevents', timestamp=datetime.datetime(2158, 1, 5, 14, 12), attr_dict={'itemid': '51092', 'label': 'Opiate Screen, Urine', 'fluid': 'Urine', 'category': 'Chemistry', 'value': 'NEG', 'valuenum': None, 'valueuom': None, 'flag': None, 'storetime': '2158-01-05 18:14:00'}),\n", + " Event(event_type='labevents', timestamp=datetime.datetime(2158, 1, 5, 14, 12), attr_dict={'itemid': '51090', 'label': 'Methadone, Urine', 'fluid': 'Urine', 'category': 'Chemistry', 'value': 'NEG', 'valuenum': None, 'valueuom': None, 'flag': None, 'storetime': '2158-01-05 18:14:00'}),\n", + " Event(event_type='labevents', timestamp=datetime.datetime(2158, 1, 5, 14, 12), attr_dict={'itemid': '51087', 'label': 'Length of Urine Collection', 'fluid': 'Urine', 'category': 'Chemistry', 'value': None, 'valuenum': None, 'valueuom': None, 'flag': None, 'storetime': None}),\n", + " Event(event_type='labevents', timestamp=datetime.datetime(2158, 1, 5, 14, 12), attr_dict={'itemid': '51079', 'label': 'Cocaine, Urine', 'fluid': 'Urine', 'category': 'Chemistry', 'value': 'NEG', 'valuenum': None, 'valueuom': None, 'flag': None, 'storetime': '2158-01-05 18:14:00'}),\n", + " Event(event_type='labevents', timestamp=datetime.datetime(2158, 1, 5, 14, 12), attr_dict={'itemid': '51075', 'label': 'Benzodiazepine Screen, Urine', 'fluid': 'Urine', 'category': 'Chemistry', 'value': 'NEG', 'valuenum': None, 'valueuom': None, 'flag': None, 'storetime': '2158-01-05 18:14:00'}),\n", + " Event(event_type='labevents', timestamp=datetime.datetime(2158, 1, 5, 14, 12), attr_dict={'itemid': '51103', 'label': 'Uhold', 'fluid': 'Urine', 'category': 'Chemistry', 'value': 'HOLD.', 'valuenum': None, 'valueuom': None, 'flag': None, 'storetime': None}),\n", + " Event(event_type='labevents', timestamp=datetime.datetime(2158, 1, 5, 14, 12), attr_dict={'itemid': '51087', 'label': 'Length of Urine Collection', 'fluid': 'Urine', 'category': 'Chemistry', 'value': None, 'valuenum': None, 'valueuom': None, 'flag': None, 'storetime': None}),\n", + " Event(event_type='labevents', timestamp=datetime.datetime(2158, 1, 5, 14, 12), attr_dict={'itemid': '51103', 'label': 'Uhold', 'fluid': 'Urine', 'category': 'Chemistry', 'value': 'HOLD.', 'valuenum': None, 'valueuom': None, 'flag': None, 'storetime': None}),\n", + " Event(event_type='labevents', timestamp=datetime.datetime(2158, 1, 5, 14, 12), attr_dict={'itemid': '51087', 'label': 'Length of Urine Collection', 'fluid': 'Urine', 'category': 'Chemistry', 'value': None, 'valuenum': None, 'valueuom': None, 'flag': None, 'storetime': None})]" ] }, - "execution_count": 6, + "execution_count": 2, "metadata": {}, "output_type": "execute_result" } @@ -562,23 +554,23 @@ }, { "cell_type": "code", - "execution_count": 7, + "execution_count": 3, "id": "a66e489f", "metadata": {}, "outputs": [ { "data": { "text/plain": [ - "{'patient_id': '11753938',\n", - " 'admission_id': '29579516',\n", - " 'labs': tensor([[ 0.0000, 0.0000, 141.0000, 0.0000, 0.0000, 0.0000, 4.5000,\n", - " 0.0000, 0.0000, 0.0000, 102.0000, 0.0000, 0.0000, 0.0000,\n", - " 0.0000, 0.0000, 162.0000, 0.0000, 0.0000, 0.0000, 2.2000,\n", - " 18.0000, 0.0000, 0.0000, 0.0000, 0.0000, 5.2000]]),\n", + "{'patient_id': '15853169',\n", + " 'admission_id': '23443189',\n", + " 'labs': tensor([[ 0.0000, 0.0000, 139.0000, 0.0000, 0.0000, 0.0000, 4.4000,\n", + " 0.0000, 0.0000, 0.0000, 103.0000, 0.0000, 0.0000, 0.0000,\n", + " 0.0000, 0.0000, 83.0000, 0.0000, 0.0000, 0.0000, 2.2000,\n", + " 16.0000, 0.0000, 0.0000, 0.0000, 0.0000, 4.7000]]),\n", " 'mortality': tensor([0.])}" ] }, - "execution_count": 7, + "execution_count": 3, "metadata": {}, "output_type": "execute_result" } @@ -589,7 +581,7 @@ }, { "cell_type": "code", - "execution_count": 3, + "execution_count": 4, "id": "3b642c1d", "metadata": {}, "outputs": [ @@ -598,9 +590,7 @@ "output_type": "stream", "text": [ "/home/johnwu3/projects/PyHealth_Branch_Testing/PyHealth/pyhealth/sampler/sage_sampler.py:3: UserWarning: pkg_resources is deprecated as an API. See https://setuptools.pypa.io/en/latest/pkg_resources.html. The pkg_resources package is slated for removal as early as 2025-11-30. Refrain from using this package or pin to Setuptools<81.\n", - " import pkg_resources\n", - "/home/johnwu3/projects/PyHealth_Branch_Testing/PyHealth/pyhealth/metrics/calibration.py:122: SyntaxWarning: invalid escape sequence '\\c'\n", - " accuracy of 1. Thus, the ECE is :math:`\\\\frac{1}{3} \\cdot 0.49 + \\\\frac{2}{3}\\cdot 0.3=0.3633`.\n" + " import pkg_resources\n" ] }, { @@ -628,21 +618,21 @@ "name": "stderr", "output_type": "stream", "text": [ - "Evaluation: 100%|██████████| 6/6 [00:02<00:00, 2.31it/s]" + "Evaluation: 100%|██████████| 6/6 [00:00<00:00, 20.72it/s]" ] }, { "name": "stdout", "output_type": "stream", "text": [ - "{'roc_auc': 0.8403575989782885, 'loss': 0.6699792544047037}\n", + "{'roc_auc': 0.8935969868173259, 'loss': 0.6720269918441772}\n", "Training:\n", "Batch size: 32\n", "Optimizer: \n", "Optimizer params: {'lr': 0.0001}\n", "Weight decay: 0.0\n", "Max grad norm: None\n", - "Val dataloader: \n", + "Val dataloader: \n", "Monitor: roc_auc\n", "Monitor criterion: max\n", "Epochs: 10\n", @@ -660,7 +650,7 @@ { "data": { "application/vnd.jupyter.widget-view+json": { - "model_id": "52c3da3ac211429984652fde2e4b3921", + "model_id": "6f07dd9d11e94dd6b73cad58fe7f876a", "version_major": 2, "version_minor": 0 }, @@ -676,14 +666,14 @@ "output_type": "stream", "text": [ "--- Train epoch-0, step-20 ---\n", - "loss: 0.6346\n" + "loss: 0.6315\n" ] }, { "name": "stderr", "output_type": "stream", "text": [ - "Evaluation: 100%|██████████| 3/3 [00:00<00:00, 85.73it/s]" + "Evaluation: 100%|██████████| 3/3 [00:00<00:00, 57.97it/s]" ] }, { @@ -691,9 +681,9 @@ "output_type": "stream", "text": [ "--- Eval epoch-0, step-20 ---\n", - "roc_auc: 0.7556\n", - "loss: 0.5881\n", - "New best roc_auc score (0.7556) at epoch-0, step-20\n", + "roc_auc: 0.8116\n", + "loss: 0.6003\n", + "New best roc_auc score (0.8116) at epoch-0, step-20\n", "\n" ] }, @@ -707,7 +697,7 @@ { "data": { "application/vnd.jupyter.widget-view+json": { - "model_id": "3020cd8aa9144d2693c7baf9cb2a7a12", + "model_id": "6613ee2bc2f54dae9afbc7bf32470b88", "version_major": 2, "version_minor": 0 }, @@ -723,14 +713,14 @@ "output_type": "stream", "text": [ "--- Train epoch-1, step-40 ---\n", - "loss: 0.5562\n" + "loss: 0.5568\n" ] }, { "name": "stderr", "output_type": "stream", "text": [ - "Evaluation: 100%|██████████| 3/3 [00:00<00:00, 100.40it/s]" + "Evaluation: 100%|██████████| 3/3 [00:00<00:00, 56.94it/s]" ] }, { @@ -738,8 +728,9 @@ "output_type": "stream", "text": [ "--- Eval epoch-1, step-40 ---\n", - "roc_auc: 0.7333\n", - "loss: 0.5019\n", + "roc_auc: 0.8709\n", + "loss: 0.5197\n", + "New best roc_auc score (0.8709) at epoch-1, step-40\n", "\n" ] }, @@ -753,7 +744,7 @@ { "data": { "application/vnd.jupyter.widget-view+json": { - "model_id": "16a577a3ec4e4139b7c5fabc07265814", + "model_id": "7199636faade4f2aaaf6d01f6405e387", "version_major": 2, "version_minor": 0 }, @@ -769,14 +760,14 @@ "output_type": "stream", "text": [ "--- Train epoch-2, step-60 ---\n", - "loss: 0.4677\n" + "loss: 0.4634\n" ] }, { "name": "stderr", "output_type": "stream", "text": [ - "Evaluation: 100%|██████████| 3/3 [00:00<00:00, 92.85it/s]" + "Evaluation: 100%|██████████| 3/3 [00:00<00:00, 61.21it/s]" ] }, { @@ -784,8 +775,9 @@ "output_type": "stream", "text": [ "--- Eval epoch-2, step-60 ---\n", - "roc_auc: 0.5889\n", - "loss: 0.4027\n", + "roc_auc: 0.8791\n", + "loss: 0.4268\n", + "New best roc_auc score (0.8791) at epoch-2, step-60\n", "\n" ] }, @@ -799,7 +791,7 @@ { "data": { "application/vnd.jupyter.widget-view+json": { - "model_id": "3e7ecd481fe34a128f3a5f628f9c2620", + "model_id": "06c74a715efe47509b9cbeda5a5532bf", "version_major": 2, "version_minor": 0 }, @@ -815,14 +807,14 @@ "output_type": "stream", "text": [ "--- Train epoch-3, step-80 ---\n", - "loss: 0.3583\n" + "loss: 0.3546\n" ] }, { "name": "stderr", "output_type": "stream", "text": [ - "Evaluation: 100%|██████████| 3/3 [00:00<00:00, 91.70it/s]" + "Evaluation: 100%|██████████| 3/3 [00:00<00:00, 63.47it/s]" ] }, { @@ -830,8 +822,8 @@ "output_type": "stream", "text": [ "--- Eval epoch-3, step-80 ---\n", - "roc_auc: 0.7111\n", - "loss: 0.2732\n", + "roc_auc: 0.8372\n", + "loss: 0.3041\n", "\n" ] }, @@ -845,7 +837,7 @@ { "data": { "application/vnd.jupyter.widget-view+json": { - "model_id": "c908d81f7ac64299b1c0b659db89e02d", + "model_id": "c1f6ca836eb3481e8c7b9c5761dd18e3", "version_major": 2, "version_minor": 0 }, @@ -861,14 +853,14 @@ "output_type": "stream", "text": [ "--- Train epoch-4, step-100 ---\n", - "loss: 0.2206\n" + "loss: 0.2161\n" ] }, { "name": "stderr", "output_type": "stream", "text": [ - "Evaluation: 100%|██████████| 3/3 [00:00<00:00, 113.34it/s]" + "Evaluation: 100%|██████████| 3/3 [00:00<00:00, 66.92it/s]" ] }, { @@ -876,8 +868,8 @@ "output_type": "stream", "text": [ "--- Eval epoch-4, step-100 ---\n", - "roc_auc: 0.7111\n", - "loss: 0.1420\n", + "roc_auc: 0.8116\n", + "loss: 0.1927\n", "\n" ] }, @@ -891,7 +883,7 @@ { "data": { "application/vnd.jupyter.widget-view+json": { - "model_id": "bd3fd090b6c6425cbd9f097e128487c2", + "model_id": "ef763b8e6bca45a0a8b5c81ef1d9c3b7", "version_major": 2, "version_minor": 0 }, @@ -907,14 +899,14 @@ "output_type": "stream", "text": [ "--- Train epoch-5, step-120 ---\n", - "loss: 0.1343\n" + "loss: 0.1378\n" ] }, { "name": "stderr", "output_type": "stream", "text": [ - "Evaluation: 100%|██████████| 3/3 [00:00<00:00, 98.47it/s]" + "Evaluation: 100%|██████████| 3/3 [00:00<00:00, 64.43it/s]" ] }, { @@ -922,8 +914,8 @@ "output_type": "stream", "text": [ "--- Eval epoch-5, step-120 ---\n", - "roc_auc: 0.7111\n", - "loss: 0.0992\n", + "roc_auc: 0.8140\n", + "loss: 0.1700\n", "\n" ] }, @@ -937,7 +929,7 @@ { "data": { "application/vnd.jupyter.widget-view+json": { - "model_id": "60d2c391608143588f368773ebfda7ac", + "model_id": "fbaed0b261794a42ad920cd1da754cc3", "version_major": 2, "version_minor": 0 }, @@ -953,14 +945,14 @@ "output_type": "stream", "text": [ "--- Train epoch-6, step-140 ---\n", - "loss: 0.1191\n" + "loss: 0.1185\n" ] }, { "name": "stderr", "output_type": "stream", "text": [ - "Evaluation: 100%|██████████| 3/3 [00:00<00:00, 87.03it/s]" + "Evaluation: 100%|██████████| 3/3 [00:00<00:00, 64.68it/s]" ] }, { @@ -968,8 +960,8 @@ "output_type": "stream", "text": [ "--- Eval epoch-6, step-140 ---\n", - "roc_auc: 0.7111\n", - "loss: 0.0901\n", + "roc_auc: 0.8093\n", + "loss: 0.1698\n", "\n" ] }, @@ -983,7 +975,7 @@ { "data": { "application/vnd.jupyter.widget-view+json": { - "model_id": "5499197e5e374e41a4eb5552d1bc4dfc", + "model_id": "d9a852db80c94d75ac6781d5206fe4bc", "version_major": 2, "version_minor": 0 }, @@ -999,14 +991,14 @@ "output_type": "stream", "text": [ "--- Train epoch-7, step-160 ---\n", - "loss: 0.1205\n" + "loss: 0.1153\n" ] }, { "name": "stderr", "output_type": "stream", "text": [ - "Evaluation: 100%|██████████| 3/3 [00:00<00:00, 101.82it/s]" + "Evaluation: 100%|██████████| 3/3 [00:00<00:00, 57.79it/s]" ] }, { @@ -1014,8 +1006,8 @@ "output_type": "stream", "text": [ "--- Eval epoch-7, step-160 ---\n", - "roc_auc: 0.7111\n", - "loss: 0.0877\n", + "roc_auc: 0.8116\n", + "loss: 0.1709\n", "\n" ] }, @@ -1029,7 +1021,7 @@ { "data": { "application/vnd.jupyter.widget-view+json": { - "model_id": "56a6457e4f4a4133bca676a5cfa6cd3e", + "model_id": "81c14ee9ee424ec1b616e58c4cba7b2f", "version_major": 2, "version_minor": 0 }, @@ -1045,14 +1037,14 @@ "output_type": "stream", "text": [ "--- Train epoch-8, step-180 ---\n", - "loss: 0.1158\n" + "loss: 0.1155\n" ] }, { "name": "stderr", "output_type": "stream", "text": [ - "Evaluation: 100%|██████████| 3/3 [00:00<00:00, 101.16it/s]" + "Evaluation: 100%|██████████| 3/3 [00:00<00:00, 64.75it/s]" ] }, { @@ -1060,8 +1052,8 @@ "output_type": "stream", "text": [ "--- Eval epoch-8, step-180 ---\n", - "roc_auc: 0.7111\n", - "loss: 0.0852\n", + "roc_auc: 0.8116\n", + "loss: 0.1714\n", "\n" ] }, @@ -1075,7 +1067,7 @@ { "data": { "application/vnd.jupyter.widget-view+json": { - "model_id": "afa185d5939a4067bb7f8e86382676c7", + "model_id": "5cbe741388a247eca40d31971c300f12", "version_major": 2, "version_minor": 0 }, @@ -1091,14 +1083,14 @@ "output_type": "stream", "text": [ "--- Train epoch-9, step-200 ---\n", - "loss: 0.1144\n" + "loss: 0.1135\n" ] }, { "name": "stderr", "output_type": "stream", "text": [ - "Evaluation: 100%|██████████| 3/3 [00:00<00:00, 97.20it/s]" + "Evaluation: 100%|██████████| 3/3 [00:00<00:00, 55.26it/s]" ] }, { @@ -1106,8 +1098,8 @@ "output_type": "stream", "text": [ "--- Eval epoch-9, step-200 ---\n", - "roc_auc: 0.7111\n", - "loss: 0.0839\n", + "roc_auc: 0.8093\n", + "loss: 0.1719\n", "Loaded best model\n" ] }, diff --git a/pyhealth/tasks/__init__.py b/pyhealth/tasks/__init__.py index bcfb19f7a..097df9a29 100644 --- a/pyhealth/tasks/__init__.py +++ b/pyhealth/tasks/__init__.py @@ -12,6 +12,7 @@ from .chestxray14_binary_classification import ChestXray14BinaryClassification from .chestxray14_multilabel_classification import ChestXray14MultilabelClassification from .covid19_cxr_classification import COVID19CXRClassification +from .dka import DKAPredictionMIMIC4 from .drug_recommendation import ( DrugRecommendationMIMIC3, DrugRecommendationMIMIC4, diff --git a/pyhealth/tasks/dka.py b/pyhealth/tasks/dka.py new file mode 100644 index 000000000..3cd70798e --- /dev/null +++ b/pyhealth/tasks/dka.py @@ -0,0 +1,497 @@ +# Description: DKA (Diabetic Ketoacidosis) prediction task for MIMIC-IV dataset + +import math +from datetime import datetime, timedelta +from typing import Any, ClassVar, Dict, List, Optional, Set, Tuple + +import polars as pl + +from .base_task import BaseTask + + +class DKAPredictionMIMIC4(BaseTask): + """Task for predicting Diabetic Ketoacidosis (DKA) in Type 1 Diabetes patients. + + This task creates PATIENT-LEVEL samples by identifying patients with Type 1 + Diabetes Mellitus (T1DM) and predicting whether they will develop DKA within + a specified time window. The task uses diagnosis codes and lab results across + all admissions in StageNet format for temporal modeling. + + Target Population: + - Patients with Type 1 Diabetes (ICD-9 or ICD-10 codes) + - Excludes patients without any T1DM diagnosis codes + + Label Definition: + - Positive (1): Patient has DKA code within 90 days of T1DM diagnosis + - Negative (0): Patient has T1DM but no DKA within the window + + Time Calculation: + - Diagnosis codes: Hours from previous admission (0 for first visit) + - Labs: Hours from admission start (within-visit measurements) + + Lab Processing: + - 6-dimensional vectors (one per lab category relevant to DKA) + - Categories: glucose, bicarbonate, anion_gap, potassium, sodium, chloride + - Multiple itemids per category → take mean of observed values + - Missing categories → NaN in vector + + Args: + dka_window_days: Number of days to consider for DKA occurrence after + T1DM diagnosis. Default: 90. + padding: Additional padding for StageNet processor. Default: 0. + + Attributes: + task_name (str): The name of the task. + input_schema (Dict[str, Tuple[str, Dict]]): The schema for input data: + - diagnoses: Diagnosis ICD codes (stagenet format, nested by visit) + - labs: Lab results (stagenet_tensor, 6D vectors per timestamp) + output_schema (Dict[str, str]): The schema for output data: + - label: Binary indicator (1 if DKA within window, 0 otherwise) + + Example: + >>> from pyhealth.datasets import MIMIC4Dataset + >>> from pyhealth.tasks import DKAPredictionMIMIC4 + >>> + >>> dataset = MIMIC4Dataset( + ... root="/path/to/mimic4", + ... tables=["diagnoses_icd", "labevents", "admissions"], + ... ) + >>> task = DKAPredictionMIMIC4(dka_window_days=90) + >>> samples = dataset.set_task(task) + """ + + task_name: str = "DKAPredictionMIMIC4" + + # ICD-10 prefix for Type 1 Diabetes Mellitus + T1DM_ICD10_PREFIX: ClassVar[str] = "E10" + + # ICD-9 codes for Type 1 Diabetes Mellitus + T1DM_ICD9_CODES: ClassVar[Set[str]] = { + "25001", "25003", "25011", "25013", "25021", "25023", + "25031", "25033", "25041", "25043", "25051", "25053", + "25061", "25063", "25071", "25073", "25081", "25083", + "25091", "25093", + } + + # ICD-9 codes for Diabetic Ketoacidosis + DKA_ICD9_CODES: ClassVar[Set[str]] = {"25010", "25011", "25012", "25013"} + + # ICD-10 prefix for DKA (E10.1x codes) + DKA_ICD10_PREFIX: ClassVar[str] = "E101" + + # Lab categories relevant to DKA monitoring + # Each category maps to ONE dimension in the output vector + LAB_CATEGORIES: ClassVar[Dict[str, List[str]]] = { + "glucose": ["50809", "50931", "52027", "52569"], + "bicarbonate": ["50803", "50804", "51084"], + "anion_gap": ["50868"], + "potassium": ["50822", "50971", "52452", "52510"], + "sodium": ["50824", "50983", "52455"], + "chloride": ["50806", "50902", "52434"], + } + + # Ordered list of category names (defines vector dimension order) + LAB_CATEGORY_ORDER: ClassVar[List[str]] = [ + "glucose", + "bicarbonate", + "anion_gap", + "potassium", + "sodium", + "chloride", + ] + + # Flat list of all lab item IDs for filtering + ALL_LAB_ITEMIDS: ClassVar[List[str]] = sorted( + {item for items in LAB_CATEGORIES.values() for item in items} + ) + + def __init__(self, dka_window_days: int = 90, padding: int = 0): + """Initialize task with configurable DKA window and padding. + + Args: + dka_window_days: Days after T1DM diagnosis to check for DKA. Default: 90. + padding: Additional padding for nested sequences. Default: 0. + """ + self.dka_window_days = dka_window_days + self.dka_window = timedelta(days=dka_window_days) + self.padding = padding + + # Use tuple format to pass kwargs to processor + self.input_schema: Dict[str, Tuple[str, Dict[str, Any]]] = { + "diagnoses": ("stagenet", {"padding": padding}), + "labs": ("stagenet_tensor", {}), + } + self.output_schema: Dict[str, str] = {"label": "binary"} + + @staticmethod + def _normalize_icd(code: Optional[str]) -> str: + """Normalize ICD code by removing dots and standardizing format. + + Args: + code: Raw ICD code string, may contain dots and varying case. + + Returns: + Normalized uppercase code without dots, or empty string if None. + """ + if code is None: + return "" + return code.replace(".", "").strip().upper() + + def _is_t1dm_code(self, code: Optional[str], version: Optional[object]) -> bool: + """Check if an ICD code represents Type 1 Diabetes Mellitus. + + Args: + code: ICD diagnosis code. + version: ICD version (9 or 10). + + Returns: + True if code represents T1DM, False otherwise. + """ + normalized = self._normalize_icd(code) + if not normalized: + return False + + version_str = str(version) if version is not None else "" + + if version_str == "10": + return normalized.startswith(self.T1DM_ICD10_PREFIX) + if version_str == "9": + return normalized in self.T1DM_ICD9_CODES + + return False + + def _is_dka_code(self, code: Optional[str], version: Optional[object]) -> bool: + """Check if an ICD code represents Diabetic Ketoacidosis. + + Args: + code: ICD diagnosis code. + version: ICD version (9 or 10). + + Returns: + True if code represents DKA, False otherwise. + """ + normalized = self._normalize_icd(code) + if not normalized: + return False + + version_str = str(version) if version is not None else "" + + if version_str == "10": + return normalized.startswith(self.DKA_ICD10_PREFIX) + if version_str == "9": + return normalized in self.DKA_ICD9_CODES + + return False + + @staticmethod + def _safe_parse_datetime(value: Optional[object]) -> Optional[datetime]: + """Safely parse a datetime value from various formats. + + Args: + value: Datetime string or datetime object. + + Returns: + Parsed datetime object, or None if parsing fails. + """ + if value is None: + return None + if isinstance(value, datetime): + return value + + text = str(value) + for fmt in ("%Y-%m-%d %H:%M:%S", "%Y-%m-%d"): + try: + return datetime.strptime(text, fmt) + except ValueError: + continue + try: + return datetime.fromisoformat(text) + except ValueError: + return None + + @staticmethod + def _deduplicate_preserve_order(values: List[str]) -> List[str]: + """Remove duplicates from a list while preserving order. + + Args: + values: List of strings with potential duplicates. + + Returns: + Deduplicated list maintaining original order. + """ + seen: Set[str] = set() + ordered: List[str] = [] + for value in values: + if value not in seen: + seen.add(value) + ordered.append(value) + return ordered + + def pre_filter(self, df: pl.LazyFrame) -> pl.LazyFrame: + """Filter to keep only patients with Type 1 Diabetes codes. + + This pre-filter reduces the dataset to patients who have at least + one T1DM diagnosis code (ICD-9 or ICD-10), improving processing + efficiency for the downstream task. + + Args: + df: LazyFrame containing patient data with diagnosis codes. + + Returns: + Filtered LazyFrame with only T1DM patients. + """ + # Check if we have the diagnosis code column + if "diagnoses_icd/icd_code" not in df.collect_schema().names(): + # Column not present, return unfiltered + return df + + # Collect to DataFrame for filtering + collected_df = df.collect() + + # Create masks for T1DM codes + mask_icd10 = collected_df["diagnoses_icd/icd_code"].str.starts_with( + self.T1DM_ICD10_PREFIX + ) + mask_icd9 = collected_df["diagnoses_icd/icd_code"].is_in( + list(self.T1DM_ICD9_CODES) + ) + + # Get patient IDs with T1DM codes + t1dm_mask = mask_icd10 | mask_icd9 + t1dm_patients = collected_df.filter(t1dm_mask)["patient_id"].unique() + + # Keep only patients with T1DM codes + filtered_df = collected_df.filter( + collected_df["patient_id"].is_in(t1dm_patients) + ) + + return filtered_df.lazy() + + def _build_lab_vector(self, lab_df: Optional[pl.DataFrame]) -> List[float]: + """Build a lab feature vector from lab events DataFrame. + + Creates a fixed-dimension vector with one value per lab category. + Uses mean aggregation when multiple values exist for a category. + + Args: + lab_df: DataFrame containing lab events with itemid and valuenum columns. + + Returns: + List of floats with length equal to number of lab categories. + Missing categories are represented as NaN. + """ + feature_dim = len(self.LAB_CATEGORY_ORDER) + + if lab_df is None or lab_df.height == 0: + return [math.nan] * feature_dim + + # Filter and cast columns + filtered = ( + lab_df.with_columns([ + pl.col("labevents/itemid").cast(pl.Utf8), + pl.col("labevents/valuenum").cast(pl.Float64), + ]) + .filter(pl.col("labevents/itemid").is_in(self.ALL_LAB_ITEMIDS)) + .filter(pl.col("labevents/valuenum").is_not_null()) + ) + + if filtered.height == 0: + return [math.nan] * feature_dim + + # Build vector with one value per category + vector: List[float] = [] + for category in self.LAB_CATEGORY_ORDER: + itemids = self.LAB_CATEGORIES[category] + cat_df = filtered.filter(pl.col("labevents/itemid").is_in(itemids)) + + if cat_df.height == 0: + vector.append(math.nan) + else: + values = cat_df["labevents/valuenum"].drop_nulls() + if len(values) > 0: + vector.append(float(values.mean())) + else: + vector.append(math.nan) + + return vector + + def __call__(self, patient: Any) -> List[Dict[str, Any]]: + """Process a patient to create DKA prediction samples. + + Creates ONE sample per patient with T1DM diagnosis. Aggregates all + admissions and calculates whether DKA occurred within the specified + time window of T1DM diagnosis. + + Args: + patient: Patient object with get_events method. + + Returns: + List with single sample containing patient_id, diagnosis sequences, + lab sequences, and DKA label. Returns empty list if patient does + not have T1DM or lacks required data. + """ + # Get all diagnosis events + diagnosis_events = patient.get_events(event_type="diagnoses_icd") + if not diagnosis_events: + return [] + + # Identify T1DM and DKA occurrences with timestamps + has_t1dm = False + t1dm_times: List[datetime] = [] + dka_times: List[datetime] = [] + + for event in diagnosis_events: + version = getattr(event, "icd_version", None) + code = getattr(event, "icd_code", None) + event_time = self._safe_parse_datetime(getattr(event, "timestamp", None)) + + if self._is_t1dm_code(code, version): + has_t1dm = True + if event_time is not None: + t1dm_times.append(event_time) + + if self._is_dka_code(code, version): + if event_time is not None: + dka_times.append(event_time) + + # Skip patients without T1DM diagnosis + if not has_t1dm: + return [] + + # Determine DKA label based on temporal relationship + has_dka_within_window = False + + if dka_times and t1dm_times: + for diagnosis_time in t1dm_times: + for dka_time in dka_times: + if diagnosis_time is None or dka_time is None: + continue + delta = abs((dka_time - diagnosis_time).days) + if delta <= self.dka_window_days: + has_dka_within_window = True + break + if has_dka_within_window: + break + + # Fallback: if no temporal info, check if patient has any DKA codes + if not has_dka_within_window and not t1dm_times: + has_dka_within_window = len(dka_times) > 0 + + # Get admission information + admissions = patient.get_events(event_type="admissions") + admissions_info: Dict[str, Dict[str, Optional[datetime]]] = {} + + if admissions: + for admission in admissions: + hadm_id = getattr(admission, "hadm_id", None) + admit_time = self._safe_parse_datetime( + getattr(admission, "timestamp", None) + ) + discharge_time = self._safe_parse_datetime( + getattr(admission, "dischtime", None) + ) + if hadm_id is not None and admit_time is not None: + admissions_info[str(hadm_id)] = { + "admit": admit_time, + "discharge": discharge_time, + } + + # Create dummy admission if none exist + if not admissions_info: + dummy_hadm_id = f"dummy_{patient.patient_id}" + admissions_info[dummy_hadm_id] = { + "admit": datetime.now(), + "discharge": None, + } + + # Build diagnosis code sequences per admission + admission_codes: Dict[str, List[str]] = { + hadm_id: [] for hadm_id in admissions_info + } + + for event in diagnosis_events: + code = getattr(event, "icd_code", None) + normalized_code = self._normalize_icd(code) + if not normalized_code: + continue + + hadm_id = getattr(event, "hadm_id", None) + admission_key = ( + str(hadm_id) + if hadm_id is not None + else list(admissions_info.keys())[0] + ) + + if admission_key in admission_codes: + admission_codes[admission_key].append(normalized_code) + + # Sort admissions chronologically + sorted_admissions = sorted( + admissions_info.items(), + key=lambda item: item[1]["admit"] + if item[1]["admit"] is not None + else datetime.min, + ) + + # Build sequences + diagnoses_sequences: List[List[str]] = [] + diagnoses_times: List[float] = [] + lab_sequences: List[List[float]] = [] + lab_times: List[float] = [] + previous_admit: Optional[datetime] = None + + for hadm_id, info in sorted_admissions: + admit_time = info["admit"] + if admit_time is None: + admit_time = datetime.now() + + # Get deduplicated codes for this admission + codes = self._deduplicate_preserve_order( + admission_codes.get(hadm_id, []) + ) + if not codes: + codes = ["UNKNOWN"] + + # Calculate time gap from previous admission (hours) + time_gap = ( + 0.0 + if previous_admit is None + else (admit_time - previous_admit).total_seconds() / 3600.0 + ) + previous_admit = admit_time + + diagnoses_sequences.append(codes) + diagnoses_times.append(time_gap) + + # Get lab data for this admission + try: + lab_df = patient.get_events( + event_type="labevents", + start=admit_time, + end=info.get("discharge"), + return_df=True, + ) + except Exception: + lab_df = None + + lab_sequences.append(self._build_lab_vector(lab_df)) + lab_times.append(time_gap) + + # Ensure we have at least one sequence entry + if not diagnoses_sequences: + diagnoses_sequences = [["UNKNOWN"]] + diagnoses_times = [0.0] + lab_sequences = [[math.nan] * len(self.LAB_CATEGORY_ORDER)] + lab_times = [0.0] + + # Create sample in StageNet format + sample: Dict[str, Any] = { + "patient_id": patient.patient_id, + "record_id": patient.patient_id, + "diagnoses": (diagnoses_times, diagnoses_sequences), + "labs": (lab_times, lab_sequences), + "label": int(has_dka_within_window), + } + + return [sample] + diff --git a/tests/core/test_mimic4_dka.py b/tests/core/test_mimic4_dka.py new file mode 100644 index 000000000..79e3a5105 --- /dev/null +++ b/tests/core/test_mimic4_dka.py @@ -0,0 +1,240 @@ +import unittest +import os +from pathlib import Path + +from pyhealth.datasets import MIMIC4Dataset +from pyhealth.tasks.dka import DKAPredictionMIMIC4 + + +class TestMIMIC4DKAPrediction(unittest.TestCase): + """Test MIMIC-4 DKA prediction task 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 MIMIC-IV demo dataset in test resources.""" + # Get the path to the test-resources/core/mimic4demo directory + test_dir = Path(__file__).parent.parent + self.demo_dataset_path = str( + test_dir / "test-resources" / "core" / "mimic4demo" + ) + + print(f"\n{'='*60}") + print(f"Setting up MIMIC-IV demo dataset for DKA prediction") + 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"MIMIC-IV demo dataset not found at {self.demo_dataset_path}" + ) + + # List files in the hosp directory + hosp_path = os.path.join(self.demo_dataset_path, "hosp") + if os.path.exists(hosp_path): + files = os.listdir(hosp_path) + print(f"Found {len(files)} files in hosp directory:") + for f in sorted(files): + file_path = os.path.join(hosp_path, f) + size = os.path.getsize(file_path) / 1024 # KB + print(f" - {f} ({size:.1f} KB)") + print(f"{'='*60}\n") + + def _load_dataset(self): + """Load the dataset for testing.""" + tables = ["diagnoses_icd", "procedures_icd", "prescriptions", "labevents"] + print(f"Loading MIMIC4Dataset with tables: {tables}") + self.dataset = MIMIC4Dataset(root=self.demo_dataset_path, tables=tables) + print(f"✓ Dataset loaded successfully") + print(f" Total patients: {len(self.dataset.patients)}") + print() + + def test_dataset_stats(self): + """Test that the dataset loads correctly and stats() works.""" + print(f"\n{'='*60}") + print("TEST: test_dataset_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_dka_prediction_task_initialization(self): + """Test DKAPredictionMIMIC4 task initialization.""" + print(f"\n{'='*60}") + print("TEST: test_dka_prediction_task_initialization()") + print(f"{'='*60}") + + # Test default initialization + print("Testing default initialization...") + task = DKAPredictionMIMIC4() + self.assertEqual(task.task_name, "DKAPredictionMIMIC4") + self.assertEqual(task.dka_window_days, 90) + self.assertEqual(task.padding, 0) + self.assertIn("diagnoses", task.input_schema) + self.assertIn("labs", task.input_schema) + self.assertIn("label", task.output_schema) + print(f"✓ Default task initialized: {task.task_name}") + print(f" DKA window: {task.dka_window_days} days") + print(f" Input schema: {list(task.input_schema.keys())}") + print(f" Output schema: {list(task.output_schema.keys())}") + + # Test custom initialization + print("\nTesting custom initialization...") + custom_task = DKAPredictionMIMIC4(dka_window_days=30, padding=5) + self.assertEqual(custom_task.dka_window_days, 30) + self.assertEqual(custom_task.padding, 5) + print(f"✓ Custom task initialized with window={custom_task.dka_window_days}, padding={custom_task.padding}") + + def test_dka_prediction_class_variables(self): + """Test that class variables are properly defined.""" + print(f"\n{'='*60}") + print("TEST: test_dka_prediction_class_variables()") + print(f"{'='*60}") + + # Test T1DM codes + self.assertEqual(DKAPredictionMIMIC4.T1DM_ICD10_PREFIX, "E10") + self.assertIn("25001", DKAPredictionMIMIC4.T1DM_ICD9_CODES) + print(f"✓ T1DM ICD-10 prefix: {DKAPredictionMIMIC4.T1DM_ICD10_PREFIX}") + print(f"✓ T1DM ICD-9 codes: {len(DKAPredictionMIMIC4.T1DM_ICD9_CODES)} codes") + + # Test DKA codes + self.assertEqual(DKAPredictionMIMIC4.DKA_ICD10_PREFIX, "E101") + self.assertIn("25011", DKAPredictionMIMIC4.DKA_ICD9_CODES) + print(f"✓ DKA ICD-10 prefix: {DKAPredictionMIMIC4.DKA_ICD10_PREFIX}") + print(f"✓ DKA ICD-9 codes: {len(DKAPredictionMIMIC4.DKA_ICD9_CODES)} codes") + + # Test lab categories + self.assertEqual(len(DKAPredictionMIMIC4.LAB_CATEGORY_ORDER), 6) + expected_categories = ["glucose", "bicarbonate", "anion_gap", "potassium", "sodium", "chloride"] + self.assertEqual(DKAPredictionMIMIC4.LAB_CATEGORY_ORDER, expected_categories) + print(f"✓ Lab categories: {DKAPredictionMIMIC4.LAB_CATEGORY_ORDER}") + print(f"✓ Total lab item IDs: {len(DKAPredictionMIMIC4.ALL_LAB_ITEMIDS)}") + + def test_dka_prediction_set_task(self): + """Test DKAPredictionMIMIC4 task with set_task() method.""" + print(f"\n{'='*60}") + print("TEST: test_dka_prediction_set_task()") + print(f"{'='*60}") + + print("Initializing DKAPredictionMIMIC4 task...") + task = DKAPredictionMIMIC4() + + # Test using set_task method + try: + print("\nCalling dataset.set_task()...") + sample_dataset = self.dataset.set_task(task) + self.assertIsNotNone(sample_dataset, "set_task should return a dataset") + self.assertTrue( + hasattr(sample_dataset, "samples"), "Sample dataset should have samples" + ) + print(f"✓ set_task() completed") + + # Check sample count + num_samples = len(sample_dataset.samples) + print(f"✓ Generated {num_samples} DKA prediction samples") + + if num_samples > 0: + sample = sample_dataset.samples[0] + required_keys = ["patient_id", "record_id", "diagnoses", "labs", "label"] + + print(f"\nFirst sample structure:") + print(f" Sample keys: {list(sample.keys())}") + + for key in required_keys: + self.assertIn(key, sample, f"Sample should contain key: {key}") + + # Verify diagnoses format (tuple of times and sequences) + diagnoses = sample["diagnoses"] + self.assertIsInstance(diagnoses, tuple, "diagnoses should be a tuple") + self.assertEqual(len(diagnoses), 2, "diagnoses tuple should have 2 elements") + print(f" - diagnoses: {len(diagnoses[1])} admission(s)") + + # Verify labs format (tuple of times and sequences) + labs = sample["labs"] + self.assertIsInstance(labs, tuple, "labs should be a tuple") + self.assertEqual(len(labs), 2, "labs tuple should have 2 elements") + print(f" - labs: {len(labs[1])} lab vector(s)") + + # Verify label is binary + self.assertIn(sample["label"], [0, 1], "Label should be binary (0 or 1)") + print(f" - label: {sample['label']}") + + # Count label distribution + label_counts = {0: 0, 1: 0} + for s in sample_dataset.samples: + label_counts[s["label"]] += 1 + + print(f"\nLabel distribution:") + print(f" - No DKA (0): {label_counts[0]} ({label_counts[0]/num_samples*100:.1f}%)") + print(f" - Has DKA (1): {label_counts[1]} ({label_counts[1]/num_samples*100:.1f}%)") + + print(f"\n✓ test_dka_prediction_set_task() passed successfully") + + except Exception as e: + print(f"✗ Failed with error: {e}") + import traceback + traceback.print_exc() + self.fail(f"Failed to use set_task with DKAPredictionMIMIC4: {e}") + + def test_dka_prediction_helper_methods(self): + """Test helper methods of DKAPredictionMIMIC4.""" + print(f"\n{'='*60}") + print("TEST: test_dka_prediction_helper_methods()") + print(f"{'='*60}") + + task = DKAPredictionMIMIC4() + + # Test _normalize_icd + print("Testing _normalize_icd()...") + self.assertEqual(task._normalize_icd("E10.10"), "E1010") + self.assertEqual(task._normalize_icd("e10.10"), "E1010") + self.assertEqual(task._normalize_icd(None), "") + self.assertEqual(task._normalize_icd(" 25001 "), "25001") + print("✓ _normalize_icd() works correctly") + + # Test _is_t1dm_code + print("\nTesting _is_t1dm_code()...") + self.assertTrue(task._is_t1dm_code("E10.10", 10)) + self.assertTrue(task._is_t1dm_code("E1010", "10")) + self.assertTrue(task._is_t1dm_code("25001", 9)) + self.assertTrue(task._is_t1dm_code("25001", "9")) + self.assertFalse(task._is_t1dm_code("E11.0", 10)) # Type 2 + self.assertFalse(task._is_t1dm_code("25000", 9)) # Type 2 + self.assertFalse(task._is_t1dm_code(None, 10)) + print("✓ _is_t1dm_code() works correctly") + + # Test _is_dka_code + print("\nTesting _is_dka_code()...") + self.assertTrue(task._is_dka_code("E10.10", 10)) + self.assertTrue(task._is_dka_code("E1011", "10")) + self.assertTrue(task._is_dka_code("25011", 9)) + self.assertTrue(task._is_dka_code("25013", "9")) + self.assertFalse(task._is_dka_code("E10.65", 10)) # Not DKA + self.assertFalse(task._is_dka_code(None, 10)) + print("✓ _is_dka_code() works correctly") + + # Test _deduplicate_preserve_order + print("\nTesting _deduplicate_preserve_order()...") + self.assertEqual( + task._deduplicate_preserve_order(["A", "B", "A", "C", "B"]), + ["A", "B", "C"] + ) + self.assertEqual( + task._deduplicate_preserve_order([]), + [] + ) + print("✓ _deduplicate_preserve_order() works correctly") + + print(f"\n✓ test_dka_prediction_helper_methods() passed successfully") + + +if __name__ == "__main__": + unittest.main() + diff --git a/tests/core/test_mimic4_los.py b/tests/core/test_mimic4_los.py new file mode 100644 index 000000000..9745d5ab4 --- /dev/null +++ b/tests/core/test_mimic4_los.py @@ -0,0 +1,179 @@ +import unittest +import os +from pathlib import Path + +from pyhealth.datasets import MIMIC4Dataset +from pyhealth.tasks.length_of_stay_prediction import LengthOfStayPredictionMIMIC4 + + +class TestMIMIC4LengthOfStayPrediction(unittest.TestCase): + """Test MIMIC-4 length of stay prediction task 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 MIMIC-IV demo dataset in test resources.""" + # Get the path to the test-resources/core/mimic4demo directory + test_dir = Path(__file__).parent.parent + self.demo_dataset_path = str( + test_dir / "test-resources" / "core" / "mimic4demo" + ) + + print(f"\n{'='*60}") + print(f"Setting up MIMIC-IV demo dataset for length of stay prediction") + 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"MIMIC-IV demo dataset not found at {self.demo_dataset_path}" + ) + + # List files in the hosp directory + hosp_path = os.path.join(self.demo_dataset_path, "hosp") + if os.path.exists(hosp_path): + files = os.listdir(hosp_path) + print(f"Found {len(files)} files in hosp directory:") + for f in sorted(files): + file_path = os.path.join(hosp_path, f) + size = os.path.getsize(file_path) / 1024 # KB + print(f" - {f} ({size:.1f} KB)") + print(f"{'='*60}\n") + + def _load_dataset(self): + """Load the dataset for testing.""" + tables = ["diagnoses_icd", "procedures_icd", "prescriptions"] + print(f"Loading MIMIC4Dataset with tables: {tables}") + self.dataset = MIMIC4Dataset(root=self.demo_dataset_path, tables=tables) + print(f"✓ Dataset loaded successfully") + print(f" Total patients: {len(self.dataset.patients)}") + print() + + def test_dataset_stats(self): + """Test that the dataset loads correctly and stats() works.""" + print(f"\n{'='*60}") + print("TEST: test_dataset_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_length_of_stay_prediction_mimic4_set_task(self): + """Test LengthOfStayPredictionMIMIC4 task with set_task() method.""" + print(f"\n{'='*60}") + print("TEST: test_length_of_stay_prediction_mimic4_set_task()") + print(f"{'='*60}") + + print("Initializing LengthOfStayPredictionMIMIC4 task...") + task = LengthOfStayPredictionMIMIC4() + + # Test that task is properly initialized + print(f"✓ Task initialized: {task.task_name}") + self.assertEqual(task.task_name, "LengthOfStayPredictionMIMIC4") + self.assertIn("conditions", task.input_schema) + self.assertIn("procedures", task.input_schema) + self.assertIn("drugs", task.input_schema) + self.assertIn("los", task.output_schema) + print(f" Input schema: {list(task.input_schema.keys())}") + print(f" Output schema: {list(task.output_schema.keys())}") + + # Test using set_task method + try: + print("\nCalling dataset.set_task()...") + sample_dataset = self.dataset.set_task(task) + self.assertIsNotNone(sample_dataset, "set_task should return a dataset") + self.assertTrue( + hasattr(sample_dataset, "samples"), "Sample dataset should have samples" + ) + print(f"✓ set_task() completed") + + # Verify we got some samples + num_samples = len(sample_dataset.samples) + self.assertGreater(num_samples, 0, "Should generate at least one sample") + print(f"✓ Generated {num_samples} length of stay prediction samples") + + # Test sample structure + if num_samples > 0: + sample = sample_dataset.samples[0] + required_keys = [ + "visit_id", + "patient_id", + "conditions", + "procedures", + "drugs", + "los", + ] + + print(f"\nFirst sample structure:") + print(f" Sample keys: {list(sample.keys())}") + + for key in required_keys: + self.assertIn(key, sample, f"Sample should contain key: {key}") + if key in ["conditions", "procedures", "drugs"]: + print(f" - {key}: {len(sample[key])} items") + else: + print(f" - {key}: {sample[key]}") + + # Verify los label is in valid range (0-9 for 10 categories) + self.assertIn( + sample["los"], + list(range(10)), + "Length of stay category should be 0-9", + ) + + # Verify conditions include icd_version prefix (MIMIC-4 specific) + if sample["conditions"]: + first_condition = sample["conditions"][0] + self.assertIn( + "_", + first_condition, + "MIMIC-4 conditions should include version prefix (e.g., '10_E1010')", + ) + print(f" Sample condition format: {first_condition}") + + # Count LOS distribution + los_counts = {i: 0 for i in range(10)} + for s in sample_dataset.samples: + los_counts[s["los"]] += 1 + + print(f"\nLength of stay category distribution:") + category_labels = [ + "< 1 day", + "1 day", + "2 days", + "3 days", + "4 days", + "5 days", + "6 days", + "7 days", + "1-2 weeks", + "> 2 weeks", + ] + for i in range(10): + if los_counts[i] > 0: + pct = los_counts[i] / num_samples * 100 + print( + f" Category {i} ({category_labels[i]}): {los_counts[i]} ({pct:.1f}%)" + ) + + print( + f"\n✓ test_length_of_stay_prediction_mimic4_set_task() passed successfully" + ) + + except Exception as e: + print(f"✗ Failed with error: {e}") + import traceback + traceback.print_exc() + self.fail(f"Failed to use set_task with LengthOfStayPredictionMIMIC4: {e}") + + +if __name__ == "__main__": + unittest.main() + From d1a572c1501884caf19cf5c249b470c29a517054 Mon Sep 17 00:00:00 2001 From: John Wu Date: Mon, 22 Dec 2025 20:21:57 -0600 Subject: [PATCH 2/4] make example simpelr --- examples/clinical_tasks/dka_mimic4.py | 216 +----------------- .../core/mimic4demo/hosp/admissions.csv | 17 ++ .../core/mimic4demo/hosp/d_labitems.csv | 20 ++ .../core/mimic4demo/hosp/diagnoses_icd.csv | 46 ++++ .../core/mimic4demo/hosp/labevents.csv | 70 ++++++ .../core/mimic4demo/hosp/patients.csv | 12 + .../core/mimic4demo/hosp/prescriptions.csv | 26 +++ .../core/mimic4demo/hosp/procedures_icd.csv | 23 ++ 8 files changed, 218 insertions(+), 212 deletions(-) create mode 100644 test-resources/core/mimic4demo/hosp/admissions.csv create mode 100644 test-resources/core/mimic4demo/hosp/d_labitems.csv create mode 100644 test-resources/core/mimic4demo/hosp/diagnoses_icd.csv create mode 100644 test-resources/core/mimic4demo/hosp/labevents.csv create mode 100644 test-resources/core/mimic4demo/hosp/patients.csv create mode 100644 test-resources/core/mimic4demo/hosp/prescriptions.csv create mode 100644 test-resources/core/mimic4demo/hosp/procedures_icd.csv diff --git a/examples/clinical_tasks/dka_mimic4.py b/examples/clinical_tasks/dka_mimic4.py index d17201978..64c6081fb 100644 --- a/examples/clinical_tasks/dka_mimic4.py +++ b/examples/clinical_tasks/dka_mimic4.py @@ -6,7 +6,6 @@ 2. Applying the DKAPredictionMIMIC4 task 3. Creating a SampleDataset with StageNet processors 4. Training a StageNet model for DKA prediction -5. Testing with synthetic hold-out set (unseen codes, varying lengths) Target Population: - Patients with Type 1 Diabetes Mellitus (T1DM) @@ -14,15 +13,12 @@ """ import os -import random -import numpy as np import torch from pyhealth.datasets import ( MIMIC4Dataset, get_dataloader, split_by_patient, - SampleDataset, ) from pyhealth.datasets.utils import save_processors, load_processors from pyhealth.models import StageNet @@ -30,161 +26,13 @@ from pyhealth.trainer import Trainer -def generate_holdout_set( - sample_dataset: SampleDataset, num_samples: int = 10, seed: int = 42 -) -> SampleDataset: - """Generate synthetic hold-out set with unseen codes and varying lengths. - - This function creates synthetic samples to test the processor's ability to: - 1. Handle completely unseen tokens (mapped to ) - 2. Handle sequence lengths larger than training but within padding - - Args: - sample_dataset: Original SampleDataset with fitted processors - num_samples: Number of synthetic samples to generate - seed: Random seed for reproducibility - - Returns: - SampleDataset with synthetic samples using fitted processors - """ - random.seed(seed) - np.random.seed(seed) - - # Get the fitted processors - diagnoses_processor = sample_dataset.input_processors["diagnoses"] - - # Get max nested length from diagnoses processor - max_diag_len = diagnoses_processor._max_nested_len - # Handle both old and new processor versions - padding = getattr(diagnoses_processor, "_padding", 0) - - print("\n=== Hold-out Set Generation ===") - print(f"Diagnoses max nested length: {max_diag_len}") - print(f"Padding: {padding}") - print(f"Observed max (without padding): {max_diag_len - padding}") - - synthetic_samples = [] - - # DKA-relevant ICD codes for synthetic samples - synthetic_t1dm_codes = [ - "E1010", "E1011", "E1065", "E1100", "E1122", - "25001", "25003", "25011", "25013", - ] - synthetic_other_codes = [ - "I10", "N179", "J189", "K219", "R509", "I509", - ] - - for i in range(num_samples): - # Generate random number of visits (1-5) - num_visits = random.randint(1, 5) - - # Generate diagnosis codes - diagnoses_list = [] - diagnoses_times_list = [] - - for visit_idx in range(num_visits): - # Generate sequence length - observed_max = max_diag_len - padding - seq_len = random.randint(max(1, observed_max - 2), max(observed_max, 3)) - - # Mix of known and unseen codes - visit_codes = [] - for j in range(seq_len): - if random.random() < 0.3: - # 30% chance of T1DM-related code - visit_codes.append(random.choice(synthetic_t1dm_codes)) - elif random.random() < 0.5: - # 35% chance of other known code - visit_codes.append(random.choice(synthetic_other_codes)) - else: - # 35% chance of unseen code - visit_codes.append(f"NEWCODE_{i}_{visit_idx}_{j}") - - diagnoses_list.append(visit_codes) - - # Generate time intervals (hours from previous visit) - if visit_idx == 0: - diagnoses_times_list.append(0.0) - else: - diagnoses_times_list.append(random.uniform(24.0, 720.0)) - - # Generate lab data (6-dimensional vectors for DKA task) - # Categories: glucose, bicarbonate, anion_gap, potassium, sodium, chloride - num_lab_timestamps = random.randint(3, 10) - lab_values_list = [] - lab_times_list = [] - - for ts_idx in range(num_lab_timestamps): - # Generate 6D vector with realistic ranges - lab_vector = [] - # glucose (mg/dL) - lab_vector.append( - random.uniform(70.0, 500.0) if random.random() < 0.9 else None - ) - # bicarbonate (mEq/L) - lab_vector.append( - random.uniform(10.0, 30.0) if random.random() < 0.85 else None - ) - # anion_gap (mEq/L) - lab_vector.append( - random.uniform(8.0, 30.0) if random.random() < 0.7 else None - ) - # potassium (mEq/L) - lab_vector.append( - random.uniform(3.0, 6.5) if random.random() < 0.9 else None - ) - # sodium (mEq/L) - lab_vector.append( - random.uniform(130.0, 150.0) if random.random() < 0.9 else None - ) - # chloride (mEq/L) - lab_vector.append( - random.uniform(95.0, 110.0) if random.random() < 0.85 else None - ) - - lab_values_list.append(lab_vector) - lab_times_list.append(random.uniform(0.0, 48.0)) - - # Create sample in the expected format (before processing) - synthetic_sample = { - "patient_id": f"HOLDOUT_PATIENT_{i}", - "record_id": f"HOLDOUT_PATIENT_{i}", - "diagnoses": (diagnoses_times_list, diagnoses_list), - "labs": (lab_times_list, lab_values_list), - "label": random.randint(0, 1), - } - - synthetic_samples.append(synthetic_sample) - - # Create a new SampleDataset with the FITTED processors - holdout_dataset = SampleDataset( - samples=synthetic_samples, - input_schema=sample_dataset.input_schema, - output_schema=sample_dataset.output_schema, - dataset_name=f"{sample_dataset.dataset_name}_holdout", - task_name=sample_dataset.task_name, - input_processors=sample_dataset.input_processors, - output_processors=sample_dataset.output_processors, - ) - - print(f"Generated {len(holdout_dataset)} synthetic samples") - sample_seq_lens = [len(s["diagnoses"][1]) for s in synthetic_samples[:3]] - print(f"Sample diagnosis sequence lengths: {sample_seq_lens}") - sample_codes_per_visit = [ - [len(visit) for visit in s["diagnoses"][1]] for s in synthetic_samples[:3] - ] - print(f"Sample codes per visit: {sample_codes_per_visit}") - - return holdout_dataset - - def main(): """Main function to run DKA prediction pipeline.""" # Configuration MIMIC4_ROOT = "/srv/local/data/physionet.org/files/mimiciv/2.2/" - PROCESSOR_DIR = "../../output/processors/stagenet_dka_mimic4" - CACHE_DIR = "../../mimic4_dka_stagenet_cache" + PROCESSOR_DIR = "pyhealth/processors/stagenet_dka_mimic4" + CACHE_DIR = "pyhealth/cache/mimic4_dka_stagenet" DEVICE = "cuda:0" if torch.cuda.is_available() else "cpu" print("=" * 60) @@ -205,7 +53,7 @@ def main(): # dev=True, # Uncomment for faster development iteration ) - print(f"Dataset loaded with {len(base_dataset.patients)} patients") + print("Dataset initialized, proceeding to task processing...") # STEP 2: Apply DKA prediction task print("\n=== Step 2: Applying DKA Prediction Task ===") @@ -322,66 +170,10 @@ def main(): print(f"Predicted probabilities: {output['y_prob'][:5]}") print(f"True labels: {output['y_true'][:5]}") - # STEP 8: Test with synthetic hold-out set print("\n" + "=" * 60) - print("TESTING PROCESSOR ROBUSTNESS WITH SYNTHETIC HOLD-OUT SET") + print("DKA PREDICTION TRAINING COMPLETED!") print("=" * 60) - holdout_dataset = generate_holdout_set( - sample_dataset=sample_dataset, num_samples=50, seed=42 - ) - - holdout_loader = get_dataloader(holdout_dataset, batch_size=16, shuffle=False) - - # Inspect processed samples - print("\n=== Inspecting Processed Hold-out Samples ===") - holdout_batch = next(iter(holdout_loader)) - - print(f"Batch size: {len(holdout_batch['patient_id'])}") - print(f"Diagnoses tensor shape: {holdout_batch['diagnoses'][1].shape}") - - # Check for unknown tokens - diagnoses_processor = sample_dataset.input_processors["diagnoses"] - unk_token_idx = diagnoses_processor.code_vocab[""] - pad_token_idx = diagnoses_processor.code_vocab[""] - - print(f"\n token index: {unk_token_idx}") - print(f" token index: {pad_token_idx}") - - # Count unknown and padding tokens - diag_values = holdout_batch["diagnoses"][1] - num_unk = (diag_values == unk_token_idx).sum().item() - num_pad = (diag_values == pad_token_idx).sum().item() - total_tokens = diag_values.numel() - - print("\nToken statistics in hold-out batch:") - print(f" Total tokens: {total_tokens}") - print(f" Unknown tokens: {num_unk} ({100*num_unk/total_tokens:.1f}%)") - print(f" Padding tokens: {num_pad} ({100*num_pad/total_tokens:.1f}%)") - - # Run model inference on hold-out set - print("\n=== Model Inference on Hold-out Set ===") - with torch.no_grad(): - holdout_output = model(**holdout_batch) - - print(f"Predictions shape: {holdout_output['y_prob'].shape}") - print(f"Sample predictions: {holdout_output['y_prob'][:5]}") - - print("\n" + "=" * 60) - print("HOLD-OUT SET TEST COMPLETED SUCCESSFULLY!") - print("=" * 60) - - # STEP 9: Processor information - print("\n=== Processor Information ===") - print(f"Processors saved at: {PROCESSOR_DIR}") - print(f"\nDiagnoses Processor:") - print(f" Vocabulary size: {diagnoses_processor.size()}") - print(f" Max nested length: {diagnoses_processor._max_nested_len}") - - labs_processor = sample_dataset.input_processors["labs"] - print(f"\nLabs Processor:") - print(f" Feature dimension: {labs_processor.size}") - return results diff --git a/test-resources/core/mimic4demo/hosp/admissions.csv b/test-resources/core/mimic4demo/hosp/admissions.csv new file mode 100644 index 000000000..c5cf4a8f6 --- /dev/null +++ b/test-resources/core/mimic4demo/hosp/admissions.csv @@ -0,0 +1,17 @@ +subject_id,hadm_id,admittime,dischtime,admission_type,admission_location,insurance,language,marital_status,race,discharge_location,hospital_expire_flag +10001,20001,2150-03-15 08:00:00,2150-03-18 14:00:00,ELECTIVE,PHYSICIAN REFERRAL,Medicare,ENGLISH,MARRIED,WHITE,HOME,0 +10001,20002,2150-06-20 10:30:00,2150-06-25 16:00:00,EMERGENCY,EMERGENCY ROOM,Medicare,ENGLISH,MARRIED,WHITE,HOME,0 +10002,20003,2151-01-10 07:00:00,2151-01-12 11:00:00,URGENT,TRANSFER FROM HOSPITAL,Medicaid,ENGLISH,SINGLE,BLACK,HOME,0 +10002,20004,2151-04-05 14:00:00,2151-04-20 09:00:00,EMERGENCY,EMERGENCY ROOM,Medicaid,ENGLISH,SINGLE,BLACK,REHAB,0 +10003,20005,2152-02-28 09:00:00,2152-03-05 15:00:00,EMERGENCY,EMERGENCY ROOM,Medicare,ENGLISH,WIDOWED,WHITE,HOME,0 +10003,20006,2152-08-10 11:00:00,2152-08-15 08:00:00,EMERGENCY,EMERGENCY ROOM,Medicare,ENGLISH,WIDOWED,WHITE,DIED,1 +10004,20007,2150-05-01 06:00:00,2150-05-02 10:00:00,ELECTIVE,PHYSICIAN REFERRAL,Private,SPANISH,MARRIED,HISPANIC,HOME,0 +10005,20008,2151-07-15 08:30:00,2151-07-22 12:00:00,EMERGENCY,EMERGENCY ROOM,Medicaid,ENGLISH,SINGLE,WHITE,HOME,0 +10006,20009,2152-09-01 10:00:00,2152-09-08 14:00:00,URGENT,CLINIC REFERRAL,Medicare,ENGLISH,DIVORCED,ASIAN,HOME,0 +10006,20010,2152-11-15 07:00:00,2152-11-18 16:00:00,EMERGENCY,EMERGENCY ROOM,Medicare,ENGLISH,DIVORCED,ASIAN,HOME,0 +10007,20011,2150-04-10 09:00:00,2150-04-11 11:00:00,ELECTIVE,PHYSICIAN REFERRAL,Private,ENGLISH,MARRIED,WHITE,HOME,0 +10008,20012,2151-10-05 08:00:00,2151-10-25 10:00:00,EMERGENCY,EMERGENCY ROOM,Medicare,ENGLISH,WIDOWED,WHITE,SKILLED NURSING FACILITY,0 +10008,20013,2151-12-15 06:00:00,2151-12-20 09:00:00,EMERGENCY,EMERGENCY ROOM,Medicare,ENGLISH,WIDOWED,WHITE,DIED,1 +10009,20014,2152-03-20 07:30:00,2152-03-23 14:00:00,URGENT,TRANSFER FROM HOSPITAL,Medicaid,ENGLISH,SINGLE,BLACK,HOME,0 +10010,20015,2150-08-01 10:00:00,2150-08-05 15:00:00,EMERGENCY,EMERGENCY ROOM,Private,ENGLISH,MARRIED,WHITE,HOME,0 + diff --git a/test-resources/core/mimic4demo/hosp/d_labitems.csv b/test-resources/core/mimic4demo/hosp/d_labitems.csv new file mode 100644 index 000000000..868e4d9d2 --- /dev/null +++ b/test-resources/core/mimic4demo/hosp/d_labitems.csv @@ -0,0 +1,20 @@ +itemid,label,fluid,category +50809,Glucose,Blood,Chemistry +50931,Glucose,Blood,Chemistry +52027,Glucose,Blood,Chemistry +52569,Glucose,Blood,Chemistry +50803,Calculated Bicarbonate,Blood,Blood Gas +50804,Calculated Total CO2,Blood,Blood Gas +51084,Bicarbonate,Blood,Chemistry +50868,Anion Gap,Blood,Chemistry +50822,Potassium,Blood,Chemistry +50971,Potassium,Blood,Chemistry +52452,Potassium,Blood,Chemistry +52510,Potassium,Blood,Chemistry +50824,Sodium,Blood,Chemistry +50983,Sodium,Blood,Chemistry +52455,Sodium,Blood,Chemistry +50806,Chloride,Blood,Chemistry +50902,Chloride,Blood,Chemistry +52434,Chloride,Blood,Chemistry + diff --git a/test-resources/core/mimic4demo/hosp/diagnoses_icd.csv b/test-resources/core/mimic4demo/hosp/diagnoses_icd.csv new file mode 100644 index 000000000..7b55d8223 --- /dev/null +++ b/test-resources/core/mimic4demo/hosp/diagnoses_icd.csv @@ -0,0 +1,46 @@ +subject_id,hadm_id,seq_num,icd_code,icd_version +10001,20001,1,E1010,10 +10001,20001,2,E1165,10 +10001,20001,3,I10,10 +10001,20002,1,E1011,10 +10001,20002,2,E1065,10 +10001,20002,3,N179,10 +10002,20003,1,E1100,10 +10002,20003,2,I10,10 +10002,20004,1,E1100,10 +10002,20004,2,J189,10 +10002,20004,3,N390,10 +10003,20005,1,E1010,10 +10003,20005,2,E1065,10 +10003,20005,3,I10,10 +10003,20006,1,E1011,10 +10003,20006,2,E1065,10 +10003,20006,3,N170,10 +10003,20006,4,I509,10 +10004,20007,1,K219,10 +10004,20007,2,I10,10 +10005,20008,1,25001,9 +10005,20008,2,25011,9 +10005,20008,3,4019,9 +10005,20008,4,5849,9 +10006,20009,1,E1100,10 +10006,20009,2,E1122,10 +10006,20009,3,I10,10 +10006,20010,1,E1100,10 +10006,20010,2,J441,10 +10007,20011,1,J069,10 +10007,20011,2,R509,10 +10008,20012,1,25003,9 +10008,20012,2,25013,9 +10008,20012,3,4280,9 +10008,20012,4,5859,9 +10008,20013,1,25003,9 +10008,20013,2,25013,9 +10008,20013,3,5849,9 +10009,20014,1,E119,10 +10009,20014,2,I10,10 +10009,20014,3,E785,10 +10010,20015,1,E1010,10 +10010,20015,2,E1065,10 +10010,20015,3,I10,10 + diff --git a/test-resources/core/mimic4demo/hosp/labevents.csv b/test-resources/core/mimic4demo/hosp/labevents.csv new file mode 100644 index 000000000..7aa9406ee --- /dev/null +++ b/test-resources/core/mimic4demo/hosp/labevents.csv @@ -0,0 +1,70 @@ +subject_id,hadm_id,itemid,charttime,storetime,value,valuenum,valueuom,flag +10001,20001,50809,2150-03-15 10:00:00,2150-03-15 10:30:00,285,285.0,mg/dL,abnormal +10001,20001,50803,2150-03-15 10:00:00,2150-03-15 10:30:00,18,18.0,mEq/L,abnormal +10001,20001,50868,2150-03-15 10:00:00,2150-03-15 10:30:00,16,16.0,mEq/L,abnormal +10001,20001,50822,2150-03-15 10:00:00,2150-03-15 10:30:00,4.8,4.8,mEq/L, +10001,20001,50824,2150-03-15 10:00:00,2150-03-15 10:30:00,140,140.0,mEq/L, +10001,20001,50806,2150-03-15 10:00:00,2150-03-15 10:30:00,102,102.0,mEq/L, +10001,20002,50809,2150-06-20 12:00:00,2150-06-20 12:30:00,420,420.0,mg/dL,abnormal +10001,20002,50803,2150-06-20 12:00:00,2150-06-20 12:30:00,12,12.0,mEq/L,abnormal +10001,20002,50868,2150-06-20 12:00:00,2150-06-20 12:30:00,22,22.0,mEq/L,abnormal +10001,20002,50822,2150-06-20 12:00:00,2150-06-20 12:30:00,5.5,5.5,mEq/L,abnormal +10001,20002,50824,2150-06-20 12:00:00,2150-06-20 12:30:00,138,138.0,mEq/L, +10001,20002,50806,2150-06-20 12:00:00,2150-06-20 12:30:00,104,104.0,mEq/L, +10002,20003,50809,2151-01-10 09:00:00,2151-01-10 09:30:00,145,145.0,mg/dL,abnormal +10002,20003,50803,2151-01-10 09:00:00,2151-01-10 09:30:00,24,24.0,mEq/L, +10002,20003,50822,2151-01-10 09:00:00,2151-01-10 09:30:00,4.2,4.2,mEq/L, +10002,20003,50824,2151-01-10 09:00:00,2151-01-10 09:30:00,142,142.0,mEq/L, +10002,20004,50809,2151-04-06 08:00:00,2151-04-06 08:30:00,180,180.0,mg/dL,abnormal +10002,20004,50803,2151-04-06 08:00:00,2151-04-06 08:30:00,22,22.0,mEq/L, +10002,20004,50822,2151-04-06 08:00:00,2151-04-06 08:30:00,3.9,3.9,mEq/L, +10003,20005,50809,2152-02-28 11:00:00,2152-02-28 11:30:00,350,350.0,mg/dL,abnormal +10003,20005,50803,2152-02-28 11:00:00,2152-02-28 11:30:00,15,15.0,mEq/L,abnormal +10003,20005,50868,2152-02-28 11:00:00,2152-02-28 11:30:00,18,18.0,mEq/L,abnormal +10003,20005,50822,2152-02-28 11:00:00,2152-02-28 11:30:00,5.2,5.2,mEq/L, +10003,20005,50824,2152-02-28 11:00:00,2152-02-28 11:30:00,136,136.0,mEq/L, +10003,20005,50806,2152-02-28 11:00:00,2152-02-28 11:30:00,100,100.0,mEq/L, +10003,20006,50809,2152-08-10 13:00:00,2152-08-10 13:30:00,550,550.0,mg/dL,abnormal +10003,20006,50803,2152-08-10 13:00:00,2152-08-10 13:30:00,8,8.0,mEq/L,abnormal +10003,20006,50868,2152-08-10 13:00:00,2152-08-10 13:30:00,28,28.0,mEq/L,abnormal +10003,20006,50822,2152-08-10 13:00:00,2152-08-10 13:30:00,6.2,6.2,mEq/L,abnormal +10003,20006,50824,2152-08-10 13:00:00,2152-08-10 13:30:00,132,132.0,mEq/L, +10003,20006,50806,2152-08-10 13:00:00,2152-08-10 13:30:00,98,98.0,mEq/L, +10004,20007,50809,2150-05-01 08:00:00,2150-05-01 08:30:00,95,95.0,mg/dL, +10004,20007,50803,2150-05-01 08:00:00,2150-05-01 08:30:00,26,26.0,mEq/L, +10004,20007,50822,2150-05-01 08:00:00,2150-05-01 08:30:00,4.0,4.0,mEq/L, +10005,20008,50809,2151-07-15 10:00:00,2151-07-15 10:30:00,380,380.0,mg/dL,abnormal +10005,20008,50803,2151-07-15 10:00:00,2151-07-15 10:30:00,14,14.0,mEq/L,abnormal +10005,20008,50868,2151-07-15 10:00:00,2151-07-15 10:30:00,20,20.0,mEq/L,abnormal +10005,20008,50822,2151-07-15 10:00:00,2151-07-15 10:30:00,5.8,5.8,mEq/L,abnormal +10005,20008,50824,2151-07-15 10:00:00,2151-07-15 10:30:00,134,134.0,mEq/L, +10005,20008,50806,2151-07-15 10:00:00,2151-07-15 10:30:00,96,96.0,mEq/L, +10006,20009,50809,2152-09-01 12:00:00,2152-09-01 12:30:00,165,165.0,mg/dL,abnormal +10006,20009,50803,2152-09-01 12:00:00,2152-09-01 12:30:00,25,25.0,mEq/L, +10006,20009,50822,2152-09-01 12:00:00,2152-09-01 12:30:00,4.1,4.1,mEq/L, +10006,20009,50824,2152-09-01 12:00:00,2152-09-01 12:30:00,141,141.0,mEq/L, +10006,20010,50809,2152-11-15 09:00:00,2152-11-15 09:30:00,155,155.0,mg/dL,abnormal +10006,20010,50803,2152-11-15 09:00:00,2152-11-15 09:30:00,23,23.0,mEq/L, +10007,20011,50809,2150-04-10 11:00:00,2150-04-10 11:30:00,92,92.0,mg/dL, +10007,20011,50803,2150-04-10 11:00:00,2150-04-10 11:30:00,24,24.0,mEq/L, +10008,20012,50809,2151-10-05 10:00:00,2151-10-05 10:30:00,220,220.0,mg/dL,abnormal +10008,20012,50803,2151-10-05 10:00:00,2151-10-05 10:30:00,20,20.0,mEq/L, +10008,20012,50822,2151-10-05 10:00:00,2151-10-05 10:30:00,4.5,4.5,mEq/L, +10008,20012,50824,2151-10-05 10:00:00,2151-10-05 10:30:00,139,139.0,mEq/L, +10008,20013,50809,2151-12-15 08:00:00,2151-12-15 08:30:00,480,480.0,mg/dL,abnormal +10008,20013,50803,2151-12-15 08:00:00,2151-12-15 08:30:00,10,10.0,mEq/L,abnormal +10008,20013,50868,2151-12-15 08:00:00,2151-12-15 08:30:00,24,24.0,mEq/L,abnormal +10008,20013,50822,2151-12-15 08:00:00,2151-12-15 08:30:00,5.9,5.9,mEq/L,abnormal +10008,20013,50824,2151-12-15 08:00:00,2151-12-15 08:30:00,130,130.0,mEq/L, +10008,20013,50806,2151-12-15 08:00:00,2151-12-15 08:30:00,94,94.0,mEq/L, +10009,20014,50809,2152-03-20 09:00:00,2152-03-20 09:30:00,135,135.0,mg/dL,abnormal +10009,20014,50803,2152-03-20 09:00:00,2152-03-20 09:30:00,24,24.0,mEq/L, +10009,20014,50822,2152-03-20 09:00:00,2152-03-20 09:30:00,4.3,4.3,mEq/L, +10009,20014,50824,2152-03-20 09:00:00,2152-03-20 09:30:00,143,143.0,mEq/L, +10010,20015,50809,2150-08-01 12:00:00,2150-08-01 12:30:00,310,310.0,mg/dL,abnormal +10010,20015,50803,2150-08-01 12:00:00,2150-08-01 12:30:00,17,17.0,mEq/L,abnormal +10010,20015,50868,2150-08-01 12:00:00,2150-08-01 12:30:00,17,17.0,mEq/L,abnormal +10010,20015,50822,2150-08-01 12:00:00,2150-08-01 12:30:00,4.9,4.9,mEq/L, +10010,20015,50824,2150-08-01 12:00:00,2150-08-01 12:30:00,137,137.0,mEq/L, +10010,20015,50806,2150-08-01 12:00:00,2150-08-01 12:30:00,103,103.0,mEq/L, + diff --git a/test-resources/core/mimic4demo/hosp/patients.csv b/test-resources/core/mimic4demo/hosp/patients.csv new file mode 100644 index 000000000..ce1a83a5e --- /dev/null +++ b/test-resources/core/mimic4demo/hosp/patients.csv @@ -0,0 +1,12 @@ +subject_id,gender,anchor_age,anchor_year,anchor_year_group,dod +10001,M,45,2150,2017 - 2019, +10002,F,32,2151,2017 - 2019, +10003,M,58,2152,2017 - 2019,2152-08-15 +10004,F,67,2150,2017 - 2019, +10005,M,28,2151,2017 - 2019, +10006,F,55,2152,2017 - 2019, +10007,M,41,2150,2017 - 2019, +10008,F,73,2151,2017 - 2019,2151-12-20 +10009,M,35,2152,2017 - 2019, +10010,F,50,2150,2017 - 2019, + diff --git a/test-resources/core/mimic4demo/hosp/prescriptions.csv b/test-resources/core/mimic4demo/hosp/prescriptions.csv new file mode 100644 index 000000000..d14ecf7a1 --- /dev/null +++ b/test-resources/core/mimic4demo/hosp/prescriptions.csv @@ -0,0 +1,26 @@ +subject_id,hadm_id,starttime,stoptime,drug,ndc,prod_strength,dose_val_rx,dose_unit_rx,route +10001,20001,2150-03-15 09:00:00,2150-03-18 08:00:00,Insulin Glargine,00088221905,100 unit/mL,20,UNIT,SC +10001,20001,2150-03-15 09:00:00,2150-03-18 08:00:00,Metformin,00093101501,500 mg,500,MG,PO +10001,20002,2150-06-20 11:00:00,2150-06-25 15:00:00,Insulin Lispro,00002751001,100 unit/mL,10,UNIT,SC +10001,20002,2150-06-20 11:00:00,2150-06-25 15:00:00,Potassium Chloride,00338001404,20 mEq/100mL,20,MEQ,IV +10002,20003,2151-01-10 08:00:00,2151-01-12 10:00:00,Lisinopril,00185013301,10 mg,10,MG,PO +10002,20004,2151-04-05 15:00:00,2151-04-20 08:00:00,Ceftriaxone,00409727301,1 g,1,G,IV +10002,20004,2151-04-05 15:00:00,2151-04-20 08:00:00,Metformin,00093101501,500 mg,1000,MG,PO +10003,20005,2152-02-28 10:00:00,2152-03-05 14:00:00,Insulin Glargine,00088221905,100 unit/mL,25,UNIT,SC +10003,20006,2152-08-10 12:00:00,2152-08-15 07:00:00,Insulin Regular,00002821501,100 unit/mL,6,UNIT,IV +10003,20006,2152-08-10 12:00:00,2152-08-15 07:00:00,Sodium Bicarbonate,00264760020,8.4%,50,MEQ,IV +10004,20007,2150-05-01 07:00:00,2150-05-02 09:00:00,Omeprazole,00378603793,40 mg,40,MG,PO +10005,20008,2151-07-15 09:00:00,2151-07-22 11:00:00,Insulin NPH,00002851028,100 unit/mL,15,UNIT,SC +10005,20008,2151-07-15 09:00:00,2151-07-22 11:00:00,Normal Saline,00338004904,0.9%,1000,ML,IV +10006,20009,2152-09-01 11:00:00,2152-09-08 13:00:00,Metformin,00093101501,500 mg,500,MG,PO +10006,20009,2152-09-01 11:00:00,2152-09-08 13:00:00,Sitagliptin,00006027731,100 mg,100,MG,PO +10006,20010,2152-11-15 08:00:00,2152-11-18 15:00:00,Albuterol,00173068220,90 mcg/actuation,2,PUFF,INH +10007,20011,2150-04-10 10:00:00,2150-04-11 10:00:00,Azithromycin,00069307260,250 mg,500,MG,PO +10008,20012,2151-10-05 09:00:00,2151-10-25 09:00:00,Insulin Glargine,00088221905,100 unit/mL,30,UNIT,SC +10008,20012,2151-10-05 09:00:00,2151-10-25 09:00:00,Furosemide,00054822925,40 mg,40,MG,PO +10008,20013,2151-12-15 07:00:00,2151-12-20 08:00:00,Insulin Regular,00002821501,100 unit/mL,8,UNIT,IV +10009,20014,2152-03-20 08:00:00,2152-03-23 13:00:00,Metformin,00093101501,500 mg,1000,MG,PO +10009,20014,2152-03-20 08:00:00,2152-03-23 13:00:00,Atorvastatin,00378377710,20 mg,20,MG,PO +10010,20015,2150-08-01 11:00:00,2150-08-05 14:00:00,Insulin Lispro,00002751001,100 unit/mL,8,UNIT,SC +10010,20015,2150-08-01 11:00:00,2150-08-05 14:00:00,Potassium Chloride,00338001404,20 mEq/100mL,40,MEQ,IV + diff --git a/test-resources/core/mimic4demo/hosp/procedures_icd.csv b/test-resources/core/mimic4demo/hosp/procedures_icd.csv new file mode 100644 index 000000000..001fbf26e --- /dev/null +++ b/test-resources/core/mimic4demo/hosp/procedures_icd.csv @@ -0,0 +1,23 @@ +subject_id,hadm_id,seq_num,icd_code,icd_version +10001,20001,1,5A1955Z,10 +10001,20001,2,3E0G76Z,10 +10001,20002,1,5A1D70Z,10 +10002,20003,1,3E0234Z,10 +10002,20004,1,5A1935Z,10 +10002,20004,2,0BH17EZ,10 +10003,20005,1,5A1955Z,10 +10003,20006,1,5A1D70Z,10 +10003,20006,2,02HV33Z,10 +10004,20007,1,0DJ08ZZ,10 +10005,20008,1,5A1D70Z,10 +10005,20008,2,3991,9 +10006,20009,1,3E0G76Z,10 +10006,20010,1,5A09357,10 +10007,20011,1,3E0G76Z,10 +10008,20012,1,5A1D70Z,10 +10008,20012,2,9904,9 +10008,20013,1,5A1955Z,10 +10009,20014,1,3E0G76Z,10 +10010,20015,1,5A1955Z,10 +10010,20015,2,3E0G76Z,10 + From 1a99bf73431cee0ed06138bd514025bac87668fc Mon Sep 17 00:00:00 2001 From: John Wu Date: Wed, 24 Dec 2025 07:46:39 -0600 Subject: [PATCH 3/4] new updates to general population dka prediction --- examples/clinical_tasks/dka_mimic4.py | 54 ++-- examples/clinical_tasks/t1dka_mimic4.py | 185 +++++++++++ pyhealth/tasks/__init__.py | 2 +- pyhealth/tasks/dka.py | 413 +++++++++++++++++++++--- 4 files changed, 588 insertions(+), 66 deletions(-) create mode 100644 examples/clinical_tasks/t1dka_mimic4.py diff --git a/examples/clinical_tasks/dka_mimic4.py b/examples/clinical_tasks/dka_mimic4.py index 64c6081fb..e83f0dbbb 100644 --- a/examples/clinical_tasks/dka_mimic4.py +++ b/examples/clinical_tasks/dka_mimic4.py @@ -3,13 +3,16 @@ This example demonstrates: 1. Loading MIMIC-IV data with relevant tables for DKA prediction -2. Applying the DKAPredictionMIMIC4 task +2. Applying the DKAPredictionMIMIC4 task (general population) 3. Creating a SampleDataset with StageNet processors 4. Training a StageNet model for DKA prediction Target Population: - - Patients with Type 1 Diabetes Mellitus (T1DM) - - Predicts DKA occurrence within 90 days of T1DM diagnosis + - ALL patients in MIMIC-IV (no diabetes filtering) + - Much larger patient pool with more negative samples + - Label: 1 if patient has ANY DKA diagnosis, 0 otherwise + +Note: For T1DM-specific DKA prediction, see t1dka_mimic4.py """ import os @@ -27,16 +30,17 @@ def main(): - """Main function to run DKA prediction pipeline.""" + """Main function to run DKA prediction pipeline on general population.""" # Configuration MIMIC4_ROOT = "/srv/local/data/physionet.org/files/mimiciv/2.2/" - PROCESSOR_DIR = "pyhealth/processors/stagenet_dka_mimic4" - CACHE_DIR = "pyhealth/cache/mimic4_dka_stagenet" - DEVICE = "cuda:0" if torch.cuda.is_available() else "cpu" + DATASET_CACHE_DIR = "/shared/rsaas/pyhealth/cache/mimic4_dataset" + TASK_CACHE_DIR = "/shared/rsaas/pyhealth/cache/mimic4_dka_general_stagenet" + PROCESSOR_DIR = "/shared/rsaas/pyhealth/processors/stagenet_dka_general_mimic4" + DEVICE = "cuda:5" if torch.cuda.is_available() else "cpu" print("=" * 60) - print("DKA PREDICTION WITH STAGENET ON MIMIC-IV") + print("DKA PREDICTION (GENERAL POPULATION) WITH STAGENET ON MIMIC-IV") print("=" * 60) # STEP 1: Load MIMIC-IV base dataset @@ -44,27 +48,28 @@ def main(): base_dataset = MIMIC4Dataset( ehr_root=MIMIC4_ROOT, ehr_tables=[ - "patients", "admissions", "diagnoses_icd", "procedures_icd", "labevents", ], + cache_dir=DATASET_CACHE_DIR, # dev=True, # Uncomment for faster development iteration ) print("Dataset initialized, proceeding to task processing...") - # STEP 2: Apply DKA prediction task - print("\n=== Step 2: Applying DKA Prediction Task ===") + # STEP 2: Apply DKA prediction task (general population) + print("\n=== Step 2: Applying DKA Prediction Task (General Population) ===") - # Create task with 90-day DKA window and padding for unseen sequences - dka_task = DKAPredictionMIMIC4(dka_window_days=90, padding=20) + # Create task with padding for unseen sequences + # No T1DM filtering - includes ALL patients + dka_task = DKAPredictionMIMIC4(padding=10) print(f"Task: {dka_task.task_name}") - print(f"DKA window: {dka_task.dka_window_days} days") print(f"Input schema: {list(dka_task.input_schema.keys())}") print(f"Output schema: {list(dka_task.output_schema.keys())}") + print("Note: This includes ALL patients (not just diabetics)") # Check for pre-fitted processors if os.path.exists(os.path.join(PROCESSOR_DIR, "input_processors.pkl")): @@ -74,7 +79,7 @@ def main(): sample_dataset = base_dataset.set_task( dka_task, num_workers=4, - cache_dir=CACHE_DIR, + cache_dir=TASK_CACHE_DIR, input_processors=input_processors, output_processors=output_processors, ) @@ -83,7 +88,7 @@ def main(): sample_dataset = base_dataset.set_task( dka_task, num_workers=4, - cache_dir=CACHE_DIR, + cache_dir=TASK_CACHE_DIR, ) # Save processors for future runs @@ -95,19 +100,19 @@ def main(): # Count label distribution label_counts = {0: 0, 1: 0} - for sample in sample_dataset.samples: - label_counts[sample["label"]] += 1 + for sample in sample_dataset: + label_counts[int(sample["label"].item())] += 1 print(f"Label distribution:") print(f" No DKA (0): {label_counts[0]} ({100*label_counts[0]/len(sample_dataset):.1f}%)") print(f" Has DKA (1): {label_counts[1]} ({100*label_counts[1]/len(sample_dataset):.1f}%)") # Inspect a sample - sample = sample_dataset.samples[0] + sample = sample_dataset[0] print("\nSample structure:") print(f" Patient ID: {sample['patient_id']}") - print(f" Diagnoses: {len(sample['diagnoses'][1])} admission(s)") - print(f" Labs: {len(sample['labs'][0])} timestep(s)") + print(f" ICD codes (diagnoses + procedures): {sample['icd_codes'][1].shape} (visits x codes)") + print(f" Labs: {sample['labs'][0].shape} (timesteps x features)") print(f" Label: {sample['label']}") # STEP 3: Split dataset @@ -149,9 +154,9 @@ def main(): trainer.train( train_dataloader=train_loader, val_dataloader=val_loader, - epochs=20, + epochs=50, monitor="roc_auc", - optimizer_params={"lr": 1e-4}, + optimizer_params={"lr": 1e-5}, ) # STEP 6: Evaluate on test set @@ -171,7 +176,7 @@ def main(): print(f"True labels: {output['y_true'][:5]}") print("\n" + "=" * 60) - print("DKA PREDICTION TRAINING COMPLETED!") + print("DKA PREDICTION (GENERAL POPULATION) TRAINING COMPLETED!") print("=" * 60) return results @@ -179,4 +184,3 @@ def main(): if __name__ == "__main__": main() - diff --git a/examples/clinical_tasks/t1dka_mimic4.py b/examples/clinical_tasks/t1dka_mimic4.py new file mode 100644 index 000000000..9d3705650 --- /dev/null +++ b/examples/clinical_tasks/t1dka_mimic4.py @@ -0,0 +1,185 @@ +""" +Example of using StageNet for T1D DKA (Diabetic Ketoacidosis) prediction on MIMIC-IV. + +This example demonstrates: +1. Loading MIMIC-IV data with relevant tables for DKA prediction +2. Applying the T1DDKAPredictionMIMIC4 task +3. Creating a SampleDataset with StageNet processors +4. Training a StageNet model for DKA prediction + +Target Population: + - Patients with Type 1 Diabetes Mellitus (T1DM) ONLY + - Predicts DKA occurrence within 90 days of T1DM diagnosis + - Smaller, focused patient cohort +""" + +import os +import torch + +from pyhealth.datasets import ( + MIMIC4Dataset, + get_dataloader, + split_by_patient, +) +from pyhealth.datasets.utils import save_processors, load_processors +from pyhealth.models import StageNet +from pyhealth.tasks import T1DDKAPredictionMIMIC4 +from pyhealth.trainer import Trainer + + +def main(): + """Main function to run T1D DKA prediction pipeline.""" + + # Configuration + MIMIC4_ROOT = "/srv/local/data/physionet.org/files/mimiciv/2.2/" + DATASET_CACHE_DIR = "/shared/rsaas/pyhealth/cache/mimic4_dataset" + TASK_CACHE_DIR = "/shared/rsaas/pyhealth/cache/mimic4_t1d_dka_stagenet_v2" + PROCESSOR_DIR = "/shared/rsaas/pyhealth/processors/stagenet_t1d_dka_mimic4_v2" + DEVICE = "cuda:5" if torch.cuda.is_available() else "cpu" + + print("=" * 60) + print("T1D DKA PREDICTION WITH STAGENET ON MIMIC-IV") + print("=" * 60) + + # STEP 1: Load MIMIC-IV base dataset + print("\n=== Step 1: Loading MIMIC-IV Dataset ===") + base_dataset = MIMIC4Dataset( + ehr_root=MIMIC4_ROOT, + ehr_tables=[ + "admissions", + "diagnoses_icd", + "procedures_icd", + "labevents", + ], + cache_dir=DATASET_CACHE_DIR, + # dev=True, # Uncomment for faster development iteration + ) + + print("Dataset initialized, proceeding to task processing...") + + # STEP 2: Apply T1D DKA prediction task + print("\n=== Step 2: Applying T1D DKA Prediction Task ===") + + # Create task with 90-day DKA window and padding for unseen sequences + dka_task = T1DDKAPredictionMIMIC4(dka_window_days=90, padding=20) + + print(f"Task: {dka_task.task_name}") + print(f"DKA window: {dka_task.dka_window_days} days") + print(f"Input schema: {list(dka_task.input_schema.keys())}") + print(f"Output schema: {list(dka_task.output_schema.keys())}") + + # Check for pre-fitted processors + if os.path.exists(os.path.join(PROCESSOR_DIR, "input_processors.pkl")): + print("\nLoading pre-fitted processors...") + input_processors, output_processors = load_processors(PROCESSOR_DIR) + + sample_dataset = base_dataset.set_task( + dka_task, + num_workers=4, + cache_dir=TASK_CACHE_DIR, + input_processors=input_processors, + output_processors=output_processors, + ) + else: + print("\nFitting new processors...") + sample_dataset = base_dataset.set_task( + dka_task, + num_workers=4, + cache_dir=TASK_CACHE_DIR, + ) + + # Save processors for future runs + print("Saving processors...") + os.makedirs(PROCESSOR_DIR, exist_ok=True) + save_processors(sample_dataset, PROCESSOR_DIR) + + print(f"\nTotal samples: {len(sample_dataset)}") + + # Count label distribution + label_counts = {0: 0, 1: 0} + for sample in sample_dataset: + label_counts[int(sample["label"].item())] += 1 + + print(f"Label distribution:") + print(f" No DKA (0): {label_counts[0]} ({100*label_counts[0]/len(sample_dataset):.1f}%)") + print(f" Has DKA (1): {label_counts[1]} ({100*label_counts[1]/len(sample_dataset):.1f}%)") + + # Inspect a sample + sample = sample_dataset[0] + print("\nSample structure:") + print(f" Patient ID: {sample['patient_id']}") + print(f" ICD codes (diagnoses + procedures): {sample['icd_codes'][1].shape} (visits x codes)") + print(f" Labs: {sample['labs'][0].shape} (timesteps x features)") + print(f" Label: {sample['label']}") + + # STEP 3: Split dataset + print("\n=== Step 3: Splitting Dataset ===") + train_dataset, val_dataset, test_dataset = split_by_patient( + sample_dataset, [0.8, 0.1, 0.1] + ) + + print(f"Train: {len(train_dataset)} samples") + print(f"Validation: {len(val_dataset)} samples") + print(f"Test: {len(test_dataset)} samples") + + # Create dataloaders + train_loader = get_dataloader(train_dataset, batch_size=256, shuffle=True) + val_loader = get_dataloader(val_dataset, batch_size=256, shuffle=False) + test_loader = get_dataloader(test_dataset, batch_size=256, shuffle=False) + + # STEP 4: Initialize StageNet model + print("\n=== Step 4: Initializing StageNet Model ===") + model = StageNet( + dataset=sample_dataset, + embedding_dim=128, + chunk_size=128, + levels=3, + dropout=0.3, + ) + + num_params = sum(p.numel() for p in model.parameters()) + print(f"Model parameters: {num_params:,}") + + # STEP 5: Train the model + print("\n=== Step 5: Training Model ===") + trainer = Trainer( + model=model, + device=DEVICE, + metrics=["pr_auc", "roc_auc", "accuracy", "f1"], + ) + + trainer.train( + train_dataloader=train_loader, + val_dataloader=val_loader, + epochs=50, + monitor="roc_auc", + optimizer_params={"lr": 1e-5}, + ) + + # STEP 6: Evaluate on test set + print("\n=== Step 6: Evaluation ===") + results = trainer.evaluate(test_loader) + print("\nTest Results:") + for metric, value in results.items(): + print(f" {metric}: {value:.4f}") + + # STEP 7: Inspect model predictions + print("\n=== Step 7: Sample Predictions ===") + sample_batch = next(iter(test_loader)) + with torch.no_grad(): + output = model(**sample_batch) + + print(f"Predicted probabilities: {output['y_prob'][:5]}") + print(f"True labels: {output['y_true'][:5]}") + + print("\n" + "=" * 60) + print("T1D DKA PREDICTION TRAINING COMPLETED!") + print("=" * 60) + + return results + + +if __name__ == "__main__": + main() + + diff --git a/pyhealth/tasks/__init__.py b/pyhealth/tasks/__init__.py index 097df9a29..67ba88206 100644 --- a/pyhealth/tasks/__init__.py +++ b/pyhealth/tasks/__init__.py @@ -12,7 +12,7 @@ from .chestxray14_binary_classification import ChestXray14BinaryClassification from .chestxray14_multilabel_classification import ChestXray14MultilabelClassification from .covid19_cxr_classification import COVID19CXRClassification -from .dka import DKAPredictionMIMIC4 +from .dka import DKAPredictionMIMIC4, T1DDKAPredictionMIMIC4 from .drug_recommendation import ( DrugRecommendationMIMIC3, DrugRecommendationMIMIC4, diff --git a/pyhealth/tasks/dka.py b/pyhealth/tasks/dka.py index 3cd70798e..29e42e2c2 100644 --- a/pyhealth/tasks/dka.py +++ b/pyhealth/tasks/dka.py @@ -1,4 +1,4 @@ -# Description: DKA (Diabetic Ketoacidosis) prediction task for MIMIC-IV dataset +# Description: DKA (Diabetic Ketoacidosis) prediction tasks for MIMIC-IV dataset import math from datetime import datetime, timedelta @@ -10,12 +10,312 @@ class DKAPredictionMIMIC4(BaseTask): + """Task for predicting Diabetic Ketoacidosis (DKA) in the general patient population. + + This task creates PATIENT-LEVEL samples from ALL patients in the dataset, + predicting whether they have ever been diagnosed with DKA. This provides + a much larger patient pool with more negative samples compared to T1DM-specific + prediction. + + Target Population: + - ALL patients in the dataset (no filtering) + - Large pool of negative samples (patients without DKA) + + Label Definition: + - Positive (1): Patient has any DKA diagnosis code (ICD-9 or ICD-10) + - Negative (0): Patient has no DKA diagnosis codes + + Features: + - icd_codes: Combined diagnosis + procedure ICD codes (stagenet format) + - labs: 10-dimensional vectors with lab categories + + Args: + padding: Additional padding for StageNet processor. Default: 0. + + Example: + >>> from pyhealth.datasets import MIMIC4Dataset + >>> from pyhealth.tasks import DKAPredictionMIMIC4 + >>> + >>> dataset = MIMIC4Dataset( + ... root="/path/to/mimic4", + ... tables=["diagnoses_icd", "procedures_icd", "labevents", "admissions"], + ... ) + >>> task = DKAPredictionMIMIC4() + >>> samples = dataset.set_task(task) + """ + + task_name: str = "DKAPredictionMIMIC4" + + # ICD-9 codes for Diabetic Ketoacidosis + DKA_ICD9_CODES: ClassVar[Set[str]] = {"25010", "25011", "25012", "25013"} + + # ICD-10 prefix for DKA (E10.1x, E11.1x, E13.1x codes cover T1D, T2D, other DKA) + DKA_ICD10_PREFIXES: ClassVar[List[str]] = ["E101", "E111", "E131"] + + # Lab categories from mortality_prediction_stagenet_mimic4.py (verified item IDs) + LAB_CATEGORIES: ClassVar[Dict[str, List[str]]] = { + "Sodium": ["50824", "52455", "50983", "52623"], + "Potassium": ["50822", "52452", "50971", "52610"], + "Chloride": ["50806", "52434", "50902", "52535"], + "Bicarbonate": ["50803", "50804"], + "Glucose": ["50809", "52027", "50931", "52569"], + "Calcium": ["50808", "51624"], + "Magnesium": ["50960"], + "Anion Gap": ["50868", "52500"], + "Osmolality": ["52031", "50964", "51701"], + "Phosphate": ["50970"], + } + + LAB_CATEGORY_ORDER: ClassVar[List[str]] = [ + "Sodium", "Potassium", "Chloride", "Bicarbonate", "Glucose", + "Calcium", "Magnesium", "Anion Gap", "Osmolality", "Phosphate", + ] + + ALL_LAB_ITEMIDS: ClassVar[List[str]] = sorted( + {item for items in LAB_CATEGORIES.values() for item in items} + ) + + def __init__(self, padding: int = 0): + """Initialize task with optional padding. + + Args: + padding: Additional padding for nested sequences. Default: 0. + """ + self.padding = padding + self.input_schema: Dict[str, Tuple[str, Dict[str, Any]]] = { + "icd_codes": ("stagenet", {"padding": padding}), + "labs": ("stagenet_tensor", {}), + } + self.output_schema: Dict[str, str] = {"label": "binary"} + + @staticmethod + def _normalize_icd(code: Optional[str]) -> str: + """Normalize ICD code by removing dots and standardizing format.""" + if code is None: + return "" + return code.replace(".", "").strip().upper() + + def _is_dka_code(self, code: Optional[str], version: Optional[object]) -> bool: + """Check if an ICD code represents Diabetic Ketoacidosis.""" + normalized = self._normalize_icd(code) + if not normalized: + return False + + version_str = str(version) if version is not None else "" + + if version_str == "10": + return any(normalized.startswith(prefix) for prefix in self.DKA_ICD10_PREFIXES) + if version_str == "9": + return normalized in self.DKA_ICD9_CODES + + return False + + @staticmethod + def _safe_parse_datetime(value: Optional[object]) -> Optional[datetime]: + """Safely parse a datetime value from various formats.""" + if value is None: + return None + if isinstance(value, datetime): + return value + text = str(value) + for fmt in ("%Y-%m-%d %H:%M:%S", "%Y-%m-%d"): + try: + return datetime.strptime(text, fmt) + except ValueError: + continue + try: + return datetime.fromisoformat(text) + except ValueError: + return None + + @staticmethod + def _deduplicate_preserve_order(values: List[str]) -> List[str]: + """Remove duplicates from a list while preserving order.""" + seen: Set[str] = set() + ordered: List[str] = [] + for value in values: + if value not in seen: + seen.add(value) + ordered.append(value) + return ordered + + def _build_lab_vector(self, lab_df: Optional[pl.DataFrame]) -> List[float]: + """Build a lab feature vector from lab events DataFrame.""" + feature_dim = len(self.LAB_CATEGORY_ORDER) + + if lab_df is None or lab_df.height == 0: + return [math.nan] * feature_dim + + filtered = ( + lab_df.with_columns([ + pl.col("labevents/itemid").cast(pl.Utf8), + pl.col("labevents/valuenum").cast(pl.Float64), + ]) + .filter(pl.col("labevents/itemid").is_in(self.ALL_LAB_ITEMIDS)) + .filter(pl.col("labevents/valuenum").is_not_null()) + ) + + if filtered.height == 0: + return [math.nan] * feature_dim + + vector: List[float] = [] + for category in self.LAB_CATEGORY_ORDER: + itemids = self.LAB_CATEGORIES[category] + cat_df = filtered.filter(pl.col("labevents/itemid").is_in(itemids)) + if cat_df.height == 0: + vector.append(math.nan) + else: + values = cat_df["labevents/valuenum"].drop_nulls() + vector.append(float(values.mean()) if len(values) > 0 else math.nan) + return vector + + def __call__(self, patient: Any) -> List[Dict[str, Any]]: + """Process a patient to create DKA prediction samples. + + Creates ONE sample per patient. Labels based on whether the patient + has ANY DKA diagnosis code in their history. + + Args: + patient: Patient object with get_events method. + + Returns: + List with single sample containing patient_id, ICD codes, labs, and label. + Returns empty list if patient has no admissions. + """ + # Get admissions + admissions = patient.get_events(event_type="admissions") + if not admissions: + return [] + + # Get diagnosis events and check for DKA + diagnosis_events = patient.get_events(event_type="diagnoses_icd") + has_dka = False + + if diagnosis_events: + for event in diagnosis_events: + version = getattr(event, "icd_version", None) + code = getattr(event, "icd_code", None) + if self._is_dka_code(code, version): + has_dka = True + break + + # Build admissions info + admissions_info: Dict[str, Dict[str, Optional[datetime]]] = {} + for admission in admissions: + hadm_id = getattr(admission, "hadm_id", None) + admit_time = self._safe_parse_datetime(getattr(admission, "timestamp", None)) + discharge_time = self._safe_parse_datetime(getattr(admission, "dischtime", None)) + if hadm_id is not None and admit_time is not None: + admissions_info[str(hadm_id)] = { + "admit": admit_time, + "discharge": discharge_time, + } + + if not admissions_info: + return [] + + # Build ICD code sequences per admission + admission_codes: Dict[str, List[str]] = { + hadm_id: [] for hadm_id in admissions_info + } + + # Add diagnosis codes + if diagnosis_events: + for event in diagnosis_events: + code = getattr(event, "icd_code", None) + normalized_code = self._normalize_icd(code) + if not normalized_code: + continue + hadm_id = getattr(event, "hadm_id", None) + admission_key = ( + str(hadm_id) if hadm_id is not None + else list(admissions_info.keys())[0] + ) + if admission_key in admission_codes: + admission_codes[admission_key].append(f"D_{normalized_code}") + + # Add procedure codes + procedure_events = patient.get_events(event_type="procedures_icd") + if procedure_events: + for event in procedure_events: + code = getattr(event, "icd_code", None) + normalized_code = self._normalize_icd(code) + if not normalized_code: + continue + hadm_id = getattr(event, "hadm_id", None) + admission_key = ( + str(hadm_id) if hadm_id is not None + else list(admissions_info.keys())[0] + ) + if admission_key in admission_codes: + admission_codes[admission_key].append(f"P_{normalized_code}") + + # Sort admissions chronologically + sorted_admissions = sorted( + admissions_info.items(), + key=lambda item: item[1]["admit"] or datetime.min, + ) + + # Build sequences + icd_sequences: List[List[str]] = [] + icd_times: List[float] = [] + lab_sequences: List[List[float]] = [] + lab_times: List[float] = [] + previous_admit: Optional[datetime] = None + + for hadm_id, info in sorted_admissions: + admit_time = info["admit"] or datetime.now() + + codes = self._deduplicate_preserve_order(admission_codes.get(hadm_id, [])) + if not codes: + codes = ["UNKNOWN"] + + time_gap = ( + 0.0 if previous_admit is None + else (admit_time - previous_admit).total_seconds() / 3600.0 + ) + previous_admit = admit_time + + icd_sequences.append(codes) + icd_times.append(time_gap) + + try: + lab_df = patient.get_events( + event_type="labevents", + start=admit_time, + end=info.get("discharge"), + return_df=True, + ) + except Exception: + lab_df = None + + lab_sequences.append(self._build_lab_vector(lab_df)) + lab_times.append(time_gap) + + if not icd_sequences: + icd_sequences = [["UNKNOWN"]] + icd_times = [0.0] + lab_sequences = [[math.nan] * len(self.LAB_CATEGORY_ORDER)] + lab_times = [0.0] + + sample: Dict[str, Any] = { + "patient_id": patient.patient_id, + "record_id": patient.patient_id, + "icd_codes": (icd_times, icd_sequences), + "labs": (lab_times, lab_sequences), + "label": int(has_dka), + } + + return [sample] + + +class T1DDKAPredictionMIMIC4(BaseTask): """Task for predicting Diabetic Ketoacidosis (DKA) in Type 1 Diabetes patients. This task creates PATIENT-LEVEL samples by identifying patients with Type 1 Diabetes Mellitus (T1DM) and predicting whether they will develop DKA within - a specified time window. The task uses diagnosis codes and lab results across - all admissions in StageNet format for temporal modeling. + a specified time window. The task uses diagnosis codes, procedure codes, and + lab results across all admissions in StageNet format for temporal modeling. Target Population: - Patients with Type 1 Diabetes (ICD-9 or ICD-10 codes) @@ -26,12 +326,17 @@ class DKAPredictionMIMIC4(BaseTask): - Negative (0): Patient has T1DM but no DKA within the window Time Calculation: - - Diagnosis codes: Hours from previous admission (0 for first visit) + - ICD codes: Hours from previous admission (0 for first visit) - Labs: Hours from admission start (within-visit measurements) + Features: + - icd_codes: Combined diagnosis + procedure ICD codes (stagenet format) + - labs: 10-dimensional vectors with lab categories + Lab Processing: - - 6-dimensional vectors (one per lab category relevant to DKA) - - Categories: glucose, bicarbonate, anion_gap, potassium, sodium, chloride + - 10-dimensional vectors (same as mortality prediction task) + - Categories: Sodium, Potassium, Chloride, Bicarbonate, Glucose, + Calcium, Magnesium, Anion Gap, Osmolality, Phosphate - Multiple itemids per category → take mean of observed values - Missing categories → NaN in vector @@ -43,24 +348,24 @@ class DKAPredictionMIMIC4(BaseTask): Attributes: task_name (str): The name of the task. input_schema (Dict[str, Tuple[str, Dict]]): The schema for input data: - - diagnoses: Diagnosis ICD codes (stagenet format, nested by visit) - - labs: Lab results (stagenet_tensor, 6D vectors per timestamp) + - icd_codes: Combined diagnosis + procedure ICD codes (stagenet format) + - labs: Lab results (stagenet_tensor, 10D vectors per timestamp) output_schema (Dict[str, str]): The schema for output data: - label: Binary indicator (1 if DKA within window, 0 otherwise) Example: >>> from pyhealth.datasets import MIMIC4Dataset - >>> from pyhealth.tasks import DKAPredictionMIMIC4 + >>> from pyhealth.tasks import T1DDKAPredictionMIMIC4 >>> >>> dataset = MIMIC4Dataset( ... root="/path/to/mimic4", - ... tables=["diagnoses_icd", "labevents", "admissions"], + ... tables=["diagnoses_icd", "procedures_icd", "labevents", "admissions"], ... ) - >>> task = DKAPredictionMIMIC4(dka_window_days=90) + >>> task = T1DDKAPredictionMIMIC4(dka_window_days=90) >>> samples = dataset.set_task(task) """ - task_name: str = "DKAPredictionMIMIC4" + task_name: str = "T1DDKAPredictionMIMIC4" # ICD-10 prefix for Type 1 Diabetes Mellitus T1DM_ICD10_PREFIX: ClassVar[str] = "E10" @@ -79,25 +384,33 @@ class DKAPredictionMIMIC4(BaseTask): # ICD-10 prefix for DKA (E10.1x codes) DKA_ICD10_PREFIX: ClassVar[str] = "E101" - # Lab categories relevant to DKA monitoring - # Each category maps to ONE dimension in the output vector + # Lab categories from mortality_prediction_stagenet_mimic4.py (verified item IDs) + # Each category maps to ONE dimension in the output vector (10 total) LAB_CATEGORIES: ClassVar[Dict[str, List[str]]] = { - "glucose": ["50809", "50931", "52027", "52569"], - "bicarbonate": ["50803", "50804", "51084"], - "anion_gap": ["50868"], - "potassium": ["50822", "50971", "52452", "52510"], - "sodium": ["50824", "50983", "52455"], - "chloride": ["50806", "50902", "52434"], + "Sodium": ["50824", "52455", "50983", "52623"], + "Potassium": ["50822", "52452", "50971", "52610"], + "Chloride": ["50806", "52434", "50902", "52535"], + "Bicarbonate": ["50803", "50804"], + "Glucose": ["50809", "52027", "50931", "52569"], + "Calcium": ["50808", "51624"], + "Magnesium": ["50960"], + "Anion Gap": ["50868", "52500"], + "Osmolality": ["52031", "50964", "51701"], + "Phosphate": ["50970"], } # Ordered list of category names (defines vector dimension order) LAB_CATEGORY_ORDER: ClassVar[List[str]] = [ - "glucose", - "bicarbonate", - "anion_gap", - "potassium", - "sodium", - "chloride", + "Sodium", + "Potassium", + "Chloride", + "Bicarbonate", + "Glucose", + "Calcium", + "Magnesium", + "Anion Gap", + "Osmolality", + "Phosphate", ] # Flat list of all lab item IDs for filtering @@ -118,7 +431,7 @@ def __init__(self, dka_window_days: int = 90, padding: int = 0): # Use tuple format to pass kwargs to processor self.input_schema: Dict[str, Tuple[str, Dict[str, Any]]] = { - "diagnoses": ("stagenet", {"padding": padding}), + "icd_codes": ("stagenet", {"padding": padding}), "labs": ("stagenet_tensor", {}), } self.output_schema: Dict[str, str] = {"label": "binary"} @@ -326,9 +639,9 @@ def __call__(self, patient: Any) -> List[Dict[str, Any]]: patient: Patient object with get_events method. Returns: - List with single sample containing patient_id, diagnosis sequences, - lab sequences, and DKA label. Returns empty list if patient does - not have T1DM or lacks required data. + List with single sample containing patient_id, combined ICD codes + (diagnoses + procedures), lab sequences, and DKA label. + Returns empty list if patient does not have T1DM or lacks required data. """ # Get all diagnosis events diagnosis_events = patient.get_events(event_type="diagnoses_icd") @@ -404,11 +717,12 @@ def __call__(self, patient: Any) -> List[Dict[str, Any]]: "discharge": None, } - # Build diagnosis code sequences per admission + # Build ICD code sequences per admission (diagnoses + procedures) admission_codes: Dict[str, List[str]] = { hadm_id: [] for hadm_id in admissions_info } + # Add diagnosis codes for event in diagnosis_events: code = getattr(event, "icd_code", None) normalized_code = self._normalize_icd(code) @@ -423,7 +737,26 @@ def __call__(self, patient: Any) -> List[Dict[str, Any]]: ) if admission_key in admission_codes: - admission_codes[admission_key].append(normalized_code) + admission_codes[admission_key].append(f"D_{normalized_code}") + + # Add procedure codes + procedure_events = patient.get_events(event_type="procedures_icd") + if procedure_events: + for event in procedure_events: + code = getattr(event, "icd_code", None) + normalized_code = self._normalize_icd(code) + if not normalized_code: + continue + + hadm_id = getattr(event, "hadm_id", None) + admission_key = ( + str(hadm_id) + if hadm_id is not None + else list(admissions_info.keys())[0] + ) + + if admission_key in admission_codes: + admission_codes[admission_key].append(f"P_{normalized_code}") # Sort admissions chronologically sorted_admissions = sorted( @@ -434,8 +767,8 @@ def __call__(self, patient: Any) -> List[Dict[str, Any]]: ) # Build sequences - diagnoses_sequences: List[List[str]] = [] - diagnoses_times: List[float] = [] + icd_sequences: List[List[str]] = [] + icd_times: List[float] = [] lab_sequences: List[List[float]] = [] lab_times: List[float] = [] previous_admit: Optional[datetime] = None @@ -460,8 +793,8 @@ def __call__(self, patient: Any) -> List[Dict[str, Any]]: ) previous_admit = admit_time - diagnoses_sequences.append(codes) - diagnoses_times.append(time_gap) + icd_sequences.append(codes) + icd_times.append(time_gap) # Get lab data for this admission try: @@ -478,9 +811,9 @@ def __call__(self, patient: Any) -> List[Dict[str, Any]]: lab_times.append(time_gap) # Ensure we have at least one sequence entry - if not diagnoses_sequences: - diagnoses_sequences = [["UNKNOWN"]] - diagnoses_times = [0.0] + if not icd_sequences: + icd_sequences = [["UNKNOWN"]] + icd_times = [0.0] lab_sequences = [[math.nan] * len(self.LAB_CATEGORY_ORDER)] lab_times = [0.0] @@ -488,7 +821,7 @@ def __call__(self, patient: Any) -> List[Dict[str, Any]]: sample: Dict[str, Any] = { "patient_id": patient.patient_id, "record_id": patient.patient_id, - "diagnoses": (diagnoses_times, diagnoses_sequences), + "icd_codes": (icd_times, icd_sequences), "labs": (lab_times, lab_sequences), "label": int(has_dka_within_window), } From 9190f955b784480e91438d9a26b3a7804b09b842 Mon Sep 17 00:00:00 2001 From: John Wu Date: Wed, 24 Dec 2025 11:32:31 -0600 Subject: [PATCH 4/4] more commits for improving the robustness of task processing --- pyhealth/datasets/configs/mimic4_ehr.yaml | 1 + pyhealth/tasks/dka.py | 839 ++++++++-------------- 2 files changed, 308 insertions(+), 532 deletions(-) diff --git a/pyhealth/datasets/configs/mimic4_ehr.yaml b/pyhealth/datasets/configs/mimic4_ehr.yaml index 0a5f8c7a1..a22b91826 100644 --- a/pyhealth/datasets/configs/mimic4_ehr.yaml +++ b/pyhealth/datasets/configs/mimic4_ehr.yaml @@ -105,6 +105,7 @@ tables: - "valueuom" - "flag" - "storetime" + - "hadm_id" hcpcsevents: file_path: "hosp/hcpcsevents.csv.gz" diff --git a/pyhealth/tasks/dka.py b/pyhealth/tasks/dka.py index 29e42e2c2..91f4a856e 100644 --- a/pyhealth/tasks/dka.py +++ b/pyhealth/tasks/dka.py @@ -1,7 +1,7 @@ # Description: DKA (Diabetic Ketoacidosis) prediction tasks for MIMIC-IV dataset import math -from datetime import datetime, timedelta +from datetime import datetime from typing import Any, ClassVar, Dict, List, Optional, Set, Tuple import polars as pl @@ -13,9 +13,8 @@ class DKAPredictionMIMIC4(BaseTask): """Task for predicting Diabetic Ketoacidosis (DKA) in the general patient population. This task creates PATIENT-LEVEL samples from ALL patients in the dataset, - predicting whether they have ever been diagnosed with DKA. This provides - a much larger patient pool with more negative samples compared to T1DM-specific - prediction. + predicting whether they will develop DKA. Features are collected from + admissions BEFORE the first DKA event to prevent data leakage. Target Population: - ALL patients in the dataset (no filtering) @@ -25,6 +24,13 @@ class DKAPredictionMIMIC4(BaseTask): - Positive (1): Patient has any DKA diagnosis code (ICD-9 or ICD-10) - Negative (0): Patient has no DKA diagnosis codes + Data Leakage Prevention: + - Admissions are sorted chronologically + - For DKA-positive patients: Only data from admissions BEFORE the + first DKA admission is included (no data from DKA admission or after) + - For DKA-negative patients: All admissions are included + - Patients whose first admission has DKA are excluded (no pre-DKA data) + Features: - icd_codes: Combined diagnosis + procedure ICD codes (stagenet format) - labs: 10-dimensional vectors with lab categories @@ -71,9 +77,10 @@ class DKAPredictionMIMIC4(BaseTask): "Calcium", "Magnesium", "Anion Gap", "Osmolality", "Phosphate", ] - ALL_LAB_ITEMIDS: ClassVar[List[str]] = sorted( - {item for items in LAB_CATEGORIES.values() for item in items} - ) + # Flat list of all lab item IDs for filtering + LABITEMS: ClassVar[List[str]] = [ + item for items in LAB_CATEGORIES.values() for item in items + ] def __init__(self, padding: int = 0): """Initialize task with optional padding. @@ -88,225 +95,180 @@ def __init__(self, padding: int = 0): } self.output_schema: Dict[str, str] = {"label": "binary"} - @staticmethod - def _normalize_icd(code: Optional[str]) -> str: - """Normalize ICD code by removing dots and standardizing format.""" - if code is None: - return "" - return code.replace(".", "").strip().upper() - - def _is_dka_code(self, code: Optional[str], version: Optional[object]) -> bool: + def _is_dka_code(self, code: str, version: Any) -> bool: """Check if an ICD code represents Diabetic Ketoacidosis.""" - normalized = self._normalize_icd(code) - if not normalized: + if not code: return False - + normalized = code.replace(".", "").strip().upper() version_str = str(version) if version is not None else "" if version_str == "10": - return any(normalized.startswith(prefix) for prefix in self.DKA_ICD10_PREFIXES) + return any(normalized.startswith(p) for p in self.DKA_ICD10_PREFIXES) if version_str == "9": return normalized in self.DKA_ICD9_CODES - return False - @staticmethod - def _safe_parse_datetime(value: Optional[object]) -> Optional[datetime]: - """Safely parse a datetime value from various formats.""" - if value is None: - return None - if isinstance(value, datetime): - return value - text = str(value) - for fmt in ("%Y-%m-%d %H:%M:%S", "%Y-%m-%d"): - try: - return datetime.strptime(text, fmt) - except ValueError: - continue - try: - return datetime.fromisoformat(text) - except ValueError: - return None - - @staticmethod - def _deduplicate_preserve_order(values: List[str]) -> List[str]: - """Remove duplicates from a list while preserving order.""" - seen: Set[str] = set() - ordered: List[str] = [] - for value in values: - if value not in seen: - seen.add(value) - ordered.append(value) - return ordered - - def _build_lab_vector(self, lab_df: Optional[pl.DataFrame]) -> List[float]: - """Build a lab feature vector from lab events DataFrame.""" - feature_dim = len(self.LAB_CATEGORY_ORDER) - - if lab_df is None or lab_df.height == 0: - return [math.nan] * feature_dim + def _build_lab_vector(self, lab_df: pl.DataFrame) -> List[float]: + """Build a 10D lab feature vector from lab events DataFrame.""" + if lab_df.height == 0: + return [math.nan] * len(self.LAB_CATEGORY_ORDER) + # Filter to relevant lab items and cast filtered = ( lab_df.with_columns([ pl.col("labevents/itemid").cast(pl.Utf8), pl.col("labevents/valuenum").cast(pl.Float64), ]) - .filter(pl.col("labevents/itemid").is_in(self.ALL_LAB_ITEMIDS)) + .filter(pl.col("labevents/itemid").is_in(self.LABITEMS)) .filter(pl.col("labevents/valuenum").is_not_null()) ) if filtered.height == 0: - return [math.nan] * feature_dim + return [math.nan] * len(self.LAB_CATEGORY_ORDER) + # Build vector with one value per category (mean of observed values) vector: List[float] = [] for category in self.LAB_CATEGORY_ORDER: itemids = self.LAB_CATEGORIES[category] cat_df = filtered.filter(pl.col("labevents/itemid").is_in(itemids)) - if cat_df.height == 0: - vector.append(math.nan) - else: + if cat_df.height > 0: values = cat_df["labevents/valuenum"].drop_nulls() vector.append(float(values.mean()) if len(values) > 0 else math.nan) + else: + vector.append(math.nan) return vector def __call__(self, patient: Any) -> List[Dict[str, Any]]: """Process a patient to create DKA prediction samples. - Creates ONE sample per patient. Labels based on whether the patient - has ANY DKA diagnosis code in their history. + Iterates through sorted admissions, collecting features until DKA is found. + Label is based on whether DKA occurs in any future admission. Args: patient: Patient object with get_events method. Returns: - List with single sample containing patient_id, ICD codes, labs, and label. - Returns empty list if patient has no admissions. + List with single sample, or empty list if insufficient data. """ - # Get admissions + # Get admissions and sort by timestamp admissions = patient.get_events(event_type="admissions") if not admissions: return [] - # Get diagnosis events and check for DKA - diagnosis_events = patient.get_events(event_type="diagnoses_icd") - has_dka = False + # Sort admissions chronologically by timestamp + admissions = sorted(admissions, key=lambda x: x.timestamp) - if diagnosis_events: - for event in diagnosis_events: - version = getattr(event, "icd_version", None) - code = getattr(event, "icd_code", None) - if self._is_dka_code(code, version): - has_dka = True - break + # Initialize aggregated data structures + all_icd_codes: List[List[str]] = [] + all_icd_times: List[float] = [] + all_lab_values: List[List[float]] = [] + all_lab_times: List[float] = [] - # Build admissions info - admissions_info: Dict[str, Dict[str, Optional[datetime]]] = {} + previous_admission_time: Optional[datetime] = None + has_dka = False + + # Iterate through admissions in chronological order for admission in admissions: - hadm_id = getattr(admission, "hadm_id", None) - admit_time = self._safe_parse_datetime(getattr(admission, "timestamp", None)) - discharge_time = self._safe_parse_datetime(getattr(admission, "dischtime", None)) - if hadm_id is not None and admit_time is not None: - admissions_info[str(hadm_id)] = { - "admit": admit_time, - "discharge": discharge_time, - } - - if not admissions_info: - return [] + # Parse admission times + try: + admission_time = admission.timestamp + dischtime_str = getattr(admission, "dischtime", None) + if dischtime_str: + admission_dischtime = datetime.strptime( + dischtime_str, "%Y-%m-%d %H:%M:%S" + ) + else: + admission_dischtime = None + except (ValueError, AttributeError): + continue - # Build ICD code sequences per admission - admission_codes: Dict[str, List[str]] = { - hadm_id: [] for hadm_id in admissions_info - } + # Get diagnoses for this admission + diagnoses = patient.get_events( + event_type="diagnoses_icd", + filters=[("hadm_id", "==", admission.hadm_id)], + ) - # Add diagnosis codes - if diagnosis_events: - for event in diagnosis_events: - code = getattr(event, "icd_code", None) - normalized_code = self._normalize_icd(code) - if not normalized_code: - continue - hadm_id = getattr(event, "hadm_id", None) - admission_key = ( - str(hadm_id) if hadm_id is not None - else list(admissions_info.keys())[0] - ) - if admission_key in admission_codes: - admission_codes[admission_key].append(f"D_{normalized_code}") - - # Add procedure codes - procedure_events = patient.get_events(event_type="procedures_icd") - if procedure_events: - for event in procedure_events: - code = getattr(event, "icd_code", None) - normalized_code = self._normalize_icd(code) - if not normalized_code: + # Iterate through diagnoses - check for DKA and collect codes + visit_codes: List[str] = [] + seen: Set[str] = set() + + for diag in diagnoses: + code = getattr(diag, "icd_code", None) + version = getattr(diag, "icd_version", None) + if not code: continue - hadm_id = getattr(event, "hadm_id", None) - admission_key = ( - str(hadm_id) if hadm_id is not None - else list(admissions_info.keys())[0] - ) - if admission_key in admission_codes: - admission_codes[admission_key].append(f"P_{normalized_code}") - - # Sort admissions chronologically - sorted_admissions = sorted( - admissions_info.items(), - key=lambda item: item[1]["admit"] or datetime.min, - ) - # Build sequences - icd_sequences: List[List[str]] = [] - icd_times: List[float] = [] - lab_sequences: List[List[float]] = [] - lab_times: List[float] = [] - previous_admit: Optional[datetime] = None + # Check for DKA - if found, stop everything + if self._is_dka_code(code, version): + has_dka = True + break - for hadm_id, info in sorted_admissions: - admit_time = info["admit"] or datetime.now() + # Add diagnosis code if not seen + normalized = f"D_{code.replace('.', '').upper()}" + if normalized not in seen: + seen.add(normalized) + visit_codes.append(normalized) - codes = self._deduplicate_preserve_order(admission_codes.get(hadm_id, [])) - if not codes: - codes = ["UNKNOWN"] + # If DKA found, don't append this visit's data and stop + if has_dka: + break - time_gap = ( - 0.0 if previous_admit is None - else (admit_time - previous_admit).total_seconds() / 3600.0 + # Get procedures for this admission + procedures = patient.get_events( + event_type="procedures_icd", + filters=[("hadm_id", "==", admission.hadm_id)], ) - previous_admit = admit_time - icd_sequences.append(codes) - icd_times.append(time_gap) + for proc in procedures: + code = getattr(proc, "icd_code", None) + if not code: + continue + normalized = f"P_{code.replace('.', '').upper()}" + if normalized not in seen: + seen.add(normalized) + visit_codes.append(normalized) + + # Calculate time from previous admission (hours) + if previous_admission_time is None: + time_from_previous = 0.0 + else: + time_from_previous = ( + admission_time - previous_admission_time + ).total_seconds() / 3600.0 + previous_admission_time = admission_time + + # Append this visit's codes + if visit_codes: + all_icd_codes.append(visit_codes) + all_icd_times.append(time_from_previous) + + # Get lab events for this admission using hadm_id + lab_df = patient.get_events( + event_type="labevents", + filters=[("hadm_id", "==", admission.hadm_id)], + return_df=True, + ) - try: - lab_df = patient.get_events( - event_type="labevents", - start=admit_time, - end=info.get("discharge"), - return_df=True, - ) - except Exception: - lab_df = None - - lab_sequences.append(self._build_lab_vector(lab_df)) - lab_times.append(time_gap) - - if not icd_sequences: - icd_sequences = [["UNKNOWN"]] - icd_times = [0.0] - lab_sequences = [[math.nan] * len(self.LAB_CATEGORY_ORDER)] - lab_times = [0.0] - - sample: Dict[str, Any] = { + if lab_df.height > 0: + all_lab_values.append(self._build_lab_vector(lab_df)) + all_lab_times.append(time_from_previous) + + # Skip if no pre-DKA data (DKA on first visit or no valid admissions) + if not all_icd_codes: + return [] + + # Ensure we have lab data (use NaN vector if missing) + if not all_lab_values: + all_lab_values = [[math.nan] * len(self.LAB_CATEGORY_ORDER)] + all_lab_times = [0.0] + + return [{ "patient_id": patient.patient_id, "record_id": patient.patient_id, - "icd_codes": (icd_times, icd_sequences), - "labs": (lab_times, lab_sequences), + "icd_codes": (all_icd_times, all_icd_codes), + "labs": (all_lab_times, all_lab_values), "label": int(has_dka), - } - - return [sample] + }] class T1DDKAPredictionMIMIC4(BaseTask): @@ -314,8 +276,8 @@ class T1DDKAPredictionMIMIC4(BaseTask): This task creates PATIENT-LEVEL samples by identifying patients with Type 1 Diabetes Mellitus (T1DM) and predicting whether they will develop DKA within - a specified time window. The task uses diagnosis codes, procedure codes, and - lab results across all admissions in StageNet format for temporal modeling. + a specified time window. Features are collected from admissions BEFORE the + first DKA event to prevent data leakage. Target Population: - Patients with Type 1 Diabetes (ICD-9 or ICD-10 codes) @@ -325,34 +287,22 @@ class T1DDKAPredictionMIMIC4(BaseTask): - Positive (1): Patient has DKA code within 90 days of T1DM diagnosis - Negative (0): Patient has T1DM but no DKA within the window - Time Calculation: - - ICD codes: Hours from previous admission (0 for first visit) - - Labs: Hours from admission start (within-visit measurements) + Data Leakage Prevention: + - Admissions are sorted chronologically + - For DKA-positive patients: Only data from admissions BEFORE the + first DKA admission is included (no data from DKA admission or after) + - For DKA-negative patients: All admissions are included + - Patients whose first admission has DKA are excluded (no pre-DKA data) Features: - icd_codes: Combined diagnosis + procedure ICD codes (stagenet format) - labs: 10-dimensional vectors with lab categories - Lab Processing: - - 10-dimensional vectors (same as mortality prediction task) - - Categories: Sodium, Potassium, Chloride, Bicarbonate, Glucose, - Calcium, Magnesium, Anion Gap, Osmolality, Phosphate - - Multiple itemids per category → take mean of observed values - - Missing categories → NaN in vector - Args: dka_window_days: Number of days to consider for DKA occurrence after T1DM diagnosis. Default: 90. padding: Additional padding for StageNet processor. Default: 0. - Attributes: - task_name (str): The name of the task. - input_schema (Dict[str, Tuple[str, Dict]]): The schema for input data: - - icd_codes: Combined diagnosis + procedure ICD codes (stagenet format) - - labs: Lab results (stagenet_tensor, 10D vectors per timestamp) - output_schema (Dict[str, str]): The schema for output data: - - label: Binary indicator (1 if DKA within window, 0 otherwise) - Example: >>> from pyhealth.datasets import MIMIC4Dataset >>> from pyhealth.tasks import T1DDKAPredictionMIMIC4 @@ -384,8 +334,7 @@ class T1DDKAPredictionMIMIC4(BaseTask): # ICD-10 prefix for DKA (E10.1x codes) DKA_ICD10_PREFIX: ClassVar[str] = "E101" - # Lab categories from mortality_prediction_stagenet_mimic4.py (verified item IDs) - # Each category maps to ONE dimension in the output vector (10 total) + # Lab categories from mortality_prediction_stagenet_mimic4.py LAB_CATEGORIES: ClassVar[Dict[str, List[str]]] = { "Sodium": ["50824", "52455", "50983", "52623"], "Potassium": ["50822", "52452", "50971", "52610"], @@ -399,432 +348,258 @@ class T1DDKAPredictionMIMIC4(BaseTask): "Phosphate": ["50970"], } - # Ordered list of category names (defines vector dimension order) LAB_CATEGORY_ORDER: ClassVar[List[str]] = [ - "Sodium", - "Potassium", - "Chloride", - "Bicarbonate", - "Glucose", - "Calcium", - "Magnesium", - "Anion Gap", - "Osmolality", - "Phosphate", + "Sodium", "Potassium", "Chloride", "Bicarbonate", "Glucose", + "Calcium", "Magnesium", "Anion Gap", "Osmolality", "Phosphate", ] - # Flat list of all lab item IDs for filtering - ALL_LAB_ITEMIDS: ClassVar[List[str]] = sorted( - {item for items in LAB_CATEGORIES.values() for item in items} - ) + LABITEMS: ClassVar[List[str]] = [ + item for items in LAB_CATEGORIES.values() for item in items + ] def __init__(self, dka_window_days: int = 90, padding: int = 0): - """Initialize task with configurable DKA window and padding. - - Args: - dka_window_days: Days after T1DM diagnosis to check for DKA. Default: 90. - padding: Additional padding for nested sequences. Default: 0. - """ + """Initialize task with configurable DKA window and padding.""" self.dka_window_days = dka_window_days - self.dka_window = timedelta(days=dka_window_days) self.padding = padding - - # Use tuple format to pass kwargs to processor self.input_schema: Dict[str, Tuple[str, Dict[str, Any]]] = { "icd_codes": ("stagenet", {"padding": padding}), "labs": ("stagenet_tensor", {}), } self.output_schema: Dict[str, str] = {"label": "binary"} - @staticmethod - def _normalize_icd(code: Optional[str]) -> str: - """Normalize ICD code by removing dots and standardizing format. - - Args: - code: Raw ICD code string, may contain dots and varying case. - - Returns: - Normalized uppercase code without dots, or empty string if None. - """ - if code is None: - return "" - return code.replace(".", "").strip().upper() - - def _is_t1dm_code(self, code: Optional[str], version: Optional[object]) -> bool: - """Check if an ICD code represents Type 1 Diabetes Mellitus. - - Args: - code: ICD diagnosis code. - version: ICD version (9 or 10). - - Returns: - True if code represents T1DM, False otherwise. - """ - normalized = self._normalize_icd(code) - if not normalized: + def _is_t1dm_code(self, code: str, version: Any) -> bool: + """Check if an ICD code represents Type 1 Diabetes Mellitus.""" + if not code: return False - + normalized = code.replace(".", "").strip().upper() version_str = str(version) if version is not None else "" if version_str == "10": return normalized.startswith(self.T1DM_ICD10_PREFIX) if version_str == "9": return normalized in self.T1DM_ICD9_CODES - return False - def _is_dka_code(self, code: Optional[str], version: Optional[object]) -> bool: - """Check if an ICD code represents Diabetic Ketoacidosis. - - Args: - code: ICD diagnosis code. - version: ICD version (9 or 10). - - Returns: - True if code represents DKA, False otherwise. - """ - normalized = self._normalize_icd(code) - if not normalized: + def _is_dka_code(self, code: str, version: Any) -> bool: + """Check if an ICD code represents Diabetic Ketoacidosis.""" + if not code: return False - + normalized = code.replace(".", "").strip().upper() version_str = str(version) if version is not None else "" if version_str == "10": return normalized.startswith(self.DKA_ICD10_PREFIX) if version_str == "9": return normalized in self.DKA_ICD9_CODES - return False - @staticmethod - def _safe_parse_datetime(value: Optional[object]) -> Optional[datetime]: - """Safely parse a datetime value from various formats. - - Args: - value: Datetime string or datetime object. - - Returns: - Parsed datetime object, or None if parsing fails. - """ - if value is None: - return None - if isinstance(value, datetime): - return value - - text = str(value) - for fmt in ("%Y-%m-%d %H:%M:%S", "%Y-%m-%d"): - try: - return datetime.strptime(text, fmt) - except ValueError: - continue - try: - return datetime.fromisoformat(text) - except ValueError: - return None - - @staticmethod - def _deduplicate_preserve_order(values: List[str]) -> List[str]: - """Remove duplicates from a list while preserving order. - - Args: - values: List of strings with potential duplicates. - - Returns: - Deduplicated list maintaining original order. - """ - seen: Set[str] = set() - ordered: List[str] = [] - for value in values: - if value not in seen: - seen.add(value) - ordered.append(value) - return ordered - - def pre_filter(self, df: pl.LazyFrame) -> pl.LazyFrame: - """Filter to keep only patients with Type 1 Diabetes codes. - - This pre-filter reduces the dataset to patients who have at least - one T1DM diagnosis code (ICD-9 or ICD-10), improving processing - efficiency for the downstream task. - - Args: - df: LazyFrame containing patient data with diagnosis codes. - - Returns: - Filtered LazyFrame with only T1DM patients. - """ - # Check if we have the diagnosis code column - if "diagnoses_icd/icd_code" not in df.collect_schema().names(): - # Column not present, return unfiltered - return df - - # Collect to DataFrame for filtering - collected_df = df.collect() - - # Create masks for T1DM codes - mask_icd10 = collected_df["diagnoses_icd/icd_code"].str.starts_with( - self.T1DM_ICD10_PREFIX - ) - mask_icd9 = collected_df["diagnoses_icd/icd_code"].is_in( - list(self.T1DM_ICD9_CODES) - ) - - # Get patient IDs with T1DM codes - t1dm_mask = mask_icd10 | mask_icd9 - t1dm_patients = collected_df.filter(t1dm_mask)["patient_id"].unique() + def _build_lab_vector(self, lab_df: pl.DataFrame) -> List[float]: + """Build a 10D lab feature vector from lab events DataFrame.""" + if lab_df.height == 0: + return [math.nan] * len(self.LAB_CATEGORY_ORDER) - # Keep only patients with T1DM codes - filtered_df = collected_df.filter( - collected_df["patient_id"].is_in(t1dm_patients) - ) - - return filtered_df.lazy() - - def _build_lab_vector(self, lab_df: Optional[pl.DataFrame]) -> List[float]: - """Build a lab feature vector from lab events DataFrame. - - Creates a fixed-dimension vector with one value per lab category. - Uses mean aggregation when multiple values exist for a category. - - Args: - lab_df: DataFrame containing lab events with itemid and valuenum columns. - - Returns: - List of floats with length equal to number of lab categories. - Missing categories are represented as NaN. - """ - feature_dim = len(self.LAB_CATEGORY_ORDER) - - if lab_df is None or lab_df.height == 0: - return [math.nan] * feature_dim - - # Filter and cast columns filtered = ( lab_df.with_columns([ pl.col("labevents/itemid").cast(pl.Utf8), pl.col("labevents/valuenum").cast(pl.Float64), ]) - .filter(pl.col("labevents/itemid").is_in(self.ALL_LAB_ITEMIDS)) + .filter(pl.col("labevents/itemid").is_in(self.LABITEMS)) .filter(pl.col("labevents/valuenum").is_not_null()) ) if filtered.height == 0: - return [math.nan] * feature_dim + return [math.nan] * len(self.LAB_CATEGORY_ORDER) - # Build vector with one value per category vector: List[float] = [] for category in self.LAB_CATEGORY_ORDER: itemids = self.LAB_CATEGORIES[category] cat_df = filtered.filter(pl.col("labevents/itemid").is_in(itemids)) - - if cat_df.height == 0: - vector.append(math.nan) - else: + if cat_df.height > 0: values = cat_df["labevents/valuenum"].drop_nulls() - if len(values) > 0: - vector.append(float(values.mean())) - else: - vector.append(math.nan) - + vector.append(float(values.mean()) if len(values) > 0 else math.nan) + else: + vector.append(math.nan) return vector + def pre_filter(self, df: pl.LazyFrame) -> pl.LazyFrame: + """Filter to keep only patients with Type 1 Diabetes codes.""" + if "diagnoses_icd/icd_code" not in df.collect_schema().names(): + return df + + collected_df = df.collect() + mask_icd10 = collected_df["diagnoses_icd/icd_code"].str.starts_with( + self.T1DM_ICD10_PREFIX + ) + mask_icd9 = collected_df["diagnoses_icd/icd_code"].is_in( + list(self.T1DM_ICD9_CODES) + ) + t1dm_patients = collected_df.filter(mask_icd10 | mask_icd9)["patient_id"].unique() + return collected_df.filter(collected_df["patient_id"].is_in(t1dm_patients)).lazy() + def __call__(self, patient: Any) -> List[Dict[str, Any]]: """Process a patient to create DKA prediction samples. - Creates ONE sample per patient with T1DM diagnosis. Aggregates all - admissions and calculates whether DKA occurred within the specified - time window of T1DM diagnosis. + First checks if patient has T1DM before processing admissions. + Iterates through sorted admissions, collecting features until DKA is found. + Label is based on whether DKA occurs within the time window of T1DM diagnosis. Args: patient: Patient object with get_events method. Returns: - List with single sample containing patient_id, combined ICD codes - (diagnoses + procedures), lab sequences, and DKA label. - Returns empty list if patient does not have T1DM or lacks required data. + List with single sample, or empty list if patient lacks T1DM or pre-DKA data. """ - # Get all diagnosis events - diagnosis_events = patient.get_events(event_type="diagnoses_icd") - if not diagnosis_events: + # First check: does this patient have T1DM? (quick scan before expensive ops) + all_diagnoses = patient.get_events(event_type="diagnoses_icd") + if not all_diagnoses: return [] - # Identify T1DM and DKA occurrences with timestamps has_t1dm = False t1dm_times: List[datetime] = [] - dka_times: List[datetime] = [] - - for event in diagnosis_events: - version = getattr(event, "icd_version", None) - code = getattr(event, "icd_code", None) - event_time = self._safe_parse_datetime(getattr(event, "timestamp", None)) + for diag in all_diagnoses: + code = getattr(diag, "icd_code", None) + version = getattr(diag, "icd_version", None) if self._is_t1dm_code(code, version): has_t1dm = True - if event_time is not None: - t1dm_times.append(event_time) + diag_time = getattr(diag, "timestamp", None) + if diag_time: + t1dm_times.append(diag_time) - if self._is_dka_code(code, version): - if event_time is not None: - dka_times.append(event_time) - - # Skip patients without T1DM diagnosis + # Skip patients without T1DM diagnosis (early exit before sorting) if not has_t1dm: return [] - # Determine DKA label based on temporal relationship - has_dka_within_window = False + # Get admissions and sort by timestamp + admissions = patient.get_events(event_type="admissions") + if not admissions: + return [] - if dka_times and t1dm_times: - for diagnosis_time in t1dm_times: - for dka_time in dka_times: - if diagnosis_time is None or dka_time is None: - continue - delta = abs((dka_time - diagnosis_time).days) - if delta <= self.dka_window_days: - has_dka_within_window = True - break - if has_dka_within_window: - break + # Sort admissions chronologically by timestamp + admissions = sorted(admissions, key=lambda x: x.timestamp) - # Fallback: if no temporal info, check if patient has any DKA codes - if not has_dka_within_window and not t1dm_times: - has_dka_within_window = len(dka_times) > 0 + # Initialize tracking variables + all_icd_codes: List[List[str]] = [] + all_icd_times: List[float] = [] + all_lab_values: List[List[float]] = [] + all_lab_times: List[float] = [] - # Get admission information - admissions = patient.get_events(event_type="admissions") - admissions_info: Dict[str, Dict[str, Optional[datetime]]] = {} - - if admissions: - for admission in admissions: - hadm_id = getattr(admission, "hadm_id", None) - admit_time = self._safe_parse_datetime( - getattr(admission, "timestamp", None) - ) - discharge_time = self._safe_parse_datetime( - getattr(admission, "dischtime", None) - ) - if hadm_id is not None and admit_time is not None: - admissions_info[str(hadm_id)] = { - "admit": admit_time, - "discharge": discharge_time, - } - - # Create dummy admission if none exist - if not admissions_info: - dummy_hadm_id = f"dummy_{patient.patient_id}" - admissions_info[dummy_hadm_id] = { - "admit": datetime.now(), - "discharge": None, - } - - # Build ICD code sequences per admission (diagnoses + procedures) - admission_codes: Dict[str, List[str]] = { - hadm_id: [] for hadm_id in admissions_info - } + previous_admission_time: Optional[datetime] = None + has_dka = False + dka_time: Optional[datetime] = None - # Add diagnosis codes - for event in diagnosis_events: - code = getattr(event, "icd_code", None) - normalized_code = self._normalize_icd(code) - if not normalized_code: + # Iterate through admissions in chronological order + for admission in admissions: + # Parse admission times + try: + admission_time = admission.timestamp + dischtime_str = getattr(admission, "dischtime", None) + if dischtime_str: + admission_dischtime = datetime.strptime( + dischtime_str, "%Y-%m-%d %H:%M:%S" + ) + else: + admission_dischtime = None + except (ValueError, AttributeError): continue - hadm_id = getattr(event, "hadm_id", None) - admission_key = ( - str(hadm_id) - if hadm_id is not None - else list(admissions_info.keys())[0] + # Get diagnoses for this admission + diagnoses = patient.get_events( + event_type="diagnoses_icd", + filters=[("hadm_id", "==", admission.hadm_id)], ) - if admission_key in admission_codes: - admission_codes[admission_key].append(f"D_{normalized_code}") + # Iterate through diagnoses - check for DKA and collect codes + visit_codes: List[str] = [] + seen: Set[str] = set() - # Add procedure codes - procedure_events = patient.get_events(event_type="procedures_icd") - if procedure_events: - for event in procedure_events: - code = getattr(event, "icd_code", None) - normalized_code = self._normalize_icd(code) - if not normalized_code: + for diag in diagnoses: + code = getattr(diag, "icd_code", None) + version = getattr(diag, "icd_version", None) + if not code: continue - hadm_id = getattr(event, "hadm_id", None) - admission_key = ( - str(hadm_id) - if hadm_id is not None - else list(admissions_info.keys())[0] - ) - - if admission_key in admission_codes: - admission_codes[admission_key].append(f"P_{normalized_code}") - - # Sort admissions chronologically - sorted_admissions = sorted( - admissions_info.items(), - key=lambda item: item[1]["admit"] - if item[1]["admit"] is not None - else datetime.min, - ) + # Check for DKA - if found, record time and stop + if self._is_dka_code(code, version): + has_dka = True + dka_time = getattr(diag, "timestamp", admission_time) + break - # Build sequences - icd_sequences: List[List[str]] = [] - icd_times: List[float] = [] - lab_sequences: List[List[float]] = [] - lab_times: List[float] = [] - previous_admit: Optional[datetime] = None - - for hadm_id, info in sorted_admissions: - admit_time = info["admit"] - if admit_time is None: - admit_time = datetime.now() - - # Get deduplicated codes for this admission - codes = self._deduplicate_preserve_order( - admission_codes.get(hadm_id, []) + # Add diagnosis code if not seen + normalized = f"D_{code.replace('.', '').upper()}" + if normalized not in seen: + seen.add(normalized) + visit_codes.append(normalized) + + # If DKA found, don't append this visit's data and stop + if has_dka: + break + + # Get procedures for this admission + procedures = patient.get_events( + event_type="procedures_icd", + filters=[("hadm_id", "==", admission.hadm_id)], ) - if not codes: - codes = ["UNKNOWN"] - - # Calculate time gap from previous admission (hours) - time_gap = ( - 0.0 - if previous_admit is None - else (admit_time - previous_admit).total_seconds() / 3600.0 + + for proc in procedures: + code = getattr(proc, "icd_code", None) + if not code: + continue + normalized = f"P_{code.replace('.', '').upper()}" + if normalized not in seen: + seen.add(normalized) + visit_codes.append(normalized) + + # Calculate time from previous admission (hours) + if previous_admission_time is None: + time_from_previous = 0.0 + else: + time_from_previous = ( + admission_time - previous_admission_time + ).total_seconds() / 3600.0 + previous_admission_time = admission_time + + # Append this visit's codes + if visit_codes: + all_icd_codes.append(visit_codes) + all_icd_times.append(time_from_previous) + + # Get lab events for this admission using hadm_id + lab_df = patient.get_events( + event_type="labevents", + filters=[("hadm_id", "==", admission.hadm_id)], + return_df=True, ) - previous_admit = admit_time - icd_sequences.append(codes) - icd_times.append(time_gap) + if lab_df.height > 0: + all_lab_values.append(self._build_lab_vector(lab_df)) + all_lab_times.append(time_from_previous) - # Get lab data for this admission - try: - lab_df = patient.get_events( - event_type="labevents", - start=admit_time, - end=info.get("discharge"), - return_df=True, - ) - except Exception: - lab_df = None - - lab_sequences.append(self._build_lab_vector(lab_df)) - lab_times.append(time_gap) - - # Ensure we have at least one sequence entry - if not icd_sequences: - icd_sequences = [["UNKNOWN"]] - icd_times = [0.0] - lab_sequences = [[math.nan] * len(self.LAB_CATEGORY_ORDER)] - lab_times = [0.0] - - # Create sample in StageNet format - sample: Dict[str, Any] = { + # Skip if no pre-DKA data + if not all_icd_codes: + return [] + + # Determine label based on temporal relationship + has_dka_within_window = False + if has_dka and t1dm_times and dka_time: + for t1dm_time in t1dm_times: + delta = abs((dka_time - t1dm_time).days) + if delta <= self.dka_window_days: + has_dka_within_window = True + break + elif has_dka and not t1dm_times: + # Fallback: if no temporal info, use has_dka + has_dka_within_window = True + + # Ensure we have lab data + if not all_lab_values: + all_lab_values = [[math.nan] * len(self.LAB_CATEGORY_ORDER)] + all_lab_times = [0.0] + + return [{ "patient_id": patient.patient_id, "record_id": patient.patient_id, - "icd_codes": (icd_times, icd_sequences), - "labs": (lab_times, lab_sequences), + "icd_codes": (all_icd_times, all_icd_codes), + "labs": (all_lab_times, all_lab_values), "label": int(has_dka_within_window), - } - - return [sample] - + }]