Skip to content

Commit

Permalink
no prefix, guard against missing attributes
Browse files Browse the repository at this point in the history
  • Loading branch information
edward-burn committed Sep 25, 2024
1 parent 78ff92a commit db1fc1d
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 5 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: CohortConstructor
Title: Build and Manipulate Study Cohorts Using a Common Data Model
Version: 0.3.0
Version: 0.3.0.900
Authors@R: c(
person("Edward", "Burn", , "[email protected]",
role = c("aut", "cre"), comment = c(ORCID = "0000-0002-9286-1128")),
Expand Down
25 changes: 21 additions & 4 deletions R/conceptCohort.R
Original file line number Diff line number Diff line change
Expand Up @@ -382,12 +382,26 @@ reportConceptsFromUnsopportedDomains <- function(cdm,
}

addIndex <- function(cdm, name, cols) {
dbType <- attr(attr(cdm[[name]], "tbl_source"), "source_type")
tblSource <- attr(cdm[[name]], "tbl_source")
if(is.null(tblSource)){
return(invisible(NULL))
}
dbType <- attr(tblSource, "source_type")
if(is.null(dbType)){
return(invisible(NULL))
}

if (dbType == "postgresql") {
cli::cli_inform("Adding indexes to table")
con <- attr(attr(cdm[[name]], "tbl_source"), "dbcon")
schema <- attr(attr(cdm[[name]], "tbl_source"), "write_schema")[["schema"]]
prefix <- attr(attr(cdm[[name]], "tbl_source"), "write_schema")[["prefix"]]
con <- attr(cdm, "dbcon")
schema <- attr(cdm, "write_schema")
if(length(schema) > 1){
prefix <- attr(cdm, "write_schema")["prefix"]
schema <- attr(cdm, "write_schema")["schema"]
} else {
prefix <- NULL
}

cols <- paste0(cols, collapse = ",")

query <- paste0(
Expand All @@ -399,6 +413,9 @@ addIndex <- function(cdm, name, cols) {
)
suppressMessages(DBI::dbExecute(con, query))
}

return(invisible(NULL))

}

getDomainCohort <- function(cdm,
Expand Down

0 comments on commit db1fc1d

Please sign in to comment.