Skip to content

Fix height.sql COALESCE using h1 for both args instead of h1/h2#1985

Open
Chessing234 wants to merge 1 commit intoMIT-LCP:mainfrom
Chessing234:fix/height-coalesce-copy-paste
Open

Fix height.sql COALESCE using h1 for both args instead of h1/h2#1985
Chessing234 wants to merge 1 commit intoMIT-LCP:mainfrom
Chessing234:fix/height-coalesce-copy-paste

Conversation

@Chessing234
Copy link
Copy Markdown

Summary

In height.sql, the ht_stg0 CTE merges height-in-cm (h1) and height-in-inches (h2) via a FULL OUTER JOIN. The COALESCE for subject_id, stay_id, and charttime uses h1 as both arguments:

COALESCE(h1.subject_id, h1.subject_id) AS subject_id  -- should be h2
COALESCE(h1.stay_id, h1.stay_id) AS stay_id            -- should be h2
COALESCE(h1.charttime, h1.charttime) AS charttime      -- should be h2
COALESCE(h1.height, h2.height) AS height               -- this one is correct

When a patient has height charted only in inches (itemid 226707, an h2 row with no matching h1 row), the FULL OUTER JOIN produces a row where all h1.* columns are NULL. COALESCE(NULL, NULL) yields NULL for subject_id, stay_id, and charttime, making the record unjoinable to any patient — silently dropping all inch-only height measurements.

Fix: Change the second argument from h1 to h2 in all three COALESCE calls, matching the pattern already used for height on the next line. Applied to all three dialect files (BigQuery, PostgreSQL, DuckDB).

Test plan

  • Verified line 31 already correctly uses h2.height as fallback
  • Verified the same copy-paste error exists in all three dialect files
  • Query should now return non-NULL subject_id/stay_id for inch-only height records

🤖 Generated with Claude Code

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) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant