Anyone have an update query to link a Chart note to an appointment for when a provider forgets this step when starting their note?
It would be a manual process because you would need to lookup the appointment visitid and the document.
To find the VISITID you could perform a query like this:
SELECT RPTAPPT.VISITID, RPTAPPT.APPTDATE, BOOK.NAME, PERSON.SEARCHNAME, PERSON.DATEOFBIRTH FROM RPTAPPT
INNER JOIN BOOK ON RPTAPPT.BOOKID = BOOK.ID
INNER JOIN PERSON ON PERSON.PID = RPTAPPT.PID
WHERE UPPER(PERSON.SEARCHNAME) LIKE 'TEST, ANGELA%'
ORDER BY APPTDATE DESC
You would probably want to search for something other than the patient by name, we would use PERSON.EXTERNALID to search for a particular patient. The query above would return a list of all of that patients appointments and which appt book it was in. The VISITID from the appropriate appt would neet to be put into the documents table.
To find the document try something like this:
SELECT DOCUMENT.SDID, PERSON.PID, PERSON.SEARCHNAME, PERSON.DATEOFBIRTH, DOCTYPES.ABBR,
DOCUMENT.SUMMARY, USRINFO.SEARCHNAME PROVIDER, ML.CONVERT_ID_TO_DATE(CLINICALDATE) CLINICALDATE
FROM DOCUMENT
INNER JOIN PERSON ON DOCUMENT.PID = PERSON.PID
INNER JOIN DOCTYPES ON DOCTYPES.DTID = DOCUMENT.DOCTYPE
INNER JOIN USRINFO ON DOCUMENT.USRID = USRINFO.PVID
WHERE DOCTYPES.ABBR LIKE 'Ofc Visit'
AND UPPER(PERSON.SEARCHNAME) LIKE 'TEST, ANGELA%'
AND DOCUMENT.VISITID IS NULL
AND DOCUMENT.XID = 100000000000000000000000000000000000
ORDER BY CLINICALDATE DESC
What we need is the document SDID and, just in case, the PERSON.PID in the documents table for the appropriate note. These are both 16 digit numbers.
The update would look something like this: (replace the <> and everything in between with the appropriate info)
UPDATE DOCUMENT SET VISITID = '<VISITID>' WHERE SDID = '<SDID>' AND PID = '<PID>'