Ejemplo n.º 1
0
        /// <summary>
        /// GetComponent - get the field component list for a given field
        /// use the HL7 encoding character for components
        /// split the field string based on the component encoding character and return the value
        /// at the index
        /// if no components are found return orginal string
        /// </summary>
        /// <param name="msg">HL7 message</param>
        /// <returns></returns>
        public string GetComponent(HL7Encoding _encode, string msg, int idx = -1)
        {
            string sStr = "";

            idx--;

            if (string.IsNullOrEmpty(msg) || idx < 0)
            {
                return(msg);                   // bad
            }

            string[] saStr = msg.Split(_encode.Encoding[(int)encodingCharacters.ComponentSeparator]);
//			if (idx <= saStr.Count())
//			{
            try
            {
                sStr = saStr.GetValue(idx).ToString();
            }
            catch (IndexOutOfRangeException)
            {
                sStr = string.Empty;                            // not found
            }
//			}
//			else
//			{
//				return msg;    // not found
//			}
            return(sStr);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// getElement - get the HL7 element for the given message
        /// </summary>
        /// <param name="msg">HL7 message</param>
        /// <returns></returns>
        public string GetField(HL7Encoding _encode, string msg, int idx = -1)
        {
            string sStr = "";

            if (string.IsNullOrEmpty(msg) || idx == -1)
            {
                return(null);                   // bad
            }

            string[] saStr = msg.Split(_encode.FieldSeparator);
            if (idx <= saStr.Count())
            {
                try
                {
                    sStr = saStr.GetValue(idx).ToString();
                }
                catch (IndexOutOfRangeException)
                {
                    sStr = string.Empty;
                }
            }
            else
            {
                return(msg);                   // not found
            }
            return(sStr);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// getElement - return the element for the message segment
        /// </summary>
        /// <param name="msg">HL7 message</param>
        /// <param name="idx">Index to the element within the message</param>
        /// <returns>object. can be string, datetime, int</returns>
        public object GetElement(HL7Encoding _encode, string msg, int idx = -1)
        {
            string sStr = "";

            if (string.IsNullOrEmpty(msg) || idx == -1)
            {
                return(null);                   // bad
            }

            string[] saStr = msg.Split(_encode.FieldSeparator);
            if (idx >= saStr.Length)
            {
                // error
                return(null);
            }
            try
            {
                sStr = saStr.GetValue(idx).ToString();
            }
            catch (IndexOutOfRangeException)
            {
                sStr = string.Empty;
            }
            return(sStr);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// getField - Get the HL7 value for the given field based on field value
        /// I.E. field = 3.1 get the value from field index 3 subvalue 1
        /// I.E. field = 5.3 get the value from field 5 subvalue 3
        /// </summary>
        /// <param name="msg">segment to parse</param>
        /// <param name="encoding">HL7 encoding characters from the MSH segment use to obtain the field separator character</param>
        /// <param name="field">field index Major.Subfield</param>
        /// <returns>string</returns>If null failed to retreive the field
        public string GetField(HL7Encoding _encode, string msg, double element = 0.0)
        {
            if (string.IsNullOrEmpty(msg) || _encode.Encoding[(int)encodingCharacters.ComponentSeparator] <= 32 || element == 0.0)
            {
                return(null);
            }

            string sStr = "";

            // lets split the value to field.subField
            // I.E.  5.3 or 5.3.1 or 5.4.3.1
            // first index is Field, other nunbers are subfield
            string[] saField = string.Format("{0}", element).Split('.');
            int[]    fldIdx  = new int[10];
            for (int xx = 0; xx < saField.Length; xx++)
            {
                fldIdx[xx] = int.Parse(saField[xx]);
            }

            // break string into fields
            string[] saStr = msg.Split(_encode.FieldSeparator);
            if (element <= saStr.Count())
            {
                sStr = saStr.GetValue(fldIdx[0]).ToString();
                if (fldIdx[1] != 0)
                {
                    // now get the subfield
                    string[] subFld = sStr.Split(_encode.Encoding[(int)encodingCharacters.ComponentSeparator]);
                    sStr = subFld[fldIdx[1] - 1];
                }
            }
            else
            {
                return(null);                   // bad
            }
            return(sStr);
        }
Ejemplo n.º 5
0
 public HL7Header(MSH msh, List <NTE> notes, HL7Encoding _encoding)
 {
     MSHSegment  = msh;
     NTESegments = notes;
     HL7Encoding = _encoding;
 }