Skip to content

Commit dd643c3

Browse files
committed
v4.0.2
1 parent 7f8e7cd commit dd643c3

4 files changed

Lines changed: 27 additions & 31 deletions

File tree

DESCRIPTION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Package: CodelistGenerator
22
Title: Identify Relevant Clinical Codes and Evaluate Their Use
3-
Version: 4.0.1
3+
Version: 4.0.2
44
Authors@R: c(
55
person("Edward", "Burn", email = "edward.burn@ndorms.ox.ac.uk",
66
role = c("aut", "cre"),

NEWS.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
# CodelistGenerator 4.0.2
2+
* Improve performance of summariseOrphanCodes()
3+
14
# CodelistGenerator 4.0.1
25
* Fix edge case for summariseOrphanCodes() when no records found
36

R/summariseCodeUse.R

Lines changed: 20 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -514,8 +514,7 @@ getRelevantRecords <- function(cdm,
514514
.env$standardConceptIdName[[1]],
515515
.env$sourceConceptIdName[[1]],
516516
.env$sourceConceptValueName[[1]],
517-
.env$typeConceptIdName[[1]]) |>
518-
dplyr::mutate(table = !!omopgenerics::tableName(cdm[[tableName[[1]]]]))
517+
.env$typeConceptIdName[[1]])
519518
if(!is.null(cohortTable)){
520519
# keep only records of those in the cohorts of interest
521520
if(timing == "entry"){
@@ -529,11 +528,10 @@ getRelevantRecords <- function(cdm,
529528
dplyr::inner_join(cohortSubjects,
530529
by = "person_id")
531530
}
531+
codeRecords <- codeRecords |>
532+
dplyr::compute(name = tmpTblName1)
532533
}
533534

534-
codeRecords <- codeRecords |>
535-
dplyr::compute(name = tmpTblName1)
536-
537535
if(is.null(codeRecords)){
538536
return(NULL)
539537
}
@@ -549,26 +547,19 @@ getRelevantRecords <- function(cdm,
549547
temporary = FALSE)
550548
codeRecords <- codeRecords |>
551549
dplyr::mutate(start_date = !!dplyr::sym(startDateName[[1]]),
552-
end_date = !!dplyr::sym(endDateName[[1]])) |>
553-
dplyr::mutate(year = clock::get_year(.data$start_date)) |>
550+
table = !!omopgenerics::tableName(cdm[[tableName[[1]]]])
551+
) |>
554552
dplyr::select(dplyr::all_of(c("person_id",
555553
standardConceptIdName[[1]],
556554
sourceConceptIdName[[1]],
557555
sourceConceptValueName[[1]],
558556
typeConceptIdName[[1]],
559557
"table",
560-
"start_date","end_date", "year"))) |>
558+
"start_date"))) |>
561559
dplyr::rename("standard_concept_id" = .env$standardConceptIdName[[1]],
562560
"source_concept_id" = .env$sourceConceptIdName[[1]],
563561
"source_concept_value" = .env$sourceConceptValueName[[1]],
564-
"type_concept_id" = .env$typeConceptIdName[[1]]) |>
565-
dplyr::compute(
566-
name = paste0(intermediateTable,"_grr"),
567-
temporary = FALSE,
568-
schema = attr(cdm, "write_schema"),
569-
overwrite = TRUE,
570-
logPrefix = "CodelistGenerator.getRelevantRecords_join"
571-
)
562+
"type_concept_id" = .env$typeConceptIdName[[1]])
572563

573564
if(isTRUE(useSourceCodes)){
574565
codeRecords <- codeRecords |>
@@ -626,25 +617,21 @@ getRelevantRecords <- function(cdm,
626617
dplyr::select("concept_id", "domain_id"),
627618
overwrite = TRUE,
628619
temporary = FALSE)
620+
629621
workingRecords <- workingRecords |>
630-
dplyr::mutate(start_date = !!dplyr::sym(startDateName[[i+1]])) |>
631-
dplyr::mutate(year = clock::get_year(.data$start_date),
632-
table = !!omopgenerics::tableName(cdm[[tableName[[1]]]])) |>
622+
dplyr::mutate(start_date = !!dplyr::sym(startDateName[[i+1]]),
623+
table = !!omopgenerics::tableName(cdm[[tableName[[i+1]]]])
624+
) |>
633625
dplyr::select(dplyr::all_of(c("person_id",
634626
standardConceptIdName[[i+1]],
635627
sourceConceptIdName[[i+1]],
628+
sourceConceptValueName[[i+1]],
636629
typeConceptIdName[[i+1]],
637-
"start_date", "year"))) |>
630+
"table", "start_date"))) |>
638631
dplyr::rename("standard_concept_id" = .env$standardConceptIdName[[i+1]],
639632
"source_concept_id" = .env$sourceConceptIdName[[i+1]],
640-
"type_concept_id" = .env$typeConceptIdName[[i+1]]) |>
641-
dplyr::compute(
642-
name = paste0(intermediateTable,"_grr1"),
643-
temporary = FALSE,
644-
schema = attr(cdm, "write_schema"),
645-
overwrite = TRUE,
646-
logPrefix = "CodelistGenerator.getRelevantRecords_join1"
647-
)
633+
"source_concept_value" = .env$sourceConceptValueName[[i+1]],
634+
"type_concept_id" = .env$typeConceptIdName[[i+1]])
648635

649636
if(isTRUE(useSourceCodes)){
650637
workingRecords <- workingRecords |>
@@ -817,6 +804,11 @@ getSummaryCounts <- function(records,
817804
personSummary <- dplyr::tibble()
818805
}
819806

807+
if(byYear == TRUE) {
808+
records <- records |>
809+
dplyr::mutate(year = clock::get_year(.data$start_date))
810+
}
811+
820812
if ("record" %in% countBy & byYear == TRUE) {
821813
recordSummary <- dplyr::bind_rows(
822814
recordSummary,

tests/testthat/test-summariseCodeUse.R

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -603,7 +603,7 @@ test_that("summarise cohort code use - eunomia", {
603603
})
604604

605605
test_that("summarise code use - redshift", {
606-
606+
testthat::skip() # just run manually
607607
testthat::skip_if(Sys.getenv("CDM5_REDSHIFT_DBNAME") == "")
608608

609609
db <- DBI::dbConnect(RPostgres::Redshift(),
@@ -619,7 +619,8 @@ test_that("summarise code use - redshift", {
619619
writeSchema = Sys.getenv("CDM5_REDSHIFT_SCRATCH_SCHEMA"),
620620
cdmVersion = "5.3")
621621

622-
asthma <- list(asthma = c(317009L, 257581L))
622+
asthma <- list(asthma = c(317009L, 257581L)) |>
623+
omopgenerics::newCodelist()
623624

624625
results <- summariseCodeUse(asthma,
625626
cdm = cdm,

0 commit comments

Comments
 (0)