I’m working on a project that’s going to develop into a study protocol and trying to put the basic pieces together. Our plan will be to publish our cohort definitions on the public ATLAS server. So I’m currently just trying to figure out how to grab a cohort definition from there using RTools, and generate sql for postgres.
Starting here, in a fork of the StudyProtocols repository:
getwd()
# [1] ".../OHDSI/StudyProtocols/AhasHfBkleAmputation"
library(DatabaseConnector)
library(SqlRender)
connectionDetails <- createConnectionDetails( dbms="postgresql",
server=paste0(Sys.getenv("PGHOST"),'/',
Sys.getenv('PGDATABASE')),
user = Sys.getenv('PGUSER'),
password = Sys.getenv('PGPASSWORD'),
schema="mimic3_100p")
conn <- connect(connectionDetails)
./inst/settings/settings.csv:
"cohortId","atlasId","name","fullName"
987654321,1769961,"Male50plus","Male > 50"
The following seems to work, but it generates an error:
OhdsiRTools::insertCohortDefinitionSetInPackage(fileName = "settings.csv",
baseUrl = "http://api.ohdsi.org:80/WebAPI",
insertTableSql = TRUE,
insertCohortCreationR = TRUE,
generateStats = FALSE,
packageName="ischemicStrokePhenotype")
# Inserting cohort: Male50plus
# Error in readChar(fileName, file.info(fileName)$size) :
# invalid 'nchars' argument
# In addition: Warning message:
# In file(con, "rb") :
# file("") only supports open = "w+" and open = "w+b": using the former
I say it seems to work because it generates a json and sql file (./inst/cohorts/Male50plus.json and ./inst/sql/sql_server/Male50plus.sql). I’m not sure what all the next steps are, but I’m going to need my sql file generated for postgres, not just sql server. So I’m trying the following, which generates the same error, but doesn’t create any files:
renderedSql <- loadRenderTranslateSql("Male50plus.sql",
#packageName = "CohortMethod", # tried this and below
packageName = "ischemicStrokePhenotype",
dbms = connectionDetails$dbms,
CDM_schema = "mimic3_100p_results")
# Error in readChar(pathToSql, file.info(pathToSql)$size) :
# invalid 'nchars' argument
# In addition: Warning message:
# In file(con, "rb") :
# file("") only supports open = "w+" and open = "w+b": using the former
This is the first time I’ve worked with any of the OHDSI R packages, so I apologize for my cluelessness. Any advice about what I’m doing wrong so far?
Many thanks