1
0
mirror of https://github.com/msberends/AMR.git synced 2025-07-08 09:11:51 +02:00

atc_groups

This commit is contained in:
2018-06-19 10:05:38 +02:00
parent 0a5898b17d
commit bdc860e29c
14 changed files with 234 additions and 92 deletions

View File

@ -3,6 +3,9 @@ context("atc.R")
test_that("atc_property works", {
expect_equal(tolower(atc_property("J01CA04", property = "Name")), "amoxicillin")
expect_equivalent(atc_property("J01CA04", "DDD"), 1)
expect_equal(length(atc_property("J01CA04", property = "Groups")), 4)
expect_error(atc_property("J01CA04", property = c(1:5)))
expect_error(atc_property("J01CA04", administration = c(1:5)))
})
test_that("abname works", {

View File

@ -8,46 +8,57 @@ test_that("keyantibiotics work", {
})
test_that("first isolates work", {
# septic_patients contains 1960 out of 2000 first isolates
#septic_ptns <- septic_patients
expect_equal(sum(first_isolate(tbl = septic_patients,
col_date = "date",
col_patient_id = "patient_id",
col_bactid = "bactid",
info = FALSE)), 1960)
# septic_patients contains 1962 out of 2000 first *weighted* isolates
# septic_patients contains 1959 out of 2000 first isolates
expect_equal(
suppressWarnings(sum(
first_isolate(tbl = septic_patients %>% mutate(keyab = key_antibiotics(.)),
sum(
first_isolate(tbl = septic_patients,
col_date = "date",
col_patient_id = "patient_id",
col_bactid = "bactid",
col_keyantibiotics = "keyab",
type = "keyantibiotics",
info = TRUE))),
1962)
info = FALSE),
na.rm = TRUE), 1959)
# septic_patients contains 1733 out of 2000 first non-ICU isolates
# septic_patients contains 1961 out of 2000 first *weighted* isolates
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)),
1961)
# septic_patients contains 1732 out of 2000 first non-ICU isolates
expect_equal(
sum(
first_isolate(septic_patients, col_bactid = "bactid", col_date = "date", col_patient_id = "patient_id", col_icu = "ward_icu", info = TRUE, icu_exclude = TRUE)),
1733
)
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),
1732)
# set 1500 random observations to be of specimen type 'Urine'
random_rows <- sample(x = 1:2000, size = 1500, replace = FALSE)
expect_lt(sum(
first_isolate(tbl = mutate(septic_patients,
specimen = if_else(row_number() %in% random_rows,
"Urine",
"Unknown")),
col_date = "date",
col_patient_id = "patient_id",
col_bactid = "bactid",
col_specimen = "specimen",
filter_specimen = "Urine",
info = TRUE)),
expect_lt(
sum(
first_isolate(tbl = mutate(septic_patients,
specimen = if_else(row_number() %in% random_rows,
"Urine",
"Unknown")),
col_date = "date",
col_patient_id = "patient_id",
col_bactid = "bactid",
col_specimen = "specimen",
filter_specimen = "Urine",
info = TRUE),
na.rm = TRUE),
1501)
})