Skip to contents

`addCodelistAttribute()` allows the users to add a codelist to a cohort in OMOP CDM.

This is particularly important for the use of `codelistDiagnostics()`, as the underlying assumption is that the cohort that is fed into `codelistDiagnostics()` has a cohort_codelist attribute attached to it.

Usage

addCodelistAttribute(cohort, codelist, cohortName = names(codelist))

Arguments

cohort

Cohort table in a cdm reference

codelist

Named list of concepts

cohortName

For each element of the codelist, the name of the cohort in `cohort` to which the codelist refers

Value

A cohort

Examples

# \donttest{
library(omock)
library(CohortConstructor)
library(PhenotypeR)

cdm <- mockCdmFromDataset(source = "duckdb")
#>  Loading bundled GiBleed tables from package data.
#>  Adding drug_strength table.
#>  Creating local <cdm_reference> object.
#>  Inserting <cdm_reference> into duckdb.
cdm$warfarin <- conceptCohort(cdm,
                              conceptSet =  list(warfarin = c(1310149L,
                                                              40163554L)),
                              name = "warfarin")
#>  Subsetting table drug_exposure using 2 concepts with domain: drug.
#>  Combining tables.
#>  Creating cohort attributes.
#>  Applying cohort requirements.
#>  Merging overlapping records.
#>  Cohort warfarin created.

cohort <- addCodelistAttribute(cohort = cdm$warfarin,
               codelist = list("warfarin" = c(1310149L,  40163554L)))
#> Warning: Overwriting codelist for cohort warfarin
attr(cohort, "cohort_codelist")
#> # Source:   table<results.test_warfarin_codelist> [?? x 4]
#> # Database: DuckDB 1.4.4 [unknown@Linux 6.14.0-1017-azure:R 4.5.2//tmp/RtmpCa2OUY/file1db479fff499.duckdb]
#>   cohort_definition_id codelist_name concept_id codelist_type
#>                  <int> <chr>              <int> <chr>        
#> 1                    1 warfarin         1310149 index event  
#> 2                    1 warfarin        40163554 index event  

CDMConnector::cdmDisconnect(cdm)
# }