Skip to content

Commit

Permalink
Merge pull request #502 from katy-sadowski/katy__schema_param
Browse files Browse the repository at this point in the history
More small bugfixes
  • Loading branch information
katy-sadowski authored Nov 4, 2023
2 parents eb295b0 + 16990b4 commit b3a1f5e
Show file tree
Hide file tree
Showing 7 changed files with 43 additions and 16 deletions.
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)
})

0 comments on commit b3a1f5e

Please sign in to comment.