Bug in query 1203

For complex topics that regular users would not be interested in. For power users and database administrators.
Post Reply
Floss
Posts: 6
Joined: Fri Sep 22, 2023 7:39 am

Bug in query 1203

Post by Floss » Fri Mar 15, 2024 4:14 pm

In query 1203 Count of new patients, total patients, and total patient visits in date range. you can potentially miss new patients.

The new patient part boils down to :
SET @StartDate=curdate() - INTERVAL 1 MONTH, @EndDate=curdate();
SET @ignoreCodes='D9986,D9987';

/*New patients*/
SELECT 'NP' AS 'CountType',pls.ProcDate,pls.PatNum, pls.ProvNum
FROM procedurelog pls
INNER JOIN procedurecode pc ON pc.CodeNum=pls.CodeNum
AND pc.ProcCode NOT IN ('D9986','D9987')
WHERE pls.ProcStatus=2 #Complete
GROUP BY pls.PatNum
HAVING pls.ProcDate=MIN(pls.ProcDate)
AND pls.ProcDate BETWEEN @StartDate AND @EndDate
Instead it should be:
SET @StartDate=curdate() - INTERVAL 1 MONTH, @EndDate=curdate();
SET @ignoreCodes='D9986,D9987';

/*New patients*/
SELECT 'NP' AS 'CountType',pl.ProcDate,pl.PatNum, pl.ProvNum
FROM procedurelog pl
INNER JOIN procedurecode pc ON pc.CodeNum=pl.CodeNum
AND pc.ProcCode NOT IN (@ignoreCodes)
WHERE pl.ProcStatus=2 #Complete
GROUP BY pl.PatNum
HAVING MIN(pl.ProcDate) BETWEEN @StartDate AND @EndDate
I don't entirely understand why there's a difference in results. I just found it when comparing against query 1645 New and Lost patient report.

felixr
Posts: 1
Joined: Tue Mar 19, 2024 1:09 pm

Re: Bug in query 1203

Post by felixr » Tue Mar 19, 2024 1:15 pm

The Query Team is working on fixing the query, but the suggested solution won't work. We need to rewrite the new patient section to properly retrieve the patients, dates, and providers.

Post Reply