On this page:

9.0Interceptors

 

The HAPI FHIR Server Interceptor Framework is a mechanism for modifying the behavior of the server in a variety of ways.

As described in the documentation, special classes called Interceptors can be used to:

  • Pre-process or mask data that is being returned to the client as a result of a FHIR search, read, etc.
  • Add additional business checks before processing a write operation
  • Modify data that was submitted by a client prior to saving it

9.0.1HAPI FHIR and Smile CDR Pointcuts

 

In the interceptor framework, a Pointcut is a specific spot in the processing pipeline where custom logic can be added via an interceptor. The custom logic (i.e. code) itself is called a Hook. See the HAPI FHIR Interceptor Documentation for more information on the terminology used here.

Most HAPI FHIR interceptors are supported in the appropriate Smile CDR modules for the given Pointcut type. In addition to supporting HAPI FHIR interceptor Pointcuts, a set of Smile CDR specific pointcuts are available as well.

HAPI FHIR interceptors use the @Hook annotation and Pointcut enum. For example:

@Hook(Pointcut.SERVER_OUTGOING_WRITER_CREATED)
public Writer capture(RequestDetails theRequestDetails, Writer theWriter) {
   CountingWriter retVal = new CountingWriter(theWriter);
   theRequestDetails.getUserData().put(COUNTING_WRITER_KEY, retVal);
   return retVal;
}

Smile CDR interceptors use an equivalent pair of classes: The @CdrHook annotation and the CdrPointcut enum. For example:

@CdrHook(CdrPointcut.FHIRGW_SEARCH_TARGET_PREINVOKE)
public void preInvoke(SearchRequest theRequest) {
   theRequest.removeParameters("_id");
   theRequest.addParameter("_id", "101");
}

9.0.2Deploying Interceptors to Smile CDR Modules

 

The following table outlines the various module types, and the various types of Pointcuts that may be intercepted by an interceptor registered against that module.

Module Types Allowable Pointcuts
FHIR Endpoint
  • SERVER_xxx (HAPI FHIR)
  • STORAGE_xxx (HAPI FHIR)
  • JPA_PERFTRACE_xxx (HAPI FHIR)
Examples
Hybrid Providers
  • SERVER_xxx (HAPI FHIR)
Examples
FHIR Gateway
  • SERVER_xxx (HAPI FHIR)
  • FHIRGW_xxx (Smile CDR)
Examples
FHIR Storage
  • INTERCEPTOR_xxx (HAPI FHIR)
  • STORAGE_xxx (HAPI FHIR)
  • JPA_PERFTRACE_xxx (HAPI FHIR)
Examples
Subscription
  • SUBSCRIPTION_xxx (HAPI FHIR)

Registering An Interceptor

Interceptor classes should be packaged as a simple JAR file containing only the classes defined by the interceptor (i.e. library dependencies such as Spring or Commons-Lang should not be included in your JAR). The JAR file should be placed in the smilecdr/customerlib folder.

The interceptor class (or classes) that you have defined should then be set on the interceptor_bean_types property within the appropriate module configuration. Smile CDR must be restarted for changes to take effect.

For example, the following property sets a custom interceptor from within the configuration property file:

module.persistence.config.interceptor_bean_types=com.example.fhir.ExampleAttributeEnhancingInterceptor

Interceptor classes have access to any of the standard libraries available within Smile CDR. This includes Spring Framework, Apache HTTPClient, Gson, Jackson, Woodstox, and others.