|
| 1 | +# Concept Set Attribute class ---------------------------- |
| 2 | + |
| 3 | +#' An S4 class for a concept set attribute that holds a reference to a concept set ID |
| 4 | +#' @slot |
| 5 | +#' name the name of the attribute |
| 6 | +#' @slot |
| 7 | +#' conceptSet a ConceptSet object that provides the ID reference |
| 8 | +#' @include conceptSet.R |
| 9 | +setClass("conceptSetAttribute", |
| 10 | + slots = c(name = "character", |
| 11 | + conceptSet = "ConceptSet"), |
| 12 | + prototype = list(name = NA_character_, conceptSet = new("ConceptSet"))) |
| 13 | + |
| 14 | +setValidity("conceptSetAttribute", function(object) { |
| 15 | + stopifnot(is.character(object@name), length(object@name) == 1) |
| 16 | + TRUE |
| 17 | +}) |
| 18 | + |
| 19 | +# Console Print --------------- |
| 20 | + |
| 21 | +setMethod("show", "conceptSetAttribute", function(object) { |
| 22 | + cli::cat_bullet(paste("Capr Concept Set Attribute:", object@name, "- ID:", object@conceptSet@id), bullet = "sup_plus") |
| 23 | +}) |
| 24 | + |
1 | 25 | # Concept Attribute class ---------------------------- |
2 | 26 |
|
3 | 27 | #' An S4 class for a concept attribute |
@@ -107,6 +131,23 @@ buildConceptAttribute <- function(ids, attributeName, connection, vocabularyData |
107 | 131 | return(attr_concept) |
108 | 132 | } |
109 | 133 |
|
| 134 | + |
| 135 | +#' Add a value as concept attribute |
| 136 | +#' @param ids the concept ids for the attribute |
| 137 | +#' @param connection a connection to an OMOP dbms to get vocab info about the concept |
| 138 | +#' @param vocabularyDatabaseSchema the database schema for the vocabularies |
| 139 | +#' @return |
| 140 | +#' An attribute that can be used in a query function |
| 141 | +#' @export |
| 142 | +#' |
| 143 | +valueAsConcept <- function(ids, connection, vocabularyDatabaseSchema) { |
| 144 | + res <- buildConceptAttribute(ids = ids, attributeName = "ValueAsConcept", |
| 145 | + connection = connection, |
| 146 | + vocabularyDatabaseSchema = vocabularyDatabaseSchema) |
| 147 | + return(res) |
| 148 | +} |
| 149 | + |
| 150 | + |
110 | 151 | #' Add a drug type attribute to determine the provenance of the record |
111 | 152 | #' @param ids the concept ids for the attribute |
112 | 153 | #' @param connection a connection to an OMOP dbms to get vocab info about the concept |
@@ -217,6 +258,94 @@ conditionStatus <- function(ids, connection, vocabularyDatabaseSchema) { |
217 | 258 | return(res) |
218 | 259 | } |
219 | 260 |
|
| 261 | +#' Add a condition source concept attribute |
| 262 | +#' @param conceptSet a ConceptSet object containing the source concepts |
| 263 | +#' @return |
| 264 | +#' An attribute that can be used in a query function |
| 265 | +#' @export |
| 266 | +#' |
| 267 | +conditionSourceConcept <- function(conceptSet) { |
| 268 | + if (!methods::is(conceptSet, "ConceptSet")) { |
| 269 | + rlang::abort("conditionSourceConcept requires a ConceptSet object") |
| 270 | + } |
| 271 | + |
| 272 | + res <- methods::new("conceptSetAttribute", |
| 273 | + name = "ConditionSourceConcept", |
| 274 | + conceptSet = conceptSet) |
| 275 | + return(res) |
| 276 | +} |
| 277 | + |
| 278 | +#' Add a drug source concept attribute |
| 279 | +#' @param conceptSet a ConceptSet object containing the source concepts |
| 280 | +#' @return |
| 281 | +#' An attribute that can be used in a query function |
| 282 | +#' @export |
| 283 | +#' |
| 284 | +drugSourceConcept <- function(conceptSet) { |
| 285 | + if (!methods::is(conceptSet, "ConceptSet")) { |
| 286 | + rlang::abort("drugSourceConcept requires a ConceptSet object") |
| 287 | + } |
| 288 | + |
| 289 | + res <- methods::new("conceptSetAttribute", |
| 290 | + name = "DrugSourceConcept", |
| 291 | + conceptSet = conceptSet) |
| 292 | + return(res) |
| 293 | +} |
| 294 | + |
| 295 | + |
| 296 | +#' Add a procedure source concept attribute |
| 297 | +#' @param conceptSet a ConceptSet object containing the source concepts |
| 298 | +#' @return |
| 299 | +#' An attribute that can be used in a query function |
| 300 | +#' @export |
| 301 | +#' |
| 302 | +procedureSourceConcept <- function(conceptSet) { |
| 303 | + if (!methods::is(conceptSet, "ConceptSet")) { |
| 304 | + rlang::abort("procedureSourceConcept requires a ConceptSet object") |
| 305 | + } |
| 306 | + |
| 307 | + res <- methods::new("conceptSetAttribute", |
| 308 | + name = "ProcedureSourceConcept", |
| 309 | + conceptSet = conceptSet) |
| 310 | + return(res) |
| 311 | +} |
| 312 | + |
| 313 | + |
| 314 | + |
| 315 | +#' Add a observation source concept attribute |
| 316 | +#' @param conceptSet a ConceptSet object containing the source concepts |
| 317 | +#' @return |
| 318 | +#' An attribute that can be used in a query function |
| 319 | +#' @export |
| 320 | +#' |
| 321 | +observationSourceConcept <- function(conceptSet) { |
| 322 | + if (!methods::is(conceptSet, "ConceptSet")) { |
| 323 | + rlang::abort("observationSourceConcept requires a ConceptSet object") |
| 324 | + } |
| 325 | + |
| 326 | + res <- methods::new("conceptSetAttribute", |
| 327 | + name = "ObservationSourceConcept", |
| 328 | + conceptSet = conceptSet) |
| 329 | + return(res) |
| 330 | +} |
| 331 | + |
| 332 | +#' Add a visit source concept attribute |
| 333 | +#' @param conceptSet a ConceptSet object containing the source concepts |
| 334 | +#' @return |
| 335 | +#' An attribute that can be used in a query function |
| 336 | +#' @export |
| 337 | +#' |
| 338 | +visitSourceConcept <- function(conceptSet) { |
| 339 | + if (!methods::is(conceptSet, "ConceptSet")) { |
| 340 | + rlang::abort("visitSourceConcept requires a ConceptSet object") |
| 341 | + } |
| 342 | + |
| 343 | + res <- methods::new("conceptSetAttribute", |
| 344 | + name = "VisitSourceConcept", |
| 345 | + conceptSet = conceptSet) |
| 346 | + return(res) |
| 347 | +} |
| 348 | + |
220 | 349 | #' Add a observation period type attribute to determine the provenance of the record |
221 | 350 | #' @param ids the concept ids for the attribute |
222 | 351 | #' @param connection a connection to an OMOP dbms to get vocab info about the concept |
@@ -281,6 +410,11 @@ measurementUnit <- function(x) { |
281 | 410 |
|
282 | 411 | # Coercion ------------------ |
283 | 412 |
|
| 413 | +setMethod("as.list", "conceptSetAttribute", function(x) { |
| 414 | + nm <- x@name |
| 415 | + tibble::lst(`:=`(!!nm, x@conceptSet@id)) |
| 416 | +}) |
| 417 | + |
284 | 418 | setMethod("as.list", "conceptAttribute", function(x) { |
285 | 419 |
|
286 | 420 | concepts <- purrr::map(x@conceptSet, ~as.list(.x)) |
|
0 commit comments