web stats
Mirth Community - View Single Post - Creating a batch file with header and footer segments
View Single Post
  #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