我正在使用EDIFabric来构建交换和单个消息。我有一个非常简单的格式,我需要输出到EDI x12字符串。我的代码正确地填充了交换和组(查看本地变量和集合),但是当我在我的交换对象上运行.ToEdi()时,我正在返回空消息组
我的输出:
"ISA*00* *00* *IS*SenderID *IS*ReceiverID *160809*1008*^*00501*000001ISA*0*P*:~GS*FA*GS_02_SenderCode*GS_03_ReceiverCode*21160809*1008*00001GS06*X*005010~ST~AK1~AK2~IK3~IK5~AK9~SE~GE*000001*00001GS06~IEA*00001*000001ISA~"
不应该为空时
ST~AK1~AK2~IK3~IK5~AK9~SE~GE
创作课
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using EdiFabric.Framework.Envelopes.X12;
using EdiFabric.Definitions.Hipaa_005010_999_X231;
using EdiFabric.Framework.Messages;
using EdiFabric.Framework.Envelopes;
namespace X12PayloadProcessing
{
public class DS_M_999
{
private DS_M_999_Interchange _Interchange;
private DS_M_999_Group _Group;
private Message _EDI_Message;
private S_ISA _EDI_ISA = new S_ISA();
private S_IEA _EDI_IEA = new S_IEA();
public Interchange _EDI_Interchange = new Interchange();
private S_GE _EDI_GE = new S_GE();
private S_GS _EDI_GS = new S_GS();
private Group _EDI_Group = new Group();
private M_999 _EDI_999 = new M_999();
private S_ST _EDI_ST = new S_ST();
private S_SE _EDI_SE = new S_SE();
private S_AK1 _EDI_AK1 = new S_AK1();
private S_AK2 _EDI_AK2 = new S_AK2();
private S_AK9 _EDI_AK9 = new S_AK9();
private S_IK3 _EDI_IK3 = new S_IK3();
private S_IK5 _EDI_IK5 = new S_IK5();
private List<G_TS999_2000> _EDI_2000_List = new List<G_TS999_2000>();
private G_TS999_2000 _EDI_2000 = new G_TS999_2000();
private G_TS999_2100 _EDI_2100 = new G_TS999_2100();
private List<G_TS999_2100> _EDI_2100_List = new List<G_TS999_2100>();
public DS_M_999(DS_M_999_Group Group, DS_M_999_Interchange Interchange)
{
_Group = Group;
_Interchange = Interchange;
_EDI_Interchange.Groups = new List<Group>();
_EDI_ISA.D_744_1 = _Interchange.ISA_01_Authorization.PadRight(2).Substring(0,2);
_EDI_ISA.D_745_2 = _Interchange.ISA_02_AuthInfo.PadRight(10).Substring(0,10);
_EDI_ISA.D_746_3 = _Interchange.ISA_03_SecurityQualifier.PadRight(2).Substring(0, 2);
_EDI_ISA.D_747_4 = _Interchange.ISA_04_Password.PadRight(10).Substring(0, 10);
_EDI_ISA.D_704_5 = _Interchange.ISA_05_SenderQualifier.PadRight(2).Substring(0, 2);
_EDI_ISA.D_705_6 = _Interchange.ISA_06_SenderId.PadRight(15).Substring(0,15);
_EDI_ISA.D_704_7 = _Interchange.ISA_07_ReceiverQualifier.PadRight(2).Substring(0, 2);
_EDI_ISA.D_706_8 = _Interchange.ISA_08_ReceiverId.PadRight(15).Substring(0, 15);
_EDI_ISA.D_373_9 = _Interchange.ISA_09_DateReceived.PadRight(6).Substring(0, 6);
_EDI_ISA.D_337_10 = _Interchange.ISA_10_TimeRecieved.PadRight(4).Substring(0, 4);
_EDI_ISA.D_726_11 = _Interchange.ISA_11_RepetitionSeparator.PadRight(1).Substring(0, 1);
_EDI_ISA.D_703_12 = _Interchange.ISA_12_X12Version.PadRight(5).Substring(0, 5);
_EDI_ISA.D_709_13 = _Interchange.ISA_13_UniqueNumberCounter.PadLeft(9,'0');
_EDI_ISA.D_749_14 = _Interchange.ISA_14_AcknoledgementRequested;
_EDI_ISA.D_748_15 = _Interchange.ISA_15_UsageIndicator;
_EDI_ISA.D_701_16 = _Interchange.ISA_16_CompElementSeparator;
_EDI_IEA.D_405_1 = _Interchange.IEA_01_FunctionalGroupCounter.PadLeft(5, '0');
_EDI_IEA.D_709_2 = _Interchange.IEA_02_UniqueNumberCounter.PadLeft(9, '0');
_EDI_Interchange.Iea = _EDI_IEA;
_EDI_Interchange.Isa = _EDI_ISA;
_EDI_GE.D_97_1 = _Interchange.GE_01_TransactionSetCounter.PadLeft(6, '0');
_EDI_GE.D_28_2 = _Interchange.GE_02_UniqueNumberCounter.PadLeft(9, '0');
_EDI_Group.Ge = _EDI_GE;
_EDI_GS.D_479_1 = _Interchange.GS_01.PadRight(2).Substring(0, 2);
_EDI_GS.D_142_2 = _Interchange.GS_02_SenderCode;
_EDI_GS.D_124_3 = _Interchange.GS_03_ReceiverCode;
_EDI_GS.D_29_4 = _Interchange.GS_04_DateReceived.PadRight(6).Substring(0, 8); //datetime.ToString("yyyyMMdd")
_EDI_GS.D_30_5 = _Interchange.GS_05_TimeReceived.PadRight(4).Substring(0, 4); //datetime.ToString("HHmm")
_EDI_GS.D_28_6 = _Interchange.GS_06_UniqueNumberCounter.PadLeft(9,'0');
_EDI_GS.D_455_7 = _Interchange.GS_07_AgencyCode.PadRight(1).Substring(0, 1);
_EDI_GS.D_480_8 = _Interchange.GS_08_X12Version.PadRight(6).Substring(0, 6);
_EDI_Group.Gs = _EDI_GS;
//Set ST Block
_EDI_ST.D_ST01 = X12_ID_143.Item999;
_EDI_ST.D_ST02 = _Group.ST_02_TransactionSetCounter;
_EDI_ST.D_ST03 = X12_ID_1705.Item005010X231A1;
_EDI_999.S_ST = _EDI_ST;
//Set AK1 Block
_EDI_AK1.D_AK101 = _Group.AK_101_FunctionalIdentifier;
_EDI_AK1.D_AK102 = _Group.AK_102_GroupControlNumber;
_EDI_AK1.D_AK103 = _Group.AK_103_VersionIdentifier;
_EDI_999.S_AK1 = _EDI_AK1;
_EDI_AK2.D_AK201 = _Group.AK_201_TransactionSetIdentifier;
_EDI_AK2.D_AK202 = _Group.AK_202_ControlNumber;
_EDI_AK2.D_AK203 = _Group.AK_203_VersionIdentifier;
_EDI_2000.S_AK2 = _EDI_AK2;
//Set IK3 Block
_EDI_IK3.D_IK301 = _Group.IK_301_MissingSegment;
_EDI_IK3.D_IK302 = _Group.IK_302_PositionInTransactionSet;
_EDI_IK3.D_IK304 = X12_ID_620.Item3; // _Group.IK_304_ErrorCode;
_EDI_2100.S_IK3 = _EDI_IK3;
//Set IK5 Block
_EDI_IK5.D_IK501 = X12_ID_717.R;
_EDI_IK5.D_IK502 = X12_ID_618.Item5;
_EDI_2000.S_IK5 = _EDI_IK5;
//Set Lists
_EDI_2100_List.Add(_EDI_2100);
_EDI_2000.G_TS999_2100 = _EDI_2100_List;
_EDI_2000_List.Add(_EDI_2000);
_EDI_999.G_TS999_2000 = _EDI_2000_List;
//AK9 Block
_EDI_AK9.D_AK901 = X12_ID_715.R;//_Group.AK_901_RejectIndicator;
_EDI_AK9.D_AK902 = _Group.AK_902_NumberOfTransactionSets;
_EDI_AK9.D_AK903 = _Group.AK_903_NumberOfTransactionSets;
_EDI_AK9.D_AK904 = _Group.AK_904_NumberAccepted;
_EDI_999.S_AK9 = _EDI_AK9;
//SE Block
_EDI_SE.D_SE01 = _Group.SE_01_SegmentCounter;
_EDI_SE.D_SE02 = _Group.SE_02_TransactionSetCounter;
_EDI_999.S_SE = _EDI_SE;
_EDI_Message = new Message(_EDI_999);
_EDI_Group.Messages.Add(new Message((object)_EDI_999));
_EDI_Interchange.Groups.Add(_EDI_Group);
}
public string GetEdiString()
{
var parsedXml = _EDI_Interchange.ToEdi();
return string.Concat(parsedXml);
}
}
public class DS_M_999_Interchange
{
public string ISA_01_Authorization { get; set; } //default 00
public string ISA_02_AuthInfo { get; set; } //defualt ""
public string ISA_03_SecurityQualifier { get; set; } //default 00
public string ISA_04_Password { get; set; } //default ""
//get from 270/276
public string ISA_05_SenderQualifier { get; set; }
public string ISA_06_SenderId { get; set; }
public string ISA_07_ReceiverQualifier { get; set; }
public string ISA_08_ReceiverId { get; set; }
public string ISA_09_DateReceived { get; set; } //default YYMMDD
public string ISA_10_TimeRecieved { get; set; } //default HHMM
public string ISA_11_RepetitionSeparator { get; set; } //default ^
public string ISA_12_X12Version { get; set; } //default 00501
public string ISA_13_UniqueNumberCounter { get; set; } //will be generated by app
public string ISA_14_AcknoledgementRequested { get; set; } //default 0
public string ISA_15_UsageIndicator { get; set; } //default P
public string ISA_16_CompElementSeparator { get; set; } //default :
//Interchange GS
public string GS_01 { get; set; } //default FA
//from 270/276
public string GS_02_SenderCode { get; set; }
public string GS_03_ReceiverCode { get; set; }
public string GS_04_DateReceived { get; set; } //default CCYYMMDD
public string GS_05_TimeReceived { get; set; } //default HHMM
public string GS_06_UniqueNumberCounter { get; set; } //will be generated by app
public string GS_07_AgencyCode { get; set; } //default "X"
public string GS_08_X12Version { get; set; } //default 00501X231A1
public string GE_01_TransactionSetCounter { get; set; } //number of transaction sets output typically 1
public string GE_02_UniqueNumberCounter { get; set; } //same as GS06
public string IEA_01_FunctionalGroupCounter { get; set; } //number of functional groups typically 1
public string IEA_02_UniqueNumberCounter { get; set; } //same as ISA_13
public DS_M_999_Interchange()
{
ISA_01_Authorization = "00";
ISA_02_AuthInfo = "";
ISA_03_SecurityQualifier = "00";
ISA_04_Password = "";
ISA_09_DateReceived = DateTime.Now.ToString("yyMMdd");
ISA_10_TimeRecieved = DateTime.Now.ToString("HHMM");
ISA_11_RepetitionSeparator = "^";
ISA_12_X12Version = "005010";
ISA_13_UniqueNumberCounter = "1ISA"; //Need to generate/track
ISA_14_AcknoledgementRequested = "0";
ISA_15_UsageIndicator = "P";
ISA_16_CompElementSeparator = ":";
GS_01 = "FA";
GS_04_DateReceived = (DateTime.Now.Year / 100 + 1).ToString() + DateTime.Now.ToString("yyMMdd");
GS_05_TimeReceived = DateTime.Now.ToString("HHMM");
GS_06_UniqueNumberCounter = "1GS06"; //Need to generate/track
GS_07_AgencyCode = "X";
GS_08_X12Version = "005010X231A1";
GE_01_TransactionSetCounter = "1";
GE_02_UniqueNumberCounter = GS_06_UniqueNumberCounter;
IEA_01_FunctionalGroupCounter = "1";
IEA_02_UniqueNumberCounter = ISA_13_UniqueNumberCounter;
}
}
public class DS_M_999_Group
{
public string ST_01_TransactionSetIdentifier { get; set; } //default 999
public string ST_02_TransactionSetCounter { get; set; } //will be generated by app startiing at 0001 (always 0001 in our instance)
public string ST_03_X12Version { get; set; } //default 005010x231a1
//from 270 /276
public string AK_101_FunctionalIdentifier { get; set; }
public string AK_102_GroupControlNumber { get; set; }
public string AK_103_VersionIdentifier { get; set; }
public string AK_201_TransactionSetIdentifier { get; set; }
public string AK_202_ControlNumber { get; set; }
public string AK_203_VersionIdentifier { get; set; }
public string IK_301_MissingSegment { get; set; } //set from x12ParserHelper MissingFields
public string IK_302_PositionInTransactionSet { get; set; } //need to figure this out by parsing incoming edi
public string IK_304_ErrorCode { get; set; } //default 3
public string IK_501_RejectIndicator { get; set; } //default R
public string IK_502_RejectCode { get; set; } //default 5
public string AK_901_RejectIndicator { get; set; } //default R
//from 270/276
public string AK_902_NumberOfTransactionSets { get; set; }
public string AK_903_NumberOfTransactionSets { get; set; }
public string AK_904_NumberAccepted { get; set; } //default 0
public string SE_01_SegmentCounter { get; set; } //#of segments in tx set ST to SE
public string SE_02_TransactionSetCounter { get; set; } //same as ST02
public DS_M_999_Group()
{
ST_01_TransactionSetIdentifier = "999";
ST_02_TransactionSetCounter = "0001";
ST_03_X12Version = "005010X231A1";
IK_304_ErrorCode = "3";
IK_501_RejectIndicator = "R";
IK_502_RejectCode = "5";
AK_901_RejectIndicator = "R";
AK_904_NumberAccepted = "0";
SE_01_SegmentCounter = "1";
SE_02_TransactionSetCounter = ST_02_TransactionSetCounter;
}
}
}
测试类:
using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using X12PayloadProcessing;
namespace X12PayloadProcessing.Tests
{
[TestClass]
public class DS_M_999_Tests
{
[TestMethod]
public void DSM999_ToEdiStringShouldBeValid()
{
DS_M_999_Interchange Interchange = new DS_M_999_Interchange();
Interchange.ISA_05_SenderQualifier = "ISA_05_SenderQualifier";
Interchange.ISA_06_SenderId = "SenderID"; //15 space padded
Interchange.ISA_07_ReceiverQualifier = "ISA_06_ReciverQualifier";
Interchange.ISA_08_ReceiverId = "ReceiverID"; //15 space padded
Interchange.GS_02_SenderCode = "GS_02_SenderCode";
Interchange.GS_03_ReceiverCode = "GS_03_ReceiverCode";
DS_M_999_Group Group = new DS_M_999_Group();
Group.AK_101_FunctionalIdentifier = "AK_101_FunctionalIdentifier";
Group.AK_102_GroupControlNumber = "AK_102_GroupControlNumber";
Group.AK_103_VersionIdentifier = "AK_103_VersionIdentifier";
Group.AK_201_TransactionSetIdentifier = "AK_201_TransactionSetIdentifier";
Group.AK_202_ControlNumber = "AK_202_ControlNumber";
Group.AK_203_VersionIdentifier = "AK_203_VersionIdentifier";
Group.IK_301_MissingSegment = "IK_301_MissingSegment";
Group.IK_302_PositionInTransactionSet = "IK_302_PositionInTransactionSet";
Group.AK_902_NumberOfTransactionSets = "AK_902_NumberOfTransactionSets";
Group.AK_903_NumberOfTransactionSets = "AK_903_NumberOfTransactionSets";
DS_M_999 DS_M_999 = new DS_M_999(Group, Interchange);
string ediString = DS_M_999.GetEdiString();
var x = DS_M_999._EDI_Interchange.ToEdi();
Assert.IsNotNull(ediString);
}
}
}
测试将按原样传递,但它不会产生预期的EDI输出。 Obewon Kenobe请帮忙,这是我们唯一的希望。
答案 0 :(得分:0)
我发现问题在于SDK代码已被翻译成我自己的代码库。 GS.D_480_8不应填写
_EDI_GS.D_480_8 = _Interchange.GS_08_X12Version.PadRight(6).Substring(0, 6);
有问题的SDK文件是GRP.cs代码:
public void Version(string versionNo)
{
versionNo = versionNo.PadRight(6);
Group.Gs.D_480_8 = versionNo.Substring(0, 6);
}
我的特定文件是一个长度为12个字符的GS08版本,当不是全部存在时,EDIFabric框架没有处理。
答案 1 :(得分:0)
问题似乎在于创建GS,在D_480_8中需要设置完整版本号,以便:
_EDI_GS.D_480_8 = _Interchange.GS_08_X12Version.PadRight(6).Substring(0, 6);
应改为:
_EDI_GS.D_480_8 = _Interchange.GS_08_X12Version;
解析器确定正确类型的方式 - 它从GS而不是ST或MessageContext中拉出X231A1部分(或Origin)。