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

How to remove duplicate repeating fields

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

  • How to remove duplicate repeating fields

    I want to keep only first instance of OBR.16 when OBR.16.1 length equals 10.
    There could be repeating fields where OBR.16.1 equals 10 and these OBR.16 fields should be deleted and other repeating OBR.16 fields should be deleted.

    This code works great when only 1 instance of OBR.16.1 length equals 10, but if repeating OBR.16.1 length equals 10, it does not delete.

    Code:
    for (var npi = msg['OBR']['OBR.16'].length() - 1; npi >= 0; npi--) {
    if (msg['OBR']['OBR.16'][npi]['OBR.16.1'].toString().length != 10)
    delete msg['OBR']['OBR.16'][npi];
    }
    Message will have only 1 OBR segment.

    Example
    Code:
    OBR|1|||||||||||||||1234567891^PHYLAST^PHYFIRST^^^^^^^^^^OTHER~16492578^PHYLAST^PHYFIRST^^~1234567891^PHYLAST^PHYFIRST^^^^^^|

    Expected
    Code:
    OBR|1|||||||||||||||1234567891^PHYLAST^PHYFIRST^^^^^^^^^^OTHER|
    Last edited by jg12345; 05-09-2022, 02:28 PM.

  • #2
    PHP Code:

    if (msg['OBR']['OBR.16'][0]['OBR.16.1'].toString().length == 10) {
      
    msg['OBR']['OBR.16'] = msg['OBR']['OBR.16'][0]


    Hmm - or you need to walk that OBR finding the first one where the length is 10? You can adapt that code of course, just find the first one and set it like I did there using your index in the brackets.
    Last edited by pacmano; 05-09-2022, 03:46 PM.
    Diridium Technologies, Inc.
    https://diridium.com

    Comment


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

      if (msg['OBR']['OBR.16'][0]['OBR.16.1'].toString().length == 10) {
      msg['OBR']['OBR.16'] = msg['OBR']['OBR.16'][0]


      Hmm - or you need to walk that OBR finding the first one where the length is 10? You can adapt that code of course, just find the first one and set it like I did there using your index in the brackets.
      Yea, the first instance length may not equal 10. Need to keep first one where length equals 10 and delete the rest. OBR.16 can also be empty.

      Example:

      Code:
      OBR|1|||||||||||||||123^PHYLAST^PHYFIRST^^OTHER~16492578^PHYLAST^PHYFIRST^^~9876543212^PHYLAST^PHYFIRST^^~1234567891^PHYLAST^PHYFIRST^^^|

      Expected
      Code:
      OBR|1|||||||||||||||9876543212^PHYLAST^PHYFIRST^^
      Last edited by jg12345; 05-10-2022, 04:49 AM.

      Comment


      • #4
        I already mentioned you can adapt the code I posted by adding the iteration to find the correct one to leave remaining.

        Using for each:


        PHP Code:

        for each (obr16 in msg['OBR']['OBR.16']) {
         if (
        obr16['OBR.16.1'].toString().length == 10) {
           
        msg['OBR']['OBR.16'] = obr16
           
        break;
         }

        Last edited by pacmano; 05-10-2022, 05:12 AM.
        Diridium Technologies, Inc.
        https://diridium.com

        Comment


        • #5
          Makes sense.. thanks!

          Comment

          Working...
          X