Hi,
I am working on patient data at hospital and need to calculate the number of ER visits and number of Inpatient visits in the last 6 months from the date of the current admission. Below is the sample data for a patient ( unique ID is MRN and for each visit there will be a distinct Account number).
MRN AccountNumber AdmitDt DischDt Type
MRN123 PA123 1/1/2017 1/20/2017 I
MRN123 PA234 4/1/2017 4/1/2017 ER
MRN123 PA345 4/5/2017 4/10/2017 I
MRN123 PA456 5/1/2017 5/1/2017 ER
MRN123 PA567 5/5/2017 5/10/2017 I
MRN123 PA678 5/15/2017 5/15/2017 ER
MRN123 PA789 7/1/2017 7/10/2017 I
I need to add two more columns ( number of ED visits in last 6 months and number of Inpatient visits in last 6 months) and expect the results to look like
MRN AccountNumber AdmitDt DischDt Type ERVisitsinlast6month Inpatientvisitsinlast6months
MRN123 PA123 1/1/2017 1/20/2017 I 0 0
MRN123 PA234 4/1/2017 4/1/2017 ER 0 1
MRN123 PA345 4/5/2017 4/10/2017 I 1 1
MRN123 PA456 5/1/2017 5/1/2017 ER 1 2
MRN123 PA567 5/5/2017 5/10/2017 I 1 2
MRN123 PA678 5/15/2017 5/15/2017 ER 2 3
MRN123 PA789 7/1/2017 7/10/2017 I 3 2
please suggest any ideas.
Thanks,