We are currently updating the OP Help Center content for the release of OP 19, which is a member of the certified OP 14 family of products. OP 19’s official version is 14.19.1, which you may see in your software (such as in Help > About) and in the Help Center tabs labeled 14.19. You may also notice that the version number in content and videos may not match the version of your software, and some procedural content may not match the workflow in your software. We appreciate your patience and understanding as we make these enhancements.

SQL: Ages of Patients Seen between Dates

About

This report lists all patients seen between the two dates that you specify. It also lists their age on the date of service.

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

Caveats

  • "Seen” is defined as a sick note OR a well note on a given date of service.
  • “Age” is defined as their age at the time of the visit, not necessarily their current age.

Code

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

select distinct * from (
select patno, date1, birthdat,
floor(datediff(month, dateadd(day,-extract(day from birthdat)+1,birthdat), dateadd(day,-extract (day from birthdat)+1,date1))/12) as age_on_dos
 from physical 
inner join register on register.patno = physical.patno
where date1 between :start_date and :end_date
union

select patno, date1, birthdat,
floor(datediff(month, dateadd(day,-extract(day from birthdat)+1,birthdat), dateadd(day,-extract (day from birthdat)+1,date1))/12) as age_on_dos
from enc_note 
inner join register on register.patno = enc_note.patno
where  date1 between :start_date and :end_date
)