I created simple wrapper classes around message types and do the following:
public HL7MSH(Message Msg)
throws DataTypeException, HL7Exception
{
_Msh = (MSH) Msg.get("MSH");
_Version = _Msh.getVersionID().getVersionID().getValue();
_Code =
_Msh.getMsh9_MessageType().getMsg1_MessageCode().getValue();
_Type =
_Msh.getMsh9_MessageType().getMsg2_TriggerEvent().getValue();
_Time = _Msh.getDateTimeOfMessage().getValueAsCalendar() ==
null ? null : new HL7DTM(_Msh.getDateTimeOfMessage())._Cal;
_Id = _Msh.getMessageControlID().getValue();
}
This is the constructor to my HL7MSH wrapper object. Then in the main
code, i do like this
HL7MSH Msh = new HL7MSH(Msg);
if (Msh._Code.equals("ADT") == false)
return new ADTRecord(Msh, Msg, "HL7Message Error: This is not
an ADT Message (it's a "+Msh._Code+"). Message won't be processed.");
ADTRecord ADT = (Msh._Type.equals("A01") == true) ? (ADTRecord)
new ADT01or04or08Record(Msh, Msg)
: (Msh._Type.equals("A02") == true) ? (ADTRecord)
new ADT02Record(Msh, Msg)
: (Msh._Type.equals("A03") == true) ? (ADTRecord)
new ADT03Record(Msh, Msg)
: (Msh._Type.equals("A04") == true) ? (ADTRecord)
new ADT01or04or08Record(Msh, Msg)
: (Msh._Type.equals("A05") == true) ? (ADTRecord)
new ADT05or28or31Record(Msh, Msg)
: (Msh._Type.equals("A06") == true) ? (ADTRecord)
new ADT06or07Record(Msh, Msg)
: (Msh._Type.equals("A07") == true) ? (ADTRecord)
new ADT06or07Record(Msh, Msg)
: (Msh._Type.equals("A08") == true) ? (ADTRecord)
new ADT01or04or08Record(Msh, Msg)
: (Msh._Type.equals("A28") == true) ? (ADTRecord)
new ADT05or28or31Record(Msh, Msg)
: (Msh._Type.equals("A31") == true) ? (ADTRecord)
new ADT05or28or31Record(Msh, Msg)
: new ADTRecord(Msh, Msg, "HL7Message Error: This
is not a supported ADT A01-A08, A28 or A31 message (it's a
"+Msh._Type+"). Message won't be processed.");
Obviously, i am calling my own wrapper classes here, but essentially, i
get the code and type of any incoming message and route accordingly to
process.
Hope this helps a bit.
------------------------------------------------------------------------
*Laurent (Harry) Hasson*
Co-Founder, 360Fresh.com <https://360Fresh.com>
On 3/16/2012 04:14, Gabriel Euzet wrote:
Hi Sanjay,
I have the same problem.
ca.uhn.hl7v2.model.Message has no method to get the MSH segment until
you cast it to ADT_A01 ...
I found 3 ways to identify the message type :
* use reflection to invoke getMSH(), again to invoke
getMessageType(), and again for methods getMessageStructure() and
getTriggerEvent().
* use Terser :
Terser t = new Terser(message);
String triggerEvent = t.get("/MSH-9-2");
String messageStructure = t.get("/MSH-9-3");
Then you just need to write a long list of if(
"ADT....".equals(messageStructure) ) .....
* write the long list of if( message instance of ADT_...) ...
Hope it helps
Gabriel
2012/3/15 Sanjay Bhandari<san...@ziffusion.com>:
I'm trying to figure out what is the normal way of casting a incoming
message to the appropriate type.
Specifically, if I register for messages with:
server.registerApplication("*", "*", handler);
I see the following:
MSH -> getMESSAGETYPE() -> getMessageType() -> getValue()
Is this what I switch on, and cast? Or is there another preferred way?
------------------------------------------------------------------------------
This SF email is sponsosred by:
Try Windows Azure free for 90 days Click Here
http://p.sf.net/sfu/sfd2d-msazure
_______________________________________________
Hl7api-devel mailing list
Hl7api-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/hl7api-devel
------------------------------------------------------------------------------
This SF email is sponsosred by:
Try Windows Azure free for 90 days Click Here
http://p.sf.net/sfu/sfd2d-msazure
_______________________________________________
Hl7api-devel mailing list
Hl7api-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/hl7api-devel
------------------------------------------------------------------------------
This SF email is sponsosred by:
Try Windows Azure free for 90 days Click Here
http://p.sf.net/sfu/sfd2d-msazure
_______________________________________________
Hl7api-devel mailing list
Hl7api-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/hl7api-devel