web stats
Creating a batch file with header and footer segments - Mirth Community

Go Back   Mirth Community > Mirth Connect > Support

Reply
 
Thread Tools Display Modes
  #1  
Old 08-23-2019, 01:45 PM
johnpmetcalf johnpmetcalf is offline
What's HL7?
 
Join Date: Jan 2015
Posts: 2
johnpmetcalf is on a distinguished road
Default Creating a batch file with header and footer segments

I have searched the forums for help with creating a batch interface and it seems like none of the tips I have found has worked.

I am trying to create a batch file from a live ORU interface. I am able to get all the messages into a single text file but I am having trouble getting a single set of headers and footers attached. Currently I am using two channels to try and accomplish this with no luck

Channel 1. Performs all what I would call normal message transforms and writes to a single text file daily.

Channel 2 picks up the file and tries to append a header and a footer and it writes out to second file.

The problem I am having in channel 2 is it adds headers and footers for each message processed.

I am attaching the code I am using special thanks to user Chuck Citrano for getting me this far in a post from 2012.
Quote:
// Let's put the file and batch segments in
msg.prependChild(<BHS/>);
msg.prependChild(<FHS/>);
createSegment('BTS', msg);
createSegment('FTS', msg);

// We need to get a count of messages, so let's iterate through and count the 'MSH' segments
var MSH_Counter = 0;

for each (seg in msg..MSH) {
MSH_Counter++;
}

// Let's delete any ZPS segments that were stuffed into the file by the batch writer. This was used to convey the
// filename
//for(var i=0; i<msg['ZPS'].length();i++){
// delete msg['ZPS'][i];
//}

// Let's fill the new segments in with default values
// FHS Segment
msg['FHS']['FHS.1'] = '|';
msg['FHS']['FHS.2'] = '^~\\&';
msg['FHS']['FHS.3']['FHS.3.1'] = msg['MSH'][0]['MSH.3']['MSH.3.1'].toString();
msg['FHS']['FHS.3']['FHS.3.2'] = msg['MSH'][0]['MSH.3']['MSH.3.2'].toString();
msg['FHS']['FHS.4']['FHS.4.1'] = msg['MSH'][0]['MSH.4']['MSH.4.1'].toString();
msg['FHS']['FHS.4']['FHS.4.2'] = msg['MSH'][0]['MSH.4']['MSH.4.2'].toString();
msg['FHS']['FHS.4']['FHS.4.3'] = msg['MSH'][0]['MSH.4']['MSH.4.3'].toString();
msg['FHS']['FHS.5']['FHS.5.1'] = msg['MSH'][0]['MSH.5']['MSH.5.1'].toString();
msg['FHS']['FHS.6']['FHS.6.1'] = msg['MSH'][0]['MSH.6']['MSH.6.1'].toString();
msg['FHS']['FHS.6']['FHS.6.2'] = msg['MSH'][0]['MSH.6']['MSH.6.2'].toString();
msg['FHS']['FHS.7']['FHS.7.1'] = msg['MSH'][0]['MSH.7']['MSH.7.1'].toString();
msg['FHS']['FHS.9']['FHS.9.1'] = msg['MSH'][0]['MSH.9']['MSH.9.1'].toString();
msg['FHS']['FHS.9']['FHS.9.2'] = msg['MSH'][0]['MSH.9']['MSH.9.2'].toString();
msg['FHS']['FHS.9']['FHS.9.3'] = msg['MSH'][0]['MSH.9']['MSH.9.3'].toString();
msg['FHS']['FHS.10']['FHS.10.1'] = msg['MSH'][0]['MSH.10']['MSH.10.1'].toString();
msg['FHS']['FHS.11']['FHS.11.1'] = msg['MSH'][0]['MSH.11']['MSH.11.1'].toString();

// BHS Segment
msg['BHS']['BHS.1'] = '|';
msg['BHS']['BHS.2'] = '^~\\&';
msg['BHS']['BHS.3']['BHS.3.1'] = msg['MSH'][0]['MSH.3']['MSH.3.1'].toString();
msg['BHS']['BHS.3']['BHS.3.2'] = msg['MSH'][0]['MSH.3']['MSH.3.2'].toString();
msg['BHS']['BHS.4']['BHS.4.1'] = msg['MSH'][0]['MSH.4']['MSH.4.1'].toString();
msg['BHS']['BHS.4']['BHS.4.2'] = msg['MSH'][0]['MSH.4']['MSH.4.2'].toString();
msg['BHS']['BHS.4']['BHS.4.3'] = msg['MSH'][0]['MSH.4']['MSH.4.3'].toString();
msg['BHS']['BHS.5']['BHS.5.1'] = msg['MSH'][0]['MSH.5']['MSH.5.1'].toString();
msg['BHS']['BHS.6']['BHS.6.1'] = msg['MSH'][0]['MSH.6']['MSH.6.1'].toString();
msg['BHS']['BHS.6']['BHS.6.2'] = msg['MSH'][0]['MSH.6']['MSH.6.2'].toString();
msg['BHS']['BHS.7']['BHS.7.1'] = msg['MSH'][0]['MSH.7']['MSH.7.1'].toString();
msg['BHS']['BHS.9']['BHS.9.1'] = msg['MSH'][0]['MSH.9']['MSH.9.1'].toString();
msg['BHS']['BHS.9']['BHS.9.2'] = msg['MSH'][0]['MSH.9']['MSH.9.2'].toString();
msg['BHS']['BHS.9']['BHS.9.3'] = msg['MSH'][0]['MSH.9']['MSH.9.3'].toString();
msg['BHS']['BHS.11']['BHS.11.1'] = msg['MSH'][0]['MSH.11']['MSH.11.1'].toString();

// BTS Segment
msg['BTS']['BTS.1']['BTS.1.1'] = MSH_Counter;
msg['BTS']['BTS.2']['BTS.2.1'] = '';
msg['BTS']['BTS.3']['BTS.3.1'] = '';

// FTS Segment
msg['FTS']['FTS.1']['FTS.1.1'] = 1;
msg['FTS']['FTS.2']['FTS.2.1'] = 'Transfer to Complete';
msg['FTS']['FTS.3']['FTS.3.1'] = '';
Reply With Quote
  #2  
Old 08-26-2019, 09:49 AM
agermano agermano is offline
Mirth Guru
 
Join Date: Apr 2017
Location: Indiana, USA
Posts: 1,008
agermano is on a distinguished road
Default

Don't use Process Batch on your second channel. You want the entire file to be one message for your code to work. You might run into performance issues if the files are too large.

If you find they are taking too long to process, there are other ways to do it, but this is probably the easiest.

Also, you don't need to iterate over the MSH segments to count them. You can do:
Code:
var MSH_Counter = msg['MSH'].length();
Reply With Quote
  #3  
Old 08-26-2019, 10:17 AM
johnpmetcalf johnpmetcalf is offline
What's HL7?
 
Join Date: Jan 2015
Posts: 2
johnpmetcalf is on a distinguished road
Default

You rock!
I also kicking myself because I was one radio button away from solving this and I has spent hours trying to figure it out with code.
Reply With Quote
Reply

Tags
batched hl7, hl7

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 07:01 PM.


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