From e938536a0fa5e6ea64df1d4e702053fdde0cc173 Mon Sep 17 00:00:00 2001 From: Maarten van Kessel Date: Fri, 29 Nov 2024 10:16:52 +0100 Subject: [PATCH] Minor updates, including docs --- R/Module-TreatmentPatterns.R | 277 ++++++++------------------------- man/TreatmentPatternsModule.Rd | 96 +++++++++++- 2 files changed, 155 insertions(+), 218 deletions(-) diff --git a/R/Module-TreatmentPatterns.R b/R/Module-TreatmentPatterns.R index 6efcc64..f84df2b 100644 --- a/R/Module-TreatmentPatterns.R +++ b/R/Module-TreatmentPatterns.R @@ -1,4 +1,19 @@ -# TreatmentPatternsModule ------------- +# Copyright 2024 Observational Health Data Sciences and Informatics +# +# This file is part of Strategus +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + #' @title Evaluate phenotypes with the \href{https://github.com/darwin-eu/TreatmentPatterns/}{DARWIN TreatmentPatterns Package} #' @export #' @description @@ -66,6 +81,31 @@ TreatmentPatternsModule <- R6::R6Class( on.exit(Andromeda::close(outputEnv)) }, + #' @description Create the results data model for the module + #' @template resultsConnectionDetails + #' @template resultsDatabaseSchema + #' @template tablePrefix + createResultsDataModel = function(resultsConnectionDetails, resultsDatabaseSchema, tablePrefix = "") { + super$createResultsDataModel(resultsConnectionDetails, resultsDatabaseSchema, tablePrefix) + message("`createResultsDataModel()` is not implemented.") + }, + + #' @description Get the results data model specification for the module + #' @template tablePrefix + getResultsDataModelSpecification = function(tablePrefix = "") { + super$getResultsDataModelSpecification() + message("`getResultsDataModelSpecification()` is not implemented") + }, + + #' @description Upload the results for TreatmentPatterns + #' @template resultsConnectionDetails + #' @template analysisSpecifications + #' @template resultsDataModelSettings + uploadResults = function(resultsConnectionDetails, analysisSpecifications, resultsDataModelSettings) { + super$uplaodResults(resultsConnectionDetails, analysisSpecifications, resultsDataModelSettings) + message("`uploadResults()` is not implemented") + }, + #' @description Creates the TreatmentPatternsnModule Specifications #' #' @param cohorts (`data.frame()`)\cr @@ -125,226 +165,33 @@ TreatmentPatternsModule <- R6::R6Class( #' \item{`"remove"`}{Censors pathways <`minCellCount` by removing them completely.} #' \item{`"mean"`}{Censors pathways <`minCellCount` to the mean of all frequencies below `minCellCount`} #' } - createModuleSpecifications = function(cohorts, - cohortTableName, - connectionDetails = NULL, - cdmSchema = NULL, - resultSchema = NULL, - tempEmulationSchema = NULL, - includeTreatments = "startDate", - indexDateOffset = 0, - minEraDuration = 0, - splitEventCohorts = NULL, - splitTime = NULL, - eraCollapseSize = 30, - combinationWindow = 30, - minPostCombinationDuration = 30, - filterTreatments = "First", - maxPathLength = 5, - ageWindow = 5, - minCellCount = 1, - censorType = "minCellCount" + createModuleSpecifications = function( + cohorts, + cohortTableName, + connectionDetails = NULL, + cdmSchema = NULL, + resultSchema = NULL, + tempEmulationSchema = NULL, + includeTreatments = "startDate", + indexDateOffset = 0, + minEraDuration = 0, + splitEventCohorts = NULL, + splitTime = NULL, + eraCollapseSize = 30, + combinationWindow = 30, + minPostCombinationDuration = 30, + filterTreatments = "First", + maxPathLength = 5, + ageWindow = 5, + minCellCount = 1, + censorType = "minCellCount" ) { - # input checks - validateComputePathways <- function() { - args <- eval( - # Expression to get names of function arguments in current function - expr = expression(mget(names(formals()))), - # Run expression in function that calls `validateComputePathways` - envir = sys.frame(sys.nframe() - 1) - ) - - if (args$minEraDuration > args$minPostCombinationDuration) { - warning("The `minPostCombinationDuration` is set lower than the `minEraDuration`, this might result in unexpected behavior") - } - - if (args$minEraDuration > args$combinationWindow) { - warning("The `combinationWindow` is set lower than the `minEraDuration`, this might result in unexpected behavior") - } - - assertCol <- checkmate::makeAssertCollection() - - checkmate::assertCharacter( - args$includeTreatments, - len = 1, - add = assertCol, - .var.name = "includeTreatments" - ) - - checkmate::assertSubset( - args$includeTreatments, - choices = c("startDate", "endDate"), - add = assertCol, - .var.name = "includeTreatments" - ) - - checkmate::assertNumeric( - args$indexDateOffset, - len = 1, - finite = TRUE, - null.ok = FALSE, - add = assertCol, - .var.name = "indexDateOffset" - ) - - checkmate::assertNumeric( - x = args$minEraDuration, - lower = 0, - finite = TRUE, - len = 1, - null.ok = FALSE, - add = assertCol, - .var.name = "minEraDuration" - ) - - checkmate::assertIntegerish( - x = args$splitEventCohorts, - null.ok = TRUE, - add = assertCol, - .var.name = "splitEventCohorts" - ) - - checkmate::assertIntegerish( - x = args$splitTime, - lower = 0, - null.ok = TRUE, - add = assertCol, - .var.name = "splitTime" - ) - - checkmate::assertNumeric( - x = args$eraCollapseSize, - lower = 0, - finite = TRUE, - len = 1, - null.ok = FALSE, - add = assertCol, - .var.name = "eraCollapseSize" - ) - - checkmate::assertNumeric( - x = args$combinationWindow, - lower = 0, - finite = TRUE, - len = 1, - null.ok = FALSE, - add = assertCol, - .var.name = "combinationWindow" - ) - - checkmate::assertNumeric( - x = args$minPostCombinationDuration, - lower = 0, - finite = TRUE, - len = 1, - null.ok = FALSE, - add = assertCol, - .var.name = "minPostCombinationDuration" - ) - - checkmate::assertCharacter( - x = args$filterTreatments, - len = 1, - add = assertCol, - .var.name = "filterTreatments" - ) - - checkmate::assertSubset( - x = args$filterTreatments, - choices = c("First", "Changes", "All"), - add = assertCol, - .var.name = "filterTreatments" - ) - - checkmate::assertNumeric( - x = args$maxPathLength, - lower = 0, - upper = 5, - finite = TRUE, - len = 1, - null.ok = FALSE, - add = assertCol, - .var.name = "maxPathLength" - ) - - checkmate::assertDataFrame( - x = args$cohorts, - types = c("integerish", "character", "character"), - any.missing = FALSE, - all.missing = FALSE, - ncols = 3, - min.rows = 1, - col.names = "named", - add = assertCol, - .var.name = "cohorts" - ) - - checkmate::assertSubset( - x = names(args$cohorts), - choices = c("cohortId", "cohortName", "type"), - add = assertCol, - .var.name = "cohorts" - ) - - checkmate::assertSubset( - x = args$cohorts$type, - choices = c("event", "target", "exit"), - add = assertCol, - .var.name = "cohorts" - ) - - checkmate::assertCharacter( - x = args$cohortTableName, - len = 1, - null.ok = FALSE, - .var.name = "cohortTableName" - ) - - checkmate::assertClass( - x = args$connectionDetails, - classes = "ConnectionDetails", - null.ok = TRUE, - add = assertCol, - .var.name = "connectionDetails" - ) - - checkmate::assertCharacter( - x = args$connectionDetails$dbms, - len = 1, - null.ok = TRUE, - add = assertCol, - .var.name = "connectionDetails" - ) - - checkmate::assertCharacter( - args$cdmDatabaseSchema, - null.ok = TRUE, - len = 1, - add = assertCol, - .var.name = "cdmDatabaseSchema" - ) - - checkmate::assertCharacter( - args$resultSchema, - null.ok = TRUE, - len = 1, - add = assertCol, - .var.name = "resultSchema" - ) - - checkmate::reportAssertions(collection = assertCol) - } - validateComputePathways() - analysis <- list() for (name in names(formals(self$createModuleSpecifications))) { analysis[[name]] <- get(name) } - specifications <- super$createModuleSpecifications( - moduleSpecifications = analysis - ) - return(specifications) + super$createModuleSpecifications(analysis) }, #' @description Validate the module specifications diff --git a/man/TreatmentPatternsModule.Rd b/man/TreatmentPatternsModule.Rd index bd8e11e..e735edb 100644 --- a/man/TreatmentPatternsModule.Rd +++ b/man/TreatmentPatternsModule.Rd @@ -21,6 +21,9 @@ Characterisation and description of patterns of events (cohorts). against the OM \itemize{ \item \href{#method-TreatmentPatternsModule-new}{\code{TreatmentPatternsModule$new()}} \item \href{#method-TreatmentPatternsModule-execute}{\code{TreatmentPatternsModule$execute()}} +\item \href{#method-TreatmentPatternsModule-createResultsDataModel}{\code{TreatmentPatternsModule$createResultsDataModel()}} +\item \href{#method-TreatmentPatternsModule-getResultsDataModelSpecification}{\code{TreatmentPatternsModule$getResultsDataModelSpecification()}} +\item \href{#method-TreatmentPatternsModule-uploadResults}{\code{TreatmentPatternsModule$uploadResults()}} \item \href{#method-TreatmentPatternsModule-createModuleSpecifications}{\code{TreatmentPatternsModule$createModuleSpecifications()}} \item \href{#method-TreatmentPatternsModule-validateModuleSpecifications}{\code{TreatmentPatternsModule$validateModuleSpecifications()}} \item \href{#method-TreatmentPatternsModule-clone}{\code{TreatmentPatternsModule$clone()}} @@ -29,10 +32,7 @@ Characterisation and description of patterns of events (cohorts). against the OM \if{html}{\out{
Inherited methods
@@ -69,6 +69,9 @@ Execute Treatment Patterns \item{\code{analysisSpecifications}}{An object of type \code{AnalysisSpecifications} as created by \code{\link[=createEmptyAnalysisSpecificiations]{createEmptyAnalysisSpecificiations()}}.} +\item{\code{analysisSpecifications}}{An object of type \code{AnalysisSpecifications} as created +by \code{\link[=createEmptyAnalysisSpecificiations]{createEmptyAnalysisSpecificiations()}}.} + \item{\code{executionSettings}}{An object of type \code{ExecutionSettings} as created by \code{\link[=createCdmExecutionSettings]{createCdmExecutionSettings()}} or \code{\link[=createResultsExecutionSettings]{createResultsExecutionSettings()}}.} } @@ -76,6 +79,93 @@ by \code{\link[=createCdmExecutionSettings]{createCdmExecutionSettings()}} or \c } } \if{html}{\out{
}} +\if{html}{\out{}} +\if{latex}{\out{\hypertarget{method-TreatmentPatternsModule-createResultsDataModel}{}}} +\subsection{Method \code{createResultsDataModel()}}{ +Create the results data model for the module +\subsection{Usage}{ +\if{html}{\out{
}}\preformatted{TreatmentPatternsModule$createResultsDataModel( + resultsConnectionDetails, + resultsDatabaseSchema, + tablePrefix = "" +)}\if{html}{\out{
}} +} + +\subsection{Arguments}{ +\if{html}{\out{
}} +\describe{ +\item{\code{resultsConnectionDetails}}{The connection details to the results database which +is an object of class \code{connectionDetails} as created by the +\code{\link[DatabaseConnector:createConnectionDetails]{DatabaseConnector::createConnectionDetails()}} function.} + +\item{\code{resultsConnectionDetails}}{The connection details to the results database which +is an object of class \code{connectionDetails} as created by the +\code{\link[DatabaseConnector:createConnectionDetails]{DatabaseConnector::createConnectionDetails()}} function.} + +\item{\code{resultsDatabaseSchema}}{The schema in the results database that holds the results data model.} + +\item{\code{tablePrefix}}{A prefix to apply to the database table names (optional).} + +\item{\code{tablePrefix}}{A prefix to apply to the database table names (optional).} +} +\if{html}{\out{
}} +} +} +\if{html}{\out{
}} +\if{html}{\out{}} +\if{latex}{\out{\hypertarget{method-TreatmentPatternsModule-getResultsDataModelSpecification}{}}} +\subsection{Method \code{getResultsDataModelSpecification()}}{ +Get the results data model specification for the module +\subsection{Usage}{ +\if{html}{\out{
}}\preformatted{TreatmentPatternsModule$getResultsDataModelSpecification(tablePrefix = "")}\if{html}{\out{
}} +} + +\subsection{Arguments}{ +\if{html}{\out{
}} +\describe{ +\item{\code{tablePrefix}}{A prefix to apply to the database table names (optional).} + +\item{\code{tablePrefix}}{A prefix to apply to the database table names (optional).} +} +\if{html}{\out{
}} +} +} +\if{html}{\out{
}} +\if{html}{\out{}} +\if{latex}{\out{\hypertarget{method-TreatmentPatternsModule-uploadResults}{}}} +\subsection{Method \code{uploadResults()}}{ +Upload the results for TreatmentPatterns +\subsection{Usage}{ +\if{html}{\out{
}}\preformatted{TreatmentPatternsModule$uploadResults( + resultsConnectionDetails, + analysisSpecifications, + resultsDataModelSettings +)}\if{html}{\out{
}} +} + +\subsection{Arguments}{ +\if{html}{\out{
}} +\describe{ +\item{\code{resultsConnectionDetails}}{The connection details to the results database which +is an object of class \code{connectionDetails} as created by the +\code{\link[DatabaseConnector:createConnectionDetails]{DatabaseConnector::createConnectionDetails()}} function.} + +\item{\code{resultsConnectionDetails}}{The connection details to the results database which +is an object of class \code{connectionDetails} as created by the +\code{\link[DatabaseConnector:createConnectionDetails]{DatabaseConnector::createConnectionDetails()}} function.} + +\item{\code{analysisSpecifications}}{An object of type \code{AnalysisSpecifications} as created +by \code{\link[=createEmptyAnalysisSpecificiations]{createEmptyAnalysisSpecificiations()}}.} + +\item{\code{analysisSpecifications}}{An object of type \code{AnalysisSpecifications} as created +by \code{\link[=createEmptyAnalysisSpecificiations]{createEmptyAnalysisSpecificiations()}}.} + +\item{\code{resultsDataModelSettings}}{The results data model settings as created using [@seealso \code{\link[=createResultsDataModelSettings]{createResultsDataModelSettings()}}]} +} +\if{html}{\out{
}} +} +} +\if{html}{\out{
}} \if{html}{\out{}} \if{latex}{\out{\hypertarget{method-TreatmentPatternsModule-createModuleSpecifications}{}}} \subsection{Method \code{createModuleSpecifications()}}{