/// <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> Creates a CQ.</summary> /// <param name="message">the Message to which this Type belongs /// </param> public CQ(Message message) : base(message) { data = new Type[2]; data[0] = new NM(message); data[1] = new ST(message); }
/// <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> <p>Parses a message string and returns the corresponding Message /// object. This method checks that the given message string is XML encoded, creates an /// XML Document object (using Xerces) from the given String, and calls the abstract /// method <code>parse(Document XMLMessage)</code></p> /// </summary> protected internal override Message doParse(System.String message, System.String version) { Message m = null; //parse message string into a DOM document try { System.Xml.XmlDocument doc = new System.Xml.XmlDocument(); doc.Load(new System.IO.StringReader(message)); //rlb: Don't think we need to lock this... //lock (this) //{ // //UPDATE_NOT: Replaced the following // //parser.parse(new XmlSourceSupport(new System.IO.StringReader(message))); // //doc = parser.getDocument(); //} m = parseDocument(doc, version); } //UPGRADE_TODO: Class 'org.xml.sax.SAXException' was converted to 'System.Xml.XmlException' which has a different behavior. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1073'" catch (System.Xml.XmlException e) { throw new HL7Exception("XmlException parsing XML", HL7Exception.APPLICATION_INTERNAL_ERROR, e); } catch (System.IO.IOException e) { throw new HL7Exception("IOException parsing XML", HL7Exception.APPLICATION_INTERNAL_ERROR, e); } return(m); }
/// <summary> Formats a Message object into an HL7 message string using this parser's /// default encoding (XML encoding). This method calls the abstract method /// <code>encodeDocument(...)</code> in order to obtain XML Document object /// representation of the Message, then serializes it to a String. /// </summary> /// <throws> HL7Exception if the data fields in the message do not permit encoding </throws> /// <summary> (e.g. required fields are null) /// </summary> protected internal override System.String doEncode(Message source) { if (source is GenericMessage) { throw new HL7Exception("Can't XML-encode a GenericMessage. Message must have a recognized structure."); } System.Xml.XmlDocument doc = encodeDocument(source); //UPGRADE_TODO: Method 'org.w3c.dom.Element.setAttribute' was converted to 'System.Xml.XmlElement.SetAttribute' which has a different behavior. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1073_orgw3cdomElementsetAttribute_javalangString_javalangString'" ((System.Xml.XmlElement)doc.DocumentElement).SetAttribute("xmlns", "urn:hl7-org:v2xml"); System.IO.StringWriter out_Renamed = new System.IO.StringWriter(); return(doc.OuterXml); //OutputFormat outputFormat = new OutputFormat("", null, true); //XMLSerializer ser = new XMLSerializer(out_Renamed, outputFormat); //default output format //try //{ // ser.serialize(doc); //} //catch (System.IO.IOException e) //{ // throw new HL7Exception("IOException serializing XML document to string", HL7Exception.APPLICATION_INTERNAL_ERROR, e); //} //return out_Renamed.ToString(); }
public void ParseORFR04ToXmlNoOCR() { string message = @"MSH|^~\&|Query Result Locator|Query Facility Name|Query Application Name|ST ELSEWHERE HOSPITAL|20051024074506||ORF^R04|432|P|2.4| MSA|AA|123456789| QRD|20060228160421|R|I||||10^RD&Records&0126|38923^^^^^^^^&TCH||| QRF||20050101000000|| PID|||38923^^^ST ELSEWHERE HOSPITAL Medical Record Numbers& MEDIC AL RECORD NUMBER&ST ELSEWHERE HOSPITAL^MR^ST ELSEWHERE HOSPITAL||Bombadill^Tom||19450605|M|||1&Main Street^^Littleton^CO^80122||^^^^^303^4376329^22| OBR|1|0015566|DH2211223|83036^HEMOGLOBIN A1C^^83036^HEMOGLOBIN A1C|||20040526094000|||||||20040526094000||J12345^JENS^JENNY^^^DR^MD^^^^^^^112233&TCH||||| TP QUEST DIAGNOSTICS-TAMPA 4225 E. FOWLER AVE TAMPA FL 33617|20030622070400|||F| OBX|1|NM|50026400^HEMOGLOBIN A1C^^50026400^HEMOGLOBIN A1C||12|^% TOTAL HGB|4.0 - 6.0|H|||F|||20040510094000|TP^^L|"; ca.uhn.hl7v2.parser.PipeParser parser = new ca.uhn.hl7v2.parser.PipeParser(); ca.uhn.hl7v2.model.Message m = parser.parse(message); ca.uhn.hl7v2.model.v24.message.ORF_R04 orfR04 = m as ca.uhn.hl7v2.model.v24.message.ORF_R04; Assert.IsNotNull(orfR04); ca.uhn.hl7v2.parser.XMLParser xmlParser = new ca.uhn.hl7v2.parser.DefaultXMLParser(); string recoveredMessage = xmlParser.encode(orfR04); Assert.IsNotNull(recoveredMessage); Assert.IsFalse(recoveredMessage.IndexOf("ORC") > -1, "Returned message added ORC segment."); }
/// <summary> Formats a Message object into an html table object using the given /// </summary> /// <throws> HL7Exception if the data fields in the message do not permit encoding </throws> /// <summary> (e.g. required fields are null) /// </summary> /// <throws> EncodingNotSupportedException if the requested encoding is not </throws> /// <summary> supported by this parser. /// </summary> public Table buildTable(Message source) { //get encoding characters ... Segment msh = (Segment)source.get_Renamed("MSH"); System.String fieldSepString = Terser.Get(msh, 1, 0, 1, 1); if (fieldSepString == null) { throw new HL7Exception("Can't encode message: MSH-1 (field separator) is missing"); } char fieldSep = '|'; if (fieldSepString != null && fieldSepString.Length > 0) { fieldSep = fieldSepString[0]; } System.String encCharString = Terser.Get(msh, 2, 0, 1, 1); EncodingCharacters en = new EncodingCharacters(fieldSep, encCharString); //pass down to group encoding method which will operate recursively on children ... Table tbl = new Table(); encode((Group)source, en, tbl); return(tbl); }
/// <summary> Formats a Message object into an HL7 message string using this parser's /// default encoding ("VB"). /// </summary> /// <throws> HL7Exception if the data fields in the message do not permit encoding </throws> /// <summary> (e.g. required fields are null) /// </summary> protected internal override System.String doEncode(Message source) { //get encoding characters ... Segment msh = (Segment)source.get_Renamed("MSH"); System.String fieldSepString = Terser.Get(msh, 1, 0, 1, 1); if (fieldSepString == null) { throw new HL7Exception("Can't encode message: MSH-1 (field separator) is missing"); } char fieldSep = '|'; if (fieldSepString != null && fieldSepString.Length > 0) { fieldSep = fieldSepString[0]; } System.String encCharString = Terser.Get(msh, 2, 0, 1, 1); if (encCharString == null) { throw new HL7Exception("Can't encode message: MSH-2 (encoding characters) is missing"); } if (encCharString.Length != 4) { throw new HL7Exception("Encoding characters '" + encCharString + "' invalid -- must be 4 characters", HL7Exception.DATA_TYPE_ERROR); } EncodingCharacters en = new EncodingCharacters(fieldSep, encCharString); //pass down to group encoding method which will operate recursively on children ... return(encode((Group)source, en)); }
/// <summary> Note that the validation context of the resulting message is set to this parser's validation /// context. The validation context is used within Primitive.setValue(). /// /// </summary> /// <param name="name">name of the desired structure in the form XXX_YYY /// </param> /// <param name="version">HL7 version (e.g. "2.3") /// </param> /// <param name="isExplicit">true if the structure was specified explicitly in MSH-9-3, false if it /// was inferred from MSH-9-1 and MSH-9-2. If false, a lookup may be performed to find /// an alternate structure corresponding to that message type and event. /// </param> /// <returns> a Message instance /// </returns> /// <throws> HL7Exception if the version is not recognized or no appropriate class can be found or the Message </throws> /// <summary> class throws an exception on instantiation (e.g. if args are not as expected) /// </summary> protected internal virtual Message instantiateMessage(System.String theName, System.String theVersion, bool isExplicit) { Message result = null; try { System.Type messageClass = myFactory.getMessageClass(theName, theVersion, isExplicit); if (messageClass == null) { //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'" throw new System.Exception("Can't find message class in current package list: " + theName); } //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'" log.info("Instantiating msg of class " + messageClass.FullName); System.Reflection.ConstructorInfo constructor = messageClass.GetConstructor(new System.Type[] { typeof(ModelClassFactory) }); result = (Message)constructor.Invoke(new System.Object[] { myFactory }); } catch (System.Exception e) { throw new HL7Exception("Couldn't create Message object of type " + theName, HL7Exception.UNSUPPORTED_MESSAGE_TYPE, e); } result.ValidationContext = myContext; return(result); }
/// <summary> Creates a CK.</summary> /// <param name="message">the Message to which this Type belongs /// </param> public CK(Message message) : base(message) { data = new Type[3]; data[0] = new NM(message); data[1] = new NM(message); data[2] = new ID(message, 0); }
/// <summary> <p>Creates and populates a Message object from an XML Document that contains an XML-encoded HL7 message.</p> /// <p>The easiest way to implement this method for a particular message structure is as follows: /// <ol><li>Create an instance of the Message type you are going to handle with your subclass /// of XMLParser</li> /// <li>Go through the given Document and find the Elements that represent the top level of /// each message segment. </li> /// <li>For each of these segments, call <code>parse(Segment segmentObject, Element segmentElement)</code>, /// providing the appropriate Segment from your Message object, and the corresponding Element.</li></ol> /// At the end of this process, your Message object should be populated with data from the XML /// Document.</p> /// </summary> /// <throws> HL7Exception if the message is not correctly formatted. </throws> /// <throws> EncodingNotSupportedException if the message encoded </throws> /// <summary> is not supported by this parser. /// </summary> public override Message parseDocument(System.Xml.XmlDocument XMLMessage, System.String version) { System.String messageName = ((System.Xml.XmlElement)XMLMessage.DocumentElement).Name; Message message = instantiateMessage(messageName, version, true); parse(message, (System.Xml.XmlElement)XMLMessage.DocumentElement); return(message); }
/// <summary> Formats a Message object into an HL7 message string using the given /// encoding. /// </summary> /// <throws> HL7Exception if the data fields in the message do not permit encoding </throws> /// <summary> (e.g. required fields are null) /// </summary> /// <throws> EncodingNotSupportedException if the requested encoding is not </throws> /// <summary> supported by this parser. /// </summary> protected internal override System.String doEncode(Message source, System.String encoding) { if (!encoding.Equals("XML")) { throw new EncodingNotSupportedException("XMLParser supports only XML encoding"); } return(encode(source)); }
/// <summary> Formats a Message object into an HL7 message string using the given /// encoding. /// /// </summary> /// <param name="source">a Message object from which to construct an encoded message string /// </param> /// <param name="encoding">the name of the HL7 encoding to use (eg "XML"; most implementations support only /// one encoding) /// </param> /// <returns> the encoded message /// </returns> /// <throws> HL7Exception if the data fields in the message do not permit encoding </throws> /// <summary> (e.g. required fields are null) /// </summary> /// <throws> EncodingNotSupportedException if the requested encoding is not </throws> /// <summary> supported by this parser. /// </summary> public virtual System.String encode(Message source, System.String encoding) { myValidator.validate(source); System.String result = doEncode(source, encoding); myValidator.validate(result, encoding.Equals("XML"), source.Version); return(result); }
/// <summary> Creates a CN.</summary> /// <param name="message">the Message to which this Type belongs /// </param> public CN(Message message) : base(message) { data = new Type[5]; data[0] = new ST(message); data[1] = new ST(message); data[2] = new ST(message); data[3] = new ST(message); data[4] = new ST(message); }
/// <summary> Formats a Message object into an HL7 message string using the given /// encoding. /// </summary> /// <throws> HL7Exception if the data fields in the message do not permit encoding </throws> /// <summary> (e.g. required fields are null) /// </summary> /// <throws> EncodingNotSupportedException if the requested encoding is not </throws> /// <summary> supported by this parser. /// </summary> protected internal override System.String doEncode(Message source, System.String encoding) { if (!this.supportsEncoding(encoding)) { throw new EncodingNotSupportedException("This parser does not support the " + encoding + " encoding"); } return(encode(source)); }
public void ParseQRYR02() { string message = @"MSH|^~\&|CohieCentral|COHIE|Clinical Data Provider|TCH|20060228155525||QRY^R02^QRY_R02|1|P|2.4| QRD|20060228155525|R|I||||10^RD&Records&0126|38923^^^^^^^^&TCH|||"; ca.uhn.hl7v2.parser.PipeParser parser = new ca.uhn.hl7v2.parser.PipeParser(); ca.uhn.hl7v2.model.Message m = parser.parse(message); ca.uhn.hl7v2.model.v24.message.QRY_R02 qryR02 = m as ca.uhn.hl7v2.model.v24.message.QRY_R02; Assert.IsNotNull(qryR02); Assert.AreEqual("38923", qryR02.QRD.getWhoSubjectFilter(0).IDNumber.Value); }
public static new void Main(System.String[] args) { if (args.Length != 1) { System.Console.Out.WriteLine("Usage: DefaultXMLParser pipe_encoded_file"); System.Environment.Exit(1); } //read and parse message from file try { System.IO.FileInfo messageFile = new System.IO.FileInfo(args[0]); long fileLength = SupportClass.FileLength(messageFile); //UPGRADE_TODO: Constructor 'java.io.FileReader.FileReader' was converted to 'System.IO.StreamReader' which has a different behavior. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1073'" System.IO.StreamReader r = new System.IO.StreamReader(messageFile.FullName, System.Text.Encoding.Default); char[] cbuf = new char[(int)fileLength]; //UPGRADE_TODO: Method 'java.io.Reader.read' was converted to 'System.IO.StreamReader.Read' which has a different behavior. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1073_javaioReaderread_char[]'" System.Console.Out.WriteLine("Reading message file ... " + r.Read((System.Char[])cbuf, 0, cbuf.Length) + " of " + fileLength + " chars"); r.Close(); System.String messString = System.Convert.ToString(cbuf); Parser inParser = null; Parser outParser = null; PipeParser pp = new PipeParser(); ca.uhn.hl7v2.parser.XMLParser xp = new DefaultXMLParser(); System.Console.Out.WriteLine("Encoding: " + pp.getEncoding(messString)); if (pp.getEncoding(messString) != null) { inParser = pp; outParser = xp; } else if (xp.getEncoding(messString) != null) { inParser = xp; outParser = pp; } Message mess = inParser.parse(messString); System.Console.Out.WriteLine("Got message of type " + mess.GetType().FullName); System.String otherEncoding = outParser.encode(mess); System.Console.Out.WriteLine(otherEncoding); } catch (System.Exception e) { SupportClass.WriteStackTrace(e, Console.Error); } }
public void ParseORFR04() { string message = @"MSH|^~\&|Query Result Locator|Query Facility Name|Query Application Name|ST ELSEWHERE HOSPITAL|20051024074506||ORF^R04|432|P|2.4| MSA|AA|123456789| QRD|20060228160421|R|I||||10^RD&Records&0126|38923^^^^^^^^&TCH||| QRF||20050101000000|| PID|||38923^^^ST ELSEWHERE HOSPITAL Medical Record Numbers& MEDIC AL RECORD NUMBER&ST ELSEWHERE HOSPITAL^MR^ST ELSEWHERE HOSPITAL||Bombadill^Tom||19450605|M|||1&Main Street^^Littleton^CO^80122||^^^^^303^4376329^22| OBR|1|0015566|DH2211223|83036^HEMOGLOBIN A1C^^83036^HEMOGLOBIN A1C|||20040526094000|||||||20040526094000||J12345^JENS^JENNY^^^DR^MD^^^^^^^112233&TCH||||| TP QUEST DIAGNOSTICS-TAMPA 4225 E. FOWLER AVE TAMPA FL 33617|20030622070400|||F| OBX|1|NM|50026400^HEMOGLOBIN A1C^^50026400^HEMOGLOBIN A1C||12|^% TOTAL HGB|4.0 - 6.0|H|||F|||20040510094000|TP^^L|"; ca.uhn.hl7v2.parser.PipeParser parser = new ca.uhn.hl7v2.parser.PipeParser(); ca.uhn.hl7v2.model.Message m = parser.parse(message); ca.uhn.hl7v2.model.v24.message.ORF_R04 orfR04 = m as ca.uhn.hl7v2.model.v24.message.ORF_R04; Assert.IsNotNull(orfR04); Assert.AreEqual("12", orfR04.getRESPONSE().getORDER().getOBSERVATION().OBX.getObservationValue()[0].Data.ToString()); }
public void ParseXMLToHL7() { string message = GetQRYR02XML(); ca.uhn.hl7v2.parser.XMLParser xmlParser = new ca.uhn.hl7v2.parser.DefaultXMLParser(); ca.uhn.hl7v2.model.Message m = xmlParser.parse(message); ca.uhn.hl7v2.model.v24.message.QRY_R02 qryR02 = m as ca.uhn.hl7v2.model.v24.message.QRY_R02; Assert.IsNotNull(qryR02); ca.uhn.hl7v2.parser.PipeParser pipeParser = new ca.uhn.hl7v2.parser.PipeParser(); string pipeOutput = pipeParser.encode(qryR02); Assert.IsNotNull(pipeOutput); Assert.IsFalse(string.Empty.Equals(pipeOutput)); }
public virtual Message parse(System.String message, System.String version) { System.String encoding = getEncoding(message); if (!supportsEncoding(encoding)) { throw new EncodingNotSupportedException("Can't parse message beginning " + message.Substring(0, (System.Math.Min(message.Length, 50)) - (0))); } if (!validVersion(version)) { throw new HL7Exception("Can't process message of version '" + version + "' - version not recognized", HL7Exception.UNSUPPORTED_VERSION_ID); } myValidator.validate(message, encoding.Equals("XML"), version); Message result = doParse(message, version); myValidator.validate(result); return(result); }
/// <summary> <p>Creates an XML Document that corresponds to the given Message object. </p> /// <p>If you are implementing this method, you should create an XML Document, and insert XML Elements /// into it that correspond to the groups and segments that belong to the message type that your subclass /// of XMLParser supports. Then, for each segment in the message, call the method /// <code>encode(Segment segmentObject, Element segmentElement)</code> using the Element for /// that segment and the corresponding Segment object from the given Message.</p> /// </summary> public override System.Xml.XmlDocument encodeDocument(Message source) { System.String messageClassName = source.GetType().FullName; System.String messageName = messageClassName.Substring(messageClassName.LastIndexOf('.') + 1); System.Xml.XmlDocument doc = null; try { //UPGRADE_TODO: Class 'javax.xml.parsers.DocumentBuilder' was converted to 'System.Xml.XmlDocument' which has a different behavior. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1073_javaxxmlparsersDocumentBuilder'" doc = new System.Xml.XmlDocument(); System.Xml.XmlElement root = doc.CreateElement(messageName); doc.AppendChild(root); } catch (System.Exception 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'" throw new HL7Exception("Can't create XML document - " + e.GetType().FullName, HL7Exception.APPLICATION_INTERNAL_ERROR, e); } encode(source, (System.Xml.XmlElement)doc.DocumentElement); return(doc); }
/// <summary> Creates a version-specific MSH object and returns it as a version-independent /// MSH interface. /// throws HL7Exception if there is a problem, e.g. invalid version, code not available /// for given version. /// </summary> public static Segment makeControlMSH(System.String version, ModelClassFactory factory) { Segment msh = null; try { Message dummy = (Message)GenericMessage.getGenericMessageClass(version).GetConstructor(new System.Type[] { typeof(ModelClassFactory) }).Invoke(new System.Object[] { factory }); System.Type[] constructorParamTypes = new System.Type[] { typeof(Group), typeof(ModelClassFactory) }; System.Object[] constructorParamArgs = new System.Object[] { dummy, factory }; System.Type c = factory.getSegmentClass("MSH", version); System.Reflection.ConstructorInfo constructor = c.GetConstructor(constructorParamTypes); msh = (Segment)constructor.Invoke(constructorParamArgs); } catch (System.Exception e) { throw new HL7Exception("Couldn't create MSH for version " + version + " (does your classpath include this version?) ... ", HL7Exception.APPLICATION_INTERNAL_ERROR, e); } return(msh); }
/// <summary> Parses a message string and returns the corresponding Message /// object. Unexpected segments added at the end of their group. /// /// </summary> /// <throws> HL7Exception if the message is not correctly formatted. </throws> /// <throws> EncodingNotSupportedException if the message encoded </throws> /// <summary> is not supported by this parser. /// </summary> protected internal override Message doParse(System.String message, System.String version) { //try to instantiate a message object of the right class MessageStructure structure = getStructure(message); Message m = instantiateMessage(structure.messageStructure, version, structure.explicitlyDefined); //MessagePointer ptr = new MessagePointer(this, m, getEncodingChars(message)); MessageIterator messageIter = new MessageIterator(m, "MSH", true); FilterIterator.Predicate segmentsOnly = new AnonymousClassPredicate(this); FilterIterator segmentIter = new FilterIterator(messageIter, segmentsOnly); System.String[] segments = split(message, segDelim); for (int i = 0; i < segments.Length; i++) { //get rid of any leading whitespace characters ... if (segments[i] != null && segments[i].Length > 0 && System.Char.IsWhiteSpace(segments[i][0])) { segments[i] = stripLeadingWhitespace(segments[i]); } //sometimes people put extra segment delimiters at end of msg ... if (segments[i] != null && segments[i].Length >= 3) { //UPGRADE_NOTE: Final was removed from the declaration of 'name '. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1003'" System.String name = segments[i].Substring(0, (3) - (0)); log.debug("Parsing segment " + name); messageIter.Direction = name; FilterIterator.Predicate byDirection = new AnonymousClassPredicate1(name, this); FilterIterator dirIter = new FilterIterator(segmentIter, byDirection); //UPGRADE_TODO: Method 'java.util.Iterator.hasNext' was converted to 'System.Collections.IEnumerator.MoveNext' which has a different behavior. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1073_javautilIteratorhasNext'" if (dirIter.MoveNext()) { //UPGRADE_TODO: Method 'java.util.Iterator.next' was converted to 'System.Collections.IEnumerator.Current' which has a different behavior. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1073_javautilIteratornext'" parse((Segment)dirIter.Current, segments[i], getEncodingChars(message)); } } } return(m); }
/// <param name="theMessage">message to which this Type belongs /// </param> public TSComponentOne(Message theMessage, string description) : base(theMessage, description) { }
public ID(Message message, System.Int32 theTable, string description) : base(message, description) { myTable = theTable; }
public IS(Message theMessage, System.Int32 theTable, string description) : base(theMessage, theTable, description) { }
/// <param name="theMessage">message to which this Type belongs /// </param> public TSComponentOne(Message theMessage) : base(theMessage) { }
/// <summary> Formats a Message object into an html table object using the given /// </summary> /// <throws> HL7Exception if the data fields in the message do not permit encoding </throws> /// <summary> (e.g. required fields are null) /// </summary> /// <throws> EncodingNotSupportedException if the requested encoding is not </throws> /// <summary> supported by this parser. /// </summary> public Table buildTable(Message source) { //get encoding characters ... Segment msh = (Segment) source.get_Renamed("MSH"); System.String fieldSepString = Terser.Get(msh, 1, 0, 1, 1); if (fieldSepString == null) throw new HL7Exception("Can't encode message: MSH-1 (field separator) is missing"); char fieldSep = '|'; if (fieldSepString != null && fieldSepString.Length > 0) fieldSep = fieldSepString[0]; System.String encCharString = Terser.Get(msh, 2, 0, 1, 1); EncodingCharacters en = new EncodingCharacters(fieldSep, encCharString); //pass down to group encoding method which will operate recursively on children ... Table tbl = new Table(); encode((Group) source, en, tbl); return tbl; }
/// <summary> Formats a Message object into an HL7 message string using this parser's /// default encoding ("VB"). /// </summary> /// <throws> HL7Exception if the data fields in the message do not permit encoding </throws> /// <summary> (e.g. required fields are null) /// </summary> protected internal override System.String doEncode(Message source) { //get encoding characters ... Segment msh = (Segment) source.get_Renamed("MSH"); System.String fieldSepString = Terser.Get(msh, 1, 0, 1, 1); if (fieldSepString == null) throw new HL7Exception("Can't encode message: MSH-1 (field separator) is missing"); char fieldSep = '|'; if (fieldSepString != null && fieldSepString.Length > 0) fieldSep = fieldSepString[0]; System.String encCharString = Terser.Get(msh, 2, 0, 1, 1); if (encCharString == null) throw new HL7Exception("Can't encode message: MSH-2 (encoding characters) is missing"); if (encCharString.Length != 4) throw new HL7Exception("Encoding characters '" + encCharString + "' invalid -- must be 4 characters", HL7Exception.DATA_TYPE_ERROR); EncodingCharacters en = new EncodingCharacters(fieldSep, encCharString); //pass down to group encoding method which will operate recursively on children ... return encode((Group) source, en); }
/// <param name="theMessage">message to which this Type belongs /// </param> /// <param name="theTable">HL7 table from which values are to be drawn /// </param> public ID(Message theMessage, int theTable) : base(theMessage) { myTable = theTable; }
/// <param name="theMessage">message to which this Type belongs /// </param> public DT(Message theMessage) : base(theMessage) { }
/// <param name="message">message to which this Type belongs /// </param> public CM(Message message) : base(message) { }
/// <param name="theMessage">message to which this Type belongs /// </param> /// <param name="theTable">HL7 table from which values are to be drawn /// </param> public IS(Message theMessage, int theTable, string description) : base(theMessage, description) { myTable = theTable; }
/// <summary> Formats a Message object into an HL7 message string using the given /// encoding. /// </summary> /// <throws> HL7Exception if the data fields in the message do not permit encoding </throws> /// <summary> (e.g. required fields are null) /// </summary> /// <throws> EncodingNotSupportedException if the requested encoding is not </throws> /// <summary> supported by this parser. /// </summary> protected internal override System.String doEncode(Message source, System.String encoding) { if (!this.supportsEncoding(encoding)) throw new EncodingNotSupportedException("This parser does not support the " + encoding + " encoding"); return encode(source); }
public static void Main(System.String[] args) { if (args.Length != 1) { System.Console.Out.WriteLine("Usage: XMLParser pipe_encoded_file"); System.Environment.Exit(1); } //read and parse message from file try { PipeParser parser = new PipeParser(); System.IO.FileInfo messageFile = new System.IO.FileInfo(args[0]); long fileLength = SupportClass.FileLength(messageFile); //UPGRADE_TODO: Constructor 'java.io.FileReader.FileReader' was converted to 'System.IO.StreamReader' which has a different behavior. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1073'" System.IO.StreamReader r = new System.IO.StreamReader(messageFile.FullName, System.Text.Encoding.Default); char[] cbuf = new char[(int)fileLength]; //UPGRADE_TODO: Method 'java.io.Reader.read' was converted to 'System.IO.StreamReader.Read' which has a different behavior. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1073_javaioReaderread_char[]'" System.Console.Out.WriteLine("Reading message file ... " + r.Read((System.Char[])cbuf, 0, cbuf.Length) + " of " + fileLength + " chars"); r.Close(); System.String messString = System.Convert.ToString(cbuf); Message mess = parser.parse(messString); System.Console.Out.WriteLine("Got message of type " + mess.GetType().FullName); ca.uhn.hl7v2.parser.XMLParser xp = new AnonymousClassXMLParser(); //loop through segment children of message, encode, print to console System.String[] structNames = mess.Names; for (int i = 0; i < structNames.Length; i++) { Structure[] reps = mess.getAll(structNames[i]); for (int j = 0; j < reps.Length; j++) { if (typeof(Segment).IsAssignableFrom(reps[j].GetType())) { //ignore groups //UPGRADE_TODO: Class 'javax.xml.parsers.DocumentBuilder' was converted to 'System.Xml.XmlDocument' which has a different behavior. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1073_javaxxmlparsersDocumentBuilder'" //UPGRADE_ISSUE: Method 'javax.xml.parsers.DocumentBuilderFactory.newInstance' was not converted. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1000_javaxxmlparsersDocumentBuilderFactory'" //DocumentBuilderFactory.newInstance(); System.Xml.XmlDocument docBuilder = new System.Xml.XmlDocument(); //UPGRADE_TODO: Class 'javax.xml.parsers.DocumentBuilder' was converted to 'System.Xml.XmlDocument' which has a different behavior. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1073_javaxxmlparsersDocumentBuilder'" System.Xml.XmlDocument doc = new System.Xml.XmlDocument(); //new doc for each segment System.Xml.XmlElement root = doc.CreateElement(reps[j].GetType().FullName); doc.AppendChild(root); xp.encode((Segment)reps[j], root); System.IO.StringWriter out_Renamed = new System.IO.StringWriter(); System.Console.Out.WriteLine("Segment " + reps[j].GetType().FullName + ": \r\n" + doc.OuterXml); System.Type[] segmentConstructTypes = new System.Type[] { typeof(Message) }; System.Object[] segmentConstructArgs = new System.Object[] { null }; Segment s = (Segment)reps[j].GetType().GetConstructor(segmentConstructTypes).Invoke(segmentConstructArgs); xp.parse(s, root); //UPGRADE_TODO: Class 'javax.xml.parsers.DocumentBuilder' was converted to 'System.Xml.XmlDocument' which has a different behavior. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1073_javaxxmlparsersDocumentBuilder'" System.Xml.XmlDocument doc2 = new System.Xml.XmlDocument(); System.Xml.XmlElement root2 = doc2.CreateElement(s.GetType().FullName); doc2.AppendChild(root2); xp.encode(s, root2); System.IO.StringWriter out2 = new System.IO.StringWriter(); System.Xml.XmlTextWriter ser = new System.Xml.XmlTextWriter(out2); //System.Xml.XmlWriter ser = System.Xml.XmlWriter.Create(out2); doc.WriteTo(ser); if (out2.ToString().Equals(out_Renamed.ToString())) { System.Console.Out.WriteLine("Re-encode OK"); } else { System.Console.Out.WriteLine("Warning: XML different after parse and re-encode: \r\n" + out2.ToString()); } } } } } catch (System.Exception e) { SupportClass.WriteStackTrace(e, Console.Error); } }
/// <param name="theMessage">message to which this Type belongs /// </param> /// <param name="theTable">HL7 table from which values are to be drawn /// </param> //UPGRADE_ISSUE: Parameter of type 'java.lang.Integer' was migrated to type 'Int32' which is identical to 'int'. You will get a compilation error with method overloads. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1205'" //UPGRADE_NOTE: ref keyword was added to struct-type parameters. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1303'" public ID(Message message, ref System.Int32 theTable) : base(message) { myTable = theTable; }
/// <summary> Called by encode(Message) to perform implementation-specific encoding work. /// /// </summary> /// <param name="source">a Message object from which to construct an encoded message string /// </param> /// <returns> the encoded message /// </returns> /// <throws> HL7Exception if the data fields in the message do not permit encoding </throws> /// <summary> (e.g. required fields are null) /// </summary> /// <throws> EncodingNotSupportedException if the requested encoding is not </throws> /// <summary> supported by this parser. /// </summary> protected internal abstract System.String doEncode(Message source);
/// <param name="theMessage">message to which this Type belongs /// </param> /// <param name="theTable">HL7 table from which values are to be drawn /// </param> public IS(Message theMessage, int theTable) : base(theMessage) { myTable = theTable; }
/// <param name="theMessage">message to which this Type belongs /// </param> public ID(Message theMessage) : base(theMessage) { }
/// <param name="theMessage">message to which this Type belongs /// </param> /// <param name="theTable">HL7 table from which values are to be drawn /// </param> public IS(Message theMessage, int theTable) : base(theMessage, theTable) { }
/// <param name="theMessage">message to which this Type belongs /// </param> public TM(Message theMessage) : base(theMessage) { }
public TM(Message theMessage, string description) : base(theMessage, description) { }
/// <summary> <p>Creates an XML Document that corresponds to the given Message object. </p> /// <p>If you are implementing this method, you should create an XML Document, and insert XML Elements /// into it that correspond to the groups and segments that belong to the message type that your subclass /// of XMLParser supports. Then, for each segment in the message, call the method /// <code>encode(Segment segmentObject, Element segmentElement)</code> using the Element for /// that segment and the corresponding Segment object from the given Message.</p> /// </summary> public abstract System.Xml.XmlDocument encodeDocument(Message source);
/// <summary> Formats a Message object into an HL7 message string using the given /// encoding. /// </summary> /// <throws> HL7Exception if the data fields in the message do not permit encoding </throws> /// <summary> (e.g. required fields are null) /// </summary> /// <throws> EncodingNotSupportedException if the requested encoding is not </throws> /// <summary> supported by this parser. /// </summary> protected internal override System.String doEncode(Message source, System.String encoding) { if (!encoding.Equals("XML")) throw new EncodingNotSupportedException("XMLParser supports only XML encoding"); return encode(source); }
/// <summary> Formats a Message object into an HL7 message string using this parser's /// default encoding. /// /// </summary> /// <param name="source">a Message object from which to construct an encoded message string /// </param> /// <param name="encoding">the name of the encoding to use (eg "XML"; most implementations support only one /// encoding) /// </param> /// <returns> the encoded message /// </returns> /// <throws> HL7Exception if the data fields in the message do not permit encoding </throws> /// <summary> (e.g. required fields are null) /// </summary> public virtual System.String encode(Message source) { System.String encoding = DefaultEncoding; myValidator.validate(source); System.String result = doEncode(source); myValidator.validate(result, encoding.Equals("XML"), source.Version); return result; }
public override System.Xml.XmlDocument encodeDocument(Message source) { return(null); }
/// <summary> Formats a Message object into an HL7 message string using this parser's /// default encoding (XML encoding). This method calls the abstract method /// <code>encodeDocument(...)</code> in order to obtain XML Document object /// representation of the Message, then serializes it to a String. /// </summary> /// <throws> HL7Exception if the data fields in the message do not permit encoding </throws> /// <summary> (e.g. required fields are null) /// </summary> protected internal override System.String doEncode(Message source) { if (source is GenericMessage) { throw new HL7Exception("Can't XML-encode a GenericMessage. Message must have a recognized structure."); } System.Xml.XmlDocument doc = encodeDocument(source); //UPGRADE_TODO: Method 'org.w3c.dom.Element.setAttribute' was converted to 'System.Xml.XmlElement.SetAttribute' which has a different behavior. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1073_orgw3cdomElementsetAttribute_javalangString_javalangString'" ((System.Xml.XmlElement) doc.DocumentElement).SetAttribute("xmlns", "urn:hl7-org:v2xml"); System.IO.StringWriter out_Renamed = new System.IO.StringWriter(); return doc.OuterXml; //OutputFormat outputFormat = new OutputFormat("", null, true); //XMLSerializer ser = new XMLSerializer(out_Renamed, outputFormat); //default output format //try //{ // ser.serialize(doc); //} //catch (System.IO.IOException e) //{ // throw new HL7Exception("IOException serializing XML document to string", HL7Exception.APPLICATION_INTERNAL_ERROR, e); //} //return out_Renamed.ToString(); }
/// <param name="theMessage">message to which this Type belongs /// </param> /// <param name="theTable">HL7 table from which values are to be drawn /// </param> //UPGRADE_ISSUE: Parameter of type 'java.lang.Integer' was migrated to type 'Int32' which is identical to 'int'. You will get a compilation error with method overloads. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1205'" //UPGRADE_NOTE: ref keyword was added to struct-type parameters. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1303'" public IS(Message theMessage, ref System.Int32 theTable) : base(theMessage) { myTable = theTable; }
public override System.Xml.XmlDocument encodeDocument(Message source) { return null; }
/// <summary> <p>Creates an XML Document that corresponds to the given Message object. </p> /// <p>If you are implementing this method, you should create an XML Document, and insert XML Elements /// into it that correspond to the groups and segments that belong to the message type that your subclass /// of XMLParser supports. Then, for each segment in the message, call the method /// <code>encode(Segment segmentObject, Element segmentElement)</code> using the Element for /// that segment and the corresponding Segment object from the given Message.</p> /// </summary> public override System.Xml.XmlDocument encodeDocument(Message source) { System.String messageClassName = source.GetType().FullName; System.String messageName = messageClassName.Substring(messageClassName.LastIndexOf('.') + 1); System.Xml.XmlDocument doc = null; try { //UPGRADE_TODO: Class 'javax.xml.parsers.DocumentBuilder' was converted to 'System.Xml.XmlDocument' which has a different behavior. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1073_javaxxmlparsersDocumentBuilder'" doc = new System.Xml.XmlDocument(); System.Xml.XmlElement root = doc.CreateElement(messageName); doc.AppendChild(root); } catch (System.Exception 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'" throw new HL7Exception("Can't create XML document - " + e.GetType().FullName, HL7Exception.APPLICATION_INTERNAL_ERROR, e); } encode(source, (System.Xml.XmlElement) doc.DocumentElement); return doc; }