Extract timings between select event codes within an examination timeline.

extract_event_timing(record, spans = list(`Initial Classification` =
  list(start = "^PGPC$", end = "^(?:OI|PG$)", before = "^DOCK$"),
  `Art Unit to Examiner` = list(start = "^DOCK$", end = "^FWDX$", before =
  "^(?:CTFR|EX\\.R|N/=\\.)"), `Examiner to Action` = list(start = "^FWDX$",
  end = "^(?:CT|EX\\.R|N/=\\.)", before = "^(?:DOCK$|A)")))

Arguments

record

A matrix-like object with dates in the first column (recognizable by as.Date) and event codes (recognizable by the patterns in span) in the second.

spans

A list with entries defining each event window. Each entry should be a list with entries for start, end, and before, each containing regular expression strings identifying event codes.

Value

A list with a data.frame for each entry in span.

Examples

extract_event_timing(data.frame(
  date = c("2020-01-15", "2020-01-20"),
  event = c("FWDX", "CTNF")
))
#> $`Initial Classification`
#> NULL
#> 
#> $`Art Unit to Examiner`
#> NULL
#> 
#> $`Examiner to Action`
#>   start  startDate startEvent end    endDate endEvent days
#> 1     2 2020-01-15       FWDX   1 2020-01-20     CTNF    5
#>