-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Claude/investigate creatinine extraction 019 sv5xzgi meg wp3qdb lh r5 m #1950
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
kontramind
wants to merge
19
commits into
MIT-LCP:main
from
kontramind:claude/investigate-creatinine-extraction-019Sv5xzgiMegWP3qdbLhR5M
Closed
Claude/investigate creatinine extraction 019 sv5xzgi meg wp3qdb lh r5 m #1950
kontramind
wants to merge
19
commits into
MIT-LCP:main
from
kontramind:claude/investigate-creatinine-extraction-019Sv5xzgiMegWP3qdbLhR5M
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- Calculates patient age at ICU admission - Handles HIPAA de-identification for patients >89 years - Unit of analysis: ICU stays (all stays, no filters) - Includes comprehensive documentation and usage examples
- Creates icu_age table for better reusability and performance - Follows MIMIC-IV DuckDB pattern (CREATE TABLE vs SELECT query) - Added comprehensive usage examples for joins with other tables - Added diagnostic queries for data exploration - Included VIEW alternative for users who prefer dynamic queries
- Calculates binary readmission flag at ICU stay level - Definition follows Pishgar et al. (2022) BMC Med Inform Decis Mak - Uses LEAD window function to identify next ICU admission - Includes days_to_next_icu for survival analysis - Handles last ICU stay per patient (no readmission possible) - Comprehensive examples for joining with icu_age table - Diagnostic queries for quality metrics and analysis
- Added is_readmission_30d (backward-looking): identifies if current stay is a readmission - Kept readmission_30d (forward-looking): predicts if stay will lead to readmission - Added prev_icustay_id, prev_hadm_id, prev_icu_outtime for backward analysis - Added days_from_prev_icu for time since previous discharge - Added is_first_icu_stay flag - Comprehensive comments explaining both directions - Updated examples to demonstrate both flag types
- More explicit about forward-looking nature - Better contrast with is_readmission_30d (backward) - Clearer semantics: "leads to" vs "is" - Updated all examples and documentation
- Extracts first measurement of 8 vital signs per ICU stay - Vitals: HR, SBP, DBP, MAP, SpO2, RR, Temperature, Glucose - Uses UNION ALL approach for clean, maintainable code - Temperature: automatic Fahrenheit to Celsius conversion - Value range filters for data quality (commented in code) - ITEMID tracking for invasive vs non-invasive distinction - Includes timing metrics (minutes from ICU admission) - Comprehensive examples for joining with age/readmission tables - Diagnostic queries for data completeness and quality checks
- Focused version with only systolic and diastolic BP - Clear, configurable ITEMID lists (easy to edit) - Same structure: value, time, itemid, minutes - Comprehensive examples for joining with age/readmission - Diagnostic queries for invasive vs non-invasive rates - Much simpler than full vitals version
- Extracts first HR measurement per ICU stay (unit of analysis: icustay_id) - Configurable ITEMID list (222, 220045) with clear edit section - Includes value, timestamp, ITEMID tracking, and minutes from admission - Value range filter: 0-300 bpm (physiologically plausible) - Comprehensive diagnostic queries for data quality assessment - Follows same pattern as icu_first_bp_duckdb.sql for consistency
- Extracts first heart rhythm measurement per ICU stay (unit of analysis: icustay_id) - Configurable ITEMID list (212, 3354, 5119, 220048) with clear edit section - Includes value, timestamp, ITEMID tracking, and minutes from admission - Rhythm is categorical/text value (e.g., "Sinus Rhythm", "Atrial Fibrillation") - Comprehensive diagnostic queries including rhythm distribution and abnormal rhythm detection - Follows same pattern as icu_first_hr_duckdb.sql and icu_first_bp_duckdb.sql
- Extracts first respiratory rate measurement per ICU stay (unit of analysis: icustay_id) - Configurable ITEMID list (615, 224690) - "Total" respiratory rate only - "Total" includes both spontaneous and ventilator-assisted breaths - Includes value, timestamp, ITEMID tracking, and minutes from admission - Value range filter: 0-70 breaths/min (physiologically plausible) - Comprehensive diagnostic queries including bradypnea/tachypnea detection - Follows same pattern as icu_first_hr_duckdb.sql and icu_first_rhythm_duckdb.sql
…lc-01L8sYhd6z75BNa12PjrNjkL Claude/investigate mimic age calc 01 l8s yhd6z75 b na12 pjr njk l
- Extracts first creatinine measurement per ICU stay (unit of analysis: icustay_id) - Uses ITEMID 50912 from labevents table (laboratory values) - Allows 6-hour window before admission to capture baseline labs - Includes value, timestamp, ITEMID tracking, and minutes from admission - Value range filter: 0-150 mg/dL (physiologically plausible) - Clearly marked filter sections for easy adjustment - Comprehensive diagnostic queries including AKI detection thresholds - Follows same pattern as icu_first_hr_duckdb.sql and icu_first_resprate_duckdb.sql
- Extracts first potassium measurement per ICU stay (unit of analysis: icustay_id) - Uses BOTH ITEMIDs 50971 (chemistry) and 50822 (blood gas) for maximum data completeness - Allows 6-hour window before admission to capture baseline labs - Includes value, timestamp, ITEMID tracking, and minutes from admission - Value range filter: 0-30 mEq/L (physiologically plausible) - Clearly marked filter sections for easy adjustment - Comprehensive diagnostic queries including hypokalemia/hyperkalemia detection - Follows same pattern as icu_first_hr_duckdb.sql and icu_first_creatinine_duckdb.sql Key documented decisions: - Both chemistry (50971) and blood gas (50822) K+ sources included - "Earliest" means relative to each ICU stay's admission (not hospital admission) - PARTITION BY icustay_id ensures each ICU stay analyzed independently - Clinical rationale: blood gas K+ often available first in critical situations
Creates 4 separate tables for comprehensive lipid profiling: - icu_first_total_cholesterol: Total cholesterol (ITEMID 50907) - icu_first_hdl: HDL cholesterol (ITEMID 50904) - icu_first_ldl: LDL cholesterol (ITEMIDs 50905 calculated, 50906 measured) - icu_first_triglycerides: Triglycerides (ITEMID 51000) Common features across all tables: - Extracts first measurement per ICU stay (unit of analysis: icustay_id) - Allows 6-hour window before admission to capture baseline labs - Includes value, timestamp, ITEMID tracking, and minutes from admission - Clearly marked filter sections for easy adjustment - Comprehensive diagnostic queries with clinical categories - Each ICU stay analyzed independently (PARTITION BY icustay_id) - Follows same pattern as icu_first_creatinine_duckdb.sql and icu_first_potassium_duckdb.sql Value range filters (physiologically plausible, filters outliers): - Total cholesterol: 0-500 mg/dL - HDL: 0-150 mg/dL - LDL: 0-400 mg/dL - Triglycerides: 0-2000 mg/dL (allows severe hypertriglyceridemia) Key documented decisions: - LDL includes BOTH calculated (50905) and measured (50906) methods for completeness - "Earliest" means relative to each ICU stay's admission (not hospital admission) - Separate tables maintain consistent single-value pattern - NOT routine ICU labs - lower data completeness expected vs creatinine/potassium - Clinical context documented: cardiovascular risk, pancreatitis screening, etc. Clinical notes: - Lipid panels affected by fasting status, critical illness, medications - Triglycerides >400 mg/dL invalidates Friedewald equation for calculated LDL - Triglycerides >1000 mg/dL indicates pancreatitis risk
Major changes to all 4 lipid tables (Total Chol, HDL, LDL, Triglycerides): DECISION: Different approach for sparse labs vs routine labs - Routine labs (creatinine, BUN, potassium): Use ±6 hour window, "first" chronologically - Sparse labs (lipids): Use "closest within hospital admission" approach Rationale: - Lipid panels are NOT routine ICU labs (measured infrequently) - Often drawn days before ICU transfer (on floor/ED, not in ICU) - Critical illness affects lipids over days, not hours - A lipid panel from 2 days before ICU is still clinically relevant - Maximizes data completeness while maintaining clinical relevance Implementation changes: - Join on hadm_id (hospital admission level) instead of subject_id - Order by ABS(DATE_DIFF(...)) - closest by absolute time distance - Time window: ±7 days (vs ±6 hours for routine labs) - Time offset can be negative (before ICU) or positive (after ICU) - Calculate seconds_from_intime in CTE for efficiency Documentation updates: - Extensive header documentation explaining the different approach - Clear rationale for why lipids differ from routine labs - Updated diagnostic queries with broader time categories - Timing analysis shows distribution (e.g., "1-3 days before ICU") Files modified: - icu_first_total_cholesterol_duckdb.sql - icu_first_hdl_duckdb.sql - icu_first_ldl_duckdb.sql - icu_first_triglycerides_duckdb.sql This hybrid approach balances data completeness with clinical relevance.
Implements icu_first_bun_duckdb.sql following the routine lab pattern with refined time window approach: - Time window: intime - 6 hours to outtime (ICU stay bounded) - First value chronologically within window - ITEMID 51006 (Blood Urea Nitrogen) - Value range: 0-300 mg/dL - Prevents contamination from other ICU stays by using outtime as upper bound Includes comprehensive clinical documentation about BUN's role in kidney function assessment, AKI detection, and severity scoring (SAPS II).
Update both icu_first_creatinine_duckdb.sql and icu_first_potassium_duckdb.sql to use the refined time window approach: - Time window: intime - 6 hours to outtime (ICU stay bounded) - Prevents contamination from other ICU stays by using outtime as upper bound - Ensures measurements are from THIS specific ICU stay only - Added icu_outtime to output for reference - Enhanced documentation explaining ICU stay bounded approach This brings creatinine and potassium tables in line with the BUN table implementation for consistency across all routine lab extractions.
Updated icu_first_resprate_duckdb.sql to include both "Total" and spontaneous respiratory rate measurements: - Added ITEMID 618 (Respiratory Rate - CareVue) - Added ITEMID 220210 (Respiratory Rate - MetaVision) - Now includes 4 ITEMIDs total: 615, 618, 220210, 224690 This provides more comprehensive respiratory rate data by capturing both spontaneous-only and total (spontaneous + ventilator-assisted) measurements.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
No description provided.