-
Good afternoon, I'm looking to have a transformer in Mirth remove a ZAD segment if ZAD.1 == 0 and the rest of the segments are blank. I can get this to work when there is only one FT1 segment, but we send out charges with multiple FT1 segments and the logic doesn't work when there are multiple. Sample Message Current iteration of transformer var count=0;
for each (segment in msg.children() ){
if(segment.name() == "ZAD"){
if ((msg['ZAD'][count]['ZAD.1']['ZAD.1.1'].toString() == "0")
&& (msg['ZAD'][count]['ZAD.2']['ZAD.2.1'].toString() == "")
&& (msg['ZAD'][count]['ZAD.3']['ZAD.3.1'].toString() == "")
&& (msg['ZAD'][count]['ZAD.4']['ZAD.4.1'].toString() == "")
&& (msg['ZAD'][count]['ZAD.5']['ZAD.5.1'].toString() == "")
&& (msg['ZAD'][count]['ZAD.6']['ZAD.6.1'].toString() == "")
&& (msg['ZAD'][count]['ZAD.7']['ZAD.7.1'].toString() == "")
&& (msg['ZAD'][count]['ZAD.8']['ZAD.8.1'].toString() == "")
&& (msg['ZAD'][count]['ZAD.9']['ZAD.9.1'].toString() == "")
&& (msg['ZAD'][count]['ZAD.10']['ZAD.10.1'].toString() == "")
&& (msg['ZAD'][count]['ZAD.11']['ZAD.11.1'].toString() == "")
&& (msg['ZAD'][count]['ZAD.12']['ZAD.12.1'].toString() == "")
&& (msg['ZAD'][count]['ZAD.13']['ZAD.13.1'].toString() == "")
&& (msg['ZAD'][count]['ZAD.14']['ZAD.14.1'].toString() == "")
&& (msg['ZAD'][count]['ZAD.15']['ZAD.15.1'].toString() == "")
&& (msg['ZAD'][count]['ZAD.16']['ZAD.16.1'].toString() == "")
&& (msg['ZAD'][count]['ZAD.17']['ZAD.17.1'].toString() == "")
&& (msg['ZAD'][count]['ZAD.18']['ZAD.18.1'].toString() == "")
&& (msg['ZAD'][count]['ZAD.19']['ZAD.19.1'].toString() == "")
&& (msg['ZAD'][count]['ZAD.20']['ZAD.20.1'].toString() == "")
&& (msg['ZAD'][count]['ZAD.21']['ZAD.21.1'].toString() == "")
&& (msg['ZAD'][count]['ZAD.22']['ZAD.22.1'].toString() == "")
&& (msg['ZAD'][count]['ZAD.23']['ZAD.23.1'].toString() == "")
&& (msg['ZAD'][count]['ZAD.24']['ZAD.24.1'].toString() == "")
&& (msg['ZAD'][count]['ZAD.25']['ZAD.25.1'].toString() == "")
&& (msg['ZAD'][count]['ZAD.26']['ZAD.26.1'].toString() == "")
&& (msg['ZAD'][count]['ZAD.27']['ZAD.27.1'].toString() == "")
&& (msg['ZAD'][count]['ZAD.28']['ZAD.28.1'].toString() == "")
&& (msg['ZAD'][count]['ZAD.29']['ZAD.29.1'].toString() == "")
&& (msg['ZAD'][count]['ZAD.30']['ZAD.30.1'].toString() == "")
&& (msg['ZAD'][count]['ZAD.31']['ZAD.31.1'].toString() == "")
&& (msg['ZAD'][count]['ZAD.32']['ZAD.32.1'].toString() == "")
&& (msg['ZAD'][count]['ZAD.33']['ZAD.33.1'].toString() == "")
&& (msg['ZAD'][count]['ZAD.34']['ZAD.34.1'].toString() == "")
&& (msg['ZAD'][count]['ZAD.35']['ZAD.35.1'].toString() == "")
&& (msg['ZAD'][count]['ZAD.36']['ZAD.36.1'].toString() == "")
&& (msg['ZAD'][count]['ZAD.37']['ZAD.37.1'].toString() == "")
&& (msg['ZAD'][count]['ZAD.38']['ZAD.38.1'].toString() == "")
&& (msg['ZAD'][count]['ZAD.39']['ZAD.39.1'].toString() == "")
&& (msg['ZAD'][count]['ZAD.40']['ZAD.40.1'].toString() == "")){
delete msg['ZAD'][count];
}
count++;
}
} I'm getting the following error when trying to transform the sample message above Transformer error Does anyone have any thoughts or suggestions? I'm new to Mirth and I feel like the solution is sitting right in front of my nose. Thanks, |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 12 replies
-
@dombarone please format your code and use code blocks. Read https://docs.github.com/en/get-started/writing-on-github/getting-started-with-writing-and-formatting-on-github/basic-writing-and-formatting-syntax |
Beta Was this translation helpful? Give feedback.
-
Import @tonygermano xfilter code template from: https://github.com/nextgenhealthcare/connect-examples/tree/master/Code%20Templates/Filter%20XMLLists and make sure in channel dependencies it is avaiable to your channel. Then: function keepZadSegment(zadSegment) {
// Check fields after ZAD|0|
for (var i = 2; i < zadSegment.children().length(); i++) {
if (zadSegment['ZAD.' + i].toString().trim() !== '') {
return true; // Keep this segment as it has non-empty fields
}
}
return false; // Remove this segment as all fields are empty
}
var filteredZads = xFilter(msg.ZAD, keepZadSegment, 0, Number.MAX_VALUE, false);
// Assign the filtered ZAD segments back to msg.ZAD
msg.ZAD = filteredZads; Before:
After
|
Beta Was this translation helpful? Give feedback.
you might need:
var modifiedMessageString = hl7MessageString.replace(/^ZAD\|0(\|*)+\r?$/gm, '').replace(/\r\r/gm, '\r')
I probably was pasting new lines for line ends, they should be carriage returns as per spec.