コード例 #1
0
        private async void GetDataButton_Click(object sender, EventArgs e)
        {
            if (this.resourceSelectorComboBox.SelectedIndex == 0)
            {
                if (MessageBox.Show("You must select a Resource...", "Alert!!", MessageBoxButtons.OK) == DialogResult.OK)
                {
                    return;
                }
            }
            string uri = ConfigurationManager.AppSettings["FHIRBaseAPIURI"];

            // Ensure an ID is selected for the appropriate Resource
            if (String.IsNullOrEmpty(this.resourceIDTextBox.Text))
            {
                if (this.resourceSelectorComboBox.SelectedIndex == 1)
                {
                    if (MessageBox.Show("Please enter a Patient ID. ", "Alert!!", MessageBoxButtons.OK) == DialogResult.OK)
                    {
                        return;
                    }
                }
                else if (this.resourceSelectorComboBox.SelectedIndex == 2)
                {
                    if (MessageBox.Show("Please enter an Encounter ID. ", "Alert!!", MessageBoxButtons.OK) == DialogResult.OK)
                    {
                        return;
                    }
                }
                else
                {
                    if (MessageBox.Show("Please enter an Observation ID. ", "Alert!!", MessageBoxButtons.OK) == DialogResult.OK)
                    {
                        return;
                    }
                }
            }
            else
            {
                // Set proper URI based on the resource
                uri += @"/" + this.resourceSelectorComboBox.Text + @"/" + this.resourceIDTextBox.Text;
            }


            var result = await this.GetTokenForConfidentialClient();

            if (result != null)
            {
                this.statusTextBox.Text += "Getting ready to invoke the API" + Environment.NewLine;
                var httpClient = new HttpClient();
                var apiCaller  = new ProtectedApiCallHelper(httpClient);
                //uri = String.IsNullOrEmpty(this.resourceIDTextBox.Text) ? this._patientURI : this._patientURI + @"/" + this.resourceIDTextBox.Text;
                await apiCaller.GetDataFromAPIAsync(uri, result.AccessToken, Display);
            }
        }