Beispiel #1
0
        public static System.String encode(Segment source, EncodingCharacters encodingChars)
        {
            System.Text.StringBuilder result = new System.Text.StringBuilder();
            result.Append(source.getStructureName());
            result.Append(encodingChars.FieldSeparator);

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

            if (isDelimDefSegment(source.getStructureName()))
            {
                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.getStructureName()) && i == 2)
                        {
                            fieldText = Escape.unescape(fieldText, encodingChars);
                        }
                        result.Append(fieldText);
                        if (j < reps.Length - 1)
                        {
                            result.Append(encodingChars.RepetitionSeparator);
                        }
                    }
                }
                catch (HL7Exception e)
                {
                    log.error("Error while encoding segment: ", e);
                }
                result.Append(encodingChars.FieldSeparator);
            }

            //strip trailing delimiters ...
            return(stripExtraDelimiters(result.ToString(), encodingChars.FieldSeparator));
        }
Beispiel #2
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.getStructureName().Equals("ERR"))
            {
                throw new HL7Exception("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(errorSegment, 1, rep, 1, 1, this.SegmentName);
            }

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

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

            Terser.Set(errorSegment, 1, rep, 4, 1, System.Convert.ToString(this.errCode));
            Terser.Set(errorSegment, 1, rep, 4, 3, "hl70357");
            //UPGRADE_TODO: The equivalent in .NET for method 'java.lang.Throwable.getMessage' may return a different value. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1043'"
            Terser.Set(errorSegment, 1, rep, 4, 5, this.Message);

            //try to get error condition text
            try
            {
                System.String desc = TableRepository.Instance.getDescription(357, System.Convert.ToString(this.errCode));
                Terser.Set(errorSegment, 1, rep, 4, 2, desc);
            }
            catch (LookupException e)
            {
                ourLog.debug("Warning: LookupException getting error condition text (are we connected to a TableRepository?)", e);
            }
        }
Beispiel #3
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)
        {
            //UPGRADE_TODO: Class 'java.util.HashSet' was converted to 'SupportClass.HashSetSupport' which has a different behavior. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1073_javautilHashSet'"
            SupportClass.HashSetSupport done = new SupportClass.HashSetSupport();

            //        for (int i = 1; i <= segmentObject.numFields(); i++) {
            //            String elementName = makeElementName(segmentObject, i);
            //            done.add(elementName);
            //            parseReps(segmentObject, segmentElement, elementName, i);
            //        }

            //UPGRADE_TODO: Method 'org.w3c.dom.Node.getChildNodes' was converted to 'System.Xml.XmlNode.ChildNodes' which has a different behavior. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1073'"
            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
                    {
                        log.debug("Child of segment " + segmentObject.getStructureName() + " doesn't look like a field: " + elementName);
                    }
                }
            }

            //set data type of OBX-5
            if (segmentObject.GetType().FullName.IndexOf("OBX") >= 0)
            {
                Varies.fixOBX5(segmentObject, Factory);
            }
        }
Beispiel #4
0
        /// <summary> Returns the expected XML element name for the given child of a message constituent
        /// of the given class (the class should be a Composite or Segment class).
        /// </summary>

        /*private String makeElementName(Class c, int child) {
         * String longClassName = c.getName();
         * String shortClassName = longClassName.substring(longClassName.lastIndexOf('.') + 1, longClassName.length());
         * if (shortClassName.startsWith("Valid")) {
         * shortClassName = shortClassName.substring(5, shortClassName.length());
         * }
         * return shortClassName + "." + child;
         * }*/

        /// <summary>Returns the expected XML element name for the given child of the given Segment </summary>
        private System.String makeElementName(Segment s, int child)
        {
            return(s.getStructureName() + "." + child);
        }
        protected virtual void encode(Segment source, EncodingCharacters encodingChars, Table tbl)
        {
            TableRow tr;
            TableCell td;
            tr = new TableRow();
            td = new TableCell();
            td.ColumnSpan = 3;
            if(_cssSegmentHeader!=null && _cssSegmentHeader.Trim().Length>0)
            {
                tr.CssClass=_cssSegmentHeader;
            }
            td.Text = source.getStructureName();
            tr.Cells.Add(td);
            tbl.Rows.Add(tr);

            //start at field 2 for MSH segment because field 1 is the field delimiter
            int startAt = 1;
            if (isDelimDefSegment(source.getStructureName()))
                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
                {
                    tr = new TableRow();

                    td = new TableCell();
                    td.Text = i.ToString();
                    tr.Cells.Add(td);

                    Type[] reps = source.getField(i);
                    string description = source.getFieldDescription(i);
                    td = new TableCell();
                    if(_cssSegmentField!=null)
                        td.CssClass = _cssSegmentField;
                    if(description!=null && description.Trim().Length>0)
                        td.Text = description;
                    else
                        td.Text ="&nbsp;";

                    tr.Cells.Add(td);

                    td = new TableCell();
                    if(reps.Length==0)
                        td.Text = "&nbsp;";
                    else
                    {
                        for (int j = 0; j < reps.Length; j++)
                        {
                            td.Controls.Add(encode(reps[j], encodingChars));
                            if(j<reps.Length-1)
                                td.Controls.Add(new LiteralControl("<hr size='2'>"));
                        }
                    }
                    tr.Cells.Add(td);
                    tbl.Rows.Add(tr);
                }
                catch (HL7Exception e)
                {
                    log.error("Error while encoding segment: ", e);
                }
            }
        }
Beispiel #6
0
 /// <summary> Returns the expected XML element name for the given child of a message constituent 
 /// of the given class (the class should be a Composite or Segment class). 
 /// </summary>
 /*private String makeElementName(Class c, int child) {
 String longClassName = c.getName();
 String shortClassName = longClassName.substring(longClassName.lastIndexOf('.') + 1, longClassName.length());
 if (shortClassName.startsWith("Valid")) {
 shortClassName = shortClassName.substring(5, shortClassName.length());
 }
 return shortClassName + "." + child;
 }*/
 /// <summary>Returns the expected XML element name for the given child of the given Segment </summary>
 private System.String makeElementName(Segment s, int child)
 {
     return s.getStructureName() + "." + child;
 }
Beispiel #7
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)
        {
            //UPGRADE_TODO: Class 'java.util.HashSet' was converted to 'SupportClass.HashSetSupport' which has a different behavior. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1073_javautilHashSet'"
            SupportClass.HashSetSupport done = new SupportClass.HashSetSupport();

            //        for (int i = 1; i <= segmentObject.numFields(); i++) {
            //            String elementName = makeElementName(segmentObject, i);
            //            done.add(elementName);
            //            parseReps(segmentObject, segmentElement, elementName, i);
            //        }

            //UPGRADE_TODO: Method 'org.w3c.dom.Node.getChildNodes' was converted to 'System.Xml.XmlNode.ChildNodes' which has a different behavior. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1073'"
            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
                    {
                        log.debug("Child of segment " + segmentObject.getStructureName() + " doesn't look like a field: " + elementName);
                    }
                }
            }

            //set data type of OBX-5
            if (segmentObject.GetType().FullName.IndexOf("OBX") >= 0)
            {
                Varies.fixOBX5(segmentObject, Factory);
            }
        }
Beispiel #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, EncodingCharacters encodingChars)
        {
            int fieldOffset = 0;
            if (isDelimDefSegment(destination.getStructureName()))
            {
                fieldOffset = 1;
                //set field 1 to fourth character of string
                Terser.Set(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));
                if (log.DebugEnabled)
                {
                    log.debug(reps.Length + "reps delimited by: " + encodingChars.RepetitionSeparator);
                }

                //MSH-2 will get split incorrectly so we have to fudge it ...
                bool isMSH2 = isDelimDefSegment(destination.getStructureName()) && 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);
                        log.debug(statusMessage.ToString());
                        //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 (HL7Exception e)
                    {
                        //set the field location and throw again ...
                        e.FieldPosition = i;
                        e.SegmentRepetition = MessageIterator.getIndex(destination.ParentGroup, destination).rep;
                        e.SegmentName = destination.getStructureName();
                        throw e;
                    }
                }
            }

            //set data type of OBX-5
            if (destination.GetType().FullName.IndexOf("OBX") >= 0)
            {
                Varies.fixOBX5(destination, Factory);
            }
        }
Beispiel #9
0
        public static System.String encode(Segment source, EncodingCharacters encodingChars)
        {
            System.Text.StringBuilder result = new System.Text.StringBuilder();
            result.Append(source.getStructureName());
            result.Append(encodingChars.FieldSeparator);

            //start at field 2 for MSH segment because field 1 is the field delimiter
            int startAt = 1;
            if (isDelimDefSegment(source.getStructureName()))
                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.getStructureName()) && i == 2)
                            fieldText = Escape.unescape(fieldText, encodingChars);
                        result.Append(fieldText);
                        if (j < reps.Length - 1)
                            result.Append(encodingChars.RepetitionSeparator);
                    }
                }
                catch (HL7Exception e)
                {
                    log.error("Error while encoding segment: ", e);
                }
                result.Append(encodingChars.FieldSeparator);
            }

            //strip trailing delimiters ...
            return stripExtraDelimiters(result.ToString(), encodingChars.FieldSeparator);
        }
Beispiel #10
0
        protected virtual void encode(Segment source, EncodingCharacters encodingChars, Table tbl)
        {
            TableRow  tr;
            TableCell td;

            tr            = new TableRow();
            td            = new TableCell();
            td.ColumnSpan = 3;
            if (_cssSegmentHeader != null && _cssSegmentHeader.Trim().Length > 0)
            {
                tr.CssClass = _cssSegmentHeader;
            }
            td.Text = source.getStructureName();
            tr.Cells.Add(td);
            tbl.Rows.Add(tr);


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

            if (isDelimDefSegment(source.getStructureName()))
            {
                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
                {
                    tr = new TableRow();

                    td      = new TableCell();
                    td.Text = i.ToString();
                    tr.Cells.Add(td);

                    Type[] reps        = source.getField(i);
                    string description = source.getFieldDescription(i);
                    td = new TableCell();
                    if (_cssSegmentField != null)
                    {
                        td.CssClass = _cssSegmentField;
                    }
                    if (description != null && description.Trim().Length > 0)
                    {
                        td.Text = description;
                    }
                    else
                    {
                        td.Text = "&nbsp;";
                    }

                    tr.Cells.Add(td);

                    td = new TableCell();
                    if (reps.Length == 0)
                    {
                        td.Text = "&nbsp;";
                    }
                    else
                    {
                        for (int j = 0; j < reps.Length; j++)
                        {
                            td.Controls.Add(encode(reps[j], encodingChars));
                            if (j < reps.Length - 1)
                            {
                                td.Controls.Add(new LiteralControl("<hr size='2'>"));
                            }
                        }
                    }
                    tr.Cells.Add(td);
                    tbl.Rows.Add(tr);
                }
                catch (HL7Exception e)
                {
                    log.error("Error while encoding segment: ", e);
                }
            }
        }
Beispiel #11
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.getStructureName().Equals("ERR"))
                throw new HL7Exception("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(errorSegment, 1, rep, 1, 1, this.SegmentName);

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

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

            Terser.Set(errorSegment, 1, rep, 4, 1, System.Convert.ToString(this.errCode));
            Terser.Set(errorSegment, 1, rep, 4, 3, "hl70357");
            //UPGRADE_TODO: The equivalent in .NET for method 'java.lang.Throwable.getMessage' may return a different value. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1043'"
            Terser.Set(errorSegment, 1, rep, 4, 5, this.Message);

            //try to get error condition text
            try
            {
                System.String desc = TableRepository.Instance.getDescription(357, System.Convert.ToString(this.errCode));
                Terser.Set(errorSegment, 1, rep, 4, 2, desc);
            }
            catch (LookupException e)
            {
                ourLog.debug("Warning: LookupException getting error condition text (are we connected to a TableRepository?)", e);
            }
        }
Beispiel #12
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, EncodingCharacters encodingChars)
        {
            int fieldOffset = 0;

            if (isDelimDefSegment(destination.getStructureName()))
            {
                fieldOffset = 1;
                //set field 1 to fourth character of string
                Terser.Set(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));
                if (log.DebugEnabled)
                {
                    log.debug(reps.Length + "reps delimited by: " + encodingChars.RepetitionSeparator);
                }

                //MSH-2 will get split incorrectly so we have to fudge it ...
                bool isMSH2 = isDelimDefSegment(destination.getStructureName()) && 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);
                        log.debug(statusMessage.ToString());
                        //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 (HL7Exception e)
                    {
                        //set the field location and throw again ...
                        e.FieldPosition     = i;
                        e.SegmentRepetition = MessageIterator.getIndex(destination.ParentGroup, destination).rep;
                        e.SegmentName       = destination.getStructureName();
                        throw e;
                    }
                }
            }

            //set data type of OBX-5
            if (destination.GetType().FullName.IndexOf("OBX") >= 0)
            {
                Varies.fixOBX5(destination, Factory);
            }
        }