Skip to content
Merged
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
7 changes: 5 additions & 2 deletions R/alert_functions.R
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,8 @@ fouralert <- function(obj, crit, miss="last",dy=4){
#'@param dataini "notif" (default) or "sinpri"
#'@param writedb TRUE if it should write into the database, default is FALSE.
#'@param datasource posgreSQL connection to project's database
#'@param firstday First date of the notification series passed to getCases().
#' Defaults to 2018-01-01.
#'@return data.frame with the week condition and the number of weeks within the
#'last lag weeks with conditions = TRUE.
#'@examples
Expand All @@ -273,7 +275,7 @@ fouralert <- function(obj, crit, miss="last",dy=4){
pipe_infodengue <- function(cities, cid10="A90", datarelatorio, finalday = Sys.Date(),
iniSE = 201001, nowcasting="none", narule=NULL,
writedb = FALSE, datasource = con, completetail = NA,
dataini = "notific"){
dataini = "notific", firstday = as.Date("2018-01-01")){


if(missing(datarelatorio)) {
Expand Down Expand Up @@ -312,7 +314,8 @@ pipe_infodengue <- function(cities, cid10="A90", datarelatorio, finalday = Sys.D
message("getCli done")
# Reading Cases
print("Obtendo dados de notificacao ...")
casos <- getCases(cities, lastday = finalday, cid10 = cid10, type = "all", # novo
casos <- getCases(cities, lastday = finalday, firstday = firstday,
cid10 = cid10, type = "all", # novo
dataini = dataini, completetail = completetail)
message("getCases done")
casos$inc <- casos$casos/casos$pop*100000
Expand Down
6 changes: 5 additions & 1 deletion man/pipe_infodengue.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

41 changes: 41 additions & 0 deletions tests/testthat/test-pipe-infodengue-firstday.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
test_that("pipe_infodengue keeps the source default and forwards an override", {
expect_identical(eval(formals(pipe_infodengue)$firstday), as.Date("2018-01-01"))

calls <- list()
local_mocked_bindings(
read.parameters = function(cities, cid10) {
data.frame(municipio_geocodigo = cities)
},
getClima = function(...) data.frame(),
getCases = function(cities, lastday, firstday, cid10, type,
dataini, completetail) {
calls[[length(calls) + 1L]] <<- list(
cities = cities, lastday = lastday, firstday = firstday,
cid10 = cid10, type = type, dataini = dataini,
completetail = completetail
)
stop("captured getCases call")
},
.package = "AlertTools"
)

report_end <- as.Date("2026-08-01")
expect_error(pipe_infodengue(2201919, finalday = report_end),
"captured getCases call")
expect_identical(calls[[1L]]$firstday, as.Date("2018-01-01"))
expect_identical(calls[[1L]]$lastday, report_end)

historical_start <- as.Date("2010-01-03")
expect_error(pipe_infodengue(2201919, finalday = report_end,
firstday = historical_start),
"captured getCases call")
expect_identical(calls[[2L]]$firstday, historical_start)
expect_identical(calls[[2L]]$cid10, "A90")
expect_identical(calls[[2L]]$type, "all")

# The original positional arguments still end at dataini.
expect_error(pipe_infodengue(2201919, "A90", 202630, report_end,
201001, "none", NULL, FALSE, NULL, NA,
"notific"), "captured getCases call")
expect_identical(calls[[3L]]$firstday, as.Date("2018-01-01"))
})