|
|
@ -10,6 +10,12 @@ |
|
|
|
#' |
|
|
|
#' @md |
|
|
|
#' @param region one of "`national`", "`hhs`", "`census`", or "`state`" |
|
|
|
#' @param years a vector of years to retrieve data for (i.e. `2014` for CDC |
|
|
|
#' flu season 2014-2015). CDC has data for this API going back to 1997. |
|
|
|
#' Default value (`NULL`) means retrieve **all** years. NOTE: if you |
|
|
|
#' happen to specify a 2-digit season value (i.e. `57` == 2017-2018) |
|
|
|
#' the function is smart enough to retrieve by season ID vs convert that |
|
|
|
#' to a year. |
|
|
|
#' @references |
|
|
|
#' - [CDC FluView Portal](https://gis.cdc.gov/grasp/fluview/fluportaldashboard.html) |
|
|
|
#' - [ILINet Portal](https://wwwn.cdc.gov/ilinet/) (Login required) |
|
|
@ -26,10 +32,12 @@ |
|
|
|
#' c("national", "hhs", "census", "state"), |
|
|
|
#' ~ilinet(.x) %>% readr::type_convert()) |
|
|
|
#' } |
|
|
|
ilinet <- function(region=c("national", "hhs", "census", "state")) { |
|
|
|
ilinet <- 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 = "ILINet")), |
|
|
@ -43,8 +51,27 @@ ilinet <- 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() |
|
|
|