I have a database of prescription claims that contains the dispensing date and end date of each prescription, as defined by days supplied. The goal is to calculate how many whether the patient has continuous coverage without more than a 7-day gap. The issue is that there are times in which a patient may have 2 ore more prescriptions in which the dispensing and end dates overlap. For example, the data might look like this:
PATIENT_ID RX_ID DISPENSE_DATE END_DATE
1 A 1/1/2022 1/8/2022
1 B 1/7/2022 1/9/2022
1 C 1/8/2022 1/11/2022
1 D 1/19/2022 1/25/2022
1 E 1/26/2022 1/30/2022
If you only consider the dispense_date and end_date, it looks like consider there is a 8-day gap between C and D. However, RX_ID B overlaps with A for 2 days (1/7/2022-1/8/2022), and C overlaps with A for 1 day (1/8/2022), and I would like to consider the patient as having coverage from 1/1/2022 through 1/14/2022 (i.e., 1/11/2022 plus the number of overlapping dates), in which case there is only a 5-day gap before D. Basically, I want to turn the above database into something like the following (the observations for D and E would stay the same because there is no overlap).
PATIENT_ID RX_ID DISPENSE_DATE END_DATE_COMBINED
1 A 1/1/2022 1/14/2022
1 D 1/19/2022 1/25/2022
1 E 1/26/2022 1/30/2022
Note: while not in this example data, I'm aware that there could be situations in which prescription D could have started on 1/13/2022, in which case it overlaps with the new range of A after stitching A/B/C together. However, I don't care about that for the purposes of this analysis.
I'd appreciate any advice. Thanks.
... View more