SQL: Vaccine Count for Active Patients

About

This report shows all active patients and the number of vaccines they have had recorded in their chart.  Blank means 0. You can change the dropdown filter to show only blanks.

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

Caveats

  • Only active patients are included.
  • The vaccines shown are both vaccines given by your practice and legacy vaccines. 
  • A child might have a blank record if the patient has never received any vaccines (either newborn or total vaccine refuser), or if you simply don’t have a vaccine record for that patient recorded in OP yet.

Code

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

select register.patno, fname, lname, birthdat, t as total_vaccines from register
left outer join
(

select register.patno, t from register
left outer join (select patno, count(vacname) as t from vaccine1 group by patno) v on v.patno = register.patno
where status_pat = 'ACTIVE'
) u  on u.patno = register.patno
where status_pat = 'ACTIVE' and register.patno > 99