Skip to content

First draft of query updates to support CM v6#13

Merged
jreps merged 13 commits intodevelopfrom
cm_version_6
Mar 3, 2026
Merged

First draft of query updates to support CM v6#13
jreps merged 13 commits intodevelopfrom
cm_version_6

Conversation

@anthonysena
Copy link
Collaborator

@anthonysena anthonysena commented Dec 3, 2025

Updates queries based on upcoming changes for CohortMethod v6. One thing that needs discussion with @schuemie is the addition of the nesting cohort for indications - that is not currently supported by the queries in this package so we probably need to add those to the shiny modules and these reporting queries.

Here is some code I used to test the query changes on this branch:

schema <- "sena_cmv6_test"
resultsDatabaseConnectionDetails <- DatabaseConnector::createConnectionDetails(
  dbms = 'postgresql',
  user = Sys.getenv("OHDA_RESULTS_USER"),
  password = Sys.getenv("OHDA_RESULTS_PASSWORD"),
  server = Sys.getenv("OHDA_RESULTS_SERVER")
)

CohortGenerator::createResultsDataModel(
  connectionDetails = resultsDatabaseConnectionDetails,
  databaseSchema = schema
)

# NOTE: CohortMethod build from the `version_6` branch
CohortMethod::createResultsDataModel(
  connectionDetails = resultsDatabaseConnectionDetails,
  databaseSchema = schema
)

connection <- ResultModelManager::ConnectionHandler$new(resultsDatabaseConnectionDetails)
# NOTE: OhdsiReportGenerator built from this branch
library(OhdsiReportGenerator)

data <- getCmTargets(
  connectionHandler = connection,
  schema = schema
)
cli::cli_alert_success("getCmTargets")

data <- getCmOutcomes(
  connectionHandler = connection,
  schema = schema
)
cli::cli_alert_success("getCmOutcomes")

data <- getCMEstimation(
  connectionHandler = connection,
  schema = schema
)
cli::cli_alert_success("getCMEstimation")

data <- getCmDiagnosticsData(
  connectionHandler = connection,
  schema = schema
)
cli::cli_alert_success("getCmDiagnosticsData")

data <- getCmNegativeControlEstimates(
  connectionHandler = connection,
  schema = schema
)
cli::cli_alert_success("getCmNegativeControlEstimates")

data <- getCmPropensityModel(
  connectionHandler = connection,
  schema = schema,
  targetId = 1,
  comparatorId = 1,
  analysisId = 1,
  databaseId = 1
)
cli::cli_alert_success("getCmPropensityModel")

data <- getCmTable(
  connectionHandler = connection,
  schema = schema,
  table = "attrition"
)
cli::cli_alert_success("getCmTable")

connection$closeConnection()

@anthonysena
Copy link
Collaborator Author

@jreps per our discussion, I've made modifications to this branch in an attempt to preserve backwards compatibly between CohortMethod v5 and v6. To that end, here is what has changed:

  • Added a .cmGetVersion function to interrogate the results data model to obtain the latest migration order from CohortMethod's migration table. If the migration order is >= 3, we can safely assume it contains CM v6 results otherwise it will default to assume CM v5 results are stored.
  • All CM related SQL queries are now externalized from their respective functions in the inst/sql/sql_server folder and named accordingly. Each query contains the suffix V5 or V6 to denote which version of the results model it targets. Additionally, the V5 queries were modified to include the indication_id and indication_name which was added as part of CM v6 to support the updates that will happen in OhdsiShinyModules. Furthermore, in some instances you will see in the V5 SQL code where I've added in code like: --@use_indication so when these new parameters are passed to the V5 queries, it does not throw a warning or error out.
  • All CM related reporting functions will use .cmGetVersion to get the proper version of the reporting query.

I'm still testing this out but wanted to summarize this here for others that may be following along with this PR.

@codecov
Copy link

codecov bot commented Feb 25, 2026

Codecov Report

❌ Patch coverage is 99.19355% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 92.29%. Comparing base (67c7329) to head (2464df1).
⚠️ Report is 15 commits behind head on develop.

Files with missing lines Patch % Lines
R/EstimationQueries.R 99.19% 1 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##           develop      #13      +/-   ##
===========================================
- Coverage    92.54%   92.29%   -0.26%     
===========================================
  Files           13       13              
  Lines         5244     5085     -159     
===========================================
- Hits          4853     4693     -160     
- Misses         391      392       +1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@anthonysena anthonysena marked this pull request as ready for review March 3, 2026 13:46
@jreps jreps merged commit 856c0b0 into develop Mar 3, 2026
10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants