select_events: Extracts From the database

Description Usage Arguments Details Value Examples

Description

This is a generic function for extracting EHR data from the database

Usage

1
2
select_events(db = NULL, tab, columns = "*", where = NULL,
  sql_only = FALSE, convert_dates = FALSE)

Arguments

db

a database connection

tab

the database table to extract from

columns

character vector of columns to extract from the table "*" means all tables

where

string representation of the selection criteria

sql_only

logical should the function just return a string of the SQL query?

convert_dates

logical should date fields be converted to R date format?

Details

The function is the base function for a range of others It can either extract by itself or generate the SQL to make a query. In this way it can be combined to make compound queries. The where argument is equivalent to the WHERE clause in sql The elements are converted to SQL using dplyr::translate_sql_ If an element is wrapped in a '.()', the element is expanded. Dates should be entered as strings in ISO format (

Value

a dataframe or a string representing an sql query

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
## Not run: 
# medical lookup tables are provided with CPRD
load("data/medical.RData")
a <- read.csv("data/chronic-renal-disease.csv")
a <- read_to_medcodes(a, medical, "code", lookup_readcodes= "readcode", 
lookup_medcodes="medcode", description = T)
b <- select_events(db, tab = "Referral", columns = c("patid", "eventdate", "medcode"), 
where = "medcode %in% .(a$medcode) & eventdate < '2000-01-01'")
b1 <- select_events(db, tab = "Clinical", columns = c("patid", "eventdate", "medcode"), 
where = "medcode %in% .(a$medcode) & eventdate < '2000-01-01'")

## End(Not run)

rEHR documentation built on Jan. 23, 2017, 1 p.m.

Related to select_events in rEHR...