Skip to content

Proposed Subscription Design Change

Ken Stevens edited this page Dec 8, 2018 · 5 revisions

Background

In the fall of 2018, we have been modifying HAPI-FHIR Server Subscription functionality to add support for running subscription matching outside of the REST server in a separate process. This has happened in stages:

In-memory matcher added a new class SubscriptionMatcherInMemory that matches incoming resources against subscription criteria by examining the content within the resource directly as opposed to querying the database.

Standalone subscription added a new maven module called hapi-fhir-jpaserver-subscription and moved classes there from hapi-fhir-jpaserver-base so that the SubscriptionMatcherInMemory had everything it needed to match resources against subscription criteria without access to a database. Shared classes needed by both hapi-fhir-jpaserver-subscription and hapi-fhir-jpaserver-base were moved into two new maven modules called hapi-fhir-jpaserver-model and hapi-fhir-jpaserver-searchparam.

One final change remains in order to be able to process subscription outside of the REST server: maintaining an in-memory cache of active subscriptions.

Requirements

Four things need to happen when a new subscription arrives on the REST server:

  1. Validate the criteria on the subscription and reject it if the criteria are invalid.
  2. Activate the subscription (that is change the status of the subscription from REQUESTED to ACTIVE)
  3. Add the subscription to an in-memory cache of active subscriptions that future resources are matched against.
  4. Create a new Spring MessageChannel and MessageHandler. Matching resources will be sent to that channel and handled by the MessageHandler. The MessageHandler will perform the action specified in the subscription, e.g. e.g. send an e-mail, make a REST call, etc.

How it works today

Currently, all of four of these functions are managed within HAPI-FHIR Interceptors. Most of the functionality resides within the abstract class BaseSubscriptionInterceptor. There are subclasses of this for each type of subscription: SubscriptionRestHookInterceptor, SubscriptionEmailInterceptor etc... When the HAPI-FHIR JPA Server starts up, subscription processing functionality is added to it by enabling one or more of these interceptors.

Interceptor startup

When the interceptor starts up, it

Clone this wiki locally