Skip to content

Commit

Permalink
applying the same changes to getICD10Codes
Browse files Browse the repository at this point in the history
  • Loading branch information
xihang-chen committed Jun 14, 2024
1 parent a80bd38 commit 763a16c
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 5 deletions.
14 changes: 11 additions & 3 deletions R/getICD10StandardCodes.R
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,12 @@ getICD10StandardCodes <- function(cdm,
by = "concept_id")
# split into list
ICD10StandardCodes <- ICD10MapsTo %>%
dplyr::collect()
dplyr::collect() %>%
dplyr::left_join(cdm[["concept"]] %>% dplyr::select(.data$concept_id, .data$concept_code),
by = "concept_id",
copy = T) %>%
dplyr::mutate(name = paste0(.data$concept_code,"_", .data$name))

ICD10StandardCodes <- split(
x = ICD10StandardCodes,
f = as.factor(ICD10StandardCodes$name),
Expand All @@ -150,14 +155,17 @@ getICD10StandardCodes <- function(cdm,
} else {
# split into list (only returning vector of concept ids)
ICD10StandardCodes <- ICD10MapsTo %>%
dplyr::collect()
dplyr::collect() %>%
dplyr::left_join(cdm[["concept"]] %>% dplyr::select(.data$concept_id, .data$concept_code),
by = "concept_id",
copy = T) %>%
dplyr::mutate(name = paste0(.data$concept_code,"_", .data$name))
ICD10StandardCodes <- split(
x = ICD10StandardCodes$concept_id,
f = ICD10StandardCodes$name
)
}


if(isFALSE(withConceptDetails)){
ICD10StandardCodes <- omopgenerics::newCodelist(ICD10StandardCodes)
}
Expand Down
12 changes: 10 additions & 2 deletions tests/testthat/test-getICD10StandardCodes.R
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ test_that("db without icd10 codes loaded", {
"ICD10 SubChapter"
))
expect_true(length(codes) == 2)
expect_true("arthropathies" %in% names(codes))
expect_true("diseases_of_the_musculoskeletal_system_and_connective_tissue" %in%
expect_true("1234_arthropathies" %in% names(codes))
expect_true("1234_diseases_of_the_musculoskeletal_system_and_connective_tissue" %in%
names(codes))
# we should pick up mapping and descendants
expect_true(all(c(3,4,5) %in% codes[[1]]))
Expand Down Expand Up @@ -79,3 +79,11 @@ test_that("expected errors", {
)))

})

test_that("change of name", {
skip_on_cran()
cdm <- mockVocabRef()
code_icd10 <- getICD10StandardCodes(cdm = cdm)

expect_true(all(startsWith(names(code_icd10), "1234_")))
})

0 comments on commit 763a16c

Please sign in to comment.