From: Christian O. <chr...@gm...> - 2015-11-16 14:23:08
|
In your case, nothing tells HAPI to instantiate a "PFM" message when it comes across a message with MFN^M01 in the MSH-9 field. This is the task of the so-called event map. It's a file located in the ca.uhn.hl7v2.parser.eventmap package and called <version>.properties (i.e. in your case "2.5.properties"). The file contains two columns: col 1 specifies the message structure and col 2 specifies the custom class that implements this structure. If there is no match, it falls back to the standard event map, instantiating a instance of ca.uhn.hl7v2.model.v25.message.MFN_M01, which gives you the ClassCastException. Check the existing HAPI structure libraries for these eventmap files. So you have two choices * rename the class com.msh.bgapp.hl7.custommodel.v25.message.PFM class to MFN_M01. You don't need an custom eventmap then. * add an event map file to your project that explicitly maps MFN_M01 to PFM I usually choose option 1 as it keeps the naming convention and also indicates in the class name what is replaced. Also note that you do not necessarily have to extend from the original message structure class. cheers Christian 2015-10-26 20:08 GMT+01:00 Davies, Brian <Bri...@mc...>: > Related to the previous issue, I get an exception when casting down to my > object which extends the MFN_M01 message. I am extending MFN_M01 because > this is specified in the message type field, so I’m unable to avoid it. I > am using the v25 libraries and JDK1.7 > > > > Exception in thread "main" *java.lang.ClassCastException*: > ca.uhn.hl7v2.model.v25.message.MFN_M01 cannot be cast to > com.msh.bgapp.hl7.custommodel.v25.message.PFM > > at com.msh.bgapp.hl7.custommodel.v25.message.PFM.main( > *PFM.java:106*) > > > > > > String HDR= > "MSH|^~\\&|DSF||Vendor||20150926151426||MFN^M01|610-100672|P|2.5\r" > > > > > > * public* *class* PFM *extends* MFN_M01 { > > *private* *static* *final* *long* *serialVersionUID* = > -6182782287494872212L; > > > > > > *public* PFM(ModelClassFactory theFactory) { > > *super*(theFactory); > > init(theFactory); > > } > > > > *private* *void* init(ModelClassFactory factory) { > > *try* { > > *this*.add(MSH.*class*, *true*, *false* > ); > > *this*.add(MFI.*class*, *false*, > *false*); > > *this*.add(MFE.*class*, *false*, > *false*); > > > > } *catch*(HL7Exception e) { > > *log*.error("Unexpected error creating PFM ,e); > > } > > } > > > > *public* MSH getMSH() { > > *return* getTyped("MSH", MSH.*class*); > > } > > > > > > > > > > > > > > *public* ZRQ getZRQ() { > > *return* (ZRQ)getTyped("ZRQ", ZRQ.*class*); > > } > > > > *public* String getVersion() { > > *return* "2.5"; > > } > > > > > > > > > > > > > > *public* *static* *void* main(String[] args) *throws* > DataTypeException, HL7Exception, IOException { > > > > String HDR= > "MSH|^~\\&|DSF||Vendor||20150926151426||MFN^M01|610-100672|P|2.5\r" > > +"MFI|ZBM||UPD|20150917172522|20150917172522|AL\r" > > +"MFE|MAD|610-100672|20150917172522|610-100672|CE\r" > > > > ModelClassFactory cmf = *new* CustomModelClassFactory( > "com.msh.bgapp.hl7.custommodel"); > > @SuppressWarnings("resource") > > HapiContext context=*new* DefaultHapiContext(cmf); > > Parser parser = context.getPipeParser(); > > PFM o=(PFM)parser.parse(HDR); > > > > > > > > } > > > > } > > > > > ------------------------------------------------------------------------------ > > _______________________________________________ > Hl7api-devel mailing list > Hl7...@li... > https://lists.sourceforge.net/lists/listinfo/hl7api-devel > > |