예제 #1
0
파일: Main.cs 프로젝트: HL7/ehrsfm-tool
        private void batch(EA.Repository Repository)
        {
            Dictionary <string, EA.Package> content = new Dictionary <string, EA.Package>();
            string   xml                 = Repository.SQLQuery("SELECT Name, ea_guid FROM t_object WHERE Object_Type = 'Package'"); // order by package_id
            XElement xEADATA             = XElement.Parse(xml, LoadOptions.None);
            IEnumerable <XElement> xRows = xEADATA.XPathSelectElements("//Data/Row");

            foreach (XElement xRow in xRows)
            {
                string ea_guid = xRow.Element("ea_guid").Value;
                string name    = xRow.Element("Name").Value;
                content[name] = Repository.GetPackageByGuid(ea_guid);
            }
            BatchForm form = new BatchForm();

            form.setContent(content);
            form.ShowDialog();

            if (form.isExportButtonPressed())
            {
                Repository.CreateOutputTab(MAX_TABNAME);
                Repository.ClearOutput(MAX_TABNAME);
                bool issues = false;
                foreach (string name in form.getSelectedItems())
                {
                    EA.Package package = content[name];
                    issues |= new Filters().exportPackage(Repository, package);
                }
                if (issues)
                {
                    // only popup when there were any issues
                    Repository.EnsureOutputVisible(MAX_TABNAME);
                }
            }
        }
예제 #2
0
 public void enable(EA.Repository r)
 {
     this.toggle     = true;
     this.repository = r;
     if (this.toggle)
     {
         repository.CreateOutputTab("IAG");
         repository.EnsureOutputVisible("IAG");
         repository.ClearOutput("IAG");
         log("Logger is enabled");
         string version = System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString();
         log("APIAddIn version " + version);
     }
 }
예제 #3
0
        public static void SynchronizePackageWithJIRA(EA.Repository Repository, EA.Package Package, PackageConnectionSettingsViewModel PackageConnectionSettings, JiraConnection JiraConnection)
        {
            //Steps:
            //      1. User must be able to login to JIRA -- must ensure caller
            //      2. Creating Repository.Output -- well... am thinking about event, JTS so far
            //      3. Get the proper JQL -- i will get from parameter
            //      4. Do to job

            Repository.CreateOutputTab(EAGoatJira.JiraOutputWindowName);
            Repository.EnsureOutputVisible(EAGoatJira.JiraOutputWindowName);
            Repository.ClearOutput(EAGoatJira.JiraOutputWindowName);
            Repository.WriteOutput(EAGoatJira.JiraOutputWindowName, "Reading data...", 0);

            PackageConnectionSettings.Refresh();

            Dictionary <string, EA.Element> IssuesInEA = ReadIssuesFromEA(Repository, Package.Elements);

            var issues = JiraConnection.GetJiraIssues(PackageConnectionSettings.Jql);

            foreach (var issue in issues)
            {
                EA.Element EAElementForIssue = SynchronizeItem(issue, Repository, Package, null, IssuesInEA);

                if (PackageConnectionSettings.PackageConnectionSettings.Type == PackageConnectionSettingsType.EpicsAndStories)
                {
                    var epicissues = JiraConnection.GetJiraIssues($"\"Epic Link\" = {issue.Key}");
                    foreach (var epicissue in epicissues)
                    {
                        SynchronizeItem(epicissue, Repository, Package, EAElementForIssue, IssuesInEA);
                    }
                }
                EAElementForIssue.Update();
            }

            if (IssuesInEA.Count > 0)
            { //some issues that are in the Package are not in the issues (they were deleted or moved or the Jql has chaned)
                EA.Package PackageForRemovedIssues = EAUtils.CreatePackage(Package, "Removed Issues", ForceCreation: false);
                foreach (var removedItem in IssuesInEA)
                {
                    Repository.WriteOutput(EAGoatJira.JiraOutputWindowName, $"Removing issue {removedItem.Key}", removedItem.Value.ElementID);
                    removedItem.Value.PackageID = PackageForRemovedIssues.PackageID;
                    removedItem.Value.Update();
                    EAUtils.WriteTaggedValue(removedItem.Value, EAGoatJira.TagValueNameOperation, "Issue was " + IssueOperation.Removed.ToString() + ".", WriteValueToNotes: false);
                }
                PackageForRemovedIssues.Update();
            }

            Package.Update();
            Repository.WriteOutput(EAGoatJira.JiraOutputWindowName, $"Done.", 0);
        }
예제 #4
0
        /**
         * Compile Profile will take a profile definition and create a profile based on that.
         * 1. Export profile definitions to MAX file (filename is in MAX::ExportFile) of ProfileDefinition Package
         * 2. Find Base Model MAX File (filename is in MAX::ImportFile) of <use> Dependency target from ProfileDefinition Package
         * 3. Compile profile to MAX File (filename is in MAX::ExportFile) of <create> Dependency target from ProfileDefinition Package
         * 4. (optionally) import the compiled profile
         */
        private void CompileProfile(EA.Repository repository, EA.Package package)
        {
            // Only on a "HL7-Profile-Definition" stereotypes package
            if (R2Const.ST_FM_PROFILEDEFINITION.Equals(package.StereotypeEx))
            {
                repository.CreateOutputTab(Properties.Resources.OUTPUT_TAB_HL7_FM);
                repository.ClearOutput(Properties.Resources.OUTPUT_TAB_HL7_FM);
                repository.EnsureOutputVisible(Properties.Resources.OUTPUT_TAB_HL7_FM);

                // !! Use tagged value "MAX:ExportFile" as fileNames!
                // Export it to MAX.
                EA.TaggedValue tvExportFile = (EA.TaggedValue)package.Element.TaggedValues.GetByName("MAX::ExportFile");
                if (tvExportFile == null)
                {
                    EAHelper.LogMessage(string.Format("[ERROR] MAX::ExportFile tag missing in Package \"{0}\"", package.Name), package.Element.ElementID);
                    MessageBox.Show(MESSAGE_PROFILE_DEFINITION, "Complete setup", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    return;
                }
                string profileDefinitionFileName = tvExportFile.Value;
                EAHelper.LogMessage(string.Format("[INFO] Profile Definition MAX file: {0}", profileDefinitionFileName));
                EAHelper.LogMessage("[BEGIN] Export Profile Definition to MAX file");
                new MAX_EA.MAXExporter3().exportPackage(repository, package, profileDefinitionFileName);
                EAHelper.LogMessage("[END] Export Profile Definition to MAX file");

                // Find associated Base
                EA.Package baseModelPackage = EAHelper.getAssociatedBaseModel(repository, package);
                if (baseModelPackage == null)
                {
                    MessageBox.Show(MESSAGE_PROFILE_DEFINITION, "Complete setup", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    return;
                }
                EAHelper.LogMessage(string.Format("[INFO] Base Model Package name: {0}", baseModelPackage.Name));
                EA.TaggedValue tvImportFile = (EA.TaggedValue)baseModelPackage.Element.TaggedValues.GetByName("MAX::ImportFile");
                if (tvImportFile == null)
                {
                    EAHelper.LogMessage(string.Format("[ERROR] MAX::ImportFile tag missing in Package \"{0}\"", baseModelPackage.Name));
                    MessageBox.Show(MESSAGE_PROFILE_DEFINITION, "Complete setup", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    return;
                }
                string baseModelFileName = tvImportFile.Value;
                EAHelper.LogMessage(string.Format("[INFO] Base Model MAX file: {0}", baseModelFileName));

                // Find associated Target Profile Package
                EA.Package compiledProfilePackage = EAHelper.getAssociatedOutputProfile(repository, package);
                if (compiledProfilePackage == null)
                {
                    MessageBox.Show(MESSAGE_PROFILE_DEFINITION, "Complete setup", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    return;
                }
                EAHelper.LogMessage(string.Format("[INFO] Compiled Profile Package name: {0}", compiledProfilePackage.Name));
                EA.TaggedValue tvExportFile2 = (EA.TaggedValue)compiledProfilePackage.Element.TaggedValues.GetByName("MAX::ExportFile");
                if (tvExportFile2 == null)
                {
                    EAHelper.LogMessage(string.Format("MAX::ExportFile tag missing in Package \"{0}\"", compiledProfilePackage.Name));
                    MessageBox.Show(MESSAGE_PROFILE_DEFINITION, "Complete setup", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    return;
                }
                string profileFileName = tvExportFile2.Value;

                // Call R2ProfileCompiler
                EAHelper.LogMessage(string.Format("[INFO] Compiled Profile MAX file: {0}", profileFileName));
                EAHelper.LogMessage("[BEGIN] Compile Profile");
                R2ProfileCompiler compiler = new R2ProfileCompiler();
                compiler._OutputListener = new EAOutputListener();
                compiler.Compile(baseModelFileName, profileDefinitionFileName, profileFileName);
                EAHelper.LogMessage("[END] Compile Profile");

                // Import compiled profile from MAX file
                //new MAX_EA.MAXImporter3().import(repository, profilePackage, profileFileName);
                MessageBox.Show("Manually import compiled profile now...", "Done", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            else
            {
                MessageBox.Show("Select a Profile Definition Package to Compile.");
            }
        }
예제 #5
0
        public void validate(EA.Repository repository, EA.Package rootPackage)
        {
            string sch_filepath = null;

            switch (rootPackage.StereotypeEx)
            {
            case R2Const.ST_FM:
                sch_filepath = Main.getAppDataFullPath(@"Schematron\EHRS_FM_R2-validation.sch");
                break;

            case R2Const.ST_FM_PROFILEDEFINITION:
                sch_filepath = Main.getAppDataFullPath(@"Schematron\EHRS_FM_R2_FPDEF-validation.sch");
                break;

            case R2Const.ST_FM_PROFILE:
                sch_filepath = Main.getAppDataFullPath(@"Schematron\EHRS_FM_R2_FP-validation.sch");
                break;

            default:
                MessageBox.Show(string.Format("Validation not available for {0}.\nChoose ", rootPackage.Name), "Choose other package", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                return;
            }

            repository.CreateOutputTab(Properties.Resources.OUTPUT_TAB_HL7_FM);
            repository.ClearOutput(Properties.Resources.OUTPUT_TAB_HL7_FM);
            repository.EnsureOutputVisible(Properties.Resources.OUTPUT_TAB_HL7_FM);

            // TODO: Change to memorybased!!
            // TODO: Transform once to XSL, only if the xsl is older or not existing

            // Create and load the transform with script execution enabled.
            XslCompiledTransform transform = new XslCompiledTransform();
            XsltSettings         settings  = new XsltSettings {
                EnableScript = true
            };
            XmlUrlResolver resolver = new XmlUrlResolver();

            // transform the Schematron to a XSL
            string iso_sch_xsl_filepath = Main.getAppDataFullPath(@"Schematron\iso-schematron-xslt1\iso_svrl_for_xslt1.xsl");

            transform.Load(iso_sch_xsl_filepath, settings, resolver);
            string sch_xsl_filepath = Main.getAppDataFullPath(@"Schematron\EHRS_FM_R2-validation.sch.xsl");

            transform.Transform(sch_filepath, sch_xsl_filepath);

            // export to temp MAX file
            string temp_max_file = Main.getAppDataFullPath(@"Schematron\__temp__.max");

            new MAX_EA.MAXExporter3().exportPackage(repository, rootPackage, temp_max_file);

            // now execute the Schematron XSL
            transform.Load(sch_xsl_filepath, settings, resolver);
            string svrl_filepath = Main.getAppDataFullPath(@"Schematron\svrl_output.xml");

            transform.Transform(temp_max_file, svrl_filepath);

            // build element dictionary
            Dictionary <string, EA.Element> eaElementDict = new Dictionary <string, EA.Element>();

            recurseEaPackage(rootPackage, eaElementDict);

            XmlReader xReader = XmlReader.Create(svrl_filepath);

            // make sure file gets closed
            using (xReader)
            {
                XElement            svrl  = XElement.Load(xReader);
                XmlNamespaceManager nsmgr = new XmlNamespaceManager(xReader.NameTable);
                nsmgr.AddNamespace("svrl", "http://purl.oclc.org/dsdl/svrl");

                appendSvrlMessagesToOutputTab(repository, svrl.XPathSelectElements("//svrl:successful-report", nsmgr), eaElementDict, nsmgr);
                appendSvrlMessagesToOutputTab(repository, svrl.XPathSelectElements("//svrl:failed-assert", nsmgr), eaElementDict, nsmgr);
            }
            MessageBox.Show("Validation done.\nCheck output tab for message and issues.", "Done", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);

            repository.EnsureOutputVisible(Properties.Resources.OUTPUT_TAB_HL7_FM);
        }
예제 #6
0
        public void import(EA.Repository Repository, EA.Package rootPackage)
        {
            Repository.EnableUIUpdates = false;
            Repository.BatchAppend     = true;

            Repository.CreateOutputTab(Properties.Resources.OUTPUT_TAB_HL7_FM);
            Repository.ClearOutput(Properties.Resources.OUTPUT_TAB_HL7_FM);
            Repository.EnsureOutputVisible(Properties.Resources.OUTPUT_TAB_HL7_FM);

            chapterColors["DC"] = 0x00ffff;
            chapterColors["S"]  = 0x00d7ff;
            chapterColors["IN"] = 0xffcc00;

            functions.Clear();
            functionCompSource.Clear();
            functionCompTarget.Clear();
            functionLinkSource.Clear();
            functionLinkTarget.Clear();
            functionSeeAlsoSource.Clear();
            functionSeeAlsoTarget.Clear();

            XmlDocument xmlDoc = new XmlDocument();

            xmlDoc.Load(@"D:\VisualStudio Projects\HL7\EHRSFM_EA_AddIn\EHRSFM\EHRS_FunctionalModel_Rel1.1.xml");

            EA.Package fmPackage = (EA.Package)rootPackage.Packages.AddNew("EHR-S FM R1.1", "Package");
            fmPackage.Alias       = xmlDoc.SelectSingleNode("/FunctionalModel/Name").InnerText;
            fmPackage.Version     = xmlDoc.SelectSingleNode("/FunctionalModel/Version").InnerText + " " + xmlDoc.SelectSingleNode("/FunctionalModel/Date").InnerText;
            fmPackage.IsNamespace = true;
            fmPackage.Update();
            fmPackage.Element.Locked = LOCK_ELEMENTS;

            XmlNodeList chapterList = xmlDoc.SelectNodes("/FunctionalModel/Chapter");

            foreach (XmlNode chapterNode in chapterList)
            {
                string     name           = chapterNode.SelectSingleNode("Name").InnerText;
                string     alias          = chapterNode.SelectSingleNode("Alias").InnerText;
                string     description    = chapterNode.SelectSingleNode("Description").InnerText;
                EA.Package chapterPackage = (EA.Package)fmPackage.Packages.AddNew(name, "Package");
                chapterPackage.Alias       = alias;
                chapterPackage.Notes       = description;
                chapterPackage.IsNamespace = true;
                chapterPackage.Update();
                if (chapterColors.ContainsKey(alias))
                {
                    chapterPackage.Element.SetAppearance(1 /*Base*/, 0 /*BGCOLOR*/, chapterColors[alias]);
                }
                chapterPackage.Element.Update();
                chapterPackage.Element.Locked = LOCK_ELEMENTS;

                XmlNodeList functionList = chapterNode.SelectNodes("Function");
                foreach (XmlNode functionNode in functionList)
                {
                    EA.Element functionElement = (EA.Element)chapterPackage.Elements.AddNew("", "Feature");
                    importFunctionOrHeader(functionElement, functionNode, Repository);
                    functionElement.Update();
                    functionElement.Locked = LOCK_ELEMENTS;
                }
            }

            for (int i = 0; i < functionSeeAlsoSource.Count; i++)
            {
                string sourceID = functionSeeAlsoSource[i];
                string targetID = functionSeeAlsoTarget[i];
                if (functions.ContainsKey(targetID))
                {
                    EA.Element   sourceElement = functions[sourceID];
                    EA.Element   targetElement = functions[targetID];
                    EA.Connector connector     = (EA.Connector)sourceElement.Connectors.AddNew("", "Association");
                    connector.Stereotype = "See Also";
                    connector.SupplierID = targetElement.ElementID;
                    connector.Update();
                }
                else
                {
                    EAHelper.LogMessage(string.Format("See Also from {0} to {1}, target not found.", sourceID, targetID));
                }
            }

            for (int i = 0; i < functionLinkSource.Count; i++)
            {
                string sourceID = functionLinkSource[i];
                string targetID = functionLinkTarget[i];
                if (functions.ContainsKey(targetID))
                {
                    EA.Element   sourceElement = functions[sourceID];
                    EA.Element   targetElement = functions[targetID];
                    EA.Connector connector     = (EA.Connector)sourceElement.Connectors.AddNew("", "Dependency");
                    connector.SupplierID = targetElement.ElementID;
                    connector.Update();
                }
                else
                {
                    EAHelper.LogMessage(string.Format("Function link from {0} to {1}, target not found.", sourceID, targetID));
                }
            }

            for (int i = 0; i < functionCompSource.Count; i++)
            {
                string sourceID = functionCompSource[i];
                string targetID = functionCompTarget[i];
                if (functions.ContainsKey(targetID))
                {
                    EA.Element   sourceElement = functions[sourceID];
                    EA.Element   targetElement = functions[targetID];
                    EA.Connector connector     = (EA.Connector)sourceElement.Connectors.AddNew("", "Aggregation");
                    connector.SupplierID = targetElement.ElementID;
                    connector.SupplierEnd.Aggregation = 2; // "composite"
                    connector.Update();
                }
                else
                {
                    EAHelper.LogMessage(string.Format("Function composition from {0} to {1}, target not found.", sourceID, targetID));
                }
            }

            Repository.EnableUIUpdates = true;
            Repository.BatchAppend     = false;

            Repository.RefreshModelView(fmPackage.PackageID);

            Repository.EnsureOutputVisible(Properties.Resources.OUTPUT_TAB_HL7_FM);
        }
예제 #7
0
 public void ClearOutput(string Name)
 {
     eaRepository.ClearOutput(Name);
 }
예제 #8
0
파일: Main.cs 프로젝트: HL7/ehrsfm-tool
        //Called when user makes a selection in the menu.
        //This is your main exit point to the rest of your Add-in
        public void EA_MenuClick(EA.Repository Repository, string Location, string MenuName, string ItemName)
        {
            try
            {
                EA.Package selectedPackage = Repository.GetTreeSelectedPackage();
                switch (ItemName)
                {
                case "Import":
                    Repository.CreateOutputTab(MAX_TABNAME);
                    Repository.ClearOutput(MAX_TABNAME);
                    if (new Filters().import(Repository, selectedPackage))
                    {
                        // only popup when there were any issues
                        Repository.EnsureOutputVisible(MAX_TABNAME);
                    }
                    break;

                case "Import NoDelRel":
                    Repository.CreateOutputTab(MAX_TABNAME);
                    Repository.ClearOutput(MAX_TABNAME);
                    if (new Filters().import(Repository, selectedPackage, false))
                    {
                        // only popup when there were any issues
                        Repository.EnsureOutputVisible(MAX_TABNAME);
                    }
                    break;

                case "Export":
                    Repository.CreateOutputTab(MAX_TABNAME);
                    Repository.ClearOutput(MAX_TABNAME);
                    if (new Filters().export(Repository))
                    {
                        // only popup when there were any issues
                        Repository.EnsureOutputVisible(MAX_TABNAME);
                    }
                    break;

                case "Filters":
                    // TODO: create Config Filters Dialogs
                    MessageBox.Show("NYI");
                    break;

                case "Transform":
                    Repository.CreateOutputTab(MAX_TABNAME);
                    Repository.ClearOutput(MAX_TABNAME);
                    if (new TransformParamsForm().Show(Repository))
                    {
                        // only popup when there were any issues
                        Repository.EnsureOutputVisible(MAX_TABNAME);
                    }
                    break;

                case "Validate":
                    Repository.CreateOutputTab(MAX_TABNAME);
                    Repository.ClearOutput(MAX_TABNAME);
                    if (new ValidateParamsForm().Show(Repository))
                    {
                        // only popup when there were any issues
                        Repository.EnsureOutputVisible(MAX_TABNAME);
                    }
                    break;

                case "Merge Diagrams":
                    mergeDiagrams(Repository, selectedPackage);
                    break;

                case "Lock":
                    setLocked(selectedPackage, true);
                    break;

                case "Unlock":
                    setLocked(selectedPackage, false);
                    break;

                case "Batch":
                    batch(Repository);
                    break;

                case "Quick Access Tab":
                    if (view_ctrl == null || !view_ctrl.Visible)
                    {
                        if (view_ctrl != null)
                        {
                            // if control removed dispose old instance
                            view_ctrl.Dispose();
                        }
                        view_ctrl = (QuickAccessControl)Repository.AddTab(MAX_TABNAME, "MAX_EA_Extension.QuickAccessControl");
                        view_ctrl.SetRepository(Repository);
                        Repository.ActivateTab(MAX_TABNAME);
                    }
                    break;

                case "About...":
                    AboutBox about = new AboutBox();
                    about.ShowDialog();
                    break;
                }
            }
            catch (Exception e)
            {
                MessageBox.Show(e.ToString());
            }
        }
예제 #9
0
        public void import(EA.Repository Repository, EA.Package rootPackage, string xmlFileName)
        {
            this.Repository            = Repository;
            Repository.EnableUIUpdates = false;
            Repository.BatchAppend     = true;

            Repository.CreateOutputTab(Properties.Resources.OUTPUT_TAB_HL7_FM);
            Repository.ClearOutput(Properties.Resources.OUTPUT_TAB_HL7_FM);
            Repository.EnsureOutputVisible(Properties.Resources.OUTPUT_TAB_HL7_FM);

            // Just make sure the lists,dictionaries are empty
            elements.Clear();
            compositions.Clear();
            consequenceLinks.Clear();

            // Read the XML
            XElement xModel = XElement.Load(xmlFileName);

            // setup progress window
            progress.Show();
            int functionCount = int.Parse(xModel.XPathEvaluate("count(//Function)").ToString());

            progress.setup(functionCount);

            // Create the main package
            string fmName = string.Format("{0} (imported)", getXElementValue(xModel, "Alias"));

            EA.Package fmPackage = (EA.Package)rootPackage.Packages.AddNew(fmName, "Package");
            fmPackage.Version     = getXElementValue(xModel, "Version") + " " + getXElementValue(xModel, "Date");
            fmPackage.Notes       = xModel.XPathSelectElement("Overview").CreateNavigator().InnerXml.Replace("<br />", "\r\n");
            fmPackage.IsNamespace = true;
            fmPackage.Update();
            fmPackage.Element.Stereotype = R2Const.ST_FM;
            fmPackage.Element.Author     = getXElementValue(xModel, "Author");
            fmPackage.Element.Phase      = getXElementValue(xModel, "Type");
            fmPackage.Element.Update();
            fmPackage.Element.Locked = LOCK_ELEMENTS;

            // Start with the chapters (section!) and iterate functions/headers and attach criteria
            foreach (XElement xChapter in xModel.Elements("Chapter"))
            {
                string name     = getXElementValue(xChapter, "Name");
                string ID       = getXElementValue(xChapter, "ID");
                string alias    = getXElementValue(xChapter, "Alias");
                string overview = getXElementValue(xChapter, "Overview");
                string example  = getXElementValue(xChapter, "Example");
                string actors   = getXElementValue(xChapter, "Actors");
                string notes    = string.Format("$OV${0}$EX${1}$AC${2}", overview, example, actors);

                EA.Package sectionPackage = (EA.Package)fmPackage.Packages.AddNew(name, "Package");
                sectionPackage.Notes       = notes;
                sectionPackage.IsNamespace = true;
                sectionPackage.TreePos     = int.Parse(ID);
                sectionPackage.Update();
                sectionPackage.Element.Alias      = alias;
                sectionPackage.Element.Stereotype = R2Const.ST_SECTION;
                R2Config.config.updateStyle(sectionPackage.Element);
                sectionPackage.Element.Update();
                sectionPackage.Element.Locked = LOCK_ELEMENTS;

                // Create TaggedValues for extra notes
                addTaggedValue(sectionPackage.Element, "ID", ID);

                int TPos = 0;
                foreach (XElement xFunction in xChapter.Elements("Function"))
                {
                    EA.Element functionElement;
                    string     parentID = getXElementValue(xFunction, "ParentID");
                    if (elements.ContainsKey(parentID))
                    {
                        EA.Element parentElement = elements[parentID];
                        functionElement = (EA.Element)parentElement.Elements.AddNew("", "Feature");
                    }
                    else // If the parent function doesnot exist; add to the sectionPackage; chapters are not in the functions dictionary
                    {
                        functionElement = (EA.Element)sectionPackage.Elements.AddNew("", "Feature");
                    }
                    string functionID = getXElementValue(xFunction, "ID");
                    addComposition(functionID, parentID);
                    importFunction(functionElement, xFunction);
                    functionElement.TreePos = TPos++; // Keep order from import file
                    functionElement.Update();
                    functionElement.Locked = LOCK_ELEMENTS;
                }
            }

            // Add ConsequenceLinks
            foreach (Link clink in consequenceLinks.Values)
            {
                if (elements.ContainsKey(clink.targetID))
                {
                    EA.Element   sourceElement = elements[clink.sourceID];
                    EA.Element   targetElement = elements[clink.targetID];
                    EA.Connector connector     = (EA.Connector)sourceElement.Connectors.AddNew("", "Dependency");
                    connector.Stereotype = R2Const.ST_CONSEQUENCELINK;
                    connector.Notes      = clink.notes;
                    connector.SupplierID = targetElement.ElementID;
                    connector.Update();
                }
                else
                {
                    EAHelper.LogMessage(string.Format("ConsequenceLink from {0} to {1}, target Function not found.", clink.sourceID, clink.targetID));
                }
            }

            // Add SeeAlso Links
            foreach (Link slink in seeAlsoLinks.Values)
            {
                if (elements.ContainsKey(slink.targetID))
                {
                    EA.Element   sourceElement = elements[slink.sourceID];
                    EA.Element   targetElement = elements[slink.targetID];
                    EA.Connector connector     = (EA.Connector)sourceElement.Connectors.AddNew("", "Dependency");
                    connector.Stereotype = R2Const.ST_SEEALSO;
                    connector.SupplierID = targetElement.ElementID;
                    connector.Update();
                }
                else
                {
                    EAHelper.LogMessage(string.Format("SeeAlso link from {0} to {1}, target Function not found.", slink.sourceID, slink.targetID));
                }
            }

            // Add compositions
            foreach (Link composition in compositions.Values)
            {
                if (elements.ContainsKey(composition.targetID))
                {
                    EA.Element   sourceElement = elements[composition.sourceID];
                    EA.Element   targetElement = elements[composition.targetID];
                    EA.Connector connector     = (EA.Connector)sourceElement.Connectors.AddNew("", "Aggregation");
                    connector.SupplierID = targetElement.ElementID;
                    connector.SupplierEnd.Aggregation = 2; // "composite"
                    connector.Update();
                }
                else
                {
                    // If the target is the section package then ignore the link
                    int?sectionColor = R2Config.config.getSectionColorInt(composition.targetID);
                    if (sectionColor == null)
                    {
                        EAHelper.LogMessage(string.Format("Function composition from {0} to {1}, target not found.", composition.sourceID, composition.targetID));
                    }
                }
            }
            progress.Close();

            Repository.EnableUIUpdates = true;
            Repository.BatchAppend     = false;
            Repository.RefreshModelView(fmPackage.PackageID);
            Repository.EnsureOutputVisible(Properties.Resources.OUTPUT_TAB_HL7_FM);
        }