I have the following 2 classes which seem to conform to the expected setup for a custom model. I stripped the jars referenced in the project to just the log4j and slf4j and the hapi-structures-v25-2.2.jar and hapi-base-2.2.jar. It is more or less the same code as in the examples. I tried doing this because I was getting a similar exception the core project so I decided to strip it down to the bare minimum. I am also using JDK.1.7. Any help would be most welcome.
However, I am getting a ClassCastException : log4j:WARN Please initialize the log4j system properly. log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info. Fido Fred 13 Exception in thread "main" java.lang.ClassCastException: [Lca.uhn.hl7v2.model.Type; cannot be cast to [Lca.uhn.hl7v2.model.v25.datatype.ST; at com.msh.bgapp.hl7.custommodel.v25.segment.ZPI.getPetName(ZPI.java:49) at com.msh.bgapp.hl7.TestCustomModel.main(TestCustomModel.java:42) package com.msh.bgapp.hl7.custommodel.v25.segment; import ca.uhn.hl7v2.HL7Exception; import ca.uhn.hl7v2.model.AbstractSegment; import ca.uhn.hl7v2.model.Group; import ca.uhn.hl7v2.model.Message; import ca.uhn.hl7v2.model.Type; import ca.uhn.hl7v2.model.v25.datatype.NM; import ca.uhn.hl7v2.model.v25.datatype.ST; import ca.uhn.hl7v2.parser.ModelClassFactory; public class ZPI extends AbstractSegment { private static final long serialVersionUID = 1L; public ZPI(Group parent, ModelClassFactory modelClassFactory) throws HL7Exception { super(parent, modelClassFactory); Message message = getMessage(); Class<? extends Type> type = ST.class; boolean required = true; int maxReps = 0; int maxLength = 100; Object[] constructorArgs = { message }; String fieldName = "Pet Name(s)"; add(type, required, maxReps, maxLength, constructorArgs, fieldName); type = NM.class; required = false; maxReps = 1; maxLength = 4; constructorArgs = new Object[] { message }; fieldName = "Shoe Size"; add(type, required, maxReps, maxLength, constructorArgs, fieldName); } protected Type createNewTypeWithoutReflection(int field) { return null; } public ST[] getPetName() throws HL7Exception { return (ST[])super.getField(1); } public NM getShoeSize() throws HL7Exception { return (NM)super.getField(1, 0); } } package com.msh.bgapp.hl7; import com.msh.bgapp.hl7.custommodel.v25.message.ZDT_A01; import com.msh.bgapp.hl7.custommodel.v25.segment.ZPI; import ca.uhn.hl7v2.HL7Exception; import ca.uhn.hl7v2.model.Segment; import ca.uhn.hl7v2.model.v25.message.ADT_A01; import ca.uhn.hl7v2.parser.CustomModelClassFactory; import ca.uhn.hl7v2.parser.ModelClassFactory; import ca.uhn.hl7v2.parser.Parser; import ca.uhn.hl7v2.parser.PipeParser; public class TestCustomModel { public static void main(String[] args) throws HL7Exception { String messageText = "MSH|^~\\&|IRIS|SANTER|AMB_R|SANTER|200803051508||ADT^A01|263206|P|2.5\rEVN||200803051509||||200803031508\rPID|||5520255^^^PK^PK~ZZZZZZ83M64Z148R^^^CF^CF~ZZZZZZ83M64Z148R^^^SSN^SSN^^20070103^99991231~^^^^TEAM||ZZZ^ZZZ||19830824|F||||||||||||||||||||||N\rZPI|Fido~Fred|13\rPV1||I|6402DH^^^^^^^^MED. 1 - ONCOLOGIA^^OSPEDALE MAGGIORE DI LODI&LODI|||^^^^^^^^^^OSPEDALE MAGGIORE DI LODI&LODI|13936^TEST^TEST||||||||||5068^TEST2^TEST2||2008003369||||||||||||||||||||||||||200803031508\rPR1|1||1111^Mastoplastica|Protesi|20090224|02|"; ADT_A01 message = (ADT_A01)new PipeParser().parse(messageText); Segment zpiGenericSegment = (Segment)message.get("ZPI"); String firstPetName = zpiGenericSegment.getField(1, 0).encode(); String secondPetName = zpiGenericSegment.getField(1, 1).encode(); System.out.println(firstPetName); System.out.println(secondPetName); String shoeSize = zpiGenericSegment.getField(2, 0).encode(); System.out.println(shoeSize); ModelClassFactory cmf = new CustomModelClassFactory("com.msh.bgapp.hl7.custommodel"); Parser parser = new PipeParser(cmf); messageText = "MSH|^~\\&|IRIS|SANTER|AMB_R|SANTER|200803051508||ZDT^A01|263206|P|2.5\rEVN||200803051509||||200803031508\rPID|||5520255^^^PK^PK~ZZZZZZ83M64Z148R^^^CF^CF~ZZZZZZ83M64Z148R^^^SSN^SSN^^20070103^99991231~^^^^TEAM||ZZZ^ZZZ||19830824|F||||||||||||||||||||||N\rZPI|Fido~Fred|13\rPV1||I|6402DH^^^^^^^^MED. 1 - ONCOLOGIA^^OSPEDALE MAGGIORE DI LODI&LODI|||^^^^^^^^^^OSPEDALE MAGGIORE DI LODI&LODI|13936^TEST^TEST||||||||||5068^TEST2^TEST2||2008003369||||||||||||||||||||||||||200803031508\rPR1|1||1111^Mastoplastica|Protesi|20090224|02|"; ZDT_A01 zdtA01 = (ZDT_A01)parser.parse(messageText); ZPI zpi = zdtA01.getZPI(); System.out.println(zpi.getPetName()[0].encode()); System.out.println(zpi.getPetName()[1].encode()); System.out.println(zpi.getShoeSize().encode()); } } package com.msh.bgapp.hl7.custommodel.v25.message; import ca.uhn.hl7v2.HL7Exception; import ca.uhn.hl7v2.model.v25.message.ADT_A01; import ca.uhn.hl7v2.parser.ModelClassFactory; import java.util.Arrays; import com.msh.bgapp.hl7.custommodel.v25.segment.ZPI; public class ZDT_A01 extends ADT_A01 { private static final long serialVersionUID = -2504830694193741286L; public ZDT_A01(ModelClassFactory factory) throws HL7Exception { super(factory); String[] segmentNames = getNames(); int indexOfPid = Arrays.asList(segmentNames).indexOf("PID"); Class<ZPI> type = ZPI.class; boolean required = true; boolean repeating = false; int index = indexOfPid + 1; add(type, required, repeating, index); } public ZPI getZPI() throws HL7Exception { return (ZPI)get("ZPI"); } }
------------------------------------------------------------------------------
_______________________________________________ Hl7api-devel mailing list Hl7api-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/hl7api-devel