GithubHelp home page GithubHelp logo

cdcgov / rnssp Goto Github PK

View Code? Open in Web Editor NEW
37.0 8.0 13.0 42.03 MB

A Signature R package for the National Syndromic Surveillance Program (NSSP) at the Centers for Disease Control and Prevention (CDC). A collection of tools, classes and functions that supports the Community of Practice of the NSSP.

Home Page: https://cdcgov.github.io/Rnssp

License: Apache License 2.0

R 100.00%
cdc nssp essence essence-api nssp-cop

rnssp's Issues

Using this package with R 4.3.0

To make this package work with R version 4.3.0, we would also need to force the installation of the deprecate dependencies below,

#install the Rnssp package
install.packages("devtools")
library(devtools)
install_bitbucket("richierocks/assertive.base")
install_bitbucket("richierocks/assertive.properties")
install_bitbucket("richierocks/assertive.types")
install.packages(c("magrittr", "purrr", "dplyr"))
devtools::install_github("cdcgov/Rnssp")

get_essence_data not working for all APIs

The get_essence_data() function does not work with all APIs. Below is an example, copied directly from ESSENCE with no modifications:


url <- "https://essence2.syndromicsurveillance.org/nssp_essence/api/tableBuilder?datasource=va_hosp&startDate=1Jan2013&medicalGroupingSystem=essencesyndromes&userId=5099&endDate=9May2023&percentParam=noPercent&site=934&hospFacilityType=emergency%20care&aqtTarget=TableBuilder&geographySystem=hospital&detector=nodetectordetector&timeResolution=daily&hasBeenE=1&rowFields=timeResolution&columnField=site"

data <- Rnssp::get_essence_data(url)

returns error: Error in Rnssp::get_essence_data():
! URL is not of ESSENCE type. Check your URL or use get_api_data() instead!

I do not want to use get_api_data() for a number of reasons, the big one being that I still have to manipulate it into a data frame and the point of get_essence_data() is to avoid the extra required steps every time.

When I run my version of get_essence_data() it works:


function(url, start_date = NULL, end_date = NULL) {
  
  api_type <- str_extract(url,"(?<=api/).+(?=\\?)")
  
  url_new <- Rnssp::change_dates(url, start_date, end_date)
  
  if (api_type == "timeSeries") {
    api_response <- myProfile$get_api_response(url_new)
    api_response_json <- content(api_response, as = "text")
    api_data <- fromJSON(api_response_json) %>%
      extract2("timeSeriesData")
  } else if (api_type == "timeSeries/graph") {
    api_png <- myProfile$get_api_tsgraph(url_new)
    knitr::include_graphics(api_png$tsgraph)
  } else if (api_type == "tableBuilder") {
    api_data <- myProfile$get_api_data(url_new)
  } else if (api_type == "tableBuilder/csv") {
    api_data <- myProfile$get_api_data(url_new, fromCSV = TRUE)
  } else if (api_type == "dataDetails") {
    api_data <- myProfile$get_api_data(url_new) %>%
      extract2("dataDetails")
  } else if (api_type == "dataDetails/csv") {
    api_data <- myProfile$get_api_data(url_new, fromCSV = TRUE) 
  } else if (api_type == "summaryData") {
    api_data <- myProfile$get_api_data(url_new) %>%
      extract2("summaryData")
  } else if (api_type == "alerts/regionSyndromeAlerts") {
    api_data <- myProfile$get_api_data(url_new) %>%
      extract2("regionSyndromeAlerts")
  } else if (api_type == "alerts/hospitalSyndromeAlerts") {
    api_data <- myProfile$get_api_data(url_new) %>%
      extract2("hospitalSyndromeAlerts")
  } else {
    writeLines("Error: API did not work as expected. Please check your URL, dates, and password before trying again.")
  }
  
}

Add functionality to return just a data frame rather than a list

Currently the API call functions built into the Rnssp package return a list rather than a data frame (or image). Users are still required to extract the data frame or image from the list for each API call, a step that could be wrapped into the existing API call functions. This would require fewer lines of code for users to write, reduce the chances of error, and make the package and APIs more user-friendly.

Below is a suggested function that would return the final result from each type of API call (including visualizations). Arguments have been made in the past that if the API structure changes, functions like this would no longer work, but if that does happen then users will have to update all of their code to match the new structure. This way, any updates in the API structure can be accounted for in this function, and as long as users update the package they will be able to use the function to call the API and get the output they need.

The function below is based on the code found in the Rnssp_intro vignette (https://cdcgov.github.io/Rnssp/articles/Rnssp_intro.html) prior to the addition of the newer API call functions.

get_essence_data <- function(url, start_date = NULL, end_date = NULL) {
  
  api_type <- str_extract(url,"(?<=api/).+(?=\\?)")
  
  url_new <- change_dates(url, start_date, end_date)
  
  if (api_type == "timeSeries") {
    api_response <- myProfile$get_api_response(url_new)
    api_response_json <- content(api_response, as = "text")
    api_data <- fromJSON(api_response_json) %>%
      extract2("timeSeriesData")
  } else if (api_type == "timeSeries/graph") {
    api_png <- myProfile$get_api_tsgraph(url_new)
    knitr::include_graphics(api_png$tsgraph)
  } else if (api_type == "tableBuilder") {
    api_data <- myProfile$get_api_data(url_new)
  } else if (api_type == "tableBuilder/csv") {
    api_data <- myProfile$get_api_data(url_new, fromCSV = TRUE)
  } else if (api_type == "dataDetails") {
    api_data <- myProfile$get_api_data(url_new) %>%
      extract2("dataDetails")
  } else if (api_type == "dataDetails/csv") {
    api_data <- myProfile$get_api_data(url_new, fromCSV = TRUE) 
  } else if (api_type == "summaryData") {
    api_data <- myProfile$get_api_data(url_new) %>%
      extract2("summaryData")
  } else if (api_type == "alerts/regionSyndromeAlerts") {
    api_data <- myProfile$get_api_data(url_new) %>%
      extract2("regionSyndromeAlerts")
  } else if (api_type == "alerts/hospitalSyndromeAlerts") {
    api_data <- myProfile$get_api_data(url_new) %>%
      extract2("hospitalSyndromeAlerts")
  } else {
    writeLines("Error: API did not work as expected. Please check your URL, dates, and password before trying again.")
  }
  
}

Installation Problems due to dependency assertive.types no longer available on CRAN

Hi everyone,

Unfortunately I received the error message "dependency 'assertive.types' is not available for package 'Rnssp'" when trying to install your package. On CRAN it says that this package was archived on 2023-10-24 https://cran.r-project.org/web/packages/assertive.types/index.html. Thus one can only get the package running using former available versions of assertive.types. Do you plan to change your code to not depend on this package anymore or any other solution?
Thanks!

change_dates() feature is flip-flopping start and end_date values

When providing start and end dates for change_dates(), the dates are sometimes updated backwards in the ESSENCE API URL. This causes the API call not to return any records. When examining the URL, it is subbing the start date value in for the end date and vice versa if startDate appears first in the URL.

library(Rnssp)

# Does not work because startDate appears first in the URL
url1 <- "https://essence2.syndromicsurveillance.org/nssp_essence/api/dataDetails/csv?percentParam=noPercent&datasource=va_erccdd&detector=nodetectordetector&syndrome=resp&timeResolution=weekly&hasBeenE=1&ccddCategoryFreeText=ISNULL,or,ISBLANK,or,%5E,andnot,%5E;CDC%20Broad%20Acute%20Respiratory%20DD%20v1;%5E&aqtTarget=TimeSeries&startDate=30Jul23&endDate=30Jul23"

change_dates(url1, start_date = "2022-09-01", end_date = "2022-09-02")

# Works because endDate appears first in the URL
url2 <- "https://essence2.syndromicsurveillance.org/nssp_essence/api/dataDetails/csv?percentParam=noPercent&datasource=va_erccdd&detector=nodetectordetector&syndrome=resp&timeResolution=weekly&hasBeenE=1&ccddCategoryFreeText=ISNULL,or,ISBLANK,or,%5E,andnot,%5E;CDC%20Broad%20Acute%20Respiratory%20DD%20v1;%5E&aqtTarget=TimeSeries&endDate=30Jul23&startDate=30Jul23"

change_dates(url2, start_date = "2022-09-01", end_date = "2022-09-02")

Installed assertive.types manually, but when installing Rnssp, vignette build failed

I was able to download and install assertive.base, assertive.properties, and assertive.types from CRAN archives and install them manually. I also had to install ggside separately. When I tried to install Rnssp after that, I was able to install it without vignettes, but not with vignettes. When I tried to install with vignettes, I got the following error.

> devtools::install_github("cdcgov/Rnssp", build_vignette = TRUE)
Downloading GitHub repo cdcgov/Rnssp@HEAD
Skipping 1 packages not available: assertive.types
── R CMD build ───────────────────────────────────────────────────────────────────────────
✔  checking for file 'C:\Users\ajstamm\AppData\Local\Temp\RtmpkfB0xK\remotes4bbc78167a45\CDCgov-Rnssp-afbcb80/DESCRIPTION' ...preparing 'Rnssp': (533ms)
✔  checking DESCRIPTION meta-information ...installing the package to build vignettes
E  creating vignettes (12.9s)
   --- re-building 'Rnssp_intro.Rmd' using rmarkdown
   
   Quitting from lines 54-55 [load] (Rnssp_intro.Rmd)
   Error: processing vignette 'Rnssp_intro.Rmd' failed with diagnostics:
   cannot open the connection
   --- failed re-building 'Rnssp_intro.Rmd'
   
   --- re-building 'Rnssp_rstudio_addins.Rmd' using rmarkdown
   --- finished re-building 'Rnssp_rstudio_addins.Rmd'
   
   --- re-building 'Rnssp_text_mining.Rmd' using rmarkdown
   
   Quitting from lines 51-52 [load] (Rnssp_text_mining.Rmd)
   Error: processing vignette 'Rnssp_text_mining.Rmd' failed with diagnostics:
   cannot open the connection
   --- failed re-building 'Rnssp_text_mining.Rmd'
   
   --- re-building 'Rnssp_trend_alert_detection.Rmd' using rmarkdown
   
   Quitting from lines 43-45 [load] (Rnssp_trend_alert_detection.Rmd)
   Error: processing vignette 'Rnssp_trend_alert_detection.Rmd' failed with diagnostics:
   cannot open the connection
   --- failed re-building 'Rnssp_trend_alert_detection.Rmd'
   
   SUMMARY: processing the following files failed:
     'Rnssp_intro.Rmd' 'Rnssp_text_mining.Rmd'
     'Rnssp_trend_alert_detection.Rmd'
   
   Error: Vignette re-building failed.
   Execution halted
Error: Failed to install 'Rnssp' from GitHub:
  ! System command 'Rcmd.exe' failed

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.