In this vignette we will introduce the three different types of codelist that CodelistGenerator uses: codelist, codelist with details, and concept set. First of all, we will upload the packages required for the demonstration.
library(omopgenerics, warn.conflicts = FALSE)
library(dplyr, warn.conflicts = FALSE)
library(CodelistGenerator)Codelist format is the simplest of the three formats. To create one, we just need a named list where each element contains a vector of concept IDs. You can see an example below on how to create one:
codelist <- list("codes1" = c(1L, 2L, 3L),
"codes2" = c(4L, 5L, 10L))
codelist <- newCodelist(codelist)
codelist Notice that the codelist has two specific attributes, the name of the codelists that contains and the class:
Codelist with details contains a tibble in each element. To create one, we need a named list where each element contains a tibble with at least the column concept_id.
codelist_with_details <- list("codes1" = tibble("concept_id" = c(1L, 2L, 3L)),
"codes2" = tibble("concept_id" = c(4L, 5L, 10L)))
codelist_with_details <- newCodelistWithDetails(codelist_with_details)
codelist_with_detailsNotice that this allows us to add more information of each one of the codes:
codelist_with_details <- list(
"codes1" = tibble("concept_id" = c(1L, 2L, 3L),
"concept_name" = c("Musculoskeletal disorder", "Osteoarthrosis", "Arthritis"),
"domain_id" = c("Condition", "Condition", "Condition"),
"vocabulary_id" = c("SNOMED","SNOMED","SNOMED"),
"standard_concept" = c("S","S","S")),
"codes2" = tibble("concept_id" = c(4L, 5L, 10L),
"concept_name" = c("Osteoarthritis of knee", "Osteoarthritis of hip", "Adalimumab"),
"domain_id" = c("Condition", "Condition", "Drug"),
"vocabulary_id" = c("SNOMED","SNOMED","RxNorm"),
"standard_concept" = c("S","S","S")))
codelist_with_details <- newCodelistWithDetails(codelist_with_details)
codelist_with_detailsThe codelist with details also has two specific attributes:
A concept set expression contains a tibble with the logic describing how this concepts will be included or excluded. It usually follows the JSON file structure. To create one, we need a named list with a tibble containing the columns: concept_id, excluded, descendants, and mapped:
concept_set_expression <- list(
"codes1" = tibble("concept_id" = c(1L, 2L, 3L),
"excluded" = c(FALSE, FALSE, FALSE),
"descendants" = c(TRUE, FALSE, FALSE),
"mapped" = c(TRUE, TRUE, TRUE)),
"codes2" = tibble("concept_id" = c(4L, 5L, 10L),
"excluded" = c(FALSE, FALSE, FALSE),
"descendants" = c(FALSE, FALSE, FALSE),
"mapped" = c(TRUE, TRUE, TRUE))
)
concept_set_expression <- newConceptSetExpression(concept_set_expression)
concept_set_expressionYou can also see the attributes:
We can also use omopGenerics package to create an empty concept set expression:
CodelistGenerator contains a function that allows us to read a JSON file and transform it to a concept set expression (or other types of codelists). See the vignette Extract codelists from JSON files for further information.
There are several functions in CodelistGenerator that will allow us to go from a codelist to a codelist with details.
Notice that to go from a codelist or concept_set_expression to a codelist_with_details, we will need to provide the cdm, as the details of the concepts will be extracted from the concept table.