Skip to content

Commit fa03ba0

Browse files
authored
Merge pull request #73 from OHDSI/develop
update to v2.0.5
2 parents 561033d + c3596bb commit fa03ba0

142 files changed

Lines changed: 2088 additions & 895 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,4 @@ errorReportSql.txt
66
/Meta/
77
work/*
88
scratch/
9+
inst/doc

DESCRIPTION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Package: Capr
22
Title: Cohort Definition Application Programming
3-
Version: 2.0.4
3+
Version: 2.0.5
44
Authors@R: c(
55
person("Martin", "Lavallee", , "mdlavallee92@gmail.com", role = c("aut", "cre")),
66
person("Adam", "Black", , "black@ohdsi.org", role = "aut")

NAMESPACE

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,16 @@ export(bt)
1111
export(censoringEvents)
1212
export(cohort)
1313
export(compile.Cohort)
14-
export(condition)
1514
export(conditionEra)
15+
export(conditionOccurrence)
1616
export(continuousObservation)
1717
export(cs)
1818
export(daysOfSupply)
1919
export(death)
2020
export(descendants)
21-
export(drug)
2221
export(drugEra)
2322
export(drugExit)
23+
export(drugExposure)
2424
export(drugQuantity)
2525
export(drugRefills)
2626
export(duringInterval)

NEWS.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
Capr 2.0.5
2+
==========
3+
- change query functions to match known syntax (i.e. drug => drugExposure, condition => conditionOccurrence)
4+
- require a name for `cs()`
5+
- improve documentation (add vignette for query, count and group)
6+
7+
18
Capr 2.0.4
29
==========
310
- hot fix add procedure occurrence into query

R/conceptSet.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ newConcept <- function(id,
193193
#' cs(1, 2, 3, exclude(4, 5), mapped(6, 7), descendants(8, 9))
194194
#' cs(descendants(1, 2, 3), exclude(descendants(8, 9)))
195195
#' }
196-
cs <- function(..., name = "", id = NULL) {
196+
cs <- function(..., name, id = NULL) {
197197
dots <- unlist(list(...), recursive = F)
198198

199199
conceptList <- lapply(dots, function(x) {

R/query.R

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ query <- function(domain, conceptSet = NULL, ...) {
115115
#'
116116
#' @return A Capr Query
117117
#' @export
118-
condition <- function(conceptSet, ...) {
118+
conditionOccurrence <- function(conceptSet, ...) {
119119

120120
query(domain = "ConditionOccurrence",
121121
conceptSet = conceptSet,
@@ -129,7 +129,7 @@ condition <- function(conceptSet, ...) {
129129
#'
130130
#' @return A Capr Query
131131
#' @export
132-
drug <- function(conceptSet, ...) {
132+
drugExposure <- function(conceptSet, ...) {
133133

134134
query(domain = "DrugExposure",
135135
conceptSet = conceptSet,

README.md

Lines changed: 2 additions & 234 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,6 @@ Learn more about the OHDSI approach to cohort building in the [cohorts chapter o
1616

1717
# Installation
1818

19-
Capr can be installed via:
20-
21-
``` r
22-
# install.packages("Capr")
23-
```
2419

2520
Users can install the current development version of Capr from [GitHub](https://github.com/) with:
2621

@@ -29,246 +24,19 @@ Users can install the current development version of Capr from [GitHub](https://
2924
devtools::install_github("ohdsi/Capr")
3025
```
3126

32-
# How to Use
33-
34-
## Examples
35-
36-
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)
37-
38-
### Simple diclofenac cohort
39-
40-
``` r
41-
library(Capr)
42-
43-
# Define concepts sets with cs()
44-
diclofenac <- cs(descendants(1124300))
45-
46-
ch <- cohort(
47-
entry = entry(drugEra(diclofenac))
48-
)
49-
50-
ch
51-
#> Formal class 'Cohort' [package "Capr"] with 4 slots
52-
#> ..@ entry :Formal class 'CohortEntry' [package "Capr"] with 5 slots
53-
#> ..@ attrition:Formal class 'CohortAttrition' [package "Capr"] with 2 slots
54-
#> ..@ exit :Formal class 'CohortExit' [package "Capr"] with 2 slots
55-
#> ..@ era :Formal class 'CohortEra' [package "Capr"] with 3 slots
56-
```
57-
58-
### Adding more complexity
59-
60-
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:
61-
62-
- Ages 16 or older
63-
- With at least 365 days of continuous observation prior to exposure
64-
- With cohort exit defined as discontinuation of exposure (allowing for a 30-day gap)
65-
66-
``` r
67-
diclofenac <- cs(descendants(1124300))
68-
69-
ch <- cohort(
70-
entry = entry(drugEra(diclofenac, age(gte(16))),
71-
observationWindow = continuousObservation(-365L, 0L)),
72-
exit = exit(drugExit(diclofenac))
73-
)
74-
75-
ch
76-
#> Formal class 'Cohort' [package "Capr"] with 4 slots
77-
#> ..@ entry :Formal class 'CohortEntry' [package "Capr"] with 5 slots
78-
#> ..@ attrition:Formal class 'CohortAttrition' [package "Capr"] with 2 slots
79-
#> ..@ exit :Formal class 'CohortExit' [package "Capr"] with 2 slots
80-
#> ..@ era :Formal class 'CohortEra' [package "Capr"] with 3 slots
81-
```
82-
83-
### Adding cohort attrition
84-
85-
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:
86-
87-
- Without prior exposure to any NSAID (Non-Steroidal Anti-Inflammatory Drug)
88-
- Without prior diagnosis of cancer
89-
90-
``` r
91-
diclofenac <- cs(descendants(1124300), name = "diclofenac")
92-
nsaid <- cs(descendants(21603933), name = "nsaid")
93-
cancer <- cs(descendants(443392), name = "cancer")
94-
95-
ch <- cohort(
96-
entry = entry(drugEra(diclofenac, age(gte(16))),
97-
observationWindow = continuousObservation(-365L, 0L)),
98-
attrition = attrition(
99-
withAll(
100-
exactly(0, drug(nsaid), eventStarts(-Inf, 0, index = "startDate")),
101-
exactly(0, condition(cancer), eventStarts(-Inf, 0, index = "startDate"))
102-
)
103-
),
104-
exit = exit(
105-
endStrategy = drugExit(diclofenac, persistenceWindow = 30)
106-
)
107-
)
108-
109-
ch
110-
#> Formal class 'Cohort' [package "Capr"] with 4 slots
111-
#> ..@ entry :Formal class 'CohortEntry' [package "Capr"] with 5 slots
112-
#> ..@ attrition:Formal class 'CohortAttrition' [package "Capr"] with 2 slots
113-
#> ..@ exit :Formal class 'CohortExit' [package "Capr"] with 2 slots
114-
#> ..@ era :Formal class 'CohortEra' [package "Capr"] with 3 slots
115-
```
116-
117-
## Save cohort as JSON
118-
119-
OHDSI standard cohorts are represented as json files and can be copy and pasted into Atlas.
120-
121-
``` r
122-
123-
path <- file.path(tempdir(), "diclofenacCohort.json")
124-
125-
writeCohort(ch, path)
126-
127-
cat(substr(readr::read_file(path), 1, 100))
128-
#> {
129-
#> "ConceptSets": [
130-
#> {
131-
#> "id": 0,
132-
#> "name": "diclofenac",
133-
#> "expression": {
134-
#>
135-
```
136-
137-
### Fill in missing concept set details
138-
139-
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.
140-
141-
``` r
142-
143-
diclofenac <- cs(descendants(1124300), name = "diclofenac")
144-
145-
cat(as.json(diclofenac))
146-
#> {
147-
#> "id": "11d012608fce118593830a3039042e56",
148-
#> "name": "diclofenac",
149-
#> "expression": {
150-
#> "items": [
151-
#> {
152-
#> "concept": {
153-
#> "CONCEPT_ID": 1124300,
154-
#> "CONCEPT_NAME": "",
155-
#> "STANDARD_CONCEPT": "",
156-
#> "STANDARD_CONCEPT_CAPTION": "",
157-
#> "INVALID_REASON": "",
158-
#> "INVALID_REASON_CAPTION": "",
159-
#> "CONCEPT_CODE": "",
160-
#> "DOMAIN_ID": "",
161-
#> "VOCABULARY_ID": "",
162-
#> "CONCEPT_CLASS_ID": ""
163-
#> },
164-
#> "isExcluded": false,
165-
#> "includeDescendants": true,
166-
#> "includeMapped": false
167-
#> }
168-
#> ]
169-
#> }
170-
#> }
171-
```
172-
173-
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.
174-
175-
``` r
176-
con <- DatabaseConnector::connect(Eunomia::getEunomiaConnectionDetails())
177-
diclofenac <- getConceptSetDetails(diclofenac, con, vocabularyDatabaseSchema = "main")
178-
cat(as.json(diclofenac))
179-
#> {
180-
#> "id": "11d012608fce118593830a3039042e56",
181-
#> "name": "diclofenac",
182-
#> "expression": {
183-
#> "items": [
184-
#> {
185-
#> "concept": {
186-
#> "CONCEPT_ID": 1124300,
187-
#> "CONCEPT_NAME": "Diclofenac",
188-
#> "STANDARD_CONCEPT": "S",
189-
#> "STANDARD_CONCEPT_CAPTION": "Standard",
190-
#> "INVALID_REASON": "V",
191-
#> "INVALID_REASON_CAPTION": "Valid",
192-
#> "CONCEPT_CODE": "3355",
193-
#> "DOMAIN_ID": "Drug",
194-
#> "VOCABULARY_ID": "RxNorm",
195-
#> "CONCEPT_CLASS_ID": "Ingredient"
196-
#> },
197-
#> "isExcluded": false,
198-
#> "includeDescendants": true,
199-
#> "includeMapped": false
200-
#> }
201-
#> ]
202-
#> }
203-
#> }
204-
```
205-
206-
### Generating Capr Cohorts
207-
208-
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.
209-
210-
## Building Capr Templates
211-
212-
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.
213-
214-
``` r
215-
216-
# A Capr cohort template is a function that returns a cohort
217-
drugEraTemplate <- function(ingredientConceptId) {
218-
219-
drugConceptSet <- cs(descendants(ingredientConceptId))
220-
221-
cohort(
222-
entry = entry(drugEra(drugConceptSet, age(gte(16))),
223-
observationWindow = continuousObservation(-365L, 0L)),
224-
exit = exit(drugExit(drugConceptSet, persistenceWindow = 30))
225-
)
226-
}
227-
228-
229-
library(dplyr, warn.conflicts = FALSE)
230-
231-
# create a cohort for every single ingredient
232-
df <- DBI::dbGetQuery(con,
233-
"Select * from concept where concept_class_id = 'Ingredient'") %>%
234-
tibble() %>%
235-
select(concept_id, concept_name) %>%
236-
mutate(capr_cohort = purrr::map(concept_id, drugEraTemplate)) %>%
237-
mutate(cohort_json = purrr::map_chr(capr_cohort, as.json))
238-
239-
df
240-
#> # A tibble: 91 × 4
241-
#> concept_id concept_name capr_cohort cohort_json
242-
#> <dbl> <chr> <list> <chr>
243-
#> 1 1557272 Alendronate <Cohort> "{\n \"ConceptSets\": [\n {\n …
244-
#> 2 708298 Midazolam <Cohort> "{\n \"ConceptSets\": [\n {\n …
245-
#> 3 701322 Memantine <Cohort> "{\n \"ConceptSets\": [\n {\n …
246-
#> 4 723013 Diazepam <Cohort> "{\n \"ConceptSets\": [\n {\n …
247-
#> 5 1129625 Diphenhydramine <Cohort> "{\n \"ConceptSets\": [\n {\n …
248-
#> 6 1149196 Cetirizine <Cohort> "{\n \"ConceptSets\": [\n {\n …
249-
#> 7 1149380 fluticasone <Cohort> "{\n \"ConceptSets\": [\n {\n …
250-
#> 8 1150770 Astemizole <Cohort> "{\n \"ConceptSets\": [\n {\n …
251-
#> 9 1150836 Terfenadine <Cohort> "{\n \"ConceptSets\": [\n {\n …
252-
#> 10 1124300 Diclofenac <Cohort> "{\n \"ConceptSets\": [\n {\n …
253-
#> # … with 81 more rows
254-
```
255-
256-
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.
257-
258-
``` r
259-
DatabaseConnector::disconnect(con)
260-
```
26127

26228
# User Documentation
26329

26430
Documentation can be found on the [package website](https://ohdsi.github.io/Capr/).
26531

32+
26633
PDF versions of the documentation are also available:
26734

26835
- Vignette: [Using Capr](https://raw.githubusercontent.com/OHDSI/Capr/main/extras/pdf_vignette/Using-Capr.pdf)
26936
- Vignette: [Capr Examples](https://raw.githubusercontent.com/OHDSI/Capr/main/extras/pdf_vignette/Examples.pdf)
27037
- Vignette: [Working with Concept Sets in Capr](https://raw.githubusercontent.com/OHDSI/Capr/main/extras/pdf_vignette/Capr-conceptSets.pdf)
27138
- Vignette: [Capr for Templating Cohort Definitions](https://raw.githubusercontent.com/OHDSI/Capr/main/extras/pdf_vignette/capr_templatesr.pdf)
39+
- Vignette: [Capr components](https://raw.githubusercontent.com/OHDSI/Capr/main/extras/pdf_vignette/capr_objects.pdf)
27240
- [Design Document](https://raw.githubusercontent.com/OHDSI/Capr/main/extras/pdf_vignette/capr_design.pdf)
27341
- [Package manual](https://raw.githubusercontent.com/OHDSI/Capr/main/extras/Capr.pdf)
27442

docs/404.html

Lines changed: 4 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/LICENSE.html

Lines changed: 4 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)