From 298675be8a06e713b3d7128fb394b4a231337963 Mon Sep 17 00:00:00 2001 From: Ger Inberg Date: Wed, 5 Apr 2023 12:59:35 +0200 Subject: [PATCH] #188 update extras/vignettes --- extras/GetHdpsCovariates.R | 5 ++++- extras/TestCode.R | 18 +++++++-------- extras/VignetteDataFetch.R | 22 +++++++++---------- tests/testthat/test-CovariateData.R | 2 +- ...reatingCovariatesUsingCohortAttributes.Rmd | 4 ++-- vignettes/CreatingCustomCovariateBuilders.Rmd | 10 ++++----- .../CreatingCustomCovariateBuildersKorean.Rmd | 10 ++++----- vignettes/UsingFeatureExtraction.Rmd | 10 ++++----- vignettes/UsingFeatureExtractionKorean.Rmd | 10 ++++----- 9 files changed, 47 insertions(+), 44 deletions(-) diff --git a/extras/GetHdpsCovariates.R b/extras/GetHdpsCovariates.R index 3dd35b6a..ac596e47 100644 --- a/extras/GetHdpsCovariates.R +++ b/extras/GetHdpsCovariates.R @@ -37,11 +37,14 @@ getDbHdpsCovariateData <- function(connection, cdmDatabaseSchema, cohortTable = "cohort_person", cohortId = -1, + cohortIds = c(-1), cdmVersion = "5", rowIdField = "subject_id", covariateSettings, aggregated = FALSE) { - if (cohortId != -1) + if (!missing(cohortId)) + stop("cohortId argument has been deprecated, please use cohortIds") + if (cohortIds != -1) stop("Haven't implemented restricting to cohort ID yet.") if (aggregated) stop("Aggregation not implemented yet") diff --git a/extras/TestCode.R b/extras/TestCode.R index 9a49ee81..a9ba4e9b 100644 --- a/extras/TestCode.R +++ b/extras/TestCode.R @@ -188,7 +188,7 @@ covs <- getDbCovariateData(connectionDetails = connectionDetails, cdmDatabaseSchema = cdmDatabaseSchema, cohortDatabaseSchema = cohortDatabaseSchema, cohortTable = cohortTable, - cohortId = c(740910, 945286), + cohortIds = c(740910, 945286), rowIdField = "row_id", cohortTableIsTemp = FALSE, covariateSettings = settings, @@ -222,7 +222,7 @@ covs <- getDbCovariateData(connectionDetails = connectionDetails, cdmDatabaseSchema = cdmDatabaseSchema, cohortDatabaseSchema = cohortDatabaseSchema, cohortTable = cohortTable, - cohortId = 1, + cohortIds = c(1), rowIdField = "row_id", cohortTableIsTemp = FALSE, covariateSettings = list(settings, settings2), @@ -238,7 +238,7 @@ covs <- getDbCovariateData(connectionDetails = connectionDetails, cdmDatabaseSchema = cdmDatabaseSchema, cohortDatabaseSchema = cohortDatabaseSchema, cohortTable = cohortTable, - cohortId = 1, + cohortIds = c(1), rowIdField = "row_id", cohortTableIsTemp = FALSE, covariateSettings = covariateSettings, @@ -261,7 +261,7 @@ covs <- getDbCovariateData(connectionDetails = connectionDetails, cdmDatabaseSchema = cdmDatabaseSchema, cohortDatabaseSchema = cohortDatabaseSchema, cohortTable = cohortTable, - cohortId = 1, + cohortIds = c(1), rowIdField = "row_id", cohortTableIsTemp = FALSE, covariateSettings = covariateSettings, @@ -274,7 +274,7 @@ aggCovs <- getDbCovariateData(connectionDetails = connectionDetails, cdmDatabaseSchema = cdmDatabaseSchema, cohortDatabaseSchema = cohortDatabaseSchema, cohortTable = cohortTable, - cohortId = 1, + cohortIds = c(1), rowIdField = "row_id", cohortTableIsTemp = FALSE, covariateSettings = covariateSettings, @@ -304,7 +304,7 @@ getDbDefaultCovariateData(connection = conn, oracleTempSchema = oracleTempSchema, cdmDatabaseSchema = cdmDatabaseSchema, cohortTable = paste(cohortDatabaseSchema, cohortTable, sep = "."), - cohortId = -1, + cohortIds = c(-1), rowIdField = "row_id", covariateSettings = settings, targetCovariateTable = "#my_covs", @@ -402,7 +402,7 @@ covs <- getDbCovariateData(connectionDetails = connectionDetails, cdmDatabaseSchema = cdmDatabaseSchema, cohortDatabaseSchema = cohortDatabaseSchema, cohortTable = cohortTable, - cohortId = 1, + cohortIds = c(1), rowIdField = "row_id", cohortTableIsTemp = FALSE, covariateSettings = settings, @@ -541,7 +541,7 @@ covs <- getDbCovariateData(connectionDetails = connectionDetails, cdmDatabaseSchema = "main", cohortDatabaseSchema = "main", cohortTable = "cohort", - cohortId = c(2^34), + cohortIds = c(2^34), covariateSettings = settings, aggregated = TRUE) @@ -595,7 +595,7 @@ covs <- getDbCovariateData(connectionDetails = connectionDetails, cdmDatabaseSchema = "main", cohortDatabaseSchema = "main", cohortTable = "cohort", - cohortId = c(1,2), + cohortIds = c(1,2), covariateSettings = settings, aggregated = TRUE) diff --git a/extras/VignetteDataFetch.R b/extras/VignetteDataFetch.R index e269a3c5..84664461 100644 --- a/extras/VignetteDataFetch.R +++ b/extras/VignetteDataFetch.R @@ -69,7 +69,7 @@ covariateData <- getDbCovariateData(connection = connection, cohortDatabaseSchema = resultsDatabaseSchema, cohortTable = cohortsTable, cohortTableIsTemp = TRUE, - cohortId = 1118084, + cohortIds = c(1118084), rowIdField = "subject_id", covariateSettings = covariateSettings) @@ -95,7 +95,7 @@ covariateData2 <- getDbCovariateData(connection = connection, cohortDatabaseSchema = resultsDatabaseSchema, cohortTable = cohortsTable, cohortTableIsTemp = TRUE, - cohortId = 1118084, + cohortIds = c(1118084), covariateSettings = covariateSettings, aggregated = TRUE) @@ -113,7 +113,7 @@ covariateData2b <- getDbCovariateData(connection = connection, cohortDatabaseSchema = resultsDatabaseSchema, cohortTable = cohortsTable, cohortTableIsTemp = TRUE, - cohortId = 1118084, + cohortIds = c(1118084), covariateSettings = covariateSettings, aggregated = TRUE) @@ -131,7 +131,7 @@ covDiclofenac <- getDbCovariateData(connection = connection, cohortDatabaseSchema = resultsDatabaseSchema, cohortTable = cohortsTable, cohortTableIsTemp = TRUE, - cohortId = 1124300, + cohortIds = c(1124300), covariateSettings = covariateSettings, aggregated = TRUE) @@ -142,7 +142,7 @@ covCelecoxib <- getDbCovariateData(connection = connection, cohortDatabaseSchema = resultsDatabaseSchema, cohortTable = cohortsTable, cohortTableIsTemp = TRUE, - cohortId = 1118084, + cohortIds = c(1118084), covariateSettings = covariateSettings, aggregated = TRUE) @@ -202,10 +202,10 @@ getDbLooCovariateData <- function(connection, "ON op.person_id = c.subject_id", "WHERE cohort_start_date >= observation_period_start_date", "AND cohort_start_date <= observation_period_end_date", - "{@cohort_id != -1} ? {AND cohort_definition_id = @cohort_id}") + "{@cohort_ids != -1} ? {AND cohort_definition_id IN @cohort_ids}") sql <- SqlRender::render(sql, cohort_table = cohortTable, - cohort_id = cohortId, + cohort_ids = cohortIds, row_id_field = rowIdField, cdm_database_schema = cdmDatabaseSchema) sql <- SqlRender::translate(sql, targetDialect = attr(connection, "dbms")) @@ -244,7 +244,7 @@ covariates <- getDbCovariateData(connection = connection, cdmDatabaseSchema = cdmDatabaseSchema, cohortDatabaseSchema = resultsDatabaseSchema, cohortTable = "rehospitalization", - cohortId = 1, + cohortIds = c(1), covariateSettings = looCovSet) aggCovs <- aggregateCovariates(covariates) @@ -264,7 +264,7 @@ covariates <- getDbCovariateData(connection = connection, cdmDatabaseSchema = cdmDatabaseSchema, cohortDatabaseSchema = resultsDatabaseSchema, cohortTable = "rehospitalization", - cohortId = 1, + cohortIds = c(1), covariateSettings = covariateSettingsList) covariates$analysisRef @@ -329,7 +329,7 @@ covariates <- getDbCovariateData(connectionDetails = connectionDetails, cdmDatabaseSchema = cdmDatabaseSchema, cohortDatabaseSchema = cohortDatabaseSchema, cohortTable = "rehospitalization", - cohortId = 1, + cohortIds = c(1), covariateSettings = looCovSet) summary(covariates) @@ -351,7 +351,7 @@ covariates <- getDbCovariateData(connectionDetails = connectionDetails, cdmDatabaseSchema = cdmDatabaseSchema, cohortDatabaseSchema = cohortDatabaseSchema, cohortTable = "rehospitalization", - cohortId = 1, + cohortIds = c(1), covariateSettings = covariateSettingsList) diff --git a/tests/testthat/test-CovariateData.R b/tests/testthat/test-CovariateData.R index fb4630d0..18b7cb4c 100644 --- a/tests/testthat/test-CovariateData.R +++ b/tests/testthat/test-CovariateData.R @@ -79,7 +79,7 @@ test_that("test summary call for covariateData class", { sumOut <- summary(covariateData) Andromeda::close(covariateData) - expect_equal(sumOut$metaData$cohortId, 1L) + expect_equal(sumOut$metaData$cohortIds, 1L) }) test_that("test loadCovariateData", { diff --git a/vignettes/CreatingCovariatesUsingCohortAttributes.Rmd b/vignettes/CreatingCovariatesUsingCohortAttributes.Rmd index 75e7575f..8d2a4367 100644 --- a/vignettes/CreatingCovariatesUsingCohortAttributes.Rmd +++ b/vignettes/CreatingCovariatesUsingCohortAttributes.Rmd @@ -130,7 +130,7 @@ covariates <- getDbCovariateData(connectionDetails = connectionDetails, cdmDatabaseSchema = cdmDatabaseSchema, cohortDatabaseSchema = cohortDatabaseSchema, cohortTable = "rehospitalization", - cohortId = 1, + cohortIds = c(1), covariateSettings = looCovSet) ``` @@ -155,7 +155,7 @@ covariates <- getDbCovariateData(connectionDetails = connectionDetails, cdmDatabaseSchema = cdmDatabaseSchema, cohortDatabaseSchema = resultsDatabaseSchema, cohortTable = "rehospitalization", - cohortId = 1, + cohortIds = c(1), covariateSettings = covariateSettingsList) ``` diff --git a/vignettes/CreatingCustomCovariateBuilders.Rmd b/vignettes/CreatingCustomCovariateBuilders.Rmd index 8c233677..eaeb34e3 100644 --- a/vignettes/CreatingCustomCovariateBuilders.Rmd +++ b/vignettes/CreatingCustomCovariateBuilders.Rmd @@ -68,7 +68,7 @@ The covariate construction function has to accept the following arguments: * `cdmDatabaseSchema`: The name of the database schema that contains the OMOP CDM instance. On SQL Server, this will specify both the database and the schema, so for example 'cdm_instance.dbo'. * `cdmVersion`: Defines the OMOP CDM version used: currently supports "4" and "5". * `cohortTable`: Name of the table holding the cohort for which we want to construct covariates. This is a fully specified name, so either the name of a temp table (e.g. '#cohort_table'), or a permanent table including its database schema (e.g. 'cdm_schema.dbo.cohort'). -* `cohortId`: The cohort definition ID of the cohort. If set to -1, use all entries in the cohort table. +* `cohortIds`: The cohort definition IDs of the cohort. If set to -1, use all entries in the cohort table. * `rowIdField`: The name of the field in the cohort temp table that is to be used as the row_id field in the output table. This can be especially usefull if there is more than one period per person. * `covariateSettings`: The object created in your covariate settings function. * `aggregated`: Should covariates be constructed per-person, or aggregated across the cohort? @@ -113,10 +113,10 @@ getDbLooCovariateData <- function(connection, "ON op.person_id = c.subject_id", "WHERE cohort_start_date >= observation_period_start_date", "AND cohort_start_date <= observation_period_end_date", - "{@cohort_id != -1} ? {AND cohort_definition_id = @cohort_id}") + "{@cohort_ids != -1} ? {AND cohort_definition_id IN @cohort_ids}") sql <- SqlRender::render(sql, cohort_table = cohortTable, - cohort_id = cohortId, + cohort_ids = cohortIds, row_id_field = rowIdField, cdm_database_schema = cdmDatabaseSchema) sql <- SqlRender::translate(sql, targetDialect = attr(connection, "dbms")) @@ -163,7 +163,7 @@ covariates <- getDbCovariateData(connectionDetails = connectionDetails, cdmDatabaseSchema = cdmDatabaseSchema, cohortDatabaseSchema = resultsDatabaseSchema, cohortTable = "rehospitalization", - cohortId = 1, + cohortIds = c(1), covariateSettings = looCovSet) ``` @@ -186,7 +186,7 @@ covariates <- getDbCovariateData(connectionDetails = connectionDetails, cdmDatabaseSchema = cdmDatabaseSchema, cohortDatabaseSchema = resultsDatabaseSchema, cohortTable = "rehospitalization", - cohortId = 1, + cohortIds = c(1), covariateSettings = covariateSettingsList) ``` diff --git a/vignettes/CreatingCustomCovariateBuildersKorean.Rmd b/vignettes/CreatingCustomCovariateBuildersKorean.Rmd index a4c5eed7..2e6e496f 100644 --- a/vignettes/CreatingCustomCovariateBuildersKorean.Rmd +++ b/vignettes/CreatingCustomCovariateBuildersKorean.Rmd @@ -71,7 +71,7 @@ createLooCovariateSettings <- function(useLengthOfObs = TRUE) { - cdmDatabaseSchema : OMOP CDM 인스턴스를 포함하는 데이터베이스 스키마의 이름. SQL SQL 서버에서 이것은 데이터베이스와 스키마를 모두 지정한다(예: cdm_instance.dbo) - cdmVersion : 사용되는 OMOP CDM 버전 정의: 현재 "4" 및 "5" 지원 - cohortTable : 우리가 공변량을 구성하고자 하는 코호트를 보유하고 있는 테이블의 이름. 이것은 완전히 구체적인 이름이므로 임시테이블의 이름(예: '#cohort_table') 또는 데이터베이스 스키마가 포함된 영구 테이블(예: 'cdm_schema.dbo.cohort)이 될 수 있다. -- cohortId : 코호트의 코호트 정의 ID. -1로 설정된 경우 코호트 테이블의 모든 항목을 사용하면 된다. +- cohortIds : 코호트의 코호트 정의 ID. -1로 설정된 경우 코호트 테이블의 모든 항목을 사용하면 된다. - cdmVersion : 공통 데이터 모델 버전 - rowIdField : 결과 테이블에서 row_id 필드로 사용될 코호트 임시 테이블의 필드 이름이다. 1인당 1개이상의 기간이 있는 경우 특히 유용하다. - covariateSettings : 공변량 설정 함수에서 생성된 객체 @@ -116,10 +116,10 @@ getDbLooCovariateData <- function(connection, "ON op.person_id = c.subject_id", "WHERE cohort_start_date >= observation_period_start_date", "AND cohort_start_date <= observation_period_end_date", - "{@cohort_id != -1} ? {AND cohort_definition_id = @cohort_id}") + "{@cohort_ids != -1} ? {AND cohort_definition_id IN @cohort_ids}") sql <- SqlRender::render(sql, cohort_table = cohortTable, - cohort_id = cohortId, + cohort_ids = cohortIds, row_id_field = rowIdField, cdm_database_schema = cdmDatabaseSchema) sql <- SqlRender::translate(sql, targetDialect = attr(connection, "dbms")) @@ -173,7 +173,7 @@ covariates <- getDbCovariateData(connectionDetails = connectionDetails, cdmDatabaseSchema = cdmDatabaseSchema, cohortDatabaseSchema = resultsDatabaseSchema, cohortTable = "rehospitalization", - cohortId = 1, + cohortIds = c(1), covariateSettings = looCovSet) ``` @@ -195,7 +195,7 @@ covariates <- getDbCovariateData(connectionDetails = connectionDetails, cdmDatabaseSchema = cdmDatabaseSchema, cohortDatabaseSchema = resultsDatabaseSchema, cohortTable = "rehospitalization", - cohortId = 1, + cohortIds = c(1), covariateSettings = covariateSettingsList) ``` diff --git a/vignettes/UsingFeatureExtraction.Rmd b/vignettes/UsingFeatureExtraction.Rmd index dcbd0e6f..e7a1b74d 100644 --- a/vignettes/UsingFeatureExtraction.Rmd +++ b/vignettes/UsingFeatureExtraction.Rmd @@ -277,7 +277,7 @@ covariateData <- getDbCovariateData(connectionDetails = connectionDetails, cdmDatabaseSchema = cdmDatabaseSchema, cohortDatabaseSchema = resultsDatabaseSchema, cohortTable = "cohorts_of_interest", - cohortId = 1118084, + cohortIds = c(1118084), rowIdField = "subject_id", covariateSettings = covariateSettings) @@ -399,7 +399,7 @@ covariateData2 <- getDbCovariateData(connectionDetails = connectionDetails, cdmDatabaseSchema = cdmDatabaseSchema, cohortDatabaseSchema = resultsDatabaseSchema, cohortTable = "cohorts_of_interest", - cohortId = 1118084, + cohortIds = c(1118084), covariateSettings = covariateSettings, aggregated = TRUE) summary(covariateData2) @@ -475,7 +475,7 @@ covariateData2b <- getDbCovariateData(connectionDetails = connectionDetails, cdmDatabaseSchema = cdmDatabaseSchema, cohortDatabaseSchema = resultsDatabaseSchema, cohortTable = "cohorts_of_interest", - cohortId = 1118084, + cohortIds = c(1118084), covariateSettings = covariateSettings, aggregated = TRUE) summary(covariateData2b) @@ -499,7 +499,7 @@ covCelecoxib <- getDbCovariateData(connectionDetails = connectionDetails, cdmDatabaseSchema = cdmDatabaseSchema, cohortDatabaseSchema = resultsDatabaseSchema, cohortTable = "cohorts_of_interest", - cohortId = 1118084, + cohortIds = c(1118084), covariateSettings = settings, aggregated = TRUE) @@ -507,7 +507,7 @@ covDiclofenac <- getDbCovariateData(connectionDetails = connectionDetails, cdmDatabaseSchema = cdmDatabaseSchema, cohortDatabaseSchema = resultsDatabaseSchema, cohortTable = "cohorts_of_interest", - cohortId = 1124300, + cohortIds = c(1124300), covariateSettings = settings, aggregated = TRUE) diff --git a/vignettes/UsingFeatureExtractionKorean.Rmd b/vignettes/UsingFeatureExtractionKorean.Rmd index 6655cefe..2b6dcefa 100644 --- a/vignettes/UsingFeatureExtractionKorean.Rmd +++ b/vignettes/UsingFeatureExtractionKorean.Rmd @@ -287,7 +287,7 @@ covariateData <- getDbCovariateData(connectionDetails = connectionDetails, cdmDatabaseSchema = cdmDatabaseSchema, cohortDatabaseSchema = resultsDatabaseSchema, cohortTable = "cohorts_of_interest", - cohortId = 1118084, + cohortIds = c(1118084), rowIdField = "subject_id", covariateSettings = covariateSettings) @@ -392,7 +392,7 @@ covariateData2 <- getDbCovariateData(connectionDetails = connectionDetails, cdmDatabaseSchema = cdmDatabaseSchema, cohortDatabaseSchema = resultsDatabaseSchema, cohortTable = "cohorts_of_interest", - cohortId = 1118084, + cohortIds = c(1118084), covariateSettings = covariateSettings, aggregated = TRUE) summary(covariateData2) @@ -470,7 +470,7 @@ covariateData2b <- getDbCovariateData(connectionDetails = connectionDetails, cdmDatabaseSchema = cdmDatabaseSchema, cohortDatabaseSchema = resultsDatabaseSchema, cohortTable = "cohorts_of_interest", - cohortId = 1118084, + cohortIds = c(1118084), covariateSettings = covariateSettings, aggregated = TRUE) summary(covariateData2b) @@ -496,7 +496,7 @@ covCelecoxib <- getDbCovariateData(connectionDetails = connectionDetails, cdmDatabaseSchema = cdmDatabaseSchema, cohortDatabaseSchema = resultsDatabaseSchema, cohortTable = "cohorts_of_interest", - cohortId = 1118084, + cohortIds = c(1118084), covariateSettings = settings, aggregated = TRUE) @@ -504,7 +504,7 @@ covDiclofenac <- getDbCovariateData(connectionDetails = connectionDetails, cdmDatabaseSchema = cdmDatabaseSchema, cohortDatabaseSchema = resultsDatabaseSchema, cohortTable = "cohorts_of_interest", - cohortId = 1124300, + cohortIds = c(1124300), covariateSettings = settings, aggregated = TRUE)