/// <param name="message">a parsed message to validate (note that MSH-9-1 and MSH-9-2 must be valued) /// </param> /// <returns> true if the message is OK /// </returns> /// <throws> HL7Exception if there is at least one error and this validator is set to fail on errors </throws> public virtual bool validate(Message message) { Terser t = new Terser(message); MessageRule[] rules = myContext.getMessageRules(message.Version, t.Get("MSH-9-1"), t.Get("MSH-9-2")); ValidationException toThrow = null; bool result = true; for (int i = 0; i < rules.Length; i++) { ValidationException[] ex = rules[i].test(message); for (int j = 0; j < ex.Length; j++) { result = false; ourLog.error("Invalid message", ex[j]); if (failOnError && toThrow == null) { toThrow = ex[j]; } } } if (toThrow != null) { throw new HL7Exception("Invalid message", toThrow); } return(result); }
/// <summary>Parses a primitive type by filling it with text child, if any </summary> private void parsePrimitive(Primitive datatypeObject, System.Xml.XmlElement datatypeElement) { //UPGRADE_TODO: Method 'org.w3c.dom.Node.getChildNodes' was converted to 'System.Xml.XmlNode.ChildNodes' which has a different behavior. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1073'" System.Xml.XmlNodeList children = datatypeElement.ChildNodes; int c = 0; bool full = false; while (c < children.Count && !full) { System.Xml.XmlNode child = children.Item(c++); if (System.Convert.ToInt16(child.NodeType) == (short)System.Xml.XmlNodeType.Text) { try { if (child.Value != null && !child.Value.Equals("")) { if (keepAsOriginal(child.ParentNode)) { datatypeObject.Value = child.Value; } else { datatypeObject.Value = removeWhitespace(child.Value); } } } //UPGRADE_TODO: Class 'org.w3c.dom.DOMException' was converted to 'System.Exceptiont' which has a different behavior. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1073'" catch (System.Exception e) { log.error("Error parsing primitive value from TEXT_NODE", e); } full = true; } } }
public static void Main(System.String[] args) { try { //UPGRADE_TODO: The differences in the format of parameters for method 'java.lang.Class.forName' may cause compilation errors. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1092'" System.Type.GetType("sun.jdbc.odbc.JdbcOdbcDriver"); //UPGRADE_ISSUE: Method 'java.lang.System.setProperty' was not converted. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1000_javalangSystem'" //System_Renamed.setProperty("ca.on.uhn.hl7.database.url", "jdbc:odbc:hl7v25"); // Above line not supported... //UPGRADE_NOTE: There are other database providers or managers under System.Data namespace which can be used optionally to better fit the application requirements. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1208'" System.Data.OleDb.OleDbConnection conn = NormativeDatabase.Instance.Connection; //UPGRADE_TODO: Method 'java.sql.Connection.createStatement' was converted to 'SupportClass.TransactionManager.manager.CreateStatement' which has a different behavior. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1073_javasqlConnectioncreateStatement'" System.Data.OleDb.OleDbCommand stmt = SupportClass.TransactionManager.manager.CreateStatement(conn); //UPGRADE_TODO: Interface 'java.sql.ResultSet' was converted to 'System.Data.OleDb.OleDbDataReader' which has a different behavior. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1073_javasqlResultSet'" System.Data.OleDb.OleDbCommand temp_OleDbCommand; temp_OleDbCommand = stmt; temp_OleDbCommand.CommandText = "select * from TableValues"; System.Data.OleDb.OleDbDataReader rs = temp_OleDbCommand.ExecuteReader(); while (rs.Read()) { System.Object tabNum = rs.GetValue(1 - 1); System.Object val = rs.GetValue(3 - 1); System.Object desc = rs.GetValue(4 - 1); //UPGRADE_TODO: The equivalent in .NET for method 'java.lang.Object.toString' may return a different value. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1043'" System.Console.Out.WriteLine("Table: " + tabNum + " Value: " + val + " Description: " + desc); } } catch (System.Data.OleDb.OleDbException e) { log.error("test msg!!", e); } //UPGRADE_NOTE: Exception 'java.lang.ClassNotFoundException' was converted to 'System.Exception' which has different behavior. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1100'" catch (System.Exception e) { log.error("test msg!!", e); } }
public static System.String encode(Segment source, EncodingCharacters encodingChars) { System.Text.StringBuilder result = new System.Text.StringBuilder(); result.Append(source.getStructureName()); result.Append(encodingChars.FieldSeparator); //start at field 2 for MSH segment because field 1 is the field delimiter int startAt = 1; if (isDelimDefSegment(source.getStructureName())) { startAt = 2; } //loop through fields; for every field delimit any repetitions and add field delimiter after ... int numFields = source.numFields(); for (int i = startAt; i <= numFields; i++) { try { Type[] reps = source.getField(i); for (int j = 0; j < reps.Length; j++) { System.String fieldText = encode(reps[j], encodingChars); //if this is MSH-2, then it shouldn't be escaped, so unescape it again if (isDelimDefSegment(source.getStructureName()) && i == 2) { fieldText = Escape.unescape(fieldText, encodingChars); } result.Append(fieldText); if (j < reps.Length - 1) { result.Append(encodingChars.RepetitionSeparator); } } } catch (HL7Exception e) { log.error("Error while encoding segment: ", e); } result.Append(encodingChars.FieldSeparator); } //strip trailing delimiters ... return(stripExtraDelimiters(result.ToString(), encodingChars.FieldSeparator)); }
/// <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 { 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); StructureDef[] contents = group.Structures; //make base directory if (!(baseDirectory.EndsWith("\\") || baseDirectory.EndsWith("/"))) { baseDirectory = baseDirectory + "/"; } System.IO.FileInfo targetDir = SourceGenerator.makeDirectory(baseDirectory + SourceGenerator.getVersionPackageDirectory(version) + "message"); System.Console.Out.WriteLine("Writing " + message + " to " + targetDir.FullName); //UPGRADE_WARNING: At least one expression was used more than once in the target code. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1181'" //UPGRADE_TODO: Constructor 'java.io.FileWriter.FileWriter' was converted to 'System.IO.StreamWriter' which has a different behavior. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1073_javaioFileWriterFileWriter_javalangString_boolean'" //UPGRADE_TODO: Class 'java.io.FileWriter' was converted to 'System.IO.StreamWriter' which has a different behavior. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1073_javaioFileWriter'" using (System.IO.StreamWriter out_Renamed = new System.IO.StreamWriter(targetDir.FullName + "/" + message + ".cs")) { //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 + ".cs", 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(GroupGenerator.makeAccessor(group, i)); } out_Renamed.Write(makeVersion(version)); //add implementation of model.control interface, if any //out.write(Control.getImplementation(Control.getInterfaceImplementedBy(message), version)); 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); //UPGRADE_TODO: The equivalent in .NET for method 'java.lang.Class.getName' may return a different value. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1043'" //UPGRADE_TODO: The equivalent in .NET for method 'java.lang.Throwable.getMessage' may return a different value. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1043'" log.warn("Warning: could not write source code for message structure " + message + " - " + e.GetType().FullName + ": " + e.Message); } }
/// <summary> Called from getField(...) methods. If a field has been requested that /// doesn't exist (eg getField(15) when only 10 fields in segment) adds Varies /// fields to the end of the segment up to the required number. /// </summary> private void ensureEnoughFields(int fieldRequested) { int fieldsToAdd = fieldRequested - this.numFields(); if (fieldsToAdd < 0) { fieldsToAdd = 0; } try { for (int i = 0; i < fieldsToAdd; i++) { this.add(typeof(Varies), false, 0, 65536, null); //using 65536 following example of OBX-5 } } catch (HL7Exception e) { log.error("Can't create additional generic fields to handle request for field " + fieldRequested, e); } }
protected virtual void encode(Segment source, EncodingCharacters encodingChars, Table tbl) { TableRow tr; TableCell td; tr = new TableRow(); td = new TableCell(); td.ColumnSpan = 3; if (_cssSegmentHeader != null && _cssSegmentHeader.Trim().Length > 0) { tr.CssClass = _cssSegmentHeader; } td.Text = source.getStructureName(); tr.Cells.Add(td); tbl.Rows.Add(tr); //start at field 2 for MSH segment because field 1 is the field delimiter int startAt = 1; if (isDelimDefSegment(source.getStructureName())) { startAt = 2; } //loop through fields; for every field delimit any repetitions and add field delimiter after ... int numFields = source.numFields(); for (int i = startAt; i <= numFields; i++) { try { tr = new TableRow(); td = new TableCell(); td.Text = i.ToString(); tr.Cells.Add(td); Type[] reps = source.getField(i); string description = source.getFieldDescription(i); td = new TableCell(); if (_cssSegmentField != null) { td.CssClass = _cssSegmentField; } if (description != null && description.Trim().Length > 0) { td.Text = description; } else { td.Text = " "; } tr.Cells.Add(td); td = new TableCell(); if (reps.Length == 0) { td.Text = " "; } else { for (int j = 0; j < reps.Length; j++) { td.Controls.Add(encode(reps[j], encodingChars)); if (j < reps.Length - 1) { td.Controls.Add(new LiteralControl("<hr size='2'>")); } } } tr.Cells.Add(td); tbl.Rows.Add(tr); } catch (HL7Exception e) { log.error("Error while encoding segment: ", e); } } }
/// <summary> Given a list of structures and the position of a SegmentDef that /// indicates the start of a group (ie "{" or "["), returns the position /// of the corresponding end of the group. Nested group markers are ignored. /// </summary> /// <throws> IllegalArgumentException if groupStart is out of range or does not </throws> /// <summary> point to a group opening marker. /// </summary> /// <throws> HL7Exception if the end of the group is not found or if other pairs </throws> /// <summary> are not properly nested inside this one. /// </summary> public static int findGroupEnd(StructureDef[] structures, int groupStart) { // {} is rep; [] is optionality System.String endMarker = null; try { System.String startMarker = structures[groupStart].Name; if (startMarker.Equals("[")) { endMarker = "]"; } else if (startMarker.Equals("{")) { endMarker = "}"; } else if (startMarker.Equals("[{")) { endMarker = "}]"; } else { log.error("Problem starting at " + groupStart); for (int i = 0; i < structures.Length; i++) { log.error("Structure " + i + ": " + structures[i].Name); } throw new System.ArgumentException("The segment " + startMarker + " does not begin a group - must be [ or {"); } } catch (System.IndexOutOfRangeException) { throw new System.ArgumentException("The given start location is out of bounds"); } //loop, increment and decrement opening and closing markers until we get back to 0 System.String segName = null; int offset = 0; try { int nestedInside = 1; while (nestedInside > 0) { offset++; segName = structures[groupStart + offset].Name; if (segName.Equals("{") || segName.Equals("[") || segName.Equals("[{")) { nestedInside++; } else if (segName.Equals("}") || segName.Equals("]") || segName.Equals("}]")) { nestedInside--; } } } catch (System.IndexOutOfRangeException) { throw new HL7Exception("Couldn't find end of group", HL7Exception.APPLICATION_INTERNAL_ERROR); } if (!endMarker.Equals(segName)) { throw new HL7Exception("Group markers are not nested properly", HL7Exception.APPLICATION_INTERNAL_ERROR); } return(groupStart + offset); }