No announcement yet.

Combine Two Z Segments Into One

  • Filter
  • Time
  • Show
Clear All
new posts

  • 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|60|O|IND||||||||1000||22|||Coinsurance Out of Network|EXCLUDES DEDUCTIBLE|||

    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.

  • #2
    I am no expert... but possibly something like this?

    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();
        } else {
           msg['ZP2'][i]['ZP2.14'] = z['ZP2.14'].toString();
           delete z;
    Last edited by glenn71; 09-04-2013, 10:27 PM.