Search code examples
javahl7hapi

How can I use addForcedEncode to write all fields (even empty) of MSH and MSA messages


I need to respond to a system that requires messages with all fileds even id they are empty.

I think I have to use the Parser.Configuration.addForcedEncode but I don't know how to add the rules (path) to say "write all fields of the MSH and MSA messages".

Now when I send a response I have this:

MSH|^~\&|||Dazerolab|ViLMA Box|20160202110346||ACK^R01|4|P|2.3.1||||0||ASCII
MSA|AA|4|Message accepted|||0

and I would like obtain this:

MSH|^~\&|||Dazerolab|ViLMA Box|20160202110346||ACK^R01|4|P|2.3.1||||0||ASCII|||
MSA|AA|4|Message accepted|||0|

Can you help me?

Thank you


Solution

  • I solved this problem in this way

        mContext = new DefaultHapiContext();
        mContext.getParserConfiguration().addForcedEncode("MSH-21");
        mContext.getParserConfiguration().addForcedEncode("MSA-7");