Skip to content

Commit

Permalink
Merge pull request #227 from OHDSI/v0.1.2
Browse files Browse the repository at this point in the history
v0.1.2
  • Loading branch information
martaalcalde authored Nov 13, 2024
2 parents e5d68a1 + 46bc63a commit 0abd870
Show file tree
Hide file tree
Showing 55 changed files with 1,567 additions and 1,978 deletions.
4 changes: 3 additions & 1 deletion .github/workflows/test-coverage.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ permissions: read-all
jobs:
test-coverage:
runs-on: ubuntu-latest
env:
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}

steps:
- uses: actions/checkout@v4
Expand Down Expand Up @@ -42,7 +44,7 @@ jobs:
file: ./cobertura.xml
plugin: noop
disable_search: true
token: 8e3843c1-7a05-4c43-89ac-ddc8f0edff7d
token: ${{ secrets.CODECOV_TOKEN }}

- name: Show testthat output
if: always()
Expand Down
60 changes: 19 additions & 41 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: OmopSketch
Title: Characterise Tables of an OMOP Common Data Model Instance
Version: 0.1.1
Version: 0.1.2
Authors@R: c(
person(
"Marta", "Alcalde-Herraiz",
Expand All @@ -15,10 +15,6 @@ Authors@R: c(
"Elin", "Rowlands", email = "[email protected]",
role = c("aut"), comment = c(ORCID = "0009-0005-5166-0417")
),
person(
"Cecilia", "Campanile", email = "[email protected]",
role = c("aut"), comment = c(ORCID = "0009-0007-6629-4661")
),
person(
"Edward", "Burn", email = "[email protected]",
role = c("aut"), comment = c(ORCID = "0000-0002-9286-1128")
Expand All @@ -34,45 +30,27 @@ Description: Summarises key information in data mapped to the Observational
to obtain feasibility counts and trends.
License: Apache License (>= 2)
Encoding: UTF-8
Roxygen: list(markdown = TRUE)
RoxygenNote: 7.3.2
Suggests:
CodelistGenerator,
DBI,
duckdb,
flextable,
gt,
here,
knitr,
odbc,
remotes,
rmarkdown,
RPostgres,
testthat (>= 3.0.0),
withr,
omock (>= 0.3.0),
covr
Suggests: CodelistGenerator, DBI, here, knitr, odbc, remotes,
rmarkdown, RPostgres, testthat (>= 3.0.0), withr
Config/testthat/edition: 3
Config/testthat/parallel: true
Imports:
CDMConnector (>= 1.3.0),
cli,
clock,
CohortConstructor (>= 0.3.1),
dplyr,
ggplot2,
omopgenerics (>= 0.3.1),
PatientProfiles (>= 1.2.1),
purrr,
rlang,
stringr,
tibble,
tidyr,
visOmopResults (>= 0.4.0)
Depends:
R (>= 2.10)
Imports: CDMConnector (>= 1.3.0), cli, clock, gt, flextable,
CohortCharacteristics (>= 0.3.0), CohortConstructor (>= 0.3.1),
dplyr, ggplot2, omock (>= 0.3.0), omopgenerics (>= 0.3.1),
PatientProfiles (>= 1.2.0), purrr, rlang, stringr, tibble,
tidyr, visOmopResults (>= 0.4.0), duckdb
Depends: R (>= 2.10)
URL: https://OHDSI.github.io/OmopSketch/
BugReports: https://github.com/OHDSI/OmopSketch/issues
VignetteBuilder: knitr
Remotes:
darwin-eu-dev/omopgenerics
NeedsCompilation: no
Packaged: 2024-11-12 21:14:36 UTC; martaa
Author: Marta Alcalde-Herraiz [aut, cre]
(<https://orcid.org/0009-0002-4405-1814>),
Kim Lopez-Guell [aut] (<https://orcid.org/0000-0002-8462-8668>),
Elin Rowlands [aut] (<https://orcid.org/0009-0005-5166-0417>),
Edward Burn [aut] (<https://orcid.org/0000-0002-9286-1128>),
Martí Català [aut] (<https://orcid.org/0000-0003-3308-9905>)
Repository: CRAN
Date/Publication: 2024-11-12 21:40:07 UTC
6 changes: 2 additions & 4 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,18 @@ export(plotInObservation)
export(plotObservationPeriod)
export(plotRecordCount)
export(settings)
export(summariseAllConceptCounts)
export(summariseClinicalRecords)
export(summariseConceptCounts)
export(summariseInObservation)
export(summariseMissingData)
export(summariseObservationPeriod)
export(summariseOmopSnapshot)
export(summarisePopulationCharacteristics)
export(summariseRecordCount)
export(suppress)
export(tableAllConceptCounts)
export(tableClinicalRecords)
export(tableMissingData)
export(tableObservationPeriod)
export(tableOmopSnapshot)
export(tablePopulationCharacteristics)
importFrom(dplyr,"%>%")
importFrom(omopgenerics,bind)
importFrom(omopgenerics,exportSummarisedResult)
Expand Down
28 changes: 4 additions & 24 deletions R/checks.R
Original file line number Diff line number Diff line change
@@ -1,32 +1,12 @@
#' @noRd
checkInterval <- function(interval, call = parent.frame()){
omopgenerics::assertCharacter(interval, length = 1, na = FALSE, null = FALSE, call = call)
checkUnit <- function(unit, call = parent.frame()){
omopgenerics::assertCharacter(unit, length = 1, na = FALSE, null = FALSE, call = call)

if(!interval %in% c("year","month")){
cli::cli_abort("Interval argument {interval} is not valid. Valid options are either `year` or `month`.", call = call)
if(!unit %in% c("year","month")){
cli::cli_abort("Unit argument {unit} is not valid. Valid options are either `year` or `month`.", call = call)
}
}

validateIntervals <- function(interval, call = parent.frame()){

omopgenerics::assertCharacter(interval, length = 1, na = FALSE, null = FALSE, call = call)

if(!interval %in% c("overall","years","months","quarters")){
cli::cli_abort("Interval argument {interval} is not valid. Valid options are either `overall`, `years`, `quarters` or `months`.", call = call)
}

unitInterval <- dplyr::case_when(
interval == "overall" ~ NA,
interval == "quarters" ~ 4,
interval == "months" ~ 1,
interval == "years" ~ 1
)

if(interval == "quarters"){quarters <- "month"}else{interval <- gsub("s$","",interval)}

return(list("interval" = interval, "unitInterval" = unitInterval))
}

#' @noRd
checkCategory <- function(category, overlap = FALSE, type = "numeric", call = parent.frame()) {
omopgenerics::assertList(
Expand Down
3 changes: 3 additions & 0 deletions R/mockOmopSketch.R
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@
#' @return A mock cdm_reference object.
#' @export
#' @examples
#' \donttest{
#' library(OmopSketch)
#' mockOmopSketch(numberIndividuals = 100)
#' }
mockOmopSketch <- function(con = NULL,
writeSchema = NULL,
numberIndividuals = 100,
Expand Down
62 changes: 18 additions & 44 deletions R/plotConceptCounts.R
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
#' @export
#' @examples
#' \donttest{
#' library(dplyr)
#' library(dplyr, warn.conflicts = FALSE)
#'
#' cdm <- mockOmopSketch()
#'
Expand All @@ -22,8 +22,8 @@
#' )
#'
#' result |>
#' filter(variable_name == "Number subjects") |>
#' plotConceptCounts(facet = "codelist_name", colour = "standard_concept_name")
#' filter(estimate_name == "person_count", variable_name == "overall") |>
#' plotConceptCounts(facet = "codelist_name", colour = "codelist_name")
#'
#' PatientProfiles::mockDisconnect(cdm)
#' }
Expand All @@ -36,55 +36,29 @@ plotConceptCounts <- function(result,
# subset to results of interest
result <- result |>
visOmopResults::filterSettings(.data$result_type == "summarise_concept_counts")

if (nrow(result) == 0) {
cli::cli_abort(c("!" = "No records found with result_type == summarise_concept_counts"))
}

# check only one estimate is contained
variable <- unique(result$variable_name)
if (length(variable) > 1) {
estimate <- unique(result$estimate_name)
if (length(estimate) > 1) {
cli::cli_abort(c(
"!" = "Subset to the variable of interest, there are results from: {variable}.",
"i" = "result |> dplyr::filter(variable_name == '{variable[1]}')"
"!" = "Subset to the estimate of interest, there are results from: {estimate}.",
"i" = "result |> dplyr::filter(estimate_name == '{estimate[1]}')"
))
}

result1 <- result |> visOmopResults::splitAdditional()
# Detect if there are several time intervals
if("time_interval" %in% colnames(result1)){
# Line plot where each concept is a different line
p <- result1 |>
dplyr::filter(.data$time_interval != "overall") |>
visOmopResults::uniteAdditional(cols = c("time_interval", "standard_concept_name", "standard_concept_id", "source_concept_name", "source_concept_id", "domain_id")) |>
visOmopResults::scatterPlot(x = "time_interval",
y = "count",
line = TRUE,
point = TRUE,
ribbon = TRUE,
group = "standard_concept_name",
facet = facet,
colour = colour)
}else{
if("standard_concept_name" %in% colnames(result1)){
p <- result |>
visOmopResults::barPlot(x = "standard_concept_name",
y = "count",
facet = facet,
colour = colour)
}else{
p <- result |>
visOmopResults::barPlot(x = "codelist_name",
y = "count",
facet = facet,
colour = colour)
}
p <- p +
ggplot2::labs(
x = "Concept name"
)
}

p +
order <- c("overall", sort(unique(result$variable_name[result$variable_name != "overall"])))
result |>
dplyr::mutate(variable_name = factor(.data$variable_name,
levels = order)) |>
visOmopResults::barPlot(x = "variable_name",
y = estimate,
facet = facet,
colour = colour) +
ggplot2::labs(
x = "Concept name"
) +
ggplot2::theme(axis.text.x = ggplot2::element_text(angle = 90, vjust = 0.5, hjust = 1))
}
52 changes: 22 additions & 30 deletions R/plotInObservation.R
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#' @export
#' @examples
#' \donttest{
#' library(dplyr)
#' library(dplyr, warn.conflicts = FALSE)
#'
#' cdm <- mockOmopSketch()
#'
Expand Down Expand Up @@ -52,35 +52,27 @@ plotInObservation <- function(result,
}

# warn
warnFacetColour(result, list(facet = asCharacterFacet(facet), colour = colour, "additional_level"))
warnFacetColour(result, list(facet = asCharacterFacet(facet), colour = colour, "variable_level"))

# plot
if(length(unique(result$additional_level)) > 1 ){
result |>
dplyr::mutate(additional_level = as.character(gsub("-01$","",as.Date(gsub(" to.*","",.data$additional_level))))) |>
dplyr::filter(.data$estimate_name == "count") |>
visOmopResults::scatterPlot(
x = "time_interval",
y = "count",
line = TRUE,
point = TRUE,
ribbon = FALSE,
ymin = NULL,
ymax = NULL,
facet = facet,
colour = colour,
group = c("cdm_name", "omop_table", visOmopResults::strataColumns(result))
) +
ggplot2::labs(
y = variable,
x = "Date"
)
}else{
result |>
dplyr::filter(.data$estimate_name == "count") |>
visOmopResults::barPlot(x = "variable_name",
y = "count",
facet = facet,
colour = colour)
}
result |>
dplyr::mutate(variable_level = as.Date(stringr::str_extract(
.data$variable_level, "^[^ to]+"))) |>
dplyr::filter(.data$estimate_name == "count") |>
visOmopResults::scatterPlot(
x = "variable_level",
y = "count",
line = TRUE,
point = TRUE,
ribbon = FALSE,
ymin = NULL,
ymax = NULL,
facet = facet,
colour = colour,
group = c("cdm_name", "omop_table", visOmopResults::strataColumns(result))
) +
ggplot2::labs(
y = variable,
x = "Date"
)
}
14 changes: 7 additions & 7 deletions R/plotObservationPeriod.R
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,9 @@ plotObservationPeriod <- function(result,

validateFacet(facet, result)

optFacetColour <- c("cdm_name", "observation_period_ordinal",
visOmopResults::strataColumns(result))
omopgenerics::assertChoice(facet, optFacetColour, null = TRUE)
optFacetColour <- visOmopResults::tidyColumns(result)
optFacetColour <- optFacetColour[optFacetColour %in% visOmopResults::tidyColumns(result)]
omopgenerics::assertChoice(facet, optFacetColour, null = TRUE, call = call)

# this is due to bug in visOmopResults to remove in next release
# https://github.com/darwin-eu/visOmopResults/issues/246
Expand All @@ -68,7 +68,8 @@ plotObservationPeriod <- function(result,

if(length(visOmopResults::groupColumns(result)) == 0){
result <- result |>
dplyr::mutate(group_name = "observation_period_ordinal")
dplyr::mutate(group_name = "observation_period_ordinal",
group_level = "Overall")
}

if (plotType == "barplot") {
Expand All @@ -85,7 +86,7 @@ plotObservationPeriod <- function(result,
x = "observation_period_ordinal",
facet = facet,
colour = colour)
} else if (plotType == "densityplot") {
} else {
p <- visOmopResults::scatterPlot(
result = result,
x = "density_x",
Expand All @@ -95,8 +96,7 @@ plotObservationPeriod <- function(result,
ribbon = FALSE,
facet = facet,
colour = colour,
group = optFacetColour
) +
group = optFacetColour) +
ggplot2::xlab(stringr::str_to_sentence(unique(result$variable_name))) +
ggplot2::ylab("Density")
}
Expand Down
Loading

0 comments on commit 0abd870

Please sign in to comment.