/// <summary> /// Write Purchase Orders /// </summary> static void Write() { using (var stream = new MemoryStream()) { var transaction = EdifactTransactionBuilders.BuildPurchaseOrder("1"); MessageErrorContext mec; if (transaction.IsValid(out mec, new ValidationSettings { SkipTrailerValidation = true })) { // valid using (var writer = new EdifactWriter(stream)) { writer.Write(SegmentBuilders.BuildUnb("1")); writer.Write(transaction); } var ediString = stream.LoadToString(); } else { // invalid var errors = mec.Flatten(); } } }
/// <summary> /// Write with custom separators, by default it uses the standard separators. /// </summary> public static void Run() { Debug.WriteLine("******************************"); Debug.WriteLine(MethodBase.GetCurrentMethod().Name); Debug.WriteLine("******************************"); var invoice = SegmentBuilders.BuildInvoice("1"); using (var stream = new MemoryStream()) { using (var writer = new X12Writer(stream)) { // Set a custom segment separator. var separators = Separators.X12; separators.Segment = '|'; // Write the ISA with the custom separator set writer.Write(SegmentBuilders.BuildIsa("1"), separators); writer.Write(SegmentBuilders.BuildGs("1")); writer.Write(invoice); } Debug.Write(stream.LoadToString()); } }
/// <summary> /// Write with custom separators, by default it uses the standard separators. /// </summary> public static void WriteWithCustomSeparators() { Debug.WriteLine("******************************"); Debug.WriteLine(MethodBase.GetCurrentMethod().Name); Debug.WriteLine("******************************"); var invoice = X12TransactionBuilders.BuildInvoice("1"); using (var stream = new MemoryStream()) { using (var writer = new X12Writer(stream)) { // Set a custom segment separator. var separators = new Separators('|', Separators.X12.ComponentDataElement, Separators.X12.DataElement, Separators.X12.RepetitionDataElement, Separators.X12.Escape); // Write the ISA with the custom separator set writer.Write(SegmentBuilders.BuildIsa("1"), separators); writer.Write(SegmentBuilders.BuildGs("1")); writer.Write(invoice); } Debug.Write(stream.LoadToString()); } }
/// <summary> /// Batch multiple transactions under multiple functional groups in the same EDI stream /// </summary> public static void WriteMultipleGroups() { Debug.WriteLine("******************************"); Debug.WriteLine(MethodBase.GetCurrentMethod().Name); Debug.WriteLine("******************************"); using (var stream = new MemoryStream()) { using (var writer = new X12Writer(stream)) { writer.Write(SegmentBuilders.BuildIsa("1")); // 1. Write the first group writer.Write(SegmentBuilders.BuildGs("1")); // Write the transactions... writer.Write(X12TransactionBuilders.BuildInvoice("1")); // 2. Write the second group // No need to close the previous group with a GE writer.Write(SegmentBuilders.BuildGs("2")); // Write the transactions... writer.Write(X12TransactionBuilders.BuildInvoice("2")); } Debug.Write(stream.LoadToString()); } }
/// <summary> /// Write without auto trailers /// </summary> public static void Run() { Debug.WriteLine("******************************"); Debug.WriteLine(MethodBase.GetCurrentMethod().Name); Debug.WriteLine("******************************"); using (var stream = new MemoryStream()) { // Set AutoTrailers to false using (var writer = new NcpdpScriptWriter(stream, new NcpdpScriptWriterSettings { AutoTrailers = false })) { // Write the interchange header writer.Write(SegmentBuilders.BuildInterchangeHeader()); // Write the prescription request writer.Write(SegmentBuilders.BuildPrescriptionRequest()); // trailers need to be manually written } using (var writer = new StreamWriter(stream)) { var uiz = new UIZ { InterchangeControlCount_02 = "1" }; writer.Write(uiz.ToEdi(Separators.NcpdpScript)); writer.Flush(); Debug.Write(stream.LoadToString()); } } }
/// <summary> /// Write transactions with whitespace. /// </summary> public static void Run() { Debug.WriteLine("******************************"); Debug.WriteLine(MethodBase.GetCurrentMethod().Name); Debug.WriteLine("******************************"); var prescriptionRequest = SegmentBuilders.BuildPrescriptionRequest(); // Initialize some properties with blanks prescriptionRequest.PVD[0].I016_09 = new I016(); prescriptionRequest.PVD[0].I016_09.CommunicationNumber_01 = ""; using (var stream = new MemoryStream()) { using (var writer = new NcpdpScriptWriter(stream, new NcpdpScriptWriterSettings() { PreserveWhitespace = true })) { // Write the interchange header writer.Write(SegmentBuilders.BuildInterchangeHeader()); // Write the prescription request writer.Write(prescriptionRequest); } Debug.Write(stream.LoadToString()); } }
/// <summary> /// Write Purchase Order /// </summary> static void Write() { using (var stream = new MemoryStream()) { var transaction = X12TransactionBuilders.BuildPurchaseOrder("1"); MessageErrorContext mec; if (transaction.IsValid(out mec, true)) { // valid using (var writer = new X12Writer(stream)) { writer.Write(SegmentBuilders.BuildIsa("1")); writer.Write(SegmentBuilders.BuildGs("1")); writer.Write(transaction); } var ediString = stream.LoadToString(); } else { // invalid var errors = mec.Flatten(); } } }
/// <summary> /// Write transactions with whitespace. /// </summary> public static void WriteSegmentWithWhitespace() { Debug.WriteLine("******************************"); Debug.WriteLine(MethodBase.GetCurrentMethod().Name); Debug.WriteLine("******************************"); var invoice = X12TransactionBuilders.BuildInvoice("1"); // Initialize some properties with blanks invoice.BIG.ReleaseNumber_05 = ""; invoice.BIG.ChangeOrderSequenceNumber_06 = ""; using (var stream = new MemoryStream()) { // Set the PreserveWhitespace flag to true using (var writer = new X12Writer(stream, new X12WriterSettings() { PreserveWhitespace = true })) { writer.Write(SegmentBuilders.BuildIsa("1")); writer.Write(SegmentBuilders.BuildGs("1")); writer.Write(invoice); } Debug.Write(stream.LoadToString()); } }
/// <summary> /// Batch multiple transmissions in the same stream. /// </summary> public static void Run2() { Debug.WriteLine("******************************"); Debug.WriteLine(MethodBase.GetCurrentMethod().Name); Debug.WriteLine("******************************"); using (var stream = new MemoryStream()) { using (var writer = new NcpdpTelcoWriter(stream)) { // Write transmission header 1 writer.Write(SegmentBuilders.BuildTransmissionHeader("1")); // Write the claim writer.Write(SegmentBuilders.BuildClaim("1")); // Write transmission header 2 writer.Write(SegmentBuilders.BuildTransmissionHeader("1")); // Write the claim writer.Write(SegmentBuilders.BuildClaim("2")); //... } Debug.Write(stream.LoadToString()); } }
/// <summary> /// Batch multiple transactions in the same functional group\EDI stream. /// </summary> public static void Run() { Debug.WriteLine("******************************"); Debug.WriteLine(MethodBase.GetCurrentMethod().Name); Debug.WriteLine("******************************"); using (var stream = new MemoryStream()) { using (var writer = new X12Writer(stream, new X12WriterSettings() { Postfix = Environment.NewLine })) { writer.Write(SegmentBuilders.BuildIsa("1")); writer.Write(SegmentBuilders.BuildGs("1")); // 1. Write the first invoice writer.Write(EF_X12_004010_810_Builder.BuildInvoice("1")); // 2. Write the second invoice writer.Write(EF_X12_004010_810_Builder.BuildInvoice("2")); // 3. Write any subsequent invoices... } Debug.Write(stream.LoadToString()); } }
/// <summary> /// Write transactions with whitespace. /// </summary> public static void WriteSegmentWithWhitespace() { Debug.WriteLine("******************************"); Debug.WriteLine(MethodBase.GetCurrentMethod().Name); Debug.WriteLine("******************************"); var invoice = EdifactTransactionBuilders.BuildInvoice("1"); // Initialize a blank property invoice.BGM.Responsetypecoded_04 = ""; using (var stream = new MemoryStream()) { // Set PreserveWhitespace flag to true using (var writer = new EdifactWriter(stream, new EdifactWriterSettings() { PreserveWhitespace = true })) { writer.Write(SegmentBuilders.BuildUnb("1")); writer.Write(invoice); } Debug.Write(stream.LoadToString()); } }
/// <summary> /// Batch multiple transactions under multiple functional groups in the same EDI stream. /// </summary> public static void Run() { Debug.WriteLine("******************************"); Debug.WriteLine(MethodBase.GetCurrentMethod().Name); Debug.WriteLine("******************************"); using (var stream = new MemoryStream()) { using (var writer = new EdifactWriter(stream)) { writer.Write(SegmentBuilders.BuildUnb("1")); // 1. Write the first group writer.Write(SegmentBuilders.BuildUng("1", "INVOIC")); writer.Write(EF_EDIFACT_D96A_INVOIC_Builder.BuildInvoice("1")); // 2. Write the second group // No need to close the previous group with a UNE writer.Write(SegmentBuilders.BuildUng("2", "ORDERS")); writer.Write(EF_EDIFACT_D96A_ORDERS_Builder.BuildPurchaseOrder("1")); } Debug.Write(stream.LoadToString()); } }
/// <summary> /// Write without auto trailers /// </summary> public static void WriteWithoutAutoTrailers() { Debug.WriteLine("******************************"); Debug.WriteLine(MethodBase.GetCurrentMethod().Name); Debug.WriteLine("******************************"); using (var stream = new MemoryStream()) { // Set AutoTrailers to false using (var writer = new EdifactWriter(stream, new EdifactWriterSettings { AutoTrailers = false })) { writer.Write(SegmentBuilders.BuildUnb("1")); writer.Write(EdifactTransactionBuilders.BuildInvoice("1")); // trailers need to be manually written } using (var writer = new StreamWriter(stream)) { var unz = new UNZ(); unz.InterchangeControlCount_1 = "1"; unz.InterchangeControlReference_2 = "000000001"; writer.Write(unz.ToEdi(Separators.Edifact)); writer.Flush(); Debug.Write(stream.LoadToString()); } } }
/// <summary> /// Batch multiple interchanges in the same EDI stream /// </summary> public static void Run() { Debug.WriteLine("******************************"); Debug.WriteLine(MethodBase.GetCurrentMethod().Name); Debug.WriteLine("******************************"); using (var stream = new MemoryStream()) { using (var writer = new X12Writer(stream)) { // 1. Write the first interchange writer.Write(SegmentBuilders.BuildIsa("1")); writer.Write(SegmentBuilders.BuildGs("1")); writer.Write(SegmentBuilders.BuildInvoice("1")); // 2. Write the second interchange // No need to close the previous interchange with a IEA writer.Write(SegmentBuilders.BuildIsa("2")); writer.Write(SegmentBuilders.BuildGs("1")); writer.Write(SegmentBuilders.BuildInvoice("1")); } Debug.Write(stream.LoadToString()); } }
/// <summary> /// Generate and write EDI document to a file. /// </summary> public static void WriteSingleInvoiceToFile() { Debug.WriteLine("******************************"); Debug.WriteLine(MethodBase.GetCurrentMethod().Name); Debug.WriteLine("******************************"); // 1. Construct the invoice var invoice = EdifactTransactionBuilders.BuildInvoice("1"); // 2. Validate it by skipping trailer validation MessageErrorContext errorContext; if (invoice.IsValid(out errorContext, new ValidationSettings { SkipTrailerValidation = true })) { Debug.WriteLine("Message {0} with control number {1} is valid.", errorContext.Name, errorContext.ControlNumber); // 3. Write directly to a file using (var writer = new EdifactWriter(@"C:\Test\Output.txt", false)) { writer.Write(SegmentBuilders.BuildUnb("1")); writer.Write(invoice); } Debug.WriteLine("Written to file."); } else { // The invoice is invalid } }
/// <summary> /// Write transactions with whitespace. /// </summary> public static void Run() { Debug.WriteLine("******************************"); Debug.WriteLine(MethodBase.GetCurrentMethod().Name); Debug.WriteLine("******************************"); var dispense = SegmentBuilders.BuildDispense("LAB1", "LAB", "DEST2", "DEST", "1"); // Add "" as the value to account for a delete dispense.LoopORC[0].ORC.PlacerOrderNumber_02.NamespaceID_02 = "\"\""; // Add empty string as the value to add an extra separator to keep the position dispense.LoopORC[0].ORC.PlacerOrderNumber_02.UniversalID_03 = ""; using (var stream = new MemoryStream()) { using (var writer = new Hl7Writer(stream, new Hl7WriterSettings() { PreserveWhitespace = true })) { // Write the dispense writer.Write(dispense); } Debug.Write(stream.LoadToString()); } }
/// <summary> /// Write Claim /// </summary> static void Write() { using (var stream = new MemoryStream()) { var transaction = HipaaTransactionBuilders.BuildClaim("1"); MessageErrorContext mec; if (transaction.IsValid(out mec, true)) { var separators = new Separators(Separators.X12.Segment, ':', Separators.X12.DataElement, Separators.X12.RepetitionDataElement, Separators.X12.Escape); // valid using (var writer = new X12Writer(stream, Encoding.UTF8, Environment.NewLine)) { writer.Write(SegmentBuilders.BuildIsa("1"), separators); writer.Write(SegmentBuilders.BuildGs("1")); writer.Write(transaction); } var ediString = stream.LoadToString(); } else { // invalid var errors = mec.Flatten(); } } }
/// <summary> /// Batch multiple interchanges in the same stream. /// </summary> public static void Run2() { Debug.WriteLine("******************************"); Debug.WriteLine(MethodBase.GetCurrentMethod().Name); Debug.WriteLine("******************************"); using (var stream = new MemoryStream()) { using (var writer = new NcpdpScriptWriter(stream)) { // Write transmission header 1 writer.Write(SegmentBuilders.BuildInterchangeHeader("1")); // Write the prescription request writer.Write(SegmentBuilders.BuildPrescriptionRequest("1")); // Write transmission header 2 writer.Write(SegmentBuilders.BuildInterchangeHeader("1")); // Write the prescription request writer.Write(SegmentBuilders.BuildPrescriptionRequest("1")); //... } Debug.Write(stream.LoadToString()); } }
/// <summary> /// Batch multiple transactions in the same functional group\EDI stream. /// </summary> public static void WriteMultipleInvoices() { Debug.WriteLine("******************************"); Debug.WriteLine(MethodBase.GetCurrentMethod().Name); Debug.WriteLine("******************************"); using (var stream = new MemoryStream()) { using (var writer = new X12Writer(stream, Encoding.Default, Environment.NewLine)) { writer.Write(SegmentBuilders.BuildIsa("1")); writer.Write(SegmentBuilders.BuildGs("1")); // 1. Write the first invoice writer.Write(X12TransactionBuilders.BuildInvoice("1")); // 2. Write the second invoice writer.Write(X12TransactionBuilders.BuildInvoice("2")); // 3. Write any subsequent invoices... } Debug.Write(stream.LoadToString()); } }
/// <summary> /// Batch multiple transactions under multiple functional groups in the same HL7 stream /// </summary> public static void Run() { Debug.WriteLine("******************************"); Debug.WriteLine(MethodBase.GetCurrentMethod().Name); Debug.WriteLine("******************************"); using (var stream = new MemoryStream()) { using (var writer = new Hl7Writer(stream)) { writer.Write(SegmentBuilders.BuildFhs("LAB1", "LAB", "DEST2", "DEST", "TESTFILE", "1234")); // 1. Write the first group writer.Write(SegmentBuilders.BuildBhs("LAB1", "LAB", "DEST2", "DEST", "TESTBATCH", "1")); // Write the transactions... writer.Write(SegmentBuilders.BuildDispense("LAB1", "LAB", "DEST2", "DEST", "1")); // 2. Write the second group writer.Write(SegmentBuilders.BuildBhs("LAB1", "LAB", "DEST2", "DEST", "TESTBATCH", "2")); // Write the transactions... writer.Write(SegmentBuilders.BuildDispense("LAB1", "LAB", "DEST2", "DEST", "1")); } Debug.Write(stream.LoadToString()); } }
/// <summary> /// Write Invoices /// </summary> static void Write() { using (var stream = new MemoryStream()) { var transaction = EancomTransactionBuilders.BuildInvoice("1"); MessageErrorContext mec; if (transaction.IsValid(out mec, true)) { // valid using (var writer = new EdifactWriter(stream)) { writer.Write(SegmentBuilders.BuildUnb("1")); writer.Write(transaction); } var ediString = stream.LoadToString(); } else { // invalid var errors = mec.Flatten(); } } }
/// <summary> /// Generate and write EDI document to a stream async /// </summary> public static async void Run() { Debug.WriteLine("******************************"); Debug.WriteLine(MethodBase.GetCurrentMethod().Name); Debug.WriteLine("******************************"); // 1. Construct the invoice var invoice = EF_X12_004010_810_Builder.BuildInvoice("1"); using (var stream = new MemoryStream()) { using (var writer = new X12Writer(stream)) { // 2. Begin with ISA segment await writer.WriteAsync(SegmentBuilders.BuildIsa("1")); // 3. Follow up with GS segment await writer.WriteAsync(SegmentBuilders.BuildGs("1")); // 4. Then write the invoice(s) await writer.WriteAsync(invoice); } Debug.Write(stream.LoadToString()); } }
/// <summary> /// Generate and write NCPDP document to a file /// </summary> public static void Run() { Debug.WriteLine("******************************"); Debug.WriteLine(MethodBase.GetCurrentMethod().Name); Debug.WriteLine("******************************"); using (var writer = new NcpdpTelcoWriter(@"C:\Test\Output.txt", false)) { // Write the transmission header writer.Write(SegmentBuilders.BuildTransmissionHeader()); // Write the claim writer.Write(SegmentBuilders.BuildClaim()); } }
/// <summary> /// Generate and write NCPDP document to a file /// </summary> public static void Run() { Debug.WriteLine("******************************"); Debug.WriteLine(MethodBase.GetCurrentMethod().Name); Debug.WriteLine("******************************"); using (var writer = new NcpdpScriptWriter(@"C:\Test\Output.txt", false)) { // Write the transmission header writer.Write(SegmentBuilders.BuildInterchangeHeader()); // Write the prescription request writer.Write(SegmentBuilders.BuildPrescriptionRequest()); } }
/// <summary> /// Generate and write EDI document to a stream async /// </summary> public static async void WriteSingleInvoiceToStreamAsync() { Debug.WriteLine("******************************"); Debug.WriteLine(MethodBase.GetCurrentMethod().Name); Debug.WriteLine("******************************"); // 1. Construct the invoice var invoice = X12TransactionBuilders.BuildInvoice("1"); // 2. Validate it by skipping trailer validation MessageErrorContext errorContext; if (invoice.IsValid(out errorContext, new ValidationSettings { SkipTrailerValidation = true })) { Debug.WriteLine("Message {0} with control number {1} is valid.", errorContext.Name, errorContext.ControlNumber); using (var stream = new MemoryStream()) { using (var writer = new X12Writer(stream)) { // 3. Begin with ISA segment await writer.WriteAsync(SegmentBuilders.BuildIsa("1")); // 4. Follow up with GS segment await writer.WriteAsync(SegmentBuilders.BuildGs("1")); // 5. Then write the invoice(s) await writer.WriteAsync(invoice); } Debug.Write(stream.LoadToString()); } } else { // The invoice is invalid Debug.WriteLine("Message {0} with control number {1} is invalid with errors:", errorContext.Name, errorContext.ControlNumber); // List all error messages var errors = errorContext.Flatten(); foreach (var error in errors) { Debug.WriteLine(error); } } }
/// <summary> /// Write Invoices /// </summary> static void Write() { var transaction = BuildInvoice("1"); using (var stream = new MemoryStream()) { using (var writer = new EdifactWriter(stream)) { writer.Write(SegmentBuilders.BuildUnb("1")); writer.Write(transaction); } var ediString = stream.LoadToString(); } }
/// <summary> /// Generate and write HL7 document to a file /// </summary> public static void Run() { Debug.WriteLine("******************************"); Debug.WriteLine(MethodBase.GetCurrentMethod().Name); Debug.WriteLine("******************************"); // Write directly to a file // Change the path to a file on your machine using (var writer = new Hl7Writer(@"C:\Test\Output.txt", false)) { writer.Write(SegmentBuilders.BuildFhs("LAB1", "LAB", "DEST2", "DEST", "TESTFILE", "1")); writer.Write(SegmentBuilders.BuildBhs("LAB1", "LAB", "DEST2", "DEST", "TESTBATCH", "1")); writer.Write(SegmentBuilders.BuildDispense("LAB1", "LAB", "DEST2", "DEST", "1")); } }
/// <summary> /// Write Payment /// </summary> static void Write() { var transaction = BuildPayment("1"); using (var stream = new MemoryStream()) { using (var writer = new X12Writer(stream)) { writer.Write(SegmentBuilders.BuildIsa("1")); writer.Write(SegmentBuilders.BuildGs("1")); writer.Write(transaction); } var ediString = stream.LoadToString(); } }
/// <summary> /// Write Response Transmission /// </summary> static void Write() { var transaction = BuildResponseTransmission("1"); using (var stream = new MemoryStream()) { using (var writer = new X12Writer(stream)) { writer.Write(SegmentBuilders.BuildIsa("1")); writer.Write(SegmentBuilders.BuildGs("1", "SENDER1", "RECEIVER1", "005010X212")); writer.Write(transaction); } var ediString = stream.LoadToString(); } }
/// <summary> /// Write Passenger Data /// </summary> static void Write() { var transaction = BuildPassengerData("1"); using (var stream = new MemoryStream()) { using (var writer = new EdifactWriter(stream)) { writer.Write(SegmentBuilders.BuildUnb("13052210400995")); writer.Write(SegmentBuilders.BuildUng("13052210400995", "PNRGOV")); writer.Write(transaction); } var ediString = stream.LoadToString(); } }