Need Query Help - Trying to bypass Planned Appointments
Posted: Tue Mar 11, 2014 5:14 am
Like many other users, I feel PlannedAppointments module is extremely unfriendly, time-consuming, very difficult to use, and in general useless.
So I am trying to bypass it, using a query to return patients with unscheduled treatment that were tx planned in a time range.
Unfortunately, I am running into the same problem as in TxFinder - if a patient has a future recall appointment, they do not show up in the list for unscheduled tx.
I thought the query below would exclude appts for recall procedures, but we have the same problem.
Shouldn't the highlighted line exclude recall appts?
/*164 Returns all treatment planned procedures for active patients without a scheduled OR planned apt, who were last seen in a given date range
with phone numbers, useful for those transitioning to planned appointments
(this differs FROM #56 largely in that it is date limited and lists out the treatment)*/
DROP TABLE IF EXISTS tmp1;
DROP TABLE IF EXISTS tmp2;
SET @FROMDate= DATE_SUB(CurDate(), INTERVAL 7 Day) ,@ToDate= DATE(CurDate()) ;
CREATE TABLE tmp1 AS SELECT patient.PatNum, CONCAT(LName, ', ',FName, ' ', MiddleI) AS PatName, HmPhone, WkPhone,
WirelessPhone AS Wireless, ProcFee, pc.ProcCode FROM patient
INNER JOIN procedurelog pl ON patient.PatNum=pl.PatNum
INNER JOIN procedurecode pc ON pl.CodeNum= pc.CodeNum AND ProcStatus=1
LEFT JOIN appointment ap ON patient.PatNum=ap.PatNum AND (ap.AptStatus=1 OR ap.AptStatus=6 )
WHERE ap.AptNum IS NULL AND patient.PatStatus=0 AND pc.ProcCode NOT IN('D0120', 'D0150','D1120', 'D1110','D1203','D1204', 'D1206', 'D0272','D0274','D0210', 'D0220', 'D0230', 'D4910', 'D4910.3') AND ProcFee NOT IN ('0');
CREATE TABLE tmp2 AS SELECT p.PatNum, DATE_FORMAT(MAX(ProcDate),'%m/%d/%Y') AS 'LastVisit', MAX(ProcDate) AS 'DateLast'
FROM patient p
INNER JOIN procedurelog pl ON pl.PatNum=p.PatNum
WHERE pl.ProcStatus=2 AND p.PatStatus=0
GROUP BY pl.PatNum;
SELECT PatName,Left(HmPhone,15) AS HmPhone,Left(WkPhone,21) As WKPhone,Left(Wireless,15) AS Wireless, ProcFee AS '$Fee', LastVisit
FROM tmp1 INNER JOIN tmp2 ON tmp1.PatNum=tmp2.PatNum
WHERE DateLast BETWEEN @FROMDate AND @ToDate
ORDER BY PatName;
DROP TABLE IF EXISTS tmp1;
So I am trying to bypass it, using a query to return patients with unscheduled treatment that were tx planned in a time range.
Unfortunately, I am running into the same problem as in TxFinder - if a patient has a future recall appointment, they do not show up in the list for unscheduled tx.
I thought the query below would exclude appts for recall procedures, but we have the same problem.
Shouldn't the highlighted line exclude recall appts?
/*164 Returns all treatment planned procedures for active patients without a scheduled OR planned apt, who were last seen in a given date range
with phone numbers, useful for those transitioning to planned appointments
(this differs FROM #56 largely in that it is date limited and lists out the treatment)*/
DROP TABLE IF EXISTS tmp1;
DROP TABLE IF EXISTS tmp2;
SET @FROMDate= DATE_SUB(CurDate(), INTERVAL 7 Day) ,@ToDate= DATE(CurDate()) ;
CREATE TABLE tmp1 AS SELECT patient.PatNum, CONCAT(LName, ', ',FName, ' ', MiddleI) AS PatName, HmPhone, WkPhone,
WirelessPhone AS Wireless, ProcFee, pc.ProcCode FROM patient
INNER JOIN procedurelog pl ON patient.PatNum=pl.PatNum
INNER JOIN procedurecode pc ON pl.CodeNum= pc.CodeNum AND ProcStatus=1
LEFT JOIN appointment ap ON patient.PatNum=ap.PatNum AND (ap.AptStatus=1 OR ap.AptStatus=6 )
WHERE ap.AptNum IS NULL AND patient.PatStatus=0 AND pc.ProcCode NOT IN('D0120', 'D0150','D1120', 'D1110','D1203','D1204', 'D1206', 'D0272','D0274','D0210', 'D0220', 'D0230', 'D4910', 'D4910.3') AND ProcFee NOT IN ('0');
CREATE TABLE tmp2 AS SELECT p.PatNum, DATE_FORMAT(MAX(ProcDate),'%m/%d/%Y') AS 'LastVisit', MAX(ProcDate) AS 'DateLast'
FROM patient p
INNER JOIN procedurelog pl ON pl.PatNum=p.PatNum
WHERE pl.ProcStatus=2 AND p.PatStatus=0
GROUP BY pl.PatNum;
SELECT PatName,Left(HmPhone,15) AS HmPhone,Left(WkPhone,21) As WKPhone,Left(Wireless,15) AS Wireless, ProcFee AS '$Fee', LastVisit
FROM tmp1 INNER JOIN tmp2 ON tmp1.PatNum=tmp2.PatNum
WHERE DateLast BETWEEN @FROMDate AND @ToDate
ORDER BY PatName;
DROP TABLE IF EXISTS tmp1;