Help with query for inactive patients

For users or potential users.
Post Reply
Nate
Posts: 164
Joined: Wed Jun 27, 2007 1:36 pm
Location: Kansas City, MO

Help with query for inactive patients

Post by Nate » Wed Jan 27, 2010 7:55 am

I want a query to search for patients that we can inactivate and pull charts for. I have the following query but it includes patients that are also inactive and we have already pulled their charts.

Patients not seen since XYZ Date

SELECT patient.LName, patient.FName, patient.Address, patient.Address2, patient.City, patient.State, patient.Zip, procedurelog.procdate
FROM patient,procedurelog
WHERE procedurelog.patnum=patient.patnum
AND procedurelog.procstatus = '2'
GROUP BY procedurelog.patnum
HAVING MAX(procdate) < '2008-01-01'

Thanks for any help

atd
Posts: 404
Joined: Thu Mar 27, 2008 2:28 pm
Location: Minneapolis, MN

Re: Help with query for inactive patients

Post by atd » Thu Jan 28, 2010 1:20 pm

These are the patient.PatStatus values:
Patient: 0
NonPatient: 1
Inactive: 2
Archived: 3
Deleted: 4
Deceased: 5
So I just added patient.PatStatus=0 to your query below.

SELECT patient.LName, patient.FName, patient.Address, patient.Address2, patient.City, patient.State, patient.Zip, procedurelog.procdate
FROM patient,procedurelog
WHERE procedurelog.patnum=patient.patnum
AND procedurelog.procstatus = '2'
AND patient.PatStatus=0
GROUP BY procedurelog.patnum
HAVING MAX(procdate) < '2008-01-01'

User avatar
Jorgebon
Posts: 502
Joined: Mon Jun 18, 2007 2:25 pm
Location: Mayaguez, PR
Contact:

Re: Help with query for inactive patients

Post by Jorgebon » Thu Jan 28, 2010 3:05 pm

I would also add that to get the correct date of the patient's last visit, you should make a small change in the SELECT line as follows:

SELECT patient.LName, patient.FName, patient.Address, patient.Address2, patient.City, patient.State, patient.Zip, Date_Format(MAX(procedurelog.ProcDate),'%m/%d/%y') as 'Date Last Visit'
FROM patient,procedurelog
WHERE procedurelog.patnum=patient.patnum
AND procedurelog.procstatus = '2'
AND patient.PatStatus=0
GROUP BY procedurelog.patnum
HAVING MAX(procdate) < '2008-01-01'

You could also add a line at the end to order the list alphabetically with:
ORDER BY patient.LName, patient.FName

Jorge Bonilla, DMD
Jorge Bonilla DMD
Open Dental user since May 2005

Post Reply