hapi-fhir/example-projects/hapi-fhir-jpaserver-dynamic/.README.md.html

714 lines
20 KiB
HTML

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Strict//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>/Users/anoushmouradian/Documents/projects/chip-hapi-fhir-new/hapi-fhir-jpaserver-dynamic/.README.md.html</title>
<style type="text/css">
body {
color: #333;
font: 13px/1.4 "Helvetica Neue", Helvetica, "Segoe UI", Arial, freesans, sans-serif;
padding: 0;
margin: 0;
}
a {
background: transparent;
color: #4183c4;
text-decoration: none;
}
a:active,
a:hover {
outline: 0 none;
text-decoration: underline;
}
abbr[title] {
border-bottom: 1px dotted;
}
b,
strong {
font-weight: bold;
}
dfn {
font-style: italic;
}
h1 {
font-size: 2em;
margin: 0.67em 0;
}
mark {
background: #ff0;
color: #000;
}
small {
font-size: 80%;
}
sub, sup {
font-size: 75%;
line-height: 0;
position: relative;
vertical-align: baseline;
}
sup {
top: -0.5em;
}
sub {
bottom: -0.25em;
}
img {
border: 0 none;
}
svg:not(:root) {
overflow: hidden;
}
figure {
margin: 1em 40px;
}
hr {
box-sizing: content-box;
height: 0;
}
code,
kbd,
pre,
samp {
font-family: monospace,monospace;
font-size: 1em;
}
pre {
overflow: auto;
font: 12px Consolas,"Liberation Mono",Menlo,Courier,monospace;
margin-bottom: 0;
margin-top: 0;
}
.markdown-body {
padding: 30px;
font-size: 16px;
line-height: 1.6;
word-wrap: break-word;
}
.markdown-body>*:first-child {
margin-top: 0 !important;
}
.markdown-body>*:last-child {
margin-bottom: 0 !important;
}
.markdown-body .absent {
color: #c00;
}
.markdown-body .anchor {
position: absolute;
top: 0;
bottom: 0;
left: 0;
display: block;
padding-right: 6px;
padding-left: 30px;
margin-left: -30px;
}
.markdown-body .anchor:focus {
outline: none;
}
.markdown-body h1,
.markdown-body h2,
.markdown-body h3,
.markdown-body h4,
.markdown-body h5,
.markdown-body h6 {
position: relative;
margin-top: 1em;
margin-bottom: 16px;
font-weight: bold;
line-height: 1.4;
}
.markdown-body h1 .octicon-link,
.markdown-body h2 .octicon-link,
.markdown-body h3 .octicon-link,
.markdown-body h4 .octicon-link,
.markdown-body h5 .octicon-link,
.markdown-body h6 .octicon-link {
display: none;
color: #000;
vertical-align: middle;
}
.markdown-body h1:hover .anchor,
.markdown-body h2:hover .anchor,
.markdown-body h3:hover .anchor,
.markdown-body h4:hover .anchor,
.markdown-body h5:hover .anchor,
.markdown-body h6:hover .anchor {
padding-left: 8px;
margin-left: -30px;
line-height: 1;
text-decoration: none;
}
.markdown-body h1:hover .anchor .octicon-link,
.markdown-body h2:hover .anchor .octicon-link,
.markdown-body h3:hover .anchor .octicon-link,
.markdown-body h4:hover .anchor .octicon-link,
.markdown-body h5:hover .anchor .octicon-link,
.markdown-body h6:hover .anchor .octicon-link {
display: inline-block;
}
.markdown-body h1 tt,
.markdown-body h1 code,
.markdown-body h2 tt,
.markdown-body h2 code,
.markdown-body h3 tt,
.markdown-body h3 code,
.markdown-body h4 tt,
.markdown-body h4 code,
.markdown-body h5 tt,
.markdown-body h5 code,
.markdown-body h6 tt,
.markdown-body h6 code {
font-size: inherit;
}
.markdown-body h1 {
padding-bottom: 0.3em;
font-size: 2.25em;
line-height: 1.2;
border-bottom: 1px solid #eee;
}
.markdown-body h2 {
padding-bottom: 0.3em;
font-size: 1.75em;
line-height: 1.225;
border-bottom: 1px solid #eee;
}
.markdown-body h3 {
font-size: 1.5em;
line-height: 1.43;
}
.markdown-body h4 {
font-size: 1.25em;
}
.markdown-body h5 {
font-size: 1em;
}
.markdown-body h6 {
font-size: 1em;
color: #777;
}
.markdown-body p,.markdown-body blockquote,
.markdown-body ul,.markdown-body ol,
.markdown-body dl,.markdown-body table,
.markdown-body pre {
margin-top: 0;
margin-bottom: 16px;
}
.markdown-body hr {
height: 4px;
padding: 0;
margin: 16px 0;
background-color: #e7e7e7;
border: 0 none;
}
.markdown-body ul,
.markdown-body ol {
padding-left: 2em;
}
.markdown-body ul.no-list,
.markdown-body ol.no-list {
padding: 0;
list-style-type: none;
}
.markdown-body ul ul,
.markdown-body ul ol,
.markdown-body ol ol,
.markdown-body ol ul {
margin-top: 0;
margin-bottom: 0;
}
.markdown-body li>p {
margin-top: 16px;
}
.markdown-body dl {
padding: 0;
}
.markdown-body dl dt {
padding: 0;
margin-top: 16px;
font-size: 1em;
font-style: italic;
font-weight: bold;
}
.markdown-body dl dd {
padding: 0 16px;
margin-bottom: 16px;
}
.markdown-body blockquote {
padding: 0 15px;
color: #777;
border-left: 4px solid #ddd;
}
.markdown-body blockquote>:first-child {
margin-top: 0;
}
.markdown-body blockquote>:last-child {
margin-bottom: 0;
}
.markdown-body table {
display: block;
width: 100%;
overflow: auto;
word-break: normal;
word-break: keep-all;
}
.markdown-body table th {
font-weight: bold;
}
.markdown-body table th,
.markdown-body table td {
padding: 6px 13px;
border: 1px solid #ddd;
}
.markdown-body table tr {
background-color: #fff;
border-top: 1px solid #ccc;
}
.markdown-body table tr:nth-child(2n) {
background-color: #f8f8f8;
}
.markdown-body img {
max-width: 100%;
-moz-box-sizing: border-box;
box-sizing: border-box;
}
.markdown-body span.frame {
display: block;
overflow: hidden;
}
.markdown-body span.frame>span {
display: block;
float: left;
width: auto;
padding: 7px;
margin: 13px 0 0;
overflow: hidden;
border: 1px solid #ddd;
}
.markdown-body span.frame span img {
display: block;
float: left;
}
.markdown-body span.frame span span {
display: block;
padding: 5px 0 0;
clear: both;
color: #333;
}
.markdown-body span.align-center {
display: block;
overflow: hidden;
clear: both;
}
.markdown-body span.align-center>span {
display: block;
margin: 13px auto 0;
overflow: hidden;
text-align: center;
}
.markdown-body span.align-center span img {
margin: 0 auto;
text-align: center;
}
.markdown-body span.align-right {
display: block;
overflow: hidden;
clear: both;
}
.markdown-body span.align-right>span {
display: block;
margin: 13px 0 0;
overflow: hidden;
text-align: right;
}
.markdown-body span.align-right span img {
margin: 0;
text-align: right;
}
.markdown-body span.float-left {
display: block;
float: left;
margin-right: 13px;
overflow: hidden;
}
.markdown-body span.float-left span {
margin: 13px 0 0;
}
.markdown-body span.float-right {
display: block;
float: right;
margin-left: 13px;
overflow: hidden;
}
.markdown-body span.float-right>span {
display: block;
margin: 13px auto 0;
overflow: hidden;
text-align: right;
}
.markdown-body code,.markdown-body tt {
padding: 0;
padding-top: 0.2em;
padding-bottom: 0.2em;
margin: 0;
font-size: 85%;
background-color: rgba(0,0,0,0.04);
border-radius: 3px;
}
.markdown-body code:before,
.markdown-body code:after,
.markdown-body tt:before,
.markdown-body tt:after {
letter-spacing: -0.2em;
content: "\00a0";
}
.markdown-body code br,
.markdown-body tt br {
display: none;
}
.markdown-body del code {
text-decoration: inherit;
}
.markdown-body pre>code {
padding: 0;
margin: 0;
font-size: 100%;
word-break: normal;
white-space: pre;
background: transparent;
border: 0;
}
.markdown-body .highlight {
margin-bottom: 16px;
}
.markdown-body .highlight pre,
.markdown-body pre {
padding: 16px;
overflow: auto;
font-size: 85%;
line-height: 1.45;
background-color: #f7f7f7;
border-radius: 3px;
}
.markdown-body .highlight pre {
margin-bottom: 0;
word-break: normal;
}
.markdown-body pre {
word-wrap: normal;
}
.markdown-body pre code,
.markdown-body pre tt {
display: inline;
max-width: initial;
padding: 0;
margin: 0;
overflow: initial;
line-height: inherit;
word-wrap: normal;
background-color: transparent;
border: 0;
}
.markdown-body pre code:before,
.markdown-body pre code:after,
.markdown-body pre tt:before,
.markdown-body pre tt:after {
content: normal;
}
.highlight .pl-coc,
.highlight .pl-entl,
.highlight .pl-entm,
.highlight .pl-eoa,
.highlight .pl-mai .pl-sf,
.highlight .pl-mm,
.highlight .pl-pdv,
.highlight .pl-sc,
.highlight .pl-som,
.highlight .pl-sr,
.highlight .pl-v,
.highlight .pl-vpf {
color: #0086b3;
}
.highlight .pl-eoac,
.highlight .pl-mdht,
.highlight .pl-mi1,
.highlight .pl-mri,
.highlight .pl-va,
.highlight .pl-vpu {
color: #008080;
}
.highlight .pl-c,
.highlight .pl-pdc {
color: #b4b7b4;
font-style: italic;
}
.highlight .pl-k,
.highlight .pl-ko,
.highlight .pl-kolp,
.highlight .pl-mc,
.highlight .pl-mr,
.highlight .pl-ms,
.highlight .pl-s,
.highlight .pl-sok,
.highlight .pl-st {
color: #6e5494;
}
.highlight .pl-ef,
.highlight .pl-enf,
.highlight .pl-enm,
.highlight .pl-entc,
.highlight .pl-eoi,
.highlight .pl-sf,
.highlight .pl-smc {
color: #d12089;
}
.highlight .pl-ens,
.highlight .pl-eoai,
.highlight .pl-kos,
.highlight .pl-mh .pl-pdh,
.highlight .pl-mp,
.highlight .pl-pde,
.highlight .pl-stp {
color: #458;
}
.highlight .pl-enti {
color: #d12089;
font-weight: bold;
}
.highlight .pl-cce,
.highlight .pl-enc,
.highlight .pl-kou,
.highlight .pl-mq {
color: #f93;
}
.highlight .pl-mp1 .pl-sf {
color: #458;
font-weight: bold;
}
.highlight .pl-cos,
.highlight .pl-ent,
.highlight .pl-md,
.highlight .pl-mdhf,
.highlight .pl-ml,
.highlight .pl-pdc1,
.highlight .pl-pds,
.highlight .pl-s1,
.highlight .pl-scp,
.highlight .pl-sol {
color: #df5000;
}
.highlight .pl-c1,
.highlight .pl-cn,
.highlight .pl-pse,
.highlight .pl-pse .pl-s2,
.highlight .pl-vi {
color: #a31515;
}
.highlight .pl-mb,
.highlight .pl-pdb {
color: #df5000;
font-weight: bold;
}
.highlight .pl-mi,
.highlight .pl-pdi {
color: #6e5494;
font-style: italic;
}
.highlight .pl-ms1 {
background-color: #f5f5f5;
}
.highlight .pl-mdh,
.highlight .pl-mdi {
font-weight: bold;
}
.highlight .pl-mdr {
color: #0086b3;
font-weight: bold;
}
.highlight .pl-s2 {
color: #333;
}
.highlight .pl-ii {
background-color: #df5000;
color: #fff;
}
.highlight .pl-ib {
background-color: #f93;
}
.highlight .pl-id {
background-color: #a31515;
color: #fff;
}
.highlight .pl-iu {
background-color: #b4b7b4;
}
.highlight .pl-mo {
color: #969896;
}
</style>
<script type="text/javascript">
function getDocumentScrollTop()
{
var res = document.body.scrollTop || document.documentElement.scrollTop || window.pageYOffset || 0;
// alert(res);
return res;
}
function setDocumentScrollTop(ypos)
{
window.scrollTo(0, ypos);
}
</script>
</head>
<body class="markdown-body">
<h2> <a id="description" class="anchor" href="#description" aria-hidden="true"><span aria-hidden="true" class="octicon octicon-link"></span></a>Description</h2>
<p>This project has been built with hapi-fhir-jpaserver-example as a base. It has been made more dynamic by replacing <code>web.xml</code> with <code>ca.uhn.fhir.jpa.demo.WebInitializer</code> class which extends Spring <code>org.springframework.web.WebApplicationInitializer</code> 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.</p>
<h4> <a id="environment-variables" class="anchor" href="#environment-variables" aria-hidden="true"><span aria-hidden="true" class="octicon octicon-link"></span></a>Environment variables</h4>
<p>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:</p>
<ul>
<li> <p><code>DB_URL</code> - database url in a standard jdbc url format, specific to a database of your choosing. For example for Postgres it will be: <code>jdbc:postgresql://localhost:5432/&lt;databaseName&gt;?user=&lt;username&gt;&amp;password=&lt;password&gt;</code>. So far support has been added for MySQL, derby and Postgres databases.</p> </li>
<li> <p><code>DATABASE_URL</code> - if you deploy your server to HEROKU and create a Postgres database, its URL will be exposed through <code>DATABASE_URL</code> environment variable set by HEROKU. If <code>DATABASE_URL</code> is present it will overwrite <code>DB_URL</code> and its value will be used as jdbc url. This implementations assumes that Heroku will be setup with Postgres database, so current implementation handles postgres <code>DATABASE_URL</code> that gets set in this format: <code>postgres://&lt;username&gt;:&lt;password&gt;@&lt;hostname&gt;:5432/&lt;databaseName&gt;</code>. We convert it into standard jdbc format: <code>jdbc:postgresql://localhost:5432/&lt;databaseName&gt;?user=&lt;username&gt;&amp;password=&lt;password&gt;</code></p> </li>
<li> <p><code>SCHEMA_NAME</code> - used only if <code>DATABASE_URL</code> is set, which is expected to be Postgres database url set by HEROKU. If it's set <code>currentSchema</code> parameter will be added to the jdbc url, e.g.:<br /> <code>jdbc:postgresql://localhost:5432/&lt;databaseName&gt;?user=&lt;username&gt;&amp;password=&lt;password&gt;&amp;currentScema=&lt;schemaName&gt;</code>. Note that schema has to be created beforehand and user should have the right permissions to create tables.</p> </li>
<li> <p><code>STU_VERSION</code> - can be set to <code>dstu2</code> or <code>dstu3</code>. If not set by default <code>dstu3</code> will be used. Corresponding classes will get dynamically loaded at a server startup.</p> </li>
<li> <p><code>ENV</code> - environment this server will run in, and based on which corresponding property files will be loaded.</p> <p>It can be one of those values: <code>local, dev, stg, prod</code>. Based on the value one of the property files will be loaded: <code>resources/config/&lt;STU_VERSION&gt;/app_&lt;ENV&gt;.properties</code>.</p> <p>So for example if <code>ENV=local</code> and <code>STU_VERSION=dstu3</code> this file will be loaded:</p> <p><code>resources/config/dstu3/app_local.properties</code></p> </li>
<li> <p><code>HIBERNATE_CREATE</code> - can be set to <code>true</code> or <code>false</code>. If set to <code>true</code> database schema will be dropped and recreated again upon application startup. If set to <code>false</code> hibernate will run with <code>validate</code> as a schema setting.</p> </li>
</ul>
<h4> <a id="property-files" class="anchor" href="#property-files" aria-hidden="true"><span aria-hidden="true" class="octicon octicon-link"></span></a>Property files</h4>
<p>There are number of property files created for different environments: <code>local, dev, stg, prod</code>. So if <code>ENV</code> environment variable is set to one of those values corresponding property file will be loaded at a run time, by default <code>local</code> files will be loaded. Property files are located at: <code>src/main/resources/config/dstu2</code> and <code>src/main/resources/config/dstu3s</code> directories. These are the files:</p>
<pre><code> 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.
</code></pre>
<p>Any of the Environment variables can be defined in one of the <code>app_&lt;ENV&gt;.properties</code> property files. If a property is also defined as Environment variable it will overwrite value defined in property file. Properties defined in <code>immutable.properties</code> 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.</p>
<h2> <a id="running-hapi-fhir-jpaserver-dynamic-with-a-webapp-runner" class="anchor" href="#running-hapi-fhir-jpaserver-dynamic-with-a-webapp-runner" aria-hidden="true"><span aria-hidden="true" class="octicon octicon-link"></span></a>Running hapi-fhir-jpaserver-dynamic with a webapp-runner</h2>
<p>You can run the web application with webapp-runner and pass environment variables to it.</p>
<p>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.</p>
<p>Note optional command to unset DATABASE_URL, so that only DB_URL is used locally. Also make sure to replace placeholder parameters <code>&lt;databasename&gt;</code>, <code>&lt;username&gt;</code> and <code>&lt;password&gt;</code> with actual values.</p>
<pre><code>mvn clean install
unset DATABASE_URL
java $JAVA_OPTS -DSTU_VERSION=dstu3 -DHIBERNATE_CREATE=true -DDB_URL='jdbc:postgresql://localhost:5432/&lt;databaseName&gt;?user=&lt;username&gt;&amp;password=&lt;password&gt;' -DENV=local -jar target/dependency/webapp-runner.jar target/*.war
</code></pre>
<p>You should be able to access HAPI_FHIR server at: <a href="http://localhost:8080/" rel="nofollow">http://localhost:8080/</a> .</p>
<p>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.</p>
<pre><code>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/&lt;databaseName&gt;?user=&lt;username&gt;&amp;password=&lt;password&gt;' -DENV=local -jar target/dependency/webapp-runner.jar target/*.war
</code></pre>
<h2> <a id="running-hapi-fhir-jpaserver-dynamic-in-tomcat-from-intellij" class="anchor" href="#running-hapi-fhir-jpaserver-dynamic-in-tomcat-from-intellij" aria-hidden="true"><span aria-hidden="true" class="octicon octicon-link"></span></a>Running hapi-fhir-jpaserver-dynamic in Tomcat from IntelliJ</h2>
<p>Install Tomcat.</p>
<p>Make sure you have Tomcat set up in IntelliJ.</p>
<ul>
<li>File-&gt;Settings-&gt;Build, Execution, Deployment-&gt;Application Servers</li>
<li>Click +</li>
<li>Select &quot;Tomcat Server&quot;</li>
<li>Enter the path to your tomcat deployment for both Tomcat Home (IntelliJ will fill in base directory for you)</li>
</ul>
<p>Add a Run Configuration for running hapi-fhir-jpaserver-dynamic under Tomcat</p>
<ul>
<li>Run-&gt;Edit Configurations</li>
<li>Click the green +</li>
<li>Select Tomcat Server, Local</li>
<li>Change the name to whatever you wish</li>
<li>Uncheck the &quot;After launch&quot; checkbox</li>
<li>On the &quot;Deployment&quot; tab, click the green +</li>
<li>Select &quot;Artifact&quot;</li>
<li>Select &quot;hapi-fhir-jpaserver-dynamic:war&quot;</li>
<li>In &quot;Application context&quot; type /hapi</li>
</ul>
<p>Run the configuration.</p>
<ul>
<li>You should now have an &quot;Application Servers&quot; in the list of windows at the bottom.</li>
<li>Click it.</li>
<li>Select your server, and click the green triangle (or the bug if you want to debug)</li>
<li>Wait for the console output to stop</li>
</ul>
<p>Point your browser (or fiddler, or what have you) to <code>http://localhost:8080/fhir/base/Patient</code></p>
<p>You should get an empty bundle back.</p>
<h2> <a id="running-hapi-fhir-jpaserver-dynamic-in-a-docker-container" class="anchor" href="#running-hapi-fhir-jpaserver-dynamic-in-a-docker-container" aria-hidden="true"><span aria-hidden="true" class="octicon octicon-link"></span></a>Running hapi-fhir-jpaserver-dynamic in a Docker container</h2>
<p>Execute the <code>build-docker-image.sh</code> script to build the docker image.</p>
<p>Use this command to start the container: <code>docker run -d --name hapi-fhir-jpaserver-dynamic -p 8080:8080 hapi-fhir/hapi-fhir-jpaserver-dynamic</code></p>
<p>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.</p>
<p>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.</p>
</body>
</html>