Skip to content

Commit

Permalink
Updating vignettes to use latest Capr functions. Fixes #159
Browse files Browse the repository at this point in the history
  • Loading branch information
schuemie committed Jan 31, 2024
1 parent 22179f4 commit 79bddeb
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 45 deletions.
16 changes: 5 additions & 11 deletions extras/MultiAnalysesVignetteDataFetch.R
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ cohortTable <- "cm_vignette"

# Define exposure cohorts ------------------------------------------------------
library(Capr)
library(CirceR)

osteoArthritisOfKneeConceptId <- 4079750
celecoxibConceptId <- 1118084
Expand All @@ -46,9 +45,9 @@ osteoArthritisOfKnee <- cs(
descendants(osteoArthritisOfKneeConceptId),
name = "Osteoarthritis of knee"
)
attrition = attrition(
attrition <- attrition(
"prior osteoarthritis of knee" = withAll(
atLeast(1, condition(osteoArthritisOfKnee), duringInterval(eventStarts(-Inf, 0)))
atLeast(1, conditionOccurrence(osteoArthritisOfKnee), duringInterval(eventStarts(-Inf, 0)))
)
)
celecoxib <- cs(
Expand All @@ -61,7 +60,7 @@ diclofenac <- cs(
)
celecoxibCohort <- cohort(
entry = entry(
drug(celecoxib, firstOccurrence()),
drugExposure(celecoxib, firstOccurrence()),
observationWindow = continuousObservation(priorDays = 365)
),
attrition = attrition,
Expand All @@ -71,20 +70,15 @@ celecoxibCohort <- cohort(
)
diclofenacCohort <- cohort(
entry = entry(
drug(diclofenac, firstOccurrence()),
drugExposure(diclofenac, firstOccurrence()),
observationWindow = continuousObservation(priorDays = 365)
),
attrition = attrition,
exit = exit(endStrategy = drugExit(diclofenac,
persistenceWindow = 30,
surveillanceWindow = 0))
)
exposureCohorts <- tibble(cohortId = c(1,2),
cohortName = c("Celecoxib", "Diclofenac"),
json = c(as.json(celecoxibCohort), as.json(diclofenacCohort)))
exposureCohorts$sql <- sapply(exposureCohorts$json,
buildCohortQuery,
options = createGenerateOptions())
exposureCohorts <- makeCohortSet(celecoxibCohort, diclofenacCohort)

# Define outcome cohort --------------------------------------------------------
library(PhenotypeLibrary)
Expand Down
15 changes: 5 additions & 10 deletions extras/SingleStudyVignetteDataFetch.R
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ osteoArthritisOfKnee <- cs(
)
attrition = attrition(
"prior osteoarthritis of knee" = withAll(
atLeast(1, condition(osteoArthritisOfKnee), duringInterval(eventStarts(-Inf, 0)))
atLeast(1, conditionOccurrence(osteoArthritisOfKnee), duringInterval(eventStarts(-Inf, 0)))
)
)
celecoxib <- cs(
Expand All @@ -61,7 +61,7 @@ diclofenac <- cs(
)
celecoxibCohort <- cohort(
entry = entry(
drug(celecoxib, firstOccurrence()),
drugExposure(celecoxib, firstOccurrence()),
observationWindow = continuousObservation(priorDays = 365)
),
attrition = attrition,
Expand All @@ -71,26 +71,21 @@ celecoxibCohort <- cohort(
)
diclofenacCohort <- cohort(
entry = entry(
drug(diclofenac, firstOccurrence()),
drugExposure(diclofenac, firstOccurrence()),
observationWindow = continuousObservation(priorDays = 365)
),
attrition = attrition,
exit = exit(endStrategy = drugExit(diclofenac,
persistenceWindow = 30,
surveillanceWindow = 0))
)
exposureCohorts <- makeCohortSet(celecoxibCohort, diclofenacCohort)

# Define outcome cohort --------------------------------------------------------
library(PhenotypeLibrary)
outcomeCohorts <- getPlCohortDefinitionSet(77) # GI bleed

# Generate cohorts -------------------------------------------------------------
library(CirceR)
exposureCohorts <- tibble(cohortId = c(1,2),
cohortName = c("Celecoxib", "Diclofenac"),
json = c(as.json(celecoxibCohort), as.json(diclofenacCohort)))
exposureCohorts$sql <- sapply(exposureCohorts$json,
buildCohortQuery,
options = createGenerateOptions())
allCohorts <- bind_rows(outcomeCohorts,
exposureCohorts)
library(CohortGenerator)
Expand Down
16 changes: 4 additions & 12 deletions vignettes/MultipleAnalyses.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ osteoArthritisOfKnee <- cs(
)
attrition = attrition(
"prior osteoarthritis of knee" = withAll(
atLeast(1, condition(osteoArthritisOfKnee),
atLeast(1, conditionOccurrence(osteoArthritisOfKnee),
duringInterval(eventStarts(-Inf, 0)))
)
)
Expand All @@ -98,7 +98,7 @@ diclofenac <- cs(
)
celecoxibCohort <- cohort(
entry = entry(
drug(celecoxib, firstOccurrence()),
drugExposure(celecoxib, firstOccurrence()),
observationWindow = continuousObservation(priorDays = 365)
),
attrition = attrition,
Expand All @@ -108,14 +108,15 @@ celecoxibCohort <- cohort(
)
diclofenacCohort <- cohort(
entry = entry(
drug(diclofenac, firstOccurrence()),
drugExposure(diclofenac, firstOccurrence()),
observationWindow = continuousObservation(priorDays = 365)
),
attrition = attrition,
exit = exit(endStrategy = drugExit(diclofenac,
persistenceWindow = 30,
surveillanceWindow = 0))
)
exposureCohorts <- makeCohortSet(celecoxibCohort, diclofenacCohort)
```

We'll pull the outcome definition from the OHDSI `PhenotypeLibrary`:
Expand Down Expand Up @@ -146,15 +147,6 @@ negativeControlCohorts <- tibble(
We combine the exposure and outcome cohort definitions, and use `CohortGenerator` to generate the cohorts:

```{r eval=FALSE}
library(CirceR)
# For exposures, create a cohort definition set table as required by CohortGenerator:
exposureCohorts <- tibble(cohortId = c(1,2),
cohortName = c("Celecoxib", "Diclofenac"),
json = c(as.json(celecoxibCohort),
as.json(diclofenacCohort)))
exposureCohorts$sql <- sapply(exposureCohorts$json,
buildCohortQuery,
options = createGenerateOptions())
allCohorts <- bind_rows(outcomeCohorts,
exposureCohorts)
Expand Down
16 changes: 4 additions & 12 deletions vignettes/SingleStudies.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ osteoArthritisOfKnee <- cs(
)
attrition = attrition(
"prior osteoarthritis of knee" = withAll(
atLeast(1, condition(osteoArthritisOfKnee), duringInterval(eventStarts(-Inf, 0)))
atLeast(1, conditionOccurrence(osteoArthritisOfKnee), duringInterval(eventStarts(-Inf, 0)))
)
)
celecoxib <- cs(
Expand All @@ -91,7 +91,7 @@ diclofenac <- cs(
)
celecoxibCohort <- cohort(
entry = entry(
drug(celecoxib, firstOccurrence()),
drugExposure(celecoxib, firstOccurrence()),
observationWindow = continuousObservation(priorDays = 365)
),
attrition = attrition,
Expand All @@ -101,14 +101,15 @@ celecoxibCohort <- cohort(
)
diclofenacCohort <- cohort(
entry = entry(
drug(diclofenac, firstOccurrence()),
drugExposure(diclofenac, firstOccurrence()),
observationWindow = continuousObservation(priorDays = 365)
),
attrition = attrition,
exit = exit(endStrategy = drugExit(diclofenac,
persistenceWindow = 30,
surveillanceWindow = 0))
)
exposureCohorts <- makeCohortSet(celecoxibCohort, diclofenacCohort)
```

We'll pull the outcome definition from the OHDSI `PhenotypeLibrary`:
Expand All @@ -121,15 +122,6 @@ outcomeCohorts <- getPlCohortDefinitionSet(77) # GI bleed
We combine the exposure and outcome cohort definitions, and use `CohortGenerator` to generate the cohorts:

```{r eval=FALSE}
library(CirceR)
# For exposures, create a cohort definition set table as required by CohortGenerator:
exposureCohorts <- tibble(cohortId = c(1,2),
cohortName = c("Celecoxib", "Diclofenac"),
json = c(as.json(celecoxibCohort),
as.json(diclofenacCohort)))
exposureCohorts$sql <- sapply(exposureCohorts$json,
buildCohortQuery,
options = createGenerateOptions())
allCohorts <- bind_rows(outcomeCohorts,
exposureCohorts)
Expand Down

0 comments on commit 79bddeb

Please sign in to comment.