web stats
Mirth - Flat file to Text channel - Mirth Community

Go Back   Mirth Community > Mirth Connect > Support

Reply
 
Thread Tools Display Modes
  #1  
Old 02-06-2019, 04:52 AM
ahj610 ahj610 is offline
What's HL7?
 
Join Date: Feb 2019
Posts: 2
ahj610 is on a distinguished road
Default Mirth - Flat file to Text channel

Hello All,

I am trying to create a simple channel which will read a csv file and create a text message out for each row of file. I am using Mirth 3.5.1.
I checked on this community and tried with some sample channels but facing an error as below,

Either

DETAILS: TypeError: Cannot read property "row" from undefined

or

DETAILS: TypeError: Cannot call method "elements" of undefined

Attached my sample channel, Can anyone review the same and guide me what am I missing here.

Thanks in advance.
Attached Files
File Type: xml CSV to Text.xml (14.2 KB, 8 views)
Reply With Quote
  #2  
Old 02-06-2019, 09:40 AM
Brad_AZ Brad_AZ is offline
OBX.1 Kenobi
 
Join Date: Mar 2018
Location: Arizona, USA
Posts: 27
Brad_AZ is on a distinguished road
Default

Quote:
Originally Posted by ahj610 View Post
Hello All,
<snip>
DETAILS: TypeError: Cannot read property "row" from undefined

or

DETAILS: TypeError: Cannot call method "elements" of undefined
</snip>.
Your undefined message lead me to try assigning a value to msg and that seemed to work. But I struggled a little with the CSV syntax and came up with something that parses a CSV like this:

ApptStatus,ApptDate,Name
booked,01/01/2020,John Smith
cancelled,02/19/2019,Jane Brown

And outputs the following:

Hello John Smith, your next appointment for 01/01/2020 is booked
Hello Jane Brown, your next appointment for 02/19/2019 is cancelled

I set up the source to read the file as a batch and ignore the header. and I didn't do much with the destination other than log the data. (got my day job to do! )

Not sure if this is what you are looking for, but it may give you something that helps your needs. Attaching the channel, but it is in 3.7 so here's the destination side of things:

Code:
var msg = connectorMessage.getRawData();
logger.info('msg is '+ msg);

var arr = msg.split(",");


//logger.info(arr[0])
var status = (arr[0]);
//logger.info(arr[1])
var date = (arr[1]);
//logger.info(arr[2])
var name = (arr[2]);

var note = 'Hello ' + name + ', your next appointment for '+ date + ' is ' + status;
logger.info(note);
Usual disclaimers - use at your own risk. Thank you to this forum and my co-workers for Mirth support. Hope this helps.
Attached Files
File Type: xml CSV_to_text.xml (18.3 KB, 4 views)
__________________
SIG|1|Brad|Mirth Certified Interface Analyst^Cancer Treatment Centers of America

Last edited by Brad_AZ; 02-06-2019 at 10:26 AM.
Reply With Quote
  #3  
Old 02-06-2019, 09:48 PM
ahj610 ahj610 is offline
What's HL7?
 
Join Date: Feb 2019
Posts: 2
ahj610 is on a distinguished road
Default

Thanks Brad for your quick response.

I am able to define the message however while trying to access row as below, its giving the same error.

var msg = connectorMessage.getRawData();
logger.info('msg is '+ msg); // This is working

var appt_Status = msg['row'][0]['ApptStatus'].toString(); // This gives an error of
DETAILS: TypeError: Cannot read property "0" from undefined.

Even msg.elements('row').length() is also giving the same undefined error.

As you mentioned, Splitting by (,) will not work here because the field might contain (,) in between a record e.g. "Dr John Doe, MD" as this is a single data.

Thanks.
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 12:44 PM.


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