Skip to content

Commit

Permalink
Handle data types for primary keys - character conversion only (#53)
Browse files Browse the repository at this point in the history
* Handle data types for primary keys - character conversion only

* Added chat gipty tests

* Added chat gipty tests

* changed usage of mittagr

* Fixes to tests

* Updated news

* Package maintenance

---------

Co-authored-by: Jamie Gilbert <[email protected]>
  • Loading branch information
anthonysena and azimov authored May 2, 2024
1 parent 02a5906 commit 665b71a
Show file tree
Hide file tree
Showing 45 changed files with 193 additions and 85 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: ResultModelManager
Title: Result Model Manager
Version: 0.5.6
Version: 0.5.7
Authors@R:
person("Jamie", "Gilbert", , "[email protected]", role = c("aut", "cre"))
Description: Database data model management utilities for OHDSI packages.
Expand Down
6 changes: 6 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -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

Expand Down
2 changes: 1 addition & 1 deletion R/ConnectionHandler.R
Original file line number Diff line number Diff line change
@@ -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
#
Expand Down
2 changes: 1 addition & 1 deletion R/DataMigrationManager.R
Original file line number Diff line number Diff line change
@@ -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
#
Expand Down
38 changes: 37 additions & 1 deletion R/DataModel.R
Original file line number Diff line number Diff line change
@@ -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
#
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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)
}
2 changes: 1 addition & 1 deletion R/PooledConnectionHandler.R
Original file line number Diff line number Diff line change
@@ -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
#
Expand Down
2 changes: 1 addition & 1 deletion R/QueryNamespace.R
Original file line number Diff line number Diff line change
@@ -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
#
Expand Down
2 changes: 1 addition & 1 deletion R/ResultExportManager.R
Original file line number Diff line number Diff line change
@@ -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
#
Expand Down
2 changes: 1 addition & 1 deletion R/ResultModelManager.R
Original file line number Diff line number Diff line change
@@ -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
#
Expand Down
2 changes: 1 addition & 1 deletion R/SchemaGenerator.R
Original file line number Diff line number Diff line change
@@ -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
#
Expand Down
2 changes: 1 addition & 1 deletion R/Utils.R
Original file line number Diff line number Diff line change
@@ -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
#
Expand Down
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.

2 changes: 1 addition & 1 deletion docs/LICENSE-text.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/CreatingMigrations.html

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

14 changes: 4 additions & 10 deletions docs/articles/ExampleProject.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/PackageDesign.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/UploadFunctionality.html

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

10 changes: 5 additions & 5 deletions docs/articles/UsingAnExportManager.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/UsingConnectionHandlers.html

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

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

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

2 changes: 1 addition & 1 deletion docs/articles/index.html

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

14 changes: 7 additions & 7 deletions docs/authors.html

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

Loading

0 comments on commit 665b71a

Please sign in to comment.