Announcement

Collapse
No announcement yet.

Delete Leading WhiteSpace

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

  • Delete Leading WhiteSpace

    I am sometimes getting a leading whitespace in the PV1.3.2 segment that is causing some issues. Is it possible to delete that whitespace if it exists and to not do anything if it doesn't?
    Thanks

  • #2
    A single leading white space can be stripped with

    Code:
    strString = strString.replace(' ','');
    
    //all white spaces
    
    strString = strString.replace(' '\g,'');
    
    //or
    
    strString = strString.replace(\ \g,'');
    
    //may contain typos  (and just a caveat...for some reason string replace always gives //me problems
    I can be reached through gmail and Google Talk using davidrothbauer at gmail dot com
    http://www.linkedin.com/pub/david-rothbauer/5/923/518
    codeismydrug.wordpress.com
    hl7coders.wordpress.com

    Test all my code suggestions prior to implementation

    Comment


    • #3
      You would probably have to take care of the Whitespace within the Pre-Processing script section.

      You might be able to do something along these lines:

      Code:
      message = message.toString().replace(/\s+/g, ' ');
      or
      Code:
      message = new java.lang.String(message).trim();

      Comment


      • #4
        Thanks upstart, I was wondering if .trim would work in Mirth (I hadn't had a chance to try it).

        Wouldn't recommend this in the pre-processor though as the replacement has to be in the specific field. The pre-processor will strip all white spaces in the message. If you're passing any NTE segments or OBX.5's with narratives, that would really irritate your users.
        I can be reached through gmail and Google Talk using davidrothbauer at gmail dot com
        http://www.linkedin.com/pub/david-rothbauer/5/923/518
        codeismydrug.wordpress.com
        hl7coders.wordpress.com

        Test all my code suggestions prior to implementation

        Comment


        • #5
          Do I have to specify the segment PV1.3.2 or will this message = message.toString().replace(/\s+/g, ' '); just work for any whitespace?

          Comment


          • #6
            I must be doing something wrong because I am still getting the whitespaces. Should I apply those suggestions to a javascript transformer?

            Comment


            • #7
              Is the issue that the whitespace is breaking the message as you are receiving it, before you have a chance to do anything to it, or when you are trying to put the data into the database?

              Comment


              • #8
                Originally posted by lukekrouse View Post
                I must be doing something wrong because I am still getting the whitespaces. Should I apply those suggestions to a javascript transformer?
                Hi;
                Yes, add a transformer, double click on the right hand column (where is says Message Builder), then select javascript.

                If that doesn't work, post your code please
                Last edited by Bostad; 08-02-2011, 09:28 AM. Reason: oops, missed that last bit of the question...
                I can be reached through gmail and Google Talk using davidrothbauer at gmail dot com
                http://www.linkedin.com/pub/david-rothbauer/5/923/518
                codeismydrug.wordpress.com
                hl7coders.wordpress.com

                Test all my code suggestions prior to implementation

                Comment


                • #9
                  When I am trying to put the data in the database I am having some issues. I can process the data just fine, it is just that I do not want to store the data i.e room number with a space. Right now, I am getting PV1|1|I|2SN^ 302^01. What I need is PV1|1|I|2SN^302^01 <-- no space between ^ 302.

                  Comment


                  • #10
                    Originally posted by lukekrouse View Post
                    I must be doing something wrong because I am still getting the whitespaces. Should I apply those suggestions to a javascript transformer?
                    Originally posted by lukekrouse View Post
                    When I am trying to put the data in the database I am having some issues. I can process the data just fine, it is just that I do not want to store the data i.e room number with a space. Right now, I am getting PV1|1|I|2SN^ 302^01. What I need is PV1|1|I|2SN^302^01 <-- no space between ^ 302.

                    I just fired this into a channel I'm working on and tested with your values, it works.

                    Just create a javascript transformer and paste this in and viola...

                    Code:
                    msg['PV1']['PV1.3']['PV1.3.2'] = msg['PV1']['PV1.3']['PV1.3.2'].toString().replace(' ','');
                    I can be reached through gmail and Google Talk using davidrothbauer at gmail dot com
                    http://www.linkedin.com/pub/david-rothbauer/5/923/518
                    codeismydrug.wordpress.com
                    hl7coders.wordpress.com

                    Test all my code suggestions prior to implementation

                    Comment


                    • #11
                      Thank you Bostad that worked perfectly.

                      Comment


                      • #12
                        Always happy to help!
                        I can be reached through gmail and Google Talk using davidrothbauer at gmail dot com
                        http://www.linkedin.com/pub/david-rothbauer/5/923/518
                        codeismydrug.wordpress.com
                        hl7coders.wordpress.com

                        Test all my code suggestions prior to implementation

                        Comment

                        Working...
                        X