Announcement

Collapse
No announcement yet.

Creating an ascii/carriage return

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

  • Creating an ascii/carriage return

    Hello,
    I have incoming messages in Mirth version 2.2.1.5861 as a single line via:

    MSH|^~\&|Client||||20130114013602||ADT^A04|||2.2|\ r\nPID||0123456789|9876543210||Smith^Dave||1970010 1|M|||||||||||555-55-5555|

    I would like to utilize the preprocessor to change "\r\n" into what Mirth recognizes as an ascii/carriage return, but have had no luck with the following examples found here on the forums:

    return message.replace(/[\r\n]+(?![A-Z]{2}[A-Z\d]\|)/g,'\\X0D\\');
    return message.replace(/\r\n+(?![A-Z]{2}[A-Z\d]\|)/g,'\\X0D\\');

    At your convenience, let me know where my scripting is incorrect for this modification or if my method is not appropriate for this modification.

  • #2
    What exactly are you trying to do? If you're trying to convert ALL CRLFs and/or LFs in the message to CRs, you can do this:

    Code:
    return message.replace(/\r\n|\n/g,'\r');
    Step 1: JAVA CACHE...DID YOU CLEAR ...wait, ding dong the witch is dead?

    Nicholas Rupley
    Work: 949-237-6069
    Always include what Mirth Connect version you're working with. Also include (if applicable) the code you're using and full stacktraces for errors (use CODE tags). Posting your entire channel is helpful as well; make sure to scrub any PHI/passwords first.


    - How do I foo?
    - You just bar.

    Comment


    • #3
      I would like to preprocess the above message in Mirth into the generic HL7 form:

      MSH|^~\&|Client||||20130114013602||ADT^A04|||2.2|
      PID||0123456789|9876543210||Smith^Dave||1970010 1|M|||||||||||555-55-5555|

      This will allow me to call the PID components respectively opposed to Mirth treating them as MSH components.

      Name field example:

      Current method (undesired)
      tmp['PID']['PID.5']['PID.5.1'] = msg['MSH']['MSH.18']['MSH.18.1'].toString();
      tmp['PID']['PID.5']['PID.5.2'] = msg['MSH']['MSH.18']['MSH.18.2'].toString();
      tmp['PID']['PID.5']['PID.5.3'] = msg['MSH']['MSH.18']['MSH.18.3'].toString();

      Ideal method (if possible)
      tmp['PID']['PID.5']['PID.5.1'] = msg['PID']['PID.5']['PID.5.1'].toString();
      tmp['PID']['PID.5']['PID.5.2'] = msg['PID']['PID.5']['PID.5.2'].toString();
      tmp['PID']['PID.5']['PID.5.3'] = msg['PID']['PID.5']['PID.5.3'].toString();

      Thanks
      Last edited by eslingerc; 01-21-2013, 01:19 PM.

      Comment


      • #4
        I understand that you're trying to convert the message to valid HL7, but where are you expecting CRLFs to occur? If they are occurring only at the end of segments (i.e. they are sending CRLF as opposed to CR at the end of segments) then you can take my initial code suggestion, as that will replace all occurrences. If you're getting invalid CRs in the middle of a segment, that would be a case where you'd want to replace them with an escape sequence like \X0D\.
        Last edited by narupley; 01-18-2013, 11:19 AM.
        Step 1: JAVA CACHE...DID YOU CLEAR ...wait, ding dong the witch is dead?

        Nicholas Rupley
        Work: 949-237-6069
        Always include what Mirth Connect version you're working with. Also include (if applicable) the code you're using and full stacktraces for errors (use CODE tags). Posting your entire channel is helpful as well; make sure to scrub any PHI/passwords first.


        - How do I foo?
        - You just bar.

        Comment


        • #5
          Yes, I agree your above example sounds logical and should work if my understanding of the preprocessor script is correct: Applies to any source message whether first processing, reprocessing, or even sending a new message from within said channel in mirth.

          However, my settings must be wrong for the preprocessor to actually do anything or I need to head down a different path for other reasons and should therefore consider utilizing a different command such as:
          message = messageObject.getRawData();
          return message.replace(/\r\n|\n/g,'\r');

          Thanks again,

          Comment


          • #6
            Originally posted by eslingerc View Post
            Yes, I agree your above example sounds logical and should work if my understanding of the preprocessor script is correct: Applies to any source message whether first processing, reprocessing, or even sending a new message from within said channel in mirth.

            However, my settings must be wrong for the preprocessor to actually do anything or I need to head down a different path for other reasons and should therefore consider utilizing a different command such as:
            message = messageObject.getRawData();
            return message.replace(/\r\n|\n/g,'\r');

            Thanks again,
            That code won't work since "messageObject" isn't defined in the preprocessor. I guess I'm still confused as to what exactly you're asking or trying to accomplish. Did the initial code suggestion not work?
            Step 1: JAVA CACHE...DID YOU CLEAR ...wait, ding dong the witch is dead?

            Nicholas Rupley
            Work: 949-237-6069
            Always include what Mirth Connect version you're working with. Also include (if applicable) the code you're using and full stacktraces for errors (use CODE tags). Posting your entire channel is helpful as well; make sure to scrub any PHI/passwords first.


            - How do I foo?
            - You just bar.

            Comment


            • #7
              Update: Mirth is utilizing the preprocessor when sending a message from within mirth even though I have it set up as an LLP listener. In other words, the function: return message.replace(/\r\n|\n/g,'\r'); is actually being hit. However, Mirth still does not recognize the msg.PID variables via: (example) tmp['PID']['PID.2']['PID.2.1'] = msg['PID']['PID.2']['PID.2.1'].toString(); still returns nothing for this component.

              Other settings: Summary tab -> Data types -> source connector inbound & outbound -> properties -> check parse field repetitions, parse subcomponents, and strip namespaces.
              Destination connector -> properties -> checked strip namespaces and convert LF to CR. If I uncheck the convert LF to CR and then check parse field repetitions and parse subcomponents for the destination connector the entire channel disconnects from the client and cannot under any circumstance reconnect even after changing these settings. Any ideas are appreciated!

              Comment


              • #8
                Any message sent through a channel goes through the entire message life-cycle: Preprocessor, Source filter/transformer, Destination filters/transformers, Postprocessor. That's true whether a source connector automatically receives or grabs a message, or you manually send/reprocess a message in the message browser.

                Regarding the other issue, I'm not sure exactly what's happening so can you post the channel here?
                Step 1: JAVA CACHE...DID YOU CLEAR ...wait, ding dong the witch is dead?

                Nicholas Rupley
                Work: 949-237-6069
                Always include what Mirth Connect version you're working with. Also include (if applicable) the code you're using and full stacktraces for errors (use CODE tags). Posting your entire channel is helpful as well; make sure to scrub any PHI/passwords first.


                - How do I foo?
                - You just bar.

                Comment


                • #9
                  Thanks Nick
                  Attached Files

                  Comment


                  • #10
                    That works fine for me; any CRLFs or LFs are converted to CRs, and the message is serialized to XML correctly.

                    I think you're confusing yourself because you have this in your transformer's inbound template:

                    Code:
                    MSH|^~\&|TrueNorth||||20130114013602||ADT^A04|||2.2|\r\nPID||0123456789|9876543210||Smith^Dave||19791215|1|||||||||||555-55-5555|
                    The template represents a literal string and isn't in a JavaScript context yet. So "\r\n" is literally backslash-r-backslash-n. Just replace that with a carriage return and the Message Trees tab will populate as you expect. When you hit Enter in the template, I think the actual line break inserted is platform-dependent, and since you have "Convert LF to CR" turned off, the inbound template won't convert a LF or CRLF for you. So you'll either have to turn that option on (you might as well since you're doing the same thing in your preprocessor anyway), or you can import a template from a file that already has the correct line breaks.

                    In any case, realize that the inbound template is simply there for drag-and-drop convenience and holds no bearing upon the behaviour of your channel. The transformer's inbound template isn't used in actual processing, and obviously doesn't pass through the preprocessor, but any regularly incoming message does go through the preprocessor, and therefore will have all CRLFs/LFs converted to CRs as per the script you have set.
                    Step 1: JAVA CACHE...DID YOU CLEAR ...wait, ding dong the witch is dead?

                    Nicholas Rupley
                    Work: 949-237-6069
                    Always include what Mirth Connect version you're working with. Also include (if applicable) the code you're using and full stacktraces for errors (use CODE tags). Posting your entire channel is helpful as well; make sure to scrub any PHI/passwords first.


                    - How do I foo?
                    - You just bar.

                    Comment

                    Working...
                    X