Mirth Community

Mirth Community (http://www.mirthcorp.com/community/forums/index.php)
-   Support (http://www.mirthcorp.com/community/forums/forumdisplay.php?f=6)
-   -   Combine Two Z Segments Into One (http://www.mirthcorp.com/community/forums/showthread.php?t=9245)

nplaisted 09-03-2013 08:08 AM

Combine Two Z Segments Into One
 
We have an inbound HL7 feed that often contains multiple ZP2 segments in a single message. We have a problem with values that should be in the same segment being split into 2 segments. The vendor will only fix it on their side for a large fee, so we are trying to fix it within Mirth Connect, but are a little stumped how to go about it.

Here is an example of the ZP2 segments:

ZP2|1|P|30|O|FAM||||||||1000||22|||Coinsurance Out of Network|EXCLUDES DEDUCTIBLE|||
ZP2|1|P|30|O|FAM|||||||||2000||||||||
ZP2|1|P|60|O|IND||||||||1000||22|||Coinsurance Out of Network|EXCLUDES DEDUCTIBLE|||
ZP2|1|P|60|O|IND|||||||||2000||||||||

What I need to do with these ZP2 segments is this:
- If ZP2.1 through ZP2.5 are all the same in 2 diferent segments, Then move the value from ZP2.14 from the 2nd segment into the first segment, and then delete the 2nd ZP2 segment.

Note: there could be many more ZP2 segments with all different values. Some will have a match and need this transformation, some will not.

So for the example above, the outbound ZP2 segments should look like this:

ZP2|1|P|30|O|FAM||||||||1000|2000|22|||Coinsurance Out of Network|EXCLUDES DEDUCTIBLE|||
ZP2|1|P|60|O|IND||||||||1000|2000|22|||Coinsurance Out of Network|EXCLUDES DEDUCTIBLE|||

Ultimately what we are trying to do is call a stored procedure for each ZP2 segment, but when that ZP2.14 value is not in the same segment it does not work.

I hope all this makes sense. Any guidance getting started on this would be greatly appreciated.

glenn71 09-04-2013 10:08 PM

I am no expert... but possibly something like this?

Code:

var z1 = '';
var z2 = '';
var z3 = '';
var z4 = '';
var z5 = '';
var i = -1;

for each (z in msg.ZP2)
{
    if (z1 != z['ZP2.1'].toString() || z2 != z['ZP2.2'].toString() ||
        z3 != z['ZP2.3'].toString() || z4 != z['ZP2.4'].toString() ||
        z5 != z['ZP2.5'].toString() )
    {
        z1 = z['ZP2.1'].toString();
        z2 = z['ZP2.2'].toString();
        z3 = z['ZP2.3'].toString();
        z4 = z['ZP2.4'].toString();
        z5 = z['ZP2.5'].toString();
        i++;
    } else {
      msg['ZP2'][i]['ZP2.14'] = z['ZP2.14'].toString();
      delete z;
    }
   
}



All times are GMT -8. The time now is 06:12 AM.

Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2019, vBulletin Solutions, Inc.
Mirth Corporation