我有一個SIU S12 message不包含PV2段。但是,當我從NHAPI獲得解析的消息時,PV2的父組SIU_S12_PATIENT組返回1,表示存在PV2,即currentReps ("PV2")。如何通過NHAPI知道段是否實際存在於HL7消息中?
var parser = new NHapi.Base.Parser.PipeParser();
var parsedMessage = parser.Parse(message) as NHapi.Model.V231.Message.SIU_S12;
var patientGroup=parsedMessage.GetPATIENT(0);
// This call should not create the segment if it does not exist
int pv2Count=patientGroup.currentReps("PV2");
//pv2Count is 1 here despite no PV2 segment exists in the message
//also Both GetAll("PV2") and SegmentFinder say the PV2 segment is present
//DG1RepetitionsUsed is also 1 despite no DG1 segment is present in the message
我試圖避免編寫代碼來評估段中的每個字段。 PV2僅僅是一個例子 - 消息源中可能會丟失更多的段。
我使用NHAPI v 2.4,最新版本。
更新:下面泰森的建議,我想出這個方法,
var parser = new NHapi.Base.Parser.PipeParser();
var parsedMessage = parser.Parse(message) as NHapi.Model.V231.Message.SIU_S12;
var encodingChars = new NHapi.Base.Parser.EncodingCharacters('|', null);
var patientGroup = parsedMessage.GetPATIENT(0);
var dg1 = (NHapi.Model.V231.Segment.DG1) (patientGroup.GetStructure("DG1"));
string encodedDg1 = NHapi.Base.Parser.PipeParser.Encode(dg1, encodingChars);
bool dg1Exists = string.Compare(encodedDg1,
"DG1", StringComparison.InvariantCultureIgnoreCase)==0;
PiperParser不返回空字符串,但返回段名稱。但是,仍然可以用來檢查段是否爲空,謝謝。 – 2013-07-12 22:18:35