SQL: Specific Billed Diagnosis Review for Dates

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 instances of a specific billed diagnosis for active patients between two dates you specify. The diagnosis code is entered when you enter the the date range.

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

Caveats

  • The billed diagnosis code must match exactly what was entered. If the user enters J45.2, but the practice used J45.21 or J45.3, those instances will not appear. You can add % as a wildcard. For example, J45.% will show J45.2, J45.21 and J45.3
  • Only active patients are shown.
  • The diagnosis code could have been billed as the first, second, third, or fourth diagnosis.
  • A patient appears each time a diagnosis code was used.  If a patient was seen for diagnosis code J45.21 on 3/1, 4/1, and 5/1, the patient will appear three times in the listing.

SQL Code: Firebird

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

select register.patno, fname, lname, sex,  birthdat, dos, dx from register
inner join
(
select patno, date1 as dos, dxcode1 as dx from archive_Transactions where date1 between :start_date and :end_Date and dxcode1  like (:mydx)
union
select patno, date1 as dos, dxcode2 as dx from archive_Transactions where date1 between :start_date and :end_Date and  dxcode2  like (:mydx)
union
select patno, date1 as dos, dxcode3 as dx from archive_Transactions where date1 between :start_date and :end_Date and dxcode3  like (:mydx)
union
select patno, date1 as dos, dxcode4 as dx from archive_Transactions where date1 between :start_date and :end_Date and dxcode4  like (:mydx)
) d on register.patno = d.patno
where status_pat = 'ACTIVE' and dos is not null


SQL Code: MySQL

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

select register.patno, fname, lname, sex,  birthdat, dos, dx from register
inner join
(
select patno, date1 as dos, dxcode1 as dx from archive_Transactions where date1 between :start_date and :end_Date and dxcode1 is not null and dxcode1 <> '' and dxcode1 not like 'Z%' and dxcode1 like :mydx
union
select patno, date1 as dos, dxcode2 as dx from archive_Transactions where date1 between :start_date and :end_Date and dxcode2 is not null and dxcode2 <> '' and dxcode2 not like 'Z%' and dxcode2 like :mydx
union
select patno, date1 as dos, dxcode3 as dx from archive_Transactions where date1 between :start_date and :end_Date and dxcode3 is not null and dxcode3 <> '' and dxcode3 not like 'Z%' and dxcode3 like :mydx
union
select patno, date1 as dos, dxcode4 as dx from archive_Transactions where date1 between :start_date and :end_Date and dxcode4 is not null and dxcode4 <> '' and dxcode4 not like 'Z%' and dxcode4 like :mydx
) d on register.patno = d.patno
where status_pat = 'ACTIVE' and dos is not null