Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

👼 Automate schema creation #1

Closed
wants to merge 7 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
language: java
jdk:
- openjdk10

sudo: required
services:
- docker

# Fix for https://travis-ci.community/t/problematic-docker-compose-version-1-23-1/5362/3
before_install:
- sudo rm /usr/local/bin/docker-compose
- curl -L https://github.com/docker/compose/releases/download/1.24.1/docker-compose-Linux-x86_64 > docker-compose
- chmod +x docker-compose
- sudo mv docker-compose /usr/local/bin

install:
- mvn -Ptravis install -DskipTests=true -Dmaven.javadoc.skip=true -B -V

script:
- mvn test -Dskip.tests=false
35 changes: 35 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1 +1,36 @@
# omoponfhir-omopv5-jpabase

<!-- TODO: Change this URL when merged -->
[![Build Status](https://travis-ci.org/PheMA/omoponfhir-omopv5-jpabase.svg?branch=flyway)](https://travis-ci.org/PheMA/omoponfhir-omopv5-jpabase)

Java library containing Hibernate JPA entities used by OMOP on FHIR.


## Schema Preparation

At least one table and one view need to be created to support mapping the OMOP CDM to FHIR. First, the `f_person` table
must be created to contain additional demographic information used by FHIR, but not typically stored in the OMOP CDM.
Second, since both the CDM `measurement` and `observation` tables map to the FHIR <kbd>Observation</kbd> resource, we
create a view called `f_observation_view`, which is a union of these two tables.

The PostgreSQL scripts for creating these two tables, as well as an index on `f_person` can be found in
[`src/main/resources/flyway/migrations/postgresql`](src/main/resources/flyway/migrations/postgresql).

### Automatic Schema Creation

To automatically create the necessary tables, or apply any updates implemented since you last ran the scripts, do the
following.

First, clone this repository:

```
git clone https://github.com/omoponfhir/omoponfhir-omopv5-jpabase.git
```

Then, use Maven and Flyway to apply the scripts for you:

```sh
mvn flyway:migrate -Ddatabase.url='jdbc:postgresql://localhost:5432/postgres?currentSchema=cdm' -Ddatabase.user=postgres -Ddatabase.password=postgres
```

Adjust the parameters as required. Importantly, ensure the correct schema is selected (`cdm` in the above example).
288 changes: 185 additions & 103 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,111 +6,193 @@
OR CONDITIONS OF ANY KIND, either express or implied. See the License for
the specific language governing permissions and limitations under the License. -->
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>edu.gatech.chai</groupId>
<artifactId>omoponfhir-omopv5-jpabase</artifactId>
<packaging>jar</packaging>
<version>1.1.2</version>
<name>omoponfhir-omopv5-jpabase</name>
<description>OMOP on FHIR JPABASE for OMOP version 5</description>
<url>http://maven.apache.org</url>
<groupId>edu.gatech.chai</groupId>
<artifactId>omoponfhir-omopv5-jpabase</artifactId>
<packaging>jar</packaging>
<version>1.1.2</version>
<name>omoponfhir-omopv5-jpabase</name>
<description>OMOP on FHIR JPABASE for OMOP version 5</description>
<url>http://maven.apache.org</url>

<licenses>
<license>
<name>Apache License, Version 2.0</name>
<url>http://www.apache.org/licenses/LICENSE-2.0.txt</url>
<distribution>repo</distribution>
</license>
</licenses>
<licenses>
<license>
<name>Apache License, Version 2.0</name>
<url>http://www.apache.org/licenses/LICENSE-2.0.txt</url>
<distribution>repo</distribution>
</license>
</licenses>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<hibernate_version>5.3.1.Final</hibernate_version>
<spring_version>5.0.8.RELEASE</spring_version>
<hibernate_version>5.3.1.Final</hibernate_version>
</properties>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<hibernate_version>5.3.1.Final</hibernate_version>
<spring_version>5.0.8.RELEASE</spring_version>
<hibernate_version>5.3.1.Final</hibernate_version>
<!-- For Flyway migrations -->
<flyway.version>6.1.3</flyway.version>
<postgres.driver.version>42.2.6</postgres.driver.version>
<database.url/>
<database.user/>
<database.password/>
<!-- Testing -->
<skip.tests>true</skip.tests>
<junit.jupiter.version>5.4.2</junit.jupiter.version>
<testcontainers.version>1.12.3</testcontainers.version>
</properties>

<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.eclipse.persistence</groupId>
<artifactId>javax.persistence</artifactId>
<version>2.2.0</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>${hibernate_version}</version>
</dependency>
<dependency>
<groupId>org.javassist</groupId>
<artifactId>javassist</artifactId>
<version>3.20.0-GA</version>
</dependency>
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<version>9.4.1211.jre7</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>${spring_version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-orm</artifactId>
<version>${spring_version}</version>
</dependency>
<dependency>
<groupId>net.jcip</groupId>
<artifactId>jcip-annotations</artifactId>
<version>1.0</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.json/json -->
<dependency>
<groupId>org.json</groupId>
<artifactId>json</artifactId>
<version>20180130</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.25</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.6</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.12.4</version>
<configuration>
<skipTests>true</skipTests>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.0</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>org.eclipse.persistence</groupId>
<artifactId>javax.persistence</artifactId>
<version>2.2.0</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>${hibernate_version}</version>
</dependency>
<dependency>
<groupId>org.javassist</groupId>
<artifactId>javassist</artifactId>
<version>3.20.0-GA</version>
</dependency>
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<version>9.4.1211.jre7</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>${spring_version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-orm</artifactId>
<version>${spring_version}</version>
</dependency>
<dependency>
<groupId>net.jcip</groupId>
<artifactId>jcip-annotations</artifactId>
<version>1.0</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.json/json -->
<dependency>
<groupId>org.json</groupId>
<artifactId>json</artifactId>
<version>20180130</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.25</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.6</version>
</dependency>
<!-- Testing -->
<dependency>
<groupId>org.flywaydb</groupId>
<artifactId>flyway-core</artifactId>
<version>${flyway.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>${junit.jupiter.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-params</artifactId>
<version>${junit.jupiter.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>${junit.jupiter.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.testcontainers</groupId>
<artifactId>testcontainers</artifactId>
<version>${testcontainers.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.testcontainers</groupId>
<artifactId>junit-jupiter</artifactId>
<version>${testcontainers.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.testcontainers</groupId>
<artifactId>postgresql</artifactId>
<version>${testcontainers.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.zaxxer</groupId>
<artifactId>HikariCP</artifactId>
<version>3.4.1</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.19.1</version>
<configuration>
<skipTests>${skip.tests}</skipTests>
</configuration>
<dependencies>
<dependency>
<groupId>org.junit.platform</groupId>
<artifactId>junit-platform-surefire-provider</artifactId>
<version>1.0.1</version>
</dependency>
</dependencies>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.0</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<groupId>org.flywaydb</groupId>
<artifactId>flyway-maven-plugin</artifactId>
<version>${flyway.version}</version>
<configuration>
<sqlMigrationSeparator>__</sqlMigrationSeparator>
<locations>
<location>filesystem:src/main/resources/flyway/migrations/postgresql</location>
</locations>
<url>${database.url}</url>
<user>${database.user}</user>
<password>${database.password}</password>
<baselineOnMigrate>true</baselineOnMigrate>
</configuration>
<dependencies>
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<version>${postgres.driver.version}</version>
</dependency>
</dependencies>
</plugin>
</plugins>
</build>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
CREATE TABLE f_person
(
person_id INTEGER NOT NULL,
family_name VARCHAR(255),
given1_name VARCHAR(255),
given2_name VARCHAR(255),
prefix_name VARCHAR(255),
suffix_name VARCHAR(255),
preferred_language VARCHAR(255),
ssn VARCHAR(12),
active SMALLINT DEFAULT 1,
contact_point1 VARCHAR(255),
contact_point2 VARCHAR(255),
contact_point3 VARCHAR(255),
maritalstatus VARCHAR(255)
);
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
CREATE INDEX f_person_person_id_idx
ON f_person (person_id);
Loading