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(arr_date   >= lubridate::as_datetime('2022-08-01'), 
         arr_date   <= lubridate::as_datetime('2022-08-07'), 
         pod_l1      = '999', 
         and pod_l2b = 'see & treat') %>% 
  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'",
  "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       = 96,
               window_post      = 96, 
               window_units     = "hours",
               activity_filter  = activity_filter,
               svr              = svr)

# Run the analysis
analyse(obj)