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 OutlineIsSameAsOriginal()
        {
            var         parser      = new X12Parser();
            Interchange interchange = parser.ParseMultiple(new MemoryStream(Encoding.ASCII.GetBytes(this.inquiry))).First();

            Interchange interchangeFromOutline = parser.ParseMultiple(new MemoryStream(Encoding.ASCII.GetBytes(this.inquiryOutline))).First();

            Assert.AreEqual(interchange.SerializeToX12(false), interchangeFromOutline.SerializeToX12(false));
        }
Ejemplo n.º 3
0
        static void Main(string[] args)
        {
            var opts = new ExecutionOptions();

            try
            {
                opts.LoadOptions(args);
            }
            catch (ArgumentException exc)
            {
                Console.Write(exc.Message);
                return;
            }

            X12Parser parser = new X12Parser();

            foreach (var filename in Directory.GetFiles(opts.InputDirectory, opts.FilenamePattern))
            {
                FileInfo           inputFile = new FileInfo(filename);
                List <Interchange> list      = new List <Interchange>();
                using (FileStream fs = new FileStream(inputFile.FullName, FileMode.Open, FileAccess.Read))
                {
                    X12StreamReader    reader      = new X12StreamReader(fs, Encoding.UTF8);
                    X12FlatTransaction transaction = reader.ReadNextTransaction();
                    while (!string.IsNullOrEmpty(transaction.Transactions.First()))
                    {
                        string x12         = transaction.ToString();
                        var    interchange = parser.ParseMultiple(x12).First();
                        if (opts.LoopId == "ST")
                        {
                            list.Add(interchange);
                        }
                        else
                        {
                            list.AddRange(parser.UnbundleByLoop(interchange, opts.LoopId));
                        }
                        transaction = reader.ReadNextTransaction();
                    }
                }
                List <Interchange> interchanges = parser.ParseMultiple(new FileStream(filename, FileMode.Open, FileAccess.Read));
                for (int i = 0; i < list.Count; i++)
                {
                    string outputFilename = String.Format(opts.FormatString, opts.OutputDirectory, inputFile.Name, i + 1, inputFile.Extension);
                    using (FileStream outputFilestream = new FileStream(outputFilename, FileMode.Create, FileAccess.Write))
                    {
                        using (StreamWriter writer = new StreamWriter(outputFilestream))
                        {
                            writer.Write(list[i].SerializeToX12(opts.IncludeWhitespace));
                            writer.Close();
                        }
                        outputFilestream.Close();
                    }
                }
            }
        }
Ejemplo n.º 4
0
        public override XmlDocument Load(TextReader txtReader, XmlDocument xDoc = null)
        {
            #region setup the rootNode
            XmlNode rootNode;
            if (xDoc == null)
            {
                xDoc = new XmlDocument();
            }
            if (xDoc.DocumentElement == null)
            {
                rootNode = xDoc.CreateElement(RootNodeName);
                xDoc.AppendChild(rootNode);
            }

            rootNode = xDoc.DocumentElement;
            #endregion

            X12Parser          parser       = new X12Parser(false);
            List <Interchange> interchanges = parser.ParseMultiple(txtReader.ReadToEnd());
            foreach (Interchange interchange in interchanges)
            {
                string      xmlContent          = interchange.Serialize(true);
                XmlDocument interchangeDocument = new XmlDocument();
                interchangeDocument.LoadXml(xmlContent);
                foreach (XmlNode interchangeNode in interchangeDocument.SelectNodes("Interchange"))
                {
                    XmlNode childNode = xDoc.ImportNode(interchangeNode, true);
                    rootNode.AppendChild(childNode);
                }
            }

            return(xDoc);
        }
Ejemplo n.º 5
0
        public EligibilityBenefitDocument Transform271ToBenefitResponse(Stream stream)
        {
            EligibilityBenefitDocument fullResponse = new EligibilityBenefitDocument();

            var parser       = new X12Parser();
            var interchanges = parser.ParseMultiple(stream);

            foreach (var interchange in interchanges)
            {
                var xml = interchange.Serialize();

                var transformStream = Assembly.GetExecutingAssembly().GetManifestResourceStream("OopFactory.X12.Hipaa.Eligibility.Services.Xsl.X12-271-To-BenefitResponse.xslt");

                var transform = new XslCompiledTransform();
                if (transformStream != null)
                {
                    transform.Load(XmlReader.Create(transformStream));
                }

                var outputStream = new MemoryStream();

                transform.Transform(XmlReader.Create(new StringReader(xml)), new XsltArgumentList(), outputStream);
                outputStream.Position = 0;
                string responseXml = new StreamReader(outputStream).ReadToEnd();
                var    response    = EligibilityBenefitDocument.Deserialize(responseXml);
                fullResponse.EligibilityBenefitInquiries.AddRange(response.EligibilityBenefitInquiries);
                fullResponse.EligibilityBenefitResponses.AddRange(response.EligibilityBenefitResponses);
                fullResponse.RequestValidations.AddRange(response.RequestValidations);
            }
            return(fullResponse);
        }
Ejemplo n.º 6
0
        public void UnbundleItemsFrom856Test()
        {
            var         parser      = new X12Parser();
            Interchange interchange = parser.ParseMultiple(Extensions.GetEdi("ORD._856.Example1.txt")).First();

            var list = parser.UnbundleByLoop(interchange, "ITEM");
        }
Ejemplo n.º 7
0
        public void FlattenUsingXmlDocument()
        {
            Stream stream = Assembly.GetExecutingAssembly().GetManifestResourceStream("OopFactory.X12.Tests.Unit.Parsing._SampleEdiFiles.ORD._820.Example1_MortgageBankers.txt");

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

            XmlDocument doc = new XmlDocument();

            doc.LoadXml(xml);

            FileStream   fstream = new FileStream("ORD._820.Example1.txt", FileMode.Create);
            StreamWriter writer  = new StreamWriter(fstream);

            writer.WriteLine("Transaction,Creation Date,Submitter Name, Borrower Last Name, Remittance ID");
            foreach (XmlElement transaction in doc.SelectNodes("/Interchange/FunctionGroup/Transaction"))
            {
                foreach (XmlElement entity in transaction.SelectNodes("Loop[@LoopId='ENT']"))
                {
                    foreach (XmlElement remit in entity.SelectNodes("Loop[@LoopId='RMR']"))
                    {
                        writer.WriteLine("{0},{1},{2},{3},{4}",
                                         transaction.SelectSingleNode("ST/ST02").InnerText,
                                         transaction.SelectSingleNode("DTM[DTM01='097']/DTM02").InnerText,
                                         transaction.SelectSingleNode("Loop[@LoopId='N1']/N1[N101='41']/N102").InnerText,
                                         entity.SelectSingleNode("Loop[@LoopId='NM1']/NM1[NM101='BW']/NM103").InnerText,
                                         remit.SelectSingleNode("RMR/RMR02").InnerText);
                    }
                }
            }

            writer.Close();
            fstream.Close();
        }
Ejemplo n.º 8
0
        public void ParseAndUnparse()
        {
            string resourcePath = Convert.ToString(TestContext.DataRow["ResourcePath"]);

            Trace.WriteLine(resourcePath);
            Stream stream     = GetEdi(resourcePath);
            string orignalX12 = new StreamReader(stream).ReadToEnd();

            stream = GetEdi(resourcePath);
            var parser = new X12Parser();

            parser.ParserWarning += new X12Parser.X12ParserWarningEventHandler(parser_ParserWarning);
            List <Interchange> interchanges = parser.ParseMultiple(stream);

            if (resourcePath.Contains("_811"))
            {
                Trace.Write("");
            }

            StringBuilder x12 = new StringBuilder();

            foreach (var interchange in interchanges)
            {
                x12.AppendLine(interchange.SerializeToX12(true));
            }

            Assert.AreEqual(orignalX12, x12.ToString().Trim());
            Trace.Write(x12.ToString());
        }
Ejemplo n.º 9
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);
        }
Ejemplo n.º 10
0
        public void LoadAllTestFiles()
        {
            var repo = new SqlTransactionRepository <long>("Data Source=127.0.0.1;Initial Catalog=X12;Integrated Security=True", new SpecificationFinder(),
                                                           new string[] { "AMT",
                                                                          "BHT",
                                                                          "CAS",
                                                                          "CL1",
                                                                          "CLM",
                                                                          "CN1",
                                                                          "DMG",
                                                                          "DN1",
                                                                          "DTP",
                                                                          "HCP",
                                                                          "HI",
                                                                          "HL",
                                                                          "K3",
                                                                          "LX",
                                                                          "MEA",
                                                                          "N3",
                                                                          "N4",
                                                                          "NM1",
                                                                          "NTE",
                                                                          "OI",
                                                                          "PAT",
                                                                          "PER",
                                                                          "PRV",
                                                                          "PWK",
                                                                          "QTY",
                                                                          "REF",
                                                                          "SBR",
                                                                          "SV1",
                                                                          "SV2",
                                                                          "SV3",
                                                                          "SVD",
                                                                          "TOO", }, "Inbound");

            var parser = new X12Parser();

            foreach (var resource in Assembly.GetExecutingAssembly().GetManifestResourceNames())
            {
                if (resource.StartsWith("OopFactory.X12.Tests.Unit.Parsing._SampleEdiFiles") && !resource.EndsWith(".xml"))
                {
                    var stream = Assembly.GetExecutingAssembly().GetManifestResourceStream(resource);

                    try
                    {
                        var interchanges = parser.ParseMultiple(stream);
                        foreach (var interchange in interchanges)
                        {
                            repo.Save(interchange, resource, "dstrubhar");
                        }
                    }
                    catch (Exception exc)
                    {
                        Trace.WriteLine(resource);
                        Trace.WriteLine(exc.Message);
                    }
                }
            }
        }
Ejemplo n.º 11
0
        static void Main(string[] args)
        {
            string dsn = ConfigurationManager.ConnectionStrings["X12"].ConnectionString;

            bool throwExceptionOnSyntaxErrors = ConfigurationManager.AppSettings["ThrowExceptionOnSyntaxErrors"] == "true";

            string[] segments           = ConfigurationManager.AppSettings["IndexedSegments"].Split(',');
            string   parseDirectory     = ConfigurationManager.AppSettings["ParseDirectory"];
            string   parseSearchPattern = ConfigurationManager.AppSettings["ParseSearchPattern"];
            string   archiveDirectory   = ConfigurationManager.AppSettings["ArchiveDirectory"];
            string   failureDirectory   = ConfigurationManager.AppSettings["FailureDirectory"];
            string   sqlDateType        = ConfigurationManager.AppSettings["SqlDateType"];
            int      segmentBatchSize   = Convert.ToInt32(ConfigurationManager.AppSettings["SqlSegmentBatchSize"]);

            var specFinder = new SpecificationFinder();
            var parser     = new X12Parser(throwExceptionOnSyntaxErrors);

            parser.ParserWarning += new X12Parser.X12ParserWarningEventHandler(parser_ParserWarning);
            var repo = new SqlTransactionRepository <int>(dsn, specFinder, segments, ConfigurationManager.AppSettings["schema"], ConfigurationManager.AppSettings["containerSchema"], segmentBatchSize, sqlDateType);

            foreach (var filename in Directory.GetFiles(parseDirectory, parseSearchPattern, SearchOption.AllDirectories))
            {
                byte[] header = new byte[6];
                using (FileStream fs = new FileStream(filename, FileMode.Open, FileAccess.Read))
                {
                    // peak at first 6 characters to determine if this is a unicode file
                    fs.Read(header, 0, 6);
                    fs.Close();
                }
                Encoding encoding = (header[1] == 0 && header[3] == 0 && header[5] == 0) ? Encoding.Unicode : Encoding.UTF8;


                var fi = new FileInfo(filename);
                using (FileStream fs = new FileStream(filename, FileMode.Open, FileAccess.Read))
                {
                    try
                    {
                        var interchanges = parser.ParseMultiple(fs, encoding);

                        foreach (var interchange in interchanges)
                        {
                            repo.Save(interchange, filename, Environment.UserName);
                        }
                        if (!string.IsNullOrWhiteSpace(archiveDirectory))
                        {
                            MoveTo(fi, parseDirectory, archiveDirectory);
                        }
                    }
                    catch (Exception exc)
                    {
                        Trace.TraceError("Error parsing {0}: {1}\n{2}", fi.FullName, exc.Message, exc.StackTrace);
                        if (!string.IsNullOrEmpty(failureDirectory))
                        {
                            MoveTo(fi, parseDirectory, failureDirectory);
                        }
                    }
                }
            }
        }
        public void ParseUnicodeFile()
        {
            // arrange
            var fs     = Assembly.GetExecutingAssembly().GetManifestResourceStream("X12.Tests.Unit.Parsing._SampleEdiFiles.INS._837P._5010.UnicodeExample.txt");
            var parser = new X12Parser();

            // act - assert
            var interchange = parser.ParseMultiple(fs, Encoding.Unicode);
        }
Ejemplo n.º 13
0
        public void Unbundling835ByLoop2110()
        {
            X12Parser   parser      = new X12Parser();
            Interchange interchange = parser.ParseMultiple(Extensions.GetEdi("INS._835._4010.Example1_GripElements.txt")).First();

            var list = parser.UnbundleByLoop(interchange, "2110");

            Assert.AreEqual(9, list.Count);
        }
Ejemplo n.º 14
0
        public List <Interchange> GetInterchanges(string filename)
        {
            var fs           = new FileStream(filename, FileMode.Open, FileAccess.Read);
            var parser       = new X12Parser();
            var interchanges = parser.ParseMultiple(fs);

            fs.Close();
            return(interchanges);
        }
Ejemplo n.º 15
0
        public void UnbundleClaimsIn837FromNthTest()
        {
            X12Parser   parser      = new X12Parser();
            Interchange interchange = parser.ParseMultiple(Extensions.GetEdi("INS._837P._4010.FromNth.837_DeIdent_05.dat")).First();

            var list = parser.UnbundleByLoop(interchange, "2300");

            Assert.AreEqual(186, list.Count);
        }
Ejemplo n.º 16
0
        public void ParseUnicodeFile()
        {
            var fs = Assembly.GetExecutingAssembly().GetManifestResourceStream("OopFactory.X12.Tests.Unit.Parsing._SampleEdiFiles.INS._837P._5010.UnicodeExample.txt");


            X12Parser parser      = new X12Parser();
            var       interchange = parser.ParseMultiple(fs, Encoding.Unicode);

            Trace.Write(interchange.First().Serialize());
        }
Ejemplo n.º 17
0
        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));
        }
Ejemplo n.º 18
0
        public void Unbundle835FromNthTest()
        {
            // arrange
            var         parser      = new X12Parser();
            Interchange interchange = parser.ParseMultiple(Extensions.GetEdi("INS._835._4010.FromNth.835_DeIdent_02.dat")).First();

            // act
            var list = parser.UnbundleByLoop(interchange, "2000");

            // assert
            Assert.AreEqual(6, list.Count);
        }
Ejemplo n.º 19
0
        public void UnbundleItemsFrom856Test()
        {
            X12Parser   parser      = new X12Parser();
            Interchange interchange = parser.ParseMultiple(Extensions.GetEdi("ORD._856.Example1.txt")).First();

            var list = parser.UnbundleByLoop(interchange, "ITEM");

            foreach (var item in list)
            {
                Trace.WriteLine("...");
                Trace.WriteLine(item.SerializeToX12(true));
            }
        }
Ejemplo n.º 20
0
        /// <summary>
        /// Reads a claim that has been st
        /// </summary>
        /// <param name="stream"></param>
        /// <returns></returns>
        public ClaimDocument Transform837ToClaimDocument(Stream stream)
        {
            var           interchanges = _parser.ParseMultiple(stream);
            ClaimDocument doc          = new ClaimDocument();

            foreach (var interchange in interchanges)
            {
                var thisDoc = Transform837ToClaimDocument(interchange);
                AddRevenueCodeDescription(thisDoc);
                doc.Claims.AddRange(thisDoc.Claims);
            }
            return(doc);
        }
        /// <summary>
        /// Reads a claim that has been st
        /// </summary>
        /// <param name="stream"></param>
        /// <returns></returns>
        public ClaimDocument Transform837ToClaimDocument(Stream stream)
        {
            var           parser       = new X12Parser();
            var           interchanges = parser.ParseMultiple(stream);
            ClaimDocument doc          = new ClaimDocument();

            foreach (var interchange in interchanges)
            {
                var thisDoc = Transform837ToClaimDocument(interchange);
                doc.Claims.AddRange(thisDoc.Claims);
            }
            return(doc);
        }
Ejemplo n.º 22
0
        public void TransToDentalClaim5010()
        {
            string x12 = @"ISA*00*          *00*          *01*9012345720000  *01*9088877320000  *020816*1144*U*00401*000000031*1*T*:~
  GS*HC*901234572000*908887732000*20070816*1615*31*X*005010X096A1~
    ST*837*873501~
      BHT*0019*00*0125*19970411*1524*CH~
      REF*87*004010X097~
      NM1*41*2*DENTAL ASSOCIATES*****46*579999999~
        PER*IC*SYDNEY SNOW*TE*2125557987~
      NM1*40*2*HEISMAN INSURANCE COMPANY*****46*555667777~
      HL*1**20*1~
        NM1*85*2*DENTAL ASSOCIATES*****XX*591PD123~
          N3*10 1/2 SHOEMAKER STREET~
          N4*COBBLER*CA*99997~
          REF*TJ*579999999~
        HL*2*1*22*1~
          SBR*P*****6***LM~
          NM1*IL*1*HOWLING*HAL****MI*B99977791G~
          NM1*PR*2*HEISMAN INSURANCE COMPANY*****PI*999888777~
          HL*3*2*23*0~
            PAT*41~
            NM1*QC*1*DIMPSON*D*J***34*567324788~
              N3*32 BUFFALO RUN~
              N4*ROCKING HORSE*CA*99666~
              DMG*D8*19480601*M~
              REF*Y4*32323232~
            CLM*900000032*390***11::1*Y**Y*Y**AA:::CA~
              DTP*439*D8*19970201~
              DTP*472*D8*19970202~
              NM1*82*1*MOGLIE*BRUNO****34*224873702~
                PRV*PE*ZZ*122300000N~
              LX*1~
                SV3*AD:D0330*40****1~
              LX*2~
                SV3*AD:D5820*350***I*1~
                TOO*JP*8~
                TOO*JP*9*M~
                TOO*JP*13*M:O~
    SE*35*873501~
  GE*1*31~
IEA*1*000000031~";

            var service = new ClaimTransformationService();

            var x12Parser = new X12Parser();
            var document  = service.Transform837ToClaimDocument(x12Parser.ParseMultiple(x12).First());

            Claim claim = document.Claims.First();

            Assert.AreEqual(3, claim.ServiceLines.Sum(sl => sl.ToothInformations.Count));
        }
Ejemplo n.º 23
0
        public void UnbundleClaimsIn837ByServiceLineTest()
        {
            // arrange
            string lastServiceLine = @"ISA*00*          *01*SECRET    *ZZ*SUBMITTERS.ID  *ZZ*RECEIVERS.ID   *930602*1253*^*00401*000000905*1*T*:~
  GS*HC*SENDER CODE*RECEIVER CODE*1994033*0802*1*X*004010X098A1~
    ST*837*0021~
      BHT*0019*00*0123*19981015*1023*RP~
      REF*87*004010X098~
      NM1*41*2*PREMIER BILLING SERVICE*****46*TGJ23~
        PER*IC*JERRY*TE*3055552222*EX*231~
      NM1*40*2*REPRICER XYZ*****46*66783JJT~
      HL*1**20*1~
        NM1*85*2*PREMIER BILLING SERVICE*****24*587654321~
          N3*234 Seaway St~
          N4*Miami*FL*33111~
        NM1*87*2*KILDARE ASSOC*****24*581234567~
          N3*2345 OCEAN BLVD~
          N4*MIAMI*FL*33111~
        HL*2*1*22*0~
          SBR*P*18*12312-A******HM~
          NM1*IL*1*SMITH*TED****34*000221111~
            N3*236 N MAIN ST~
            N4*MIAMI*FL*33413~
            DMG*D8*19430501*M~
          NM1*PR*2*ALLIANCE HEALTH AND LIFE INSURANCE*****PI*741234~
          CLM*26462967*100***11::1*Y*A*Y*Y*C~
            DTP*431*D8*19981003~
            REF*D9*17312345600006351~
            HI*BK:0340*BF:V7389~
            NM1*82*1*KILDARE*BEN****34*112233334~
              PRV*PE*ZZ*203BF0100Y~
            NM1*77*2*KILDARE ASSOCIATES*****24*581234567~
              N3*2345 OCEAN BLVD~
              N4*MIAMI*FL*33111~
            LX*4~
              SV1*HC:86663*10*UN*1***2**N~
              DTP*472*D8*19981010~
    SE*33*0021~
  GE*1*1~
IEA*1*000000905~";

            var         parser      = new X12Parser();
            Interchange interchange = parser.ParseMultiple(Extensions.GetEdi("INS._837P._4010.Spec_4.1.1_PatientIsSubscriber.txt")).First();

            // act
            var list = parser.UnbundleByLoop(interchange, "2400");

            // assert
            Assert.AreEqual(4, list.Count);
            Assert.AreEqual(lastServiceLine, list[3].SerializeToX12(true));
        }
Ejemplo n.º 24
0
        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);
            }
        }
Ejemplo n.º 25
0
        public void ParseToXml()
        {
            string resourcePath = Convert.ToString(TestContext.DataRow["ResourcePath"]);

            Trace.WriteLine(resourcePath);
            Stream stream = GetEdi(resourcePath);

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

#if DEBUG
            new FileStream(resourcePath.Replace(".txt", ".xml"), FileMode.Create).PrintToFile(xml);
#endif
            XmlDocument doc = new XmlDocument();
            doc.LoadXml(xml);
            int    index = 1;
            string query = GetXPathQuery(index);
            while (!string.IsNullOrWhiteSpace(query))
            {
                string  expected = GetExpectedValue(index);
                XmlNode node     = doc.SelectSingleNode((string)query);
                Assert.IsNotNull(node, "Query '{0}' not found in {1}.", query, resourcePath);
                Assert.AreEqual(expected, node.InnerText, "Value {0} not expected from query {1} in {2}.", node.InnerText, query, resourcePath);
                Trace.WriteLine(String.Format("Query '{0}' succeeded.", query));
                query = GetXPathQuery(++index);
            }

            if (resourcePath.Contains("_837D"))
            {
                stream      = GetEdi(resourcePath);
                parser      = new X12Parser(new DentalClaimSpecificationFinder());
                interchange = parser.ParseMultiple(stream).First();
                xml         = interchange.Serialize();
#if DEBUG
                new FileStream(resourcePath.Replace(".txt", "_837D.xml"), FileMode.Create).PrintToFile(xml);
#endif
            }

            if (resourcePath.Contains("_837I"))
            {
                stream      = GetEdi(resourcePath);
                parser      = new X12Parser(new InstitutionalClaimSpecificationFinder());
                interchange = parser.ParseMultiple(stream).First();
                xml         = interchange.Serialize();
#if DEBUG
                new FileStream(resourcePath.Replace(".txt", "_837I.xml"), FileMode.Create).PrintToFile(xml);
#endif
            }
        }
Ejemplo n.º 26
0
        public void FlattenUsingXslt()
        {
            Stream stream = Assembly.GetExecutingAssembly().GetManifestResourceStream("X12.Tests.Unit.Parsing._SampleEdiFiles.ORD._820.Example1_MortgageBankers.txt");

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

            var transform = new XslCompiledTransform();

            transform.Load(XmlReader.Create(Assembly.GetExecutingAssembly().GetManifestResourceStream("X12.Tests.Unit.Flattening.820-XML-to-csv.xslt")));
            var writer = new StringWriter();

            transform.Transform(XmlReader.Create(new StringReader(xml)), new XsltArgumentList(), writer);
        }
        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);
            }
        }
Ejemplo n.º 28
0
        public void UnbundleClaimsFrom837Test()
        {
            // arrange
            var         parser      = new X12Parser();
            Interchange interchange = parser.ParseMultiple(Extensions.GetEdi("INS._837P._5010.Example1_2_And_3_Combined.txt")).First();

            // act
            var list = parser.UnbundleByLoop(interchange, "2300");

            // assert
            Assert.AreEqual(3, list.Count);
            Assert.AreEqual(ExpectedClaim1, list[0].SerializeToX12(true));
            Assert.AreEqual(ExpectedClaim2, list[1].SerializeToX12(true));
            Assert.AreEqual(ExpectedClaim3, list[2].SerializeToX12(true));
        }
Ejemplo n.º 29
0
        public void FlattenUsingXslt()
        {
            Stream stream = Assembly.GetExecutingAssembly().GetManifestResourceStream("X12.Tests.Unit.Parsing._SampleEdiFiles.INS._837P._4010.FromNth.837_DeIdent_01.dat");

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

            var transform = new XslCompiledTransform();

            transform.Load(XmlReader.Create(Assembly.GetExecutingAssembly().GetManifestResourceStream("X12.Tests.Unit.Flattening.837-XML-to-claim-level-csv.xslt")));
            var writer = new StringWriter();

            transform.Transform(XmlReader.Create(new StringReader(xml)), new XsltArgumentList(), writer);
        }
Ejemplo n.º 30
0
        public void UnbundleClaimsFrom837Test()
        {
            X12Parser   parser      = new X12Parser();
            Interchange interchange = parser.ParseMultiple(Extensions.GetEdi("INS._837P._5010.Example1_2_And_3_Combined.txt")).First();

            var list = parser.UnbundleByLoop(interchange, "2300");

            Assert.AreEqual(3, list.Count);
            foreach (var item in list)
            {
                Trace.WriteLine("...");
                Trace.WriteLine(item.SerializeToX12(true));
            }

            Assert.AreEqual(expectedClaim1, list[0].SerializeToX12(true));
            Assert.AreEqual(expectedClaim2, list[1].SerializeToX12(true));
            Assert.AreEqual(expectedClaim3, list[2].SerializeToX12(true));
        }