MIMIC-IV Patient Analysis: Comprehensive QA Generation
Goal
Systematically explore a patient's complete clinical record and submit diverse, high-quality QA pairs covering all meaningful clinical domains. Successful analyses generate 12–24 QA pairs spanning multiple dimensions of care.
Database Overview
The database has 27 tables with two prefixes:
hosp_ — hospital-level data (diagnoses, procedures, medications, admissions, labs)
icu_ — ICU-specific data (stays, inputs/outputs, procedures, events)
Three special metadata tables: table_comments, column_comments, column_documentation
Start with get_database_info to confirm available tables, then proceed without re-describing every table.
Key Column Names (Common Pitfalls)
Incorrect column names are the #1 cause of failed queries. Memorize these:
| Table |
Use This |
NOT This |
hosp_d_icd_diagnoses |
long_title |
description, title |
hosp_d_icd_procedures |
long_title |
description |
icu_icustays |
los |
length, length_of_stay |
hosp_omr |
subject_id, chartdate, result_name, result_value |
hadm_id, charttime, result_unit |
hosp_drgcodes |
description (own column, no JOIN needed) |
joining a separate dictionary |
hosp_d_hcpcs |
code (join key), short_description |
hcpcs_cd as join key |
hosp_hcpcsevents |
hcpcs_cd, short_description |
joining hosp_d_hcpcs on hcpcs_cd |
hosp_pharmacy |
medication, route, frequency |
drug |
hosp_emar |
medication, event_txt, charttime |
route, dose_val_rx |
hosp_prescriptions |
starttime, doses_per_24_hrs |
start_date, frequency |
hosp_poe |
order_type, order_subtype, ordertime |
order_name |
hosp_transfers |
careunit, intime, outtime, eventtype |
unit, transfer_type |
hosp_services |
transfertime, curr_service, prev_service |
starttime |
hosp_microbiologyevents |
spec_type_desc, org_name, ab_name, interpretation |
specimen_type, organism_name |
Critical: hosp_labevents does NOT exist. For outpatient measurements use hosp_omr. For ICU lab-like data use icu_d_items + icu_inputevents/icu_outputevents.
JOIN Patterns
Many tables store hadm_id but not subject_id. To filter by patient:
-- Pattern for tables with hadm_id only
SELECT ... FROM hosp_services s
JOIN hosp_admissions ha ON s.hadm_id = ha.hadm_id
WHERE ha.subject_id = <subject_id>
-- hosp_omr only has subject_id — query directly
SELECT chartdate, result_name, result_value
FROM hosp_omr WHERE subject_id = <subject_id>
ORDER BY chartdate
-- ICD diagnosis with readable title
SELECT d.hadm_id, d.seq_num, d.icd_code, d.icd_version, dt.long_title
FROM hosp_diagnoses_icd d
JOIN hosp_d_icd_diagnoses dt ON d.icd_code = dt.icd_code AND d.icd_version = dt.icd_version
WHERE d.subject_id = <subject_id>
-- DRG codes (description is already in hosp_drgcodes)
SELECT drg_type, drg_code, description, drg_severity, drg_mortality
FROM hosp_drgcodes WHERE subject_id = <subject_id>
-- ICU stays for a patient
SELECT ic.* FROM icu_icustays ic
JOIN hosp_admissions ha ON ic.hadm_id = ha.hadm_id
WHERE ha.subject_id = <subject_id>
When a query fails with "no such column", check column_comments for the correct name:
SELECT column_name, comment FROM column_comments WHERE table_name = '<table>'
Systematic Exploration Order
Work through domains in this order, querying and drafting QA pairs as you go:
Phase 1 — Foundation (always do first)
- Patient demographics:
hosp_patients → age, gender, date of death
- Admissions overview:
hosp_admissions → count, dates, admission types, insurance, discharge locations, in-hospital deaths
- Diagnoses:
hosp_diagnoses_icd JOIN hosp_d_icd_diagnoses → primary and comorbid conditions
- Procedures:
hosp_procedures_icd JOIN hosp_d_icd_procedures → surgical and clinical interventions
- Clinical services:
hosp_services → service transitions per admission
Phase 2 — Medications & Care (do for all patients)
- Prescriptions:
hosp_prescriptions → drugs, routes, dosing
- Pharmacy orders:
hosp_pharmacy → medication, route, frequency
- Transfers & care units:
hosp_transfers → intra-hospital movements, care unit progression
- DRG classifications:
hosp_drgcodes → billing severity and mortality risk
Phase 3 — Detailed Clinical Data (pursue based on what you find)
- ICU stays:
icu_icustays → if ICU admissions exist, explore icu_inputevents, icu_outputevents, icu_procedureevents using stay_id
- Microbiology:
hosp_microbiologyevents → infections, cultures, antibiotic sensitivities
- Outpatient measurements:
hosp_omr → weight, BMI, blood pressure trends over time
- eMAR:
hosp_emar → actual medication administrations (vs. just orders)
- HCPCS events:
hosp_hcpcsevents → billed procedures/services
Phase 4 — Synthesis
- Look for longitudinal trends: disease progression, care escalation, discharge destination changes
- Identify clinically interesting patterns: unusual comorbidity combinations, high-severity DRGs, recurrent infections
QA Generation Strategy
Coverage Targets
Generate QA pairs across these domains (not all may be relevant for every patient):
| Domain |
Example question angles |
| Primary diagnosis & chief complaint |
What condition drove this admission? What intervention was performed? |
| Comorbid conditions |
What chronic diseases complicate this patient's care? |
| Surgical/procedural interventions |
What procedures were performed? What was the clinical indication? |
| Medication regimen |
What drug classes were prescribed? Why? (anticoagulants, immunosuppressants, etc.) |
| Care trajectory & hospitalization pattern |
How many admissions? What was the progression over time? |
| Clinical service assignments |
Which services managed this patient and when did they transition? |
| ICU care |
What critical care interventions were used? How long was ICU stay? |
| Infectious complications |
What organisms were cultured? What was the treatment pattern? |
| DRG severity & billing |
What DRG classifications reflect the complexity of care? |
| Discharge & outcomes |
Where was the patient discharged? Did they die in-hospital or post-discharge? |
| Longitudinal trends |
How did weight, vitals, or disease burden change over time? |
| Transfer & care unit patterns |
How did the patient move through the hospital? |
QA Quality Standards
Write QA pairs that are:
- Self-contained: the question and answer together tell a complete clinical story
- Specific: include concrete values (dates, quantities, drug names, diagnoses), not vague generalities
- Clinically meaningful: focus on facts that matter for understanding the patient's care
- Diverse: each QA pair should cover a different clinical domain or aspect
Avoid:
- Redundant QA pairs covering the same information in slightly different words
- Questions answerable without querying the data (too obvious)
- Questions about columns or database structure (not clinical)
- Submitting before you've verified the data from a query
Submission Pattern
Submit QA pairs after each thematic cluster of queries — don't wait until the end. Aim to interleave: query → verify data → submit 1-2 QA pairs → continue exploring. This ensures you don't lose work if the session ends early.
A good target is 12–20+ QA pairs for a patient with multiple admissions, fewer (8–12) for simple single-admission cases.
Handling Query Failures
When a query fails:
- Read the error — it shows the available columns for that table
- Correct the column name immediately and retry
- If a table doesn't exist (e.g.,
hosp_labevents), use the alternative listed above
Do not spend more than 2 retries on any single query — move on if data isn't available.
1---2name: mimic-iv-patient-analysis-53description: Comprehensive strategy for analyzing individual patient records in MIMIC-IV EHR database and generating high-quality, diverse QA pairs. Use this skill whenever the task involves analyzing a specific patient's clinical data from MIMIC-IV (or similar EHR databases), querying across hospital and ICU tables, and submitting QA pairs that cover the patient's full clinical story — diagnoses, procedures, medications, care trajectory, and outcomes. Trigger when you see tasks like "Analyze patient <ID>", "Generate QA pairs for patient", or any patient-centric EHR exploration task.4---56# MIMIC-IV Patient Analysis: Comprehensive QA Generation78## Goal910Systematically explore a patient's complete clinical record and submit diverse, high-quality QA pairs covering all meaningful clinical domains. Successful analyses generate 12–24 QA pairs spanning multiple dimensions of care.1112## Database Overview1314The database has 27 tables with two prefixes:15- **`hosp_`** — hospital-level data (diagnoses, procedures, medications, admissions, labs)16- **`icu_`** — ICU-specific data (stays, inputs/outputs, procedures, events)1718Three special metadata tables: `table_comments`, `column_comments`, `column_documentation`1920Start with `get_database_info` to confirm available tables, then proceed without re-describing every table.2122## Key Column Names (Common Pitfalls)2324Incorrect column names are the #1 cause of failed queries. Memorize these:2526| Table | Use This | NOT This |27|---|---|---|28| `hosp_d_icd_diagnoses` | `long_title` | `description`, `title` |29| `hosp_d_icd_procedures` | `long_title` | `description` |30| `icu_icustays` | `los` | `length`, `length_of_stay` |31| `hosp_omr` | `subject_id`, `chartdate`, `result_name`, `result_value` | `hadm_id`, `charttime`, `result_unit` |32| `hosp_drgcodes` | `description` (own column, no JOIN needed) | joining a separate dictionary |33| `hosp_d_hcpcs` | `code` (join key), `short_description` | `hcpcs_cd` as join key |34| `hosp_hcpcsevents` | `hcpcs_cd`, `short_description` | joining `hosp_d_hcpcs` on `hcpcs_cd` |35| `hosp_pharmacy` | `medication`, `route`, `frequency` | `drug` |36| `hosp_emar` | `medication`, `event_txt`, `charttime` | `route`, `dose_val_rx` |37| `hosp_prescriptions` | `starttime`, `doses_per_24_hrs` | `start_date`, `frequency` |38| `hosp_poe` | `order_type`, `order_subtype`, `ordertime` | `order_name` |39| `hosp_transfers` | `careunit`, `intime`, `outtime`, `eventtype` | `unit`, `transfer_type` |40| `hosp_services` | `transfertime`, `curr_service`, `prev_service` | `starttime` |41| `hosp_microbiologyevents` | `spec_type_desc`, `org_name`, `ab_name`, `interpretation` | `specimen_type`, `organism_name` |4243**Critical**: `hosp_labevents` does NOT exist. For outpatient measurements use `hosp_omr`. For ICU lab-like data use `icu_d_items` + `icu_inputevents`/`icu_outputevents`.4445## JOIN Patterns4647Many tables store `hadm_id` but not `subject_id`. To filter by patient:48```sql49-- Pattern for tables with hadm_id only50SELECT ... FROM hosp_services s51JOIN hosp_admissions ha ON s.hadm_id = ha.hadm_id52WHERE ha.subject_id = <subject_id>5354-- hosp_omr only has subject_id — query directly55SELECT chartdate, result_name, result_value56FROM hosp_omr WHERE subject_id = <subject_id>57ORDER BY chartdate5859-- ICD diagnosis with readable title60SELECT d.hadm_id, d.seq_num, d.icd_code, d.icd_version, dt.long_title61FROM hosp_diagnoses_icd d62JOIN hosp_d_icd_diagnoses dt ON d.icd_code = dt.icd_code AND d.icd_version = dt.icd_version63WHERE d.subject_id = <subject_id>6465-- DRG codes (description is already in hosp_drgcodes)66SELECT drg_type, drg_code, description, drg_severity, drg_mortality67FROM hosp_drgcodes WHERE subject_id = <subject_id>6869-- ICU stays for a patient70SELECT ic.* FROM icu_icustays ic71JOIN hosp_admissions ha ON ic.hadm_id = ha.hadm_id72WHERE ha.subject_id = <subject_id>73```7475When a query fails with "no such column", check `column_comments` for the correct name:76```sql77SELECT column_name, comment FROM column_comments WHERE table_name = '<table>'78```7980## Systematic Exploration Order8182Work through domains in this order, querying and drafting QA pairs as you go:8384### Phase 1 — Foundation (always do first)851. **Patient demographics**: `hosp_patients` → age, gender, date of death862. **Admissions overview**: `hosp_admissions` → count, dates, admission types, insurance, discharge locations, in-hospital deaths873. **Diagnoses**: `hosp_diagnoses_icd` JOIN `hosp_d_icd_diagnoses` → primary and comorbid conditions884. **Procedures**: `hosp_procedures_icd` JOIN `hosp_d_icd_procedures` → surgical and clinical interventions895. **Clinical services**: `hosp_services` → service transitions per admission9091### Phase 2 — Medications & Care (do for all patients)926. **Prescriptions**: `hosp_prescriptions` → drugs, routes, dosing937. **Pharmacy orders**: `hosp_pharmacy` → `medication`, `route`, `frequency`948. **Transfers & care units**: `hosp_transfers` → intra-hospital movements, care unit progression959. **DRG classifications**: `hosp_drgcodes` → billing severity and mortality risk9697### Phase 3 — Detailed Clinical Data (pursue based on what you find)9810. **ICU stays**: `icu_icustays` → if ICU admissions exist, explore `icu_inputevents`, `icu_outputevents`, `icu_procedureevents` using `stay_id`9911. **Microbiology**: `hosp_microbiologyevents` → infections, cultures, antibiotic sensitivities10012. **Outpatient measurements**: `hosp_omr` → weight, BMI, blood pressure trends over time10113. **eMAR**: `hosp_emar` → actual medication administrations (vs. just orders)10214. **HCPCS events**: `hosp_hcpcsevents` → billed procedures/services103104### Phase 4 — Synthesis10515. Look for longitudinal trends: disease progression, care escalation, discharge destination changes10616. Identify clinically interesting patterns: unusual comorbidity combinations, high-severity DRGs, recurrent infections107108## QA Generation Strategy109110### Coverage Targets111Generate QA pairs across these domains (not all may be relevant for every patient):112113| Domain | Example question angles |114|---|---|115| Primary diagnosis & chief complaint | What condition drove this admission? What intervention was performed? |116| Comorbid conditions | What chronic diseases complicate this patient's care? |117| Surgical/procedural interventions | What procedures were performed? What was the clinical indication? |118| Medication regimen | What drug classes were prescribed? Why? (anticoagulants, immunosuppressants, etc.) |119| Care trajectory & hospitalization pattern | How many admissions? What was the progression over time? |120| Clinical service assignments | Which services managed this patient and when did they transition? |121| ICU care | What critical care interventions were used? How long was ICU stay? |122| Infectious complications | What organisms were cultured? What was the treatment pattern? |123| DRG severity & billing | What DRG classifications reflect the complexity of care? |124| Discharge & outcomes | Where was the patient discharged? Did they die in-hospital or post-discharge? |125| Longitudinal trends | How did weight, vitals, or disease burden change over time? |126| Transfer & care unit patterns | How did the patient move through the hospital? |127128### QA Quality Standards129130**Write QA pairs that are:**131- Self-contained: the question and answer together tell a complete clinical story132- Specific: include concrete values (dates, quantities, drug names, diagnoses), not vague generalities133- Clinically meaningful: focus on facts that matter for understanding the patient's care134- Diverse: each QA pair should cover a different clinical domain or aspect135136**Avoid:**137- Redundant QA pairs covering the same information in slightly different words138- Questions answerable without querying the data (too obvious)139- Questions about columns or database structure (not clinical)140- Submitting before you've verified the data from a query141142### Submission Pattern143144Submit QA pairs after each thematic cluster of queries — don't wait until the end. Aim to interleave: query → verify data → submit 1-2 QA pairs → continue exploring. This ensures you don't lose work if the session ends early.145146A good target is 12–20+ QA pairs for a patient with multiple admissions, fewer (8–12) for simple single-admission cases.147148## Handling Query Failures149150When a query fails:1511. Read the error — it shows the available columns for that table1522. Correct the column name immediately and retry1533. If a table doesn't exist (e.g., `hosp_labevents`), use the alternative listed above154155Do not spend more than 2 retries on any single query — move on if data isn't available.