Missed Appointment Note

For users or potential users.
Post Reply
KevinRossen
Posts: 293
Joined: Mon Apr 22, 2013 8:49 am
Location: Dallas, TX
Contact:

Missed Appointment Note

Post by KevinRossen » Mon Oct 19, 2015 12:56 pm

I'm working on revamping one of my queries and I've discovered something new regarding the broken appointment function that utilizes the CDT D9986 code. It seems to automatically add an entry to the procnote table as soon as the appointment is broken. Then it adds an additional procnote when the OK button is entered. So, there will always either be a duplicate procnote or a second note if the user enters notes for the missed appointment.

I understand that this is probably great for auditing purposes, but it's challenging me to pull the most recent note for some queries I'm re-doing. I'm including a broken appointment query for example below:

Code: Select all

SELECT
	pl.ProcDate AS DateBroken,
	CONCAT(p.LName,', ',p.FName) AS Patient,
	DATE(ap.DateNextSchedApt) AS NextApt,
	pc.Descript AS BrokeType,
	pn.Note AS BrokeNote
FROM procedurelog pl
LEFT JOIN procedurecode pc ON pl.CodeNum = pc.CodeNum
LEFT JOIN procnote pn ON pl.ProcNum = pn.ProcNum
LEFT JOIN patient p ON pl.PatNum = p.PatNum
LEFT JOIN 
	(
	SELECT
		a.PatNum,
		MIN(DATE(a.AptDateTime)) AS DateNextSchedApt
	FROM appointment a
	WHERE 
		DATE(a.AptDateTime)>=CURDATE()
		AND a.AptStatus IN (1,2,4)
	GROUP BY a.PatNum
	) ap ON p.PatNum=ap.PatNum
WHERE 
	pc.ProcCode LIKE 'D9986%'
	AND pl.ProcStatus = 2
	AND pl.ProcDate = CURDATE()
;
Kevin Rossen
Office Manager, Rossen Dental
Founder, DivergentDental.com
Image

User avatar
jsalmon
Posts: 1562
Joined: Tue Nov 30, 2010 12:33 pm
Contact:

Re: Missed Appointment Note

Post by jsalmon » Mon Oct 19, 2015 3:16 pm

The procedure note with the largest date and time is the most recent note. So you simply need to add something like this to your WHERE clause:

Code: Select all

AND pn.EntryDateTime=(SELECT MAX(pn2.EntryDateTime)
FROM procnote pn2
WHERE pn.ProcNum = pn2.ProcNum)
The best thing about a boolean is even if you are wrong, you are only off by a bit.

Jason Salmon
Open Dental Software
http://www.opendental.com

KevinRossen
Posts: 293
Joined: Mon Apr 22, 2013 8:49 am
Location: Dallas, TX
Contact:

Re: Missed Appointment Note

Post by KevinRossen » Tue Oct 20, 2015 3:22 pm

jsalmon wrote:The procedure note with the largest date and time is the most recent note. So you simply need to add something like this to your WHERE clause:

Code: Select all

AND pn.EntryDateTime=(SELECT MAX(pn2.EntryDateTime)
FROM procnote pn2
WHERE pn.ProcNum = pn2.ProcNum)

Worked like a charm. Thanks!!! Below is my modified query for those who are interested. It actually finds broken appointments from the previous day.

Code: Select all

SELECT
	pl.ProcDate AS DateBroken,
	CONCAT(p.LName,', ',p.FName) AS Patient,
	DATE(ap.DateNextSchedApt) AS NextApt,
	pc.Descript AS BrokeType,
	pn.Note AS BrokeNote
FROM procedurelog pl
LEFT JOIN procedurecode pc ON pl.CodeNum = pc.CodeNum
LEFT JOIN procnote pn ON pl.ProcNum = pn.ProcNum
LEFT JOIN patient p ON pl.PatNum = p.PatNum
LEFT JOIN 
	(
	SELECT
		a.PatNum,
		MIN(DATE(a.AptDateTime)) AS DateNextSchedApt
	FROM appointment a
	WHERE 
		DATE(a.AptDateTime)>=CURDATE()
		AND a.AptStatus IN (1,2,4)
	GROUP BY a.PatNum
	) ap ON p.PatNum=ap.PatNum
WHERE 
	pc.ProcCode LIKE 'D9986%'
	AND pl.ProcStatus = 2
	AND pl.ProcDate = (SELECT MAX(DATE(AptDateTime)) FROM appointment WHERE AptStatus=2 AND DATE(AptDateTime)<CURDATE())
	AND pn.EntryDateTime=(SELECT MAX(pn2.EntryDateTime) FROM procnote pn2 WHERE pn.ProcNum = pn2.ProcNum);
Kevin Rossen
Office Manager, Rossen Dental
Founder, DivergentDental.com
Image

Post Reply