0

I have this ugly code below for hl7 message seen here. The code runs for varied versions of HL7 listeners. For one system I receive in v2.3 but for the other one I get in v2.5

As you can notice the job is almost same for all versions. But the base of ACK is message and I can't call getMsa1_AcknowledgementCode method without explicitly casting to exact HL7 version,and there isn't a common ACK class among them. By this dummy diagram I tried to present the problem. (I know there are some other elements ,such as AbstractMessage,Group...)

enter image description here

And for first two the method name is getMsa1_AcknowledgementCode but for v2.5 it has missing e letter and seems like getMsa1_AcknowledgmentCode.

Should I use reflection and find a method starts with the name getMsa_Ack... to check an Acknowledge message or is there any type safe and beautiful way for this purpose in hapi project?

Do not constrain yourself for ACK message while answering I wonder a better way for others as well.

MSH|^~\&|Vendor|VandorApp|Receiver|RCApp|201504241154||ACK|187718704|T|2.3|||AL|AL|TR
MSA|AA|187718704

        String result="AA";

        ca.uhn.hl7v2.model.Message hl7 = initiator.sendAndReceive(msg);

        if(hl7 instanceof ca.uhn.hl7v2.model.v231.message.ACK)
        {
            ca.uhn.hl7v2.model.v231.datatype.ID id= ((ca.uhn.hl7v2.model.v231.message.ACK)hl7).getMSA().getMsa1_AcknowledgementCode();
            result=id.getValue();               
        }else if (hl7 instanceof ca.uhn.hl7v2.model.v23.message.ACK)
        {
            ca.uhn.hl7v2.model.v23.datatype.ID id=  ((ca.uhn.hl7v2.model.v23.message.ACK)hl7).getMSA().getMsa1_AcknowledgementCode();
            result=id.getValue();               
        }else if( hl7 instanceof ca.uhn.hl7v2.model.v25.message.ACK)
        {
            ca.uhn.hl7v2.model.v25.datatype.ID id=  ((ca.uhn.hl7v2.model.v25.message.ACK)hl7).getMSA().getMsa1_AcknowledgmentCode();
            result=id.getValue();
        }
4

1 に答える 1