Esempio n. 1
0
        /// <summary> Populates the given Segment object with data from the given XML Element.</summary>
        /// <throws>  HL7Exception if the XML Element does not have the correct name and structure </throws>
        /// <summary>      for the given Segment, or if there is an error while setting individual field values.
        /// </summary>
        public virtual void  parse(Segment segmentObject, System.Xml.XmlElement segmentElement)
        {
            SupportClass.HashSetSupport done = new SupportClass.HashSetSupport();

            System.Xml.XmlNodeList all = segmentElement.ChildNodes;
            for (int i = 0; i < all.Count; i++)
            {
                System.String elementName = all.Item(i).Name;
                if (System.Convert.ToInt16(all.Item(i).NodeType) == (short)System.Xml.XmlNodeType.Element && !done.Contains(elementName))
                {
                    done.Add(elementName);

                    int index = elementName.IndexOf('.');
                    if (index >= 0 && elementName.Length > index)
                    {
                        //properly formatted element
                        System.String fieldNumString = elementName.Substring(index + 1);
                        int           fieldNum       = System.Int32.Parse(fieldNumString);
                        parseReps(segmentObject, segmentElement, elementName, fieldNum);
                    }
                    else
                    {
                    }
                }
            }

            //set data type of OBX-5
            if (segmentObject.GetType().FullName.IndexOf("OBX") >= 0)
            {
                Varies.fixOBX5(segmentObject, Factory);
            }
        }
Esempio n. 2
0
        /// <summary> Encodes a Varies type by extracting it's data field and encoding that.  Returns true
        /// if the data field (or one of its components) contains a value.
        /// </summary>
        private bool encodeVaries(Varies datatypeObject, System.Xml.XmlElement datatypeElement)
        {
            bool hasData = false;

            if (datatypeObject.Data != null)
            {
                hasData = encode(datatypeObject.Data, datatypeElement);
            }
            return(hasData);
        }
Esempio n. 3
0
 /// <summary> Parses an XML element into a Varies by determining whether the element is primitive or
 /// composite, calling setData() on the Varies with a new generic primitive or composite as appropriate,
 /// and then calling parse again with the new Type object.
 /// </summary>
 private void  parseVaries(Varies datatypeObject, System.Xml.XmlElement datatypeElement)
 {
     //figure out what data type it holds
     //short nodeType = datatypeElement.getFirstChild().getNodeType();
     if (!hasChildElement(datatypeElement))
     {
         //it's a primitive
         datatypeObject.Data = new GenericPrimitive(datatypeObject.Message);
     }
     else
     {
         //it's a composite ... almost know what type, except that we don't have the version here
         datatypeObject.Data = new GenericComposite(datatypeObject.Message);
     }
     parse(datatypeObject.Data, datatypeElement);
 }
Esempio n. 4
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);
            }
        }
Esempio n. 5
0
		/// <summary> Encodes a Varies type by extracting it's data field and encoding that.  Returns true 
		/// if the data field (or one of its components) contains a value.  
		/// </summary>
		private bool encodeVaries(Varies datatypeObject, System.Xml.XmlElement datatypeElement)
		{
			bool hasData = false;
			if (datatypeObject.Data != null)
			{
				hasData = encode(datatypeObject.Data, datatypeElement);
			}
			return hasData;
		}
Esempio n. 6
0
		/// <summary> Parses an XML element into a Varies by determining whether the element is primitive or 
		/// composite, calling setData() on the Varies with a new generic primitive or composite as appropriate, 
		/// and then calling parse again with the new Type object.  
		/// </summary>
		private void  parseVaries(Varies datatypeObject, System.Xml.XmlElement datatypeElement)
		{
			//figure out what data type it holds 
			//short nodeType = datatypeElement.getFirstChild().getNodeType();        
			if (!hasChildElement(datatypeElement))
			{
				//it's a primitive 
				datatypeObject.Data = new GenericPrimitive(datatypeObject.Message);
			}
			else
			{
				//it's a composite ... almost know what type, except that we don't have the version here 
				datatypeObject.Data = new GenericComposite(datatypeObject.Message);
			}
			parse(datatypeObject.Data, datatypeElement);
		}