Skip to content

Commit

Permalink
#188 update extras/vignettes
Browse files Browse the repository at this point in the history
  • Loading branch information
ginberg committed Apr 5, 2023
1 parent 7df638f commit 298675b
Show file tree
Hide file tree
Showing 9 changed files with 47 additions and 44 deletions.
5 changes: 4 additions & 1 deletion extras/GetHdpsCovariates.R
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
18 changes: 9 additions & 9 deletions extras/TestCode.R
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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),
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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)

Expand Down
22 changes: 11 additions & 11 deletions extras/VignetteDataFetch.R
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ covariateData <- getDbCovariateData(connection = connection,
cohortDatabaseSchema = resultsDatabaseSchema,
cohortTable = cohortsTable,
cohortTableIsTemp = TRUE,
cohortId = 1118084,
cohortIds = c(1118084),
rowIdField = "subject_id",
covariateSettings = covariateSettings)

Expand All @@ -95,7 +95,7 @@ covariateData2 <- getDbCovariateData(connection = connection,
cohortDatabaseSchema = resultsDatabaseSchema,
cohortTable = cohortsTable,
cohortTableIsTemp = TRUE,
cohortId = 1118084,
cohortIds = c(1118084),
covariateSettings = covariateSettings,
aggregated = TRUE)

Expand All @@ -113,7 +113,7 @@ covariateData2b <- getDbCovariateData(connection = connection,
cohortDatabaseSchema = resultsDatabaseSchema,
cohortTable = cohortsTable,
cohortTableIsTemp = TRUE,
cohortId = 1118084,
cohortIds = c(1118084),
covariateSettings = covariateSettings,
aggregated = TRUE)

Expand All @@ -131,7 +131,7 @@ covDiclofenac <- getDbCovariateData(connection = connection,
cohortDatabaseSchema = resultsDatabaseSchema,
cohortTable = cohortsTable,
cohortTableIsTemp = TRUE,
cohortId = 1124300,
cohortIds = c(1124300),
covariateSettings = covariateSettings,
aggregated = TRUE)

Expand All @@ -142,7 +142,7 @@ covCelecoxib <- getDbCovariateData(connection = connection,
cohortDatabaseSchema = resultsDatabaseSchema,
cohortTable = cohortsTable,
cohortTableIsTemp = TRUE,
cohortId = 1118084,
cohortIds = c(1118084),
covariateSettings = covariateSettings,
aggregated = TRUE)

Expand Down Expand Up @@ -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"))
Expand Down Expand Up @@ -244,7 +244,7 @@ covariates <- getDbCovariateData(connection = connection,
cdmDatabaseSchema = cdmDatabaseSchema,
cohortDatabaseSchema = resultsDatabaseSchema,
cohortTable = "rehospitalization",
cohortId = 1,
cohortIds = c(1),
covariateSettings = looCovSet)

aggCovs <- aggregateCovariates(covariates)
Expand All @@ -264,7 +264,7 @@ covariates <- getDbCovariateData(connection = connection,
cdmDatabaseSchema = cdmDatabaseSchema,
cohortDatabaseSchema = resultsDatabaseSchema,
cohortTable = "rehospitalization",
cohortId = 1,
cohortIds = c(1),
covariateSettings = covariateSettingsList)
covariates$analysisRef

Expand Down Expand Up @@ -329,7 +329,7 @@ covariates <- getDbCovariateData(connectionDetails = connectionDetails,
cdmDatabaseSchema = cdmDatabaseSchema,
cohortDatabaseSchema = cohortDatabaseSchema,
cohortTable = "rehospitalization",
cohortId = 1,
cohortIds = c(1),
covariateSettings = looCovSet)
summary(covariates)

Expand All @@ -351,7 +351,7 @@ covariates <- getDbCovariateData(connectionDetails = connectionDetails,
cdmDatabaseSchema = cdmDatabaseSchema,
cohortDatabaseSchema = cohortDatabaseSchema,
cohortTable = "rehospitalization",
cohortId = 1,
cohortIds = c(1),
covariateSettings = covariateSettingsList)


Expand Down
2 changes: 1 addition & 1 deletion tests/testthat/test-CovariateData.R
Original file line number Diff line number Diff line change
Expand Up @@ -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", {
Expand Down
4 changes: 2 additions & 2 deletions vignettes/CreatingCovariatesUsingCohortAttributes.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ covariates <- getDbCovariateData(connectionDetails = connectionDetails,
cdmDatabaseSchema = cdmDatabaseSchema,
cohortDatabaseSchema = cohortDatabaseSchema,
cohortTable = "rehospitalization",
cohortId = 1,
cohortIds = c(1),
covariateSettings = looCovSet)
```

Expand All @@ -155,7 +155,7 @@ covariates <- getDbCovariateData(connectionDetails = connectionDetails,
cdmDatabaseSchema = cdmDatabaseSchema,
cohortDatabaseSchema = resultsDatabaseSchema,
cohortTable = "rehospitalization",
cohortId = 1,
cohortIds = c(1),
covariateSettings = covariateSettingsList)
```

Expand Down
10 changes: 5 additions & 5 deletions vignettes/CreatingCustomCovariateBuilders.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -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?
Expand Down Expand Up @@ -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"))
Expand Down Expand Up @@ -163,7 +163,7 @@ covariates <- getDbCovariateData(connectionDetails = connectionDetails,
cdmDatabaseSchema = cdmDatabaseSchema,
cohortDatabaseSchema = resultsDatabaseSchema,
cohortTable = "rehospitalization",
cohortId = 1,
cohortIds = c(1),
covariateSettings = looCovSet)
```

Expand All @@ -186,7 +186,7 @@ covariates <- getDbCovariateData(connectionDetails = connectionDetails,
cdmDatabaseSchema = cdmDatabaseSchema,
cohortDatabaseSchema = resultsDatabaseSchema,
cohortTable = "rehospitalization",
cohortId = 1,
cohortIds = c(1),
covariateSettings = covariateSettingsList)
```

Expand Down
10 changes: 5 additions & 5 deletions vignettes/CreatingCustomCovariateBuildersKorean.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -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 : 공변량 설정 함수에서 생성된 객체
Expand Down Expand Up @@ -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"))
Expand Down Expand Up @@ -173,7 +173,7 @@ covariates <- getDbCovariateData(connectionDetails = connectionDetails,
cdmDatabaseSchema = cdmDatabaseSchema,
cohortDatabaseSchema = resultsDatabaseSchema,
cohortTable = "rehospitalization",
cohortId = 1,
cohortIds = c(1),
covariateSettings = looCovSet)
```

Expand All @@ -195,7 +195,7 @@ covariates <- getDbCovariateData(connectionDetails = connectionDetails,
cdmDatabaseSchema = cdmDatabaseSchema,
cohortDatabaseSchema = resultsDatabaseSchema,
cohortTable = "rehospitalization",
cohortId = 1,
cohortIds = c(1),
covariateSettings = covariateSettingsList)
```

Expand Down
Loading

0 comments on commit 298675b

Please sign in to comment.