2018-07-23 14:14:03 +02:00
|
|
|
context("first_isolate.R")
|
2018-03-27 17:43:42 +02:00
|
|
|
|
|
|
|
test_that("first isolates work", {
|
2018-08-02 13:15:45 +02:00
|
|
|
# septic_patients contains 1331 out of 2000 first isolates
|
2018-04-02 16:05:09 +02:00
|
|
|
expect_equal(
|
2018-06-19 10:05:38 +02:00
|
|
|
sum(
|
|
|
|
first_isolate(tbl = septic_patients,
|
2018-04-02 16:05:09 +02:00
|
|
|
col_date = "date",
|
|
|
|
col_patient_id = "patient_id",
|
|
|
|
col_bactid = "bactid",
|
2018-07-25 14:17:04 +02:00
|
|
|
info = TRUE),
|
2018-07-02 09:34:20 +02:00
|
|
|
na.rm = TRUE),
|
2018-08-02 13:15:45 +02:00
|
|
|
1331)
|
2018-06-19 10:05:38 +02:00
|
|
|
|
2018-08-02 13:15:45 +02:00
|
|
|
# septic_patients contains 1426 out of 2000 first *weighted* isolates
|
2018-06-19 10:05:38 +02:00
|
|
|
expect_equal(
|
|
|
|
suppressWarnings(
|
|
|
|
sum(
|
|
|
|
first_isolate(tbl = septic_patients %>% mutate(keyab = key_antibiotics(.)),
|
|
|
|
col_date = "date",
|
|
|
|
col_patient_id = "patient_id",
|
|
|
|
col_bactid = "bactid",
|
|
|
|
col_keyantibiotics = "keyab",
|
|
|
|
type = "keyantibiotics",
|
|
|
|
info = TRUE),
|
|
|
|
na.rm = TRUE)),
|
2018-08-02 13:15:45 +02:00
|
|
|
1426)
|
|
|
|
# and 1430 when using points
|
2018-07-02 09:34:20 +02:00
|
|
|
expect_equal(
|
|
|
|
suppressWarnings(
|
|
|
|
sum(
|
|
|
|
first_isolate(tbl = septic_patients %>% mutate(keyab = key_antibiotics(.)),
|
|
|
|
col_date = "date",
|
|
|
|
col_patient_id = "patient_id",
|
|
|
|
col_bactid = "bactid",
|
|
|
|
col_keyantibiotics = "keyab",
|
|
|
|
type = "points",
|
|
|
|
info = TRUE),
|
|
|
|
na.rm = TRUE)),
|
2018-08-02 13:15:45 +02:00
|
|
|
1430)
|
2018-04-03 11:08:31 +02:00
|
|
|
|
2018-08-02 13:15:45 +02:00
|
|
|
# septic_patients contains 1176 out of 2000 first non-ICU isolates
|
2018-04-20 13:45:34 +02:00
|
|
|
expect_equal(
|
|
|
|
sum(
|
2018-06-19 10:05:38 +02:00
|
|
|
first_isolate(septic_patients,
|
|
|
|
col_bactid = "bactid",
|
|
|
|
col_date = "date",
|
|
|
|
col_patient_id = "patient_id",
|
|
|
|
col_icu = "ward_icu",
|
|
|
|
info = TRUE,
|
|
|
|
icu_exclude = TRUE),
|
|
|
|
na.rm = TRUE),
|
2018-08-02 13:15:45 +02:00
|
|
|
1176)
|
2018-04-20 13:45:34 +02:00
|
|
|
|
2018-04-03 11:08:31 +02:00
|
|
|
# set 1500 random observations to be of specimen type 'Urine'
|
|
|
|
random_rows <- sample(x = 1:2000, size = 1500, replace = FALSE)
|
2018-06-19 10:05:38 +02:00
|
|
|
expect_lt(
|
|
|
|
sum(
|
|
|
|
first_isolate(tbl = mutate(septic_patients,
|
|
|
|
specimen = if_else(row_number() %in% random_rows,
|
|
|
|
"Urine",
|
2018-07-25 14:17:04 +02:00
|
|
|
"Other")),
|
2018-06-19 10:05:38 +02:00
|
|
|
col_date = "date",
|
|
|
|
col_patient_id = "patient_id",
|
|
|
|
col_bactid = "bactid",
|
|
|
|
col_specimen = "specimen",
|
|
|
|
filter_specimen = "Urine",
|
|
|
|
info = TRUE),
|
|
|
|
na.rm = TRUE),
|
2018-04-03 11:08:31 +02:00
|
|
|
1501)
|
2018-07-02 09:34:20 +02:00
|
|
|
# same, but now exclude ICU
|
|
|
|
expect_lt(
|
|
|
|
sum(
|
|
|
|
first_isolate(tbl = mutate(septic_patients,
|
|
|
|
specimen = if_else(row_number() %in% random_rows,
|
|
|
|
"Urine",
|
2018-07-25 14:17:04 +02:00
|
|
|
"Other")),
|
2018-07-02 09:34:20 +02:00
|
|
|
col_date = "date",
|
|
|
|
col_patient_id = "patient_id",
|
|
|
|
col_bactid = "bactid",
|
|
|
|
col_specimen = "specimen",
|
|
|
|
filter_specimen = "Urine",
|
|
|
|
col_icu = "ward_icu",
|
|
|
|
icu_exclude = TRUE,
|
|
|
|
info = TRUE),
|
|
|
|
na.rm = TRUE),
|
|
|
|
1501)
|
2018-03-27 17:43:42 +02:00
|
|
|
})
|