You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

80 lines
2.9 KiB

  1. #' Retrieve weekly state-level ILI indicators per-state for a given season
  2. #'
  3. #' @md
  4. #' @param season_start_year numeric; start year for flu season (e.g. 2017 for 2017-2018 season)
  5. #' @references
  6. #' - [ILI Activity Indicator Map Portal](https://gis.cdc.gov/grasp/fluview/main.html)
  7. #' @note These statistics use the proportion of outpatient visits to healthcare providers
  8. #' for influenza-like illness to measure the ILI activity level within a state. They do
  9. #' not, however, measure the extent of geographic spread of flu within a state. Therefore,
  10. #' outbreaks occurring in a single city could cause the state to display high activity levels.\cr
  11. #' \cr
  12. #' Data collected in ILINet may disproportionately represent certain populations within
  13. #' a state, and therefore may not accurately depict the full picture of influenza activity
  14. #' for the whole state.\cr
  15. #' \cr
  16. #' All summary statistics are based on either data collected in ILINet, or reports from
  17. #' state and territorial epidemiologists. Differences in the summary data presented by
  18. #' CDC and state health departments likely represent differing levels of data completeness
  19. #' with data presented by the state likely being the more complete.
  20. #' @export
  21. #' @examples \dontrun{
  22. #' ili_weekly_activity_indicators(2016)
  23. #' }
  24. ili_weekly_activity_indicators <- function(season_start_year) {
  25. jsonlite::fromJSON("https://gis.cdc.gov/grasp/fluView1/Phase1IniP") %>%
  26. jsonlite::fromJSON() -> meta
  27. season <- season_start_year - 1960
  28. res <- httr::GET(sprintf("https://gis.cdc.gov/grasp/fluView1/Phase1SeasonDataP/%s",
  29. season))
  30. httr::stop_for_status(res)
  31. res <- httr::content(res, as="parsed")
  32. res <- jsonlite::fromJSON(res)
  33. setNames(
  34. meta$ili_intensity[,c("iliActivityid", "ili_activity_label", "legend")],
  35. c("iliactivityid", "ili_activity_label", "ili_activity_group")
  36. ) -> iliact
  37. dplyr::left_join(res$busdata, meta$stateinfo, "stateid") %>%
  38. dplyr::left_join(res$mmwr, "mmwrid") %>%
  39. dplyr::left_join(iliact, "iliactivityid") -> xdf
  40. xdf <- xdf[,c("statename", "ili_activity_label", "ili_activity_group",
  41. "statefips", "stateabbr", "weekend", "weeknumber", "year", "seasonid")]
  42. xdf$statefips <- trimws(xdf$statefips)
  43. xdf$stateabbr <- trimws(xdf$stateabbr)
  44. xdf$weekend <- as.Date(xdf$weekend)
  45. xdf$ili_activity_label <- factor(xdf$ili_activity_label,
  46. levels=iliact$ili_activity_label)
  47. class(xdf) <- c("tbl_df", "tbl", "data.frame")
  48. xdf
  49. }
  50. #' Retrieve metadata about U.S. State CDC Provider Data
  51. #'
  52. #' @md
  53. #' @export
  54. #' @examples
  55. #' state_data_providers()
  56. state_data_providers <- function() {
  57. jsonlite::fromJSON("https://gis.cdc.gov/grasp/fluView1/Phase1IniP") %>%
  58. jsonlite::fromJSON() -> meta
  59. state_info <- meta$stateinfo
  60. state_info <- state_info[,c("statename", "statehealthdeptname", "url", "statewebsitename", "statefluphonenum")]
  61. class(state_info) <- c("tbl_df", "tbl", "data.frame")
  62. state_info
  63. }