darwin-eu / CodelistGenerator

Identifying relevant concepts from the OMOP CDM vocabularies
https://darwin-eu.github.io/CodelistGenerator/
Other
12 stars 8 forks source link

getDrugIngredientCodes result in name with curly bracket "{" #163

Closed MimiYuchenGuo closed 4 months ago

MimiYuchenGuo commented 4 months ago

Describe the bug It later will cause a problem when using the name with '{' as the name of list in DUS. I am not sure if this is our database problem or something you can remove. See the reprex and the name that is causing problem printing out:

library(DBI)
library(dplyr)
library(log4r)
library(CDMConnector)
library(here)
library(IncidencePrevalence)
library(RPostgres)
library(DrugUtilisation)
library(CodelistGenerator)
library(readr)
library(omopgenerics)

db <- dbConnect(...)

# The name of the schema that contains the OMOP CDM with patient-level data
cdmSchema <- "..."

# The name of the schema where results tables will be created 
writeSchema <- "..."

writePrefix <- "..."

# minimum counts that can be displayed according to data governance
minCellCount <- 5
# start log ----
resultsFolder <- here("Results")
log_file <- paste0(resultsFolder, "log.txt")
logger <- create.logger()
logfile(logger) <- log_file
level(logger) <- "INFO"

# create cdm object ----
info(logger, "CREATE CDM OBJECT")
cdm <- cdmFromCon(
  con = db,
  cdmSchema = c(schema = cdmSchema),
  writeSchema = c(schema = writeSchema, prefix = writePrefix),
  cdmName = dbName
)

info(logger, "Get cdmsnap, get start date - 10 year from latest date")

cdm_snap <- snapshot(cdm)
cdm_start_date <- as.POSIXlt(cdm_snap$latest_observation_period_end_date)
cdm_start_date$year <- cdm_start_date$year - 10

# generate codelists---------
codelist_glp <- c(
  "exenatide" = 1583722,
  "liraglutide" = 40170911,
  "lixisenatide" = 44506754,
  "dulaglutide" = 45774435,
  "semaglutide" = 793143
)

codelist_lw <- c(
  "orlistat" = 741530,
  "metformin" = 1503297,
  "naltrexone" = 1714319,
  "bupropion" = 750982,
  "phentermine" = 735340,
  "topiramate" = 742267
)

glp_code <- getDrugIngredientCodes(cdm,
                                   name = names(codelist_glp),
                                   ingredientRange = c(1, 1)
)

#---------------- sensitivity analysis------------------

glp_code_count <- summariseCodeUse(
  glp_code,
  cdm
)
#> Getting use of codes from exenatide (1 of 5)
#> Getting use of codes from liraglutide (2 of 5)
#> Getting use of codes from lixisenatide (3 of 5)
#> Getting use of codes from dulaglutide (4 of 5)
#> Getting use of codes from semaglutide (5 of 5)
#> Warning: name: `additional_name` and level: `additional_level` does not match in number
#> of arguments (7 unmatch), first 5 unmatch:
#> • additional_name: source_concept_name &&& source_concept_id &&& domain_id;
#>   additional_level: Exenatide 2mg powder and solvent for prolonged-release
#>   suspension for injection vials &&& 37690087 &&& drug
#> • additional_name: source_concept_name &&& source_concept_id &&& domain_id;
#>   additional_level: Bydureon 2mg powder and solvent for prolonged-release
#>   suspension for injection vials (AstraZeneca UK Ltd) &&& 37690093 &&& drug
#> • additional_name: source_concept_name &&& source_concept_id &&& domain_id;
#>   additional_level: Bydureon 2mg powder and solvent for prolonged-release
#>   suspension for injection pre-filled pen (AstraZeneca UK Ltd) &&& 37778651 &&&
#>   drug
#> • additional_name: source_concept_name &&& source_concept_id &&& domain_id;
#>   additional_level: Exenatide 2mg powder and solvent for prolonged-release
#>   suspension for injection pre-filled disposable devices &&& 37778649 &&& drug
#> • additional_name: source_concept_name &&& source_concept_id &&& domain_id;
#>   additional_level: Lixisenatide 10micrograms/0.2ml solution for injection 3ml
#>   pre-filled disposable devices and Lixisenatide 20micrograms/0.2ml solution
#>   for injection 3ml pre-filled disposable devices &&& 37782462 &&& drug

glp_code_final <- glp_code_count %>%
  mutate(estimate_value = as.numeric(estimate_value)) %>%
  filter(estimate_value >= 30) %>%
  select("variable_level", "variable_name") %>%
  filter(variable_name != "overall") %>%
  distinct()
glp_list_sens <- split(as.integer(glp_code_final$variable_level), glp_code_final$variable_name)

cdm <- generateDenominatorCohortSet(cdm,
                                    name = "denominator_sens",
                                    cohortDateRange = as.Date(c(cdm_start_date, NA)),
                                    requirementInteractions = FALSE
)
#> ℹ Creating denominator cohorts
#> ✔ Cohorts created in 14 min and 14 sec

cdm <- generateDrugUtilisationCohortSet(
  cdm = cdm,
  name = "numerator_sens",
  cohortDateRange = as.Date(c(cdm_start_date, NA)),
  conceptSet = glp_list_sens,
  gapEra = 30 # gap era to be confirmed
)
#> Error in "lapply(text, glue_cmd, .envir = .envir)": ! Could not parse cli `{}` expression: `(0.2 ML Lixisenatid…`.
#> Caused by error in `parse(text = code, keep.source = FALSE)`:
#> ! <text>:1:6: unexpected symbol
#> 1: (0.2 ML
#>          ^

print(names(glp_list_sens)[[1]])
#> [1] "{(0.2 ML Lixisenatide 0.05 MG/ML Injectable Solution) / (0.2 ML Lixisenatide 0.1 MG/ML Injectable Solution) } Pack"
edward-burn commented 4 months ago

this is an issue for DUS, so reposted the underlying cause there https://github.com/darwin-eu-dev/omopgenerics/issues/389