// 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); }
public BloodPressureValue GetLatestBloodPressureValue(string patientId, string loinc_BloodPressureType) { //Loinc code is made up of the url to the source as well as the code number itself. string loinc_path = loinc_Url + loinc_BloodPressureType; var query = new string[] { string.Format("patient={0}", patientId), string.Format("code={0}", loinc_path) }; var myObservations = FhirClient.Search <Observation>(query); List <BloodPressureValue> valuesList = new List <BloodPressureValue>(); //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) { BloodPressureValue bloodPressureValue = new BloodPressureValue(); Observation myObservation = (Hl7.Fhir.Model.Observation)entry.Resource; var myComponents = myObservation.Component; //We have the observation entry. Now we have to pull the Systolic value out of that. foreach (var myCode in myComponents) { if (myCode.Code.Coding.FirstOrDefault <Coding>().Code.ToString() == loinc_BloodPressureType) { SimpleQuantity mySimpleQuantity = (Hl7.Fhir.Model.SimpleQuantity)myCode.Value; var bpValue = mySimpleQuantity.Value; bloodPressureValue.Value = bpValue; bloodPressureValue.IssuedDate = myObservation.Issued.Value.DateTime; bloodPressureValue.BloodPressureType = loinc_BloodPressureType; valuesList.Add(bloodPressureValue); } valuesList.Add(bloodPressureValue); } } //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()); }