From 923be0549c117e57338a2b258f361c2fdf4dc17c Mon Sep 17 00:00:00 2001 From: Taksh Date: Sun, 12 Apr 2026 12:20:58 +0530 Subject: [PATCH] Fix height.sql COALESCE using h1 for both args instead of h1/h2 The FULL OUTER JOIN merges ht_cm (h1) and ht_in (h2), but the COALESCE for subject_id, stay_id, and charttime uses h1 as both arguments. When a patient has height charted only in inches (h2 row with no h1 match), all three columns are NULL, silently dropping the record. The height column on the next line already correctly falls back to h2. Fixed in all three dialect files (BigQuery, PostgreSQL, DuckDB). Co-Authored-By: Claude Opus 4.6 (1M context) --- mimic-iv/concepts/measurement/height.sql | 6 +++--- mimic-iv/concepts_duckdb/measurement/height.sql | 6 +++--- mimic-iv/concepts_postgres/measurement/height.sql | 6 +++--- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/mimic-iv/concepts/measurement/height.sql b/mimic-iv/concepts/measurement/height.sql index 2f4e4673d..85a00e4f7 100644 --- a/mimic-iv/concepts/measurement/height.sql +++ b/mimic-iv/concepts/measurement/height.sql @@ -25,9 +25,9 @@ WITH ht_in AS ( -- merge cm/height, only take 1 value per charted row , ht_stg0 AS ( SELECT - COALESCE(h1.subject_id, h1.subject_id) AS subject_id - , COALESCE(h1.stay_id, h1.stay_id) AS stay_id - , COALESCE(h1.charttime, h1.charttime) AS charttime + COALESCE(h1.subject_id, h2.subject_id) AS subject_id + , COALESCE(h1.stay_id, h2.stay_id) AS stay_id + , COALESCE(h1.charttime, h2.charttime) AS charttime , COALESCE(h1.height, h2.height) AS height FROM ht_cm h1 FULL OUTER JOIN ht_in h2 diff --git a/mimic-iv/concepts_duckdb/measurement/height.sql b/mimic-iv/concepts_duckdb/measurement/height.sql index 3afa74234..59e014406 100644 --- a/mimic-iv/concepts_duckdb/measurement/height.sql +++ b/mimic-iv/concepts_duckdb/measurement/height.sql @@ -21,9 +21,9 @@ WITH ht_in AS ( NOT c.valuenum IS NULL AND c.itemid = 226730 ), ht_stg0 AS ( SELECT - COALESCE(h1.subject_id, h1.subject_id) AS subject_id, - COALESCE(h1.stay_id, h1.stay_id) AS stay_id, - COALESCE(h1.charttime, h1.charttime) AS charttime, + COALESCE(h1.subject_id, h2.subject_id) AS subject_id, + COALESCE(h1.stay_id, h2.stay_id) AS stay_id, + COALESCE(h1.charttime, h2.charttime) AS charttime, COALESCE(h1.height, h2.height) AS height FROM ht_cm AS h1 FULL OUTER JOIN ht_in AS h2 diff --git a/mimic-iv/concepts_postgres/measurement/height.sql b/mimic-iv/concepts_postgres/measurement/height.sql index ef1d5ee16..b62756215 100644 --- a/mimic-iv/concepts_postgres/measurement/height.sql +++ b/mimic-iv/concepts_postgres/measurement/height.sql @@ -22,9 +22,9 @@ WITH ht_in AS ( NOT c.valuenum IS NULL AND /* Height cm */ c.itemid = 226730 ), ht_stg0 AS ( SELECT - COALESCE(h1.subject_id, h1.subject_id) AS subject_id, - COALESCE(h1.stay_id, h1.stay_id) AS stay_id, - COALESCE(h1.charttime, h1.charttime) AS charttime, + COALESCE(h1.subject_id, h2.subject_id) AS subject_id, + COALESCE(h1.stay_id, h2.stay_id) AS stay_id, + COALESCE(h1.charttime, h2.charttime) AS charttime, COALESCE(h1.height, h2.height) AS height FROM ht_cm AS h1 FULL OUTER JOIN ht_in AS h2