public virtual NuGenHL7Exception[] testField(Genetibase.NuGenHL7.model.Type type, Field profile, bool escape, System.String profileID) { System.Collections.ArrayList exList = new System.Collections.ArrayList(20); //account for MSH 1 & 2 which aren't escaped System.String encoded = null; if (!escape && typeof(Primitive).IsAssignableFrom(type.GetType())) encoded = ((Primitive) type).Value; addToList(testType(type, profile, encoded, profileID), exList); //test children if (profile.Components > 0 && !profile.Usage.Equals("X")) { if (typeof(Composite).IsAssignableFrom(type.GetType())) { Composite comp = (Composite) type; for (int i = 1; i <= profile.Components; i++) { Component childProfile = profile.getComponent(i); try { Genetibase.NuGenHL7.model.Type child = comp.getComponent(i - 1); addToList(testComponent(child, childProfile, profileID), exList); } catch (DataTypeException de) { exList.Add(new NuGenProfileNotHL7CompliantException("More components in profile than allowed in message: " + de.Message)); } } addToList(checkExtraComponents(comp, profile.Components), exList); } else { exList.Add(new NuGenProfileNotHL7CompliantException("A field has type primitive " + type.GetType().FullName + " but the profile defines components")); } } return toArray(exList); }
/// <summary>Indexed setter for property field (index starts at 1 following HL7 convention).</summary> /// <param name="index">Index of the property (starts at 1 following HL7 convention). /// </param> /// <param name="field">New value of the property at <CODE>index</CODE>. /// /// </param> /// <throws> ProfileException </throws> public virtual void setField(int index, Field field) { index--; extendChildList(index); Field oldField = this.fields[index]; this.fields[index] = field; try { SupportClass.PropertyChangingEventArgs ve32 = new SupportClass.PropertyChangingEventArgs("fields", null, null); } catch (System.ArgumentOutOfRangeException vetoException) { this.fields[index] = oldField; throw new NuGenProfileException(null, vetoException); } SupportClass.PropertyChangingEventArgs me32 = new SupportClass.PropertyChangingEventArgs("fields", null, null); }
/// <summary>Makes child list long enough to accommodate setter. </summary> private void extendChildList(int index) { if (index >= this.fields.Length) { Field[] newCopy = new Field[index + 1]; Array.Copy(this.fields, 0, newCopy, 0, this.fields.Length); this.fields = newCopy; } }
/// <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); }