Class HL7DataFormat

  • All Implemented Interfaces:
    AutoCloseable, org.apache.camel.Service, org.apache.camel.ShutdownableService, org.apache.camel.spi.DataFormat, org.apache.camel.spi.DataFormatName, org.apache.camel.StatefulService, org.apache.camel.SuspendableService

    @Dataformat("hl7")
    public class HL7DataFormat
    extends org.apache.camel.support.service.ServiceSupport
    implements org.apache.camel.spi.DataFormat, org.apache.camel.spi.DataFormatName
    HL7 DataFormat (supports v2.x of the HL7 protocol).

    This data format supports two operations:

    • marshal = from Message to String (can be used when returning as response using the HL7 MLLP codec)
    • unmarshal = from String to Message (can be used when receiving streamed data from the HL7 MLLP codec). This operation will also enrich the message by adding the MSH fields (MSH-3 to MSH-12) as headers on the message.

    Uses the HAPI (HL7 API) for HL7 parsing.

    Uses the default GenericParser from the HAPI API. This DataFormat only supports both the EDI based HL7 messages and the XML based messages.

    The unmarshal operation adds these MSH fields as headers on the Camel message (key, MSH-field):

    • CamelHL7SendingApplication = MSH-3
    • CamelHL7SendingFacility = MSH-4
    • CamelHL7ReceivingApplication = MSH-5
    • CamelHL7ReceivingFacility = MSH-6
    • CamelHL7Timestamp = MSH-7
    • CamelHL7Security = MSH-8
    • CamelHL7MessageType = MSH-9-1
    • CamelHL7TriggerEvent = MSH-9-2
    • CamelHL7MessageControl = MSH-10
    • CamelHL7ProcessingId = MSH-11
    • CamelHL7VersionId = MSH-12
    • CamelHL7Charset = MSH-18
    All headers are String types.

    See Also:
    HL7MLLPCodec
    • Field Summary

      • Fields inherited from class org.apache.camel.support.service.BaseService

        BUILT, FAILED, INITIALIZED, INITIALIZING, lock, NEW, SHUTDOWN, SHUTTING_DOWN, STARTED, STARTING, status, STOPPED, STOPPING, SUSPENDED, SUSPENDING
    • Constructor Summary

      Constructors 
      Constructor Description
      HL7DataFormat()  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      protected void doStart()  
      protected void doStop()  
      String getDataFormatName()  
      ca.uhn.hl7v2.HapiContext getHapiContext()  
      ca.uhn.hl7v2.parser.Parser getParser()  
      protected String guessCharsetName​(byte[] b, org.apache.camel.Exchange exchange)
      In HL7 the charset of the message can be set in MSH-18, but you need to decode the input stream in order to be able to read MSH-18.
      boolean isValidate()  
      void marshal​(org.apache.camel.Exchange exchange, Object body, OutputStream outputStream)  
      void setHapiContext​(ca.uhn.hl7v2.HapiContext context)  
      void setParser​(ca.uhn.hl7v2.parser.Parser parser)  
      void setValidate​(boolean validate)  
      Object unmarshal​(org.apache.camel.Exchange exchange, InputStream inputStream)  
      • Methods inherited from class org.apache.camel.support.service.BaseService

        build, doBuild, doFail, doInit, doLifecycleChange, doResume, doShutdown, doSuspend, fail, getStatus, init, isBuild, isInit, isNew, isRunAllowed, isShutdown, isStarted, isStarting, isStartingOrStarted, isStopped, isStopping, isStoppingOrStopped, isSuspended, isSuspending, isSuspendingOrSuspended, resume, shutdown, start, stop, suspend
      • Methods inherited from interface org.apache.camel.Service

        build, close, init, start, stop
      • Methods inherited from interface org.apache.camel.ShutdownableService

        shutdown
      • Methods inherited from interface org.apache.camel.StatefulService

        getStatus, isRunAllowed, isStarted, isStarting, isStopped, isStopping, isSuspending
      • Methods inherited from interface org.apache.camel.SuspendableService

        isSuspended, resume, suspend
    • Constructor Detail

      • HL7DataFormat

        public HL7DataFormat()
    • Method Detail

      • getDataFormatName

        public String getDataFormatName()
        Specified by:
        getDataFormatName in interface org.apache.camel.spi.DataFormatName
      • marshal

        public void marshal​(org.apache.camel.Exchange exchange,
                            Object body,
                            OutputStream outputStream)
                     throws Exception
        Specified by:
        marshal in interface org.apache.camel.spi.DataFormat
        Throws:
        Exception
      • unmarshal

        public Object unmarshal​(org.apache.camel.Exchange exchange,
                                InputStream inputStream)
                         throws Exception
        Specified by:
        unmarshal in interface org.apache.camel.spi.DataFormat
        Throws:
        Exception
      • isValidate

        public boolean isValidate()
      • setValidate

        public void setValidate​(boolean validate)
      • getHapiContext

        public ca.uhn.hl7v2.HapiContext getHapiContext()
      • setHapiContext

        public void setHapiContext​(ca.uhn.hl7v2.HapiContext context)
      • getParser

        public ca.uhn.hl7v2.parser.Parser getParser()
      • setParser

        public void setParser​(ca.uhn.hl7v2.parser.Parser parser)
      • doStart

        protected void doStart()
                        throws Exception
        Overrides:
        doStart in class org.apache.camel.support.service.BaseService
        Throws:
        Exception
      • doStop

        protected void doStop()
                       throws Exception
        Overrides:
        doStop in class org.apache.camel.support.service.BaseService
        Throws:
        Exception
      • guessCharsetName

        protected String guessCharsetName​(byte[] b,
                                          org.apache.camel.Exchange exchange)
        In HL7 the charset of the message can be set in MSH-18, but you need to decode the input stream in order to be able to read MSH-18. This works well for differentiating e.g. between ASCII, UTF-8 and ISI-8859 charsets, but not for multi-byte charsets like UTF-16, Big5 etc. This method is called to "guess" the initial encoding, and subclasses can overwrite it using 3rd party libraries like ICU4J that provide a CharsetDetector. The implementation in this class just assumes the charset defined in the exchange property or header by calling ExchangeHelper.getCharsetName(Exchange).
        Parameters:
        b - byte array
        exchange - the exchange
        Returns:
        charset name