Skip to content

Commit

Permalink
Properly remove ncos for each generation - fixes #177 (#178)
Browse files Browse the repository at this point in the history
  • Loading branch information
anthonysena authored Aug 7, 2024
1 parent dc3bde3 commit ae64ca3
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 2 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package: CohortGenerator
Type: Package
Title: An R Package for Cohort Generation Against the OMOP CDM
Version: 0.10.0
Version: 0.11.0
Date: 2024-07-14
Authors@R: c(
person("Anthony", "Sena", email = "[email protected]", role = c("aut", "cre")),
Expand Down
5 changes: 5 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
CohortGenerator 0.11.0
=======================
Bug Fixes
- Negative control outcome generation bug (#177)

CohortGenerator 0.10.0
=======================
New Features
Expand Down
2 changes: 1 addition & 1 deletion inst/sql/sql_server/NegativeControlOutcomes.sql
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ CREATE TABLE #Codesets (

DELETE FROM @cohort_database_schema.@cohort_table
WHERE cohort_definition_id IN (
SELECT DISTINCT ancestor_concept_id
SELECT DISTINCT cohort_definition_id
FROM #Codesets
)
;
Expand Down
57 changes: 57 additions & 0 deletions tests/testthat/test-NegativeControlCohorts.R
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
library(testthat)
library(dplyr)
library(CohortGenerator)

# createEmptyNegativeControlOutcomeCohortSet ----------
Expand Down Expand Up @@ -227,6 +228,62 @@ test_that("Call generateNegativeControlOutcomeCohorts with occurrenceType == 'fi
)
})

test_that("Call generateNegativeControlOutcomeCohorts with occurrenceType == 'first' and detectOnDescendants == FALSE multiple times to ensure there are no duplicates", {
cohortTableNames <- getCohortTableNames(cohortTable = "ot_first_dod_f")
connection <- DatabaseConnector::connect(connectionDetails = connectionDetails)
on.exit(DatabaseConnector::disconnect(connection))
createCohortTables(
connection = connection,
cohortDatabaseSchema = "main",
cohortTableNames = cohortTableNames
)
ncSet <- getNegativeControlOutcomeCohortsForTest()

# Set the cohort ID to something other than the concept ID
ncSet <- ncSet %>%
mutate(cohortId = row_number())
expect_output(
generateNegativeControlOutcomeCohorts(
connection = connection,
cdmDatabaseSchema = "main",
cohortDatabaseSchema = "main",
cohortTable = cohortTableNames$cohortTable,
negativeControlOutcomeCohortSet = ncSet,
occurrenceType = "first",
detectOnDescendants = FALSE
)
)

# Get the cohort counts from the first run
counts1 <- getCohortCounts(
connection = connection,
cohortDatabaseSchema = "main",
cohortTable = cohortTableNames$cohortTable,
cohortDefinitionSet = ncSet
)

# Regenerate the negative control outcomes
expect_output(
generateNegativeControlOutcomeCohorts(
connection = connection,
cdmDatabaseSchema = "main",
cohortDatabaseSchema = "main",
cohortTable = cohortTableNames$cohortTable,
negativeControlOutcomeCohortSet = ncSet,
occurrenceType = "first",
detectOnDescendants = FALSE
)
)

counts2 <- getCohortCounts(
connection = connection,
cohortDatabaseSchema = "main",
cohortTable = cohortTableNames$cohortTable,
cohortDefinitionSet = ncSet
)

expect_equal(counts1,counts2)
})

test_that("incremental mode", {
incrementalFolder <- tempfile()
Expand Down

0 comments on commit ae64ca3

Please sign in to comment.