Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions R/alert_functions.R
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,14 @@ pipe_infodengue <- function(cities, cid10="A90", datarelatorio, finalday = NULL,

.as_legacy_alert_objects <- function(result) {
data <- result$data
diseases <- unique(c(as.character(data$CID10),
as.character(result$parameters$cid10)))
if (!"CID10" %in% names(data) ||
!"cid10" %in% names(result$parameters) ||
length(diseases) != 1L || anyNA(diseases) || any(!nzchar(diseases))) {
stop("The legacy adapter requires exactly one disease in data and parameters.",
call. = FALSE)
}
groups <- split(seq_len(nrow(data)), factor(data$cidade,
levels = unique(data$cidade)))
legacy <- lapply(names(groups), function(city) {
Expand Down
10 changes: 10 additions & 0 deletions tests/testthat/test-legacy-disease-guard.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
test_that("legacy adapter rejects mixed or inconsistent disease results", {
result <- review_result()
mixed <- result
mixed$data$CID10[1] <- "A92.0"
expect_error(AlertTools:::.as_legacy_alert_objects(mixed), "exactly one disease")
inconsistent <- result
inconsistent$parameters$cid10 <- "A92.0"
expect_error(AlertTools:::.as_legacy_alert_objects(inconsistent), "exactly one disease")
expect_s3_class(AlertTools:::.as_legacy_alert_objects(result)[[1]], "alerta")
})
Loading