Hi Christian,
I am relying on the untyped message, however I have tested by casting the
message back to a typed message and I found the same result:
((ca.uhn.hl7v2.model.v231.message.ADT_A01)msg).insertNK1(2);
// ca.uhn.hl7v2.HL7Exception: Invalid index: 2, structure NK1 must be between 0
and 1
Suprisingly, inserting in order does make the problem disappear in the same way
as Terser.set, with the unexpected side effect of not clearing the data in the
initial NK segment.
((ca.uhn.hl7v2.model.v231.message.ADT_A01)msg).insertNK1(1);
((ca.uhn.hl7v2.model.v231.message.ADT_A01)msg).insertNK1(2);
// no runtime error
Many thanks for your help.
Andrew
From: Christian Ohr [mailto:christian....@gmail.com]
Sent: Friday, 1 November 2013 1:03 AM
To: Andrew Bowden
Cc: hl7api-devel@lists.sourceforge.net
Subject: Re: [HAPI-devel] Insert segment repetition
hi,
do you rely on working on an untyped message (i.e. AbstractMessage)? In this
case, adding a segment (repetition) can be ambiguous as it is not clear where
in the message the segment should actually be added. Messages of different
types and versions usually have a dedicated structure definition, which can
change even for the same message type in different versions.
My experience is that when you create or modify a message using the HAPI API,
you should work on typed messages (like
ca.uhn.hl7v2.model.v25.message.ADT_A01). And here the API provides you with
methods like insertNK1(int rep):NK1.
cheers
Christian
2013/10/31 Andrew Bowden
<andrew.bow...@rch.org.au<mailto:andrew.bow...@rch.org.au>>
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
------------------------------------------------------------------------------
Android is increasing in popularity, but the open development platform that
developers love is also attractive to malware creators. Download this white
paper to learn more about secure code signing practices that can help keep
Android apps secure.
http://pubads.g.doubleclick.net/gampad/clk?id=65839951&iu=/4140/ostg.clktrk
_______________________________________________
Hl7api-devel mailing list
Hl7api-devel@lists.sourceforge.net<mailto:Hl7api-devel@lists.sourceforge.net>
https://lists.sourceforge.net/lists/listinfo/hl7api-devel
------------------------------------------------------------------------------
Android is increasing in popularity, but the open development platform that
developers love is also attractive to malware creators. Download this white
paper to learn more about secure code signing practices that can help keep
Android apps secure.
http://pubads.g.doubleclick.net/gampad/clk?id=65839951&iu=/4140/ostg.clktrk
_______________________________________________
Hl7api-devel mailing list
Hl7api-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/hl7api-devel