Exemple #1
0
        static void Main(string[] args)
        {
            string x12Filename    = args[0];
            string outputFilename = args.Length > 1 ? args[1] : x12Filename + ".edi";

            if (x12Filename.Length == 0)
            {
                Console.WriteLine("There was an error reading the input file argument. Please check the path and filename.");
                return;
            }
            var    fs      = new StreamReader(x12Filename);
            string xmltext = fs.ReadToEnd();
            var    parser  = new X12Parser();
            string x12     = string.Empty;

            try
            {
                x12 = parser.TransformToX12(xmltext);
            }
            catch (Exception ex)
            {
                Console.WriteLine("The transformation encountered a problem: " + ex.Message + " -> " + ex.InnerException);
            }
            finally
            {
                fs.Close();
            }

            var outputFs = new FileStream(outputFilename, FileMode.Create);
            var writer   = new StreamWriter(outputFs);

            writer.Write(x12);
            writer.Close();
        }
Exemple #2
0
        public void ParseInterchangeToXml()
        {
            var x = new XmlDocument();

            var         i   = new Interchange(DateTime.Now, 1, true);
            var         fg  = i.AddFunctionGroup("HS", DateTime.Now, 11, "005010X279A1");
            Transaction st  = fg.AddTransaction("270", "1001");
            var         xml = i.Serialize(true);

            x.PreserveWhitespace = true;
            x.LoadXml(xml);
            var assertCount = new Action <string, int>((s, c) =>
            {
                var o = int.Parse(x.SelectSingleNode(s).InnerText);
                Assert.IsNotNull(o);
                Assert.AreEqual(c, o, s + " count is wrong");
            });

            assertCount("Interchange/IEA/IEA01", 1);
            assertCount("Interchange/FunctionGroup/GE/GE01", 1);
            assertCount("Interchange/FunctionGroup/Transaction/SE/SE01", 2);

            var prsr = new X12Parser();
            var edi  = prsr.TransformToX12(x.OuterXml);

            prsr.ParseMultiple(edi);
        }
        public void ParseModifyAndTransformBackToX12(
            [ValueSource(typeof(ResourcePathManager), nameof(ResourcePathManager.ResourcePaths))]
            string resourcePath)
        {
            var stream = GetEdi("INS._270._4010.Example1_DHHS.txt");

            var         parser      = new X12Parser();
            Interchange interchange = parser.ParseMultiple(stream).First();
            string      xml         = interchange.Serialize();

            var doc = new XmlDocument
            {
                PreserveWhitespace = true
            };

            doc.LoadXml(xml);

            XmlElement dmgElement = (XmlElement)doc.GetElementsByTagName("DMG")[0];

            dmgElement.ParentNode.RemoveChild(dmgElement);

            string x12 = parser.TransformToX12(doc.OuterXml);

            var    modifiedInterchange = parser.ParseMultiple(x12).First();
            string newX12 = modifiedInterchange.SerializeToX12(true);

            var seSegment = modifiedInterchange.FunctionGroups.First().Transactions.First().TrailerSegments.FirstOrDefault(ts => ts.SegmentId == "SE");

            Assert.IsNotNull(seSegment);
            Assert.AreEqual("0001", seSegment.GetElement(2));
            Assert.AreEqual("15", seSegment.GetElement(1));
        }
        public void ParseModifyAndTransformBackToX12()
        {
            var stream = GetEdi("INS._270._4010.Example1_DHHS.txt");

            var         parser      = new X12Parser();
            Interchange interchange = parser.ParseMultiple(stream).First();
            string      originalX12 = interchange.SerializeToX12(true);

            string xml = interchange.Serialize();

            XmlDocument doc = new XmlDocument();

            doc.PreserveWhitespace = true;
            doc.LoadXml(xml);

            XmlElement dmgElement = (XmlElement)(doc.GetElementsByTagName("DMG")[0]);

            dmgElement.ParentNode.RemoveChild(dmgElement);

            Console.WriteLine(doc.OuterXml);
            string x12 = parser.TransformToX12(doc.OuterXml);

            Console.WriteLine("ISA Segmemt:");
            Console.WriteLine(x12.Substring(0, 106));
            Console.WriteLine("Directly from XML:");
            Console.WriteLine(x12);


            var modifiedInterchange = parser.ParseMultiple(x12).First();

            string newX12 = modifiedInterchange.SerializeToX12(true);

            Console.WriteLine("After passing through interchange object:");
            Console.WriteLine(newX12);

            var seSegment = modifiedInterchange.FunctionGroups.First().Transactions.First().TrailerSegments.FirstOrDefault(ts => ts.SegmentId == "SE");

            Assert.IsNotNull(seSegment);
            Assert.AreEqual("0001", seSegment.GetElement(2));
            Assert.AreEqual("15", seSegment.GetElement(1));
        }
        public void ParseAndTransformToX12()
        {
            string resourcePath = Convert.ToString(TestContext.DataRow["ResourcePath"]);  // "INS._837P._4010.Spec_4.1.1_PatientIsSubscriber.txt";

            if (!resourcePath.Contains("_0x1D"))
            {
                Trace.WriteLine(resourcePath);
                Stream stream = GetEdi(resourcePath);

                var         parser      = new X12Parser();
                Interchange interchange = parser.ParseMultiple(stream).First();
                string      originalX12 = interchange.SerializeToX12(true);

                string xml = interchange.Serialize();
                string x12 = parser.TransformToX12(xml);

                Interchange newInterchange = parser.ParseMultiple(x12).First();
                string      newX12         = newInterchange.SerializeToX12(true);

                Assert.AreEqual(originalX12, newX12);
                Trace.Write(x12);
            }
        }
        public void ParseAndTransformToX12(
            [ValueSource(typeof(ResourcePathManager), nameof(ResourcePathManager.ResourcePaths))]
            string resourcePath)
        {
            if (!resourcePath.Contains("_0x1D"))
            {
                // arrange
                Stream stream = GetEdi(resourcePath);

                // act
                var         parser      = new X12Parser();
                Interchange interchange = parser.ParseMultiple(stream).First();
                string      originalX12 = interchange.SerializeToX12(true);

                string xml = interchange.Serialize();
                string x12 = parser.TransformToX12(xml);

                Interchange newInterchange = parser.ParseMultiple(x12).First();
                string      newX12         = newInterchange.SerializeToX12(true);

                // assert
                Assert.AreEqual(originalX12, newX12);
            }
        }