Announcement

Collapse

Mirth Connect 4.0.1 Released!

Mirth Connect 4.0.1 is now available as an appliance update and on our GitHub page. Mirth Connect 4.0.1 is a patch release containing a bug fix which includes fixing a Jetty keystore regression that caused Connect servers using a PKCS12 keystore containing a wildcard certificate and/or a certificate with a SAN to throw an exception on startup. See the release notes for the list of fixes and updates.

Download | See What's New | Upgrade Guide | Release Notes

For discussion on this release, see this thread.
See more
See less

Help identifying if repeating segment exists, to copy field value

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

  • Help identifying if repeating segment exists, to copy field value

    We are receiving PID segments which may have either no PID-13 field at all, a single PID-13 field, or repeating PID-13 fields.

    I need to capture any available PID-13.4 containing an email address, and copy it to PID-26. So far I've been able to make it work *except* when there is no PID-13 field data available at all.

    The code below works to copy PID-13.4 (matching on the "@" character to signify email) into PID-26, and also correctly does nothing when no "@" character is found. However, it errors out when there is no PID-13 value at all.

    How can I update this to only work when it finds something in PID-13?





    Code:
    (i=0; i < msg['PID']['PID.13'].length() > 0;
    if
    msg['PID']['PID.13'][i]['PID.13.4'].indexOf('@') > 0)
    {
    (msg['PID']['PID.26']['PID.26.1'] = msg['PID']['PID.13'][i]['PID.13.4'].toString());
    }



    I did try expanding the IF statement to (msg['PID'][i]['PID.13'].length > 0) && msg['PID']['PID.13'][i]['PID.13.4'].indexOf('@') > 0), expecting it would look to see if the PID-13 contained any value, but it didn't and also removed the copy function that was working before the change. Basically, it does nothing.



    Code:
    (i=0; i < msg['PID']['PID.13'].length() > 0;
    if
    (msg['PID']['PID.13'].length > 0 && msg['PID']['PID.13'][i]['PID.13.4'].indexOf('@') > 0)
    
    {
    (msg['PID']['PID.26']['PID.26.1'] = msg['PID']['PID.13'][i]['PID.13.4'].toString());
    }
    Last edited by Ozz; 05-06-2022, 08:26 AM.

  • #2
    I got a little further with some slight changes. I now have the transformer working for all situations (no PID-13, PID-13 without email, PID-13 with email), but it's placing the email when found...only the email is being placed into PID-26.5 instead of PID-26.1 where I'm specifying. Why? Since I only want that subcomponent, I can't use toString() because it'll pull the XML, so what is my way around that while also getting it into the correct field?



    Code:
    (i=0; i < msg['PID'][i]['PID.13'].length() > 1; //loop through each available pid-13
    i++
    where
    (msg['PID'][i]['PID.13'].length() > 1 && msg['PID'][i]['PID.13']['PID.13.4'].indexOf('@') > 0)
    {msg['PID']['PID.26']['PID.26.1'] = msg['PID'][i]['PID.13']['PID.13.4'];
    }


    Raw:

    PID|||12345^^^EPI^EPI||LAST^FIRST^^^^^ D||19900101000000|F||CAU|100 MAIN ST^^SAN DIEGO^CA^96146^US^P^^||(619)555-5555^P^7^^^619^5555555~^NET^Internet^[email protected]||ENGLISH|SINGLE|||000-77-9999|||NON-HISPANIC||||||||N|


    Transformed, pulling the PID.13.4 field value with an email address into PID.26.5 instead of PID.26.1:

    PID|||12345^^^EPI^EPI||LAST^FIRST^^^^^ D||19900101000000|F||CAU|100 MAIN ST^^SAN DIEGO^CA^96146^US^P^^||(619)555-5555^^^^^619^5555555~~(619)555-555^^^^^619^5555555||ENGLISH|SINGLE|||000-77-9999|||NON-HISPANIC||||^^^^[email protected]^||||N|
    Last edited by Ozz; 05-06-2022, 09:34 AM.

    Comment


    • #3
      I think you want the renameField function (which is a copy). https://github.com/nextgenhealthcare...%20HL7%20Field

      I won't lie, though, I didn't read the entire thread. lol, ignore this response, see below.
      Last edited by pacmano; 05-06-2022, 12:10 PM.
      Diridium Technologies, Inc.
      https://diridium.com

      Comment


      • #4
        Originally posted by pacmano View Post
        I think you want the renameField function (which is a copy). https://github.com/nextgenhealthcare...%20HL7%20Field

        I won't lie, though, I didn't read the entire thread.
        I'll give that a shot, but I've used it before and can't see how it might apply here.

        Short & sweet, if it helps:

        I need to assume a message can contain either of these 3 options: PID-13 entirely blank, PID-13 repeating with email address present in 2nd repetition, PID-13 with 2nd repetition present but no email present.

        PID|1|||||||||||| (blank PID-13)|
        PID|1||||||||||||phone~^^^[email protected]|
        PID|1||||||||||||phone~^^^(noemailhere)|

        And if an email address is found, copy it to PID-26. My code above is copying to PID-26.5 which is as close as I can get so far. I know it's reading my capture wrong, but I haven't been able to figure out why, and it's throwing the result out into PID.26.5.

        Comment


        • #5
          PHP Code:

          try {
          msg['PID']['PID.26']['PID.26.1'] = msg['PID']['PID.13'][1]['PID.13.4'].toString().indexOf('@') != -msg['PID']['PID.13'][1]['PID.13.4'].toString() : ''
          } catch (e) {} 
          But not sure I understand the complete ask here. You may need to iterate as well.
          Last edited by pacmano; 05-06-2022, 12:11 PM.
          Diridium Technologies, Inc.
          https://diridium.com

          Comment


          • #6
            Originally posted by pacmano View Post
            PHP Code:

            try {
            msg['PID']['PID.26']['PID.26.1'] = msg['PID']['PID.13'][1]['PID.13.4'].toString().indexOf('@') != -msg['PID']['PID.13'][1]['PID.13.4'].toString() : ''
            } catch (e) {} 
            But not sure I understand the complete ask here. You may need to iterate as well.
            Wow, that did it as-is. I've only seen, but am not familiar with, try & catch functions. I'll have to read up on those to make sense of how this works. Thank you!


            I'm trying to not muddle my words, maybe this is more concise: look in PID-13 to find an email address and copy to PID-26. If no PID-13 is found, or no email address is found, do nothing.


            I first got stuck making it search in the 2nd iteration of PID-13, because it would error when no 2nd iteration was found. The only way I got to work around that, my "catch" was producing "^^^^[email protected]" instead of just "[email protected]"

            Comment

            Working...
            X