knitr::opts_chunk$set( collapse = TRUE, comment = "#>" )
library(rdrugshortages)
There are two Canadian databases accessible via rdrugshortages
:
Canada-wide mandatory shortage reporting database. You must create an account to access the database via the API.
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. No account is required.
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
everytime 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 discontinuation… updated_date status <int> <chr> <chr> <chr> <chr> <chr> <chr> <chr> <chr> 1 81418 2019-04-11T… 0237… TEVA CANADA… C08DB SELECTIVE CALC… 2019-03-15T00:0… 2019-04-11T… disco… 2 82552 2019-04-26T… 0237… TEVA CANADA… C08DB SELECTIVE CALC… NA 2019-04-26T… activ… 3 82555 2019-04-26T… 0237… TEVA CANADA… C08DB SELECTIVE CALC… NA 2019-04-26T… activ… 4 61340 2018-09-12T… 0237… TEVA CANADA… C08DB01 SELECTIVE CALC… NA 2018-10-11T… activ… 5 9901 2017-05-10T… 0237… ACTAVIS PHA… C08DB SELECTIVE CALC… NA 2017-09-19T… resol… 6 81381 2019-04-11T… 0237… TEVA CANADA… C08DB SELECTIVE CALC… 2019-01-09T00:0… 2019-04-11T… disco…
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.
Accessing Health Canada's Drug Product is much simplier, as you do not need an account. There is no API so rdrugshortages
simply downloads a copy of extracts of the database. The Health Canada site hosts an very important README that outlines the schema and contents.
To use the DPD extract, use the dpd_load
function. With download=T
, this
function will create the data_dir
if it does not already exist, and download
the latest DPD extract before returning the tables as a data.frame
:
dpd = dpd_load(data_dir="data/", download=T)
This returns a list, with each element a table from the DPD. Each table can be
joined to any other by the DRUG_CODE
field.
library(dplyr) atc_info = inner_join(dpd$drug, dpd$ther, by="DRUG_CODE")
These data can then be merged into the drug shortage reports from the DSC using
the dpd$drug$DRUG_IDENTIFICATION_NUMBER
field.
diltiazem_shortages = dsc_search(term="diltiazem") %>% left_join(atc_info, by=c("din" = "DRUG_IDENTIFICATION_NUMBER"))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.