public SimpleQuestionControl( string label, StandardValidTerm questionType, string description, List <StandardValidTerm> answers, List <StandardCodeSequence> nonQuantifableAnswers, List <StandardValidTerm> initialSelection, int minCardinality, int maxCardinality, int questionNumber, bool hasConfidence, bool addFirstDefaultItem, bool shouldDisplay, List <string> staticDisplayItems) { Platform.CheckForNullReference(answers, "answers"); InitializeComponent(); _questionType = questionType; _lblEntity.Text = _questionType == null ? label : CodeUtils.ToStringBuilder(_questionType, new StringBuilder()).ToString(); _lblEntity.ToolTipText = SplitIntoLines(description); _lblEntity.ShowToolTipChanged += OnLabelShowToolTipChanged; _lblEntity.TabStop = false; _questionNumber = questionNumber; Debug.Assert(maxCardinality - minCardinality >= 0, "MinCardinality must be less or equal to MaxCardinality in a question"); _maxNumberOfAnswers = Math.Max(1, Math.Min(answers.Count, maxCardinality)); var availableAnswers = new List <StandardValidTerm>(answers); if (nonQuantifableAnswers != null) { Debug.Assert(false, "Non-quantifieables should not really be here"); availableAnswers.InsertRange(0, ComponentUtilities.ToStandardValidTermList(nonQuantifableAnswers)); } _selectedAnswers = initialSelection; _staticDisplayItems = staticDisplayItems; if (shouldDisplay) { SuspendLayout(); _questionControl = InitializeResponseControl(availableAnswers, initialSelection, addFirstDefaultItem); Controls.Add(_questionControl); Height += _questionControl.Height + 3; if (hasConfidence) { _confidenceControl = InitializeConfidenceControl(); Controls.Add(_confidenceControl); Height += _confidenceControl.Height + 3; } ResumeLayout(false); PerformLayout(); } else { if (initialSelection == null || initialSelection.Count == 0) { Platform.Log(LogLevel.Error, "Template data error: no default values are provided for questions that are not going to be displayed. Template answers are never going to be valid"); } } }
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(); }