profile
viewpoint

issue openedOHDSI/SqlRender

DATEDIFF function not rendering correct Postgres or Oracle syntax

DATEDIFF is listed as a supported function across dialects.

However, when use SqlRender to translate the following code: SELECT DISTINCT c.person_id ,inc_dx_strong ,inc_dx_weak ,inc_lab_any ,inc_lab_pos ,'3.0' AS phenotype_version ,CASE WHEN datediff(year, d.birth_datetime, getdate()) BETWEEN 0 AND 4 THEN '0-4' WHEN datediff(year, d.birth_datetime, getdate()) BETWEEN 5 AND 9 THEN '5-9' WHEN datediff(year, d.birth_datetime, getdate()) BETWEEN 10 AND 14 THEN '10-14' WHEN datediff(year, d.birth_datetime, getdate()) BETWEEN 15 AND 19 THEN '15-19' WHEN datediff(year, d.birth_datetime, getdate()) BETWEEN 20 AND 24 THEN '20-24' WHEN datediff(year, d.birth_datetime, getdate()) BETWEEN 25 AND 29 THEN '25-29' WHEN datediff(year, d.birth_datetime, getdate()) BETWEEN 30 AND 34 THEN '30-34' WHEN datediff(year, d.birth_datetime, getdate()) BETWEEN 35 AND 39 THEN '35-39' WHEN datediff(year, d.birth_datetime, getdate()) BETWEEN 40 AND 44 THEN '40-44' WHEN datediff(year, d.birth_datetime, getdate()) BETWEEN 45 AND 49 THEN '45-49' WHEN datediff(year, d.birth_datetime, getdate()) BETWEEN 50 AND 54 THEN '50-54' WHEN datediff(year, d.birth_datetime, getdate()) BETWEEN 55 AND 59 THEN '55-59' WHEN datediff(year, d.birth_datetime, getdate()) BETWEEN 60 AND 64 THEN '60-64' WHEN datediff(year, d.birth_datetime, getdate()) BETWEEN 65 AND 69 THEN '65-69' WHEN datediff(year, d.birth_datetime, getdate()) BETWEEN 70 AND 74 THEN '70-74' WHEN datediff(year, d.birth_datetime, getdate()) BETWEEN 75 AND 79 THEN '75-79' WHEN datediff(year, d.birth_datetime, getdate()) BETWEEN 80 AND 84 THEN '80-84' WHEN datediff(year, d.birth_datetime, getdate()) BETWEEN 85 AND 89 THEN '85-89' WHEN datediff(year, d.birth_datetime, getdate()) >= 90 THEN '90+' END AS pt_age ,d.gender_concept_id AS sex ,d.ethnicity_concept_id AS hispanic ,d.race_concept_id AS race ,( SELECT TOP 1 vocabulary_version FROM @cdmDatabaseSchema.vocabulary WHERE vocabulary_id = 'None' ) AS vocabulary_version FROM cohort c JOIN @cdmDatabaseSchema.person d ON c.person_id = d.person_id;

The Oracle dialect output is: SELECT DISTINCT c.person_id ,inc_dx_strong ,inc_dx_weak ,inc_lab_any ,inc_lab_pos ,'3.0' AS phenotype_version ,CASE WHEN floor(datediff(month, d.birth_date, SYSDATE)/12) BETWEEN 0 and 4 THEN '0-4' WHEN floor(datediff(month, d.birth_date, SYSDATE)/12) BETWEEN 5 and 9 THEN '5-9' WHEN floor(datediff(month, d.birth_date, SYSDATE)/12) BETWEEN 10 and 14 THEN '10-14' WHEN floor(datediff(month, d.birth_date, SYSDATE)/12) BETWEEN 15 and 19 THEN '15-19' WHEN floor(datediff(month, d.birth_date, SYSDATE)/12) BETWEEN 20 and 24 THEN '20-24' WHEN floor(datediff(month, d.birth_date, SYSDATE)/12) BETWEEN 25 and 29 THEN '25-29' WHEN floor(datediff(month, d.birth_date, SYSDATE)/12) BETWEEN 30 and 34 THEN '30-34' WHEN floor(datediff(month, d.birth_date, SYSDATE)/12) BETWEEN 35 and 39 THEN '35-39' WHEN floor(datediff(month, d.birth_date, SYSDATE)/12) BETWEEN 40 and 44 THEN '40-44' WHEN floor(datediff(month, d.birth_date, SYSDATE)/12) BETWEEN 45 and 49 THEN '45-49' WHEN floor(datediff(month, d.birth_date, SYSDATE)/12) BETWEEN 50 and 54 THEN '50-54' WHEN floor(datediff(month, d.birth_date, SYSDATE)/12) BETWEEN 55 and 59 THEN '55-59' WHEN floor(datediff(month, d.birth_date, SYSDATE)/12) BETWEEN 60 and 64 THEN '60-64' WHEN floor(datediff(month, d.birth_date, SYSDATE)/12) BETWEEN 65 and 69 THEN '65-69' WHEN floor(datediff(month, d.birth_date, SYSDATE)/12) BETWEEN 70 and 74 THEN '70-74' WHEN floor(datediff(month, d.birth_date, SYSDATE)/12) BETWEEN 75 and 79 THEN '75-79' WHEN floor(datediff(month, d.birth_date, SYSDATE)/12) BETWEEN 80 and 84 THEN '80-84' WHEN floor(datediff(month, d.birth_date, SYSDATE)/12) BETWEEN 85 and 89 THEN '85-89' WHEN floor(datediff(month, d.birth_date, SYSDATE)/12) >= 90 THEN '90+' END as pt_age,

But the repeating "WHEN floor(datediff(month, d.birth_date, SYSDATE)/12)" is not supported in Oracle. The dialect should be "WHEN floor(months_between(SYSDATE, d.birth_datetime)/12)".

A similar issue arises in Postgres: SELECT DISTINCT c.person_id ,inc_dx_strong ,inc_dx_weak ,inc_lab_any ,inc_lab_pos ,'3.0' AS phenotype_version ,CASE WHEN datediff(year, d.birth_datetime, CURRENT_DATE) BETWEEN 0 AND 4 THEN '0-4' WHEN datediff(year, d.birth_datetime, CURRENT_DATE) BETWEEN 5 AND 9 THEN '5-9' WHEN datediff(year, d.birth_datetime, CURRENT_DATE) BETWEEN 10 AND 14 THEN '10-14' WHEN datediff(year, d.birth_datetime, CURRENT_DATE) BETWEEN 15 AND 19 THEN '15-19' WHEN datediff(year, d.birth_datetime, CURRENT_DATE) BETWEEN 20 AND 24 THEN '20-24' WHEN datediff(year, d.birth_datetime, CURRENT_DATE) BETWEEN 25 AND 29 THEN '25-29' WHEN datediff(year, d.birth_datetime, CURRENT_DATE) BETWEEN 30 AND 34 THEN '30-34' WHEN datediff(year, d.birth_datetime, CURRENT_DATE) BETWEEN 35 AND 39 THEN '35-39' WHEN datediff(year, d.birth_datetime, CURRENT_DATE) BETWEEN 40 AND 44 THEN '40-44' WHEN datediff(year, d.birth_datetime, CURRENT_DATE) BETWEEN 45 AND 49 THEN '45-49' WHEN datediff(year, d.birth_datetime, CURRENT_DATE) BETWEEN 50 AND 54 THEN '50-54' WHEN datediff(year, d.birth_datetime, CURRENT_DATE) BETWEEN 55 AND 59 THEN '55-59' WHEN datediff(year, d.birth_datetime, CURRENT_DATE) BETWEEN 60 AND 64 THEN '60-64' WHEN datediff(year, d.birth_datetime, CURRENT_DATE) BETWEEN 65 AND 69 THEN '65-69' WHEN datediff(year, d.birth_datetime, CURRENT_DATE) BETWEEN 70 AND 74 THEN '70-74' WHEN datediff(year, d.birth_datetime, CURRENT_DATE) BETWEEN 75 AND 79 THEN '75-79' WHEN datediff(year, d.birth_datetime, CURRENT_DATE) BETWEEN 80 AND 84 THEN '80-84' WHEN datediff(year, d.birth_datetime, CURRENT_DATE) BETWEEN 85 AND 89 THEN '85-89' WHEN datediff(year, d.birth_datetime, CURRENT_DATE) >= 90 THEN '90+' END AS pt_age

The syntax "WHEN datediff(year, d.birth_datetime, CURRENT_DATE)" is not supported in Postgres. It should be "DATE_PART('year', CURRENT_DATE) - DATE_PART('year', d.birth_datetime)".

If additional context is helpful, this is our overall GitHub Repo. We began to see reports of this DATEDIFF issue as we are about to release branch Phenotype-3.0 and there were multiple sites who reported issues with the translation of this function.

created time in 13 hours

startedprivatenumber/vue-2-3

started time in 19 hours

startedZettlr/Zettlr

started time in 2 days

startedben-rogerson/twin.macro

started time in 2 days

startedDustinBrett/x

started time in 2 days

startedGopherJ/Vs

started time in 2 days

push eventOHDSI/Cyclops

jianxiaoyang

commit sha 1d4572a7fc27d39894bb24a1ed91e83a50b18b3f

implement fine-gray model with three kernels

view details

push time in 2 days

startedanders-biostat/sleepwalk

started time in 3 days

startedFil/d3-inertia

started time in 3 days

startedFil/d3-tricontour

started time in 3 days

startedFil/attitude

started time in 3 days

startedrstudio/leaflet.mapboxgl

started time in 3 days

startedwalkerke/mapboxapi

started time in 3 days

startedvarkor/quiver

started time in 4 days

startedchangkun/modern-cpp-tutorial

started time in 4 days

startedspectresystems/spectre.console

started time in 4 days

issue commentOHDSI/FeatureExtraction

Covariates from in-cohort period?

Sorry, that is not support by FeatureExtraction

ted9219

comment created time in 5 days

push eventOHDSI/FeatureExtraction

Schuemie

commit sha e65172d01abf8e700af218d051cc19758e74bf87

Fix typo

view details

push time in 5 days

issue openedOHDSI/FeatureExtraction

Covariates from in-cohort period?

Hi,

I use the FeatureExtraction package (especially temporal feature function) for constructing covariates not only before the index date but after the index date. The covariates with the timeID are useful for tracking how many patients were using that covariate.

but I can't find the options restricting the covariate period in each patient. How can I restrict the covariates from only the in-cohort period (from cohort_start_date to cohort_end_date)?

For example, I want to get the drug_expousure covariates from each patient's inpatient period. To my knowledge, in createTemporalCovariateSettings, I can define the same end day only adding to cohort_start_date for all patients.

As you know, we can restrict the time period for each patient after getting the whole covariates in R. However, I think it is inefficient.

If I have something missed or if you have any other options or comments, please let me know.

Best wishes, Chungsoo

created time in 5 days

push eventOHDSI/PhenotypeLibrary

Gowtham Rao

commit sha 4e944832fd192b333e18eb1ac9fc73322f80653d

Changed phenotype description for osetoarthritis (added inflammation) for myasthenia gravis (added acquired) added design diagnostics work for existing concepts

view details

push time in 6 days

Pull request review commentOHDSI/DatabaseConnector

Add downloadJdbcDrivers function and remove dependency on DatabaseConnectorJars package.

 createConnectionDetails <- function(dbms, }  jdbcDrivers <- new.env()+jdbcDrivers$defaultPath <- Sys.getenv("DATABASECONNECTOR_JAR_FOLDER", +                                      unset = path.expand("~/DatabaseConnectorDrivers"))

Why store an environmental variable in a global variable? This way updates to the environmental variable will have no impact. Can't we just always refer to the environmental variable throughout the code?

ablack3

comment created time in 6 days

Pull request review commentOHDSI/DatabaseConnector

Add downloadJdbcDrivers function and remove dependency on DatabaseConnectorJars package.

 createConnectionDetails <- function(dbms, }  jdbcDrivers <- new.env()+jdbcDrivers$defaultPath <- Sys.getenv("DATABASECONNECTOR_JAR_FOLDER", +                                      unset = path.expand("~/DatabaseConnectorDrivers"))++#' Download DatabaseConnector JDBC Jar files+#' +#' Download the DatabaseConnector JDBC drivers from https://github.com/OHDSI +#'+#' @param destination The full path to the folder where the Jar files should be downloaded to.+#'        If NULL (default) then the value of the environment variable "DATABASECONNECTOR_JAR_FOLDER" is used.+#'        If DATABASECONNECTOR_JAR_FOLDER is not set then "~/DatabaseConnectorDrivers" is used.+#' @param method The method used for downloading files. See \code{?download.file} for details and options.+#' @param ... Further arguments passed on to \code{download.file} +#' +#' @return Invisibly returns the destination if the download was successful.+#' @export+#'+#' @examples+#' \dontrun{+#' downloadJdbcDrivers()+#' }+downloadJdbcDrivers <- function(destination = NULL, method = "auto", ...){+  if (is.null(destination) || missing(destination)) {+    destination <- jdbcDrivers$defaultPath+  }+  +  if (!dir.exists(destination)) dir.create(destination)+  +  baseUrl <- "https://github.com/OHDSI/DatabaseConnectorJars/blob/master/inst/java"+  jdbcDriverNames <- c("RedshiftJDBC4-no-awssdk-1.2.20.1043.jar",+                       "ojdbc8.jar",+                       "postgresql-42.2.5.jre6.jar",+                       "sqljdbc4.jar")+  

RedShift now requires a ton of jars to be installed (which is why we're being refused by CRAN). We need to install all of those (which also argues for allowing users to specify which driver to install).

ablack3

comment created time in 6 days

Pull request review commentOHDSI/DatabaseConnector

Add downloadJdbcDrivers function and remove dependency on DatabaseConnectorJars package.

 createConnectionDetails <- function(dbms, }  jdbcDrivers <- new.env()+jdbcDrivers$defaultPath <- Sys.getenv("DATABASECONNECTOR_JAR_FOLDER", +                                      unset = path.expand("~/DatabaseConnectorDrivers"))++#' Download DatabaseConnector JDBC Jar files+#' +#' Download the DatabaseConnector JDBC drivers from https://github.com/OHDSI +#'+#' @param destination The full path to the folder where the Jar files should be downloaded to.+#'        If NULL (default) then the value of the environment variable "DATABASECONNECTOR_JAR_FOLDER" is used.+#'        If DATABASECONNECTOR_JAR_FOLDER is not set then "~/DatabaseConnectorDrivers" is used.+#' @param method The method used for downloading files. See \code{?download.file} for details and options.+#' @param ... Further arguments passed on to \code{download.file} +#' +#' @return Invisibly returns the destination if the download was successful.+#' @export+#'+#' @examples+#' \dontrun{+#' downloadJdbcDrivers()+#' }+downloadJdbcDrivers <- function(destination = NULL, method = "auto", ...){+  if (is.null(destination) || missing(destination)) {

Should we allow the user to specify which JDBC driver to download? Likely they'll only need one.

ablack3

comment created time in 6 days

push eventOHDSI/Cyclops

jianxiaoyang

commit sha 01f906d3c70c93eedc2ab751ab5f1fb8542e48e0

first commit regarding to fine-gray model

view details

push time in 6 days

push eventOHDSI/PhenotypeLibrary

Gowtham Rao

commit sha e536596d876539de8baf96a6e8a492fc457ee110

Added script to perform design diagnostics, generated DesignDiagnosticsConcepts.xlsx xlsx

view details

push time in 6 days

push eventOHDSI/Cyclops

jianxiaoyang

commit sha 71658f8b25a78f4c87800eee8f95e140bba5bba7

turn off debug printing for benchmark

view details

push time in 6 days

push eventOHDSI/Cyclops

jianxiaoyang

commit sha cc641510b9cb3257272a8f1b4defc181458161e8

remember to check hessian

view details

push time in 6 days

startedextendr/extendr

started time in 6 days

startedextendr/rextendr

started time in 6 days

more