コード例 #1
0
ファイル: Terser.cs プロジェクト: henriquetomaz/nhapi-1
        /// <summary> Returns the component (or sub-component, as the case may be) at the given
        /// index.  If it does not exist, it is added as an "extra component".
        /// If comp > 1 is requested from a Varies with GenericPrimitive data, the
        /// data is set to GenericComposite (this avoids the creation of a chain of
        /// ExtraComponents on GenericPrimitives).
        /// Components are numbered from 1.
        /// </summary>
        private static ca.uhn.hl7v2.model.Type getComponent(model.Type type, int comp)
        {
            model.Type ret = null;
            if (typeof(Varies).IsAssignableFrom(type.GetType()))
            {
                Varies v = (Varies)type;

                try
                {
                    if (comp > 1 && typeof(GenericPrimitive).IsAssignableFrom(v.Data.GetType()))
                    {
                        v.Data = new GenericComposite(v.Message);
                    }
                }
                catch (DataTypeException de)
                {
                    //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'"
                    System.String message = "Unexpected exception copying data to generic composite: " + de.Message;
                    log.error(message, de);
                    throw new System.ApplicationException(message);
                }

                ret = getComponent(v.Data, comp);
            }
            else
            {
                if (typeof(Primitive).IsAssignableFrom(type.GetType()) && comp == 1)
                {
                    ret = type;
                }
                else if (typeof(GenericComposite).IsAssignableFrom(type.GetType()) || (typeof(Composite).IsAssignableFrom(type.GetType()) && comp <= numStandardComponents(type)))
                {
                    //note that GenericComposite can return components > number of standard components

                    try
                    {
                        ret = ((Composite)type).getComponent(comp - 1);
                    }
                    catch (System.Exception e)
                    {
                        //TODO:  This may not be the write exception type:  Error() was originally thrown, but was not in project.
                        throw new ApplicationException("Internal error: HL7Exception thrown on getComponent(x) where x < # standard components.", e);
                    }
                }
                else
                {
                    ret = type.ExtraComponents.getComponent(comp - numStandardComponents(type) - 1);
                }
            }
            return(ret);
        }
コード例 #2
0
        /// <summary> Returns the index of the given structure as a child of the
        /// given parent.  Returns null if the child isn't found.
        /// </summary>
        public static Index getIndex(Group parent, Structure child)
        {
            Index index = null;

            System.String[] names = parent.Names;
            for (int i = 0; i < names.Length; i++)
            {
                if (names[i].StartsWith(child.getStructureName()))
                {
                    try
                    {
                        Structure[] reps = parent.getAll(names[i]);
                        for (int j = 0; j < reps.Length; j++)
                        {
                            if (child == reps[j])
                            {
                                index = new Index(names[i], j);
                                //UPGRADE_NOTE: Labeled break statement was changed to a goto statement. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1012'"
                                goto findChild_brk;
                            }
                        }
                    }
                    catch (HL7Exception e)
                    {
                        log.error("", e);
                        //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'"
                        throw new System.ApplicationException("Internal HL7Exception finding structure index: " + e.Message);
                    }
                }
            }
            //UPGRADE_NOTE: Label 'findChild_brk' was added. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1011'"

            findChild_brk :;

            return(index);
        }