diff --git a/DESCRIPTION b/DESCRIPTION index 8184983..3d17f78 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: ResultModelManager Title: Result Model Manager -Version: 0.5.6 +Version: 0.5.7 Authors@R: person("Jamie", "Gilbert", , "gilbert@ohdsi.org", role = c("aut", "cre")) Description: Database data model management utilities for OHDSI packages. diff --git a/NEWS.md b/NEWS.md index b79f504..b72bd84 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,3 +1,9 @@ +# ResultModelManager 0.5.7 + +Bug fixes: + +1. Added type conversion checking on upload of data where columns are characters but interpreted as numeric from reading +inserted data # ResultModelManager 0.5.6 diff --git a/R/ConnectionHandler.R b/R/ConnectionHandler.R index 8d640f5..f70e7ac 100644 --- a/R/ConnectionHandler.R +++ b/R/ConnectionHandler.R @@ -1,4 +1,4 @@ -# Copyright 2023 Observational Health Data Sciences and Informatics +# Copyright 2024 Observational Health Data Sciences and Informatics # # This file is part of CemConnector # diff --git a/R/DataMigrationManager.R b/R/DataMigrationManager.R index 0aa2e46..f84eadc 100644 --- a/R/DataMigrationManager.R +++ b/R/DataMigrationManager.R @@ -1,4 +1,4 @@ -# Copyright 2023 Observational Health Data Sciences and Informatics +# Copyright 2024 Observational Health Data Sciences and Informatics # # This file is part of CohortDiagnostics # diff --git a/R/DataModel.R b/R/DataModel.R index 4531405..250e4e9 100644 --- a/R/DataModel.R +++ b/R/DataModel.R @@ -1,4 +1,4 @@ -# Copyright 2023 Observational Health Data Sciences and Informatics +# Copyright 2024 Observational Health Data Sciences and Informatics # # This file is part of OHdsiSharing # @@ -347,6 +347,10 @@ uploadChunk <- function(chunk, pos, env, specifications, resultsFolder, connecti # Check if inserting data would violate primary key constraints: if (!is.null(env$primaryKeyValuesInDb)) { + chunk <- formatChunk( + pkValuesInDb = env$primaryKeyValuesInDb, + chunk = chunk + ) primaryKeyValuesInChunk <- unique(chunk[env$primaryKey]) duplicates <- dplyr::inner_join(env$primaryKeyValuesInDb, @@ -791,3 +795,35 @@ loadResultsDataModelSpecifications <- function(filePath) { assertSpecificationColumns(colnames(spec)) return(spec) } + + +#' This helper function will convert the data in the +#' primary key values in the `chunk` which is read from +#' the csv file to the format of the primary key data +#' retrieved from the database (`pkValuesInDb`). The assumption made +#' by this function is that the `pkValuesInDb` reflect the proper data +#' types while `chunk` is the best guess from the readr +#' package. In the future, if we adopt strongly-types data.frames +#' this will no longer be necessary. +#' +#' Another assumption of this function is that we're only attempting to +#' recast to a character data type and not try to handle different type +#' conversions. +formatChunk <- function(pkValuesInDb, chunk) { + for (columnName in names(pkValuesInDb)) { + if (class(pkValuesInDb[[columnName]]) != class(chunk[[columnName]])) { + if (class(pkValuesInDb[[columnName]]) == "character") { + chunk <- chunk |> dplyr::mutate_at(columnName, as.character) + } else { + errorMsg <- paste0( + columnName, + " is of type ", + class(pkValuesInDb[[columnName]]), + " which cannot be converted between data frames pkValuesInDb and chunk" + ) + stop(errorMsg) + } + } + } + return(chunk) +} diff --git a/R/PooledConnectionHandler.R b/R/PooledConnectionHandler.R index c204330..caff359 100644 --- a/R/PooledConnectionHandler.R +++ b/R/PooledConnectionHandler.R @@ -1,4 +1,4 @@ -# Copyright 2023 Observational Health Data Sciences and Informatics +# Copyright 2024 Observational Health Data Sciences and Informatics # # This file is part of CohortDiagnostics # diff --git a/R/QueryNamespace.R b/R/QueryNamespace.R index 651df14..0d346d3 100644 --- a/R/QueryNamespace.R +++ b/R/QueryNamespace.R @@ -1,4 +1,4 @@ -# Copyright 2023 Observational Health Data Sciences and Informatics +# Copyright 2024 Observational Health Data Sciences and Informatics # # This file is part of CohortDiagnostics # diff --git a/R/ResultExportManager.R b/R/ResultExportManager.R index 8f45044..1d47b35 100644 --- a/R/ResultExportManager.R +++ b/R/ResultExportManager.R @@ -1,4 +1,4 @@ -# Copyright 2023 Observational Health Data Sciences and Informatics +# Copyright 2024 Observational Health Data Sciences and Informatics # # This file is part of CohortDiagnostics # diff --git a/R/ResultModelManager.R b/R/ResultModelManager.R index 7863103..ef9661e 100644 --- a/R/ResultModelManager.R +++ b/R/ResultModelManager.R @@ -1,4 +1,4 @@ -# Copyright 2023 Observational Health Data Sciences and Informatics +# Copyright 2024 Observational Health Data Sciences and Informatics # # This file is part of CohortDiagnostics # diff --git a/R/SchemaGenerator.R b/R/SchemaGenerator.R index 14b9c46..11232ac 100644 --- a/R/SchemaGenerator.R +++ b/R/SchemaGenerator.R @@ -1,4 +1,4 @@ -# Copyright 2023 Observational Health Data Sciences and Informatics +# Copyright 2024 Observational Health Data Sciences and Informatics # # This file is part of CohortDiagnostics # diff --git a/R/Utils.R b/R/Utils.R index c0ade61..8b0edec 100644 --- a/R/Utils.R +++ b/R/Utils.R @@ -1,4 +1,4 @@ -# Copyright 2023 Observational Health Data Sciences and Informatics +# Copyright 2024 Observational Health Data Sciences and Informatics # # This file is part of CohortDiagnostics # diff --git a/docs/404.html b/docs/404.html index 96e4e04..8b858dc 100644 --- a/docs/404.html +++ b/docs/404.html @@ -32,7 +32,7 @@
diff --git a/docs/LICENSE-text.html b/docs/LICENSE-text.html index 85cf394..23b1275 100644 --- a/docs/LICENSE-text.html +++ b/docs/LICENSE-text.html @@ -17,7 +17,7 @@ diff --git a/docs/articles/CreatingMigrations.html b/docs/articles/CreatingMigrations.html index eb192e9..c5013aa 100644 --- a/docs/articles/CreatingMigrations.html +++ b/docs/articles/CreatingMigrations.html @@ -33,7 +33,7 @@ @@ -97,7 +97,7 @@CreatingMigrations.Rmd
ExampleProject.Rmd
# note - the table prefix and schema parameters are not neeeded when we do this
qns$executeSql(sql)
-##
- |
- | | 0%
- |
- |=================================== | 50%
- |
- |======================================================================| 100%
-## Executing SQL took 0.0192 secs
+## | | | 0% | |=================================== | 50% | |======================================================================| 100%
+## Executing SQL took 0.0276 secs
Alternatively, we can just use DatabaseConnector
functions directly.
diff --git a/docs/articles/PackageDesign.html b/docs/articles/PackageDesign.html
index 62ef259..0e3c054 100644
--- a/docs/articles/PackageDesign.html
+++ b/docs/articles/PackageDesign.html
@@ -33,7 +33,7 @@
PackageDesign.Rmd
UploadFunctionality.Rmd
UsingAnExportManager.Rmd
-andr <- Andromeda::andromeda()
+andr <- Andromeda::andromeda()
andr$my_andromeda_table <- data.frame(covariate_id = 1:1e4, value = stats::runif(1e4))
first <- TRUE
@@ -252,7 +252,7 @@ Exporting an Andromeda result in
return(invisible(NULL))
}
-Andromeda::batchApply(andr$my_andromeda_table, writeBatch)
UsingConnectionHandlers.Rmd
UsingQueryNamespaces.Rmd
##
- |
- | | 0%
- |
- |======================================================================| 100%
-## Executing SQL took 0.0151 secs
+## | | | 0% | |======================================================================| 100%
+## Executing SQL took 0.0202 secs
We can then query the table with sql that automatically replaces the table names:
diff --git a/docs/articles/index.html b/docs/articles/index.html
index 912fbb0..b13f142 100644
--- a/docs/articles/index.html
+++ b/docs/articles/index.html
@@ -17,7 +17,7 @@
Gilbert J (2023). -ResultModelManager: Result Model Manager (RMM) for OHDSI packages. -R package version 0.5.6. +
Gilbert J (2024). +ResultModelManager: Result Model Manager. +R package version 0.5.7.
@Manual{, - title = {ResultModelManager: Result Model Manager (RMM) for OHDSI packages}, + title = {ResultModelManager: Result Model Manager}, author = {Jamie Gilbert}, - year = {2023}, - note = {R package version 0.5.6}, + year = {2024}, + note = {R package version 0.5.7}, }diff --git a/docs/index.html b/docs/index.html index d473049..73da5f5 100644 --- a/docs/index.html +++ b/docs/index.html @@ -5,13 +5,13 @@ -
ResultModelManager-package.Rd