From 90e47acc3719acb3843715a29b8e8bda2b9b4285 Mon Sep 17 00:00:00 2001 From: Rian354 Date: Thu, 14 May 2026 05:45:43 -0400 Subject: [PATCH 01/11] feat(tasks): generalized note section extraction by note type Introduces _RADIOLOGY_SECTION_TARGETS and a general-purpose extract_note_sections(text, note_type) static method that routes to discharge vs radiology target sets. _parse_note_sections splits the shared parsing logic. _extract_admission_sections is now a backward-compatible alias (all 18 unit tests still pass unchanged). Adds Social History, Family History, Allergies, ROS to discharge targets. Co-Authored-By: Claude Sonnet 4.6 --- pyhealth/tasks/multimodal_mimic4.py | 58 +++++++++++++++++++++++------ 1 file changed, 46 insertions(+), 12 deletions(-) diff --git a/pyhealth/tasks/multimodal_mimic4.py b/pyhealth/tasks/multimodal_mimic4.py index 248377322..ecf874b03 100644 --- a/pyhealth/tasks/multimodal_mimic4.py +++ b/pyhealth/tasks/multimodal_mimic4.py @@ -75,7 +75,9 @@ def __init__( ): self.window_hours = window_hours - _ADMISSION_SECTION_TARGETS: ClassVar[frozenset] = frozenset({ + # Discharge notes: admission-context sections (clinically available at + # admission time). Headers are lowercased before matching. + _DISCHARGE_SECTION_TARGETS: ClassVar[frozenset] = frozenset({ "chief complaint", "history of present illness", "hpi", @@ -86,10 +88,28 @@ def __init__( "medications on admission", "admission medications", "home medications", + "social history", + "family history", + "allergies", + "review of systems", + }) + + # Radiology notes: diagnostic findings sections. + _RADIOLOGY_SECTION_TARGETS: ClassVar[frozenset] = frozenset({ + "impression", + "findings", + "clinical indication", + "indication", + "clinical history", + "history", + "comparison", + "technique", + "conclusion", + "summary", }) # Matches a line that is purely a section header: words + colon + nothing else. - # E.g. "Chief Complaint:", "Past Medical History:", "HPI:". + # E.g. "Chief Complaint:", "Past Medical History:", "IMPRESSION:". _SECTION_HEADER_RE: ClassVar[re.Pattern] = re.compile( r"^\s*([A-Za-z][A-Za-z\s,/\-\.]{1,60}?)\s*:\s*$" ) @@ -100,17 +120,11 @@ def _clean_text(text: Optional[str]) -> Optional[str]: return text if text else None @staticmethod - def _extract_admission_sections(text: str) -> str: - """Extract admission-context sections from a MIMIC-IV discharge note. - - Parses Chief Complaint, HPI, Past Medical History, and Medications on - Admission sections — information clinically available at admission time. - Falls back to the first 1 024 characters if no target sections are found. - """ + def _parse_note_sections(text: str) -> Dict[str, str]: + """Split a note into {lowercased_header: content_text} pairs.""" sections: Dict[str, str] = {} current_key: Optional[str] = None current_lines: List[str] = [] - for line in text.split("\n"): m = BaseMultimodalMIMIC4Task._SECTION_HEADER_RE.match(line) if m: @@ -120,14 +134,34 @@ def _extract_admission_sections(text: str) -> str: current_lines = [] elif current_key is not None: current_lines.append(line) - if current_key is not None: sections[current_key] = "\n".join(current_lines).strip() + return sections - targets = BaseMultimodalMIMIC4Task._ADMISSION_SECTION_TARGETS + @staticmethod + def extract_note_sections(text: str, note_type: str = "discharge") -> str: + """Extract clinically relevant sections from a MIMIC-IV note. + + Routes to the appropriate target set based on note type. Falls back to + the first 1024 characters when no target sections are present. + + Args: + text: Raw note text. + note_type: ``"discharge"`` (default) or ``"radiology"``. + """ + if note_type == "radiology": + targets = BaseMultimodalMIMIC4Task._RADIOLOGY_SECTION_TARGETS + else: + targets = BaseMultimodalMIMIC4Task._DISCHARGE_SECTION_TARGETS + sections = BaseMultimodalMIMIC4Task._parse_note_sections(text) extracted = [v for k, v in sections.items() if k in targets and v] return " [SEP] ".join(extracted) if extracted else text[:1024] + @staticmethod + def _extract_admission_sections(text: str) -> str: + """Backward-compatible alias; extracts discharge note sections.""" + return BaseMultimodalMIMIC4Task.extract_note_sections(text, note_type="discharge") + def _collect_admission_note_sections( self, patient: Any, From 1541b1166a047fb739e837aafb5a310c031305d6 Mon Sep 17 00:00:00 2001 From: William Pang Date: Mon, 25 May 2026 15:21:44 -0700 Subject: [PATCH 02/11] Rename radiology_section_targets into radiology_clinical_headers --- pyhealth/tasks/multimodal_mimic4.py | 27 +++++++++++++-------------- 1 file changed, 13 insertions(+), 14 deletions(-) diff --git a/pyhealth/tasks/multimodal_mimic4.py b/pyhealth/tasks/multimodal_mimic4.py index ecf874b03..f80415654 100644 --- a/pyhealth/tasks/multimodal_mimic4.py +++ b/pyhealth/tasks/multimodal_mimic4.py @@ -69,6 +69,19 @@ class BaseMultimodalMIMIC4Task(BaseTask): item for itemids in VITAL_CATEGORIES.values() for item in itemids ] + RADIOLOGY_CLINICAL_HEADERS: ClassVar[List[str]] = [ + "impression", + "findings", + "clinical indication", + "indication", + "clinical history", + "history", + "comparison", + "technique", + "conclusion", + "summary", + ] + def __init__( self, window_hours: Optional[float] = None, @@ -94,20 +107,6 @@ def __init__( "review of systems", }) - # Radiology notes: diagnostic findings sections. - _RADIOLOGY_SECTION_TARGETS: ClassVar[frozenset] = frozenset({ - "impression", - "findings", - "clinical indication", - "indication", - "clinical history", - "history", - "comparison", - "technique", - "conclusion", - "summary", - }) - # Matches a line that is purely a section header: words + colon + nothing else. # E.g. "Chief Complaint:", "Past Medical History:", "IMPRESSION:". _SECTION_HEADER_RE: ClassVar[re.Pattern] = re.compile( From 9848f2fdf8dae3f574d3d2dbcf4f389ed2cf9093 Mon Sep 17 00:00:00 2001 From: William Pang Date: Mon, 25 May 2026 15:29:04 -0700 Subject: [PATCH 03/11] Revert "Rename radiology_section_targets into radiology_clinical_headers" This reverts commit 1541b1166a047fb739e837aafb5a310c031305d6. --- pyhealth/tasks/multimodal_mimic4.py | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/pyhealth/tasks/multimodal_mimic4.py b/pyhealth/tasks/multimodal_mimic4.py index f80415654..ecf874b03 100644 --- a/pyhealth/tasks/multimodal_mimic4.py +++ b/pyhealth/tasks/multimodal_mimic4.py @@ -69,19 +69,6 @@ class BaseMultimodalMIMIC4Task(BaseTask): item for itemids in VITAL_CATEGORIES.values() for item in itemids ] - RADIOLOGY_CLINICAL_HEADERS: ClassVar[List[str]] = [ - "impression", - "findings", - "clinical indication", - "indication", - "clinical history", - "history", - "comparison", - "technique", - "conclusion", - "summary", - ] - def __init__( self, window_hours: Optional[float] = None, @@ -107,6 +94,20 @@ def __init__( "review of systems", }) + # Radiology notes: diagnostic findings sections. + _RADIOLOGY_SECTION_TARGETS: ClassVar[frozenset] = frozenset({ + "impression", + "findings", + "clinical indication", + "indication", + "clinical history", + "history", + "comparison", + "technique", + "conclusion", + "summary", + }) + # Matches a line that is purely a section header: words + colon + nothing else. # E.g. "Chief Complaint:", "Past Medical History:", "IMPRESSION:". _SECTION_HEADER_RE: ClassVar[re.Pattern] = re.compile( From 6a0b86f3156603c911fe699d4d38ebfb3adc1044 Mon Sep 17 00:00:00 2001 From: William Pang Date: Mon, 25 May 2026 15:31:18 -0700 Subject: [PATCH 04/11] rename radiology section targets as radiology clinical headers --- pyhealth/tasks/multimodal_mimic4.py | 27 +++++++++++++-------------- 1 file changed, 13 insertions(+), 14 deletions(-) diff --git a/pyhealth/tasks/multimodal_mimic4.py b/pyhealth/tasks/multimodal_mimic4.py index ecf874b03..835e29d66 100644 --- a/pyhealth/tasks/multimodal_mimic4.py +++ b/pyhealth/tasks/multimodal_mimic4.py @@ -69,6 +69,19 @@ class BaseMultimodalMIMIC4Task(BaseTask): item for itemids in VITAL_CATEGORIES.values() for item in itemids ] + RADIOLOGY_CLINICAL_HEADERS: ClassVar[List[str]] = [ + "impression", + "findings", + "clinical indication", + "indication", + "clinical history", + "history", + "comparison", + "technique", + "conclusion", + "summary" + ] + def __init__( self, window_hours: Optional[float] = None, @@ -94,20 +107,6 @@ def __init__( "review of systems", }) - # Radiology notes: diagnostic findings sections. - _RADIOLOGY_SECTION_TARGETS: ClassVar[frozenset] = frozenset({ - "impression", - "findings", - "clinical indication", - "indication", - "clinical history", - "history", - "comparison", - "technique", - "conclusion", - "summary", - }) - # Matches a line that is purely a section header: words + colon + nothing else. # E.g. "Chief Complaint:", "Past Medical History:", "IMPRESSION:". _SECTION_HEADER_RE: ClassVar[re.Pattern] = re.compile( From 38d883ce54e64c67560c7aac3ca3a60b1e7c992f Mon Sep 17 00:00:00 2001 From: William Pang Date: Mon, 25 May 2026 15:35:54 -0700 Subject: [PATCH 05/11] Rename discharge clinical section targets as discharge clinical headers --- pyhealth/tasks/multimodal_mimic4.py | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/pyhealth/tasks/multimodal_mimic4.py b/pyhealth/tasks/multimodal_mimic4.py index 835e29d66..61ba9321a 100644 --- a/pyhealth/tasks/multimodal_mimic4.py +++ b/pyhealth/tasks/multimodal_mimic4.py @@ -82,15 +82,7 @@ class BaseMultimodalMIMIC4Task(BaseTask): "summary" ] - def __init__( - self, - window_hours: Optional[float] = None, - ): - self.window_hours = window_hours - - # Discharge notes: admission-context sections (clinically available at - # admission time). Headers are lowercased before matching. - _DISCHARGE_SECTION_TARGETS: ClassVar[frozenset] = frozenset({ + DISCHARGE_CLINICAL_HEADERS: ClassVar[List[str]] = [ "chief complaint", "history of present illness", "hpi", @@ -105,7 +97,13 @@ def __init__( "family history", "allergies", "review of systems", - }) + ] + + def __init__( + self, + window_hours: Optional[float] = None, + ): + self.window_hours = window_hours # Matches a line that is purely a section header: words + colon + nothing else. # E.g. "Chief Complaint:", "Past Medical History:", "IMPRESSION:". From a5750ac3de0fa7a9492b79bfe782feb13c5903fe Mon Sep 17 00:00:00 2001 From: William Pang Date: Fri, 29 May 2026 22:57:50 -0700 Subject: [PATCH 06/11] Some updates --- .../multimodal_mimic4_task_tutorial.ipynb | 278 ++- pyhealth/tasks/multimodal_mimic4.py | 161 +- .../core/mimic4demo/note/discharge.csv | 1894 ++++++++++++++++- 3 files changed, 2180 insertions(+), 153 deletions(-) diff --git a/examples/multimodal_mimic4_task_tutorial.ipynb b/examples/multimodal_mimic4_task_tutorial.ipynb index 3fda88002..362c82c98 100644 --- a/examples/multimodal_mimic4_task_tutorial.ipynb +++ b/examples/multimodal_mimic4_task_tutorial.ipynb @@ -25,7 +25,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 1, "id": "8477e2ac-322f-49e9-819f-ce7621b214c6", "metadata": {}, "outputs": [], @@ -50,7 +50,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 2, "id": "201c3a62-2a2e-47ab-9ab8-eea77812f349", "metadata": {}, "outputs": [], @@ -69,15 +69,12 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 3, "id": "9a466c4b-2283-443f-94a3-5768babddf50", "metadata": {}, "outputs": [], "source": [ - "SEED = 42\n", - "random.seed(SEED)\n", - "np.random.seed(SEED)\n", - "torch.manual_seed(SEED)" + "SEED = 999" ] }, { @@ -90,7 +87,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 4, "id": "05ec2dc9-1a0c-4360-a028-d93173dcba65", "metadata": {}, "outputs": [], @@ -108,7 +105,7 @@ " print(f\" admittime: {adm.timestamp}\")\n", " print(f\" dischtime: {adm.dischtime}\")\n", "\n", - "def print_patient_note_info(sample, note_type=\"discharge\", char_limit=80):\n", + "def print_patient_note_info(sample, note_type=\"discharge\", char_limit=500):\n", " patient = dataset.get_patient(sample['patient_id'])\n", " notes = patient.get_events(\n", " event_type=note_type,\n", @@ -139,12 +136,12 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 5, "id": "tv8ir9mp9t", "metadata": {}, "outputs": [], "source": [ - "PYHEALTH_REPO_ROOT = '/Users/wpang/Desktop/PyHealth'\n", + "PYHEALTH_REPO_ROOT = '/Users/williampang/Desktop/PyHealth'\n", "\n", "EHR_ROOT = os.path.join(PYHEALTH_REPO_ROOT, \"test-resources/core/mimic4demo\")\n", "NOTE_ROOT = os.path.join(PYHEALTH_REPO_ROOT, \"test-resources/core/mimic4demo\")\n", @@ -153,10 +150,43 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 6, "id": "2f0f9ac3-1e3e-438b-b463-32e839941ce0", "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Memory usage Starting MIMIC4Dataset init: 475.3 MB\n", + "Initializing mimic4 dataset from /Users/williampang/Desktop/PyHealth/test-resources/core/mimic4demo|/Users/williampang/Desktop/PyHealth/test-resources/core/mimic4demo|None (dev mode: False)\n", + "Using provided cache_dir: /var/folders/zl/lm3qrxjd2jl17byd443y505h0000gn/T/tmpzo54xibb/efe373f9-a874-5fc5-96be-d6950c2af293\n", + "Initializing MIMIC4EHRDataset with tables: ['diagnoses_icd', 'procedures_icd', 'labevents'] (dev mode: False)\n", + "Using default EHR config: /Users/williampang/Desktop/PyHealth/pyhealth/datasets/configs/mimic4_ehr.yaml\n", + "Memory usage Before initializing mimic4_ehr: 475.3 MB\n", + "Initializing mimic4_ehr dataset from /Users/williampang/Desktop/PyHealth/test-resources/core/mimic4demo (dev mode: False)\n", + "Using provided cache_dir: /var/folders/zl/lm3qrxjd2jl17byd443y505h0000gn/T/tmpzo54xibb/efe373f9-a874-5fc5-96be-d6950c2af293/b271011a-2030-58ea-b25e-ee3250e00f4b\n", + "Memory usage After initializing mimic4_ehr: 475.5 MB\n", + "Memory usage After EHR dataset initialization: 475.5 MB\n", + "Initializing MIMIC4NoteDataset with tables: ['discharge', 'radiology'] (dev mode: False)\n", + "Using default note config: /Users/williampang/Desktop/PyHealth/pyhealth/datasets/configs/mimic4_note.yaml\n", + "Memory usage Before initializing mimic4_note: 475.5 MB\n", + "Initializing mimic4_note dataset from /Users/williampang/Desktop/PyHealth/test-resources/core/mimic4demo (dev mode: False)\n", + "Using provided cache_dir: /var/folders/zl/lm3qrxjd2jl17byd443y505h0000gn/T/tmpzo54xibb/efe373f9-a874-5fc5-96be-d6950c2af293/6e09f2d3-d3cc-5cd5-951c-e0e02a7aff3c\n", + "Memory usage After initializing mimic4_note: 475.5 MB\n", + "Memory usage After Note dataset initialization: 475.5 MB\n", + "Memory usage Completed MIMIC4Dataset init: 475.5 MB\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "/Users/williampang/Desktop/PyHealth/pyhealth/datasets/mimic4.py:121: UserWarning: Events from discharge table only have date timestamp (no specific time). This may affect temporal ordering of events.\n", + " warnings.warn(\n" + ] + } + ], "source": [ "dataset = MIMIC4Dataset(\n", " ehr_root=EHR_ROOT,\n", @@ -187,10 +217,49 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 7, "id": "d3b027ab-c814-49cd-8542-885d76b2401b", "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Setting task ClinicalNotesICDLabsMIMIC4 for mimic4 base dataset...\n", + "Task cache paths: task_df=/var/folders/zl/lm3qrxjd2jl17byd443y505h0000gn/T/tmpzo54xibb/efe373f9-a874-5fc5-96be-d6950c2af293/tasks/ClinicalNotesICDLabsMIMIC4_493ab707-d120-581c-a795-319ffd5c468e/task_df.ld, samples=/var/folders/zl/lm3qrxjd2jl17byd443y505h0000gn/T/tmpzo54xibb/efe373f9-a874-5fc5-96be-d6950c2af293/tasks/ClinicalNotesICDLabsMIMIC4_493ab707-d120-581c-a795-319ffd5c468e/samples_cdbbc602-34e2-5a41-8643-4c76b08829f6.ld\n", + "Applying task transformations on data with 1 workers...\n", + "No cached event dataframe found. Creating: /var/folders/zl/lm3qrxjd2jl17byd443y505h0000gn/T/tmpzo54xibb/efe373f9-a874-5fc5-96be-d6950c2af293/global_event_df.parquet\n", + "Combining data from ehr dataset\n", + "Scanning table: diagnoses_icd from /Users/williampang/Desktop/PyHealth/test-resources/core/mimic4demo/hosp/diagnoses_icd.csv.gz\n", + "Joining with table: /Users/williampang/Desktop/PyHealth/test-resources/core/mimic4demo/hosp/admissions.csv.gz\n", + "Scanning table: procedures_icd from /Users/williampang/Desktop/PyHealth/test-resources/core/mimic4demo/hosp/procedures_icd.csv.gz\n", + "Joining with table: /Users/williampang/Desktop/PyHealth/test-resources/core/mimic4demo/hosp/admissions.csv.gz\n", + "Scanning table: labevents from /Users/williampang/Desktop/PyHealth/test-resources/core/mimic4demo/hosp/labevents.csv.gz\n", + "Joining with table: /Users/williampang/Desktop/PyHealth/test-resources/core/mimic4demo/hosp/d_labitems.csv.gz\n", + "Scanning table: patients from /Users/williampang/Desktop/PyHealth/test-resources/core/mimic4demo/hosp/patients.csv.gz\n", + "Scanning table: admissions from /Users/williampang/Desktop/PyHealth/test-resources/core/mimic4demo/hosp/admissions.csv.gz\n", + "Scanning table: icustays from /Users/williampang/Desktop/PyHealth/test-resources/core/mimic4demo/icu/icustays.csv.gz\n", + "Combining data from note dataset\n", + "Scanning table: discharge from /Users/williampang/Desktop/PyHealth/test-resources/core/mimic4demo/note/discharge.csv.gz\n", + "Scanning table: radiology from /Users/williampang/Desktop/PyHealth/test-resources/core/mimic4demo/note/radiology.csv.gz\n", + "Creating combined dataframe\n", + "Caching event dataframe to /var/folders/zl/lm3qrxjd2jl17byd443y505h0000gn/T/tmpzo54xibb/efe373f9-a874-5fc5-96be-d6950c2af293/global_event_df.parquet...\n", + "Detected Jupyter notebook environment, setting num_workers to 1\n", + "Single worker mode, processing sequentially\n", + "Worker 0 started processing 13 patients. (Polars threads: 12)\n", + "Worker 0 finished processing patients.\n", + "Fitting processors on the dataset...\n", + "Label mortality vocab: {0: 0, 1: 1}\n", + "Processing samples and saving to /var/folders/zl/lm3qrxjd2jl17byd443y505h0000gn/T/tmpzo54xibb/efe373f9-a874-5fc5-96be-d6950c2af293/tasks/ClinicalNotesICDLabsMIMIC4_493ab707-d120-581c-a795-319ffd5c468e/samples_cdbbc602-34e2-5a41-8643-4c76b08829f6.ld...\n", + "Applying processors on data with 1 workers...\n", + "Detected Jupyter notebook environment, setting num_workers to 1\n", + "Single worker mode, processing sequentially\n", + "Worker 0 started processing 13 samples. (0 to 13)\n", + "Worker 0 finished processing samples.\n", + "Cached processed samples to /var/folders/zl/lm3qrxjd2jl17byd443y505h0000gn/T/tmpzo54xibb/efe373f9-a874-5fc5-96be-d6950c2af293/tasks/ClinicalNotesICDLabsMIMIC4_493ab707-d120-581c-a795-319ffd5c468e/samples_cdbbc602-34e2-5a41-8643-4c76b08829f6.ld\n" + ] + } + ], "source": [ "%%capture\n", "task = ClinicalNotesICDLabsMIMIC4()\n", @@ -199,11 +268,67 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 8, "id": "6b70acb2-bdea-4a43-8b9a-7725c34fcfce", "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "\n", + "Patient ID: 1\n", + "Mortality Flag: tensor([0.])\n", + "Found 13 unique patient IDs\n", + "\n", + "num_admissions: 2\n", + " hadm_id: 1\n", + " admittime: 2150-01-01 00:00:00\n", + " dischtime: 2150-01-01 01:00:00\n", + " hadm_id: 2\n", + " admittime: 2150-01-16 00:00:00\n", + " dischtime: 2150-01-16 01:00:00\n", + "\n", + "discharge notes: 1\n", + " note_id: d18\n", + " hadm_id: 1\n", + " charttime: 2150-01-01 12:00:00\n", + " storetime: 2150-01-01 13:00:00\n", + " text: Name: ___ Unit No: ___\n", + "\n", + "Admission Date: ___ Discharge Date: ___\n", + "\n", + "Date of Birth: ___ Sex: F\n", + "\n", + "Service: NEUROLOGY\n", + "\n", + "Allergies:\n", + "codeine\n", + "\n", + "Attending: ___.\n", + "\n", + "Chief Complaint:\n", + "sudden onset left-sided weakness\n", + "\n", + "Major Surgical or Invasive Procedure:\n", + "IV tPA administration\n", + "\n", + "History of Present Illness:\n", + "___ year old female with hypertension and atrial fibrillation brought by EMS\n", + "with sudden onset left arm and leg weakness and facial droop noted 2 hours\n", + "prior to..(Limited to 500 Characters).\n", + "\n", + "radiology notes: 1\n", + " note_id: r18\n", + " hadm_id: 1\n", + " charttime: 2150-01-01 14:00:00\n", + " storetime: 2150-01-01 15:00:00\n", + " text: Chest X-ray for patient 1. No acute cardiopulmonary process identified. Heart size normal...(Limited to 500 Characters).\n" + ] + } + ], "source": [ + "np.random.seed(SEED)\n", "random_patient_record = np.random.randint(0, len(samples)-1)\n", "sample = samples[random_patient_record]\n", "sample_patient_id = sample['patient_id']\n", @@ -231,10 +356,33 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 9, "id": "16121916-e52e-4f66-8463-ff0f931cf416", "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Setting task ClinicalNotesICDLabsMIMIC4 for mimic4 base dataset...\n", + "Task cache paths: task_df=/var/folders/zl/lm3qrxjd2jl17byd443y505h0000gn/T/tmpzo54xibb/efe373f9-a874-5fc5-96be-d6950c2af293/tasks/ClinicalNotesICDLabsMIMIC4_6c674c02-3635-50c0-bdde-3a45cb1e6f31/task_df.ld, samples=/var/folders/zl/lm3qrxjd2jl17byd443y505h0000gn/T/tmpzo54xibb/efe373f9-a874-5fc5-96be-d6950c2af293/tasks/ClinicalNotesICDLabsMIMIC4_6c674c02-3635-50c0-bdde-3a45cb1e6f31/samples_cdbbc602-34e2-5a41-8643-4c76b08829f6.ld\n", + "Applying task transformations on data with 1 workers...\n", + "Detected Jupyter notebook environment, setting num_workers to 1\n", + "Single worker mode, processing sequentially\n", + "Worker 0 started processing 13 patients. (Polars threads: 12)\n", + "Worker 0 finished processing patients.\n", + "Fitting processors on the dataset...\n", + "Label mortality vocab: {0: 0, 1: 1}\n", + "Processing samples and saving to /var/folders/zl/lm3qrxjd2jl17byd443y505h0000gn/T/tmpzo54xibb/efe373f9-a874-5fc5-96be-d6950c2af293/tasks/ClinicalNotesICDLabsMIMIC4_6c674c02-3635-50c0-bdde-3a45cb1e6f31/samples_cdbbc602-34e2-5a41-8643-4c76b08829f6.ld...\n", + "Applying processors on data with 1 workers...\n", + "Detected Jupyter notebook environment, setting num_workers to 1\n", + "Single worker mode, processing sequentially\n", + "Worker 0 started processing 13 samples. (0 to 13)\n", + "Worker 0 finished processing samples.\n", + "Cached processed samples to /var/folders/zl/lm3qrxjd2jl17byd443y505h0000gn/T/tmpzo54xibb/efe373f9-a874-5fc5-96be-d6950c2af293/tasks/ClinicalNotesICDLabsMIMIC4_6c674c02-3635-50c0-bdde-3a45cb1e6f31/samples_cdbbc602-34e2-5a41-8643-4c76b08829f6.ld\n" + ] + } + ], "source": [ "%%capture\n", "task = ClinicalNotesICDLabsMIMIC4(window_hours=12)\n", @@ -245,10 +393,58 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 10, "id": "42df85ab-2649-497b-92a2-415dc169798e", "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "\n", + "Patient ID: 1\n", + "Mortality Flag: tensor([0.])\n", + "Window start: 2150-01-01 00:00:00\n", + "Window end: 2150-01-01 12:00:00\n", + "\n", + "num_admissions: 1\n", + " hadm_id: 1\n", + " admittime: 2150-01-01 00:00:00\n", + " dischtime: 2150-01-01 01:00:00\n", + "\n", + "discharge notes: 1\n", + " note_id: d18\n", + " hadm_id: 1\n", + " charttime: 2150-01-01 12:00:00\n", + " storetime: 2150-01-01 13:00:00\n", + " text: Name: ___ Unit No: ___\n", + "\n", + "Admission Date: ___ Discharge Date: ___\n", + "\n", + "Date of Birth: ___ Sex: F\n", + "\n", + "Service: NEUROLOGY\n", + "\n", + "Allergies:\n", + "codeine\n", + "\n", + "Attending: ___.\n", + "\n", + "Chief Complaint:\n", + "sudden onset left-sided weakness\n", + "\n", + "Major Surgical or Invasive Procedure:\n", + "IV tPA administration\n", + "\n", + "History of Present Illness:\n", + "___ year old female with hypertension and atrial fibrillation brought by EMS\n", + "with sudden onset left arm and leg weakness and facial droop noted 2 hours\n", + "prior to..(Limited to 500 Characters).\n", + "\n", + "radiology notes: 0\n" + ] + } + ], "source": [ "print(f\"\\nPatient ID: {sample_patient_id}\")\n", "print(f\"Mortality Flag: {sample['mortality']}\")\n", @@ -265,6 +461,37 @@ "print_patient_note_info(sample, note_type=\"radiology\")" ] }, + { + "cell_type": "markdown", + "id": "e1dd556a", + "metadata": {}, + "source": [ + "### 3.3 Inspect Pre-Tokenization Note Text\n", + "\n", + "Call the task directly on a patient (bypassing the processor) to see the note text **after section filtering but before tokenization**. This lets you verify the note has been shrunk to only the `DISCHARGE_CLINICAL_HEADERS` sections." + ] + }, + { + "cell_type": "code", + "execution_count": 11, + "id": "e089c9b6", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[{'patient_id': '1', 'discharge_note_times': (['chief complaint: sudden onset left-sided weakness'], [12.0]), 'radiology_note_times': ([], []), 'icd_codes': ([0.0, 0.0], [[''], ['']]), 'labs': ([0.0, 0.0], [[0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0], [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0]]), 'labs_mask': ([0.0, 0.0], [[False, False, False, False, False, False, False, False, False, False], [False, False, False, False, False, False, False, False, False, False]]), 'mortality': 0, 'window_start': datetime.datetime(2150, 1, 1, 0, 0), 'window_end': datetime.datetime(2150, 1, 1, 12, 0)}]\n" + ] + } + ], + "source": [ + "patient = dataset.get_patient(sample_patient_id)\n", + "raw_samples = task(patient)\n", + "\n", + "print(raw_samples)" + ] + }, { "cell_type": "markdown", "id": "a447c4e2-cfae-4e15-a2ac-0fac5754c1f2", @@ -283,7 +510,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 12, "id": "57208cc0-94af-456d-9078-12acaf556df7", "metadata": {}, "outputs": [], @@ -294,9 +521,9 @@ ], "metadata": { "kernelspec": { - "display_name": "Python 3 (ipykernel)", + "display_name": "pyhealth", "language": "python", - "name": "python3" + "name": "pyhealth" }, "language_info": { "codemirror_mode": { @@ -307,7 +534,8 @@ "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", - "pygments_lexer": "ipython3" + "pygments_lexer": "ipython3", + "version": "3.13.3" } }, "nbformat": 4, diff --git a/pyhealth/tasks/multimodal_mimic4.py b/pyhealth/tasks/multimodal_mimic4.py index 61ba9321a..88a2f0ea0 100644 --- a/pyhealth/tasks/multimodal_mimic4.py +++ b/pyhealth/tasks/multimodal_mimic4.py @@ -84,19 +84,19 @@ class BaseMultimodalMIMIC4Task(BaseTask): DISCHARGE_CLINICAL_HEADERS: ClassVar[List[str]] = [ "chief complaint", - "history of present illness", - "hpi", - "past medical history", - "past medical and surgical history", - "past medical/surgical history", - "past surgical history", - "medications on admission", - "admission medications", - "home medications", - "social history", - "family history", - "allergies", - "review of systems", + # "history of present illness", + # "hpi", + # "past medical history", + # "past medical and surgical history", + # "past medical/surgical history", + # "past surgical history", + # "medications on admission", + # "admission medications", + # "home medications", + # "social history", + # "family history", + # "allergies", + # "review of systems", ] def __init__( @@ -105,12 +105,6 @@ def __init__( ): self.window_hours = window_hours - # Matches a line that is purely a section header: words + colon + nothing else. - # E.g. "Chief Complaint:", "Past Medical History:", "IMPRESSION:". - _SECTION_HEADER_RE: ClassVar[re.Pattern] = re.compile( - r"^\s*([A-Za-z][A-Za-z\s,/\-\.]{1,60}?)\s*:\s*$" - ) - @staticmethod def _clean_text(text: Optional[str]) -> Optional[str]: """Return text if non-empty, otherwise None.""" @@ -119,80 +113,14 @@ def _clean_text(text: Optional[str]) -> Optional[str]: @staticmethod def _parse_note_sections(text: str) -> Dict[str, str]: """Split a note into {lowercased_header: content_text} pairs.""" - sections: Dict[str, str] = {} - current_key: Optional[str] = None - current_lines: List[str] = [] - for line in text.split("\n"): - m = BaseMultimodalMIMIC4Task._SECTION_HEADER_RE.match(line) - if m: - if current_key is not None: - sections[current_key] = "\n".join(current_lines).strip() - current_key = m.group(1).strip().lower() - current_lines = [] - elif current_key is not None: - current_lines.append(line) - if current_key is not None: - sections[current_key] = "\n".join(current_lines).strip() - return sections - - @staticmethod - def extract_note_sections(text: str, note_type: str = "discharge") -> str: - """Extract clinically relevant sections from a MIMIC-IV note. - - Routes to the appropriate target set based on note type. Falls back to - the first 1024 characters when no target sections are present. - - Args: - text: Raw note text. - note_type: ``"discharge"`` (default) or ``"radiology"``. - """ - if note_type == "radiology": - targets = BaseMultimodalMIMIC4Task._RADIOLOGY_SECTION_TARGETS - else: - targets = BaseMultimodalMIMIC4Task._DISCHARGE_SECTION_TARGETS - sections = BaseMultimodalMIMIC4Task._parse_note_sections(text) - extracted = [v for k, v in sections.items() if k in targets and v] - return " [SEP] ".join(extracted) if extracted else text[:1024] - - @staticmethod - def _extract_admission_sections(text: str) -> str: - """Backward-compatible alias; extracts discharge note sections.""" - return BaseMultimodalMIMIC4Task.extract_note_sections(text, note_type="discharge") - - def _collect_admission_note_sections( - self, - patient: Any, - hadm_id: Any, - admission_time: datetime, - ) -> Tuple[List[str], List[float]]: - """Collect admission-context text from the discharge note. - - No time filter is applied because the target sections (CC, HPI, PMH, - Medications on Admission) describe the patient's state *at admission* - regardless of when the note was finalised. Returned timestamps are 0.0 - so downstream models treat the text as admission-time context. - """ - notes = patient.get_events( - event_type="discharge", - filters=[("hadm_id", "==", hadm_id)], + section_re = re.compile( + r"^\s*([A-Za-z][A-Za-z \t,/\-\.]{1,60}?)\s*:\s*\n(.*?)(?=^\s*[A-Za-z][A-Za-z \t,/\-\.]{1,60}?\s*:\s*$|\Z)", + re.MULTILINE | re.DOTALL, ) - - texts: List[str] = [] - for note in notes: - try: - raw = note.text - if not raw: - continue - extracted = self._extract_admission_sections(raw) - if extracted: - texts.append(extracted) - except AttributeError: - pass - - if not texts: - return [self.MISSING_TEXT_TOKEN], [self.MISSING_FLOAT_TOKEN] - - return texts, [0.0] * len(texts) + return { + m.group(1).strip().lower(): m.group(2).strip() + for m in section_re.finditer(text) + } @staticmethod def _parse_datetime(value: Any) -> Optional[datetime]: @@ -455,6 +383,7 @@ def _collect_notes( admission_time: datetime, start_time: Optional[datetime] = None, end_time: Optional[datetime] = None, + section_headers: Optional[List[str]] = None, ) -> Tuple[List[str], List[float]]: """Collect notes of a given type for one admission. @@ -463,8 +392,11 @@ def _collect_notes( note_event_type: Event type string (e.g. "discharge", "radiology"). hadm_id: Admission ID to filter by. admission_time: Admission start time; used to compute time offsets. - start_time: Optional start of the time window - end_time: Optional end of the time window + start_time: Optional start of the time window. + end_time: Optional end of the time window. + section_headers: When provided, extract only these named sections + from each note (lowercased match against parsed headers). Falls + back to the full note text when no matching sections are found. Returns: Tuple of (texts, hours_from_admission). Falls back to @@ -484,6 +416,10 @@ def _collect_notes( try: note_text = self._clean_text(note.text) if note_text: + if section_headers is not None: + parsed = self._parse_note_sections(note_text) + extracted = [f"{k}: {v}" for k, v in parsed.items() if k in section_headers and v] + note_text = " [SEP] ".join(extracted) if extracted else note_text time_from_admission = self._to_hours( (note.timestamp - admission_time).total_seconds() ) @@ -494,12 +430,6 @@ def _collect_notes( ): # note object is missing .text or .timestamp attribute (e.g. malformed note) pass - if ( - not notes or not texts - ): # If we get an empty list or all notes were malformed - return [self.MISSING_TEXT_TOKEN], [ - self.MISSING_FLOAT_TOKEN - ] # Token representing missing text/time return texts, note_times @@ -580,6 +510,7 @@ def __call__(self, patient: Any) -> List[Dict[str, Any]]: admission_time, start_time=effective_start, end_time=effective_end, + section_headers=self.DISCHARGE_CLINICAL_HEADERS, ) all_discharge_texts.extend(discharge_texts) all_discharge_times_from_admission.extend(discharge_times) @@ -591,10 +522,18 @@ def __call__(self, patient: Any) -> List[Dict[str, Any]]: admission_time, start_time=effective_start, end_time=effective_end, + section_headers=self.RADIOLOGY_CLINICAL_HEADERS, ) all_radiology_texts.extend(radiology_texts) all_radiology_times_from_admission.extend(radiology_times) + if not all_discharge_texts: + all_discharge_texts = [self.MISSING_TEXT_TOKEN] + all_discharge_times_from_admission = [self.MISSING_FLOAT_TOKEN] + if not all_radiology_texts: + all_radiology_texts = [self.MISSING_TEXT_TOKEN] + all_radiology_times_from_admission = [self.MISSING_FLOAT_TOKEN] + discharge_note_times_from_admission = ( all_discharge_texts, all_discharge_times_from_admission, @@ -728,6 +667,7 @@ def __call__(self, patient: Any) -> List[Dict[str, Any]]: admission_time, start_time=effective_start, end_time=effective_end, + section_headers=self.DISCHARGE_CLINICAL_HEADERS, ) all_discharge_texts.extend(discharge_texts) all_discharge_times_from_admission.extend(discharge_times) @@ -739,6 +679,7 @@ def __call__(self, patient: Any) -> List[Dict[str, Any]]: admission_time, start_time=effective_start, end_time=effective_end, + section_headers=self.RADIOLOGY_CLINICAL_HEADERS, ) all_radiology_texts.extend(radiology_texts) all_radiology_times_from_admission.extend(radiology_times) @@ -777,6 +718,13 @@ def __call__(self, patient: Any) -> List[Dict[str, Any]]: all_lab_masks.append([False] * len(self.LAB_CATEGORY_NAMES)) all_lab_times.append(self.MISSING_FLOAT_TOKEN) + if not all_discharge_texts: + all_discharge_texts = [self.MISSING_TEXT_TOKEN] + all_discharge_times_from_admission = [self.MISSING_FLOAT_TOKEN] + if not all_radiology_texts: + all_radiology_texts = [self.MISSING_TEXT_TOKEN] + all_radiology_times_from_admission = [self.MISSING_FLOAT_TOKEN] + discharge_note_times_from_admission = ( all_discharge_texts, all_discharge_times_from_admission, @@ -1023,9 +971,12 @@ def __call__(self, patient: Any) -> List[Dict[str, Any]]: if admission_dischtime < admission_time: admission_dischtime = admission_time - # Admission-context sections — no time window applied to notes - note_texts, note_times = self._collect_admission_note_sections( - patient, admission.hadm_id, admission_time + note_texts, note_times = self._collect_notes( + patient, + "discharge", + admission.hadm_id, + admission_time, + section_headers=self.DISCHARGE_CLINICAL_HEADERS, ) all_note_texts.extend(note_texts) all_note_times.extend(note_times) @@ -1087,6 +1038,10 @@ def __call__(self, patient: Any) -> List[Dict[str, Any]]: all_vital_masks.append([False] * len(self.VITAL_CATEGORY_NAMES)) all_vital_times.append(self.MISSING_FLOAT_TOKEN) + if not all_note_texts: + all_note_texts = [self.MISSING_TEXT_TOKEN] + all_note_times = [self.MISSING_FLOAT_TOKEN] + record: Dict[str, Any] = { "patient_id": patient.patient_id, "admission_note_times": (all_note_texts, all_note_times), diff --git a/test-resources/core/mimic4demo/note/discharge.csv b/test-resources/core/mimic4demo/note/discharge.csv index 116c6d69e..ddc46151f 100644 --- a/test-resources/core/mimic4demo/note/discharge.csv +++ b/test-resources/core/mimic4demo/note/discharge.csv @@ -1,25 +1,1869 @@ -note_id,subject_id,hadm_id,note_type,note_seq,charttime,storetime,text -d1,10001,19999,DS,1,2150-02-18 12:00:00,2150-02-18 13:00:00,Patient 10001 admitted for evaluation. Vitals stable. Labs reviewed. Discharged in good condition. -d2,10002,20000,DS,1,2151-01-02 12:00:00,2151-01-02 13:00:00,Patient 10002 admitted for evaluation. Vitals stable. Labs reviewed. Discharged in good condition. -d3,10001,20001,DS,1,2150-03-18 12:00:00,2150-03-18 13:00:00,Patient 10001 admitted for evaluation. Vitals stable. Labs reviewed. Discharged in good condition. -d4,10001,20002,DS,1,2150-06-25 12:00:00,2150-06-25 13:00:00,Patient 10001 admitted for evaluation. Vitals stable. Labs reviewed. Discharged in good condition. -d5,10002,20003,DS,1,2151-01-12 12:00:00,2151-01-12 13:00:00,Patient 10002 admitted for evaluation. Vitals stable. Labs reviewed. Discharged in good condition. -d6,10002,20004,DS,1,2151-04-20 12:00:00,2151-04-20 13:00:00,Patient 10002 admitted for evaluation. Vitals stable. Labs reviewed. Discharged in good condition. -d7,10003,20005,DS,1,2152-03-05 12:00:00,2152-03-05 13:00:00,Patient 10003 admitted for evaluation. Vitals stable. Labs reviewed. Discharged in good condition. -d8,10003,20006,DS,1,2152-08-15 12:00:00,2152-08-15 13:00:00,Patient 10003 admitted for evaluation. Vitals stable. Labs reviewed. Discharged in good condition. -d9,10004,20007,DS,1,2150-05-02 12:00:00,2150-05-02 13:00:00,Patient 10004 admitted for evaluation. Vitals stable. Labs reviewed. Discharged in good condition. -d10,10005,20008,DS,1,2151-07-22 12:00:00,2151-07-22 13:00:00,Patient 10005 admitted for evaluation. Vitals stable. Labs reviewed. Discharged in good condition. -d11,10006,20009,DS,1,2152-09-08 12:00:00,2152-09-08 13:00:00,Patient 10006 admitted for evaluation. Vitals stable. Labs reviewed. Discharged in good condition. -d12,10006,20010,DS,1,2152-11-18 12:00:00,2152-11-18 13:00:00,Patient 10006 admitted for evaluation. Vitals stable. Labs reviewed. Discharged in good condition. -d13,10007,20011,DS,1,2150-04-11 12:00:00,2150-04-11 13:00:00,Patient 10007 admitted for evaluation. Vitals stable. Labs reviewed. Discharged in good condition. -d14,10008,20012,DS,1,2151-10-25 12:00:00,2151-10-25 13:00:00,Patient 10008 admitted for evaluation. Vitals stable. Labs reviewed. Discharged in good condition. -d15,10008,20013,DS,1,2151-12-20 12:00:00,2151-12-20 13:00:00,Patient 10008 admitted for evaluation. Vitals stable. Labs reviewed. Discharged in good condition. -d16,10009,20014,DS,1,2152-03-23 12:00:00,2152-03-23 13:00:00,Patient 10009 admitted for evaluation. Vitals stable. Labs reviewed. Discharged in good condition. -d17,10010,20015,DS,1,2150-08-05 12:00:00,2150-08-05 13:00:00,Patient 10010 admitted for evaluation. Vitals stable. Labs reviewed. Discharged in good condition. -d18,1,1,DS,1,2150-01-01 12:00:00,2150-01-01 13:00:00,Patient 1 admitted for evaluation. Vitals stable. Labs reviewed. Discharged in good condition. -d19,1,2,DS,1,2150-01-16 12:00:00,2150-01-16 13:00:00,Patient 1 admitted for evaluation. Vitals stable. Labs reviewed. Discharged in good condition. -d20,2,3,DS,1,2150-01-01 12:00:00,2150-01-01 13:00:00,Patient 2 admitted for evaluation. Vitals stable. Labs reviewed. Discharged in good condition. -d21,2,4,DS,1,2150-01-16 12:00:00,2150-01-16 13:00:00,Patient 2 admitted for evaluation. Vitals stable. Labs reviewed. Discharged in good condition. -d22,2,5,DS,1,2150-01-21 12:00:00,2150-01-21 13:00:00,Patient 2 admitted for evaluation. Vitals stable. Labs reviewed. Discharged in good condition. -d23,2,6,DS,1,2150-01-22 12:00:00,2150-01-22 13:00:00,Patient 2 admitted for evaluation. Vitals stable. Labs reviewed. Discharged in good condition. -d24,3,7,DS,1,2150-01-01 12:00:00,2150-01-01 13:00:00,Patient 3 admitted for evaluation. Vitals stable. Labs reviewed. Discharged in good condition. +"note_id","subject_id","hadm_id","note_type","note_seq","charttime","storetime","text" +"d1","10001","19999","DS","1","2150-02-18 12:00:00","2150-02-18 13:00:00","Name: ___ Unit No: ___ + +Admission Date: ___ Discharge Date: ___ + +Date of Birth: ___ Sex: M + +Service: SURGERY + +Allergies: +morphine + +Attending: ___. + +Chief Complaint: +abdominal pain + +Major Surgical or Invasive Procedure: +none + +History of Present Illness: +This patient is a ___ year old male who complains of right lower quadrant +abdominal pain for 2 days. Pain worsens with movement. Patient denies fevers +or chills. No relief with over-the-counter analgesics. + +Past Medical History: +none + +Social History: +___ + +Family History: +NC + +Physical Exam: +Temp: 97.8 HR: 90 BP: 124/86 Resp: 14 O2Sat: 100 +Abdomen: right lower quadrant tenderness without rebound + +Pertinent Results: +WBC-8.9 RBC-5.59 Hgb-12.5 Hct-42.0 +Glucose-99 UreaN-13 Creat-1.0 Na-137 K-4.0 Cl-103 HCO3-22 + +Brief Hospital Course: +Patient admitted for observation. Serial abdominal exams performed. +Pain resolved with conservative management. Diet advanced without issue. +Discharged home in stable condition. + +Medications on Admission: +none + +Discharge Medications: +none + +Discharge Disposition: +Home + +Discharge Diagnosis: +abdominal pain + +Discharge Condition: +Mental Status: Clear and coherent. +Level of Consciousness: Alert and interactive. +Activity Status: Ambulatory - Independent. + +Discharge Instructions: +Return to ER for worsening pain, fever >101.5F, vomiting, or new symptoms. + +Followup Instructions: +Follow up with primary care physician in 1 week." +"d2","10002","20000","DS","1","2151-01-02 12:00:00","2151-01-02 13:00:00","Name: ___ Unit No: ___ + +Admission Date: ___ Discharge Date: ___ + +Date of Birth: ___ Sex: F + +Service: CARDIOLOGY + +Allergies: +penicillin + +Attending: ___. + +Chief Complaint: +chest pain + +Major Surgical or Invasive Procedure: +cardiac catheterization + +History of Present Illness: +___ year old female with hypertension presenting with substernal chest pain +radiating to the left arm, onset 3 hours prior to admission. Associated +diaphoresis and shortness of breath. EKG showed ST depression in V4-V6. + +Past Medical History: +1. Hypertension +2. Hyperlipidemia +3. Type 2 Diabetes Mellitus + +Social History: +Non-smoker. Occasional alcohol use. Lives with spouse. + +Family History: +Father with MI at age 60. Mother with hypertension. + +Physical Exam: +Temp: 98.2 HR: 88 BP: 152/94 Resp: 18 O2Sat: 97 +Cardiovascular: Regular rate and rhythm. No murmurs. +Chest: Clear to auscultation bilaterally. + +Pertinent Results: +Troponin I: 2.4 (elevated) +BNP: 180 +WBC-9.1 Hgb-11.8 Hct-36.2 Plt-220 + +Brief Hospital Course: +Patient admitted for NSTEMI. Heparin drip initiated. Cardiac cath revealed +70% LAD stenosis; drug-eluting stent placed. Post-procedure course +uncomplicated. Discharged on dual antiplatelet therapy. + +Medications on Admission: +1. Lisinopril 10 mg daily +2. Atorvastatin 40 mg nightly +3. Metformin 1000 mg twice daily + +Discharge Medications: +1. Aspirin 81 mg daily +2. Clopidogrel 75 mg daily +3. Lisinopril 10 mg daily +4. Atorvastatin 80 mg nightly +5. Metformin 1000 mg twice daily + +Discharge Disposition: +Home with services + +Discharge Diagnosis: +NSTEMI, coronary artery disease + +Discharge Condition: +Mental Status: Clear and coherent. +Level of Consciousness: Alert and interactive. +Activity Status: Ambulatory - Independent. + +Discharge Instructions: +Do not stop aspirin or clopidogrel without consulting your cardiologist. +Call your doctor for chest pain, shortness of breath, or leg swelling. + +Followup Instructions: +Follow up with cardiology in 1 week." +"d3","10001","20001","DS","1","2150-03-18 12:00:00","2150-03-18 13:00:00","Name: ___ Unit No: ___ + +Admission Date: ___ Discharge Date: ___ + +Date of Birth: ___ Sex: M + +Service: MEDICINE + +Allergies: +sulfa drugs + +Attending: ___. + +Chief Complaint: +shortness of breath + +Major Surgical or Invasive Procedure: +none + +History of Present Illness: +___ year old male with known COPD presenting with 3 days of worsening dyspnea +and productive cough with yellow sputum. Patient reports increased inhaler use +without improvement. Denies fever. Smoking history: 40 pack-years. + +Past Medical History: +1. COPD, moderate severity +2. Hypertension +3. Gastroesophageal reflux disease + +Social History: +Former smoker, quit 5 years ago. No alcohol or illicit drug use. Lives alone. + +Family History: +Mother with asthma. No family history of lung cancer. + +Physical Exam: +Temp: 98.6 HR: 102 BP: 138/82 Resp: 24 O2Sat: 88% on room air +Chest: Diffuse expiratory wheezes. Prolonged expiratory phase. +Accessory muscle use noted. + +Pertinent Results: +ABG: pH 7.34 pCO2 52 pO2 58 HCO3 28 +WBC-11.2 (elevated) CXR: hyperinflation, no consolidation + +Brief Hospital Course: +Admitted for COPD exacerbation. Started on systemic steroids, nebulized +bronchodilators, and supplemental oxygen. Azithromycin added for possible +infectious trigger. O2 sats improved to 94% on 2L NC. Discharged on +steroid taper. + +Medications on Admission: +1. Albuterol inhaler PRN +2. Tiotropium 18 mcg daily +3. Lisinopril 5 mg daily +4. Omeprazole 20 mg daily + +Discharge Medications: +1. Prednisone 40 mg daily x 3 days then taper per schedule +2. Azithromycin 250 mg daily x 3 days (2 doses remaining) +3. Albuterol inhaler q4h PRN +4. Tiotropium 18 mcg daily +5. Lisinopril 5 mg daily + +Discharge Disposition: +Home + +Discharge Diagnosis: +COPD exacerbation + +Discharge Condition: +Mental Status: Clear and coherent. +Level of Consciousness: Alert and interactive. +Activity Status: Ambulatory with mild exertional dyspnea. + +Discharge Instructions: +Complete the full steroid taper. Use albuterol inhaler as needed. +Return to ER for oxygen saturation below 90%, severe dyspnea, or confusion. + +Followup Instructions: +Follow up with pulmonology in 2 weeks." +"d4","10001","20002","DS","1","2150-06-25 12:00:00","2150-06-25 13:00:00","Name: ___ Unit No: ___ + +Admission Date: ___ Discharge Date: ___ + +Date of Birth: ___ Sex: F + +Service: CARDIOLOGY + +Allergies: +no known drug allergies + +Attending: ___. + +Chief Complaint: +leg swelling and shortness of breath + +Major Surgical or Invasive Procedure: +none + +History of Present Illness: +___ year old female with history of congestive heart failure (EF 30%) presenting +with 1 week of progressive bilateral lower extremity edema and orthopnea. +Weight gain of 8 lbs over past week. Patient reports dietary indiscretion +with increased sodium intake. + +Past Medical History: +1. Congestive heart failure, EF 30% +2. Atrial fibrillation +3. Hypertension +4. Chronic kidney disease stage 3 + +Social History: +Non-smoker. No alcohol. Lives with daughter. + +Family History: +Father with heart failure. Sister with hypertension. + +Physical Exam: +Temp: 98.0 HR: 96 (irregularly irregular) BP: 148/90 Resp: 20 O2Sat: 94% +JVD present. Bilateral crackles at lung bases. +2+ pitting edema to knees bilaterally. + +Pertinent Results: +BNP: 1840 (markedly elevated) +Creatinine 1.8 (baseline 1.5) +CXR: pulmonary vascular congestion, bilateral pleural effusions + +Brief Hospital Course: +Admitted for decompensated CHF. IV furosemide initiated with good diuretic +response (negative 3L over 48 hours). Transitioned to oral diuretics. +Weight at discharge 4 lbs below admission weight. Cardiology consulted. + +Medications on Admission: +1. Furosemide 40 mg daily +2. Carvedilol 12.5 mg twice daily +3. Lisinopril 5 mg daily +4. Warfarin 5 mg daily +5. Digoxin 0.125 mg daily + +Discharge Medications: +1. Furosemide 80 mg daily (increased) +2. Carvedilol 12.5 mg twice daily +3. Lisinopril 5 mg daily +4. Warfarin 5 mg daily +5. Digoxin 0.125 mg daily + +Discharge Disposition: +Home with services + +Discharge Diagnosis: +Acute decompensated heart failure + +Discharge Condition: +Mental Status: Clear and coherent. +Level of Consciousness: Alert and interactive. +Activity Status: Ambulatory with assistance. + +Discharge Instructions: +Weigh yourself daily. If weight increases by more than 2 lbs in a day or +5 lbs in a week, call your doctor immediately. Restrict sodium to 2g/day. + +Followup Instructions: +Follow up with cardiologist in 3 days." +"d5","10002","20003","DS","1","2151-01-12 12:00:00","2151-01-12 13:00:00","Name: ___ Unit No: ___ + +Admission Date: ___ Discharge Date: ___ + +Date of Birth: ___ Sex: M + +Service: MEDICINE + +Allergies: +amoxicillin + +Attending: ___. + +Chief Complaint: +fever and productive cough + +Major Surgical or Invasive Procedure: +none + +History of Present Illness: +___ year old male presenting with 5 days of productive cough with green sputum, +fever to 101.8F, and pleuritic chest pain. Patient reports decreased appetite +and fatigue. No sick contacts. Up to date on vaccinations. + +Past Medical History: +1. Type 2 Diabetes Mellitus +2. Hypertension + +Social History: +Non-smoker. No alcohol or drug use. Works as a teacher. + +Family History: +No family history of pulmonary disease. + +Physical Exam: +Temp: 101.6 HR: 108 BP: 128/78 Resp: 22 O2Sat: 93% on room air +Chest: Decreased breath sounds and dullness to percussion at right base. +Egophony present at right lower lobe. + +Pertinent Results: +WBC-14.8 (elevated) with left shift +Procalcitonin: 2.1 (elevated) +CXR: right lower lobe consolidation consistent with pneumonia + +Brief Hospital Course: +Admitted for community-acquired pneumonia. Started on ceftriaxone and +azithromycin. O2 sats improved on 4L NC. Transitioned to oral antibiotics +on hospital day 3. Glucose levels monitored and insulin sliding scale used. + +Medications on Admission: +1. Metformin 500 mg twice daily +2. Lisinopril 10 mg daily +3. Aspirin 81 mg daily + +Discharge Medications: +1. Levofloxacin 750 mg daily x 5 days (3 doses remaining) +2. Metformin 500 mg twice daily +3. Lisinopril 10 mg daily +4. Aspirin 81 mg daily + +Discharge Disposition: +Home + +Discharge Diagnosis: +Community-acquired pneumonia + +Discharge Condition: +Mental Status: Clear and coherent. +Level of Consciousness: Alert and interactive. +Activity Status: Ambulatory - Independent. + +Discharge Instructions: +Complete the full antibiotic course. Return for worsening shortness of breath, +persistent fever, or hemoptysis. + +Followup Instructions: +Follow up with primary care in 1 week for repeat CXR." +"d6","10002","20004","DS","1","2151-04-20 12:00:00","2151-04-20 13:00:00","Name: ___ Unit No: ___ + +Admission Date: ___ Discharge Date: ___ + +Date of Birth: ___ Sex: F + +Service: NEUROLOGY + +Allergies: +codeine + +Attending: ___. + +Chief Complaint: +sudden onset left-sided weakness + +Major Surgical or Invasive Procedure: +IV tPA administration + +History of Present Illness: +___ year old female with hypertension and atrial fibrillation brought by EMS +with sudden onset left arm and leg weakness and facial droop noted 2 hours +prior to arrival. Last known well time established. NIHSS 12 on arrival. +CT head showed no hemorrhage. IV tPA administered within window. + +Past Medical History: +1. Atrial fibrillation +2. Hypertension +3. Hyperlipidemia + +Social History: +Non-smoker. Rare alcohol use. Retired. Lives alone. + +Family History: +Father with stroke at age 72. Mother with hypertension. + +Physical Exam: +Temp: 98.4 HR: 84 (irregular) BP: 168/96 Resp: 16 O2Sat: 98% +Neuro: left facial droop, left arm 3/5 strength, left leg 4/5 strength. +Dysarthria present. + +Pertinent Results: +MRI brain: right MCA territory infarct +Echo: no thrombus. EF 55%. +INR: 1.1 (not anticoagulated at time of stroke) + +Brief Hospital Course: +Admitted to stroke unit. tPA given without hemorrhagic complication. +Deficits improved over 48 hours. Anticoagulation initiated with apixaban. +Physical therapy and speech therapy consulted. Swallow evaluation passed. + +Medications on Admission: +1. Metoprolol 25 mg twice daily +2. Amlodipine 5 mg daily +3. Atorvastatin 20 mg nightly + +Discharge Medications: +1. Apixaban 5 mg twice daily (new) +2. Aspirin 81 mg daily +3. Metoprolol 25 mg twice daily +4. Amlodipine 5 mg daily +5. Atorvastatin 80 mg nightly (increased) + +Discharge Disposition: +Rehabilitation facility + +Discharge Diagnosis: +Acute ischemic stroke, right MCA territory + +Discharge Condition: +Mental Status: Clear and coherent. +Level of Consciousness: Alert and interactive. +Activity Status: Ambulatory with assistance. + +Discharge Instructions: +Take apixaban as directed. Do not stop without consulting your neurologist. +Call 911 immediately for any new weakness, vision changes, or speech difficulty. + +Followup Instructions: +Follow up with neurology in 2 weeks." +"d7","10003","20005","DS","1","2152-03-05 12:00:00","2152-03-05 13:00:00","Name: ___ Unit No: ___ + +Admission Date: ___ Discharge Date: ___ + +Date of Birth: ___ Sex: M + +Service: SURGERY + +Allergies: +morphine + +Attending: ___. + +Chief Complaint: +abdominal pain + +Major Surgical or Invasive Procedure: +none + +History of Present Illness: +This patient is a ___ year old male who complains of right lower quadrant +abdominal pain for 2 days. Pain worsens with movement. Patient denies fevers +or chills. No relief with over-the-counter analgesics. + +Past Medical History: +none + +Social History: +___ + +Family History: +NC + +Physical Exam: +Temp: 97.8 HR: 90 BP: 124/86 Resp: 14 O2Sat: 100 +Abdomen: right lower quadrant tenderness without rebound + +Pertinent Results: +WBC-8.9 RBC-5.59 Hgb-12.5 Hct-42.0 +Glucose-99 UreaN-13 Creat-1.0 Na-137 K-4.0 Cl-103 HCO3-22 + +Brief Hospital Course: +Patient admitted for observation. Serial abdominal exams performed. +Pain resolved with conservative management. Diet advanced without issue. +Discharged home in stable condition. + +Medications on Admission: +none + +Discharge Medications: +none + +Discharge Disposition: +Home + +Discharge Diagnosis: +abdominal pain + +Discharge Condition: +Mental Status: Clear and coherent. +Level of Consciousness: Alert and interactive. +Activity Status: Ambulatory - Independent. + +Discharge Instructions: +Return to ER for worsening pain, fever >101.5F, vomiting, or new symptoms. + +Followup Instructions: +Follow up with primary care physician in 1 week." +"d8","10003","20006","DS","1","2152-08-15 12:00:00","2152-08-15 13:00:00","Name: ___ Unit No: ___ + +Admission Date: ___ Discharge Date: ___ + +Date of Birth: ___ Sex: F + +Service: CARDIOLOGY + +Allergies: +penicillin + +Attending: ___. + +Chief Complaint: +chest pain + +Major Surgical or Invasive Procedure: +cardiac catheterization + +History of Present Illness: +___ year old female with hypertension presenting with substernal chest pain +radiating to the left arm, onset 3 hours prior to admission. Associated +diaphoresis and shortness of breath. EKG showed ST depression in V4-V6. + +Past Medical History: +1. Hypertension +2. Hyperlipidemia +3. Type 2 Diabetes Mellitus + +Social History: +Non-smoker. Occasional alcohol use. Lives with spouse. + +Family History: +Father with MI at age 60. Mother with hypertension. + +Physical Exam: +Temp: 98.2 HR: 88 BP: 152/94 Resp: 18 O2Sat: 97 +Cardiovascular: Regular rate and rhythm. No murmurs. +Chest: Clear to auscultation bilaterally. + +Pertinent Results: +Troponin I: 2.4 (elevated) +BNP: 180 +WBC-9.1 Hgb-11.8 Hct-36.2 Plt-220 + +Brief Hospital Course: +Patient admitted for NSTEMI. Heparin drip initiated. Cardiac cath revealed +70% LAD stenosis; drug-eluting stent placed. Post-procedure course +uncomplicated. Discharged on dual antiplatelet therapy. + +Medications on Admission: +1. Lisinopril 10 mg daily +2. Atorvastatin 40 mg nightly +3. Metformin 1000 mg twice daily + +Discharge Medications: +1. Aspirin 81 mg daily +2. Clopidogrel 75 mg daily +3. Lisinopril 10 mg daily +4. Atorvastatin 80 mg nightly +5. Metformin 1000 mg twice daily + +Discharge Disposition: +Home with services + +Discharge Diagnosis: +NSTEMI, coronary artery disease + +Discharge Condition: +Mental Status: Clear and coherent. +Level of Consciousness: Alert and interactive. +Activity Status: Ambulatory - Independent. + +Discharge Instructions: +Do not stop aspirin or clopidogrel without consulting your cardiologist. +Call your doctor for chest pain, shortness of breath, or leg swelling. + +Followup Instructions: +Follow up with cardiology in 1 week." +"d9","10004","20007","DS","1","2150-05-02 12:00:00","2150-05-02 13:00:00","Name: ___ Unit No: ___ + +Admission Date: ___ Discharge Date: ___ + +Date of Birth: ___ Sex: M + +Service: MEDICINE + +Allergies: +sulfa drugs + +Attending: ___. + +Chief Complaint: +shortness of breath + +Major Surgical or Invasive Procedure: +none + +History of Present Illness: +___ year old male with known COPD presenting with 3 days of worsening dyspnea +and productive cough with yellow sputum. Patient reports increased inhaler use +without improvement. Denies fever. Smoking history: 40 pack-years. + +Past Medical History: +1. COPD, moderate severity +2. Hypertension +3. Gastroesophageal reflux disease + +Social History: +Former smoker, quit 5 years ago. No alcohol or illicit drug use. Lives alone. + +Family History: +Mother with asthma. No family history of lung cancer. + +Physical Exam: +Temp: 98.6 HR: 102 BP: 138/82 Resp: 24 O2Sat: 88% on room air +Chest: Diffuse expiratory wheezes. Prolonged expiratory phase. +Accessory muscle use noted. + +Pertinent Results: +ABG: pH 7.34 pCO2 52 pO2 58 HCO3 28 +WBC-11.2 (elevated) CXR: hyperinflation, no consolidation + +Brief Hospital Course: +Admitted for COPD exacerbation. Started on systemic steroids, nebulized +bronchodilators, and supplemental oxygen. Azithromycin added for possible +infectious trigger. O2 sats improved to 94% on 2L NC. Discharged on +steroid taper. + +Medications on Admission: +1. Albuterol inhaler PRN +2. Tiotropium 18 mcg daily +3. Lisinopril 5 mg daily +4. Omeprazole 20 mg daily + +Discharge Medications: +1. Prednisone 40 mg daily x 3 days then taper per schedule +2. Azithromycin 250 mg daily x 3 days (2 doses remaining) +3. Albuterol inhaler q4h PRN +4. Tiotropium 18 mcg daily +5. Lisinopril 5 mg daily + +Discharge Disposition: +Home + +Discharge Diagnosis: +COPD exacerbation + +Discharge Condition: +Mental Status: Clear and coherent. +Level of Consciousness: Alert and interactive. +Activity Status: Ambulatory with mild exertional dyspnea. + +Discharge Instructions: +Complete the full steroid taper. Use albuterol inhaler as needed. +Return to ER for oxygen saturation below 90%, severe dyspnea, or confusion. + +Followup Instructions: +Follow up with pulmonology in 2 weeks." +"d10","10005","20008","DS","1","2151-07-22 12:00:00","2151-07-22 13:00:00","Name: ___ Unit No: ___ + +Admission Date: ___ Discharge Date: ___ + +Date of Birth: ___ Sex: F + +Service: CARDIOLOGY + +Allergies: +no known drug allergies + +Attending: ___. + +Chief Complaint: +leg swelling and shortness of breath + +Major Surgical or Invasive Procedure: +none + +History of Present Illness: +___ year old female with history of congestive heart failure (EF 30%) presenting +with 1 week of progressive bilateral lower extremity edema and orthopnea. +Weight gain of 8 lbs over past week. Patient reports dietary indiscretion +with increased sodium intake. + +Past Medical History: +1. Congestive heart failure, EF 30% +2. Atrial fibrillation +3. Hypertension +4. Chronic kidney disease stage 3 + +Social History: +Non-smoker. No alcohol. Lives with daughter. + +Family History: +Father with heart failure. Sister with hypertension. + +Physical Exam: +Temp: 98.0 HR: 96 (irregularly irregular) BP: 148/90 Resp: 20 O2Sat: 94% +JVD present. Bilateral crackles at lung bases. +2+ pitting edema to knees bilaterally. + +Pertinent Results: +BNP: 1840 (markedly elevated) +Creatinine 1.8 (baseline 1.5) +CXR: pulmonary vascular congestion, bilateral pleural effusions + +Brief Hospital Course: +Admitted for decompensated CHF. IV furosemide initiated with good diuretic +response (negative 3L over 48 hours). Transitioned to oral diuretics. +Weight at discharge 4 lbs below admission weight. Cardiology consulted. + +Medications on Admission: +1. Furosemide 40 mg daily +2. Carvedilol 12.5 mg twice daily +3. Lisinopril 5 mg daily +4. Warfarin 5 mg daily +5. Digoxin 0.125 mg daily + +Discharge Medications: +1. Furosemide 80 mg daily (increased) +2. Carvedilol 12.5 mg twice daily +3. Lisinopril 5 mg daily +4. Warfarin 5 mg daily +5. Digoxin 0.125 mg daily + +Discharge Disposition: +Home with services + +Discharge Diagnosis: +Acute decompensated heart failure + +Discharge Condition: +Mental Status: Clear and coherent. +Level of Consciousness: Alert and interactive. +Activity Status: Ambulatory with assistance. + +Discharge Instructions: +Weigh yourself daily. If weight increases by more than 2 lbs in a day or +5 lbs in a week, call your doctor immediately. Restrict sodium to 2g/day. + +Followup Instructions: +Follow up with cardiologist in 3 days." +"d11","10006","20009","DS","1","2152-09-08 12:00:00","2152-09-08 13:00:00","Name: ___ Unit No: ___ + +Admission Date: ___ Discharge Date: ___ + +Date of Birth: ___ Sex: M + +Service: MEDICINE + +Allergies: +amoxicillin + +Attending: ___. + +Chief Complaint: +fever and productive cough + +Major Surgical or Invasive Procedure: +none + +History of Present Illness: +___ year old male presenting with 5 days of productive cough with green sputum, +fever to 101.8F, and pleuritic chest pain. Patient reports decreased appetite +and fatigue. No sick contacts. Up to date on vaccinations. + +Past Medical History: +1. Type 2 Diabetes Mellitus +2. Hypertension + +Social History: +Non-smoker. No alcohol or drug use. Works as a teacher. + +Family History: +No family history of pulmonary disease. + +Physical Exam: +Temp: 101.6 HR: 108 BP: 128/78 Resp: 22 O2Sat: 93% on room air +Chest: Decreased breath sounds and dullness to percussion at right base. +Egophony present at right lower lobe. + +Pertinent Results: +WBC-14.8 (elevated) with left shift +Procalcitonin: 2.1 (elevated) +CXR: right lower lobe consolidation consistent with pneumonia + +Brief Hospital Course: +Admitted for community-acquired pneumonia. Started on ceftriaxone and +azithromycin. O2 sats improved on 4L NC. Transitioned to oral antibiotics +on hospital day 3. Glucose levels monitored and insulin sliding scale used. + +Medications on Admission: +1. Metformin 500 mg twice daily +2. Lisinopril 10 mg daily +3. Aspirin 81 mg daily + +Discharge Medications: +1. Levofloxacin 750 mg daily x 5 days (3 doses remaining) +2. Metformin 500 mg twice daily +3. Lisinopril 10 mg daily +4. Aspirin 81 mg daily + +Discharge Disposition: +Home + +Discharge Diagnosis: +Community-acquired pneumonia + +Discharge Condition: +Mental Status: Clear and coherent. +Level of Consciousness: Alert and interactive. +Activity Status: Ambulatory - Independent. + +Discharge Instructions: +Complete the full antibiotic course. Return for worsening shortness of breath, +persistent fever, or hemoptysis. + +Followup Instructions: +Follow up with primary care in 1 week for repeat CXR." +"d12","10006","20010","DS","1","2152-11-18 12:00:00","2152-11-18 13:00:00","Name: ___ Unit No: ___ + +Admission Date: ___ Discharge Date: ___ + +Date of Birth: ___ Sex: F + +Service: NEUROLOGY + +Allergies: +codeine + +Attending: ___. + +Chief Complaint: +sudden onset left-sided weakness + +Major Surgical or Invasive Procedure: +IV tPA administration + +History of Present Illness: +___ year old female with hypertension and atrial fibrillation brought by EMS +with sudden onset left arm and leg weakness and facial droop noted 2 hours +prior to arrival. Last known well time established. NIHSS 12 on arrival. +CT head showed no hemorrhage. IV tPA administered within window. + +Past Medical History: +1. Atrial fibrillation +2. Hypertension +3. Hyperlipidemia + +Social History: +Non-smoker. Rare alcohol use. Retired. Lives alone. + +Family History: +Father with stroke at age 72. Mother with hypertension. + +Physical Exam: +Temp: 98.4 HR: 84 (irregular) BP: 168/96 Resp: 16 O2Sat: 98% +Neuro: left facial droop, left arm 3/5 strength, left leg 4/5 strength. +Dysarthria present. + +Pertinent Results: +MRI brain: right MCA territory infarct +Echo: no thrombus. EF 55%. +INR: 1.1 (not anticoagulated at time of stroke) + +Brief Hospital Course: +Admitted to stroke unit. tPA given without hemorrhagic complication. +Deficits improved over 48 hours. Anticoagulation initiated with apixaban. +Physical therapy and speech therapy consulted. Swallow evaluation passed. + +Medications on Admission: +1. Metoprolol 25 mg twice daily +2. Amlodipine 5 mg daily +3. Atorvastatin 20 mg nightly + +Discharge Medications: +1. Apixaban 5 mg twice daily (new) +2. Aspirin 81 mg daily +3. Metoprolol 25 mg twice daily +4. Amlodipine 5 mg daily +5. Atorvastatin 80 mg nightly (increased) + +Discharge Disposition: +Rehabilitation facility + +Discharge Diagnosis: +Acute ischemic stroke, right MCA territory + +Discharge Condition: +Mental Status: Clear and coherent. +Level of Consciousness: Alert and interactive. +Activity Status: Ambulatory with assistance. + +Discharge Instructions: +Take apixaban as directed. Do not stop without consulting your neurologist. +Call 911 immediately for any new weakness, vision changes, or speech difficulty. + +Followup Instructions: +Follow up with neurology in 2 weeks." +"d13","10007","20011","DS","1","2150-04-11 12:00:00","2150-04-11 13:00:00","Name: ___ Unit No: ___ + +Admission Date: ___ Discharge Date: ___ + +Date of Birth: ___ Sex: M + +Service: SURGERY + +Allergies: +morphine + +Attending: ___. + +Chief Complaint: +abdominal pain + +Major Surgical or Invasive Procedure: +none + +History of Present Illness: +This patient is a ___ year old male who complains of right lower quadrant +abdominal pain for 2 days. Pain worsens with movement. Patient denies fevers +or chills. No relief with over-the-counter analgesics. + +Past Medical History: +none + +Social History: +___ + +Family History: +NC + +Physical Exam: +Temp: 97.8 HR: 90 BP: 124/86 Resp: 14 O2Sat: 100 +Abdomen: right lower quadrant tenderness without rebound + +Pertinent Results: +WBC-8.9 RBC-5.59 Hgb-12.5 Hct-42.0 +Glucose-99 UreaN-13 Creat-1.0 Na-137 K-4.0 Cl-103 HCO3-22 + +Brief Hospital Course: +Patient admitted for observation. Serial abdominal exams performed. +Pain resolved with conservative management. Diet advanced without issue. +Discharged home in stable condition. + +Medications on Admission: +none + +Discharge Medications: +none + +Discharge Disposition: +Home + +Discharge Diagnosis: +abdominal pain + +Discharge Condition: +Mental Status: Clear and coherent. +Level of Consciousness: Alert and interactive. +Activity Status: Ambulatory - Independent. + +Discharge Instructions: +Return to ER for worsening pain, fever >101.5F, vomiting, or new symptoms. + +Followup Instructions: +Follow up with primary care physician in 1 week." +"d14","10008","20012","DS","1","2151-10-25 12:00:00","2151-10-25 13:00:00","Name: ___ Unit No: ___ + +Admission Date: ___ Discharge Date: ___ + +Date of Birth: ___ Sex: F + +Service: CARDIOLOGY + +Allergies: +penicillin + +Attending: ___. + +Chief Complaint: +chest pain + +Major Surgical or Invasive Procedure: +cardiac catheterization + +History of Present Illness: +___ year old female with hypertension presenting with substernal chest pain +radiating to the left arm, onset 3 hours prior to admission. Associated +diaphoresis and shortness of breath. EKG showed ST depression in V4-V6. + +Past Medical History: +1. Hypertension +2. Hyperlipidemia +3. Type 2 Diabetes Mellitus + +Social History: +Non-smoker. Occasional alcohol use. Lives with spouse. + +Family History: +Father with MI at age 60. Mother with hypertension. + +Physical Exam: +Temp: 98.2 HR: 88 BP: 152/94 Resp: 18 O2Sat: 97 +Cardiovascular: Regular rate and rhythm. No murmurs. +Chest: Clear to auscultation bilaterally. + +Pertinent Results: +Troponin I: 2.4 (elevated) +BNP: 180 +WBC-9.1 Hgb-11.8 Hct-36.2 Plt-220 + +Brief Hospital Course: +Patient admitted for NSTEMI. Heparin drip initiated. Cardiac cath revealed +70% LAD stenosis; drug-eluting stent placed. Post-procedure course +uncomplicated. Discharged on dual antiplatelet therapy. + +Medications on Admission: +1. Lisinopril 10 mg daily +2. Atorvastatin 40 mg nightly +3. Metformin 1000 mg twice daily + +Discharge Medications: +1. Aspirin 81 mg daily +2. Clopidogrel 75 mg daily +3. Lisinopril 10 mg daily +4. Atorvastatin 80 mg nightly +5. Metformin 1000 mg twice daily + +Discharge Disposition: +Home with services + +Discharge Diagnosis: +NSTEMI, coronary artery disease + +Discharge Condition: +Mental Status: Clear and coherent. +Level of Consciousness: Alert and interactive. +Activity Status: Ambulatory - Independent. + +Discharge Instructions: +Do not stop aspirin or clopidogrel without consulting your cardiologist. +Call your doctor for chest pain, shortness of breath, or leg swelling. + +Followup Instructions: +Follow up with cardiology in 1 week." +"d15","10008","20013","DS","1","2151-12-20 12:00:00","2151-12-20 13:00:00","Name: ___ Unit No: ___ + +Admission Date: ___ Discharge Date: ___ + +Date of Birth: ___ Sex: M + +Service: MEDICINE + +Allergies: +sulfa drugs + +Attending: ___. + +Chief Complaint: +shortness of breath + +Major Surgical or Invasive Procedure: +none + +History of Present Illness: +___ year old male with known COPD presenting with 3 days of worsening dyspnea +and productive cough with yellow sputum. Patient reports increased inhaler use +without improvement. Denies fever. Smoking history: 40 pack-years. + +Past Medical History: +1. COPD, moderate severity +2. Hypertension +3. Gastroesophageal reflux disease + +Social History: +Former smoker, quit 5 years ago. No alcohol or illicit drug use. Lives alone. + +Family History: +Mother with asthma. No family history of lung cancer. + +Physical Exam: +Temp: 98.6 HR: 102 BP: 138/82 Resp: 24 O2Sat: 88% on room air +Chest: Diffuse expiratory wheezes. Prolonged expiratory phase. +Accessory muscle use noted. + +Pertinent Results: +ABG: pH 7.34 pCO2 52 pO2 58 HCO3 28 +WBC-11.2 (elevated) CXR: hyperinflation, no consolidation + +Brief Hospital Course: +Admitted for COPD exacerbation. Started on systemic steroids, nebulized +bronchodilators, and supplemental oxygen. Azithromycin added for possible +infectious trigger. O2 sats improved to 94% on 2L NC. Discharged on +steroid taper. + +Medications on Admission: +1. Albuterol inhaler PRN +2. Tiotropium 18 mcg daily +3. Lisinopril 5 mg daily +4. Omeprazole 20 mg daily + +Discharge Medications: +1. Prednisone 40 mg daily x 3 days then taper per schedule +2. Azithromycin 250 mg daily x 3 days (2 doses remaining) +3. Albuterol inhaler q4h PRN +4. Tiotropium 18 mcg daily +5. Lisinopril 5 mg daily + +Discharge Disposition: +Home + +Discharge Diagnosis: +COPD exacerbation + +Discharge Condition: +Mental Status: Clear and coherent. +Level of Consciousness: Alert and interactive. +Activity Status: Ambulatory with mild exertional dyspnea. + +Discharge Instructions: +Complete the full steroid taper. Use albuterol inhaler as needed. +Return to ER for oxygen saturation below 90%, severe dyspnea, or confusion. + +Followup Instructions: +Follow up with pulmonology in 2 weeks." +"d16","10009","20014","DS","1","2152-03-23 12:00:00","2152-03-23 13:00:00","Name: ___ Unit No: ___ + +Admission Date: ___ Discharge Date: ___ + +Date of Birth: ___ Sex: F + +Service: CARDIOLOGY + +Allergies: +no known drug allergies + +Attending: ___. + +Chief Complaint: +leg swelling and shortness of breath + +Major Surgical or Invasive Procedure: +none + +History of Present Illness: +___ year old female with history of congestive heart failure (EF 30%) presenting +with 1 week of progressive bilateral lower extremity edema and orthopnea. +Weight gain of 8 lbs over past week. Patient reports dietary indiscretion +with increased sodium intake. + +Past Medical History: +1. Congestive heart failure, EF 30% +2. Atrial fibrillation +3. Hypertension +4. Chronic kidney disease stage 3 + +Social History: +Non-smoker. No alcohol. Lives with daughter. + +Family History: +Father with heart failure. Sister with hypertension. + +Physical Exam: +Temp: 98.0 HR: 96 (irregularly irregular) BP: 148/90 Resp: 20 O2Sat: 94% +JVD present. Bilateral crackles at lung bases. +2+ pitting edema to knees bilaterally. + +Pertinent Results: +BNP: 1840 (markedly elevated) +Creatinine 1.8 (baseline 1.5) +CXR: pulmonary vascular congestion, bilateral pleural effusions + +Brief Hospital Course: +Admitted for decompensated CHF. IV furosemide initiated with good diuretic +response (negative 3L over 48 hours). Transitioned to oral diuretics. +Weight at discharge 4 lbs below admission weight. Cardiology consulted. + +Medications on Admission: +1. Furosemide 40 mg daily +2. Carvedilol 12.5 mg twice daily +3. Lisinopril 5 mg daily +4. Warfarin 5 mg daily +5. Digoxin 0.125 mg daily + +Discharge Medications: +1. Furosemide 80 mg daily (increased) +2. Carvedilol 12.5 mg twice daily +3. Lisinopril 5 mg daily +4. Warfarin 5 mg daily +5. Digoxin 0.125 mg daily + +Discharge Disposition: +Home with services + +Discharge Diagnosis: +Acute decompensated heart failure + +Discharge Condition: +Mental Status: Clear and coherent. +Level of Consciousness: Alert and interactive. +Activity Status: Ambulatory with assistance. + +Discharge Instructions: +Weigh yourself daily. If weight increases by more than 2 lbs in a day or +5 lbs in a week, call your doctor immediately. Restrict sodium to 2g/day. + +Followup Instructions: +Follow up with cardiologist in 3 days." +"d17","10010","20015","DS","1","2150-08-05 12:00:00","2150-08-05 13:00:00","Name: ___ Unit No: ___ + +Admission Date: ___ Discharge Date: ___ + +Date of Birth: ___ Sex: M + +Service: MEDICINE + +Allergies: +amoxicillin + +Attending: ___. + +Chief Complaint: +fever and productive cough + +Major Surgical or Invasive Procedure: +none + +History of Present Illness: +___ year old male presenting with 5 days of productive cough with green sputum, +fever to 101.8F, and pleuritic chest pain. Patient reports decreased appetite +and fatigue. No sick contacts. Up to date on vaccinations. + +Past Medical History: +1. Type 2 Diabetes Mellitus +2. Hypertension + +Social History: +Non-smoker. No alcohol or drug use. Works as a teacher. + +Family History: +No family history of pulmonary disease. + +Physical Exam: +Temp: 101.6 HR: 108 BP: 128/78 Resp: 22 O2Sat: 93% on room air +Chest: Decreased breath sounds and dullness to percussion at right base. +Egophony present at right lower lobe. + +Pertinent Results: +WBC-14.8 (elevated) with left shift +Procalcitonin: 2.1 (elevated) +CXR: right lower lobe consolidation consistent with pneumonia + +Brief Hospital Course: +Admitted for community-acquired pneumonia. Started on ceftriaxone and +azithromycin. O2 sats improved on 4L NC. Transitioned to oral antibiotics +on hospital day 3. Glucose levels monitored and insulin sliding scale used. + +Medications on Admission: +1. Metformin 500 mg twice daily +2. Lisinopril 10 mg daily +3. Aspirin 81 mg daily + +Discharge Medications: +1. Levofloxacin 750 mg daily x 5 days (3 doses remaining) +2. Metformin 500 mg twice daily +3. Lisinopril 10 mg daily +4. Aspirin 81 mg daily + +Discharge Disposition: +Home + +Discharge Diagnosis: +Community-acquired pneumonia + +Discharge Condition: +Mental Status: Clear and coherent. +Level of Consciousness: Alert and interactive. +Activity Status: Ambulatory - Independent. + +Discharge Instructions: +Complete the full antibiotic course. Return for worsening shortness of breath, +persistent fever, or hemoptysis. + +Followup Instructions: +Follow up with primary care in 1 week for repeat CXR." +"d18","1","1","DS","1","2150-01-01 12:00:00","2150-01-01 13:00:00","Name: ___ Unit No: ___ + +Admission Date: ___ Discharge Date: ___ + +Date of Birth: ___ Sex: F + +Service: NEUROLOGY + +Allergies: +codeine + +Attending: ___. + +Chief Complaint: +sudden onset left-sided weakness + +Major Surgical or Invasive Procedure: +IV tPA administration + +History of Present Illness: +___ year old female with hypertension and atrial fibrillation brought by EMS +with sudden onset left arm and leg weakness and facial droop noted 2 hours +prior to arrival. Last known well time established. NIHSS 12 on arrival. +CT head showed no hemorrhage. IV tPA administered within window. + +Past Medical History: +1. Atrial fibrillation +2. Hypertension +3. Hyperlipidemia + +Social History: +Non-smoker. Rare alcohol use. Retired. Lives alone. + +Family History: +Father with stroke at age 72. Mother with hypertension. + +Physical Exam: +Temp: 98.4 HR: 84 (irregular) BP: 168/96 Resp: 16 O2Sat: 98% +Neuro: left facial droop, left arm 3/5 strength, left leg 4/5 strength. +Dysarthria present. + +Pertinent Results: +MRI brain: right MCA territory infarct +Echo: no thrombus. EF 55%. +INR: 1.1 (not anticoagulated at time of stroke) + +Brief Hospital Course: +Admitted to stroke unit. tPA given without hemorrhagic complication. +Deficits improved over 48 hours. Anticoagulation initiated with apixaban. +Physical therapy and speech therapy consulted. Swallow evaluation passed. + +Medications on Admission: +1. Metoprolol 25 mg twice daily +2. Amlodipine 5 mg daily +3. Atorvastatin 20 mg nightly + +Discharge Medications: +1. Apixaban 5 mg twice daily (new) +2. Aspirin 81 mg daily +3. Metoprolol 25 mg twice daily +4. Amlodipine 5 mg daily +5. Atorvastatin 80 mg nightly (increased) + +Discharge Disposition: +Rehabilitation facility + +Discharge Diagnosis: +Acute ischemic stroke, right MCA territory + +Discharge Condition: +Mental Status: Clear and coherent. +Level of Consciousness: Alert and interactive. +Activity Status: Ambulatory with assistance. + +Discharge Instructions: +Take apixaban as directed. Do not stop without consulting your neurologist. +Call 911 immediately for any new weakness, vision changes, or speech difficulty. + +Followup Instructions: +Follow up with neurology in 2 weeks." +"d19","1","2","DS","1","2150-01-16 12:00:00","2150-01-16 13:00:00","Name: ___ Unit No: ___ + +Admission Date: ___ Discharge Date: ___ + +Date of Birth: ___ Sex: M + +Service: SURGERY + +Allergies: +morphine + +Attending: ___. + +Chief Complaint: +abdominal pain + +Major Surgical or Invasive Procedure: +none + +History of Present Illness: +This patient is a ___ year old male who complains of right lower quadrant +abdominal pain for 2 days. Pain worsens with movement. Patient denies fevers +or chills. No relief with over-the-counter analgesics. + +Past Medical History: +none + +Social History: +___ + +Family History: +NC + +Physical Exam: +Temp: 97.8 HR: 90 BP: 124/86 Resp: 14 O2Sat: 100 +Abdomen: right lower quadrant tenderness without rebound + +Pertinent Results: +WBC-8.9 RBC-5.59 Hgb-12.5 Hct-42.0 +Glucose-99 UreaN-13 Creat-1.0 Na-137 K-4.0 Cl-103 HCO3-22 + +Brief Hospital Course: +Patient admitted for observation. Serial abdominal exams performed. +Pain resolved with conservative management. Diet advanced without issue. +Discharged home in stable condition. + +Medications on Admission: +none + +Discharge Medications: +none + +Discharge Disposition: +Home + +Discharge Diagnosis: +abdominal pain + +Discharge Condition: +Mental Status: Clear and coherent. +Level of Consciousness: Alert and interactive. +Activity Status: Ambulatory - Independent. + +Discharge Instructions: +Return to ER for worsening pain, fever >101.5F, vomiting, or new symptoms. + +Followup Instructions: +Follow up with primary care physician in 1 week." +"d20","2","3","DS","1","2150-01-01 12:00:00","2150-01-01 13:00:00","Name: ___ Unit No: ___ + +Admission Date: ___ Discharge Date: ___ + +Date of Birth: ___ Sex: F + +Service: CARDIOLOGY + +Allergies: +penicillin + +Attending: ___. + +Chief Complaint: +chest pain + +Major Surgical or Invasive Procedure: +cardiac catheterization + +History of Present Illness: +___ year old female with hypertension presenting with substernal chest pain +radiating to the left arm, onset 3 hours prior to admission. Associated +diaphoresis and shortness of breath. EKG showed ST depression in V4-V6. + +Past Medical History: +1. Hypertension +2. Hyperlipidemia +3. Type 2 Diabetes Mellitus + +Social History: +Non-smoker. Occasional alcohol use. Lives with spouse. + +Family History: +Father with MI at age 60. Mother with hypertension. + +Physical Exam: +Temp: 98.2 HR: 88 BP: 152/94 Resp: 18 O2Sat: 97 +Cardiovascular: Regular rate and rhythm. No murmurs. +Chest: Clear to auscultation bilaterally. + +Pertinent Results: +Troponin I: 2.4 (elevated) +BNP: 180 +WBC-9.1 Hgb-11.8 Hct-36.2 Plt-220 + +Brief Hospital Course: +Patient admitted for NSTEMI. Heparin drip initiated. Cardiac cath revealed +70% LAD stenosis; drug-eluting stent placed. Post-procedure course +uncomplicated. Discharged on dual antiplatelet therapy. + +Medications on Admission: +1. Lisinopril 10 mg daily +2. Atorvastatin 40 mg nightly +3. Metformin 1000 mg twice daily + +Discharge Medications: +1. Aspirin 81 mg daily +2. Clopidogrel 75 mg daily +3. Lisinopril 10 mg daily +4. Atorvastatin 80 mg nightly +5. Metformin 1000 mg twice daily + +Discharge Disposition: +Home with services + +Discharge Diagnosis: +NSTEMI, coronary artery disease + +Discharge Condition: +Mental Status: Clear and coherent. +Level of Consciousness: Alert and interactive. +Activity Status: Ambulatory - Independent. + +Discharge Instructions: +Do not stop aspirin or clopidogrel without consulting your cardiologist. +Call your doctor for chest pain, shortness of breath, or leg swelling. + +Followup Instructions: +Follow up with cardiology in 1 week." +"d21","2","4","DS","1","2150-01-16 12:00:00","2150-01-16 13:00:00","Name: ___ Unit No: ___ + +Admission Date: ___ Discharge Date: ___ + +Date of Birth: ___ Sex: M + +Service: MEDICINE + +Allergies: +sulfa drugs + +Attending: ___. + +Chief Complaint: +shortness of breath + +Major Surgical or Invasive Procedure: +none + +History of Present Illness: +___ year old male with known COPD presenting with 3 days of worsening dyspnea +and productive cough with yellow sputum. Patient reports increased inhaler use +without improvement. Denies fever. Smoking history: 40 pack-years. + +Past Medical History: +1. COPD, moderate severity +2. Hypertension +3. Gastroesophageal reflux disease + +Social History: +Former smoker, quit 5 years ago. No alcohol or illicit drug use. Lives alone. + +Family History: +Mother with asthma. No family history of lung cancer. + +Physical Exam: +Temp: 98.6 HR: 102 BP: 138/82 Resp: 24 O2Sat: 88% on room air +Chest: Diffuse expiratory wheezes. Prolonged expiratory phase. +Accessory muscle use noted. + +Pertinent Results: +ABG: pH 7.34 pCO2 52 pO2 58 HCO3 28 +WBC-11.2 (elevated) CXR: hyperinflation, no consolidation + +Brief Hospital Course: +Admitted for COPD exacerbation. Started on systemic steroids, nebulized +bronchodilators, and supplemental oxygen. Azithromycin added for possible +infectious trigger. O2 sats improved to 94% on 2L NC. Discharged on +steroid taper. + +Medications on Admission: +1. Albuterol inhaler PRN +2. Tiotropium 18 mcg daily +3. Lisinopril 5 mg daily +4. Omeprazole 20 mg daily + +Discharge Medications: +1. Prednisone 40 mg daily x 3 days then taper per schedule +2. Azithromycin 250 mg daily x 3 days (2 doses remaining) +3. Albuterol inhaler q4h PRN +4. Tiotropium 18 mcg daily +5. Lisinopril 5 mg daily + +Discharge Disposition: +Home + +Discharge Diagnosis: +COPD exacerbation + +Discharge Condition: +Mental Status: Clear and coherent. +Level of Consciousness: Alert and interactive. +Activity Status: Ambulatory with mild exertional dyspnea. + +Discharge Instructions: +Complete the full steroid taper. Use albuterol inhaler as needed. +Return to ER for oxygen saturation below 90%, severe dyspnea, or confusion. + +Followup Instructions: +Follow up with pulmonology in 2 weeks." +"d22","2","5","DS","1","2150-01-21 12:00:00","2150-01-21 13:00:00","Name: ___ Unit No: ___ + +Admission Date: ___ Discharge Date: ___ + +Date of Birth: ___ Sex: F + +Service: CARDIOLOGY + +Allergies: +no known drug allergies + +Attending: ___. + +Chief Complaint: +leg swelling and shortness of breath + +Major Surgical or Invasive Procedure: +none + +History of Present Illness: +___ year old female with history of congestive heart failure (EF 30%) presenting +with 1 week of progressive bilateral lower extremity edema and orthopnea. +Weight gain of 8 lbs over past week. Patient reports dietary indiscretion +with increased sodium intake. + +Past Medical History: +1. Congestive heart failure, EF 30% +2. Atrial fibrillation +3. Hypertension +4. Chronic kidney disease stage 3 + +Social History: +Non-smoker. No alcohol. Lives with daughter. + +Family History: +Father with heart failure. Sister with hypertension. + +Physical Exam: +Temp: 98.0 HR: 96 (irregularly irregular) BP: 148/90 Resp: 20 O2Sat: 94% +JVD present. Bilateral crackles at lung bases. +2+ pitting edema to knees bilaterally. + +Pertinent Results: +BNP: 1840 (markedly elevated) +Creatinine 1.8 (baseline 1.5) +CXR: pulmonary vascular congestion, bilateral pleural effusions + +Brief Hospital Course: +Admitted for decompensated CHF. IV furosemide initiated with good diuretic +response (negative 3L over 48 hours). Transitioned to oral diuretics. +Weight at discharge 4 lbs below admission weight. Cardiology consulted. + +Medications on Admission: +1. Furosemide 40 mg daily +2. Carvedilol 12.5 mg twice daily +3. Lisinopril 5 mg daily +4. Warfarin 5 mg daily +5. Digoxin 0.125 mg daily + +Discharge Medications: +1. Furosemide 80 mg daily (increased) +2. Carvedilol 12.5 mg twice daily +3. Lisinopril 5 mg daily +4. Warfarin 5 mg daily +5. Digoxin 0.125 mg daily + +Discharge Disposition: +Home with services + +Discharge Diagnosis: +Acute decompensated heart failure + +Discharge Condition: +Mental Status: Clear and coherent. +Level of Consciousness: Alert and interactive. +Activity Status: Ambulatory with assistance. + +Discharge Instructions: +Weigh yourself daily. If weight increases by more than 2 lbs in a day or +5 lbs in a week, call your doctor immediately. Restrict sodium to 2g/day. + +Followup Instructions: +Follow up with cardiologist in 3 days." +"d23","2","6","DS","1","2150-01-22 12:00:00","2150-01-22 13:00:00","Name: ___ Unit No: ___ + +Admission Date: ___ Discharge Date: ___ + +Date of Birth: ___ Sex: M + +Service: MEDICINE + +Allergies: +amoxicillin + +Attending: ___. + +Chief Complaint: +fever and productive cough + +Major Surgical or Invasive Procedure: +none + +History of Present Illness: +___ year old male presenting with 5 days of productive cough with green sputum, +fever to 101.8F, and pleuritic chest pain. Patient reports decreased appetite +and fatigue. No sick contacts. Up to date on vaccinations. + +Past Medical History: +1. Type 2 Diabetes Mellitus +2. Hypertension + +Social History: +Non-smoker. No alcohol or drug use. Works as a teacher. + +Family History: +No family history of pulmonary disease. + +Physical Exam: +Temp: 101.6 HR: 108 BP: 128/78 Resp: 22 O2Sat: 93% on room air +Chest: Decreased breath sounds and dullness to percussion at right base. +Egophony present at right lower lobe. + +Pertinent Results: +WBC-14.8 (elevated) with left shift +Procalcitonin: 2.1 (elevated) +CXR: right lower lobe consolidation consistent with pneumonia + +Brief Hospital Course: +Admitted for community-acquired pneumonia. Started on ceftriaxone and +azithromycin. O2 sats improved on 4L NC. Transitioned to oral antibiotics +on hospital day 3. Glucose levels monitored and insulin sliding scale used. + +Medications on Admission: +1. Metformin 500 mg twice daily +2. Lisinopril 10 mg daily +3. Aspirin 81 mg daily + +Discharge Medications: +1. Levofloxacin 750 mg daily x 5 days (3 doses remaining) +2. Metformin 500 mg twice daily +3. Lisinopril 10 mg daily +4. Aspirin 81 mg daily + +Discharge Disposition: +Home + +Discharge Diagnosis: +Community-acquired pneumonia + +Discharge Condition: +Mental Status: Clear and coherent. +Level of Consciousness: Alert and interactive. +Activity Status: Ambulatory - Independent. + +Discharge Instructions: +Complete the full antibiotic course. Return for worsening shortness of breath, +persistent fever, or hemoptysis. + +Followup Instructions: +Follow up with primary care in 1 week for repeat CXR." +"d24","3","7","DS","1","2150-01-01 12:00:00","2150-01-01 13:00:00","Name: ___ Unit No: ___ + +Admission Date: ___ Discharge Date: ___ + +Date of Birth: ___ Sex: F + +Service: NEUROLOGY + +Allergies: +codeine + +Attending: ___. + +Chief Complaint: +sudden onset left-sided weakness + +Major Surgical or Invasive Procedure: +IV tPA administration + +History of Present Illness: +___ year old female with hypertension and atrial fibrillation brought by EMS +with sudden onset left arm and leg weakness and facial droop noted 2 hours +prior to arrival. Last known well time established. NIHSS 12 on arrival. +CT head showed no hemorrhage. IV tPA administered within window. + +Past Medical History: +1. Atrial fibrillation +2. Hypertension +3. Hyperlipidemia + +Social History: +Non-smoker. Rare alcohol use. Retired. Lives alone. + +Family History: +Father with stroke at age 72. Mother with hypertension. + +Physical Exam: +Temp: 98.4 HR: 84 (irregular) BP: 168/96 Resp: 16 O2Sat: 98% +Neuro: left facial droop, left arm 3/5 strength, left leg 4/5 strength. +Dysarthria present. + +Pertinent Results: +MRI brain: right MCA territory infarct +Echo: no thrombus. EF 55%. +INR: 1.1 (not anticoagulated at time of stroke) + +Brief Hospital Course: +Admitted to stroke unit. tPA given without hemorrhagic complication. +Deficits improved over 48 hours. Anticoagulation initiated with apixaban. +Physical therapy and speech therapy consulted. Swallow evaluation passed. + +Medications on Admission: +1. Metoprolol 25 mg twice daily +2. Amlodipine 5 mg daily +3. Atorvastatin 20 mg nightly + +Discharge Medications: +1. Apixaban 5 mg twice daily (new) +2. Aspirin 81 mg daily +3. Metoprolol 25 mg twice daily +4. Amlodipine 5 mg daily +5. Atorvastatin 80 mg nightly (increased) + +Discharge Disposition: +Rehabilitation facility + +Discharge Diagnosis: +Acute ischemic stroke, right MCA territory + +Discharge Condition: +Mental Status: Clear and coherent. +Level of Consciousness: Alert and interactive. +Activity Status: Ambulatory with assistance. + +Discharge Instructions: +Take apixaban as directed. Do not stop without consulting your neurologist. +Call 911 immediately for any new weakness, vision changes, or speech difficulty. + +Followup Instructions: +Follow up with neurology in 2 weeks." From 550784214e6876bc1c7cdbf7a7521e7641d41f15 Mon Sep 17 00:00:00 2001 From: William Pang Date: Fri, 29 May 2026 23:02:59 -0700 Subject: [PATCH 07/11] clear notebook outputs --- .../multimodal_mimic4_task_tutorial.ipynb | 242 ++---------------- 1 file changed, 18 insertions(+), 224 deletions(-) diff --git a/examples/multimodal_mimic4_task_tutorial.ipynb b/examples/multimodal_mimic4_task_tutorial.ipynb index 362c82c98..830f7da7c 100644 --- a/examples/multimodal_mimic4_task_tutorial.ipynb +++ b/examples/multimodal_mimic4_task_tutorial.ipynb @@ -25,7 +25,7 @@ }, { "cell_type": "code", - "execution_count": 1, + "execution_count": null, "id": "8477e2ac-322f-49e9-819f-ce7621b214c6", "metadata": {}, "outputs": [], @@ -50,7 +50,7 @@ }, { "cell_type": "code", - "execution_count": 2, + "execution_count": null, "id": "201c3a62-2a2e-47ab-9ab8-eea77812f349", "metadata": {}, "outputs": [], @@ -69,7 +69,7 @@ }, { "cell_type": "code", - "execution_count": 3, + "execution_count": null, "id": "9a466c4b-2283-443f-94a3-5768babddf50", "metadata": {}, "outputs": [], @@ -87,7 +87,7 @@ }, { "cell_type": "code", - "execution_count": 4, + "execution_count": null, "id": "05ec2dc9-1a0c-4360-a028-d93173dcba65", "metadata": {}, "outputs": [], @@ -136,7 +136,7 @@ }, { "cell_type": "code", - "execution_count": 5, + "execution_count": null, "id": "tv8ir9mp9t", "metadata": {}, "outputs": [], @@ -150,43 +150,10 @@ }, { "cell_type": "code", - "execution_count": 6, + "execution_count": null, "id": "2f0f9ac3-1e3e-438b-b463-32e839941ce0", "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "Memory usage Starting MIMIC4Dataset init: 475.3 MB\n", - "Initializing mimic4 dataset from /Users/williampang/Desktop/PyHealth/test-resources/core/mimic4demo|/Users/williampang/Desktop/PyHealth/test-resources/core/mimic4demo|None (dev mode: False)\n", - "Using provided cache_dir: /var/folders/zl/lm3qrxjd2jl17byd443y505h0000gn/T/tmpzo54xibb/efe373f9-a874-5fc5-96be-d6950c2af293\n", - "Initializing MIMIC4EHRDataset with tables: ['diagnoses_icd', 'procedures_icd', 'labevents'] (dev mode: False)\n", - "Using default EHR config: /Users/williampang/Desktop/PyHealth/pyhealth/datasets/configs/mimic4_ehr.yaml\n", - "Memory usage Before initializing mimic4_ehr: 475.3 MB\n", - "Initializing mimic4_ehr dataset from /Users/williampang/Desktop/PyHealth/test-resources/core/mimic4demo (dev mode: False)\n", - "Using provided cache_dir: /var/folders/zl/lm3qrxjd2jl17byd443y505h0000gn/T/tmpzo54xibb/efe373f9-a874-5fc5-96be-d6950c2af293/b271011a-2030-58ea-b25e-ee3250e00f4b\n", - "Memory usage After initializing mimic4_ehr: 475.5 MB\n", - "Memory usage After EHR dataset initialization: 475.5 MB\n", - "Initializing MIMIC4NoteDataset with tables: ['discharge', 'radiology'] (dev mode: False)\n", - "Using default note config: /Users/williampang/Desktop/PyHealth/pyhealth/datasets/configs/mimic4_note.yaml\n", - "Memory usage Before initializing mimic4_note: 475.5 MB\n", - "Initializing mimic4_note dataset from /Users/williampang/Desktop/PyHealth/test-resources/core/mimic4demo (dev mode: False)\n", - "Using provided cache_dir: /var/folders/zl/lm3qrxjd2jl17byd443y505h0000gn/T/tmpzo54xibb/efe373f9-a874-5fc5-96be-d6950c2af293/6e09f2d3-d3cc-5cd5-951c-e0e02a7aff3c\n", - "Memory usage After initializing mimic4_note: 475.5 MB\n", - "Memory usage After Note dataset initialization: 475.5 MB\n", - "Memory usage Completed MIMIC4Dataset init: 475.5 MB\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "/Users/williampang/Desktop/PyHealth/pyhealth/datasets/mimic4.py:121: UserWarning: Events from discharge table only have date timestamp (no specific time). This may affect temporal ordering of events.\n", - " warnings.warn(\n" - ] - } - ], + "outputs": [], "source": [ "dataset = MIMIC4Dataset(\n", " ehr_root=EHR_ROOT,\n", @@ -217,49 +184,10 @@ }, { "cell_type": "code", - "execution_count": 7, + "execution_count": null, "id": "d3b027ab-c814-49cd-8542-885d76b2401b", "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "Setting task ClinicalNotesICDLabsMIMIC4 for mimic4 base dataset...\n", - "Task cache paths: task_df=/var/folders/zl/lm3qrxjd2jl17byd443y505h0000gn/T/tmpzo54xibb/efe373f9-a874-5fc5-96be-d6950c2af293/tasks/ClinicalNotesICDLabsMIMIC4_493ab707-d120-581c-a795-319ffd5c468e/task_df.ld, samples=/var/folders/zl/lm3qrxjd2jl17byd443y505h0000gn/T/tmpzo54xibb/efe373f9-a874-5fc5-96be-d6950c2af293/tasks/ClinicalNotesICDLabsMIMIC4_493ab707-d120-581c-a795-319ffd5c468e/samples_cdbbc602-34e2-5a41-8643-4c76b08829f6.ld\n", - "Applying task transformations on data with 1 workers...\n", - "No cached event dataframe found. Creating: /var/folders/zl/lm3qrxjd2jl17byd443y505h0000gn/T/tmpzo54xibb/efe373f9-a874-5fc5-96be-d6950c2af293/global_event_df.parquet\n", - "Combining data from ehr dataset\n", - "Scanning table: diagnoses_icd from /Users/williampang/Desktop/PyHealth/test-resources/core/mimic4demo/hosp/diagnoses_icd.csv.gz\n", - "Joining with table: /Users/williampang/Desktop/PyHealth/test-resources/core/mimic4demo/hosp/admissions.csv.gz\n", - "Scanning table: procedures_icd from /Users/williampang/Desktop/PyHealth/test-resources/core/mimic4demo/hosp/procedures_icd.csv.gz\n", - "Joining with table: /Users/williampang/Desktop/PyHealth/test-resources/core/mimic4demo/hosp/admissions.csv.gz\n", - "Scanning table: labevents from /Users/williampang/Desktop/PyHealth/test-resources/core/mimic4demo/hosp/labevents.csv.gz\n", - "Joining with table: /Users/williampang/Desktop/PyHealth/test-resources/core/mimic4demo/hosp/d_labitems.csv.gz\n", - "Scanning table: patients from /Users/williampang/Desktop/PyHealth/test-resources/core/mimic4demo/hosp/patients.csv.gz\n", - "Scanning table: admissions from /Users/williampang/Desktop/PyHealth/test-resources/core/mimic4demo/hosp/admissions.csv.gz\n", - "Scanning table: icustays from /Users/williampang/Desktop/PyHealth/test-resources/core/mimic4demo/icu/icustays.csv.gz\n", - "Combining data from note dataset\n", - "Scanning table: discharge from /Users/williampang/Desktop/PyHealth/test-resources/core/mimic4demo/note/discharge.csv.gz\n", - "Scanning table: radiology from /Users/williampang/Desktop/PyHealth/test-resources/core/mimic4demo/note/radiology.csv.gz\n", - "Creating combined dataframe\n", - "Caching event dataframe to /var/folders/zl/lm3qrxjd2jl17byd443y505h0000gn/T/tmpzo54xibb/efe373f9-a874-5fc5-96be-d6950c2af293/global_event_df.parquet...\n", - "Detected Jupyter notebook environment, setting num_workers to 1\n", - "Single worker mode, processing sequentially\n", - "Worker 0 started processing 13 patients. (Polars threads: 12)\n", - "Worker 0 finished processing patients.\n", - "Fitting processors on the dataset...\n", - "Label mortality vocab: {0: 0, 1: 1}\n", - "Processing samples and saving to /var/folders/zl/lm3qrxjd2jl17byd443y505h0000gn/T/tmpzo54xibb/efe373f9-a874-5fc5-96be-d6950c2af293/tasks/ClinicalNotesICDLabsMIMIC4_493ab707-d120-581c-a795-319ffd5c468e/samples_cdbbc602-34e2-5a41-8643-4c76b08829f6.ld...\n", - "Applying processors on data with 1 workers...\n", - "Detected Jupyter notebook environment, setting num_workers to 1\n", - "Single worker mode, processing sequentially\n", - "Worker 0 started processing 13 samples. (0 to 13)\n", - "Worker 0 finished processing samples.\n", - "Cached processed samples to /var/folders/zl/lm3qrxjd2jl17byd443y505h0000gn/T/tmpzo54xibb/efe373f9-a874-5fc5-96be-d6950c2af293/tasks/ClinicalNotesICDLabsMIMIC4_493ab707-d120-581c-a795-319ffd5c468e/samples_cdbbc602-34e2-5a41-8643-4c76b08829f6.ld\n" - ] - } - ], + "outputs": [], "source": [ "%%capture\n", "task = ClinicalNotesICDLabsMIMIC4()\n", @@ -268,65 +196,10 @@ }, { "cell_type": "code", - "execution_count": 8, + "execution_count": null, "id": "6b70acb2-bdea-4a43-8b9a-7725c34fcfce", "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "\n", - "Patient ID: 1\n", - "Mortality Flag: tensor([0.])\n", - "Found 13 unique patient IDs\n", - "\n", - "num_admissions: 2\n", - " hadm_id: 1\n", - " admittime: 2150-01-01 00:00:00\n", - " dischtime: 2150-01-01 01:00:00\n", - " hadm_id: 2\n", - " admittime: 2150-01-16 00:00:00\n", - " dischtime: 2150-01-16 01:00:00\n", - "\n", - "discharge notes: 1\n", - " note_id: d18\n", - " hadm_id: 1\n", - " charttime: 2150-01-01 12:00:00\n", - " storetime: 2150-01-01 13:00:00\n", - " text: Name: ___ Unit No: ___\n", - "\n", - "Admission Date: ___ Discharge Date: ___\n", - "\n", - "Date of Birth: ___ Sex: F\n", - "\n", - "Service: NEUROLOGY\n", - "\n", - "Allergies:\n", - "codeine\n", - "\n", - "Attending: ___.\n", - "\n", - "Chief Complaint:\n", - "sudden onset left-sided weakness\n", - "\n", - "Major Surgical or Invasive Procedure:\n", - "IV tPA administration\n", - "\n", - "History of Present Illness:\n", - "___ year old female with hypertension and atrial fibrillation brought by EMS\n", - "with sudden onset left arm and leg weakness and facial droop noted 2 hours\n", - "prior to..(Limited to 500 Characters).\n", - "\n", - "radiology notes: 1\n", - " note_id: r18\n", - " hadm_id: 1\n", - " charttime: 2150-01-01 14:00:00\n", - " storetime: 2150-01-01 15:00:00\n", - " text: Chest X-ray for patient 1. No acute cardiopulmonary process identified. Heart size normal...(Limited to 500 Characters).\n" - ] - } - ], + "outputs": [], "source": [ "np.random.seed(SEED)\n", "random_patient_record = np.random.randint(0, len(samples)-1)\n", @@ -356,33 +229,10 @@ }, { "cell_type": "code", - "execution_count": 9, + "execution_count": null, "id": "16121916-e52e-4f66-8463-ff0f931cf416", "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "Setting task ClinicalNotesICDLabsMIMIC4 for mimic4 base dataset...\n", - "Task cache paths: task_df=/var/folders/zl/lm3qrxjd2jl17byd443y505h0000gn/T/tmpzo54xibb/efe373f9-a874-5fc5-96be-d6950c2af293/tasks/ClinicalNotesICDLabsMIMIC4_6c674c02-3635-50c0-bdde-3a45cb1e6f31/task_df.ld, samples=/var/folders/zl/lm3qrxjd2jl17byd443y505h0000gn/T/tmpzo54xibb/efe373f9-a874-5fc5-96be-d6950c2af293/tasks/ClinicalNotesICDLabsMIMIC4_6c674c02-3635-50c0-bdde-3a45cb1e6f31/samples_cdbbc602-34e2-5a41-8643-4c76b08829f6.ld\n", - "Applying task transformations on data with 1 workers...\n", - "Detected Jupyter notebook environment, setting num_workers to 1\n", - "Single worker mode, processing sequentially\n", - "Worker 0 started processing 13 patients. (Polars threads: 12)\n", - "Worker 0 finished processing patients.\n", - "Fitting processors on the dataset...\n", - "Label mortality vocab: {0: 0, 1: 1}\n", - "Processing samples and saving to /var/folders/zl/lm3qrxjd2jl17byd443y505h0000gn/T/tmpzo54xibb/efe373f9-a874-5fc5-96be-d6950c2af293/tasks/ClinicalNotesICDLabsMIMIC4_6c674c02-3635-50c0-bdde-3a45cb1e6f31/samples_cdbbc602-34e2-5a41-8643-4c76b08829f6.ld...\n", - "Applying processors on data with 1 workers...\n", - "Detected Jupyter notebook environment, setting num_workers to 1\n", - "Single worker mode, processing sequentially\n", - "Worker 0 started processing 13 samples. (0 to 13)\n", - "Worker 0 finished processing samples.\n", - "Cached processed samples to /var/folders/zl/lm3qrxjd2jl17byd443y505h0000gn/T/tmpzo54xibb/efe373f9-a874-5fc5-96be-d6950c2af293/tasks/ClinicalNotesICDLabsMIMIC4_6c674c02-3635-50c0-bdde-3a45cb1e6f31/samples_cdbbc602-34e2-5a41-8643-4c76b08829f6.ld\n" - ] - } - ], + "outputs": [], "source": [ "%%capture\n", "task = ClinicalNotesICDLabsMIMIC4(window_hours=12)\n", @@ -393,58 +243,10 @@ }, { "cell_type": "code", - "execution_count": 10, + "execution_count": null, "id": "42df85ab-2649-497b-92a2-415dc169798e", "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "\n", - "Patient ID: 1\n", - "Mortality Flag: tensor([0.])\n", - "Window start: 2150-01-01 00:00:00\n", - "Window end: 2150-01-01 12:00:00\n", - "\n", - "num_admissions: 1\n", - " hadm_id: 1\n", - " admittime: 2150-01-01 00:00:00\n", - " dischtime: 2150-01-01 01:00:00\n", - "\n", - "discharge notes: 1\n", - " note_id: d18\n", - " hadm_id: 1\n", - " charttime: 2150-01-01 12:00:00\n", - " storetime: 2150-01-01 13:00:00\n", - " text: Name: ___ Unit No: ___\n", - "\n", - "Admission Date: ___ Discharge Date: ___\n", - "\n", - "Date of Birth: ___ Sex: F\n", - "\n", - "Service: NEUROLOGY\n", - "\n", - "Allergies:\n", - "codeine\n", - "\n", - "Attending: ___.\n", - "\n", - "Chief Complaint:\n", - "sudden onset left-sided weakness\n", - "\n", - "Major Surgical or Invasive Procedure:\n", - "IV tPA administration\n", - "\n", - "History of Present Illness:\n", - "___ year old female with hypertension and atrial fibrillation brought by EMS\n", - "with sudden onset left arm and leg weakness and facial droop noted 2 hours\n", - "prior to..(Limited to 500 Characters).\n", - "\n", - "radiology notes: 0\n" - ] - } - ], + "outputs": [], "source": [ "print(f\"\\nPatient ID: {sample_patient_id}\")\n", "print(f\"Mortality Flag: {sample['mortality']}\")\n", @@ -473,18 +275,10 @@ }, { "cell_type": "code", - "execution_count": 11, + "execution_count": null, "id": "e089c9b6", "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "[{'patient_id': '1', 'discharge_note_times': (['chief complaint: sudden onset left-sided weakness'], [12.0]), 'radiology_note_times': ([], []), 'icd_codes': ([0.0, 0.0], [[''], ['']]), 'labs': ([0.0, 0.0], [[0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0], [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0]]), 'labs_mask': ([0.0, 0.0], [[False, False, False, False, False, False, False, False, False, False], [False, False, False, False, False, False, False, False, False, False]]), 'mortality': 0, 'window_start': datetime.datetime(2150, 1, 1, 0, 0), 'window_end': datetime.datetime(2150, 1, 1, 12, 0)}]\n" - ] - } - ], + "outputs": [], "source": [ "patient = dataset.get_patient(sample_patient_id)\n", "raw_samples = task(patient)\n", @@ -510,7 +304,7 @@ }, { "cell_type": "code", - "execution_count": 12, + "execution_count": null, "id": "57208cc0-94af-456d-9078-12acaf556df7", "metadata": {}, "outputs": [], From 95ffe60a7a4e191362bee26de395770cfcf40429 Mon Sep 17 00:00:00 2001 From: William Pang Date: Sat, 30 May 2026 11:14:47 -0700 Subject: [PATCH 08/11] update test resource to make it closer to MIMIC-data --- .../core/mimic4demo/note/radiology.csv | 290 ++++++++++++++++-- 1 file changed, 265 insertions(+), 25 deletions(-) diff --git a/test-resources/core/mimic4demo/note/radiology.csv b/test-resources/core/mimic4demo/note/radiology.csv index 1ac26f104..c51a6c825 100644 --- a/test-resources/core/mimic4demo/note/radiology.csv +++ b/test-resources/core/mimic4demo/note/radiology.csv @@ -1,25 +1,265 @@ -note_id,subject_id,hadm_id,note_type,note_seq,charttime,storetime,text -r1,10001,19999,RR,1,2150-02-15 14:00:00,2150-02-15 15:00:00,Chest X-ray for patient 10001. No acute cardiopulmonary process identified. Heart size normal. -r2,10002,20000,RR,1,2151-01-01 14:00:00,2151-01-01 15:00:00,Chest X-ray for patient 10002. No acute cardiopulmonary process identified. Heart size normal. -r3,10001,20001,RR,1,2150-03-15 14:00:00,2150-03-15 15:00:00,Chest X-ray for patient 10001. No acute cardiopulmonary process identified. Heart size normal. -r4,10001,20002,RR,1,2150-06-20 14:00:00,2150-06-20 15:00:00,Chest X-ray for patient 10001. No acute cardiopulmonary process identified. Heart size normal. -r5,10002,20003,RR,1,2151-01-10 14:00:00,2151-01-10 15:00:00,Chest X-ray for patient 10002. No acute cardiopulmonary process identified. Heart size normal. -r6,10002,20004,RR,1,2151-04-05 14:00:00,2151-04-05 15:00:00,Chest X-ray for patient 10002. No acute cardiopulmonary process identified. Heart size normal. -r7,10003,20005,RR,1,2152-02-28 14:00:00,2152-02-28 15:00:00,Chest X-ray for patient 10003. No acute cardiopulmonary process identified. Heart size normal. -r8,10003,20006,RR,1,2152-08-10 14:00:00,2152-08-10 15:00:00,Chest X-ray for patient 10003. No acute cardiopulmonary process identified. Heart size normal. -r9,10004,20007,RR,1,2150-05-01 14:00:00,2150-05-01 15:00:00,Chest X-ray for patient 10004. No acute cardiopulmonary process identified. Heart size normal. -r10,10005,20008,RR,1,2151-07-15 14:00:00,2151-07-15 15:00:00,Chest X-ray for patient 10005. No acute cardiopulmonary process identified. Heart size normal. -r11,10006,20009,RR,1,2152-09-01 14:00:00,2152-09-01 15:00:00,Chest X-ray for patient 10006. No acute cardiopulmonary process identified. Heart size normal. -r12,10006,20010,RR,1,2152-11-15 14:00:00,2152-11-15 15:00:00,Chest X-ray for patient 10006. No acute cardiopulmonary process identified. Heart size normal. -r13,10007,20011,RR,1,2150-04-10 14:00:00,2150-04-10 15:00:00,Chest X-ray for patient 10007. No acute cardiopulmonary process identified. Heart size normal. -r14,10008,20012,RR,1,2151-10-05 14:00:00,2151-10-05 15:00:00,Chest X-ray for patient 10008. No acute cardiopulmonary process identified. Heart size normal. -r15,10008,20013,RR,1,2151-12-15 14:00:00,2151-12-15 15:00:00,Chest X-ray for patient 10008. No acute cardiopulmonary process identified. Heart size normal. -r16,10009,20014,RR,1,2152-03-20 14:00:00,2152-03-20 15:00:00,Chest X-ray for patient 10009. No acute cardiopulmonary process identified. Heart size normal. -r17,10010,20015,RR,1,2150-08-01 14:00:00,2150-08-01 15:00:00,Chest X-ray for patient 10010. No acute cardiopulmonary process identified. Heart size normal. -r18,1,1,RR,1,2150-01-01 14:00:00,2150-01-01 15:00:00,Chest X-ray for patient 1. No acute cardiopulmonary process identified. Heart size normal. -r19,1,2,RR,1,2150-01-16 14:00:00,2150-01-16 15:00:00,Chest X-ray for patient 1. No acute cardiopulmonary process identified. Heart size normal. -r20,2,3,RR,1,2150-01-01 14:00:00,2150-01-01 15:00:00,Chest X-ray for patient 2. No acute cardiopulmonary process identified. Heart size normal. -r21,2,4,RR,1,2150-01-16 14:00:00,2150-01-16 15:00:00,Chest X-ray for patient 2. No acute cardiopulmonary process identified. Heart size normal. -r22,2,5,RR,1,2150-01-21 14:00:00,2150-01-21 15:00:00,Chest X-ray for patient 2. No acute cardiopulmonary process identified. Heart size normal. -r23,2,6,RR,1,2150-01-22 14:00:00,2150-01-22 15:00:00,Chest X-ray for patient 2. No acute cardiopulmonary process identified. Heart size normal. -r24,3,7,RR,1,2150-01-01 14:00:00,2150-01-01 15:00:00,Chest X-ray for patient 3. No acute cardiopulmonary process identified. Heart size normal. +note_id,subject_id,hadm_id,note_type,note_seq,charttime,storetime,text +r1,10001,19999,RR,1,2150-02-15 14:00:00,2150-02-15 15:00:00,"CLINICAL HISTORY: Patient fell onto right ribs. The patient also on anticoagulants. + +CHEST AP: + +The heart and mediastinum are normal. The lung fields are clear. No effusion or pneumothorax is present. + +No rib fracture is seen on limited views. + +Vascular stent is seen within the lower SVC, position unchanged. + +IMPRESSION: No pneumothorax. No effusion. No rib fracture identified." +r2,10002,20000,RR,1,2151-01-01 14:00:00,2151-01-01 15:00:00,"CLINICAL HISTORY: Patient fell onto right ribs. The patient also on anticoagulants. + +CHEST AP: + +The heart and mediastinum are normal. The lung fields are clear. No effusion or pneumothorax is present. + +No rib fracture is seen on limited views. + +Vascular stent is seen within the lower SVC, position unchanged. + +IMPRESSION: No pneumothorax. No effusion. No rib fracture identified." +r3,10001,20001,RR,1,2150-03-15 14:00:00,2150-03-15 15:00:00,"CLINICAL HISTORY: Patient fell onto right ribs. The patient also on anticoagulants. + +CHEST AP: + +The heart and mediastinum are normal. The lung fields are clear. No effusion or pneumothorax is present. + +No rib fracture is seen on limited views. + +Vascular stent is seen within the lower SVC, position unchanged. + +IMPRESSION: No pneumothorax. No effusion. No rib fracture identified." +r4,10001,20002,RR,1,2150-06-20 14:00:00,2150-06-20 15:00:00,"CLINICAL HISTORY: Patient fell onto right ribs. The patient also on anticoagulants. + +CHEST AP: + +The heart and mediastinum are normal. The lung fields are clear. No effusion or pneumothorax is present. + +No rib fracture is seen on limited views. + +Vascular stent is seen within the lower SVC, position unchanged. + +IMPRESSION: No pneumothorax. No effusion. No rib fracture identified." +r5,10002,20003,RR,1,2151-01-10 14:00:00,2151-01-10 15:00:00,"CLINICAL HISTORY: Patient fell onto right ribs. The patient also on anticoagulants. + +CHEST AP: + +The heart and mediastinum are normal. The lung fields are clear. No effusion or pneumothorax is present. + +No rib fracture is seen on limited views. + +Vascular stent is seen within the lower SVC, position unchanged. + +IMPRESSION: No pneumothorax. No effusion. No rib fracture identified." +r6,10002,20004,RR,1,2151-04-05 14:00:00,2151-04-05 15:00:00,"CLINICAL HISTORY: Patient fell onto right ribs. The patient also on anticoagulants. + +CHEST AP: + +The heart and mediastinum are normal. The lung fields are clear. No effusion or pneumothorax is present. + +No rib fracture is seen on limited views. + +Vascular stent is seen within the lower SVC, position unchanged. + +IMPRESSION: No pneumothorax. No effusion. No rib fracture identified." +r7,10003,20005,RR,1,2152-02-28 14:00:00,2152-02-28 15:00:00,"CLINICAL HISTORY: Patient fell onto right ribs. The patient also on anticoagulants. + +CHEST AP: + +The heart and mediastinum are normal. The lung fields are clear. No effusion or pneumothorax is present. + +No rib fracture is seen on limited views. + +Vascular stent is seen within the lower SVC, position unchanged. + +IMPRESSION: No pneumothorax. No effusion. No rib fracture identified." +r8,10003,20006,RR,1,2152-08-10 14:00:00,2152-08-10 15:00:00,"CLINICAL HISTORY: Patient fell onto right ribs. The patient also on anticoagulants. + +CHEST AP: + +The heart and mediastinum are normal. The lung fields are clear. No effusion or pneumothorax is present. + +No rib fracture is seen on limited views. + +Vascular stent is seen within the lower SVC, position unchanged. + +IMPRESSION: No pneumothorax. No effusion. No rib fracture identified." +r9,10004,20007,RR,1,2150-05-01 14:00:00,2150-05-01 15:00:00,"CLINICAL HISTORY: Patient fell onto right ribs. The patient also on anticoagulants. + +CHEST AP: + +The heart and mediastinum are normal. The lung fields are clear. No effusion or pneumothorax is present. + +No rib fracture is seen on limited views. + +Vascular stent is seen within the lower SVC, position unchanged. + +IMPRESSION: No pneumothorax. No effusion. No rib fracture identified." +r10,10005,20008,RR,1,2151-07-15 14:00:00,2151-07-15 15:00:00,"CLINICAL HISTORY: Patient fell onto right ribs. The patient also on anticoagulants. + +CHEST AP: + +The heart and mediastinum are normal. The lung fields are clear. No effusion or pneumothorax is present. + +No rib fracture is seen on limited views. + +Vascular stent is seen within the lower SVC, position unchanged. + +IMPRESSION: No pneumothorax. No effusion. No rib fracture identified." +r11,10006,20009,RR,1,2152-09-01 14:00:00,2152-09-01 15:00:00,"CLINICAL HISTORY: Patient fell onto right ribs. The patient also on anticoagulants. + +CHEST AP: + +The heart and mediastinum are normal. The lung fields are clear. No effusion or pneumothorax is present. + +No rib fracture is seen on limited views. + +Vascular stent is seen within the lower SVC, position unchanged. + +IMPRESSION: No pneumothorax. No effusion. No rib fracture identified." +r12,10006,20010,RR,1,2152-11-15 14:00:00,2152-11-15 15:00:00,"CLINICAL HISTORY: Patient fell onto right ribs. The patient also on anticoagulants. + +CHEST AP: + +The heart and mediastinum are normal. The lung fields are clear. No effusion or pneumothorax is present. + +No rib fracture is seen on limited views. + +Vascular stent is seen within the lower SVC, position unchanged. + +IMPRESSION: No pneumothorax. No effusion. No rib fracture identified." +r13,10007,20011,RR,1,2150-04-10 14:00:00,2150-04-10 15:00:00,"CLINICAL HISTORY: Patient fell onto right ribs. The patient also on anticoagulants. + +CHEST AP: + +The heart and mediastinum are normal. The lung fields are clear. No effusion or pneumothorax is present. + +No rib fracture is seen on limited views. + +Vascular stent is seen within the lower SVC, position unchanged. + +IMPRESSION: No pneumothorax. No effusion. No rib fracture identified." +r14,10008,20012,RR,1,2151-10-05 14:00:00,2151-10-05 15:00:00,"CLINICAL HISTORY: Patient fell onto right ribs. The patient also on anticoagulants. + +CHEST AP: + +The heart and mediastinum are normal. The lung fields are clear. No effusion or pneumothorax is present. + +No rib fracture is seen on limited views. + +Vascular stent is seen within the lower SVC, position unchanged. + +IMPRESSION: No pneumothorax. No effusion. No rib fracture identified." +r15,10008,20013,RR,1,2151-12-15 14:00:00,2151-12-15 15:00:00,"CLINICAL HISTORY: Patient fell onto right ribs. The patient also on anticoagulants. + +CHEST AP: + +The heart and mediastinum are normal. The lung fields are clear. No effusion or pneumothorax is present. + +No rib fracture is seen on limited views. + +Vascular stent is seen within the lower SVC, position unchanged. + +IMPRESSION: No pneumothorax. No effusion. No rib fracture identified." +r16,10009,20014,RR,1,2152-03-20 14:00:00,2152-03-20 15:00:00,"CLINICAL HISTORY: Patient fell onto right ribs. The patient also on anticoagulants. + +CHEST AP: + +The heart and mediastinum are normal. The lung fields are clear. No effusion or pneumothorax is present. + +No rib fracture is seen on limited views. + +Vascular stent is seen within the lower SVC, position unchanged. + +IMPRESSION: No pneumothorax. No effusion. No rib fracture identified." +r17,10010,20015,RR,1,2150-08-01 14:00:00,2150-08-01 15:00:00,"CLINICAL HISTORY: Patient fell onto right ribs. The patient also on anticoagulants. + +CHEST AP: + +The heart and mediastinum are normal. The lung fields are clear. No effusion or pneumothorax is present. + +No rib fracture is seen on limited views. + +Vascular stent is seen within the lower SVC, position unchanged. + +IMPRESSION: No pneumothorax. No effusion. No rib fracture identified." +r18,1,1,RR,1,2150-01-01 14:00:00,2150-01-01 15:00:00,"CLINICAL HISTORY: Patient fell onto right ribs. The patient also on anticoagulants. + +CHEST AP: + +The heart and mediastinum are normal. The lung fields are clear. No effusion or pneumothorax is present. + +No rib fracture is seen on limited views. + +Vascular stent is seen within the lower SVC, position unchanged. + +IMPRESSION: No pneumothorax. No effusion. No rib fracture identified." +r19,1,2,RR,1,2150-01-16 14:00:00,2150-01-16 15:00:00,"CLINICAL HISTORY: Patient fell onto right ribs. The patient also on anticoagulants. + +CHEST AP: + +The heart and mediastinum are normal. The lung fields are clear. No effusion or pneumothorax is present. + +No rib fracture is seen on limited views. + +Vascular stent is seen within the lower SVC, position unchanged. + +IMPRESSION: No pneumothorax. No effusion. No rib fracture identified." +r20,2,3,RR,1,2150-01-01 14:00:00,2150-01-01 15:00:00,"CLINICAL HISTORY: Patient fell onto right ribs. The patient also on anticoagulants. + +CHEST AP: + +The heart and mediastinum are normal. The lung fields are clear. No effusion or pneumothorax is present. + +No rib fracture is seen on limited views. + +Vascular stent is seen within the lower SVC, position unchanged. + +IMPRESSION: No pneumothorax. No effusion. No rib fracture identified." +r21,2,4,RR,1,2150-01-16 14:00:00,2150-01-16 15:00:00,"CLINICAL HISTORY: Patient fell onto right ribs. The patient also on anticoagulants. + +CHEST AP: + +The heart and mediastinum are normal. The lung fields are clear. No effusion or pneumothorax is present. + +No rib fracture is seen on limited views. + +Vascular stent is seen within the lower SVC, position unchanged. + +IMPRESSION: No pneumothorax. No effusion. No rib fracture identified." +r22,2,5,RR,1,2150-01-21 14:00:00,2150-01-21 15:00:00,"CLINICAL HISTORY: Patient fell onto right ribs. The patient also on anticoagulants. + +CHEST AP: + +The heart and mediastinum are normal. The lung fields are clear. No effusion or pneumothorax is present. + +No rib fracture is seen on limited views. + +Vascular stent is seen within the lower SVC, position unchanged. + +IMPRESSION: No pneumothorax. No effusion. No rib fracture identified." +r23,2,6,RR,1,2150-01-22 14:00:00,2150-01-22 15:00:00,"CLINICAL HISTORY: Patient fell onto right ribs. The patient also on anticoagulants. + +CHEST AP: + +The heart and mediastinum are normal. The lung fields are clear. No effusion or pneumothorax is present. + +No rib fracture is seen on limited views. + +Vascular stent is seen within the lower SVC, position unchanged. + +IMPRESSION: No pneumothorax. No effusion. No rib fracture identified." +r24,3,7,RR,1,2150-01-01 14:00:00,2150-01-01 15:00:00,"CLINICAL HISTORY: Patient fell onto right ribs. The patient also on anticoagulants. + +CHEST AP: + +The heart and mediastinum are normal. The lung fields are clear. No effusion or pneumothorax is present. + +No rib fracture is seen on limited views. + +Vascular stent is seen within the lower SVC, position unchanged. + +IMPRESSION: No pneumothorax. No effusion. No rib fracture identified." From 633ecde871c85d44bcb1dcf9f39bf9b2861bddbb Mon Sep 17 00:00:00 2001 From: William Pang Date: Sat, 30 May 2026 11:14:55 -0700 Subject: [PATCH 09/11] Update multimodal_mimic4.py --- pyhealth/tasks/multimodal_mimic4.py | 48 +++++++++++++++++------------ 1 file changed, 29 insertions(+), 19 deletions(-) diff --git a/pyhealth/tasks/multimodal_mimic4.py b/pyhealth/tasks/multimodal_mimic4.py index 88a2f0ea0..8d0114a40 100644 --- a/pyhealth/tasks/multimodal_mimic4.py +++ b/pyhealth/tasks/multimodal_mimic4.py @@ -70,16 +70,15 @@ class BaseMultimodalMIMIC4Task(BaseTask): ] RADIOLOGY_CLINICAL_HEADERS: ClassVar[List[str]] = [ - "impression", - "findings", - "clinical indication", "indication", - "clinical history", - "history", - "comparison", - "technique", - "conclusion", - "summary" + "impression", + # "findings", + # "clinical history", + # "history", + # "comparison", + # "technique", + # "conclusion", + # "summary" ] DISCHARGE_CLINICAL_HEADERS: ClassVar[List[str]] = [ @@ -111,15 +110,19 @@ def _clean_text(text: Optional[str]) -> Optional[str]: return text if text else None @staticmethod - def _parse_note_sections(text: str) -> Dict[str, str]: + def _parse_note_sections(text: str, note_type: str) -> Dict[str, str]: """Split a note into {lowercased_header: content_text} pairs.""" - section_re = re.compile( - r"^\s*([A-Za-z][A-Za-z \t,/\-\.]{1,60}?)\s*:\s*\n(.*?)(?=^\s*[A-Za-z][A-Za-z \t,/\-\.]{1,60}?\s*:\s*$|\Z)", - re.MULTILINE | re.DOTALL, - ) + ext_text = text + '\n\n' + if note_type == "radiology": + section_re = re.compile(r'([a-zA-Z ]+):[ \t\n]+(.+?)\n{2,}', re.DOTALL) + elif note_type == "discharge": + section_re = re.compile(r'([a-zA-Z ]+):\n+(.+?)\n{2,}', re.DOTALL) + else: + raise ValueError(f"Note Type '{note_type}' not supported.") return { m.group(1).strip().lower(): m.group(2).strip() - for m in section_re.finditer(text) + for m in section_re.finditer(ext_text) + if m.end() - m.start() > 0 } @staticmethod @@ -384,6 +387,7 @@ def _collect_notes( start_time: Optional[datetime] = None, end_time: Optional[datetime] = None, section_headers: Optional[List[str]] = None, + fallback_to_full_note: bool = False, ) -> Tuple[List[str], List[float]]: """Collect notes of a given type for one admission. @@ -395,8 +399,10 @@ def _collect_notes( start_time: Optional start of the time window. end_time: Optional end of the time window. section_headers: When provided, extract only these named sections - from each note (lowercased match against parsed headers). Falls - back to the full note text when no matching sections are found. + from each note (lowercased match against parsed headers). + fallback_to_full_note: When True (default), falls back to the full + note text if no matching sections are found. When False, notes + with no matching sections are dropped entirely. Returns: Tuple of (texts, hours_from_admission). Falls back to @@ -417,9 +423,13 @@ def _collect_notes( note_text = self._clean_text(note.text) if note_text: if section_headers is not None: - parsed = self._parse_note_sections(note_text) + parsed = self._parse_note_sections(note_text, note_type=note_event_type) extracted = [f"{k}: {v}" for k, v in parsed.items() if k in section_headers and v] - note_text = " [SEP] ".join(extracted) if extracted else note_text + if extracted: + note_text = " [SEP] ".join(extracted) + elif not fallback_to_full_note: + continue + time_from_admission = self._to_hours( (note.timestamp - admission_time).total_seconds() ) From 456da12e5c7139d4006faec527f9feeadd042bc3 Mon Sep 17 00:00:00 2001 From: William Pang Date: Sat, 30 May 2026 11:14:58 -0700 Subject: [PATCH 10/11] Update multimodal_mimic4_task_tutorial.ipynb --- .../multimodal_mimic4_task_tutorial.ipynb | 294 ++++++++++++++++-- 1 file changed, 266 insertions(+), 28 deletions(-) diff --git a/examples/multimodal_mimic4_task_tutorial.ipynb b/examples/multimodal_mimic4_task_tutorial.ipynb index 830f7da7c..9df82f20b 100644 --- a/examples/multimodal_mimic4_task_tutorial.ipynb +++ b/examples/multimodal_mimic4_task_tutorial.ipynb @@ -25,7 +25,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 1, "id": "8477e2ac-322f-49e9-819f-ce7621b214c6", "metadata": {}, "outputs": [], @@ -50,7 +50,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 2, "id": "201c3a62-2a2e-47ab-9ab8-eea77812f349", "metadata": {}, "outputs": [], @@ -69,12 +69,12 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 3, "id": "9a466c4b-2283-443f-94a3-5768babddf50", "metadata": {}, "outputs": [], "source": [ - "SEED = 999" + "SEED = 1" ] }, { @@ -87,7 +87,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 4, "id": "05ec2dc9-1a0c-4360-a028-d93173dcba65", "metadata": {}, "outputs": [], @@ -136,7 +136,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 5, "id": "tv8ir9mp9t", "metadata": {}, "outputs": [], @@ -150,10 +150,43 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 6, "id": "2f0f9ac3-1e3e-438b-b463-32e839941ce0", "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Memory usage Starting MIMIC4Dataset init: 521.0 MB\n", + "Initializing mimic4 dataset from /Users/williampang/Desktop/PyHealth/test-resources/core/mimic4demo|/Users/williampang/Desktop/PyHealth/test-resources/core/mimic4demo|None (dev mode: False)\n", + "Using provided cache_dir: /var/folders/zl/lm3qrxjd2jl17byd443y505h0000gn/T/tmpbrpwqzrq/efe373f9-a874-5fc5-96be-d6950c2af293\n", + "Initializing MIMIC4EHRDataset with tables: ['diagnoses_icd', 'procedures_icd', 'labevents'] (dev mode: False)\n", + "Using default EHR config: /Users/williampang/Desktop/PyHealth/pyhealth/datasets/configs/mimic4_ehr.yaml\n", + "Memory usage Before initializing mimic4_ehr: 521.1 MB\n", + "Initializing mimic4_ehr dataset from /Users/williampang/Desktop/PyHealth/test-resources/core/mimic4demo (dev mode: False)\n", + "Using provided cache_dir: /var/folders/zl/lm3qrxjd2jl17byd443y505h0000gn/T/tmpbrpwqzrq/efe373f9-a874-5fc5-96be-d6950c2af293/b271011a-2030-58ea-b25e-ee3250e00f4b\n", + "Memory usage After initializing mimic4_ehr: 521.3 MB\n", + "Memory usage After EHR dataset initialization: 521.3 MB\n", + "Initializing MIMIC4NoteDataset with tables: ['discharge', 'radiology'] (dev mode: False)\n", + "Using default note config: /Users/williampang/Desktop/PyHealth/pyhealth/datasets/configs/mimic4_note.yaml\n", + "Memory usage Before initializing mimic4_note: 521.3 MB\n", + "Initializing mimic4_note dataset from /Users/williampang/Desktop/PyHealth/test-resources/core/mimic4demo (dev mode: False)\n", + "Using provided cache_dir: /var/folders/zl/lm3qrxjd2jl17byd443y505h0000gn/T/tmpbrpwqzrq/efe373f9-a874-5fc5-96be-d6950c2af293/6e09f2d3-d3cc-5cd5-951c-e0e02a7aff3c\n", + "Memory usage After initializing mimic4_note: 521.3 MB\n", + "Memory usage After Note dataset initialization: 521.3 MB\n", + "Memory usage Completed MIMIC4Dataset init: 521.3 MB\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "/Users/williampang/Desktop/PyHealth/pyhealth/datasets/mimic4.py:121: UserWarning: Events from discharge table only have date timestamp (no specific time). This may affect temporal ordering of events.\n", + " warnings.warn(\n" + ] + } + ], "source": [ "dataset = MIMIC4Dataset(\n", " ehr_root=EHR_ROOT,\n", @@ -184,10 +217,49 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 7, "id": "d3b027ab-c814-49cd-8542-885d76b2401b", "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Setting task ClinicalNotesICDLabsMIMIC4 for mimic4 base dataset...\n", + "Task cache paths: task_df=/var/folders/zl/lm3qrxjd2jl17byd443y505h0000gn/T/tmpbrpwqzrq/efe373f9-a874-5fc5-96be-d6950c2af293/tasks/ClinicalNotesICDLabsMIMIC4_493ab707-d120-581c-a795-319ffd5c468e/task_df.ld, samples=/var/folders/zl/lm3qrxjd2jl17byd443y505h0000gn/T/tmpbrpwqzrq/efe373f9-a874-5fc5-96be-d6950c2af293/tasks/ClinicalNotesICDLabsMIMIC4_493ab707-d120-581c-a795-319ffd5c468e/samples_cdbbc602-34e2-5a41-8643-4c76b08829f6.ld\n", + "Applying task transformations on data with 1 workers...\n", + "No cached event dataframe found. Creating: /var/folders/zl/lm3qrxjd2jl17byd443y505h0000gn/T/tmpbrpwqzrq/efe373f9-a874-5fc5-96be-d6950c2af293/global_event_df.parquet\n", + "Combining data from ehr dataset\n", + "Scanning table: diagnoses_icd from /Users/williampang/Desktop/PyHealth/test-resources/core/mimic4demo/hosp/diagnoses_icd.csv.gz\n", + "Joining with table: /Users/williampang/Desktop/PyHealth/test-resources/core/mimic4demo/hosp/admissions.csv.gz\n", + "Scanning table: procedures_icd from /Users/williampang/Desktop/PyHealth/test-resources/core/mimic4demo/hosp/procedures_icd.csv.gz\n", + "Joining with table: /Users/williampang/Desktop/PyHealth/test-resources/core/mimic4demo/hosp/admissions.csv.gz\n", + "Scanning table: labevents from /Users/williampang/Desktop/PyHealth/test-resources/core/mimic4demo/hosp/labevents.csv.gz\n", + "Joining with table: /Users/williampang/Desktop/PyHealth/test-resources/core/mimic4demo/hosp/d_labitems.csv.gz\n", + "Scanning table: patients from /Users/williampang/Desktop/PyHealth/test-resources/core/mimic4demo/hosp/patients.csv.gz\n", + "Scanning table: admissions from /Users/williampang/Desktop/PyHealth/test-resources/core/mimic4demo/hosp/admissions.csv.gz\n", + "Scanning table: icustays from /Users/williampang/Desktop/PyHealth/test-resources/core/mimic4demo/icu/icustays.csv.gz\n", + "Combining data from note dataset\n", + "Scanning table: discharge from /Users/williampang/Desktop/PyHealth/test-resources/core/mimic4demo/note/discharge.csv.gz\n", + "Scanning table: radiology from /Users/williampang/Desktop/PyHealth/test-resources/core/mimic4demo/note/radiology.csv.gz\n", + "Creating combined dataframe\n", + "Caching event dataframe to /var/folders/zl/lm3qrxjd2jl17byd443y505h0000gn/T/tmpbrpwqzrq/efe373f9-a874-5fc5-96be-d6950c2af293/global_event_df.parquet...\n", + "Detected Jupyter notebook environment, setting num_workers to 1\n", + "Single worker mode, processing sequentially\n", + "Worker 0 started processing 13 patients. (Polars threads: 12)\n", + "Worker 0 finished processing patients.\n", + "Fitting processors on the dataset...\n", + "Label mortality vocab: {0: 0, 1: 1}\n", + "Processing samples and saving to /var/folders/zl/lm3qrxjd2jl17byd443y505h0000gn/T/tmpbrpwqzrq/efe373f9-a874-5fc5-96be-d6950c2af293/tasks/ClinicalNotesICDLabsMIMIC4_493ab707-d120-581c-a795-319ffd5c468e/samples_cdbbc602-34e2-5a41-8643-4c76b08829f6.ld...\n", + "Applying processors on data with 1 workers...\n", + "Detected Jupyter notebook environment, setting num_workers to 1\n", + "Single worker mode, processing sequentially\n", + "Worker 0 started processing 13 samples. (0 to 13)\n", + "Worker 0 finished processing samples.\n", + "Cached processed samples to /var/folders/zl/lm3qrxjd2jl17byd443y505h0000gn/T/tmpbrpwqzrq/efe373f9-a874-5fc5-96be-d6950c2af293/tasks/ClinicalNotesICDLabsMIMIC4_493ab707-d120-581c-a795-319ffd5c468e/samples_cdbbc602-34e2-5a41-8643-4c76b08829f6.ld\n" + ] + } + ], "source": [ "%%capture\n", "task = ClinicalNotesICDLabsMIMIC4()\n", @@ -196,10 +268,72 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 8, "id": "6b70acb2-bdea-4a43-8b9a-7725c34fcfce", "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "\n", + "Patient ID: 10005\n", + "Mortality Flag: tensor([0.])\n", + "Found 13 unique patient IDs\n", + "\n", + "num_admissions: 1\n", + " hadm_id: 20008\n", + " admittime: 2151-07-15 08:30:00\n", + " dischtime: 2151-07-22 12:00:00\n", + "\n", + "discharge notes: 1\n", + " note_id: d10\n", + " hadm_id: 20008\n", + " charttime: 2151-07-22 12:00:00\n", + " storetime: 2151-07-22 13:00:00\n", + " text: Name: ___ Unit No: ___\n", + "\n", + "Admission Date: ___ Discharge Date: ___\n", + "\n", + "Date of Birth: ___ Sex: F\n", + "\n", + "Service: CARDIOLOGY\n", + "\n", + "Allergies:\n", + "no known drug allergies\n", + "\n", + "Attending: ___.\n", + "\n", + "Chief Complaint:\n", + "leg swelling and shortness of breath\n", + "\n", + "Major Surgical or Invasive Procedure:\n", + "none\n", + "\n", + "History of Present Illness:\n", + "___ year old female with history of congestive heart failure (EF 30%) presenting\n", + "with 1 week of progressive bilateral lower extremity edema and orthopnea.\n", + "W..(Limited to 500 Characters).\n", + "\n", + "radiology notes: 1\n", + " note_id: r10\n", + " hadm_id: 20008\n", + " charttime: 2151-07-15 14:00:00\n", + " storetime: 2151-07-15 15:00:00\n", + " text: CLINICAL HISTORY: Patient fell onto right ribs. The patient also on anticoagulants.\n", + "\n", + "CHEST AP:\n", + "\n", + "The heart and mediastinum are normal. The lung fields are clear. No effusion or pneumothorax is present.\n", + "\n", + "No rib fracture is seen on limited views.\n", + "\n", + "Vascular stent is seen within the lower SVC, position unchanged.\n", + "\n", + "IMPRESSION: No pneumothorax. No effusion. No rib fracture identified...(Limited to 500 Characters).\n" + ] + } + ], "source": [ "np.random.seed(SEED)\n", "random_patient_record = np.random.randint(0, len(samples)-1)\n", @@ -224,15 +358,38 @@ "id": "fd7d6767-ae51-4278-bb55-d12bdf3a4ff2", "metadata": {}, "source": [ - "### 3.2 Random Patient Window" + "### 3.2 Patient with Filtered Time Window" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 9, "id": "16121916-e52e-4f66-8463-ff0f931cf416", "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Setting task ClinicalNotesICDLabsMIMIC4 for mimic4 base dataset...\n", + "Task cache paths: task_df=/var/folders/zl/lm3qrxjd2jl17byd443y505h0000gn/T/tmpbrpwqzrq/efe373f9-a874-5fc5-96be-d6950c2af293/tasks/ClinicalNotesICDLabsMIMIC4_6c674c02-3635-50c0-bdde-3a45cb1e6f31/task_df.ld, samples=/var/folders/zl/lm3qrxjd2jl17byd443y505h0000gn/T/tmpbrpwqzrq/efe373f9-a874-5fc5-96be-d6950c2af293/tasks/ClinicalNotesICDLabsMIMIC4_6c674c02-3635-50c0-bdde-3a45cb1e6f31/samples_cdbbc602-34e2-5a41-8643-4c76b08829f6.ld\n", + "Applying task transformations on data with 1 workers...\n", + "Detected Jupyter notebook environment, setting num_workers to 1\n", + "Single worker mode, processing sequentially\n", + "Worker 0 started processing 13 patients. (Polars threads: 12)\n", + "Worker 0 finished processing patients.\n", + "Fitting processors on the dataset...\n", + "Label mortality vocab: {0: 0, 1: 1}\n", + "Processing samples and saving to /var/folders/zl/lm3qrxjd2jl17byd443y505h0000gn/T/tmpbrpwqzrq/efe373f9-a874-5fc5-96be-d6950c2af293/tasks/ClinicalNotesICDLabsMIMIC4_6c674c02-3635-50c0-bdde-3a45cb1e6f31/samples_cdbbc602-34e2-5a41-8643-4c76b08829f6.ld...\n", + "Applying processors on data with 1 workers...\n", + "Detected Jupyter notebook environment, setting num_workers to 1\n", + "Single worker mode, processing sequentially\n", + "Worker 0 started processing 13 samples. (0 to 13)\n", + "Worker 0 finished processing samples.\n", + "Cached processed samples to /var/folders/zl/lm3qrxjd2jl17byd443y505h0000gn/T/tmpbrpwqzrq/efe373f9-a874-5fc5-96be-d6950c2af293/tasks/ClinicalNotesICDLabsMIMIC4_6c674c02-3635-50c0-bdde-3a45cb1e6f31/samples_cdbbc602-34e2-5a41-8643-4c76b08829f6.ld\n" + ] + } + ], "source": [ "%%capture\n", "task = ClinicalNotesICDLabsMIMIC4(window_hours=12)\n", @@ -243,10 +400,46 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 10, "id": "42df85ab-2649-497b-92a2-415dc169798e", "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "\n", + "Patient ID: 10005\n", + "Mortality Flag: tensor([0.])\n", + "Window start: 2151-07-15 08:30:00\n", + "Window end: 2151-07-15 20:30:00\n", + "\n", + "num_admissions: 1\n", + " hadm_id: 20008\n", + " admittime: 2151-07-15 08:30:00\n", + " dischtime: 2151-07-22 12:00:00\n", + "\n", + "discharge notes: 0\n", + "\n", + "radiology notes: 1\n", + " note_id: r10\n", + " hadm_id: 20008\n", + " charttime: 2151-07-15 14:00:00\n", + " storetime: 2151-07-15 15:00:00\n", + " text: CLINICAL HISTORY: Patient fell onto right ribs. The patient also on anticoagulants.\n", + "\n", + "CHEST AP:\n", + "\n", + "The heart and mediastinum are normal. The lung fields are clear. No effusion or pneumothorax is present.\n", + "\n", + "No rib fracture is seen on limited views.\n", + "\n", + "Vascular stent is seen within the lower SVC, position unchanged.\n", + "\n", + "IMPRESSION: No pneumothorax. No effusion. No rib fracture identified...(Limited to 500 Characters).\n" + ] + } + ], "source": [ "print(f\"\\nPatient ID: {sample_patient_id}\")\n", "print(f\"Mortality Flag: {sample['mortality']}\")\n", @@ -268,22 +461,67 @@ "id": "e1dd556a", "metadata": {}, "source": [ - "### 3.3 Inspect Pre-Tokenization Note Text\n", - "\n", - "Call the task directly on a patient (bypassing the processor) to see the note text **after section filtering but before tokenization**. This lets you verify the note has been shrunk to only the `DISCHARGE_CLINICAL_HEADERS` sections." + "### 4. Inspect Task Output (before processor)" ] }, { "cell_type": "code", - "execution_count": null, - "id": "e089c9b6", + "execution_count": 11, + "id": "9113eab7-20f5-455b-8e99-570de8622ba6", "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Setting task ClinicalNotesICDLabsMIMIC4 for mimic4 base dataset...\n", + "Task cache paths: task_df=/var/folders/zl/lm3qrxjd2jl17byd443y505h0000gn/T/tmpbrpwqzrq/efe373f9-a874-5fc5-96be-d6950c2af293/tasks/ClinicalNotesICDLabsMIMIC4_493ab707-d120-581c-a795-319ffd5c468e/task_df.ld, samples=/var/folders/zl/lm3qrxjd2jl17byd443y505h0000gn/T/tmpbrpwqzrq/efe373f9-a874-5fc5-96be-d6950c2af293/tasks/ClinicalNotesICDLabsMIMIC4_493ab707-d120-581c-a795-319ffd5c468e/samples_cdbbc602-34e2-5a41-8643-4c76b08829f6.ld\n", + "Found cached processed samples at /var/folders/zl/lm3qrxjd2jl17byd443y505h0000gn/T/tmpbrpwqzrq/efe373f9-a874-5fc5-96be-d6950c2af293/tasks/ClinicalNotesICDLabsMIMIC4_493ab707-d120-581c-a795-319ffd5c468e/samples_cdbbc602-34e2-5a41-8643-4c76b08829f6.ld, skipping processing.\n" + ] + } + ], "source": [ - "patient = dataset.get_patient(sample_patient_id)\n", - "raw_samples = task(patient)\n", + "%%capture\n", + "task = ClinicalNotesICDLabsMIMIC4()\n", + "samples = dataset.set_task(task, num_workers=1)\n", + "sample = samples[random_patient_record]\n", + "sample_patient_id = sample['patient_id']\n", "\n", - "print(raw_samples)" + "patient = dataset.get_patient(sample_patient_id)\n", + "sample_task_output = task(patient)" + ] + }, + { + "cell_type": "code", + "execution_count": 12, + "id": "23399090-175d-4492-8657-4a2c51293992", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "[{'patient_id': '10005',\n", + " 'discharge_note_times': (['chief complaint: leg swelling and shortness of breath'],\n", + " [171.5]),\n", + " 'radiology_note_times': (['impression: No pneumothorax. No effusion. No rib fracture identified.'],\n", + " [5.5]),\n", + " 'icd_codes': ([0.0],\n", + " [['25001', '5849', '4019', '25011', '5A1D70Z', '3991']]),\n", + " 'labs': ([1.5], [[134.0, 5.8, 96.0, 14.0, 380.0, 0.0, 0.0, 20.0, 0.0, 0.0]]),\n", + " 'labs_mask': ([1.5],\n", + " [[True, True, True, True, True, False, False, True, False, False]]),\n", + " 'mortality': 0,\n", + " 'window_start': datetime.datetime(2151, 7, 15, 8, 30),\n", + " 'window_end': datetime.datetime(2151, 7, 22, 12, 0)}]" + ] + }, + "execution_count": 12, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "sample_task_output" ] }, { @@ -291,7 +529,7 @@ "id": "a447c4e2-cfae-4e15-a2ac-0fac5754c1f2", "metadata": {}, "source": [ - "## 4. Cleanup" + "## 5. Cleanup" ] }, { @@ -304,7 +542,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 13, "id": "57208cc0-94af-456d-9078-12acaf556df7", "metadata": {}, "outputs": [], From 422cbf5b637eb4b7d9cc911c503057a8e92967ac Mon Sep 17 00:00:00 2001 From: William Pang Date: Sat, 30 May 2026 11:15:20 -0700 Subject: [PATCH 11/11] Update multimodal_mimic4_task_tutorial.ipynb --- .../multimodal_mimic4_task_tutorial.ipynb | 266 ++---------------- 1 file changed, 20 insertions(+), 246 deletions(-) diff --git a/examples/multimodal_mimic4_task_tutorial.ipynb b/examples/multimodal_mimic4_task_tutorial.ipynb index 9df82f20b..ba7bf5d29 100644 --- a/examples/multimodal_mimic4_task_tutorial.ipynb +++ b/examples/multimodal_mimic4_task_tutorial.ipynb @@ -25,7 +25,7 @@ }, { "cell_type": "code", - "execution_count": 1, + "execution_count": null, "id": "8477e2ac-322f-49e9-819f-ce7621b214c6", "metadata": {}, "outputs": [], @@ -50,7 +50,7 @@ }, { "cell_type": "code", - "execution_count": 2, + "execution_count": null, "id": "201c3a62-2a2e-47ab-9ab8-eea77812f349", "metadata": {}, "outputs": [], @@ -69,7 +69,7 @@ }, { "cell_type": "code", - "execution_count": 3, + "execution_count": null, "id": "9a466c4b-2283-443f-94a3-5768babddf50", "metadata": {}, "outputs": [], @@ -87,7 +87,7 @@ }, { "cell_type": "code", - "execution_count": 4, + "execution_count": null, "id": "05ec2dc9-1a0c-4360-a028-d93173dcba65", "metadata": {}, "outputs": [], @@ -136,7 +136,7 @@ }, { "cell_type": "code", - "execution_count": 5, + "execution_count": null, "id": "tv8ir9mp9t", "metadata": {}, "outputs": [], @@ -150,43 +150,10 @@ }, { "cell_type": "code", - "execution_count": 6, + "execution_count": null, "id": "2f0f9ac3-1e3e-438b-b463-32e839941ce0", "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "Memory usage Starting MIMIC4Dataset init: 521.0 MB\n", - "Initializing mimic4 dataset from /Users/williampang/Desktop/PyHealth/test-resources/core/mimic4demo|/Users/williampang/Desktop/PyHealth/test-resources/core/mimic4demo|None (dev mode: False)\n", - "Using provided cache_dir: /var/folders/zl/lm3qrxjd2jl17byd443y505h0000gn/T/tmpbrpwqzrq/efe373f9-a874-5fc5-96be-d6950c2af293\n", - "Initializing MIMIC4EHRDataset with tables: ['diagnoses_icd', 'procedures_icd', 'labevents'] (dev mode: False)\n", - "Using default EHR config: /Users/williampang/Desktop/PyHealth/pyhealth/datasets/configs/mimic4_ehr.yaml\n", - "Memory usage Before initializing mimic4_ehr: 521.1 MB\n", - "Initializing mimic4_ehr dataset from /Users/williampang/Desktop/PyHealth/test-resources/core/mimic4demo (dev mode: False)\n", - "Using provided cache_dir: /var/folders/zl/lm3qrxjd2jl17byd443y505h0000gn/T/tmpbrpwqzrq/efe373f9-a874-5fc5-96be-d6950c2af293/b271011a-2030-58ea-b25e-ee3250e00f4b\n", - "Memory usage After initializing mimic4_ehr: 521.3 MB\n", - "Memory usage After EHR dataset initialization: 521.3 MB\n", - "Initializing MIMIC4NoteDataset with tables: ['discharge', 'radiology'] (dev mode: False)\n", - "Using default note config: /Users/williampang/Desktop/PyHealth/pyhealth/datasets/configs/mimic4_note.yaml\n", - "Memory usage Before initializing mimic4_note: 521.3 MB\n", - "Initializing mimic4_note dataset from /Users/williampang/Desktop/PyHealth/test-resources/core/mimic4demo (dev mode: False)\n", - "Using provided cache_dir: /var/folders/zl/lm3qrxjd2jl17byd443y505h0000gn/T/tmpbrpwqzrq/efe373f9-a874-5fc5-96be-d6950c2af293/6e09f2d3-d3cc-5cd5-951c-e0e02a7aff3c\n", - "Memory usage After initializing mimic4_note: 521.3 MB\n", - "Memory usage After Note dataset initialization: 521.3 MB\n", - "Memory usage Completed MIMIC4Dataset init: 521.3 MB\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "/Users/williampang/Desktop/PyHealth/pyhealth/datasets/mimic4.py:121: UserWarning: Events from discharge table only have date timestamp (no specific time). This may affect temporal ordering of events.\n", - " warnings.warn(\n" - ] - } - ], + "outputs": [], "source": [ "dataset = MIMIC4Dataset(\n", " ehr_root=EHR_ROOT,\n", @@ -217,49 +184,10 @@ }, { "cell_type": "code", - "execution_count": 7, + "execution_count": null, "id": "d3b027ab-c814-49cd-8542-885d76b2401b", "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "Setting task ClinicalNotesICDLabsMIMIC4 for mimic4 base dataset...\n", - "Task cache paths: task_df=/var/folders/zl/lm3qrxjd2jl17byd443y505h0000gn/T/tmpbrpwqzrq/efe373f9-a874-5fc5-96be-d6950c2af293/tasks/ClinicalNotesICDLabsMIMIC4_493ab707-d120-581c-a795-319ffd5c468e/task_df.ld, samples=/var/folders/zl/lm3qrxjd2jl17byd443y505h0000gn/T/tmpbrpwqzrq/efe373f9-a874-5fc5-96be-d6950c2af293/tasks/ClinicalNotesICDLabsMIMIC4_493ab707-d120-581c-a795-319ffd5c468e/samples_cdbbc602-34e2-5a41-8643-4c76b08829f6.ld\n", - "Applying task transformations on data with 1 workers...\n", - "No cached event dataframe found. Creating: /var/folders/zl/lm3qrxjd2jl17byd443y505h0000gn/T/tmpbrpwqzrq/efe373f9-a874-5fc5-96be-d6950c2af293/global_event_df.parquet\n", - "Combining data from ehr dataset\n", - "Scanning table: diagnoses_icd from /Users/williampang/Desktop/PyHealth/test-resources/core/mimic4demo/hosp/diagnoses_icd.csv.gz\n", - "Joining with table: /Users/williampang/Desktop/PyHealth/test-resources/core/mimic4demo/hosp/admissions.csv.gz\n", - "Scanning table: procedures_icd from /Users/williampang/Desktop/PyHealth/test-resources/core/mimic4demo/hosp/procedures_icd.csv.gz\n", - "Joining with table: /Users/williampang/Desktop/PyHealth/test-resources/core/mimic4demo/hosp/admissions.csv.gz\n", - "Scanning table: labevents from /Users/williampang/Desktop/PyHealth/test-resources/core/mimic4demo/hosp/labevents.csv.gz\n", - "Joining with table: /Users/williampang/Desktop/PyHealth/test-resources/core/mimic4demo/hosp/d_labitems.csv.gz\n", - "Scanning table: patients from /Users/williampang/Desktop/PyHealth/test-resources/core/mimic4demo/hosp/patients.csv.gz\n", - "Scanning table: admissions from /Users/williampang/Desktop/PyHealth/test-resources/core/mimic4demo/hosp/admissions.csv.gz\n", - "Scanning table: icustays from /Users/williampang/Desktop/PyHealth/test-resources/core/mimic4demo/icu/icustays.csv.gz\n", - "Combining data from note dataset\n", - "Scanning table: discharge from /Users/williampang/Desktop/PyHealth/test-resources/core/mimic4demo/note/discharge.csv.gz\n", - "Scanning table: radiology from /Users/williampang/Desktop/PyHealth/test-resources/core/mimic4demo/note/radiology.csv.gz\n", - "Creating combined dataframe\n", - "Caching event dataframe to /var/folders/zl/lm3qrxjd2jl17byd443y505h0000gn/T/tmpbrpwqzrq/efe373f9-a874-5fc5-96be-d6950c2af293/global_event_df.parquet...\n", - "Detected Jupyter notebook environment, setting num_workers to 1\n", - "Single worker mode, processing sequentially\n", - "Worker 0 started processing 13 patients. (Polars threads: 12)\n", - "Worker 0 finished processing patients.\n", - "Fitting processors on the dataset...\n", - "Label mortality vocab: {0: 0, 1: 1}\n", - "Processing samples and saving to /var/folders/zl/lm3qrxjd2jl17byd443y505h0000gn/T/tmpbrpwqzrq/efe373f9-a874-5fc5-96be-d6950c2af293/tasks/ClinicalNotesICDLabsMIMIC4_493ab707-d120-581c-a795-319ffd5c468e/samples_cdbbc602-34e2-5a41-8643-4c76b08829f6.ld...\n", - "Applying processors on data with 1 workers...\n", - "Detected Jupyter notebook environment, setting num_workers to 1\n", - "Single worker mode, processing sequentially\n", - "Worker 0 started processing 13 samples. (0 to 13)\n", - "Worker 0 finished processing samples.\n", - "Cached processed samples to /var/folders/zl/lm3qrxjd2jl17byd443y505h0000gn/T/tmpbrpwqzrq/efe373f9-a874-5fc5-96be-d6950c2af293/tasks/ClinicalNotesICDLabsMIMIC4_493ab707-d120-581c-a795-319ffd5c468e/samples_cdbbc602-34e2-5a41-8643-4c76b08829f6.ld\n" - ] - } - ], + "outputs": [], "source": [ "%%capture\n", "task = ClinicalNotesICDLabsMIMIC4()\n", @@ -268,72 +196,10 @@ }, { "cell_type": "code", - "execution_count": 8, + "execution_count": null, "id": "6b70acb2-bdea-4a43-8b9a-7725c34fcfce", "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "\n", - "Patient ID: 10005\n", - "Mortality Flag: tensor([0.])\n", - "Found 13 unique patient IDs\n", - "\n", - "num_admissions: 1\n", - " hadm_id: 20008\n", - " admittime: 2151-07-15 08:30:00\n", - " dischtime: 2151-07-22 12:00:00\n", - "\n", - "discharge notes: 1\n", - " note_id: d10\n", - " hadm_id: 20008\n", - " charttime: 2151-07-22 12:00:00\n", - " storetime: 2151-07-22 13:00:00\n", - " text: Name: ___ Unit No: ___\n", - "\n", - "Admission Date: ___ Discharge Date: ___\n", - "\n", - "Date of Birth: ___ Sex: F\n", - "\n", - "Service: CARDIOLOGY\n", - "\n", - "Allergies:\n", - "no known drug allergies\n", - "\n", - "Attending: ___.\n", - "\n", - "Chief Complaint:\n", - "leg swelling and shortness of breath\n", - "\n", - "Major Surgical or Invasive Procedure:\n", - "none\n", - "\n", - "History of Present Illness:\n", - "___ year old female with history of congestive heart failure (EF 30%) presenting\n", - "with 1 week of progressive bilateral lower extremity edema and orthopnea.\n", - "W..(Limited to 500 Characters).\n", - "\n", - "radiology notes: 1\n", - " note_id: r10\n", - " hadm_id: 20008\n", - " charttime: 2151-07-15 14:00:00\n", - " storetime: 2151-07-15 15:00:00\n", - " text: CLINICAL HISTORY: Patient fell onto right ribs. The patient also on anticoagulants.\n", - "\n", - "CHEST AP:\n", - "\n", - "The heart and mediastinum are normal. The lung fields are clear. No effusion or pneumothorax is present.\n", - "\n", - "No rib fracture is seen on limited views.\n", - "\n", - "Vascular stent is seen within the lower SVC, position unchanged.\n", - "\n", - "IMPRESSION: No pneumothorax. No effusion. No rib fracture identified...(Limited to 500 Characters).\n" - ] - } - ], + "outputs": [], "source": [ "np.random.seed(SEED)\n", "random_patient_record = np.random.randint(0, len(samples)-1)\n", @@ -363,33 +229,10 @@ }, { "cell_type": "code", - "execution_count": 9, + "execution_count": null, "id": "16121916-e52e-4f66-8463-ff0f931cf416", "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "Setting task ClinicalNotesICDLabsMIMIC4 for mimic4 base dataset...\n", - "Task cache paths: task_df=/var/folders/zl/lm3qrxjd2jl17byd443y505h0000gn/T/tmpbrpwqzrq/efe373f9-a874-5fc5-96be-d6950c2af293/tasks/ClinicalNotesICDLabsMIMIC4_6c674c02-3635-50c0-bdde-3a45cb1e6f31/task_df.ld, samples=/var/folders/zl/lm3qrxjd2jl17byd443y505h0000gn/T/tmpbrpwqzrq/efe373f9-a874-5fc5-96be-d6950c2af293/tasks/ClinicalNotesICDLabsMIMIC4_6c674c02-3635-50c0-bdde-3a45cb1e6f31/samples_cdbbc602-34e2-5a41-8643-4c76b08829f6.ld\n", - "Applying task transformations on data with 1 workers...\n", - "Detected Jupyter notebook environment, setting num_workers to 1\n", - "Single worker mode, processing sequentially\n", - "Worker 0 started processing 13 patients. (Polars threads: 12)\n", - "Worker 0 finished processing patients.\n", - "Fitting processors on the dataset...\n", - "Label mortality vocab: {0: 0, 1: 1}\n", - "Processing samples and saving to /var/folders/zl/lm3qrxjd2jl17byd443y505h0000gn/T/tmpbrpwqzrq/efe373f9-a874-5fc5-96be-d6950c2af293/tasks/ClinicalNotesICDLabsMIMIC4_6c674c02-3635-50c0-bdde-3a45cb1e6f31/samples_cdbbc602-34e2-5a41-8643-4c76b08829f6.ld...\n", - "Applying processors on data with 1 workers...\n", - "Detected Jupyter notebook environment, setting num_workers to 1\n", - "Single worker mode, processing sequentially\n", - "Worker 0 started processing 13 samples. (0 to 13)\n", - "Worker 0 finished processing samples.\n", - "Cached processed samples to /var/folders/zl/lm3qrxjd2jl17byd443y505h0000gn/T/tmpbrpwqzrq/efe373f9-a874-5fc5-96be-d6950c2af293/tasks/ClinicalNotesICDLabsMIMIC4_6c674c02-3635-50c0-bdde-3a45cb1e6f31/samples_cdbbc602-34e2-5a41-8643-4c76b08829f6.ld\n" - ] - } - ], + "outputs": [], "source": [ "%%capture\n", "task = ClinicalNotesICDLabsMIMIC4(window_hours=12)\n", @@ -400,46 +243,10 @@ }, { "cell_type": "code", - "execution_count": 10, + "execution_count": null, "id": "42df85ab-2649-497b-92a2-415dc169798e", "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "\n", - "Patient ID: 10005\n", - "Mortality Flag: tensor([0.])\n", - "Window start: 2151-07-15 08:30:00\n", - "Window end: 2151-07-15 20:30:00\n", - "\n", - "num_admissions: 1\n", - " hadm_id: 20008\n", - " admittime: 2151-07-15 08:30:00\n", - " dischtime: 2151-07-22 12:00:00\n", - "\n", - "discharge notes: 0\n", - "\n", - "radiology notes: 1\n", - " note_id: r10\n", - " hadm_id: 20008\n", - " charttime: 2151-07-15 14:00:00\n", - " storetime: 2151-07-15 15:00:00\n", - " text: CLINICAL HISTORY: Patient fell onto right ribs. The patient also on anticoagulants.\n", - "\n", - "CHEST AP:\n", - "\n", - "The heart and mediastinum are normal. The lung fields are clear. No effusion or pneumothorax is present.\n", - "\n", - "No rib fracture is seen on limited views.\n", - "\n", - "Vascular stent is seen within the lower SVC, position unchanged.\n", - "\n", - "IMPRESSION: No pneumothorax. No effusion. No rib fracture identified...(Limited to 500 Characters).\n" - ] - } - ], + "outputs": [], "source": [ "print(f\"\\nPatient ID: {sample_patient_id}\")\n", "print(f\"Mortality Flag: {sample['mortality']}\")\n", @@ -466,20 +273,10 @@ }, { "cell_type": "code", - "execution_count": 11, + "execution_count": null, "id": "9113eab7-20f5-455b-8e99-570de8622ba6", "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "Setting task ClinicalNotesICDLabsMIMIC4 for mimic4 base dataset...\n", - "Task cache paths: task_df=/var/folders/zl/lm3qrxjd2jl17byd443y505h0000gn/T/tmpbrpwqzrq/efe373f9-a874-5fc5-96be-d6950c2af293/tasks/ClinicalNotesICDLabsMIMIC4_493ab707-d120-581c-a795-319ffd5c468e/task_df.ld, samples=/var/folders/zl/lm3qrxjd2jl17byd443y505h0000gn/T/tmpbrpwqzrq/efe373f9-a874-5fc5-96be-d6950c2af293/tasks/ClinicalNotesICDLabsMIMIC4_493ab707-d120-581c-a795-319ffd5c468e/samples_cdbbc602-34e2-5a41-8643-4c76b08829f6.ld\n", - "Found cached processed samples at /var/folders/zl/lm3qrxjd2jl17byd443y505h0000gn/T/tmpbrpwqzrq/efe373f9-a874-5fc5-96be-d6950c2af293/tasks/ClinicalNotesICDLabsMIMIC4_493ab707-d120-581c-a795-319ffd5c468e/samples_cdbbc602-34e2-5a41-8643-4c76b08829f6.ld, skipping processing.\n" - ] - } - ], + "outputs": [], "source": [ "%%capture\n", "task = ClinicalNotesICDLabsMIMIC4()\n", @@ -493,33 +290,10 @@ }, { "cell_type": "code", - "execution_count": 12, + "execution_count": null, "id": "23399090-175d-4492-8657-4a2c51293992", "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "[{'patient_id': '10005',\n", - " 'discharge_note_times': (['chief complaint: leg swelling and shortness of breath'],\n", - " [171.5]),\n", - " 'radiology_note_times': (['impression: No pneumothorax. No effusion. No rib fracture identified.'],\n", - " [5.5]),\n", - " 'icd_codes': ([0.0],\n", - " [['25001', '5849', '4019', '25011', '5A1D70Z', '3991']]),\n", - " 'labs': ([1.5], [[134.0, 5.8, 96.0, 14.0, 380.0, 0.0, 0.0, 20.0, 0.0, 0.0]]),\n", - " 'labs_mask': ([1.5],\n", - " [[True, True, True, True, True, False, False, True, False, False]]),\n", - " 'mortality': 0,\n", - " 'window_start': datetime.datetime(2151, 7, 15, 8, 30),\n", - " 'window_end': datetime.datetime(2151, 7, 22, 12, 0)}]" - ] - }, - "execution_count": 12, - "metadata": {}, - "output_type": "execute_result" - } - ], + "outputs": [], "source": [ "sample_task_output" ] @@ -542,7 +316,7 @@ }, { "cell_type": "code", - "execution_count": 13, + "execution_count": null, "id": "57208cc0-94af-456d-9078-12acaf556df7", "metadata": {}, "outputs": [],