From: Andrew B. <And...@rc...> - 2013-10-31 04:52:50
|
Hi all, What is the best way to insert a new segment into an existing message. I need to add a repeating NK1 to transform an existing message for compliance, however whenever I try to insert a new NK1 segment using a terser, the code throws an exception. I can avoid this by setting the first NK1 again, however this doesn't feel like the best way to approach the problem. I would be interested in any thoughts as to the best way to approach the problem. <code> private AbstractMessage msg; public constructor(rawMsg){ msg = (AbstractMessage)parser.parse(rawMsg); Terser t = new Terser(msg); hapiTerser.set("/.NK1(2)-1-1", "2"); // throws HL7 Exception - ca.uhn.hl7v2.HL7Exception: Can't return repetition #2 of NK1 - there are currently only 1 repetitions so rep# must be between 0 and 1 } </code> I have found that if I: hapiTerser.set("/.NK1-1-1", "1");, the problem appears to go away, so I can either iterate over each item or deepcopy to get them across, however this feels like a hack to get this working. I appreciate you taking the time to look at this problem and welcome any suggestion. Andrew |