MIMIC-IV Patient Analysis
Perform a comprehensive, systematic analysis of a patient's complete clinical record from the MIMIC-IV database by querying the SQLite database directly and efficiently.
Database Structure
The database has 27 tables. Key tables and their primary columns:
Core patient tables:
hosp_patients — demographics: subject_id, gender, anchor_age, anchor_year, anchor_year_group, dod
hosp_admissions — hospital stays: subject_id, hadm_id, admittime, dischtime, deathtime, admission_type, admission_location, discharge_location, insurance, language, marital_status, race, edregtime, edouttime, hospital_expire_flag
Clinical data (per admission):
hosp_diagnoses_icd — ICD diagnoses: subject_id, hadm_id, seq_num, icd_code, icd_version
hosp_d_icd_diagnoses — diagnosis dictionary: icd_code, icd_version, long_title
hosp_procedures_icd — ICD procedures: subject_id, hadm_id, seq_num, chartdate, icd_code, icd_version
hosp_d_icd_procedures — procedure dictionary: icd_code, icd_version, long_title
hosp_drgcodes — DRG billing: subject_id, hadm_id, drg_type, drg_code, description, drg_severity, drg_mortality
hosp_services — clinical service: subject_id, hadm_id, transfertime, prev_service, curr_service
hosp_transfers — unit movements: subject_id, hadm_id, transfer_id, eventtype, careunit, intime, outtime
Medications:
hosp_prescriptions — prescribed drugs: subject_id, hadm_id, starttime, stoptime, drug, drug_type, dose_val_rx, dose_unit_rx, route
hosp_emar — administration record: subject_id, hadm_id, emar_id, charttime, medication, event_txt, scheduletime
hosp_pharmacy — pharmacy fills: subject_id, hadm_id, pharmacy_id, drug, starttime, stoptime
Diagnostics:
hosp_microbiologyevents — cultures: subject_id, hadm_id, charttime, spec_type_desc, test_name, org_name, interpretation, comments
hosp_omr — vitals/anthropometrics: subject_id, chartdate, seq_num, result_name, result_value
hosp_hcpcsevents — billing codes: subject_id, hadm_id, chartdate, hcpcs_cd, short_description
hosp_d_hcpcs — HCPCS dictionary: code, category, long_description, short_description
Orders:
hosp_poe — provider orders: subject_id, hadm_id, poe_id, ordertime, order_type, order_subtype, transaction_type, order_status
ICU tables (only present if patient had ICU stay):
icu_icustays — ICU episodes: subject_id, hadm_id, stay_id, first_careunit, last_careunit, intime, outtime, los
icu_inputevents, icu_outputevents, icu_procedureevents — ICU events by stay_id
Critical Column Name Pitfalls
Avoid these common errors that cause query failures:
| Table |
WRONG |
CORRECT |
hosp_transfers |
transfertime |
intime (sort by intime) |
hosp_poe |
order_time |
ordertime |
hosp_omr |
charttime |
chartdate |
hosp_hcpcsevents JOIN hosp_d_hcpcs |
ON h.hcpcs_cd = d.hcpcs_cd |
ON h.hcpcs_cd = d.code |
Analysis Workflow
Start with get_database_info to confirm table availability, then query directly — do not call describe_table before each query; use the column names listed above.
Step 1 — Patient demographics
SELECT * FROM hosp_patients WHERE subject_id = <patient_id>
Note: anchor_age is age in anchor_year (dates are shifted for privacy). If dod is not null, the patient died.
Step 2 — All hospital admissions
SELECT * FROM hosp_admissions WHERE subject_id = <patient_id> ORDER BY admittime
For each hadm_id, note: admission/discharge times, type, source, destination, insurance, hospital_expire_flag.
Step 3 — ICU stays
SELECT * FROM icu_icustays WHERE subject_id = <patient_id> ORDER BY intime
Empty result = no ICU. If ICU present, note care units and length of stay (los).
Step 4 — Diagnoses (with human-readable names)
SELECT d.icd_code, d.icd_version, d.long_title, diag.hadm_id, diag.seq_num
FROM hosp_diagnoses_icd diag
JOIN hosp_d_icd_diagnoses d ON diag.icd_code = d.icd_code AND diag.icd_version = d.icd_version
WHERE diag.subject_id = <patient_id>
ORDER BY diag.hadm_id, diag.seq_num
seq_num=1 is the primary diagnosis. Group by hadm_id to see diagnoses per admission.
Step 5 — Procedures
SELECT p.hadm_id, p.seq_num, p.chartdate, p.icd_code, proc.long_title
FROM hosp_procedures_icd p
JOIN hosp_d_icd_procedures proc ON p.icd_code = proc.icd_code AND p.icd_version = proc.icd_version
WHERE p.subject_id = <patient_id>
ORDER BY p.hadm_id, p.seq_num
Step 6 — Medications prescribed
SELECT hadm_id, drug, starttime, stoptime, dose_val_rx, dose_unit_rx, route
FROM hosp_prescriptions
WHERE subject_id = <patient_id>
ORDER BY hadm_id, starttime
Step 7 — Physical measurements (BMI, weight, height, BP)
SELECT chartdate, result_name, result_value
FROM hosp_omr
WHERE subject_id = <patient_id>
ORDER BY chartdate
Step 8 — Microbiology cultures
SELECT chartdate, spec_type_desc, test_name, org_name, interpretation, comments
FROM hosp_microbiologyevents
WHERE subject_id = <patient_id>
ORDER BY chartdate
org_name null with a comment like "< 10,000 CFU/mL" = negative culture.
Step 9 — Clinical service and transfers
-- Service
SELECT * FROM hosp_services WHERE subject_id = <patient_id> ORDER BY transfertime
-- Physical location movements
SELECT * FROM hosp_transfers WHERE hadm_id = <hadm_id> ORDER BY intime
Step 10 — DRG billing codes
SELECT * FROM hosp_drgcodes WHERE subject_id = <patient_id>
APR-DRG has severity (1-4) and mortality (1-4) scores.
Optional — Provider orders and eMAR
Query hosp_poe (by hadm_id, ORDER BY ordertime) to see what was ordered and when. Query hosp_emar (by hadm_id, ORDER BY charttime) to see which medications were actually administered vs "Not Given".
Synthesizing the Analysis
After gathering data, produce a structured summary covering:
- Demographics — age, sex, race, insurance, vital status (alive/deceased + date if known)
- Admission summary — number of admissions, dates, types, sources, discharge destinations
- ICU course — whether ICU was needed, which units, duration
- Primary diagnosis and DRG — main condition(s), billing classification, severity
- Comorbidities — significant secondary diagnoses across admissions
- Procedures — surgical and therapeutic interventions
- Medications — key drug classes, notable transitions (e.g., anticoagulation changes), route
- Diagnostics — culture results, physical measurements/trends
- Clinical trajectory — how the patient's condition evolved across admissions
- Key clinical insights — clinically meaningful patterns (e.g., discharge to rehab suggesting functional impairment, multiple laxatives suggesting immobility, sequential anticoagulants suggesting treatment adjustment)
End the analysis with FINISH: followed by the full summary.
Efficiency Tips
- Query all admissions first, then drill into individual
hadm_id values for detailed data
- For patients with multiple admissions, query diagnoses and medications across all
hadm_ids at once using subject_id
- If a query returns an error mentioning available columns, correct the column name immediately — do not call
describe_table; instead consult the column reference above
- Use LIMIT when exploring eMAR/POE (large tables); paginate with OFFSET if needed
- The
hosp_emar event_txt field distinguishes "Administered" from "Not Given" — this reveals medication compliance
1---2name: mimic-patient-analysis-23description: Comprehensive patient analysis using the MIMIC-IV clinical database. Use this skill whenever asked to analyze, summarize, or investigate a patient's medical history, hospital admissions, diagnoses, medications, procedures, or clinical course from a MIMIC-IV SQLite database. Triggers on prompts like "Analyze patient [ID]", "summarize patient history", "what happened to patient X", or any request to explore patient-level EHR data from MIMIC-IV tables.4---56# MIMIC-IV Patient Analysis78Perform a comprehensive, systematic analysis of a patient's complete clinical record from the MIMIC-IV database by querying the SQLite database directly and efficiently.910## Database Structure1112The database has 27 tables. Key tables and their primary columns:1314**Core patient tables:**15- `hosp_patients` — demographics: `subject_id, gender, anchor_age, anchor_year, anchor_year_group, dod`16- `hosp_admissions` — hospital stays: `subject_id, hadm_id, admittime, dischtime, deathtime, admission_type, admission_location, discharge_location, insurance, language, marital_status, race, edregtime, edouttime, hospital_expire_flag`1718**Clinical data (per admission):**19- `hosp_diagnoses_icd` — ICD diagnoses: `subject_id, hadm_id, seq_num, icd_code, icd_version`20- `hosp_d_icd_diagnoses` — diagnosis dictionary: `icd_code, icd_version, long_title`21- `hosp_procedures_icd` — ICD procedures: `subject_id, hadm_id, seq_num, chartdate, icd_code, icd_version`22- `hosp_d_icd_procedures` — procedure dictionary: `icd_code, icd_version, long_title`23- `hosp_drgcodes` — DRG billing: `subject_id, hadm_id, drg_type, drg_code, description, drg_severity, drg_mortality`24- `hosp_services` — clinical service: `subject_id, hadm_id, transfertime, prev_service, curr_service`25- `hosp_transfers` — unit movements: `subject_id, hadm_id, transfer_id, eventtype, careunit, intime, outtime`2627**Medications:**28- `hosp_prescriptions` — prescribed drugs: `subject_id, hadm_id, starttime, stoptime, drug, drug_type, dose_val_rx, dose_unit_rx, route`29- `hosp_emar` — administration record: `subject_id, hadm_id, emar_id, charttime, medication, event_txt, scheduletime`30- `hosp_pharmacy` — pharmacy fills: `subject_id, hadm_id, pharmacy_id, drug, starttime, stoptime`3132**Diagnostics:**33- `hosp_microbiologyevents` — cultures: `subject_id, hadm_id, charttime, spec_type_desc, test_name, org_name, interpretation, comments`34- `hosp_omr` — vitals/anthropometrics: `subject_id, chartdate, seq_num, result_name, result_value`35- `hosp_hcpcsevents` — billing codes: `subject_id, hadm_id, chartdate, hcpcs_cd, short_description`36- `hosp_d_hcpcs` — HCPCS dictionary: `code, category, long_description, short_description`3738**Orders:**39- `hosp_poe` — provider orders: `subject_id, hadm_id, poe_id, ordertime, order_type, order_subtype, transaction_type, order_status`4041**ICU tables (only present if patient had ICU stay):**42- `icu_icustays` — ICU episodes: `subject_id, hadm_id, stay_id, first_careunit, last_careunit, intime, outtime, los`43- `icu_inputevents`, `icu_outputevents`, `icu_procedureevents` — ICU events by `stay_id`4445## Critical Column Name Pitfalls4647Avoid these common errors that cause query failures:4849| Table | WRONG | CORRECT |50|-------|-------|---------|51| `hosp_transfers` | `transfertime` | `intime` (sort by `intime`) |52| `hosp_poe` | `order_time` | `ordertime` |53| `hosp_omr` | `charttime` | `chartdate` |54| `hosp_hcpcsevents` JOIN `hosp_d_hcpcs` | `ON h.hcpcs_cd = d.hcpcs_cd` | `ON h.hcpcs_cd = d.code` |5556## Analysis Workflow5758Start with `get_database_info` to confirm table availability, then query directly — **do not call `describe_table` before each query**; use the column names listed above.5960### Step 1 — Patient demographics61```sql62SELECT * FROM hosp_patients WHERE subject_id = <patient_id>63```64Note: `anchor_age` is age in `anchor_year` (dates are shifted for privacy). If `dod` is not null, the patient died.6566### Step 2 — All hospital admissions67```sql68SELECT * FROM hosp_admissions WHERE subject_id = <patient_id> ORDER BY admittime69```70For each `hadm_id`, note: admission/discharge times, type, source, destination, insurance, hospital_expire_flag.7172### Step 3 — ICU stays73```sql74SELECT * FROM icu_icustays WHERE subject_id = <patient_id> ORDER BY intime75```76Empty result = no ICU. If ICU present, note care units and length of stay (los).7778### Step 4 — Diagnoses (with human-readable names)79```sql80SELECT d.icd_code, d.icd_version, d.long_title, diag.hadm_id, diag.seq_num81FROM hosp_diagnoses_icd diag82JOIN hosp_d_icd_diagnoses d ON diag.icd_code = d.icd_code AND diag.icd_version = d.icd_version83WHERE diag.subject_id = <patient_id>84ORDER BY diag.hadm_id, diag.seq_num85```86seq_num=1 is the primary diagnosis. Group by hadm_id to see diagnoses per admission.8788### Step 5 — Procedures89```sql90SELECT p.hadm_id, p.seq_num, p.chartdate, p.icd_code, proc.long_title91FROM hosp_procedures_icd p92JOIN hosp_d_icd_procedures proc ON p.icd_code = proc.icd_code AND p.icd_version = proc.icd_version93WHERE p.subject_id = <patient_id>94ORDER BY p.hadm_id, p.seq_num95```9697### Step 6 — Medications prescribed98```sql99SELECT hadm_id, drug, starttime, stoptime, dose_val_rx, dose_unit_rx, route100FROM hosp_prescriptions101WHERE subject_id = <patient_id>102ORDER BY hadm_id, starttime103```104105### Step 7 — Physical measurements (BMI, weight, height, BP)106```sql107SELECT chartdate, result_name, result_value108FROM hosp_omr109WHERE subject_id = <patient_id>110ORDER BY chartdate111```112113### Step 8 — Microbiology cultures114```sql115SELECT chartdate, spec_type_desc, test_name, org_name, interpretation, comments116FROM hosp_microbiologyevents117WHERE subject_id = <patient_id>118ORDER BY chartdate119```120`org_name` null with a comment like "< 10,000 CFU/mL" = negative culture.121122### Step 9 — Clinical service and transfers123```sql124-- Service125SELECT * FROM hosp_services WHERE subject_id = <patient_id> ORDER BY transfertime126127-- Physical location movements128SELECT * FROM hosp_transfers WHERE hadm_id = <hadm_id> ORDER BY intime129```130131### Step 10 — DRG billing codes132```sql133SELECT * FROM hosp_drgcodes WHERE subject_id = <patient_id>134```135APR-DRG has severity (1-4) and mortality (1-4) scores.136137### Optional — Provider orders and eMAR138Query `hosp_poe` (by `hadm_id`, ORDER BY `ordertime`) to see what was ordered and when. Query `hosp_emar` (by `hadm_id`, ORDER BY `charttime`) to see which medications were actually administered vs "Not Given".139140## Synthesizing the Analysis141142After gathering data, produce a structured summary covering:1431441. **Demographics** — age, sex, race, insurance, vital status (alive/deceased + date if known)1452. **Admission summary** — number of admissions, dates, types, sources, discharge destinations1463. **ICU course** — whether ICU was needed, which units, duration1474. **Primary diagnosis and DRG** — main condition(s), billing classification, severity1485. **Comorbidities** — significant secondary diagnoses across admissions1496. **Procedures** — surgical and therapeutic interventions1507. **Medications** — key drug classes, notable transitions (e.g., anticoagulation changes), route1518. **Diagnostics** — culture results, physical measurements/trends1529. **Clinical trajectory** — how the patient's condition evolved across admissions15310. **Key clinical insights** — clinically meaningful patterns (e.g., discharge to rehab suggesting functional impairment, multiple laxatives suggesting immobility, sequential anticoagulants suggesting treatment adjustment)154155End the analysis with `FINISH:` followed by the full summary.156157## Efficiency Tips158159- Query all admissions first, then drill into individual `hadm_id` values for detailed data160- For patients with multiple admissions, query diagnoses and medications across all `hadm_id`s at once using `subject_id`161- If a query returns an error mentioning available columns, correct the column name immediately — do not call `describe_table`; instead consult the column reference above162- Use LIMIT when exploring eMAR/POE (large tables); paginate with OFFSET if needed163- The `hosp_emar` `event_txt` field distinguishes "Administered" from "Not Given" — this reveals medication compliance