We are on EMR 9.8 spk3 and CPS11. I need to be able to find duplicate medical record numbers in the emr. I need help with this as soon as possible. Thanks
[email protected]
Do you have Crystal Reports?
Here is a CR definition.
(Well, I will try to upload it here... however, it appears that .rpt files cannot be uploaded)
Note, I had to change the file extension from .rpt to .txt to get this to upload. So, download and then rename it.
This script should do it for you...
SELECT First, Last, PatientProfileID, PatientId, MedicalRecordNumber
FROM PatientProfile
WHERE MedicalRecordNumber IN (
SELECT MedicalRecordNumber
FROM
(
SELECT ROW_NUMBER() OVER (PARTITION BY MedicalRecordNumber ORDER BY PatientProfileId DESC) AS MRN_COUNT, *
FROM PatientProfile
WHERE MedicalRecordNumber IS NOT NULL) AS TEMP
WHERE MRN_COUNT > 1)
;WITH cte_MRN AS (
SELECT MedicalRecordNumber, COUNT(PId) AS PatientCount
FROM PatientProfile
GROUP BY MedicalRecordNumber
HAVING COUNT(PId) > 1)
SELECT p.* --edit column list as needed
FROM PatientProfile p
INNER JOIN cte_MRN c
ON p.MedicalRecordNumber = c.MedicalRecordNumber;
That would give you the list of patients who have duplicate MRNs. Or you could just run the contents of the CTE to get the list of MRNs that appear more than once.