public static List<aim4_dotnet.ImagingPhysicalEntityCharacteristic> SelectedAnatomicEntityCharacteristics(AimTemplateTreeAnatomicEntityCharacteristicNode node)
        {
            var imagingPhysicalEntityCharacteristics = new List<aim4_dotnet.ImagingPhysicalEntityCharacteristic>();

            if (node.SelectedCharacteristicQuantificationAllowedTerms.IsNullOrEmpty())
            {
                // Provide default NULL answer when answers are optional
                if (node.MinCardinality == 0)
                {
                    imagingPhysicalEntityCharacteristics.Add(
                        new aim4_dotnet.ImagingPhysicalEntityCharacteristic
                            {
                                TypeCode = new List<aim4_dotnet.iso_21090.CD>
                                        {
                                            new aim4_dotnet.iso_21090.CD(
                                                AimAnnotationComponent.NullCodeValue.CodeValue,
                                                AimAnnotationComponent.NullCodeValue.CodeMeaning,
                                                AimAnnotationComponent.NullCodeValue.CodingSchemeDesignator,
                                                AimAnnotationComponent.NullCodeValue.CodingSchemeVersion)
                                        },
                                QuestionTypeCode = ToNativeCodeList(node.QuestionType),
                                QuestionIndex = node.ItemNumber,
                                Label = node.Label
                            });
                }
            }
            else
            {
                foreach (var validTerm in node.SelectedCharacteristicQuantificationAllowedTerms)
                {
                    if (validTerm == null)
                        continue;

                    double? confidence = null;
                    if (node.HasConfidence)
                        confidence = node.ConfidenceValue;

                    if (validTerm.CharacteristicQuantifications != null && validTerm.CharacteristicQuantifications.All(quantification => quantification.Valid))
                    {
                        imagingPhysicalEntityCharacteristics.Add(
                            new aim4_dotnet.ImagingPhysicalEntityCharacteristic
                            {
                                TypeCode = ToNativeCodeList(validTerm),
                                QuestionTypeCode = ToNativeCodeList(node.QuestionType),
                                QuestionIndex = node.ItemNumber,
                                Label = node.Label,
                                AnnotatorConfidence = confidence,
                                CharacteristicQuantificationCollection = ToCharacteristicQuantifications(validTerm)
                            });

                    }
                    else
                    {
                        imagingPhysicalEntityCharacteristics.Add(
                            new aim4_dotnet.ImagingPhysicalEntityCharacteristic
                                {
                                    TypeCode = ToNativeCodeList(validTerm),
                                    QuestionTypeCode = ToNativeCodeList(node.QuestionType),
                                    QuestionIndex = node.ItemNumber,
                                    Label = node.Label,
                                    AnnotatorConfidence = confidence
                                });
                    }
                }
            }

            return imagingPhysicalEntityCharacteristics;
        }
        public AnatomicEntityCharacteristicWpfControl(AimTemplateTreeAnatomicEntityCharacteristicNode characteristic)
        {
            Characteristic = characteristic;
            InitializeComponent();

            ChildControls = new List<IValidTreeControl>();

            _originalBackground = Background;

            // Hide the allowed terms control that is not being used
            if (MaxNumberOfAnswers > 1)
            {
                _comboBox.Visibility = Visibility.Hidden;
                _comboBox.Height = 0;

                var cardinalityString = String.Empty;

                if (Characteristic.MinCardinality > 0 && Characteristic.MaxCardinality >= Characteristic.CharacteristicQuantificationAllowedTerms.Count)
                    cardinalityString = "Select at least " + Characteristic.MinCardinality;
                else if (Characteristic.MaxCardinality < Characteristic.CharacteristicQuantificationAllowedTerms.Count && Characteristic.MinCardinality <= 0)
                    cardinalityString = "Select less than " + (Characteristic.MaxCardinality + 1);
                else if (Characteristic.MinCardinality > 0 && Characteristic.MaxCardinality < Characteristic.CharacteristicQuantificationAllowedTerms.Count)
                    cardinalityString = "Select at least " + Characteristic.MinCardinality + " and less than " +
                                        (Characteristic.MaxCardinality + 1);

                if (!String.IsNullOrEmpty(cardinalityString))
                    ((TextBlock)_label.Content).Text += Environment.NewLine + cardinalityString;
            }
            else
            {
                _itemsControl.Visibility = Visibility.Hidden;
                _itemsControl.Height = 0;
            }

            // Add confidence control
            if (Characteristic.ShouldDisplay && Characteristic.HasConfidence)
            {
                NodeConfidenceWpfControl = new NodeConfidenceWpfControl(Characteristic);
                _stackPanel.Children.Add(NodeConfidenceWpfControl);
            }

            foreach (var term in Characteristic.SelectedCharacteristicQuantificationAllowedTerms)
            {
                foreach (var quantification in term.CharacteristicQuantifications)
                {
                    var characteristicControl = new CharacteristicQuantificationDetailsWpfControl(quantification);
                    _stackPanel.Children.Add(characteristicControl);
                    ChildControls.Add(characteristicControl);
                }
            }

            Loaded += AnatomicEntityCharacteristicWpfControlLoaded;

            Characteristic.SelectedAllowedTermsChanged += SelectedAllowedTermsCollectionChanged;
            CheckBoxControls = new Dictionary<CharacteristicQuantificationAllowedTerm, CheckBox>();

            if (!Characteristic.ShouldDisplay)
            {
                _label.Visibility = Visibility.Hidden;
                _label.Height = 0;
                _itemsControl.Visibility = Visibility.Hidden;
                _itemsControl.Height = 0;
                _comboBox.Visibility = Visibility.Hidden;
                _comboBox.Height = 0;
                if (Characteristic.SelectedCharacteristicQuantificationAllowedTerms.Count == 0)
                {
                    this.Visibility = Visibility.Hidden;
                    this.Height = 0;
                }
            }
        }