Skip to content

Conversation

@SivamshIndukuri
Copy link

@SivamshIndukuri SivamshIndukuri commented Dec 16, 2025

This PR updates the TreatmentPatterns Module to enable multiple analyses to be run simultaneously.

Summary of Changes

  1. Added createModuleSpecification:
    This function builds a TreatmentPatterns analysis spec from lists of target, event, and exit cohort definitions, converting them into the cohort data frame the package expects, and returns an analysis settings list.

  2. Added createMultiAnalysisModuleSpecification:
    This function takes a list of analysis specifications made by createAnalysisSpecification

  3. Modified createModuleSpecification:
    I modified the return specification to be wrapped by a list so it matches the createMultiAnalysisModuleSpecification returned results. Now it returns a list in the form of list(tpAnalysisList = list())

  4. Modified execute:
    I modified this function so it can loop through the tpAnalysisList and run each treatment pattern. All the logs of passed and failed pathways are written to the treatment_pathway_runs.csv in the work folder. The execute method also makes a new table in the results folder called analysis_cohorts, which has the columns:
    event_cohort_name, event_cohort_id, target_cohort_id, target_event_id, and analysis_id

  5. Modified data model:
    Modified the model to allow the analysis_cohorts table to be inserted

eg.

tp <- TreatmentPatternsModule$new()

modSpecs <- list(
tp$createAnalysisSpecification(...),
tp$createAnalysisSpecification(...),
)

tpModuleSpecifications <- tp$createMultiAnalysisModuleSpecification(tpAnalysis = modSpecs)

@SivamshIndukuri
Copy link
Author

The script now checks that the results folder exists, reads completed analysis IDs from any passed_pathway_runs.csv files, and then runs only the treatment patterns that have not yet been executed. The work folder is updated with two files: passed_pathway_runs.csv and failed_pathway_runs.csv.

@codecov
Copy link

codecov bot commented Dec 23, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 99.03%. Comparing base (6187132) to head (f6a97e7).
⚠️ Report is 1 commits behind head on develop.

Additional details and impacted files
@@             Coverage Diff             @@
##           develop     #273      +/-   ##
===========================================
+ Coverage    97.82%   99.03%   +1.20%     
===========================================
  Files           16       16              
  Lines         4193     4748     +555     
===========================================
+ Hits          4102     4702     +600     
+ Misses          91       46      -45     

☔ 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.

Admin_SInduku2 and others added 8 commits December 23, 2025 21:01
Update TreatmentPatternsModule.Rd
* fixed data types and added cdm_version_concept_id

* missed col value

* target_id as int

* changed yes/no
Removed duplicate table in treatmentPatternsRdms.csv
@SivamshIndukuri SivamshIndukuri force-pushed the issue-271-multiple-analysis branch from 2357413 to 33e2f41 Compare December 24, 2025 02:12
@SivamshIndukuri SivamshIndukuri force-pushed the issue-271-multiple-analysis branch from ccf6270 to c520b3b Compare December 24, 2025 05:54
@SivamshIndukuri SivamshIndukuri force-pushed the issue-271-multiple-analysis branch from c520b3b to 09481c8 Compare December 24, 2025 07:29
Copy link
Collaborator

@anthonysena anthonysena left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove the createAnalysisSpecification function - I think all that is needed here is the createModuleSpecification changes (that appear to be in createAnalysisSpecification) and the multi analysis function. Reach out with any questions or concerns.

Copy link
Collaborator

@anthonysena anthonysena left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@SivamshIndukuri a few additional comments based on a deeper review. Let me know if you have any questions or concerns. Thanks!

resultAppend <- FALSE
passedPathways <- integer(0)

if (file.exists(file.path(workFolder, "passed_pathway_runs.csv")) && dir.exists(resultsFolder)) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One more addition to the logic here: we should consider the value of the incremental flag of the executionSettings: https://ohdsi.github.io/Strategus/reference/createCdmExecutionSettings.html#arg-incremental. If executionSettings$incremental == FALSE, we should remove any info on prior runs (passed and failed) and re-run from scratch.

Copy link
Author

@SivamshIndukuri SivamshIndukuri Jan 12, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adding executionSettings$incremental to the 'if condition' should resolve this. It will act like 0 pathways passed and resultAppend will be false.

Comment on lines 111 to 117
targets <- cohorts[cohorts$type == "target", c("cohortName", "cohortId"), drop = FALSE]
colnames(targets) <- c("target_cohort_name", "target_cohort_id")

events <- cohorts[cohorts$type == "event", c("cohortName", "cohortId"), drop = FALSE]
colnames(events) <- c("event_cohort_name", "event_cohort_id")

cohortAnalysisTable <- merge(targets, events, by = NULL) %>% dplyr::mutate("analysis_id" = analysisId)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cohortAnalysisTable provides the combination of target cohorts, event cohorts, exit cohorts and the current analysisId. cohorts already contains the target/event/exit cohorts, so would it be easiest to construct cohortAnalysisTable by appending the current analysisId? Also, we aim to use camelCase in R code per OHDSI code guidelines here: https://ohdsi.github.io/Hades/codeStyle.html#Interfacing_between_R_and_SQL. If you need to move between snake & camelCase, DatabaseConnector has some utility functions described in that link.

Copy link
Author

@SivamshIndukuri SivamshIndukuri Jan 12, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes that would be the easiest. I originally went with this to make it easier when making the queries for OhdsiReportGenerator but it should still work in this format.

@anthonysena anthonysena changed the title Issue 271 multiple analysis Multi-analysis specification with TreatmentPatternsModule Jan 13, 2026
@anthonysena anthonysena merged commit 217566a into OHDSI:develop Jan 13, 2026
6 checks passed
@SivamshIndukuri SivamshIndukuri deleted the issue-271-multiple-analysis branch January 13, 2026 15:44
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.

Add analysisId and stratify options to TreatmentPatterns

2 participants