From 1e13010141bf7d8b72bdf0b7c505de303ca797a2 Mon Sep 17 00:00:00 2001 From: Chris Knoll Date: Mon, 14 Apr 2025 13:52:51 -0400 Subject: [PATCH 1/2] API Changes for Incidence Rates Renaming 'outcomeIds' to 'outcomeCohortIds' to avoid collision with Incidence Rate terminology for 'outcomes'. Adding incidence rate outcome_id to the output of getIncidenceRates. Adding tar_id to output of getIncidenceRates --- R/CharacterzationQueries.R | 17 ++++++++++------- man-roxygen/outcomeCohortIds.R | 1 + man/getIncidenceRates.Rd | 5 +++-- 3 files changed, 14 insertions(+), 9 deletions(-) create mode 100644 man-roxygen/outcomeCohortIds.R diff --git a/R/CharacterzationQueries.R b/R/CharacterzationQueries.R index 41ab40b..81beff3 100644 --- a/R/CharacterzationQueries.R +++ b/R/CharacterzationQueries.R @@ -12,7 +12,7 @@ #' @template cgTablePrefix #' @template databaseTable #' @template targetIds -#' @template outcomeIds +#' @template outcomeCohortIds #' @family Characterization #' @return #' Returns a data.frame with the columns: @@ -22,6 +22,7 @@ #' \item{targetId the target cohort unique identifier} #' \item{outcomeName the outcome name} #' \item{outcomeId the outcome unique identifier} +#' \item{outcomeCohortId the outcome cohort Id} #' \item{cleanWindow clean windown around outcome} #' \item{subgroupName name for the result subgroup} #' \item{ageGroupName name for the result age group} @@ -62,7 +63,7 @@ getIncidenceRates <- function( cgTablePrefix = 'cg_', databaseTable = 'database_meta_data', targetIds = NULL, - outcomeIds = NULL + outcomeCohortIds = NULL ){ sql <- 'select @@ -70,13 +71,15 @@ getIncidenceRates <- function( cg1.cohort_name as target_name, i.target_cohort_definition_id as target_id, cg2.cohort_name as outcome_name, - i.outcome_cohort_definition_id as outcome_id, + i.outcome_id, + i.outcome_cohort_definition_id as outcome_cohort_id, i.clean_window, i.subgroup_name, i.age_group_name, i.gender_name, i.start_year, + i.tar_id, i.tar_start_with, i.tar_start_offset, i.tar_end_with, @@ -120,7 +123,7 @@ getIncidenceRates <- function( where 1 = 1 {@use_target}?{ and target_cohort_definition_id in (@target_id)} - {@use_outcome}?{ and outcome_cohort_definition_id in (@outcome_id)} + {@use_outcome}?{ and outcome_cohort_definition_id in (@outcome_cohort_id)} ;' result <- connectionHandler$queryDb( @@ -130,14 +133,14 @@ getIncidenceRates <- function( cg_table_prefix = cgTablePrefix, target_id = paste0(targetIds, collapse = ','), use_target = !is.null(targetIds), - outcome_id = paste0(outcomeIds, collapse = ','), - use_outcome = !is.null(outcomeIds), + outcome_cohort_id = paste0(outcomeCohortIds, collapse = ','), + use_outcome = !is.null(outcomeCohortIds), database_table_name = databaseTable ) result$incidenceProportionP100p[is.na(result$incidenceProportionP100p)] <- result$outcomes[is.na(result$incidenceProportionP100p)]/result$personsAtRisk[is.na(result$incidenceProportionP100p)]*100 result$incidenceProportionP100p[is.na(result$incidenceProportionP100p)] <- 0 - result$incidenceRateP100py[is.na(result$incidenceRateP100py)] <- result$outcomes[is.na(result$incidenceRateP100py)]/(result$personDays[is.na(result$incidenceRateP100py)]/365)*100 + result$incidenceRateP100py[is.na(result$incidenceRateP100py)] <- result$outcomes[is.na(result$incidenceRateP100py)]/(result$personDays[is.na(result$incidenceRateP100py)]/365.25)*100 result$incidenceRateP100py[is.na(result$incidenceRateP100py)] <- 0 result[is.na(result)] <- 'Any' result <- unique(result) diff --git a/man-roxygen/outcomeCohortIds.R b/man-roxygen/outcomeCohortIds.R new file mode 100644 index 0000000..cae9223 --- /dev/null +++ b/man-roxygen/outcomeCohortIds.R @@ -0,0 +1 @@ +#' @param outcomeCohortIds A vector of integers corresponding to the outcome cohort IDs diff --git a/man/getIncidenceRates.Rd b/man/getIncidenceRates.Rd index 67186cb..8651ebe 100644 --- a/man/getIncidenceRates.Rd +++ b/man/getIncidenceRates.Rd @@ -11,7 +11,7 @@ getIncidenceRates( cgTablePrefix = "cg_", databaseTable = "database_meta_data", targetIds = NULL, - outcomeIds = NULL + outcomeCohortIds = NULL ) } \arguments{ @@ -27,7 +27,7 @@ getIncidenceRates( \item{targetIds}{A vector of integers corresponding to the target cohort IDs} -\item{outcomeIds}{A vector of integers corresponding to the outcome cohort IDs} +\item{outcomeCohortIds}{A vector of integers corresponding to the outcome cohort IDs} } \value{ Returns a data.frame with the columns: @@ -37,6 +37,7 @@ Returns a data.frame with the columns: \item{targetId the target cohort unique identifier} \item{outcomeName the outcome name} \item{outcomeId the outcome unique identifier} + \item{outcomeCohortId the outcome cohort Id} \item{cleanWindow clean windown around outcome} \item{subgroupName name for the result subgroup} \item{ageGroupName name for the result age group} From 67a59cc83fb015c00753f156dc37bf4ef55a4785 Mon Sep 17 00:00:00 2001 From: Chris Knoll Date: Wed, 23 Apr 2025 09:55:16 -0400 Subject: [PATCH 2/2] Address API compatability. Adjust ci template to use outcomeCohortId paramater. Regenerated documentation. --- R/CharacterzationQueries.R | 4 +++- inst/templates/presentation/cohort_incidence_template.qmd | 4 ++-- man/getIncidenceRates.Rd | 5 ++++- 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/R/CharacterzationQueries.R b/R/CharacterzationQueries.R index 81beff3..e5e4055 100644 --- a/R/CharacterzationQueries.R +++ b/R/CharacterzationQueries.R @@ -12,6 +12,7 @@ #' @template cgTablePrefix #' @template databaseTable #' @template targetIds +#' @template outcomeIds #' @template outcomeCohortIds #' @family Characterization #' @return @@ -63,7 +64,8 @@ getIncidenceRates <- function( cgTablePrefix = 'cg_', databaseTable = 'database_meta_data', targetIds = NULL, - outcomeCohortIds = NULL + outcomeIds = NULL, # This should be removed in next major release in favor of 'outcomeCohortIds'. + outcomeCohortIds = outcomeIds ){ sql <- 'select diff --git a/inst/templates/presentation/cohort_incidence_template.qmd b/inst/templates/presentation/cohort_incidence_template.qmd index 29581e2..86a9747 100644 --- a/inst/templates/presentation/cohort_incidence_template.qmd +++ b/inst/templates/presentation/cohort_incidence_template.qmd @@ -8,14 +8,14 @@ cat("\n::: {style='font-size: 50%;'}\n\n") cat('\n\n:::: {.panel-tabset .nav-pills}\n') for(outcomeInd in 1:nrow(outcomes)){ - outcomeId <- outcomes$cohortDefinitionId[outcomeInd] + outcomeCohortId <- outcomes$cohortDefinitionId[outcomeInd] outcomeName <- outcomes$cohortFriendlyName[outcomeInd] incidence <- OhdsiReportGenerator::getIncidenceRates( connectionHandler = connectionHandler, schema = resultsSchema, targetIds = ciIds, - outcomeIds = outcomeId + outcomeCohortIds = outcomeCohortId ) if(nrow(incidence) > 0 ){ diff --git a/man/getIncidenceRates.Rd b/man/getIncidenceRates.Rd index 8651ebe..f85e620 100644 --- a/man/getIncidenceRates.Rd +++ b/man/getIncidenceRates.Rd @@ -11,7 +11,8 @@ getIncidenceRates( cgTablePrefix = "cg_", databaseTable = "database_meta_data", targetIds = NULL, - outcomeCohortIds = NULL + outcomeIds = NULL, + outcomeCohortIds = outcomeIds ) } \arguments{ @@ -27,6 +28,8 @@ getIncidenceRates( \item{targetIds}{A vector of integers corresponding to the target cohort IDs} +\item{outcomeIds}{A vector of integers corresponding to the outcome cohort IDs} + \item{outcomeCohortIds}{A vector of integers corresponding to the outcome cohort IDs} } \value{