/// <summary>This method builds a Conformance Field Class</summary> /// <param name="field">the Field to build /// </param> /// <param name="parentUnderlyingType">the data type of the parent Segment for this field /// example "Genetibase.NuGenHL7.model.v24.segment.MSH" /// </param> /// <param name="profileName"> ProfileName /// </param> public virtual void buildClass(Field field, System.String parentUnderlyingType, ProfileName profileName) { GeneratedConformanceContainer gcc = new GeneratedConformanceContainer(); GeneratedMethod gm = new GeneratedMethod(); // Check for possible snags in the Runtime Profile Segment if (field.Name == null || field.Name.Length < 1) { throw new ConformanceError("Error building ConformanceField: Runtime Field does not contain a name."); } // Set up class gcc.ClassPackage = packageName; gcc.addClassImport("Genetibase.NuGenHL7.conf.classes.abs.*"); gcc.addClassImport("Genetibase.NuGenHL7.conf.classes.exceptions.*"); gcc.addClassImport("Genetibase.NuGenHL7.model.*"); gcc.addClassImport("Genetibase.NuGenHL7.*"); if (field.Components > 0) { gcc.addClassImport(packageName + "." + profileName.PackageName + ".*"); } gcc.Name = profileName.ClassName; gcc.Properties = "extends AbstractConformanceContainer implements Repeatable"; gcc.setMinMaxReps(field.Min, field.Max); underlyingType = "Genetibase.NuGenHL7.model." + versionString + ".datatype." + field.Datatype; gcc.addMemberVariable(underlyingType + " hapiType;"); gcc.addMemberVariable("private final short MAX_LENGTH = " + field.Length + ";"); gm.ReturnType = "long"; gm.Visibility = "public"; gm.Name = "getMaxLength"; gm.addToBody("return this.MAX_LENGTH;"); docBuilder.decorateMaxLength(gm); gcc.addMethod(gm); // Set up underlying Field type gcc.Constructor.addParam(parentUnderlyingType + " hapiSegment", "The underlying HAPI field object"); gcc.Constructor.addParam("int rep", "The desired repetition"); gcc.Constructor.addToBody("try {"); UnderlyingAccessor underlyingAccessor = new UnderlyingAccessor(parentUnderlyingType, profileName.AccessorName); gcc.Constructor.addToBody(" this.hapiType = hapiSegment." + underlyingAccessor + ";"); docBuilder.decorateConstructor(gcc.Constructor, profileName.ClassName); // Create the getters and member variables associated with each child for (int i = 1; i <= field.Components; i++) { //don't build not supported, backward, or unknown types System.String usage = field.getComponent(i).Usage; if (usage != null && (usage.Equals("X") || usage.Equals("B") || usage.Equals("U"))) { continue; } bool hasChildren = (field.getComponent(i).SubComponents > 0)?true:false; ProfileName childProfileName = new ProfileName(field.getComponent(i).Name, ProfileName.PS_COMP); gcc.addComponent(childProfileName, (short)(i - 1), hasChildren); } gcc.Constructor.addToBody("} catch ( HL7Exception e ) {"); gcc.Constructor.addToBody(" throw new ConformanceError( \"Invalid Attempt to access a rep. This is a bug.\" );"); gcc.Constructor.addToBody("}"); // Decorate with comments docBuilder.decorateField(gcc, field); if (depManager.Verbose) { System.Console.Out.WriteLine("Generating Field: " + packageName + "." + gcc.Name); } // Create the components for (int i = 1; i <= field.Components; i++) { if (field.getComponent(i).SubComponents == 0) { ConformancePrimitiveBuilder childBuilder = new ConformancePrimitiveBuilder(packageName + "." + profileName.PackageName, depManager); childBuilder.buildClass(field.getComponent(i), ProfileName.PS_COMP); } else { ConformanceComponentBuilder childBuilder = new ConformanceComponentBuilder(packageName + "." + profileName.PackageName, depManager, versionString); childBuilder.buildClass(field.getComponent(i)); } } depManager.generateFile(gcc, packageName, gcc.Name); }
/// <summary>This method builds a Conformance Component Class</summary> /// <param name="comp">the Component to build /// </param> public virtual void buildClass(Component comp) { ProfileName profileName = new ProfileName(comp.Name, ProfileName.PS_COMP); GeneratedConformanceContainer gcc = new GeneratedConformanceContainer(); gcc.ClassPackage = packageName; gcc.addClassImport("Genetibase.NuGenHL7.conf.classes.abs.*"); gcc.addClassImport("Genetibase.NuGenHL7.conf.classes.exceptions.*"); gcc.addClassImport("Genetibase.NuGenHL7.model.*"); gcc.addClassImport(packageName + "." + profileName.PackageName + ".*"); gcc.Name = profileName.ClassName; gcc.Properties = "extends AbstractConformanceContainer"; gcc.addMemberVariable("private Composite hapiType;"); gcc.Constructor.addToComments("Creates new instances of all SubComponents contained in this Component"); gcc.Constructor.addToBody("this.hapiType = hapiType;"); docBuilder.decorateConstructor(gcc.Constructor, profileName.ClassName); // Add member variables and getters for subcomponents gcc.Constructor.addToBody("try{"); for (int i = 1; i <= comp.SubComponents; i++) { //don't build not supported, backward, or unknown types System.String usage = comp.getSubComponent(i).Usage; if (usage != null && (usage.Equals("X") || usage.Equals("B") || usage.Equals("U"))) { continue; } // The following is a workaround to allow for composite subcomponents. System.Type c; System.Object instance; try { c = System.Type.GetType("Genetibase.NuGenHL7.model." + versionString + ".datatype." + comp.getSubComponent(i).Datatype); instance = c.GetConstructor(null).Invoke(null); } catch (System.Exception e) { throw new ConformanceError("Could not find underlying SubComponent datatype. This is a bug. Exception: " + e.ToString()); } if (instance is Composite) { // In this case, the child is a composite subcomponent Component generatedComponent = createSubComponentProfile(c, comp.getSubComponent(i).Name); gcc.addComponent(new ProfileName(comp.getSubComponent(i).Name, ProfileName.PS_COMP), i - 1, true); ConformanceComponentBuilder childBuilder = new ConformanceComponentBuilder(packageName + "." + profileName.PackageName, depManager, versionString); childBuilder.buildClass(generatedComponent); } else { // In this case, the child is a primitive (this is the normal case) gcc.addSubComponent(new ProfileName(comp.getSubComponent(i).Name, ProfileName.PS_SUBC), i - 1); ConformancePrimitiveBuilder childBuilder = new ConformancePrimitiveBuilder(packageName + "." + profileName.PackageName, depManager); childBuilder.buildClass(comp.getSubComponent(i), ProfileName.PS_SUBC); } } gcc.Constructor.addParam("Composite hapiType", "Reference to the underlying HAPI Composite data type."); gcc.Constructor.addToBody("} catch ( DataTypeException e ) {"); gcc.Constructor.addToBody(" throw new ConformanceError(\"Invalid Attempt to access a rep. This is a Conformance Class Bug\");"); gcc.Constructor.addToBody("}"); // Decorate with comments docBuilder.decorateComponent(gcc, comp); if (depManager.Verbose) { System.Console.Out.WriteLine("Generating Component: " + packageName + "." + gcc.Name); } depManager.generateFile(gcc, packageName, gcc.Name); }