diff --git a/.gitignore b/.gitignore index 0bd2a448..95aa7b8f 100644 --- a/.gitignore +++ b/.gitignore @@ -6,3 +6,4 @@ errorReportSql.txt /Meta/ work/* scratch/ +inst/doc diff --git a/DESCRIPTION b/DESCRIPTION index c361772a..868eaf92 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: Capr Title: Cohort Definition Application Programming -Version: 2.0.4 +Version: 2.0.5 Authors@R: c( person("Martin", "Lavallee", , "mdlavallee92@gmail.com", role = c("aut", "cre")), person("Adam", "Black", , "black@ohdsi.org", role = "aut") diff --git a/NAMESPACE b/NAMESPACE index 702b8477..f003a377 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -11,16 +11,16 @@ export(bt) export(censoringEvents) export(cohort) export(compile.Cohort) -export(condition) export(conditionEra) +export(conditionOccurrence) export(continuousObservation) export(cs) export(daysOfSupply) export(death) export(descendants) -export(drug) export(drugEra) export(drugExit) +export(drugExposure) export(drugQuantity) export(drugRefills) export(duringInterval) diff --git a/NEWS.md b/NEWS.md index 410ff7cd..2a9fbd9a 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,3 +1,10 @@ +Capr 2.0.5 +========== +- change query functions to match known syntax (i.e. drug => drugExposure, condition => conditionOccurrence) +- require a name for `cs()` +- improve documentation (add vignette for query, count and group) + + Capr 2.0.4 ========== - hot fix add procedure occurrence into query diff --git a/R/conceptSet.R b/R/conceptSet.R index 73f86320..2359a828 100644 --- a/R/conceptSet.R +++ b/R/conceptSet.R @@ -193,7 +193,7 @@ newConcept <- function(id, #' cs(1, 2, 3, exclude(4, 5), mapped(6, 7), descendants(8, 9)) #' cs(descendants(1, 2, 3), exclude(descendants(8, 9))) #' } -cs <- function(..., name = "", id = NULL) { +cs <- function(..., name, id = NULL) { dots <- unlist(list(...), recursive = F) conceptList <- lapply(dots, function(x) { diff --git a/R/query.R b/R/query.R index fd908f4e..64e854a5 100644 --- a/R/query.R +++ b/R/query.R @@ -115,7 +115,7 @@ query <- function(domain, conceptSet = NULL, ...) { #' #' @return A Capr Query #' @export -condition <- function(conceptSet, ...) { +conditionOccurrence <- function(conceptSet, ...) { query(domain = "ConditionOccurrence", conceptSet = conceptSet, @@ -129,7 +129,7 @@ condition <- function(conceptSet, ...) { #' #' @return A Capr Query #' @export -drug <- function(conceptSet, ...) { +drugExposure <- function(conceptSet, ...) { query(domain = "DrugExposure", conceptSet = conceptSet, diff --git a/README.md b/README.md index 76bdb5e9..4f1504ef 100644 --- a/README.md +++ b/README.md @@ -16,11 +16,6 @@ Learn more about the OHDSI approach to cohort building in the [cohorts chapter o # Installation -Capr can be installed via: - -``` r -# install.packages("Capr") -``` Users can install the current development version of Capr from [GitHub](https://github.com/) with: @@ -29,246 +24,19 @@ Users can install the current development version of Capr from [GitHub](https:// devtools::install_github("ohdsi/Capr") ``` -# How to Use - -## Examples - -Capr uses many defaults that match the defaults in Atlas. Creating a simple cohort is a single line of code. As an example we will define a cohort of new users of diclofenac described in the [Book of OHDSI.](https://ohdsi.github.io/TheBookOfOhdsi/SuggestedAnswers.html#Cohortsanswers) - -### Simple diclofenac cohort - -``` r -library(Capr) - -# Define concepts sets with cs() -diclofenac <- cs(descendants(1124300)) - -ch <- cohort( - entry = entry(drugEra(diclofenac)) -) - -ch -#> Formal class 'Cohort' [package "Capr"] with 4 slots -#> ..@ entry :Formal class 'CohortEntry' [package "Capr"] with 5 slots -#> ..@ attrition:Formal class 'CohortAttrition' [package "Capr"] with 2 slots -#> ..@ exit :Formal class 'CohortExit' [package "Capr"] with 2 slots -#> ..@ era :Formal class 'CohortEra' [package "Capr"] with 3 slots -``` - -### Adding more complexity - -We can make more complex cohorts by adding a window of continuous observation and a custom cohort exit. The following information was added to the diclofenac cohort: - -- Ages 16 or older -- With at least 365 days of continuous observation prior to exposure -- With cohort exit defined as discontinuation of exposure (allowing for a 30-day gap) - -``` r -diclofenac <- cs(descendants(1124300)) - -ch <- cohort( - entry = entry(drugEra(diclofenac, age(gte(16))), - observationWindow = continuousObservation(-365L, 0L)), - exit = exit(drugExit(diclofenac)) -) - -ch -#> Formal class 'Cohort' [package "Capr"] with 4 slots -#> ..@ entry :Formal class 'CohortEntry' [package "Capr"] with 5 slots -#> ..@ attrition:Formal class 'CohortAttrition' [package "Capr"] with 2 slots -#> ..@ exit :Formal class 'CohortExit' [package "Capr"] with 2 slots -#> ..@ era :Formal class 'CohortEra' [package "Capr"] with 3 slots -``` - -### Adding cohort attrition - -Users can also add attrition to the cohort by specifying inclusion and exclusion criteria to modify the cohort entry. The following exclusion criteria were added to the diclofenac cohort: - -- Without prior exposure to any NSAID (Non-Steroidal Anti-Inflammatory Drug) -- Without prior diagnosis of cancer - -``` r -diclofenac <- cs(descendants(1124300), name = "diclofenac") -nsaid <- cs(descendants(21603933), name = "nsaid") -cancer <- cs(descendants(443392), name = "cancer") - -ch <- cohort( - entry = entry(drugEra(diclofenac, age(gte(16))), - observationWindow = continuousObservation(-365L, 0L)), - attrition = attrition( - withAll( - exactly(0, drug(nsaid), eventStarts(-Inf, 0, index = "startDate")), - exactly(0, condition(cancer), eventStarts(-Inf, 0, index = "startDate")) - ) - ), - exit = exit( - endStrategy = drugExit(diclofenac, persistenceWindow = 30) - ) -) - -ch -#> Formal class 'Cohort' [package "Capr"] with 4 slots -#> ..@ entry :Formal class 'CohortEntry' [package "Capr"] with 5 slots -#> ..@ attrition:Formal class 'CohortAttrition' [package "Capr"] with 2 slots -#> ..@ exit :Formal class 'CohortExit' [package "Capr"] with 2 slots -#> ..@ era :Formal class 'CohortEra' [package "Capr"] with 3 slots -``` - -## Save cohort as JSON - -OHDSI standard cohorts are represented as json files and can be copy and pasted into Atlas. - -``` r - -path <- file.path(tempdir(), "diclofenacCohort.json") - -writeCohort(ch, path) - -cat(substr(readr::read_file(path), 1, 100)) -#> { -#> "ConceptSets": [ -#> { -#> "id": 0, -#> "name": "diclofenac", -#> "expression": { -#> -``` - -### Fill in missing concept set details - -Users can build valid cohorts with minimal concept information, only supplying a concept id and name. The example below shows the minimal concept set input for Capr. - -``` r - -diclofenac <- cs(descendants(1124300), name = "diclofenac") - -cat(as.json(diclofenac)) -#> { -#> "id": "11d012608fce118593830a3039042e56", -#> "name": "diclofenac", -#> "expression": { -#> "items": [ -#> { -#> "concept": { -#> "CONCEPT_ID": 1124300, -#> "CONCEPT_NAME": "", -#> "STANDARD_CONCEPT": "", -#> "STANDARD_CONCEPT_CAPTION": "", -#> "INVALID_REASON": "", -#> "INVALID_REASON_CAPTION": "", -#> "CONCEPT_CODE": "", -#> "DOMAIN_ID": "", -#> "VOCABULARY_ID": "", -#> "CONCEPT_CLASS_ID": "" -#> }, -#> "isExcluded": false, -#> "includeDescendants": true, -#> "includeMapped": false -#> } -#> ] -#> } -#> } -``` - -However, when saving cohorts it is helpful to fill in the concept details. This requires a live connection to an OMOP CDM database that includes the vocabularies used in the cohort definition. - -``` r -con <- DatabaseConnector::connect(Eunomia::getEunomiaConnectionDetails()) -diclofenac <- getConceptSetDetails(diclofenac, con, vocabularyDatabaseSchema = "main") -cat(as.json(diclofenac)) -#> { -#> "id": "11d012608fce118593830a3039042e56", -#> "name": "diclofenac", -#> "expression": { -#> "items": [ -#> { -#> "concept": { -#> "CONCEPT_ID": 1124300, -#> "CONCEPT_NAME": "Diclofenac", -#> "STANDARD_CONCEPT": "S", -#> "STANDARD_CONCEPT_CAPTION": "Standard", -#> "INVALID_REASON": "V", -#> "INVALID_REASON_CAPTION": "Valid", -#> "CONCEPT_CODE": "3355", -#> "DOMAIN_ID": "Drug", -#> "VOCABULARY_ID": "RxNorm", -#> "CONCEPT_CLASS_ID": "Ingredient" -#> }, -#> "isExcluded": false, -#> "includeDescendants": true, -#> "includeMapped": false -#> } -#> ] -#> } -#> } -``` - -### Generating Capr Cohorts - -Once a Capr cohort has been constructed, the user can generate this cohort definition on an OMOP CDM connection. It is suggested to use [CohortGenerator](https://github.com/OHDSI/CohortGenerator) and [CirceR](https://github.com/OHDSI/CirceR) to generate Capr cohorts on a database. - -## Building Capr Templates - -A Capr cohort template is a function that always returns a Capr cohort. It can accept arguments that can be used to parameterize any part of a cohort definition. Capr cohort templates are the recommended approach for building large numbers of similar cohorts in R. - -``` r - -# A Capr cohort template is a function that returns a cohort -drugEraTemplate <- function(ingredientConceptId) { - - drugConceptSet <- cs(descendants(ingredientConceptId)) - - cohort( - entry = entry(drugEra(drugConceptSet, age(gte(16))), - observationWindow = continuousObservation(-365L, 0L)), - exit = exit(drugExit(drugConceptSet, persistenceWindow = 30)) - ) -} - - -library(dplyr, warn.conflicts = FALSE) - -# create a cohort for every single ingredient -df <- DBI::dbGetQuery(con, - "Select * from concept where concept_class_id = 'Ingredient'") %>% - tibble() %>% - select(concept_id, concept_name) %>% - mutate(capr_cohort = purrr::map(concept_id, drugEraTemplate)) %>% - mutate(cohort_json = purrr::map_chr(capr_cohort, as.json)) - -df -#> # A tibble: 91 × 4 -#> concept_id concept_name capr_cohort cohort_json -#> -#> 1 1557272 Alendronate "{\n \"ConceptSets\": [\n {\n … -#> 2 708298 Midazolam "{\n \"ConceptSets\": [\n {\n … -#> 3 701322 Memantine "{\n \"ConceptSets\": [\n {\n … -#> 4 723013 Diazepam "{\n \"ConceptSets\": [\n {\n … -#> 5 1129625 Diphenhydramine "{\n \"ConceptSets\": [\n {\n … -#> 6 1149196 Cetirizine "{\n \"ConceptSets\": [\n {\n … -#> 7 1149380 fluticasone "{\n \"ConceptSets\": [\n {\n … -#> 8 1150770 Astemizole "{\n \"ConceptSets\": [\n {\n … -#> 9 1150836 Terfenadine "{\n \"ConceptSets\": [\n {\n … -#> 10 1124300 Diclofenac "{\n \"ConceptSets\": [\n {\n … -#> # … with 81 more rows -``` - -The capr_cohort column of the dataframe is a list of Capr cohort object. The cohort_json column contains the json specifications for each cohort. - -``` r -DatabaseConnector::disconnect(con) -``` # User Documentation Documentation can be found on the [package website](https://ohdsi.github.io/Capr/). + PDF versions of the documentation are also available: - Vignette: [Using Capr](https://raw.githubusercontent.com/OHDSI/Capr/main/extras/pdf_vignette/Using-Capr.pdf) - Vignette: [Capr Examples](https://raw.githubusercontent.com/OHDSI/Capr/main/extras/pdf_vignette/Examples.pdf) - Vignette: [Working with Concept Sets in Capr](https://raw.githubusercontent.com/OHDSI/Capr/main/extras/pdf_vignette/Capr-conceptSets.pdf) - Vignette: [Capr for Templating Cohort Definitions](https://raw.githubusercontent.com/OHDSI/Capr/main/extras/pdf_vignette/capr_templatesr.pdf) +- Vignette: [Capr components](https://raw.githubusercontent.com/OHDSI/Capr/main/extras/pdf_vignette/capr_objects.pdf) - [Design Document](https://raw.githubusercontent.com/OHDSI/Capr/main/extras/pdf_vignette/capr_design.pdf) - [Package manual](https://raw.githubusercontent.com/OHDSI/Capr/main/extras/Capr.pdf) diff --git a/docs/404.html b/docs/404.html index 53695b70..74923ba3 100644 --- a/docs/404.html +++ b/docs/404.html @@ -39,7 +39,7 @@ Capr - 2.0.4 + 2.0.5 @@ -61,6 +61,9 @@
  • Capr Design Guide and Roadmap
  • +
  • + Capr Objects +
  • Capr for Templating Cohort Definitions
  • diff --git a/docs/LICENSE.html b/docs/LICENSE.html index b38db886..e77d74d5 100644 --- a/docs/LICENSE.html +++ b/docs/LICENSE.html @@ -17,7 +17,7 @@ Capr - 2.0.4 + 2.0.5 @@ -37,6 +37,9 @@
  • Capr Design Guide and Roadmap
  • +
  • + Capr Objects +
  • Capr for Templating Cohort Definitions
  • diff --git a/docs/articles/Capr-conceptSets.html b/docs/articles/Capr-conceptSets.html index fae90410..a56ca248 100644 --- a/docs/articles/Capr-conceptSets.html +++ b/docs/articles/Capr-conceptSets.html @@ -40,7 +40,7 @@ Capr - 2.0.4 + 2.0.5 @@ -62,6 +62,9 @@
  • Capr Design Guide and Roadmap
  • +
  • + Capr Objects +
  • Capr for Templating Cohort Definitions
  • @@ -136,14 +139,16 @@

    Defining a concept set name = "aceInhibitors") ace1 #> -- <Capr Concept Set> aceInhibitors -------------------------------------------- -#> # A tibble: 5 x 4 -#> conceptId includeDescendants isExcluded includeMapped -#> <int> <lgl> <lgl> <lgl> -#> 1 1335471 FALSE FALSE FALSE -#> 2 1340128 FALSE FALSE FALSE -#> 3 1341927 FALSE FALSE FALSE -#> 4 1308216 FALSE FALSE FALSE -#> 5 1363749 FALSE FALSE FALSE +#> # A tibble: 5 x 9 +#> conceptId conceptCode conceptName domainId vocabularyId standardConcept +#> <int> <chr> <chr> <chr> <chr> <chr> +#> 1 1335471 "" "" "" "" "" +#> 2 1340128 "" "" "" "" "" +#> 3 1341927 "" "" "" "" "" +#> 4 1308216 "" "" "" "" "" +#> 5 1363749 "" "" "" "" "" +#> # i 3 more variables: includeDescendants <lgl>, isExcluded <lgl>, +#> # includeMapped <lgl> +#> # A tibble: 5 x 9 +#> conceptId conceptCode conceptName domainId vocabularyId standardConcept +#> <int> <chr> <chr> <chr> <chr> <chr> +#> 1 1335471 "" "" "" "" "" +#> 2 1340128 "" "" "" "" "" +#> 3 1341927 "" "" "" "" "" +#> 4 1363749 "" "" "" "" "" +#> 5 1308216 "" "" "" "" "" +#> # i 3 more variables: includeDescendants <lgl>, isExcluded <lgl>, +#> # includeMapped <lgl> +#> # A tibble: 5 x 9 +#> conceptId conceptCode conceptName domainId vocabularyId standardConcept +#> <int> <chr> <chr> <chr> <chr> <chr> +#> 1 1335471 "" "" "" "" "" +#> 2 1340128 "" "" "" "" "" +#> 3 1341927 "" "" "" "" "" +#> 4 1363749 "" "" "" "" "" +#> 5 1308216 "" "" "" "" "" +#> # i 3 more variables: includeDescendants <lgl>, isExcluded <lgl>, +#> # includeMapped <lgl> + +
    +

    Fill in missing concept set details +

    +

    By default, Capr puts in minimal information for the +concept set, the concept id. However it is often helpful to fill out the +remaining information of the concept using the OMOP vocabularies. To +fill out the remaining information, a user needs to connect to a OMOP +CDM to access the vocabulary information for the concept in the concept +set. First we show a regular concept set, and the json it renders.

    +
    +diclofenac <- cs(descendants(1124300), name = "diclofenac")
    +cat(as.json(diclofenac))
    +

    Now we add in the CDM connection to get the remaining +information:

    +
    +con <- DatabaseConnector::connect(Eunomia::getEunomiaConnectionDetails())
    +diclofenac <- getConceptSetDetails(diclofenac, con, vocabularyDatabaseSchema = "main")
    +cat(as.json(diclofenac))
    diff --git a/docs/articles/Examples.html b/docs/articles/Examples.html index c61ef3d9..35d74d01 100644 --- a/docs/articles/Examples.html +++ b/docs/articles/Examples.html @@ -40,7 +40,7 @@ Capr - 2.0.4 + 2.0.5 @@ -62,6 +62,9 @@
  • Capr Design Guide and Roadmap
  • +
  • + Capr Objects +
  • Capr for Templating Cohort Definitions
  • @@ -139,7 +142,7 @@

    Type 2 diabetes mellitus ch <- cohort( entry = entry( - condition(cs0), + conditionOccurrence(cs0), observationWindow = continuousObservation(priorDays = 365) ), exit = exit( @@ -164,12 +167,12 @@

    Type 2 diabetes mellitus ch <- cohort( entry = entry( - condition(cs0), + conditionOccurrence(cs0), observationWindow = continuousObservation(priorDays = 365) ), attrition = attrition( - exactly(0, condition(cs1), duringInterval(eventStarts(-Inf, 0))), - exactly(0, condition(cs2), duringInterval(eventStarts(-Inf, 0))) + exactly(0, conditionOccurrence(cs1), duringInterval(eventStarts(-Inf, 0))), + exactly(0, conditionOccurrence(cs2), duringInterval(eventStarts(-Inf, 0))) ), exit = exit( endStrategy = observationExit() @@ -200,18 +203,18 @@

    Type 2 diabetes mellitus ch <- cohort( entry = entry( - condition(cs0), - drug(cs4), + conditionOccurrence(cs0), + drugExposure(cs4), measurement(cs3, valueAsNumber(bt(6.5, 30)), unit("%")), measurement(cs3, valueAsNumber(bt(48, 99)), unit("mmol/mol")), observationWindow = continuousObservation(priorDays = 365) ), attrition = attrition( 'no T1D' = withAll( - exactly(0, condition(cs1), duringInterval(eventStarts(-Inf, 0))) + exactly(0, conditionOccurrence(cs1), duringInterval(eventStarts(-Inf, 0))) ), 'no secondary diabettes' = withAll( - exactly(0, condition(cs2), duringInterval(eventStarts(-Inf, 0))) + exactly(0, conditionOccurrence(cs2), duringInterval(eventStarts(-Inf, 0))) ) ), exit = exit( @@ -230,7 +233,7 @@

    Type 1 diabetes mellitus ch <- cohort( entry = entry( - condition(cs0), + conditionOccurrence(cs0), observationWindow = continuousObservation(priorDays = 365) ) ) @@ -253,12 +256,12 @@

    Type 1 diabetes mellitus ch <- cohort( entry = entry( - condition(cs1), + conditionOccurrence(cs1), observationWindow = continuousObservation(priorDays = 365) ), attrition = attrition( - "no prior T2DM" = exactly(0, condition(cs0), duringInterval(eventStarts(-Inf, 0))), - "no prior secondary T1DM" = exactly(0, condition(cs2), duringInterval(eventStarts(-Inf, 0))) + "no prior T2DM" = exactly(0, conditionOccurrence(cs0), duringInterval(eventStarts(-Inf, 0))), + "no prior secondary T1DM" = exactly(0, conditionOccurrence(cs2), duringInterval(eventStarts(-Inf, 0))) ) ) @@ -273,7 +276,7 @@

    Atrial Fibrillationcs0 <- cs(descendants(313217), name = "Atrial fibrillation") -ch <- cohort(condition(cs0)) +ch <- cohort(conditionOccurrence(cs0))

    Persons with atrial fibrillation per Subramanya et al 2021

    https://atlas-phenotype.ohdsi.org/#/cohortdefinition/94

    @@ -290,13 +293,13 @@

    Atrial Fibrillationch <- cohort( entry = entry( - condition(afib, + conditionOccurrence(afib, nestedWithAny( atLeast(1, visit(ip), duringInterval(eventStarts(-Inf, 0), eventEnds(0, Inf))), nestedWithAll( atLeast(1, visit(op, duringInterval(eventStarts(-Inf, 0), eventEnds(0, Inf)), nestedWithAll( - atLeast(1, condition(afib, duringInterval(eventStarts(7, 365)), + atLeast(1, conditionOccurrence(afib, duringInterval(eventStarts(7, 365)), nestedWithAll( atLeast(1, visit(op, duringInterval(eventStarts(-Inf, 0), eventEnds(0, Inf)))) ) diff --git a/docs/articles/Using-Capr.html b/docs/articles/Using-Capr.html index 889f4be7..4ae3b12a 100644 --- a/docs/articles/Using-Capr.html +++ b/docs/articles/Using-Capr.html @@ -40,7 +40,7 @@ Capr - 2.0.4 + 2.0.5 @@ -62,6 +62,9 @@
  • Capr Design Guide and Roadmap
  • +
  • + Capr Objects +
  • Capr for Templating Cohort Definitions
  • @@ -143,7 +146,7 @@

    Building a concept set
     library(Capr)
     
    -GIBleed <- cs(descendants(192671))
    +GIBleed <- cs(descendants(192671), name = "GIbleed")
     
     GIBleed

    The GIBleed concept set will include all descendants of the @@ -159,7 +162,7 @@

    Creating a cohort
     giBleedCohort <- cohort(
       entry = entry(
    -    condition(GIBleed),
    +    conditionOccurrence(GIBleed),
         observationWindow = continuousObservation(0L, 0L),
         primaryCriteriaLimit = "First"
       ),
    diff --git a/docs/articles/capr_design.html b/docs/articles/capr_design.html
    index 695c44e4..ca011e80 100644
    --- a/docs/articles/capr_design.html
    +++ b/docs/articles/capr_design.html
    @@ -40,7 +40,7 @@
           
           
             Capr
    -        2.0.4
    +        2.0.5
           
         
     
    @@ -62,6 +62,9 @@
         
  • Capr Design Guide and Roadmap
  • +
  • + Capr Objects +
  • Capr for Templating Cohort Definitions
  • @@ -464,7 +467,7 @@
    1) Query CDM. For example:

     visit(conceptSet, ...)
    -condition(concept, ...)
    +condition(concept, ...)

    The conceptSet input takes on a a concept set built from the cs command. The dots argument is where the user can supply attributes that contextualize the query to a specific subpopulation.

    @@ -491,9 +494,9 @@

    2) Attribute
    -condition(cs(descendants(201826L), name = "T2D"), male())
    -condition(cs(descendants(201826L), name = "T2D"), age(gte(18)))
    -condition(cs(descendants(201826L), name = "T2D"), first())
    +condition(cs(descendants(201826L), name = "T2D"), male()) +condition(cs(descendants(201826L), name = "T2D"), age(gte(18))) +condition(cs(descendants(201826L), name = "T2D"), first())

    The first example in code snippet 4 utilizes a concept attribute. The male() function automatically maps the concept to the male concept id. Other concept attribute functions will have mappers and @@ -558,7 +561,7 @@

    3) Criteria
     exactly(0, 
    -        query = condition(cs(descendants(201826L), name = "T2D")),
    +        query = condition(cs(descendants(201826L), name = "T2D")),
             aperture = duringInterval(eventStarts(-Inf, -1))
             )

    A note for the criteria is that its meaning is tethered to an event diff --git a/docs/articles/capr_objects.html b/docs/articles/capr_objects.html new file mode 100644 index 00000000..e07aca05 --- /dev/null +++ b/docs/articles/capr_objects.html @@ -0,0 +1,708 @@ + + + + + + + +Capr Objects • Capr + + + + + + + + + + + + + + + + + + + +

    +
    + + + + +
    +
    + + + + +
    +

    Intro +

    +

    Capr allows users to build OHDSI cohort definitions in R +outside of ATLAS. Capr, like ATLAS, uses the same +underlying software circe-be to compose the cohort logic +into an actionable query. Therefore we must understand sub-components of +the cohort definition, in order to properly apply them to our cohort +construction. There are three main sub-components that drive building of +the cohort logic: 1) query, 2) criteria and 3) group. In this vignette, +we will describe the purpose of each sub-component and demonstrate the +Capr commands to invoke these structures.

    +
    +
    +

    Query +

    +
    +

    Definition +

    +

    The query is a circe-be construct that defines +which concepts to extract from which domain table in the OMOP CDM. In +basic terms it is finding the persons that have a particular code in the +data. Through a more technical lens, the query is supplying the +WHERE and FROM logic in portions of +the SQL script. Ultimately the logic we construct in Capr +or ATLAS render a standardized SQL script that finds persons in the +database, of which the query is vital in providing the code sets to +search from. The query will be found all over the cohort +definition. Whenever we need to apply a concept set, it will be through +a query. In Capr the query function is +specified based on the domain tables available in the CDM. The table +below provides the mapping between the OMOP domain and the the +Capr function call.

    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    OMOP DomainCapr Function
    DrugExposuredrugExposure
    DrugEradrugEra
    ConditionOccurrenceconditionOccurrence
    ConditionEraconditionEra
    ProcedureOccurrenceprocedure
    Measurementmeasurement
    VisitOccurrencevisit
    Observationobservation
    Deathdeath
    +
    +
    +

    Example +

    +

    A simple example of how to use a query in Capr can be +seen below:

    +
    +t1dConceptSet <- cs(descendants(195771), name = "T1D")
    +t1dQuery <- conditionOccurrence(t1dConceptSet)
    +

    With our query we can apply this in a variety of places within the +cohort definition. Below we give an example of a cohort of persons +starting on metformin as our index event, where they could not have been +diagnosed with Type 1 Diabetes any time prior.

    +
    +metforminConceptSet <- cs(descendants(1503297), name = "metformin")
    +t1dConceptSet <- cs(descendants(195771), name = "T1D")
    +
    +metforminCohort <- cohort(
    +  entry = entry(
    +    # metformin drug query as index event
    +    drugExposure(metforminConceptSet, firstOccurrence()), 
    +    observationWindow = continuousObservation(priorDays = -365, postDays = 365L),
    +    primaryCriteriaLimit = "All"
    +  ),
    +  attrition = attrition(
    +    'noT1d' = withAll(
    +      exactly(
    +        x = 0, 
    +        # query for t1d occurrence to exclude patients
    +        query = conditionOccurrence(t1dConceptSet), 
    +        aperture = duringInterval(
    +          startWindow = eventStarts(a = -Inf, b = 0, index = "startDate")
    +        )
    +      )
    +    )
    +  ),
    +  exit = exit(
    +    endStrategy = observationExit(),
    +    censor = censoringEvents(
    +      #exit based on observence of t1d condition
    +      # query for t1d occurrence for censor
    +      conditionOccurrence(t1dConceptSet) 
    +    )
    +  )
    +)
    +

    Notice that the query is applied all over this cohort +definition. The metformin query sets the concept set to use as the index +event. The Type 1 Diabetes (T1D) query sets the attrition of the +patients identified at index who should be excluded for having the +condition. The T1D query also sets the exit from cohort. The cohort ends +when the person has no more observation time in the database or they +have been diagnosed with T1D. Remember the query is infusing +the concept sets into the cohort logic based on which domain to search +for codes in person healthcare records.

    +
    +
    +

    Attributes +

    +

    The query is often contextualized by an attribute. For +example in the cohort above, we are searching for metformin in the drug +exposure table given it has occurred for the first time in the person +history. The attribute is a object that modifies queries by filtering +records based on the presence of another parameter. Attributes can be +based on person information (such as gender, race, or age), time based +(observation at a certain time window), domain based (presence of a code +in a different column of the same domain), or event based (based on the +observation of another event occurring). We will go into more details on +different attributes in a different vignette. In Capr as +many attributes can be attached within the query after providing the +concept set. Example below:

    +
    +t1dConceptSet <- cs(descendants(195771), name = "T1D")
    +
    +maleT1D <- conditionOccurrence(t1dConceptSet, male())
    +maleT1D18andOlder <- conditionOccurrence(t1dConceptSet, male(), age(gte(18)))
    +maleT1D18andOlderFirstDx <- conditionOccurrence(
    +  t1dConceptSet, male(), age(gte(18)), firstOccurrence())
    +

    One special type of attribute is a nested query. This construct is +more complex and requires understanding of the criteria and +group objects. We will return to this idea later in this +vignette.

    +
    +
    +
    +

    Criteria +

    +
    +

    Definition +

    +

    A criteria object is one that enumerates the presence or +absence of an event within a window of observation relative to an index +point. The index point may be the entry event of the cohort definition. +It could also be a prior event if we are building a nested query. The +purpose of this object is to count whether a person has experienced +certain events that would either include or exclude them from the +cohort. Its easiest to show a criteria using a figure. Say +relative from index we want to see two exposures of a drug within 365 +days and 30 days before index. Those that fit that criteria remain in +the cohort, those that do not are excluded from the cohort. See the +figure below as an example:

    +
    +

    Example of Criteria

    +
    +

    When building a criteria object the user needs: 1) a query, +2) an operator that specifies the number of times a query is observed +(occurrences), and 3) a time window which we call the aperture. Using +the figure as an example, think of the stars as the query, the number of +stars as the occurrences, and the box as the aperture. We could orient +this idea around the index event in a variety of different ways.

    +
    +
    +

    Example +

    +

    With this definition in mind, let us build an example of a +criteria object that reflects the image above.

    +
    +atenololConceptSet <- cs(descendants(1314002), name - "atenolol")
    +
    +atenololCriteria <- atLeast(
    +  x = 2, 
    +  query = drugExposure(atenololConceptSet),
    +  aperture = duringInterval(
    +    startWindow = eventStarts(a = -365, b = -30, index = "startDate")
    +  )
    +)
    +

    This criteria specifies that we must observe at least 2 drug +exposures of atenolol within 365 days and 30 days before the index start +date. By itself, a criteria makes little sense. It must sit +within the context of the entire cohort definition, where an index event +has been specified. In Capr the criteria object is +called in three ways: atLeast, atMost and +exactly. The criteria object in Capr +is contextualized by the number of occurrences of the query for its +function call. If we wanted to have exactly 2 drug exposures of atenolol +or at most 2 drug exposures they can be done as shown below.

    +
    +atenololConceptSet <- cs(descendants(1314002), name - "atenolol")
    +
    +atenololCriteriaA <- exactly(
    +  x = 2, 
    +  query = drugExposure(atenololConceptSet),
    +  aperture = duringInterval(
    +    startWindow = eventStarts(a = -365, b = -30, index = "startDate")
    +  )
    +)
    +
    +atenololCriteriaB <- atMost(
    +  x = 2, 
    +  query = drugExposure(atenololConceptSet),
    +  aperture = duringInterval(
    +    startWindow = eventStarts(a = -365, b = -30, index = "startDate")
    +  )
    +)
    +
    +
    +

    Aperture +

    +

    An important part of the criteria object is providing the +temporal context to enumerating the occurrences of the query. In +Capr we term this interval relative to index as the +aperture. It is the opening in the patient timeline at which we are +enumerating the event of interest. An aperture can view when an event +starts and when the event ends. For both event start and event end, we +define a window for which the event is observed. Below we illustrate a +few examples of building an aperture and then show the corresponding the +Capr code.

    +

    Example 1: Retrospective Start Window In this first example we +are observing when an event starts between time of 365 to 30 days before +the index start date. To build this aperture we use the following +Capr code:

    +
    +aperture1 <- duringInterval(
    +  startWindow = eventStarts(a = -365, b = -30, index = "startDate")
    +)
    +

    Notice that we define the anchor for our index, either the index +start date or the index end date. More times than not this will be the +index start date.

    +

    Example 2: Retrospective Start Window all time prior This next +example is similar to the first, however now we have an unbounded event +window. In this case the event start must be between any time before and +30 days before the index start date. In Capr we can always +create an unbounded event window by using the Inf operator +in our code, as shown below.

    +
    +aperture2 <- duringInterval(
    +  startWindow = eventStarts(a = -Inf, b = -30, index = "startDate")
    +)
    +

    Example 3: Start window including future time Our next example +provides an instance where we want our event window to utilize future +time. Normally we want to observe an event prior to index. On occasion +we can allow for an event to take place after index. The +Capr code to build this aperture is shown below:

    +
    +aperture3 <- duringInterval(
    +  startWindow = eventStarts(a = -30, b = 30, index = "startDate")
    +)
    +

    Example 4: Start and end window in aperture Our final example +shows a scenario when we want the aperture to be constrained by both a +start window and end window. The end window is considering observation +of the end of the event. Say for example the event era starts with an +exposure to a drug and end is when the person stops taking the drug. If +the interest is the full time the person was encountering this medical +event we need to create both a start and end window in the aperture. The +Capr code below would replicate the concept from the +figure.

    +
    +aperture4 <- duringInterval(
    +  startWindow = eventStarts(a = -365, b = -30, index = "startDate"),
    +  endWindow = eventEnds(a = 30, b = 365, index = "startDate")
    +)
    +

    An aperture has two more potential toggles: a) restrict event to the +same visit and b) allow events outside the observation period. By +default these options are toggled as FALSE, so they do not +need to be defined in the Capr code unless made +TRUE. These are more advanced options in cohort building. +To use the we add this to aperture example 4 to show a full set of +options for an aperture in Capr:

    +
    +aperture5 <- duringInterval(
    +  startWindow = eventStarts(a = -365, b = -30, index = "startDate"),
    +  endWindow = eventEnds(a = 30, b = 365, index = "startDate"),
    +  restrictVisit = TRUE,
    +  ignoreObservationPeriod = TRUE
    +)
    +
    +
    +
    +

    Group +

    +
    +

    Definition +

    +

    A group object is one that binds multiple criteria and +sub-groups as a single expression. This is a very powerful construction +because it allows us to build all sorts of complexity in our cohort +definition. A group must have an operator informing how many +criteria must be TRUE in order for the person to +enter the cohort. In Capr the options available to build a +group are: withAll, withAny, +withAtLeast and withAtMost. The functions are +meant to be intuitive in terms of logic building. withAll +indicates all the criteria must be TRUE for the person to +remain in the cohort. withAny indicates any one of the +criteria needs to be TRUE. The functions +withAtLeast and withAtMost require an integer +to determine how many criteria must be TRUE.

    +
    +
    +

    Example +

    +

    To show the idea of a group let us consider a very +complicated cohort, like the PheKB +T2D case algorithm. To consider a person to be a case of T2D, any +one of 5 pathways needs to be TRUE.

    +
    +t2dAlgo <- withAny(
    +  # Path 1: 0 T2Dx + 1 T2Rx + 1 abLab
    +  withAll(
    +    exactly(0, 
    +            t2d, 
    +            duringInterval(startWindow = eventStarts(-Inf, 0))
    +    ),
    +    atLeast(1, 
    +            t2dDrug, 
    +            duringInterval(startWindow = eventStarts(-Inf, 0))
    +    ),
    +    withAny(
    +      atLeast(1, 
    +              abLabHb, 
    +              duringInterval(startWindow = eventStarts(-Inf, 0))
    +      ),
    +      atLeast(1, 
    +              abLabRan, 
    +              duringInterval(startWindow = eventStarts(-Inf, 0))
    +      ),
    +      atLeast(1, 
    +              abLabFast, 
    +              duringInterval(startWindow = eventStarts(-Inf, 0))
    +      )
    +    )
    +  ),
    +  #Path 2: 1 T2Dx + 0 T1Rx + 0 T2Rx + 1 AbLab
    +  withAll(
    +    atLeast(1, 
    +            t2d, 
    +            duringInterval(startWindow = eventStarts(-Inf, 0))
    +    ),
    +    exactly(0, 
    +            t1dDrug, 
    +            duringInterval(startWindow = eventStarts(-Inf, 0))
    +    ),
    +    exactly(0, 
    +            t2dDrug, 
    +            duringInterval(startWindow = eventStarts(-Inf, 0))
    +    ),
    +    withAny(
    +      atLeast(1, 
    +              abLabHb, 
    +              duringInterval(startWindow = eventStarts(-Inf, 0))
    +      ),
    +      atLeast(1, 
    +              abLabRan, 
    +              duringInterval(startWindow = eventStarts(-Inf, 0))
    +      ),
    +      atLeast(1, 
    +              abLabFast, 
    +              duringInterval(startWindow = eventStarts(-Inf, 0))
    +      )
    +    )
    +  ),
    +  #Path 3: 1 T2Dx + 0 T1Rx + 1 T2Rx
    +  withAll(
    +    atLeast(1, 
    +            t2d, 
    +            duringInterval(startWindow = eventStarts(-Inf, 0))
    +    ),
    +    exactly(0, 
    +            t1dDrug, 
    +            duringInterval(startWindow = eventStarts(-Inf, 0))
    +    ),
    +    atLeast(1, 
    +            t2dDrug, 
    +            duringInterval(startWindow = eventStarts(-Inf, 0))
    +    )
    +  ),
    +  #Path 4: 1 T2Dx + 1 T1Rx + 1 T1Rx|T2Rx
    +  withAll(
    +    atLeast(1, 
    +            t2d, 
    +            duringInterval(startWindow = eventStarts(-Inf, 0))
    +    ),
    +    atLeast(1, 
    +            t1dDrug, 
    +            duringInterval(startWindow = eventStarts(-Inf, 0))
    +    ),
    +    atLeast(1, 
    +            t1dDrugWT2Drug, 
    +            duringInterval(startWindow = eventStarts(-Inf, 0))
    +    )
    +  ),
    +  #Path 5: 1 T2Dx  + 1 T1Rx + 0 T2Rx + 2 T2Dx
    +  withAll(
    +    atLeast(1, 
    +            t2d, 
    +            duringInterval(startWindow = eventStarts(-Inf, 0))
    +    ),
    +    atLeast(1, 
    +            t1dDrug, 
    +            duringInterval(startWindow = eventStarts(-Inf, 0))
    +    ),
    +    exactly(0, 
    +            t2dDrug, 
    +            duringInterval(startWindow = eventStarts(-Inf, 0))
    +    ),
    +    atLeast(2, 
    +            t2d, 
    +            duringInterval(startWindow = eventStarts(-Inf, 0))
    +    )
    +  )
    +)
    +

    Each pathway is complex and require multiple criteria to determine a +T2D case. The group allows us to bundle multiple ideas together +to build one complex expression.

    +
    +
    +

    Notes +

    +

    Now that we have introduced the criteria and group, +there are a few important comments on how these objects are used within +circe-be.

    +

    1) Criteria must be placed within a group

    +

    A criteria can not be used on its own, it must be wrapped in +a group. Even if only one criteria is needed, still +wrap it in a group. An example would be:

    +
    +noT1d <- withAll(
    +  # criteria: no t1d prior
    +  exactly(
    +    x = 0, 
    +    query = conditionOccurrence(t1dConceptSet), 
    +    aperture = duringInterval(
    +      startWindow = eventStarts(a = -Inf, b = 0, index = "startDate")
    +    )
    +  )
    +)
    +# wrap this in a group withAll
    +

    Further to this point, a single attrition rule is a group. +The example of noT1d above would be a single rule in the +cohort attrition. This is how we would apply it:

    +
    +cohort <- cohort(
    +  entry = entry(
    +    # index event....
    +  ),
    +  attrition = attrition(
    +    'noT1d' = withAll(
    +      exactly(
    +        x = 0, 
    +        # query for t1d occurrence to exclude patients
    +        query = conditionOccurrence(t1dConceptSet), 
    +        aperture = duringInterval(
    +          startWindow = eventStarts(a = -Inf, b = 0, index = "startDate")
    +        )
    +      )
    +    )
    +  ),
    +  exit = exit(
    +    #cohort exit....
    +  )
    +)
    +

    2) Groups may contain groups

    +

    A group may contain more groups as part of the same object. We saw +this in the PheKB T2D example where one path required an abnormal lab. +In the definition there are 3 types of abnormal labs: random glucose, +fasting glucose and HbA1c. Any one of these three could be abnormal as +part of path 1 of the case algorithm. To build this we need a group +within a group.

    +
    +# Path 1: 0 T2Dx + 1 T2Rx + 1 abLab
    +path1 <- withAll(
    +  exactly(0, 
    +          t2d, 
    +          duringInterval(startWindow = eventStarts(-Inf, 0))
    +  ),
    +  atLeast(1, 
    +          t2dDrug, 
    +          duringInterval(startWindow = eventStarts(-Inf, 0))
    +  ),
    +  withAny(
    +    atLeast(1, 
    +            abLabHb, 
    +            duringInterval(startWindow = eventStarts(-Inf, 0))
    +    ),
    +    atLeast(1, 
    +            abLabRan, 
    +            duringInterval(startWindow = eventStarts(-Inf, 0))
    +    ),
    +    atLeast(1, 
    +            abLabFast, 
    +            duringInterval(startWindow = eventStarts(-Inf, 0))
    +    )
    +  )
    +)
    +

    3) Nested criteria are groups

    +

    Previously we mentioned a special kind of attribute called a nested +criteria (also known via ATLAS as a correlated criteria). The idea of a +nested criteria is that the index event is based on a particular concept +set expression as opposed to the entry event of the cohort definition. +For example, we want to build a cohort based on a hospitalization due to +heart failure. In this case a person is counted in the cohort if they +have first an inpatient visit given that a heart failure (HF) diagnosis +has occurred around the time of the inpatient visit. In +Capr a nested attribute uses the same syntax as a +group with a prefix of nested-, as shown in the +example below. The enumeration of the criteria is now indexed +based on the inpatient visit rather than the entry event of the cohort +definition.

    +
    +ipCse <- cs(descendants(9201, 9203, 262), name = "visit")
    +hf <- cs(descendants(316139), name = "heart failure")
    +
    +query <- visit(
    +  ipCse, #index
    +  #nested attribute
    +  nestedWithAll(
    +    atLeast(1,
    +            conditionOccurrence(hf),
    +            duringInterval(
    +              startWindow = eventStarts(0, Inf, index = "startDate"),
    +              endWindow = eventStarts(-Inf, 0, index = "endDate")
    +            )
    +    )
    +  )
    +)
    +
    +
    +
    +

    Concluding Remarks +

    +

    For more information on sub-components of a cohort definition via +circe-be, users should watch the videos created by +Chris Knoll outlining these ideas. while these videos utilize ATLAS, +Capr follows the same principles.

    +
    +
    + + + +
    + + + +
    + +
    +

    +

    Site built with pkgdown 2.0.7.

    +
    + +
    +
    + + + + + + + + diff --git a/docs/articles/capr_templates.html b/docs/articles/capr_templates.html index 62576346..94baaa8c 100644 --- a/docs/articles/capr_templates.html +++ b/docs/articles/capr_templates.html @@ -40,7 +40,7 @@ Capr - 2.0.4 + 2.0.5 @@ -62,6 +62,9 @@
  • Capr Design Guide and Roadmap
  • +
  • + Capr Objects +
  • Capr for Templating Cohort Definitions
  • @@ -110,8 +113,6 @@

    Capr for Templating Cohort Definitions

    -

    Building a Template

    @@ -126,11 +127,11 @@

    Building a Template
    +
     cvEvents <- function(conceptSet) {
       cd <- cohort(
         entry = entry(
    -      condition(conceptSet),
    +      conditionOccurrence(conceptSet),
           observationWindow = continuousObservation(365, 0)
         ),
         exit = exit(
    @@ -147,7 +148,7 @@ 

    Building a TemplateAthena, I look up the OMOP concept ids for the concepts of interest. With these concept ids, I can create a concept set for each cardiovascular event

    -
    +
     afib <- cs(descendants(313217), name = "Atrial Fibrillation")
     stroke <- cs(descendants(4310996), name = "Ischemic Stroke")
     hyp <- cs(descendants(320128), name = "Hypertension")
    @@ -160,7 +161,7 @@ 

    Building a Template
    +
     cvSet <- list(afib, stroke, hyp, mi, hf)
     cvCohorts <- purrr::map(cvSet, ~cvEvents(.x))

    @@ -171,13 +172,13 @@

    Improving the Template -
    +
     cvEvents2 <- function(conceptSet) {
       
       #Capr template logic
       cd <- cohort(
         entry = entry(
    -      condition(conceptSet),
    +      conditionOccurrence(conceptSet),
           observationWindow = continuousObservation(365, 0)
         ),
         exit = exit(
    @@ -204,7 +205,7 @@ 

    Building templates from concept se .csv or .json file that we can use towards the cohort template. We update our Capr template function to handle the import of a concept set, as shown below.

    -
    +
     cvEvents3 <- function(file) {
       
       # get file name
    @@ -216,7 +217,7 @@ 

    Building templates from concept se #Capr template logic cd <- cohort( entry = entry( - condition(conceptSet), + conditionOccurrence(conceptSet), observationWindow = continuousObservation(365, 0) ), exit = exit( @@ -237,137 +238,10 @@

    Building templates from concept se Luckily, we have a concept set from ATLAS that we used in a previous study that has this already detailed. We can import the csv file for this concept set and apply it to the Capr template.

    -
    +
     miPath <- fs::path_package("Capr", "extdata/acuteMI.csv") 
     miCohort <- cvEvents3(miPath)
    -cat(miCohort)
    -#> {
    -#>   "ConceptSets": [
    -#>     {
    -#>       "id": 0,
    -#>       "name": "Inpatient or ER visit",
    -#>       "expression": {
    -#>         "items": [
    -#>           {
    -#>             "concept": {
    -#>               "CONCEPT_ID": 262,
    -#>               "CONCEPT_NAME": "Emergency Room and Inpatient Visit",
    -#>               "STANDARD_CONCEPT": "S",
    -#>               "STANDARD_CONCEPT_CAPTION": "",
    -#>               "INVALID_REASON": "",
    -#>               "INVALID_REASON_CAPTION": "",
    -#>               "CONCEPT_CODE": "ERIP",
    -#>               "DOMAIN_ID": "Visit",
    -#>               "VOCABULARY_ID": "Visit",
    -#>               "CONCEPT_CLASS_ID": ""
    -#>             },
    -#>             "isExcluded": false,
    -#>             "includeDescendants": true,
    -#>             "includeMapped": false
    -#>           },
    -#>           {
    -#>             "concept": {
    -#>               "CONCEPT_ID": 9203,
    -#>               "CONCEPT_NAME": "Emergency Room Visit",
    -#>               "STANDARD_CONCEPT": "S",
    -#>               "STANDARD_CONCEPT_CAPTION": "",
    -#>               "INVALID_REASON": "",
    -#>               "INVALID_REASON_CAPTION": "",
    -#>               "CONCEPT_CODE": "ER",
    -#>               "DOMAIN_ID": "Visit",
    -#>               "VOCABULARY_ID": "Visit",
    -#>               "CONCEPT_CLASS_ID": ""
    -#>             },
    -#>             "isExcluded": false,
    -#>             "includeDescendants": true,
    -#>             "includeMapped": false
    -#>           },
    -#>           {
    -#>             "concept": {
    -#>               "CONCEPT_ID": 9201,
    -#>               "CONCEPT_NAME": "Inpatient Visit",
    -#>               "STANDARD_CONCEPT": "S",
    -#>               "STANDARD_CONCEPT_CAPTION": "",
    -#>               "INVALID_REASON": "",
    -#>               "INVALID_REASON_CAPTION": "",
    -#>               "CONCEPT_CODE": "IP",
    -#>               "DOMAIN_ID": "Visit",
    -#>               "VOCABULARY_ID": "Visit",
    -#>               "CONCEPT_CLASS_ID": ""
    -#>             },
    -#>             "isExcluded": false,
    -#>             "includeDescendants": true,
    -#>             "includeMapped": false
    -#>           },
    -#>           {
    -#>             "concept": {
    -#>               "CONCEPT_ID": 4329847,
    -#>               "CONCEPT_NAME": "Myocardial infarction",
    -#>               "STANDARD_CONCEPT": "S",
    -#>               "STANDARD_CONCEPT_CAPTION": "",
    -#>               "INVALID_REASON": "",
    -#>               "INVALID_REASON_CAPTION": "",
    -#>               "CONCEPT_CODE": "22298006",
    -#>               "DOMAIN_ID": "Condition",
    -#>               "VOCABULARY_ID": "SNOMED",
    -#>               "CONCEPT_CLASS_ID": ""
    -#>             },
    -#>             "isExcluded": false,
    -#>             "includeDescendants": true,
    -#>             "includeMapped": false
    -#>           },
    -#>           {
    -#>             "concept": {
    -#>               "CONCEPT_ID": 314666,
    -#>               "CONCEPT_NAME": "Old myocardial infarction",
    -#>               "STANDARD_CONCEPT": "S",
    -#>               "STANDARD_CONCEPT_CAPTION": "",
    -#>               "INVALID_REASON": "",
    -#>               "INVALID_REASON_CAPTION": "",
    -#>               "CONCEPT_CODE": "1755008",
    -#>               "DOMAIN_ID": "Condition",
    -#>               "VOCABULARY_ID": "SNOMED",
    -#>               "CONCEPT_CLASS_ID": ""
    -#>             },
    -#>             "isExcluded": true,
    -#>             "includeDescendants": true,
    -#>             "includeMapped": false
    -#>           }
    -#>         ]
    -#>       }
    -#>     }
    -#>   ],
    -#>   "PrimaryCriteria": {
    -#>     "CriteriaList": [
    -#>       {
    -#>         "ConditionOccurrence": {
    -#>           "CodesetId": 0
    -#>         }
    -#>       }
    -#>     ],
    -#>     "ObservationWindow": {
    -#>       "PriorDays": 365,
    -#>       "PostDays": 0
    -#>     },
    -#>     "PrimaryCriteriaLimit": {
    -#>       "Type": "First"
    -#>     }
    -#>   },
    -#>   "QualifiedLimit": {
    -#>     "Type": "First"
    -#>   },
    -#>   "ExpressionLimit": {
    -#>     "Type": "First"
    -#>   },
    -#>   "InclusionRules": [],
    -#>   "CensoringCriteria": [],
    -#>   "CollapseSettings": {
    -#>     "CollapseType": "ERA",
    -#>     "EraPad": 0
    -#>   },
    -#>   "CensorWindow": {},
    -#>   "cdmVersionRange": ">=5.0.0"
    -#> }
    +cat(miCohort)

    Saving Capr cohorts @@ -376,7 +250,7 @@

    Saving Capr cohortsreadr::write_file or the base R equivalent.

    -
    +
     
     outputPath <- fs::path(here::here("cohorts"), "miCohort", ext = "json")
     readr::write_file(miCohort, file = outputPath)
    diff --git a/docs/articles/images/aperture1.png b/docs/articles/images/aperture1.png new file mode 100644 index 00000000..b48c043d Binary files /dev/null and b/docs/articles/images/aperture1.png differ diff --git a/docs/articles/images/aperture2.png b/docs/articles/images/aperture2.png new file mode 100644 index 00000000..568f2d3b Binary files /dev/null and b/docs/articles/images/aperture2.png differ diff --git a/docs/articles/images/aperture3.png b/docs/articles/images/aperture3.png new file mode 100644 index 00000000..ff21a0c2 Binary files /dev/null and b/docs/articles/images/aperture3.png differ diff --git a/docs/articles/images/aperture4.png b/docs/articles/images/aperture4.png new file mode 100644 index 00000000..372e0548 Binary files /dev/null and b/docs/articles/images/aperture4.png differ diff --git a/docs/articles/images/criteria_example.png b/docs/articles/images/criteria_example.png new file mode 100644 index 00000000..bb02c0b6 Binary files /dev/null and b/docs/articles/images/criteria_example.png differ diff --git a/docs/articles/index.html b/docs/articles/index.html index 917cd175..663a6675 100644 --- a/docs/articles/index.html +++ b/docs/articles/index.html @@ -17,7 +17,7 @@ Capr - 2.0.4 + 2.0.5
    @@ -37,6 +37,9 @@
  • Capr Design Guide and Roadmap
  • +
  • + Capr Objects +
  • Capr for Templating Cohort Definitions
  • @@ -79,6 +82,8 @@

    All vignettes

    Capr Design Guide and Roadmap
    +
    Capr Objects
    +
    Capr for Templating Cohort Definitions
    Cohort Definition Examples
    diff --git a/docs/authors.html b/docs/authors.html index f0fb78cb..532583b1 100644 --- a/docs/authors.html +++ b/docs/authors.html @@ -17,7 +17,7 @@ Capr - 2.0.4 + 2.0.5
    @@ -37,6 +37,9 @@
  • Capr Design Guide and Roadmap
  • +
  • + Capr Objects +
  • Capr for Templating Cohort Definitions
  • diff --git a/docs/index.html b/docs/index.html index 8f097fbb..6ccaf345 100644 --- a/docs/index.html +++ b/docs/index.html @@ -46,7 +46,7 @@ Capr - 2.0.4 + 2.0.5
    @@ -68,6 +68,9 @@
  • Capr Design Guide and Roadmap
  • +
  • + Capr Objects +
  • Capr for Templating Cohort Definitions
  • @@ -124,249 +127,28 @@

    Introduction

    Installation

    -

    Capr can be installed via:

    -
    -# install.packages("Capr")

    Users can install the current development version of Capr from GitHub with:

    -
    +
     # install.packages("devtools")
     devtools::install_github("ohdsi/Capr")
    -

    How to Use -

    -
    -

    Examples -

    -

    Capr uses many defaults that match the defaults in Atlas. Creating a simple cohort is a single line of code. As an example we will define a cohort of new users of diclofenac described in the Book of OHDSI.

    -
    -

    Simple diclofenac cohort -

    -
    -library(Capr)
    -
    -# Define concepts sets with cs()
    -diclofenac <- cs(descendants(1124300))
    -
    -ch <- cohort(
    -  entry = entry(drugEra(diclofenac))
    -)
    -
    -ch
    -#> Formal class 'Cohort' [package "Capr"] with 4 slots
    -#>   ..@ entry    :Formal class 'CohortEntry' [package "Capr"] with 5 slots
    -#>   ..@ attrition:Formal class 'CohortAttrition' [package "Capr"] with 2 slots
    -#>   ..@ exit     :Formal class 'CohortExit' [package "Capr"] with 2 slots
    -#>   ..@ era      :Formal class 'CohortEra' [package "Capr"] with 3 slots
    -
    -
    -

    Adding more complexity -

    -

    We can make more complex cohorts by adding a window of continuous observation and a custom cohort exit. The following information was added to the diclofenac cohort:

    -
      -
    • Ages 16 or older
    • -
    • With at least 365 days of continuous observation prior to exposure
    • -
    • With cohort exit defined as discontinuation of exposure (allowing for a 30-day gap)
    • -
    -
    -diclofenac <- cs(descendants(1124300))
    -
    -ch <- cohort(
    -  entry = entry(drugEra(diclofenac, age(gte(16))),
    -                observationWindow = continuousObservation(-365L, 0L)),
    -  exit = exit(drugExit(diclofenac))
    -)
    -
    -ch
    -#> Formal class 'Cohort' [package "Capr"] with 4 slots
    -#>   ..@ entry    :Formal class 'CohortEntry' [package "Capr"] with 5 slots
    -#>   ..@ attrition:Formal class 'CohortAttrition' [package "Capr"] with 2 slots
    -#>   ..@ exit     :Formal class 'CohortExit' [package "Capr"] with 2 slots
    -#>   ..@ era      :Formal class 'CohortEra' [package "Capr"] with 3 slots
    -
    -
    -

    Adding cohort attrition -

    -

    Users can also add attrition to the cohort by specifying inclusion and exclusion criteria to modify the cohort entry. The following exclusion criteria were added to the diclofenac cohort:

    -
      -
    • Without prior exposure to any NSAID (Non-Steroidal Anti-Inflammatory Drug)
    • -
    • Without prior diagnosis of cancer
    • -
    -
    -diclofenac <- cs(descendants(1124300), name = "diclofenac")
    -nsaid <- cs(descendants(21603933), name = "nsaid")
    -cancer <- cs(descendants(443392), name = "cancer")
    -
    -ch <- cohort(
    -  entry = entry(drugEra(diclofenac, age(gte(16))),
    -                observationWindow = continuousObservation(-365L, 0L)),
    -  attrition = attrition(
    -    withAll(
    -      exactly(0, drug(nsaid), eventStarts(-Inf, 0, index = "startDate")),
    -      exactly(0, condition(cancer), eventStarts(-Inf, 0, index = "startDate"))
    -    )
    -  ),
    -  exit = exit(
    -    endStrategy = drugExit(diclofenac, persistenceWindow = 30)
    -    )
    -)
    -
    -ch
    -#> Formal class 'Cohort' [package "Capr"] with 4 slots
    -#>   ..@ entry    :Formal class 'CohortEntry' [package "Capr"] with 5 slots
    -#>   ..@ attrition:Formal class 'CohortAttrition' [package "Capr"] with 2 slots
    -#>   ..@ exit     :Formal class 'CohortExit' [package "Capr"] with 2 slots
    -#>   ..@ era      :Formal class 'CohortEra' [package "Capr"] with 3 slots
    -
    -
    -
    -

    Save cohort as JSON -

    -

    OHDSI standard cohorts are represented as json files and can be copy and pasted into Atlas.

    -
    -
    -path <- file.path(tempdir(), "diclofenacCohort.json")
    -
    -writeCohort(ch, path)
    -
    -cat(substr(readr::read_file(path), 1, 100))
    -#> {
    -#>   "ConceptSets": [
    -#>     {
    -#>       "id": 0,
    -#>       "name": "diclofenac",
    -#>       "expression": {
    -#> 
    -
    -

    Fill in missing concept set details -

    -

    Users can build valid cohorts with minimal concept information, only supplying a concept id and name. The example below shows the minimal concept set input for Capr.

    -
    -
    -diclofenac <- cs(descendants(1124300), name = "diclofenac")
    -
    -cat(as.json(diclofenac))
    -#> {
    -#>   "id": "11d012608fce118593830a3039042e56",
    -#>   "name": "diclofenac",
    -#>   "expression": {
    -#>     "items": [
    -#>       {
    -#>         "concept": {
    -#>           "CONCEPT_ID": 1124300,
    -#>           "CONCEPT_NAME": "",
    -#>           "STANDARD_CONCEPT": "",
    -#>           "STANDARD_CONCEPT_CAPTION": "",
    -#>           "INVALID_REASON": "",
    -#>           "INVALID_REASON_CAPTION": "",
    -#>           "CONCEPT_CODE": "",
    -#>           "DOMAIN_ID": "",
    -#>           "VOCABULARY_ID": "",
    -#>           "CONCEPT_CLASS_ID": ""
    -#>         },
    -#>         "isExcluded": false,
    -#>         "includeDescendants": true,
    -#>         "includeMapped": false
    -#>       }
    -#>     ]
    -#>   }
    -#> }
    -

    However, when saving cohorts it is helpful to fill in the concept details. This requires a live connection to an OMOP CDM database that includes the vocabularies used in the cohort definition.

    -
    -con <- DatabaseConnector::connect(Eunomia::getEunomiaConnectionDetails())
    -diclofenac <- getConceptSetDetails(diclofenac, con, vocabularyDatabaseSchema = "main")
    -cat(as.json(diclofenac))
    -#> {
    -#>   "id": "11d012608fce118593830a3039042e56",
    -#>   "name": "diclofenac",
    -#>   "expression": {
    -#>     "items": [
    -#>       {
    -#>         "concept": {
    -#>           "CONCEPT_ID": 1124300,
    -#>           "CONCEPT_NAME": "Diclofenac",
    -#>           "STANDARD_CONCEPT": "S",
    -#>           "STANDARD_CONCEPT_CAPTION": "Standard",
    -#>           "INVALID_REASON": "V",
    -#>           "INVALID_REASON_CAPTION": "Valid",
    -#>           "CONCEPT_CODE": "3355",
    -#>           "DOMAIN_ID": "Drug",
    -#>           "VOCABULARY_ID": "RxNorm",
    -#>           "CONCEPT_CLASS_ID": "Ingredient"
    -#>         },
    -#>         "isExcluded": false,
    -#>         "includeDescendants": true,
    -#>         "includeMapped": false
    -#>       }
    -#>     ]
    -#>   }
    -#> }
    -
    -
    -

    Generating Capr Cohorts -

    -

    Once a Capr cohort has been constructed, the user can generate this cohort definition on an OMOP CDM connection. It is suggested to use CohortGenerator and CirceR to generate Capr cohorts on a database.

    -
    -
    -
    -

    Building Capr Templates -

    -

    A Capr cohort template is a function that always returns a Capr cohort. It can accept arguments that can be used to parameterize any part of a cohort definition. Capr cohort templates are the recommended approach for building large numbers of similar cohorts in R.

    -
    -
    -# A Capr cohort template is a function that returns a cohort
    -drugEraTemplate <- function(ingredientConceptId) {
    -  
    -  drugConceptSet <- cs(descendants(ingredientConceptId))
    -  
    -  cohort(
    -    entry = entry(drugEra(drugConceptSet, age(gte(16))),
    -                  observationWindow = continuousObservation(-365L, 0L)),
    -    exit = exit(drugExit(drugConceptSet, persistenceWindow = 30))
    -  )
    -}
    -
    -
    -library(dplyr, warn.conflicts = FALSE)
    -
    -# create a cohort for every single ingredient
    -df <- DBI::dbGetQuery(con, 
    -                      "Select * from concept where concept_class_id = 'Ingredient'") %>% 
    -  tibble() %>% 
    -  select(concept_id, concept_name) %>% 
    -  mutate(capr_cohort = purrr::map(concept_id, drugEraTemplate)) %>% 
    -  mutate(cohort_json = purrr::map_chr(capr_cohort, as.json))
    -
    -df
    -#> # A tibble: 91 × 4
    -#>    concept_id concept_name    capr_cohort cohort_json                           
    -#>         <dbl> <chr>           <list>      <chr>                                 
    -#>  1    1557272 Alendronate     <Cohort>    "{\n  \"ConceptSets\": [\n    {\n    …
    -#>  2     708298 Midazolam       <Cohort>    "{\n  \"ConceptSets\": [\n    {\n    …
    -#>  3     701322 Memantine       <Cohort>    "{\n  \"ConceptSets\": [\n    {\n    …
    -#>  4     723013 Diazepam        <Cohort>    "{\n  \"ConceptSets\": [\n    {\n    …
    -#>  5    1129625 Diphenhydramine <Cohort>    "{\n  \"ConceptSets\": [\n    {\n    …
    -#>  6    1149196 Cetirizine      <Cohort>    "{\n  \"ConceptSets\": [\n    {\n    …
    -#>  7    1149380 fluticasone     <Cohort>    "{\n  \"ConceptSets\": [\n    {\n    …
    -#>  8    1150770 Astemizole      <Cohort>    "{\n  \"ConceptSets\": [\n    {\n    …
    -#>  9    1150836 Terfenadine     <Cohort>    "{\n  \"ConceptSets\": [\n    {\n    …
    -#> 10    1124300 Diclofenac      <Cohort>    "{\n  \"ConceptSets\": [\n    {\n    …
    -#> # … with 81 more rows
    -

    The capr_cohort column of the dataframe is a list of Capr cohort object. The cohort_json column contains the json specifications for each cohort.

    -
    -DatabaseConnector::disconnect(con)
    -
    -
    -

    User Documentation

    Documentation can be found on the package website.

    +

    PDF versions of the documentation are also available:

    diff --git a/docs/news/index.html b/docs/news/index.html index f602e6bd..19bf366f 100644 --- a/docs/news/index.html +++ b/docs/news/index.html @@ -17,7 +17,7 @@ Capr - 2.0.4 + 2.0.5

    @@ -37,6 +37,9 @@
  • Capr Design Guide and Roadmap
  • +
  • + Capr Objects +
  • Capr for Templating Cohort Definitions
  • @@ -72,6 +75,13 @@

    Changelog

    Source: NEWS.md
    +
    + +
    • change query functions to match known syntax (i.e. drug => drugExposure, condition => conditionOccurrence)
    • +
    • require a name for cs() +
    • +
    • improve documentation (add vignette for query, count and group)
    • +
    • hot fix add procedure occurrence into query
    • diff --git a/docs/pkgdown.yml b/docs/pkgdown.yml index 21d2d712..ce97bf9f 100644 --- a/docs/pkgdown.yml +++ b/docs/pkgdown.yml @@ -4,8 +4,9 @@ pkgdown_sha: ~ articles: Capr-conceptSets: Capr-conceptSets.html capr_design: capr_design.html + capr_objects: capr_objects.html capr_templates: capr_templates.html Examples: Examples.html Using-Capr: Using-Capr.html -last_built: 2023-06-13T19:42Z +last_built: 2023-07-03T17:28Z diff --git a/docs/reference/Capr-package.html b/docs/reference/Capr-package.html index 478e324a..92efe96b 100644 --- a/docs/reference/Capr-package.html +++ b/docs/reference/Capr-package.html @@ -18,7 +18,7 @@ Capr - 2.0.4 + 2.0.5
    @@ -38,6 +38,9 @@
  • Capr Design Guide and Roadmap
  • +
  • + Capr Objects +
  • Capr for Templating Cohort Definitions
  • diff --git a/docs/reference/CensoringCriteria-class.html b/docs/reference/CensoringCriteria-class.html index bc079fa7..083d2a9a 100644 --- a/docs/reference/CensoringCriteria-class.html +++ b/docs/reference/CensoringCriteria-class.html @@ -19,7 +19,7 @@ Capr - 2.0.4 + 2.0.5

    @@ -39,6 +39,9 @@
  • Capr Design Guide and Roadmap
  • +
  • + Capr Objects +
  • Capr for Templating Cohort Definitions
  • diff --git a/docs/reference/Concept-class.html b/docs/reference/Concept-class.html index 5edfd275..86ba0cd3 100644 --- a/docs/reference/Concept-class.html +++ b/docs/reference/Concept-class.html @@ -17,7 +17,7 @@ Capr - 2.0.4 + 2.0.5

    @@ -37,6 +37,9 @@
  • Capr Design Guide and Roadmap
  • +
  • + Capr Objects +
  • Capr for Templating Cohort Definitions
  • diff --git a/docs/reference/ConceptAttribute-class.html b/docs/reference/ConceptAttribute-class.html index a6a951a1..b0ff0359 100644 --- a/docs/reference/ConceptAttribute-class.html +++ b/docs/reference/ConceptAttribute-class.html @@ -17,7 +17,7 @@ Capr - 2.0.4 + 2.0.5

    @@ -37,6 +37,9 @@
  • Capr Design Guide and Roadmap
  • +
  • + Capr Objects +
  • Capr for Templating Cohort Definitions
  • diff --git a/docs/reference/ConceptSet-class.html b/docs/reference/ConceptSet-class.html index 6fc21314..7e02ddb3 100644 --- a/docs/reference/ConceptSet-class.html +++ b/docs/reference/ConceptSet-class.html @@ -17,7 +17,7 @@ Capr - 2.0.4 + 2.0.5 @@ -37,6 +37,9 @@
  • Capr Design Guide and Roadmap
  • +
  • + Capr Objects +
  • Capr for Templating Cohort Definitions
  • diff --git a/docs/reference/ConceptSetItem-class.html b/docs/reference/ConceptSetItem-class.html index d2d09f83..8534d96e 100644 --- a/docs/reference/ConceptSetItem-class.html +++ b/docs/reference/ConceptSetItem-class.html @@ -17,7 +17,7 @@ Capr - 2.0.4 + 2.0.5 @@ -37,6 +37,9 @@
  • Capr Design Guide and Roadmap
  • +
  • + Capr Objects +
  • Capr for Templating Cohort Definitions
  • diff --git a/docs/reference/Criteria-class.html b/docs/reference/Criteria-class.html index c5ad737f..b948650a 100644 --- a/docs/reference/Criteria-class.html +++ b/docs/reference/Criteria-class.html @@ -17,7 +17,7 @@ Capr - 2.0.4 + 2.0.5 @@ -37,6 +37,9 @@
  • Capr Design Guide and Roadmap
  • +
  • + Capr Objects +
  • Capr for Templating Cohort Definitions
  • diff --git a/docs/reference/DrugExposureExit-class.html b/docs/reference/DrugExposureExit-class.html index c3d7cdd5..4e6e19b8 100644 --- a/docs/reference/DrugExposureExit-class.html +++ b/docs/reference/DrugExposureExit-class.html @@ -24,7 +24,7 @@ Capr - 2.0.4 + 2.0.5 @@ -44,6 +44,9 @@
  • Capr Design Guide and Roadmap
  • +
  • + Capr Objects +
  • Capr for Templating Cohort Definitions
  • diff --git a/docs/reference/Endpoint-class.html b/docs/reference/Endpoint-class.html index d5668a8b..b214600f 100644 --- a/docs/reference/Endpoint-class.html +++ b/docs/reference/Endpoint-class.html @@ -17,7 +17,7 @@ Capr - 2.0.4 + 2.0.5 @@ -37,6 +37,9 @@
  • Capr Design Guide and Roadmap
  • +
  • + Capr Objects +
  • Capr for Templating Cohort Definitions
  • diff --git a/docs/reference/EventAperture-class.html b/docs/reference/EventAperture-class.html index bc61612b..4506d540 100644 --- a/docs/reference/EventAperture-class.html +++ b/docs/reference/EventAperture-class.html @@ -17,7 +17,7 @@ Capr - 2.0.4 + 2.0.5 @@ -37,6 +37,9 @@
  • Capr Design Guide and Roadmap
  • +
  • + Capr Objects +
  • Capr for Templating Cohort Definitions
  • diff --git a/docs/reference/EventWindow-class.html b/docs/reference/EventWindow-class.html index 109ae795..60af8125 100644 --- a/docs/reference/EventWindow-class.html +++ b/docs/reference/EventWindow-class.html @@ -17,7 +17,7 @@ Capr - 2.0.4 + 2.0.5 @@ -37,6 +37,9 @@
  • Capr Design Guide and Roadmap
  • +
  • + Capr Objects +
  • Capr for Templating Cohort Definitions
  • diff --git a/docs/reference/FixedDurationExit-class.html b/docs/reference/FixedDurationExit-class.html index 8759f784..43d03c04 100644 --- a/docs/reference/FixedDurationExit-class.html +++ b/docs/reference/FixedDurationExit-class.html @@ -24,7 +24,7 @@ Capr - 2.0.4 + 2.0.5 @@ -44,6 +44,9 @@
  • Capr Design Guide and Roadmap
  • +
  • + Capr Objects +
  • Capr for Templating Cohort Definitions
  • diff --git a/docs/reference/Group-class.html b/docs/reference/Group-class.html index 71a67fe7..477e712a 100644 --- a/docs/reference/Group-class.html +++ b/docs/reference/Group-class.html @@ -17,7 +17,7 @@ Capr - 2.0.4 + 2.0.5 @@ -37,6 +37,9 @@
  • Capr Design Guide and Roadmap
  • +
  • + Capr Objects +
  • Capr for Templating Cohort Definitions
  • diff --git a/docs/reference/LogicAttribute-class.html b/docs/reference/LogicAttribute-class.html index 700524fc..a4d9b455 100644 --- a/docs/reference/LogicAttribute-class.html +++ b/docs/reference/LogicAttribute-class.html @@ -17,7 +17,7 @@ Capr - 2.0.4 + 2.0.5 @@ -37,6 +37,9 @@
  • Capr Design Guide and Roadmap
  • +
  • + Capr Objects +
  • Capr for Templating Cohort Definitions
  • diff --git a/docs/reference/ObservationExit-class.html b/docs/reference/ObservationExit-class.html index 0169e4bf..b6dcc1d6 100644 --- a/docs/reference/ObservationExit-class.html +++ b/docs/reference/ObservationExit-class.html @@ -17,7 +17,7 @@ Capr - 2.0.4 + 2.0.5 @@ -37,6 +37,9 @@
  • Capr Design Guide and Roadmap
  • +
  • + Capr Objects +
  • Capr for Templating Cohort Definitions
  • diff --git a/docs/reference/ObservationWindow-class.html b/docs/reference/ObservationWindow-class.html index ccd900b7..632359d9 100644 --- a/docs/reference/ObservationWindow-class.html +++ b/docs/reference/ObservationWindow-class.html @@ -18,7 +18,7 @@ Capr - 2.0.4 + 2.0.5 @@ -38,6 +38,9 @@
  • Capr Design Guide and Roadmap
  • +
  • + Capr Objects +
  • Capr for Templating Cohort Definitions
  • diff --git a/docs/reference/Occurrence-class.html b/docs/reference/Occurrence-class.html index 28e25b2a..ab9a8031 100644 --- a/docs/reference/Occurrence-class.html +++ b/docs/reference/Occurrence-class.html @@ -18,7 +18,7 @@ Capr - 2.0.4 + 2.0.5 @@ -38,6 +38,9 @@
  • Capr Design Guide and Roadmap
  • +
  • + Capr Objects +
  • Capr for Templating Cohort Definitions
  • diff --git a/docs/reference/Query-class.html b/docs/reference/Query-class.html index 49080826..44d4b4df 100644 --- a/docs/reference/Query-class.html +++ b/docs/reference/Query-class.html @@ -18,7 +18,7 @@ Capr - 2.0.4 + 2.0.5 @@ -38,6 +38,9 @@
  • Capr Design Guide and Roadmap
  • +
  • + Capr Objects +
  • Capr for Templating Cohort Definitions
  • diff --git a/docs/reference/age.html b/docs/reference/age.html index 5bacebf6..a77c2e09 100644 --- a/docs/reference/age.html +++ b/docs/reference/age.html @@ -17,7 +17,7 @@ Capr - 2.0.4 + 2.0.5 @@ -37,6 +37,9 @@
  • Capr Design Guide and Roadmap
  • +
  • + Capr Objects +
  • Capr for Templating Cohort Definitions
  • diff --git a/docs/reference/as.data.frame-ConceptSet-method.html b/docs/reference/as.data.frame-ConceptSet-method.html index 99b02adb..231465da 100644 --- a/docs/reference/as.data.frame-ConceptSet-method.html +++ b/docs/reference/as.data.frame-ConceptSet-method.html @@ -17,7 +17,7 @@ Capr - 2.0.4 + 2.0.5 @@ -37,6 +37,9 @@
  • Capr Design Guide and Roadmap
  • +
  • + Capr Objects +
  • Capr for Templating Cohort Definitions
  • diff --git a/docs/reference/as.json.html b/docs/reference/as.json.html index 0816fb0d..6bfabb7f 100644 --- a/docs/reference/as.json.html +++ b/docs/reference/as.json.html @@ -17,7 +17,7 @@ Capr - 2.0.4 + 2.0.5 @@ -37,6 +37,9 @@
  • Capr Design Guide and Roadmap
  • +
  • + Capr Objects +
  • Capr for Templating Cohort Definitions
  • diff --git a/docs/reference/atLeast.html b/docs/reference/atLeast.html index 43b09f91..cc885191 100644 --- a/docs/reference/atLeast.html +++ b/docs/reference/atLeast.html @@ -17,7 +17,7 @@ Capr - 2.0.4 + 2.0.5 @@ -37,6 +37,9 @@
  • Capr Design Guide and Roadmap
  • +
  • + Capr Objects +
  • Capr for Templating Cohort Definitions
  • diff --git a/docs/reference/atMost.html b/docs/reference/atMost.html index f54cf180..f336476f 100644 --- a/docs/reference/atMost.html +++ b/docs/reference/atMost.html @@ -17,7 +17,7 @@ Capr - 2.0.4 + 2.0.5 @@ -37,6 +37,9 @@
  • Capr Design Guide and Roadmap
  • +
  • + Capr Objects +
  • Capr for Templating Cohort Definitions
  • diff --git a/docs/reference/attributes.html b/docs/reference/attributes.html index 2dd6d9ad..2616ec1d 100644 --- a/docs/reference/attributes.html +++ b/docs/reference/attributes.html @@ -18,7 +18,7 @@ Capr - 2.0.4 + 2.0.5 @@ -38,6 +38,9 @@
  • Capr Design Guide and Roadmap
  • +
  • + Capr Objects +
  • Capr for Templating Cohort Definitions
  • @@ -106,12 +109,12 @@

    Examples

    if (FALSE) {
     # Create a cohort of males with Type 1 diabetes
     t1dm <- cs(descendants(201254, 435216, 40484648))
    -t1dm_males <- cohort(condition(t1dm, male()))
    +t1dm_males <- cohort(condition(t1dm, male()))
     }
     if (FALSE) {
     # Create a cohort of males with Type 1 diabetes
     t1dm <- cs(descendants(201254, 435216, 40484648))
    -t1dm_females <- cohort(condition(t1dm, female()))
    +t1dm_females <- cohort(condition(t1dm, female()))
     }
     
    diff --git a/docs/reference/attrition.html b/docs/reference/attrition.html index 8116f0ca..1783bd59 100644 --- a/docs/reference/attrition.html +++ b/docs/reference/attrition.html @@ -17,7 +17,7 @@ Capr - 2.0.4 + 2.0.5 @@ -37,6 +37,9 @@
  • Capr Design Guide and Roadmap
  • +
  • + Capr Objects +
  • Capr for Templating Cohort Definitions
  • diff --git a/docs/reference/bt.html b/docs/reference/bt.html index 5e599b39..b1a6265f 100644 --- a/docs/reference/bt.html +++ b/docs/reference/bt.html @@ -17,7 +17,7 @@ Capr - 2.0.4 + 2.0.5 @@ -37,6 +37,9 @@
  • Capr Design Guide and Roadmap
  • +
  • + Capr Objects +
  • Capr for Templating Cohort Definitions
  • diff --git a/docs/reference/censoringEvents.html b/docs/reference/censoringEvents.html index 2a3660cb..42dda73a 100644 --- a/docs/reference/censoringEvents.html +++ b/docs/reference/censoringEvents.html @@ -17,7 +17,7 @@ Capr - 2.0.4 + 2.0.5 @@ -37,6 +37,9 @@
  • Capr Design Guide and Roadmap
  • +
  • + Capr Objects +
  • Capr for Templating Cohort Definitions
  • diff --git a/docs/reference/cohort.html b/docs/reference/cohort.html index c1800ddf..cf68c152 100644 --- a/docs/reference/cohort.html +++ b/docs/reference/cohort.html @@ -17,7 +17,7 @@ Capr - 2.0.4 + 2.0.5 @@ -37,6 +37,9 @@
  • Capr Design Guide and Roadmap
  • +
  • + Capr Objects +
  • Capr for Templating Cohort Definitions
  • diff --git a/docs/reference/compile.Cohort.html b/docs/reference/compile.Cohort.html index 1bfff1f3..0cc94f52 100644 --- a/docs/reference/compile.Cohort.html +++ b/docs/reference/compile.Cohort.html @@ -17,7 +17,7 @@ Capr - 2.0.4 + 2.0.5 @@ -37,6 +37,9 @@
  • Capr Design Guide and Roadmap
  • +
  • + Capr Objects +
  • Capr for Templating Cohort Definitions
  • @@ -102,7 +105,7 @@

    Value

    Examples

    if (FALSE) {
    -ch <- cohort(condition(cs(1,2)))
    +ch <- cohort(condition(cs(1,2)))
     compile(ch)
     }
     
    diff --git a/docs/reference/conditionEra.html b/docs/reference/conditionEra.html index 65431671..3b9ae67d 100644 --- a/docs/reference/conditionEra.html +++ b/docs/reference/conditionEra.html @@ -17,7 +17,7 @@ Capr - 2.0.4 + 2.0.5
    @@ -37,6 +37,9 @@
  • Capr Design Guide and Roadmap
  • +
  • + Capr Objects +
  • Capr for Templating Cohort Definitions
  • diff --git a/docs/reference/conditionOccurrence.html b/docs/reference/conditionOccurrence.html new file mode 100644 index 00000000..dad3f534 --- /dev/null +++ b/docs/reference/conditionOccurrence.html @@ -0,0 +1,127 @@ + +Query the condition domain — conditionOccurrence • Capr + + +
    +
    + + + +
    +
    + + +
    +

    Query the condition domain

    +
    + +
    +
    conditionOccurrence(conceptSet, ...)
    +
    + +
    +

    Arguments

    +
    conceptSet
    +

    A condition concept set

    + + +
    ...
    +

    optional attributes

    + +
    +
    +

    Value

    + + +

    A Capr Query

    +
    + +
    + +
    + + +
    + +
    +

    Site built with pkgdown 2.0.7.

    +
    + +
    + + + + + + + + diff --git a/docs/reference/continuousObservation.html b/docs/reference/continuousObservation.html index db4b9d7b..ae4d3620 100644 --- a/docs/reference/continuousObservation.html +++ b/docs/reference/continuousObservation.html @@ -17,7 +17,7 @@ Capr - 2.0.4 + 2.0.5 @@ -37,6 +37,9 @@
  • Capr Design Guide and Roadmap
  • +
  • + Capr Objects +
  • Capr for Templating Cohort Definitions
  • diff --git a/docs/reference/cs.html b/docs/reference/cs.html index 9625c3a8..175f1afa 100644 --- a/docs/reference/cs.html +++ b/docs/reference/cs.html @@ -20,7 +20,7 @@ Capr - 2.0.4 + 2.0.5 @@ -40,6 +40,9 @@
  • Capr Design Guide and Roadmap
  • +
  • + Capr Objects +
  • Capr for Templating Cohort Definitions
  • @@ -84,7 +87,7 @@

    Create a concept set

    -
    cs(..., name = "", id = NULL)
    +    
    cs(..., name, id = NULL)
     
     exclude(...)
     
    diff --git a/docs/reference/daysOfSupply.html b/docs/reference/daysOfSupply.html
    index db4db445..94219f52 100644
    --- a/docs/reference/daysOfSupply.html
    +++ b/docs/reference/daysOfSupply.html
    @@ -19,7 +19,7 @@
           
           
             Capr
    -        2.0.4
    +        2.0.5
           
         
    @@ -39,6 +39,9 @@
  • Capr Design Guide and Roadmap
  • +
  • + Capr Objects +
  • Capr for Templating Cohort Definitions
  • diff --git a/docs/reference/death.html b/docs/reference/death.html index e994d363..124f7be4 100644 --- a/docs/reference/death.html +++ b/docs/reference/death.html @@ -17,7 +17,7 @@ Capr - 2.0.4 + 2.0.5
    @@ -37,6 +37,9 @@
  • Capr Design Guide and Roadmap
  • +
  • + Capr Objects +
  • Capr for Templating Cohort Definitions
  • diff --git a/docs/reference/drugEra.html b/docs/reference/drugEra.html index de6af19a..740f7ec0 100644 --- a/docs/reference/drugEra.html +++ b/docs/reference/drugEra.html @@ -17,7 +17,7 @@ Capr - 2.0.4 + 2.0.5
    @@ -37,6 +37,9 @@
  • Capr Design Guide and Roadmap
  • +
  • + Capr Objects +
  • Capr for Templating Cohort Definitions
  • diff --git a/docs/reference/drugExit.html b/docs/reference/drugExit.html index 2a985d77..e827910f 100644 --- a/docs/reference/drugExit.html +++ b/docs/reference/drugExit.html @@ -17,7 +17,7 @@ Capr - 2.0.4 + 2.0.5 @@ -37,6 +37,9 @@
  • Capr Design Guide and Roadmap
  • +
  • + Capr Objects +
  • Capr for Templating Cohort Definitions
  • diff --git a/docs/reference/drugExposure.html b/docs/reference/drugExposure.html new file mode 100644 index 00000000..2cc4ed9f --- /dev/null +++ b/docs/reference/drugExposure.html @@ -0,0 +1,127 @@ + +Query the drug domain — drugExposure • Capr + + +
    +
    + + + +
    +
    + + +
    +

    Query the drug domain

    +
    + +
    +
    drugExposure(conceptSet, ...)
    +
    + +
    +

    Arguments

    +
    conceptSet
    +

    A drug concept set

    + + +
    ...
    +

    optional attributes

    + +
    +
    +

    Value

    + + +

    A Capr Query

    +
    + +
    + +
    + + +
    + +
    +

    Site built with pkgdown 2.0.7.

    +
    + +
    + + + + + + + + diff --git a/docs/reference/drugQuantity.html b/docs/reference/drugQuantity.html index 34be9a0b..5ae679fc 100644 --- a/docs/reference/drugQuantity.html +++ b/docs/reference/drugQuantity.html @@ -19,7 +19,7 @@ Capr - 2.0.4 + 2.0.5 @@ -39,6 +39,9 @@
  • Capr Design Guide and Roadmap
  • +
  • + Capr Objects +
  • Capr for Templating Cohort Definitions
  • diff --git a/docs/reference/drugRefills.html b/docs/reference/drugRefills.html index 01d33ba3..e94ede55 100644 --- a/docs/reference/drugRefills.html +++ b/docs/reference/drugRefills.html @@ -19,7 +19,7 @@ Capr - 2.0.4 + 2.0.5 @@ -39,6 +39,9 @@
  • Capr Design Guide and Roadmap
  • +
  • + Capr Objects +
  • Capr for Templating Cohort Definitions
  • diff --git a/docs/reference/duringInterval.html b/docs/reference/duringInterval.html index efdf5ff8..8c346b3b 100644 --- a/docs/reference/duringInterval.html +++ b/docs/reference/duringInterval.html @@ -20,7 +20,7 @@ Capr - 2.0.4 + 2.0.5 @@ -40,6 +40,9 @@
  • Capr Design Guide and Roadmap
  • +
  • + Capr Objects +
  • Capr for Templating Cohort Definitions
  • diff --git a/docs/reference/endDate.html b/docs/reference/endDate.html index 5a8fb36b..0ee00f7f 100644 --- a/docs/reference/endDate.html +++ b/docs/reference/endDate.html @@ -17,7 +17,7 @@ Capr - 2.0.4 + 2.0.5 @@ -37,6 +37,9 @@
  • Capr Design Guide and Roadmap
  • +
  • + Capr Objects +
  • Capr for Templating Cohort Definitions
  • diff --git a/docs/reference/entry.html b/docs/reference/entry.html index 1139d832..5f948479 100644 --- a/docs/reference/entry.html +++ b/docs/reference/entry.html @@ -17,7 +17,7 @@ Capr - 2.0.4 + 2.0.5 @@ -37,6 +37,9 @@
  • Capr Design Guide and Roadmap
  • +
  • + Capr Objects +
  • Capr for Templating Cohort Definitions
  • diff --git a/docs/reference/eq.html b/docs/reference/eq.html index d38490f8..02bb5529 100644 --- a/docs/reference/eq.html +++ b/docs/reference/eq.html @@ -17,7 +17,7 @@ Capr - 2.0.4 + 2.0.5 @@ -37,6 +37,9 @@
  • Capr Design Guide and Roadmap
  • +
  • + Capr Objects +
  • Capr for Templating Cohort Definitions
  • diff --git a/docs/reference/equals-methods.html b/docs/reference/equals-methods.html index 35bbd921..4c67efd6 100644 --- a/docs/reference/equals-methods.html +++ b/docs/reference/equals-methods.html @@ -17,7 +17,7 @@ Capr - 2.0.4 + 2.0.5 @@ -37,6 +37,9 @@
  • Capr Design Guide and Roadmap
  • +
  • + Capr Objects +
  • Capr for Templating Cohort Definitions
  • diff --git a/docs/reference/era.html b/docs/reference/era.html index 85198edc..d18939f9 100644 --- a/docs/reference/era.html +++ b/docs/reference/era.html @@ -19,7 +19,7 @@ Capr - 2.0.4 + 2.0.5 @@ -39,6 +39,9 @@
  • Capr Design Guide and Roadmap
  • +
  • + Capr Objects +
  • Capr for Templating Cohort Definitions
  • diff --git a/docs/reference/eventEnds.html b/docs/reference/eventEnds.html index 58bb8325..4a4dc127 100644 --- a/docs/reference/eventEnds.html +++ b/docs/reference/eventEnds.html @@ -17,7 +17,7 @@ Capr - 2.0.4 + 2.0.5 @@ -37,6 +37,9 @@
  • Capr Design Guide and Roadmap
  • +
  • + Capr Objects +
  • Capr for Templating Cohort Definitions
  • diff --git a/docs/reference/eventStarts.html b/docs/reference/eventStarts.html index 175bfbd6..ebdbb111 100644 --- a/docs/reference/eventStarts.html +++ b/docs/reference/eventStarts.html @@ -37,7 +37,7 @@ Capr - 2.0.4 + 2.0.5 @@ -57,6 +57,9 @@
  • Capr Design Guide and Roadmap
  • +
  • + Capr Objects +
  • Capr for Templating Cohort Definitions
  • diff --git a/docs/reference/exactly.html b/docs/reference/exactly.html index 15cc97de..4ff239bb 100644 --- a/docs/reference/exactly.html +++ b/docs/reference/exactly.html @@ -17,7 +17,7 @@ Capr - 2.0.4 + 2.0.5 @@ -37,6 +37,9 @@
  • Capr Design Guide and Roadmap
  • +
  • + Capr Objects +
  • Capr for Templating Cohort Definitions
  • diff --git a/docs/reference/exit.html b/docs/reference/exit.html index b656a9c5..a86a51dc 100644 --- a/docs/reference/exit.html +++ b/docs/reference/exit.html @@ -17,7 +17,7 @@ Capr - 2.0.4 + 2.0.5 @@ -37,6 +37,9 @@
  • Capr Design Guide and Roadmap
  • +
  • + Capr Objects +
  • Capr for Templating Cohort Definitions
  • diff --git a/docs/reference/firstOccurrence.html b/docs/reference/firstOccurrence.html index 71c329f1..21a92cae 100644 --- a/docs/reference/firstOccurrence.html +++ b/docs/reference/firstOccurrence.html @@ -17,7 +17,7 @@ Capr - 2.0.4 + 2.0.5 @@ -37,6 +37,9 @@
  • Capr Design Guide and Roadmap
  • +
  • + Capr Objects +
  • Capr for Templating Cohort Definitions
  • diff --git a/docs/reference/fixedExit.html b/docs/reference/fixedExit.html index 28831033..fe6e7d56 100644 --- a/docs/reference/fixedExit.html +++ b/docs/reference/fixedExit.html @@ -17,7 +17,7 @@ Capr - 2.0.4 + 2.0.5 @@ -37,6 +37,9 @@
  • Capr Design Guide and Roadmap
  • +
  • + Capr Objects +
  • Capr for Templating Cohort Definitions
  • diff --git a/docs/reference/generateCaprTemplate.html b/docs/reference/generateCaprTemplate.html index c74bc3cc..004fdc55 100644 --- a/docs/reference/generateCaprTemplate.html +++ b/docs/reference/generateCaprTemplate.html @@ -17,7 +17,7 @@ Capr - 2.0.4 + 2.0.5 @@ -37,6 +37,9 @@
  • Capr Design Guide and Roadmap
  • +
  • + Capr Objects +
  • Capr for Templating Cohort Definitions
  • diff --git a/docs/reference/getConceptSetCall.html b/docs/reference/getConceptSetCall.html index 3c8a42e8..2c61a5af 100644 --- a/docs/reference/getConceptSetCall.html +++ b/docs/reference/getConceptSetCall.html @@ -17,7 +17,7 @@ Capr - 2.0.4 + 2.0.5 @@ -37,6 +37,9 @@
  • Capr Design Guide and Roadmap
  • +
  • + Capr Objects +
  • Capr for Templating Cohort Definitions
  • diff --git a/docs/reference/getConceptSetDetails.html b/docs/reference/getConceptSetDetails.html index 78ea158d..6036bfe4 100644 --- a/docs/reference/getConceptSetDetails.html +++ b/docs/reference/getConceptSetDetails.html @@ -19,7 +19,7 @@ Capr - 2.0.4 + 2.0.5 @@ -39,6 +39,9 @@
  • Capr Design Guide and Roadmap
  • +
  • + Capr Objects +
  • Capr for Templating Cohort Definitions
  • diff --git a/docs/reference/gt.html b/docs/reference/gt.html index 293b2f13..5acd1a35 100644 --- a/docs/reference/gt.html +++ b/docs/reference/gt.html @@ -17,7 +17,7 @@ Capr - 2.0.4 + 2.0.5 @@ -37,6 +37,9 @@
  • Capr Design Guide and Roadmap
  • +
  • + Capr Objects +
  • Capr for Templating Cohort Definitions
  • diff --git a/docs/reference/gte.html b/docs/reference/gte.html index 4097e401..d2069db7 100644 --- a/docs/reference/gte.html +++ b/docs/reference/gte.html @@ -17,7 +17,7 @@ Capr - 2.0.4 + 2.0.5 @@ -37,6 +37,9 @@
  • Capr Design Guide and Roadmap
  • +
  • + Capr Objects +
  • Capr for Templating Cohort Definitions
  • diff --git a/docs/reference/index.html b/docs/reference/index.html index 76ee36ad..9969f550 100644 --- a/docs/reference/index.html +++ b/docs/reference/index.html @@ -17,7 +17,7 @@ Capr - 2.0.4 + 2.0.5 @@ -37,6 +37,9 @@
  • Capr Design Guide and Roadmap
  • +
  • + Capr Objects +
  • Capr for Templating Cohort Definitions
  • @@ -139,14 +142,14 @@

    All functions ConceptSetItem-class

    An S4 class for ConceptSetItem

    - -

    condition()

    - -

    Query the condition domain

    conditionEra()

    Query the condition era domain

    + +

    conditionOccurrence()

    + +

    Query the condition domain

    continuousObservation()

    @@ -167,10 +170,6 @@

    All functions death()

    Query the condition era domain

    - -

    drug()

    - -

    Query the drug domain

    drugEra()

    @@ -179,6 +178,10 @@

    All functions drugExit()

    Function to create an exit based on exit based on the end of a continuous drug exposure

    + +

    drugExposure()

    + +

    Query the drug domain

    DrugExposureExit-class

    diff --git a/docs/reference/lt.html b/docs/reference/lt.html index e840c609..9d9a7655 100644 --- a/docs/reference/lt.html +++ b/docs/reference/lt.html @@ -17,7 +17,7 @@ Capr - 2.0.4 + 2.0.5 @@ -37,6 +37,9 @@
  • Capr Design Guide and Roadmap
  • +
  • + Capr Objects +
  • Capr for Templating Cohort Definitions
  • diff --git a/docs/reference/lte.html b/docs/reference/lte.html index 43e40214..f6644fa3 100644 --- a/docs/reference/lte.html +++ b/docs/reference/lte.html @@ -17,7 +17,7 @@ Capr - 2.0.4 + 2.0.5 @@ -37,6 +37,9 @@
  • Capr Design Guide and Roadmap
  • +
  • + Capr Objects +
  • Capr for Templating Cohort Definitions
  • diff --git a/docs/reference/measurement.html b/docs/reference/measurement.html index 72c2ee72..204cfe48 100644 --- a/docs/reference/measurement.html +++ b/docs/reference/measurement.html @@ -17,7 +17,7 @@ Capr - 2.0.4 + 2.0.5 @@ -37,6 +37,9 @@
  • Capr Design Guide and Roadmap
  • +
  • + Capr Objects +
  • Capr for Templating Cohort Definitions
  • diff --git a/docs/reference/nbt.html b/docs/reference/nbt.html index ef474874..eebfd924 100644 --- a/docs/reference/nbt.html +++ b/docs/reference/nbt.html @@ -17,7 +17,7 @@ Capr - 2.0.4 + 2.0.5 @@ -37,6 +37,9 @@
  • Capr Design Guide and Roadmap
  • +
  • + Capr Objects +
  • Capr for Templating Cohort Definitions
  • diff --git a/docs/reference/nestedAttribute-class.html b/docs/reference/nestedAttribute-class.html index 3d57a216..b8400090 100644 --- a/docs/reference/nestedAttribute-class.html +++ b/docs/reference/nestedAttribute-class.html @@ -17,7 +17,7 @@ Capr - 2.0.4 + 2.0.5 @@ -37,6 +37,9 @@
  • Capr Design Guide and Roadmap
  • +
  • + Capr Objects +
  • Capr for Templating Cohort Definitions
  • diff --git a/docs/reference/nestedWithAll.html b/docs/reference/nestedWithAll.html index dfa802b8..d77e2262 100644 --- a/docs/reference/nestedWithAll.html +++ b/docs/reference/nestedWithAll.html @@ -17,7 +17,7 @@ Capr - 2.0.4 + 2.0.5 @@ -37,6 +37,9 @@
  • Capr Design Guide and Roadmap
  • +
  • + Capr Objects +
  • Capr for Templating Cohort Definitions
  • diff --git a/docs/reference/nestedWithAny.html b/docs/reference/nestedWithAny.html index 751cae82..8085a362 100644 --- a/docs/reference/nestedWithAny.html +++ b/docs/reference/nestedWithAny.html @@ -17,7 +17,7 @@ Capr - 2.0.4 + 2.0.5 @@ -37,6 +37,9 @@
  • Capr Design Guide and Roadmap
  • +
  • + Capr Objects +
  • Capr for Templating Cohort Definitions
  • diff --git a/docs/reference/nestedWithAtLeast.html b/docs/reference/nestedWithAtLeast.html index 680e19fa..0ed2fd5d 100644 --- a/docs/reference/nestedWithAtLeast.html +++ b/docs/reference/nestedWithAtLeast.html @@ -20,7 +20,7 @@ Capr - 2.0.4 + 2.0.5 @@ -40,6 +40,9 @@
  • Capr Design Guide and Roadmap
  • +
  • + Capr Objects +
  • Capr for Templating Cohort Definitions
  • diff --git a/docs/reference/nestedWithAtMost.html b/docs/reference/nestedWithAtMost.html index 694a9029..bd3e8a17 100644 --- a/docs/reference/nestedWithAtMost.html +++ b/docs/reference/nestedWithAtMost.html @@ -17,7 +17,7 @@ Capr - 2.0.4 + 2.0.5 @@ -37,6 +37,9 @@
  • Capr Design Guide and Roadmap
  • +
  • + Capr Objects +
  • Capr for Templating Cohort Definitions
  • diff --git a/docs/reference/observation.html b/docs/reference/observation.html index 7e951cfd..dda00b69 100644 --- a/docs/reference/observation.html +++ b/docs/reference/observation.html @@ -17,7 +17,7 @@ Capr - 2.0.4 + 2.0.5 @@ -37,6 +37,9 @@
  • Capr Design Guide and Roadmap
  • +
  • + Capr Objects +
  • Capr for Templating Cohort Definitions
  • diff --git a/docs/reference/observationExit.html b/docs/reference/observationExit.html index 4c31e15d..4082e593 100644 --- a/docs/reference/observationExit.html +++ b/docs/reference/observationExit.html @@ -17,7 +17,7 @@ Capr - 2.0.4 + 2.0.5 @@ -37,6 +37,9 @@
  • Capr Design Guide and Roadmap
  • +
  • + Capr Objects +
  • Capr for Templating Cohort Definitions
  • diff --git a/docs/reference/opAttributeDate-class.html b/docs/reference/opAttributeDate-class.html index 0049f3b3..c15f50bb 100644 --- a/docs/reference/opAttributeDate-class.html +++ b/docs/reference/opAttributeDate-class.html @@ -17,7 +17,7 @@ Capr - 2.0.4 + 2.0.5 @@ -37,6 +37,9 @@
  • Capr Design Guide and Roadmap
  • +
  • + Capr Objects +
  • Capr for Templating Cohort Definitions
  • diff --git a/docs/reference/opAttributeInteger-class.html b/docs/reference/opAttributeInteger-class.html index 4b5cb070..a7257f8d 100644 --- a/docs/reference/opAttributeInteger-class.html +++ b/docs/reference/opAttributeInteger-class.html @@ -17,7 +17,7 @@ Capr - 2.0.4 + 2.0.5 @@ -37,6 +37,9 @@
  • Capr Design Guide and Roadmap
  • +
  • + Capr Objects +
  • Capr for Templating Cohort Definitions
  • diff --git a/docs/reference/opAttributeNumeric-class.html b/docs/reference/opAttributeNumeric-class.html index cdb809dd..4864ad7a 100644 --- a/docs/reference/opAttributeNumeric-class.html +++ b/docs/reference/opAttributeNumeric-class.html @@ -17,7 +17,7 @@ Capr - 2.0.4 + 2.0.5 @@ -37,6 +37,9 @@
  • Capr Design Guide and Roadmap
  • +
  • + Capr Objects +
  • Capr for Templating Cohort Definitions
  • diff --git a/docs/reference/opAttributeSuper-class.html b/docs/reference/opAttributeSuper-class.html index 934714a6..ac58afc5 100644 --- a/docs/reference/opAttributeSuper-class.html +++ b/docs/reference/opAttributeSuper-class.html @@ -17,7 +17,7 @@ Capr - 2.0.4 + 2.0.5 @@ -37,6 +37,9 @@
  • Capr Design Guide and Roadmap
  • +
  • + Capr Objects +
  • Capr for Templating Cohort Definitions
  • diff --git a/docs/reference/pipe.html b/docs/reference/pipe.html index 4cba49aa..c1489672 100644 --- a/docs/reference/pipe.html +++ b/docs/reference/pipe.html @@ -17,7 +17,7 @@ Capr - 2.0.4 + 2.0.5 @@ -37,6 +37,9 @@
  • Capr Design Guide and Roadmap
  • +
  • + Capr Objects +
  • Capr for Templating Cohort Definitions
  • diff --git a/docs/reference/procedure.html b/docs/reference/procedure.html index ab457a1b..0de2a03d 100644 --- a/docs/reference/procedure.html +++ b/docs/reference/procedure.html @@ -17,7 +17,7 @@ Capr - 2.0.4 + 2.0.5 @@ -37,6 +37,9 @@
  • Capr Design Guide and Roadmap
  • +
  • + Capr Objects +
  • Capr for Templating Cohort Definitions
  • diff --git a/docs/reference/rangeHigh.html b/docs/reference/rangeHigh.html index cc2528c5..c6d46f3f 100644 --- a/docs/reference/rangeHigh.html +++ b/docs/reference/rangeHigh.html @@ -19,7 +19,7 @@ Capr - 2.0.4 + 2.0.5 @@ -39,6 +39,9 @@
  • Capr Design Guide and Roadmap
  • +
  • + Capr Objects +
  • Capr for Templating Cohort Definitions
  • diff --git a/docs/reference/rangeLow.html b/docs/reference/rangeLow.html index 65fe1ef6..02d633f2 100644 --- a/docs/reference/rangeLow.html +++ b/docs/reference/rangeLow.html @@ -19,7 +19,7 @@ Capr - 2.0.4 + 2.0.5 @@ -39,6 +39,9 @@
  • Capr Design Guide and Roadmap
  • +
  • + Capr Objects +
  • Capr for Templating Cohort Definitions
  • diff --git a/docs/reference/readConceptSet.html b/docs/reference/readConceptSet.html index 71b72f2f..ecf63bfc 100644 --- a/docs/reference/readConceptSet.html +++ b/docs/reference/readConceptSet.html @@ -18,7 +18,7 @@ Capr - 2.0.4 + 2.0.5 @@ -38,6 +38,9 @@
  • Capr Design Guide and Roadmap
  • +
  • + Capr Objects +
  • Capr for Templating Cohort Definitions
  • diff --git a/docs/reference/startDate.html b/docs/reference/startDate.html index 70aa5f46..742f9a12 100644 --- a/docs/reference/startDate.html +++ b/docs/reference/startDate.html @@ -17,7 +17,7 @@ Capr - 2.0.4 + 2.0.5 @@ -37,6 +37,9 @@
  • Capr Design Guide and Roadmap
  • +
  • + Capr Objects +
  • Capr for Templating Cohort Definitions
  • diff --git a/docs/reference/toCirce.html b/docs/reference/toCirce.html index ebb6b1bf..ee1cec37 100644 --- a/docs/reference/toCirce.html +++ b/docs/reference/toCirce.html @@ -17,7 +17,7 @@ Capr - 2.0.4 + 2.0.5 @@ -37,6 +37,9 @@
  • Capr Design Guide and Roadmap
  • +
  • + Capr Objects +
  • Capr for Templating Cohort Definitions
  • diff --git a/docs/reference/unit.html b/docs/reference/unit.html index f5b0c11f..1613974c 100644 --- a/docs/reference/unit.html +++ b/docs/reference/unit.html @@ -17,7 +17,7 @@ Capr - 2.0.4 + 2.0.5 @@ -37,6 +37,9 @@
  • Capr Design Guide and Roadmap
  • +
  • + Capr Objects +
  • Capr for Templating Cohort Definitions
  • diff --git a/docs/reference/valueAsNumber.html b/docs/reference/valueAsNumber.html index 9cbff9b6..bbc44326 100644 --- a/docs/reference/valueAsNumber.html +++ b/docs/reference/valueAsNumber.html @@ -19,7 +19,7 @@ Capr - 2.0.4 + 2.0.5 @@ -39,6 +39,9 @@
  • Capr Design Guide and Roadmap
  • +
  • + Capr Objects +
  • Capr for Templating Cohort Definitions
  • diff --git a/docs/reference/visit.html b/docs/reference/visit.html index 8c7071e3..1eff1e82 100644 --- a/docs/reference/visit.html +++ b/docs/reference/visit.html @@ -17,7 +17,7 @@ Capr - 2.0.4 + 2.0.5 @@ -37,6 +37,9 @@
  • Capr Design Guide and Roadmap
  • +
  • + Capr Objects +
  • Capr for Templating Cohort Definitions
  • diff --git a/docs/reference/withAll.html b/docs/reference/withAll.html index 712c2c5d..58d245cb 100644 --- a/docs/reference/withAll.html +++ b/docs/reference/withAll.html @@ -17,7 +17,7 @@ Capr - 2.0.4 + 2.0.5 @@ -37,6 +37,9 @@
  • Capr Design Guide and Roadmap
  • +
  • + Capr Objects +
  • Capr for Templating Cohort Definitions
  • diff --git a/docs/reference/withAny.html b/docs/reference/withAny.html index 94c9b6ae..87ca52bc 100644 --- a/docs/reference/withAny.html +++ b/docs/reference/withAny.html @@ -17,7 +17,7 @@ Capr - 2.0.4 + 2.0.5 @@ -37,6 +37,9 @@
  • Capr Design Guide and Roadmap
  • +
  • + Capr Objects +
  • Capr for Templating Cohort Definitions
  • diff --git a/docs/reference/withAtLeast.html b/docs/reference/withAtLeast.html index e2cb1215..b3a30d56 100644 --- a/docs/reference/withAtLeast.html +++ b/docs/reference/withAtLeast.html @@ -17,7 +17,7 @@ Capr - 2.0.4 + 2.0.5 @@ -37,6 +37,9 @@
  • Capr Design Guide and Roadmap
  • +
  • + Capr Objects +
  • Capr for Templating Cohort Definitions
  • diff --git a/docs/reference/withAtMost.html b/docs/reference/withAtMost.html index b33a11ad..4850f759 100644 --- a/docs/reference/withAtMost.html +++ b/docs/reference/withAtMost.html @@ -17,7 +17,7 @@ Capr - 2.0.4 + 2.0.5 @@ -37,6 +37,9 @@
  • Capr Design Guide and Roadmap
  • +
  • + Capr Objects +
  • Capr for Templating Cohort Definitions
  • diff --git a/docs/reference/writeCohort.html b/docs/reference/writeCohort.html index 4fbafe16..0892f5ef 100644 --- a/docs/reference/writeCohort.html +++ b/docs/reference/writeCohort.html @@ -17,7 +17,7 @@ Capr - 2.0.4 + 2.0.5 @@ -37,6 +37,9 @@
  • Capr Design Guide and Roadmap
  • +
  • + Capr Objects +
  • Capr for Templating Cohort Definitions
  • @@ -97,7 +100,7 @@

    Examples

    if (FALSE) {
     cs1 <- cs(descendants(exclude(436665),440383,442306,4175329))
     cs1 <- getConceptSetDetails(cs1)
    -x <- cohort(condition(cs1))
    +x <- cohort(condition(cs1))
     writeCohort(x, "cohortDefinition.json")
     }
     
    diff --git a/docs/reference/writeConceptSet.html b/docs/reference/writeConceptSet.html index 20765ccf..37895c94 100644 --- a/docs/reference/writeConceptSet.html +++ b/docs/reference/writeConceptSet.html @@ -17,7 +17,7 @@ Capr - 2.0.4 + 2.0.5 @@ -37,6 +37,9 @@
  • Capr Design Guide and Roadmap
  • +
  • + Capr Objects +
  • Capr for Templating Cohort Definitions
  • diff --git a/docs/sitemap.xml b/docs/sitemap.xml index ea2ce789..d357f6fc 100644 --- a/docs/sitemap.xml +++ b/docs/sitemap.xml @@ -9,6 +9,9 @@ /articles/capr_design.html + + /articles/capr_objects.html + /articles/capr_templates.html @@ -186,6 +189,9 @@ /reference/conditionEra.html + + /reference/conditionOccurrence.html + /reference/continuousObservation.html @@ -543,6 +549,9 @@ /reference/drugExit.html + + /reference/drugExposure.html + /reference/DrugExposureExit-class.html diff --git a/extras/Capr.pdf b/extras/Capr.pdf index c132119c..98991502 100644 Binary files a/extras/Capr.pdf and b/extras/Capr.pdf differ diff --git a/extras/PackageMaintenance.R b/extras/PackageMaintenance.R index adb178b2..ea87adac 100644 --- a/extras/PackageMaintenance.R +++ b/extras/PackageMaintenance.R @@ -35,12 +35,13 @@ shell("R CMD Rd2pdf ./ --output=extras/Capr.pdf") dir.create(path = "./extras/pdf_vignette/", showWarnings = FALSE) rmarkdown::render("vignettes/capr_design.Rmd", output_file = "../extras/pdf_vignette/capr_design.pdf", + rmarkdown::pdf_document(latex_engine = "pdflatex", toc = TRUE, number_sections = TRUE)) unlink("extras/pdf_vignette/capr_design.tex") # Examples -dir.create(path = "./extras/pdf_vignette/", showWarnings = FALSE) +#dir.create(path = "./extras/pdf_vignette/", showWarnings = FALSE) rmarkdown::render("vignettes/Examples.Rmd", output_file = "../extras/pdf_vignette/Examples.pdf", rmarkdown::pdf_document(latex_engine = "pdflatex", @@ -49,26 +50,35 @@ unlink("extras/pdf_vignette/Examples.tex") # Using Capr -dir.create(path = "./extras/pdf_vignette/", showWarnings = FALSE) +#dir.create(path = "./extras/pdf_vignette/", showWarnings = FALSE) rmarkdown::render("vignettes/Using-Capr.Rmd", output_file = "../extras/pdf_vignette/Using-Capr.pdf", rmarkdown::pdf_document(latex_engine = "pdflatex", toc = TRUE, number_sections = TRUE)) unlink("extras/pdf_vignette/Using-Capr.tex") -# capr templates -dir.create(path = "./extras/pdf_vignette/", showWarnings = FALSE) -rmarkdown::render("vignettes/capr_templates.Rmd", output_file = "../extras/pdf_vignette/capr_templates.pdf", - rmarkdown::pdf_document(latex_engine = "pdflatex", toc = TRUE, number_sections = TRUE)) +# capr templates dir.create(path = './extras/pdf_vignette/', showWarnings = FALSE) +rmarkdown::render("vignettes/capr_templates.Rmd", + output_file = "../extras/pdf_vignette/capr_templates.pdf", + + rmarkdown::pdf_document(latex_engine = "pdflatex", toc = TRUE, number_sections = TRUE)) unlink("extras/pdf_vignette/capr_templates.tex") -# capr concept sets -dir.create(path = "./extras/pdf_vignette/", showWarnings = FALSE) -rmarkdown::render("vignettes/Capr-conceptSets.Rmd", output_file = "../extras/pdf_vignette/Capr-conceptSets.pdf", - rmarkdown::pdf_document(latex_engine = "pdflatex", toc = TRUE, number_sections = TRUE)) +# capr concept sets dir.create(path = './extras/pdf_vignette/', showWarnings = FALSE) +rmarkdown::render("vignettes/Capr-conceptSets.Rmd", + output_file = "../extras/pdf_vignette/Capr-conceptSets.pdf", + + rmarkdown::pdf_document(latex_engine = "pdflatex", toc = TRUE, number_sections = TRUE)) unlink("extras/pdf_vignette/Capr-conceptSets.tex") +# capr components +rmarkdown::render("vignettes/capr_objects.Rmd", + output_file = "../extras/pdf_vignette/capr_objects.pdf", + + rmarkdown::pdf_document(latex_engine = "pdflatex", toc = TRUE, number_sections = TRUE)) +unlink("extras/pdf_vignette/capr_objects.tex") + # build site pkgdown::build_site() OhdsiRTools::fixHadesLogo() diff --git a/extras/pdf_vignette/Capr-conceptSets.pdf b/extras/pdf_vignette/Capr-conceptSets.pdf index 69152986..20cbcbf6 100644 Binary files a/extras/pdf_vignette/Capr-conceptSets.pdf and b/extras/pdf_vignette/Capr-conceptSets.pdf differ diff --git a/extras/pdf_vignette/Examples.pdf b/extras/pdf_vignette/Examples.pdf index 26010181..517403a2 100644 Binary files a/extras/pdf_vignette/Examples.pdf and b/extras/pdf_vignette/Examples.pdf differ diff --git a/extras/pdf_vignette/Using-Capr.pdf b/extras/pdf_vignette/Using-Capr.pdf index 932191c3..5478b801 100644 Binary files a/extras/pdf_vignette/Using-Capr.pdf and b/extras/pdf_vignette/Using-Capr.pdf differ diff --git a/extras/pdf_vignette/capr_design.pdf b/extras/pdf_vignette/capr_design.pdf index 6ceb8493..e6fd1a78 100644 Binary files a/extras/pdf_vignette/capr_design.pdf and b/extras/pdf_vignette/capr_design.pdf differ diff --git a/extras/pdf_vignette/capr_objects.pdf b/extras/pdf_vignette/capr_objects.pdf new file mode 100644 index 00000000..7bbb2c38 Binary files /dev/null and b/extras/pdf_vignette/capr_objects.pdf differ diff --git a/extras/pdf_vignette/capr_templates.pdf b/extras/pdf_vignette/capr_templates.pdf index e51b5caa..a39d23ab 100644 Binary files a/extras/pdf_vignette/capr_templates.pdf and b/extras/pdf_vignette/capr_templates.pdf differ diff --git a/man/condition.Rd b/man/conditionOccurrence.Rd similarity index 75% rename from man/condition.Rd rename to man/conditionOccurrence.Rd index 201c6a23..9649814a 100644 --- a/man/condition.Rd +++ b/man/conditionOccurrence.Rd @@ -1,10 +1,10 @@ % Generated by roxygen2: do not edit by hand % Please edit documentation in R/query.R -\name{condition} -\alias{condition} +\name{conditionOccurrence} +\alias{conditionOccurrence} \title{Query the condition domain} \usage{ -condition(conceptSet, ...) +conditionOccurrence(conceptSet, ...) } \arguments{ \item{conceptSet}{A condition concept set} diff --git a/man/cs.Rd b/man/cs.Rd index 204be24c..ddcad5c9 100644 --- a/man/cs.Rd +++ b/man/cs.Rd @@ -7,7 +7,7 @@ \alias{descendants} \title{Create a concept set} \usage{ -cs(..., name = "", id = NULL) +cs(..., name, id = NULL) exclude(...) diff --git a/man/drug.Rd b/man/drugExposure.Rd similarity index 79% rename from man/drug.Rd rename to man/drugExposure.Rd index 2bc1a0e3..0b298f1c 100644 --- a/man/drug.Rd +++ b/man/drugExposure.Rd @@ -1,10 +1,10 @@ % Generated by roxygen2: do not edit by hand % Please edit documentation in R/query.R -\name{drug} -\alias{drug} +\name{drugExposure} +\alias{drugExposure} \title{Query the drug domain} \usage{ -drug(conceptSet, ...) +drugExposure(conceptSet, ...) } \arguments{ \item{conceptSet}{A drug concept set} diff --git a/tests/testthat/test-AdditionalCriteria.R b/tests/testthat/test-AdditionalCriteria.R index 10892717..cd84a386 100644 --- a/tests/testthat/test-AdditionalCriteria.R +++ b/tests/testthat/test-AdditionalCriteria.R @@ -3,7 +3,7 @@ test_that("cohort with additional criteria works", { # LEGEND stroke cd <- cohort( entry = entry( - condition(cs(372924, 376713, 441874, 439847, + conditionOccurrence(cs(372924, 376713, 441874, 439847, 432923, 43530727, 4148906, descendants(443454), name = "stroke")), observationWindow = continuousObservation(0L, 0L), diff --git a/tests/testthat/test-cohort.R b/tests/testthat/test-cohort.R index 85776a6b..f3680dde 100644 --- a/tests/testthat/test-cohort.R +++ b/tests/testthat/test-cohort.R @@ -2,12 +2,12 @@ test_that("cohort entry works", { # ch <- cohort() # empty cohort is valid in circe but not Capr skip_if_not_installed("CirceR") # simplest possible cohort - simpleCohort <- cohort(condition(cs(1))) + simpleCohort <- cohort(conditionOccurrence(cs(1, name = "test"))) expect_s4_class(simpleCohort, "Cohort") # shared concept set - cs1 <- cs(descendants(exclude(436665),440383,442306,4175329)) - x <- cohort(entry(condition(cs1), drug(cs1))) + cs1 <- cs(descendants(exclude(436665),440383,442306,4175329), name = "test") + x <- cohort(entry(conditionOccurrence(cs1), drugExposure(cs1))) expect_s4_class(x, "Cohort") expect_type(as.list(x), "list") # TODO Do we keep as.list and as.json? expect_type(toCirce(x), "list") @@ -19,9 +19,9 @@ test_that("cohort entry works", { expect_type(sql, "character") # different concept sets - cs1 <- cs(descendants(exclude(436665),440383,442306,4175329)) - cs2 <- cs(descendants(exclude(436665),440383,442306)) - x <- cohort(entry(condition(cs1), drug(cs2))) + cs1 <- cs(descendants(exclude(436665),440383,442306,4175329), name = "test") + cs2 <- cs(descendants(exclude(436665),440383,442306), name = "test") + x <- cohort(entry(conditionOccurrence(cs1), drugExposure(cs2))) expect_s4_class(x, "Cohort") expect_type(as.list(x), "list") # TODO Do we keep as.list and as.json? expect_type(toCirce(x), "list") @@ -35,7 +35,7 @@ test_that("cohort entry works", { test_that("getConceptSetDetails works on Eunomia", { skip_if_not_installed("Eunomia") - gibleed <- cs(descendants(192671)) + gibleed <- cs(descendants(192671), name = "test") connectionDetails <- Eunomia::getEunomiaConnectionDetails() suppressMessages({ con <- DatabaseConnector::connect(connectionDetails) @@ -53,20 +53,20 @@ test_that("full cohort works", { cd <- cohort( entry = entry( - condition(cs(descendants(201826L)), male()), + conditionOccurrence(cs(descendants(201826L), name = "test"), male()), observationWindow = continuousObservation(365, 0) ), attrition = attrition( 'no t1d' = withAll( exactly(0, - condition(cs(descendants(201254L))), + conditionOccurrence(cs(descendants(201254L), name = "test")), duringInterval(eventStarts(-Inf, -1)) ) ), 'abnormal hba1c' = withAll( atLeast(1, measurement( - cs(descendants(4184637L)), + cs(descendants(4184637L), name = "test"), valueAsNumber(lt(13)), unit(8713L) ), @@ -100,17 +100,17 @@ test_that("full cohort works without group", { cd <- cohort( entry = entry( - condition(cs(descendants(201826L)), male()), + conditionOccurrence(cs(descendants(201826L), name = "test"), male()), observationWindow = continuousObservation(365, 0) ), attrition = attrition( 'no t1d' = exactly(0, - condition(cs(descendants(201254L))), + conditionOccurrence(cs(descendants(201254L), name = "test")), duringInterval(eventStarts(-Inf, -1)) ), 'abnormal hba1c' = atLeast(1, measurement( - cs(descendants(4184637L)), + cs(descendants(4184637L), name = "test"), valueAsNumber(lt(13)), unit(8713L)), duringInterval(eventStarts(-Inf, -1)) @@ -145,7 +145,7 @@ test_that("Capr cohort generates on synpuf", { # need simple cohort for synpuf cd <- cohort( entry = entry( - drug(cs(descendants(1118084), name = "celecoxib"), male()), + drugExposure(cs(descendants(1118084), name = "celecoxib"), male()), observationWindow = continuousObservation(365, 0) ) ) @@ -199,6 +199,6 @@ test_that("Capr cohort generates on synpuf", { }) test_that("compile generic works", { - ch <- cohort(condition(cs(1,2))) + ch <- cohort(conditionOccurrence(cs(1,2, name = "test"))) expect_gt(nchar(generics::compile(ch)), 10) }) diff --git a/tests/testthat/test-collectCodesetId.R b/tests/testthat/test-collectCodesetId.R index 0459973a..0c2b448b 100644 --- a/tests/testthat/test-collectCodesetId.R +++ b/tests/testthat/test-collectCodesetId.R @@ -4,19 +4,19 @@ # Query, group test_that("listConceptSets - Query", { - conceptSets <- listConceptSets(condition(cs(1))) + conceptSets <- listConceptSets(conditionOccurrence(cs(1, name = "test"))) expect_true(all(purrr::map_lgl(conceptSets, ~all(names(.) == c("id", "name", "expression"))))) }) test_that("listConceptSets - Criteria", { - conceptSets <- listConceptSets(atLeast(1, condition(cs(1)))) + conceptSets <- listConceptSets(atLeast(1, conditionOccurrence(cs(1, name = "test")))) expect_true(all(purrr::map_lgl(conceptSets, ~all(names(.) == c("id", "name", "expression"))))) }) test_that("listConceptSets - Group", { g <- withAll( - atLeast(1, condition(cs(1))), - exactly(0, condition(cs(2))) + atLeast(1, conditionOccurrence(cs(1, name = "test"))), + exactly(0, conditionOccurrence(cs(2, name = "test"))) ) conceptSets <- listConceptSets(g) expect_length(conceptSets, 2) @@ -25,8 +25,8 @@ test_that("listConceptSets - Group", { test_that("listConceptSets - Entry", { e <- entry(withAll( - atLeast(1, condition(cs(1))), - exactly(0, condition(cs(2))) + atLeast(1, conditionOccurrence(cs(1, name = "test"))), + exactly(0, conditionOccurrence(cs(2, name = "test"))) )) conceptSets <- listConceptSets(e) expect_true(all(purrr::map_lgl(conceptSets, ~all(names(.) == c("id", "name", "expression"))))) @@ -34,8 +34,8 @@ test_that("listConceptSets - Entry", { test_that("listConceptSets - Attrition", { x <- attrition(withAll( - atLeast(1, condition(cs(1))), - exactly(0, condition(cs(2))) + atLeast(1, conditionOccurrence(cs(1, name = "test"))), + exactly(0, conditionOccurrence(cs(2, name = "test"))) )) conceptSets <- listConceptSets(x) @@ -48,14 +48,14 @@ test_that("listConceptSets - Attrition", { x <- attrition( 'no t1d' = withAll( exactly(0, - condition(cs(descendants(201254L))), + conditionOccurrence(cs(descendants(201254L), name = "test")), duringInterval(eventStarts(-Inf, -1)) ) ), 'abnormal hba1c' = withAll( atLeast(1, measurement( - cs(descendants(4184637L)), + cs(descendants(4184637L), name = "test"), valueAsNumber(lt(13)), unit(8713L) ), @@ -73,7 +73,7 @@ test_that("listConceptSets - Attrition", { test_that("listConceptSets - CohortExit", { - e <- exit(drugExit(cs(1,2,5))) + e <- exit(drugExit(cs(1,2,5, name = "test"))) expect_s4_class(e, "CohortExit") conceptSets <- listConceptSets(e) expect_length(conceptSets, 1) @@ -81,9 +81,9 @@ test_that("listConceptSets - CohortExit", { }) test_that("listConceptSets - Query with nested criteria", { - x <- visit(cs(1), - nestedWithAll(atLeast(1, condition(cs(9))), - atLeast(1, drug(cs(1:5))))) + x <- visit(cs(1, name = "test"), + nestedWithAll(atLeast(1, conditionOccurrence(cs(9, name = "test"))), + atLeast(1, drugExposure(cs(1:5, name = "test"))))) conceptSets <- listConceptSets(x) expect_length(conceptSets, 3) @@ -91,11 +91,11 @@ test_that("listConceptSets - Query with nested criteria", { }) test_that("listConceptSets - Query with double nested criteria", { - x <- visit(cs(1), + x <- visit(cs(1, name = "test"), nestedWithAll( - atLeast(1, drug(cs(21:24))), - atLeast(1, condition(cs(9), - nestedWithAll(atLeast(1, drug(cs(11)))) + atLeast(1, drugExposure(cs(21:24, name = "test"))), + atLeast(1, conditionOccurrence(cs(9, name = "test"), + nestedWithAll(atLeast(1, drugExposure(cs(11, name = "test")))) )))) conceptSets <- listConceptSets(x) @@ -107,13 +107,13 @@ test_that("listConceptSets - nested Query", { skip("failing test") # TODO fix listConceptSets so this passes # this works fine - x <- visit(cs(descendants(9201, 9203, 262)), + x <- visit(cs(descendants(9201, 9203, 262), name = "test"), nestedWithAll( atLeast(1, - condition(cs(descendants(316139), name = "heart failure"), + conditionOccurrence(cs(descendants(316139), name = "heart failure"), attributes = nestedWithAll( atLeast(1, - condition(cs(descendants(316139), name = "heart failure")) + conditionOccurrence(cs(descendants(316139), name = "heart failure")) ) ) ) @@ -127,13 +127,13 @@ test_that("listConceptSets - nested Query", { expect_true(all(purrr::map_lgl(conceptSets, ~all(names(.) == c("id", "name", "expression"))))) # this does not work - x <- visit(cs(descendants(9201, 9203, 262)), + x <- visit(cs(descendants(9201, 9203, 262), name = "test"), nestedWithAll( atLeast(1, - condition(cs(descendants(316139), name = "heart failure"), + conditionOccurrence(cs(descendants(316139), name = "heart failure"), attributes = list(male(), nestedWithAll( atLeast(1, - condition(cs(descendants(316139), name = "heart failure")) + conditionOccurrence(cs(descendants(316139), name = "heart failure")) ) )) ) @@ -151,20 +151,20 @@ test_that("listConceptSets - Cohort", { cd <- cohort( entry = entry( - condition(cs(descendants(201826L)), male()), + conditionOccurrence(cs(descendants(201826L), name = "test"), male()), observationWindow = continuousObservation(365, 0) ), attrition = attrition( 'no t1d' = withAll( exactly(0, - condition(cs(descendants(201254L))), + conditionOccurrence(cs(descendants(201254L), name = "test")), duringInterval(eventStarts(-Inf, -1)) ) ), 'abnormal hba1c' = withAll( atLeast(1, measurement( - cs(descendants(4184637L)), + cs(descendants(4184637L), name = "test"), valueAsNumber(lt(13)), unit(8713L) ), diff --git a/tests/testthat/test-conceptSet.R b/tests/testthat/test-conceptSet.R index 5067f2e8..b336765c 100644 --- a/tests/testthat/test-conceptSet.R +++ b/tests/testthat/test-conceptSet.R @@ -1,5 +1,5 @@ test_that("cs helpers work", { - concepts <- cs(3, descendants(4, mapped(5, exclude(6)))) + concepts <- cs(3, descendants(4, mapped(5, exclude(6))), name = "test") df <- tibble::tribble( ~conceptId, ~includeDescendants, ~isExcluded, ~includeMapped, @@ -19,7 +19,7 @@ test_that("cs helpers work", { test_that("writeConceptSet works", { path <- tempfile("concepts", fileext = ".json") - concepts <- cs(1, 2, descendants(4, 5), exclude(descendants(6, 7))) + concepts <- cs(1, 2, descendants(4, 5), exclude(descendants(6, 7)), name = "test") writeConceptSet(concepts, path = path) # cat(readr::read_file(path)) concepts2 <- readConceptSet(path) @@ -29,7 +29,7 @@ test_that("writeConceptSet works", { }) test_that("dedupConceptSet works", { - allConceptSets <- list(cs(2,1), cs(2,3), cs(1,2)) + allConceptSets <- list(cs(2,1, name = "test"), cs(2,3, name = "test"), cs(1,2, name = "test")) r <- dedupConceptSets(allConceptSets) uniqueConceptSets <- r$uniqueConceptSets lookup <- r$lookup @@ -39,40 +39,40 @@ test_that("dedupConceptSet works", { test_that("equality works", { # order should not matter - expect_true(cs(1,descendants(9),3) == cs(1,3,descendants(9))) - expect_false(cs(2,descendants(9),3) == cs(1,3,descendants(9))) + expect_true(cs(1,descendants(9),3, name = "test") == cs(1,3,descendants(9), name = "test")) + expect_false(cs(2,descendants(9),3, name = "test") == cs(1,3,descendants(9), name = "test")) - expect_false(cs(descendants(9), 3) == cs(9,3)) - expect_false(cs(mapped(9), 3) == cs(9,3)) - expect_false(cs(exclude(9), 3) == cs(9,3)) - expect_false(cs(exclude(9), 3) == cs(exclude(mapped(9)),3)) - expect_false(cs(exclude(9), 3) == cs(exclude(mapped(9)),3)) + expect_false(cs(descendants(9), 3, name = "test") == cs(9,3, name = "test")) + expect_false(cs(mapped(9), 3, name = "test") == cs(9,3, name = "test")) + expect_false(cs(exclude(9), 3, name = "test") == cs(9,3, name = "test")) + expect_false(cs(exclude(9), 3, name = "test") == cs(exclude(mapped(9)),3, name = "test")) + expect_false(cs(exclude(9), 3, name = "test") == cs(exclude(mapped(9)),3, name = "test")) - expect_error(cs(3, 3), "duplicated") # duplicates are not allowed + expect_error(cs(3, 3, name = "test"), "duplicated") # duplicates are not allowed # name and id are ignored expect_true(cs(9, 3, name = "a") == cs(9, 3, name = "b")) - expect_true(cs(9, 3, id = "a") == cs(9, 3, id = "b")) + expect_true(cs(9, 3, id = "a", name = "test") == cs(9, 3, id = "b", name = "test")) }) test_that("uniqueConceptSets works", { x <- uniqueConceptSets(list( - cs(1,2,3), - cs(1,2,3), - cs(1,2, exclude(3)) + cs(1,2,3, name = "test"), + cs(1,2,3, name = "test"), + cs(1,2, exclude(3), name = "test") )) expect_true(length(x) == 2) - expect_true(x[[1]] == cs(1,2,3)) - expect_true(x[[2]] == cs(1,2, exclude(3))) + expect_true(x[[1]] == cs(1,2,3, name = "test")) + expect_true(x[[2]] == cs(1,2, exclude(3), name = "test")) }) test_that("concept set id does not depend on order", { - a <- cs(1,descendants(9),3) - b <- cs(1,3,descendants(9)) - c <- cs(1,3,9) - d <- cs(1,descendants(9),3) + a <- cs(1,descendants(9),3, name = "test") + b <- cs(1,3,descendants(9), name = "test") + c <- cs(1,3,9, name = "test") + d <- cs(1,descendants(9),3, name = "test") expect_type(a@id, "character") expect_true(a@id == b@id) @@ -90,7 +90,7 @@ test_that("read/writeConceptSet works", { # write and read concept set as csv f1 <- tempfile(fileext = ".csv") - aceInhibitors <- cs(descendants(1335471, 1340128, 1341927, 1363749, 1308216, 1310756, 1373225, 1331235, 1334456, 1342439)) + aceInhibitors <- cs(descendants(1335471, 1340128, 1341927, 1363749, 1308216, 1310756, 1373225, 1331235, 1334456, 1342439), name = "test") writeConceptSet(aceInhibitors, f1) comparison1 <- readConceptSet(f1) expect_true(aceInhibitors == comparison1) diff --git a/tests/testthat/test-exit.R b/tests/testthat/test-exit.R index 9c5e3900..a59575b4 100644 --- a/tests/testthat/test-exit.R +++ b/tests/testthat/test-exit.R @@ -15,7 +15,7 @@ test_that("Drug Exit Works", { cd <- cohort( entry = entry( - drug(aceCS), + drugExposure(aceCS), observationWindow = continuousObservation(priorDays = 0L, postDays = 0L), primaryCriteriaLimit = "First" ), @@ -45,7 +45,7 @@ test_that("Fixed Duration Exit Works", { cd <- cohort( entry = entry( - drug(aceCS), + drugExposure(aceCS), observationWindow = continuousObservation(priorDays = 0L, postDays = 0L), primaryCriteriaLimit = "First" ), diff --git a/tests/testthat/test-nest.R b/tests/testthat/test-nest.R index ba91c8e4..f85a33d5 100644 --- a/tests/testthat/test-nest.R +++ b/tests/testthat/test-nest.R @@ -1,9 +1,9 @@ test_that("Nesting Criteria works", { - query <- visit(cs(descendants(9201, 9203, 262)), + query <- visit(cs(descendants(9201, 9203, 262), name = "visit"), nestedWithAll( atLeast(1, - condition(cs(descendants(316139), name = "heart failure")), + conditionOccurrence(cs(descendants(316139), name = "heart failure")), duringInterval(startWindow = eventStarts(0, Inf), endWindow = eventStarts(-Inf, 0, index = "endDate") ) @@ -24,10 +24,10 @@ test_that("Can build a cohort with nested attribute", { skip_if_not_installed("CirceR") cd <- cohort( entry = entry( - visit(cs(descendants(9201, 9203, 262)), + visit(cs(descendants(9201, 9203, 262), name = "visit"), nestedWithAll( atLeast(1, - condition(cs(descendants(316139), name = "heart failure")), + conditionOccurrence(cs(descendants(316139), name = "heart failure")), duringInterval(startWindow = eventStarts(0, Inf), endWindow = eventStarts(-Inf, 0, index = "endDate") ) @@ -95,20 +95,20 @@ test_that("Can build a cohort with nested attribute", { test_that("Can build a cohort with nested groups", { skip_if_not_installed("CirceR") - t2dDrug <- drug(cs(descendants(1502809,1502826,1503297,1510202,1515249,1516766, + t2dDrug <- drugExposure(cs(descendants(1502809,1502826,1503297,1510202,1515249,1516766, 1525215,1529331,1530014,1547504,1559684,1560171, - 1580747,1583722,1594973,1597756))) + 1580747,1583722,1594973,1597756), name = "t2dDrug")) - t2d <- condition(cs(descendants(201826))) + t2d <- conditionOccurrence(cs(descendants(201826), name = "t2d")) - t1d <- condition(cs(descendants(201254))) + t1d <- conditionOccurrence(cs(descendants(201254), name = "t1d")) - t1dDrug <- drug(cs(descendants(1502905,1513876,1516976,1517998, - 1531601,1544838,1550023,1567198))) + t1DrugCs <- cs(descendants(1502905,1513876,1516976,1517998, + 1531601,1544838,1550023,1567198), name = "t1Drug") + t1dDrug <- drugExposure(t1DrugCs) - t1dDrugWT2Drug <- drug(cs(descendants(1502905,1513876,1516976,1517998, - 1531601,1544838,1550023,1567198)), + t1dDrugWT2Drug <- drugExposure(t1DrugCs, nestedWithAll( atLeast(1, t2dDrug, duringInterval(startWindow = eventStarts(-Inf, -1)) @@ -116,11 +116,11 @@ test_that("Can build a cohort with nested groups", { ) ) - abLabFast <- measurement(cs(descendants(3037110)), + abLabFast <- measurement(cs(descendants(3037110), name = "abLabFast"), valueAsNumber(gte(125))) - abLabHb <- measurement(cs(descendants(3003309,3004410,3005673,3007263)), + abLabHb <- measurement(cs(descendants(3003309,3004410,3005673,3007263), name = "abLabHb"), valueAsNumber(gte(6))) - abLabRan <- measurement(cs(descendants(3000483,3004501)), + abLabRan <- measurement(cs(descendants(3000483,3004501), name = "abLabRan"), valueAsNumber(gte(200))) @@ -167,7 +167,7 @@ test_that("Can build a cohort with nested groups", { withAll( atLeast(1, t2d, duringInterval(startWindow = eventStarts(-Inf, 0))), exactly(0, t1dDrug, duringInterval(startWindow = eventStarts(-Inf, 0))), - atLeast(0, t2dDrug, duringInterval(startWindow = eventStarts(-Inf, 0))) + atLeast(1, t2dDrug, duringInterval(startWindow = eventStarts(-Inf, 0))) ), #Path 4 withAll( @@ -210,10 +210,10 @@ test_that("Can build a cohort with nested groups", { }) test_that("listConceptSets works with nested Query", { - a <- visit(cs(descendants(9201, 9203, 262)), + a <- visit(cs(descendants(9201, 9203, 262), name = "visit"), nestedWithAll( atLeast(1, - condition(cs(descendants(316139), name = "heart failure")) + conditionOccurrence(cs(descendants(316139), name = "heart failure")) ) ) ) diff --git a/vignettes/Capr-conceptSets.Rmd b/vignettes/Capr-conceptSets.Rmd index 939c5557..bdbf53b4 100644 --- a/vignettes/Capr-conceptSets.Rmd +++ b/vignettes/Capr-conceptSets.Rmd @@ -56,4 +56,20 @@ ace3 ``` +## Fill in missing concept set details + +By default, `Capr` puts in minimal information for the concept set, the concept id. However it is often helpful to fill out the remaining information of the concept using the OMOP vocabularies. To fill out the remaining information, a user needs to connect to a OMOP CDM to access the vocabulary information for the concept in the concept set. First we show a regular concept set, and the json it renders. + +```{r baseSet, eval=FALSE} +diclofenac <- cs(descendants(1124300), name = "diclofenac") +cat(as.json(diclofenac)) +``` + +Now we add in the CDM connection to get the remaining information: + +```{r fillOut, eval=FALSE} +con <- DatabaseConnector::connect(Eunomia::getEunomiaConnectionDetails()) +diclofenac <- getConceptSetDetails(diclofenac, con, vocabularyDatabaseSchema = "main") +cat(as.json(diclofenac)) +``` diff --git a/vignettes/Examples.Rmd b/vignettes/Examples.Rmd index 5e8703b1..52860276 100644 --- a/vignettes/Examples.Rmd +++ b/vignettes/Examples.Rmd @@ -51,7 +51,7 @@ cs1 <- cs(descendants(443238, 201820, 442793), name = "Type 2 diabetes mellitus (diabetes mellitus excluding T1DM and secondary)") ch <- cohort( - entry = condition(cs1), + entry = conditionOccurrence(cs1), attrition = attrition( atLeast(1, observationPeriod(), @@ -74,7 +74,7 @@ cs0 <- cs(descendants(443238, 201820, 442793), ch <- cohort( entry = entry( - condition(cs0), + conditionOccurrence(cs0), observationWindow = continuousObservation(priorDays = 365) ), exit = exit( @@ -108,12 +108,12 @@ cs2 <- cs(descendants(195771), ch <- cohort( entry = entry( - condition(cs0), + conditionOccurrence(cs0), observationWindow = continuousObservation(priorDays = 365) ), attrition = attrition( - exactly(0, condition(cs1), duringInterval(eventStarts(-Inf, 0))), - exactly(0, condition(cs2), duringInterval(eventStarts(-Inf, 0))) + exactly(0, conditionOccurrence(cs1), duringInterval(eventStarts(-Inf, 0))), + exactly(0, conditionOccurrence(cs2), duringInterval(eventStarts(-Inf, 0))) ), exit = exit( endStrategy = observationExit() @@ -153,18 +153,18 @@ cs4 <- cs(descendants(21600744), ch <- cohort( entry = entry( - condition(cs0), - drug(cs4), + conditionOccurrence(cs0), + drugExposure(cs4), measurement(cs3, valueAsNumber(bt(6.5, 30)), unit("%")), measurement(cs3, valueAsNumber(bt(48, 99)), unit("mmol/mol")), observationWindow = continuousObservation(priorDays = 365) ), attrition = attrition( 'no T1D' = withAll( - exactly(0, condition(cs1), duringInterval(eventStarts(-Inf, 0))) + exactly(0, conditionOccurrence(cs1), duringInterval(eventStarts(-Inf, 0))) ), 'no secondary diabettes' = withAll( - exactly(0, condition(cs2), duringInterval(eventStarts(-Inf, 0))) + exactly(0, conditionOccurrence(cs2), duringInterval(eventStarts(-Inf, 0))) ) ), exit = exit( @@ -190,7 +190,7 @@ cs0 <- cs(descendants(195771), ch <- cohort( entry = entry( - condition(cs0), + conditionOccurrence(cs0), observationWindow = continuousObservation(priorDays = 365) ) ) @@ -220,12 +220,12 @@ cs2 <- cs(descendants(195771), ch <- cohort( entry = entry( - condition(cs1), + conditionOccurrence(cs1), observationWindow = continuousObservation(priorDays = 365) ), attrition = attrition( - "no prior T2DM" = exactly(0, condition(cs0), duringInterval(eventStarts(-Inf, 0))), - "no prior secondary T1DM" = exactly(0, condition(cs2), duringInterval(eventStarts(-Inf, 0))) + "no prior T2DM" = exactly(0, conditionOccurrence(cs0), duringInterval(eventStarts(-Inf, 0))), + "no prior secondary T1DM" = exactly(0, conditionOccurrence(cs2), duringInterval(eventStarts(-Inf, 0))) ) ) @@ -247,7 +247,7 @@ https://atlas-phenotype.ohdsi.org/#/cohortdefinition/93 cs0 <- cs(descendants(313217), name = "Atrial fibrillation") -ch <- cohort(condition(cs0)) +ch <- cohort(conditionOccurrence(cs0)) ``` @@ -273,13 +273,13 @@ op <- cs(descendants(9202, 9203), ch <- cohort( entry = entry( - condition(afib, + conditionOccurrence(afib, nestedWithAny( atLeast(1, visit(ip), duringInterval(eventStarts(-Inf, 0), eventEnds(0, Inf))), nestedWithAll( atLeast(1, visit(op, duringInterval(eventStarts(-Inf, 0), eventEnds(0, Inf)), nestedWithAll( - atLeast(1, condition(afib, duringInterval(eventStarts(7, 365)), + atLeast(1, conditionOccurrence(afib, duringInterval(eventStarts(7, 365)), nestedWithAll( atLeast(1, visit(op, duringInterval(eventStarts(-Inf, 0), eventEnds(0, Inf)))) ) diff --git a/vignettes/Using-Capr.Rmd b/vignettes/Using-Capr.Rmd index 552a03ce..6028bdc0 100644 --- a/vignettes/Using-Capr.Rmd +++ b/vignettes/Using-Capr.Rmd @@ -46,7 +46,7 @@ The condition concept ID for Gastrointestinal hemorrhage is 192671. We can creat ```{r} library(Capr) -GIBleed <- cs(descendants(192671)) +GIBleed <- cs(descendants(192671), name = "GIbleed") GIBleed ``` @@ -63,7 +63,7 @@ of many defaults that match the defaults in Atlas. ```{r} giBleedCohort <- cohort( entry = entry( - condition(GIBleed), + conditionOccurrence(GIBleed), observationWindow = continuousObservation(0L, 0L), primaryCriteriaLimit = "First" ), diff --git a/vignettes/capr_objects.Rmd b/vignettes/capr_objects.Rmd new file mode 100644 index 00000000..0e3df579 --- /dev/null +++ b/vignettes/capr_objects.Rmd @@ -0,0 +1,440 @@ +--- +title: "Capr Objects" +output: rmarkdown::html_vignette +vignette: > + %\VignetteIndexEntry{Capr Objects} + %\VignetteEngine{knitr::rmarkdown} + %\VignetteEncoding{UTF-8} +--- + +```{r, include = FALSE} +knitr::opts_chunk$set( + collapse = TRUE, + comment = "#>" +) +``` + +```{r setup, echo=FALSE} +library(Capr) +``` + + +# Intro + +`Capr` allows users to build OHDSI cohort definitions in R outside of ATLAS. `Capr`, like ATLAS, uses the same underlying software `circe-be` to compose the cohort logic into an actionable query. Therefore we must understand sub-components of the cohort definition, in order to properly apply them to our cohort construction. There are three main sub-components that drive building of the cohort logic: 1) query, 2) criteria and 3) group. In this vignette, we will describe the purpose of each sub-component and demonstrate the `Capr` commands to invoke these structures. + +# Query + +## Definition + +The *query* is a `circe-be` construct that defines which concepts to extract from which domain table in the OMOP CDM. In basic terms it is finding the persons that have a particular code in the data. Through a more technical lens, the query is supplying the **WHERE** and **FROM** logic in portions of the SQL script. Ultimately the logic we construct in `Capr` or ATLAS render a standardized SQL script that finds persons in the database, of which the query is vital in providing the code sets to search from. The *query* will be found all over the cohort definition. Whenever we need to apply a concept set, it will be through a *query*. In `Capr` the *query* function is specified based on the domain tables available in the CDM. The table below provides the mapping between the OMOP domain and the the `Capr` function call. + +```{r queryTable, echo=FALSE} +tb <- tibble::tribble( + ~`OMOP Domain`, ~`Capr Function`, + "DrugExposure", "drugExposure", + "DrugEra", "drugEra", + "ConditionOccurrence", "conditionOccurrence", + "ConditionEra", "conditionEra", + "ProcedureOccurrence", "procedure", + "Measurement", "measurement", + "VisitOccurrence", "visit", + "Observation", "observation", + "Death", "death" +) +knitr::kable(tb) +``` + +## Example + +A simple example of how to use a query in `Capr` can be seen below: + +```{r queryEx, eval=FALSE} +t1dConceptSet <- cs(descendants(195771), name = "T1D") +t1dQuery <- conditionOccurrence(t1dConceptSet) +``` + + +With our query we can apply this in a variety of places within the cohort definition. Below we give an example of a cohort of persons starting on metformin as our index event, where they could not have been diagnosed with Type 1 Diabetes any time prior. + +```{r queryInCohort, eval=FALSE} +metforminConceptSet <- cs(descendants(1503297), name = "metformin") +t1dConceptSet <- cs(descendants(195771), name = "T1D") + +metforminCohort <- cohort( + entry = entry( + # metformin drug query as index event + drugExposure(metforminConceptSet, firstOccurrence()), + observationWindow = continuousObservation(priorDays = -365, postDays = 365L), + primaryCriteriaLimit = "All" + ), + attrition = attrition( + 'noT1d' = withAll( + exactly( + x = 0, + # query for t1d occurrence to exclude patients + query = conditionOccurrence(t1dConceptSet), + aperture = duringInterval( + startWindow = eventStarts(a = -Inf, b = 0, index = "startDate") + ) + ) + ) + ), + exit = exit( + endStrategy = observationExit(), + censor = censoringEvents( + #exit based on observence of t1d condition + # query for t1d occurrence for censor + conditionOccurrence(t1dConceptSet) + ) + ) +) +``` + +Notice that the *query* is applied all over this cohort definition. The metformin query sets the concept set to use as the index event. The Type 1 Diabetes (T1D) query sets the attrition of the patients identified at index who should be excluded for having the condition. The T1D query also sets the exit from cohort. The cohort ends when the person has no more observation time in the database or they have been diagnosed with T1D. Remember the *query* is infusing the concept sets into the cohort logic based on which domain to search for codes in person healthcare records. + +## Attributes + +The *query* is often contextualized by an attribute. For example in the cohort above, we are searching for metformin in the drug exposure table given it has occurred for the first time in the person history. The attribute is a object that modifies queries by filtering records based on the presence of another parameter. Attributes can be based on person information (such as gender, race, or age), time based (observation at a certain time window), domain based (presence of a code in a different column of the same domain), or event based (based on the observation of another event occurring). We will go into more details on different attributes in a different vignette. In `Capr` as many attributes can be attached within the query after providing the concept set. Example below: + +```{r attrInQuery, eval=FALSE} +t1dConceptSet <- cs(descendants(195771), name = "T1D") + +maleT1D <- conditionOccurrence(t1dConceptSet, male()) +maleT1D18andOlder <- conditionOccurrence(t1dConceptSet, male(), age(gte(18))) +maleT1D18andOlderFirstDx <- conditionOccurrence( + t1dConceptSet, male(), age(gte(18)), firstOccurrence()) +``` + +One special type of attribute is a nested query. This construct is more complex and requires understanding of the *criteria* and *group* objects. We will return to this idea later in this vignette. + +# Criteria + +## Definition + +A *criteria* object is one that enumerates the presence or absence of an event within a window of observation relative to an index point. The index point may be the entry event of the cohort definition. It could also be a prior event if we are building a nested query. The purpose of this object is to count whether a person has experienced certain events that would either include or exclude them from the cohort. Its easiest to show a *criteria* using a figure. Say relative from index we want to see two exposures of a drug within 365 days and 30 days before index. Those that fit that criteria remain in the cohort, those that do not are excluded from the cohort. See the figure below as an example: + +![Example of Criteria](images/criteria_example.png) + +When building a *criteria* object the user needs: 1) a query, 2) an operator that specifies the number of times a query is observed (occurrences), and 3) a time window which we call the aperture. Using the figure as an example, think of the stars as the query, the number of stars as the occurrences, and the box as the aperture. We could orient this idea around the index event in a variety of different ways. + + +## Example + +With this definition in mind, let us build an example of a *criteria* object that reflects the image above. + +```{r criteriaExampleA, eval=FALSE} +atenololConceptSet <- cs(descendants(1314002), name - "atenolol") + +atenololCriteria <- atLeast( + x = 2, + query = drugExposure(atenololConceptSet), + aperture = duringInterval( + startWindow = eventStarts(a = -365, b = -30, index = "startDate") + ) +) +``` + +This *criteria* specifies that we must observe at least 2 drug exposures of atenolol within 365 days and 30 days before the index start date. By itself, a *criteria* makes little sense. It must sit within the context of the entire cohort definition, where an index event has been specified. In `Capr` the *criteria* object is called in three ways: `atLeast`, `atMost` and `exactly`. The *criteria* object in `Capr` is contextualized by the number of occurrences of the query for its function call. If we wanted to have exactly 2 drug exposures of atenolol or at most 2 drug exposures they can be done as shown below. + +```{r criteriaExampleB, eval=FALSE} +atenololConceptSet <- cs(descendants(1314002), name - "atenolol") + +atenololCriteriaA <- exactly( + x = 2, + query = drugExposure(atenololConceptSet), + aperture = duringInterval( + startWindow = eventStarts(a = -365, b = -30, index = "startDate") + ) +) + +atenololCriteriaB <- atMost( + x = 2, + query = drugExposure(atenololConceptSet), + aperture = duringInterval( + startWindow = eventStarts(a = -365, b = -30, index = "startDate") + ) +) + +``` + +## Aperture + +An important part of the *criteria* object is providing the temporal context to enumerating the occurrences of the query. In `Capr` we term this interval relative to index as the aperture. It is the opening in the patient timeline at which we are enumerating the event of interest. An aperture can view when an event starts and when the event ends. For both event start and event end, we define a window for which the event is observed. Below we illustrate a few examples of building an aperture and then show the corresponding the `Capr` code. + +![Example 1: Retrospective Start Window](images/aperture1.png) +In this first example we are observing when an event starts between time of 365 to 30 days before the index start date. To build this aperture we use the following `Capr` code: + +```{r aperture1, eval=FALSE} +aperture1 <- duringInterval( + startWindow = eventStarts(a = -365, b = -30, index = "startDate") +) +``` + +Notice that we define the anchor for our index, either the index start date or the index end date. More times than not this will be the index start date. + +![Example 2: Retrospective Start Window all time prior](images/aperture2.png) +This next example is similar to the first, however now we have an unbounded event window. In this case the event start must be between any time before and 30 days before the index start date. In `Capr` we can always create an unbounded event window by using the `Inf` operator in our code, as shown below. + +```{r aperture2, eval=FALSE} +aperture2 <- duringInterval( + startWindow = eventStarts(a = -Inf, b = -30, index = "startDate") +) +``` + +![Example 3: Start window including future time](images/aperture3.png) +Our next example provides an instance where we want our event window to utilize future time. Normally we want to observe an event prior to index. On occasion we can allow for an event to take place after index. The `Capr` code to build this aperture is shown below: + +```{r aperture3, eval=FALSE} +aperture3 <- duringInterval( + startWindow = eventStarts(a = -30, b = 30, index = "startDate") +) +``` + +![Example 4: Start and end window in aperture](images/aperture4.png) +Our final example shows a scenario when we want the aperture to be constrained by both a start window and end window. The end window is considering observation of the end of the event. Say for example the event era starts with an exposure to a drug and end is when the person stops taking the drug. If the interest is the full time the person was encountering this medical event we need to create both a start and end window in the aperture. The `Capr` code below would replicate the concept from the figure. + +```{r aperture4, eval=FALSE} +aperture4 <- duringInterval( + startWindow = eventStarts(a = -365, b = -30, index = "startDate"), + endWindow = eventEnds(a = 30, b = 365, index = "startDate") +) +``` + +An aperture has two more potential toggles: a) restrict event to the same visit and b) allow events outside the observation period. By default these options are toggled as `FALSE`, so they do not need to be defined in the `Capr` code unless made `TRUE`. These are more advanced options in cohort building. To use the we add this to aperture example 4 to show a full set of options for an aperture in `Capr`: + +```{r aperture5, eval=FALSE} +aperture5 <- duringInterval( + startWindow = eventStarts(a = -365, b = -30, index = "startDate"), + endWindow = eventEnds(a = 30, b = 365, index = "startDate"), + restrictVisit = TRUE, + ignoreObservationPeriod = TRUE +) +``` + +# Group + +## Definition + +A *group* object is one that binds multiple criteria and sub-groups as a single expression. This is a very powerful construction because it allows us to build all sorts of complexity in our cohort definition. A *group* must have an operator informing how many *criteria* must be `TRUE` in order for the person to enter the cohort. In `Capr` the options available to build a group are: `withAll`, `withAny`, `withAtLeast` and `withAtMost`. The functions are meant to be intuitive in terms of logic building. `withAll` indicates all the criteria must be `TRUE` for the person to remain in the cohort. `withAny` indicates any one of the *criteria* needs to be `TRUE`. The functions `withAtLeast` and `withAtMost` require an integer to determine how many *criteria* must be `TRUE`. + +## Example + +To show the idea of a *group* let us consider a very complicated cohort, like the [PheKB T2D case algorithm](https://www.phekb.org/phenotype/type-2-diabetes-mellitus). To consider a person to be a case of T2D, any one of 5 pathways needs to be `TRUE`. + +```{r t2dAlgo, eval=FALSE} +t2dAlgo <- withAny( + # Path 1: 0 T2Dx + 1 T2Rx + 1 abLab + withAll( + exactly(0, + t2d, + duringInterval(startWindow = eventStarts(-Inf, 0)) + ), + atLeast(1, + t2dDrug, + duringInterval(startWindow = eventStarts(-Inf, 0)) + ), + withAny( + atLeast(1, + abLabHb, + duringInterval(startWindow = eventStarts(-Inf, 0)) + ), + atLeast(1, + abLabRan, + duringInterval(startWindow = eventStarts(-Inf, 0)) + ), + atLeast(1, + abLabFast, + duringInterval(startWindow = eventStarts(-Inf, 0)) + ) + ) + ), + #Path 2: 1 T2Dx + 0 T1Rx + 0 T2Rx + 1 AbLab + withAll( + atLeast(1, + t2d, + duringInterval(startWindow = eventStarts(-Inf, 0)) + ), + exactly(0, + t1dDrug, + duringInterval(startWindow = eventStarts(-Inf, 0)) + ), + exactly(0, + t2dDrug, + duringInterval(startWindow = eventStarts(-Inf, 0)) + ), + withAny( + atLeast(1, + abLabHb, + duringInterval(startWindow = eventStarts(-Inf, 0)) + ), + atLeast(1, + abLabRan, + duringInterval(startWindow = eventStarts(-Inf, 0)) + ), + atLeast(1, + abLabFast, + duringInterval(startWindow = eventStarts(-Inf, 0)) + ) + ) + ), + #Path 3: 1 T2Dx + 0 T1Rx + 1 T2Rx + withAll( + atLeast(1, + t2d, + duringInterval(startWindow = eventStarts(-Inf, 0)) + ), + exactly(0, + t1dDrug, + duringInterval(startWindow = eventStarts(-Inf, 0)) + ), + atLeast(1, + t2dDrug, + duringInterval(startWindow = eventStarts(-Inf, 0)) + ) + ), + #Path 4: 1 T2Dx + 1 T1Rx + 1 T1Rx|T2Rx + withAll( + atLeast(1, + t2d, + duringInterval(startWindow = eventStarts(-Inf, 0)) + ), + atLeast(1, + t1dDrug, + duringInterval(startWindow = eventStarts(-Inf, 0)) + ), + atLeast(1, + t1dDrugWT2Drug, + duringInterval(startWindow = eventStarts(-Inf, 0)) + ) + ), + #Path 5: 1 T2Dx + 1 T1Rx + 0 T2Rx + 2 T2Dx + withAll( + atLeast(1, + t2d, + duringInterval(startWindow = eventStarts(-Inf, 0)) + ), + atLeast(1, + t1dDrug, + duringInterval(startWindow = eventStarts(-Inf, 0)) + ), + exactly(0, + t2dDrug, + duringInterval(startWindow = eventStarts(-Inf, 0)) + ), + atLeast(2, + t2d, + duringInterval(startWindow = eventStarts(-Inf, 0)) + ) + ) +) +``` + +Each pathway is complex and require multiple criteria to determine a T2D case. The *group* allows us to bundle multiple ideas together to build one complex expression. + +## Notes + +Now that we have introduced the *criteria* and *group*, there are a few important comments on how these objects are used within `circe-be`. + +**1) Criteria must be placed within a group** + +A *criteria* can not be used on its own, it must be wrapped in a *group*. Even if only one *criteria* is needed, still wrap it in a *group*. An example would be: + +```{r criteriaInGroup, eval=FALSE} +noT1d <- withAll( + # criteria: no t1d prior + exactly( + x = 0, + query = conditionOccurrence(t1dConceptSet), + aperture = duringInterval( + startWindow = eventStarts(a = -Inf, b = 0, index = "startDate") + ) + ) +) +# wrap this in a group withAll +``` + +Further to this point, a single attrition rule is a *group*. The example of `noT1d` above would be a single rule in the cohort attrition. This is how we would apply it: + +```{r cohortAttrition, eval=FALSE} +cohort <- cohort( + entry = entry( + # index event.... + ), + attrition = attrition( + 'noT1d' = withAll( + exactly( + x = 0, + # query for t1d occurrence to exclude patients + query = conditionOccurrence(t1dConceptSet), + aperture = duringInterval( + startWindow = eventStarts(a = -Inf, b = 0, index = "startDate") + ) + ) + ) + ), + exit = exit( + #cohort exit.... + ) +) +``` + + +**2) Groups may contain groups** + +A group may contain more groups as part of the same object. We saw this in the PheKB T2D example where one path required an abnormal lab. In the definition there are 3 types of abnormal labs: random glucose, fasting glucose and HbA1c. Any one of these three could be abnormal as part of path 1 of the case algorithm. To build this we need a group within a group. + +```{r groupInGroup, eval=FALSE} +# Path 1: 0 T2Dx + 1 T2Rx + 1 abLab +path1 <- withAll( + exactly(0, + t2d, + duringInterval(startWindow = eventStarts(-Inf, 0)) + ), + atLeast(1, + t2dDrug, + duringInterval(startWindow = eventStarts(-Inf, 0)) + ), + withAny( + atLeast(1, + abLabHb, + duringInterval(startWindow = eventStarts(-Inf, 0)) + ), + atLeast(1, + abLabRan, + duringInterval(startWindow = eventStarts(-Inf, 0)) + ), + atLeast(1, + abLabFast, + duringInterval(startWindow = eventStarts(-Inf, 0)) + ) + ) +) +``` + +**3) Nested criteria are groups** + +Previously we mentioned a special kind of attribute called a nested criteria (also known via ATLAS as a correlated criteria). The idea of a nested criteria is that the index event is based on a particular concept set expression as opposed to the entry event of the cohort definition. For example, we want to build a cohort based on a hospitalization due to heart failure. In this case a person is counted in the cohort if they have first an inpatient visit given that a heart failure (HF) diagnosis has occurred around the time of the inpatient visit. In `Capr` a nested attribute uses the same syntax as a *group* with a prefix of `nested-`, as shown in the example below. The enumeration of the *criteria* is now indexed based on the inpatient visit rather than the entry event of the cohort definition. + +```{r hospHf, eval=FALSE} +ipCse <- cs(descendants(9201, 9203, 262), name = "visit") +hf <- cs(descendants(316139), name = "heart failure") + +query <- visit( + ipCse, #index + #nested attribute + nestedWithAll( + atLeast(1, + conditionOccurrence(hf), + duringInterval( + startWindow = eventStarts(0, Inf, index = "startDate"), + endWindow = eventStarts(-Inf, 0, index = "endDate") + ) + ) + ) +) +``` + +# Concluding Remarks + +For more information on sub-components of a cohort definition via `circe-be`, users should watch the [videos](https://www.youtube.com/@chrisknoll2007) created by Chris Knoll outlining these ideas. while these videos utilize ATLAS, `Capr` follows the same principles. diff --git a/vignettes/capr_templates.Rmd b/vignettes/capr_templates.Rmd index c79a569b..d21c4485 100644 --- a/vignettes/capr_templates.Rmd +++ b/vignettes/capr_templates.Rmd @@ -10,12 +10,13 @@ vignette: > ```{r, include = FALSE} knitr::opts_chunk$set( collapse = TRUE, - comment = "#>" + comment = "#>", + eval = FALSE ) ``` -```{r setup} +```{r setup, echo=FALSE} library(Capr) ``` @@ -30,7 +31,7 @@ To build all these cohorts using a template, we can easily define the logic in C cvEvents <- function(conceptSet) { cd <- cohort( entry = entry( - condition(conceptSet), + conditionOccurrence(conceptSet), observationWindow = continuousObservation(365, 0) ), exit = exit( @@ -71,7 +72,7 @@ cvEvents2 <- function(conceptSet) { #Capr template logic cd <- cohort( entry = entry( - condition(conceptSet), + conditionOccurrence(conceptSet), observationWindow = continuousObservation(365, 0) ), exit = exit( @@ -105,7 +106,7 @@ cvEvents3 <- function(file) { #Capr template logic cd <- cohort( entry = entry( - condition(conceptSet), + conditionOccurrence(conceptSet), observationWindow = continuousObservation(365, 0) ), exit = exit( diff --git a/vignettes/images/aperture1.png b/vignettes/images/aperture1.png new file mode 100644 index 00000000..b48c043d Binary files /dev/null and b/vignettes/images/aperture1.png differ diff --git a/vignettes/images/aperture2.png b/vignettes/images/aperture2.png new file mode 100644 index 00000000..568f2d3b Binary files /dev/null and b/vignettes/images/aperture2.png differ diff --git a/vignettes/images/aperture3.png b/vignettes/images/aperture3.png new file mode 100644 index 00000000..ff21a0c2 Binary files /dev/null and b/vignettes/images/aperture3.png differ diff --git a/vignettes/images/aperture4.png b/vignettes/images/aperture4.png new file mode 100644 index 00000000..372e0548 Binary files /dev/null and b/vignettes/images/aperture4.png differ diff --git a/vignettes/images/criteria_example.png b/vignettes/images/criteria_example.png new file mode 100644 index 00000000..bb02c0b6 Binary files /dev/null and b/vignettes/images/criteria_example.png differ