SQL: ADHD Recall

There are two versions of this SQL: Firebird and MySQL. The MySQL version only applies to clients who are have migrated to MySQL.. All other Practices should continue to use the Firebird version of this code. Click to expand and copy the code you need. If you are unsure which code to use, please check with your Practice Administrator.

About

This SQL will show all active patients of your practice for whom you have prescribed an ADHD medication in the past year and do not have a future follow up appointment on the schedule. The report will show:
  • Last well visit which you coded ADHD as a diagnosis in Dx 2-Dx 4.
  • Encounter noted which you coded ADHD in Dx 1.
  • Last ADHD Rx was written

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

Report Usage Ideas

  • Run the ADHD SQL and sort by PCP and print the list for each. The PCP can reach out telephonically to his or her parents on the list as a "virtual check-in" (G2012) and schedule the next appointment.
  • Rn the ADHD SQL and create a message using PMX (Patient Message Exchange) with a link to chadis.com asking the family to login and complete ADHD home forms.

SQL Code: Firebird

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

select r.patno, staffname, fname, lname, birthdat, last_well_adhd, last_visit, cast(mdm_plan as char(20000)) as last_plan,  last_rx, next_appt from register r
left outer join (select patno, max(date1) as last_visit from enc_note where dxcode like 'F90%' group by patno)
e on e.patno = r.patno  left outer join (select patno, max(date1) as last_well_adhd from physical where (dxcd2 like 'F90%' or dxcd3 like 'F90%' or dxcd4 like 'F90%')  group by patno) w on w.patno = r.patno inner join (select patno, max(date1) as last_Rx from medications  where
( lower(prescrib) like '%adderall%' or
lower(prescrib) like '%concerta%' or lower(prescrib) like '%methylphenidate%' or lower(prescrib) like
'%vyvanse%' or lower(prescrib) like '%ritalin%' or lower(prescrib) like '%guanfacine%' or lower(prescrib) like
'%dextroamphetamine%' or lower(prescrib) like '%clonidine%' or lower(prescrib) like '%intuniv%' or
lower(prescrib) like '%focalin%' or lower(prescrib) like '%procentra%' or lower(prescrib) like '%quillivant%' or lower(prescrib) like '%metadate%' or lower(prescrib) like '%tenex%' or lower(prescrib) like '%quillichew%' or lower(prescrib) like '%strattera%') and purpose not like '%reference%'
and date1 >= cast('today' as date) - 365  group by patno) m on m.patno = r.patno
left outer join (select patno, date1, mdm_plan from enc_note) e2 on e2.patno = r.patno and e2.date1 = e.last_visit
left outer join (select patno, min(appt_date) as next_appt from schedule where appt_date > cast('today' as date) and( visit_status is null or visit_status not in ('Cancelled','Canceled','No Show','No Show*')) group by patno) s on s.patno = r.patno
left outer join staff1 on staff1.staffid = r.addr_id
where status_pat = 'ACTIVE' and lname <> 'TESTPATIENT'
and next_appt is null


SQL Code: MySQL

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

select r.patno, staffname, fname, lname, birthdat, last_well_adhd, last_visit, mdm_plan as last_plan,  last_rx, next_appt from register r
left outer join (select patno, max(date1) as last_visit from enc_note where dxcode like 'F90%' group by patno)
 e on e.patno = r.patno  left outer join (select patno, max(date1) as last_well_adhd from physical where (dxcd2 like 'F90%' or dxcd3 like 'F90%' or dxcd4 like 'F90%')  group by patno) w on w.patno = r.patno
 inner join (select patno, max(date1) as last_Rx from medications  where
 ( lower(prescrib) like '%adderall%' or
 lower(prescrib) like '%concerta%' or lower(prescrib) like '%methylphenidate%' or lower(prescrib) like
 '%vyvanse%' or lower(prescrib) like '%ritalin%' or lower(prescrib) like '%guanfacine%' or lower(prescrib) like
 '%dextroamphetamine%' or lower(prescrib) like '%clonidine%' or lower(prescrib) like '%intuniv%' or
lower(prescrib) like '%focalin%' or lower(prescrib) like '%procentra%' or lower(prescrib) like '%quillivant%' or lower(prescrib) like '%metadate%' or lower(prescrib) like '%tenex%' or lower(prescrib)
 like '%quillichew%' or lower(prescrib) like '%strattera%') and purpose not like '%reference%'
  and datediff(curdate(),date1) <= 365  group by patno) m on m.patno = r.patno
left outer join (select patno, date1, mdm_plan from enc_note) e2 on e2.patno = r.patno and e2.date1 = e.last_visit
left outer join (select patno, min(appt_date) as next_appt from schedule where appt_date > curdate() and( visit_status is null or visit_status not in ('Cancelled','Canceled','No Show','No Show*')) group by patno) s on s.patno = r.patno
left outer join staff1 on staff1.staffid = r.addr_id
where status_pat = 'ACTIVE' and lname <> 'TESTPATIENT'
and next_appt is null