Announcement

Collapse
No announcement yet.

Encode to HL7 escape sequence

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Encode to HL7 escape sequence

    Hi,

    Is there any option on Mirth to encode/replace special characters to HL7 escape sequence when sending an HL7 message?

    I have a channel receiving a XML and transform data to send an HL7 message. This is an example of the OBR produced for the message:
    OBR||30381000|142018001804|10740^Braço, duas incidências||20180702163620|20180702163620|2018070 2163620|||||||||||

    How could I encode the special characters like 'ê' to send the OBR segment like this:
    OBR||30381000|142018001804|10740^Braço, duas incid\XEA\ncias||20180702163620|20180702163620|201 80702163620|||||||||||

  • #2
    The best place to replace them would be in preprocessor, like this fiddle

    https://jsfiddle.net/j7ph83vz/1/

    But these are acute accent, i noticed that you don't to encode ç, but just ê - Why is that?
    HL7v2.7 Certified Control Specialist!

    Comment


    • #3
      This was just an example. I want to replace all special characteres on HL7 message with the correspondent hexadecimal.
      In the example I've provided it should also encode the 'ç' character.

      From the resolution you gave, I must map all special characters and the correspondent hexa value?! This would be a very extensive list!! Isn't there a simpler way?

      Comment


      • #4
        What problems are you facing with the content, assuming that you don't encode them? Is the message erroring in Mirth?

        If that is the case, you might want to switch your encoding scheme on the reader to ISO-8859-1 or Windows-1252.

        per wiki pedia, ISO-8859-1 and Windows-1252 character encodings include the letters á, é, í, ó, ú, ý, and their respective capital forms. Dozens more letters with the acute accent are available in Unicode.
        HL7v2.7 Certified Control Specialist!

        Comment


        • #5
          I'm not getting any errors on Mirth. The problem is that we receive HL7 messages from sender that come with all special characteres encoded in hexa decimals.

          When we send other messages to the sender (client), they are expecting that this special characters also to be encoded.
          Last edited by fzenha; 07-10-2018, 06:25 AM.

          Comment


          • #6
            Hello fzenha,


            i have this 2 functions that i put in CodeTemplates and you can invoke both just by doing yourvariable.toString().hexDecode() / .hexEncode()
            In this case it will encode/decode all the string.
            With some twinks you could probably just encode/decode just the character you need.


            Code:
            String.prototype.hexEncode = function()
            {
                var hex, i;
            
                var result = "";
                for (i=0; i<this.length; i++) 
                {
                    hex = this.charCodeAt(i).toString(16);
                    result += ("000"+hex).slice(-4);
                }
            
                return result;
            }
            
            String.prototype.hexDecode = function()
            {
                var j;
                var hexes = this.match(/.{1,4}/g) || [];
                var back = "";
                for(j = 0; j<hexes.length; j++) 
                {
                    back += String.fromCharCode(parseInt(hexes[j], 16));
                }
            
                return back;
            }


            give it a try.
            Best Regards,
            Alex Neiva

            Comment


            • #7
              Thanks AlexNeiva. That did the trick.

              Comment

              Working...
              X