# data %>%
# filter(age < 18 | is.na(age) | age > 100) %>%
# select(study_id, age)
# study_id age
# <chr> <dbl>
# 1 2192017008 13
# 2 2840038946 17
# 3 2900134333 16
# 4 2019032888 17
# 5 2400029191 14
# 6 2692028597 0 -- fixed
# 7 2292024038 0 -- fixed
# 8 2931047341 14
# 9 2851043805 12
# 10 2981041559 17
# 11 2951036174 17
# 12 2891035628 1 -- fixed
# 13 2391033346 16
# 14 2731031508 12
# 15 2681025310 17
# 16 2170023623 167 -- fixed
# 17 1349042713 17
# 18 2019033052 14
# 19 1499.013.450 15
# 20 1049013802 17
# 21 1789.011.265 17
# data %>%
# filter(is.na(sex.factor)) %>%
# select(study_id, sex, sex.factor)
# study_id sex
# <chr> <dbl+lbl>
# 1 2180024326 NA -- fixed
# 2 2971033025 NA -- fixed
# 3 1039013496 NA -- fixed
# 4 2071039462 NA -- fixed
# 5 1399.049.496 NA -- fixed
# consistency check for previous abdominal surgery excluding Crohn
# data %>%
# filter(
# prev_abd_surg == 0 & (
# prev_abd_surg_typ___1 == 1 |
# prev_abd_surg_typ___2 == 1 |
# prev_abd_surg_typ___3 == 1 |
# prev_abd_surg_typ___4 == 1 |
# prev_abd_surg_typ___5 == 1 |
# prev_abd_surg_typ___6 == 1 |
# prev_abd_surg_typ___7 == 1
# )
# ) %>%
# select(
# prev_abd_surg, # Previous abdominal surgery (EXCLUDING procedures for Crohn's)
# prev_abd_surg_typ___1, # appendicectomy
# prev_abd_surg_typ___2, # cholecystectomy
# prev_abd_surg_typ___3, # gynecologic procedure (including C section)
# prev_abd_surg_typ___4, # gastric surgery
# prev_abd_surg_typ___5, # colon surgery
# prev_abd_surg_typ___6, # hepatic surgery
# prev_abd_surg_typ___7, # other
# )
# all good
# consistency check for previous Crohn surgery
# data %>%
# filter(
# location_previous_crohn___10 == 1 & ( # no previous operations
# location_previous_crohn___1 == 1 | # terminal ileum
# location_previous_crohn___2 == 1 | # ileum
# location_previous_crohn___3 == 1 | # jejenum
# location_previous_crohn___4 == 1 | # right colon
# location_previous_crohn___5 == 1 | # transverse colon
# location_previous_crohn___6 == 1 | # left colon
# location_previous_crohn___7 == 1 | # rectum
# location_previous_crohn___8 == 1 | # perianal
# location_previous_crohn___9 == 1 # uppergi
# )
# ) %>%
# select(
# study_id,
# location_previous_crohn___1, # terminal ileum
# location_previous_crohn___2, # ileum
# location_previous_crohn___3, # jejenum
# location_previous_crohn___4, # right colon
# location_previous_crohn___5, # transverse colon
# location_previous_crohn___6, # left colon
# location_previous_crohn___7, # rectum
# location_previous_crohn___8, # perianal
# location_previous_crohn___9, # uppergi
# location_previous_crohn___10, # no previous operations
# )
# study_id
# <chr>
# 1 2022046044 -- fixed
# 2 2871026699 -- fixed
# problematic admiss_date, disch_date, surg_date
# data %>%
# filter(
# difftime(as.Date(disch_date), as.Date(surg_date), units = "days") < 0 |
# difftime(as.Date(surg_date), as.Date(admiss_date), units = "days") < 0 |
# difftime(as.Date(disch_date), as.Date(admiss_date), units = "days") < 0 |
# difftime(as.Date(surg_date), as.Date(admiss_date), units = "days") > 100 |
# difftime(as.Date(disch_date), as.Date(admiss_date)) > 100
# ) %>%
# select(study_id, surg_date, admiss_date, disch_date)
## wrong dates
# study_id surg_date admiss_date disch_date
# <chr> <date> <date> <date>
# 1 2482045216 2022-09-28 2022-09-29 2022-10-03 -- fixed
# 2 201933269 2019-06-27 2019-07-26 2019-07-03 -- fixed
# 3 2482058889 2023-01-04 2023-01-30 2023-01-12 -- fixed
# 4 2082019572 2022-03-17 2022-03-09 2022-03-16 -- fixed
# 5 2402019398 2022-03-11 2022-03-13 2022-03-24 -- fixed
# 6 2561046387 2021-10-28 2021-10-25 2021-10-02 -- fixed
# 7 1263.037.284 2019-10-02 2013-09-30 2013-10-09 -- fixed
# 8 2019041728 2019-08-26 2019-08-28 2019-09-02 -- wrong nosologic code
## long stay
# study_id surg_date admiss_date disch_date
# <chr> <date> <date> <date>
# 1 2612019003 2022-03-13 2021-03-13 2022-03-21 -- fixed
# 2 2391011962 2021-02-02 2021-01-21 2021-06-04 -- correct
# 3 2010139691 2020-06-08 2020-01-26 2020-06-20 -- fixed
# 4 1263.037.284 2019-10-02 2013-09-30 2013-10-09 -- fixed
# 5 1758.168.350 2019-06-25 2018-06-24 2019-07-01 -- unfixable, all three dates are wrong
# data %>%
# filter(
# (dis_beahviour___1 == 1 | dis_beahviour___2 == 1) & dis_beahviour___3 == 1
# ) %>%
# select(study_id, dis_beahviour___1, dis_beahviour___2, dis_beahviour___3)
# study_id dis_beahviour___1 dis_beahviour___2 dis_beahviour___3
# <chr> <dbl+lbl> <dbl+lbl> <dbl+lbl>
# 1 2910130481 0 [Unchecked] 1 [Checked] 1 [Checked]
df_fix <- data %>%
dplyr:: mutate (
age = case_when (
study_id == 2170023623 ~ 67 ,
study_id == 2891035628 ~ 26 ,
study_id == 2692028597 ~ 50 ,
study_id == 2292024038 ~ 77 ,
.default = as.integer (age),
),
alb_surg = case_when (
study_id == 2191039889 ~ "40.4" ,
.default = alb_surg,
),
previous_biologics = case_when (
study_id == 2340035674 ~ 0 ,
.default = previous_biologics,
),
adalim_end = case_when (
study_id == 2271028772 ~ "16-01-2021" ,
study_id == 2391011962 ~ "01-05-2012" ,
.default = adalim_end,
),
sex.factor = case_when (
study_id == 2180024326 ~ "Female" ,
study_id == 2971033025 ~ "Male" ,
study_id == 1039013496 ~ "Male" ,
study_id == 2071039462 ~ "Male" ,
study_id == "1399.049.496" ~ "Male" ,
.default = sex.factor,
),
admiss_date = case_when (
study_id == 2482045216 ~ as.Date ("2022-09-27" ),
study_id == 2482058889 ~ as.Date ("2023-01-03" ),
study_id == 201933269 ~ as.Date ("2019-06-26" ),
study_id == 2402019398 ~ as.Date ("2022-03-10" ),
study_id == "1263.037.284" ~ as.Date ("2019-09-30" ),
study_id == 2612019003 ~ as.Date ("2022-03-13" ),
study_id == 2010139691 ~ as.Date ("2020-05-19" ),
.default = as.Date (admiss_date),
),
# admiss_date = structure(as.Date(admiss_date), label = "Admission date"),
disch_date = case_when (
study_id == "1263.037.284" ~ as.Date ("2019-10-09" ),
study_id == 2561046387 ~ as.Date ("2021-11-02" ),
study_id == 2082019572 ~ as.Date ("2022-03-23" ),
.default = as.Date (disch_date)
),
# disch_date = structure(as.Date(disch_date), label = "Discharge date"),
# surg_date = structure(as.Date(surg_date), label = "Surgery date"),
# dis_beahviour___1 = as.factor(dis_beahviour___1),
# dis_beahviour___2 = as.factor(dis_beahviour___2),
# dis_beahviour___3 = case_when(
# study_id == 2910130481 ~ 0,
# .default = as.factor(dis_beahviour___3),
# ),
# dis_beahviour___3.factor = case_when(
# study_id == 2910130481 ~ "Unchecked",
# .default = dis_beahviour___3.factor,
# ),
dis_behavior = case_when (
(dis_beahviour___1 == 1 & dis_beahviour___2 == 0 ) ~ 0 ,
(dis_beahviour___1 == 0 & dis_beahviour___2 == 1 ) ~ 1 , # corrects 2910130481
(dis_beahviour___1 == 1 & dis_beahviour___2 == 1 ) ~ 2 ,
(dis_beahviour___1 == 0 & dis_beahviour___2 == 0 & dis_beahviour___3 == 1 ) ~ 3 ,
.default = NA ,
),
dis_behavior = structure (
factor (dis_behavior,
levels = c (0 , 1 , 2 , 3 ),
labels = c ("Stenotic" , "Fistulizing" , "Stenotic + fistulizing" , "None" )
),
label = "Disease behavior"
),
location_previous_crohn___1 = case_when (
study_id == 2022046044 ~ factor (0 , levels = c (0 , 1 )),
.default = as.factor (location_previous_crohn___1),
),
location_previous_crohn___5 = case_when (
study_id == 2871026699 ~ factor (0 , levels = c (0 , 1 )),
.default = as.factor (location_previous_crohn___5),
),
location_previous_crohn___6 = case_when (
study_id == 2871026699 ~ factor (0 , levels = c (0 , 1 )),
.default = as.factor (location_previous_crohn___6),
),
location_previous_crohn___8 = case_when (
study_id == 2022046044 ~ factor (1 , levels = c (0 , 1 )),
.default = as.factor (location_previous_crohn___8),
),
location_previous_crohn___10 = case_when (
study_id == 2022046044 ~ factor (0 , levels = c (0 , 1 )),
study_id == 2871026699 ~ factor (1 , levels = c (0 , 1 )),
.default = as.factor (location_previous_crohn___10),
),
location_previous_crohn___2 = as.factor (location_previous_crohn___2),
location_previous_crohn___3 = case_when (
study_id == "2551047268" ~ factor (1 , levels = c (0 , 1 )),
.default = as.factor (location_previous_crohn___3)
),
location_previous_crohn___4 = as.factor (location_previous_crohn___4),
location_previous_crohn___7 = as.factor (location_previous_crohn___7),
location_previous_crohn___9 = as.factor (location_previous_crohn___9),
alb_surg = case_when (
study_id == "2019041728" ~ "40.4" ,
study_id == "2641033696" ~ "43.5" ,
study_id == "2391039025" ~ "39.3" ,
study_id == "1469044516" ~ "37.7" ,
.default = alb_surg,
),
) %>%
rename (
cci_age = age_ce7bf7,
cci_age.factor = age_ce7bf7.factor,
)
df_clean <- df_fix %>%
mutate (
age = structure (age, label = "Age" , units = "years" ),
bmi = structure (bmi, label = "BMI" , units = "kg/m\u{00B2}" ),
sex = structure (factor (sex, levels = c (0 , 1 ), labels = c ("Female" , "Male" )), label = "Sex" ),
sex.factor = structure (as.factor (sex.factor), label = "Gender" ),
cci_gt2 = structure (factor (ifelse (cci_total_sc > 2 , 1 , 0 ), levels = c (0 , 1 ), labels = c ("≤ 2" , "> 2" )),
label = "Charlson Comorbidity Index ≤2"
),
cci_total_sc = structure (as.integer (cci_total_sc), label = "Charlson Comorbidity Index score" ),
years_disease = structure (as.integer (years_disease), label = "Disease duration" , units = "years" ),
surg_durat = structure (as.integer (surg_durat), label = "Surgery duration" , units = "minutes" ),
asa_score = structure (factor (asa_score, levels = c (1 : 4 )), label = "ASA score" ),
dis_behavior = case_when (
(dis_beahviour___1 == 1 & dis_beahviour___2 == 0 ) ~ 0 ,
(dis_beahviour___1 == 0 & dis_beahviour___2 == 1 ) ~ 1 ,
(dis_beahviour___1 == 1 & dis_beahviour___2 == 1 ) ~ 2 ,
(dis_beahviour___1 == 0 & dis_beahviour___2 == 0 & dis_beahviour___3 == 1 ) ~ 3 ,
.default = NA ,
),
dis_behavior = structure (
factor (dis_behavior,
levels = c (0 , 1 , 2 , 3 ),
labels = c ("Stenotic" , "Fistulizing" , "Stenotic + fistulizing" , "None" )
),
label = "Disease behavior"
),
recurrence = structure (factor (recurrence, levels = c (0 , 1 ), labels = c ("No" , "Yes" )),
label = "Recurrence on previously operated site"
),
los_before = structure (as.integer (difftime (surg_date, admiss_date, units = "days" )),
label = "Length of stay before surgery, days"
),
los_after = structure (as.integer (difftime (disch_date, surg_date, units = "days" )),
label = "Length of stay after surgery, days"
),
los_total = structure (as.integer (difftime (disch_date, admiss_date, units = "days" )),
label = "Hospital length of stay, days"
),
laparoscopy = structure (factor (
laparoscopy,
levels = c (1 , 2 , 3 , 4 , 5 , 6 , 7 ),
labels = c (
"Laparoscopy" ,
"Laparoscopic converted to open" ,
"Hand-assisted" ,
"Open" ,
"Robotic" ,
"Robotic converted to laparoscopic" ,
"Robotic converted to open"
)
)),
surg_approach = structure (droplevels (laparoscopy), label = "Surgical approach" ),
surg_timing = structure (factor (surg_timing, levels = c (1 , 2 , 3 ), labels = c ("Elective" , "Urgent" , "Emergency" )),
label = "Surgical timing"
), # very few urgent and emergent...
surg_itu = structure (
factor (surg_itu,
levels = c (1 , 2 , 3 ),
labels = c ("No" , "Postop ICU scheduled" , "Postop ICU unexpected" )
),
label = "Intesive Care admission after surgery"
),
surg_disease_multi = case_when (
rowSums (across (starts_with ("location_disease___" ))) >= 2 ~ 1 ,
rowSums (across (starts_with ("location_disease___" ))) == 1 ~ 0 ,
rowSums (across (starts_with ("location_disease___" ))) == 0 ~ NA , # surgery for stoma closure usually
),
surg_disease_multi = structure (factor (surg_disease_multi, levels = c (0 , 1 ), labels = c ("No" , "Yes" )),
label = "Multiple localizations of disease requiring surgery"
),
location_disease___1 = structure (factor (location_disease___1, levels = c (0 , 1 )),
label = "terminal ileum"
),
location_disease___2 = structure (factor (location_disease___2, levels = c (0 , 1 )),
label = "ileum"
),
location_disease___3 = structure (factor (location_disease___3, levels = c (0 , 1 )),
label = "jejunum"
),
location_disease___4 = structure (factor (location_disease___4, levels = c (0 , 1 )),
label = "right colon"
),
location_disease___5 = structure (factor (location_disease___5, levels = c (0 , 1 )),
label = "transverse colon"
),
location_disease___6 = structure (factor (location_disease___6, levels = c (0 , 1 )),
label = "left colon"
),
location_disease___7 = structure (factor (location_disease___7, levels = c (0 , 1 )),
label = "rectum"
),
location_disease___8 = structure (factor (location_disease___8, levels = c (0 , 1 )),
label = "perianal"
),
location_disease___9 = structure (factor (location_disease___9, levels = c (0 , 1 )),
label = "upper GI including duodenum"
),
resection = ifelse (termileum_surg___1 == 1 | ileum_surg___1 == 1 | jej_surg___1 == 1 |
colon_surg___1 == 1 | ugi_surg___1 == 1 , 1 , 0 ),
stricturoplasty = ifelse (termileum_surg___2 == 1 | ileum_surg___2 == 1 | jej_surg___2 == 1 |
colon_surg___2 == 1 | ugi_surg___2 == 1 , 1 , 0 ),
fistulectomy = ifelse (ileum_surg___4 == 1 | jej_surg___4 == 1 | colon_surg___4 == 1 | ugi_surg___4 == 1 , 1 , 0 ),
perianal_surg = structure (factor (perianal_surg, levels = c (0 , 1 ), labels = c ("No" , "Yes" )),
label = "Perianal surgery"
),
stoma = structure (factor (stoma_typ, levels = c (0 : 6 ), labels = c (
"No stoma" ,
"Ileostomia loop" ,
"Ileostomia terminale" ,
"Ileostomia loop-end" ,
"Ileostomia a canna di fucile" ,
"Colostomia loop" ,
"Colostomia terminale"
)), label = "Type of stoma" ),
surg_procedure = structure (paste (
ifelse (termileum_surg___3, "resezione ileocecale" , NA_character_ ),
ifelse (resection, "resezione non ileocecale" , NA_character_ ),
ifelse (stricturoplasty, "stricturoplastica" , NA_character_ ),
ifelse (fistulectomy, "fistulectomia" , NA_character_ ),
ifelse (perianal_surg == "Yes" , "chirurgia perianale" , NA_character_ ),
case_when (
stoma == "No stoma" ~ NA_character_ ,
grepl ("terminale" , stoma) ~ "stomia terminale" ,
grepl ("loop|fucile" , stoma) ~ "stomia loop" ,
),
ifelse (termileum_surg___4 == 1 | ileum_surg___3 == 1 | jej_surg___3 == 1 |
colon_surg___3 == 1 | colon_surg___5 == 1 | ugi_surg___3 == 1 , "altre procedure" , NA_character_ ),
sep = " + "
), label = "Surgical procedure" ),
surg_procedure = glue:: trim (gsub (" \\ + NA|NA \\ + " , "" , surg_procedure)),
surg_procedure_simple = case_when (
termileum_surg___3 == 1 ~ 4 ,
resection == 1 ~ 3 ,
stricturoplasty == 1 | fistulectomy == 1 |
((termileum_surg___3 == 0 & resection == 0 | stricturoplasty == 0 & fistulectomy == 0 ) & perianal_surg == "Yes" ) ~ 2 ,
stoma_surg_close == 1 ~ 1 ,
termileum_surg___4 == 1 | ileum_surg___3 == 1 | jej_surg___3 == 1 |
colon_surg___3 == 1 | colon_surg___5 == 1 | ugi_surg___3 | stoma != "No stoma" ~ 0 ,
.default = NA ,
),
surg_procedure_simple = structure (factor (surg_procedure_simple, levels = c (0 : 4 ), labels = c (
"Other procedures" ,
"Stoma closure" ,
"Stricturoplasty, fistulectomy or perianal surgery" ,
"Resection (non ileocecal)" ,
"Resection ileocecal"
)), label = "Surgical procedure (simple)" ),
perforation = factor (perforation, levels = c (0 , 1 ), labels = c ("No" , "Yes" )),
abscess = structure (factor (abscess, levels = c (0 , 1 ), labels = c ("No" , "Yes" )),
label = "Abscess at surgery"
),
abscess_multi = case_when (
is.na (abscess) ~ NA ,
rowSums (across (starts_with ("abscess_location___" ))) >= 2 ~ 2 ,
rowSums (across (starts_with ("abscess_location___" ))) == 1 ~ 1 ,
rowSums (across (starts_with ("abscess_location___" ))) == 0 ~ 0 ,
.default = NA ,
),
abscess_multi = structure (
factor (abscess_multi,
levels = c (0 : 2 ),
labels = c ("No abscess" , "Single abscess" , "Multiple abscesses" )
),
label = "Abscesses at surgery"
),
abscess_location = structure (paste (
ifelse (abscess_location___1, sub (".*choice=(.*) \\ )" , " \\ 1" , label (abscess_location___1)), NA_character_ ), # abdominal wall
ifelse (abscess_location___2, sub (".*choice=(.*) \\ )" , " \\ 1" , label (abscess_location___2)), NA_character_ ), # mesentery
ifelse (abscess_location___3, sub (".*choice=(.*) \\ )" , " \\ 1" , label (abscess_location___3)), NA_character_ ), # intraparietal
ifelse (abscess_location___4, sub (".*choice=(.*) \\ )" , " \\ 1" , label (abscess_location___4)), NA_character_ ), # pelvic
ifelse (abscess_location___5, sub (".*choice=(.*) \\ )" , " \\ 1" , label (abscess_location___5)), NA_character_ ), # retroperitoneal
ifelse (abscess_location___6, sub (".*choice=(.*) \\ )" , " \\ 1" , label (abscess_location___6)), NA_character_ ), # other
sep = " + "
), label = "Location of abscesses" ),
abscess_location = glue:: trim (gsub ("( \\ + )?NA?( \\ + )?" , "" , abscess_location)),
training = structure (factor (training, levels = c (0 , 1 ), labels = c ("No" , "Yes" )),
label = "Training surgery (trainee performing part of all operation under supervision)"
),
po_death = structure (factor (po_death, levels = c (0 , 1 ), labels = c ("No" , "Yes" )),
label = "Death within 30 days from surgery"
),
surg_date = structure (as.Date (surg_date), label = "Surgery date" ),
po_inf_when = structure (as.Date (po_inf_when), label = "Date of post-surgery infection diagnosis" ),
# variable for time-to-infection in days
po_inf_time = structure (difftime (po_inf_when, surg_date, units = "days" ), label = "Time from surgery to first infection" ),
# variable for infection within 30d post surgery
po_inf_30d = case_when (
(po_inf_time >= 0 & po_inf_time <= 30 ) ~ 1 ,
# is.na(po_inf_yn) ~ NA,
.default = 0 ,
),
po_inf_30d = structure (
factor (po_inf_30d, levels = c (0 , 1 ), labels = c ("No" , "Yes" )),
label = "Any post-surgery infection within 30 days"
),
# new variable considering any case with previous major abdominal surgery
prev_surg_yn = case_when (
if_any (
c (
prev_abd_surg, # Previous abdominal surgery (EXCLUDING procedures for Crohn's)
prev_abd_surg_typ___3, # gynecologic procedure (including C section)
prev_abd_surg_typ___4, # gastric surgery
prev_abd_surg_typ___5, # colon surgery
prev_abd_surg_typ___6, # hepatic surgery
), ~ .x == 1
) ~ 1 ,
if_any (matches ("location_previous_crohn___[1-9]$" ), ~ . == 1 ) ~ 1 ,
location_previous_crohn___10 == 1 ~ 0 , # no previous Crohn surgery
if_all (
c (
prev_abd_surg, # Previous abdominal surgery (EXCLUDING procedures for Crohn's)
prev_abd_surg_typ___3, # gynecologic procedure (including C section)
prev_abd_surg_typ___4, # gastric surgery
prev_abd_surg_typ___5, # colon surgery
prev_abd_surg_typ___6, # hepatic surgery
matches ("location_previous_crohn___[1-9]$" ) # any Crohn surgery excluding 10 (none)
), ~ .x == 0 ,
) ~ 0 ,
.default = 0 ,
),
prev_surg_yn = structure (
factor (prev_surg_yn, levels = c (0 , 1 ), labels = c ("No" , "Yes" )),
label = "Any previous major abdominal surgery"
),
pre_op_atb_yn = structure (factor (pre_op_atb_yn, levels = c (0 , 1 ), labels = c ("No" , "Yes" )),
label = "Antibiotics within 4 weeks before surgery"
),
# steroid_surg_yn = case_when(
# (steroids_ongoing == 1 | ster_surg == 1) ~ 1, # steroids ongoing at time of surgery (from IBD or Medications)
# steroids_ongoing == 1 & if_any(matches("steroid_type___[1-4]"), ~ . == 1) ~ 1, # any type of steroids (from IBD medications) excluding topical
# (steroids_ongoing == 0 | ster_surg == 0) ~ 0,
# if_all(starts_with("steroid_type___"), ~ . == 0) ~ 0,
# .default = NA,
# ),
steroid_surg_yn = case_when (
steroids_ongoing == 1 & (
difftime (as.Date (surg_date), as.Date (steroid_start), units = c ("days" )) >= 14 |
difftime (as.Date (steroid_end), as.Date (steroid_start), units = c ("days" )) >= 14 |
is.na (steroid_start) | steroid_start == ""
) ~ 1 ,
steroids_ongoing == 0 | (steroids_ongoing == 1 & (
difftime (as.Date (surg_date), as.Date (steroid_start), units = c ("days" )) < 14 |
difftime (as.Date (steroid_end), as.Date (steroid_start), units = c ("days" )) < 14
)) ~ 0 ,
# steroid_suspended4w == 1 & (
# difftime(as.Date(surg_date), as.Date(steroid_start), units = c("days")) >= 14 |
# difftime(as.Date(steroid_end), as.Date(steroid_start), units = c("days")) >= 14) ~ 1,
.default = NA ,
),
steroid_surg_yn = structure (factor (steroid_surg_yn, levels = c (0 , 1 ), labels = c ("No" , "Yes" )),
label = "Any oral steroids ongoing at surgery"
),
steroid_surg_dose = case_when (
# ster_surg == 1 & ster_surg_dose == 1 ~ 3, # prednisone > 20 mg/die or equivalent (from Medications) -- checked
# ster_surg == 1 & ster_surg_dose == 0 ~ 2, # prednisone < 20 mg/die or equivalent (from Medications) -- checked
# ster_surg == 1 & is.na(ster_surg_dose) ~ 1, # steroids ongoing without dosage (from Medications) -- checked
# steroids_ongoing == 1 required as type includes stopped within 4 and 8 weeks of surgery
steroid_surg_yn == "Yes" & steroid_type___1 == 1 ~ 3 , # prednisone > 20 mg/die or equivalent (from IBD medications)
steroid_surg_yn == "Yes" & steroid_type___2 == 1 ~ 2 , # prednisone < 20 mg/die or equivalent (from IBD medications)
# Beclomethasone group is empty
steroid_surg_yn == "Yes" & (steroid_type___3 == 1 | steroid_type___4 == 1 ) ~ 1 , # beclomethasone or budesonide (from IBD medications)
# ignoring steroid_type___5 -- topical steroid
steroid_surg_yn == "No" ~ 0 , # no steroids
.default = NA ,
),
steroid_surg_dose = structure (factor (
steroid_surg_dose,
levels = c (0 , 1 , 2 , 3 ),
labels = c ("No steroids" , "Other steroid" , "Prednisone < 20 mg/day" , "Prednisone > 20 mg/day" )
), label = "Dose of oral steroids ongoing at surgery" ),
# steroid_surg_time = as.integer(ster_surg_time),
inflix_start_weeks = structure (round (difftime (as.Date (surg_date), as.Date (inflix_start), units = c ("weeks" ))),
label = "Weeks from start of infliximab to surgery"
),
adalim_start_weeks = structure (round (difftime (as.Date (surg_date), as.Date (adalim_start), units = c ("weeks" ))),
label = "Weeks from start of adalimumab to surgery"
),
vedoli_start_weeks = structure (round (difftime (as.Date (surg_date), as.Date (vedo_start), units = c ("weeks" ))),
label = "Weeks from start of vedolizumab to surgery"
),
usteki_start_weeks = structure (round (difftime (as.Date (surg_date), as.Date (ustek_start), units = c ("weeks" ))),
label = "Weeks from start of ustekinumab to surgery"
),
inflix_end_weeks = structure (round (difftime (as.Date (surg_date), as.Date (inflix_end), units = c ("weeks" ))),
label = "Weeks from last infliximab dose to surgery"
),
adalim_end_weeks = structure (round (difftime (as.Date (surg_date), as.Date (adalim_end), units = c ("weeks" ))),
label = "Weeks from last adalimumab dose to surgery"
),
vedoli_end_weeks = structure (round (difftime (as.Date (surg_date), as.Date (vedo_end), units = c ("weeks" ))),
label = "Weeks from last vedolizumab dose to surgery"
),
usteki_end_weeks = structure (round (difftime (as.Date (surg_date), as.Date (ustek_end), units = c ("weeks" ))),
label = "Weeks from last ustekinumab dose to surgery"
),
# only include last dose of biologics from 24 to 8 weeks (6-2 months) before surgery vs within 8 weeks (2 months) from surgery
# biologic_surg_8w = case_when(
# ((biologic == 1 & (preop_bio_current == 0 & preop_bio_current_weekstop <= 8) | preop_bio_current_weekstop <= 8) |
# (inflix_end_weeks <= 8 | preop_ifx_current_weekstop <= 8) |
# (adalim_end_weeks <= 8 | preop_ada_current_weekstop <= 8) |
# (vedoli_end_weeks <= 8 | preop_ved_current_weekstop <= 8) |
# (usteki_end_weeks <= 8 | preop_ust_current_weekstop <= 8)) ~ 1,
# ((biologic == 1 & (preop_bio_current_weekstop > 8 & preop_bio_current_weekstop <= 24)) |
# ((inflix_end_weeks > 8 & inflix_end_weeks <= 24) | (preop_ifx_current_weekstop > 8 & preop_ifx_current_weekstop <= 24)) |
# ((adalim_end_weeks > 8 & adalim_end_weeks <= 24) | (preop_ada_current_weekstop > 8 & preop_ada_current_weekstop <= 24)) |
# ((vedoli_end_weeks > 8 & vedoli_end_weeks <= 24) | (preop_ved_current_weekstop > 8 & preop_ada_current_weekstop <= 24)) |
# ((usteki_end_weeks > 8 & usteki_end_weeks <= 24) | (preop_ust_current_weekstop > 8 & preop_ust_current_weekstop <= 24))) ~ 0,
# .default = NA
# # ),
# biologic_surg_8w = structure(factor(biologic_surg_8w, levels = c(0, 1), labels = c("No", "Yes")),
# label = "Last dose of any biologic within 8 weeks from surgery (vs last dose 2-6 months before)"),
across (matches ("(inflix|adalim|vedo|ustek)_(start|end)$" ), as.Date),
biologic_surg_8w_yn = case_when (
# ((biologic == 1 & (preop_bio_current == 0 & preop_bio_current_weekstop <= 8) | preop_bio_current_weekstop <= 8) |
# (preop_ifx_current_weekstop <= 8 | preop_ada_current_weekstop <= 8 |
# preop_ved_current_weekstop <= 8) | preop_ust_current_weekstop <= 8)) ~ 1,
# biologic == 0 ~ 0,
# preop_bio_current_weekstop > 8 |
# preop_ifx_current_weekstop > 8 |
# preop_ada_current_weekstop > 8 |
# preop_ved_current_weekstop > 8 |
# preop_ust_current_weekstop > 8 ~ 0,
previous_biologics == 0 ~ 0 ,
(inflix_end_weeks <= 8 | (inflix_start_weeks >= 0 & is.na (inflix_end_weeks))) |
(adalim_end_weeks <= 8 | (adalim_start_weeks >= 0 & is.na (adalim_end_weeks))) |
(vedoli_end_weeks <= 8 | (vedoli_start_weeks >= 0 & is.na (vedoli_end_weeks))) |
(usteki_end_weeks <= 8 | (usteki_start_weeks >= 0 & is.na (usteki_end_weeks))) ~ 1 ,
# (is.na(inflix_end_weeks) & if_all(starts_with("discont_inflix___"), ~ .x == 0)))) |
# (is.na(adalim_end_weeks) & if_all(starts_with("discont_adalim___"), ~ .x == 0)))) |
# (is.na(vedoli_end_weeks) & if_all(starts_with("discont_vedoliz___"), ~ .x == 0)))) |
# (is.na(usteki_end_weeks) & if_all(starts_with("discont_ustek___"), ~ .x == 0)))) ~ 1,
inflix_start_weeks < 0 | adalim_start_weeks < 0 | vedoli_start_weeks < 0 | usteki_start_weeks < 0 ~ 0 ,
inflix_end_weeks > 8 | adalim_end_weeks > 8 | vedoli_end_weeks > 8 | usteki_end_weeks > 8 ~ 0 ,
# (is.na(inflix_end) & if_any(starts_with("discont_inflix___"), ~ .x == 1)) |
# (is.na(adalim_end) & if_any(starts_with("discont_adalim___"), ~ .x == 1)) |
# (is.na(vedo_end) & if_any(starts_with("discont_vedoliz___"), ~ .x == 1)) |
# (is.na(ustek_end) & if_any(starts_with("discont_ustek___"), ~ .x == 1)) ~ 0,
# (biologic == 1 & preop_bio_current == 1) |
# (preop_multi_bio_yn == 1 & if_all(matches("multi_(ifx|ada|ved|ust)_current"), ~ is.na(.x) | .x == 1)) ~ 0,
.default = NA ,
),
biologic_surg_8w_yn = structure (factor (biologic_surg_8w_yn, levels = c (0 , 1 ), labels = c ("No" , "Yes" )),
label = "Exposed to biologics within 8 weeks from surgery vs more or never"
),
infliximab_ongoing = structure (factor (case_when (
# previous_biologics == 0 ~ 0,
# biologic_speficy___1 == 0 ~ 0,
inflix_start_weeks < 0 | inflix_end_weeks > 8 ~ 0 ,
inflix_end_weeks <= 8 ~ 1 ,
! (is.na (inflix_start)) & is.na (inflix_end) & if_all (starts_with ("discont_inflix___" ), ~ .x == 0 ) ~ 1 ,
.default = NA ,
)), label = "Infliximab within 8 weeks of surgery vs more" ),
adalimumab_ongoing = structure (factor (case_when (
# previous_biologics == 0 ~ 0,
# biologic_specify___2 == 0 ~ 0,
adalim_start_weeks < 0 | adalim_end_weeks > 8 ~ 0 ,
adalim_end_weeks <= 8 ~ 1 ,
! (is.na (adalim_start)) & is.na (adalim_end) & if_all (starts_with ("discont_adalim___" ), ~ .x == 0 ) ~ 1 ,
.default = NA ,
)), label = "Adalimumab within 8 weeks of surgery vs more" ),
vedolizumab_ongoing = structure (factor (case_when (
# previous_biologics == 0 ~ 0,
# biologic_specify___3 == 0 ~ 0,
vedoli_start_weeks < 0 | vedoli_end_weeks > 8 ~ 0 ,
vedoli_end_weeks <= 8 ~ 1 ,
! (is.na (vedo_start)) & is.na (vedo_end) & if_all (starts_with ("discont_vedoliz___" ), ~ .x == 0 ) ~ 1 ,
.default = NA ,
)), label = "Vedolizumab within 8 weeks of surgery vs more" ),
ustekinumab_ongoing = structure (factor (case_when (
# previous_biologics == 0 ~ 0,
# biologic_specify___3 == 0 ~ 0,
usteki_start_weeks < 0 | usteki_end_weeks > 8 ~ 0 ,
usteki_end_weeks <= 8 ~ 1 ,
! (is.na (ustek_start)) & is.na (ustek_end) & if_all (starts_with ("discont_ustek___" ), ~ .x == 0 ) ~ 1 ,
.default = NA ,
)), label = "Ustekinumab within 8 weeks of surgery vs more" ),
biologic_surg_8w_new = structure (factor (case_when (
previous_biologics == 0 ~ 0 ,
if_any (matches ("(infliximab|adalimumab|ustekinumab|vedolizumab)_ongoing" ), ~ .x == 1 ) ~ 1 ,
if_all (matches ("(infliximab|adalimumab|ustekinumab|vedolizumab)_ongoing" ), ~ is.na (.x)) ~ NA ,
if_all (matches ("(infliximab|adalimumab|ustekinumab|vedolizumab)_ongoing" ), ~ .x == 0 | is.na (.x)) ~ 0 ,
.default = NA ,
), levels = c (0 : 1 ), labels = c ("No" , "Yes" )), label = "Exposed to biologics within 8 weeks from surgery vs all others" ),
# aza_end_weeks = structure(difftime(as.Date(aza_end), as.Date(surg_date), units = c("weeks")), label = "Weeks from last azathioprine dose to surgery"),
# aza_start_weeks = structure(difftime(as.Date(aza_start), as.Date(surg_date), units = c("weeks")), label = "Weeks from first azathioprine dose to surgery"),
# aza_surg_yn = case_when(
# (aza_surg == 1 | aza_prev_stop == 0 | (aza_end_weeks >= 0 & aza_end_weeks <= 16) | aza_start_weeks >= 12) ~ 1,
# (aza_surg == 0 | aza_prev_stop == 1 | aza_end_weeks > 16 | aza_end_weeks < 0 | aza_start_weeks < 12) ~ 0,
# .default = NA
# ),
# aza_surg_yn = structure(factor(aza_surg_yn, levels = c(0, 1), labels = c("No", "Yes")),
# label = "Last 5-ASA within 4 months from surgery"),
inflix_surg_8w = case_when (
inflix_start_weeks >= 0 & (inflix_end_weeks <= 8 |
(is.na (inflix_end_weeks) & if_all (starts_with ("discont_inflix___" ), ~ .x == 0 ))) ~ 1 ,
is.na (inflix_start_weeks) & inflix_end_weeks <= 8 ~ 1 ,
inflix_end_weeks > 8 & inflix_end_weeks <= 24 ~ 0 ,
# preop_bio_typ == 0 & preop_bio_current_weekstop <= 8 ~ 1,
# preop_ifx_current_weekstop <= 8 ~ 1,
# preop_bio_typ == 0 & preop_bio_current_weekstop > 8 & preop_bio_current_weekstop <= 24 ~ 0,
# preop_ifx_current_weekstop > 8 & preop_ifx_current_weekstop <= 24 ~ 0,
.default = NA ,
),
inflix_surg_8w = structure (factor (inflix_surg_8w, levels = c (0 , 1 ), labels = c ("No" , "Yes" )),
label = "Infliximab within 8 weeks from surgery (vs last dose 2-6 months before)"
),
adalim_surg_8w = case_when (
adalim_start_weeks >= 0 & (adalim_end_weeks <= 8 |
(is.na (adalim_end_weeks) & if_all (starts_with ("discont_adalim___" ), ~ .x == 0 ))) ~ 1 ,
is.na (adalim_start_weeks) & adalim_end_weeks <= 8 ~ 1 ,
adalim_end_weeks > 8 & adalim_end_weeks <= 24 ~ 0 ,
# preop_bio_typ == 1 & preop_bio_current_weekstop <= 8 ~ 1,
# preop_ada_current_weekstop <= 8 ~ 1,
# preop_bio_typ == 1 & preop_bio_current_weekstop > 8 & preop_bio_current_weekstop <= 24 ~ 0,
# preop_ada_current_weekstop > 8 & preop_ifx_current_weekstop <= 24 ~ 0,
.default = NA ,
),
adalim_surg_8w = structure (factor (adalim_surg_8w, levels = c (0 , 1 ), labels = c ("No" , "Yes" )),
label = "Adalimumab within 8 weeks from surgery (vs last dose 2-6 months before)"
),
vedoli_surg_8w = case_when (
vedoli_start_weeks >= 0 & (vedoli_end_weeks <= 8 |
(is.na (vedoli_end_weeks) & if_all (starts_with ("discont_ustek___" ), ~ .x == 0 ))) ~ 1 ,
is.na (vedoli_start_weeks) & vedoli_end_weeks <= 8 ~ 1 ,
vedoli_end_weeks > 8 & vedoli_end_weeks <= 24 ~ 0 ,
# preop_bio_typ == 2 & preop_bio_current_weekstop <= 8 ~ 1,
# preop_ved_current_weekstop <= 8 ~ 1,
# preop_bio_typ == 2 & preop_bio_current_weekstop > 8 & preop_bio_current_weekstop <= 24 ~ 0,
# preop_ved_current_weekstop > 8 & preop_ved_current_weekstop <= 24 ~ 0,
.default = NA ,
),
vedoli_surg_8w = structure (factor (vedoli_surg_8w, levels = c (0 , 1 ), labels = c ("No" , "Yes" )),
label = "Vedolizumab within 8 weeks from surgery (vs last dose 2-6 months before)"
),
usteki_surg_8w = case_when (
usteki_start_weeks >= 0 & (usteki_end_weeks <= 8 |
(is.na (usteki_end_weeks) & if_all (starts_with ("discont_vedoliz___" ), ~ .x == 0 ))) ~ 1 ,
is.na (usteki_start_weeks) & usteki_end_weeks <= 8 ~ 1 ,
usteki_end_weeks > 8 & usteki_end_weeks <= 24 ~ 0 ,
# preop_bio_typ == 3 & preop_bio_current_weekstop <= 8 ~ 1,
# preop_ust_current_weekstop <= 8 ~ 1,
# preop_bio_typ == 3 & preop_bio_current_weekstop > 8 & preop_bio_current_weekstop <= 24 ~ 0,
# preop_ust_current_weekstop > 8 & preop_ust_current_weekstop <= 24 ~ 0,
.default = NA ,
),
usteki_surg_8w = structure (factor (usteki_surg_8w, levels = c (0 , 1 ), labels = c ("No" , "Yes" )),
label = "Ustekinumab within 8 weeks from surgery (vs last dose 2-6 months before)"
),
biologics_num = case_when (
previous_biologics == 1 ~ rowSums (across (starts_with ("biologic_specify___" ), ~ as.integer (.x))),
# biologic == 1 & preop_multi_bio_yn == 0 ~ 1,
# biologic == 1 & preop_multi_bio_yn == 1 ~ 1 + rowSums(across(starts_with("preop_multi_bio_typ___"), ~ as.integer(.x))),
previous_biologics == 0 ~ 0 , # | biologic == 0 ~ 0,
.default = NA ,
),
biologics_num = structure (factor (biologics_num, levels = c (0 : 4 ), labels = c ("0" , "1" , "2" , "3" , "4" )),
label = "Number of biologics before surgery"
),
previous_biologics = structure (factor (previous_biologics, levels = c (0 , 1 ), labels = c ("No" , "Yes" )),
label = "Any biologic in patient history"
),
alb_surg = sub ("," , "." , alb_surg),
alb_surg = structure (ifelse (as.double (alb_surg) > 10 , as.double (alb_surg) / 10 , as.double (alb_surg)),
label = "Albumin at surgery" , units = "g/dL"
),
) %>%
filter (
age >= 18 &
! is.na (po_inf_yn) &
study_id != "2019041728" & # patient data no longer available
study_id != "2071024413" & # chirurgia oncologica
los_total >= 0 & los_total < 200 & # 2110024554 for missing dimiss_date
los_before >= 0 & los_after >= 0
)