Skip to content

Commit

Permalink
add drugType attribute
Browse files Browse the repository at this point in the history
  • Loading branch information
mdlavallee92 committed Feb 21, 2024
1 parent a7b3f02 commit c4d52ee
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 0 deletions.
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export(drugExit)
export(drugExposure)
export(drugQuantity)
export(drugRefills)
export(drugType)
export(duringInterval)
export(endDate)
export(entry)
Expand Down
44 changes: 44 additions & 0 deletions R/attributes-concept.R
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,50 @@ female <- function() {
}


findConceptInVocabulary <- function(id, connection, vocabularyDatabaseSchema) {

detailedConceptSet <- cs(id, name = glue::glue("{id}")) |>
getConceptSetDetails(con = connection,
vocabularyDatabaseSchema = vocabularyDatabaseSchema)
return(detailedConceptSet)
}

pullConceptClass <- function(detailedConceptSet) {
conceptClass <- detailedConceptSet@Expression[[1]]@Concept
return(conceptClass)
}

buildConceptAttribute <- function(ids, attributeName, connection, vocabularyDatabaseSchema) {

# get concepts from vocabulary table
conceptsForAttributes <- purrr::map(
ids,
~findConceptInVocabulary(id = .x, connection = connection, vocabularyDatabaseSchema = vocabularyDatabaseSchema) |>
pullConceptClass()
)

attr_concept <- methods::new("conceptAttribute",
name = attributeName,
conceptSet = list(conceptsForAttributes))
return(attr_concept)
}

#' Add a drug type attribute
#' @param ids the concept ids for the attribute
#' @param connection a connection to an OMOP dbms to get vocab info about the concept
#' @param vocabularyDatabaseSchema the database schema for the vocabularies
#' @return
#' An attribute that can be used in a query function
#' @export
#'
drugType <- function(ids, connection, vocabularyDatabaseSchema) {
res <- buildConceptAttribute(ids = ids, attributeName = "DrugType",
connection = connection,
vocabularyDatabaseSchema = vocabularyDatabaseSchema)
return(res)
}


#' Add unit attribute to a query
#' @param x A single character idetifier for a unit or a concept set that identifies units
#' @return
Expand Down
21 changes: 21 additions & 0 deletions man/drugType.Rd

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

0 comments on commit c4d52ee

Please sign in to comment.