Description

This project has been built with hapi-fhir-jpaserver-example as a base. It has been made more dynamic by replacing web.xml with ca.uhn.fhir.jpa.demo.WebInitializer class which extends Spring org.springframework.web.WebApplicationInitializer class and loads application contexts in a dynamic manner, so that based on environment and/or property variables it can be started either as dstu2 or dstu3 version of HAPI-FHIR JPA Server. Some of the classes have been also refactored to make them more generic.

Environment variables

There are number of environment variables that will control the behavior of the application at run time (such as start as dstu2 or dstu3 version, whether database schema gets recreated or no, database url, etc..). They can also be defined in Property files, see section below. These are environment variables that can be set before application starts:

Property files

There are number of property files created for different environments: local, dev, stg, prod. So if ENV environment variable is set to one of those values corresponding property file will be loaded at a run time, by default local files will be loaded. Property files are located at: src/main/resources/config/dstu2 and src/main/resources/config/dstu3s directories. These are the files:

   app_local.properties
   app_dev.properties
   app_stg.properties
   app_prod.properties
   immutable.properties - DO NOT modify any of the properties defined in that file.

Any of the Environment variables can be defined in one of the app_<ENV>.properties property files. If a property is also defined as Environment variable it will overwrite value defined in property file. Properties defined in immutable.properties should not be changed, those are servlet/Spring mappings and names of classes that will be loaded at a run time and are specific to dstu version being used.

Running hapi-fhir-jpaserver-dynamic with a webapp-runner

You can run the web application with webapp-runner and pass environment variables to it.

Here is a sample command to run the webapp runner which will start dynamic HAPI-FHIR server with version dstu3, postgres database and hibernate schema being dropped and re-created.

Note optional command to unset DATABASE_URL, so that only DB_URL is used locally. Also make sure to replace placeholder parameters <databasename>, <username> and <password> with actual values.

mvn clean install

unset DATABASE_URL

java $JAVA_OPTS -DSTU_VERSION=dstu3 -DHIBERNATE_CREATE=true -DDB_URL='jdbc:postgresql://localhost:5432/<databaseName>?user=<username>&password=<password>' -DENV=local -jar target/dependency/webapp-runner.jar target/*.war

You should be able to access HAPI_FHIR server at: http://localhost:8080/ .

If you'd like to open a debugging port run this command and attach remote debugger in IDE of your choice to port 5000. Again make sure to replace placeholder parameters with actual values before you run the command.

java $JAVA_OPTS -Xdebug -Xrunjdwp:transport=dt_socket,server=y,address=5000,suspend=n -DSTU_VERSION=dstu3 -DHIBERNATE_CREATE=false -DDB_URL='jdbc:postgresql://localhost:5432/<databaseName>?user=<username>&password=<password>' -DENV=local -jar target/dependency/webapp-runner.jar target/*.war

Running hapi-fhir-jpaserver-dynamic in Tomcat from IntelliJ

Install Tomcat.

Make sure you have Tomcat set up in IntelliJ.

Add a Run Configuration for running hapi-fhir-jpaserver-dynamic under Tomcat

Run the configuration.

Point your browser (or fiddler, or what have you) to http://localhost:8080/fhir/base/Patient

You should get an empty bundle back.

Running hapi-fhir-jpaserver-dynamic in a Docker container

Execute the build-docker-image.sh script to build the docker image.

Use this command to start the container: docker run -d --name hapi-fhir-jpaserver-dynamic -p 8080:8080 hapi-fhir/hapi-fhir-jpaserver-dynamic

Note: with this command data is persisted across container restarts, but not after removal of the container. Use a docker volume mapping on /var/lib/jetty/target to achieve this.

There is also Dockerfile.tomcat which contains docker commands to run hapi-fhir-jpaserver-dynamic within tomcat. Rename Dockerfile.tomcat to Dockerfile if you would rather use tomcat as your application container.