/// <summary> <p>Given a list of structures defining the deep content of a group (as provided in
        /// the normative database, some being pairs of optionality and repetition markers
        /// and segments nested within) returns a GroupDef including a short list of the shallow contents of the
        /// group (including segments and groups that are immediate children).</p>
        /// <p>For example given MSH [PID PV1] {[ERR NTE]}, short list would be something like
        /// MSH PID_GROUP ERR_GROUP (with PID_GROUP marked as optional and ERR_GROUP marked as
        /// optional and repeating).</p>
        /// <p>This method calls writeGroup(...) where necessary in order to create source code for
        /// any nested groups before returning corresponding GroupDefs.</p>
        /// </summary>
        public static GroupDef getGroupDef(StructureDef[] structures, System.String groupName, System.String baseDirectory, System.String version, System.String message)
        {
            GroupDef ret       = null;
            bool     required  = true;
            bool     repeating = false;
            bool     rep_opt   = false;

            int len = structures.Length;

            StructureDef[] shortList        = new StructureDef[len];      //place to put final list of groups/seg's w/o opt & rep markers
            int            currShortListPos = 0;
            int            currLongListPos  = 0;

            try
            {
                //check for rep and opt (see if start & end elements are [] or {} AND they are each others' pair) ...
                //System.out.println(len + " " + structures[0].getName() +structures[1].getName()+ ".." +structures[len-2].getName() + structures[len-1].getName()+ " " + message);
                if (optMarkers(structures[0].Name, structures[len - 1].Name) && (findGroupEnd(structures, 0) == len - 1))
                {
                    required = false;
                }
                if (repMarkers(structures[0].Name, structures[len - 1].Name) && (findGroupEnd(structures, 0) == len - 1))
                {
                    repeating = true;
                }
                if (repoptMarkers(structures[0].Name, structures[len - 1].Name) && (findGroupEnd(structures, 0) == len - 1))
                {
                    rep_opt = true;
                }
                if (repeating || !required)
                {
                    if (optMarkers(structures[1].Name, structures[len - 2].Name) && (findGroupEnd(structures, 1) == len - 2))
                    {
                        required = false;
                    }
                    if (repMarkers(structures[1].Name, structures[len - 2].Name) && (findGroupEnd(structures, 1) == len - 2))
                    {
                        repeating = true;
                    }
                }

                //loop through, recurse nested groups, and build short list of structures for this group
                int skip = 0;
                if (!required)
                {
                    skip++;
                }
                if (repeating)
                {
                    skip++;
                }
                if (rep_opt)
                {
                    skip++;
                }
                currLongListPos = skip;
                while (currLongListPos < len - skip)
                {
                    System.String currSegName = structures[currLongListPos].Name;
                    if (currSegName.Equals("[") || currSegName.Equals("{") || currSegName.Equals("[{"))
                    {
                        //this is the opening of a new group ...
                        System.String  name               = ((SegmentDef)structures[currLongListPos]).GroupName;
                        int            endOfNewGroup      = findGroupEnd(structures, currLongListPos);
                        StructureDef[] newGroupStructures = new StructureDef[endOfNewGroup - currLongListPos + 1];
                        Array.Copy(structures, currLongListPos, newGroupStructures, 0, newGroupStructures.Length);
                        shortList[currShortListPos] = writeGroup(newGroupStructures, name, baseDirectory, version, message);
                        currLongListPos             = endOfNewGroup + 1;
                    }
                    else
                    {
                        //copy verbatim into short list ...
                        shortList[currShortListPos] = structures[currLongListPos];
                        currLongListPos++;
                    }
                    currShortListPos++;
                }
            }
            catch (System.ArgumentException e)
            {
                //UPGRADE_TODO: The equivalent in .NET for method 'java.lang.Class.getName' may return a different value. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1043'"
                //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 HL7Exception("Problem creating nested group: " + e.GetType().FullName + ": " + e.Message, HL7Exception.APPLICATION_INTERNAL_ERROR);
            }

            ret = new GroupDef(message, groupName, required, repeating, "a Group object");
            StructureDef[] finalList = new StructureDef[currShortListPos];             //note: incremented after last assignment
            Array.Copy(shortList, 0, finalList, 0, currShortListPos);
            for (int i = 0; i < finalList.Length; i++)
            {
                ret.addStructure(finalList[i]);
            }

            return(ret);
        }
Beispiel #2
0
        /// <summary> <p>Given a list of structures defining the deep content of a group (as provided in 
        /// the normative database, some being pairs of optionality and repetition markers
        /// and segments nested within) returns a GroupDef including a short list of the shallow contents of the 
        /// group (including segments and groups that are immediate children).</p> 
        /// <p>For example given MSH [PID PV1] {[ERR NTE]}, short list would be something like 
        /// MSH PID_GROUP ERR_GROUP (with PID_GROUP marked as optional and ERR_GROUP marked as 
        /// optional and repeating).</p>
        /// <p>This method calls writeGroup(...) where necessary in order to create source code for 
        /// any nested groups before returning corresponding GroupDefs.</p>
        /// </summary>
        public static GroupDef getGroupDef(StructureDef[] structures, System.String groupName, System.String baseDirectory, System.String version, System.String message)
        {
            GroupDef ret = null;
            bool required = true;
            bool repeating = false;
            bool rep_opt = false;

            int len = structures.Length;
            StructureDef[] shortList = new StructureDef[len]; //place to put final list of groups/seg's w/o opt & rep markers
            int currShortListPos = 0;
            int currLongListPos = 0;

            try
            {
                //check for rep and opt (see if start & end elements are [] or {} AND they are each others' pair) ...
                //System.out.println(len + " " + structures[0].getName() +structures[1].getName()+ ".." +structures[len-2].getName() + structures[len-1].getName()+ " " + message);
                if (optMarkers(structures[0].Name, structures[len - 1].Name) && (findGroupEnd(structures, 0) == len - 1))
                    required = false;
                if (repMarkers(structures[0].Name, structures[len - 1].Name) && (findGroupEnd(structures, 0) == len - 1))
                    repeating = true;
                if (repoptMarkers(structures[0].Name, structures[len - 1].Name) && (findGroupEnd(structures, 0) == len - 1))
                    rep_opt = true;
                if (repeating || !required)
                {
                    if (optMarkers(structures[1].Name, structures[len - 2].Name) && (findGroupEnd(structures, 1) == len - 2))
                        required = false;
                    if (repMarkers(structures[1].Name, structures[len - 2].Name) && (findGroupEnd(structures, 1) == len - 2))
                        repeating = true;
                }

                //loop through, recurse nested groups, and build short list of structures for this group
                int skip = 0;
                if (!required)
                    skip++;
                if (repeating)
                    skip++;
                if (rep_opt)
                    skip++;
                currLongListPos = skip;
                while (currLongListPos < len - skip)
                {
                    System.String currSegName = structures[currLongListPos].Name;
                    if (currSegName.Equals("[") || currSegName.Equals("{") || currSegName.Equals("[{"))
                    {
                        //this is the opening of a new group ...
                        System.String name = ((SegmentDef) structures[currLongListPos]).GroupName;
                        int endOfNewGroup = findGroupEnd(structures, currLongListPos);
                        StructureDef[] newGroupStructures = new StructureDef[endOfNewGroup - currLongListPos + 1];
                        Array.Copy(structures, currLongListPos, newGroupStructures, 0, newGroupStructures.Length);
                        shortList[currShortListPos] = writeGroup(newGroupStructures, name, baseDirectory, version, message);
                        currLongListPos = endOfNewGroup + 1;
                    }
                    else
                    {
                        //copy verbatim into short list ...
                        shortList[currShortListPos] = structures[currLongListPos];
                        currLongListPos++;
                    }
                    currShortListPos++;
                }
            }
            catch (System.ArgumentException e)
            {
                //UPGRADE_TODO: The equivalent in .NET for method 'java.lang.Class.getName' may return a different value. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1043'"
                //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 HL7Exception("Problem creating nested group: " + e.GetType().FullName + ": " + e.Message, HL7Exception.APPLICATION_INTERNAL_ERROR);
            }

            ret = new GroupDef(message, groupName, required, repeating, "a Group object");
            StructureDef[] finalList = new StructureDef[currShortListPos]; //note: incremented after last assignment
            Array.Copy(shortList, 0, finalList, 0, currShortListPos);
            for (int i = 0; i < finalList.Length; i++)
            {
                ret.addStructure(finalList[i]);
            }

            return ret;
        }