OHDSI / PatientLevelPrediction

An R package for performing patient level prediction in an observational database in the OMOP Common Data Model.
https://ohdsi.github.io/PatientLevelPrediction
188 stars 89 forks source link

Parametrized SQL in "Building patient-level predictive models" #364

Open lcpinheiro opened 1 year ago

lcpinheiro commented 1 year ago

In Building patient-level predictive models, the AfStrokeCohorts.sql script uses the parameter @resultsDatabaseSchema to call that object in R. However, the subsequent code does not use that object, but a different parameter: @cohortsDatabaseSchema.

library(SqlRender)
sql <- [readSql](https://ohdsi.github.io/SqlRender/reference/readSql.html)("AfStrokeCohorts.sql")
sql <- [renderSql](https://ohdsi.github.io/SqlRender/reference/renderSql.html)(sql,
cdmDatabaseSchema = cdmDatabaseSchema,
cohortsDatabaseSchema = cohortsDatabaseSchema,
post_time = 30,
pre_time = 365)$sql
sql <- [translateSql](https://ohdsi.github.io/SqlRender/reference/translateSql.html)(sql, targetDialect = connectionDetails$dbms)$sql

connection <- connect(connectionDetails)
executeSql(connection, sql)

This means the resulting SQL does not replace the parameter and thus throws an error.

jreps commented 1 year ago

Another easy first commit:

Replace '@resultsDatabaseSchema' in the document "Building patient-level prediction models" cohort generation SQL code with '@cohortDatabaseSchema'.

There may also be a bug in this part (I'm not sure we defined resultsDatabaseSchema? so may need to replace resultsDatabaseSchema with cohortDatabaseSchema):

databaseDetails <- createDatabaseDetails( connectionDetails = connectionDetails, cdmDatabaseSchema = cdmDatabaseSchema, cdmDatabaseName = '', cohortDatabaseSchema = resultsDatabaseSchema, cohortTable = 'AFibStrokeCohort', cohortId = 1, outcomeDatabaseSchema = resultsDatabaseSchema, outcomeTable = 'AFibStrokeCohort', outcomeIds = 2, cdmVersion = 5 )

lcpinheiro commented 1 year ago

Thanks, indeed, I changed my SQL file locally. Seems the SQL also creates two tables: PLPAFibStrokeCohort and AFibStrokeCohort, I suppose it's just the one (?).