MIRTH-2353: Fixed bug that caused the ER7Serializer to incorrectly serialize/deserialize when the escape or subcomponent characters are omitted (which is legal according to the HL7 specifications).…
MIRTH-2353: Fixed bug that caused the ER7Serializer to incorrectly serialize/deserialize when the escape or subcomponent characters are omitted (which is legal according to the HL7 specifications).
On the serialization side, this is happening because ER7Reader assumes that the default values for the escape and subcomponent characters are "\" and "&" respectively. If one or both of the characters are omitted in the inbound message, then the serializer appends those characters anyway. This is wrong because the HL7 data could contain those literal characters (not meant as metadata delimiters). ER7Reader has been modified so that when MSH.2 is constructed, the component and repetition characters are always included but the escape and subcomponent characters are conditionally omitted. Also, a check is done in handleComponent to not handle subcomponents when the subcomponent delimiter is empty.
On the deserialization side, this is happening because XMLEncodedHL7Handler takes a subsequence of the current output (e.g. "MSH|^~\&" or "MSH|^~") from
length-4 to length. If all four delimiters are included then this works because the resulting subsequence is "^~\&". However if the latter two are omitted then the subsequence is "H|^~", which then causes the parser to regard "H" as the component delimiter, etc. XMLEncodedHL7Handler has been modified so that the subsequence always starts at index 4 and only includes the encoding characters and nothing before. This parser also deletes characters from the output to remove trailing delimiters. To prevent characters from being deleted when nothing was added in the first place (as would happen when the subcomponent character is omitted), the length of the last delimiter appended is kept track of, and a check is done to make sure something was added before it attempts to delete the trailing delimiter.