Formatting code for IntakesWithPrimaryDxProviderOffice


show source only

======Intakes for Period with Primary Dx, Primary Provider, and Office Location======

Back to [[QueryDirectory Query Directory]]

//
I need a query that can be done by date range for charge with a CPT code of 90801 and will print out the ID, Name, Primary Dx, Primary Provider, and Office location (which is taken from Box 32 in the CSU that is attached to the charge).
//


%%(sql)
SELECT
a.id AS "ID",
(a.lastname+', '+a.firstname) AS "Name",
e.dxcode AS "Primary Dx",
f.provcode AS "Primary Provider",
g.shorthand AS "Office Location"

FROM
patients a
JOIN journal b ON a.ptnum = b.ptnum
JOIN jcharges c ON b.jnum = c.jnum
JOIN ptcsu d ON c.ptcsunum = d.ptcsunum
LEFT OUTER JOIN dx e ON d.dx1 = e.dxnum
LEFT OUTER JOIN providers f ON a.providernum = f.providernum
LEFT OUTER JOIN facilities g ON d.facilitynum = g.facilitynum
JOIN services h ON c.servicenum = h.servicenum
WHERE
h.cptcode = '90801'
AND b.trandate BETWEEN '2008-01-01' AND '2008-12-31'
Order BY "Name"
%%


----
CategoryQueries
Valid XHTML 1.0 Transitional :: Valid CSS :: Powered by WikkaWiki