This tutorial will explain how to save a code list (or any other content) downloaded from the Concept Library into a SQL table in the SAIL DB2 Database.

First, follow the steps listed in 06 Connecting to the Concept Library API from R to connect to the Concept Library and download a concept.

Note: These steps are only applicable if working within the SAIL Gateway.

Downloading and installing SAILDBUtils

The SAIL Analytical Services team provide an R library to allow easy connectivity to the SAIL DB2 gateway from R, and to allow common database tasks to be performed more easily.

Install the library by running the following code:

Installing the SAILDBUtils Library
source('R:/R_Packages/SAILDBUtils/install.r')

Saving a DataFrame to the database

A complete example of how to save a dataframe to the database:

Example of how to save a DataFrame to the Database
library(ConceptLibraryClient);
library(SAILDBUtils);

# Create a connection to the SAIL Database. You will be prompted for username/password
db <- SAILDBUtils::SAILConnect();

# Retrieve the latest version of a concept. You will be prompted for a username and password
copd_icd10 = ConceptLibraryClient::get_concept_codes(
  url='https://conceptlibrary.saildatabank.com',
  id=141
);

# View the retrieved data frame
copd_icd10;

# Set your credentials so you don't have to log in for each command.
credentials = create_auth();

# Get a concept, explicitly specifying a particular version.
copd_icd10_20200602 = get_concept_codes(
  url='https://conceptlibrary.saildatabank.com',
  id=141,
  version=392,
  auth=credentials #Supply username and password
);

# Retrieve multiple concepts into a single data frame
comorbidities_primary_care = get_concept_codes(
  url='https://conceptlibrary.saildatabank.com',
  id=c(140,142,144),
  auth=credentials
);

# Save a dataframe to the database:
SAILDBUtils::create_table_from_df(
	db_conn=db,
	output_table='sailw1234v.code_table',	# the name of the table you want to create should go here
	df = copd_icd10_20200602				# the concept you wish to save to the database
)
  • No labels