SQL: Active Patients with Obesity

About

This SQL shows all active patients with BMI greater than the 95th percentile for age.

A sample image of this SQL report run in the Database Viewer is shown below:

Caveats

This will show you all active patients whose BMI is greater than 95%.

Notes:

  • The SQL only pulls patients whose status is ACTIVE.
  • It only pulls patients ages 2 and up, since younger children don't have a BMI defined.
  • It pulls patients whose BMI is GREATER than 95, not GREATER THAN OR EQUAL to 95.   
  • It looks at the patient’s most recent BMI.  So, if a child's BMI is currently under 95 even though the patient's previous three BMIs were over 95, the patient won't appear in the grid.

Code

To highlight and copy the code below to your clipboard, simply click the Copy button.

select p.* , pc.bmi_percent from
(
 (select patno, cast(max(date1) as date) as most_recent from physical_chart group by patno) p
left outer join physical_chart pc on pc.patno = p.patno and pc.date1 = p.most_recent
)
inner join register on register.patno = p.patno
where status_pat = 'ACTIVE' and bmi_percent > 95