SQL: Meningitis ACWY Vaccine Completion Status

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 report shows all active patients ages 16 and up and lists the number of meningococcal ACWY vaccines they have had administered (either by the practice or legacy vaccines).

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

Caveats

  • This report only includes Men ACWY vaccines, not Men B vaccines.
  • Meningococcal vaccines include only the following vaccine CVX codes: 114, 136,32, 108, 147.
  • Only active patients are included.

SQL Code: Firebird

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

select * from 
(
select register.patno, number_mcv, birthdat,floor(datediff(month, dateadd(day,-extract(day from birthdat)+1,birthdat),  dateadd(day,-extract (day from birthdat)+1,cast('today' as date)) )/12) as age
from register
left outer join (select patno, coalesce(count(vacname),0) as number_mcv from vaccine1 where cvxcode in ('114','136','32','108','147') group by patno) v on v.patno = register.patno
where status_pat = 'ACTIVE' and register.patno >99
) 
where age>=16


SQL Code: MySQL

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

select * from 
(
select register.patno, number_mcv, birthdat,floor(timestampdiff(year,birthdat,curdate()))  as age
from register
left outer join (select patno, coalesce(count(vacname),0) as number_mcv from vaccine1 where cvxcode in ('114','136','32','108','147') group by patno) v on v.patno = register.patno
where status_pat = 'ACTIVE' and register.patno >99
) t1
where age>=16