private void SearchAllergies(string PatientId)
        {
            WorkingMessage();
            listAllergies.Items.Clear();
            string FHIR_EndPoint = this.txtFHIREndpoint.Text.ToString();
            var    client        = new Hl7.Fhir.Rest.FhirClient(FHIR_EndPoint);

            try
            {
                var p = new Hl7.Fhir.Rest.SearchParams();
                p.Add("patient", PatientId);

                var results = client.Search <AllergyIntolerance>(p);
                this.UseWaitCursor   = false;
                lblErrorMessage.Text = "";
                while (results != null)
                {
                    if (results.Total == 0)
                    {
                        lblErrorMessage.Text = "No allergies found";
                    }

                    foreach (var entry in results.Entry)
                    {
                        var    Alrgy   = (AllergyIntolerance)entry.Resource;
                        string Content = Alrgy.Code.Coding[0].Display
                                         + " / " + Alrgy.VerificationStatus.Coding[0].Code
                                         + " (" + Alrgy.ClinicalStatus.Coding[0].Code + ")";
                        listAllergies.Items.Add(Content);
                    }
                    // get the next page of results
                    results = client.Continue(results);
                }
            }
            catch (Exception err)
            {
                lblErrorMessage.Text = "Error:" + err.Message.ToString();
            }
            if (lblErrorMessage.Text != "")
            {
                lblErrorMessage.Visible = true;
            }
        }
        private void SearchPatients()
        {
            WorkingMessage();
            listCandidates.Items.Clear();
            string FHIR_EndPoint = this.txtFHIREndpoint.Text.ToString();
            var    client        = new Hl7.Fhir.Rest.FhirClient(FHIR_EndPoint);

            client.OnBeforeRequest += (object sender, BeforeRequestEventArgs e) =>
            {
                // Replace with a valid bearer token for the server
                // e.RawRequest.Headers.Add("Authorization", "Bearer ya29.QQIBibTwvKkE39hY8mdkT_mXZoRh7Ub9cK9hNsqrxem4QJ6sQa36VHfyuBe");
            };
            try
            {
                string patId   = txtPatientID.Text.ToString();
                string patName = txtPatientName.Text.ToString();
                var    p       = new Hl7.Fhir.Rest.SearchParams();

                switch (SearchOption)
                {
                case 1:
                    p.Add("_id", patId);
                    break;

                case 2:
                    p.Add("name", patName);
                    break;

                case 3:
                    p.Add("name", patName);
                    p.Add("birthdate", dateTimeDob.Text);
                    break;
                }

                var results = client.Search <Patient>(p);
                this.UseWaitCursor   = false;
                lblErrorMessage.Text = "";

                while (results != null)
                {
                    if (results.Total == 0)
                    {
                        lblErrorMessage.Text = "No patients found";
                    }
                    btnShowAllergies.Enabled = true;
                    foreach (var entry in results.Entry)
                    {
                        var    Pat = (Patient)entry.Resource;
                        string Fam = "", Giv = "", ideS = "", ideV = "";
                        if (Pat.Name.Count > 0)
                        {
                            Fam = Pat.Name[0].Family;
                            Giv = Pat.Name[0].GivenElement[0].ToString();
                        }
                        if (Pat.Identifier.Count > 0)
                        {
                            ideS = Pat.Identifier[0]?.System;
                            ideV = Pat.Identifier[0]?.Value;
                        }

                        string       Content = Fam + " " + Giv + " (" + ideS + "-" + ideV + ")";
                        ListViewItem l       = new ListViewItem
                        {
                            Text = Content,
                            Tag  = entry.Resource.Id
                        };
                        listCandidates.Items.Add(l);
                    }

                    // get the next page of results
                    results = client.Continue(results);
                }
            }
            catch (Exception err)
            {
                lblErrorMessage.Text = "Error:" + err.Message.ToString();
            }
            if (lblErrorMessage.Text != "")
            {
                lblErrorMessage.Visible = true;
            }
        }