diff --git a/R/who-nrvess.r b/R/who-nrvess.r index b06459b..e407f86 100644 --- a/R/who-nrvess.r +++ b/R/who-nrvess.r @@ -31,10 +31,12 @@ #' census_who <- who_nrevss("census") #' state_who <- who_nrevss("state") #' } -who_nrevss <- function(region=c("national", "hhs", "census", "state")) { +who_nrevss <- function(region=c("national", "hhs", "census", "state"), years=NULL) { region <- match.arg(tolower(region), c("national", "hhs", "census", "state")) + meta <- jsonlite::fromJSON("https://gis.cdc.gov/grasp/flu2/GetPhase02InitApp?appVersion=Public") + list( AppVersion = "Public", DatasourceDT = list(list(ID = 1, Name = "WHO_NREVSS")), @@ -49,8 +51,27 @@ who_nrevss <- function(region=c("national", "hhs", "census", "state")) { state = { lapply(1:59, function(i) list(ID=i, Name=as.character(i))) } ) - seasons <- 37:((unclass(as.POSIXlt(Sys.time()))[["year"]] + 1900) - 1960) - params$SeasonsDT <- lapply(seasons, function(i) list(ID=i, Name=as.character(i))) + available_seasons <- sort(meta$seasons$seasonid) + + if (is.null(years)) { # ALL YEARS + years <- available_seasons + } else { # specified years or seasons or a mix + + years <- as.numeric(years) + years <- ifelse(years > 1996, years - 1960, years) + years <- sort(unique(years)) + years <- years[years %in% available_seasons] + + if (length(years) == 0) { + years <- rev(sort(meta$seasons$seasonid))[1] + curr_season_descr <- meta$seasons[meta$seasons$seasonid == years, "description"] + message(sprintf("No valid years specified, defaulting to this flu season => ID: %s [%s]", + years, curr_season_descr)) + } + + } + + params$SeasonsDT <- lapply(years, function(i) list(ID=i, Name=as.character(i))) tf <- tempfile(fileext = ".zip") td <- tempdir() diff --git a/man/who_nrevss.Rd b/man/who_nrevss.Rd index 60a4536..9ef038f 100644 --- a/man/who_nrevss.Rd +++ b/man/who_nrevss.Rd @@ -4,7 +4,7 @@ \alias{who_nrevss} \title{Retrieve WHO/NREVSS Surveillance Data} \usage{ -who_nrevss(region = c("national", "hhs", "census", "state")) +who_nrevss(region = c("national", "hhs", "census", "state"), years = NULL) } \arguments{ \item{region}{one of "\code{national}", "\code{hhs}", "\code{census}", or "\code{state}"}