Пример #1
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 + "/";
            }

            var targetDir =
                SourceGenerator.MakeDirectory(baseDirectory + PackageManager.GetVersionPackagePath(version) + "Segment");

            // get list of data types
            var conn = NormativeDatabase.Instance.Connection;
            var 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;
            var rs = temp_OleDbCommand.ExecuteReader();

            var segments = new ArrayList();

            while (rs.Read())
            {
                var 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 (var i = 0; i < segments.Count; i++)
            {
                try
                {
                    var seg    = (string)segments[i];
                    var source = MakeSegment(seg, version);
                    using (var 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);
                }
            }
        }
Пример #2
0
        public static void MakeAll(string baseDirectory, string version)
        {
            // make base directory
            if (!(baseDirectory.EndsWith("\\") || baseDirectory.EndsWith("/")))
            {
                baseDirectory = baseDirectory + "/";
            }

            var targetDir =
                SourceGenerator.MakeDirectory(baseDirectory + PackageManager.GetVersionPackagePath(version) + "EventMapping");

            // get list of data types
            var conn = NormativeDatabase.Instance.Connection;
            var 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;
            var rs = temp_OleDbCommand.ExecuteReader();

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

                    sw.WriteLine(string.Format("{0} {1}", messageType, structure));
                }
            }
        }
Пример #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(string message, string baseDirectory, string chapter, string version)
        {
            try
            {
                var segments = GetSegments(message, version);

                // System.out.println("Making: " + message + " with " + segments.length + " segments (not writing message code - just groups)");
                var group = GroupGenerator.GetGroupDef(segments, null, baseDirectory, version, message);
                var contents = group.Structures;

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

                var targetDir =
                    SourceGenerator.MakeDirectory(
                        Path.Combine(baseDirectory, PackageManager.GetVersionPackagePath(version), "Message"));

                var targetFile = Path.Combine(targetDir.FullName, $"{message}.cs");

                var stringBuilder = new StringBuilder();

                stringBuilder.Append(MakePreamble(contents, message, chapter, version));
                stringBuilder.Append(MakeConstructor(contents, message, version));
                for (var i = 0; i < contents.Length; i++)
                {
                    var groupAccessor = GroupGenerator.MakeAccessor(@group, i);
                    stringBuilder.Append(groupAccessor);
                }

                // add implementation of model.control interface, if any
                stringBuilder.Append("}\r\n"); // End class
                stringBuilder.Append("}\r\n"); // End namespace

                FileAbstraction.WriteAllBytes(targetFile, Encoding.UTF8.GetBytes(stringBuilder.ToString()));
            }
            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);
            }
        }
Пример #4
0
        public static void MakeAll(string baseDirectory, string version)
        {
            // make base directory
            if (!(baseDirectory.EndsWith("\\") || baseDirectory.EndsWith("/")))
            {
                baseDirectory += Path.DirectorySeparatorChar;
            }

            var targetDir =
                SourceGenerator.MakeDirectory(
                    Path.Combine(baseDirectory, PackageManager.GetVersionPackagePath(version), "EventMapping"));

            // get list of data types
            var conn = NormativeDatabase.Instance.Connection;
            var 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;
            var rs = temp_OleDbCommand.ExecuteReader();

            var targetFile = Path.Combine(targetDir.FullName, "EventMap.properties");

            var stringBuilder = new StringBuilder();

            stringBuilder.AppendLine($"#event -> structure map for {version}");
            if (version == "2.1" || version == "2.2")
            {
                stringBuilder.AppendLine("#note: no mappings are defined for 2.1 and 2.2");
            }
            else
            {
                while (rs.Read())
                {
                    var messageType = $"{rs["message_typ_snd"]}_{rs["event_code"]}";
                    var structure   = (string)rs["message_structure_snd"];

                    stringBuilder.AppendLine($"{messageType} {structure}");
                }
            }

            FileAbstraction.WriteAllBytes(targetFile, Encoding.UTF8.GetBytes(stringBuilder.ToString()));
        }
Пример #5
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
            {
                var segments = GetSegments(message, version);

                // System.out.println("Making: " + message + " with " + segments.length + " segments (not writing message code - just groups)");
                var group    = GroupGenerator.GetGroupDef(segments, null, baseDirectory, version, message);
                var contents = group.Structures;

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

                var targetDir =
                    SourceGenerator.MakeDirectory(baseDirectory + PackageManager.GetVersionPackagePath(version) + "Message");
                Console.Out.WriteLine("Writing " + message + " to " + targetDir.FullName);
                using (var out_Renamed = new StreamWriter(targetDir.FullName + "/" + message + ".cs"))
                {
                    out_Renamed.Write(MakePreamble(contents, message, chapter, version));
                    out_Renamed.Write(MakeConstructor(contents, message, version));
                    for (var i = 0; i < contents.Length; i++)
                    {
                        var 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);
            }
        }
Пример #6
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 += Path.DirectorySeparatorChar;
            }

            var targetDir =
                SourceGenerator.MakeDirectory(
                    Path.Combine(baseDirectory, PackageManager.GetVersionPackagePath(version), "Group"));

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

            var targetFile = Path.Combine(targetDir.FullName, $"{@group.Name}.cs");

            var stringBuilder = new StringBuilder();

            stringBuilder.Append(MakePreamble(group, version));
            stringBuilder.Append(MakeConstructor(group, version));

            var shallow = group.Structures;

            for (var i = 0; i < shallow.Length; i++)
            {
                stringBuilder.Append(MakeAccessor(group, i));
            }

            stringBuilder.Append("}\r\n"); // Closing class
            stringBuilder.Append("}\r\n"); // Closing namespace

            FileAbstraction.WriteAllBytes(targetFile, Encoding.UTF8.GetBytes(stringBuilder.ToString()));
            return(group);
        }
Пример #7
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 + "/";
            }

            var 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("/", "_");
            var group = GetGroupDef(structures, groupName, baseDirectory, version, message);

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

                var shallow = group.Structures;
                for (var 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);
        }
Пример #8
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 + "/";
            }

            var targetDir =
                SourceGenerator.MakeDirectory(baseDirectory + PackageManager.GetVersionPackagePath(version) + "Datatype");

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

            // get list of data types
            var types = new ArrayList();
            var conn  = NormativeDatabase.Instance.Connection;
            var 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 + "'";
            var 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 (var type in types.Cast <string>())
            {
                if (!type.Equals("*"))
                {
                    Make(targetDir, type, version);
                }
            }
        }