After making some changes the RDS_R06 class is loaded but not the PFG custom 
Group.  I tried different package arrangements for the PFG  group but it never 
got loaded.  I notice in Ian's example he extends from class ORU_ORMIS, whilst 
I'm extending from AbstractMessage. I see that as the  most significant 
difference in my approach.  Other than extending AbstractMessage I'm not aware 
of which standard class to extend from.

This is the structure of the code :

com.lds.hl7.zxx.custommodel.v25.message
RDS_R06 , this is the custom message class

com.lds.hl7.zxx.custommodel.v25.segment
ZR2 , this is a custom segment
Other segments etc. are also present in this package but omitted.



com.lds.hl7.zxx.custommodel.v25.group
PFG



package com.lds.hl7.zxx.custommodel.v25.message;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
import com..lds.hl7.zxx.custommodel.v25.group.PFG;
import ca.uhn.hl7v2.HL7Exception;
import ca.uhn.hl7v2.model.AbstractMessage;
import ca.uhn.hl7v2.model.v25.segment.MSH;
import ca.uhn.hl7v2.parser.DefaultModelClassFactory;
import ca.uhn.hl7v2.parser.ModelClassFactory;

/////////////////Custom Message//////////////////
public class RDS_R06 extends AbstractMessage {

               private static final long serialVersionUID = 
-3887972873943927154L;

               public RDS_R06() {
                              this(new DefaultModelClassFactory());
               }

               public RDS_R06(ModelClassFactory theFactory) {
                              super(theFactory);
                              init(theFactory);
               }

               private void init(ModelClassFactory factory) {
                              try {
                                             System.out.println("RDS_R06is 
called!!!!!!!");
                                             this.add(MSH.class, true, false, 
false);
                                             this.add(PFG.class, true, true, 
false);
                              } catch (HL7Exception e) {
                                             log.error("Unexpected error 
creating PFM - this is probably a bug in " + "the source code generator.", e);
                              }
               }

               public MSH getMSH() {
                              return getTyped("MSH", MSH.class);
               }

               public java.util.List<PFG> getPFGAll() {
                              try {
                                             return getAllAsList("PFG", 
PFG.class);
                              } catch (HL7Exception e) {
                                             return new ArrayList<PFG>();
                              }
               }

               public int getPFGReps() {
                              return getReps("PFG");
               }


}

///////////////////////Custom Group////////////////////
import com.lds.hl7.zxx.custommodel.v25.segment.ZR2;
import ca.uhn.hl7v2.HL7Exception;
import ca.uhn.hl7v2.model.AbstractGroup;
import ca.uhn.hl7v2.model.Group;
import ca.uhn.hl7v2.model.v25.segment.ORC;
import ca.uhn.hl7v2.model.v25.segment.PID;
import ca.uhn.hl7v2.model.v25.segment.RXD;
import ca.uhn.hl7v2.parser.ModelClassFactory;

public class PFG extends AbstractGroup {

               private static final long serialVersionUID = 
-5950843839679571210L;

               protected PFG(Group parent, ModelClassFactory factory) {
                              super(parent, factory);
                              try {
                                             init();
                              } catch (HL7Exception e) {
                                             log.error("Unexpected error 
creating PFG.", e);
                              }
               }

               private void init() throws HL7Exception {
                              this.add(PID.class, true, false);
                              this.add(ORC.class, true, false);
                              this.add(RXD.class, true, false);
                              this.add(ZR2.class, true, false);
                              System.out.println("PFG!!!!!!");
               }

               public String getVersion() {
                              return "2.5";
               }

               public PID getPID() {
                              return getTyped("PID", PID.class);
               }

               public ORC getORC() {
                              return getTyped("ORC", ORC.class);
               }

               public RXD getRXD() {
                              return getTyped("RXD", RXD.class);
               }

               public ZR2 getZR2() {
                              return getTyped("ZR2", ZR2.class);
               }


               @Override
               public String getName() {
                              return "PFG";
               }

}

////////////////////Test Class//////////////
   public void testParseCustomRDS_R06Message() throws HL7Exception {
            String RDS_R06="MSH|^~\\&|VENDOR NAME 
||CDB||20010925202704||RDS^R06|573-013240530-4|P|2.5\r"
                              +"PID|||11111111116 ||WATER^UNDER^^||||||DEEP 6 
STREET^^CHARLESTON^SC^29405||(843) 745-4124\r"
                              +"ORC|OK|573-200009492-4\r"
                              +"RXD|1|S0022^SIMVASTATIN 40MG 
TAB^L|20010822081001|45|||200009492|||||||||||0108064|20020801||||||12345123412^SK567\r"
                   
+"ZR2|CTC-USPS|5161145008952133980|200009492|30.40|2.00|4.50|13.20|218^Big West 
Warehouse^2150 Hecker Pass HWY^^ Gilroy^ CA^95020\r";

        Parser p=new GenericParser();
        Map<String, String[]> hl7VersionPackageNamesMap = new HashMap<String, 
String[]>();
        String[] packageNames = 
{"ca.uhn.hl7v2.model.v25","com.mpls.lds.hl7.zxx.custommodel.v25.message","com.mckesson.mms.ecb2b.hl7.zxx.custommodel"};
        hl7VersionPackageNamesMap.put("2.3", packageNames);
        hl7VersionPackageNamesMap.put("2.3.1", packageNames);
        hl7VersionPackageNamesMap.put("2.4", packageNames);
        hl7VersionPackageNamesMap.put("2.5", packageNames);
                              ModelClassFactory cfm=new 
CustomModelClassFactory(hl7VersionPackageNamesMap);
        HapiContext context=new DefaultHapiContext(cfm);
                              //Get a Parser from the HapiContext created with 
the CustomModelClassFactory
        Parser pipeParser = context.getPipeParser();
        Message mm=pipeParser.parse(RDS_R06);

                              //Use the Parser created from the 
createHapiContext() context
        Message message = new GenericParser(HAPI_CONTEXT).parse(RDS_R06);

        //This loads the RDS_R06 class
                  System.out.println("Class Message RDS_R06 is instanceof  is 
"+(message instanceof RDS_R06));
                              //This doesn't load the RDS_R06 class
        System.out.println("Class Message RDS_R06 is instanceof  is "+(mm 
instanceof RDS_R06));
    }



////// Using ths HapiContext This doesn't give me any different results.
////In fact this doesn't even load the RDS_R06 class
    private static HapiContext createHapiContext() {
        System.setProperty(Varies.DEFAULT_OBX2_TYPE_PROP, "ST");
        System.setProperty(Varies.INVALID_OBX2_TYPE_PROP, "ST");
        Map<String, String[]> hl7VersionPackageNamesMap = new HashMap<String, 
String[]>();
        String[] packageNames = 
{"ca.uhn.hl7v2.model.v25","com.mckesson.mms.ecb2b.hl7.zxx.custommodel","com.mpls.lds.hl7.zxx.custommodel.v25.message"};
        hl7VersionPackageNamesMap.put("2.3", packageNames);
        hl7VersionPackageNamesMap.put("2.3.1", packageNames);
        hl7VersionPackageNamesMap.put("2.4", packageNames);
        hl7VersionPackageNamesMap.put("2.5", packageNames);
        HapiContext hapiContext = new DefaultHapiContext();
        hapiContext.setModelClassFactory(new 
CustomModelClassFactory(hl7VersionPackageNamesMap));
        hapiContext.setValidationRuleBuilder(new NoValidationBuilder());
        return hapiContext;
    } Output is :

RDS_R06is called!!!!!!!
Message  is instanceof RDS_R06 is  is false
Message  is instanceof RDS_R06 is  is false



------------------------------------------------------------------------------
_______________________________________________
Hl7api-devel mailing list
Hl7api-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/hl7api-devel

Reply via email to