コード例 #1
0
 /// <summary> Fills a field with values from an unparsed string representing the field.  </summary>
 /// <param name="destinationField">the field Type
 /// </param>
 /// <param name="data">the field string (including all components and subcomponents; not including field delimiters)
 /// </param>
 /// <param name="encodingCharacters">the encoding characters used in the message
 /// </param>
 private static void  parse(Type destinationField, System.String data, EncodingCharacters encodingCharacters)
 {
     System.String[] components = split(data, System.Convert.ToString(encodingCharacters.ComponentSeparator));
     for (int i = 0; i < components.Length; i++)
     {
         System.String[] subcomponents = split(components[i], System.Convert.ToString(encodingCharacters.SubcomponentSeparator));
         for (int j = 0; j < subcomponents.Length; j++)
         {
             System.String val = subcomponents[j];
             if (val != null)
             {
                 val = Escape.unescape(val, encodingCharacters);
             }
             Terser.getPrimitive(destinationField, i + 1, j + 1).Value = val;
         }
     }
 }
コード例 #2
0
 /// <summary> Encodes the given Type, using the given encoding characters.
 /// It is assumed that the Type represents a complete field rather than a component.
 /// </summary>
 public static System.String encode(Type source, EncodingCharacters encodingChars)
 {
     System.Text.StringBuilder field = new System.Text.StringBuilder();
     for (int i = 1; i <= Terser.numComponents(source); i++)
     {
         System.Text.StringBuilder comp = new System.Text.StringBuilder();
         for (int j = 1; j <= Terser.numSubComponents(source, i); j++)
         {
             Primitive p = Terser.getPrimitive(source, i, j);
             comp.Append(encodePrimitive(p, encodingChars));
             comp.Append(encodingChars.SubcomponentSeparator);
         }
         field.Append(stripExtraDelimiters(comp.ToString(), encodingChars.SubcomponentSeparator));
         field.Append(encodingChars.ComponentSeparator);
     }
     return(stripExtraDelimiters(field.ToString(), encodingChars.ComponentSeparator));
     //return encode(source, encodingChars, false);
 }
コード例 #3
0
        /// <summary> Encodes the given Type, using the given encoding characters.
        /// It is assumed that the Type represents a complete field rather than a component.
        /// </summary>
        protected virtual Control encode(Type source, EncodingCharacters encodingChars)
        {
            if (source is ca.uhn.hl7v2.model.Composite)
            {
                TableCell td;
                TableRow  tr;
                Table     tbl = new Table();
                tbl.Attributes["border"] = _componentBorder.ToString();
                tbl.CellSpacing          = _componentCellSpacing;
                tbl.CellPadding          = _componentCellPadding;
                for (int i = 1; i <= Terser.numComponents(source); i++)
                {
                    for (int j = 1; j <= Terser.numSubComponents(source, i); j++)
                    {
                        tr = new TableRow();
                        Primitive p    = Terser.getPrimitive(source, i, j);
                        Type      type = (Type)p;
                        td = new TableCell();
                        if (_cssComponentField != null)
                        {
                            td.CssClass = _cssComponentField;
                        }
                        string desc = "&nbsp;";
                        if (type.Description != null && type.Description.Trim().Length > 0)
                        {
                            desc = type.Description;
                        }
                        if (j > 1)
                        {
                            desc = "&nbsp;&nbsp;&nbsp;-" + desc;
                        }

                        td.Text = desc;
                        tr.Cells.Add(td);
                        string val = "&nbsp;";
                        if (p.Value != null && p.Value.Trim().Length > 0)
                        {
                            val = p.Value;
                            val = val.Replace(@"\.br\", "<BR>");
                        }
                        td      = new TableCell();
                        td.Text = val;
                        tr.Cells.Add(td);
                        tbl.Rows.Add(tr);
                    }
                }
                return(tbl);
            }
            else
            {
                Primitive p   = Terser.getPrimitive(source, 1, 1);
                string    val = "&nbsp;";

                if (p.Value != null && p.Value.Trim().Length > 0)
                {
                    val = p.Value;
                    val = val.Replace(@"\.br\", "<BR>");
                }
                return(new LiteralControl(val));
            }
        }
コード例 #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, 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);
            }
        }