Example #1
0
        /// <summary> Populates the given Element with data from the given Segment, by inserting
        /// Elements corresponding to the Segment's fields, their components, etc.  Returns
        /// true if there is at least one data value in the segment.
        /// </summary>
        public virtual bool encode(Segment segmentObject, System.Xml.XmlElement segmentElement)
        {
            bool hasValue = false;
            int  n        = segmentObject.numFields();

            for (int i = 1; i <= n; i++)
            {
                System.String name = makeElementName(segmentObject, i);
                Type[]        reps = segmentObject.getField(i);
                for (int j = 0; j < reps.Length; j++)
                {
                    System.Xml.XmlElement newNode = segmentElement.OwnerDocument.CreateElement(name);
                    bool componentHasValue        = encode(reps[j], newNode);
                    if (componentHasValue)
                    {
                        try
                        {
                            segmentElement.AppendChild(newNode);
                        }
                        catch (System.Exception e)
                        {
                            throw new NuGenHL7Exception("DOMException encoding Segment: ", NuGenHL7Exception.APPLICATION_INTERNAL_ERROR, e);
                        }
                        hasValue = true;
                    }
                }
            }
            return(hasValue);
        }
Example #2
0
 private void  parseReps(Segment segmentObject, System.Xml.XmlElement segmentElement, System.String fieldName, int fieldNum)
 {
     System.Xml.XmlNodeList reps = segmentElement.GetElementsByTagName(fieldName);
     for (int i = 0; i < reps.Count; i++)
     {
         parse(segmentObject.getField(fieldNum, i), (System.Xml.XmlElement)reps.Item(i));
     }
 }
Example #3
0
        private void  parse(System.String field, Segment segment, int num, NuGenEncodingCharacters ec)
        {
            if (field != null)
            {
                int  rep          = 0;
                int  component    = 1;
                int  subcomponent = 1;
                Type type         = segment.getField(num, rep);

                System.String delim = System.Convert.ToString(new char[] { ec.RepetitionSeparator, ec.ComponentSeparator, ec.SubcomponentSeparator });
                for (SupportClass.Tokenizer tok = new SupportClass.Tokenizer(field, delim, true); tok.HasMoreTokens();)
                {
                    System.String token = tok.NextToken();
                    char          c     = token[0];
                    if (c == ec.RepetitionSeparator)
                    {
                        rep++;
                        component    = 1;
                        subcomponent = 1;
                        type         = segment.getField(num, rep);
                    }
                    else if (c == ec.ComponentSeparator)
                    {
                        component++;
                        subcomponent = 1;
                    }
                    else if (c == ec.SubcomponentSeparator)
                    {
                        subcomponent++;
                    }
                    else
                    {
                        Primitive p = Terser.getPrimitive(type, component, subcomponent);
                        p.Value = token;
                    }
                }
            }
        }
Example #4
0
        public static System.String encode(Segment source, NuGenEncodingCharacters encodingChars)
        {
            System.Text.StringBuilder result = new System.Text.StringBuilder();
            result.Append(source.getName());
            result.Append(encodingChars.FieldSeparator);

            //start at field 2 for MSH segment because field 1 is the field delimiter
            int startAt = 1;

            if (isDelimDefSegment(source.getName()))
            {
                startAt = 2;
            }

            //loop through fields; for every field delimit any repetitions and add field delimiter after ...
            int numFields = source.numFields();

            for (int i = startAt; i <= numFields; i++)
            {
                try
                {
                    Type[] reps = source.getField(i);
                    for (int j = 0; j < reps.Length; j++)
                    {
                        System.String fieldText = encode(reps[j], encodingChars);
                        //if this is MSH-2, then it shouldn't be escaped, so unescape it again
                        if (isDelimDefSegment(source.getName()) && i == 2)
                        {
                            fieldText = NuGenEscape.unescape(fieldText, encodingChars);
                        }
                        result.Append(fieldText);
                        if (j < reps.Length - 1)
                        {
                            result.Append(encodingChars.RepetitionSeparator);
                        }
                    }
                }
                catch (NuGenHL7Exception)
                {
                }
                result.Append(encodingChars.FieldSeparator);
            }

            //strip trailing delimiters ...
            return(stripExtraDelimiters(result.ToString(), encodingChars.FieldSeparator));
        }
Example #5
0
        /// <summary> Populates the given error segment with information from this Exception.</summary>
        public virtual void  populate(Segment errorSegment)
        {
            //make sure it's an ERR
            if (!errorSegment.getName().Equals("ERR"))
            {
                throw new NuGenHL7Exception("Can only populate an ERR segment with an exception -- got: " + errorSegment.GetType().FullName);
            }

            int rep = errorSegment.getField(1).Length;             //append after existing reps

            if (this.SegmentName != null)
            {
                Terser.set_Renamed(errorSegment, 1, rep, 1, 1, this.SegmentName);
            }

            if (this.SegmentRepetition >= 0)
            {
                Terser.set_Renamed(errorSegment, 1, rep, 2, 1, System.Convert.ToString(this.SegmentRepetition));
            }

            if (this.FieldPosition >= 0)
            {
                Terser.set_Renamed(errorSegment, 1, rep, 3, 1, System.Convert.ToString(this.FieldPosition));
            }

            Terser.set_Renamed(errorSegment, 1, rep, 4, 1, System.Convert.ToString(this.errCode));
            Terser.set_Renamed(errorSegment, 1, rep, 4, 3, "hl70357");
            Terser.set_Renamed(errorSegment, 1, rep, 4, 5, this.Message);

            //try to get error condition text
            try
            {
                System.String desc = NuGenTableRepository.Instance.getDescription(357, System.Convert.ToString(this.errCode));
                Terser.set_Renamed(errorSegment, 1, rep, 4, 2, desc);
            }
            catch (NuGenLookupException)
            {
            }
        }
		public static System.String encode(Segment source, NuGenEncodingCharacters encodingChars)
		{
			System.Text.StringBuilder result = new System.Text.StringBuilder();
			result.Append(source.getName());
			result.Append(encodingChars.FieldSeparator);
			
			//start at field 2 for MSH segment because field 1 is the field delimiter
			int startAt = 1;
			if (isDelimDefSegment(source.getName()))
				startAt = 2;
			
			//loop through fields; for every field delimit any repetitions and add field delimiter after ...
			int numFields = source.numFields();
			for (int i = startAt; i <= numFields; i++)
			{
				try
				{
					Type[] reps = source.getField(i);
					for (int j = 0; j < reps.Length; j++)
					{
						System.String fieldText = encode(reps[j], encodingChars);
						//if this is MSH-2, then it shouldn't be escaped, so unescape it again
						if (isDelimDefSegment(source.getName()) && i == 2)
							fieldText = NuGenEscape.unescape(fieldText, encodingChars);
						result.Append(fieldText);
						if (j < reps.Length - 1)
							result.Append(encodingChars.RepetitionSeparator);
					}
				}
				catch (NuGenHL7Exception)
				{
				}
				result.Append(encodingChars.FieldSeparator);
			}
			
			//strip trailing delimiters ...
			return stripExtraDelimiters(result.ToString(), encodingChars.FieldSeparator);
		}
		/// <summary> Parses a segment string and populates the given Segment object.  Unexpected fields are
		/// added as Varies' at the end of the segment.  
		/// 
		/// </summary>
		/// <throws>  HL7Exception if the given string does not contain the </throws>
		/// <summary>      given segment or if the string is not encoded properly
		/// </summary>
		public virtual void  parse(Segment destination, System.String segment, NuGenEncodingCharacters encodingChars)
		{
			int fieldOffset = 0;
			if (isDelimDefSegment(destination.getName()))
			{
				fieldOffset = 1;
				//set field 1 to fourth character of string
				Terser.set_Renamed(destination, 1, 0, 1, 1, System.Convert.ToString(encodingChars.FieldSeparator));
			}
			
			System.String[] fields = split(segment, System.Convert.ToString(encodingChars.FieldSeparator));
			//destination.setName(fields[0]);
			for (int i = 1; i < fields.Length; i++)
			{
				System.String[] reps = split(fields[i], System.Convert.ToString(encodingChars.RepetitionSeparator));
				
				//MSH-2 will get split incorrectly so we have to fudge it ...
				bool isMSH2 = isDelimDefSegment(destination.getName()) && i + fieldOffset == 2;
				if (isMSH2)
				{
					reps = new System.String[1];
					reps[0] = fields[i];
				}
				
				for (int j = 0; j < reps.Length; j++)
				{
					try
					{
						System.Text.StringBuilder statusMessage = new System.Text.StringBuilder("Parsing field ");
						statusMessage.Append(i + fieldOffset);
						statusMessage.Append(" repetition ");
						statusMessage.Append(j);
						//parse(destination.getField(i + fieldOffset, j), reps[j], encodingChars, false);
						
						Type field = destination.getField(i + fieldOffset, j);
						if (isMSH2)
						{
							Terser.getPrimitive(field, 1, 1).Value = reps[j];
						}
						else
						{
							parse(field, reps[j], encodingChars);
						}
					}
					catch (NuGenHL7Exception e)
					{
						//set the field location and throw again ...
						e.FieldPosition = i;
						e.SegmentRepetition = MessageIterator.getIndex(destination.Parent, destination).rep;
						e.SegmentName = destination.getName();
						throw e;
					}
				}
			}
			
			//set data type of OBX-5
			if (destination.GetType().FullName.IndexOf("OBX") >= 0)
			{
				Varies.fixOBX5(destination, Factory);
			}
		}
Example #8
0
        /// <summary> Parses a segment string and populates the given Segment object.  Unexpected fields are
        /// added as Varies' at the end of the segment.
        ///
        /// </summary>
        /// <throws>  HL7Exception if the given string does not contain the </throws>
        /// <summary>      given segment or if the string is not encoded properly
        /// </summary>
        public virtual void  parse(Segment destination, System.String segment, NuGenEncodingCharacters encodingChars)
        {
            int fieldOffset = 0;

            if (isDelimDefSegment(destination.getName()))
            {
                fieldOffset = 1;
                //set field 1 to fourth character of string
                Terser.set_Renamed(destination, 1, 0, 1, 1, System.Convert.ToString(encodingChars.FieldSeparator));
            }

            System.String[] fields = split(segment, System.Convert.ToString(encodingChars.FieldSeparator));
            //destination.setName(fields[0]);
            for (int i = 1; i < fields.Length; i++)
            {
                System.String[] reps = split(fields[i], System.Convert.ToString(encodingChars.RepetitionSeparator));

                //MSH-2 will get split incorrectly so we have to fudge it ...
                bool isMSH2 = isDelimDefSegment(destination.getName()) && i + fieldOffset == 2;
                if (isMSH2)
                {
                    reps    = new System.String[1];
                    reps[0] = fields[i];
                }

                for (int j = 0; j < reps.Length; j++)
                {
                    try
                    {
                        System.Text.StringBuilder statusMessage = new System.Text.StringBuilder("Parsing field ");
                        statusMessage.Append(i + fieldOffset);
                        statusMessage.Append(" repetition ");
                        statusMessage.Append(j);
                        //parse(destination.getField(i + fieldOffset, j), reps[j], encodingChars, false);

                        Type field = destination.getField(i + fieldOffset, j);
                        if (isMSH2)
                        {
                            Terser.getPrimitive(field, 1, 1).Value = reps[j];
                        }
                        else
                        {
                            parse(field, reps[j], encodingChars);
                        }
                    }
                    catch (NuGenHL7Exception e)
                    {
                        //set the field location and throw again ...
                        e.FieldPosition     = i;
                        e.SegmentRepetition = MessageIterator.getIndex(destination.Parent, destination).rep;
                        e.SegmentName       = destination.getName();
                        throw e;
                    }
                }
            }

            //set data type of OBX-5
            if (destination.GetType().FullName.IndexOf("OBX") >= 0)
            {
                Varies.fixOBX5(destination, Factory);
            }
        }
		/// <summary> Populates the given error segment with information from this Exception.</summary>
		public virtual void  populate(Segment errorSegment)
		{
			//make sure it's an ERR
			if (!errorSegment.getName().Equals("ERR"))
				throw new NuGenHL7Exception("Can only populate an ERR segment with an exception -- got: " + errorSegment.GetType().FullName);
			
			int rep = errorSegment.getField(1).Length; //append after existing reps
			
			if (this.SegmentName != null)
				Terser.set_Renamed(errorSegment, 1, rep, 1, 1, this.SegmentName);
			
			if (this.SegmentRepetition >= 0)
				Terser.set_Renamed(errorSegment, 1, rep, 2, 1, System.Convert.ToString(this.SegmentRepetition));
			
			if (this.FieldPosition >= 0)
				Terser.set_Renamed(errorSegment, 1, rep, 3, 1, System.Convert.ToString(this.FieldPosition));
			
			Terser.set_Renamed(errorSegment, 1, rep, 4, 1, System.Convert.ToString(this.errCode));
			Terser.set_Renamed(errorSegment, 1, rep, 4, 3, "hl70357");
			Terser.set_Renamed(errorSegment, 1, rep, 4, 5, this.Message);
			
			//try to get error condition text
			try
			{
				System.String desc = NuGenTableRepository.Instance.getDescription(357, System.Convert.ToString(this.errCode));
				Terser.set_Renamed(errorSegment, 1, rep, 4, 2, desc);
			}
			catch (NuGenLookupException)
			{

			}
		}
		private void  parse(System.String field, Segment segment, int num, NuGenEncodingCharacters ec)
		{
			if (field != null)
			{
				int rep = 0;
				int component = 1;
				int subcomponent = 1;
				Type type = segment.getField(num, rep);
				
				System.String delim = System.Convert.ToString(new char[]{ec.RepetitionSeparator, ec.ComponentSeparator, ec.SubcomponentSeparator});
				for (SupportClass.Tokenizer tok = new SupportClass.Tokenizer(field, delim, true); tok.HasMoreTokens(); )
				{
					System.String token = tok.NextToken();
					char c = token[0];
					if (c == ec.RepetitionSeparator)
					{
						rep++;
						component = 1;
						subcomponent = 1;
						type = segment.getField(num, rep);
					}
					else if (c == ec.ComponentSeparator)
					{
						component++;
						subcomponent = 1;
					}
					else if (c == ec.SubcomponentSeparator)
					{
						subcomponent++;
					}
					else
					{
						Primitive p = Terser.getPrimitive(type, component, subcomponent);
						p.Value = token;
					}
				}
			}
		}
Example #11
0
		/// <summary> Populates the given Element with data from the given Segment, by inserting
		/// Elements corresponding to the Segment's fields, their components, etc.  Returns 
		/// true if there is at least one data value in the segment.   
		/// </summary>
		public virtual bool encode(Segment segmentObject, System.Xml.XmlElement segmentElement)
		{
			bool hasValue = false;
			int n = segmentObject.numFields();
			for (int i = 1; i <= n; i++)
			{
				System.String name = makeElementName(segmentObject, i);
				Type[] reps = segmentObject.getField(i);
				for (int j = 0; j < reps.Length; j++)
				{
					System.Xml.XmlElement newNode = segmentElement.OwnerDocument.CreateElement(name);
					bool componentHasValue = encode(reps[j], newNode);
					if (componentHasValue)
					{
						try
						{
							segmentElement.AppendChild(newNode);
						}
						catch (System.Exception e)
						{
							throw new NuGenHL7Exception("DOMException encoding Segment: ", NuGenHL7Exception.APPLICATION_INTERNAL_ERROR, e);
						}
						hasValue = true;
					}
				}
			}
			return hasValue;
		}
Example #12
0
		private void  parseReps(Segment segmentObject, System.Xml.XmlElement segmentElement, System.String fieldName, int fieldNum)
		{
			
			System.Xml.XmlNodeList reps = segmentElement.GetElementsByTagName(fieldName);
			for (int i = 0; i < reps.Count; i++)
			{
				parse(segmentObject.getField(fieldNum, i), (System.Xml.XmlElement) reps.Item(i));
			}
		}