OHDSI Home | Forums | Wiki | Github

Having trouble finding my way around StudyProtocols

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

Hi Sigried!

There are two things going on, and both indicate that a file cannot be found.

The first one is a mystery. You’re calling insertCohortDefinitionSetInPackage, and the only readChar call in that function is here, where it loads this R template from within the OhdsiRTools package. My only explanation is that something may have gone wrong installing that package.

The second one is probably because you haven’t yet built your ischemicStrokePhenotype package. The SQL file is in ‘inst/sql/sql_server’, and everything in the ‘inst’ folder gets included in your R package library when you build and install the package. When calling loadRenderTranslateSql it looks for the SQL in the package library, not in the ‘inst’ folder (which is only available to you as the package developer).

Thanks, Martijn. You’re right that I hadn’t built the package. I haven’t fixed this stuff yet, but I have a couple higher-level question about getting my bearings in the protocol authoring world:

  1. Is there a best study to use as a template or starter for authoring a new study? and

  2. Do any of the video tutorials cover the topic of study authoring in some systematic, introductory way?

Thanks again!
s

Hi Sigried. Perhaps the SkeletonComparativeEffectStudy is the best example to follow. I’m afraid we don’t have any educational materials covering this topic yet.

1 Like

Thanks, @schuemie!

I just got back to this and am about to start trying it.

I’ll follow the example and instructions faithfully. I notice it says Under development. Do not use, but since that instruction is at the bottom, I’ll follow it last :slightly_smiling_face:

t