예제 #1
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");

            //get list of data types
            OdbcConnection conn = NormativeDatabase.Instance.Connection;
            String         sql  =
                "SELECT * from HL7EventMessageTypes inner join HL7Versions on HL7EventMessageTypes.version_id = HL7Versions.version_id where HL7Versions.hl7_version = '" +
                version + "'";
            DbCommand temp_OleDbCommand = conn.CreateCommand();

            temp_OleDbCommand.Connection  = conn;
            temp_OleDbCommand.CommandText = sql;
            DbDataReader 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));
                }
            }
        }
예제 #2
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 repeatability.  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);
        }
예제 #3
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
            OdbcConnection conn = NormativeDatabase.Instance.Connection;
            String         sql  =
                "SELECT seg_code, [section] from HL7Segments, HL7Versions where HL7Segments.version_id = HL7Versions.version_id AND hl7_version = '" +
                version + "'";
            DbCommand temp_OleDbCommand = conn.CreateCommand();

            temp_OleDbCommand.Connection  = conn;
            temp_OleDbCommand.CommandText = sql;
            DbDataReader 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);
                }
            }
        }
예제 #4
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(String message, String baseDirectory, String chapter, 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 + "/";
                }

                FileInfo targetDir =
                    SourceGenerator.makeDirectory(baseDirectory + PackageManager.GetVersionPackagePath(version) + "Message");
                Console.Out.WriteLine("Writing " + message + " to " + targetDir.FullName);
                using (StreamWriter out_Renamed = new 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++)
                    {
                        string groupAccessor = GroupGenerator.makeAccessor(@group, i);
                        out_Renamed.Write(groupAccessor);
                    }

                    //add implementation of model.control interface, if any
                    out_Renamed.Write("}\r\n");                     //End class
                    out_Renamed.Write("}\r\n");                     //End namespace
                }
            }
            catch (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);
            }
        }
예제 #5
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");
            //get list of data types
            ArrayList      types = new ArrayList();
            OdbcConnection conn  = NormativeDatabase.Instance.Connection;
            DbCommand      stmt  = TransactionManager.manager.CreateStatement(conn);
            //get normal data types ...
            DbCommand 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 + "'";
            DbDataReader rs = temp_OleDbCommand.ExecuteReader();

            while (rs.Read())
            {
                types.Add(Convert.ToString(rs[1 - 1]));
            }
            rs.Close();
            //get CF, CK, CM, CN, CQ sub-types ...

            DbCommand 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(Convert.ToString(rs[1 - 1]));
            }

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

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

            foreach (string type in types.Cast <string>())
            {
                if (!type.Equals("*"))
                {
                    make(targetDir, type, version);
                }
            }
        }