Skip to content

pipitone/rdrugshortages

Repository files navigation

rdrugshortages

Access drug shortage data in R. This package currently supports accessing the following databases

  1. Drug Shortages Canada Canada-wide mandatory shortage reporting database. You must create an account to access the database via the API but you can search and export subsets of the data on the site.

  2. Drug Product Database This database, by Health Canada, provides a current and historical snapshot of all available drug products, and includes supplementary information such as manufacturer information. There are no shortage reports in this database, but it can be used in conjunction with shortage reports by cross-referencing the Drug Identification Number (DIN) field.

Installation Instructions

install.packages('rdrugshortages')

# Or, install the latest development version:
devtools::install_github('pipitone/rdrugshortages')

Use

As mentioned above, you must create an account with Drug Shortages Canada (DSC) in order to access the database via the API. Once you have done this, you can put your credentials in your .Renviron file which gets loaded every time you start R:

# ~/.Renviron
dsc.email = "youremail@domain.com"
dsc.password = "yourpassword"

You can check that this worked by typing the following into a new R session:

> Sys.getenv('dsc.email')
[1] "youremail@domain.com"

You can access the search API via the function dsc_search(). This function will automatically attempt to log in to with your account credentials when you first use it, and then return the results of the search:

> results = dsc_search(term="diltiazem")
> head(results)
# A tibble: 6 x 93
     id created_date din   company_name atc_number atc_description discontinuationupdated_date status
  <int> <chr>        <chr> <chr>        <chr>      <chr>           <chr>            <chr>        <chr> 
1 81418 2019-04-11T0237TEVA CANADAC08DB      SELECTIVE CALC2019-03-15T00:02019-04-11Tdisco2 82552 2019-04-26T0237TEVA CANADAC08DB      SELECTIVE CALCNA               2019-04-26Tactiv3 82555 2019-04-26T0237TEVA CANADAC08DB      SELECTIVE CALCNA               2019-04-26Tactiv4 61340 2018-09-12T0237TEVA CANADAC08DB01    SELECTIVE CALCNA               2018-10-11Tactiv5  9901 2017-05-10T0237ACTAVIS PHAC08DB      SELECTIVE CALCNA               2017-09-19Tresol6 81381 2019-04-11T0237TEVA CANADAC08DB      SELECTIVE CALC2019-01-09T00:02019-04-11Tdisco

The result set returned by dsc_search() is a tibble which is based on the JSON blob returned by the API.

The full specification for the DSC API is available here.

Note that rdrugshortages assembles the entire result set by making multiple requests to the API when there are more results than can be returned by the API in a single request. You should be aware that API has been rate-limited to 1000 requests per hour.

To download the entire DSC database, simple run dsc_search() without any search terms.

About

Access Drug Shortages Databases from R

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages