# Cohort Incidence {.break-slides}

::: {style='font-size: 50%;'}

```{r}
#| label: cohort incidence
#| echo: false
#| results: 'asis'

# figure out which targets are in char
ciTargetIds <- connectionHandler$queryDb("select distinct target_cohort_definition_id from @schema.ci_target_def;", schema = resultsSchema)

# targets
targetsCi <- targets %>% filter(
.data$cohortDefinitionId %in% !!ciTargetIds$targetCohortDefinitionId
)

if(nrow(targetsCi)>0 & nrow(outcomes)>0){
heading <- 'Targets'
ciIds <- targetsCi$cohortDefinitionId

result <- knitr::knit_child(text = knitr::knit_expand("cohort_incidence_template.qmd", quiet = TRUE, envir = environment()), quiet = TRUE, envir = environment())
cat(result, sep = '\n')
}

# indications
if(F){
#if(!is.null(indications)){
indicationCis <- cohorts %>%
  filter(
    .data$subsetParent %in% !!indications$cohortDefinitionId
  ) %>%
 filter(
    .data$subsetParent %in% !!ciTargetIds$targetCohortDefinitionId
  )

heading <- 'Indications'
ciIds <- indicationCis$cohortDefinitionId

result <- knitr::knit_child(text = knitr::knit_expand("cohort_incidence_template.qmd", quiet = TRUE, envir = environment()), quiet = TRUE, envir = environment())
cat(result, sep = '\n')
}

# comparators
if(!is.null(comparators)){
comparatorCis <- cohorts %>%
  filter(
    .data$subsetParent %in% !!comparators$cohortDefinitionId
  ) %>%
 filter(
    .data$subsetParent %in% !!ciTargetIds$targetCohortDefinitionId
  )

heading <- 'Comparators'
ciIds <- comparatorCis$cohortDefinitionId

result <- knitr::knit_child(text = knitr::knit_expand("cohort_incidence_template.qmd", quiet = TRUE, envir = environment()), quiet = TRUE, envir = environment())
cat(result, sep = '\n')
}





```

:::
