Пример #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(IType destinationField, String data, EncodingCharacters encodingCharacters)
        {
            String[] components = Split(data, Convert.ToString(encodingCharacters.ComponentSeparator));
            for (int i = 0; i < components.Length; i++)
            {
                int index = i + 1;

                if (components[i] != null && (Terser.isPrimitive(destinationField, index) &&
                                              components[i].Contains(Convert.ToString(encodingCharacters.SubcomponentSeparator))))
                {   // sometimes someone sends us bad data and if the destinition is a primitive we should escape what needs to be escaped
                    components[i] = Escape.escape(components[i], encodingCharacters);
                }

                String[] subcomponents = Split(components[i], Convert.ToString(encodingCharacters.SubcomponentSeparator));
                for (int j = 0; j < subcomponents.Length; j++)
                {
                    String val = subcomponents[j];
                    if (val != null)
                    {
                        val = Escape.unescape(val, encodingCharacters);
                    }
                    Terser.getPrimitive(destinationField, index, j + 1).Value = val;
                }
            }
        }
Пример #2
0
        private static string EncodePrimitive(IPrimitive p, EncodingCharacters encodingChars)
        {
            var val = p.Value == null
                ? string.Empty
                : Escape.EscapeText(p.Value, encodingChars);

            return(val);
        }
Пример #3
0
 private static System.String EncodePrimitive(IPrimitive p, EncodingCharacters encodingChars)
 {
     System.String val = ((IPrimitive)p).Value;
     if (val == null)
     {
         val = "";
     }
     else
     {
         val = Escape.escape(val, encodingChars);
     }
     return(val);
 }
Пример #4
0
        /// <summary>
        /// Formats a <see cref="IMessage"/> object into an HL7 message string using the given encoding.
        /// </summary>
        /// <param name="source">An <see cref="IMessage"/> object from which to construct an encoded message string.</param>
        /// <param name="encodingChars">Encoding characters to be used.</param>
        /// <returns>The encoded message.</returns>
        /// <exception cref="HL7Exception">Thrown if the data fields in the message do not permit encoding (e.g. required fields are null).</exception>
        /// <exception cref="EncodingNotSupportedException">Thrown if the requested encoding is not supported by this parser.</exception>
        public static string Encode(ISegment source, EncodingCharacters encodingChars)
        {
            var result = new StringBuilder();

            result.Append(source.GetStructureName());
            result.Append(encodingChars.FieldSeparator);

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

            if (IsDelimDefSegment(source.GetStructureName()))
            {
                startAt = 2;
            }

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

            for (var i = startAt; i <= numFields; i++)
            {
                try
                {
                    var reps = source.GetField(i);
                    for (var j = 0; j < reps.Length; j++)
                    {
                        var fieldText = Encode(reps[j], encodingChars);

                        // if this is MSH-2, then it shouldn't be escaped, so un-escape it again
                        if (IsDelimDefSegment(source.GetStructureName()) && i == 2)
                        {
                            fieldText = Escape.UnescapeText(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));
        }
Пример #5
0
        private static string EncodePrimitive(IPrimitive p, EncodingCharacters encodingChars)
        {
            var val = ((IPrimitive)p).Value;

            if (val == null)
            {
                val = string.Empty;
            }
            else
            {
                val = Escape.EscapeText(val, encodingChars);
            }

            return(val);
        }
Пример #6
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(IType 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;
         }
     }
 }
Пример #7
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(IType destinationField, string data, EncodingCharacters encodingCharacters)
        {
            var components = Split(data, Convert.ToString(encodingCharacters.ComponentSeparator));

            for (var i = 0; i < components.Length; i++)
            {
                var subcomponents = Split(components[i], Convert.ToString(encodingCharacters.SubcomponentSeparator));
                for (var j = 0; j < subcomponents.Length; j++)
                {
                    var val = subcomponents[j];
                    if (val != null)
                    {
                        val = Escape.UnescapeText(val, encodingCharacters);
                    }

                    Terser.GetPrimitive(destinationField, i + 1, j + 1).Value = val;
                }
            }
        }