Skip to contents
library(PrePost)
library(dplyr)
library(lubridate)

# Create an icdb::server object to access the ICB databases
svr <- icdb::server("XSW")

# Define a cohort to study
cohort <- svr$MODELLING_SQL_AREA$swd_activity %>% 
  select(nhs_number, arr_date, prov_code, pod_l2a) %>% 
  filter(dep_date   >= lubridate::as_datetime('2022-08-01'), 
         arr_date   <= lubridate::as_datetime('2022-08-01'), 
         prov_code %in% c('ra700','rvj00'),
         pod_l1      = 'secondary', 
         pod_l2a     = 'ip',
         pod_l2b     = 'non_elective') %>% 
  select(nhs_number,
         index_event_time=arr_date)

# Define the type(s) of activity to look at and the filtering that defines them
activity_filter <- list(
  "A+E"                 = "pod_l1=='secondary' & pod_l2a=='ae'",
  "Community in-person" = "pod_l1=='community' & pod_l3=='physical'",
  "999 (all types)"     = "pod_l1=='999'",
  "111"                 = "pod_l1=='111'",
  "GP"                  = "pod_l1=='primary_care_contact'")

# Create the PrePost object 
obj <- PrePost(nhs_number       = cohort$nhs_number,
               index_event_time = cohort$index_event_time,
               window_pre       = 0,
               window_post      = 168, 
               window_units     = "hours",
               activity_filter  = activity_filter,
               svr              = svr)

# Run the analysis
analyse(obj)