views:

55

answers:

2

Hi all,

I've a flat file that I cleaned the data out using SSIS, the output looks like that :

MEDICAL    ADMIT     PATIENT     PATIENT         DATE OF    DX 
REC NO     DATE      NUMBER        NAME        DISCHARGE   Code     DRG #

123613    02/16/09  12413209  MORIBALDI ,GEMMA  02/19/09   428.20     988    
130897    01/23/09  12407193  TINLEY ,PATRICIA  01/23/09   535.10     392    
139367    02/27/09  36262509  THARPE ,GLORIA    03/05/09   562.10     392 

141954    02/25/09  72779499  SHUMATE ,VALERIA  02/25/09   112.84     370   
141954    03/07/09  36271732  SHUMATE ,VALERIA  03/10/09   493.92     203  

145299    01/21/09  12406294  BAUGH ,MARIA      01/21/09   366.17     117  

and the report (final results) attached in the screen shot from the final excel report.

so what's happening is IF the same name or same account number is duplicate, that means the patient has entered the hospital again and needs to be included in the report. ![alt text][1]

what I need to do is...

Eliminate any rows that is NOT duplicate (not everybody in this file has been admitted again) and compare the dates to get the ReAdmitdate and ReDischargedate

I dumped the data into a SQL table and trying to compare the dates to figure out "ReAdmitdate" and "ReDischargedate"

any help is appreciated.

+1  A: 

Is there a unique identifier for the patients? I'm assuming patient_number is the unique identifier for each patient, and medical_rec_no is incremental.

This query works by joining the patient records to records from the same patient that have a later admit date.

SELECT p1.patient_number, p1.admit_date,
  p2.admit_date as readmit_date, p2.discharge_date AS redischarge_date
FROM patient p1
  INNER JOIN patient p2
    ON p1.patient_number = p2.patient_number AND
      p2.medical_rec_no <> p1.medical_rec_no
  LEFT OUTER JOIN patient p3
    ON p3.patient_number = p1.patient_number AND
      p3.medical_rec_no <> p1.medical_rec_no AND
      p3.admit_date < p2.admit_date
WHERE p3.patient_number IS NULL
ORDER BY p1.patient_number, p1.admit_date, p1.medical_rec_no
Marcus Adams
Cheers for reply and the good ideas...Thanks Marcusbut your query didn't get any results ! don't know why, but gave me the Idea, i've came up with but my problem now that I get duplicates if someone has admitted 3 or 4 times !I just can't figure it out ! HELP pleaseI'll post sample of the results with the duplicates to explain my problem.Thanks for your help and god bless for sharing the knowledge
Huslayer
SELECT A.MedRecNo, A.AdmitDate, B.AdmitDate AS ReAdmitDate, A.DateOfDischarge, B.DateOfDischarge AS ReDateOfDischarge, A.PatientNo, B.PatientNo AS RePatientNumber, A.PatientName, A.DXCode, B.DXCode AS ReAdmitDXCode, A.DrgNo, B.DrgNo AS ReAdmitDrgNoFROM report A INNER JOIN report B ON A.MedRecNo = B.MedRecNo AND A.AdmitDate <> B.AdmitDate AND A.AdmitDate < B.AdmitDate
Huslayer
@Huslayer, the query should work if my assumptions were correct. If I had the columns wrong, then please adjust the query, or post your schema, and I'll update the query. What's the primary record key column and what's the unique identifier for the patient?
Marcus Adams
@Marcus, Yes i've edited the column names of course but it came with 0 results, but ti's ok because it was my guiding angel :) thanks to uthe unique is the "MedRecNo"I wanna post sample screen shots !! don't know how to do it here !
Huslayer
A: 

I used to work for a hospital on the Data Warehousing team (building cubes used by the whole organization) and we had visit numbers to go by and from there we could determine if it was an appointment set (or re-admission as you refer to it). Do you have any appointment numbers and visit numbers, it may be useful to add those to your SQL table.

ajdams
No we don't use appointment numbers and visit numbers, I wish ! lol
Huslayer
Well MRN should be unique (as discovered above) =P
ajdams

related questions