@@ -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) {
130252setMethod ("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})
0 commit comments