OHDSI Home | Forums | Wiki | Github

General OMOP + WebAPI + Atlas setup

Hey everyone,

I’ve been trying to setup the following 3 components:

  • CDM - OMOP
  • WebAPI
  • Atlas

To do this I’ve done the following steps:
Provision infrastructure in Azure

Configure CDM on SQL server

## First, install the package from GitHub
install.packages("devtools")
devtools::install_github("OHDSI/CommonDataModel")

## List the currently supported SOL dialects 
CommonDataModel::listSupportedDialects()

## There are multiple ways to generate the DDLs
## 1. Use the buildRelease function to generate the text files in the dialect you choose.
##    This function will put the output files in the folder you specify
CommonDataModel::buildRelease(
  cdmVersions="5.4",
  targetDialects = "sql server",
  outputfolder = "/Users/frederDS/repos/medemotion/OMOP/CDM_demo"
)


## 2. If you have an empty schema ready to go, the package will connect and instantiate the tables for you.
### 2a. To start, you need to download DatabaseConnector in order to connect to your database.

devtools::install_github("OHDSI/DatabaseConnector")

Sys.setenv("DATABASECONNECTOR_JAR_FOLDER" = "/Users/frederDS/repos/medemotion/OMOP/drivers")
DatabaseConnector::downloadJdbcDrivers("sql server",Sys.getenv("DATABASECONNECTOR_JAR_FOLDER"),"auto")

cd <- DatabaseConnector::createConnectionDetails(dbms = "sql server",
  server = "sql-mem-dpl-sdev-01.database.windows.net",
  user = "omop",
  password = "*********************",
  pathToDriver = "/Users/frederDS/repos/medemotion/OMOP/drivers",
  extraSettings = "database=********************; encrypt=true; trustServerCertificate=false;"
)

CommonDataModel::executeDdl(
  connectionDetails = cd,
  cdmVersion = "5.4",
  cdmDatabaseSchema = "cdm"
)

This created my SQL Server tables.

The next step is to load data in there. To do this I’ve created a synthea set. I’ve made sure to use the compatible version (3.0.0) (following this method https://towardsdatascience.com/generating-synthetic-patient-data-b7901c3bd397).

Afterwards the downloaded data was loaded with the following commands:

devtools::install_github("OHDSI/ETL-Synthea")

library(ETLSyntheaBuilder)

# We are loading a version 5.4 CDM into a local PostgreSQL database called "synthea10".
# The ETLSyntheaBuilder package leverages the OHDSI/CommonDataModel package for CDM creation.
# Valid CDM versions are determined by executing CommonDataModel::listSupportedVersions().
# The strings representing supported CDM versions are currently "5.3" and "5.4". 
# The Synthea version we use in this example is 2.7.0.  Since Synthea's MASTER branch is always active, we currently
# only support version 2.7.0.

# The schema to load the Synthea tables is called "native".
# The schema to load the Vocabulary and CDM tables is "cdm_synthea10".  
# The username and pw are "postgres" and "lollipop".
# The Synthea and Vocabulary CSV files are located in /tmp/synthea/output/csv and /tmp/Vocabulary_20181119, respectively.

# For those interested in seeing the CDM changes from 5.3 to 5.4, please see: http://ohdsi.github.io/CommonDataModel/cdm54Changes.html

cd <- DatabaseConnector::createConnectionDetails(
    dbms = "sql server",
   server = "***********************",
   user = "omop",
   password = "***********",
   pathToDriver = "/Users/frederDS/repos/medemotion/OMOP/drivers",
   extraSettings = "database=****************; encrypt=true; trustServerCertificate=false;"
)

cdmSchema      <- "cdm"
cdmVersion     <- "5.4"
syntheaVersion <- "3.0.0"
syntheaSchema  <- "synthea" # SHOULD ALREADY EXIST
syntheaFileLoc <- "/Users/frederDS/repos/medemotion/OMOP/synthea"
vocabFileLoc   <- "/Users/frederDS/repos/medemotion/OMOP/vocabulary"

# 

ETLSyntheaBuilder::CreateCDMTables(connectionDetails = cd, cdmSchema = cdmSchema, cdmVersion = cdmVersion)

ETLSyntheaBuilder::CreateSyntheaTables(connectionDetails = cd, syntheaSchema = syntheaSchema, syntheaVersion = syntheaVersion)

ETLSyntheaBuilder::LoadSyntheaTables(connectionDetails = cd, syntheaSchema = syntheaSchema, syntheaFileLoc = syntheaFileLoc)

ETLSyntheaBuilder::LoadVocabFromCsv(connectionDetails = cd, cdmSchema = cdmSchema, vocabFileLoc = vocabFileLoc)

ETLSyntheaBuilder::LoadEventTables(connectionDetails = cd, cdmSchema = cdmSchema, syntheaSchema = syntheaSchema, cdmVersion = cdmVersion, syntheaVersion = syntheaVersion)
-- remove any previously added database connection configuration data
DELETE webapi.source_daimon; -- noqa: PRS
DELETE webapi.source;

-- TODO: Should this exist in the webapi instead? For now, allowing null based on insert
ALTER TABLE [webapi].[source]
ALTER COLUMN [krb_auth_method] [varchar](10) NULL -- NOT NULL in existing setup, setting to NULL based on insert

-- SET webapi CDM source
INSERT INTO webapi.source( source_id, source_name, source_key, source_connection, source_dialect)
VALUES (
    1,
    'webapi CDM V5 Database',
    'webapi-CDMV5',
    'jdbc:sqlserver://**************************************',
    'sql server');

-- CDM daimon
INSERT INTO webapi.source_daimon( source_daimon_id, source_id, daimon_type, table_qualifier, priority) VALUES (1, 1, 0, 'cdm', 2);

-- VOCABULARY daimon
INSERT INTO webapi.source_daimon( source_daimon_id, source_id, daimon_type, table_qualifier, priority) VALUES (2, 1, 1, 'cdm', 2);

-- RESULTS daimon
INSERT INTO webapi.source_daimon( source_daimon_id, source_id, daimon_type, table_qualifier, priority) VALUES (3, 1, 2, 'webapi', 2);

-- EVIDENCE daimon
INSERT INTO webapi.source_daimon( source_daimon_id, source_id, daimon_type, table_qualifier, priority) VALUES (4, 1, 3, 'results', 2);

I’ve retrieved the vocabulary content on Athena. What seems strange to me is that you cannot select any vocabulary version to download. I assume this is why my Configuration page in atlas shows v5.0

Additional information:

  • to do this I had to disable my constraints temporarily
  • Some schemas had to be provided beforehand. I did this manuallly.

My next step is to configure OMOP WebAPI + Atlas. I’m trying to run this locally with the following docker container + env vars.

FROM ohdsi/webapi:2.13.0

ENV DATASOURCE_DRIVERCLASSNAME="org.postgresql.Driver"
ENV DATASOURCE_URL="jdbc:postgresql://*********.database.azure.com/OHDSI"
ENV DATASOURCE_USERNAME="ohdsi_app_user@**************"
ENV DATASOURCE_PASSWORD="***********************"
ENV DATASOURCE_OHDSI_SCHEMA="webapi"
ENV SPRING_JPA_PROPERTIES_HIBERNATE_DIALECT="org.hibernate.dialect.PostgreSQLDialect"
ENV SPRING_JPA_PROPERTIES_HIBERNATE_DEFAULT_SCHEMA="webapi"
ENV SPRING_BATCH_REPOSITORY_TABLEPREFIX="webapi.BATCH_"
ENV FLYWAY_DATASOURCE_DRIVERCLASSNAME="org.postgresql.Driver"
ENV FLYWAY_DATASOURCE_URL="jdbc:postgresql://*************.database.azure.com/OHDSI"
ENV FLYWAY_DATASOURCE_USERNAME="ohdsi_admin_user@*************"
ENV FLYWAY_DATASOURCE_PASSWORD="***************"
ENV FLYWAY_LOCATIONS="classpath:db/migration/postgresql"
ENV FLYWAY_PLACEHOLDERS_OHDSISCHEMA="webapi"
ENV FLYWAY_SCHEMAS="webapi"
ENV FLYWAY_BASELINEONMIGRATE="true"
ENV FLYWAY_TABLE="schema_history"
ENV flyway_baselineVersionAsString="2.2.5.20180212152023"
ENV FLYWAY_BASELINEDESCRIPTION="Base Migration"
ENV SECURITY_CORS_ENABLED="true"

Atlas

from ohdsi/atlas:2.13.0

ENV WEBAPI_URL='http://localhost:8080/WebAPI/'
# ENV ATLAS_HOSTNAME=""?

Issues I have:

Questions:

  • Is this the correct way of working?
  • Do you see any issues with this configuration?

These might be helptul:
Ponos: Install an Instance of CDM/WebAPI/Atlas on Windows in 5 Easy, Standardized, Repeatable Steps - Implementers - OHDSI Forums

OHDSI/Broadsea: Broadsea deploys the core OHDSI technology stack (Atlas & R Hades), using cross-platform Docker container technology. (github.com)

Check your server logs and you may get information about a specific SQL exception. You are using 2.13, so I thought we cleared up errors related to those reports, but there could be an outstanding issue. If you find something, please let us know. Also: this depends on Achilles results, but if you are seeing some reports appear but not others, then I am guessing you have the data generated. You can also check your browser console (ctrl-shift-i on windows) to see if there’s a client side error that is causing the page to fail.

yes, the message is saying you don’t have any entry event criteria. That’s the first button at the top where it says events having the following criteria which is blank. The part you put in was an inclusion criteria looking for some death, but you didn’t say what the deaths were relative to (ie: the entry event).

Not sure, again, check the logs for errors.

Also, you mentioned in your post that you created sql server tables, but the configuration seems to indicate postgresql. Are you hosting anything on postgresql?

My webapi tables are on Postgresql, everything else is in SQL server.

See tables below:


Ok, yes so that looks good, your PG instance has WebAPI tables, your SQL Server has the cdm and results schema. At this point, all I can suggest is that you look at the WebAPI logs for exceptions about what might be wrong when requesting those URLs. Or also check your browser console for any tell-tale errors when fetching the results from the WebAPI endpoints (ie the HTTP requests that fetch the data from the server).

Considering you’ve got your db tables, your web application launched and it’s returning some data, I think you’re pretty close to a fully-functional environment. Just seem sot be some edge cases that don’t seem to be working, and I hope the logs can shed light on it.

When you learn solutions to the problems, please share for other people to benefit from your pain and suffering :slight_smile:

-Chris

I’ve honestly no clue anymore what I did wrong.

These are my logs. Screen recording can be found here: https://cegekagroup-my.sharepoint.com/:v:/g/personal/frederic_desmet_cegeka_com/EbGO8badXu5KrUegFzd-TYoBnnncrgTfRiJXHBYMuCI7og?e=SeH3hW

WebAPI logs
230405-1654_Atlas.txt (425.7 KB)
230405-1654_WEBAPI.txt (274.3 KB)

Ok, I’ll dig through your logs and see what I can find.

First one, tho, is this:

2023-04-05 14:38:30.769 ERROR taskExecutor-1 org.ohdsi.webapi.cdmresults.service.CDMCacheService - [] - Failed to warm cache MY_CDM. Exception: PreparedStatementCallback; bad SQL grammar [select cc.concept_id, record_count, descendant_record_count, person_count, descendant_person_count
from results.achilles_result_concept_count cc
join cdm.concept c on cc.concept_id = c.concept_id
WHERE cc.concept_id >= ? and cc.concept_id <= ?]; nested exception is com.microsoft.sqlserver.jdbc.SQLServerException: Invalid column name 'person_count'.

This can be resolved if you replace the results.achilles_result_concept_count with this ddl and initialization script.

I’ll continue through the logs and report back if I see anything more.

Next one:

ORDER BY ar1.count_value DESC]; nested exception is com.microsoft.sqlserver.jdbc.SQLServerException: Invalid object name 'results.concept_hierarchy'.

This script will create that table, and this script will populate it with data (it’s a cache of vocabulary data to speed up the concept hiearchy)

This table should have been part of the results schema DDL that you fetch from WebAPI if you followed these instructions, but it is possible if you’re using with a container/pre-packaged environment, maybe it wasn’t set up correctly.

Last one:

2023-04-05 14:41:54.596 ERROR http-nio-8080-exec-6 org.ohdsi.webapi.util.GenericExceptionMapper - [] - org.springframework.jdbc.BadSqlGrammarException: PreparedStatementCallback; bad SQL grammar [select subject_id, cohort_definition_id, cohort_start_date, cohort_end_date
from results.cohort
where subject_id = ?]; nested exception is com.microsoft.sqlserver.jdbc.SQLServerException: Invalid object name 'results.cohort'.

So, the results.cohort table shouldn’t be missing (if the setup instructions were followed). This error is causing the patient profile to fail to load (the page where you entered a person_id to see the patient data).

Update:
I went back to look at your screenshot, and your CDM database has the cdm tables, and I notice that there is a results schema with 2 tables related to achilles…but none of the other tables were created in the results schema, so I would follow these instructions to set up your results schema in your CDM database so that you can run the analytics (like cohort generation and characterization)

Check! This one seems to resolve that issue.

How should I’ve known to run this?

This seems to solve a lot of issues. In my understanding Achilles was completely responsible for the results tables. This is definitelynot the case.

Thank you very much for your time and assistance. This is a great forum btw!

I’ll write a “lessons learned” with everything I’ve done so far.

1 Like

The setup guide linked above tells you how to configure your CDM database (with the schemas) so that WebAPI/Atlas can use it, but it is understandable that you may not have seen those if you are using a containerized environment that should have those things set up. We can’t automate the deployment of DB schemas to the external sources via WebAPI (well, at least we haven’t done that, it opens up some security questions).

Achilles writes to a ‘results schema’ for results, and WebAPI will assume that the Achilles tables are in the WebAPI’s result schema, but thre’s no real connection between Achilles and WebAPI’s schema.

Glad the system seems to be working for you, but now you need to unleash the power by writing (or importing) some cohort definitions, buildign some characterizations and maybe try an incidence rate calculation.

I wanted to let you know that this was very helpful to me. I am new to OHDSI and was trying to setup SQL Server and this helped pull everything together.

2 Likes
t