Skip to content

Commit

Permalink
Merge pull request #34 from OHDSI/develop
Browse files Browse the repository at this point in the history
Fix guid issue in Concept Set Expression creation, add createConceptDataframe CohortGenerator and CohortDiagnostics, and fix documentation
  • Loading branch information
mdlavallee92 authored Apr 18, 2022
2 parents 351f5e5 + f8724c5 commit 2e92b03
Show file tree
Hide file tree
Showing 221 changed files with 1,704 additions and 757 deletions.
2 changes: 0 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
.Rhistory
.Rproj.user
inst/doc
.DS_Store
errorReportSql.txt
*.log
/doc/
/Meta/
work/*
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: Capr
Title: Cohort definition Application Programming in R
Version: 1.0.2
Version: 1.0.3
Authors@R:
person(given = "Martin",
family = "Lavallee",
Expand Down
3 changes: 3 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export(createAgeAtEndAttribute)
export(createAgeAtStartAttribute)
export(createAgeAttribute)
export(createCensoringCriteria)
export(createCohortDataframe)
export(createCohortDefinition)
export(createCohortEra)
export(createConceptAttribute)
Expand Down Expand Up @@ -121,6 +122,7 @@ import(methods)
importFrom(CirceR,buildCohortQuery)
importFrom(CirceR,cohortExpressionFromJson)
importFrom(CirceR,cohortPrintFriendly)
importFrom(CirceR,createGenerateOptions)
importFrom(RJSONIO,toJSON)
importFrom(jsonlite,read_json)
importFrom(magrittr,"%>%")
Expand All @@ -130,6 +132,7 @@ importFrom(methods,slot)
importFrom(purrr,discard)
importFrom(purrr,map)
importFrom(purrr,map2)
importFrom(purrr,map_chr)
importFrom(purrr,map_int)
importFrom(rlang,"!!!")
importFrom(rlang,"!!")
Expand Down
7 changes: 7 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
Capr 1.0.3
==========

1. Fix bug in guid generation...did not create unique guid each time
2. Add function to create cohort data frame for CohortGenerator and CohortDiagnostics
3. Fix pdf documentation in readme

Capr 1.0.2
==========

Expand Down
5 changes: 1 addition & 4 deletions R/LowLevelClasses.R
Original file line number Diff line number Diff line change
Expand Up @@ -551,10 +551,7 @@ setMethod("show", "ConceptSetItem", function(object) {
setClass("ConceptSetExpression",
slots = c(id = "character",
Name = "character",
Expression = "list"),
prototype = list(id = uuid::UUIDgenerate(),
Name = NA_character_,
Expression = list()))
Expression = "list"))

setValidity("ConceptSetExpression", function(object) {
# TODO create validation rules for ConceptSetExpression
Expand Down
2 changes: 1 addition & 1 deletion R/LowLevelUtilityFn.R
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ removeDupCSE <- function(cse){
}#end duplication check
}#end for loop
#discard any concept set expressions not needed
cse <- purrr::discard(cse,function(x) is(x)[1] != "ConceptSetExpression")
cse <- purrr::discard(cse, function(x) is(x)[1] != "ConceptSetExpression")
return(cse)
}

Expand Down
48 changes: 48 additions & 0 deletions R/UserCommands.R
Original file line number Diff line number Diff line change
Expand Up @@ -182,4 +182,52 @@ compileCohortDefinition <- function(CohortDefinition, generateOptions = NULL){
}


########------Create Cohort Dataframe for generation------------#################

#' Create a dataframe that can be used by cohort generator to build cohorts into backend table
#'
#' This function converts a list of Cohort definitions into a dataframe that can be used by cohort
#' generator and cohort diagnostics to build and evaluate cohorts. The dataframe returns an atlasId column and
#' a cohortId column which are equivalent. Further it creates a column for the ohdisql, json, read and name of
#' cohort.
#'
#' @param cohortList a list of cohorts to turn into a dataframe
#' @param generateStats select true if you want inclusion rule stats or false for no stats
#' @importFrom CirceR createGenerateOptions
#' @importFrom purrr map_chr
#' @return A data frame of cohort definitions containing meta data
#' @export
createCohortDataframe <- function(cohortList, generateStats = TRUE) {

check <- purrr::map_chr(cohortList, ~methods::is(.x))

if(!all(check == "CohortDefinition")) {
stop("all cohorts need to be a Capr CohortDefinition class")
}

# get cohort names
cohortName <-purrr::map_chr(cohortList, ~slot(slot(.x, "CohortDetails"), "Name"))

#set basic genops for CirceR
genOp <- CirceR::createGenerateOptions(generateStats = generateStats)

#get the info from compiler
cohortInfo <- purrr::map(cohortList, ~compileCohortDefinition(.x,
generateOptions = genOp))

#get each element from compile
cohortSql <- purrr::map_chr(cohortInfo, ~getElement(.x, "ohdiSQL"))
cohortJson <- purrr::map_chr(cohortInfo, ~getElement(.x, "circeJson"))
cohortRead <- purrr::map_chr(cohortInfo, ~getElement(.x, "cohortRead"))


#create Data frame
df <- data.frame('atlasId' = seq_along(cohortList),
'cohortId' = seq_along(cohortList),
'cohortName'= cohortName,
'sql'= cohortSql,
'json' = cohortJson,
'read' = cohortRead)
return(df)
}

11 changes: 9 additions & 2 deletions R/UserCreateFn.R
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,11 @@ createConceptSetExpression <- function(conceptSet, Name, includeDescendants =TRU
isExcluded = isExcluded,
includeMapped = includeMapped)
#create the a new concept set expression from the concept set, this also sets the guid concept id
cse <- new("ConceptSetExpression", Name = Name, Expression = concepts)
cse <- new("ConceptSetExpression", Name = Name,
Expression = concepts)
#create guid for new cse
cse@id <- uuid::UUIDgenerate()


#attach the concept set expressions to a component class object
comp <- createComponent(Name = Name,
Expand Down Expand Up @@ -306,7 +310,10 @@ createConceptSetExpressionCustom <- function(conceptSet, Name, conceptMapping =
}
}
#create the a new concept set expression from the concept set, this also sets the guid concept id
cse <- new("ConceptSetExpression", Name = Name, Expression = concepts)
cse <- new("ConceptSetExpression", Name = Name,
Expression = concepts)
#create guid for new cse
cse@id <- uuid::UUIDgenerate()

#attach the concept set expressions to a component class object
comp <- createComponent(Name = Name,
Expand Down
7 changes: 4 additions & 3 deletions docs/404.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 2e92b03

Please sign in to comment.