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