Batch header and footer in Ensemble File Operation

Primary tabs

FTP, HL7, Caché, Ensemble

Hello community,

I am receiving a HL7 message over TCP connection.

I have to set up  a process/operation to produce a daily file with this HL7 messages to be created in a directory using EnsLib.File.OutboundAdapter
and EnsLib.HL7.Operation.FileOperation. The file needs to have a header line added each time it is created and a footer .I did not find any standard class file under File Adapter which will create header/footer. 

Any suggestion will be greatly appreciated.


Jimmy Christian

  • 0
  • 0
  • 72
  • 1
  • 1


Are these standard HL7 batch headers and footers (BHS/BTS, FHS/FTS, etc) or something custom to your organization?

If they are one of the HL7 standards, have a look at these docs on HL7 batches:

One tricky part will be triggering when an old batch ends/new batch begins -- this will depend on your local requirements.

If they are custom, there are a few approaches you can consider:

  1. You could use the Record Mapper to define a record map class with header/footer and a single field record for the HL7 content. You would then use one of the  EnsLib.RecordMap.Operation.* classes instead of EnsLib.HL7.Operation.FileOperation: In particular, have a look at RolloverSchedule and/or RolloverLimit to control when a new batch file is created.
  2. If you're comfortable creating a custom class that extends EnsLib.HL7.Operation.FileOperation, you could override the outputDocument method. In your custom version of outputDocument you could check if the file already exists using ##class(%File).Exists(pathToFile) and if it doesn't you would write out the footer to the previous file and the header to the new file before calling the standard version of outputDocument using ##super.

Thank you Marc for the detailed information.

I earlier tried the approach using the Record Mapper but it did not seam feasible in this scenario. 

So i have done is 

Created a CUSTOM operation class which extends Ens.BusinessOperation, EnsLib.HL7.Operation.Standard

It uses the file adapter.

Then I overided the oninit and outputDocument method.

  1. The file adapter creates HL7 file as usual
  2. I created a new method which calls the override outputDocument method and passes the filename . Then I do a count of segments and create another file into which I copy all the necessary information and delete the file which was originaly created .
  3. Above method is called in oninit, so it is triggered on schedule whenever the operation starts. First I check if a file exists, if it does and is not the current file then I call this new method.