Example #1
0
        /// <seealso cref="Genetibase.NuGenHL7.parser.Parser.doParse(java.lang.String, java.lang.String)">
        /// </seealso>
        protected internal override Message doParse(System.String message, System.String version)
        {
            Message result = null;

            char fieldSep = message[3];
            NuGenEncodingCharacters ec = new NuGenEncodingCharacters(fieldSep, message.Substring(4, (8) - (4)));

            SupportClass.Tokenizer tok = new SupportClass.Tokenizer(message.Substring(4), System.Convert.ToString(new char[] { fieldSep, ourSegmentSeparator }), true);

            System.String[] mshFields = getMSHFields(tok, fieldSep);
            System.Object[] structure = getStructure(mshFields[8], ec.ComponentSeparator);

            StructRef root = (StructRef)myEventGuideMap[structure[0]];

            if (root == null)
            {
                result = myPipeParser.parse(message);
            }
            else
            {
                int csIndex = mshFields[11].IndexOf((System.Char)ec.ComponentSeparator);
                result = instantiateMessage((System.String)structure[1], version, ((System.Boolean)structure[2]));

                StructRef mshRef = null;
                lock (root)
                {
                    mshRef = root.getSuccessor("MSH");
                    root.reset();
                }
                Segment msh = (Segment)result.get_Renamed("MSH");
                for (int i = 0; i < mshRef.Fields.Length; i++)
                {
                    int fieldNum = mshRef.Fields[i];
                    parse(mshFields[fieldNum - 1], msh, fieldNum, ec);
                }

                parse(tok, result, root, ec);
            }

            return(result);
        }
Example #2
0
        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
            {
                NuGenPipeParser    parser      = new NuGenPipeParser();
                System.IO.FileInfo messageFile = new System.IO.FileInfo(args[0]);
                long fileLength          = SupportClass.FileLength(messageFile);
                System.IO.StreamReader r = new System.IO.StreamReader(messageFile.FullName, System.Text.Encoding.Default);
                char[] cbuf = new char[(int)fileLength];
                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);

                Genetibase.NuGenHL7.parser.NuGenXMLParser 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
                            System.Xml.XmlDocument docBuilder = new System.Xml.XmlDocument();
                            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" + out_Renamed.ToString());

                            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);
                            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();

                            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);
            }
        }
		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
			{
				NuGenPipeParser parser = new NuGenPipeParser();
				System.IO.FileInfo messageFile = new System.IO.FileInfo(args[0]);
				long fileLength = SupportClass.FileLength(messageFile);
				System.IO.StreamReader r = new System.IO.StreamReader(messageFile.FullName, System.Text.Encoding.Default);
				char[] cbuf = new char[(int) fileLength];
				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);
				
				Genetibase.NuGenHL7.parser.NuGenXMLParser 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
							System.Xml.XmlDocument docBuilder = new System.Xml.XmlDocument();
							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" + out_Renamed.ToString());
							
							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);
							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();

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