Skip to content

Commit

Permalink
Some workarounds for issues related to 64-bit cohort IDs
Browse files Browse the repository at this point in the history
  • Loading branch information
schuemie committed Jan 13, 2021
1 parent 51f9a70 commit 6ffbb32
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 13 deletions.
1 change: 1 addition & 0 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ Imports:
dplyr,
bit64,
readr,
purrr,
rlang,
SqlRender (>= 1.6.5),
pROC,
Expand Down
2 changes: 1 addition & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ Bugfixes:

1. Fixed error during positive control synthesis for platforms using `oracleTempSchema`.

2. Correctly handling 64-bit integer covariate IDs.
2. Correctly handling 64-bit integer covariate and cohort IDs.


MethodEvaluation 2.0.0
Expand Down
19 changes: 8 additions & 11 deletions R/PositiveControlSynthesis.R
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@
#' @export
synthesizePositiveControls <- function(connectionDetails,
cdmDatabaseSchema,
oracleTempSchema = cdmDatabaseSchema,
oracleTempSchema = NULL,
exposureDatabaseSchema = cdmDatabaseSchema,
exposureTable = "drug_era",
outcomeDatabaseSchema = cdmDatabaseSchema,
Expand Down Expand Up @@ -251,8 +251,7 @@ synthesizePositiveControls <- function(connectionDetails,
packageName = "MethodEvaluation",
dbms = connectionDetails$dbms,
oracleTempSchema = oracleTempSchema)
exposures <- DatabaseConnector::querySql(conn, exposureSql)
names(exposures) <- SqlRender::snakeCaseToCamelCase(names(exposures))
exposures <- DatabaseConnector::querySql(conn, exposureSql, snakeCaseToCamelCase = TRUE)
exposures <- exposures[order(exposures$rowId), ]
saveRDS(exposures, exposuresFile)
}
Expand Down Expand Up @@ -280,8 +279,7 @@ synthesizePositiveControls <- function(connectionDetails,
outcome_database_schema = outcomeDatabaseSchema,
outcome_table = outcomeTable,
first_outcome_only = firstOutcomeOnly)
priorOutcomes <- DatabaseConnector::querySql(conn, outcomeSql)
names(priorOutcomes) <- SqlRender::snakeCaseToCamelCase(names(priorOutcomes))
priorOutcomes <- DatabaseConnector::querySql(conn, outcomeSql, snakeCaseToCamelCase = TRUE)
saveRDS(priorOutcomes, priorOutcomesFile)
sql <- "TRUNCATE TABLE #exposure_outcome; DROP TABLE #exposure_outcome;"
sql <- SqlRender::translate(sql, targetDialect = connectionDetails$dbms, oracleTempSchema = oracleTempSchema)
Expand Down Expand Up @@ -311,8 +309,7 @@ synthesizePositiveControls <- function(connectionDetails,
outcome_database_schema = outcomeDatabaseSchema,
outcome_table = outcomeTable,
first_outcome_only = firstOutcomeOnly)
outcomeCounts <- DatabaseConnector::querySql(conn, outcomeSql)
names(outcomeCounts) <- SqlRender::snakeCaseToCamelCase(names(outcomeCounts))
outcomeCounts <- DatabaseConnector::querySql(conn, outcomeSql, snakeCaseToCamelCase = TRUE)
saveRDS(outcomeCounts, outcomesFile)
sql <- "TRUNCATE TABLE #exposure_outcome; DROP TABLE #exposure_outcome;"
sql <- SqlRender::translate(sql, targetDialect = connectionDetails$dbms, oracleTempSchema = oracleTempSchema)
Expand Down Expand Up @@ -363,8 +360,7 @@ synthesizePositiveControls <- function(connectionDetails,
mutate(outcomeId = !!outcomeId)
return(resultRows)
}
resultRows <- lapply(unique(result$outcomeId), generateCounts)
resultRows <- bind_rows(resultRows)
resultRows <- purrr::map_dfr(unique(result$outcomeId), generateCounts)
result <- left_join(result, resultRows, by = c("exposureId", "outcomeId")) %>%
mutate(exposures = case_when(is.na(exposures) ~ as.integer(0),
TRUE ~ as.integer(.data$exposures)),
Expand All @@ -388,7 +384,7 @@ synthesizePositiveControls <- function(connectionDetails,
return(exposureIds[order(exposureIds)])
}
outcomeIds <- unique(exposureOutcomePairs$outcomeId)
groups <- lapply(unique(outcomeIds), group)
groups <- purrr::map(unique(outcomeIds), group)
uniqueGroups <- unique(groups)
saveRDS(uniqueGroups, file.path(workFolder, "uniqueGroups.rds"))
outcomeIdToGroupId <- data.frame(outcomeIds = outcomeIds, groupIds = match(groups, uniqueGroups))
Expand Down Expand Up @@ -460,7 +456,8 @@ synthesizePositiveControls <- function(connectionDetails,
tasks <- list()
modelsWithEnoughOutcomes <- 0
outcomeIds <- unique(exposureOutcomePairs$outcomeId)
for (outcomeId in outcomeIds) {
for (i in 1:length(outcomeIds)) {
outcomeId <- outcomeIds[i]
groupId <- outcomeIdToGroupId$groupId[outcomeIdToGroupId$outcomeId == outcomeId]
groupExposureIds <- uniqueGroups[[groupId]]
idx <- result$outcomeId == outcomeId &
Expand Down
2 changes: 1 addition & 1 deletion man/synthesizePositiveControls.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 6ffbb32

Please sign in to comment.