Skip to content

Commit

Permalink
added a function getConceptIdDetails
Browse files Browse the repository at this point in the history
  • Loading branch information
gowthamrao committed Dec 10, 2020
1 parent def1b7e commit 41d10b0
Show file tree
Hide file tree
Showing 6 changed files with 69 additions and 1 deletion.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
.Rproj.user
inst/doc
.DS_Store
errorReportSql.txt
*.log
4 changes: 4 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ export(createVisitOccurrence)
export(createVisitSourceConceptAttribute)
export(createVisitTypeExcludeAttribute)
export(createWindow)
export(getConceptIdDetails)
export(getConceptSetExpression)
export(getConceptSetId)
export(listAttributeOptions)
Expand All @@ -86,6 +87,8 @@ export(readInCirce)
export(saveComponent)
export(toggleConceptMapping)
export(writeCaprCall)
import(DatabaseConnector)
import(dplyr)
import(methods)
importFrom(CirceR,buildCohortQuery)
importFrom(CirceR,cohortExpressionFromJson)
Expand All @@ -107,6 +110,7 @@ importFrom(purrr,map2)
importFrom(purrr,map_int)
importFrom(rlang,"!!!")
importFrom(rlang,"!!")
importFrom(rlang,.data)
importFrom(rlang,call2)
importFrom(rlang,expr)
importFrom(rlang,sym)
Expand Down
50 changes: 49 additions & 1 deletion R/userConceptLookupFn.R
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,55 @@
# See the License for the specific language governing permissions and
# limitations under the License.
#
#



#' get concept id details
#'
#' For one or more concept id, get concept id details by querying the
#' OMOP vocabulary in the database.
#'
#' @template Connection
#' @template VocabularyDatabaseSchema
#' @template OracleTempSchema
#' @param conceptIds a vector of concept ids
#' @return a tibble data frame object with conceptId, conceptName, standardConcept,
#' standardConceptCaption, invalidReason, invalidReasonCaption, conceptCode,
#' domainId, vocabularyId, conceptClassId.
#'
#' @export
getConceptIdDetails <- function(conceptIds,
connectionDetails = NULL,
connection = NULL,
vocabularyDatabaseSchema = NULL,
oracleTempSchema = NULL) {

errorMessage <- checkmate::makeAssertCollection()
checkmate::assertVector(conceptIds, add = errorMessage)
checkmate::reportAssertions(collection = errorMessage)

# Set up connection to server ----------------------------------------------------
if (is.null(connection)) {
if (!is.null(connectionDetails)) {
connection <- DatabaseConnector::connect(connectionDetails)
on.exit(DatabaseConnector::disconnect(connection))
} else {
stop("No connection or connectionDetails provided.")
}
}

conceptQuery <- "SELECT * FROM @vocabularyDatabaseSchema.concept WHERE concept_id IN (@conceptId);"
conceptDetails <- DatabaseConnector::renderTranslateQuerySql(connection = connection,
sql = conceptQuery,
snakeCaseToCamelCase = TRUE,
vocabularyDatabaseSchema = vocabularyDatabaseSchema,
oracleTempSchema = oracleTempSchema,
conceptId = conceptIds) %>%
dplyr::tibble()
return(conceptDetails)
}


##' Lookup Concepts by OMOP Concept Id
#'
#' This function looks up concepts using the OMOP concept id. Function requires a dbms connection to use
Expand Down
9 changes: 9 additions & 0 deletions man-roxygen/Connection.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#' @param connectionDetails An object of type \code{connectionDetails} as created using the
#' \code{\link[DatabaseConnector]{createConnectionDetails}} function in the
#' DatabaseConnector package. Can be left NULL if \code{connection} is
#' provided.
#' @param connection An object of type \code{connection} as created using the
#' \code{\link[DatabaseConnector]{connect}} function in the
#' DatabaseConnector package. Can be left NULL if \code{connectionDetails}
#' is provided, in which case a new connection will be opened at the start
#' of the function, and closed when the function finishes.
2 changes: 2 additions & 0 deletions man-roxygen/OracleTempSchema.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#' @param oracleTempSchema Should be used in Oracle to specify a schema where the user has write
#' privileges for storing temporary tables.
3 changes: 3 additions & 0 deletions man-roxygen/VocabularyDatabaseSchema.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#' @param vocabularyDatabaseSchema Schema name where your OMOP vocabulary format resides.
#' Note that for SQL Server, this should include both the database and
#' schema name, for example 'vocabulary.dbo'.

0 comments on commit 41d10b0

Please sign in to comment.