This function identifies and labels all episodes of care for a given patient in chronological order. A new episode begins after a specified gap in therapy has occurred. It is meant to be used after one has appropriately adjusted dates (propagate_date()) and identified gaps in therapy (identify_gaps()).

rank_episodes(.data, .permissible_gap = NULL, .initial_rank = 1)

Arguments

.data

Data frame with a "gap" column appended from identify_gaps()

.permissible_gap

Integer value suggesting the maximum gap allowed before labeling a new episode of care

.initial_rank

Integer value to identify what the indexing rank should be (defaults to 1).

Value

The initial claims data frame with an episode column appended, which ranks episodes of care in time

Note

This function assumes an adjusted_date column, which is produced by the propagate_date() function and a gap column, which is produced by identify_gaps(). If you would like to rank episodes of care using other dates and a separate column for gaps, you'll need to rename those columns before passing the frame to rank_episodes(). Notably, this is on purpose as this step should almost always come after the former two.

Examples

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