/// <summary>
        /// Retrieves the Cholesterol values we're going to use to calculate one of the something something something
        /// </summary>
        /// <remarks>Send in an Id for a patient and the loinc code for the the type of Cholesterol you want returned.</remarks>
        /// <param name="loinc_CholesterolType"></param>
        /// <param name="patientId"></param>
        /// <returns></returns>
        public CholesterolValue GetLatestCholesterolValue(string patientId, string loinc_CholesterolType)
        {
            //Loinc code is made up of the url to the source as well as the code number itself.
            string loinc_path = loinc_Url + loinc_CholesterolType;

            var query          = new string[] { string.Format("patient={0}", patientId), string.Format("code={0}", loinc_path) };
            var myObservations = FhirClient.Search <Observation>(query);


            List <CholesterolValue> valuesList = new List <CholesterolValue>();

            //Here we get all of the selected observations they'll let us have.
            // Fhir is supposed to use pagination so we should only get a limited set of what's available.
            // I'm assuming, for some reason, that the first ones to show up are the latest ones.
            foreach (Bundle.EntryComponent entry in myObservations.Entry)
            {
                CholesterolValue cholesterolValue = new CholesterolValue();

                Observation myObservation = (Hl7.Fhir.Model.Observation)entry.Resource;

                if (myObservation.Value is Hl7.Fhir.Model.Quantity valueQuantity)
                {
                    Quantity myQuantity = (Hl7.Fhir.Model.Quantity)myObservation.Value;

                    cholesterolValue.Value           = myQuantity.Value;
                    cholesterolValue.IssuedDate      = myObservation.Issued.Value.DateTime;
                    cholesterolValue.CholesterolType = loinc_CholesterolType;

                    valuesList.Add(cholesterolValue);
                }
            }

            //Sort by the issued date so the most recent is on the top and then select that one.
            return(valuesList.OrderByDescending(a => a.IssuedDate).FirstOrDefault());
        }
        // Let's request the conformance statement from the SMART on FHIR API server and
        // find out the endpoint URLs for the authorization server



        //public ActionResult FraminghamCalculator(CernerFullConnectionInformationViewModel cfcivm) //Models.ViewModels.Patient viewPatient)
        public FraminghamCalculatorViewModel FraminghamCalculator(CernerFullConnectionInformationViewModel cfcivm) //Models.ViewModels.Patient viewPatient)

        {
            ViewBag.Message = "Framingham Calculator";


            var client = new FhirClient(cfcivm.ServiceUrl)
            {
                PreferredFormat = ResourceFormat.Json
            };;

            client.OnBeforeRequest += (object sender, BeforeRequestEventArgs e) =>
            {
                e.RawRequest.Headers.Add("Authorization", "Bearer " + cfcivm.AccessToken);
            };


            var identity = ResourceIdentity.Build("Patient", cfcivm.PatientId);

            Hl7.Fhir.Model.Patient viewPatient = client.Read <Hl7.Fhir.Model.Patient>(identity);

            //Get those values we don't know how to retrive yet.
            FraminghamCalculatorPatient Fcp = PhillFCM(0);

            Fcp.LastName  = viewPatient.Name[viewPatient.Name.Count - 1].FamilyElement[0].ToString();
            Fcp.FirstName = viewPatient.Name[viewPatient.Name.Count - 1].GivenElement[0].ToString();
            Fcp.Gender    = viewPatient.Gender.ToString();
            Fcp.Age       = Convert.ToDateTime(viewPatient.BirthDate).Age();


            #region Get HDL
            //Now we get some real data like the HDL
            FraminghamCalculator fc = new FraminghamCalculator(Fcp);
            fc.FhirClient = client;

            string loinc_hdl = "2085-9";
            string loinc_ldl = "13457-7";
            string loinc_Cholesterol_Total = "9830-1";
            string loinc_cholesterol       = "2093-3";
            string loinc_Triglycerides     = "2571-8";
            string loinc_SystolicBP        = "8480-6";
            string loinc_DiastolicBP       = "8462-4";

            BloodPressureValue bpv      = fc.GetLatestBloodPressureValue(cfcivm.PatientId, loinc_SystolicBP);
            CholesterolValue   cv_hdl   = fc.GetLatestCholesterolValue(cfcivm.PatientId, loinc_hdl);
            CholesterolValue   cv_total = fc.GetLatestCholesterolValue(cfcivm.PatientId, loinc_cholesterol);

            #endregion Get HDL

            Fcp.SystolicBP       = (int)bpv.Value;
            Fcp.HDL              = (int)cv_hdl.Value;
            Fcp.TotalCholesterol = (int)cv_total.Value;

            FraminghamCalculatorViewModel vm = new FraminghamCalculatorViewModel();

            vm.FraminghamScore = fc.DoCalculation();
            vm.FCM             = Fcp;

            return(vm);
        }