-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathValidateNCPDPTransations.cs
49 lines (44 loc) · 1.68 KB
/
ValidateNCPDPTransations.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using EdiFabric.Core.Model.Edi;
using EdiFabric.Core.Model.Edi.ErrorContexts;
using EdiFabric.Examples.NCPDP.Script.Common;
using EdiFabric.Framework.Readers;
using EdiFabric.Templates.Script106;
namespace EdiFabric.Examples.NCPDP.Script.ValidateNCPDP
{
class ValidateNCPDPTransations
{
/// <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() + Config.TestFilesPath + @"\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))
{
// Report it back to the sender, log, etc.
var errors = errorContext.Flatten();
}
else
{
// prescription request is valid, handle it downstream
}
}
}
}
}