Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

More small bugfixes #502

Merged
merged 2 commits into from
Nov 4, 2023
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
2 changes: 1 addition & 1 deletion R/writeJsonResultsTo.R
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ writeJsonResultsToTable <- function(connectionDetails,

ParallelLogger::logInfo(sprintf("Writing results to table %s", tableName))

if ("unitConceptId" %in% colnames(df)) {
if ("conceptId" %in% colnames(df)) {
ddl <- SqlRender::loadRenderTranslateSql(
sqlFilename = "result_table_ddl_concept.sql",
packageName = "DataQualityDashboard",
Expand Down
6 changes: 3 additions & 3 deletions inst/sql/sql_server/field_fk_class.sql
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ FK_CLASS
Drug era standard concepts, ingredients only

Parameters used in this template:
cdmDatabaseSchema = @cdmDatabaseSchema
schema = @schema
vocabDatabaseSchema = @vocabDatabaseSchema
cdmTableName = @cdmTableName
cdmFieldName = @cdmFieldName
Expand Down Expand Up @@ -32,7 +32,7 @@ FROM (
SELECT
'@cdmTableName.@cdmFieldName' AS violating_field,
cdmTable.*
FROM @cdmDatabaseSchema.@cdmTableName cdmTable
FROM @schema.@cdmTableName cdmTable
LEFT JOIN @vocabDatabaseSchema.concept co
ON cdmTable.@cdmFieldName = co.concept_id
{@cohort & '@runForCohort' == 'Yes'}?{
Expand All @@ -48,7 +48,7 @@ FROM (
(
SELECT
COUNT_BIG(*) AS num_rows
FROM @cdmDatabaseSchema.@cdmTableName cdmTable
FROM @schema.@cdmTableName cdmTable
{@cohort & '@runForCohort' == 'Yes'}?{
JOIN @cohortDatabaseSchema.@cohortTableName c
ON cdmTable.person_id = c.subject_id
Expand Down
6 changes: 3 additions & 3 deletions inst/sql/sql_server/field_fk_domain.sql
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ FIELD_FK_DOMAIN
all standard concept ids are part of specified domain

Parameters used in this template:
cdmDatabaseSchema = @cdmDatabaseSchema
schema = @schema
vocabDatabaseSchema = @vocabDatabaseSchema
cdmTableName = @cdmTableName
cdmFieldName = @cdmFieldName
Expand All @@ -32,7 +32,7 @@ FROM (
SELECT
'@cdmTableName.@cdmFieldName' AS violating_field,
cdmTable.*
FROM @cdmDatabaseSchema.@cdmTableName cdmTable
FROM @schema.@cdmTableName cdmTable
LEFT JOIN @vocabDatabaseSchema.concept co
ON cdmTable.@cdmFieldName = co.concept_id
{@cohort & '@runForCohort' == 'Yes'}?{
Expand All @@ -48,7 +48,7 @@ FROM (
(
SELECT
COUNT_BIG(*) AS num_rows
FROM @cdmDatabaseSchema.@cdmTableName cdmTable
FROM @schema.@cdmTableName cdmTable
{@cohort & '@runForCohort' == 'Yes'}?{
JOIN @cohortDatabaseSchema.@cohortTableName c
ON cdmTable.PERSON_ID = c.SUBJECT_ID
Expand Down
10 changes: 5 additions & 5 deletions inst/sql/sql_server/field_plausible_temporal_after.sql
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ PLAUSIBLE_TEMPORAL_AFTER
get number of records and the proportion to total number of eligible records with datetimes that do not occur on or after their corresponding datetimes

Parameters used in this template:
cdmDatabaseSchema = @cdmDatabaseSchema
schema = @schema
cdmTableName = @cdmTableName
cdmFieldName = @cdmFieldName
plausibleTemporalAfterTableName = @plausibleTemporalAfterTableName
Expand Down Expand Up @@ -33,9 +33,9 @@ FROM
SELECT
'@cdmTableName.@cdmFieldName' AS violating_field,
cdmTable.*
FROM @cdmDatabaseSchema.@cdmTableName cdmTable
{@cdmDatabaseSchema.@cdmTableName != @cdmDatabaseSchema.@plausibleTemporalAfterTableName}?{
JOIN @cdmDatabaseSchema.@plausibleTemporalAfterTableName plausibleTable ON cdmTable.person_id = plausibleTable.person_id}
FROM @schema.@cdmTableName cdmTable
{@schema.@cdmTableName != @schema.@plausibleTemporalAfterTableName}?{
JOIN @schema.@plausibleTemporalAfterTableName plausibleTable ON cdmTable.person_id = plausibleTable.person_id}
{@cohort & '@runForCohort' == 'Yes'}?{
JOIN @cohortDatabaseSchema.@cohortTableName c ON cdmTable.person_id = c.subject_id
AND c.cohort_definition_id = @cohortDefinitionId
Expand All @@ -55,7 +55,7 @@ FROM
(
SELECT
COUNT_BIG(*) AS num_rows
FROM @cdmDatabaseSchema.@cdmTableName cdmTable
FROM @schema.@cdmTableName cdmTable
{@cohort & '@runForCohort' == 'Yes'}?{
JOIN @cohortDatabaseSchema.@cohortTableName c ON cdmTable.person_id = c.subject_id
AND c.cohort_definition_id = @cohortDefinitionId
Expand Down
27 changes: 27 additions & 0 deletions tests/testthat/test-executeDqChecks.R
Original file line number Diff line number Diff line change
Expand Up @@ -328,3 +328,30 @@ test_that("Incremental insert SQL is valid.", {

DatabaseConnector::renderTranslateExecuteSql(connection, "DROP TABLE @database_schema.dqd_results;", database_schema = resultsDatabaseSchemaEunomia)
})

test_that("Multiple cdm_source rows triggers warning.", {
outputFolder <- tempfile("dqd_")
on.exit(unlink(outputFolder, recursive = TRUE))

connectionDetailsEunomiaCS <- Eunomia::getEunomiaConnectionDetails()
connection <- DatabaseConnector::connect(connectionDetailsEunomiaCS)
on.exit(DatabaseConnector::disconnect(connection), add = TRUE)
DatabaseConnector::renderTranslateExecuteSql(connection, "INSERT INTO @database_schema.cdm_source VALUES ('foo',NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL);", database_schema = cdmDatabaseSchemaEunomia)

w <- capture_warnings(
results <- executeDqChecks(
connectionDetails = connectionDetailsEunomiaCS,
cdmDatabaseSchema = cdmDatabaseSchemaEunomia,
resultsDatabaseSchema = resultsDatabaseSchemaEunomia,
cdmSourceName = "Eunomia",
checkNames = "measurePersonCompleteness",
outputFolder = outputFolder,
writeToTable = F
))

expect_match(w, "Missing check names", all = FALSE)
expect_match(w, "The cdm_source table has", all = FALSE)

expect_true(nrow(results$CheckResults) > 1)
})

2 changes: 1 addition & 1 deletion tests/testthat/test-writeDBResultsTo.R
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ test_that("Write DB results to json", {
connectionDetailsEunomia <- Eunomia::getEunomiaConnectionDetails()
cdmDatabaseSchemaEunomia <- "main"
resultsDatabaseSchemaEunomia <- "main"
writeTableName <- "dqdashboard_results"
writeTableName <- "dqd_db_results"

expect_warning(
results <- DataQualityDashboard::executeDqChecks(
Expand Down
6 changes: 3 additions & 3 deletions tests/testthat/test-writeJsonResultsTo.R
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,11 @@ test_that("Write JSON results", {
connectionDetails = connectionDetailsEunomia,
resultsDatabaseSchema = resultsDatabaseSchemaEunomia,
jsonFilePath = jsonPath,
writeTableName = "dqd_results"
writeTableName = "dqd_json_results"
)
connection <- DatabaseConnector::connect(connectionDetailsEunomia)
on.exit(DatabaseConnector::disconnect(connection), add = TRUE)
tableNames <- DatabaseConnector::getTableNames(connection = connection, databaseSchema = resultsDatabaseSchemaEunomia)
expect_true("dqd_results" %in% tolower(tableNames))
DatabaseConnector::renderTranslateExecuteSql(connection, "DROP TABLE @database_schema.dqd_results;", database_schema = resultsDatabaseSchemaEunomia)
expect_true("dqd_json_results" %in% tolower(tableNames))
DatabaseConnector::renderTranslateExecuteSql(connection, "DROP TABLE @database_schema.dqd_json_results;", database_schema = resultsDatabaseSchemaEunomia)
})