/// <summary> /// Strings the parse and check message is positive ack. /// </summary> /// <param name="msg">The MSG.</param> /// <returns><c>true</c> if XXXX, <c>false</c> otherwise.</returns> public static bool StringParseAndCheckMessageIsPositiveAck(string msg) { try { //Purpose : Check the Message is Acknowledgment Or Not string[] dataBlocks = null; string[] sectionBlocks = null; bool isPositiveAck = false; dataBlocks = msg.Split('\r'); foreach (string dataBlock in dataBlocks) { if (dataBlock.Trim().Length > 0) { sectionBlocks = dataBlock.Replace('\n', ' ').Trim().Split('|'); if (sectionBlocks.Length > 1 && sectionBlocks[1].Trim().Equals("AA")) { isPositiveAck = true; break; } } } return(isPositiveAck); } catch (Exception ex) { ExceptionTransactionLog.WriteToLog(ex); return(false); } }
/// <summary> /// Strings the parse and get message control identifier. /// </summary> /// <param name="msg">The MSG.</param> /// <returns>System.String.</returns> public static string StringParseAndGetMessageControlID(string msg) { //Purpose : Return the Message Control ID if Exist Otherwise return Integer.Min value string MsgControlID = Convert.ToString(int.MinValue); try { string[] dataBlocks = null; string[] sectionBlocks = null; dataBlocks = msg.Split('\r'); foreach (string dataBlock in dataBlocks) { if (dataBlock.Trim().Length > 0) { sectionBlocks = dataBlock.Replace('\n', ' ').Trim().Split('|'); if (sectionBlocks[0].Trim().Equals("MSH")) { if (sectionBlocks.Length > 9 && sectionBlocks[9].Trim().ToString().Length > 0) { MsgControlID = sectionBlocks[9].Trim().ToString(); } break; } } } return(MsgControlID); } catch (Exception ex) { ExceptionTransactionLog.WriteToLog("Exception occure on HL7GeneralMessageParser, StringParseAndGetMessageControlID method", ex); return(MsgControlID); } }
/// <summary> /// Strings the parse and check message is ack. /// </summary> /// <param name="msg">The MSG.</param> /// <returns><c>true</c> if XXXX, <c>false</c> otherwise.</returns> public static bool StringParseAndCheckMessageIsAck(string msg) { try { //Purpose : Check the Message is Acknowledgment Or Not string[] dataBlocks = null; string[] sectionBlocks = null; bool isAck = false; dataBlocks = msg.Split('\r'); foreach (string str in dataBlocks) { sectionBlocks = str.Split('|'); if (sectionBlocks.Length > 8 && sectionBlocks[0].Trim().Contains("MSH") && sectionBlocks[8].Trim().Contains("ACK")) { isAck = true; break; } } return(isAck); } catch (Exception ex) { ExceptionTransactionLog.WriteToLog(ex); return(false); } }
/// <summary> /// Sets the message control character. /// </summary> /// <param name="channel">The channel.</param> public static void SetMessageControlCharacter(Channel channel) { try { if (channel.Postmessagedelimiter != null && channel.Postmessagedelimiter == Convert.ToString((int)(Enumerators.HL7.HL7PostMsgDelimiter.Ox1C_OxOD))) { postmessagedelimiter = messageDelimiter + segmentDelimiter; } else if (channel.Postmessagedelimiter != null && channel.Postmessagedelimiter == Convert.ToString((int)(Enumerators.HL7.HL7PostMsgDelimiter.Ox1C))) { postmessagedelimiter = messageDelimiter; } else { postmessagedelimiter = messageDelimiter; } if (channel.Premessagedelimiter != null && channel.Premessagedelimiter == Convert.ToString((int)(Enumerators.HL7.HL7PreMsgDelimiter.OxOB))) { premessagedelimiter = messageStartingChar; } else { premessagedelimiter = messageStartingChar; } } catch (Exception ex) { ExceptionTransactionLog.WriteToLog("Exception occure on HL7GeneralMessageParser, SetMessageControlCharacter method", ex); } }
/// <summary> /// Checks the validity of message. /// </summary> /// <param name="msg">The MSG.</param> /// <returns><c>true</c> if XXXX, <c>false</c> otherwise.</returns> public static bool CheckValidityOfMessage(string msg) { bool functionReturnValue = false; try { functionReturnValue = true; if (!msg.Contains(messageDelimiter)) { return(false); } char[] arry = messageStartingChar.ToCharArray(); msg = msg.Trim(arry); char[] arry1 = segmentDelimiter.ToCharArray(); msg = msg.Trim(arry1); char[] arry2 = messageDelimiter.ToCharArray(); msg = msg.Trim(arry2); return(isValidHL7Msg(msg.Trim(Strings.Chr(28)))); } catch (Exception ex) { ExceptionTransactionLog.WriteToLog(ex); return(false); } }
/// <summary> /// Determines whether [is valid h l7 MSG] [the specified string MSG]. /// </summary> /// <param name="strMsg">The string MSG.</param> /// <returns><c>true</c> if [is valid h l7 MSG] [the specified string MSG]; otherwise, <c>false</c>.</returns> public static bool isValidHL7Msg(string strMsg) { bool functionReturnValue = false; //Purpose : Validate the HL7 Message. try { functionReturnValue = true; if (strMsg.Length > 0) { // First Case if (strMsg.Length > 3 && Strings.StrComp(strMsg.Substring(0, 3).Trim(), "MSH", CompareMethod.Binary) == 0) { if (strMsg.Length > 4 && !string.IsNullOrEmpty(strMsg.Substring(3, 1)) && IsSpecialCharacter(strMsg.Substring(3, 1))) { if (!strMsg.Contains(Convert.ToString(Strings.Chr(13)))) { return(false); } string[] ar = strMsg.Substring(0, strMsg.IndexOf(Strings.Chr(13))).Split(strMsg.Substring(3, 1).ToCharArray()); // string[] ar = Strings.Split(strMsg.Substring(0, strMsg.IndexOf(Strings.Chr(13))), strMsg.Substring(3, 1)); if (ar.Length >= 11) { //Message Type, Message Control ID, Processing ID and Versions are Not Null if (!string.IsNullOrEmpty(ar[8].Trim()) && !string.IsNullOrEmpty(ar[9].Trim()) && !string.IsNullOrEmpty(ar[10].Trim()) && !string.IsNullOrEmpty(ar[11].Trim())) { return(true); } else { return(false); } } else { return(false); } } else { return(false); } } else { return(false); } } } catch (Exception ex) { ExceptionTransactionLog.WriteToLog(ex); return(false); } return(functionReturnValue); }
/// <summary> /// Gets the message array. /// </summary> /// <param name="data">The data.</param> /// <returns>System.String[].</returns> public static string[] GetMessageArray(string data) { //Purpose : Return One Single Message the "DATA" . string lineNo = "0\t"; try { string[] returnMessage = new string[2]; returnMessage[0] = string.Empty; returnMessage[1] = data; lineNo += "1\t"; if (data.Trim() != string.Empty) { string message = string.Empty; if (data.Contains(Convert.ToChar(messageDelimiter))) { if (data.Contains(Convert.ToChar(messageStartingChar))) { lineNo += "2\t"; data = data.Substring(data.IndexOf(messageStartingChar), data.Length - data.IndexOf(messageStartingChar)); } lineNo += "3\t"; if (data.Contains(Convert.ToChar(messageDelimiter))) { message = data.Substring(0, data.IndexOf(messageDelimiter)); lineNo += "4\t"; if (message.Length > 0) { lineNo += "5\t"; if (data.IndexOf(messageDelimiter) + 1 == data.Length) { lineNo += "6\t"; data = string.Empty; } else { lineNo += "7\t"; data = data.Substring(data.IndexOf(messageDelimiter) + 1, data.Length - (data.IndexOf(messageDelimiter) + 1)); lineNo += "8\t"; if (data.Contains(Convert.ToChar(messageStartingChar))) { lineNo += "9\t"; data = data.Substring(data.IndexOf(messageStartingChar), data.Length - data.IndexOf(messageStartingChar)); } else { lineNo += "10\t"; data = string.Empty; } } lineNo += "11\t"; message = message + messageDelimiter; lineNo += "12\t"; returnMessage[0] = message; lineNo += "13\t"; returnMessage[1] = data; } } else { returnMessage[1] = data; } } } lineNo += "15\t"; return(returnMessage); } catch (Exception ex) { ExceptionTransactionLog.WriteToLog("Exception occure on GetMessageArray Tarace : " + lineNo + " Actual Exception: " + ex.Message); throw ex; } }