# Code lists for medications

## Creating a codelists for acetaminophen

For this vignette we are going to create codelists for identifying a acetaminophen, looking in the drug domain.

## Connecting to a database with the OMOP CDM vocabularies

    # postgres database connection details
    serverDbi <- Sys.getenv("server")
    user <- Sys.getenv("user")
    password <- Sys.getenv("password")
    port <- Sys.getenv("port")
    host <- Sys.getenv("host")

    db <- DBI::dbConnect(RPostgres::Postgres(),
      dbname = serverDbi,
      port = port,
      host = host,
      user = user,
      password = password
    )

    # name of vocabulary schema
    vocabularyDatabaseSchema <- "vocabulary"

## Codelist from “acetaminophen” and its descendants

First we can follow the approach of identifying high-level codes and include all their descendants.

    library(dplyr)
    library(CodelistGenerator)

    acetaminophen1 <- getCandidateCodes(
      cdm = cdm,
      keywords = "acetaminophen",
      domains = "drug",
      standardConcept = "standard",
      includeDescendants = TRUE
    )

    acetaminophen1 %>% dplyr::glimpse()
    #> Rows: 25,844
    #> Columns: 15
    #> $ concept_id                  <int> 587290, 587473, 587705, 587929, 588401, 58…
    #> $ found_from                  <chr> "From initial search", "From initial searc…
    #> $ ingredient_concept_id       <int> 1134439, 1134439, 1036059, 1135766, 113576…
    #> $ amount_value                <dbl> NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA…
    #> $ amount_unit_concept_id      <int> NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA…
    #> $ numerator_value             <dbl> 1.25e-02, 1.25e-02, 7.49e-02, 7.42e-03, 6.…
    #> $ numerator_unit_concept_id   <int> 8576, 8576, 8576, 8576, 8576, 8576, 8576, …
    #> $ denominator_value           <dbl> NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA…
    #> $ denominator_unit_concept_id <int> 8576, 8576, 8576, 8576, 8576, 8576, 8576, …
    #> $ box_size                    <int> NA, NA, 100, 10, NA, 100, 5, NA, 5, 10, NA…
    #> $ dose_form                   <chr> "Oral Solution", "Oral Solution", "Oral So…
    #> $ concept_name                <chr> "Acetaminophen 0.0501 MG/MG / Antipyrine 0…
    #> $ domain_id                   <chr> "Drug", "Drug", "Drug", "Drug", "Drug", "D…
    #> $ vocabulary_id               <chr> "RxNorm Extension", "RxNorm Extension", "R…
    #> $ standard_concept            <chr> "standard", "standard", "standard", "stand…