Announcement

Collapse
No announcement yet.

Manipulating a field

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

  • Manipulating a field

    Working with DFT messages that could contain multiple FT1 segments. Trying to manipulate FT1-26 so that the modifier CS is the first modifier in the list (if it exist).

    Thus

    If we had the following
    FT1|1|||202102090015|202102110704|CH|27500331|EMER GENCY DEPT VISIT HIGH SEVERITY&THREA||1|||ED|||||F|||||||99285|25~CS~DA| |
    FT1|2|||202102090015|202102110704|CH|12500186|THER PROPH/DX NJX IV PUSH SINGLE/1ST SBS||1|||ED|||||F|||||||96374|59~DA||


    I would like the transformed message to look like this
    FT1|1|||202102090015|202102110704|CH|27500331|EMER GENCY DEPT VISIT HIGH SEVERITY&THREA||1|||ED|||||F|||||||99285|CS~25~DA| |
    FT1|2|||202102090015|202102110704|CH|12500186|THER PROPH/DX NJX IV PUSH SINGLE/1ST SBS||1|||ED|||||F|||||||96374|59~DA||


    I've tried a few different things but they did not work. Thanks for any light you can shed.

  • #2
    Please at least post your try.

    See https://forums.mirthproject.io/artic...orum-etiquette, note bullets 5,8,9,10.
    Last edited by pacmano; 04-07-2021, 03:22 PM.
    Diridium Technologies, Inc.
    https://diridium.com

    Comment


    • #3
      This problem is a little tricky.

      Code:
      for each (var ft1 in msg.FT1) {
          for each (var ft126 in ft1['FT1.26']) {
              if (ft126['FT1.26.1'].toString() == 'CS') {
                  // ft126 will still be a reference to the deleted node. The delete will
                  // only break the link between the child and parent to remove it from msg.
                  delete ft126[0];
                  // Put the deleted node back at the front of the list. 
                  ft1.insertChildBefore(ft1['FT1.26'][0], ft126);
                  // Neither of these lines interfere with the for each, which iterates
                  // over its own list of references to the nodes in their original order.
              }
          }
      }

      Comment


      • #4
        I thank you agermano, I tried and failed many different times trying to get this to work.

        Comment


        • #5
          Chrisp67 Not sure if it is possible or not, but I just realized that if CS is the only modifier, after it deletes it, it won't find another one when it goes to do the insert, and it will drop it completely. If that can happen, you'll need a different solution.

          Comment


          • #6
            Here is another way if you want to use the xFilter code template. This solution also handles the case where CS is the only modifier in the list.
            Code:
            function isCS(ft126) {return ft126['FT1.26.1'] == 'CS'}
            function isNotCS(ft126) {return !isCS(ft126)}
            for each (var ft1 in msg.FT1) {
                ft1['FT1.26'] = xFilter(ft1['FT1.26'], isCS) + xFilter(ft1['FT1.26'], isNotCS)
            }

            The xFilter code template is available at https://github.com/nextgenhealthcare...ter%20XMLLists

            Comment

            Working...
            X