· Jan 19, 2021

Handling carriage return in the HL7 router

We have msgs coming like below where line ending with \n then it throw error in router production but if msgs come with \r\n then router dont throw error.

any help?

EMR sending following msg.


Business Service read it like this as on line, and error msg shows in trace.



Build Map Status = 'ERROR <EnsEDI>ErrMapRequired: Missing required EVN element at segment 2'
'ERROR <EnsEDI>ErrMapRequired: Missing required PID element at segment 2'
'ERROR <EnsEDI>ErrMapRequired: Missing required PV1 element at segment 2'

Product version: HealthShare 2020.2
Discussion (2)1
Log in or sign up to continue

What class did you use for the inbound service?

I created a small batch of HL7 messages using nothing but newlines (newline is \n ... carriage return is actually \r). I consumed that file using a service based on EnsLib.HL7.Service.FileService and they were processed correctly.

If you used one of the HL7 service classes, what did you select for Framing?

Finally, is it possible that the messages you're testing with contain an actual backslash (\) character followed by the letter 'n' separating the segments? I've seen this happen before, believe it or not ...


The reason that you are getting these errors is that there is a mismatch between the following attributes of the Client and Server Adaptors. Jeffrey mentions Framing which is essentially how Ensemble detects the beginning and end of each HL7 message. Within the message itself though your message consists of 1 or more Segments. In order to determine the end of a segment Ensemble needs to know what terminator to expect which can be <LF> or <CR,LF>. In order to detect these characters Ensemble needs to know what character set the 3rd Party Adapter is using. So you need to confirm that the attributes CHARSET (Character Set) and ENCODING. The default values for these should be 'Latin-1' and 'UTF-8'. On the subject of Framing your choice is dependent of whether you are the HL7 TCP Inbound Adapter (in a Business Service) or you are the HL7 TCP Outbound Adapter. If you are the server then you have the choice of ensuring that your Framing matches the 3rd Party Client Framing. However you also have the choice of Flexible which essentially tells the Ensemble Adapter to interpret the characters being streamed to the Server and based on Pattern matching rules Ensemble can 'auto-detect' the framing. However when you are working with the Ensemble HL7 TCP Outbound Adapter you don't have the option of 'Flexible' and you either need to confirm that you and the 3rd Party are using compatible Framing formats and you can find out if they support Flexible then you can set the value for your  Client Adapter Framing to a value of your choice