-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathCreateStrategusAnalysisSpecificationTreatmentPatterns.R
More file actions
124 lines (104 loc) · 4.37 KB
/
CreateStrategusAnalysisSpecificationTreatmentPatterns.R
File metadata and controls
124 lines (104 loc) · 4.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
library(dplyr)
library(Strategus)
# Define cohorts for each analysis version
# Version 1A: Newly Diagnosed with standard In Office screening
cohorts_v1a <- c(
2, # Newly Diagnosed T2DM (3 Years Continuous Observation): target
110, # DR Screening, In Office
120, # DR Screening, Telemedicine
130 # DR Screening, AI
)
# Version 1B: Newly Diagnosed with No Specialty In Office screening
cohorts_v1b <- c(
2, # Newly Diagnosed T2DM (3 Years Continuous Observation): target
111, # DR Screening, In Office (No Specialty)
120, # DR Screening, Telemedicine
130 # DR Screening, AI
)
# Version 2A: Prevalent with standard In Office screening
cohorts_v2a <- c(
11, # Prevalent T2DM (3 Years Continuous Observation): target
110, # DR Screening, In Office
120, # DR Screening, Telemedicine
130 # DR Screening, AI
)
# Version 2B: Prevalent with No Specialty In Office screening
cohorts_v2b <- c(
11, # Prevalent T2DM (3 Years Continuous Observation): target
111, # DR Screening, In Office (No Specialty)
120, # DR Screening, Telemedicine
130 # DR Screening, AI
)
# Time-at-risks (TARs) for the outcomes of interest in your study
timeAtRisks <- tibble(
label = c("Year 1", "Year 2", "Year 3", "Year 4"),
riskWindowStart = c(0, 365, 730, 1095),
startAnchor = c("cohort start"),
riskWindowEnd = c(365, 730, 1095, 1460),
endAnchor = c("cohort end")
)
studyStartDate <- '20210101' #YYYYMMDD
studyEndDate <- '20241231' #YYYYMMDD
# Some of the settings require study dates with hyphens
studyStartDateWithHyphens <- gsub("(\\d{4})(\\d{2})(\\d{2})", "\\1-\\2-\\3", studyStartDate)
studyEndDateWithHyphens <- gsub("(\\d{4})(\\d{2})(\\d{2})", "\\1-\\2-\\3", studyEndDate)
# Function to create analysis specification for a given set of cohorts
createTPAnalysisSpec <- function(cohortsToKeep, analysisName) {
# Get cohort definitions for this analysis
cohortDefinitionSetLimited <- CohortGenerator::getCohortDefinitionSet(
settingsFileName = "inst/cohorts.csv",
jsonFolder = "inst/cohorts",
sqlFolder = "inst/sql/sql_server"
) |>
filter(cohortId %in% cohortsToKeep)
if (any(duplicated(cohortDefinitionSetLimited$cohortId))) {
stop("*** Error: duplicate cohort IDs found ***")
}
# CohortGeneratorModule
cgModuleSettingsCreator <- CohortGeneratorModule$new()
cohortDefinitionShared <- cgModuleSettingsCreator$createCohortSharedResourceSpecifications(cohortDefinitionSetLimited)
cohortGeneratorModuleSpecifications <- cgModuleSettingsCreator$createModuleSpecifications(
generateStats = TRUE
)
# TreatmentPatternsModule Settings
tpSettingsCreator <- Strategus::TreatmentPatternsModule$new()
# Define cohorts with their types
tpTargetCohorts <- cohortDefinitionSetLimited |>
mutate(
type = case_when(
cohortId < 100 ~ "target",
cohortId >= 100 & cohortId < 200 ~ "event"
)
) |>
select(cohortId, cohortName, type)
treatmentPatternsModuleSpecifications <- tpSettingsCreator$createModuleSpecifications(
cohorts = tpTargetCohorts,
includeTreatments = "startDate",
indexDateOffset = 0,
minEraDuration = 0,
splitEventCohorts = NULL,
splitTime = NULL,
eraCollapseSize = 99999, # Large value to collapse all consecutive same screening types regardless of time gap
combinationWindow = 0, # Set to 0 to prevent combination detection (no '+' concatenation)
minPostCombinationDuration = 30, # Minimum 30 days for eras around combinations
filterTreatments = "Changes", # Only show when screening type changes
maxPathLength = 5
)
# Create the analysis specifications
analysisSpecifications <- Strategus::createEmptyAnalysisSpecificiations() |>
Strategus::addSharedResources(cohortDefinitionShared) |>
Strategus::addModuleSpecifications(cohortGeneratorModuleSpecifications) |>
Strategus::addModuleSpecifications(treatmentPatternsModuleSpecifications)
# Save the specification
ParallelLogger::saveSettingsToJson(
analysisSpecifications,
file.path("inst", paste0("drScreeningStudyAnalysisSpecificationTP_", analysisName, ".json"))
)
cat("Created specification for", analysisName, "\n")
return(analysisSpecifications)
}
# Create all four analysis specifications
spec_v1a <- createTPAnalysisSpec(cohorts_v1a, "v1a")
spec_v1b <- createTPAnalysisSpec(cohorts_v1b, "v1b")
spec_v2a <- createTPAnalysisSpec(cohorts_v2a, "v2a")
spec_v2b <- createTPAnalysisSpec(cohorts_v2b, "v2b")