web stats
Cannot read property "column1" from undefined - Mirth Community

Go Back   Mirth Community > Mirth Connect > Support

Reply
 
Thread Tools Display Modes
  #1  
Old 11-07-2018, 12:00 PM
bsawant bsawant is offline
What's HL7?
 
Join Date: Aug 2018
Posts: 2
bsawant is on a distinguished road
Default Cannot read property "column1" from undefined

Hi,

I am trying to read from a flat file (with 000, 001, 002 segments) and write to a flat file. I am getting this error:

LINE NUMBER: 278
DETAILS: TypeError: Cannot read property "column1" from undefined


Here is the code:
var msg = new XML(channelMap.get( 'incomingmsg' ).toString());

for (var i = 0, j = 0; i < getArrayOrXmlLength(msg['row']); i++) {
if (msg['row'][i]['column1'].toString() == '000') {
for (var k = i+1; msg['row'][k]['column1'].toString() != '000'; k++) {
if (msg['row'][k]['column1'].toString() == '001'){
for (var l = k+1; msg['row'][l]['column1'].toString() != '000'; l++){
if ((msg['row'][l]['column1'].toString() == '002') && (msg['row'][l]['column4'].toString() == msg['row'][k]['column4'].toString())){
createSegment('row', tmp, j);
tmp['row'][j]['column1'] = validate(msg['row'][i]['column4'].toString(), '', new Array());
tmp['row'][j]['column2'] = validate(msg['row'][k]['column2'].toString(), '', new Array());
tmp['row'][j]['column3'] = "ITEM";
j++;
}
else {
}
}
}
else {
}
}
}
else {
j--;
}
i=l-1;
}

New to Mirth, any help will be appreciated. Using Mirth 3.6.1


Regards,

Bhakti
Attached Files
File Type: xml Test2 Channel.xml (41.2 KB, 1 views)
Reply With Quote
  #2  
Old 11-07-2018, 03:36 PM
agermano agermano is offline
Mirth Guru
 
Join Date: Apr 2017
Location: Indiana, USA
Posts: 530
agermano is on a distinguished road
Default

Mind explaining in english what you are trying to do? Those loops are not easy to follow. A sample input/output file would be nice, too.

The error you are getting is likely when you have selected the index of a row from msg that doesn't exist, and then are trying to access the column1 child element of that row.
Reply With Quote
  #3  
Old 11-08-2018, 07:27 AM
bsawant bsawant is offline
What's HL7?
 
Join Date: Aug 2018
Posts: 2
bsawant is on a distinguished road
Default

There are three rows in the input file and I am trying to combine all the information in a single row for output file. In detail - input file has (header row - 000, line row-001 & distribution row-002). And for one header row there can be multiple lines and for a line there can be multiple distributions.
Output row needs to be (header1 -line1 - distribution1) in one row.
For example the second output row will be (header1 -line2 - distribution1)
Attached Files
File Type: txt input.txt (433 Bytes, 1 views)
File Type: txt Output2.txt (293 Bytes, 1 views)
Reply With Quote
  #4  
Old 11-08-2018, 10:50 PM
agermano agermano is offline
Mirth Guru
 
Join Date: Apr 2017
Location: Indiana, USA
Posts: 530
agermano is on a distinguished road
Default

I still am not sure that I understand. Your output appears to be for a different input, and you don't have an example for when there are multiple lines or distributions for the same header.

I'm going to take a guess and say that each 000 segment may be followed by 1 or more 001 segments, and each 001 segment may be followed by more than 1 002 segment. You want to concatenate the rows from each combination of 000-001-002 into a single row, which should result in the same number of output rows as 002 segments in the input. You also want to remove the first column holding the segment name from each input row before copying to the output row.

For example:
Code:
Input:
000,a,1,
001,b,1-1,,
002,c,1-1-1,,,
002,d,1-1-2,,,
000,e,2,
001,f,2-1,,
002,g,2-1-1,,,
001,h,2-2,,
002,i,2-2-1,,,


Output:
a,1,,b,1-1,,,c,1-1-1,,,
a,1,,b,1-1,,,d,1-1-2,,,
e,2,,f,2-1,,,g,2-1-1,,,
e,2,,h,2-2,,,i,2-2-1,,,
This code will produce the above output for the given above input:

Code:
var current_header, current_line, current_dist, newRow;
var results = <delimited/>;

for each (var row in msg.children()) {
    var segName = row.child(0).toString();
    delete row.child(0)[0];
    switch (segName) {
        case "000":
            current_header = row;
            break;
        case "001":
            current_line = row;
            break;
        case "002":
            current_dist = row;
            newRow = current_header.copy();
            newRow.appendChild(current_line.children());
            newRow.appendChild(current_dist.children());
            results.appendChild(newRow);
    }
}

msg = results;

Last edited by agermano; 11-09-2018 at 09:50 AM. Reason: cleaned it up a little
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -8. The time now is 08:27 PM.


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