Demo data, reading it
library(tidyverse)
## -- Attaching packages ------------------------------------------------------------------------------- tidyverse 1.3.0 --
## v ggplot2 3.3.0 v purrr 0.3.4
## v tibble 3.0.1 v dplyr 0.8.5
## v tidyr 1.0.3 v stringr 1.4.0
## v readr 1.3.1 v forcats 0.5.0
## -- Conflicts ---------------------------------------------------------------------------------- tidyverse_conflicts() --
## x dplyr::filter() masks stats::filter()
## x dplyr::lag() masks stats::lag()
library(fs)
library(RSQLite)
folder='m:/ohdsi/mimic'
dbfile<-fs::path(folder,"mimicdemo.sqlite")
createdb=FALSE
if (createdb)
{
tbls<-fs::dir_ls(path = folder,glob = "*.rds")
file_delete(dbfile)
unlink(dbfile)
db <- dbConnect(RSQLite::SQLite(),dbfile )
dbListTables(db)
ll<-list()
for (tblf in tbls) {
tbl<-tblf %>% path_file %>% path_ext_remove()
#tbl
print(tbl)
d<-read_rds(tblf)
str(d)
#ll[[tbl]] <- str(d)
dbWriteTable(db, tbl,d)
}
dbListTables(db)
dbDisconnect(db)
}
db <- dbConnect(RSQLite::SQLite(),dbfile )
dbListTables(db)
## [1] "ACHILLES_analysis" "ATTRIBUTE_DEFINITION" "CARE_SITE"
## [4] "CDM_SOURCE" "COHORT_ATTRIBUTE" "COHORT_DEFINITION"
## [7] "CONCEPT_CLASS" "CONDITION_ERA" "CONDITION_OCCURRENCE"
## [10] "COST" "DEATH" "DEVICE_EXPOSURE"
## [13] "DOMAIN" "DOSE_ERA" "DRUG_ERA"
## [16] "DRUG_EXPOSURE" "FACT_RELATIONSHIP" "LOCATION"
## [19] "MEASUREMENT" "METADATA" "NOTE"
## [22] "NOTE_NLP" "OBSERVATION" "OBSERVATION_PERIOD"
## [25] "PAYER_PLAN_PERIOD" "PERSON" "PROCEDURE_OCCURRENCE"
## [28] "PROVIDER" "RELATIONSHIP" "SOURCE_TO_CONCEPT_MAP"
## [31] "SPECIMEN" "VISIT_DETAIL" "VISIT_OCCURRENCE"
## [34] "achilles_results"
dbDisconnect(db)
#library(DatabaseConn)
# getEunomiaConnectionDetails <- function(databaseFile = tempfile(fileext = ".sqlite")) {
# extractFolder <- tempdir()
# unzip(zipfile = system.file("zip", "cdm.zip", package = "Eunomia"), exdir = extractFolder)
# file.rename(from = file.path(extractFolder, "cdm.sqlite"), to = databaseFile)
# details <- DatabaseConnector::createConnectionDetails(dbms = "sqlite", server = databaseFile)
# return(details)
# }
connectionDetails <- DatabaseConnector::createConnectionDetails(dbms = "sqlite", server = dbfile)
resultsDatabaseSchema= cdmDatabaseSchema = 'main'
#list tables
#DatabaseConnector::dbListTables(conn)
#achilles
ar<-Achilles::achilles(connectionDetails,cdmDatabaseSchema,resultsDatabaseSchema,cdmVersion = '5',analysisIds = c(1,2,3),runHeel = FALSE,validateSchema = FALSE)
## Connecting using SQLite driver
## Connecting using SQLite driver
## Beginning single-threaded execution
## Connecting using SQLite driver
##
|
| | 0%
|
|=================================== | 50%
|
|======================================================================| 100%
## Executing SQL took 0.0209 secs
## Executing multiple queries. This could take a while
## Analysis 1 (Number of persons) -- START
##
|
| | 0%
|
|=================================== | 50%
|
|======================================================================| 100%
## Executing SQL took 0.014 secs
## [Main Analysis] [COMPLETE] 1 (0.023935 secs)
## Analysis 2 (Number of persons by gender) -- START
##
|
| | 0%
|
|=================================== | 50%
|
|======================================================================| 100%
## Executing SQL took 0.00698 secs
## [Main Analysis] [COMPLETE] 2 (0.018950 secs)
## Analysis 3 (Number of persons by year of birth) -- START
##
|
| | 0%
|
|=================================== | 50%
|
|======================================================================| 100%
## Executing SQL took 0.00798 secs
## [Main Analysis] [COMPLETE] 3 (0.017951 secs)
## Merging scratch Achilles tables
##
|
| | 0%
|
|=================================== | 50%
|
|======================================================================| 100%
## Executing SQL took 0.017 secs
## Done. Achilles results can now be found in schema main
## Connecting using SQLite driver
##
|
| | 0%
|
| | 0%
|
|============== | 20%
|
|============================ | 40%
|
|========================================== | 60%
|
|======================================================== | 80%
|
|======================================================================| 100%
## Executing SQL took 0.0399 secs
Achilles::fetchAchillesAnalysisResults(connectionDetails,resultsDatabaseSchema,analysisId = 1)
## Connecting using SQLite driver
## $analysisId
## [1] 1
##
## $analysisName
## [1] "Number of persons"
##
## $analysisResults
## ANALYSIS_ID STRATUM_1 STRATUM_2 STRATUM_3 STRATUM_4 STRATUM_5 COUNT_VALUE
## 1 1 <NA> <NA> <NA> <NA> <NA> 100
##
## attr(,"class")
## [1] "achillesAnalysisResults"
# result<-executeDqChecks(connectionDetails,cdmDatabaseSchema
# ,resultsDatabaseSchema = resultsDatabaseSchema
# ,cdmSourceName = cdmSourceName
# ,verboseMode = TRUE
# ,outputFolder = outputFolder
# ,checkNames = checkNames)