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 Introduction

Rnssp

Rnssp Pipeline Project Status: Active - The project has reached a stable, usable state and is being actively developed. Lifecycle: stable DOI

Overview

The Rnssp R package is a catalog of data processing and analytics tools, templates, and functions commonly used across the National Syndromic Surveillance Program at the Centers for Disease Control and Prevention (CDC). Its goal is to improve code reproducibility, standardize and document reusable functions, facilitate the sharing of routine reports across the NSSP Community of Practice (CoP), and better engage the NSSP CoP.

Installation

You can install the development version of Rnssp from GitHub:

# Install the Rnssp package
devtools::install_github("cdcgov/Rnssp")

To install the package for Webassembly, run the following in your webr REPL or add it to your shinylive application:

# Install the Rnssp package for webr
webr::install("Rnssp", repos = c("https://cdcgov.github.io/Rnssp-wasm", "https://repo.r-wasm.org"))

Usage

This is a basic example which shows you how to:

  • use the Rnssp package to create a user profile
  • and use the user profile to pull data from an API (here the ESSENCE API)
library(Rnssp)

## Creating a user profile (token)
myProfile <- create_token_profile()

## Creating a user profile (username and password)
myProfile <- create_profile()

## Inspect your `myProfile` confirming that username and password are completely hidden
myProfile

## JSON URL from ESSENCE API
url <- "https://essence.syndromicsurveillance.org/nssp_essence/api/alerts/regionSyndromeAlerts?end_date=31Jan2021&start_date=29Jan2021"

## Update Start and End dates in ESSENCE API URL
url <- change_dates(url, start_date = Sys.Date() - 30, end_date = Sys.Date())

## Pull Time Series Data from ESSENCE
api_data <- get_api_data(url) # or api_data <- myProfile$get_api_data(url)

## Inspect data object structure
names(api_data)

## Get a glimpse of the pulled dataset
glimpse(api_data$regionSyndromeAlerts) 

Contributing to this project

Should you want to contribute to this project, submit a push request to this Github repository and consider submitting a request to be added as a developer to [email protected].

Getting Help

If you encounter a clear bug, please consider emailing the author at [email protected] and/or file an issue with a minimal reproducible example.

Citing the Rnssp package

@software{Azondekon_Rnssp_A_Signature_2024,
  author = {Azondekon, Gbedegnon Roseric and Sheppard, Michael},
  doi = {10.5281/zenodo.10884244},
  license = {Apache License (>= 2)},
  month = mar,
  title = {{Rnssp: A Signature R package for the National Syndromic Surveillance Program (NSSP)}},
  url = {https://github.com/CDCgov/Rnssp},
  version = {0.3.0},
  year = {2024}
}

Public Domain Standard Notice

This repository constitutes a work of the United States Government and is not subject to domestic copyright protection under 17 USC ? 105. This repository is in the public domain within the United States, and copyright and related rights in the work worldwide are waived through the CC0 1.0 Universal public domain dedication. All contributions to this repository will be released under the CC0 dedication. By submitting a pull request you are agreeing to comply with this waiver of copyright interest.

License Standard Notice

The repository utilizes code licensed under the terms of the Apache Software License and therefore is licensed under ASL v2 or later.

This source code in this repository is free: you can redistribute it and/or modify it under the terms of the Apache Software License version 2, or (at your option) any later version.

This source code in this repository is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the Apache Software License for more details.

You should have received a copy of the Apache Software License along with this program. If not, see http://www.apache.org/licenses/LICENSE-2.0.html

The source code forked from other open source projects will inherit its license.

Privacy Standard Notice

This repository contains only non-sensitive, publicly available data and information. All material and community participation is covered by the Disclaimer and Code of Conduct. For more information about CDC's privacy policy, please visit http://www.cdc.gov/other/privacy.html.

Contributing Standard Notice

Anyone is encouraged to contribute to the repository by forking and submitting a pull request. (If you are new to GitHub, you might start with a basic tutorial.) By contributing to this project, you grant a world-wide, royalty-free, perpetual, irrevocable, non-exclusive, transferable license to all users under the terms of the Apache Software License v2 or later.

All comments, messages, pull requests, and other submissions received through CDC including this GitHub page may be subject to applicable federal law, including but not limited to the Federal Records Act, and may be archived. Learn more at http://www.cdc.gov/other/privacy.html.

Records Management Standard Notice

This repository is not a source of government records, but is a copy to increase collaboration and collaborative potential. All government records will be published through the CDC web site.

rnssp's People

Contributors

michael-sheppard avatar rosericazondekon avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

rnssp's Issues

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.")
  }
  
}

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

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")

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!

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.