web stats
Adding Header into CSV file - Mirth Community

Go Back   Mirth Community > Mirth Connect > Support

Reply
 
Thread Tools Display Modes
  #1  
Old 10-10-2018, 12:47 PM
luis.lay luis.lay is offline
What's HL7?
 
Join Date: Apr 2012
Posts: 5
luis.lay is on a distinguished road
Default Adding Header into CSV file

Hello,

I have a channel in v3.6.1 that creates a CSV file from database reader query. I need the CSV to show the query headers. If I add it the template destination (file writer), it adds the header per row. Is there a way to just add it once?
Reply With Quote
  #2  
Old 10-10-2018, 08:47 PM
siddharth siddharth is offline
Mirth Guru
 
Join Date: Feb 2013
Posts: 832
siddharth is on a distinguished road
Default

There is. It is inside the data type properties on the inbound/outbound message templates.
__________________
HL7v2.7 Certified Control Specialist!
Reply With Quote
  #3  
Old 10-12-2018, 08:30 AM
agermano agermano is offline
Mirth Guru
 
Join Date: Apr 2017
Location: Indiana, USA
Posts: 664
agermano is on a distinguished road
Default

It's easy if you are using mirth 3.5+ and your result set is small enough that you can aggregate results. It's a little more difficult if you are processing one row at a time and appending to the file. What kind of database are you querying from?
Reply With Quote
  #4  
Old 10-29-2018, 08:33 AM
luis.lay luis.lay is offline
What's HL7?
 
Join Date: Apr 2012
Posts: 5
luis.lay is on a distinguished road
Default

Hi,
I am querying from Oracle. I am using Mirth 3.5. What would be the best way to do it?
Thanks!
Reply With Quote
  #5  
Old 10-29-2018, 05:50 PM
agermano agermano is offline
Mirth Guru
 
Join Date: Apr 2017
Location: Indiana, USA
Posts: 664
agermano is on a distinguished road
Default

If you are doing aggregate results, that means your entire query will produce a single message.

See this thread for how to quickly convert database reader input to delimited text output in a transformer: https://www.mirthcorp.com/community/...d.php?t=217724

Your csv headers are just another row of data to the serializer. After the results are converted in the previous step (or you manually construct tmp) you can insert a new row at the beginning of your outbound variable that contains your headers (which can be grabbed from msg children.)

You can do the same thing if you aren't using aggregate results, but then you must be able to know which row of the result set you are on, so that you only insert the headers before the first row.

I recently opened a request to make that information available in the sourceMap as it is for File Readers. You can vote for it if you think it would be beneficial to you: http://www.mirthcorp.com/community/i...wse/MIRTH-4334

In oracle, you can add ROW_NUMBER() as a column in your query so that you can check if you are on the first row of the results. https://docs.oracle.com/cd/B19306_01...nctions137.htm
Reply With Quote
Reply

Tags
csv headers

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 09:16 PM.


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