SQL: Instances of Sick and Well on Same Day for Period

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 indicates instances of when a well visit (9938x, 9939x) was billed on the same day as a sick visit (99201-5, 99212-5). It also indicates the patient and what rendering provider.

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

Caveats

This SQL takes a while to run the report. Do not run for periods exceeding one or two months. For an extensive date range "Not Responding" may appear in the window while the data is gathered.

SQL Code: Firebird

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

select at1.patno, at1.invoiceno,staffname, at2.cptcode as sick, at3.cptcode as well from
(select distinct patno, invoiceno, rend_addr_id from archive_transactions where date1 between :start_date and :end_Date) at1
 inner join (select patno, invoiceno, date1, cptcode from archive_transactions where cptcode between '99201' and '99215' and cptcode <> '99211' and date1 between :start_date and :end_date) at2 on at2.invoiceno = at1.invoiceno 
inner join (select patno, invoiceno, date1, cptcode from archive_transactions where cptcode between '99381' and '99395' and date1 between :start_date and :end_date) at3 on at3.invoiceno = at1.invoiceno
inner join staff1 on staff1.staffid = at1.rend_addr_id


SQL Code: MySQL

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

select at1.patno, at1.invoiceno,staffname, at2.cptcode as sick, at3.cptcode as well from
(select distinct patno, invoiceno, rend_addr_id from archive_transactions where date1 between :start_date and :end_Date) at1
 inner join (select patno, invoiceno, date1, cptcode from archive_transactions where cptcode between '99201' and '99215' and cptcode <> '99211' and date1 between :start_date and :end_date) at2 on at2.invoiceno = at1.invoiceno 
inner join (select patno, invoiceno, date1, cptcode from archive_transactions where cptcode between '99381' and '99395' and date1 between :start_date and :end_date) at3 on at3.invoiceno = at1.invoiceno
inner join staff1 on staff1.staffid = at1.rend_addr_id