/// <summary>
        /// Handles the saved event of the Single Concept matching control.
        /// Adds the encoded term to the encoded list box.
        /// </summary>
        /// <param name="sender">The single concept matching control.</param>
        /// <param name="e">The <see cref="System.Windows.RoutedEventArgs"/> instance containing the event data.</param>
        private void SingleConceptMatching_Saved(object sender, System.Windows.RoutedEventArgs e)
        {
            if (this.connected && this.SingleConceptMatching.InputBoxSelectedItem != null)
            {
                ObservableCollection <AdditionalTextBoxResult> additionalTextBoxResults = new ObservableCollection <AdditionalTextBoxResult>();

                foreach (object o in this.SingleConceptMatching.AdditionalTextBoxSelectedTerms)
                {
                    AdditionalTextBoxResult additionalTextBoxResult = o as AdditionalTextBoxResult;

                    if (additionalTextBoxResult != null)
                    {
                        additionalTextBoxResults.Add(additionalTextBoxResult);
                    }
                }

                this.ShowProgressBar();

                TerminologyManager.EncodeConcept(this.SingleConceptMatching.InputBoxSelectedItem as InputFieldResult, additionalTextBoxResults);
            }
            else
            {
                this.EncodeOutput(CreateUnencodedConcept(this.SingleConceptMatching.InputBoxText));

                this.SingleConceptMatching.Clear();
                this.SingleConceptMatching.FocusInputBox();
            }

            this.lastInputBoxResults          = null;
            this.lastInputBoxSearch           = string.Empty;
            this.lastAdditionalTextBoxSearch  = string.Empty;
            this.lastAdditionalTextBoxResults = null;
        }
        /// <summary>
        /// Searches this instance.
        /// </summary>
        private void Search()
        {
            if (this.SingleConceptMatching.InputBoxText != this.lastInputBoxSearch)
            {
                this.lastInputBoxSearch = this.SingleConceptMatching.InputBoxText;

                if (this.connected)
                {
                    if (!SingleConceptMatchingPage.ValidateInputText(this.SingleConceptMatching.InputBoxText))
                    {
                        this.StatusText.Text = SingleConceptMatchingPage.InputTextValidationFailed;
                        return;
                    }

                    this.StatusText.Text = SingleConceptMatchingPage.SearchInProgressText;
                    this.ShowProgressBar();

                    this.SingleConceptMatching.InputBoxItemsSource = null;

                    FilterItem filterItem = this.SingleConceptMatching.SubsetPickerSelectedItem as FilterItem;

                    TerminologyManager.SearchInputField(SingleConceptMatchingPage.FixupInputText(this.SingleConceptMatching.InputBoxText), filterItem.SubsetCollection);
                }
            }
            else if (this.lastInputBoxResults != null && this.SingleConceptMatching.InputBoxText == this.lastInputBoxResults.SearchTextOriginal)
            {
                this.SingleConceptMatching.InputBoxItemsSource = this.lastInputBoxResults.InputFieldResults;
            }
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="SingleConceptMatchingPage"/> class.
        /// </summary>
        public SingleConceptMatchingPage()
        {
            InitializeComponent();

            this.LayoutRoot.Children.Remove(this.MainGrid);
            this.MainGrid.Margin      = new System.Windows.Thickness(15);
            this.ScrollViewer.Content = this.MainGrid;

            TerminologyManager.Initialized                     += new EventHandler <BaseTerminologyEventArgs>(this.TerminologyManagerInitialized);
            TerminologyManager.InputBoxSearchCompleted         += new EventHandler <InputFieldSearchCompletedEventArgs>(this.TerminologyManagerInputBoxSearchCompleted);
            TerminologyManager.AdditionalTextBoxParseCompleted += new EventHandler <AdditionalTextBoxParseCompletedEventArgs>(this.TerminologyManagerAdditionalTextBoxParseCompleted);
            TerminologyManager.EncodeConceptCompleted          += new EventHandler <EncodeConceptCompletedEventArgs>(this.TerminologyManagerEncodeConceptCompleted);
            TerminologyManager.GetConceptDetailsCompleted      += new EventHandler <GetConceptDetailsCompletedEventArgs>(this.TerminologyManagerGetConceptDetailsCompleted);

            this.StatusText.Text = SingleConceptMatchingPage.InitializingText;
            this.ShowProgressBar();
            TerminologyManager.Initialize();

            this.ScenarioComboBox.Loaded += new System.Windows.RoutedEventHandler(this.ScenarioComboBox_Loaded);

            this.encodableInputFieldTimer.Interval = TimeSpan.FromMilliseconds(500);
            this.encodableInputFieldTimer.Tick    += new System.EventHandler(this.EncodableInputFieldTimer_Tick);

            this.additionalTextBoxTimer.Interval = TimeSpan.FromMilliseconds(2000);
            this.additionalTextBoxTimer.Tick    += new EventHandler(this.AdditionalTextBoxTimerTick);

            this.outputs.CollectionChanged += new System.Collections.Specialized.NotifyCollectionChangedEventHandler(this.Outputs_CollectionChanged);
            this.OutputListBox.ItemsSource  = this.outputs;

            this.SelectedOutputContentPresenter.Content = new SingleConceptMatchingOutput();
        }
 /// <summary>
 /// Handles when the input field's selection changes.
 /// </summary>
 /// <param name="sender">The Single Concept Matching control.</param>
 /// <param name="e">Event Args.</param>
 private void SingleConceptMatching_InputBoxSelectionChanged(object sender, EventArgs e)
 {
     this.SingleConceptMatching.AdditionalTextBoxMatchingTermItemsSource = null;
     if (this.SingleConceptMatching.InputBoxSelectedItem != null)
     {
         TerminologyManager.GetConceptDetails((this.SingleConceptMatching.InputBoxSelectedItem as InputFieldResult).Concept.SnomedConceptId);
     }
 }
        /// <summary>
        /// Handles the GetConceptDetailsCompleted event from TerminologyManager.
        /// </summary>
        /// <param name="sender">The sender.</param>
        /// <param name="e">The <see cref="Microsoft.Cui.SampleWinform.TerminologyProvider.GetConceptDetailsCompletedEventArgs"/> instance containing the event data.</param>
        private void TerminologyManagerGetConceptDetailsCompleted(object sender, GetConceptDetailsCompletedEventArgs e)
        {
            this.conceptDetail = e.Result;

            if (this.SingleConceptMatching.InputBoxSelectedItem != null && ValidateInputText(this.SingleConceptMatching.AdditionalTextBoxText))
            {
                this.lastAdditionalTextBoxSearch = this.SingleConceptMatching.AdditionalTextBoxText;
                if (this.connected)
                {
                    this.StatusText.Text = SingleConceptMatchingPage.SearchInProgressText;
                    this.ShowProgressBar();
                    this.indexerCallCount++;
                    TerminologyManager.ParseAdditionalTextBox(this.SingleConceptMatching.AdditionalTextBoxText, this.SingleConceptMatching.InputBoxSelectedItem as InputFieldResult, this.conceptDetail);
                }
            }
        }
        /// <summary>
        /// Parses the additional text.
        /// </summary>
        private void ParseAdditionalText()
        {
            if (this.connected)
            {
                this.StatusText.Text = SingleConceptMatchingPage.SearchInProgressText;
                this.ShowProgressBar();
                this.indexerCallCount++;
                this.lastAdditionalTextBoxSearch = this.SingleConceptMatching.AdditionalTextBoxText;

                if (this.conceptDetail.SnomedConceptId == (this.SingleConceptMatching.InputBoxSelectedItem as InputFieldResult).Concept.SnomedConceptId)
                {
                    TerminologyManager.ParseAdditionalTextBox(this.SingleConceptMatching.AdditionalTextBoxText, this.SingleConceptMatching.InputBoxSelectedItem as InputFieldResult, this.conceptDetail);
                }
                else
                {
                    TerminologyManager.GetConceptDetails((this.SingleConceptMatching.InputBoxSelectedItem as InputFieldResult).SnomedDescriptionId);
                }
            }
        }