context("test-drug_tx_by_visit")
testing_code <- quote({
expect_true(all(c("patient_id",
"visit_date",
"drug_tx_prescribed") %in% names(out)))
# all rows are unique
expect_equal(nrow(unique(out[c('patient_id', 'visit_date')])),
nrow(out))
# expect all rows to have a valid patient_id
expect_false(any(is.na(out$patient_id)))
expect_true(nrow(out) <= nrow(data$hcv))
expect_false(any(grepl("FDC", out$drug_tx_prescribed)))
expect_true(all(di$patient_id[di$tx_decision %in%
c(
"Initiation/ Re-initiation",
"Modification of regimen",
"Modification due to adverse event",
"Modification due to other reasons"
)] %in%
out$patient_id))
expect_equal(nrow(unique(out[c("patient_id", "visit_date")])), nrow(out))
})
# read in test data
data <- system.file("testdata", "testdata-drug_tx_by_visit.rds", package = "hisreportr") %>%
readRDS()
# Test HCV data
di <- data$hcv
out <- drug_tx_by_visit(di)
test_that("HCV correct", eval(testing_code))
# Test HIV data
di <- data$hiv
out <- drug_tx_by_visit(di)
test_that("HIV correct", eval(testing_code))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.