Hello,
I need some help with a SQL script that will show me a specific active medication prescribed by a certain provider. For example, I need a list of Dr. Casey's patients who are on Hydrocodone. I tried some scripts but it giving me back active and inactive medications, i just need active. Any help would be appreciated. Thanks!
On the medicate table, you want these filters.
CHANGE = 2 --Signed
AND stopdate > GETDATE() -- Not Removed
AND xid = 1000000000000000000 -- Active row for the chain
For prescrib (if you are using it), also add
CHANGE < 10 -- Not Filed in Error
If you still have trouble, just post what you have and we can help you out.
Thanks! That got me pretty far. But now I am trying to find patients who are on one of the opioid medications with a combination of a benzo. For example, i need to find patients who are on hydrocodone but also on xanax,
This is what i have so far. i think i am missing something....
SELECT
pp.First,
pp.Last,
pp.PatientId,
[DESCRIPTION],
[STARTDATE],
[STOPDATE],
df.[First],
df.[Last]
FROM MEDICATE m
LEFT join patientprofile pp ON pp.PId=m.PID
LEFT JOIN DoctorFacility df ON df.DoctorFacilityId = pp.DoctorId
WHERE m.CHANGE = 2 --Signed
AND m.STOPDATE > GETDATE() -- Not Removed
AND m.XID = 1000000000000000000
AND df.[Last] IN ('casey','russ','ryan','magonet','tav','gilbert')
AND (m.DESCRIPTION like '%hydrocodone%' or m.DESCRIPTION LIKE '%vicodin%' or m.DESCRIPTION LIKE '%morphine%' or m.DESCRIPTION LIKE '%Hydromorphone%'
or m.DESCRIPTION LIKE '%Dilaudid%' or m.DESCRIPTION LIKE '%Norco%' or m.DESCRIPTION LIKE '%oxycodone%' or m.DESCRIPTION LIKE '%percocet%'
or m.DESCRIPTION LIKE '%Fentanyl%' or m.DESCRIPTION LIKE '%Roxicodone%' or m.DESCRIPTION LIKE '%MS Contin%'
or m.DESCRIPTION LIKE '%xanax%')
I would never look up med classes by names, those change all the time. I use GPI classes, I believe there is a document floating around on CHUG somewhere that explains the coding system. Its a Medispan assigned code.
I would first lookup patients with the opioid, and then do a subquery for patients that are also on the benzo, like this,
SELECT
pp.First,
pp.Last,
pp.PatientId,
[DESCRIPTION],
[STARTDATE],
[STOPDATE],
df.[First],
df.[Last]
FROM MEDICATE m
LEFT join patientprofile pp ON pp.PId=m.PID
LEFT JOIN DoctorFacility df ON df.DoctorFacilityId = pp.DoctorId
WHERE m.CHANGE = 2 --Signed
AND m.STOPDATE > GETDATE() -- Not Removed
AND m.XID = 1000000000000000000
AND df.[Last] IN ('casey','russ','ryan','magonet','tav','gilbert')
AND (m.GPI like '6510%' OR m.GPI like '9340%' OR m.GPI like '6599%' OR m.GPI like '6520%') -- is on an opioid
AND m.pid IN --This is the subquery
(SELECT distinct pid
FROM MEDICATE
WHERE MEDICATE.CHANGE = 2 --Signed
AND MEDICATE.STOPDATE > GETDATE() -- Not Removed
AND MEDICATE.XID = 1000000000000000000
AND MEDICATE.GPI like '5710%'
)
Thank you so much!