No announcement yet.

Resending Raw Message from MirthDB

  • Filter
  • Time
  • Show
Clear All
new posts

  • Resending Raw Message from MirthDB

    Good morning,
    I suspect this is something silly but I've gone around and around on it so hoping someone can give me a hand.

    I am creating a channel where we process a comma delimited text file that contains 3 items:
    • an original Mirth messageID
    • the raw HL7 message for that message ID retrieved from the d_mc table
    • JSON result from the original processing of that message.
    We need to parse out the HL7 message from this text file and send it through my channel to another trading partner in proper HL7 format. I cannot just send it from the channel that originally created the delimited file because we might require multiple sends of the same files and it might not be within the time we retain these messages in Mirth.

    I have used the attached channel and the delimited text below to try and do this. I retrieve the value held in the 2nd column of the comma delimited file and load it into a channel variable, rawMessage. Then I try to use the Serializer factory to convert it back to proper HL7 (msg = new XML(SerializerFactory.getSerializer('HL7V2').toXML ($('rawMessage')))

    I've gotten it to work to the point where I can get the HL7 to be populated by removing both the " and ' around the HL7 message but it is not recognizing the \r values embedded so everything winds up in one giant MSH segment.

    Someone have a minute to lend another pair of eyes? Thank you!

    Mirth version: 3.6.2
    Attached Files
    Last edited by peggy.collinscolorado; 07-06-2020, 07:56 AM.

  • #2
    I think you want something like this:

    var junk = msg['row']['column2'].toString().replace(/\\r/g,'\n').replace(/\\\\/g,'\\')
    $c('junk',junk) // so you can see what you set.
    msg = new XML(SerializerFactory.getSerializer('HL7V2').toXML ($('junk')));
    Also, your delimiters are singe quotes, not double quotes, change that on the datatypes button. Also I would normally expect "MSH|^~\&|" not with double slashes.
    Mirth 3.8.0 / PostgreSQL 11 / Ubuntu 18.04
    Diridium Technologies, Inc.


    • #3
      Like pacmano said, it appears you should change your quote character from the default double quote to a single quote in the delimited data type properties.

      It also looks like your hl7 message has been JSON.stringified. It would be useful to know the process for creating this file in the first place to verify that is what happened.

      You might want to try
      msg = new XML(SerializerFactory.getSerializer('HL7V2').toXML(JSON.parse($('rawMessage'))));
      That should take care of unescaping the \r sequences as well as the double backslash in MSH-2.


      • #4
        agermano's point is really important - find out exactly the process they are using to create you file(s) so you can reverse that process if possible. If it were me, I would ask them to write the entire file as JSON rather than the mishmash you have up there. Lastly, it's better to attach that message rather than post it inline - there are extra spaces in it from what I can tell.

        For example:

        ... "p ostal_code":"152...
        Mirth 3.8.0 / PostgreSQL 11 / Ubuntu 18.04
        Diridium Technologies, Inc.


        • #5
          Thanks for the hand! The single quote change + the JSON.parse addition did the trick. I'll do the attachment on the original post just to clean things up.


          • #6
            Do ask them how they are doing their transform on their side to make sure all use cases work with agermano or my method. The point being if they are manually escaping stuff, the solutions proposed here might not meet their exact method every time. Hopefully they are using a standard method (like @agermano's "un-escape"), unlike my "manual" un-escape/fix method above.

            Mirth 3.8.0 / PostgreSQL 11 / Ubuntu 18.04
            Diridium Technologies, Inc.