A sample image of this SQL report run in the Database Viewer is shown below:
In this example, active patients between ages 3 and 4 are checked to see how many ASQs they’ve had by the time they are 1095 days old (1095/365 = third birthday).
- You can edit the age range by changing the line:
- age >=3 and age <4
- You can change the title(s) of the surveys by changing the line
- where (title like '%ASQ%' or title like '%Ages and Stages%')
- You can change the maximum age in days for the survey by changing the line
- where (admin_date-birthdat) <= 1095
To highlight and copy the code below to your clipboard, simply click the Copy button.
select * from ( select register.patno, birthdat, datediff(month, dateadd(day,-extract(day from birthdat)+1,birthdat), dateadd(day,-extract (day from birthdat)+1,cast('today' as date)) )/12 as age, status_pat, total_asq from register left outer join ( select patno, count(title) as total_asq from ( select register.patno, TITLE, admin_date, status_pat from register left outer join (select register.patno, admin_date, questionhead_id from quest_result_header inner join register on register.patno = quest_result_header.patno where (admin_date-birthdat) <= 1095 ) qrh on qrh.patno = register.patno left outer join (select questionhead_id, title from quest_Questionnaire_header ) qqh on qqh.questionhead_id = qrh.questionhead_id ) where (title like '%ASQ%' or title like '%Ages and Stages%') group by patno ) a on a.patno = register.patno ) where status_pat = 'ACTIVE' and age >=3 and age <4 order by patno