The hardware and bandwidth for this mirror is donated by METANET, the Webhosting and Full Service-Cloud Provider.
If you wish to report a bug, or if you are interested in having us mirror your free-software or open-source project, please feel free to contact us at mirror[@]metanet.ch.

healthdb healthdb website

R-CMD-check Codecov test coverage

The goal of ‘healthdb’ is to provide a set of tools for identifying diseases or events from healthcare database and preparing data for epidemiological studies. It features abilities that are not natively support by database, such as matching strings by ‘stringr’ style regular expression and using ‘LIKE’ operator with multiple patterns in a vector. Three types of functions are included: interactive functions – for customizing complex definitions; call building functions – for batch execution of simple definition; miscellaneous functions – for data wrangling, computing age and comorbidity index, etc.

The package is tested only on SQL Server and SQLite as we do not have access to other SQL dialects. Please report bugs if you encounter issues with other dialects.

Administrative health data data are often stored on database with strict security measures which may disable permission to write temporary tables. Writing queries without being able to cache intermediate results is challenging, especially when the data is too large to be downloaded from database into R (i.e., local memory) without some filtering process.

This package leverages ‘dbplyr’, particularly its ability to chain subqueries, in order to implement a common disease definition as a one-shot big query. Outputs are fully compatible with ‘dplyr’ functions.

Common disease definitions often are in the form of having n primary care/hospitalization/prescription records with some International Classification of Diseases (ICD) codes within some time span. See below for an example of implementing such case definition.

Installation

Install from CRAN:

install.packages("healthdb")

You could also install the development version from GitHub with:

# install.packages("devtools")
devtools::install_github("KevinHzq/healthdb")

Usage

Case definition: One or more hospitalization with a substance use disorder (SUD) diagnostic code, OR Two or more physician claims with a substance use disorder diagnostic code within one year.

We are going to implement this definition. First, let’s make a demo data sets for the two sources:

Physician claims

library(healthdb)
library(tidyverse)

# make_test_dat() makes either a toy data.frame or database table in memory with known number of rows that satisfy the query we will show later
claim_db <- make_test_dat(vals_kept = c("303", "304", "305", "291", "292", str_glue("30{30:59}"), str_glue("29{10:29}"), noise_val = c("999", "111")), type = "database")

# this is a database table
# note that in-memory SQLite database stores dates as numbers
claim_db %>% head()
#> # Source:   SQL [6 x 6]
#> # Database: sqlite 3.45.2 [:memory:]
#>     uid clnt_id dates diagx diagx_1 diagx_2
#>   <int>   <int> <dbl> <chr> <chr>   <chr>  
#> 1    51       1 16660 999   999     999    
#> 2    24       1 17464 3048  3040    <NA>   
#> 3    14       2 17640 3041  3047    <NA>   
#> 4    37       3 16948 2913  3035    999    
#> 5    91       4 16712 999   999     999    
#> 6    82       4 16760 999   999     <NA>

Hospitalization

hosp_df <- make_test_dat(vals_kept = c(str_glue("F{10:19}"), str_glue("F{100:199}"), noise_val = "999"), type = "data.frame")

# this is a local data.frame/tibble
hosp_df %>% head()
#>   uid clnt_id      dates diagx diagx_1 diagx_2
#> 1  43       1 2015-08-13  F156    F144    F168
#> 2  16       1 2017-10-25   F12    F132    <NA>
#> 3   6       2 2018-04-19  F133    F128    <NA>
#> 4  29       3 2016-05-27  F130    F164     999
#> 5  83       4 2015-10-04   999     999    <NA>
#> 6  74       4 2015-11-21   999    <NA>     999

Here’s how you could use healthdb to implement the SUD definition above:

  1. Identify rows contains the target codes in the claim database

  2. Restrict the number of records per client

  3. Restrict the temporal pattern of diagnoses

  4. Repeat these steps for hospitalization and row bind the results.

The output of these functions, including identify_row(), exclude(), restrict_n(), restrict_date() and more can be piped into ‘dplyr’ functions for further manipulations. Therefore, wrangling with them along with ‘dplyr’ provide the maximum flexibility for implementing complex algorithms. However, your code could look repetitive if multiple data sources were involved. See the “Intro” vignette (vignette("Intro")) for a much more concise way to work with multiple sources and definitions (the ‘Call-building functions’ section).

These binaries (installable software) and packages are in development.
They may not be fully stable and should be used with caution. We make no claims about them.