Esempio n. 1
0
        public static void Translate_NCPDP_D0()
        {
            //  Change the path to point to your own file to test with
            var path = File.OpenRead(Directory.GetCurrentDirectory() + @"\..\..\..\Files\ClaimBilling");

            List <IEdiItem> ediItems;

            using (var reader = new NcpdpTelcoReader(path, "EdiFabric.Templates.Ncpdp"))
                ediItems = reader.ReadToEnd().ToList();

            foreach (var message in ediItems.OfType <EdiMessage>())
            {
                if (!message.HasErrors)
                {
                    //  Message was successfully parsed

                    MessageErrorContext mec;
                    if (message.IsValid(out mec))
                    {
                        //  Message was successfully validated
                    }
                    else
                    {
                        //  Message failed validation with the following validation issues:
                        var validationIssues = mec.Flatten();
                    }
                }
                else
                {
                    //  Message was partially parsed with errors
                }
            }
        }   //  Add a breakpoint here, run in debug mode and inspect ediItems
Esempio n. 2
0
        /// <summary>
        /// Validate data element data type using the default NCPDP code set. These aren't validated by default and need to be explicitly requested.
        /// </summary>
        public static void Default()
        {
            Debug.WriteLine("******************************");
            Debug.WriteLine(MethodBase.GetCurrentMethod().Name);
            Debug.WriteLine("******************************");

            Stream ncpdpStream = File.OpenRead(Directory.GetCurrentDirectory() + @"\..\..\..\Files\ClaimBilling");

            List <IEdiItem> ncpdpItems;

            using (var ncpdpReader = new NcpdpTelcoReader(ncpdpStream, "EdiFabric.Templates.Ncpdp"))
                ncpdpItems = ncpdpReader.ReadToEnd().ToList();

            var claims = ncpdpItems.OfType <TSB1>();

            foreach (var claim in claims)
            {
                //  Validate
                MessageErrorContext errorContext;
                if (!claim.IsValid(out errorContext, new ValidationSettings {
                    SyntaxSet = new Default()
                }))
                {
                    //  Report it back to the sender, log, etc.
                    var errors = errorContext.Flatten();
                }
                else
                {
                    //  claim is valid, handle it downstream
                }
            }
        }
        /// <summary>
        /// Validate HL7 transactions from file async
        /// </summary>
        public static async void Run()
        {
            Debug.WriteLine("******************************");
            Debug.WriteLine(MethodBase.GetCurrentMethod().Name);
            Debug.WriteLine("******************************");

            Stream ncpdpStream = File.OpenRead(Directory.GetCurrentDirectory() + @"\..\..\..\Files\ClaimBilling");

            List <IEdiItem> ncpdpItems;

            using (var ncpdpReader = new NcpdpTelcoReader(ncpdpStream, "EdiFabric.Templates.Ncpdp"))
                ncpdpItems = ncpdpReader.ReadToEnd().ToList();

            var claims = ncpdpItems.OfType <TSB1>();

            foreach (var claim in claims)
            {
                //  Validate
                Tuple <bool, MessageErrorContext> result = await claim.IsValidAsync();

                if (!result.Item1)
                {
                    //  Report it back to the sender, log, etc.
                    var errors = result.Item2.Flatten();
                }
                else
                {
                    //  claim is valid, handle it downstream
                }
            }
        }
Esempio n. 4
0
        /// <summary>
        /// Reads file with a corrupt G1
        /// </summary>
        public static void Run2()
        {
            Debug.WriteLine("******************************");
            Debug.WriteLine(MethodBase.GetCurrentMethod().Name);
            Debug.WriteLine("******************************");

            Stream ncpdpStream = File.OpenRead(Directory.GetCurrentDirectory() + @"\..\..\..\Files\ClaimBillingCorruptG1");

            List <IEdiItem> ncpdpItems;

            using (var ncpdpReader = new NcpdpTelcoReader(ncpdpStream, "EdiFabric.Templates.Ncpdp"))
                ncpdpItems = ncpdpReader.ReadToEnd().ToList();

            var readerErrors = ncpdpItems.OfType <ReaderErrorContext>();

            if (readerErrors.Any())
            {
                //  The stream is corrupt
                Debug.WriteLine(readerErrors.First().Exception.Message);
            }

            var claims = ncpdpItems.OfType <TSB1>();

            foreach (var claim in claims)
            {
                //  No claims
            }
        }
Esempio n. 5
0
        /// <summary>
        /// Reads the NCPDP stream from start to end.
        /// This method loads the file into memory. Do not use for large files.
        /// The sample file contains two claims - a valid one and an invalid one.
        /// </summary>
        public static void Run()
        {
            Debug.WriteLine("******************************");
            Debug.WriteLine(MethodBase.GetCurrentMethod().Name);
            Debug.WriteLine("******************************");

            Stream ncpdpStream = File.OpenRead(Directory.GetCurrentDirectory() + @"\..\..\..\Files\ClaimBillings");

            List <IEdiItem> ncpdpItems;

            using (var ncpdpReader = new NcpdpTelcoReader(ncpdpStream, "EdiFabric.Templates.Ncpdp"))
                ncpdpItems = ncpdpReader.ReadToEnd().ToList();

            var claims = ncpdpItems.OfType <TSB1>();
        }
Esempio n. 6
0
        /// <summary>
        /// Reads NCPDP file into a custom, partner-specific template.
        /// </summary>
        public static void Run()
        {
            Debug.WriteLine("******************************");
            Debug.WriteLine(MethodBase.GetCurrentMethod().Name);
            Debug.WriteLine("******************************");

            Stream ncpdpStream = File.OpenRead(Directory.GetCurrentDirectory() + @"\..\..\..\Files\ClaimBilling");

            List <IEdiItem> ncpdpItems;

            using (var ncpdpReader = new NcpdpTelcoReader(ncpdpStream, (TransmissionHeader transmissionHeader, TransactionHeader transactionHeader, ResponseHeader responseHeader) => typeof(TSB1Custom).GetTypeInfo()))
                ncpdpItems = ncpdpReader.ReadToEnd().ToList();

            var claims = ncpdpItems.OfType <TSB1Custom>();
        }
Esempio n. 7
0
        public static void Run()
        {
            Debug.WriteLine("******************************");
            Debug.WriteLine(MethodBase.GetCurrentMethod().Name);
            Debug.WriteLine("******************************");

            Stream ncpdpStream = File.OpenRead(Directory.GetCurrentDirectory() + @"\..\..\..\Files\ClaimBillingAndResponse");

            List <IEdiItem> ncpdpItems;

            using (var ncpdpReader = new NcpdpTelcoReader(ncpdpStream, TypeFactory))
                ncpdpItems = ncpdpReader.ReadToEnd().ToList();

            var claims   = ncpdpItems.OfType <TSB1>();
            var rsponses = ncpdpItems.OfType <TSRESPONSE>();
        }
        /// <summary>
        /// Validate with custom NCPDP codes, different than the standard NCPDP codes. Load the codes dynamically at runtime.
        /// </summary>
        public static void Run2()
        {
            Debug.WriteLine("******************************");
            Debug.WriteLine(MethodBase.GetCurrentMethod().Name);
            Debug.WriteLine("******************************");

            //  Set NCPDP codes map where the original code type will be substituted with the partner-specific code type
            var codeSetMap = new Dictionary <string, List <string> >();

            codeSetMap.Add("TELCO_ID_C6", new List <string> {
                "0", "1", "5"
            });

            Stream ncpdpStream = File.OpenRead(Directory.GetCurrentDirectory() + @"\..\..\..\Files\ClaimBilling");

            List <IEdiItem> ncpdpItems;

            using (var ncpdpReader = new NcpdpTelcoReader(ncpdpStream, "EdiFabric.Templates.Ncpdp"))
                ncpdpItems = ncpdpReader.ReadToEnd().ToList();

            var claims = ncpdpItems.OfType <TSB1>();

            foreach (var claim in claims)
            {
                //  Validate using NCPDP codes map
                MessageErrorContext errorContext;
                if (!claim.IsValid(out errorContext, new ValidationSettings {
                    DataElementCodesMap = codeSetMap
                }))
                {
                    //  Report it back to the sender, log, etc.
                    var errors = errorContext.Flatten();
                }
                else
                {
                    //  claim is valid, handle it downstream
                }
            }
        }
        /// <summary>
        /// Copy a message and remove unwanted parts.
        /// </summary>
        public static void Run()
        {
            Debug.WriteLine("******************************");
            Debug.WriteLine(MethodBase.GetCurrentMethod().Name);
            Debug.WriteLine("******************************");

            Stream ncpdpStream = File.OpenRead(Directory.GetCurrentDirectory() + @"\..\..\..\Files\ClaimBillingMultiLoop");

            //  The split is driven by setting which class to split by in the template.
            //  Set the class to inherit from EdiItem and the parser will automatically split by it.
            List <IEdiItem> ncpdpItems;

            using (var ncpdpReader = new NcpdpTelcoReader(ncpdpStream, "EdiFabric.Templates.Ncpdp"))
                ncpdpItems = ncpdpReader.ReadToEnd().ToList();

            var claims      = ncpdpItems.OfType <TSB1>();
            var splitClaims = new List <TSB1>();

            foreach (var claim in claims)
            {
                foreach (var am07Loop in claim.AM07Loop)
                {
                    var splitClaim = claim.Copy() as TSB1;
                    splitClaim.AM07Loop.RemoveAll(l => splitClaim.AM07Loop.IndexOf(l) != claim.AM07Loop.IndexOf(am07Loop));
                    splitClaims.Add(splitClaim);
                }
            }

            foreach (var claim in claims)
            {
                Debug.WriteLine(string.Format("Original: Claim - AM07 parts {0}", claim.AM07Loop.Count()));
            }

            foreach (var splitClaim in splitClaims)
            {
                Debug.WriteLine(string.Format("Split: Claim - AM07 parts {0}", splitClaim.AM07Loop.Count()));
            }
        }
Esempio n. 10
0
        /// <summary>
        /// Serialize an NCPDP object to Json using Json.NET
        /// </summary>
        public static void Run()
        {
            Debug.WriteLine("******************************");
            Debug.WriteLine(MethodBase.GetCurrentMethod().Name);
            Debug.WriteLine("******************************");

            var ncpdpStream = File.OpenRead(Directory.GetCurrentDirectory() + @"\..\..\..\Files\ClaimBilling");

            List <IEdiItem> ncpdpItems;

            using (var ncpdpReader = new NcpdpTelcoReader(ncpdpStream, "EdiFabric.Templates.Ncpdp"))
            {
                ncpdpItems = ncpdpReader.ReadToEnd().ToList();
            }

            var transactions = ncpdpItems.OfType <TSB1>();

            foreach (var transaction in transactions)
            {
                var json = Newtonsoft.Json.JsonConvert.SerializeObject(transaction);
                Debug.WriteLine(json.ToString());
            }
        }
Esempio n. 11
0
        /// <summary>
        /// Serialize an NCPDP object to NCPDP using DataContractSerializer
        /// </summary>
        public static void WithDataContractSerializer()
        {
            Debug.WriteLine("******************************");
            Debug.WriteLine(MethodBase.GetCurrentMethod().Name);
            Debug.WriteLine("******************************");

            var ncpdpStream = File.OpenRead(Directory.GetCurrentDirectory() + @"\..\..\..\Files\ClaimBilling");

            List <IEdiItem> ncpdpItems;

            using (var ncpdpReader = new NcpdpTelcoReader(ncpdpStream, "EdiFabric.Templates.Ncpdp"))
            {
                ncpdpItems = ncpdpReader.ReadToEnd().ToList();
            }

            var transactions = ncpdpItems.OfType <TSB1>();

            foreach (var transaction in transactions)
            {
                var xml = transaction.SerializeDataContract();
                Debug.WriteLine(xml.Root.ToString());
            }
        }
        /// <summary>
        /// Apply custom validation for cross segment or data element scenarios
        /// </summary>
        public static void Run()
        {
            Debug.WriteLine("******************************");
            Debug.WriteLine(MethodBase.GetCurrentMethod().Name);
            Debug.WriteLine("******************************");

            Stream ncpdpStream = File.OpenRead(Directory.GetCurrentDirectory() + @"\..\..\..\Files\ClaimBilling");

            List <IEdiItem> ncpdpItems;

            using (var ncpdpReader = new NcpdpTelcoReader(ncpdpStream, (TransmissionHeader transmissionHeader, TransactionHeader transactionHeader, ResponseHeader responseHeader) => typeof(TSB1Custom).GetTypeInfo()))
                ncpdpItems = ncpdpReader.ReadToEnd().ToList();

            var claim = ncpdpItems.OfType <TSB1Custom>().Single();

            //  Check that the custom validation was triggered
            MessageErrorContext errorContext;

            if (!claim.IsValid(out errorContext))
            {
                var customValidation = errorContext.Errors.FirstOrDefault(e => e.Message == "AM02 segment is missing.");
                Debug.WriteLine(customValidation.Message);
            }
        }