pynssp package

Subpackages

Submodules

pynssp.data module

pynssp.data.get_scenario1()[source]

Return a subset of the simulated time series data (‘scenario #1’).

Examples:
>>> from pynssp import get_scenario1
>>>
>>> scenario1_ts = get_scenario1()
>>> scenario1_ts.info()
pynssp.data.get_scenario2()[source]

Return a subset of the simulated time series data (‘scenario #2’).

Examples:
>>> from pynssp import get_scenario2
>>>
>>> scenario2_ts = get_scenario2()
>>> scenario2_ts.info()
pynssp.data.load_nssp_stopwords()[source]

Return a dataframe of NSSP-curated stopwords.

Examples:
>>> from pynssp import load_nssp_stopwords
>>>
>>> stopwords = load_nssp_stopwords()
>>> stopwords.info()
## #   Column      Non-Null Count  Dtype
## ---  ------      --------------  -----
## 1   word        835 non-null    object
## 2   type        835 non-null    object
## dtypes: int64(1), object(2)
## memory usage: 13.2+ KB
pynssp.data.load_simulated_ts()[source]

Return a dataframe of simulated time series.

Examples:
>>> from pynssp.data import load_simulated_ts
>>>
>>> simulated_ts = load_simulated_ts()
>>> simulated_ts.info()
## #   Column  Non-Null Count  Dtype
## ---  ------  --------------  -----
## 0   date    626 non-null    object
## 1   week    626 non-null    int64
## 2   year    626 non-null    int64
## 3   cases   626 non-null    int64
## 4   id      626 non-null    object
## dtypes: int64(3), object(2)
## memory usage: 24.6+ KB

pynssp.utils module

pynssp.utils.change_dates(url, start_date=None, end_date=None)[source]

Changes the start and end dates in a given URL to new dates, if provided.

Parameters:
  • url – str): The URL containing the start and end dates to be changed.

  • start_date – str): A new start date to replace the existing start date in the URL. (Default value = None)

  • end_date – str): A new end date to replace the existing end date in the URL. (Default value = None)

Returns:

The modified URL with the new start and end dates.

Examples:
>>> from pynssp import change_dates
>>>
>>> url = "https://example.com/data?startDate=01Jan2022&endDate=31Dec2022"
>>> change_dates(url, start_date="01Jan2021", end_date="31Dec2021")
pynssp.utils.create_profile(username=None, password=None)[source]

Create a new user profile with the given username and password.

Parameters:
  • username – A string representing the username. If not provided, the user will be prompted to enter it.

  • password – A string representing the user’s password. If not provided, the user will be prompted to enter it securely.

Returns:

A new Credentials object with the given username and password.

Examples:
>>> from pynssp import create_profile
>>>
>>> myProfile = create_profile()
pynssp.utils.create_token_profile(token=None, access_token='Bearer')[source]

Create a new token profile with the given token and authentication type.

Parameters:
  • token – A string representing the token. If not provided, the user will be prompted to enter it securely.

  • auth_type – A string representing the authentication type. Defaults to “Bearer”.

Returns:

A new Token object with the given token and authentication type.

Examples:
>>> from pynssp import create_token_profile
>>>
>>> myTokenProfile = create_token_profile()
pynssp.utils.get_api_data(url, fromCSV=False, profile=None, encoding='utf-8', **kwargs)[source]

Retrieve data from an API using the provided profile.

Parameters:
  • url – A string representing the URL of the API endpoint.

  • fromCSV – A boolean indicating whether the data should be retrieved from a CSV file. Defaults to False.

  • profile – An profile object of class pynssp.core.credentials.Credentials or pynssp.core.token.Token.

  • kwargs – Additional keyword arguments to be passed to the profile’s get_api_data method.

Returns:

The data retrieved from the API.

Examples:
>>> from pynssp import *
>>>
>>> myProfile = create_profile()
>>> url = "http://httpbin.org/json"
>>> api_data = get_api_data(url, profile=myProfile)
pynssp.utils.get_api_graph(url, file_ext='.png', profile=None)[source]

Retrieve a graph from an API using the provided profile.

Parameters:
  • url – A string representing the URL of the API endpoint.

  • file_ext – A string representing the file extension of the graph. Defaults to “.png”.

  • profile – An profile object of class pynssp.core.credentials.Credentials or pynssp.core.token.Token.

Returns:

The graph retrieved from the API.

Examples:
>>> from pynssp import *
>>>
>>> myProfile = create_profile()
>>> url = "http://httpbin.org/image/png"
>>> api_graph = get_api_graph(url, profile=myProfile)
pynssp.utils.get_api_response(url, profile=None)[source]

Retrieve a response from an API using the provided profile.

Parameters:
  • url – A string representing the URL of the API endpoint.

  • profile – An profile object of class pynssp.core.credentials.Credentials or pynssp.core.token.Token.

Returns:

The response object returned by the API.

Examples:
>>> from pynssp import *
>>>
>>> myProfile = create_profile()
>>> url = "http://httpbin.org/json"
>>> response = get_api_response(url, profile=myProfile)
pynssp.utils.get_essence_data(url, start_date=None, end_date=None, profile=None, **kwargs)[source]

Retrieve data from the NSSP-ESSENCE API using the provided profile.

Parameters:
  • url – A string representing the URL of the NSSP-ESSENCE API endpoint.

  • start_date – A string representing the start date of the data to retrieve.

  • end_date – A string representing the end date of the data to retrieve.

  • profile – An profile object of class pynssp.core.credentials.Credentials or pynssp.core.token.Token.

  • kwargs – Additional arguments to be passed to the get_api_data function.

Returns:

The data retrieved from the NSSP-ESSENCE API.

Examples:
>>> from pynssp import *
>>>
>>> myProfile = create_profile()
>>> url = "https://essence2.syndromicsurveillance.org/nssp_essence/api/timeSeries/graph?endDate=25Jun2022&geography=&percentParam=noPercent&datasource=va_hosp&startDate=25Jun2021&medicalGroupingSystem=essencesyndromes&userId=3751&aqtTarget=TimeSeries&ccddCategory=&geographySystem=hospitalregion&detector=probrepswitch&timeResolution=daily"
>>> api_data = get_essence_data(url, profile=myProfile)
>>> api_data.info()
pynssp.utils.webscrape_icd(icd_version='ICD10', year=None)[source]

ICD Code Web Scraper

Function to web scrape ICD discharge diagnosis code sets from the CDC FTP server (for ICD-10) or CMS website (for ICD-9). If pulling ICD-10 codes, by default the function will search for the most recent year’s code set publication by NCHS. Users can specify earlier publication years back to 2019 if needed. The ICD-9 option will only web scrape the most recent, final ICD-9 code set publication (2014) from the CMS website. This function will return an error message if the FTP server or CMS website is unresponsive or if a timeout of 60 seconds is reached. The result is a dataframe with 3 fields: code, description, and set (ICD version concatenated with year). Codes are standardized to upper case with punctuation and extra leading/tailing white space removed to enable successful joining.

Parameters:
  • icd_version – The version of ICD codes to retrieve. Default is “ICD10”.

  • year – The year for which to retrieve the ICD codes. If not provided, the current year will be used. (Default value = None)

Returns:

A DataFrame containing the ICD codes and descriptions.

Examples:
>>> # Example 1
>>> from pynssp import webscrape_icd
>>>
>>> icd9 = webscrape_icd(icd_version = "ICD9")
>>> icd9.head()
>>> # Example 2
>>> from pynssp import webscrape_icd
>>>
>>> icd10_2021 = webscrape_icd(icd_version="ICD10", year=2021)
>>> icd10_2021.info()
>>> # Example 3
>>> from pynssp import webscrape_icd
>>>
>>> icd10_2020 = webscrape_icd(icd_version="ICD10", year=2020)
>>> icd10_2020.info()

Module contents

Top-level package for pynssp.