Exemple #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, NuGenEncodingCharacters 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 = NuGenEscape.unescape(val, encodingCharacters);
             }
             Terser.getPrimitive(destinationField, i + 1, j + 1).Value = val;
         }
     }
 }
Exemple #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, NuGenEncodingCharacters 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);
 }
Exemple #3
0
        /// <summary> Tests table values for ID, IS, and CE types.  An empty list is returned for
        /// all other types or if the table name or number is missing.
        /// </summary>
        private NuGenHL7Exception[] testTypeAgainstTable(Genetibase.NuGenHL7.model.Type type, AbstractComponent profile, System.String profileID)
        {
            System.Collections.ArrayList exList = new System.Collections.ArrayList();
            if (profile.Table != null && type.Name.Equals("IS") || type.Name.Equals("ID"))
            {
                System.String codeSystem    = makeTableName(profile.Table);
                System.String value_Renamed = ((Primitive)type).Value;
                addTableTestResult(exList, profileID, codeSystem, value_Renamed);
            }
            else if (type.Name.Equals("CE"))
            {
                System.String value_Renamed = Terser.getPrimitive(type, 1, 1).Value;
                System.String codeSystem    = Terser.getPrimitive(type, 3, 1).Value;
                addTableTestResult(exList, profileID, codeSystem, value_Renamed);

                value_Renamed = Terser.getPrimitive(type, 4, 1).Value;
                codeSystem    = Terser.getPrimitive(type, 6, 1).Value;
                addTableTestResult(exList, profileID, codeSystem, value_Renamed);
            }
            return(this.toArray(exList));
        }
Exemple #4
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;
                    }
                }
            }
        }
Exemple #5
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);
            }
        }