Contents
Confusion often arises about which API calls are available (and which are not), within the Acknowledgment Translator (LLP) and Filter Translator components. In summary, queue.push()
is not available in an Acknowledgment Translator (LLP) component and ack.send()
is not available in a Filter.
Common mistakes are:
- Trying to call
queue.push{data=Message}
from an Acknowledgment Translator (LLP) component
Note: This is not possible in an Acknowledgment Translator (LLP) component because the message is automatically passed to the Filter component. - Trying to send acknowledgments from a Filter Translator component
Note: This is not possible in a Filter component, you can only send ACKs in the Acknowledgment Translator (LLP) component.
If you need to follow a logic flow something like this:
- If message is good ACK it and enqueue.
- Else if message is bad send a NACK and do not queue the message.
Then you can use this solution:
- Make a shared lua module that is invoked from two Translator components.
- Have a clean function defined in that module that:
- Takes a message and returns true/false if the message is accepted/rejected
- Gives a reason why the message is rejected
Note: This function only tests the validity of the message, it cannot have any side-effects (i.e., it cannot change any data).
- The ACKnowledgment script can then use that function to determine when to make a NACK and what to put into it.
- The Filter script can use the function to determine whether or not to enqueue the message.
In pseudo code, the shared module might look something like this:
-- Source code of myfilter shared module function IsGoodMessage(Msg) -- Do logic if Bad then return false, Reason else return true end end
And the Translator instance used for the Acknowledgment could look like this:
require('myfilter') -- main() is given the original HL7 message. function main(Data) local Msg = hl7.parse{vmd='demo.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] = os.date('%Y%M%d%h%m%S') Ack.MSA[2] = Msg.MSH[10] local Good, Reason = IsGoodMessage(Msg) if Good then Ack.MSA[1] = 'AA' Ack.MSA[3] = "Everything was okay dokay!" else Ack.MSA[1] = 'AR' Ack.MSA[3] = Reason end ack.send(Ack:S()) end
And the Filter Translator code would look like this:
require('myfilter') function main(Data) if IsGoodMessage(Data) then queue.push{data=Data} end end
Back to: Introduction