How to repeat failed ACK without hanging a channel

This is not a trick, but expansion of example from page Custom ACK Example combined with example from page Raising and Catching Errors, spiced with ‘retry’ module applied ‘as is’.

Note: This is the same example Retrying a Custom ACK, but with a some extra explanatory comments added to the code. The code is also in our repository.


-- main() is given the original HL7 message.
function main(Data)

   local Msg = hl7.parse{vmd='ack.vmd', data=Data}
   local Ack = hl7.message{vmd='ack.vmd', name='Ack'}

   Ack.MSH[3][1] = Msg.MSH[5][1]
   Ack.MSH[4][1] = Msg.MSH[6][1]
   Ack.MSH[5][1] = Msg.MSH[3][1]
   Ack.MSH[6][1] = Msg.MSH[4][1]
   Ack.MSH[10] = Msg.MSH[10]
   Ack.MSH[9][1] = 'ACK'
   Ack.MSH[11][1] = 'P'
   Ack.MSH[12][1] = '2.6.1'
   Ack.MSH[7][1] ='%Y%m%d%H%M%S')

   Ack.MSA[1] = 'AA'
   Ack.MSA[2] = Msg.MSH[10]
   Ack.MSA[3] = "Everything was okay dokay!"

   local s = Ack:S()

   local Success, Err = pcall(,
         { func = ack.send, arg1 = s, retry = 10, pause = 2} )

   if not Success then
      print("Skipping error: "..Err) 


It has been several times that people asked how to combine these all together, so maybe this page will save few emails 🙂

Leave A Comment?

This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.