Filter using Regular expression under SMAT-View fr field location within segment

Clovertech Forums Cloverleaf Filter using Regular expression under SMAT-View fr field location within segment

  • Creator
    Topic
  • #116714
    Varun Sinha
    Participant

      Hi,

      I have successfully searched if hl7 messages contain email addresses (as *.com) in SMAT files via SMAT-View- Add Specified Messages To View- Add A Regular Expression Condition with this very simple regular expression (?s).*\.com.

      As I see the documentation for Cloverleaf 6.1, it shows only content search.
      Can we search based on HL7 field location within specific segment using SMAT-View?

      e.g. Using regular expression under SMAT-View to search for messages having PID-14 not blank?

      Can we do something like that?

       

      https://usspvlclovertch2.infor.com/forums/topic/smat-regular-expression-compound-search/

       

      Thanks & Regards,

      Varun

    Viewing 11 reply threads
    • Author
      Replies
      • #116725
        Charlie Bursell
        Participant

          It could be done but would make for a very complex regexp.  Maybe you could dump to a file and examine messages there?

        • #116726
          Varun Sinha
          Participant

            Thanks Charlie for the response!

            Since, it’s production environment data, I don’t have luxury to dump it at a location. I can just search using SMAT-View.

            Using regular expression under SMAT-View: I want to search for messages having PID-14 not blank?

            The following regex under SMAT-View doesn’t work

            \rPID(?:[^\|]*\|){5}(\|)

             

            Regards,

            Varun

          • #116734
            Charlie Bursell
            Participant

              I told you it would be hairy.  The problem with using repetition meta characters like:

              PID(\|.*?\|){14}

              Is the counts are way off since you consume the | with each repetition so you have to make a long and sometimes unwieldy regular expression

              The following regexp is true if field  5 is empty.  I’ll let you add additional up to 14.  Note the regexp will also not be true if less than x number of fields.

              {\rPID\|.*?\|.*?\|.*?\|.*?\|\s+\|}

              Good luck with it

            • #116739
              Charlie Bursell
              Participant

                Got to thinking about this and though field 14 being empty would not necessarily be filled with a space.  So maybe the regex should be more like:

                {\rPID\|.*?\|.*?\|.*?\|.*?\|(\s+|\|)}

                I sure wish I had a SMAT file to play around with.

              • #116760
                Varun Sinha
                Participant

                  Thanks Charlie for your response!

                   

                  But, I am getting following error while executing the below regex via SMAT-View- Add Specified Messages To View- Add A Regular Expression Condition

                  {\rPID\|.*?\|.*?\|.*?\|.*?\|\s+\|}

                  {\rPID\|.*?\|.*?\|.*?\|.*?\|\s+\|}

                   

                  Error: The regular expression you typed is not valid.

                   

                  Thanks & Regards,

                  Varun

                • #116783
                  Charlie Bursell
                  Participant

                    Let me do some more testing.  I don’t get an error but also do not get the desired results every time

                  • #116791
                    Charlie Bursell
                    Participant

                      This thing has been bugging the heck out of me.  Finally decided I was getting spoofed by combining greedy and non-greedy expressions – a no no.

                      So I figured it out.  I ran some records through the engine and saved in SMAT so I could test.  This works!

                       

                      \rPID\|([^|]*?\|){13}(\s+|\|)

                      This says look at the 14th field.  If empty or contains spaces it will match.  If less than 14 fields it will not match.

                       

                      Try it.  Let me know.

                    • #116859
                      Varun Sinha
                      Participant

                        Thanks a lot Charlie!

                        The above regex worked beautifully with desired result all the time. Thanks for your effort by looking into this issue.

                        Please let me know any best regex tutorial to crack these kind of scenarios within cloverleaf. How can we judge these regex against any cloverleaf versions for SMAT files and for SMATDB too?

                         

                        Thanks & Regards,

                        Varun

                         

                      • #116872
                        Charlie Bursell
                        Participant

                          There are several good regex tutorials on Youtube and the web.  Some are using other programming languages but the information, except in a few cases, is the same.

                          I usually test my regexps by using a simple Tcl script with a lot of echo statements.  In the case of this one I simply created a file with a couple of HL7 messages, some that would pass, some that would not.  Then a simple Tcl script to test the regex using these files.  After passing in Tcl I tried it with SMAT.

                          The regex machine used by SMAT is in Java, I think.  There may be some nuanced differences but only with the most advance cases.

                        • #117477
                          Varun Sinha
                          Participant

                            Thanks Charlie!

                            I am not very good at tcl script. Can you please share the tcl script, so that even I can test some regex.

                            Regards,

                            Varun

                          • #117506
                            Charlie Bursell
                            Participant

                              There is no real Tcl script.  I simply run an interactive Tcl from the command line and test there.  if you want more complex you could write a simple script.

                              For example:

                              set str “

                              Hello, world!

                              regexp — {<(.*?)>(.*?)<} $str full part1 part2

                              echo $full

                              Hello, world!<

                              echo $part1
                              > h1

                              echo $part2
                              > Hello, world!

                              If something specific or large I may read in str from a file.

                              As I said, there are may examples on the web and YouTube.  If another language the regexp is usually the same.  There are many Tcl examples as well  like:

                              https://wiki.tcl-lang.org/page/Regular+Expression+Examples

                               

                               

                            • #117509
                              Varun Sinha
                              Participant

                                Thanks a lot Charlie for your help. I’ll try these out.

                                Once again, appreciate your help and guidance.

                                Regards,

                                Varun

                                 

                            Viewing 11 reply threads
                            • You must be logged in to reply to this topic.