diff --git a/NEWS.md b/NEWS.md index d9aade4f..958bd27d 100644 --- a/NEWS.md +++ b/NEWS.md @@ -2,8 +2,7 @@ Capr 2.0.4 ========== - 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 +- improve documentation (add vignette for query, count and group) Capr 2.0.3 ========== diff --git a/README.md b/README.md index b0fe528c..a26f35fb 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,235 +24,6 @@ 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 @@ -265,6 +31,7 @@ Documentation can be found on the [package website](https://ohdsi.github.io/Capr - Vignette: [Using Capr](https://ohdsi.github.io/Capr/articles/Using-Capr.html) - Vignette: [Examples](https://ohdsi.github.io/Capr/articles/Examples.html) +- Vignette: [Capr Components](https://ohdsi.github.io/Capr/articles/capr_objects.html) - [Design Document](https://ohdsi.github.io/Capr/articles/capr_design.html) - [Package manual](https://raw.githubusercontent.com/OHDSI/Capr/main/extras/Capr.pdf) diff --git a/docs/404.html b/docs/404.html index 8e77d518..3ff3c9eb 100644 --- a/docs/404.html +++ b/docs/404.html @@ -39,7 +39,7 @@ Capr - 2.0.3 + 2.0.4 @@ -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 d32362fd..4b209b03 100644 --- a/docs/LICENSE.html +++ b/docs/LICENSE.html @@ -17,7 +17,7 @@ Capr - 2.0.3 + 2.0.4 @@ -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 d30736e1..09d0f467 100644 --- a/docs/articles/Capr-conceptSets.html +++ b/docs/articles/Capr-conceptSets.html @@ -40,7 +40,7 @@ Capr - 2.0.3 + 2.0.4 @@ -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 746f3023..95445424 100644 --- a/docs/articles/Examples.html +++ b/docs/articles/Examples.html @@ -40,7 +40,7 @@ Capr - 2.0.3 + 2.0.4 @@ -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 e7768036..5caa98b9 100644 --- a/docs/articles/Using-Capr.html +++ b/docs/articles/Using-Capr.html @@ -40,7 +40,7 @@ Capr - 2.0.3 + 2.0.4 @@ -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 371b3490..2f973470 100644
    --- a/docs/articles/capr_design.html
    +++ b/docs/articles/capr_design.html
    @@ -40,7 +40,7 @@
           
           
             Capr
    -        2.0.3
    +        2.0.4
           
         
     
    @@ -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..da400225 --- /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 e34a05f3..9b30b2f2 100644 --- a/docs/articles/capr_templates.html +++ b/docs/articles/capr_templates.html @@ -40,7 +40,7 @@ Capr - 2.0.3 + 2.0.4 @@ -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 1a3c329e..4d0d0bec 100644 --- a/docs/articles/index.html +++ b/docs/articles/index.html @@ -17,7 +17,7 @@ Capr - 2.0.3 + 2.0.4
    @@ -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 872a81d1..4031af47 100644 --- a/docs/authors.html +++ b/docs/authors.html @@ -17,7 +17,7 @@ Capr - 2.0.3 + 2.0.4
    @@ -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 b7a41b8e..53bc38af 100644 --- a/docs/index.html +++ b/docs/index.html @@ -46,7 +46,7 @@ Capr - 2.0.3 + 2.0.4
    @@ -68,6 +68,9 @@
  • Capr Design Guide and Roadmap
  • +
  • + Capr Objects +
  • Capr for Templating Cohort Definitions
  • @@ -124,240 +127,12 @@

    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.

    @@ -366,6 +141,8 @@

    User DocumentationExamples +
  • Vignette: Capr Components +
  • Design Document
  • Package manual
  • diff --git a/docs/news/index.html b/docs/news/index.html index 175240ef..596acc75 100644 --- a/docs/news/index.html +++ b/docs/news/index.html @@ -17,7 +17,7 @@ Capr - 2.0.3 + 2.0.4

    @@ -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)
    • +
    • add opAttribute super class
    • diff --git a/docs/pkgdown.yml b/docs/pkgdown.yml index 57be44bf..0b5532a2 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-05-16T16:57Z +last_built: 2023-07-03T17:05Z diff --git a/docs/reference/Capr-package.html b/docs/reference/Capr-package.html index 8d952c1b..376a1aff 100644 --- a/docs/reference/Capr-package.html +++ b/docs/reference/Capr-package.html @@ -18,7 +18,7 @@ Capr - 2.0.3 + 2.0.4
    @@ -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 63ca44d9..6d8e5971 100644 --- a/docs/reference/CensoringCriteria-class.html +++ b/docs/reference/CensoringCriteria-class.html @@ -19,7 +19,7 @@ Capr - 2.0.3 + 2.0.4
    @@ -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 ec6462ce..da7bf9d1 100644 --- a/docs/reference/Concept-class.html +++ b/docs/reference/Concept-class.html @@ -17,7 +17,7 @@ Capr - 2.0.3 + 2.0.4

    @@ -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 36dc442d..cca25a68 100644 --- a/docs/reference/ConceptAttribute-class.html +++ b/docs/reference/ConceptAttribute-class.html @@ -17,7 +17,7 @@ Capr - 2.0.3 + 2.0.4

    @@ -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 567a9f9b..729e1ef5 100644 --- a/docs/reference/ConceptSet-class.html +++ b/docs/reference/ConceptSet-class.html @@ -17,7 +17,7 @@ Capr - 2.0.3 + 2.0.4

    @@ -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 ead9e5df..ed7a11f0 100644 --- a/docs/reference/ConceptSetItem-class.html +++ b/docs/reference/ConceptSetItem-class.html @@ -17,7 +17,7 @@ Capr - 2.0.3 + 2.0.4 @@ -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 5b3e4674..a0b31fba 100644 --- a/docs/reference/Criteria-class.html +++ b/docs/reference/Criteria-class.html @@ -17,7 +17,7 @@ Capr - 2.0.3 + 2.0.4 @@ -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 421249c3..96147df2 100644 --- a/docs/reference/DrugExposureExit-class.html +++ b/docs/reference/DrugExposureExit-class.html @@ -24,7 +24,7 @@ Capr - 2.0.3 + 2.0.4 @@ -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 89682386..6839d1b2 100644 --- a/docs/reference/Endpoint-class.html +++ b/docs/reference/Endpoint-class.html @@ -17,7 +17,7 @@ Capr - 2.0.3 + 2.0.4 @@ -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 a039c252..4fed21a5 100644 --- a/docs/reference/EventAperture-class.html +++ b/docs/reference/EventAperture-class.html @@ -17,7 +17,7 @@ Capr - 2.0.3 + 2.0.4 @@ -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 d6bc596d..2ab2f469 100644 --- a/docs/reference/EventWindow-class.html +++ b/docs/reference/EventWindow-class.html @@ -17,7 +17,7 @@ Capr - 2.0.3 + 2.0.4 @@ -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 17ff4fe0..8316afb9 100644 --- a/docs/reference/FixedDurationExit-class.html +++ b/docs/reference/FixedDurationExit-class.html @@ -24,7 +24,7 @@ Capr - 2.0.3 + 2.0.4 @@ -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 f0a55db1..a904ba94 100644 --- a/docs/reference/Group-class.html +++ b/docs/reference/Group-class.html @@ -17,7 +17,7 @@ Capr - 2.0.3 + 2.0.4 @@ -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 0c38c8f7..1b5c0bda 100644 --- a/docs/reference/LogicAttribute-class.html +++ b/docs/reference/LogicAttribute-class.html @@ -17,7 +17,7 @@ Capr - 2.0.3 + 2.0.4 @@ -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 34aeb7ad..f57274d4 100644 --- a/docs/reference/ObservationExit-class.html +++ b/docs/reference/ObservationExit-class.html @@ -17,7 +17,7 @@ Capr - 2.0.3 + 2.0.4 @@ -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 059cb170..36f250d7 100644 --- a/docs/reference/ObservationWindow-class.html +++ b/docs/reference/ObservationWindow-class.html @@ -18,7 +18,7 @@ Capr - 2.0.3 + 2.0.4 @@ -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 9a11af5f..c2dacb14 100644 --- a/docs/reference/Occurrence-class.html +++ b/docs/reference/Occurrence-class.html @@ -18,7 +18,7 @@ Capr - 2.0.3 + 2.0.4 @@ -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 67d137c4..ee30d3d5 100644 --- a/docs/reference/Query-class.html +++ b/docs/reference/Query-class.html @@ -18,7 +18,7 @@ Capr - 2.0.3 + 2.0.4 @@ -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 ae190652..547e7e6e 100644 --- a/docs/reference/age.html +++ b/docs/reference/age.html @@ -17,7 +17,7 @@ Capr - 2.0.3 + 2.0.4 @@ -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 f9ee8ae3..80ce0b9b 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.3 + 2.0.4 @@ -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 c1a78029..dddc2427 100644 --- a/docs/reference/as.json.html +++ b/docs/reference/as.json.html @@ -17,7 +17,7 @@ Capr - 2.0.3 + 2.0.4 @@ -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 9ad74f39..b05076e9 100644 --- a/docs/reference/atLeast.html +++ b/docs/reference/atLeast.html @@ -17,7 +17,7 @@ Capr - 2.0.3 + 2.0.4 @@ -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 50e0ef9a..2a3c8457 100644 --- a/docs/reference/atMost.html +++ b/docs/reference/atMost.html @@ -17,7 +17,7 @@ Capr - 2.0.3 + 2.0.4 @@ -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 8e92577f..e8d5fdec 100644 --- a/docs/reference/attributes.html +++ b/docs/reference/attributes.html @@ -18,7 +18,7 @@ Capr - 2.0.3 + 2.0.4 @@ -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 f1d76b7a..da34f88a 100644 --- a/docs/reference/attrition.html +++ b/docs/reference/attrition.html @@ -17,7 +17,7 @@ Capr - 2.0.3 + 2.0.4 @@ -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 f6418206..21b97261 100644 --- a/docs/reference/bt.html +++ b/docs/reference/bt.html @@ -17,7 +17,7 @@ Capr - 2.0.3 + 2.0.4 @@ -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 60ec57fa..84f44ac4 100644 --- a/docs/reference/censoringEvents.html +++ b/docs/reference/censoringEvents.html @@ -17,7 +17,7 @@ Capr - 2.0.3 + 2.0.4 @@ -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 be258bea..d213a669 100644 --- a/docs/reference/cohort.html +++ b/docs/reference/cohort.html @@ -17,7 +17,7 @@ Capr - 2.0.3 + 2.0.4 @@ -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 b4d09855..d73df46d 100644 --- a/docs/reference/compile.Cohort.html +++ b/docs/reference/compile.Cohort.html @@ -17,7 +17,7 @@ Capr - 2.0.3 + 2.0.4 @@ -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 6737cca4..c5f21baf 100644 --- a/docs/reference/conditionEra.html +++ b/docs/reference/conditionEra.html @@ -17,7 +17,7 @@ Capr - 2.0.3 + 2.0.4
    @@ -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..ca91d978 --- /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 f0f56443..ec673875 100644 --- a/docs/reference/continuousObservation.html +++ b/docs/reference/continuousObservation.html @@ -17,7 +17,7 @@ Capr - 2.0.3 + 2.0.4 @@ -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 aff60d0e..8d70ea30 100644 --- a/docs/reference/cs.html +++ b/docs/reference/cs.html @@ -20,7 +20,7 @@ Capr - 2.0.3 + 2.0.4 @@ -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 2692b57a..c57f5ba2 100644
    --- a/docs/reference/daysOfSupply.html
    +++ b/docs/reference/daysOfSupply.html
    @@ -19,7 +19,7 @@
           
           
             Capr
    -        2.0.3
    +        2.0.4
           
         
    @@ -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 65e28f54..572db088 100644 --- a/docs/reference/death.html +++ b/docs/reference/death.html @@ -17,7 +17,7 @@ Capr - 2.0.3 + 2.0.4
    @@ -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 e4cc9b93..b6f0949d 100644 --- a/docs/reference/drugEra.html +++ b/docs/reference/drugEra.html @@ -17,7 +17,7 @@ Capr - 2.0.3 + 2.0.4
    @@ -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 f0d743c6..1a4b46b6 100644 --- a/docs/reference/drugExit.html +++ b/docs/reference/drugExit.html @@ -17,7 +17,7 @@ Capr - 2.0.3 + 2.0.4 @@ -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..d4094fdc --- /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 75e2053f..aa2078bb 100644 --- a/docs/reference/drugQuantity.html +++ b/docs/reference/drugQuantity.html @@ -19,7 +19,7 @@ Capr - 2.0.3 + 2.0.4 @@ -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 ab064347..c66fb3df 100644 --- a/docs/reference/drugRefills.html +++ b/docs/reference/drugRefills.html @@ -19,7 +19,7 @@ Capr - 2.0.3 + 2.0.4 @@ -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 2f854701..4387ccb2 100644 --- a/docs/reference/duringInterval.html +++ b/docs/reference/duringInterval.html @@ -20,7 +20,7 @@ Capr - 2.0.3 + 2.0.4 @@ -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 4a0ca725..79fb7ca5 100644 --- a/docs/reference/endDate.html +++ b/docs/reference/endDate.html @@ -17,7 +17,7 @@ Capr - 2.0.3 + 2.0.4 @@ -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 9dbf90f4..29ca5516 100644 --- a/docs/reference/entry.html +++ b/docs/reference/entry.html @@ -17,7 +17,7 @@ Capr - 2.0.3 + 2.0.4 @@ -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 cad9e5c5..69bd9109 100644 --- a/docs/reference/eq.html +++ b/docs/reference/eq.html @@ -17,7 +17,7 @@ Capr - 2.0.3 + 2.0.4 @@ -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 31171dae..c13ea7cc 100644 --- a/docs/reference/equals-methods.html +++ b/docs/reference/equals-methods.html @@ -17,7 +17,7 @@ Capr - 2.0.3 + 2.0.4 @@ -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 52cb8030..d75c3277 100644 --- a/docs/reference/era.html +++ b/docs/reference/era.html @@ -19,7 +19,7 @@ Capr - 2.0.3 + 2.0.4 @@ -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 0de517d8..fed53a1c 100644 --- a/docs/reference/eventEnds.html +++ b/docs/reference/eventEnds.html @@ -17,7 +17,7 @@ Capr - 2.0.3 + 2.0.4 @@ -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 757e529b..22ccc4e8 100644 --- a/docs/reference/eventStarts.html +++ b/docs/reference/eventStarts.html @@ -37,7 +37,7 @@ Capr - 2.0.3 + 2.0.4 @@ -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 5690cce2..434b371f 100644 --- a/docs/reference/exactly.html +++ b/docs/reference/exactly.html @@ -17,7 +17,7 @@ Capr - 2.0.3 + 2.0.4 @@ -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 61ab9b17..77ffc707 100644 --- a/docs/reference/exit.html +++ b/docs/reference/exit.html @@ -17,7 +17,7 @@ Capr - 2.0.3 + 2.0.4 @@ -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 c0976177..1588ad6c 100644 --- a/docs/reference/firstOccurrence.html +++ b/docs/reference/firstOccurrence.html @@ -17,7 +17,7 @@ Capr - 2.0.3 + 2.0.4 @@ -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 121a3d91..5bf71749 100644 --- a/docs/reference/fixedExit.html +++ b/docs/reference/fixedExit.html @@ -17,7 +17,7 @@ Capr - 2.0.3 + 2.0.4 @@ -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 cfba9d40..28ade8ae 100644 --- a/docs/reference/generateCaprTemplate.html +++ b/docs/reference/generateCaprTemplate.html @@ -17,7 +17,7 @@ Capr - 2.0.3 + 2.0.4 @@ -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 685a6d5c..176afb64 100644 --- a/docs/reference/getConceptSetCall.html +++ b/docs/reference/getConceptSetCall.html @@ -17,7 +17,7 @@ Capr - 2.0.3 + 2.0.4 @@ -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 9ae46cd1..9ae8f6ed 100644 --- a/docs/reference/getConceptSetDetails.html +++ b/docs/reference/getConceptSetDetails.html @@ -19,7 +19,7 @@ Capr - 2.0.3 + 2.0.4 @@ -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 8c2748d4..98c3f89b 100644 --- a/docs/reference/gt.html +++ b/docs/reference/gt.html @@ -17,7 +17,7 @@ Capr - 2.0.3 + 2.0.4 @@ -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 8aa35db1..7a2a8003 100644 --- a/docs/reference/gte.html +++ b/docs/reference/gte.html @@ -17,7 +17,7 @@ Capr - 2.0.3 + 2.0.4 @@ -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 f92ad78d..da3735c8 100644 --- a/docs/reference/index.html +++ b/docs/reference/index.html @@ -17,7 +17,7 @@ Capr - 2.0.3 + 2.0.4 @@ -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 5df60318..6c065fb0 100644 --- a/docs/reference/lt.html +++ b/docs/reference/lt.html @@ -17,7 +17,7 @@ Capr - 2.0.3 + 2.0.4 @@ -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 37bc4a00..d031a7e5 100644 --- a/docs/reference/lte.html +++ b/docs/reference/lte.html @@ -17,7 +17,7 @@ Capr - 2.0.3 + 2.0.4 @@ -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 7ff213df..06c8423e 100644 --- a/docs/reference/measurement.html +++ b/docs/reference/measurement.html @@ -17,7 +17,7 @@ Capr - 2.0.3 + 2.0.4 @@ -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 f8f7a5f2..e016e2bc 100644 --- a/docs/reference/nbt.html +++ b/docs/reference/nbt.html @@ -17,7 +17,7 @@ Capr - 2.0.3 + 2.0.4 @@ -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 0e266f60..da0e13de 100644 --- a/docs/reference/nestedAttribute-class.html +++ b/docs/reference/nestedAttribute-class.html @@ -17,7 +17,7 @@ Capr - 2.0.3 + 2.0.4 @@ -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 5744081d..ae24ff47 100644 --- a/docs/reference/nestedWithAll.html +++ b/docs/reference/nestedWithAll.html @@ -17,7 +17,7 @@ Capr - 2.0.3 + 2.0.4 @@ -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 98574357..0d87e094 100644 --- a/docs/reference/nestedWithAny.html +++ b/docs/reference/nestedWithAny.html @@ -17,7 +17,7 @@ Capr - 2.0.3 + 2.0.4 @@ -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 bb23cc52..1641114a 100644 --- a/docs/reference/nestedWithAtLeast.html +++ b/docs/reference/nestedWithAtLeast.html @@ -20,7 +20,7 @@ Capr - 2.0.3 + 2.0.4 @@ -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 4c5f9708..62c49fdd 100644 --- a/docs/reference/nestedWithAtMost.html +++ b/docs/reference/nestedWithAtMost.html @@ -17,7 +17,7 @@ Capr - 2.0.3 + 2.0.4 @@ -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 f5384cbc..bf4b4c28 100644 --- a/docs/reference/observation.html +++ b/docs/reference/observation.html @@ -17,7 +17,7 @@ Capr - 2.0.3 + 2.0.4 @@ -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 a8ba449b..5829078b 100644 --- a/docs/reference/observationExit.html +++ b/docs/reference/observationExit.html @@ -17,7 +17,7 @@ Capr - 2.0.3 + 2.0.4 @@ -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 96e71078..c5749b70 100644 --- a/docs/reference/opAttributeDate-class.html +++ b/docs/reference/opAttributeDate-class.html @@ -17,7 +17,7 @@ Capr - 2.0.3 + 2.0.4 @@ -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 620206c1..b29f312d 100644 --- a/docs/reference/opAttributeInteger-class.html +++ b/docs/reference/opAttributeInteger-class.html @@ -17,7 +17,7 @@ Capr - 2.0.3 + 2.0.4 @@ -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 114566d2..cf30d5e0 100644 --- a/docs/reference/opAttributeNumeric-class.html +++ b/docs/reference/opAttributeNumeric-class.html @@ -17,7 +17,7 @@ Capr - 2.0.3 + 2.0.4 @@ -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 794d89d1..50ea260c 100644 --- a/docs/reference/opAttributeSuper-class.html +++ b/docs/reference/opAttributeSuper-class.html @@ -17,7 +17,7 @@ Capr - 2.0.3 + 2.0.4 @@ -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 ebc99484..182dbbd4 100644 --- a/docs/reference/pipe.html +++ b/docs/reference/pipe.html @@ -17,7 +17,7 @@ Capr - 2.0.3 + 2.0.4 @@ -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 6dbfc5b2..187516fa 100644 --- a/docs/reference/procedure.html +++ b/docs/reference/procedure.html @@ -17,7 +17,7 @@ Capr - 2.0.3 + 2.0.4 @@ -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 73f0c986..f911b021 100644 --- a/docs/reference/rangeHigh.html +++ b/docs/reference/rangeHigh.html @@ -19,7 +19,7 @@ Capr - 2.0.3 + 2.0.4 @@ -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 10fcedbf..f6ebc422 100644 --- a/docs/reference/rangeLow.html +++ b/docs/reference/rangeLow.html @@ -19,7 +19,7 @@ Capr - 2.0.3 + 2.0.4 @@ -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 9a9dd1c3..b03fca37 100644 --- a/docs/reference/readConceptSet.html +++ b/docs/reference/readConceptSet.html @@ -18,7 +18,7 @@ Capr - 2.0.3 + 2.0.4 @@ -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 63d7a5e7..6c6e492e 100644 --- a/docs/reference/startDate.html +++ b/docs/reference/startDate.html @@ -17,7 +17,7 @@ Capr - 2.0.3 + 2.0.4 @@ -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 02ba9da1..3be111e6 100644 --- a/docs/reference/toCirce.html +++ b/docs/reference/toCirce.html @@ -17,7 +17,7 @@ Capr - 2.0.3 + 2.0.4 @@ -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 dfe9b3bc..a2a09c9f 100644 --- a/docs/reference/unit.html +++ b/docs/reference/unit.html @@ -17,7 +17,7 @@ Capr - 2.0.3 + 2.0.4 @@ -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 f1f26778..a9d76c7e 100644 --- a/docs/reference/valueAsNumber.html +++ b/docs/reference/valueAsNumber.html @@ -19,7 +19,7 @@ Capr - 2.0.3 + 2.0.4 @@ -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 cc9eba30..9a082fa9 100644 --- a/docs/reference/visit.html +++ b/docs/reference/visit.html @@ -17,7 +17,7 @@ Capr - 2.0.3 + 2.0.4 @@ -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 6eeecd7c..0a8103f6 100644 --- a/docs/reference/withAll.html +++ b/docs/reference/withAll.html @@ -17,7 +17,7 @@ Capr - 2.0.3 + 2.0.4 @@ -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 8e167f45..1d867283 100644 --- a/docs/reference/withAny.html +++ b/docs/reference/withAny.html @@ -17,7 +17,7 @@ Capr - 2.0.3 + 2.0.4 @@ -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 321fc12d..ddec3f6b 100644 --- a/docs/reference/withAtLeast.html +++ b/docs/reference/withAtLeast.html @@ -17,7 +17,7 @@ Capr - 2.0.3 + 2.0.4 @@ -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 cefbdb17..fd94313c 100644 --- a/docs/reference/withAtMost.html +++ b/docs/reference/withAtMost.html @@ -17,7 +17,7 @@ Capr - 2.0.3 + 2.0.4 @@ -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 5a2d544f..2f562127 100644 --- a/docs/reference/writeCohort.html +++ b/docs/reference/writeCohort.html @@ -17,7 +17,7 @@ Capr - 2.0.3 + 2.0.4 @@ -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 5855377e..328559fa 100644 --- a/docs/reference/writeConceptSet.html +++ b/docs/reference/writeConceptSet.html @@ -17,7 +17,7 @@ Capr - 2.0.3 + 2.0.4 @@ -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 06b1bcb0..e4c8fb11 100644 Binary files a/extras/Capr.pdf and b/extras/Capr.pdf differ diff --git a/extras/PackageMaintenance.R b/extras/PackageMaintenance.R index 86463c33..b1fbd06e 100644 --- a/extras/PackageMaintenance.R +++ b/extras/PackageMaintenance.R @@ -64,12 +64,17 @@ unlink("extras/pdf_vignette/capr_templates.tex") # capr concept sets -dir.create(path = "./extras/pdf_vignette/", showWarnings = FALSE) +#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 10e844f7..1e18e143 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 8f64fa66..18618cad 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 cff66093..d661dae1 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 e2d4c751..3796f074 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..f6f803ed 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 c310de2d..9301992e 100644 Binary files a/extras/pdf_vignette/capr_templates.pdf and b/extras/pdf_vignette/capr_templates.pdf differ diff --git a/tests/testthat/test-nest.R b/tests/testthat/test-nest.R index 4e70c704..f85a33d5 100644 --- a/tests/testthat/test-nest.R +++ b/tests/testthat/test-nest.R @@ -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( 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 index f514dd97..0e3df579 100644 --- a/vignettes/capr_objects.Rmd +++ b/vignettes/capr_objects.Rmd @@ -49,7 +49,7 @@ knitr::kable(tb) A simple example of how to use a query in `Capr` can be seen below: -```{r} +```{r queryEx, eval=FALSE} t1dConceptSet <- cs(descendants(195771), name = "T1D") t1dQuery <- conditionOccurrence(t1dConceptSet) ``` @@ -57,13 +57,14 @@ 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} +```{r queryInCohort, eval=FALSE} metforminConceptSet <- cs(descendants(1503297), name = "metformin") t1dConceptSet <- cs(descendants(195771), name = "T1D") metforminCohort <- cohort( entry = entry( - drugExposure(metforminConceptSet, firstOccurrence()), # metformin drug query as index event + # metformin drug query as index event + drugExposure(metforminConceptSet, firstOccurrence()), observationWindow = continuousObservation(priorDays = -365, postDays = 365L), primaryCriteriaLimit = "All" ), @@ -71,15 +72,20 @@ metforminCohort <- cohort( 'noT1d' = withAll( exactly( x = 0, - query = conditionOccurrence(t1dConceptSet), # query for t1d occurrence to exclude patients - aperture = duringInterval(startWindow = eventStarts(a = -Inf, b = 0, index = "startDate"))) + # 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 - conditionOccurrence(t1dConceptSet) # query for t1d occurrence for censor + # query for t1d occurrence for censor + conditionOccurrence(t1dConceptSet) ) ) ) @@ -91,12 +97,13 @@ Notice that the *query* is applied all over this cohort definition. The metformi 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} +```{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()) +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. @@ -116,7 +123,7 @@ When building a *criteria* object the user needs: 1) a query, 2) an operator tha With this definition in mind, let us build an example of a *criteria* object that reflects the image above. -```{r criteriaExampleA} +```{r criteriaExampleA, eval=FALSE} atenololConceptSet <- cs(descendants(1314002), name - "atenolol") atenololCriteria <- atLeast( @@ -130,7 +137,7 @@ atenololCriteria <- atLeast( 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} +```{r criteriaExampleB, eval=FALSE} atenololConceptSet <- cs(descendants(1314002), name - "atenolol") atenololCriteriaA <- exactly( @@ -153,4 +160,281 @@ atenololCriteriaB <- atMost( ## 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 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 index a3db71b8..b48c043d 100644 Binary files a/vignettes/images/aperture1.png and b/vignettes/images/aperture1.png differ diff --git a/vignettes/images/aperture2.png b/vignettes/images/aperture2.png index 4a0e9121..568f2d3b 100644 Binary files a/vignettes/images/aperture2.png and b/vignettes/images/aperture2.png differ diff --git a/vignettes/images/aperture3.png b/vignettes/images/aperture3.png index fcd098a3..ff21a0c2 100644 Binary files a/vignettes/images/aperture3.png 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