SQL: Billed Diagnosis Review by 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 billed diagnoses for active patients between the two dates you specify.

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

Caveats

  • ICD-10 codes starting with Z are excluded.
  • 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 is not null and dxcode1 <> '' and dxcode1 not like 'Z%'
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%'
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%'
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%'
) 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%'
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%'
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%'
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%'
) d on register.patno = d.patno
where status_pat = 'ACTIVE' and dos is not null