Hi Jonathan,

A bit of background:

When a particular structure has more than one of the same segment in a row,
according to HL7, those are repetitions. An obvious example would be the
NTEs attached to an OBX.

On the other hand, when a structure has a segment of the same type but in
different locations within the structure, these are treated as distinct
segments. An obvious example of this would be the A24 "link patients"
structure, which exactly two PID segments, optionally separated by a few
related segments (PD1, PV1, etc).

Because in this case these segments have the same name (in this case PID)
but a different interpretation (in this case "Patient 1 Identification" and
"Patient 2 Identification") HAPI needs a unique name for each, so it
accomplishes this by appending a number to the end.

Now, when it comes to a GenericMessage, HAPI doesn't actually know the
"correct" structure for the message it is parsing, so it has to try and
infer it from the actual segments it finds. The logic it uses is to treat
multiple segments in a row as repetitions, but multiple segments separated
by other segments as unique segments. This behaviour also allows HAPI to be
able to encode the message back in the same order it received it.

My advice to you would probably be to call
String[] names = message.getNames();
And then iterate over that list. If you have a name start starts with "NTE",
you know it's an NTE, and you can infer which segment it belongs to using
the previous name.

Hope this helps!

James

On Fri, Oct 22, 2010 at 1:18 PM, Jonathan Bartels
<[email protected]>wrote:

>  I’m having a problem using a Terser on a GenericMessage with repeating
> NTE  segments.
>
>
>
> I whipped up a test case to show the issue. Why does the terser getter like
> “NTE2-3-1” work while “NTE(1)-3-1” fail? Is there any way to make the latter
> format work?
>
>
>
> @Test
>
> public void testNTEQuirk() {
>
>                 String hl7Message = null;
>
>                 try {
>
>                                 hl7Message =
> resourceUtil.getResourceAsString("nte_quirk.hl7");
>
>                 } catch (IOException e) {
>
>                                 fail("Could not load resource!");
>
>                 }
>
>
>
>                 GenericMessage message = new
> GenericMessage.UnknownVersion(new DefaultModelClassFactory());
>
>
>
>                 try {
>
>                                 message.parse(hl7Message);
>
>                 } catch (EncodingNotSupportedException e) {
>
>                                 e.printStackTrace();
>
>                                 throw new RuntimeException("Could not parse
> HL7 message! Encoding not supported.", e);
>
>                 } catch (HL7Exception e) {
>
>                                 e.printStackTrace();
>
>                                 throw new RuntimeException("Could not parse
> HL7 message!", e);
>
>                 }
>
>                 Terser terser = new Terser(message);
>
>
>
>                 //"/." + segment + "(" + index + ")-" + field + "-" +
> component;
>
>                 try {
>
>                                 //why do the next 3 lines work??
>
>                                 assertEquals("OBRnotes",
> terser.get("/.NTE2-3-1"));
>
>                                 assertEquals("OBX",
> terser.get("/.NTE3-3-1"));
>
>                                 assertEquals("notes",
> terser.get("/.NTE4-3-1"));
>
>                                 assertEquals("ORCnotes",
> terser.get("/.NTE(0)-3-1"));
>
>                                 //why do these lines fail??
>
>                                 assertEquals("OBRnotes",
> terser.get("/.NTE(1)-3-1"));
>
>                                 assertEquals("OBX",
> terser.get("/.NTE(2)-3-1"));
>
>                                 assertEquals("notes",
> terser.get("/.NTE(3)-3-1"));
>
>                 } catch (HL7Exception e) {
>
>                                 fail();
>
>                 }
>
> }
>
>
>
>
>
>
> MSH|^~\&|ADM|CLF654321||CLF123456|200612131130||ORU^R01|4323424|P|2.5|||AL|NE
>
> PID|||||
>
> ORC|||||||||||||||||||
>
> NTE|1||ORCnotes|
>
> OBR||||||||||||||
>
> NTE|2||OBRnotes|
>
> OBX|1|||||||||||||||
>
> NTE|3||OBX|
>
> NTE|4||notes|
>
>
> ------------------------------------------------------------------------------
> Nokia and AT&T present the 2010 Calling All Innovators-North America
> contest
> Create new apps & games for the Nokia N8 for consumers in  U.S. and Canada
> $10 million total in prizes - $4M cash, 500 devices, nearly $6M in
> marketing
> Develop with Nokia Qt SDK, Web Runtime, or Java and Publish to Ovi Store
> http://p.sf.net/sfu/nokia-dev2dev
> _______________________________________________
> Hl7api-devel mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/hl7api-devel
>
>
------------------------------------------------------------------------------
Nokia and AT&T present the 2010 Calling All Innovators-North America contest
Create new apps & games for the Nokia N8 for consumers in  U.S. and Canada
$10 million total in prizes - $4M cash, 500 devices, nearly $6M in marketing
Develop with Nokia Qt SDK, Web Runtime, or Java and Publish to Ovi Store 
http://p.sf.net/sfu/nokia-dev2dev
_______________________________________________
Hl7api-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/hl7api-devel

Reply via email to