I overcame this issue by creating a GENERIC_ADT message using techniques shown
on the Hapi site. Our establishment has many Z-segments, so I had to do all
those, and group them accordingly. A basic example is available on the Hapi
site at
http://hl7api.sourceforge.net/xref/ca/uhn/hl7v2/examples/CustomModelClasses.html
Snippets from the objects are shown below. It was quite a long repetitive
process, and I even wrote a module that created java code from a text file for
the Z segments. However, now it's done all that is required is to create a
GENERIC_ADT with it's constructor, and parse the message text with it's parse
method.
The groups shown in this snippet were defined in similar manner as additional
classes in the java project.
Hope this helps
Ian
--- code snippets ---
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package au.gov.qld.health.sit.hl7;
import ca.uhn.hl7v2.HL7Exception;
import ca.uhn.hl7v2.model.AbstractMessage;
import ca.uhn.hl7v2.model.v24.segment.*;
import ca.uhn.hl7v2.parser.ModelClassFactory;
/**
*
* @author VowlesI
*/
public class GENERIC_ADT extends AbstractMessage {
public GENERIC_ADT(ModelClassFactory factory) throws HL7Exception {
super(factory);
Class<MSH> addMsh = MSH.class;
this.add(addMsh,true,false);
Class<EVN> addEvn = EVN.class;
this.add(addEvn, false, false);
Class<SCH> addSch = SCH.class;
this.add(addSch, false, false);
Class<PID> addPid = PID.class;
this.add(addPid, true, false);
Class<PD1> addPd1 = PD1.class;
this.add(addPd1, false, false);
.
. snip .
.
.
Class<MASTERFILE> addMasterFile = MASTERFILE.class;
this.add(addMasterFile,false,false);
Class<ZHBCIS> addZhbcis = ZHBCIS.class;
this.add(addZhbcis, false, false);
Class<ZNORM> addZnorm = ZNORM.class;
this.add(addZnorm, false, false);
}
public MSH getMSH() throws HL7Exception {
return (MSH) get("MSH");
}
public EVN getEVN() throws HL7Exception {
return (EVN) get ("EVN");
}
public SCH getSCH() throws HL7Exception {
return (SCH) get ("SCH");
}
public PID getPID() throws HL7Exception {
return (PID) get ("PID");
}
public PD1 getPD1() throws HL7Exception {
return (PD1) get ("PD1");
}
.
. snip
.
.
public MASTERFILE getMASTERFILE() throws HL7Exception {
return (MASTERFILE) get ("MASTERFILE");
}
public ZHBCIS getZHBCIS() throws HL7Exception {
return (ZHBCIS) get ("ZHBCIS");
}
public ZNORM getZNORM() throws HL7Exception {
return (ZNORM) get ("ZNORM");
}
}
>>> Sumit Lahiri <sumit.lah...@gmail.com> 31/05/13 0:45 >>>
Hello there,
I'm new to HAPI. The problem I'm facing is I'm not able to typecast a ADT
message to generic ADT_AXX message type. So as a result when I try to parse a
segment eg. IN1 which is not present in a specific ADT Event type(eg ADT_A01) I
get an HL7Exception like
"IN1 does not exist in the group ca.uhn.hl7v2.model.v251.message.ADT_A01"
I'm using the following code to parse my message
HapiContext context = new DefaultHapiContext();
Parser p = context.getGenericParser();
Message hapiMsg;
try {
// The parse method performs the actual parsing
hapiMsg = p.parse(msg1);
} catch (EncodingNotSupportedException e) {
e.printStackTrace();
return;
} catch (HL7Exception e) {
e.printStackTrace();
return;
}
Any help would be highly appreciated.
Best Regards
Sumit
********************************************************************************
This email, including any attachments sent with it, is confidential and for the
sole use of the intended recipient(s). This confidentiality is not waived or
lost, if you receive it and you are not the intended recipient(s), or if it is
transmitted/received in error.
Any unauthorised use, alteration, disclosure, distribution or review of this
email is strictly prohibited. The information contained in this email,
including any attachment sent with it, may be subject to a statutory duty of
confidentiality if it relates to health service matters.
If you are not the intended recipient(s), or if you have received this email in
error, you are asked to immediately notify the sender by telephone collect on
Australia +61 1800 198 175 or by return email. You should also delete this
email, and any copies, from your computer system network and destroy any hard
copies produced.
If not an intended recipient of this email, you must not copy, distribute or
take any action(s) that relies on it; any form of disclosure, modification,
distribution and/or publication of this email is also prohibited.
Although Queensland Health takes all reasonable steps to ensure this email does
not contain malicious software, Queensland Health does not accept
responsibility for the consequences if any person's computer inadvertently
suffers any disruption to services, loss of information, harm or is infected
with a virus, other malicious computer programme or code that may occur as a
consequence of receiving this email.
Unless stated otherwise, this email represents only the views of the sender and
not the views of the Queensland Government.
**********************************************************************************
------------------------------------------------------------------------------
Introducing AppDynamics Lite, a free troubleshooting tool for Java/.NET
Get 100% visibility into your production application - at no cost.
Code-level diagnostics for performance bottlenecks with <2% overhead
Download for free and get started troubleshooting in minutes.
http://p.sf.net/sfu/appdyn_d2d_ap1
_______________________________________________
Hl7api-devel mailing list
Hl7api-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/hl7api-devel