예제 #1
0
        /// <summary> Returns heading material for class source code (package, imports, JavaDoc, class
        /// declaration).
        /// </summary>
        public static System.String makePreamble(NuGenGroupDef group, System.String version)
        {
            System.Text.StringBuilder preamble = new System.Text.StringBuilder();
            preamble.Append("package ");
            preamble.Append(NuGenSourceGenerator.getVersionPackageName(version));
            preamble.Append("group;\r\n\r\n");
            preamble.Append("import Genetibase.NuGenHL7.parser.ModelClassFactory;\r\n");
            preamble.Append("import Genetibase.NuGenHL7.HL7Exception;\r\n");
            preamble.Append("import ");
            preamble.Append(NuGenSourceGenerator.getVersionPackageName(version));
            preamble.Append("segment.*;\r\n\r\n");
            preamble.Append("import Genetibase.NuGenHL7.model.*;\r\n");
            preamble.Append("/**\r\n");
            preamble.Append(" * <p>Represents the ");
            preamble.Append(group.Name);
            preamble.Append(" Group.  A Group is an ordered collection of message \r\n");
            preamble.Append(" * segments that can repeat together or be optionally in/excluded together.\r\n");
            preamble.Append(" * This Group contains the following elements: </p>\r\n");
            preamble.Append(makeElementsDoc(group.Structures));
            preamble.Append(" */\r\n");
            preamble.Append("public class ");
            preamble.Append(group.Name);
            preamble.Append(" extends AbstractGroup {\r\n\r\n");

            return(preamble.ToString());
        }
예제 #2
0
        /// <summary> <p>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.</p>
        /// <p>The structures list may contain [] and {} pairs representing
        /// nested groups and their optionality and repeastability.  In these cases
        /// this method is called recursively.</p>
        /// <p>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.</p>
        /// </summary>
        /// <param name="structures">a list of the structures that comprise this group - must
        /// be at least 2 long
        /// </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>      properly nested.
        /// </summary>
        public static NuGenGroupDef writeGroup(NuGenStructureDef[] 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 = NuGenSourceGenerator.makeDirectory(baseDirectory + NuGenSourceGenerator.getVersionPackagePath(version) + "group");

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

            System.IO.StreamWriter out_Renamed = new System.IO.StreamWriter(new System.IO.StreamWriter(targetDir.FullName + "/" + group.Name + ".java", false, System.Text.Encoding.Default).BaseStream, new System.IO.StreamWriter(targetDir.FullName + "/" + group.Name + ".java", false, System.Text.Encoding.Default).Encoding);
            out_Renamed.Write(makePreamble(group, version));
            out_Renamed.Write(makeConstructor(group, version));

            NuGenStructureDef[] shallow = group.Structures;
            for (int i = 0; i < shallow.Length; i++)
            {
                out_Renamed.Write(makeAccessor(group, i));
            }
            out_Renamed.Write("}\r\n");
            out_Renamed.Flush();
            out_Renamed.Close();

            return(group);
        }
예제 #3
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>
        public static void  make(System.String message, System.String baseDirectory, System.String chapter, System.String version)
        {
            try
            {
                NuGenSegmentDef[] segments = getSegments(message, version);
                //System.out.println("Making: " + message + " with " + segments.length + " segments (not writing message code - just groups)");

                NuGenGroupDef       group    = NuGenGroupGenerator.getGroupDef(segments, null, baseDirectory, version, message);
                NuGenStructureDef[] contents = group.Structures;

                //make base directory
                if (!(baseDirectory.EndsWith("\\") || baseDirectory.EndsWith("/")))
                {
                    baseDirectory = baseDirectory + "/";
                }
                System.IO.FileInfo targetDir = NuGenSourceGenerator.makeDirectory(baseDirectory + NuGenSourceGenerator.getVersionPackagePath(version) + "message");
                System.Console.Out.WriteLine("Writing " + message + " to " + targetDir.FullName);
                System.IO.StreamWriter out_Renamed = new System.IO.StreamWriter(new System.IO.StreamWriter(targetDir.FullName + "/" + message + ".java", false, System.Text.Encoding.Default).BaseStream, new System.IO.StreamWriter(targetDir.FullName + "/" + message + ".java", false, System.Text.Encoding.Default).Encoding);
                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(NuGenGroupGenerator.makeAccessor(group, i));
                }

                //add implementation of model.control interface, if any
                //out.write(Control.getImplementation(Control.getInterfaceImplementedBy(message), version));
                out_Renamed.Write("}\r\n");
                out_Renamed.Flush();
                out_Renamed.Close();
            }
            catch (System.Exception)
            {
            }
        }
예제 #4
0
        /// <summary> <p>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(System.String baseDirectory, System.String version)
        {
            //make base directory
            if (!(baseDirectory.EndsWith("\\") || baseDirectory.EndsWith("/")))
            {
                baseDirectory = baseDirectory + "/";
            }
            System.IO.FileInfo targetDir = NuGenSourceGenerator.makeDirectory(baseDirectory + NuGenSourceGenerator.getVersionPackagePath(version) + "datatype");

            //get list of data types
            System.Collections.ArrayList      types = new System.Collections.ArrayList();
            System.Data.OleDb.OleDbConnection conn  = NuGenNormativeDatabase.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]));
            }

            //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]));
            }

            NuGenNormativeDatabase.Instance.returnConnection(conn);

            System.Console.Out.WriteLine("Generating " + types.Count + " datatypes for version " + version);
            if (types.Count == 0)
            {
            }

            for (int i = 0; i < types.Count; i++)
            {
                try
                {
                    make(targetDir, (System.String)types[i], version);
                }
                catch (DataTypeException)
                {
                }
                catch (System.Exception)
                {
                }
            }
        }
예제 #5
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(System.String baseDirectory, System.String version)
        {
            //make base directory
            if (!(baseDirectory.EndsWith("\\") || baseDirectory.EndsWith("/")))
            {
                baseDirectory = baseDirectory + "/";
            }
            System.IO.FileInfo targetDir = NuGenSourceGenerator.makeDirectory(baseDirectory + NuGenSourceGenerator.getVersionPackagePath(version) + "segment");

            //get list of data types
            System.Data.OleDb.OleDbConnection conn = NuGenNormativeDatabase.Instance.Connection;
            System.Data.OleDb.OleDbCommand    stmt = SupportClass.TransactionManager.manager.CreateStatement(conn);
            System.String sql = "SELECT seg_code, section from HL7Segments, HL7Versions where HL7Segments.version_id = HL7Versions.version_id AND hl7_version = '" + version + "'";
            //System.out.println(sql);
            System.Data.OleDb.OleDbCommand temp_OleDbCommand;
            temp_OleDbCommand             = stmt;
            temp_OleDbCommand.CommandText = sql;
            System.Data.OleDb.OleDbDataReader rs = temp_OleDbCommand.ExecuteReader();

            System.Collections.ArrayList segments = new System.Collections.ArrayList();
            while (rs.Read())
            {
                System.String segName = System.Convert.ToString(rs[1 - 1]);
                if (System.Char.IsLetter(segName[0]))
                {
                    segments.Add(altSegName(segName));
                }
            }

            NuGenNormativeDatabase.Instance.returnConnection(conn);

            if (segments.Count == 0)
            {
            }

            for (int i = 0; i < segments.Count; i++)
            {
                try
                {
                    System.String          seg    = (System.String)segments[i];
                    System.String          source = makeSegment(seg, version);
                    System.IO.StreamWriter w      = new System.IO.StreamWriter(new System.IO.StreamWriter(targetDir.ToString() + "/" + seg + ".java", false, System.Text.Encoding.Default).BaseStream, new System.IO.StreamWriter(targetDir.ToString() + "/" + seg + ".java", false, System.Text.Encoding.Default).Encoding);
                    w.Write(source);
                    w.Flush();
                    w.Close();
                }
                catch (System.Exception e)
                {
                    System.Console.Error.WriteLine("Error creating source code for all segments: " + e.Message);
                    SupportClass.WriteStackTrace(e, Console.Error);
                }
            }
        }
예제 #6
0
        /// <summary> Returns header material for the source code of a Message class (including
        /// package, imports, JavaDoc, and class declaration).
        /// </summary>
        public static System.String makePreamble(NuGenStructureDef[] contents, System.String message, System.String chapter, System.String version)
        {
            System.Text.StringBuilder preamble = new System.Text.StringBuilder();
            preamble.Append("package ");
            preamble.Append(NuGenSourceGenerator.getVersionPackageName(version));
            preamble.Append("message;\r\n\r\n");
            preamble.Append("import ");
            preamble.Append(NuGenSourceGenerator.getVersionPackageName(version));
            preamble.Append("group.*;\r\n\r\n");
            preamble.Append("import ");
            preamble.Append(NuGenSourceGenerator.getVersionPackageName(version));
            preamble.Append("segment.*;\r\n\r\n");
            preamble.Append("import Genetibase.NuGenHL7.HL7Exception;\r\n\r\n");
            preamble.Append("import Genetibase.NuGenHL7.parser.ModelClassFactory;\r\n\r\n");
            preamble.Append("import Genetibase.NuGenHL7.parser.DefaultModelClassFactory;\r\n\r\n");
            preamble.Append("import Genetibase.NuGenHL7.model.AbstractMessage;\r\n\r\n");
            preamble.Append("/**\r\n");
            preamble.Append(" * <p>Represents a ");
            preamble.Append(message);
            preamble.Append(" message structure (see chapter ");
            preamble.Append(chapter);
            preamble.Append("). This structure contains the \r\n");
            preamble.Append(" * following elements: </p>\r\n");
            preamble.Append(NuGenGroupGenerator.makeElementsDoc(contents));
            preamble.Append(" */\r\n");
            preamble.Append("public class ");
            preamble.Append(message);
            preamble.Append(" extends AbstractMessage ");

            //implement interface from model.control package if required

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

            preamble.Append(" {\r\n\r\n");

            return(preamble.ToString());
        }
예제 #7
0
        /// <summary> Returns the Java source code for a class that represents the specified segment.</summary>
        public static System.String makeSegment(System.String name, System.String version)
        {
            System.Text.StringBuilder source = new System.Text.StringBuilder();
            try
            {
                System.Data.OleDb.OleDbConnection conn = NuGenNormativeDatabase.Instance.Connection;

                System.Text.StringBuilder sql = new System.Text.StringBuilder();
                sql.Append("SELECT HL7SegmentDataElements.seg_code, HL7SegmentDataElements.seq_no, ");
                sql.Append("HL7SegmentDataElements.repetitional, HL7SegmentDataElements.repetitions, ");
                sql.Append("HL7DataElements.description, HL7DataElements.length, 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;");
                //System.out.println(sql.toString());  //for debugging
                System.Data.OleDb.OleDbCommand stmt = SupportClass.TransactionManager.manager.CreateStatement(conn);
                System.Data.OleDb.OleDbCommand temp_OleDbCommand;
                temp_OleDbCommand             = stmt;
                temp_OleDbCommand.CommandText = sql.ToString();
                System.Data.OleDb.OleDbDataReader rs       = temp_OleDbCommand.ExecuteReader();
                System.Collections.ArrayList      elements = new System.Collections.ArrayList();
                System.String       segDesc = null;
                NuGenSegmentElement se;
                while (rs.Read())
                {
                    if (segDesc == null)
                    {
                        segDesc = System.Convert.ToString(rs[9 - 1]);
                    }
                    se             = new NuGenSegmentElement();
                    se.field       = rs.GetInt32(2 - 1);
                    se.rep         = System.Convert.ToString(rs[3 - 1]);
                    se.repetitions = rs.GetInt32(4 - 1);
                    if (se.repetitions == 0)
                    {
                        if (se.rep == null || !se.rep.ToUpper().Equals("Y".ToUpper()))
                        {
                            se.repetitions = 1;
                        }
                    }
                    se.desc   = System.Convert.ToString(rs[5 - 1]);
                    se.length = rs.GetInt32(6 - 1);
                    se.table  = rs.GetInt32(7 - 1);
                    se.opt    = System.Convert.ToString(rs[8 - 1]);
                    se.type   = System.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);*/
                }
                NuGenNormativeDatabase.Instance.returnConnection(conn);

                //write imports, class documentation, etc ...
                source.Append("package ");
                source.Append(NuGenSourceGenerator.getVersionPackageName(version));
                source.Append("segment;\r\n\r\n");
                source.Append("import Genetibase.NuGenHL7.model.*;\r\n");
                source.Append("import ");
                source.Append(NuGenSourceGenerator.getVersionPackageName(version));
                source.Append("datatype.*;\r\n\r\n");
                source.Append("import Genetibase.NuGenHL7.parser.ModelClassFactory;\r\n");
                source.Append("import Genetibase.NuGenHL7.HL7Exception;\r\n\r\n");
                source.Append("/**\r\n");
                source.Append(" * <p>Represents an HL7 ");
                source.Append(name);
                source.Append(" message segment. \r\n");
                source.Append(" * This segment has the following fields:</p><p>\r\n");
                for (int i = 0; i < elements.Count; i++)
                {
                    se = (NuGenSegmentElement)elements[i];
                    source.Append(" * ");
                    source.Append(name);
                    source.Append("-");
                    source.Append(se.field);
                    source.Append(": ");
                    source.Append(se.desc);
                    source.Append(" (");
                    source.Append(se.type);
                    source.Append(")<br> \r\n");
                }
                source.Append(" * </p><p>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.</p>    \r\n");
                source.Append(" */\r\n");
                source.Append("public class ");
                source.Append(name);
                source.Append(" extends 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("  public ");
                source.Append(name);
                source.Append("(Group parent, ModelClassFactory factory) {\r\n");
                source.Append("    super(parent, factory);\r\n");
                source.Append("    Message message = getMessage();\r\n");
                if (elements.Count > 0)
                {
                    source.Append("    try {\r\n");
                    for (int i = 0; i < elements.Count; i++)
                    {
                        se = (NuGenSegmentElement)elements[i];
                        System.String type = NuGenSourceGenerator.getAlternateType(se.type, version);
                        source.Append("       this.add(");
                        source.Append(type);
                        source.Append(".class");
                        //                    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 Object[]{message, new Integer(");
                            source.Append(se.table);
                            source.Append(")}");
                        }
                        else
                        {
                            source.Append("new Object[]{message}");
                        }
                        source.Append(");\r\n");
                    }
                    source.Append("    } catch (HL7Exception 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 = (NuGenSegmentElement)elements[i];
                    if (!se.desc.ToUpper().Equals("UNUSED".ToUpper()))
                    {
                        //some entries in 2.1 DB say "unused"
                        System.String type = NuGenSourceGenerator.getAlternateType(se.type, version);
                        source.Append("  /**\r\n");
                        source.Append("   * Returns ");
                        if (se.repetitions != 1)
                        {
                            source.Append("a single repetition of ");
                        }
                        source.Append(se.desc);
                        source.Append(" (");
                        source.Append(name);
                        source.Append("-");
                        source.Append(se.field);
                        source.Append(").\r\n");
                        if (se.repetitions != 1)
                        {
                            source.Append("   * @param rep the repetition number (this is a repeating field)\r\n");
                            source.Append("   * @throws HL7Exception if the repetition number is invalid.\r\n");
                        }
                        source.Append("   */\r\n");
                        source.Append("  public ");
                        source.Append(type);
                        source.Append(" ");
                        source.Append(NuGenSourceGenerator.makeAccessorName(se.desc));
                        source.Append("(");
                        if (se.repetitions != 1)
                        {
                            source.Append("int rep");
                        }
                        source.Append(") ");
                        if (se.repetitions != 1)
                        {
                            source.Append("throws HL7Exception");
                        }
                        source.Append(" {\r\n");
                        source.Append("    ");
                        source.Append(type);
                        source.Append(" ret = null;\r\n");
                        source.Append("    try {\r\n");
                        source.Append("        Type 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("        ret = (");
                        source.Append(type);
                        source.Append(")t;\r\n");

                        source.Append("    } catch (ClassCastException ) {\r\n");
                        source.Append("        throw new Exception();\r\n");
                        if (se.repetitions == 1)
                        {
                            source.Append("    } catch (HL7Exception he) {\r\n");
                            source.Append("        throw new Exception();\r\n");
                        }
                        source.Append("    }\r\n");
                        source.Append("    return ret;\r\n");
                        source.Append("  }\r\n\r\n");

                        //add an array accessor as well for repeating fields
                        if (se.repetitions != 1)
                        {
                            source.Append("  /**\r\n");
                            source.Append("   * Returns all repetitions of ");
                            source.Append(se.desc);
                            source.Append(" (");
                            source.Append(name);
                            source.Append("-");
                            source.Append(se.field);
                            source.Append(").\r\n");
                            source.Append("   */\r\n");
                            source.Append("  public ");
                            source.Append(type);
                            source.Append("[] ");
                            source.Append(NuGenSourceGenerator.makeAccessorName(se.desc));
                            source.Append("() {\r\n");
                            source.Append("     ");
                            source.Append(type);
                            source.Append("[] ret = null;\r\n");
                            source.Append("    try {\r\n");
                            source.Append("        Type[] 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 (ClassCastException ) {\r\n");
                            source.Append("        throw new Exception();\r\n");
                            source.Append("    } catch (HL7Exception he) {\r\n");
                            source.Append("        throw new Exception();\r\n");
                            source.Append("    }\r\n");
                            source.Append("    return ret;\r\n");
                            source.Append("  }\r\n\r\n");
                        }
                    }
                }

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

                source.Append("}");
            }
            catch (System.Data.OleDb.OleDbException sqle)
            {
                SupportClass.WriteStackTrace(sqle, Console.Error);
            }

            return(source.ToString());
        }
예제 #8
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 System.String makeComposite(System.String dataType, System.String description, System.String[] dataTypes, System.String[] descriptions, int[] tables, System.String version)
        {
            System.Text.StringBuilder source = new System.Text.StringBuilder();
            source.Append("package ");
            source.Append(NuGenSourceGenerator.getVersionPackageName(version));
            source.Append("datatype;\r\n\r\n");
            source.Append("import Genetibase.NuGenHL7.model.Composite;\r\n");
            source.Append("import Genetibase.NuGenHL7.model.DataTypeException;\r\n");
            source.Append("import Genetibase.NuGenHL7.model.Message;\r\n");
            source.Append("import Genetibase.NuGenHL7.model.Type;\r\n");
            source.Append("import Genetibase.NuGenHL7.model.AbstractType;\r\n");
            source.Append("/**\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(descriptions[i]);
                source.Append(" (");
                source.Append(dataTypes[i]);
                source.Append(")</li>\r\n");
            }
            source.Append(" * </ol>\r\n");
            source.Append(" */\r\n");
            source.Append("public class ");
            source.Append(dataType);
            source.Append(" extends AbstractType implements ");

            //implement interface from model.control package if required
            //Class correspondingControlInterface = Control.getInterfaceImplementedBy(dataType);
            //if (correspondingControlInterface == null) {
            source.Append("Composite");
            //} else {
            //            source.append(correspondingControlInterface.getName());
            //}

            source.Append(" {\r\n\r\n");
            source.Append("\tprivate Type[] data;\r\n\r\n");
            source.Append("\t/**\r\n");
            source.Append("\t * Creates a ");
            source.Append(dataType);
            source.Append(".\r\n");
            source.Append("\t * @param message the Message to which this Type belongs\r\n");
            source.Append("\t */\r\n");
            source.Append("\tpublic ");
            source.Append(dataType);
            source.Append("(Message message) {\r\n");
            source.Append("\t\tsuper(message);\r\n");
            source.Append("\t\tdata = new Type[");
            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(NuGenSourceGenerator.getAlternateType(dataTypes[i], version));
                if (dataTypes[i].Equals("ID") || dataTypes[i].Equals("IS"))
                {
                    source.Append("(message, ");
                    source.Append(tables[i]);
                    source.Append(")");
                }
                else
                {
                    source.Append("(message)");
                }
                source.Append(";\r\n");
            }
            source.Append("\t}\r\n\r\n");
            source.Append("\t/**\r\n");
            source.Append("\t * Returns an array containing the data elements.\r\n");
            source.Append("\t */\r\n");
            source.Append("\tpublic Type[] getComponents() { \r\n");
            source.Append("\t\treturn this.data; \r\n");
            source.Append("\t}\r\n\r\n");
            source.Append("\t/**\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 */\r\n");
            source.Append("\tpublic Type getComponent(int number) throws DataTypeException { \r\n\r\n");
            source.Append("\t\ttry { \r\n");
            source.Append("\t\t\treturn this.data[number]; \r\n");
            source.Append("\t\t} catch (ArrayIndexOutOfBoundsException e) { \r\n");
            source.Append("\t\t\tthrow new DataTypeException(\"Element \" + number + \" 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");

            //make type-specific accessors ...
            for (int i = 0; i < dataTypes.Length; i++)
            {
                System.String dtName = NuGenSourceGenerator.getAlternateType(dataTypes[i], version);
                source.Append("\t/**\r\n");
                source.Append("\t * Returns ");
                source.Append(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 */\r\n");
                source.Append("\tpublic ");
                source.Append(dtName);
                source.Append(" ");
                source.Append(NuGenSourceGenerator.makeAccessorName(descriptions[i]));
                source.Append("() {\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(")getComponent(");
                source.Append(i);
                source.Append(");\r\n");
                source.Append("\t   } catch (DataTypeException e) {\r\n");
                source.Append("\t      throw new Exception();\r\n");
                source.Append("\t   }\r\n");
                source.Append("\t   return ret;\r\n");
                source.Append("\t}\r\n\r\n");
            }

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

            return(source.ToString());
        }
예제 #9
0
        /// <summary> Returns a String containing the complete source code for a Primitive HL7 data
        /// type.  Note: this method is no longer used, as all Primitives are now coded manually.
        /// </summary>
        private static System.String makePrimitive(System.String datatype, System.String description, System.String version)
        {
            //System.out.println("Making primitive: " + datatype);
            System.Text.StringBuilder source = new System.Text.StringBuilder();

            source.Append("package ");
            source.Append(NuGenSourceGenerator.getVersionPackageName(version));
            source.Append("datatype;\r\n\r\n");
            source.Append("import Genetibase.NuGenHL7.model.Primitive;\r\n");
            source.Append("import Genetibase.NuGenHL7.model.DataTypeException;\r\n");
            source.Append("import Genetibase.NuGenHL7.model.Message;\r\n");
            source.Append("import Genetibase.NuGenHL7.model.Type;\r\n");
            source.Append("import Genetibase.NuGenHL7.model.AbstractPrimitive;\r\n\r\n");
            source.Append("/**\r\n");
            source.Append(" * <p>Represents the HL7 ");
            source.Append(datatype);
            source.Append(" (");
            source.Append(description);
            source.Append(") datatype.  A ");
            source.Append(datatype);
            source.Append(" contains a single String value.\r\n");
            source.Append(" */\r\n");
            source.Append("public class ");
            source.Append(datatype);
            source.Append(" extends AbstractPrimitive ");
            source.Append(" {\r\n\r\n");
            //source.append("\tprotected String value;\r\n\r\n");
            source.Append("\t/**\r\n");
            source.Append("\t * Constructs an uninitialized ");
            source.Append(datatype);
            source.Append(".\r\n");
            source.Append("\t * @param message the Message to which this Type belongs\r\n");
            source.Append("\t */\r\n");
            source.Append("\tpublic ");
            source.Append(datatype);
            source.Append("(Message message) {\r\n");
            source.Append("\t\tsuper(message);\r\n");
            source.Append("\t}\r\n\r\n");
            //source.append("\t/**\r\n");
            //source.append("\t * Constructs a ");
            //source.append(datatype);
            //source.append(" with the given value.\r\n");
            //source.append("\t */\r\n");
            //source.append("\tpublic ");
            //source.append(datatype);
            //source.append("(String value) {\r\n");
            //source.append("\t\tthis.value = value;\r\n");
            //source.append("\t}\r\n\r\n");
            //        source.append("\t/**\r\n");
            //        source.append("\t * Sets the value (a private field), which implementing classes should validate.\r\n");
            //        source.append("\t */\r\n");
            //        source.append("\tpublic void setValue(String value) throws DataTypeException { \r\n");
            //        source.append("\t\tthis.value = value;\r\n\t}\r\n\r\n");
            //        source.append("\t/**\r\n");
            //        source.append("\t * Returns the value.\r\n");
            //        source.append("\t */\r\n");
            //        source.append("\tpublic String getValue() {\r\n");
            //        source.append("\t\treturn this.value;\r\n");
            //        source.append("\t}\r\n");

            /*if (correspondingControlInterface != null) {
             * source.append(Control.getImplementation(correspondingControlInterface, version));
             * }*/
            source.Append("\t/**\r\n");
            source.Append("\t * @return \"");
            source.Append(version);
            source.Append("\"\r\n");
            source.Append("\t */\r\n");
            source.Append("\tpublic String getVersion() {\r\n");
            source.Append("\t    return \"");
            source.Append(version);
            source.Append("\";\r\n");
            source.Append("\t}\r\n\r\n");
            source.Append("}\r\n");

            return(source.ToString());
        }