I have a method:
public boolean isFieldPresent(String pathToField, Terser terser)
{
try
{
String value = terser.get(pathToField);
if (value!=null && value.length()>0)
return true;
}
catch (ca.uhn.hl7v2.HL7Exception e)
{
//ignore exception because it indicates the field isn't present
}
return false;
}
Which I call using the path to the first required field in a segment to see if
the segment exists
if (isFieldPresent("/.GT1-1", terser))
{
....
-ryan
Date: Mon, 12 May 2008 11:14:13 -0400
From: [EMAIL PROTECTED]
To: [EMAIL PROTECTED]; [EMAIL PROTECTED]; [email protected]
Subject: Re: [HAPI-devel] How to check if a segmen tis present in a message
Thanks..but getNames() returns all the
segments that should exists in the message..not what is currently present in
the message. Calling getNames on an ADT message returned the following
structures
MSH,EVN,PID,,PD1NK1,PV1,PV2,DB1,OBX,AL1,DG1,DRG,PR1ROL,GT1,IN1IN2IN3,ACC,UB1,UB2
and my message only had MSH and PID.
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of VIOT Yves
Sent: Friday, May 09, 2008 5:05 AM
To: clarksonpj
Cc:
[email protected]
Subject: Re: [HAPI-devel] How to
check if a segmen tis present in a message
Hi,
One way, but perhaps not the best (???), could be this:
String[] segNames = hapiMessage.getNames(); Then jsut browse your string array
to find if your seg exists Hope it helps Bye
clarksonpj a écrit :
Great question, I would also like to know if there is a way of doing this.
Right now I need to check each element for null. Lansdale Redmond wrote:
How can I check if a segment is present in a message..when I do thefollowing
code it always returns a value then if I read a field the vlueis null..very
similar to if it was there...how do you know thedifference PID seg = (PID)
hapiMessage.get("PID"); if ( seg == null) return false;
else return true;
-------------------------------------------------------------------------This
SF.net email is sponsored by the 2008 JavaOne(SM) Conference Don't miss this
year's exciting event. There's still time to save $100. Use priority code
J8TL2D2.
http://ad.doubleclick.net/clk;198757673;13503038;p?http://java.sun.com/javaone_______________________________________________Hl7api-devel
mailing [EMAIL PROTECTED]://lists.sourceforge.net/lists/listinfo/hl7api-devel
:-)
_________________________________________________________________
Make Windows Vista more reliable and secure with Windows Vista Service Pack 1.
http://www.windowsvista.com/SP1?WT.mc_id=hotmailvistasp1banner-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
Hl7api-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/hl7api-devel