SQL: Anxiety 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 anxiety 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 Anxiety as a diagnosis in dx 2, dx 3, or dx 4 (LAST_WELL_ANXIETY)
  • Last encounter note in which you coded anxiety in dx 1 (LAST_VISIT)
  • When the last anxiety Rx was written

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

Caveats

  • "Anxiety" is defined as any ICD-10 beginning with F4.
  • LAST_VISIT is the most recent visit the patient had where anxiety was the primary diagnosis.   It will not show more recent visits for other diagnoses (e.g. ankle sprain, viral URI).
  • NEXT_APPT is the next appointment the patient has on the schedule -- irrespective of whether the appointment is for a behavioral visit or for some other reason (e.g. flu shot, checkup.)
  • "Anxiety Rx" includes only meds prescribed by the office (not reference meds) commonly used for anxiety, such as fluoxetine, sertraline, fluvoxamine, and  trazodone.  The list can be amended by editing the SQL.

Report Usage Ideas

  • Run the Anxiety SQL and filter out patients that do not need a followup. Once you have the list, send a message using PMX (Patient Message Exchange) asking to call and schedule a telehealth appointment. Included in the message should be a link to your telehealth policy.
  • Run the Anxiety SQL and filter out patients that do not need a followup. Once you have the list, send a personalized portal message inquiring on how everyone is doing and inviting them to connect with you through telemedicine. Include links on how to prepare their device and how to sign in.

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_anxiety, 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 'F4%' group by patno) e on e.patno = r.patno left outer join (select patno, max(date1) as last_well_anxiety from physical where (dxcd2 like 'F4%' or dxcd3 like 'F4%' or dxcd4 like 'F4%')  group by patno) w
 on w.patno = r.patno inner join (select patno, max(date1) as last_Rx from medications  where
 ( lower(prescrib) like '%fluoxetine%' or  lower(prescrib) like '%paxil%' or lower(prescrib) like '%prozac%' or lower(prescrib) like
 '%zoloft%' or lower(prescrib) like '%sertraline%' or lower(prescrib) like '%fluvoxamine%' or lower(prescrib) like
 '%lexapro%' or lower(prescrib) like '%citalopram%' or lower(prescrib) like '%celexa%' or
lower(prescrib) like '%bupropion%' or lower(prescrib) like '%amitriptyline%' or lower(prescrib) like '%paroxetine%' or
lower(prescrib) like '%trazodone%' )  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_anxiety, 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 'F4%' group by patno) e on e.patno = r.patno left outer join (select patno, max(date1) as last_well_anxiety from physical where (dxcd2 like 'F4%' or dxcd3 like 'F4%' or dxcd4 like 'F4%')  group by patno) w on w.patno = r.patno inner join (select patno, max(date1) as last_Rx from medications  where
 ( lower(prescrib) like '%fluoxetine%' or  lower(prescrib) like '%paxil%' or lower(prescrib) like '%prozac%' or lower(prescrib) like
 '%zoloft%' or lower(prescrib) like '%sertraline%' or lower(prescrib) like '%fluvoxamine%' or lower(prescrib) like
 '%lexapro%' or lower(prescrib) like '%citalopram%' or lower(prescrib) like '%celexa%' or
lower(prescrib) like '%bupropion%' or lower(prescrib) like '%amitriptyline%' or lower(prescrib) like '%paroxetine%' or
lower(prescrib) like '%trazodone%' )  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