This workflow demonstrates how to use the OHDSI Gaia suite of GIS tools to geocode the entirety of an OMOP Location table, fully enabling any further geospatial analyses supported by the Gaia GIS tools.
This workflow requires the DatabaseConnector
package.
install.packages("DatabaseConnector")
library(DatabaseConnector)
We need to configure connections to two servers: the server hosting the OMOP database and the server hosting the gaiaDB Postgres database.
connectionDetails <- createConnectionDetails(
dbms = keyring::key_get('cdm-dbms'),
user = keyring::key_get('cdm-username'),
password = keyring::key_get('cdm-password'),
server = keyring::key_get('cdm-server')
)
cdmDatabaseSchema <- "TMC_RED.dbo"
If you don’t already have a gaiaDB server set up, see the installation instructions before proceeding.
library(DatabaseConnector)
gaiaConnectionDetails <- DatabaseConnector::createConnectionDetails(
dbms = "postgresql",
server = "localhost/gaiaDB",
port = 5432,
user="postgres",
password = "mySecretPassword")
Use the gaiaCore function getLocationAddresses()
to
extract addresses from OMOP and return a transformed location table:
transformedLocation <- getLocationAddresses(connectionDetails = connectionDetails,
cdmDatabaseSchema = cdmDatabaseSchema)
splitResult <- splitAddresses(addressTable = transformedLocation)
alreadyGeocodedLocation <- splitResult$geocoded
notGeocodedLocation <- splitResult$ungeocoded
geocodedLocation <- geocodeAddresses(addressTable = notGeocodedLocation)
fullyGeocodedLocation <- geocodedLocation
if (!is.null(alreadyGeocodedLocation)) {
names(alreadyGeocodedLocation) <- tolower(names(alreadyGeocodedLocation))
alreadyGeocodedLocation <- dplyr::mutate(alreadyGeocodedLocation, lat = latitude, lon = longitude)
alreadyGeocodedLocation <- dplyr::select(alreadyGeocodedLocation, names(fullyGeocodedLocation))
alreadyGeocodedLocation <- sf::st_as_sf(boundGeocodedTable, coords = c("lon", "lat"), crs = 4326)
fullyGeocodedLocation <- rbind(fullyGeocodedLocation, alreadyGeocodedLocation)
}
importLocationTable(gaiaConnectionDetails = gaiaConnectionDetails,
location = fullyGeocodedLocation)