web stats
CSV Channel to JSON - send to destination multiple times while reading file - Mirth Community

Go Back   Mirth Community > Mirth Connect > Support

Reply
 
Thread Tools Display Modes
  #1  
Old 03-19-2014, 07:37 PM
cherribuggy cherribuggy is offline
Mirth Newb
 
Join Date: Jul 2013
Location: Pittsburgh, PA
Posts: 8
cherribuggy is on a distinguished road
Default CSV Channel to JSON - send to destination multiple times while reading file

I have a channel set up in Mirth 3.0.1 to read a .csv file (posted here as a .txt file) and output using JSON for an API call. The .csv file contains multiple purchase orders with each purchase order containing an order for 1 or more items. I want to send to the destination each time the purchase order number (requisition ID in file) changes but can't seem to figure how to force this. The code is set up in the transformer 'Convert CSV to JSON' in JavaScript. Can anyone advise? Thank you!
Attached Files
File Type: xml Clinic Orders CSV to JSON POST - ORDERS.xml (28.6 KB, 38 views)
File Type: txt TestMirthTesting.txt (618 Bytes, 39 views)
Reply With Quote
  #2  
Old 03-20-2014, 06:01 AM
narupley's Avatar
narupley narupley is online now
Mirth Employee
 
Join Date: Oct 2010
Posts: 7,119
narupley is on a distinguished road
Default

There seem to be several issues with that channel. First, I think you're fundamentally misunderstanding how messages flow through channels, and how the connector map plays into that. If you iterate in a transformer and overwrite a key/value entry in the connector map, it does just that overwrites it. Messages aren't automagically dispatched just because a value in the connector map gets overwritten. Incidentally you don't need to include JSON; it's already included with Rhino.

Also if you want to dispatch different messages based on when a column changes, just use the Delimited Text batch adaptor. Once you've limited discrete messages by using batch processing, you don't need to do any of the weird "oldPO = newPO" stuff you were doing.

Code:
var jsonObject;
for each (row in msg.row) {
	var accountNum = row.Deliver_To.toString().slice(-6);

	if (!jsonObject) {
		jsonObject = {};
		jsonObject.PurchaseOrderNumber = row.Requisition_ID.toString();
		jsonObject.SourceId = 'SCC';
		jsonObject.AccountId = accountNum;
		jsonObject.LineItems = [];
	}

	lineItemObject = {};
	lineItemObject.AccountId = accountNum;
	lineItemObject.StockAreaName = accountNum;
	lineItemObject.ItemNumber = row.Manufacturer_Item_ID.toString().replace(/-/g,'');
	lineItemObject.ItemNumberType = 1;
	lineItemObject.ItemDescription = row.Item_Description.toString().trim();
	lineItemObject.Quantity = row.Quantity.toString();
	jsonObject.LineItems.push(lineItemObject);
}

$co('orders',JSON.stringify(jsonObject));
Attached Files
File Type: xml Clinic Orders CSV to JSON POST - ORDERS - v2.xml (19.4 KB, 78 views)
__________________
Step 1: JAVA CACHE...DID YOU CLEAR ...wait, ding dong the witch is dead?

Nicholas Rupley
Work: 949-237-6069
Always include what Mirth Connect version you're working with. Also include (if applicable) the code you're using and full stacktraces for errors (use CODE tags). Posting your entire channel is helpful as well; make sure to scrub any PHI/passwords first.


- How do I foo?
- You just bar.
Reply With Quote
Reply

Tags
csv, json

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:13 PM.


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