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 a Depression 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 Depression as a diagnosis in Dx 2-Dx 4.
- Encounter noted which you coded Depression in Dx 1.
- Last Depression Rx was written
A sample image of this SQL report run in the Database Viewer is shown below:
Report Usage Ideas
- Run the Depression 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 Depression 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_depression, last_visit, cast(mdm_plan as char(30000)) 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 'F3%' group by patno) e on e.patno = r.patno left outer join (select patno, max(date1) as last_well_depression from physical where (dxcd2 like 'F3%' or dxcd3 like 'F3%' or dxcd4 like 'F3%') 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_depression, 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 'F3%' group by patno) e on e.patno = r.patno left outer join (select patno, max(date1) as last_well_depression from physical where (dxcd2 like 'F3%' or dxcd3 like 'F3%' or dxcd4 like 'F3%') 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 > 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