SQL: Fluoride Varnish Applied

About

This SQL shows all kids that are 1 - 3 years old who had a checkup on the date they were seen in a selected date range.  If they had a fluoride done (LOINC code "XFLUOR") sometime in that period (not necessarily the same day as the checkup), then it puts the date in "FLUORIDE DATE" column.

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

Caveats

This requires that you are documenting fluoride application as a Diagnostic test using the LOINC code XFLUOR.

Code

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

select physical.patno, date1, fluoride_date from physical
inner join register on register.patno = physical.patno
 
left outer join 
(select patno, loinc_code, date1 as fluoride_date from diag_test_order where loinc_code = 'XFLUOR' and date1  between :start_date and :end_date) d on d.patno = physical.patno
where date1 between :start_date and :end_date
and (date1-birthdat) >=365 and (date1-birthdat)<1460
order by patno