I try to group dates within 3 days of each other and assign points based on readmission for 30 days. MRN will receive 3 points for re-admission. Any help on modifying my request below would be great.
Example:
CREATE TABLE
Desired outcome: I really only need actual visits, OrganizationMrn and Points. (When the dates are grouped (Actual visits), the first date should be used for readmission within 30 days).
ACTUAL Visits Grouped Dates Re-admissions Points 1/2/2016 (grouped 1/2, 1/5) 1/7/2016 (grouped 1/7, 1/8, 1/9) Readmit from 1/2 (3 points) 2/4/2016 Readmit from 1/7 (3 points) 6/2/2016 (grouped 6/2, 6/3, 6/5) 6/6/2016 (grouped 6/6, 6/8) Readmit from 6/2 (3 points) 7/1/2016 Readmit from 6/6 (3 points) 8/1/2016 (grouped 8/1, 8/4) 8/15/2016 (grouped 8/15, 8/18) Readmit from 8/1 (3 points) 8/28/2016 Readmit from 8/15 (3 points) 10/12/2016 (grouped 10/12, 10/15) 11/17/2016 12/20/2016 ___________________________________________ 6 total readmits (18 total points)
The following request uses gaps and islands to group days within 3 days of each other. However, if the dates are consecutive, the start and end dates are grouped. (Example: query below groups, [1/2, 1/5, 1/7 /, 1/8, 1/9] in one line; dates should be divided into two lines [1/2, 1/5] and [1/7 /, 1/8, 1/9]).
Once grouped dates have separate lines, I need to assign 3 points for each readmission for 30 days. (The actual visit to the organization within 30 days with each other). The desired output section above describes how dates should be grouped in my example.
;WITH StartingPoints AS ( SELECT OrganizationMrn, VisitDate, ROW_NUMBER() OVER (ORDER BY VisitDate) AS Sequence FROM