public ComponentQuestionControl(Annotation.Template.Component component)
        {
            Platform.CheckForNullReference(component, "Component");

            InitializeComponent();

            _component = component;
            _selectedAnatomicEntityCharacteristics = new Dictionary<int, List<aim_dotnet.AnatomicEntityCharacteristic>>();
            _selectedImagingObservationCharacteristics = new Dictionary<int, List<aim_dotnet.ImagingObservationCharacteristic>>();

            var hasConfidence = false;
            if (component.AnatomicEntity != null)
            {
                _componentType = ComponentQuestionType.AnatomicEntity;
                hasConfidence = component.AnatomicEntity.AnnotatorConfidence;
            }
            else if (component.ImagingObservation != null)
            {
                _componentType = ComponentQuestionType.ImagingObservation;
                hasConfidence = component.ImagingObservation.AnnotatorConfidence;
            }
            else if (component.Inference != null)
            {
                _componentType = ComponentQuestionType.Inference;
                hasConfidence = component.Inference.AnnotatorConfidence;
            }
            else if (component.Calculation != null)
            {
                _componentType = ComponentQuestionType.Calculation;
            }
            else if (component.GeometricShapeSpecified)
                _componentType = ComponentQuestionType.GeometricShape;
            else
                Debug.Assert(false, "Unknown component type");

            var initialSelectionList = InitialSelection;
            var ptX = 0;
            var ptY = 0;
            var tabIndex = 0;

            SuspendLayout();

            List<string> staticDisplayItems = null;
            if (_componentType == ComponentQuestionType.GeometricShape && component.GeometricShapeSpecified)
            {
                staticDisplayItems = new List<string>();
                staticDisplayItems.Add(
                    component.GeometricShape.ToString() +
                    " Min: " + component.MinCardinality +
                    " Max: " + component.MaxCardinality);
            }
            if (component.Calculation != null && component.Calculation.CalculationTypes.Count > 0)
            {
                staticDisplayItems = new List<string>();
                foreach (var calculationType in component.Calculation.CalculationTypes)
                    staticDisplayItems.Add(calculationType.CodeMeaning);
            }

            _simpleQuestion = new SimpleQuestionControl(
                component.Label,
                ComponentUtilities.ValidTermToStandardValidTerm(component.QuestionType),
                component.ExplanatoryText,
                ComponentUtilities.AllowedTermsToValidTermList(component.AllowedTerm),
                null,
                initialSelectionList,
                component.MinCardinality,
                component.MaxCardinality,
                component.ItemNumber,
                hasConfidence,
                true,
                component.ShouldDisplay,
                staticDisplayItems);
            _simpleQuestion.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
            _simpleQuestion.Location = new Point(ptX, ptY);
            _simpleQuestion.Name = "_simpleQuestion";
            _simpleQuestion.Size = new Size(Width - ptX, _simpleQuestion.Height);
            _simpleQuestion.TabIndex = tabIndex++;
            _simpleQuestion.SelectedResponseChanged += OnAllowedTermSelected;
            ptX += 10;
            ptY += _simpleQuestion.Height;
            BorderStyle = BorderStyle.FixedSingle;

            Controls.Add(_simpleQuestion);
            Height += _simpleQuestion.Height;

            SelectedValidTerms = initialSelectionList;

            const int groupShiftX = 10;
            switch(ComponentType)
            {
                case ComponentQuestionType.AnatomicEntity:
                    {
                        var anatomicEntityCharacteristics =
                            CollectionUtils.Sort(component.AnatomicEntity.AnatomicEntityCharacteristic, (aec1, aec2) => aec1.ItemNumber.CompareTo(aec2.ItemNumber));
                        string prevGroupLabel = null;
                        var labelCount = 0;
                        var questionControlCount = 0;
                        foreach (var anatomicEntityCharacteristic in anatomicEntityCharacteristics)
                        {
                            var curGroupLabel = anatomicEntityCharacteristic.GroupLabel == null ? null : anatomicEntityCharacteristic.GroupLabel.Trim();
                            if (!string.IsNullOrEmpty(curGroupLabel))
                            {
                                if (prevGroupLabel != curGroupLabel)
                                {
                                    var groupLabel = new Label();
                                    groupLabel.Text = curGroupLabel;
                                    groupLabel.Font = new Font(groupLabel.Font.FontFamily, 9.0F, FontStyle.Bold);
                                    groupLabel.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
                                    groupLabel.Location = new Point(ptX, ptY);
                                    groupLabel.Name = string.Format("groupLabel{0}", labelCount++);
                                    groupLabel.Size = new Size(Width - ptX, groupLabel.Height);
                                    groupLabel.AutoEllipsis = true;
                                    groupLabel.TextAlign = ContentAlignment.MiddleLeft;

                                    Controls.Add(groupLabel);
                                    Height += groupLabel.Height;
                                    ptY += groupLabel.Height;
                                }
                                ptX += groupShiftX;
                            }
                            prevGroupLabel = curGroupLabel;

                            var anatomicEntityCtrl = new AnatomicEntityCharacteristicCtrl(anatomicEntityCharacteristic);
                            anatomicEntityCtrl.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
                            anatomicEntityCtrl.Margin = new Padding(4);
                            anatomicEntityCtrl.Location = new Point(ptX, ptY);
                            anatomicEntityCtrl.Name = string.Format("anatomicEntityCtrl{0}", questionControlCount++);
                            anatomicEntityCtrl.Size = new Size(Width - ptX, anatomicEntityCtrl.Height);
                            anatomicEntityCtrl.TabIndex = tabIndex++;
                            anatomicEntityCtrl.AnatomicEntityCharacteristicChanged += OnAnatomicEntityCharacteristicChanged;
                            anatomicEntityCtrl.SizeChanged += OnQuestionDetailsCtrlSizeChanged;
                            ptY += anatomicEntityCtrl.Height;

                            Controls.Add(anatomicEntityCtrl);
                            Height += anatomicEntityCtrl.Height;

                            _selectedAnatomicEntityCharacteristics[anatomicEntityCtrl.QuestionNumber] = anatomicEntityCtrl.SelectedAnatomicEntityCharacteristics;
                            Debug.Assert(_selectedAnatomicEntityCharacteristics[anatomicEntityCtrl.QuestionNumber] != null);

                            if (!string.IsNullOrEmpty(curGroupLabel))
                                ptX -= groupShiftX;
                        }
                    }
                    break;
                case ComponentQuestionType.ImagingObservation:
                    {
                        var imagingObservationCharacteristics =
                            CollectionUtils.Sort(component.ImagingObservation.ImagingObservationCharacteristic, (iec1, iec2) => iec1.ItemNumber.CompareTo(iec2.ItemNumber));
                        string prevGroupLabel = null;
                        var labelCount = 0;
                        var questionControlCount = 0;
                        foreach (var imagingObservationCharacteristic in imagingObservationCharacteristics)
                        {
                            var curGroupLabel = imagingObservationCharacteristic.GroupLabel == null ? null : imagingObservationCharacteristic.GroupLabel.Trim();
                            if (!string.IsNullOrEmpty(curGroupLabel))
                            {
                                if (prevGroupLabel != curGroupLabel)
                                {
                                    var groupLabel = new Label();
                                    groupLabel.Text = curGroupLabel;
                                    groupLabel.Font = new Font(groupLabel.Font.FontFamily, 9.0F, FontStyle.Bold);
                                    groupLabel.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
                                    groupLabel.Location = new Point(ptX, ptY);
                                    groupLabel.Name = string.Format("groupLabel{0}", labelCount++);
                                    groupLabel.Size = new Size(Width - ptX, groupLabel.Height);
                                    groupLabel.AutoEllipsis = true;
                                    groupLabel.TextAlign = ContentAlignment.MiddleLeft;

                                    Controls.Add(groupLabel);
                                    Height += groupLabel.Height;
                                    ptY += groupLabel.Height;
                                }
                                ptX += groupShiftX;
                            }
                            prevGroupLabel = curGroupLabel;

                            var imagingObservationCtrl = new ImagingObservationCharacteristicCtrl(imagingObservationCharacteristic);
                            imagingObservationCtrl.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
                            imagingObservationCtrl.Margin = new Padding(4);
                            imagingObservationCtrl.Location = new Point(ptX, ptY);
                            imagingObservationCtrl.Name = string.Format("imagingObservationCtrl{0}", questionControlCount++);
                            imagingObservationCtrl.Size = new Size(Width - ptX, imagingObservationCtrl.Height);
                            imagingObservationCtrl.TabIndex = tabIndex++;
                            imagingObservationCtrl.ImagingObservationCharacteristicChanged += OnImagingObservationCharacteristicChanged;
                            imagingObservationCtrl.SizeChanged += OnQuestionDetailsCtrlSizeChanged;
                            ptY += imagingObservationCtrl.Height;

                            Controls.Add(imagingObservationCtrl);
                            Height += imagingObservationCtrl.Height;

                            _selectedImagingObservationCharacteristics[imagingObservationCtrl.QuestionNumber] = imagingObservationCtrl.SelectedImagingObservationCharacteristics;
                            Debug.Assert(_selectedImagingObservationCharacteristics[imagingObservationCtrl.QuestionNumber] != null);

                            if (!string.IsNullOrEmpty(curGroupLabel))
                                ptX -= groupShiftX;
                        }
                    }
                    break;
                case ComponentQuestionType.Calculation:
                    break;
                case ComponentQuestionType.GeometricShape:
                    break;
            }

            ResumeLayout(false);
            PerformLayout();
        }
Ejemplo n.º 2
0
        public ComponentQuestionControl(Annotation.Template.Component component)
        {
            Platform.CheckForNullReference(component, "Component");

            InitializeComponent();

            _component = component;
            _selectedAnatomicEntityCharacteristics     = new Dictionary <int, List <aim_dotnet.AnatomicEntityCharacteristic> >();
            _selectedImagingObservationCharacteristics = new Dictionary <int, List <aim_dotnet.ImagingObservationCharacteristic> >();

            var hasConfidence = false;

            if (component.AnatomicEntity != null)
            {
                _componentType = ComponentQuestionType.AnatomicEntity;
                hasConfidence  = component.AnatomicEntity.AnnotatorConfidence;
            }
            else if (component.ImagingObservation != null)
            {
                _componentType = ComponentQuestionType.ImagingObservation;
                hasConfidence  = component.ImagingObservation.AnnotatorConfidence;
            }
            else if (component.Inference != null)
            {
                _componentType = ComponentQuestionType.Inference;
                hasConfidence  = component.Inference.AnnotatorConfidence;
            }
            else if (component.Calculation != null)
            {
                _componentType = ComponentQuestionType.Calculation;
            }
            else if (component.GeometricShapeSpecified)
            {
                _componentType = ComponentQuestionType.GeometricShape;
            }
            else
            {
                Debug.Assert(false, "Unknown component type");
            }

            var initialSelectionList = InitialSelection;
            var ptX      = 0;
            var ptY      = 0;
            var tabIndex = 0;

            SuspendLayout();

            List <string> staticDisplayItems = null;

            if (_componentType == ComponentQuestionType.GeometricShape && component.GeometricShapeSpecified)
            {
                staticDisplayItems = new List <string>();
                staticDisplayItems.Add(
                    component.GeometricShape.ToString() +
                    " Min: " + component.MinCardinality +
                    " Max: " + component.MaxCardinality);
            }
            if (component.Calculation != null && component.Calculation.CalculationTypes.Count > 0)
            {
                staticDisplayItems = new List <string>();
                foreach (var calculationType in component.Calculation.CalculationTypes)
                {
                    staticDisplayItems.Add(calculationType.CodeMeaning);
                }
            }

            _simpleQuestion = new SimpleQuestionControl(
                component.Label,
                ComponentUtilities.ValidTermToStandardValidTerm(component.QuestionType),
                component.ExplanatoryText,
                ComponentUtilities.AllowedTermsToValidTermList(component.AllowedTerm),
                null,
                initialSelectionList,
                component.MinCardinality,
                component.MaxCardinality,
                component.ItemNumber,
                hasConfidence,
                true,
                component.ShouldDisplay,
                staticDisplayItems);
            _simpleQuestion.Anchor   = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
            _simpleQuestion.Location = new Point(ptX, ptY);
            _simpleQuestion.Name     = "_simpleQuestion";
            _simpleQuestion.Size     = new Size(Width - ptX, _simpleQuestion.Height);
            _simpleQuestion.TabIndex = tabIndex++;
            _simpleQuestion.SelectedResponseChanged += OnAllowedTermSelected;
            ptX        += 10;
            ptY        += _simpleQuestion.Height;
            BorderStyle = BorderStyle.FixedSingle;

            Controls.Add(_simpleQuestion);
            Height += _simpleQuestion.Height;

            SelectedValidTerms = initialSelectionList;

            const int groupShiftX = 10;

            switch (ComponentType)
            {
            case ComponentQuestionType.AnatomicEntity:
            {
                var anatomicEntityCharacteristics =
                    CollectionUtils.Sort(component.AnatomicEntity.AnatomicEntityCharacteristic, (aec1, aec2) => aec1.ItemNumber.CompareTo(aec2.ItemNumber));
                string prevGroupLabel       = null;
                var    labelCount           = 0;
                var    questionControlCount = 0;
                foreach (var anatomicEntityCharacteristic in anatomicEntityCharacteristics)
                {
                    var curGroupLabel = anatomicEntityCharacteristic.GroupLabel == null ? null : anatomicEntityCharacteristic.GroupLabel.Trim();
                    if (!string.IsNullOrEmpty(curGroupLabel))
                    {
                        if (prevGroupLabel != curGroupLabel)
                        {
                            var groupLabel = new Label();
                            groupLabel.Text         = curGroupLabel;
                            groupLabel.Font         = new Font(groupLabel.Font.FontFamily, 9.0F, FontStyle.Bold);
                            groupLabel.Anchor       = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
                            groupLabel.Location     = new Point(ptX, ptY);
                            groupLabel.Name         = string.Format("groupLabel{0}", labelCount++);
                            groupLabel.Size         = new Size(Width - ptX, groupLabel.Height);
                            groupLabel.AutoEllipsis = true;
                            groupLabel.TextAlign    = ContentAlignment.MiddleLeft;

                            Controls.Add(groupLabel);
                            Height += groupLabel.Height;
                            ptY    += groupLabel.Height;
                        }
                        ptX += groupShiftX;
                    }
                    prevGroupLabel = curGroupLabel;

                    var anatomicEntityCtrl = new AnatomicEntityCharacteristicCtrl(anatomicEntityCharacteristic);
                    anatomicEntityCtrl.Anchor   = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
                    anatomicEntityCtrl.Margin   = new Padding(4);
                    anatomicEntityCtrl.Location = new Point(ptX, ptY);
                    anatomicEntityCtrl.Name     = string.Format("anatomicEntityCtrl{0}", questionControlCount++);
                    anatomicEntityCtrl.Size     = new Size(Width - ptX, anatomicEntityCtrl.Height);
                    anatomicEntityCtrl.TabIndex = tabIndex++;
                    anatomicEntityCtrl.AnatomicEntityCharacteristicChanged += OnAnatomicEntityCharacteristicChanged;
                    anatomicEntityCtrl.SizeChanged += OnQuestionDetailsCtrlSizeChanged;
                    ptY += anatomicEntityCtrl.Height;

                    Controls.Add(anatomicEntityCtrl);
                    Height += anatomicEntityCtrl.Height;

                    _selectedAnatomicEntityCharacteristics[anatomicEntityCtrl.QuestionNumber] = anatomicEntityCtrl.SelectedAnatomicEntityCharacteristics;
                    Debug.Assert(_selectedAnatomicEntityCharacteristics[anatomicEntityCtrl.QuestionNumber] != null);

                    if (!string.IsNullOrEmpty(curGroupLabel))
                    {
                        ptX -= groupShiftX;
                    }
                }
            }
            break;

            case ComponentQuestionType.ImagingObservation:
            {
                var imagingObservationCharacteristics =
                    CollectionUtils.Sort(component.ImagingObservation.ImagingObservationCharacteristic, (iec1, iec2) => iec1.ItemNumber.CompareTo(iec2.ItemNumber));
                string prevGroupLabel       = null;
                var    labelCount           = 0;
                var    questionControlCount = 0;
                foreach (var imagingObservationCharacteristic in imagingObservationCharacteristics)
                {
                    var curGroupLabel = imagingObservationCharacteristic.GroupLabel == null ? null : imagingObservationCharacteristic.GroupLabel.Trim();
                    if (!string.IsNullOrEmpty(curGroupLabel))
                    {
                        if (prevGroupLabel != curGroupLabel)
                        {
                            var groupLabel = new Label();
                            groupLabel.Text         = curGroupLabel;
                            groupLabel.Font         = new Font(groupLabel.Font.FontFamily, 9.0F, FontStyle.Bold);
                            groupLabel.Anchor       = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
                            groupLabel.Location     = new Point(ptX, ptY);
                            groupLabel.Name         = string.Format("groupLabel{0}", labelCount++);
                            groupLabel.Size         = new Size(Width - ptX, groupLabel.Height);
                            groupLabel.AutoEllipsis = true;
                            groupLabel.TextAlign    = ContentAlignment.MiddleLeft;

                            Controls.Add(groupLabel);
                            Height += groupLabel.Height;
                            ptY    += groupLabel.Height;
                        }
                        ptX += groupShiftX;
                    }
                    prevGroupLabel = curGroupLabel;

                    var imagingObservationCtrl = new ImagingObservationCharacteristicCtrl(imagingObservationCharacteristic);
                    imagingObservationCtrl.Anchor   = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
                    imagingObservationCtrl.Margin   = new Padding(4);
                    imagingObservationCtrl.Location = new Point(ptX, ptY);
                    imagingObservationCtrl.Name     = string.Format("imagingObservationCtrl{0}", questionControlCount++);
                    imagingObservationCtrl.Size     = new Size(Width - ptX, imagingObservationCtrl.Height);
                    imagingObservationCtrl.TabIndex = tabIndex++;
                    imagingObservationCtrl.ImagingObservationCharacteristicChanged += OnImagingObservationCharacteristicChanged;
                    imagingObservationCtrl.SizeChanged += OnQuestionDetailsCtrlSizeChanged;
                    ptY += imagingObservationCtrl.Height;

                    Controls.Add(imagingObservationCtrl);
                    Height += imagingObservationCtrl.Height;

                    _selectedImagingObservationCharacteristics[imagingObservationCtrl.QuestionNumber] = imagingObservationCtrl.SelectedImagingObservationCharacteristics;
                    Debug.Assert(_selectedImagingObservationCharacteristics[imagingObservationCtrl.QuestionNumber] != null);

                    if (!string.IsNullOrEmpty(curGroupLabel))
                    {
                        ptX -= groupShiftX;
                    }
                }
            }
            break;

            case ComponentQuestionType.Calculation:
                break;

            case ComponentQuestionType.GeometricShape:
                break;
            }

            ResumeLayout(false);
            PerformLayout();
        }