I want to find and remove patients from EMR that do not have any documents in their chart.
Would this oracle SQL work?
SELECT distinct person.PID , PERSON.EXTERNALID, PERSON.SEARCHNAME, person.db_updated_date
FROM person LEFT JOIN document ON (person.pid = document.pid)
WHERE (document.pid IS NULL) AND PERSON.PSTATUS='I'
try this:
select
distinct person.PID ,
PERSON.EXTERNALID,
PERSON.SEARCHNAME,
person.db_updated_date
FROM person
where
not exists (select * from document where document.pid=person.pid) and
PERSON.PSTATUS=’I’
One thing to keep in mind you may want to see when the patient was last Created or Updated in the PatientProfile table. If you consider this information, you will be able to tweak your script to not include patients that were recently created as new patients. Obviously new patients will not have documents right away. This will then allow you to truly focus on patients that have been existing for a while and still have no related documents.