Skip to content
Advertisement

SQL Continuous Date Ranges Previously Grouped Data

I’m working with a data extract that represents claims data for a population. The ultimate goal is to be able to associate specific claims to unique encounters. The way we’d define an encounter is a string of claims that are continuous, or within the same range; meaning the claim-to date is followed up by a claim-from date immediately after, or has an identical to & from date as another claim. However, because there is no key that actually indicates that a group of claims represent a specific encounter, we have to implement logic that does this for us.

For the sake of this example, we’ve already grouped the data by Patient & Facility.

What’d I’d like to see ultimately is an encounter ID. This is how the individual claims should be placed into encounter IDs:

Claims 1,2,3,4,5,6,7 are in Encounter 1.1; Claims 8,9 are in Encounter 1.2; Claims 10,11 are in Encounter 2.1

Any guidance would be greatly appreciated!

Advertisement

Answer

You need to find the gaps, i.e. the current start date is greater than any previous end date (plus one day)

See fiddle

User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement