public async Task CreateNewThingsReturnsIds() { IHealthVaultSodaConnection connection = HealthVaultConnectionFactory.Current.GetOrCreateSodaConnection(Constants.Configuration); IThingClient thingClient = connection.CreateThingClient(); PersonInfo personInfo = await connection.GetPersonInfoAsync(); HealthRecordInfo record = personInfo.SelectedRecord; await DeletePreviousThings(thingClient, record); LocalDateTime nowLocal = SystemClock.Instance.GetCurrentInstant().InZone(DateTimeZoneProviders.Tzdb.GetSystemDefault()).LocalDateTime; var bloodGlucose = new BloodGlucose( new HealthServiceDateTime(nowLocal), new BloodGlucoseMeasurement( 4.2, new DisplayValue(4.2, "mmol/L", "mmol-per-l")), new CodableValue("Whole blood", "wb", new VocabularyKey("glucose-measurement-type", "wc", "1"))); var weight = new Weight( new HealthServiceDateTime(nowLocal), new WeightValue(81, new DisplayValue(81, "KG", "kg"))); await thingClient.CreateNewThingsAsync( record.Id, new List <IThing> { bloodGlucose, weight, }); Assert.IsNotNull(bloodGlucose.Key, "Blood glucose was not assigned a key."); Assert.IsNotNull(weight.Key, "Weight was not assigned a key."); }
public void WhenHealthVaultBloodGlucoseTransformedToFhir_ThenCodeAndValuesEqual() { var when = new HealthServiceDateTime(); var bloodGlucose = new BloodGlucose { When = when, Value = new BloodGlucoseMeasurement(101), GlucoseMeasurementType = new CodableValue("Whole blood", "wb", "glucose-meaurement-type", "wc", "1"), OutsideOperatingTemperature = true, IsControlTest = false, ReadingNormalcy = Normalcy.Normal, MeasurementContext = new CodableValue("Before meal", "BeforeMeal", "glucose-measurement-context", "wc", "1"), }; var observation = bloodGlucose.ToFhir(); var json = FhirSerializer.SerializeToJson(observation); Assert.IsNotNull(observation); Assert.AreEqual(101, ((Quantity)observation.Value).Value); Assert.AreEqual("Whole blood", observation.Method.Text); var bloodGlucoseExtension = observation.GetExtension(HealthVaultExtensions.BloodGlucose); Assert.AreEqual("Before meal", bloodGlucoseExtension.GetExtensionValue <CodeableConcept>(HealthVaultExtensions.BloodGlucoseMeasurementContext).Text); Assert.AreEqual(true, bloodGlucoseExtension.GetBoolExtension(HealthVaultExtensions.OutsideOperatingTemperatureExtensionName)); Assert.AreEqual(false, bloodGlucoseExtension.GetBoolExtension(HealthVaultExtensions.IsControlTestExtensionName)); Assert.AreEqual("Normal", bloodGlucoseExtension.GetStringExtension(HealthVaultExtensions.ReadingNormalcyExtensionName)); }
public static string ConvertBloodGlucoseToString(BloodGlucose bloodGlucose) { string result = ""; StringBuilder sb = null; if (bloodGlucose != null) { sb = new StringBuilder(); sb.Append("Id: "); sb.Append(bloodGlucose.Id.ToString()); sb.Append(" "); sb.Append("Type: "); sb.Append(bloodGlucose.Type); sb.Append(" "); sb.Append("PII_ID: "); sb.Append(bloodGlucose.PII_ID.ToString()); sb.Append(" "); sb.Append("MGDL: "); sb.Append(bloodGlucose.MGDL.ToString()); sb.Append(" "); sb.Append("DateRead: "); sb.Append(bloodGlucose.DateRead.ToString("MM/dd/yyyy")); sb.Append(" "); sb.Append("TimeRead:"); sb.Append(bloodGlucose.TimeRead.ToString("HH:mm:ss tt")); result = sb.ToString(); } return(result); }
private static void SetGlucoseMeasurementContext(this BloodGlucose bloodGlucose, string display, string code, string vocabName, string family, string version) { if (bloodGlucose.MeasurementContext == null) { bloodGlucose.MeasurementContext = new CodableValue(display); } bloodGlucose.MeasurementContext.Add(new CodedValue(code, vocabName, family, version)); }
private BloodGlucose CreateSampleBloodGlucose() { BloodGlucose thing = new BloodGlucose(); var document = new XPathDocument(new StringReader(SampleUtils.GetSampleContent("ThingSample.xml"))); thing.ParseXml(document.CreateNavigator().SelectSingleNode("thing"), SampleUtils.GetSampleContent("ThingSample.xml")); return(thing); }
public static BloodGlucose ConvertBloodGlucose(string line, char delim) { BloodGlucose bloodGlucose = null; string[] words = null; Guid id = Guid.Empty; DateTime dt = DateTime.MinValue; Int32 val = 0; CultureInfo culture; DateTimeStyles styles = DateTimeStyles.None; culture = CultureInfo.CreateSpecificCulture("en-US"); if (string.IsNullOrEmpty(line) == false) { words = line.Split(delim); if (words != null) { if (words.Length == 6) { bloodGlucose = new BloodGlucose(); bloodGlucose.Type = words[0]; if (Guid.TryParse(words[1], out id) == true) { bloodGlucose.Id = id; } if (Guid.TryParse(words[2], out id) == true) { bloodGlucose.PII_ID = id; } if (Int32.TryParse(words[3], out val) == true) { bloodGlucose.MGDL = val; } if (DateTime.TryParse(words[4], culture, styles, out dt) == true) { bloodGlucose.DateRead = dt; } if (DateTime.TryParse(words[5], culture, styles, out dt) == true) { bloodGlucose.TimeRead = dt; } } } } return(bloodGlucose); }
public async Task MultipleQueries() { IHealthVaultSodaConnection connection = HealthVaultConnectionFactory.Current.GetOrCreateSodaConnection(Constants.Configuration); IThingClient thingClient = connection.CreateThingClient(); PersonInfo personInfo = await connection.GetPersonInfoAsync(); HealthRecordInfo record = personInfo.SelectedRecord; await DeletePreviousThings(thingClient, record); LocalDateTime nowLocal = SystemClock.Instance.GetCurrentInstant().InZone(DateTimeZoneProviders.Tzdb.GetSystemDefault()).LocalDateTime; var bloodGlucose = new BloodGlucose( new HealthServiceDateTime(nowLocal), new BloodGlucoseMeasurement( 4.2, new DisplayValue(4.2, "mmol/L", "mmol-per-l")), new CodableValue("Whole blood", "wb", new VocabularyKey("glucose-measurement-type", "wc", "1"))); var weight = new Weight( new HealthServiceDateTime(nowLocal), new WeightValue(81, new DisplayValue(81, "KG", "kg"))); await thingClient.CreateNewThingsAsync( record.Id, new List <IThing> { bloodGlucose, weight, }); var resultSet = await thingClient.GetThingsAsync(record.Id, new[] { new ThingQuery(BloodGlucose.TypeId), new ThingQuery(Weight.TypeId) }); Assert.AreEqual(2, resultSet.Count); var resultList = resultSet.ToList(); ThingCollection glucoseCollection = resultList[0]; var returnedBloodGlucose = (BloodGlucose)glucoseCollection.First(); Assert.AreEqual(bloodGlucose.Value.Value, returnedBloodGlucose.Value.Value); ThingCollection weightCollection = resultList[1]; var returnedWeight = (Weight)weightCollection.First(); Assert.AreEqual(weight.Value.Kilograms, returnedWeight.Value.Kilograms); }
internal static Observation ToFhirInternal(BloodGlucose bg, Observation observation) { observation.Method = bg.GlucoseMeasurementType.ToFhir(); var bloodGlucoseExtension = new Extension { Url = HealthVaultExtensions.BloodGlucose }; if (bg.MeasurementContext != null) { bloodGlucoseExtension.AddExtension(HealthVaultExtensions.BloodGlucoseMeasurementContext, bg.MeasurementContext.ToFhir()); } if (bg.OutsideOperatingTemperature.HasValue) { bloodGlucoseExtension.AddExtension(HealthVaultExtensions.OutsideOperatingTemperatureExtensionName, new FhirBoolean(bg.OutsideOperatingTemperature.Value)); } if (bg.ReadingNormalcy.HasValue) { bloodGlucoseExtension.AddExtension(HealthVaultExtensions.ReadingNormalcyExtensionName, new FhirString(bg.ReadingNormalcy.Value.ToString())); } if (bg.IsControlTest.HasValue) { bloodGlucoseExtension.AddExtension(HealthVaultExtensions.IsControlTestExtensionName, new FhirBoolean(bg.IsControlTest.Value)); } observation.Extension.Add(bloodGlucoseExtension); observation.Code = HealthVaultVocabularies.GenerateCodeableConcept(HealthVaultThingTypeNameCodes.BloodGlucose); var quantity = new Quantity((decimal)bg.Value.Value, UnitAbbreviations.MillimolesPerLiter); observation.Value = quantity; observation.Effective = new FhirDateTime(bg.When.ToLocalDateTime().ToDateTimeUnspecified()); return(observation); }
private void addButton_Click(object sender, EventArgs e) { string path = MS539_final_project_roderick_devalcourt.Properties.Settings.Default.DefaultPath; string fileName = MS539_final_project_roderick_devalcourt.Properties.Settings.Default.FileName; bloodGlucoseForm dlg = null; BloodGlucose bloodGlucose = null; WriteFileLogic writeFileLogic = null; string pathFileName = ""; dlg = new bloodGlucoseForm(); dlg.ShowDialog(this); if (dlg.DialogResult == DialogResult.OK) { this.Cursor = Cursors.WaitCursor; //save here bloodGlucose = new BloodGlucose(dlg.bloodGlucose); bloodGlucose.PII_ID = readFileLogic.personallyIdentifiableInformation.Id; writeFileLogic = new WriteFileLogic(); writeFileLogic.listBloodGlucose.Add(bloodGlucose); writeFileLogic.personallyIdentifiableInformation = new PersonallyIdentifiableInformation(readFileLogic.personallyIdentifiableInformation); foreach (BloodGlucose bloodGlucose1 in readFileLogic.listBloodGlucose) { writeFileLogic.listBloodGlucose.Add(new BloodGlucose(bloodGlucose1)); } foreach (PulseAndOxygen pulseAndOxygen1 in readFileLogic.listPulseAndOxygen) { writeFileLogic.listPulseAndOxygen.Add(new PulseAndOxygen(pulseAndOxygen1)); } writeFileLogic.PathName = path; writeFileLogic.FileName = fileName; pathFileName = writeFileLogic.GetFormattedFileName(); writeFileLogic.WriteFile(); LoadChart(); this.Cursor = Cursors.Default; } }
public async Task MultipleThingTypes() { IHealthVaultSodaConnection connection = HealthVaultConnectionFactory.Current.GetOrCreateSodaConnection(Constants.Configuration); IThingClient thingClient = connection.CreateThingClient(); PersonInfo personInfo = await connection.GetPersonInfoAsync(); HealthRecordInfo record = personInfo.SelectedRecord; await DeletePreviousThings(thingClient, record); LocalDateTime nowLocal = SystemClock.Instance.GetCurrentInstant().InZone(DateTimeZoneProviders.Tzdb.GetSystemDefault()).LocalDateTime; var bloodGlucose = new BloodGlucose( new HealthServiceDateTime(nowLocal), new BloodGlucoseMeasurement( 4.2, new DisplayValue(4.2, "mmol/L", "mmol-per-l")), new CodableValue("Whole blood", "wb", new VocabularyKey("glucose-measurement-type", "wc", "1"))); var weight = new Weight( new HealthServiceDateTime(nowLocal), new WeightValue(81, new DisplayValue(81, "KG", "kg"))); var bloodPressure1 = new BloodPressure { EffectiveDate = nowLocal, Systolic = 110, Diastolic = 90, }; var bloodPressure2 = new BloodPressure { EffectiveDate = nowLocal.PlusHours(-1), Systolic = 111, Diastolic = 91, }; var cholesterolProfile = new CholesterolProfileV2 { When = new HealthServiceDateTime(nowLocal), LDL = new ConcentrationMeasurement(110), HDL = new ConcentrationMeasurement(65), Triglyceride = new ConcentrationMeasurement(140) }; var labTestResult = new LabTestResults(new LabTestResultGroup[] { new LabTestResultGroup(new CodableValue("test")) }); var immunization = new Immunization(new CodableValue("diphtheria, tetanus toxoids and acellular pertussis vaccine", "DTaP", new VocabularyKey("immunizations", "wc", "1"))); var procedure = new Procedure(new CodableValue("A surgery")); var allergy = new Allergy(new CodableValue("Pollen")); var condition = new Condition(new CodableValue("Diseased")); await thingClient.CreateNewThingsAsync( record.Id, new List <IThing> { bloodGlucose, weight, bloodPressure1, bloodPressure2, cholesterolProfile, labTestResult, immunization, procedure, allergy, condition }); var query = CreateMultiThingQuery(); ThingCollection thingCollection = await thingClient.GetThingsAsync(record.Id, query); Assert.AreEqual(10, thingCollection.Count); var returnedBloodGlucose = (BloodGlucose)thingCollection.First(t => t.TypeId == BloodGlucose.TypeId); Assert.AreEqual(bloodGlucose.Value.Value, returnedBloodGlucose.Value.Value); var returnedWeight = (Weight)thingCollection.First(t => t.TypeId == Weight.TypeId); Assert.AreEqual(weight.Value.Kilograms, returnedWeight.Value.Kilograms); var returnedBloodPressures = thingCollection.Where(t => t.TypeId == BloodPressure.TypeId).Cast <BloodPressure>().ToList(); Assert.AreEqual(2, returnedBloodPressures.Count); Assert.AreEqual(bloodPressure1.Systolic, returnedBloodPressures[0].Systolic); }
public IHttpActionResult Post(BloodGlucose value) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (value.source == null || value.humanId == null) { return(BadRequest()); } using (var dbContextTransaction = db.Database.BeginTransaction()) { try { tSourceService sourceServiceObj = db.tSourceServices .SingleOrDefault(x => x.ServiceName == value.source && x.SourceID == 5); if (sourceServiceObj == null) { sourceServiceObj = new tSourceService(); sourceServiceObj.ServiceName = value.source; sourceServiceObj.TypeID = 2; //Wellness sourceServiceObj.SourceID = 5; //HumanAPI db.tSourceServices.Add(sourceServiceObj); } tUserSourceService userSourceServiceObj = null; //Get credentials tCredential credentialObj = db.tCredentials.SingleOrDefault(x => x.SourceID == 5 && x.SourceUserID == value.humanId && x.SystemStatusID == 1); if (credentialObj == null) { throw new NoUserCredentialsException("Unable to find any matching HAPI user credentials"); } else { userSourceServiceObj = db.tUserSourceServices.SingleOrDefault( x => x.SourceServiceID == sourceServiceObj.ID && x.CredentialID == credentialObj.ID && x.SystemStatusID == 1); if (userSourceServiceObj == null) { userSourceServiceObj = new tUserSourceService(); userSourceServiceObj.SourceServiceID = sourceServiceObj.ID; userSourceServiceObj.UserID = credentialObj.UserID; userSourceServiceObj.CredentialID = credentialObj.ID; userSourceServiceObj.ConnectedOnDateTime = DateTime.Now; userSourceServiceObj.LastSyncDateTime = DateTime.Now; userSourceServiceObj.LatestDateTime = value.updatedAt; userSourceServiceObj.StatusID = 3; //connected userSourceServiceObj.SystemStatusID = 1; //valid userSourceServiceObj.tCredential = credentialObj; db.tUserSourceServices.Add(userSourceServiceObj); } else { //update LatestDateTime to the most recent datetime if (userSourceServiceObj.LatestDateTime == null || userSourceServiceObj.LatestDateTime < value.updatedAt) { userSourceServiceObj.LatestDateTime = value.updatedAt; } } } tUserTestResult userTestResult = null; userTestResult = db.tUserTestResults .SingleOrDefault(x => x.SourceObjectID == value.id); if (userTestResult == null) { //insert userTestResult = new tUserTestResult(); userTestResult.SourceObjectID = value.id; userTestResult.UserID = credentialObj.UserID; userTestResult.tUserSourceService = userSourceServiceObj; userTestResult.UserSourceServiceID = userSourceServiceObj.ID; userTestResult.Name = "Blood Glucose"; userTestResult.StatusID = 3; //captured userTestResult.SystemStatusID = 1; //Dates DateTimeOffset dtoStart; if (RESTfulBAL.Models.DynamoDB.Utilities.ConvertToDateTimeOffset(value.timestamp, value.tzOffset, out dtoStart)) { userTestResult.ResultDateTime = dtoStart; } else { userTestResult.ResultDateTime = value.timestamp; } tUserTestResultComponent userTestResultComponent = new tUserTestResultComponent(); userTestResultComponent.SystemStatusID = 1; userTestResultComponent.Name = "Blood Glucose"; userTestResultComponent.Value = value.value.ToString(); //UOM if (value.unit != null) { tUnitsOfMeasure uom = null; uom = db.tUnitsOfMeasures.SingleOrDefault(x => x.UnitOfMeasure == value.unit); if (uom == null) { uom = new tUnitsOfMeasure(); uom.UnitOfMeasure = value.unit; db.tUnitsOfMeasures.Add(uom); } userTestResultComponent.tUnitsOfMeasure = uom; userTestResultComponent.UOMID = uom.ID; } userTestResult.tUserTestResultComponents.Add(userTestResultComponent); tXrefUserTestResultComponentsCode xRefComponentCode = new tXrefUserTestResultComponentsCode(); xRefComponentCode.UserTestResultComponentID = userTestResultComponent.ID; xRefComponentCode.CodeID = 604; userTestResultComponent.tXrefUserTestResultComponentsCodes.Add(xRefComponentCode); userTestResult.Comments = value.notes; if (value.mealTag != null) { userTestResult.Narrative += "Meal: " + value.mealTag; } if (userTestResult.Narrative != null) { userTestResult.Narrative += " | "; } if (value.medicationTag != null) { userTestResult.Narrative += "Medication: " + value.medicationTag; } userTestResult.tUserSourceService = userSourceServiceObj; db.tUserTestResults.Add(userTestResult); } else { //update //Dates DateTimeOffset dtoStart; if (RESTfulBAL.Models.DynamoDB.Utilities.ConvertToDateTimeOffset(value.timestamp, value.tzOffset, out dtoStart)) { userTestResult.ResultDateTime = dtoStart; } else { userTestResult.ResultDateTime = value.timestamp; } tUserTestResultComponent userTestResultComponent = db.tUserTestResultComponents .SingleOrDefault(x => x.TestResultID == userTestResult.ID); if (userTestResultComponent != null) { userTestResultComponent.Value = value.value.ToString(); //UOM if (value.unit != null) { tUnitsOfMeasure uom = null; uom = db.tUnitsOfMeasures.SingleOrDefault(x => x.UnitOfMeasure == value.unit); if (uom == null) { uom = new tUnitsOfMeasure(); uom.UnitOfMeasure = value.unit; db.tUnitsOfMeasures.Add(uom); } if (!uom.UnitOfMeasure.Equals(value.unit)) { userTestResultComponent.tUnitsOfMeasure = uom; userTestResultComponent.UOMID = uom.ID; } } userTestResult.tUserTestResultComponents.Add(userTestResultComponent); } userTestResult.Comments = value.notes; string sNarrative = ""; if (value.mealTag != null) { sNarrative += "Meal: " + value.mealTag; } if (sNarrative != "") { sNarrative += " | "; } if (value.medicationTag != null) { sNarrative += "Medication: " + value.medicationTag; } userTestResult.Narrative = sNarrative; userTestResult.LastUpdatedDateTime = DateTime.Now; userTestResult.tUserSourceService = userSourceServiceObj; } db.SaveChanges(); dbContextTransaction.Commit(); return(Ok(userTestResult)); } catch (Exception ex) { dbContextTransaction.Rollback(); //Insert Error Log tUserDataErrLog userErrorLog = new tUserDataErrLog(); userErrorLog.ErrTypeID = (int)ErrorLogging.enumErrorType.Application; userErrorLog.ErrSourceID = (int)AuditLogging.enumApplication.SFCBAL; userErrorLog.Code = ex.HResult.ToString(); userErrorLog.Description = ex.Message; userErrorLog.Trace = ex.StackTrace; dbErr.tUserDataErrLogs.Add(userErrorLog); dbErr.SaveChanges(); string ErrMsg = "An error occured and we have logged the error. Please try again later."; Exception Err = new Exception(ErrMsg, ex); return(InternalServerError(Err)); } } }
// Register the type on the generic ThingToFhir partial class public static Observation ToFhir(this BloodGlucose bg) { return(BloodGlucoseToFhir.ToFhirInternal(bg, ToFhirInternal <Observation>(bg))); }
private bool checkInputs() { bool result = false; int count = 0; decimal mgdl = 0M; bloodGlucose = new BloodGlucose(); if (string.IsNullOrEmpty(mgdlTextbox.Text) == true) { count++; this.errorProvider1.SetError(mgdlTextbox, "mg/dl is a required input!"); } else { if (decimal.TryParse(mgdlTextbox.Text, out mgdl) == false) { count++; this.errorProvider1.SetError(mgdlTextbox, "mg/dl is a decimal % (0-200)!"); } else { if ((mgdl < 0) || (mgdl > 200)) { count++; this.errorProvider1.SetError(mgdlTextbox, "mg/dl is a decimal % (0-200)!"); } else { bloodGlucose.MGDL = mgdl; } } } if (string.IsNullOrEmpty(datePicker1.Text) == true) { count++; this.errorProvider1.SetError(datePicker1, "Date is a required input!"); } else { bloodGlucose.DateRead = datePicker1.Value; } if (string.IsNullOrEmpty(timePicker1.Text) == true) { count++; this.errorProvider1.SetError(timePicker1, "Time is a required input!"); } else { bloodGlucose.TimeRead = timePicker1.Value; } if (count == 0) { result = true; } else { bloodGlucose = null; } return(result); }
public void ReadFile() { StringBuilder stringBuilder = null; string messageText = ""; Exception exceptionDetails = null; StreamReader streamReader = null; string line = ""; BloodGlucose bloodGlucose = null; PulseAndOxygen pulseAndOxygen = null; try { SetupLists(); GetFormattedFileName(); if (File.Exists(FilePathName) == true) { streamReader = new StreamReader(FilePathName, Encoding.ASCII); while (streamReader.EndOfStream == false) { line = streamReader.ReadLine(); if (string.IsNullOrEmpty(line) == false) { if (line.StartsWith("PII") == true) { this.personallyIdentifiableInformation = ConvertLogic.ConvertPersonallyIdentifiableInformation(line, '|'); } if (line.StartsWith("PO") == true) { pulseAndOxygen = ConvertLogic.ConvertPulseAndOxygen(line, '|'); if (pulseAndOxygen != null) { this.listPulseAndOxygen.Add(pulseAndOxygen); } } if (line.StartsWith("BG") == true) { bloodGlucose = ConvertLogic.ConvertBloodGlucose(line, '|'); if (bloodGlucose != null) { this.listBloodGlucose.Add(bloodGlucose); } } } } } } catch (Exception exception) { stringBuilder = new StringBuilder(); exceptionDetails = exception; while (exceptionDetails != null) { messageText = "\r\nMessage: " + exceptionDetails.Message + "\r\nSource: " + exceptionDetails.Source + "\r\nStack Trace: " + exceptionDetails.StackTrace + "\r\n----------\r\n"; stringBuilder.Append(messageText); exceptionDetails = exceptionDetails.InnerException; } messageText = stringBuilder.ToString(); throw new Exception(messageText); } finally { if (streamReader != null) { streamReader.Close(); streamReader = null; } } }