/// <summary> /// 从消息中删除患者标识信息,并将其替换为组成的患者数据。 /// </summary> /// <param name="m">The message to de-identify.</param> /// <returns>Returns the original message without identifying information.</returns> public static HL7Message DeIdentify(this HL7Message m) { HL7Message msg = m; if (msg.Segments.Get("PID") != null) { string mrn = Helper.RandomMRN(); string sex = msg.Segments.Get("PID")[0].Fields[8].Components[0].Value; msg.Segments.Get("PID")[0].Fields[2].Components[0].Value = mrn; msg.Segments.Get("PID")[0].Fields[3].Components[0].Value = mrn; msg.Segments.Get("PID")[0].Fields[4].Components[0].Value = mrn; msg.Segments.Get("PID")[0].Fields[5].Components[0].Value = Helper.RandomLastName(); msg.Segments.Get("PID")[0].Fields[5].Components[1].Value = Helper.RandomFirstName(sex); msg.Segments.Get("PID")[0].Fields[6].Components[0].Value = Helper.RandomLastName(); msg.Segments.Get("PID")[0].Fields[6].Components[1].Value = Helper.RandomFirstName("FEMALE"); msg.Segments.Get("PID")[0].Fields[9].Components[0].Value = ""; msg.Segments.Get("PID")[0].Fields[9].Components[1].Value = ""; msg.Segments.Get("PID")[0].Fields[11].Components[0].Value = Helper.RandomAddress(); msg.Segments.Get("PID")[0].Fields[13].Components[0].Value = ""; msg.Segments.Get("PID")[0].Fields[13].Components[11].Value = ""; msg.Segments.Get("PID")[0].Fields[14].Components[0].Value = ""; msg.Segments.Get("PID")[0].Fields[14].Components[11].Value = ""; msg.Segments.Get("PID")[0].Fields[18].Components[0].Value = mrn; msg.Segments.Get("PID")[0].Fields[19].Components[0].Value = "999999999"; } return(msg); }
/// <summary> /// Validates the ack against the message /// </summary> /// <param name="OutboundMessage">The message to use</param> /// <param name="AckMessage">The ack to use</param> /// <returns></returns> public static bool ValidateAck(HL7Message OutboundMessage, HL7Message AckMessage) { bool returnValue = false; if (OutboundMessage.Segments.Get("MSH").Count == 1 && AckMessage.Segments.Get("MSA").Count == 1) { Segment msh = OutboundMessage.Segments.Get("MSH")[0]; Segment msa = AckMessage.Segments.Get("MSA")[0]; if (msh.GetByID("MSH-10.1").Value == msa.GetByID("MSA-2.1").Value&& msa.GetByID("MSA-1.1").Value == "AA") { returnValue = true; } } else { returnValue = false; } return(returnValue); }
/// <summary> /// 按ID从单个消息中获取组件列表 /// </summary> /// <param name="m">The message to search</param> /// <param name="ID">The ID of the component to pull</param> /// <returns>Returns the list of components</returns> public static List <Component> GetByID(this HL7Message m, string ID) { if (!String.IsNullOrEmpty(ID)) { ComponentID cid = ID.ConvertID(); List <Component> returnValue = new List <Component>(); var items = from com in m.Segments.Get(cid.SegmentName) where com.GetByID(ID) != null select com.GetByID(ID); foreach (Component c in items) { returnValue.Add(c); } return(returnValue); } else { return(null); } }
/// <summary> /// 按ID和指定值从单个消息中获取单个组件 /// </summary> /// <param name="m">The message to search</param> /// <param name="ID">The ID of the component to pull</param> /// <param name="ValueString">The value of the component to search for</param> /// <returns>The component returned</returns> public static Component GetByID(this HL7Message m, string ID, string ValueString) { Component returnValue = new Component(); if (!String.IsNullOrEmpty(ID)) { ComponentID cid = ID.ConvertID(); List <Segment> segments = m.Segments.Get(cid.SegmentName); foreach (Segment s in segments) { Component c = s.GetByID(ID); if (ValueString.ToUpper() == "NULL") { if (c != null && String.IsNullOrEmpty(c.Value)) { returnValue = c; } } else if (ValueString.ToUpper() == "!NULL") { if (c != null && !String.IsNullOrEmpty(c.Value)) { returnValue = c; } } else { if (c != null && c.Value != null) { if (c.Value.ToUpper() == ValueString.ToUpper()) { returnValue = c; } } } } } return(returnValue); }
/// <summary> /// Creates an ACK from the MSH segment of the associated message /// </summary> /// <param name="InboundMessage">The inbound message</param> /// <returns>The ack</returns> public static HL7Message CreateAck(HL7Message InboundMessage) { if (InboundMessage.Segments.Get("MSH").Count == 1) { Segment msh = InboundMessage.Segments.Get("MSH")[0]; List <object> args = new List <object>(); args.Add((object)msh.GetByID("MSH-3.1").Value); //String.Format Arg 0 args.Add((object)msh.GetByID("MSH-4.1").Value); //String.Format Arg 1 args.Add((object)msh.GetByID("MSH-5.1").Value); //String.Format Arg 2 args.Add((object)msh.GetByID("MSH-6.1").Value); //String.Format Arg 3 args.Add((object)msh.GetByID("MSH-7.1").Value); //String.Format Arg 4 args.Add((object)msh.GetByID("MSH-9.2").Value); //String.Format Arg 5 args.Add((object)msh.GetByID("MSH-10.1").Value); //String.Format Arg 6 args.Add((object)msh.GetByID("MSH-11.1").Value); //String.Format Arg 7 args.Add((object)msh.GetByID("MSH-12.1").Value); //String.Format Arg 8 string msg = String.Format("MSH|^~\\&|{0}|{1}|{2}|{3}|{4}||ACK^{5}|{6}|{7}|{8}\r\nMSA|AA|{6}", args.ToArray()); HL7Message m = new HL7Message(msg); return(m); } else { throw new Exception("No MSH Segment Present in Inbound Message."); } }