Compute gaps in a patient's therapy from the end of their prior fill to the beginning of the next. This function assumes that one has arranged the dates and grouped appropriately outside of the function. The length of any gap will be appended to the row after the gap has occurred.

identify_gaps(.data)

Arguments

.data

data frame

Value

A new claims tibble with an appended column, gap

Note

This function relies an adjusted_date column to identify gaps in therapy. So, if you don't want to use propagate_date() beforehand, you'll need to rename the date variable you wish to use to adjusted_date.

Examples

library(adheRenceRX) library(dplyr) toy_claims %>% filter(ID == "D") %>% propagate_date(.date_var = date, .days_supply_var = days_supply) %>% identify_gaps()
#> # A tibble: 6 x 5 #> ID date days_supply adjusted_date gap #> <chr> <date> <dbl> <date> <dbl> #> 1 D 2020-01-01 60 2020-01-01 0 #> 2 D 2020-01-31 60 2020-03-01 0 #> 3 D 2020-03-01 60 2020-04-30 0 #> 4 D 2020-05-30 30 2020-06-29 0 #> 5 D 2020-08-28 60 2020-08-28 30 #> 6 D 2020-09-27 30 2020-10-27 0