SQL: Active Patients with F Category Diagnoses

About

This report shows all active patients with any "F" category diagnosis of Mental, Behavioral, and Neurodevelopmental disorders.

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

Caveats

None.

Code

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

select a.* , fname, lname from (
select patno, max(dx_date) as last_dx_date, cast(list(distinct dxcode, ', ') as char(2000)) as dxes from dx_attach where dx_date >= cast('today' as date)-(365.25*5) and attach_table in ('ENC_NOTE','PHYSICAL') and dxcode_Type = 'ICD10'
and dxcode like 'F%' and patno >99 group by patno)
a  inner join register on register.patno = a.patno
where status_pat = 'ACTIVE'