Fix #30 - Upgrade to HAPI FHIR 3.8.0

This commit is contained in:
James Agnew
2019-06-10 05:25:41 -07:00
parent b3a0f84712
commit 5b90f1f1f4
3 changed files with 276 additions and 172 deletions

126
pom.xml
View File

@@ -11,7 +11,7 @@
<parent> <parent>
<groupId>ca.uhn.hapi.fhir</groupId> <groupId>ca.uhn.hapi.fhir</groupId>
<artifactId>hapi-fhir</artifactId> <artifactId>hapi-fhir</artifactId>
<version>3.7.0</version> <version>3.8.0</version>
</parent> </parent>
<groupId>ca.uhn.hapi.fhir.demo</groupId> <groupId>ca.uhn.hapi.fhir.demo</groupId>
@@ -37,11 +37,19 @@
<dependency> <dependency>
<groupId>com.sun.mail</groupId> <groupId>com.sun.mail</groupId>
<artifactId>javax.mail</artifactId> <artifactId>javax.mail</artifactId>
<exclusions>
<exclusion>
<groupId>javax.activation</groupId>
<artifactId>activation</artifactId>
</exclusion>
</exclusions>
</dependency> </dependency>
<!--
<dependency> <dependency>
<groupId>javax.mail</groupId> <groupId>javax.mail</groupId>
<artifactId>javax.mail-api</artifactId> <artifactId>javax.mail-api</artifactId>
</dependency> </dependency>
-->
<!-- This dependency includes the core HAPI-FHIR classes --> <!-- This dependency includes the core HAPI-FHIR classes -->
<dependency> <dependency>
@@ -62,12 +70,24 @@
<groupId>ca.uhn.hapi.fhir</groupId> <groupId>ca.uhn.hapi.fhir</groupId>
<artifactId>hapi-fhir-jpaserver-base</artifactId> <artifactId>hapi-fhir-jpaserver-base</artifactId>
<version>${project.version}</version> <version>${project.version}</version>
<exclusions>
<exclusion>
<groupId>org.springframework</groupId>
<artifactId>spring-jcl</artifactId>
</exclusion>
</exclusions>
</dependency> </dependency>
<dependency> <dependency>
<groupId>ca.uhn.hapi.fhir</groupId> <groupId>ca.uhn.hapi.fhir</groupId>
<artifactId>hapi-fhir-jpaserver-elasticsearch</artifactId> <artifactId>hapi-fhir-jpaserver-elasticsearch</artifactId>
<version>${project.version}</version> <version>${project.version}</version>
<exclusions>
<exclusion>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
</exclusion>
</exclusions>
</dependency> </dependency>
<!-- This dependency is used for the "FHIR Tester" web app overlay --> <!-- This dependency is used for the "FHIR Tester" web app overlay -->
@@ -117,6 +137,12 @@
<dependency> <dependency>
<groupId>org.apache.commons</groupId> <groupId>org.apache.commons</groupId>
<artifactId>commons-dbcp2</artifactId> <artifactId>commons-dbcp2</artifactId>
<exclusions>
<exclusion>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
</exclusion>
</exclusions>
</dependency> </dependency>
<!-- This example uses Derby embedded database. If you are using another database such as Mysql or Oracle, you may omit the following dependencies and replace them with an appropriate database client <!-- This example uses Derby embedded database. If you are using another database such as Mysql or Oracle, you may omit the following dependencies and replace them with an appropriate database client
@@ -156,7 +182,8 @@
<groupId>org.eclipse.jetty</groupId> <groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-webapp</artifactId> <artifactId>jetty-webapp</artifactId>
<scope>test</scope> <scope>test</scope>
</dependency> </dependency>
<!--
<dependency> <dependency>
<groupId>com.helger</groupId> <groupId>com.helger</groupId>
<artifactId>ph-schematron</artifactId> <artifactId>ph-schematron</artifactId>
@@ -167,6 +194,7 @@
</exclusion> </exclusion>
</exclusions> </exclusions>
</dependency> </dependency>
-->
<!-- <!--
For some reason JavaDoc crashed during site generation unless we have this dependency For some reason JavaDoc crashed during site generation unless we have this dependency
@@ -260,6 +288,100 @@
</executions> </executions>
</plugin> </plugin>
<plugin>
<groupId>org.basepom.maven</groupId>
<artifactId>duplicate-finder-maven-plugin</artifactId>
<executions>
<execution>
<id>default</id>
<phase>verify</phase>
<goals>
<goal>check</goal>
</goals>
<inherited>true</inherited>
</execution>
</executions>
<configuration>
<failBuildInCaseOfConflict>true</failBuildInCaseOfConflict>
<checkTestClasspath>false</checkTestClasspath>
<!--
<printEqualFiles>false</printEqualFiles>
<failBuildInCaseOfDifferentContentConflict>true</failBuildInCaseOfDifferentContentConflict>
<failBuildInCaseOfEqualContentConflict>true</failBuildInCaseOfEqualContentConflict>
<failBuildInCaseOfConflict>true</failBuildInCaseOfConflict>
<checkCompileClasspath>true</checkCompileClasspath>
<checkRuntimeClasspath>false</checkRuntimeClasspath>
<skip>false</skip>
<quiet>false</quiet>
<preferLocal>true</preferLocal>
<useResultFile>true</useResultFile>
<resultFileMinClasspathCount>2</resultFileMinClasspathCount>
<resultFile>${project.build.directory}/duplicate-finder-result.xml</resultFile>
-->
<!--
<ignoredDependencies>
<dependency>
<groupId>javax.el</groupId>
<artifactId>javax.el-api</artifactId>
</dependency>
<dependency>
<groupId>javax.mail</groupId>
<artifactId>javax.mail-api</artifactId>
</dependency>
<dependency>
<groupId>javax.activation</groupId>
<artifactId>javax.activation-api</artifactId>
</dependency>
<dependency>
<groupId>com.helger</groupId>
<artifactId>ph-schematron</artifactId>
</dependency>
<dependency>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
</dependency>
<dependency>
<groupId>org.jscience</groupId>
<artifactId>jscience</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-jcl</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-jcl</artifactId>
</dependency>
<dependency>
<groupId>com.google.code.findbugs</groupId>
<artifactId>annotations</artifactId>
</dependency>
<dependency>
<groupId>org.apache.derby</groupId>
<artifactId>derbyclient</artifactId>
</dependency>
<dependency>
<groupId>org.apache.derby</groupId>
<artifactId>derbynet</artifactId>
</dependency>
<dependency>
<groupId>org.apache.derby</groupId>
<artifactId>derbyclient</artifactId>
</dependency>
<dependency>
<groupId>org.checkerframework</groupId>
<artifactId>checker-compat-qual</artifactId>
</dependency>
</ignoredDependencies>
-->
<ignoredResourcePatterns>
<ignoredResourcePattern>.*\.txt$</ignoredResourcePattern>
<ignoredResourcePattern>.*\.html$</ignoredResourcePattern>
</ignoredResourcePatterns>
</configuration>
</plugin>
</plugins> </plugins>
</build> </build>

View File

@@ -1,26 +1,21 @@
package ca.uhn.fhir.jpa.starter; package ca.uhn.fhir.jpa.starter;
import java.lang.reflect.InvocationTargetException; import ca.uhn.fhir.jpa.dao.DaoConfig;
import java.sql.Driver;
import ca.uhn.fhir.jpa.model.entity.ModelConfig; import ca.uhn.fhir.jpa.model.entity.ModelConfig;
import ca.uhn.fhir.jpa.subscription.module.cache.SubscriptionDeliveryHandlerFactory; import ca.uhn.fhir.jpa.subscription.module.cache.SubscriptionDeliveryHandlerFactory;
import ca.uhn.fhir.jpa.subscription.module.subscriber.email.IEmailSender; import ca.uhn.fhir.jpa.subscription.module.subscriber.email.IEmailSender;
import ca.uhn.fhir.jpa.subscription.module.subscriber.email.JavaMailEmailSender; import ca.uhn.fhir.jpa.subscription.module.subscriber.email.JavaMailEmailSender;
import org.apache.commons.dbcp2.BasicDataSource; import org.apache.commons.dbcp2.BasicDataSource;
import org.hl7.fhir.instance.model.Subscription; import org.hl7.fhir.instance.model.Subscription;
import org.springframework.beans.factory.annotation.Autowire;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
import org.springframework.transaction.annotation.EnableTransactionManagement; import org.springframework.transaction.annotation.EnableTransactionManagement;
import ca.uhn.fhir.jpa.dao.DaoConfig;
import ca.uhn.fhir.rest.server.interceptor.IServerInterceptor;
import ca.uhn.fhir.rest.server.interceptor.LoggingInterceptor;
import ca.uhn.fhir.rest.server.interceptor.ResponseHighlighterInterceptor;
import org.thymeleaf.util.Validate; import org.thymeleaf.util.Validate;
import java.lang.reflect.InvocationTargetException;
import java.sql.Driver;
/** /**
* This is the primary configuration file for the example server * This is the primary configuration file for the example server
*/ */
@@ -28,173 +23,149 @@ import org.thymeleaf.util.Validate;
@EnableTransactionManagement() @EnableTransactionManagement()
public class FhirServerConfigCommon { public class FhirServerConfigCommon {
private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(FhirServerConfigCommon.class); private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(FhirServerConfigCommon.class);
private Boolean allowContainsSearches = HapiProperties.getAllowContainsSearches(); private Boolean allowContainsSearches = HapiProperties.getAllowContainsSearches();
private Boolean allowMultipleDelete = HapiProperties.getAllowMultipleDelete(); private Boolean allowMultipleDelete = HapiProperties.getAllowMultipleDelete();
private Boolean allowExternalReferences = HapiProperties.getAllowExternalReferences(); private Boolean allowExternalReferences = HapiProperties.getAllowExternalReferences();
private Boolean expungeEnabled = HapiProperties.getExpungeEnabled(); private Boolean expungeEnabled = HapiProperties.getExpungeEnabled();
private Boolean allowPlaceholderReferences = HapiProperties.getAllowPlaceholderReferences(); private Boolean allowPlaceholderReferences = HapiProperties.getAllowPlaceholderReferences();
private Boolean subscriptionRestHookEnabled = HapiProperties.getSubscriptionRestHookEnabled(); private Boolean subscriptionRestHookEnabled = HapiProperties.getSubscriptionRestHookEnabled();
private Boolean subscriptionEmailEnabled = HapiProperties.getSubscriptionEmailEnabled(); private Boolean subscriptionEmailEnabled = HapiProperties.getSubscriptionEmailEnabled();
private Boolean allowOverrideDefaultSearchParams = HapiProperties.getAllowOverrideDefaultSearchParams(); private Boolean allowOverrideDefaultSearchParams = HapiProperties.getAllowOverrideDefaultSearchParams();
private String emailFrom = HapiProperties.getEmailFrom(); private String emailFrom = HapiProperties.getEmailFrom();
private Boolean emailEnabled = HapiProperties.getEmailEnabled(); private Boolean emailEnabled = HapiProperties.getEmailEnabled();
private String emailHost = HapiProperties.getEmailHost(); private String emailHost = HapiProperties.getEmailHost();
private Integer emailPort = HapiProperties.getEmailPort(); private Integer emailPort = HapiProperties.getEmailPort();
private String emailUsername = HapiProperties.getEmailUsername(); private String emailUsername = HapiProperties.getEmailUsername();
private String emailPassword = HapiProperties.getEmailPassword(); private String emailPassword = HapiProperties.getEmailPassword();
@Autowired
private SubscriptionDeliveryHandlerFactory mySubscriptionDeliveryHandlerFactory;
public FhirServerConfigCommon() { public FhirServerConfigCommon() {
ourLog.info("Server configured to " + (this.allowContainsSearches ? "allow" : "deny") + " contains searches"); ourLog.info("Server configured to " + (this.allowContainsSearches ? "allow" : "deny") + " contains searches");
ourLog.info("Server configured to " + (this.allowMultipleDelete ? "allow" : "deny") + " multiple deletes"); ourLog.info("Server configured to " + (this.allowMultipleDelete ? "allow" : "deny") + " multiple deletes");
ourLog.info("Server configured to " + (this.allowExternalReferences ? "allow" : "deny") + " external references"); ourLog.info("Server configured to " + (this.allowExternalReferences ? "allow" : "deny") + " external references");
ourLog.info("Server configured to " + (this.expungeEnabled ? "enable" : "disable") + " expunges"); ourLog.info("Server configured to " + (this.expungeEnabled ? "enable" : "disable") + " expunges");
ourLog.info("Server configured to " + (this.allowPlaceholderReferences ? "allow" : "deny") + " placeholder references"); ourLog.info("Server configured to " + (this.allowPlaceholderReferences ? "allow" : "deny") + " placeholder references");
ourLog.info("Server configured to " + (this.allowOverrideDefaultSearchParams ? "allow" : "deny") + " overriding default search params"); ourLog.info("Server configured to " + (this.allowOverrideDefaultSearchParams ? "allow" : "deny") + " overriding default search params");
if (this.emailEnabled) { if (this.emailEnabled) {
ourLog.info("Server is configured to enable email with host '" + this.emailHost + "' and port " + this.emailPort.toString()); ourLog.info("Server is configured to enable email with host '" + this.emailHost + "' and port " + this.emailPort.toString());
ourLog.info("Server will use '" + this.emailFrom + "' as the from email address"); ourLog.info("Server will use '" + this.emailFrom + "' as the from email address");
if (this.emailUsername != null && this.emailUsername.length() > 0) { if (this.emailUsername != null && this.emailUsername.length() > 0) {
ourLog.info("Server is configured to use username '" + this.emailUsername + "' for email"); ourLog.info("Server is configured to use username '" + this.emailUsername + "' for email");
} }
if (this.emailPassword != null && this.emailPassword.length() > 0) { if (this.emailPassword != null && this.emailPassword.length() > 0) {
ourLog.info("Server is configured to use a password for email"); ourLog.info("Server is configured to use a password for email");
} }
} }
if (this.subscriptionRestHookEnabled) { if (this.subscriptionRestHookEnabled) {
ourLog.info("REST-hook subscriptions enabled"); ourLog.info("REST-hook subscriptions enabled");
} }
if (this.subscriptionEmailEnabled) { if (this.subscriptionEmailEnabled) {
ourLog.info("Email subscriptions enabled"); ourLog.info("Email subscriptions enabled");
} }
} }
/** /**
* Configure FHIR properties around the the JPA server via this bean * Configure FHIR properties around the the JPA server via this bean
*/ */
@Bean() @Bean()
public DaoConfig daoConfig() { public DaoConfig daoConfig() {
DaoConfig retVal = new DaoConfig(); DaoConfig retVal = new DaoConfig();
retVal.setAllowContainsSearches(this.allowContainsSearches); retVal.setAllowContainsSearches(this.allowContainsSearches);
retVal.setAllowMultipleDelete(this.allowMultipleDelete); retVal.setAllowMultipleDelete(this.allowMultipleDelete);
retVal.setAllowExternalReferences(this.allowExternalReferences); retVal.setAllowExternalReferences(this.allowExternalReferences);
retVal.setExpungeEnabled(this.expungeEnabled); retVal.setExpungeEnabled(this.expungeEnabled);
retVal.setAutoCreatePlaceholderReferenceTargets(this.allowPlaceholderReferences); retVal.setAutoCreatePlaceholderReferenceTargets(this.allowPlaceholderReferences);
retVal.setEmailFromAddress(this.emailFrom); retVal.setEmailFromAddress(this.emailFrom);
Integer maxFetchSize = HapiProperties.getMaximumFetchSize(); Integer maxFetchSize = HapiProperties.getMaximumFetchSize();
retVal.setFetchSizeDefaultMaximum(maxFetchSize); retVal.setFetchSizeDefaultMaximum(maxFetchSize);
ourLog.info("Server configured to have a maximum fetch size of " + (maxFetchSize == Integer.MAX_VALUE? "'unlimited'": maxFetchSize)); ourLog.info("Server configured to have a maximum fetch size of " + (maxFetchSize == Integer.MAX_VALUE ? "'unlimited'" : maxFetchSize));
Long reuseCachedSearchResultsMillis = HapiProperties.getReuseCachedSearchResultsMillis(); Long reuseCachedSearchResultsMillis = HapiProperties.getReuseCachedSearchResultsMillis();
retVal.setReuseCachedSearchResultsForMillis(reuseCachedSearchResultsMillis ); retVal.setReuseCachedSearchResultsForMillis(reuseCachedSearchResultsMillis);
ourLog.info("Server configured to cache search results for {} milliseconds", reuseCachedSearchResultsMillis); ourLog.info("Server configured to cache search results for {} milliseconds", reuseCachedSearchResultsMillis);
// Subscriptions are enabled by channel type // Subscriptions are enabled by channel type
if (HapiProperties.getSubscriptionRestHookEnabled()) { if (HapiProperties.getSubscriptionRestHookEnabled()) {
ourLog.info("Enabling REST-hook subscriptions"); ourLog.info("Enabling REST-hook subscriptions");
retVal.addSupportedSubscriptionType(Subscription.SubscriptionChannelType.RESTHOOK); retVal.addSupportedSubscriptionType(Subscription.SubscriptionChannelType.RESTHOOK);
} }
if (HapiProperties.getSubscriptionEmailEnabled()) { if (HapiProperties.getSubscriptionEmailEnabled()) {
ourLog.info("Enabling email subscriptions"); ourLog.info("Enabling email subscriptions");
retVal.addSupportedSubscriptionType(Subscription.SubscriptionChannelType.EMAIL); retVal.addSupportedSubscriptionType(Subscription.SubscriptionChannelType.EMAIL);
} }
if (HapiProperties.getSubscriptionWebsocketEnabled()) { if (HapiProperties.getSubscriptionWebsocketEnabled()) {
ourLog.info("Enabling websocket subscriptions"); ourLog.info("Enabling websocket subscriptions");
retVal.addSupportedSubscriptionType(Subscription.SubscriptionChannelType.WEBSOCKET); retVal.addSupportedSubscriptionType(Subscription.SubscriptionChannelType.WEBSOCKET);
} }
return retVal; return retVal;
} }
@Bean @Bean
public ModelConfig modelConfig() { public ModelConfig modelConfig() {
ModelConfig modelConfig = new ModelConfig(); ModelConfig modelConfig = new ModelConfig();
modelConfig.setAllowContainsSearches(this.allowContainsSearches); modelConfig.setAllowContainsSearches(this.allowContainsSearches);
modelConfig.setAllowExternalReferences(this.allowExternalReferences); modelConfig.setAllowExternalReferences(this.allowExternalReferences);
modelConfig.setDefaultSearchParamsCanBeOverridden(this.allowOverrideDefaultSearchParams); modelConfig.setDefaultSearchParamsCanBeOverridden(this.allowOverrideDefaultSearchParams);
modelConfig.setEmailFromAddress(this.emailFrom); modelConfig.setEmailFromAddress(this.emailFrom);
// You can enable these if you want to support Subscriptions from your server // You can enable these if you want to support Subscriptions from your server
if (this.subscriptionRestHookEnabled) { if (this.subscriptionRestHookEnabled) {
modelConfig.addSupportedSubscriptionType(Subscription.SubscriptionChannelType.RESTHOOK); modelConfig.addSupportedSubscriptionType(Subscription.SubscriptionChannelType.RESTHOOK);
} }
if (this.subscriptionEmailEnabled) { if (this.subscriptionEmailEnabled) {
modelConfig.addSupportedSubscriptionType(Subscription.SubscriptionChannelType.EMAIL); modelConfig.addSupportedSubscriptionType(Subscription.SubscriptionChannelType.EMAIL);
} }
return modelConfig; return modelConfig;
} }
/** /**
* The following bean configures the database connection. The 'url' property value of "jdbc:derby:directory:jpaserver_derby_files;create=true" indicates that the server should save resources in a * The following bean configures the database connection. The 'url' property value of "jdbc:derby:directory:jpaserver_derby_files;create=true" indicates that the server should save resources in a
* directory called "jpaserver_derby_files". * directory called "jpaserver_derby_files".
* * <p>
* A URL to a remote database could also be placed here, along with login credentials and other properties supported by BasicDataSource. * A URL to a remote database could also be placed here, along with login credentials and other properties supported by BasicDataSource.
*/ */
@Bean(destroyMethod = "close") @Bean(destroyMethod = "close")
public BasicDataSource dataSource() throws ClassNotFoundException, NoSuchMethodException, IllegalAccessException, InvocationTargetException, InstantiationException { public BasicDataSource dataSource() throws ClassNotFoundException, NoSuchMethodException, IllegalAccessException, InvocationTargetException, InstantiationException {
BasicDataSource retVal = new BasicDataSource(); BasicDataSource retVal = new BasicDataSource();
Driver driver = (Driver) Class.forName(HapiProperties.getDataSourceDriver()).getConstructor().newInstance(); Driver driver = (Driver) Class.forName(HapiProperties.getDataSourceDriver()).getConstructor().newInstance();
retVal.setDriver(driver); retVal.setDriver(driver);
retVal.setUrl(HapiProperties.getDataSourceUrl()); retVal.setUrl(HapiProperties.getDataSourceUrl());
retVal.setUsername(HapiProperties.getDataSourceUsername()); retVal.setUsername(HapiProperties.getDataSourceUsername());
retVal.setPassword(HapiProperties.getDataSourcePassword()); retVal.setPassword(HapiProperties.getDataSourcePassword());
retVal.setMaxTotal(HapiProperties.getDataSourceMaxPoolSize()); retVal.setMaxTotal(HapiProperties.getDataSourceMaxPoolSize());
return retVal; return retVal;
} }
@Bean()
public IEmailSender emailSender() {
if (this.emailEnabled) {
JavaMailEmailSender retVal = new JavaMailEmailSender();
retVal.setSmtpServerHostname(this.emailHost);
retVal.setSmtpServerPort(this.emailPort);
retVal.setSmtpServerUsername(this.emailUsername);
retVal.setSmtpServerPassword(this.emailPassword);
Validate.notNull(mySubscriptionDeliveryHandlerFactory, "No subscription delivery handler");
mySubscriptionDeliveryHandlerFactory.setEmailSender(retVal);
/** return retVal;
* Do some fancy logging to create a nice access log that has details about each incoming request. }
*/
public IServerInterceptor loggingInterceptor() {
LoggingInterceptor retVal = new LoggingInterceptor();
retVal.setLoggerName(HapiProperties.getLoggerName());
retVal.setMessageFormat(HapiProperties.getLoggerFormat());
retVal.setErrorMessageFormat(HapiProperties.getLoggerErrorFormat());
retVal.setLogExceptions(HapiProperties.getLoggerLogExceptions());
return retVal;
}
/** return null;
* This interceptor adds some pretty syntax highlighting in responses when a browser is detected }
*/
@Bean(autowire = Autowire.BY_TYPE)
public IServerInterceptor responseHighlighterInterceptor() {
ResponseHighlighterInterceptor retVal = new ResponseHighlighterInterceptor();
return retVal;
}
@Autowired
private SubscriptionDeliveryHandlerFactory mySubscriptionDeliveryHandlerFactory;
@Bean()
public IEmailSender emailSender() {
if (this.emailEnabled) {
JavaMailEmailSender retVal = new JavaMailEmailSender();
retVal.setSmtpServerHostname(this.emailHost);
retVal.setSmtpServerPort(this.emailPort);
retVal.setSmtpServerUsername(this.emailUsername);
retVal.setSmtpServerPassword(this.emailPassword);
Validate.notNull(mySubscriptionDeliveryHandlerFactory, "No subscription delivery handler");
mySubscriptionDeliveryHandlerFactory.setEmailSender(retVal);
return retVal;
}
return null;
}
} }

View File

@@ -2,9 +2,9 @@ package ca.uhn.fhir.jpa.starter;
import ca.uhn.fhir.context.FhirContext; import ca.uhn.fhir.context.FhirContext;
import ca.uhn.fhir.context.FhirVersionEnum; import ca.uhn.fhir.context.FhirVersionEnum;
import ca.uhn.fhir.interceptor.api.IInterceptorService;
import ca.uhn.fhir.jpa.dao.DaoConfig; import ca.uhn.fhir.jpa.dao.DaoConfig;
import ca.uhn.fhir.jpa.dao.IFhirSystemDao; import ca.uhn.fhir.jpa.dao.IFhirSystemDao;
import ca.uhn.fhir.jpa.model.interceptor.executor.InterceptorService;
import ca.uhn.fhir.jpa.provider.JpaConformanceProviderDstu2; import ca.uhn.fhir.jpa.provider.JpaConformanceProviderDstu2;
import ca.uhn.fhir.jpa.provider.JpaSystemProviderDstu2; import ca.uhn.fhir.jpa.provider.JpaSystemProviderDstu2;
import ca.uhn.fhir.jpa.provider.SubscriptionTriggeringProvider; import ca.uhn.fhir.jpa.provider.SubscriptionTriggeringProvider;
@@ -17,21 +17,21 @@ import ca.uhn.fhir.jpa.provider.r4.TerminologyUploaderProviderR4;
import ca.uhn.fhir.jpa.search.DatabaseBackedPagingProvider; import ca.uhn.fhir.jpa.search.DatabaseBackedPagingProvider;
import ca.uhn.fhir.jpa.subscription.SubscriptionInterceptorLoader; import ca.uhn.fhir.jpa.subscription.SubscriptionInterceptorLoader;
import ca.uhn.fhir.jpa.subscription.module.interceptor.SubscriptionDebugLogInterceptor; import ca.uhn.fhir.jpa.subscription.module.interceptor.SubscriptionDebugLogInterceptor;
import ca.uhn.fhir.jpa.util.ResourceProviderFactory;
import ca.uhn.fhir.model.dstu2.composite.MetaDt; import ca.uhn.fhir.model.dstu2.composite.MetaDt;
import ca.uhn.fhir.narrative.DefaultThymeleafNarrativeGenerator; import ca.uhn.fhir.narrative.DefaultThymeleafNarrativeGenerator;
import ca.uhn.fhir.rest.server.HardcodedServerAddressStrategy; import ca.uhn.fhir.rest.server.HardcodedServerAddressStrategy;
import ca.uhn.fhir.rest.server.IResourceProvider;
import ca.uhn.fhir.rest.server.RestfulServer; import ca.uhn.fhir.rest.server.RestfulServer;
import ca.uhn.fhir.rest.server.interceptor.CorsInterceptor; import ca.uhn.fhir.rest.server.interceptor.CorsInterceptor;
import ca.uhn.fhir.rest.server.interceptor.LoggingInterceptor;
import ca.uhn.fhir.rest.server.interceptor.ResponseHighlighterInterceptor; import ca.uhn.fhir.rest.server.interceptor.ResponseHighlighterInterceptor;
import org.hl7.fhir.dstu3.model.Bundle; import org.hl7.fhir.dstu3.model.Bundle;
import org.hl7.fhir.dstu3.model.Meta; import org.hl7.fhir.dstu3.model.Meta;
import org.springframework.web.cors.CorsConfiguration;
import org.springframework.context.ApplicationContext; import org.springframework.context.ApplicationContext;
import org.springframework.web.cors.CorsConfiguration;
import javax.servlet.ServletException; import javax.servlet.ServletException;
import java.util.Arrays; import java.util.Arrays;
import java.util.List;
public class JpaRestfulServer extends RestfulServer { public class JpaRestfulServer extends RestfulServer {
@@ -52,16 +52,16 @@ public class JpaRestfulServer extends RestfulServer {
* ResourceProviders are fetched from the Spring context * ResourceProviders are fetched from the Spring context
*/ */
FhirVersionEnum fhirVersion = HapiProperties.getFhirVersion(); FhirVersionEnum fhirVersion = HapiProperties.getFhirVersion();
List<IResourceProvider> resourceProviders; ResourceProviderFactory resourceProviders;
Object systemProvider; Object systemProvider;
if (fhirVersion == FhirVersionEnum.DSTU2) { if (fhirVersion == FhirVersionEnum.DSTU2) {
resourceProviders = appCtx.getBean("myResourceProvidersDstu2", List.class); resourceProviders = appCtx.getBean("myResourceProvidersDstu2", ResourceProviderFactory.class);
systemProvider = appCtx.getBean("mySystemProviderDstu2", JpaSystemProviderDstu2.class); systemProvider = appCtx.getBean("mySystemProviderDstu2", JpaSystemProviderDstu2.class);
} else if (fhirVersion == FhirVersionEnum.DSTU3) { } else if (fhirVersion == FhirVersionEnum.DSTU3) {
resourceProviders = appCtx.getBean("myResourceProvidersDstu3", List.class); resourceProviders = appCtx.getBean("myResourceProvidersDstu3", ResourceProviderFactory.class);
systemProvider = appCtx.getBean("mySystemProviderDstu3", JpaSystemProviderDstu3.class); systemProvider = appCtx.getBean("mySystemProviderDstu3", JpaSystemProviderDstu3.class);
} else if (fhirVersion == FhirVersionEnum.R4) { } else if (fhirVersion == FhirVersionEnum.R4) {
resourceProviders = appCtx.getBean("myResourceProvidersR4", List.class); resourceProviders = appCtx.getBean("myResourceProvidersR4", ResourceProviderFactory.class);
systemProvider = appCtx.getBean("mySystemProviderR4", JpaSystemProviderR4.class); systemProvider = appCtx.getBean("mySystemProviderR4", JpaSystemProviderR4.class);
} else { } else {
throw new IllegalStateException(); throw new IllegalStateException();
@@ -69,7 +69,7 @@ public class JpaRestfulServer extends RestfulServer {
setFhirContext(appCtx.getBean(FhirContext.class)); setFhirContext(appCtx.getBean(FhirContext.class));
registerProviders(resourceProviders); registerProviders(resourceProviders.createProviders());
registerProvider(systemProvider); registerProvider(systemProvider);
/* /*
@@ -133,9 +133,20 @@ public class JpaRestfulServer extends RestfulServer {
* HTML output when the request is detected to come from a * HTML output when the request is detected to come from a
* browser. * browser.
*/ */
ResponseHighlighterInterceptor responseHighlighterInterceptor = appCtx.getBean(ResponseHighlighterInterceptor.class); ResponseHighlighterInterceptor responseHighlighterInterceptor = new ResponseHighlighterInterceptor();
;
this.registerInterceptor(responseHighlighterInterceptor); this.registerInterceptor(responseHighlighterInterceptor);
/*
* Add some logging for each request
*/
LoggingInterceptor loggingInterceptor = new LoggingInterceptor();
loggingInterceptor.setLoggerName(HapiProperties.getLoggerName());
loggingInterceptor.setMessageFormat(HapiProperties.getLoggerFormat());
loggingInterceptor.setErrorMessageFormat(HapiProperties.getLoggerErrorFormat());
loggingInterceptor.setLogExceptions(HapiProperties.getLoggerLogExceptions());
this.registerInterceptor(loggingInterceptor);
/* /*
* If you are hosting this server at a specific DNS name, the server will try to * If you are hosting this server at a specific DNS name, the server will try to
* figure out the FHIR base URL based on what the web container tells it, but * figure out the FHIR base URL based on what the web container tells it, but
@@ -172,7 +183,7 @@ public class JpaRestfulServer extends RestfulServer {
// Define your CORS configuration. This is an example // Define your CORS configuration. This is an example
// showing a typical setup. You should customize this // showing a typical setup. You should customize this
// to your specific needs // to your specific needs
if(HapiProperties.getCorsEnabled()) { if (HapiProperties.getCorsEnabled()) {
CorsConfiguration config = new CorsConfiguration(); CorsConfiguration config = new CorsConfiguration();
config.addAllowedHeader("x-fhir-starter"); config.addAllowedHeader("x-fhir-starter");
config.addAllowedHeader("Origin"); config.addAllowedHeader("Origin");
@@ -202,7 +213,7 @@ public class JpaRestfulServer extends RestfulServer {
subscriptionInterceptorLoader.registerInterceptors(); subscriptionInterceptorLoader.registerInterceptors();
// Subscription debug logging // Subscription debug logging
InterceptorService interceptorService = (InterceptorService) appCtx.getBean("interceptorService"); IInterceptorService interceptorService = appCtx.getBean(IInterceptorService.class);
interceptorService.registerInterceptor(new SubscriptionDebugLogInterceptor()); interceptorService.registerInterceptor(new SubscriptionDebugLogInterceptor());
} }