Skip to content

Commit

Permalink
pass checks
Browse files Browse the repository at this point in the history
  • Loading branch information
catalamarti committed Dec 18, 2024
1 parent 1c76b59 commit 9c78bf4
Show file tree
Hide file tree
Showing 31 changed files with 509 additions and 965 deletions.
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ export(tableMissingData)
export(tableObservationPeriod)
export(tableOmopSnapshot)
importFrom(dplyr,"%>%")
importFrom(lifecycle,deprecated)
importFrom(omopgenerics,bind)
importFrom(omopgenerics,exportSummarisedResult)
importFrom(omopgenerics,importSummarisedResult)
Expand Down
5 changes: 3 additions & 2 deletions R/OmopSketch-package.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@
"_PACKAGE"

## usethis namespace: start
#' @importFrom dplyr %>%
#' @importFrom lifecycle deprecated
#' @importFrom rlang :=
#' @importFrom rlang .data
#' @importFrom rlang .env
#' @importFrom rlang :=
#' @importFrom rlang %||%
#' @importFrom dplyr %>%
## usethis namespace: end
NULL
26 changes: 0 additions & 26 deletions R/restrictStudyPeriod.R

This file was deleted.

44 changes: 15 additions & 29 deletions R/summariseAllConceptCounts.R
Original file line number Diff line number Diff line change
@@ -1,22 +1,4 @@

my_getStrataList <- function(sex = FALSE, ageGroup = NULL, year = FALSE){
c(names(ageGroup), "sex"[sex], "year"[year])
}
checkFeasibility <- function(omopTable, tableName, conceptId) {

if (omopgenerics::isTableEmpty(omopTable)){
cli::cli_warn(paste0(tableName, " omop table is empty."))
return(NULL)
}

if (is.na(conceptId)){
cli::cli_warn(paste0(tableName, " omop table doesn't contain standard concepts."))
return(NULL)
}

return(TRUE)
}

#' Summarise concept use in patient-level data
#'
#' @param cdm A cdm object
Expand Down Expand Up @@ -67,35 +49,39 @@ summariseAllConceptCounts <- function(cdm,
omopgenerics::assertChoice(omopTableName, choices = omopgenerics::omopTables(), unique = TRUE)
ageGroup <- omopgenerics::validateAgeGroupArgument(ageGroup)
dateRange <- validateStudyPeriod(cdm, dateRange)
omopgenerics::assertNumeric(sample, integerish = TRUE, min = 1, null = TRUE, length = 1)

# settings for the created results
set <- createSettings(result_type = "summarise_all_concept_counts", study_period = dateRange)

# get strata
strata <- my_getStrataList(sex = sex, year = year, ageGroup = ageGroup) |>
omopgenerics::combineStrata()
strata <- omopgenerics::combineStrata(c(strataCols(sex = sex, ageGroup = ageGroup), "year"[year]))
concepts <- c("concept_id", "concept_name")
stratax <- c(list(concepts), purrr::map(strata, \(x) c(concepts, x)))

# how to count
counts <- c("records", "person_id")[c("record", "person") %in% countBy]

# summarise counts
resultTables <- purrr::map(omopTableName, function(table) {
# check that table is not empty
resultTables <- purrr::map(omopTableName, \(table) {
# initial table
omopTable <- dplyr::ungroup(cdm[[table]])
conceptId <- standardConcept(table)
if (is.null(checkFeasibility(omopTable, table, conceptId))) {
conceptId <- omopgenerics::omopColumns(table = table, field = "standard_concept")
if (is.na(conceptId)) {
cli::cli_warn(c("!" = "No standard concept identified for {table}."))
return(NULL)
}
prefix <- omopgenerics::tmpPrefix()

# add concept id to stratification
concepts <- c("concept_id", "concept_name")
stratax <- c(list(concepts), purrr::map(strata, \(x) c(concepts, x)))
prefix <- omopgenerics::tmpPrefix()

# restrict study period
omopTable <- restrictStudyPeriod(omopTable, dateRange)
if (is.null(omopTable)) return(NULL)

# sample table
omopTable <- omopTable |>
sampleOmopTable(sample = sample, name = omopgenerics::uniqueTableName(prefix))

result <- omopTable |>
# add concept names
dplyr::rename(concept_id = dplyr::all_of(conceptId)) |>
Expand All @@ -106,7 +92,7 @@ summariseAllConceptCounts <- function(cdm,
) |>
# add demographics and year
addStratifications(
indexDate = startDate(omopgenerics::tableName(omopTable)),
indexDate = omopgenerics::omopColumns(table = table, field = "start_date"),
sex = sex,
ageGroup = ageGroup,
interval = dplyr::if_else(year, "years", "overall"),
Expand Down
20 changes: 9 additions & 11 deletions R/summariseClinicalRecords.R
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ summariseClinicalRecords <- function(cdm,
typeConcept = TRUE,
sex = FALSE,
ageGroup = NULL,
sample = 1000000,
sample = NULL,
dateRange = NULL) {
# Initial checks ----
omopgenerics::validateCdmArgument(cdm)
Expand All @@ -78,6 +78,7 @@ summariseClinicalRecords <- function(cdm,
omopgenerics::assertLogical(typeConcept, length = 1)
omopgenerics::assertLogical(sex, length = 1)
ageGroup <- omopgenerics::validateAgeGroupArgument(ageGroup, multipleAgeGroup = FALSE)
omopgenerics::assertNumeric(sample, integerish = TRUE, min = 1, null = TRUE, length = 1)

# warnings for observation_period
warnStandardConcept <- standardConcept & !missing(standardConcept)
Expand All @@ -90,7 +91,7 @@ summariseClinicalRecords <- function(cdm,
# get strata
strata <- c(
list(character()),
omopgenerics::combineStrata(c(names(ageGroup), "sex"[sex]))
omopgenerics::combineStrata(strataCols(sex = sex, ageGroup = ageGroup))
)

# create denominator for record count
Expand Down Expand Up @@ -278,9 +279,6 @@ summariseClinicalRecords <- function(cdm,
return(result)
}

getStrataList <- function(sex, ageGroup){
omopgenerics::combineStrata(c("age_group"[!is.null(ageGroup)], "sex"[sex]))
}
summariseRecordsPerPerson <- function(x, den, strata, estimates) {
# strata
strataCols <- unique(unlist(strata))
Expand Down Expand Up @@ -394,12 +392,12 @@ addVariables <- function(x, inObservation, standardConcept, sourceVocabulary, do
newNames <- c(
# here to support death table
person_id = "person_id",
id = tableId(name),
start_date = startDate(name),
end_date = endDate(name),
standard = standardConcept(name),
source = sourceConcept(name),
type_concept = typeConcept(name)
id = omopgenerics::omopColumns(table = name, field = "unique_id"),
start_date = omopgenerics::omopColumns(table = name, field = "start_date"),
end_date = omopgenerics::omopColumns(table = name, field = "end_date"),
standard = omopgenerics::omopColumns(table = name, field = "standard_concept"),
source = omopgenerics::omopColumns(table = name, field = "source_concept"),
type_concept = omopgenerics::omopColumns(table = name, field = "type_concept")
)

newNames <- newNames[!is.na(newNames)]
Expand Down
Loading

0 comments on commit 9c78bf4

Please sign in to comment.