@@ -57,16 +57,16 @@ getVisitContext <- function(connection = NULL,
57
57
58
58
if (! is.null(conceptIdTable )) {
59
59
60
- createTablesql <- " IF OBJECT_ID('@unique_concept_id_table', 'U') IS NULL CREATE TABLE @unique_concept_id_table (concept_id BIGINT); "
61
-
62
- DatabaseConnector :: renderTranslateExecuteSql(
63
- connection = connection ,
64
- sql = createTablesql ,
65
- tempEmulationSchema = tempEmulationSchema ,
66
- unique_concept_id_table = conceptIdTable ,
67
- progressBar = FALSE ,
68
- reportOverallTime = FALSE
69
- )
60
+ # add concepts to #concept_ids if they don't already exist
61
+ if ( ! tempTableExists( connection , " concept_ids " )) {
62
+ DatabaseConnector :: renderTranslateExecuteSql(
63
+ connection = connection ,
64
+ sql = " CREATE TABLE #concept_ids (concept_id BIGINT); " ,
65
+ tempEmulationSchema = tempEmulationSchema ,
66
+ progressBar = FALSE ,
67
+ reportOverallTime = FALSE
68
+ )
69
+ }
70
70
71
71
sql <- " INSERT INTO @unique_concept_id_table (concept_id)
72
72
SELECT DISTINCT visit_concept_id
@@ -106,6 +106,33 @@ getVisitContext <- function(connection = NULL,
106
106
return (visitContext )
107
107
}
108
108
109
+
110
+
111
+ # ' runVisitContext
112
+ # '
113
+ # ' @description
114
+ # ' Generates the `visit_context.csv` which contains the counts for the subjects by `cohort_id`,
115
+ # ' `visit_concept_id` and `visit_context`. The `visit_context` categorizes visit occurrences of
116
+ # ' subjects based on how each the start and end date of each visit related to the cohort start date
117
+ # ' to which each subject belongs. No output will be generated for cohorts with no subjects.If there
118
+ # ' is no cohort with subjects execution will halt and `visit_context.csv` will not be generated.
119
+ # '
120
+ # ' @template Connection
121
+ # ' @template cohortDefinitionSet
122
+ # ' @template ExportFolder
123
+ # ' @param databaseId A short string for identifying the database (e.g. 'Synpuf').
124
+ # ' @template CohortDatabaseSchema
125
+ # ' @template CdmDatabaseSchema
126
+ # ' @template TempEmulationSchema
127
+ # ' @template CohortTable
128
+ # ' @template cdmVersion
129
+ # ' @template MinCellCount
130
+ # ' @template Incremental
131
+ # ' @param incrementalFolder If \code{incremental = TRUE}, specify a folder where records are kept
132
+ # ' of which cohort diagnostics has been executed. If not specified, a file named `incremental` will be created inside the
133
+ # ' \code{export_folder} directory.
134
+ # '
135
+ # ' @export
109
136
runVisitContext <- function (connection ,
110
137
cohortDefinitionSet ,
111
138
exportFolder ,
@@ -118,7 +145,12 @@ runVisitContext <- function(connection,
118
145
minCellCount ,
119
146
incremental ,
120
147
incrementalFolder = file.path(exportFolder , " incremental" )){
121
-
148
+
149
+ # Create export file if it doesn't exist
150
+ if (! file.exists(gsub(" /$" , " " , exportFolder ))) {
151
+ dir.create(exportFolder , recursive = TRUE )
152
+ ParallelLogger :: logInfo(" Created export folder" , exportFolder )
153
+ }
122
154
123
155
if (incremental && ! file.exists(incrementalFolder )) {
124
156
# Create the file if it doesn't exist
0 commit comments