/// <summary>
        /// Reads file with a corrupt interchange header
        /// </summary>
        public static void Run()
        {
            Debug.WriteLine("******************************");
            Debug.WriteLine(MethodBase.GetCurrentMethod().Name);
            Debug.WriteLine("******************************");

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

            List <IEdiItem> ncpdpItems;

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

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

            if (readerErrors.Any())
            {
                //  The stream is corrupt. Reject it and report back to the sender
                Debug.WriteLine(readerErrors.First().Exception.Message);
            }

            var prescriptionRequests = ncpdpItems.OfType <TSNEWRX>();

            foreach (var prescriptionRequest in prescriptionRequests)
            {
                //  No prescription requests
            }
        }
        /// <summary>
        /// Reads file with a corrupt UIH
        /// </summary>
        public static void Run2()
        {
            Debug.WriteLine("******************************");
            Debug.WriteLine(MethodBase.GetCurrentMethod().Name);
            Debug.WriteLine("******************************");

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

            List <IEdiItem> ncpdpItems;

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

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

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

            var prescriptionRequests = ncpdpItems.OfType <TSNEWRX>();

            foreach (var prescriptionRequest in prescriptionRequests)
            {
                //  All valid messages are recovered
            }
        }
        /// <summary>
        /// Validate NCPDP transactions from file
        /// </summary>
        public static void Run()
        {
            Debug.WriteLine("******************************");
            Debug.WriteLine(MethodBase.GetCurrentMethod().Name);
            Debug.WriteLine("******************************");

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

            List <IEdiItem> ncpdpItems;

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

            var prescriptionRequests = ncpdpItems.OfType <TSNEWRX>();

            foreach (var prescriptionRequest in prescriptionRequests)
            {
                //  Validate
                MessageErrorContext errorContext;
                if (!prescriptionRequest.IsValid(out errorContext, new ValidationSettings {
                    SkipTrailerValidation = true
                }))
                {
                    //  Report it back to the sender, log, etc.
                    var errors = errorContext.Flatten();
                }
                else
                {
                    //  prescription request is valid, handle it downstream
                }
            }
        }
Esempio n. 4
0
        public static void Translate_NCPDP_106()
        {
            //  Change the path to point to your own file to test with
            var path = File.OpenRead(Directory.GetCurrentDirectory() + @"\..\..\..\Files\PrescriptionRequest_NEWRX.txt");

            List <IEdiItem> ediItems;

            using (var reader = new NcpdpScriptReader(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
        /// <summary>
        /// Validate NCPDP 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\PrescriptionRequest_NEWRX.txt");

            List <IEdiItem> ncpdpItems;

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

            var prescriptionRequests = ncpdpItems.OfType <TSNEWRX>();

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

                if (!result.Item1)
                {
                    //  Report it back to the sender, log, etc.
                    var errors = result.Item2.Flatten();
                }
                else
                {
                    //  prescription request is valid, handle it downstream
                }
            }
        }
Esempio n. 6
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\PrescriptionRequest_NEWRX.txt");

            List <IEdiItem> ncpdpItems;

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

            var prescriptionRequests = ncpdpItems.OfType <TSNEWRX>();
        }
Esempio n. 7
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\PrescriptionRequest_NEWRX.txt");

            List <IEdiItem> ncpdpItems;

            using (var ncpdpReader = new NcpdpScriptReader(ncpdpStream, (UIB uib, UIH uih) => typeof(TSNEWRXCustom).GetTypeInfo()))
                ncpdpItems = ncpdpReader.ReadToEnd().ToList();

            var prescriptionRequests = ncpdpItems.OfType <TSNEWRXCustom>();
        }
        /// <summary>
        /// Split a message into parts (blocks of segments) and read each part individually.
        /// Use to process large transactions with repeating loops.
        /// </summary>
        public static void Run()
        {
            Debug.WriteLine("******************************");
            Debug.WriteLine(MethodBase.GetCurrentMethod().Name);
            Debug.WriteLine("******************************");

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

            //  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 NcpdpScriptReader(ncpdpStream, (UIB uib, UIH uih) => typeof(TSREFREQSplitter).GetTypeInfo(), new NcpdpScriptReaderSettings {
                Split = true
            }))
                ncpdpItems = ncpdpReader.ReadToEnd().ToList();

            //  Find all DRU loops, they are all different ediItems
            var druLoop = ncpdpItems.OfType <TSREFREQSplitter>().Where(m => m.DRULoop != null).SelectMany(m => m.DRULoop);

            Debug.WriteLine(string.Format("PharmacyRequest parts {0}", druLoop.Count()));
        }
Esempio n. 9
0
        /// <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("NCPDP_ID_4705", new List <string> {
                "AD", "AS", "PARTNERACODE"
            });

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

            List <IEdiItem> ncpdpItems;

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

            var prescriptionRequests = ncpdpItems.OfType <TSNEWRX>();

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

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

            //  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 NcpdpScriptReader(ncpdpStream, "EdiFabric.Templates.Ncpdp"))
                ncpdpItems = ncpdpReader.ReadToEnd().ToList();

            var pharmacyRequests      = ncpdpItems.OfType <TSREFREQ>();
            var splitPharmacyRequests = new List <TSREFREQ>();

            foreach (var pharmacyRequest in pharmacyRequests)
            {
                foreach (var druLoop in pharmacyRequest.DRULoop)
                {
                    var splitPharmacyRequest = pharmacyRequest.Copy() as TSREFREQ;
                    splitPharmacyRequest.DRULoop.RemoveAll(l => splitPharmacyRequest.DRULoop.IndexOf(l) != pharmacyRequest.DRULoop.IndexOf(druLoop));
                    splitPharmacyRequests.Add(splitPharmacyRequest);
                }
            }

            foreach (var pharmacyRequest in pharmacyRequests)
            {
                Debug.WriteLine(string.Format("Original: Pharmacy Request - DRU parts {0}", pharmacyRequest.DRULoop.Count()));
            }

            foreach (var splitPharmacyRequest in splitPharmacyRequests)
            {
                Debug.WriteLine(string.Format("Split: Pharmacy Request - DRU parts {0}", splitPharmacyRequest.DRULoop.Count()));
            }
        }
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\PrescriptionRequest_NEWRX.txt");

            List <IEdiItem> ncpdpItems;

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

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

            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\PrescriptionRequest_NEWRX.txt");

            List <IEdiItem> ncpdpItems;

            using (var ncpdpReader = new NcpdpScriptReader(ncpdpStream, (UIB uib, UIH uih) => typeof(TSNEWRXCustom).GetTypeInfo()))
                ncpdpItems = ncpdpReader.ReadToEnd().ToList();

            var prescriptionRequest = ncpdpItems.OfType <TSNEWRXCustom>().Single();

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

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