We are currently updating the OP Help Center content for the release of OP 14.19 or OP 19. OP 19 is a member of the certified OP 14 family of products (official version is 14.19.1), which you may see in your software (such as in Help > About) and in the Help Center tabs labeled 14.19. You may also notice that the version number in content and videos may not match the version of your software, and some procedural content may not match the workflow in your software. We appreciate your patience and understanding as we make these enhancements.

SQL: BMI and ZCode for All Active Patients


This report shows all active patients who have ever had a BMI computed. It lists the most recent date of BMI computation, age at computation, BMI, BMI percentile (for under 18 years old), and appropriate ICD-10 Z code for that BMI.

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


  • Age is the patient’s age when the BMI was last computed, not the current age.
  • Patients who have never had a BMI computed do not appear in the report.


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

select patno, birthdat, date1, datediff(month,birthdat,date1)/12 as age, bmi, bmi_percent, 
case when  datediff(month,birthdat,date1)/12 < 18 then 
(case when bmi_percent <5 then 'Z68.51' when bmi_percent <85 then 'Z68.52' when bmi_percent <95 then
'Z68.53' else 'Z68.54' end) else (case when bmi<40  then ( 'Z68.' ||  substring(bmi from 1 for 2)) when bmi <45 then 'Z68.41' when bmi <50 then
'Z68.42' when bmi <60 then 'Z68.43' when bmi <70 then 'Z68.44' else 'Z68.45' end) end as zcode from
select birthdat, patno, physical_chart.date1, physical_chart.bmi, physical_chart.bmi_percent  from register
inner join 
( select patno, max(date1) as most_recent from
physical_chart where bmi <>0 group by patno ) p
on p.patno = register.patno 
inner join physical_chart on register.patno = physical_chart.patno and p.most_recent= physical_chart.date1
where patno >=101 and status_pat = 'ACTIVE' and lname <> 'TESTPATIENT'
and bmi >0