Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 0 additions & 20 deletions R/validateUsagiFile.R
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
#' If usagi file has the ADD_INFO:sourceName_fi column:
#' - Check if sourceName_fi is less than 1000 characters
#' - Check if sourceName_fi is the same for all the rows of a sourceConceptId
#' - Warn if sourceName_fi is empty for APPROVED or UNCHECKED mappingStatus
#'
#' @param pathToUsagiFile Path to the Usagi mapping file to validate
#' @param connection A DatabaseConnector connection object
Expand Down Expand Up @@ -389,25 +388,6 @@ validateUsagiFile <- function(
} else {
validationLogR6$SUCCESS("SourceNameFi is not the same for all rows of the sourceConceptId", "")
}

# warn if sourceName_fi is empty, the column is optional so this is not an error
isEmptyNameFi <- usagiTibble$mappingStatus %in% c("APPROVED", "UNCHECKED") & is.na(usagiTibble$`ADD_INFO:sourceName_fi`)

if (any(isEmptyNameFi)) {
validationLogR6$WARNING(
"SourceNameFi is empty",
paste0("Found ", sum(isEmptyNameFi), " APPROVED or UNCHECKED rows with empty sourceName_fi")
)

usagiTibble <- usagiTibble |>
dplyr::mutate(tmpvalidationMessages = dplyr::if_else(
isEmptyNameFi,
paste0(tmpvalidationMessages, " | ", "WARNING: SourceNameFi is empty"),
tmpvalidationMessages
))
} else {
validationLogR6$SUCCESS("SourceNameFi is empty", "")
}
}

# - Check if ADD_INFO:sourceValidStartDate and ADD_INFO:sourceValidEndDate are used
Expand Down
1 change: 0 additions & 1 deletion man/validateUsagiFile.Rd

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

8 changes: 3 additions & 5 deletions tests/testthat/test-validateUsagiFile.R
Original file line number Diff line number Diff line change
Expand Up @@ -353,8 +353,7 @@ test_that("test validateUsagiFile validates ADD_INFO:sourceName_fi", {
validationsSummary |> dplyr::filter(type != "SUCCESS") |> dplyr::pull(step) |>
expect_setequal(c(
"SourceNameFi is more than 1000 characters",
"SourceNameFi is not the same for all rows of the sourceConceptId",
"SourceNameFi is empty"
"SourceNameFi is not the same for all rows of the sourceConceptId"
))

# SourceNameFi is more than 1000 characters
Expand All @@ -369,10 +368,9 @@ test_that("test validateUsagiFile validates ADD_INFO:sourceName_fi", {
expect_equal(rep("ERROR: SourceNameFi is not the same for all rows of the sourceConceptId", 2))
validatedUsagiFile |> dplyr::filter(sourceCode == "A02.2+H22.0") |> dplyr::pull(mappingStatus) |> expect_equal(rep("FLAGGED", 2))

# SourceNameFi is empty, only a warning, mappingStatus is not changed
validationsSummary |> dplyr::filter(step == "SourceNameFi is empty") |> dplyr::pull(type) |> as.character() |> expect_equal("WARNING")
# empty sourceName_fi is allowed, no message and mappingStatus is not changed
validatedUsagiFile |> dplyr::filter(sourceCode == "A01.0+I39.8") |> dplyr::pull(`ADD_INFO:validationMessages`) |>
expect_equal("WARNING: SourceNameFi is empty")
expect_equal(NA_character_)
validatedUsagiFile |> dplyr::filter(sourceCode == "A01.0+I39.8") |> dplyr::pull(mappingStatus) |> expect_equal("APPROVED")
})

Expand Down
7 changes: 1 addition & 6 deletions tests/testthat/test-validateVocabularyFolder.R
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,7 @@ test_that("validateVocabularyFolder returns all SUCCESS for valid vocabulary fol
)

# Check validation results
# only warning: UNITfi has the ADD_INFO:sourceName_fi column but all values are empty
notSuccess <- validationsLogTibble |> dplyr::filter(type != "SUCCESS")
notSuccess |> nrow() |> expect_equal(1)
notSuccess |> dplyr::pull(context) |> as.character() |> expect_equal("UNITfi")
notSuccess |> dplyr::pull(type) |> as.character() |> expect_equal("WARNING")
notSuccess |> dplyr::pull(step) |> expect_equal("SourceNameFi is empty")
validationsLogTibble |> dplyr::filter(type != "SUCCESS") |> nrow() |> expect_equal(0)

# Check that validated files were created
expect_true(dir.exists(pathToValidatedVocabularyFolder))
Expand Down
Loading