Hi all!,
I need some help with coming up with a query to show me patients that have been given a new medication and also rx sent that same day on the new med for a specific location.
So basically, i need a start date of a med that will match the rx date of that med. We need it to have last rx date and the start date as the same so that filters out refills and we can capture only new meds. Hopefully that makes sense. Any help would be appreciated. Thanks!
Does this help get your started?
select top 100
(select patientid from patientprofile where pid=med.pid) as [PatientId],
med.DESCRIPTION as [Description],
convert(varchar,med.STARTDATE,101) as [MedStart],
convert(varchar,pre.CLINICALDATE,101) as [RxDate]
from medicate med inner join
PRESCRIB pre on pre.MID=med.MID
where med.STARTDATE = pre.CLINICALDATE
Thanks! that helps for sure! how can i show prescriber name and patient name?
Try this and see if you get the results you want.
select top 100
(select patientid from patientprofile where pid=med.pid) as [PatientId],
med.DESCRIPTION as [Description],
convert(varchar,med.STARTDATE,101) as [MedStart],
convert(varchar,pre.CLINICALDATE,101) as [RxDate],
usr.LASTNAME + ' ' + usr.FIRSTNAME as [Prescriber],
pp.last + ' ' + pp.first as [PtName]
from medicate med inner join
PRESCRIB pre on pre.MID=med.MID inner join
usr on usr.pvid=pre.USRID inner join
patientprofile pp on pp.pid=med.PID
where med.STARTDATE = pre.CLINICALDATE