Skip to content
Open
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
17 changes: 11 additions & 6 deletions R/CharacterzationQueries.R
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#' @template databaseTable
#' @template targetIds
#' @template outcomeIds
#' @template outcomeCohortIds
#' @family Characterization
#' @return
#' Returns a data.frame with the columns:
Expand All @@ -22,6 +23,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}
Expand Down Expand Up @@ -62,21 +64,24 @@ getIncidenceRates <- function(
cgTablePrefix = 'cg_',
databaseTable = 'database_meta_data',
targetIds = NULL,
outcomeIds = NULL
outcomeIds = NULL, # This should be removed in next major release in favor of 'outcomeCohortIds'.
outcomeCohortIds = outcomeIds
){

sql <- 'select
d.cdm_source_abbreviation as database_name,
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,
Expand Down Expand Up @@ -120,7 +125,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(
Expand All @@ -130,14 +135,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)
Expand Down
4 changes: 2 additions & 2 deletions inst/templates/presentation/cohort_incidence_template.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -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 ){
Expand Down
1 change: 1 addition & 0 deletions man-roxygen/outcomeCohortIds.R
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
#' @param outcomeCohortIds A vector of integers corresponding to the outcome cohort IDs
6 changes: 5 additions & 1 deletion man/getIncidenceRates.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.