Skip to content

Commit

Permalink
fixes #177 and #142, many thanks to @overmar
Browse files Browse the repository at this point in the history
  • Loading branch information
Jack Wasey committed May 1, 2020
2 parents d868b3f + 8e8e22c commit 9e51986
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 13 deletions.
15 changes: 9 additions & 6 deletions R/parse-comorbid.R
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,14 @@ icd9_fetch_ahrq_sas <- function() {
)
}

icd10_fetch_ahrq_sas <- function(ver = "2016") {
icd10_fetch_ahrq_sas <- function(ver = "2018") {
if (!ver %in% c("2016","2017","2018")) {
stop(ver," not currently available")
}
.download_to_data_raw(
url = paste0(.ahrq_url_base, "comorbidityicd10/comformat_icd10cm_2016.txt"),
file_name = .get_versioned_raw_file_name("ahrq-comformat_icd10cm_2016.txt",
ver = "2016"
url = paste0(.ahrq_url_base, "comorbidityicd10/comformat_icd10cm_",ver,".txt"),
file_name = .get_versioned_raw_file_name(paste0("ahrq-comformat_icd10cm_",ver,".txt"),
ver = ver
)
)
}
Expand Down Expand Up @@ -138,10 +141,10 @@ icd9_parse_ahrq_sas <- function(save_pkg_data = FALSE) {

# This is in some ways simpler than that ICD-9 equivalent because I make no
# attempt to find all the child codes.
icd10_parse_ahrq_sas <- function(save_pkg_data = FALSE,
icd10_parse_ahrq_sas <- function(version = "2018", save_pkg_data = FALSE,
offline = TRUE) {
assert_flag(save_pkg_data)
ahrq_info <- icd10_fetch_ahrq_sas()
ahrq_info <- icd10_fetch_ahrq_sas(ver = version)
ahrq_sas_lines <- readLines(ahrq_info$file_path, warn = FALSE)
icd10_map_ahrq <- sas_format_extract_rcomfmt(ahrq_sas_lines)
unun <- function(x) unname(unlist(x))
Expand Down
2 changes: 1 addition & 1 deletion R/update.R
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
icd9_generate_map_elix(save_pkg_data = TRUE)
# ICD 10
.parse_icd10cm_all(save_pkg_data = TRUE)
icd10_parse_ahrq_sas(save_pkg_data = TRUE)
icd10_parse_ahrq_sas(version = "2018", save_pkg_data = TRUE)
.parse_icd10cm_cc(save_pkg_data = TRUE)
icd10_generate_map_quan_elix(save_pkg_data = TRUE)
icd10_generate_map_quan_deyo(save_pkg_data = TRUE)
Expand Down
Binary file modified data/icd10_map_ahrq.rda
Binary file not shown.
17 changes: 11 additions & 6 deletions tests/testthat/test-build-maps-icd10.R
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,17 @@ test_that("icd-10 ahrq map is reproduced", {
skip_on_appveyor()
skip_on_travis()
skip_on_cran()
skip_no_icd_data_raw(
icd10_fetch_ahrq_sas,
"AHRQ ICD-10 SAS must be downloaded with icd10_fetch_ahrq_sas"
)
expect_equivalent(
if (is.null(icd10_fetch_ahrq_sas())) {
skip("AHRQ ICD-10 SAS must be downloaded with icd10_fetch_ahrq_sas")
}
expect_identical(
icd10_map_ahrq,
icd10_parse_ahrq_sas(save_pkg_data = FALSE)
icd10_parse_ahrq_sas(save_pkg_data = FALSE,version = "2018")
)

expect_false(identical(
icd10_map_ahrq,
icd10_parse_ahrq_sas(save_pkg_data = FALSE,version = "2016")
))

})

0 comments on commit 9e51986

Please sign in to comment.