示例#1
0
        public static void makeAll(System.String baseDirectory, System.String version)
        {
            //make base directory

            if (!(baseDirectory.EndsWith("\\") || baseDirectory.EndsWith("/")))
            {
                baseDirectory = baseDirectory + "/";
            }
            System.IO.FileInfo targetDir = SourceGenerator.makeDirectory(baseDirectory + PackageManager.GetVersionPackagePath(version) + "EventMapping");

            //get list of data types
            System.Data.OleDb.OleDbConnection conn = NormativeDatabase.Instance.Connection;
            System.String sql = "SELECT * from HL7EventMessageTypes inner join HL7Versions on HL7EventMessageTypes.version_id = HL7Versions.version_id where HL7Versions.hl7_version = '" + version + "'";
            System.Data.OleDb.OleDbCommand temp_OleDbCommand = new System.Data.OleDb.OleDbCommand();
            temp_OleDbCommand.Connection  = conn;
            temp_OleDbCommand.CommandText = sql;
            System.Data.OleDb.OleDbDataReader rs = temp_OleDbCommand.ExecuteReader();


            using (StreamWriter sw = new StreamWriter(targetDir.FullName + @"\EventMap.properties", false))
            {
                sw.WriteLine("#event -> structure map for " + version);
                while (rs.Read())
                {
                    string messageType = string.Format("{0}_{1}", rs["message_typ_snd"], rs["event_code"]);
                    string structure   = (string)rs["message_structure_snd"];

                    sw.WriteLine(string.Format("{0} {1}", messageType, structure));
                    Console.WriteLine(string.Format("Mapping Event {0} to {1}", messageType, structure));
                }
            }
        }
示例#2
0
        /// <summary>
        /// Creates skeletal source code (without correct data structure but no business logic) for all
        /// data types found in the normative database.  For versions > 2.2, Primitive data types are not
        /// generated, because they are coded manually (as of HAPI 0.3).
        /// </summary>
        ///
        /// <param name="baseDirectory">    Pathname of the base directory. </param>
        /// <param name="version">          the HL7 version of the intended data type. </param>

        public static void makeAll(System.String baseDirectory, System.String version)
        {
            //make base directory
            if (!(baseDirectory.EndsWith("\\") || baseDirectory.EndsWith("/")))
            {
                baseDirectory = baseDirectory + "/";
            }
            System.IO.FileInfo targetDir =
                SourceGenerator.makeDirectory(
                    baseDirectory + PackageManager.GetVersionPackagePath(version) + "Datatype");
            SourceGenerator.makeDirectory(baseDirectory + PackageManager.GetVersionPackagePath(version) + "Datatype");
            //get list of data types
            System.Collections.ArrayList      types = new System.Collections.ArrayList();
            System.Data.OleDb.OleDbConnection conn  = NormativeDatabase.Instance.Connection;
            System.Data.OleDb.OleDbCommand    stmt  = SupportClass.TransactionManager.manager.CreateStatement(conn);
            //get normal data types ...
            System.Data.OleDb.OleDbCommand temp_OleDbCommand;
            temp_OleDbCommand             = stmt;
            temp_OleDbCommand.CommandText =
                "select data_type_code from HL7DataTypes, HL7Versions where HL7Versions.version_id = HL7DataTypes.version_id and HL7Versions.hl7_version = '"
                + version + "'";
            System.Data.OleDb.OleDbDataReader rs = temp_OleDbCommand.ExecuteReader();
            while (rs.Read())
            {
                types.Add(System.Convert.ToString(rs[1 - 1]));
            }
            rs.Close();
            //get CF, CK, CM, CN, CQ sub-types ...

            System.Data.OleDb.OleDbCommand temp_OleDbCommand2;
            temp_OleDbCommand2             = stmt;
            temp_OleDbCommand2.CommandText = "select data_structure from HL7DataStructures, HL7Versions where ("
                                             + "data_type_code  = 'CF' or " + "data_type_code  = 'CK' or "
                                             + "data_type_code  = 'CM' or " + "data_type_code  = 'CN' or "
                                             + "data_type_code  = 'CQ') and "
                                             + "HL7Versions.version_id = HL7DataStructures.version_id and  HL7Versions.hl7_version = '"
                                             + version + "'";
            rs = temp_OleDbCommand2.ExecuteReader();
            while (rs.Read())
            {
                types.Add(System.Convert.ToString(rs[1 - 1]));
            }

            stmt.Dispose();
            NormativeDatabase.Instance.returnConnection(conn);

            System.Console.Out.WriteLine("Generating " + types.Count + " datatypes for version " + version);
            if (types.Count == 0)
            {
                log.Warn("No version " + version + " data types found in database " + conn.Database);
            }

            for (int i = 0; i < types.Count; i++)
            {
                if (!((String)types[i]).Equals("*"))
                {
                    make(targetDir, (System.String)types[i], version);
                }
            }
        }
示例#3
0
        /// <summary>
        /// Creates source code for a Group and returns a GroupDef object that describes the Group's name,
        /// optionality, repeatability.  The source code is written under the given directory. The
        /// structures list may contain [] and {} pairs representing nested groups and their optionality
        /// and repeastability.  In these cases this method is called recursively. If the given
        /// structures list begins and ends with repetition and/or optionality markers the repetition and
        /// optionality of the returned GroupDef are set accordingly.
        /// </summary>
        ///
        /// <param name="structures">       a list of the structures that comprise this group - must be
        ///                                 at least 2 long. </param>
        /// <param name="groupName">        The group name. </param>
        /// <param name="baseDirectory">    the directory to which files should be written. </param>
        /// <param name="version">          The version of message. </param>
        /// <param name="message">          the message to which this group belongs. </param>
        ///
        /// <returns>   A GroupDef. </returns>

        public static GroupDef writeGroup(
            IStructureDef[] structures,
            System.String groupName,
            System.String baseDirectory,
            System.String version,
            System.String message)
        {
            //make base directory
            if (!(baseDirectory.EndsWith("\\") || baseDirectory.EndsWith("/")))
            {
                baseDirectory = baseDirectory + "/";
            }
            System.IO.FileInfo targetDir =
                SourceGenerator.makeDirectory(baseDirectory + PackageManager.GetVersionPackagePath(version) + "Group");

            GroupDef group = getGroupDef(structures, groupName, baseDirectory, version, message);

            using (
                System.IO.StreamWriter out_Renamed =
                    new System.IO.StreamWriter(targetDir.FullName + "/" + group.Name + ".cs"))
            {
                out_Renamed.Write(makePreamble(group, version));
                out_Renamed.Write(makeConstructor(group, version));

                IStructureDef[] shallow = group.Structures;
                for (int i = 0; i < shallow.Length; i++)
                {
                    out_Renamed.Write(makeAccessor(group, i));
                }
                out_Renamed.Write("}\r\n"); //Closing class
                out_Renamed.Write("}\r\n"); //Closing namespace
            }
            return(group);
        }
示例#4
0
        /// <summary> Creates source code for a Group and returns a GroupDef object that
        /// describes the Group's name, optionality, repeatability.  The source
        /// code is written under the given directory.
        /// The structures list may contain [] and {} pairs representing
        /// nested groups and their optionality and repeastability.  In these cases
        /// this method is called recursively.
        /// If the given structures list begins and ends with repetition and/or
        /// optionality markers the repetition and optionality of the returned
        /// GroupDef are set accordingly.
        /// <param name="structures">a list of the structures that comprise this group - must
        /// be at least 2 long
        /// </param>
        /// <param name="groupName">The group name</param>
        /// <param name="version">The version of message</param>
        /// <param name="baseDirectory">the directory to which files should be written
        /// </param>
        /// <param name="message">the message to which this group belongs
        /// </param>
        /// <throws>  HL7Exception if the repetition and optionality markers are not  </throws>
        /// </summary>
        public static GroupDef writeGroup(IStructureDef[] structures, String groupName, String baseDirectory, String version,
                                          String message)
        {
            //make base directory
            if (!(baseDirectory.EndsWith("\\") || baseDirectory.EndsWith("/")))
            {
                baseDirectory = baseDirectory + "/";
            }
            FileInfo targetDir =
                SourceGenerator.makeDirectory(baseDirectory + PackageManager.GetVersionPackagePath(version) + "Group");

            // some group names are troublesome and have "/" which will cause problems when writing files
            groupName = groupName.Replace("/", "_");
            GroupDef group = getGroupDef(structures, groupName, baseDirectory, version, message);

            using (StreamWriter out_Renamed = new StreamWriter(targetDir.FullName + @"\" + group.Name + ".cs"))
            {
                out_Renamed.Write(makePreamble(group, version));
                out_Renamed.Write(makeConstructor(group, version));

                IStructureDef[] shallow = group.Structures;
                for (int i = 0; i < shallow.Length; i++)
                {
                    out_Renamed.Write(makeAccessor(group, i));
                }
                out_Renamed.Write("}\r\n");                 //Closing class
                out_Renamed.Write("}\r\n");                 //Closing namespace
            }
            return(group);
        }
示例#5
0
        public static void makeAll(String baseDirectory, String version)
        {
            //make base directory
            if (!(baseDirectory.EndsWith("\\") || baseDirectory.EndsWith("/")))
            {
                baseDirectory = baseDirectory + "/";
            }
            FileInfo targetDir =
                SourceGenerator.makeDirectory(baseDirectory + PackageManager.GetVersionPackagePath(version) + "EventMapping");

            var       log = DataProviderFactory.Instance.GetProvider <IEventMappingProvider>(null);
            ArrayList messageTypes;
            ArrayList events;
            ArrayList messageStructures;

            log.GetMessageMapping(version, out messageTypes, out events, out messageStructures);
            using (StreamWriter sw = new StreamWriter(targetDir.FullName + @"\EventMap.properties", false))
            {
                sw.WriteLine("#event -> structure map for " + version);
                for (int i = 0; i < messageTypes.Count; i++)
                {
                    string messageType = string.Format("{0}_{1}", messageTypes[i], events[i]);
                    string structure   = (string)messageStructures[i];

                    sw.WriteLine(string.Format("{0} {1}", messageType, structure));
                }
            }
        }
示例#6
0
        /// <summary> <p>Creates skeletal source code (without correct data structure but no business
        /// logic) for all segments found in the normative database.  </p>
        /// </summary>
        public static void makeAll(String baseDirectory, String version)
        {
            //make base directory
            if (!(baseDirectory.EndsWith("\\") || baseDirectory.EndsWith("/")))
            {
                baseDirectory = baseDirectory + "/";
            }
            FileInfo targetDir =
                SourceGenerator.makeDirectory(baseDirectory + PackageManager.GetVersionPackagePath(version) + "Segment");

            //get list of data types
            OleDbConnection conn = NormativeDatabase.Instance.Connection;
            String          sql  =
                "SELECT seg_code, [section] from HL7Segments, HL7Versions where HL7Segments.version_id = HL7Versions.version_id AND hl7_version = '" +
                version + "'";
            OleDbCommand temp_OleDbCommand = new OleDbCommand();

            temp_OleDbCommand.Connection  = conn;
            temp_OleDbCommand.CommandText = sql;
            OleDbDataReader rs = temp_OleDbCommand.ExecuteReader();


            ArrayList segments = new ArrayList();

            while (rs.Read())
            {
                String segName = Convert.ToString(rs[1 - 1]);
                if (Char.IsLetter(segName[0]))
                {
                    segments.Add(altSegName(segName));
                }
            }
            temp_OleDbCommand.Dispose();
            NormativeDatabase.Instance.returnConnection(conn);

            if (segments.Count == 0)
            {
                log.Warn("No version " + version + " segments found in database " + conn.Database);
            }

            for (int i = 0; i < segments.Count; i++)
            {
                try
                {
                    String seg    = (String)segments[i];
                    String source = makeSegment(seg, version);
                    using (StreamWriter w = new StreamWriter(targetDir.ToString() + @"\" + GetSpecialFilename(seg) + ".cs"))
                    {
                        w.Write(source);
                        w.Write("}");
                    }
                }
                catch (Exception e)
                {
                    Console.Error.WriteLine("Error creating source code for all segments: " + e.Message);
                    SupportClass.WriteStackTrace(e, Console.Error);
                }
            }
        }
示例#7
0
        /// <summary>
        /// Creates source code for a specific message structure and writes it under the specified
        /// directory. throws IllegalArgumentException if there is no message structure for this message
        /// in the normative database.
        /// </summary>
        ///
        /// <param name="message">          The message. </param>
        /// <param name="baseDirectory">    Pathname of the base directory. </param>
        /// <param name="chapter">          The chapter. </param>
        /// <param name="version">          The version. </param>

        public static void make(
            System.String message,
            System.String baseDirectory,
            System.String chapter,
            System.String version)
        {
            try
            {
                SegmentDef[] segments = getSegments(message, version);
                //System.out.println("Making: " + message + " with " + segments.length + " segments (not writing message code - just groups)");

                GroupDef        group    = GroupGenerator.getGroupDef(segments, null, baseDirectory, version, message);
                IStructureDef[] contents = group.Structures;

                //make base directory
                if (!(baseDirectory.EndsWith("\\") || baseDirectory.EndsWith("/")))
                {
                    baseDirectory = baseDirectory + "/";
                }

                System.IO.FileInfo targetDir =
                    SourceGenerator.makeDirectory(
                        baseDirectory + PackageManager.GetVersionPackagePath(version) + "Message");
                System.Console.Out.WriteLine("Writing " + message + " to " + targetDir.FullName);
                using (
                    System.IO.StreamWriter out_Renamed =
                        new System.IO.StreamWriter(targetDir.FullName + "/" + message + ".cs"))
                {
                    out_Renamed.Write(makePreamble(contents, message, chapter, version));
                    out_Renamed.Write(makeConstructor(contents, message, version));
                    for (int i = 0; i < contents.Length; i++)
                    {
                        out_Renamed.Write(GroupGenerator.makeAccessor(group, i));
                    }

                    //add implementation of model.control interface, if any
                    out_Renamed.Write("}\r\n"); //End class
                    out_Renamed.Write("}\r\n"); //End namespace
                }
            }
            catch (System.Exception e)
            {
                log.Error("Error while creating source code", e);

                log.Warn(
                    "Warning: could not write source code for message structure " + message + " - "
                    + e.GetType().FullName + ": " + e.Message);
            }
        }
示例#8
0
        /// <summary> <p>Creates skeletal source code (without correct data structure but no business
        /// logic) for all segments found in the normative database.  </p>
        /// </summary>
        public static void makeAll(String baseDirectory, String version)
        {
            //make base directory
            if (!(baseDirectory.EndsWith("\\") || baseDirectory.EndsWith("/")))
            {
                baseDirectory = baseDirectory + "/";
            }
            FileInfo targetDir =
                SourceGenerator.makeDirectory(baseDirectory + PackageManager.GetVersionPackagePath(version) + "Segment");

            var       segmentSource = DataProviderFactory.Instance.GetProvider <ISegmentProvider>(log);
            ArrayList rawSegments   = segmentSource.GetSegmentNames(version);
            ArrayList segments      = new ArrayList();

            for (int i = 0; i < rawSegments.Count; i++)
            {
                segments.Add(altSegName((String)rawSegments[i]));
            }

            for (int i = 0; i < segments.Count; i++)
            {
                try
                {
                    String seg    = (String)segments[i];
                    String source = makeSegment(seg, version);
                    using (StreamWriter w = new StreamWriter(targetDir.ToString() + @"\" + GetSpecialFilename(seg) + ".cs"))
                    {
                        w.Write(source);
                        w.Write("}");
                    }
                }
                catch (Exception e)
                {
                    Console.Error.WriteLine("Error creating source code for all segments: " + e.Message);
                    SupportClass.WriteStackTrace(e, Console.Error);
                }
            }
        }
示例#9
0
        /// <summary> Creates skeletal source code (without correct data structure but no business
        /// logic) for all data types found in the normative database.  For versions > 2.2, Primitive data types
        /// are not generated, because they are coded manually (as of HAPI 0.3).
        /// </summary>
        public static void makeAll(String baseDirectory, String version)
        {
            //make base directory
            if (!(baseDirectory.EndsWith("\\") || baseDirectory.EndsWith("/")))
            {
                baseDirectory = baseDirectory + "/";
            }
            FileInfo targetDir =
                SourceGenerator.makeDirectory(baseDirectory + PackageManager.GetVersionPackagePath(version) + "Datatype");

            SourceGenerator.makeDirectory(baseDirectory + PackageManager.GetVersionPackagePath(version) + "Datatype");

            var       dataTypeSource = DataProviderFactory.Instance.GetProvider <IDataTypeProvider>(log);
            ArrayList types          = dataTypeSource.GetTypeNames(version);

            foreach (string type in types.Cast <string>())
            {
                if (!type.Equals("*"))
                {
                    make(targetDir, type, version);
                }
            }
        }
示例#10
0
        /// <summary> Returns the Java source code for a class that represents the specified segment.</summary>
        public static String makeSegment(String name, String version)
        {
            Console.WriteLine("Making segment " + name);
            StringBuilder source = new StringBuilder();

            try
            {
                ArrayList       elements = new ArrayList();
                SegmentElement  se;
                String          segDesc = null;
                OleDbConnection conn    = NormativeDatabase.Instance.Connection;
                StringBuilder   sql     = new StringBuilder();
                sql.Append("SELECT HL7SegmentDataElements.seg_code, HL7SegmentDataElements.seq_no, ");
                sql.Append("HL7SegmentDataElements.repetitional, HL7SegmentDataElements.repetitions, ");
                sql.Append("HL7DataElements.description, HL7DataElements.length_old, HL7DataElements.table_id, ");
                sql.Append("HL7SegmentDataElements.req_opt, HL7Segments.description, HL7DataElements.data_structure ");
                sql.Append(
                    "FROM HL7Versions RIGHT JOIN (HL7Segments INNER JOIN (HL7DataElements INNER JOIN HL7SegmentDataElements ");
                sql.Append("ON (HL7DataElements.version_id = HL7SegmentDataElements.version_id) ");
                sql.Append("AND (HL7DataElements.data_item = HL7SegmentDataElements.data_item)) ");
                sql.Append("ON (HL7Segments.version_id = HL7SegmentDataElements.version_id) ");
                sql.Append("AND (HL7Segments.seg_code = HL7SegmentDataElements.seg_code)) ");
                sql.Append("ON (HL7Versions.version_id = HL7Segments.version_id) ");
                sql.Append("WHERE HL7SegmentDataElements.seg_code = '");
                sql.Append(name);
                sql.Append("' and HL7Versions.hl7_version = '");
                sql.Append(version);
                sql.Append("' ORDER BY HL7SegmentDataElements.seg_code, HL7SegmentDataElements.seq_no;");
                OleDbCommand stmt = SupportClass.TransactionManager.manager.CreateStatement(conn);
                OleDbCommand temp_OleDbCommand;
                temp_OleDbCommand             = stmt;
                temp_OleDbCommand.CommandText = sql.ToString();
                OleDbDataReader rs = temp_OleDbCommand.ExecuteReader();

                while (rs.Read())
                {
                    if (segDesc == null)
                    {
                        segDesc = Convert.ToString(rs[9 - 1]);
                    }
                    se       = new SegmentElement();
                    se.field = Convert.ToInt32(rs.GetValue(2 - 1));
                    se.rep   = Convert.ToString(rs[3 - 1]);
                    if (rs.IsDBNull(4 - 1))
                    {
                        se.repetitions = 0;
                    }
                    else
                    {
                        se.repetitions = Convert.ToInt32(rs.GetValue(4 - 1));
                    }

                    if (se.repetitions == 0)
                    {
                        if (se.rep == null || !se.rep.ToUpper().Equals("Y".ToUpper()))
                        {
                            se.repetitions = 1;
                        }
                    }
                    se.desc = Convert.ToString(rs[5 - 1]);
                    if (!rs.IsDBNull(6 - 1))
                    {
                        se.length = DetermineLength(rs);
                    }

                    se.table = Convert.ToInt32(rs.GetValue(7 - 1));
                    se.opt   = Convert.ToString(rs[8 - 1]);
                    se.type  = Convert.ToString(rs[10 - 1]);
                    //shorten CE_x to CE
                    if (se.type.StartsWith("CE"))
                    {
                        se.type = "CE";
                    }

                    elements.Add(se);

                    /*System.out.println("Segment: " + name + " Field: " + se.field + " Rep: " + se.rep +
                     *              " Repetitions: " + se.repetitions + " Desc: " + se.desc + " Length: " + se.length +
                     *              " Table: " + se.table + " Segment Desc: " + segDesc);*/
                }
                rs.Close();
                stmt.Dispose();
                NormativeDatabase.Instance.returnConnection(conn);

                //write imports, class documentation, etc ...
                source.Append("using System;\r\n");
                source.Append("using NHapi.Base;\r\n");
                source.Append("using NHapi.Base.Parser;\r\n");
                source.Append("using NHapi.Base.Model;\r\n");
                source.Append("using ");
                source.Append(PackageManager.GetVersionPackageName(version));
                source.Append("Datatype;\r\n");
                source.Append("using NHapi.Base.Log;\r\n\r\n");

                source.Append("namespace ");
                source.Append(PackageManager.GetVersionPackageName(version));
                source.Append("Segment{\r\n\r\n");
                source.Append("///<summary>\r\n");
                source.Append("/// Represents an HL7 ");
                source.Append(name);
                source.Append(" message segment. \r\n");
                source.Append("/// This segment has the following fields:<ol>\r\n");

                PrepareAppendStringsForElementsWithDuplicateDescriptions(name, elements);

                for (int i = 0; i < elements.Count; i++)
                {
                    se = (SegmentElement)elements[i];
                    source.Append("///");
                    source.Append("<li>");
                    source.Append(name);
                    source.Append("-");
                    source.Append(se.field);
                    source.Append(": ");
                    source.Append(se.GetDescriptionWithoutSpecialCharacters());
                    source.Append(" (");
                    source.Append(se.type);
                    source.Append(")</li>\r\n");
                }
                source.Append("///</ol>\r\n");
                source.Append("/// The get...() methods return data from individual fields.  These methods \r\n");
                source.Append("/// do not throw exceptions and may therefore have to handle exceptions internally.  \r\n");
                source.Append("/// If an exception is handled internally, it is logged and null is returned.  \r\n");
                source.Append("/// This is not expected to happen - if it does happen this indicates not so much \r\n");
                source.Append("/// an exceptional circumstance as a bug in the code for this class.\r\n");
                source.Append("///</summary>\r\n");
                source.Append("[Serializable]\r\n");
                source.Append("public class ");
                source.Append(name);
                source.Append(" : AbstractSegment ");

                //implement interface from Model.control package if required

                /*Class correspondingControlInterface = Control.getInterfaceImplementedBy(name);
                 * if (correspondingControlInterface != null) {
                 * source.append("implements ");
                 * source.append(correspondingControlInterface.getName());
                 * } */

                source.Append(" {\r\n\r\n");
                source.Append("  /**\r\n");
                source.Append("   * Creates a ");
                source.Append(name);
                source.Append(" (");
                source.Append(segDesc);
                source.Append(") segment object that belongs to the given \r\n");
                source.Append("   * message.  \r\n");
                source.Append("   */\r\n");

                //write constructor
                source.Append("\tpublic ");
                source.Append(name);
                source.Append("(IGroup parent, IModelClassFactory factory) : base(parent,factory) {\r\n");
                source.Append("\tIMessage message = Message;\r\n");
                if (elements.Count > 0)
                {
                    source.Append("    try {\r\n");
                    for (int i = 0; i < elements.Count; i++)
                    {
                        se = (SegmentElement)elements[i];
                        String type = SourceGenerator.getAlternateType(se.type, version);
                        source.Append("       this.add(");
                        source.Append("typeof(" + type + ")");
                        //                    if (type.equalsIgnoreCase("Varies")) {
                        //                    } else {
                        //                        source.append("factory.getTypeClass(\"");
                        //                        source.append(type);
                        //                        source.append("\", \"");
                        //                        source.append(version);
                        //                        source.append("\")");
                        //                    }
                        source.Append(", ");
                        if (se.opt == null)
                        {
                            source.Append("false");
                        }
                        else
                        {
                            if (se.opt.ToUpper().Equals("R".ToUpper()))
                            {
                                source.Append("true");
                            }
                            else
                            {
                                source.Append("false");
                            }
                        }
                        source.Append(", ");
                        source.Append(se.repetitions);
                        source.Append(", ");
                        source.Append(se.length);
                        source.Append(", ");
                        if (se.type.Equals("ID") || se.type.Equals("IS"))
                        {
                            source.Append("new System.Object[]{message, ");
                            source.Append(se.table);
                            source.Append("}");
                        }
                        else
                        {
                            source.Append("new System.Object[]{message}");
                        }
                        if (se.desc != null && se.desc.Trim().Length > 0)
                        {
                            source.Append(", ");


                            source.Append("\"" + se.GetDescriptionWithoutSpecialCharacters() + "\"");
                        }
                        source.Append(");\r\n");
                    }
                    source.Append("    } catch (HL7Exception he) {\r\n");
                    source.Append(
                        "        HapiLogFactory.GetHapiLog(GetType()).Error(\"Can't instantiate \" + GetType().Name, he);\r\n");
                    source.Append("    }\r\n");
                }
                source.Append("  }\r\n\r\n");

                //write a datatype-specific accessor for each field
                for (int i = 0; i < elements.Count; i++)
                {
                    se = (SegmentElement)elements[i];
                    if (!se.desc.ToUpper().Equals("UNUSED".ToUpper()))
                    {
                        //some entries in 2.1 DB say "unused"
                        String type = SourceGenerator.getAlternateType(se.type, version);
                        source.Append("\t///<summary>\r\n");
                        source.Append("\t/// Returns ");
                        if (se.repetitions != 1)
                        {
                            source.Append("a single repetition of ");
                        }
                        source.Append(se.GetDescriptionWithoutSpecialCharacters());
                        source.Append("(");
                        source.Append(name);
                        source.Append("-");
                        source.Append(se.field);
                        source.Append(").\r\n");
                        if (se.repetitions != 1)
                        {
                            source.Append("\t/// throws HL7Exception if the repetition number is invalid.\r\n");
                            source.Append("\t/// <param name=\"rep\">The repetition number (this is a repeating field)</param>\r\n");
                        }
                        source.Append("\t///</summary>\r\n");
                        source.Append("\tpublic ");
                        source.Append(type);
                        source.Append(" ");
                        source.Append(SourceGenerator.MakeAccessorName(se.desc, se.repetitions) + se.AccessorNameToAppend);
                        if (se.repetitions != 1)
                        {
                            source.Append("(int rep)");
                        }
                        source.Append("\n\t{\r\n");
                        if (se.repetitions == 1)
                        {
                            source.Append("\t\tget{\r\n");
                        }
                        source.Append("\t\t\t");
                        source.Append(type);
                        source.Append(" ret = null;\r\n");
                        source.Append("\t\t\ttry\n\t\t\t{\r\n");
                        source.Append("\t\t\tIType t = this.GetField(");
                        source.Append(se.field);
                        source.Append(", ");
                        if (se.repetitions == 1)
                        {
                            source.Append("0");
                        }
                        else
                        {
                            source.Append("rep");
                        }
                        source.Append(");\r\n");
                        source.Append("\t\t\t\tret = (");
                        source.Append(type);
                        source.Append(")t;\r\n");
                        if (se.repetitions == 1)
                        {
                            source.Append("\t\t\t}\n\t\t\t catch (HL7Exception he) {\r\n");
                            source.Append(
                                "\t\t\tHapiLogFactory.GetHapiLog(GetType()).Error(\"Unexpected problem obtaining field value.  This is a bug.\", he);\r\n");
                            source.Append("\t\t\t\tthrow new System.Exception(\"An unexpected error ocurred\", he);\r\n");
                        }
                        source.Append("\t\t} catch (System.Exception ex) {\r\n");
                        source.Append(
                            "\t\t\tHapiLogFactory.GetHapiLog(GetType()).Error(\"Unexpected problem obtaining field value.  This is a bug.\", ex);\r\n");
                        source.Append("\t\t\t\tthrow new System.Exception(\"An unexpected error ocurred\", ex);\r\n");
                        source.Append("    }\r\n");
                        source.Append("\t\t\treturn ret;\r\n");
                        if (se.repetitions == 1)
                        {
                            source.Append("\t}\r\n");                             //End get
                        }
                        source.Append("  }\r\n\r\n");


                        //add an array accessor as well for repeating fields
                        if (se.repetitions != 1)
                        {
                            source.Append("  ///<summary>\r\n");
                            source.Append("  /// Returns all repetitions of ");
                            source.Append(se.GetDescriptionWithoutSpecialCharacters());
                            source.Append(" (");
                            source.Append(name);
                            source.Append("-");
                            source.Append(se.field);
                            source.Append(").\r\n");
                            source.Append("   ///</summary>\r\n");
                            source.Append("  public ");
                            source.Append(type);
                            source.Append("[] Get");
                            source.Append(SourceGenerator.MakeAccessorName(se.desc) + se.AccessorNameToAppend);
                            source.Append("() {\r\n");
                            source.Append("     ");
                            source.Append(type);
                            source.Append("[] ret = null;\r\n");
                            source.Append("    try {\r\n");
                            source.Append("        IType[] t = this.GetField(");
                            source.Append(se.field);
                            source.Append(");  \r\n");
                            source.Append("        ret = new ");
                            source.Append(type);
                            source.Append("[t.Length];\r\n");
                            source.Append("        for (int i = 0; i < ret.Length; i++) {\r\n");
                            source.Append("            ret[i] = (");
                            source.Append(type);
                            source.Append(")t[i];\r\n");
                            source.Append("        }\r\n");
                            source.Append("    } catch (HL7Exception he) {\r\n");
                            source.Append(
                                "        HapiLogFactory.GetHapiLog(this.GetType()).Error(\"Unexpected problem obtaining field value.  This is a bug.\", he);\r\n");
                            source.Append("        throw new System.Exception(\"An unexpected error ocurred\", he);\r\n");
                            source.Append("    } catch (System.Exception cce) {\r\n");
                            source.Append(
                                "        HapiLogFactory.GetHapiLog(GetType()).Error(\"Unexpected problem obtaining field value.  This is a bug.\", cce);\r\n");
                            source.Append("        throw new System.Exception(\"An unexpected error ocurred\", cce);\r\n");
                            source.Append("  }\r\n");
                            source.Append(" return ret;\r\n");
                            source.Append("}\r\n\r\n");

                            //Add property for the total repetitions of this object
                            source.Append("  ///<summary>\r\n");
                            source.Append("  /// Returns the total repetitions of ");
                            source.Append(se.GetDescriptionWithoutSpecialCharacters());
                            source.Append(" (");
                            source.Append(name);
                            source.Append("-");
                            source.Append(se.field);
                            source.Append(").\r\n");
                            source.Append("   ///</summary>\r\n");
                            source.Append("  public int ");
                            source.Append(SourceGenerator.MakeName(se.desc) + se.AccessorNameToAppend);
                            source.Append("RepetitionsUsed\r\n");
                            source.Append("{\r\n");
                            source.Append("get{\r\n");
                            source.Append("    try {\r\n");
                            source.Append("\treturn GetTotalFieldRepetitionsUsed(" + se.field + ");\r\n");
                            source.Append("    }\r\n");
                            source.Append("catch (HL7Exception he) {\r\n");
                            source.Append(
                                "        HapiLogFactory.GetHapiLog(this.GetType()).Error(\"Unexpected problem obtaining field value.  This is a bug.\", he);\r\n");
                            source.Append("        throw new System.Exception(\"An unexpected error ocurred\", he);\r\n");
                            source.Append("} catch (System.Exception cce) {\r\n");
                            source.Append(
                                "        HapiLogFactory.GetHapiLog(GetType()).Error(\"Unexpected problem obtaining field value.  This is a bug.\", cce);\r\n");
                            source.Append("        throw new System.Exception(\"An unexpected error ocurred\", cce);\r\n");
                            source.Append("}\r\n");
                            source.Append("}\r\n");
                            source.Append("}\r\n");
                        }
                    }
                }

                //add adapter method code for control package if it exists
                //source.append(Control.getImplementation(correspondingControlInterface, version));

                source.Append("\n}");
            }
            catch (OleDbException sqle)
            {
                SupportClass.WriteStackTrace(sqle, Console.Error);
            }

            return(source.ToString());
        }
示例#11
0
        /// <summary> Returns a String containing source code for a Composite data type. The
        /// dataTypes array contains the data type names (e.g. ST) of each component.
        /// The descriptions array contains the corresponding descriptions (e.g. string).
        /// </summary>
        private static String makeComposite(String dataType, String description, String[] dataTypes, String[] descriptions,
                                            int[] tables, String version)
        {
            StringBuilder source = new StringBuilder();

            source.Append("using System;\n");
            source.Append("using NHapi.Base.Model;\n");
            source.Append("using NHapi.Base.Log;\n");
            source.Append("using NHapi.Base;\n");
            source.Append("using NHapi.Base.Model.Primitive;\r\n\r\n");
            source.Append("namespace ");
            source.Append(PackageManager.GetVersionPackageName(version));
            source.Append("Datatype\r\n");
            source.Append("{\r\n\r\n");
            source.Append("///<summary>\r\n");
            source.Append("/// <p>The HL7 ");
            source.Append(dataType);
            source.Append(" (");
            source.Append(description);
            source.Append(") data type.  Consists of the following components: </p><ol>\r\n");
            for (int i = 0; i < dataTypes.Length; i++)
            {
                source.Append("/// <li>");
                source.Append(GetDescription(descriptions[i]));
                source.Append(" (");
                source.Append(dataTypes[i]);
                source.Append(")</li>\r\n");
            }
            source.Append("/// </ol>\r\n");
            source.Append("///</summary>\r\n");
            source.Append("[Serializable]\r\n");
            source.Append("public class ");
            source.Append(dataType);
            source.Append(" : AbstractType, IComposite");
            source.Append("{\r\n");
            source.Append("\tprivate IType[] data;\r\n\r\n");
            source.Append("\t///<summary>\r\n");
            source.Append("\t/// Creates a ");
            source.Append(dataType);
            source.Append(".\r\n");
            source.Append("\t/// <param name=\"message\">The Message to which this Type belongs</param>\r\n");
            source.Append("\t///</summary>\r\n");
            source.Append("\tpublic ");
            source.Append(dataType);
            source.Append("(IMessage message) : this(message, null){}\r\n\r\n");
            source.Append("\t///<summary>\r\n");
            source.Append("\t/// Creates a ");
            source.Append(dataType);
            source.Append(".\r\n");
            source.Append("\t/// <param name=\"message\">The Message to which this Type belongs</param>\r\n");
            source.Append("\t/// <param name=\"description\">The description of this type</param>\r\n");
            source.Append("\t///</summary>\r\n");
            source.Append("\tpublic ");
            source.Append(dataType);
            source.Append("(IMessage message, string description) : base(message, description){\r\n");
            source.Append("\t\tdata = new IType[");
            source.Append(dataTypes.Length);
            source.Append("];\r\n");
            for (int i = 0; i < dataTypes.Length; i++)
            {
                source.Append("\t\tdata[");
                source.Append(i);
                source.Append("] = new ");
                source.Append(SourceGenerator.getAlternateType(dataTypes[i], version));
                if (dataTypes[i].Equals("ID") || dataTypes[i].Equals("IS"))
                {
                    source.Append("(message, ");
                    source.Append(tables[i]);
                }
                else
                {
                    source.Append("(message");
                }
                if (descriptions[i] != null && descriptions[i].Trim().Length > 0)
                {
                    string desc = descriptions[i];
                    desc = desc.Replace("\"", "'");
                    desc = desc.Substring(0, 1).ToUpper() + desc.Substring(1);
                    source.Append(",\"" + desc + "\"");
                }
                source.Append(")");
                source.Append(";\r\n");
            }
            source.Append("\t}\r\n\r\n");
            source.Append("\t///<summary>\r\n");
            source.Append("\t/// Returns an array containing the data elements.\r\n");
            source.Append("\t///</summary>\r\n");
            source.Append("\tpublic IType[] Components\r\n");
            source.Append("\t{ \r\n");
            source.Append("\t\tget{\r\n");
            source.Append("\t\t\treturn this.data; \r\n");
            source.Append("\t\t}\r\n");
            source.Append("\t}\r\n\r\n");
            source.Append("\t///<summary>\r\n");
            source.Append("\t/// Returns an individual data component.\r\n");
            source.Append("\t/// @throws DataTypeException if the given element number is out of range.\r\n");
            source.Append("\t///<param name=\"index\">The index item to get (zero based)</param>\r\n");
            source.Append("\t///<returns>The data component (as a type) at the requested number (ordinal)</returns>\r\n");
            source.Append("\t///</summary>\r\n");
            source.Append("\tpublic IType this[int index] { \r\n\r\n");
            source.Append("get{\r\n");
            source.Append("\t\ttry { \r\n");
            source.Append("\t\t\treturn this.data[index]; \r\n");
            source.Append("\t\t} catch (System.ArgumentOutOfRangeException) { \r\n");
            source.Append("\t\t\tthrow new DataTypeException(\"Element \" + index + \" doesn't exist in ");
            source.Append(dataTypes.Length);
            source.Append(" element ");
            source.Append(dataType);
            source.Append(" composite\"); \r\n");
            source.Append("\t\t} \r\n");
            source.Append("\t} \r\n");
            source.Append("\t} \r\n");
            //make type-specific accessors ...
            for (int i = 0; i < dataTypes.Length; i++)
            {
                String dtName = SourceGenerator.getAlternateType(dataTypes[i], version);
                source.Append("\t///<summary>\r\n");
                source.Append("\t/// Returns ");
                source.Append(GetDescription(descriptions[i]));
                source.Append(" (component #");
                source.Append(i);
                source.Append(").  This is a convenience method that saves you from \r\n");
                source.Append("\t/// casting and handling an exception.\r\n");
                source.Append("\t///</summary>\r\n");
                source.Append("\tpublic ");
                source.Append(dtName);
                source.Append(" ");
                source.Append(SourceGenerator.MakeAccessorName(descriptions[i]));
                bool duplicateField = descriptions.Count(element => GetDescription(element) == GetDescription(descriptions[i])) > 1;
                if (duplicateField)
                {
                    source.Append("_" + i);
                }
                source.Append(" {\r\n");
                source.Append("get{\r\n");
                source.Append("\t   ");
                source.Append(dtName);
                source.Append(" ret = null;\r\n");
                source.Append("\t   try {\r\n");
                source.Append("\t      ret = (");
                source.Append(dtName);
                source.Append(")this[");
                source.Append(i);
                source.Append("];\r\n");
                source.Append("\t   } catch (DataTypeException e) {\r\n");
                source.Append(
                    "\t      HapiLogFactory.GetHapiLog(this.GetType()).Error(\"Unexpected problem accessing known data type component - this is a bug.\", e);\r\n");
                source.Append("\t      throw new System.Exception(\"An unexpected error ocurred\",e);\r\n");
                source.Append("\t   }\r\n");
                source.Append("\t   return ret;\r\n");
                source.Append("}\r\n\r\n");
                source.Append("}\r\n");
            }

            /*if (correspondingControlInterface != null) {
             * source.append(Control.getImplementation(correspondingControlInterface, version));
             * } */
            source.Append("}");

            return(source.ToString());
        }
示例#12
0
        /// <summary> Returns the Java source code for a class that represents the specified segment.</summary>
        public static String makeSegment(String name, String version)
        {
            Console.WriteLine("Making segment " + name);
            StringBuilder source = new StringBuilder();

            try
            {
                ArrayList      elements;
                SegmentElement se;
                string         segDesc;
                var            segmentSource = DataProviderFactory.Instance.GetProvider <ISegmentProvider>(log);
                segmentSource.GetSegmentDefinition(name, version, out elements, out segDesc);

                //write imports, class documentation, etc ...
                source.Append("using System;\r\n");
                source.Append("using NHapi.Base;\r\n");
                source.Append("using NHapi.Base.Parser;\r\n");
                source.Append("using NHapi.Base.Model;\r\n");
                source.Append("using ");
                source.Append(PackageManager.GetVersionPackageName(version));
                source.Append("Datatype;\r\n");
                source.Append("using NHapi.Base.Log;\r\n\r\n");

                source.Append("namespace ");
                source.Append(PackageManager.GetVersionPackageName(version));
                source.Append("Segment{\r\n\r\n");
                source.Append("///<summary>\r\n");
                source.Append("/// Represents an HL7 ");
                source.Append(name);
                source.Append(" message segment. \r\n");
                source.Append("/// This segment has the following fields:<ol>\r\n");

                PrepareAppendStringsForElementsWithDuplicateDescriptions(name, elements);

                for (int i = 0; i < elements.Count; i++)
                {
                    se = (SegmentElement)elements[i];
                    source.Append("///");
                    source.Append("<li>");
                    source.Append(name);
                    source.Append("-");
                    source.Append(se.field);
                    source.Append(": ");
                    source.Append(se.GetDescriptionWithoutSpecialCharacters());
                    source.Append(" (");
                    source.Append(se.type);
                    source.Append(")</li>\r\n");
                }
                source.Append("///</ol>\r\n");
                source.Append("/// The get...() methods return data from individual fields.  These methods \r\n");
                source.Append("/// do not throw exceptions and may therefore have to handle exceptions internally.  \r\n");
                source.Append("/// If an exception is handled internally, it is logged and null is returned.  \r\n");
                source.Append("/// This is not expected to happen - if it does happen this indicates not so much \r\n");
                source.Append("/// an exceptional circumstance as a bug in the code for this class.\r\n");
                source.Append("///</summary>\r\n");
                source.Append("[Serializable]\r\n");
                source.Append("public class ");
                source.Append(name);
                source.Append(" : AbstractSegment ");

                //implement interface from Model.control package if required

                /*Class correspondingControlInterface = Control.getInterfaceImplementedBy(name);
                 *                              if (correspondingControlInterface != null) {
                 *                              source.append("implements ");
                 *                              source.append(correspondingControlInterface.getName());
                 *                              } */

                source.Append(" {\r\n\r\n");
                source.Append("  /**\r\n");
                source.Append("   * Creates a ");
                source.Append(name);
                source.Append(" (");
                source.Append(segDesc);
                source.Append(") segment object that belongs to the given \r\n");
                source.Append("   * message.  \r\n");
                source.Append("   */\r\n");

                //write constructor
                source.Append("\tpublic ");
                source.Append(name);
                source.Append("(IGroup parent, IModelClassFactory factory) : base(parent,factory) {\r\n");
                source.Append("\tIMessage message = Message;\r\n");
                if (elements.Count > 0)
                {
                    source.Append("    try {\r\n");
                    for (int i = 0; i < elements.Count; i++)
                    {
                        se = (SegmentElement)elements[i];
                        String type = SourceGenerator.getAlternateType(se.type, version);
                        source.Append("       this.add(");
                        source.Append("typeof(" + type + ")");
                        //                    if (type.equalsIgnoreCase("Varies")) {
                        //                    } else {
                        //                        source.append("factory.getTypeClass(\"");
                        //                        source.append(type);
                        //                        source.append("\", \"");
                        //                        source.append(version);
                        //                        source.append("\")");
                        //                    }
                        source.Append(", ");
                        if (se.opt == null)
                        {
                            source.Append("false");
                        }
                        else
                        {
                            if (se.opt.ToUpper().Equals("R".ToUpper()))
                            {
                                source.Append("true");
                            }
                            else
                            {
                                source.Append("false");
                            }
                        }
                        source.Append(", ");
                        source.Append(se.repetitions);
                        source.Append(", ");
                        source.Append(se.length);
                        source.Append(", ");
                        if (se.type.Equals("ID") || se.type.Equals("IS"))
                        {
                            source.Append("new System.Object[]{message, ");
                            source.Append(se.table);
                            source.Append("}");
                        }
                        else
                        {
                            source.Append("new System.Object[]{message}");
                        }
                        if (se.desc != null && se.desc.Trim().Length > 0)
                        {
                            source.Append(", ");


                            source.Append("\"" + se.GetDescriptionWithoutSpecialCharacters() + "\"");
                        }
                        source.Append(");\r\n");
                    }
                    source.Append("    } catch (HL7Exception he) {\r\n");
                    source.Append(
                        "        HapiLogFactory.GetHapiLog(GetType()).Error(\"Can't instantiate \" + GetType().Name, he);\r\n");
                    source.Append("    }\r\n");
                }
                source.Append("  }\r\n\r\n");

                //write a datatype-specific accessor for each field
                for (int i = 0; i < elements.Count; i++)
                {
                    se = (SegmentElement)elements[i];
                    if (!se.desc.ToUpper().Equals("UNUSED".ToUpper()))
                    {
                        //some entries in 2.1 DB say "unused"
                        String type = SourceGenerator.getAlternateType(se.type, version);
                        source.Append("\t///<summary>\r\n");
                        source.Append("\t/// Returns ");
                        if (se.repetitions != 1)
                        {
                            source.Append("a single repetition of ");
                        }
                        source.Append(se.GetDescriptionWithoutSpecialCharacters());
                        source.Append("(");
                        source.Append(name);
                        source.Append("-");
                        source.Append(se.field);
                        source.Append(").\r\n");
                        if (se.repetitions != 1)
                        {
                            source.Append("\t/// throws HL7Exception if the repetition number is invalid.\r\n");
                            source.Append("\t/// <param name=\"rep\">The repetition number (this is a repeating field)</param>\r\n");
                        }
                        source.Append("\t///</summary>\r\n");
                        source.Append("\tpublic ");
                        source.Append(type);
                        source.Append(" ");
                        source.Append(SourceGenerator.MakeAccessorName(se.desc, se.repetitions) + se.AccessorNameToAppend);
                        if (se.repetitions != 1)
                        {
                            source.Append("(int rep)");
                        }
                        source.Append("\n\t{\r\n");
                        if (se.repetitions == 1)
                        {
                            source.Append("\t\tget{\r\n");
                        }
                        source.Append("\t\t\t");
                        source.Append(type);
                        source.Append(" ret = null;\r\n");
                        source.Append("\t\t\ttry\n\t\t\t{\r\n");
                        source.Append("\t\t\tIType t = this.GetField(");
                        source.Append(se.field);
                        source.Append(", ");
                        if (se.repetitions == 1)
                        {
                            source.Append("0");
                        }
                        else
                        {
                            source.Append("rep");
                        }
                        source.Append(");\r\n");
                        source.Append("\t\t\t\tret = (");
                        source.Append(type);
                        source.Append(")t;\r\n");
                        if (se.repetitions == 1)
                        {
                            source.Append("\t\t\t}\n\t\t\t catch (HL7Exception he) {\r\n");
                            source.Append(
                                "\t\t\tHapiLogFactory.GetHapiLog(GetType()).Error(\"Unexpected problem obtaining field value.  This is a bug.\", he);\r\n");
                            source.Append("\t\t\t\tthrow new System.Exception(\"An unexpected error ocurred\", he);\r\n");
                        }
                        source.Append("\t\t} catch (System.Exception ex) {\r\n");
                        source.Append(
                            "\t\t\tHapiLogFactory.GetHapiLog(GetType()).Error(\"Unexpected problem obtaining field value.  This is a bug.\", ex);\r\n");
                        source.Append("\t\t\t\tthrow new System.Exception(\"An unexpected error ocurred\", ex);\r\n");
                        source.Append("    }\r\n");
                        source.Append("\t\t\treturn ret;\r\n");
                        if (se.repetitions == 1)
                        {
                            source.Append("\t}\r\n");                             //End get
                        }
                        source.Append("  }\r\n\r\n");


                        //add an array accessor as well for repeating fields
                        if (se.repetitions != 1)
                        {
                            source.Append("  ///<summary>\r\n");
                            source.Append("  /// Returns all repetitions of ");
                            source.Append(se.GetDescriptionWithoutSpecialCharacters());
                            source.Append(" (");
                            source.Append(name);
                            source.Append("-");
                            source.Append(se.field);
                            source.Append(").\r\n");
                            source.Append("   ///</summary>\r\n");
                            source.Append("  public ");
                            source.Append(type);
                            source.Append("[] Get");
                            source.Append(SourceGenerator.MakeAccessorName(se.desc) + se.AccessorNameToAppend);
                            source.Append("() {\r\n");
                            source.Append("     ");
                            source.Append(type);
                            source.Append("[] ret = null;\r\n");
                            source.Append("    try {\r\n");
                            source.Append("        IType[] t = this.GetField(");
                            source.Append(se.field);
                            source.Append(");  \r\n");
                            source.Append("        ret = new ");
                            source.Append(type);
                            source.Append("[t.Length];\r\n");
                            source.Append("        for (int i = 0; i < ret.Length; i++) {\r\n");
                            source.Append("            ret[i] = (");
                            source.Append(type);
                            source.Append(")t[i];\r\n");
                            source.Append("        }\r\n");
                            source.Append("    } catch (HL7Exception he) {\r\n");
                            source.Append(
                                "        HapiLogFactory.GetHapiLog(this.GetType()).Error(\"Unexpected problem obtaining field value.  This is a bug.\", he);\r\n");
                            source.Append("        throw new System.Exception(\"An unexpected error ocurred\", he);\r\n");
                            source.Append("    } catch (System.Exception cce) {\r\n");
                            source.Append(
                                "        HapiLogFactory.GetHapiLog(GetType()).Error(\"Unexpected problem obtaining field value.  This is a bug.\", cce);\r\n");
                            source.Append("        throw new System.Exception(\"An unexpected error ocurred\", cce);\r\n");
                            source.Append("  }\r\n");
                            source.Append(" return ret;\r\n");
                            source.Append("}\r\n\r\n");

                            //Add property for the total repetitions of this object
                            source.Append("  ///<summary>\r\n");
                            source.Append("  /// Returns the total repetitions of ");
                            source.Append(se.GetDescriptionWithoutSpecialCharacters());
                            source.Append(" (");
                            source.Append(name);
                            source.Append("-");
                            source.Append(se.field);
                            source.Append(").\r\n");
                            source.Append("   ///</summary>\r\n");
                            source.Append("  public int ");
                            source.Append(SourceGenerator.MakeName(se.desc) + se.AccessorNameToAppend);
                            source.Append("RepetitionsUsed\r\n");
                            source.Append("{\r\n");
                            source.Append("get{\r\n");
                            source.Append("    try {\r\n");
                            source.Append("\treturn GetTotalFieldRepetitionsUsed(" + se.field + ");\r\n");
                            source.Append("    }\r\n");
                            source.Append("catch (HL7Exception he) {\r\n");
                            source.Append(
                                "        HapiLogFactory.GetHapiLog(this.GetType()).Error(\"Unexpected problem obtaining field value.  This is a bug.\", he);\r\n");
                            source.Append("        throw new System.Exception(\"An unexpected error ocurred\", he);\r\n");
                            source.Append("} catch (System.Exception cce) {\r\n");
                            source.Append(
                                "        HapiLogFactory.GetHapiLog(GetType()).Error(\"Unexpected problem obtaining field value.  This is a bug.\", cce);\r\n");
                            source.Append("        throw new System.Exception(\"An unexpected error ocurred\", cce);\r\n");
                            source.Append("}\r\n");
                            source.Append("}\r\n");
                            source.Append("}\r\n");
                        }
                    }
                }

                //add adapter method code for control package if it exists
                //source.append(Control.getImplementation(correspondingControlInterface, version));

                source.Append("\n}");
            }
            catch (OleDbException sqle)
            {
                SupportClass.WriteStackTrace(sqle, Console.Error);
            }

            return(source.ToString());
        }