Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

codelist diagnostics #111

Merged
merged 10 commits into from
Jan 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 9 additions & 10 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: CodelistGenerator
Title: Generate Code Lists for the OMOP Common Data Model
Version: 2.1.2
Title: Identify Relevant Clinical Codes and Evaluate Their Use
Version: 2.2.0
Authors@R: c(
person("Edward", "Burn", email = "[email protected]",
role = c("aut", "cre"),
Expand All @@ -13,10 +13,13 @@ License: Apache License (>= 2)
Encoding: UTF-8
Roxygen: list(markdown = TRUE)
RoxygenNote: 7.2.3
Depends:
R (>= 3.5.0)
Imports:
CDMConnector (>= 1.1.2),
checkmate (>= 2.0.0),
DBI (>= 1.1.0),
duckdb,
dplyr (>= 1.1.0),
magrittr (>= 2.0.0),
rlang (>= 1.0.0),
Expand All @@ -28,24 +31,20 @@ Imports:
purrr,
lubridate,
PatientProfiles (>= 0.3.0),
RJSONIO
RJSONIO,
vctrs
Suggests:
covr,
dbplyr (>= 2.2.1),
knitr,
readr (>= 2.1.0),
duckdb,
DT,
rmarkdown,
here (>= 1.0.0),
testthat (>= 3.0.0),
kableExtra (>= 1.0.0),
RPostgres,
odbc,
spelling,
tibble
Config/testthat/edition: 3
Config/testthat/parallel: true
VignetteBuilder: knitr
URL: https://darwin-eu.github.io/CodelistGenerator/
Language: en-US
Config/testthat/parallel: true
LazyData: true
4 changes: 4 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ export("%>%")
export(achillesCodeUse)
export(codesFromCohort)
export(codesFromConceptSet)
export(codesInUse)
export(compareCodelists)
export(findOrphanCodes)
export(getATCCodes)
export(getCandidateCodes)
export(getConceptClassId)
Expand All @@ -17,6 +19,8 @@ export(getMappings)
export(getVocabVersion)
export(getVocabularies)
export(mockVocabRef)
export(restrictToCodesInUse)
export(sourceCodesInUse)
export(summariseCodeUse)
export(summariseCohortCodeUse)
importFrom(magrittr,"%>%")
Expand Down
8 changes: 8 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
# CodelistGenerator 2.2.0
* Added functions findOrphanCodes, restrictToCodesInUse, sourceCodesInUse.
* Speed improvements in getCandidateCodes from doing search in place (e.g. on database side).
* Dropped explicit support of an Arrow cdm.

# CodelistGenerator 2.1.1
* Improved support of device domain.

# CodelistGenerator 2.0.0
* Simplified the interface of getCandidateCodes, with a number of arguments removed.
* Added function summariseCohortCodeUse.
Expand Down
23 changes: 17 additions & 6 deletions R/achillesCodeUse.R
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@
#' @export
#'
#' @examples
achillesCodeUse <- function(x,

Check warning on line 15 in R/achillesCodeUse.R

View workflow job for this annotation

GitHub Actions / lint

file=R/achillesCodeUse.R,line=15,col=1,[object_name_linter] Variable and function name style should match snake_case or symbols.
cdm,
countBy = c("record", "person"),

Check warning on line 17 in R/achillesCodeUse.R

View workflow job for this annotation

GitHub Actions / lint

file=R/achillesCodeUse.R,line=17,col=29,[object_name_linter] Variable and function name style should match snake_case or symbols.
minCellCount = 5) {

Check warning on line 18 in R/achillesCodeUse.R

View workflow job for this annotation

GitHub Actions / lint

file=R/achillesCodeUse.R,line=18,col=29,[object_name_linter] Variable and function name style should match snake_case or symbols.

errorMessage <- checkmate::makeAssertCollection()

Check warning on line 20 in R/achillesCodeUse.R

View workflow job for this annotation

GitHub Actions / lint

file=R/achillesCodeUse.R,line=20,col=3,[object_name_linter] Variable and function name style should match snake_case or symbols.
checkDbType(cdm = cdm, type = "cdm_reference", messageStore = errorMessage)
checkmate::assertTRUE(all(countBy %in% c("record", "person")),
add = errorMessage)
Expand All @@ -26,11 +26,11 @@
checkmate::reportAssertions(collection = errorMessage)

checkmate::assertList(x)
if(length(names(x)) != length(x)){

Check warning on line 29 in R/achillesCodeUse.R

View workflow job for this annotation

GitHub Actions / lint

file=R/achillesCodeUse.R,line=29,col=5,[spaces_left_parentheses_linter] Place a space before left parenthesis, except in a function call.

Check warning on line 29 in R/achillesCodeUse.R

View workflow job for this annotation

GitHub Actions / lint

file=R/achillesCodeUse.R,line=29,col=36,[brace_linter] There should be a space before an opening curly brace.

Check warning on line 29 in R/achillesCodeUse.R

View workflow job for this annotation

GitHub Actions / lint

file=R/achillesCodeUse.R,line=29,col=36,[paren_body_linter] There should be a space between a right parenthesis and a body expression.
cli::cli_abort("Must be a named list")
}

if(is.null(cdm[["achilles_results"]])){

Check warning on line 33 in R/achillesCodeUse.R

View workflow job for this annotation

GitHub Actions / lint

file=R/achillesCodeUse.R,line=33,col=5,[spaces_left_parentheses_linter] Place a space before left parenthesis, except in a function call.

Check warning on line 33 in R/achillesCodeUse.R

View workflow job for this annotation

GitHub Actions / lint

file=R/achillesCodeUse.R,line=33,col=41,[brace_linter] There should be a space before an opening curly brace.

Check warning on line 33 in R/achillesCodeUse.R

View workflow job for this annotation

GitHub Actions / lint

file=R/achillesCodeUse.R,line=33,col=41,[paren_body_linter] There should be a space between a right parenthesis and a body expression.
cli::cli_abort("No achilles tables found in cdm reference")
}

Expand All @@ -47,6 +47,7 @@

if("record" %in% countBy){
allRecordCount <- getAchillesRecordCounts(cdm = cdm, conceptId = allCodes)
if(nrow(allRecordCount)>=1){
allRecordCount <- allRecordCount %>%
dplyr::mutate(concept_id = as.character(.data$concept_id)) %>%
dplyr::left_join(codesWithDetails %>%
Expand All @@ -65,12 +66,13 @@
standard_concept_id = .data$concept_id
) %>%
dplyr::mutate(codelist_name = names(x)[i])

}
}
}

if("person" %in% countBy){
allPersonCount <- getAchillesPersonCounts(cdm = cdm, conceptId = allCodes)
if(nrow(allPersonCount)>=1){
allPersonCount <- allPersonCount %>%
dplyr::mutate(concept_id = as.character(.data$concept_id)) %>%
dplyr::left_join(codesWithDetails %>%
Expand All @@ -91,7 +93,15 @@
dplyr::mutate(codelist_name = names(x)[i])
}
}
}

if(length(codeUse) == 0){
cli::cli_inform(
c(
"i" = "No achilles counts found for the concepts provided."
))
return(dplyr::tibble())
} else {
codeUse <- dplyr::bind_rows(codeUse) %>%
dplyr::mutate(group_name = "By concept",
strata_name = "Overall",
Expand All @@ -113,12 +123,13 @@
"source_concept_id",
"domain_id", "codelist_name","cohort_name")

codeUse <- codeUse %>%
dplyr::mutate(estimate = dplyr::if_else(.data$estimate < .env$minCellCount &
.data$estimate > 0,
NA, .data$estimate)) %>%
dplyr::mutate(standard_concept_id = as.integer(.data$standard_concept_id),
source_concept_id = as.integer(.data$source_concept_id))

if(nrow(codeUse) == 0){
cli::cli_inform(
c(
"i" = "No achilles counts found for the concepts provided."
))
}

return(codeUse)
Expand Down
16 changes: 12 additions & 4 deletions R/codesFromConceptSet.R
Original file line number Diff line number Diff line change
Expand Up @@ -253,18 +253,25 @@ tibbleToList <- function(codelistTibble) {

addDetails <- function(conceptList, cdm){

# will accept either a list or tibble
# will return the same type as the input
inputIsTbl <- inherits(conceptList, "tbl_df")

if(isFALSE(inputIsTbl)){
for(i in seq_along(conceptList)){
conceptList[[i]] <- dplyr::tibble(concept_id = conceptList[[i]],
concept_set = names(conceptList)[i])
}
conceptList <- dplyr::bind_rows(conceptList)
}

conceptList <- dplyr::bind_rows(conceptList) %>%
dplyr::left_join(cdm[["concept"]] %>%
conceptList <- conceptList %>%
dplyr::left_join(cdm[["concept"]] %>%
dplyr::select("concept_id", "concept_name",
"domain_id", "vocabulary_id",
"standard_concept"),
by = "concept_id",
copy = TRUE)%>%
copy = TRUE) %>%
dplyr::mutate(
standard_concept = ifelse(is.na(.data$standard_concept),
"non-standard", .data$standard_concept
Expand All @@ -281,10 +288,11 @@ addDetails <- function(conceptList, cdm){
)
)

if(isFALSE(inputIsTbl)){
conceptList <- split(
x = conceptList %>% dplyr::select(!"concept_set"),
f = as.factor(conceptList$concept_set)
)
)}

return(conceptList)

Expand Down
Loading