On this page:

24.3Outbound HL7v2 Messaging: Transport

 

HL7 v2.x Messages can be transmitted using either MLLP or HL7 over HTTP transports.

24.3.1Customizing HL7 over HTTP Payload

 

The following example shows an interceptor that may be registered against the Subscription module that adds a custom header to outgoing HL7 over HTTP message payloads.

import ca.uhn.fhir.interceptor.api.Hook;
import ca.uhn.fhir.interceptor.api.Interceptor;
import ca.uhn.fhir.interceptor.api.Pointcut;
import ca.uhn.fhir.jpa.subscription.model.CanonicalSubscription;

/**
 * This interceptor customizes an outgoing HL7 v2.x Sending subscription in order to modify the
 * outgoing HTTP request by adding a custom header.
 *
 * Note that this mechanism does not work for HL7 over MLLP, as that transport mechanism
 * has no concept of a Header.
 *
 * This interceptor should be registered against the Subscription module (not the FHIR Storage
 * or HL7 v2.x Sending module).
 */
@Interceptor
public class Hl7v2SendingAddHeaderToHl7OverHttpInterceptor {

   @Hook(Pointcut.SUBSCRIPTION_BEFORE_DELIVERY)
   public void beforeDelivery(CanonicalSubscription theSubscription) {

      /*
       * If you want this interceptor to only apply to a specific subscription, you
       * can filter here. In this case we're only adding this header to deliveries for
       * the subscription with ID: Subscription/hl7v2-sender
       */
      if (!"hl7v2-sender".equals(theSubscription.getIdPart())) {
         return;
      }

      theSubscription.addHeader("User-Agent: Foo");
   }

}