Sidebar

How do I remove one of the repeating fields in an FT1 segment?

0 votes
576 views
asked Oct 6, 2015 by amanda-w-3695 (4,840 points)

How do I remove a specific data element in the middle of a field that has repeating segments within the same field? Needing to remove the '9' right before the '~' in all FT1 segments and am wondering how to go about that.  Below is the de-identified message: 

MSH|^~\&|UroChart|AUAFL|MIK-AIG|AUAFL|20151001111631||DFT^P03|c6c0eabd-2e18-4cc3-b381-4f16e8ca84e2|P|2.3
EVN|P03|20151001111631||||||||||
PID|1|4065784|4065784||SxxxxxH^Dxxxxx^||19271018||||^222 Lolly EST DR^NEW SMYRNA BEACH^FL^32168||3245692059|||Unspecified||4065784||||
PV1|||||||RCY^Youth^Robbie^C^^M.D.|10842^Carter^Sally^^^M.D.|||||||||||A5053244||||||||||||||||||||||||
FT1|1||402|20151001100646|||99213|||1||||||AUANS|||N95.2^^9~N39.0^^9~N35.9^^9~N81.11^^9|RCY^Youth^Robbie|^Youth^Robbie||||||||||||
ZFT|||^^^^^^||||AUANS
FT1|2||402|20151001100646|||53661|||1||||||AUANS|||N95.2^^9~N39.0^^9~N35.9^^9~N81.11^^9|RCY^Youth^Robbie|^Youth^Robbie||||||||||||
ZFT|||^^^^^^||||AUANS
FT1|3||402|20151001100646|||81003QW|||1||||||AUANS|||N95.2^^9~N39.0^^9~N35.9^^9~N81.11^^9|RCY^Youth^Robbie|^Youth^Robbie||||||||||||
ZFT|||^^^^^^||||AUANS
 
I have an FT1 segment that looks like this:
FT1|1||402|20151001100646|||99213|||1||||||AUANS|||N95.2^^9~N39.0^^9~N35.9^^9~N81.11^^9|RCY^Youth^Robbie|^Youth^Robbie||||||||||||
 
I want it to look like this:
FT1|1||402|20151001100646|||99213|||1||||||AUANS|||N95.2^^~N39.0^^~N35.9^^~N81.11^^|RCY^Youth^Robbie|^Youth^Robbie||||||||||||

1 Answer

+1 vote
 
Best answer

First, let's break down the message into manageable parts. Then we can use a series of loops to access each element we need to change.

There are three FT1 segments, so we will need to do the same for each FT1.

Each of these segments have an FT1-19 field. (Fields are separated by the '|' symbol). This is one of those fields:

N95.2^^9~N39.0^^9~N35.9^^9~N81.11^^9

Within an FT1-19 field, there are four values.  They are separated by a '~' symbol. Here are the four values:

N95.2^^9

N39.0^^9

N35.9^^9

N81.11^^9

Almost there... Each of these field values have three subfields. (Subfields are separated by '^' symbol).  Subfield 3 is the value we want to remove (the "9" at the end of each field value).

At this point, we can build the node path we need. Where "x" defines which FT1 segment (1, 2, or 3, since there are three FT1 segments), and "y" defines which FT1-19 value to use (1, 2, 3, or 4, since there are four FT1-19 values).

FT1[x]-19[y].3

We need to loop through each FT1, and then loop through each value in FT1-19, and then update the third subfield.  Here is the code to do this.

//Get all the FT1 segments
var ft1Segments = source.getAllNodes('FT1');
 
//Loop through each FT1 Segment.
for (var x = 1; x <= ft1Segments.length ; x++) {
 
   //Looping through the mutiple values of FT1-19 (up to 20 times).
   for (var y = 1; y <= 20; y++) {
 
      // If the node exists, blank out the subfield 3, otherwise, "break" out of the loop.
      if (message.checkNodeExists("FT1[" + x + "]-19[" + y + "].3")) {
         message.setNode("FT1[" + x + "]-19[" + y + "].3", "");
      } else {
         break;
      }
   }
}

 

answered Oct 6, 2015 by amanda-w-3695 (4,840 points)
selected Oct 6, 2015 by mike-r-7535
...