diff --git a/NAMESPACE b/NAMESPACE index baaa5b9c..2a77161b 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -24,6 +24,7 @@ export(drugExit) export(drugExposure) export(drugQuantity) export(drugRefills) +export(drugType) export(duringInterval) export(endDate) export(entry) diff --git a/R/attributes-concept.R b/R/attributes-concept.R index 500a7859..a61f2d3d 100644 --- a/R/attributes-concept.R +++ b/R/attributes-concept.R @@ -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 diff --git a/man/drugType.Rd b/man/drugType.Rd new file mode 100644 index 00000000..32ad5870 --- /dev/null +++ b/man/drugType.Rd @@ -0,0 +1,21 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/attributes-concept.R +\name{drugType} +\alias{drugType} +\title{Add a drug type attribute} +\usage{ +drugType(ids, connection, vocabularyDatabaseSchema) +} +\arguments{ +\item{ids}{the concept ids for the attribute} + +\item{connection}{a connection to an OMOP dbms to get vocab info about the concept} + +\item{vocabularyDatabaseSchema}{the database schema for the vocabularies} +} +\value{ +An attribute that can be used in a query function +} +\description{ +Add a drug type attribute +}