I would appreciate if anyone can give me the basic query to count the number of active patients in a certain time frame. I am looking for the number of patients that have been in within the last 18 months. If they have had 2 prophys or several visits in the past 18 months I would only want to count them once.
Thanks for any help!
Query for Active Patients
Re: Query for Active Patients
This query will count how many patients were seen in a given date range (just change it to be the last 18 months).
SELECT COUNT(DISTINCT PatNum) FROM procedurelog
WHERE ProcStatus=2 AND
ProcDate>='2012-01-01' AND
ProcDate<'2012-04-01'
If you want to check that their status is still active, then you'd need this:
SELECT COUNT(DISTINCT procedurelog.PatNum) FROM procedurelog
LEFT JOIN patient ON procedurelog.PatNum=patient.PatNum
WHERE ProcStatus=2 AND
ProcDate>='2012-01-01' AND
ProcDate<'2012-04-01' AND
PatStatus = 0
SELECT COUNT(DISTINCT PatNum) FROM procedurelog
WHERE ProcStatus=2 AND
ProcDate>='2012-01-01' AND
ProcDate<'2012-04-01'
If you want to check that their status is still active, then you'd need this:
SELECT COUNT(DISTINCT procedurelog.PatNum) FROM procedurelog
LEFT JOIN patient ON procedurelog.PatNum=patient.PatNum
WHERE ProcStatus=2 AND
ProcDate>='2012-01-01' AND
ProcDate<'2012-04-01' AND
PatStatus = 0