I would like to propose some semi-standard way how to run a feasibility cohort count with 3 or 4 OHDSI partner sites. (nothing perfect, just some code snippet perhaps)
The latest study (Raloxifene…) has a split into runFeasiblity and executeStudy which is very nice way to split it.
If I have 4 cohort definitions – supplied as 4 ids on the public server with cohort definitions (e.g., here
http://www.ohdsi.org/web/atlas/#/cohortdefinition/152651 )
What is a good R code snipped that can
- Fetch the cohort definition from the server (using my connectionDetails dbms parameter to pick the right sql flavor)
- Populate the parameters of the query (e.g., use the default cohort table) (see code below)
- Produce counts for my 4 cohorts (or simply list all my cohorts at the moment) (my draft code does that)
What I have for 2 and 3 so far is below signature. But with step 1 (I need help). We almost had it working at the tutorial during symposium (with help from Marc) – but it never worked fully and now the routine is probably even more standardized. @msuchard @schuemie
My code gets the cohort from a file on hdd. (does not do step 1)
library(DatabaseConnector);library(SqlRender)
connection<-connect(joseph)
tsql<-readLines('c:/b/coh01.sql');sql<-paste(tsql,collapse="\n")
cat(sql)
cdmDatabaseSchema='OHDSI.dbo'
targetDatabaseSchema='OHDSI.dbo'
targetCohortTable='cohort'
target_cohort_id = '9904'
sql <- SqlRender::renderSql(sql,
cdm_database_schema = cdmDatabaseSchema,
target_database_schema = targetDatabaseSchema,
target_cohort_table = targetCohortTable,
target_cohort_id = target_cohort_id)$sql
sql <- SqlRender::translateSql(sql, targetDialect = attr(connection, "dbms"))$sql
res <- DatabaseConnector::executeSql(connection, sql)
#execute other queries here
#obtain counts
sql2<-sprintf('SELECT cohort_definition_id, COUNT(*) AS count FROM %s.%s GROUP BY cohort_definition_id'
,targetDatabaseSchema,targetCohortTable)
#skipping translation (may not be safe for all) (cutting corner here)
counts<-DatabaseConnector::querySql(connection, sql2)
counts
Assume that the side does not have Atlas and WebAPI working (and for step 1 can simply use the public API (to use public (OHDSI network infrustructure) to convert JSON cohort definition to SQL cohort definition)