Esempio n. 1
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);
        }
Esempio n. 2
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));
                }
            }
        }
Esempio n. 3
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);
                }
            }
        }
Esempio n. 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);
        }
Esempio n. 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));
                }
            }
        }
Esempio n. 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);
                }
            }
        }
Esempio n. 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);
            }
        }
Esempio n. 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);
                }
            }
        }
Esempio n. 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);
                }
            }
        }