public void TestGetFieldPID() { List <string> lMsg = Initialize; HL7Parser parse = new HL7Parser(); // we need to get the HL7 field separator and encoding characters HL7Encoding _encoding = GetHL7Encoding(lMsg); List <string> lStr = new List <string>(parse.GetSegment(lMsg, "PID")); if (lStr == null || lStr.Count <= 0) { Assert.IsNull(lStr); } Assert.IsTrue(IsSegmentFound(parse, _encoding, lStr, 1)); _processHL7 = ProcessHL7Message.Instance; var fName = _processHL7.GetField(_encoding, lStr[0], 5.1); //char enCodeChar = (parse.GetField(_encoding, lMsg[0], 1).Substring(0, 1))[0]; // not using the enCodeChar to parse subfields // get the first name of the patient // PID 5.2 fName = parse.GetField(_encoding, lStr[0], 5.1); Assert.AreNotSame("TIMOTHY", fName); var name1 = parse.GetField(_encoding, lStr[0], 5.0); Assert.AreNotSame("TEST^TIMOTHY^", fName); var name2 = parse.GetField(_encoding, lStr[0], 5); Assert.AreNotSame("TEST^TIMOTHY^", fName); }
public void TestGetFieldNTE3() { // NTE|1||POC Barbiturates Result:Negative| int nIdx = 3; List <string> lMsg = Initialize; HL7Parser parse = new HL7Parser(); // we need to get the HL7 field separator and encoding characters HL7Encoding _encoding = GetHL7Encoding(lMsg); List <string> lStr = new List <string>(parse.GetSegment(lMsg, "NTE")); if (lStr == null || lStr.Count <= 0) { Assert.IsNull(lStr); } Assert.IsTrue(IsSegmentFound(parse, _encoding, lStr, nIdx)); _processHL7 = ProcessHL7Message.Instance; var data = _processHL7.GetField(_encoding, lStr[nIdx - 1], 1); Assert.AreNotSame(nIdx, data); data = _processHL7.GetField(_encoding, lStr[nIdx - 1], 3); Assert.AreNotSame(notExpected: "POC Buprenorphine Result:Positive", actual: data); }
public void TestGetFieldMSH() { List <string> lMsg = Initialize; HL7Parser parse = new HL7Parser(); // we need to get the HL7 field separator and encoding characters HL7Encoding _encoding = GetHL7Encoding(lMsg); List <string> lStr = new List <string>(parse.GetSegment(lMsg, "MSH")); if (lStr == null || lStr.Count <= 0 || lStr.Count > 1) { Assert.IsNull(lStr); } _processHL7 = ProcessHL7Message.Instance; var data = _processHL7.GetField(_encoding, lStr[0], 2); Assert.AreNotSame("CareLogic^2.16.840.1.113883.3.1452.100.4", data); data = _processHL7.GetField(_encoding, lStr[0], 2.1); Assert.AreNotSame("CareLogic", data); data = _processHL7.GetField(_encoding, lStr[0], 3); Assert.AreNotSame("TVFFC1", data); data = _processHL7.GetField(_encoding, lStr[0], 8); Assert.AreNotSame("ORM^O01", data); data = _processHL7.GetField(_encoding, lStr[0], 8.2); Assert.AreNotSame("O01", data); data = _processHL7.GetField(_encoding, lStr[0], 11); Assert.AreNotSame("2.3", data); }
public void TestGetFieldDG1() { // "DG1|1||779.34^^I9|||W" int nIdx = 1; List <string> lMsg = Initialize; HL7Parser parse = new HL7Parser(); // we need to get the HL7 field separator and encoding characters HL7Encoding _encoding = GetHL7Encoding(lMsg); List <string> lStr = new List <string>(parse.GetSegment(lMsg, "DG1")); if (lStr == null || lStr.Count <= 0) { Assert.IsNull(lStr); } Assert.IsTrue(IsSegmentFound(parse, _encoding, lStr, nIdx)); _processHL7 = ProcessHL7Message.Instance; var data = _processHL7.GetField(_encoding, lStr[nIdx - 1], 1); Assert.AreNotSame(nIdx, data); data = _processHL7.GetField(_encoding, lStr[nIdx - 1], 3.1); Assert.AreNotSame(notExpected: "779.34", actual: data); }
public void TestGetFieldOBR_POC() { int nIdx = 2; List <string> lMsg = Initialize; HL7Parser parse = new HL7Parser(); // we need to get the HL7 field separator and encoding characters HL7Encoding _encoding = GetHL7Encoding(lMsg); List <string> lStr = new List <string>(parse.GetSegment(lMsg, "OBR")); if (lStr == null || lStr.Count <= 0) { Assert.IsNull(lStr); } Assert.IsTrue(IsSegmentFound(parse, _encoding, lStr, nIdx)); _processHL7 = ProcessHL7Message.Instance; var data = _processHL7.GetField(_encoding, lStr[nIdx - 1], 1); Assert.AreNotSame(nIdx, data); data = _processHL7.GetField(_encoding, lStr[nIdx - 1], 2); Assert.AreNotSame("EA194979A", data); data = _processHL7.GetField(_encoding, lStr[nIdx - 1], 4); Assert.AreNotSame("POC^POC Testing", data); data = _processHL7.GetField(_encoding, lStr[nIdx - 1], 4.1); Assert.AreNotSame("POC", data); data = _processHL7.GetField(_encoding, lStr[nIdx - 1], 4.2); Assert.AreNotSame("POC Testing", data); }
public void TestORMParse() { HL7_ORM _order = null; List <string> lMsg = InitializeORM; // we need to get the HL7 field separator and encoding characters _processHL7 = ProcessHL7Message.Instance; // HL7_ORM _order = (HL7_ORM)_processHL7.ParseHL7(slMsg: lMsg); object obj = _processHL7.ParseHL7(slMsg: lMsg); if (obj is HL7_ORM) { _order = (HL7_ORM)obj; } else { Assert.Fail("HL7 Message is not an ORM message type"); } if (IsHeaderValid(_order.HL7Header)) { Assert.Fail("MHS Header validation failed"); } // validate Patients if (IsPatientValid(_order.HL7Patient)) { Assert.Fail("Patient segment failed validation"); } // validate insurance segments if (IsPatientInsuranceValid(_order.HL7Patient)) { Assert.Fail("Insurance segment failed validation"); } if (_order.HL7Patient.NTESegments.Count > 0) { Assert.Fail("NTE segment failed validation"); } if (_order.HL7Orders == null) { Assert.Fail("Orders object is NULL"); } else { if (IsOrderValid(_order.HL7Orders)) { Assert.Fail("Order segments failee"); } } }
private void HL7ApplySampleProcess() { string receiveString = string.Empty; //while ((!ProcessHL7Cancel.IsCancellationRequested && GlobalVariable.IsSocketRun) || hl7Manager.IsHL7ApplySampleAvailable) while ((!ProcessHL7Cancel.IsCancellationRequested && GlobalVariable.IsSocketRun)) { //进行之前接收到的样本数据处理 hl7Manager.HL7ApplySampleSignal.WaitOne(); if (!hl7Manager.IsHL7ApplySampleAvailable) { hl7Manager.HL7ApplySampleSignal.Reset(); Statusbar.SBar.SoftStatus = GlobalVariable.miniWaiting; } else { //队列里存在数据 receiveString = hl7Manager.GetHL7ApplySample(); if (receiveString.IndexOf("DSR") != -1) { //判断传回来数据为DSR数据 //解析DSR //解析完DSR数据就要回复ACKQ03消息,此时设备信息传出去 PipeParser parserActiveDSR = new PipeParser(); IMessage mActiveDSR = parserActiveDSR.Parse(receiveString); DSR_Q03 dsr = mActiveDSR as DSR_Q03; if (dsr.MSH.AcceptAcknowledgmentType.Value == "P" && dsr.QAK.QueryResponseStatus.Value == "OK") { //双重判断,既判断是否为LIS主动发送样本信息,也要判断是否OK Statusbar.SBar.SoftStatus = GlobalVariable.miniBusy;// mini mode HL7Manager.HL7SampleInfo hl7info = HL7_ParserSampleInfo(receiveString); RequestSampleData.Invoke(hl7info); //接收成功后就要发送应答信号 Connect.sendSocket(CreatACKQ03(dsr.MSH.ReceivingFacility.NamespaceID.Value)); ProcessHL7Message.Invoke(hl7info.SampleID + "LIS服务器主动发送样本申请信息\r\n", "LIS"); log.Info("Lis initiative request sample " + hl7info.SampleID); //Statusbar.SBar.SoftStatus = GlobalVariable.miniWaiting;// mini mode Statusbar.SBar.SampleId = hl7info.SampleID;//mini mode } } Statusbar.SBar.SoftStatus = GlobalVariable.miniBusy;// mini mode } } }
public void TestGetFieldOBR_NU3025() { int nIdx = 1; List <string> lMsg = Initialize; HL7Parser parse = new HL7Parser(); // we need to get the HL7 field separator and encoding characters HL7Encoding _encoding = GetHL7Encoding(lMsg); List <string> lStr = new List <string>(parse.GetSegment(lMsg, "OBR")); if (lStr == null || lStr.Count <= 0) { Assert.IsNull(lStr); } Assert.IsTrue(IsSegmentFound(parse, _encoding, lStr, nIdx)); _processHL7 = ProcessHL7Message.Instance; var data = _processHL7.GetField(_encoding, lStr[nIdx - 1], 1); Assert.AreNotSame(nIdx, data); data = _processHL7.GetField(_encoding, lStr[nIdx - 1], 2); Assert.AreNotSame("EA194979A", data); data = _processHL7.GetField(_encoding, lStr[nIdx - 1], 4); Assert.AreNotSame("NU3025^PDX Custom Panel-Urine", data); data = _processHL7.GetField(_encoding, lStr[nIdx - 1], 4.1); Assert.AreNotSame("NU3025", data); data = _processHL7.GetField(_encoding, lStr[nIdx - 1], 4.2); Assert.AreNotSame("PDX Custom Panel-Urine", data); data = _processHL7.GetField(_encoding, lStr[nIdx - 1], 16.1); Assert.AreNotSame("1010101010", data); data = _processHL7.GetField(_encoding, lStr[nIdx - 1], 16.2); Assert.AreNotSame("Support", data); data = _processHL7.GetField(_encoding, lStr[nIdx - 1], 16.3); Assert.AreNotSame("Qualifacts", data); }
public void TestGetFieldORC() { List <string> lMsg = Initialize; HL7Parser parse = new HL7Parser(); // we need to get the HL7 field separator and encoding characters HL7Encoding _encoding = GetHL7Encoding(lMsg); List <string> lStr = new List <string>(parse.GetSegment(lMsg, "ORC")); if (lStr == null || lStr.Count <= 0) { Assert.IsNull(lStr); } _processHL7 = ProcessHL7Message.Instance; var data = _processHL7.GetField(_encoding, lStr[0], 1); Assert.AreNotSame("1", data); data = _processHL7.GetField(_encoding, lStr[0], 2); Assert.AreNotSame("EA194979A", data); }
private void sendSocket() { string HL7Message = string.Empty; string receiveString; PipeParser parser; IMessage m; int SendNum = 0; log.Info("HL7 send socket start."); while (!ProcessHL7Cancel.IsCancellationRequested && GlobalVariable.IsSocketRun) { if (hl7Manager.IsHL7Available) { #region 向HL7发送样本测试结果 if (SendNum == GlobalVariable.ReSendNum) { //连续发送失败超过规定次数,不再发送 hl7Manager.RemoveHL7();//移除队列中开始处的HL7 SendNum = 0; continue; } Statusbar.SBar.SoftStatus = GlobalVariable.miniBusy;// mini mode try { HL7Message = hl7Manager.GetHL7Message(); Connect.sendSocket(HL7Message); log.Info("HL7 send" + hl7Manager.GetHL7Sample_ID()); if (SendNum == 0) { ++Statusbar.SBar.SendNum; } ++SendNum; } catch { Statusbar.SBar.SoftStatus = GlobalVariable.miniError;// mini mode ProcessHL7Message.Invoke(hl7Manager.GetHL7Sample_ID() + "Lis服务器发送失败\r\n请重新打开软件\r\n", "LIS"); break; } if (!GlobalVariable.IsOneWay)//双向 { receiveString = Connect.receiveSocket(); if (receiveString.Substring(0, 3) == "MSH")//相当于一个判断 { parser = new PipeParser(); m = parser.Parse(receiveString); ACK ack = m as ACK; if (ack.MSA.AcknowledgementCode.Value == "AA") { ProcessHL7Message.Invoke(hl7Manager.GetHL7Sample_ID() + "Lis服务器接收成功\r\n", "LIS"); log.Info("LIS receive success" + hl7Manager.GetHL7Sample_ID()); Statusbar.SBar.SoftStatus = GlobalVariable.miniWaiting; // mini mode Statusbar.SBar.SampleId = hl7Manager.GetHL7Sample_ID(); //mini mode ++Statusbar.SBar.ReplyNum; SendNum = 0; UpdateDB.Invoke(hl7Manager.GetHL7Sample_ID(), hl7Manager.GetHL7Item(), hl7Manager.GetHL7Device(), hl7Manager.GetHL7Sample_SendTime()); hl7Manager.RemoveHL7();//移除队列中开始处的HL7 } else { Statusbar.SBar.SoftStatus = GlobalVariable.miniError;// mini mode ProcessHL7Message.Invoke(hl7Manager.GetHL7Sample_ID() + "Lis服务器第" + SendNum.ToString() + "次接收失败\r\n", "LIS"); log.Info("LIS " + SendNum + " receive fail"); } } else { //接收异常 Statusbar.SBar.SoftStatus = GlobalVariable.miniError;// mini mode ProcessHL7Message.Invoke(hl7Manager.GetHL7Sample_ID() + "Lis服务器第" + SendNum.ToString() + "次接收失败\r\n", "LIS"); log.Info("LIS " + SendNum + " receive fail"); } } else//单向 { Statusbar.SBar.SoftStatus = GlobalVariable.miniWaiting;// mini mode Statusbar.SBar.SampleId = hl7Manager.GetHL7Sample_ID();//mini mode ProcessHL7Message.Invoke(hl7Manager.GetHL7Sample_ID() + "Lis服务器发送成功\r\n", "LIS"); log.Info("LIS receive success" + hl7Manager.GetHL7Sample_ID()); UpdateDB.Invoke(hl7Manager.GetHL7Sample_ID(), hl7Manager.GetHL7Item(), hl7Manager.GetHL7Device(), hl7Manager.GetHL7Sample_SendTime()); //直接回调 hl7Manager.RemoveHL7(); //移除队列中开始处的HL7 } #endregion } else if (hl7Manager.IsHL7RequestSampleDataAvailable) { #region 向LIS请求样本信息 Statusbar.SBar.SoftStatus = GlobalVariable.miniBusy;// mini mode string HL7Apply; //申请信息发送 try { HL7Apply = hl7Manager.GetHL7RequestSampleDataMessage(); Connect.sendSocket(HL7Apply); ++Statusbar.SBar.SendNum; } catch { Statusbar.SBar.SoftStatus = GlobalVariable.miniError;// mini mode ProcessHL7Message.Invoke(hl7Manager.GetHL7Sample_ID() + "Lis服务器发送失败\r\n请重新打开软件\r\n", "LIS"); break; } receiveString = Connect.receiveSocket(); if (receiveString.Substring(0, 3) == "MSH") { //传回为标准消息 parser = new PipeParser(); m = parser.Parse(receiveString); QCK_Q02 qck = m as QCK_Q02; if (qck.QAK.QueryResponseStatus.Value == "OK")//代表有样本数据 { string receiveStringDSR; int DSRIndex = receiveString.IndexOf("DSR"); if (DSRIndex == -1) //如果刚才接收过来的没有DSR数据 { receiveStringDSR = Connect.receiveSocket(); //重新来接受DSR数据 } else { receiveStringDSR = receiveString.Substring(DSRIndex);//截取后面一部分得为DSR数据 } //解析DSR //解析完DSR数据就要回复ACKQ03消息,此时设备信息传出去 PipeParser parserDSR = new PipeParser(); IMessage mDSR = parserDSR.Parse(receiveStringDSR); DSR_Q03 dsr = mDSR as DSR_Q03; if (dsr.QAK.QueryResponseStatus.Value == "OK") //相当于再做了一层判断 { HL7Manager.HL7SampleInfo hl7info = HL7_ParserSampleInfo(receiveStringDSR); //接收成功后就要发送应答信号 RequestSampleData.BeginInvoke(hl7info, null, null); Connect.sendSocket(CreatACKQ03(dsr.MSH.ReceivingFacility.NamespaceID.Value)); Statusbar.SBar.SoftStatus = GlobalVariable.miniWaiting; // mini mode Statusbar.SBar.SampleId = hl7Manager.GetHL7RequestSampleDataSample_ID(); //mini mode ProcessHL7Message.Invoke(hl7Manager.GetHL7RequestSampleDataSample_ID() + "LIS服务器申请样本成功\r\n", "LIS"); log.Info("Lis request sample success " + hl7Manager.GetHL7RequestSampleDataSample_ID()); } else { Statusbar.SBar.SoftStatus = GlobalVariable.miniError;// mini mode ProcessHL7Message.Invoke(hl7Manager.GetHL7RequestSampleDataSample_ID() + "LIS服务器申请样本异常\r\n", "LIS"); log.Info("Lis request sample fail " + hl7Manager.GetHL7RequestSampleDataSample_ID()); } } else if (qck.QAK.QueryResponseStatus.Value == "NF")//代表没有样本数据 { //此时不再回复消息 //结束 Statusbar.SBar.SoftStatus = GlobalVariable.miniError;// mini mode ProcessHL7Message.Invoke(hl7Manager.GetHL7RequestSampleDataSample_ID() + "LIS服务器无相关样本信息\r\n", "LIS"); log.Info("Lis no request sample " + hl7Manager.GetHL7RequestSampleDataSample_ID()); } } #endregion hl7Manager.RemoveHL7RequestSampleData();//移除掉队列中的申请信息 } else { #region LIS主动发送样本信息 //hl7Manager.HL7Signal.Reset(); //持续监听LIS服务器 receiveString = Connect.receiveSocket(); if (receiveString.Length > 10 && receiveString.Substring(0, 3) == "MSH") { //传回来为标准信息 hl7Manager.AddHL7ApplySample(receiveString); //扔给队列交给线程处理 hl7Manager.HL7ApplySampleSignal.Set(); //唤醒线程 } #endregion } } }