Skip to content

Commit

Permalink
Release Version: 3.22.1
Browse files Browse the repository at this point in the history
- getPhenotypeLog() now returns the original user submitted cohort name, instead of the name forced by atlas-phenotype. 
- This is in line with the original requirement. It allows for long names, names with special characters.

- Deprecated listPhenotypes(). This was an older function that did the same as getPhenotypeLog() but returned only two fields.

- Added requirement on R (4.10) because tidyverse seems to cause problems with older versions of R.
  • Loading branch information
gowthamrao authored Sep 24, 2023
1 parent 8f1905b commit aba2fce
Show file tree
Hide file tree
Showing 48 changed files with 239 additions and 161 deletions.
6 changes: 4 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
Package: PhenotypeLibrary
Type: Package
Title: The OHDSI Phenotype Library
Version: 3.22.0
Date: 2023-09-23
Version: 3.22.1
Date: 2023-09-24
Author: Gowtham Rao [aut, cre]
Maintainer: Gowtham Rao <[email protected]>
Description: A repository to store the content of the OHDSI Phenotype library.
Depends:
R (>= 4.1.0)
Imports:
checkmate,
readr,
Expand Down
1 change: 0 additions & 1 deletion NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,4 @@ export(getPhenotypeLog)
export(getPlCohortDefinitionSet)
export(getPlConceptDefinitionSet)
export(listPhenotypes)
import(dplyr)
importFrom(rlang,.data)
10 changes: 10 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
PhenotypeLibrary 3.22.1
======================

- getPhenotypeLog() now returns the original user submitted cohort name, instead of the name forced by atlas-phenotype.
- This is in line with the original requirement. It allows for long names, names with special characters.

- Deprecated listPhenotypes(). This was an older function that did the same as getPhenotypeLog() but returned only two fields.

- Added requirement on R (4.10) because tidyverse seems to cause problems with older versions of R.

PhenotypeLibrary 3.22.0
======================
Accepted Cohorts: No cohorts were accepted in this release.
Expand Down
1 change: 0 additions & 1 deletion R/PhenotypeLibrary.R
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,5 @@
#' @keywords internal
"_PACKAGE"

#' @import dplyr
#' @importFrom rlang .data
NULL
94 changes: 79 additions & 15 deletions R/Phenotypes.R
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,22 @@
# See the License for the specific language governing permissions and
# limitations under the License.

#' List all phenotypes in the library
#' Deprecated. List all phenotypes in the library.
#'
#' @return
#' A tibble with the cohort ID and name.
#' Deprecated. Please use getPhenotypeLog
#'
#' @examples
#' listPhenotypes()
#'
#' @export
listPhenotypes <- function() {
cohorts <- readr::read_csv(system.file("Cohorts.csv", package = "PhenotypeLibrary"), col_types = readr::cols())
return(cohorts)
.Deprecated(
new = "getPhenotypeLog",
msg = "listPhenotypes is deprecated. use getPhenotypeLog"
)
getPhenotypeLog()
}

#' Get a cohort definition set
Expand All @@ -37,7 +41,7 @@ listPhenotypes <- function() {
#' `CohortGenerator` package.
#'
#' @examples
#' cohorts <- listPhenotypes()
#' cohorts <- getPhenotypeLog()
#' subsetIds <- cohorts$cohortId[1:3]
#' getPlCohortDefinitionSet(subsetIds)
#'
Expand All @@ -47,8 +51,8 @@ getPlCohortDefinitionSet <- function(cohortIds) {
checkmate::assertIntegerish(cohortIds, min.len = 1, add = errorMessages)
checkmate::reportAssertions(collection = errorMessages)

cohorts <- listPhenotypes() |>
filter(.data$cohortId %in% cohortIds) |>
cohorts <- getPhenotypeLog() |>
dplyr::filter(.data$cohortId %in% cohortIds) |>
dplyr::select(
"cohortId",
"cohortName"
Expand All @@ -68,15 +72,15 @@ getPlCohortDefinitionSet <- function(cohortIds) {
sql <-
readFile(file.path(sqlFolder, paste0(cohorts$cohortId[i], ".sql")))
output <- cohorts[i, ] |>
mutate(
dplyr::mutate(
json = !!json,
sql = !!sql
)
return(output)
}

result <- lapply(seq_len(nrow(cohorts)), getJsonAndSql) |>
bind_rows()
dplyr::bind_rows()

return(result)
}
Expand All @@ -98,19 +102,48 @@ getPlCohortDefinitionSet <- function(cohortIds) {
#' getPhenotypeLog(cohortIds = c(1, 2))
#'
#' @export
getPhenotypeLog <- function(cohortIds = listPhenotypes()$cohortId) {
log <-
readr::read_csv(
system.file("Cohorts.csv", package = "PhenotypeLibrary"),
getPhenotypeLog <- function(cohortIds = NULL) {
checkmate::assertIntegerish(cohortIds,
min.len = 0,
null.ok = TRUE
)

cohorts <-
readr::read_csv(system.file("Cohorts.csv", package = "PhenotypeLibrary"),
col_types = readr::cols()
) |>
dplyr::filter(.data$cohortId %in% c(cohortIds)) |>
dplyr::mutate(
newCohortName = dplyr::case_when(
!is.na(.data$cohortNameLong) &
cohortNameLong != "" ~ .data$cohortNameLong, !is.na(.data$cohortNameFormatted) &
cohortNameFormatted != "" ~ .data$cohortNameFormatted,
TRUE ~ .data$cohortName
)
) |>
dplyr::rename(
cohortNameAtlas = .data$cohortName,
cohortName = .data$newCohortName
) |>
dplyr::relocate(
.data$cohortId,
.data$cohortName
) |>
dplyr::arrange(.data$cohortId)

cohorts <- transformColumns(cohorts)

cohorts <- cohorts |>
dplyr::mutate(
addedDate = as.Date(.data$createdDate),
updatedDate = as.Date(.data$modifiedDate)
) |>
dplyr::arrange(.data$cohortId)
return(log)

if (!is.null(cohortIds)) {
cohorts <- cohorts |>
dplyr::filter(.data$cohortId %in% c(cohortIds))
}
return(cohorts)
}


Expand All @@ -130,9 +163,40 @@ getPhenotypeLog <- function(cohortIds = listPhenotypes()$cohortId) {
#'
#' @export
getPlConceptDefinitionSet <-
function(cohortIds = listPhenotypes()$cohortId) {
function(cohortIds = getPhenotypeLog()$cohortId) {
conceptSets <-
system.file("ConceptSetsInCohortDefinition.RDS", package = "PhenotypeLibrary") |>
readRDS()

if (!is.null(cohortIds)) {
conceptSets <- conceptSets |>
dplyr::filter(.data$cohortId %in% c(cohortIds))
}

conceptSets <- transformColumns(df = conceptSets)

return(conceptSets)
}


# Function to transform columns based on conditions
transformColumns <- function(df) {
# Iterate through each column
for (col_name in names(df)) {
col_data <- df[[col_name]]

# If column contains alphabets
if (any(grepl("[a-zA-Z]", col_data, ignore.case = TRUE))) {
# Replace NA with empty string
df[[col_name]][is.na(df[[col_name]])] <- ""
}

# If column contains only 0, 1, and NA
else if (all(col_data %in% c(0, 1, NA))) {
# Replace NA with 0
df[[col_name]][is.na(df[[col_name]])] <- 0
}
}
return(df |>
dplyr::tibble())
}
2 changes: 1 addition & 1 deletion docs/404.html

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

4 changes: 2 additions & 2 deletions docs/articles/CohortDefinitionSubmissionRequirements.html

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

8 changes: 4 additions & 4 deletions docs/articles/CohortDefinitionsInOhdsiPhenotypeLibrary.html

Large diffs are not rendered by default.

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

4 changes: 2 additions & 2 deletions docs/articles/GuidanceOnCohortDefinitionSetRObject.html

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

4 changes: 2 additions & 2 deletions docs/articles/GuidanceOnLiteratureReview.html

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

4 changes: 2 additions & 2 deletions docs/articles/GuidanceOnPerformingPeerReview.html

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

4 changes: 2 additions & 2 deletions docs/articles/GuidanceOnWritingAnEvaluationReport.html

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

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

Loading

0 comments on commit aba2fce

Please sign in to comment.