Skip to content

Commit

Permalink
update codeToRun
Browse files Browse the repository at this point in the history
  • Loading branch information
tiozab committed Nov 3, 2023
1 parent 1925f38 commit cc8f2df
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 31 deletions.
37 changes: 7 additions & 30 deletions extras/CodeToRun.R
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,12 @@ password <-Sys.getenv("DB_PASSWORD")
port <-Sys.getenv("DB_PORT")
host <-Sys.getenv("DB_HOST")

# Connect to the database

#connectionDetails <-DatabaseConnector::downloadJdbcDrivers("postgresql",here::here())

# connectionDetails <-DatabaseConnector::downloadJdbcDrivers("postgresql",here::here())


# Connect to the database via database connector to run the algorithm
connectionDetails <-DatabaseConnector::createConnectionDetails(dbms = "postgresql",
server = server,
user = user,
Expand All @@ -22,39 +24,14 @@ connectionDetails <-DatabaseConnector::createConnectionDetails(dbms = "postgresq


targetDialect <-"postgresql"
cdmDatabaseSchema <-"public_100k"
vocabularyDatabaseSchema <-"public_100k"
cdmDatabaseSchema <-"public"
vocabularyDatabaseSchema <-"public"
resultsDatabaseSchema <-"results"

connection = connect(connectionDetails)
#disconnect(connection)

source("~/PregnancyAlgorithm/R/main.R")
source("~/pregnancyAlgorithm_postgresql/R/main.R")
init (connectionDetails, resultsDatabaseSchema, useMppBulkLoad = FALSE)
execute (connectionDetails, cdmDatabaseSchema, resultsDatabaseSchema)

## connect to a cdm instance
server_dbi <- Sys.getenv("DB_SERVER_DBI_gold_202207")
user <- Sys.getenv("DB_USER")
password <- Sys.getenv("DB_PASSWORD")
port <- Sys.getenv("DB_PORT")
host <- Sys.getenv("DB_HOST")

library(CDMConnector)
library(dplyr)

db <- dbConnect(RPostgres::Postgres(),
dbname = server_dbi,
port = port,
host = host,
user = user,
password = password
)

cdm <- cdm_from_con(
db,
cdm_schema = "public_100k",
write_schema = "results"
)

cdm$motherTable <- tbl(db, in_schema("results","pregnancy_episodes"))
31 changes: 30 additions & 1 deletion extras/post_process.R
Original file line number Diff line number Diff line change
@@ -1,7 +1,36 @@
## change the motherTable to the correct column names and concept ids


# unique(motherTable$original_outcome) : "SA" "DELIV" "AB" "LB" "ECT" "SB"
## connect to a cdm instance to do the postprocessing
server_dbi <- Sys.getenv("DB_SERVER_DBI_gold_202207")
user <- Sys.getenv("DB_USER")
password <- Sys.getenv("DB_PASSWORD")
port <- Sys.getenv("DB_PORT")
host <- Sys.getenv("DB_HOST")

library(CDMConnector)
library(dplyr)

db <- dbConnect(RPostgres::Postgres(),
dbname = server_dbi,
port = port,
host = host,
user = user,
password = password
)

cdm <- cdm_from_con(
db,
cdm_schema = "public",
write_schema = "results"
)

cdm$motherTable <- tbl(db, in_schema("results","pregnancy_episodes"))


# motherTable <- cdm$motherTable %>% collect()
# unique(motherTable$original_outcome)
## "SA" "DELIV" "AB" "LB" "ECT" "SB"

# explor <- motherTable %>% select("original_outcome","outcome") %>% distinct(original_outcome,outcome)

Expand Down

0 comments on commit cc8f2df

Please sign in to comment.