knitr::opts_chunk$set(echo = TRUE)

Overview

This package contains functions for building and working with the small Truven database extracts.

Examples

Load the required packages:

library(tidyverse)
library(smallDB)

Connect to an example database extract:

# connect to database
con <- DBI::dbConnect(RSQLite::SQLite(), "~/Data/cftr/pancreatitis_chronic.db")

Create timemap

Create a longitudinal timemap. In this example visit keys have not been added to the database, so these will be added temporarily to create the timemap.

tm <- build_time_map(db_con = con)

# view timemap object
tm

Add diagnosis indicators

The build_dx_indicators() function can be used to create a list of diagnosis indicators. In this example we create a single indicator for a single diagnosis - CDI.

# create the diagnosis list
dx_list <- list(cdi = list(icd9_codes = "00845",
                           icd10_codes = c("A047","A0471","A0472")))

# build the indicators
build_dx_indicators(db_con = con,condition_dx_list = dx_list)

We could also generate a list of multiple diagnoses to create multiple indicators for. Here I will use the codeBuildr package to load the diagnosis codes for AMI and CDI.

library(codeBuildr)

# load the diagnosis codes for AMI and CDI
dx_list <- load_disease_codes(c("ami","cdi"))

# view the code list
dx_list

# get the diagnosis indicators
build_dx_indicators(db_con = con,condition_dx_list = dx_list)

Add medication indicators

The function codeBuildr::load_rx_codes("all_abx") can be used to load the ndc codes for the group of all antibiotics.

abx_codes <- load_rx_codes("all_abx")

The function build_rx_indicators() can then be used to collect indicators for each of the antibiotics in the all_abx list.

build_rx_indicators(rx_list = abx_codes,db_con = con)

Close database connection

DBI::dbDisconnect(con)


aarmiller/smallDB documentation built on March 29, 2024, 9:37 a.m.