Skip to content

Commit c25f736

Browse files
authored
Merge pull request #94 from OHDSI/develop
Develop v2.0.8
2 parents b05984f + bbbe860 commit c25f736

133 files changed

Lines changed: 1741 additions & 488 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.

DESCRIPTION

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
Package: Capr
22
Title: Cohort Definition Application Programming
3-
Version: 2.0.7
3+
Version: 2.0.8
44
Authors@R: c(
5-
person("Martin", "Lavallee", , "martin.lavallee@odysseusinc.com", role = c("aut")),
6-
person("Adam", "Black", , "black@ohdsi.org", role = c("aut", "cre"))
5+
person("Martin", "Lavallee", , "martin.lavallee@boehringer-ingelheim.com", role = c("aut", "cre")),
6+
person("Adam", "Black", , "black@ohdsi.org", role = c("aut"))
77
)
88
Description: Provides a programming language for defining cohort definitions in R to use in studies for Observational
99
Health Data Sciences and Informatics (OHDSI). The functions in 'Capr' allow for the programmatic creation of
@@ -16,10 +16,9 @@ License: Apache License (>= 2)
1616
URL: https://ohdsi.github.io/Capr/, https://github.com/OHDSI/Capr/
1717
BugReports: https://github.com/OHDSI/Capr/issues/
1818
Encoding: UTF-8
19-
RoxygenNote: 7.2.3
19+
RoxygenNote: 7.3.1
2020
Depends:
21-
R (>= 3.5.0),
22-
CirceR (>= 1.3.1)
21+
R (>= 3.5.0)
2322
Imports:
2423
magrittr (>= 1.5.0),
2524
jsonlite,
@@ -40,16 +39,14 @@ Imports:
4039
DBI,
4140
DatabaseConnector,
4241
SqlRender,
43-
generics
42+
generics,
43+
CirceR
4444
Suggests:
4545
testthat (>= 3.0.0),
4646
knitr,
4747
rmarkdown
48-
Remotes:
49-
ohdsi/CirceR
5048
VignetteBuilder: knitr
5149
Config/testthat/edition: 3
52-
Additional_repositories: https://OHDSI.github.io/drat
5350
Collate:
5451
'Capr.R'
5552
'conceptSet.R'

NAMESPACE

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,20 @@ export(cohort)
1313
export(compile)
1414
export(conditionEra)
1515
export(conditionOccurrence)
16+
export(conditionType)
1617
export(continuousObservation)
1718
export(cs)
1819
export(dateAdjustment)
1920
export(daysOfSupply)
2021
export(death)
2122
export(descendants)
23+
export(deviceExposure)
2224
export(drugEra)
2325
export(drugExit)
2426
export(drugExposure)
2527
export(drugQuantity)
2628
export(drugRefills)
29+
export(drugType)
2730
export(duringInterval)
2831
export(endDate)
2932
export(entry)
@@ -46,14 +49,17 @@ export(makeCohortSet)
4649
export(male)
4750
export(mapped)
4851
export(measurement)
52+
export(measurementType)
4953
export(nbt)
5054
export(nestedWithAll)
5155
export(nestedWithAny)
5256
export(nestedWithAtLeast)
5357
export(nestedWithAtMost)
5458
export(observation)
5559
export(observationExit)
60+
export(observationType)
5661
export(procedure)
62+
export(procedureType)
5763
export(rangeHigh)
5864
export(rangeLow)
5965
export(readConceptSet)
@@ -62,6 +68,7 @@ export(toCirce)
6268
export(unit)
6369
export(valueAsNumber)
6470
export(visit)
71+
export(visitType)
6572
export(withAll)
6673
export(withAny)
6774
export(withAtLeast)

NEWS.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
Capr 2.0.8
2+
==========
3+
- add conceptTypes to determine data provenance #93
4+
- allow numeric as offsetDays #90
5+
- add deviceExposure #86
6+
- other minor edits
7+
18
Capr 2.0.7
29
==========
310
- add CirceR in REMOTES section

R/Capr.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright 2023 Observational Health Data Sciences and Informatics
1+
# Copyright 2024 Observational Health Data Sciences and Informatics
22
#
33
# This file is part of Capr
44
#

R/attributes-concept.R

Lines changed: 124 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,128 @@ female <- function() {
7979
}
8080

8181

82+
findConceptInVocabulary <- function(id, connection, vocabularyDatabaseSchema) {
83+
84+
detailedConceptSet <- cs(id, name = glue::glue("{id}")) |>
85+
getConceptSetDetails(con = connection,
86+
vocabularyDatabaseSchema = vocabularyDatabaseSchema)
87+
return(detailedConceptSet)
88+
}
89+
90+
pullConceptClass <- function(detailedConceptSet) {
91+
conceptClass <- detailedConceptSet@Expression[[1]]@Concept
92+
return(conceptClass)
93+
}
94+
95+
buildConceptAttribute <- function(ids, attributeName, connection, vocabularyDatabaseSchema) {
96+
97+
# get concepts from vocabulary table
98+
conceptsForAttributes <- purrr::map(
99+
ids,
100+
~findConceptInVocabulary(id = .x, connection = connection, vocabularyDatabaseSchema = vocabularyDatabaseSchema) |>
101+
pullConceptClass()
102+
)
103+
104+
attr_concept <- methods::new("conceptAttribute",
105+
name = attributeName,
106+
conceptSet = conceptsForAttributes)
107+
return(attr_concept)
108+
}
109+
110+
#' Add a drug type attribute to determine the provenance of the record
111+
#' @param ids the concept ids for the attribute
112+
#' @param connection a connection to an OMOP dbms to get vocab info about the concept
113+
#' @param vocabularyDatabaseSchema the database schema for the vocabularies
114+
#' @return
115+
#' An attribute that can be used in a query function
116+
#' @export
117+
#'
118+
drugType <- function(ids, connection, vocabularyDatabaseSchema) {
119+
res <- buildConceptAttribute(ids = ids, attributeName = "DrugType",
120+
connection = connection,
121+
vocabularyDatabaseSchema = vocabularyDatabaseSchema)
122+
return(res)
123+
}
124+
125+
#' Add a condition type attribute to determine the provenance of the record
126+
#' @param ids the concept ids for the attribute
127+
#' @param connection a connection to an OMOP dbms to get vocab info about the concept
128+
#' @param vocabularyDatabaseSchema the database schema for the vocabularies
129+
#' @return
130+
#' An attribute that can be used in a query function
131+
#' @export
132+
#'
133+
conditionType <- function(ids, connection, vocabularyDatabaseSchema) {
134+
res <- buildConceptAttribute(ids = ids, attributeName = "ConditionType",
135+
connection = connection,
136+
vocabularyDatabaseSchema = vocabularyDatabaseSchema)
137+
return(res)
138+
}
139+
140+
141+
142+
#' Add a visit type attribute to determine the provenance of the record
143+
#' @param ids the concept ids for the attribute
144+
#' @param connection a connection to an OMOP dbms to get vocab info about the concept
145+
#' @param vocabularyDatabaseSchema the database schema for the vocabularies
146+
#' @return
147+
#' An attribute that can be used in a query function
148+
#' @export
149+
#'
150+
visitType <- function(ids, connection, vocabularyDatabaseSchema) {
151+
res <- buildConceptAttribute(ids = ids, attributeName = "VisitType",
152+
connection = connection,
153+
vocabularyDatabaseSchema = vocabularyDatabaseSchema)
154+
return(res)
155+
}
156+
157+
158+
#' Add a measurement type attribute to determine the provenance of the record
159+
#' @param ids the concept ids for the attribute
160+
#' @param connection a connection to an OMOP dbms to get vocab info about the concept
161+
#' @param vocabularyDatabaseSchema the database schema for the vocabularies
162+
#' @return
163+
#' An attribute that can be used in a query function
164+
#' @export
165+
#'
166+
measurementType <- function(ids, connection, vocabularyDatabaseSchema) {
167+
res <- buildConceptAttribute(ids = ids, attributeName = "measurementType",
168+
connection = connection,
169+
vocabularyDatabaseSchema = vocabularyDatabaseSchema)
170+
return(res)
171+
}
172+
173+
#' Add a observation type attribute to determine the provenance of the record
174+
#' @param ids the concept ids for the attribute
175+
#' @param connection a connection to an OMOP dbms to get vocab info about the concept
176+
#' @param vocabularyDatabaseSchema the database schema for the vocabularies
177+
#' @return
178+
#' An attribute that can be used in a query function
179+
#' @export
180+
#'
181+
observationType <- function(ids, connection, vocabularyDatabaseSchema) {
182+
res <- buildConceptAttribute(ids = ids, attributeName = "observationType",
183+
connection = connection,
184+
vocabularyDatabaseSchema = vocabularyDatabaseSchema)
185+
return(res)
186+
}
187+
188+
189+
#' Add a procedure type attribute to determine the provenance of the record
190+
#' @param ids the concept ids for the attribute
191+
#' @param connection a connection to an OMOP dbms to get vocab info about the concept
192+
#' @param vocabularyDatabaseSchema the database schema for the vocabularies
193+
#' @return
194+
#' An attribute that can be used in a query function
195+
#' @export
196+
#'
197+
procedureType <- function(ids, connection, vocabularyDatabaseSchema) {
198+
res <- buildConceptAttribute(ids = ids, attributeName = "procedureType",
199+
connection = connection,
200+
vocabularyDatabaseSchema = vocabularyDatabaseSchema)
201+
return(res)
202+
}
203+
82204
#' Add unit attribute to a query
83205
#' @param x A single character idetifier for a unit or a concept set that identifies units
84206
#' @return
@@ -121,7 +243,7 @@ unit <- function(x) {
121243

122244
# conceptSet <- as.list(as.data.frame(conceptSet)$conceptId) conceptSet <- as.list(conceptSet)
123245

124-
res <- methods::new("conceptAttribute", name = "unit", conceptSet = conceptSet)
246+
res <- methods::new("conceptAttribute", name = "Unit", conceptSet = conceptSet)
125247
return(res)
126248
}
127249

@@ -130,7 +252,7 @@ unit <- function(x) {
130252
setMethod("as.list", "conceptAttribute", function(x) {
131253

132254
concepts <- purrr::map(x@conceptSet, ~as.list(.x))
133-
nm <- stringr::str_to_title(x@name)
255+
nm <- x@name
134256

135257
tibble::lst(`:=`(!!nm, concepts))
136258
})

R/exit.R

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ drugExit <- function(conceptSet,
141141

142142
#' Function to create an exit based on exit based on the end of a continuous drug exposure
143143
#' @param index specification of event date to offset. Can be either startDate or endDate
144-
#' @param offsetDays an integer specifying the number of days to offset from the event date
144+
#' @param offsetDays an number specifying the days to offset from the event date. Will coerce to an integer
145145
#' @return a fixed Duration exit S4 object used to define the cohort exit as the end of a specified time
146146
#' @export
147147
fixedExit <- function(index = c("startDate", "endDate"), offsetDays){
@@ -150,7 +150,7 @@ fixedExit <- function(index = c("startDate", "endDate"), offsetDays){
150150

151151
ee <- methods::new("FixedDurationExit",
152152
index = index,
153-
offsetDays = offsetDays)
153+
offsetDays = as.integer(offsetDays))
154154
return(ee)
155155
}
156156

R/query.R

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,21 @@ drugExposure <- function(conceptSet, ...) {
136136
...)
137137
}
138138

139+
140+
#' Query the drug domain
141+
#'
142+
#' @param conceptSet A drug concept set
143+
#' @param ... optional attributes
144+
#'
145+
#' @return A Capr Query
146+
#' @export
147+
deviceExposure <- function(conceptSet, ...) {
148+
149+
query(domain = "DeviceExposure",
150+
conceptSet = conceptSet,
151+
...)
152+
}
153+
139154
#' Query the measurement domain
140155
#'
141156
#' @param conceptSet A measurement concept set

docs/404.html

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

docs/LICENSE.html

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

0 commit comments

Comments
 (0)