コード例 #1
0
ファイル: R2ModelV2MAX.cs プロジェクト: HL7/ehrsfm-tool
            /**
             * Load a Profile Definition model from a MAX file.
             * The MAX file contains a HL7-ProfileDefinition.
             */
            public static Base.R2ProfileDefinition LoadProfileDefinition(Base.R2Model baseModel, string maxFileName)
            {
                XmlSerializer serializer = new XmlSerializer(typeof(ModelType));
                StreamReader  stream     = new StreamReader(maxFileName);
                ModelType     sourceModel;

                using (stream)
                {
                    sourceModel = (ModelType)serializer.Deserialize(stream);
                }
                ObjectType          profDefObj        = sourceModel.objects.Single(o => R2Const.ST_FM_PROFILEDEFINITION.Equals(o.stereotype));
                R2ProfileDefinition profileDefinition = new R2ProfileDefinition(profDefObj);

                foreach (ObjectType objectType in sourceModel.objects)
                {
                    R2ModelElement modelElement = Create(objectType);
                    if (modelElement != null && !(modelElement is R2RootElement))
                    {
                        profileDefinition.children.Add(modelElement);

                        // find Base Element if any
                        RelationshipType relType =
                            sourceModel.relationships.SingleOrDefault(r => modelElement.Id.Equals(r.sourceId));
                        if (relType != null)
                        {
                            string         destId           = relType.destId;
                            R2ModelElement baseModelElement =
                                baseModel.children.SingleOrDefault(e => destId.Equals(e.Id));
                            modelElement.BaseElement           = baseModelElement;
                            modelElement.IsCompilerInstruction = true;
                        }
                    }
                }
                return(profileDefinition);
            }
コード例 #2
0
ファイル: R2ModelV2MAX.cs プロジェクト: HL7/ehrsfm-tool
            /**
             * Load a HL7 Model from a MAX file.
             * The MAX file contains a HL7-FM or a HL7-Profile
             */
            public static Base.R2Model LoadModel(string maxFileName, bool ReadOnly)
            {
                XmlSerializer serializer = new XmlSerializer(typeof(ModelType));
                StreamReader  stream     = new StreamReader(maxFileName);
                ModelType     sourceModel;

                using (stream)
                {
                    sourceModel = (ModelType)serializer.Deserialize(stream);
                }

                ObjectType modelObjectType =
                    sourceModel.objects.Single(
                        o => R2Const.ST_FM.Equals(o.stereotype) || R2Const.ST_FM_PROFILE.Equals(o.stereotype));

                R2Model model = new R2Model(modelObjectType);

                model.IsReadOnly = ReadOnly;
                foreach (ObjectType objectType in sourceModel.objects)
                {
                    R2ModelElement modelElement = Create(objectType);
                    // modelElement can be null when it is a not supported object
                    if (modelElement != null && !(modelElement is R2RootElement))
                    {
                        modelElement.IsReadOnly = ReadOnly;
                        model.children.Add(modelElement);
                    }
                }
                return(model);
            }
コード例 #3
0
ファイル: R2ModelV2MAX.cs プロジェクト: HL7/ehrsfm-tool
            /*
             * Only make Compiler Instruction if there is a baseElement
             * otherwise this is a new element that was not in the base.
             */
            public static R2ModelElement CreateModelElement(R2ModelElement profileElement, R2ModelElement baseElement)
            {
                // only set in compiler instruction what is different that in base model element
                R2ModelElement element = null;

                if (profileElement is Base.R2Section)
                {
                    element = new R2Section();
                }
                else if (profileElement is Base.R2Function)
                {
                    element = new R2Function();
                }
                else if (profileElement is Base.R2Criterion)
                {
                    element = new R2Criterion();
                }
                element.BaseElement = baseElement;
                if (baseElement != null)
                {
                    element.Stereotype            = R2Const.ST_COMPILERINSTRUCTION;
                    element.IsCompilerInstruction = true;
                }
                element.LastModified = Util.FormatLastModified(DateTime.Now);
                element.Priority     = profileElement.Priority;
                element.Path         = profileElement.Path;
                if (profileElement is Base.R2Section)
                {
                    Base.R2Section profileSection = (Base.R2Section)profileElement;
                    R2Section      section        = (R2Section)element;
                    section.SectionId = profileSection.SectionId;
                    section.Name      = profileSection.Name;
                    section.Overview  = profileSection.Overview;
                    section.Example   = profileSection.Example;
                    section.Actors    = profileSection.Actors;
                }
                else if (profileElement is Base.R2Function)
                {
                    Base.R2Function profileFunction = (Base.R2Function)profileElement;
                    R2Function      function        = (R2Function)element;
                    function.FunctionId  = profileFunction.FunctionId;
                    function.Name        = profileFunction.Name;
                    function.Statement   = profileFunction.Statement;
                    function.Description = profileFunction.Description;
                }
                else if (profileElement is Base.R2Criterion)
                {
                    Base.R2Criterion profileCriterion = (Base.R2Criterion)profileElement;
                    R2Criterion      criterion        = (R2Criterion)element;
                    criterion.FunctionId     = profileCriterion.FunctionId;
                    criterion.CriterionSeqNo = profileCriterion.CriterionSeqNo;
                    criterion.Text           = profileCriterion.Text;
                    criterion.Row            = profileCriterion.Row;
                    criterion.Conditional    = profileCriterion.Conditional;
                    criterion.Dependent      = profileCriterion.Dependent;
                    criterion.Optionality    = profileCriterion.Optionality;
                }
                return(element);
            }
コード例 #4
0
ファイル: ProfilingForm.cs プロジェクト: HL7/ehrsfm-tool
 public R2ModelElementHolder(EA.Repository repository, EA.Element element)
 {
     baseModelEAElement           = element;
     compilerInstructionEAElement = findCompilerInstruction(repository, element);
     if (compilerInstructionEAElement == null)
     {
         modelElement = R2ModelV2.EA_API.Factory.Create(repository, element);
     }
     else
     {
         modelElement = R2ModelV2.EA_API.Factory.Create(repository, compilerInstructionEAElement);
     }
 }
コード例 #5
0
        //This event occurs when a user has double-clicked (or pressed [Enter])
        //on the item in context, either in a diagram or in the Project Browser.
        public bool EA_OnContextItemDoubleClicked(EA.Repository repository, string GUID, EA.ObjectType ot)
        {
            if (ot == EA.ObjectType.otElement)
            {
                EA.Element     element      = repository.GetElementByGuid(GUID);
                R2ModelElement modelElement = R2ModelV2.EA_API.Factory.Create(repository, element);
                if (modelElement != null)
                {
                    switch (modelElement.Stereotype)
                    {
                    case R2Const.ST_SECTION:     // For Section Compiler Instruction!
                        new SectionForm().Show((R2Section)modelElement);
                        return(true);

                    case R2Const.ST_HEADER:
                    case R2Const.ST_FUNCTION:
                        new FunctionForm().Show((R2Function)modelElement);
                        return(true);

                    case R2Const.ST_CRITERION:
                        new CriterionForm().Show((R2Criterion)modelElement);
                        return(true);
                    }
                }
            }
            else if (ot == EA.ObjectType.otPackage)
            {
                EA.Element element = repository.GetPackageByGuid(GUID).Element;
                switch (element.Stereotype)
                {
                case R2Const.ST_FM_PROFILE:
                    return(false);

                case R2Const.ST_FM_PROFILEDEFINITION:
                    EA.Package          profDefPackage = repository.GetPackageByGuid(GUID);
                    R2ProfileDefinition profDef        = (R2ProfileDefinition)R2ModelV2.EA_API.Factory.Create(repository, profDefPackage.Element);
                    profDef.BaseModelName = EAHelper.getAssociatedBaseModelName(repository, profDefPackage);
                    new ProfileMetadataForm().Show(profDef);
                    return(true);

                case R2Const.ST_SECTION:
                    new SectionForm().Show((R2ModelV2.Base.R2Section)R2ModelV2.EA_API.Factory.Create(repository, element));
                    return(true);
                }
            }
            return(false);
        }
コード例 #6
0
ファイル: MergeProfilesForm.cs プロジェクト: HL7/ehrsfm-tool
        private void selectButton_Click(object sender, EventArgs e)
        {
            if (modelsDataGridView.CurrentCell.ColumnIndex < 2)
            {
                // Ignore, cannot select FM or Merged Profile itself
                return;
            }
            DataGridViewCell currentCell = modelsDataGridView.CurrentCell;

            if (currentCell.Tag == null)
            {
                // Nothing to do, select an empty cell.
                return;
            }
            modelsDataGridView.CurrentRow.Cells[1].Value = currentCell.Value;

            R2ModelElement   compilerInstruction = R2ModelV2.MAX.Factory.CreateModelElement((R2ModelElement)currentCell.Tag, (R2ModelElement)modelsDataGridView.CurrentRow.Cells[0].Tag);
            DataGridViewCell cell = modelsDataGridView.CurrentRow.Cells[1];

            cell.Tag = compilerInstruction;
            if (compilerInstruction is R2Criterion)
            {
                R2Criterion criterion = (R2Criterion)compilerInstruction;
                criterion.ProfileDefinition = (R2ProfileDefinition)modelsDataGridView.Columns[COLUMN_MERGED_PROFILE].Tag;
                cell.ToolTipText            = criterion.Text;
            }
            else if (compilerInstruction is R2Function)
            {
                R2Function function = (R2Function)compilerInstruction;
                function.ProfileDefinition = (R2ProfileDefinition)modelsDataGridView.Columns[COLUMN_MERGED_PROFILE].Tag;
                cell.ToolTipText           = function.Name + "\n" + function.Description;
            }
            else if (compilerInstruction is R2Section)
            {
                R2Section section = (R2Section)compilerInstruction;
                cell.ToolTipText = section.Name;
            }
            UpdateStatistics();
        }
コード例 #7
0
ファイル: R2ModelV2MAX.cs プロジェクト: HL7/ehrsfm-tool
            /**
             * Factory method to create correct model class based on the EA.Element
             */
            public static R2ModelElement Create(ObjectType objectType)
            {
                R2ModelElement modelElement = null;

                switch (objectType.stereotype)
                {
                case R2Const.ST_FM:
                    modelElement = new R2Model(objectType);
                    break;

                case R2Const.ST_FM_PROFILEDEFINITION:
                case R2Const.ST_FM_PROFILE:
                    modelElement = new R2ProfileDefinition(objectType);
                    break;

                case R2Const.ST_SECTION:
                    modelElement = new R2Section(objectType);
                    break;

                case R2Const.ST_HEADER:
                case R2Const.ST_FUNCTION:
                    modelElement = new R2Function(objectType);
                    break;

                case R2Const.ST_CRITERION:
                    modelElement = new R2Criterion(objectType);
                    break;

                case R2Const.ST_COMPILERINSTRUCTION:
                    // TODO: baseElement comes from BaseModel, mock to Criterion for now
                    Console.Write("!! R2ModelV2MAX.Create ST_COMPILERINSTRUCTION mocked to Criterion");
                    modelElement = new R2Criterion(objectType);
                    //modelElement.IsCompilerInstruction = true;
                    break;
                }
                return(modelElement);
            }
コード例 #8
0
ファイル: R2ModelV2EA.cs プロジェクト: HL7/ehrsfm-tool
            /**
             * Factory method to create correct model class based on the EA.Element
             */
            public static R2ModelElement Create(EA.Repository repository, EA.Element element)
            {
                R2ModelElement modelElement = null;

                switch (element.Stereotype)
                {
                case R2Const.ST_FM_PROFILEDEFINITION:
                    modelElement = new R2ProfileDefinition(element);
                    break;

                case R2Const.ST_SECTION:
                    modelElement = new R2Section(element);
                    break;

                case R2Const.ST_HEADER:
                case R2Const.ST_FUNCTION:
                    modelElement = new R2Function(element);
                    break;

                case R2Const.ST_CRITERION:
                    modelElement = new R2Criterion(element);
                    break;

                case R2Const.ST_COMPILERINSTRUCTION:
                    int genCount = element.Connectors.Cast <EA.Connector>().Count(c => "Generalization".Equals(c.Type));
                    if (genCount == 0)
                    {
                        // Try Dependency/Generalization in case this is a Section Compiler instruction
                        genCount = element.Connectors.Cast <EA.Connector>().Count(c => "Dependency".Equals(c.Type) && "Generalization".Equals(c.Stereotype));
                        if (genCount == 0)
                        {
                            MessageBox.Show(string.Format("{0} is a Compiler Instruction.\nExpected one(1) Generalization to a Base Element.\nFix this manually.", element.Name), "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error);
                            return(null);
                        }
                    }
                    else if (genCount > 1)
                    {
                        MessageBox.Show(string.Format("{0} is a Compiler Instruction.\nExpected one(1) Generalization, but got {1}.\nFix this manually.", element.Name, genCount), "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        return(null);
                    }
                    EA.Connector generalization = element.Connectors.Cast <EA.Connector>().SingleOrDefault(c => "Generalization".Equals(c.Type));
                    // Try Dependency/Generalization in case this is a Section Compiler instruction
                    if (generalization == null)
                    {
                        generalization = element.Connectors.Cast <EA.Connector>().SingleOrDefault(c => "Dependency".Equals(c.Type) && "Generalization".Equals(c.Stereotype));
                    }
                    EA.Element baseElement = repository.GetElementByID(generalization.SupplierID);
                    switch (baseElement.Stereotype)
                    {
                    case R2Const.ST_SECTION:
                        modelElement             = new R2Section(element);
                        modelElement.BaseElement = new R2Section(baseElement);
                        break;

                    case R2Const.ST_HEADER:
                    case R2Const.ST_FUNCTION:
                        modelElement             = new R2Function(element);
                        modelElement.BaseElement = new R2Function(baseElement);
                        break;

                    case R2Const.ST_CRITERION:
                        modelElement             = new R2Criterion(element);
                        modelElement.BaseElement = new R2Criterion(baseElement);
                        break;
                    }
                    modelElement.IsCompilerInstruction = true;
                    if (repository != null)
                    {
                        modelElement.BaseElement.Path = GetModelElementPath(repository, baseElement);
                    }
                    break;
                }
                if (modelElement != null && repository != null)
                {
                    modelElement.Path = GetModelElementPath(repository, element);

                    // is element is in profile definition package this is a compiler instruction
                    EA.Package ProfileDefinitionPackage = repository.GetPackageByID(((EA.Element)modelElement.SourceObject).PackageID);
                    if (R2Const.ST_FM_PROFILEDEFINITION.Equals(ProfileDefinitionPackage.StereotypeEx))
                    {
                        modelElement.IsCompilerInstruction = true;

                        // The ProfileType is needed for R2FunctionCI's in the FunctionForm
                        if (modelElement is R2Function)
                        {
                            R2Function function = (R2Function)modelElement;
                            function.ProfileDefinition = (R2ProfileDefinition)Create(EAHelper.repository, ProfileDefinitionPackage.Element);
                        }
                        else if (modelElement is R2Criterion)
                        {
                            R2Criterion criterion = (R2Criterion)modelElement;
                            criterion.ProfileDefinition = (R2ProfileDefinition)Create(EAHelper.repository, ProfileDefinitionPackage.Element);
                        }
                    }
                }
                return(modelElement);
            }
コード例 #9
0
ファイル: MergeProfilesForm.cs プロジェクト: HL7/ehrsfm-tool
        private void saveButton_Click(object sender, EventArgs e)
        {
            string fileNameOutput = FileUtil.showFileDialog("Select Profile Definition MAX XML file", "max files (*.xml, *.max)|*.xml;*.max", fileNameMerged, false);

            if (string.IsNullOrEmpty(fileNameOutput))
            {
                // Save canceled
                return;
            }

            List <ObjectType>       objects       = new List <ObjectType>();
            List <RelationshipType> relationships = new List <RelationshipType>();

            R2ProfileDefinition profileDef = (R2ProfileDefinition)modelsDataGridView.Columns[COLUMN_MERGED_PROFILE].Tag;
            string     defId     = profileDef.Id;
            ObjectType maxDefObj = (ObjectType)profileDef.SourceObject;

            maxDefObj.SetTagValue("MAX::ExportDate", Util.FormatLastModified(DateTime.Now));
            maxDefObj.SetTagValue("MAX::ExportFile", fileNameOutput);
            objects.Add(maxDefObj);

            foreach (DataGridViewRow row in modelsDataGridView.Rows)
            {
                R2ModelElement element = (R2ModelElement)row.Cells[1].Tag;
                if (element != null)
                {
                    element.SaveToSource();
                    ObjectType maxObj = (ObjectType)element.SourceObject;
                    maxObj.id       = Guid.NewGuid().ToString();
                    maxObj.parentId = defId;
                    objects.Add(maxObj);

                    // Only create Generalization Relationship if this is a Compiler Instruction
                    if (element.BaseElement != null)
                    {
                        RelationshipType maxRel = new RelationshipType();
                        maxRel.sourceId      = maxObj.id;
                        maxRel.destId        = ((ObjectType)element.BaseElement.SourceObject).id;
                        maxRel.type          = RelationshipTypeEnum.Generalization;
                        maxRel.typeSpecified = true;
                        relationships.Add(maxRel);
                    }
                }
            }

            // Convert to MAX model
            ModelType model = new ModelType();

            model.exportDate    = Util.FormatLastModified(DateTime.Now);
            model.objects       = objects.ToArray();
            model.relationships = relationships.ToArray();

            // Save Merged profile definition as MAX XML
            XmlSerializer     serializer = new XmlSerializer(typeof(ModelType));
            XmlWriterSettings settings   = new XmlWriterSettings();

            settings.Indent       = true;
            settings.NewLineChars = "\n";
            using (XmlWriter writer = XmlWriter.Create(fileNameOutput, settings))
            {
                serializer.Serialize(writer, model);
            }
            MessageBox.Show("Created Profile Definition MAX file.", "Done", MessageBoxButtons.OK, MessageBoxIcon.Information);
        }