-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCodeToRun.R
115 lines (98 loc) · 4.12 KB
/
CodeToRun.R
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
# Manage project dependencies ------
# the following will prompt you to install the various packages used in the study
# install.packages("renv")
renv::activate()
renv::restore()
# Load packages ------
library(CirceR)
library(here)
library(DBI)
library(dbplyr)
library(dplyr)
library(readr)
library(log4r)
library(tidyr)
library(stringr)
library(CDMConnector)
library(ggplot2)
library(broom)
library(survival)
library(bshazard)
library(flexsurv)
library(tictoc)
library(tibble)
library(RPostgres)
library(purrr)
library(PatientProfiles)
library(CodelistGenerator)
library(SqlRender)
library(DrugUtilisation)
# Set the short name/acronym for your database (to be used in the titles of reports, etc) -----
# Please do not use omop, cdm for db.name
db.name <-"..."
# Set output folder locations -----
# the path to a folder where the results from this analysis will be saved
output.folder <- here::here("Results", db.name)
# database connection details
server <- "..."
server_dbi <- "..."
user <- "..."
password <- "..."
port <- "..."
host <- "..."
dbms <- "..." # https://dbi.r-dbi.org/articles/DBI.html for R interface with database management system
# Specify cdm_reference via DBI connection details -----
# In this study we also use the DBI package to connect to the database
# set up the dbConnect details below (see https://dbi.r-dbi.org/articles/dbi for more details)
# you may need to install another package for this (although RPostgres is included with renv in case you are using postgres)
db <- DBI::dbConnect(dbms,
dbname = server_dbi,
port = port,
host = host,
user = user,
password = password)
# Set database details -----
# The name of the schema that contains the OMOP CDM with patient-level data
cdm_database_schema <- "..."
# The name of the schema that contains the vocabularies
# (often this will be the same as cdm_database_schema)
vocabulary_database_schema <- "..."
# The name of the schema where results tables will be created
results_database_schema <- "..."
# stem table description use something short and informative such as ehdenwp2 or your initials
# Note, if there is an existing table in your results schema with the same names it will be overwritten
# needs to be in lower case and NOT more than 10 characters
table_stem <- "..."
# create cdm reference ---- DO NOT REMOVE "PREFIX" ARGUMENT IN THIS CODE
cdm <- CDMConnector::cdm_from_con(con = db,
cdm_schema = cdm_database_schema,
write_schema = c("schema" = results_database_schema,
"prefix" = table_stem),
cdm_name = db.name)
# to check whether the DBI connection is correct,
# running the next line should give you a count of your person table
cdm$person %>%
dplyr::tally() %>%
CDMConnector::computeQuery()
# Set study details -----
# if you do not have suitable data from 2000-01-01
# please put year of useable data starting from 1st jan
# must be in format YYYY-MM-DD ie. 20XX-01-01
startdate <- "2000-01-01"
# Prior history -----
# if you have a database where the observation period start date for each patient is the date of cancer diagnosis (ie. some cancer registries)
# set this value to FALSE. If your database has linkage or data where you can look in prior history before cancer diagnosis (e.g. primary care)
# set as TRUE.
priorhistory <- TRUE
# Truncated time analysis ------
# By setting this to TRUE this will perform an additional analysis where extrapolation methods will extrapolate on the observed data truncated at 2 years NOT on the full observed data.
# If FALSE this additional analysis will not be run.
PerformTruncatedAnalysis <- TRUE
# Run the study ------
source(here::here("RunStudy.R"))
# after the study is run you should have a zip folder in your output folder to share
# drop the permanent tables from the study
# YOU MUST HAVE TABLE STEM SET ABOVE WITH A NAME ABOVE OTHERWISE IT WILL DELETE EVERYTHING!
#CDMConnector::dropTable(cdm, dplyr::everything())
# Disconnect from database
#dbDisconnect(db)