darwin-eu / CodelistGenerator

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

error for search using drug domain #224

Closed catalamarti closed 2 days ago

catalamarti commented 6 days ago
cdm <- omock::mockCdmReference(vocabularySet = "eunomia") |>
    omock::mockPerson(nPerson = 100) |>
    omock::mockObservationPeriod() |>
    omock::mockConditionOccurrence(recordPerson = 3) |>
    omock::mockDrugExposure(recordPerson = 4.5)
  codes <- CodelistGenerator::getCandidateCodes(
    cdm = cdm,
    domains = "drug",
    keywords = "glucagon",
    includeDescendants = FALSE
  )
#> Limiting to domains of interest
#> Error in `dplyr::left_join()`:
#> ! Can't join `x$drug_concept_id` with `y$drug_concept_id` due to
#>   incompatible types.
#> ℹ `x$drug_concept_id` is a <character>.
#> ℹ `y$drug_concept_id` is a <double>.
#> Backtrace:
#>      ▆
#>   1. ├─CodelistGenerator::getCandidateCodes(...)
#>   2. │ └─CodelistGenerator:::runSearch(...)
#>   3. │   └─... %>% dplyr::rename_with(tolower)
#>   4. ├─dplyr::rename_with(., tolower)
#>   5. ├─dplyr::filter(...)
#>   6. ├─dplyr::left_join(...)
#>   7. ├─omopgenerics:::left_join.cdm_table(...)
#>   8. │ ├─dplyr::left_join(x, ...)
#>   9. │ └─dplyr:::left_join.data.frame(x, ...)
#>  10. │   └─dplyr:::join_mutate(...)
#>  11. │     └─dplyr:::join_cast_common(x_key, y_key, vars, error_call = error_call)
#>  12. │       ├─rlang::try_fetch(...)
#>  13. │       │ └─base::withCallingHandlers(...)
#>  14. │       └─vctrs::vec_ptype2(x, y, x_arg = "", y_arg = "", call = error_call)
#>  15. ├─vctrs (local) `<fn>`()
#>  16. │ └─vctrs::vec_default_ptype2(...)
#>  17. │   ├─base::withRestarts(...)
#>  18. │   │ └─base (local) withOneRestart(expr, restarts[[1L]])
#>  19. │   │   └─base (local) doWithOneRestart(return(expr), restart)
#>  20. │   └─vctrs::stop_incompatible_type(...)
#>  21. │     └─vctrs:::stop_incompatible(...)
#>  22. │       └─vctrs:::stop_vctrs(...)
#>  23. │         └─rlang::abort(message, class = c(class, "vctrs_error"), ..., call = call)
#>  24. │           └─rlang:::signal_abort(cnd, .file)
#>  25. │             └─base::signalCondition(cnd)
#>  26. └─rlang (local) `<fn>`(`<vctrs__2>`)
#>  27.   └─handlers[[1L]](cnd)
#>  28.     └─dplyr:::rethrow_error_join_incompatible_type(cnd, vars, error_call)
#>  29.       └─dplyr:::stop_join(...)
#>  30.         └─dplyr:::stop_dplyr(...)
#>  31.           └─rlang::abort(...)

Created on 2024-10-10 with reprex v2.0.2

edward-burn commented 2 days ago

I think this is because in the example provided the drug_concept_id in drug_strength is the wrong type.

cdm <- omock::mockCdmReference(vocabularySet = "eunomia") |>
  omock::mockPerson(nPerson = 100) |>
  omock::mockObservationPeriod() |>
  omock::mockConditionOccurrence(recordPerson = 3) |>
  omock::mockDrugExposure(recordPerson = 4.5)

cdm$drug_strength |> 
  dplyr::pull("drug_concept_id")
#> character(0)

cdm$drug_strength <- cdm$drug_strength |> 
  dplyr::mutate(drug_concept_id = as.integer())

codes <- CodelistGenerator::getCandidateCodes(
  cdm = cdm,
  domains = "drug",
  keywords = "glucagon",
  includeDescendants = FALSE
)
#> Limiting to domains of interest
#> Getting concepts to include
#> No codes found for the given search strategy

Created on 2024-10-14 with reprex v2.1.0

edward-burn commented 2 days ago

Providing a better error should I think be resolved once #226 is done