Patient Weight Assessment, Desktop Application Powered by Raven DB

I was researching on NoSQL databases and possible application(s) that can be developed. Here I am sharing a real world example where one can make use of NoSQL databases for managing data in an efficient way. There are times one has to think and use the right tools and technologies that will help in solving our day-to-day problems. The “Patient Weight Assessment” is a tool for understanding patient’s weight periodically over a time frame. We will try to gather all the required information that can help in determining the results through which the patient’s health conditions can be improved.

The assessment application uses Raven DB for managing all the assessment data. However, you can use any NoSQL as a persisting mechanism. There is a strong reason for choosing a non-relational NoSQL backend as opposed to any relational database.

Depending upon the nature of your requirement and project that you are working on, there are certain situations in which you have to think twice in deciding whether or not to go with the NoSQL. This project, “Patient Weight Assessment,” is about gathering certain weight and other related informationand could be done either with relational or non-relational. I tend to go with these projects as non-relational as we can store all the relevant patient’s weight information as a single document in NoSQL database. That will also help in data retrieval as one can do a single fetch to get all the relevant information.

Note: The application is designed by following the free form template published in,

Prerequisite

This project is coded using VS 2015. Please make sure to have it installed. Also download and install “RavenDB” if you don’t have one. You can install the same.

High Level Project Structure

Let us take a look into the high level project structure. Below is the screenshot for the same.

assesment

As you can see there are three projects, out of which two are class libraries.
  1. PatientWeightAssesment: A Windows Form Application for managing the patient assessment.

  2. PatientWeightAssesment.DataAccess: Contains domain level entities. Also has data access classes.

  3. RavenDBHelper: Contains helper classes and abstract DAO for RavenDB. It’s a reusable helper class library for RavenDB.

Using the Code

The Patient Weight Assessment is designed with multiple user controls to gather all the required and relevant information. We are making use of a Tab control consisting of Tab Pages. Each tab page holds one user control. Below is the code snippet which explains how we load the user controls to Tab Pages.

  1. private void FrmPatientWeightAssessment_Load(object sender, EventArgs e)  
  2. {  
  3.     tabControl = Controls.Find("tbPatientWeightAssessment"true);  
  4.     if (tabControl != null)  
  5.     {  
  6.         tabPages = ((TabControl) tabControl[0]).TabPages;  
  7.         tabPages[0].Controls.Add(newGeneralUC());  
  8.         tabPages[1].Controls.Add(newMedicalHistoryUC());  
  9.         tabPages[2].Controls.Add(newHistoryOfUC());  
  10.         tabPages[3].Controls.Add(newOverAllHealthUC());  
  11.         tabPages[4].Controls.Add(newNutritionUC());  
  12.         tabPages[5].Controls.Add(newExerciseUC());  
  13.         tabPages[6].Controls.Add(newOtherUC());  
  14.     }  
  15. }  
Now let us take a look into the data access assembly. Below is the screenshot which shows the domain level entities. If you take a close look into each of these classes, they are built as per the requirement. As and when you have more application features, feel free add necessary domain level entities.

entity

Here’s the code snippet for “PatientWeightAssessment.” It has composed objects for gathering all the assessment related information.
  1. public class PatientWeightAssessment  
  2. {  
  3.     public PatientWeightAssessment()   
  4.     {  
  5.         GeneralInfo = new General();  
  6.         HistoryOfInfo = new HistoryOf();  
  7.         MedicalHistoryInfo = new MedicalHistory();  
  8.         NutritionInfo = new Nutrition();  
  9.         OverAllHealthInfo = new OverAllHealth();  
  10.         ExerciseInfo = new Exercise();  
  11.         OtherInfo = new Other();  
  12.     }  
  13.   
  14.     public General GeneralInfo   
  15.     {  
  16.         get;  
  17.         set;  
  18.     }  
  19.     public HistoryOf HistoryOfInfo   
  20.     {  
  21.         get;  
  22.         set;  
  23.     }  
  24.     public MedicalHistory MedicalHistoryInfo   
  25.     {  
  26.         get;  
  27.         set;  
  28.     }  
  29.     public Nutrition NutritionInfo   
  30.     {  
  31.         get;  
  32.         set;  
  33.     }  
  34.     public OverAllHealthOverAllHealthInfo   
  35.     {  
  36.         get;  
  37.         set;  
  38.     }  
  39.     public ExerciseExerciseInfo   
  40.     {  
  41.         get;  
  42.         set;  
  43.     }  
  44.     public OtherOtherInfo   
  45.     {  
  46.         get;  
  47.         set;  
  48.     }  
  49. }  
General Info

Below is the code snippet for gathering the general info. First we have to get the user control instance from the tab page. Then we are going to access all the UI elements of the user control.

  1. var generalInfoUC = (GeneralUC) tabPages[0].Controls[0];  
  2.   
  3. // General Info  
  4. var generalInfo = patientWeightAssessment.GeneralInfo;  
  5. generalInfo.PatientName = generalInfoUC.txtGeneralName.Text.Trim();  
  6. generalInfo.DOB = generalInfoUC.dtGeneralDOB.Value.ToShortDateString();  
  7. generalInfo.Height = generalInfoUC.txtGeneralHeight.Text.Trim();  
  8. generalInfo.Weight = generalInfoUC.txtGeneralWeight.Text.Trim();  
  9. generalInfo.Race = generalInfoUC.txtGeneralRace.Text.Trim();  
  10.   
  11. if (generalInfoUC.rbMale.Checked)  
  12.     generalInfo.Gender = "Male";  
  13. else if(generalInfoUC.rbFemale.Checked)  
  14. generalInfo.Gender = "Female";  
  15. else  
  16.     generalInfo.Gender = "Unknown";  
  17.   
  18. generalInfo.Phone = generalInfoUC.txtGeneralPhone.Text.Trim();  
assesment

Medical History Info

Below is the code snippet and screenshot for gathering the medical history info.
  1. var medicalHistoryInfoUC = (MedicalHistoryUC)tabPages[1].Controls[0];  
  2. var medicalHistoryInfo = patientWeightAssessment.MedicalHistoryInfo;  
  3.   
  4. medicalHistoryInfo.DateOfLastCheckUp = medicalHistoryInfoUC.dtCheckUp.Value.ToShortDateString();  
  5. medicalHistoryInfo.Allegies = medicalHistoryInfoUC.txtMedicalAllergies.Text.Trim();  
  6. medicalHistoryInfo.BloodPressure = medicalHistoryInfoUC.txtMedicalBloodPressure.Text.Trim();  
  7. medicalHistoryInfo.Cholesterol = medicalHistoryInfoUC.txtMedicalCholestrol.Text.Trim();  
  8. medicalHistoryInfo.Injuries = medicalHistoryInfoUC.txtMedicalInjuries.Text.Trim();  
  9. medicalHistoryInfo.PreviousMedications = medicalHistoryInfoUC.txtMedicalPreviousMedications.Text.Trim();  
  10. medicalHistoryInfo.Surguries = medicalHistoryInfoUC.txtMedicalSurgeries.Text.Trim();  
assesment

History Info

Below is the code snippet for gathering the “History Of” information.
  1. var historyOfInfoUC = (HistoryOfUC) tabPages[2].Controls[0];  
  2.   
  3. var historyOfInfo = patientWeightAssessment.HistoryOfInfo;  
  4. historyOfInfo.Cancer = newHowItsRelated  
  5. {  
  6.     Me = historyOfInfoUC.chkHistoryOfCancerMe.Checked,  
  7.         IsRelation = historyOfInfoUC.chkHistoryOfCancerRelation.Checked,  
  8.         Relation = historyOfInfoUC.txtHistoryOfCancer.Text.Trim()  
  9. };  
  10. historyOfInfo.Diabetes = newHowItsRelated  
  11. {  
  12.     Me = historyOfInfoUC.chkHistoryOfDiabetes.Checked,  
  13.         IsRelation = historyOfInfoUC.chkHistoryOfDiabetesRelation.Checked,  
  14.         Relation = historyOfInfoUC.txtHistoryOfDiabetes.Text.Trim()  
  15. };  
  16. historyOfInfo.Stroke = newHowItsRelated  
  17. {  
  18.     Me = historyOfInfoUC.chkHistoryOfStroke.Checked,  
  19.         IsRelation = historyOfInfoUC.chkHistoryOfStrokeRelation.Checked,  
  20.         Relation = historyOfInfoUC.txtHistoryOfStroke.Text.Trim()  
  21. };  
  22. historyOfInfo.HeartDisease = newHowItsRelated  
  23. {  
  24.     Me = historyOfInfoUC.chkHistoryOfHeartDisease.Checked,  
  25.         IsRelation = historyOfInfoUC.chkHistoryOfHeartDiseaseRelation.Checked,  
  26.         Relation = historyOfInfoUC.txtHistoryOfHeartDisease.Text.Trim()  
  27. };  
  28. historyOfInfo.HeartAttack = newHowItsRelated  
  29. {  
  30.     Me = historyOfInfoUC.chkHistoryOfHeartAttack.Checked,  
  31.         IsRelation = historyOfInfoUC.chkHistoryOfHeartAttackRelation.Checked,  
  32.         Relation = historyOfInfoUC.txtHistoryOfHeartAttack.Text.Trim()  
  33. };  
  34. historyOfInfo.Depression = newHowItsRelated  
  35. {  
  36.     Me = historyOfInfoUC.chkHistoryOfDepression.Checked,  
  37.         IsRelation = historyOfInfoUC.chkHistoryOfDepressionRelation.Checked,  
  38.         Relation = historyOfInfoUC.txtHistoryOfDepression.Text.Trim()  
  39. };  
  40. historyOfInfo.BipolarDisorder = newHowItsRelated   
  41. {  
  42.     Me = historyOfInfoUC.chkHistoryOfBipolarDisorder.Checked,  
  43.         IsRelation = historyOfInfoUC.chkHistoryOfBipolarDisorderRelation.Checked,  
  44.         Relation = historyOfInfoUC.txtHistoryOfBipolarDisorder.Text.Trim()  
  45. };  
  46. historyOfInfo.Headaches = newHowItsRelated   
  47. {  
  48.     Me = historyOfInfoUC.chkHistoryOfHeadaches.Checked,  
  49.         IsRelation = historyOfInfoUC.chkHistoryOfHeadachesRelation.Checked,  
  50.         Relation = historyOfInfoUC.txtHistoryOfHeadaches.Text.Trim()  
  51. };  
  52. historyOfInfo.Constipation = newHowItsRelated   
  53. {  
  54.     Me = historyOfInfoUC.chkHistoryOfConstipation.Checked,  
  55.         IsRelation = historyOfInfoUC.chkHistoryOfConstipationRelation.Checked,  
  56.         Relation = historyOfInfoUC.txtHistoryOfConstipation.Text.Trim()  
  57. };  
  58. historyOfInfo.SleepDisorders = newHowItsRelated   
  59. {  
  60.     Me = historyOfInfoUC.chkHistoryOfSleepDisorders.Checked,  
  61.         IsRelation = historyOfInfoUC.chkHistoryOfSleepDisordersRelation.Checked,  
  62.         Relation = historyOfInfoUC.txtHistoryOfSleepDisorders.Text.Trim()  
  63. };  
  64. historyOfInfo.Obesity = newHowItsRelated   
  65. {  
  66.     Me = historyOfInfoUC.chkHistoryOfObesity.Checked,  
  67.         IsRelation = historyOfInfoUC.chkHistoryOfObesityRelation.Checked,  
  68.         Relation = historyOfInfoUC.txtHistoryOfObesity.Text.Trim()  
  69. };  
assesment

Overall Health Info

Below is the code snippet for gathering the Overall health info.
  1. var overAllHealthInfoUC = (OverAllHealthUC)tabPages[3].Controls[0];  
  2. var overAllHealthInfo = patientWeightAssessment.OverAllHealthInfo;  
  3.   
  4. overAllHealthInfo.OverAllHealthRating = (HealthRatingEnum)Enum.Parse(typeof(HealthRatingEnum), overAllHealthInfoUC.cbOverAllHealthRate.SelectedValue.ToString());  
  5. overAllHealthInfo.HowOftenDepressed = (DepressionEnum)Enum.Parse(typeof(DepressionEnum), overAllHealthInfoUC.cbFeelDepressed.SelectedValue.ToString());  
  6. overAllHealthInfo.HowOftenExcercise = (ExerciseEnum)Enum.Parse(typeof(ExerciseEnum), overAllHealthInfoUC.cbExercise.SelectedValue.ToString());  
  7. overAllHealthInfo.HowOftenSmoke = (GeneralEnum)Enum.Parse(typeof(GeneralEnum), overAllHealthInfoUC.cbSmoke.SelectedValue.ToString());  
  8. overAllHealthInfo.HowOftenDrinkAlcohol = (GeneralEnum)Enum.Parse(typeof(GeneralEnum), overAllHealthInfoUC.cbDrinkAlcohol.SelectedValue.ToString());  
  9. overAllHealthInfo.HowOftenFastFood = (GeneralEnum)Enum.Parse(typeof(GeneralEnum), overAllHealthInfoUC.cbEatFastFood.SelectedValue.ToString());  
  10. overAllHealthInfo.HowOftenRestfulSleep = (SleepEnum)Enum.Parse(typeof(SleepEnum), overAllHealthInfoUC.cbRestfulSleep.SelectedValue.ToString());  
  11.   
  12. overAllHealthInfo.CigarettesPerDay = overAllHealthInfoUC.txtCigarettesPerDay.Text.Trim();  
  13. overAllHealthInfo.AlcoholsPerWeek = overAllHealthInfoUC.txtAlcoholPerWeek.Text.Trim();  
  14. overAllHealthInfo.HoursOfSleepPerNight = int.Parse(overAllHealthInfoUC.txtHoursOfSleepPerNight.Text.Trim());  
  15. overAllHealthInfo.CurrentMedication = overAllHealthInfoUC.txtCurrentMedication.Text.Trim();  
  16. overAllHealthInfo.StartingDate = overAllHealthInfoUC.dtStartingDate.Value.ToString();  
  17. overAllHealthInfo.DietaryRestrictions = overAllHealthInfoUC.txtDietaryRestrictions.Text.Trim();  
  18. overAllHealthInfo.HowOftenHeadaches = overAllHealthInfoUC.txtHowOftenHeadaches.Text.Trim();  
assesment

Nutrition Info

Below is the code snippet for gathering the nutrition information.
  1. var nutritionInfoUC = (NutritionUC)tabPages[4].Controls[0];  
  2. var nutritionInfo = patientWeightAssessment.NutritionInfo;  
  3.   
  4. nutritionInfo.Vegetables = (NutritionEnum)Enum.Parse(typeof(NutritionEnum), nutritionInfoUC.cmbNutritionVegetablesDoYouEat.SelectedValue.ToString());  
  5. nutritionInfo.Fruits = (NutritionEnum)Enum.Parse(typeof(NutritionEnum), nutritionInfoUC.cmbNutritionFruitsDoYouEat.SelectedValue.ToString());  
  6. nutritionInfo.Grains = (NutritionEnum)Enum.Parse(typeof(NutritionEnum), nutritionInfoUC.cmbNutritionGrainsDoYouEat.SelectedValue.ToString());  
  7. nutritionInfo.Meat = (NutritionEnum)Enum.Parse(typeof(NutritionEnum), nutritionInfoUC.cmbNutritionMeatDoYouEat.SelectedValue.ToString());  
  8. nutritionInfo.SugarOrCarbs = (NutritionEnum)Enum.Parse(typeof(NutritionEnum), nutritionInfoUC.cmbNutritionSugar.SelectedValue.ToString());  
  9. nutritionInfo.Snack = (SnackEnum)Enum.Parse(typeof(SnackEnum), nutritionInfoUC.cmbNutritionSnack.SelectedValue.ToString());  
  10. nutritionInfo.CoffeeTea = (DrinkEnum)Enum.Parse(typeof(DrinkEnum), nutritionInfoUC.cmbNutritionCoffeeTea.SelectedValue.ToString());  
  11. nutritionInfo.EatOut = (EatEnum)Enum.Parse(typeof(EatEnum), nutritionInfoUC.cmbNutritionEatOut.SelectedValue.ToString());  
  12. nutritionInfo.MealsPerDay = int.Parse(nutritionInfoUC.txtNutritionMealsPerDay.Text.Trim());  
  13. nutritionInfo.EatSameTime = nutritionInfoUC.cbNutritionEatSameTimeYes.Checked;  
  14. nutritionInfo.SkipMeal = nutritionInfoUC.cbNutritionSkipMealsYes.Checked;  
  15. nutritionInfo.CaloriesPerMeal = nutritionInfoUC.txtNutritionCaloriesEatPerMeal.Text.Trim();  
  16. nutritionInfo.CaloriesPerDay = nutritionInfoUC.txtNutritionCaloriesEatPerDay.Text.Trim();  
  17. nutritionInfo.ShopWithAGroceryList = nutritionInfoUC.cbNutritionShopWithAGroceryListYes.Checked;  
  18. nutritionInfo.PlanMealsInAdvance = nutritionInfoUC.cbNutrititionPlanMealsYes.Checked;  
  19. nutritionInfo.UseSugarOrButterSubstitutes = nutritionInfoUC.cbNutritionSugarYes.Checked;  
  20. nutritionInfo.DrinkDietSoda = nutritionInfoUC.cbNutritionDietSodaYes.Checked;  
  21. nutritionInfo.WakeupHungryAtNight = nutritionInfoUC.cbNutritionHungryAtNightYes.Checked;  
  22. nutritionInfo.WhenDoYouFeelHungriest = nutritionInfoUC.txtNutritionWhenYouFeelHungriest.Text.Trim();  
  23. nutritionInfo.SnackAtNight = nutritionInfoUC.cbNutritionSnackAtNightYes.Checked;  
  24. nutritionInfo.EatWhenStressedOrSad = nutritionInfoUC.cbNutritionEatWhenStressedYes.Checked;  
  25. nutritionInfo.StressedOrSad = nutritionInfoUC.cbNutritionCurrentlyStressedYes.Checked;  
  26. nutritionInfo.FoodsYouCrave = nutritionInfoUC.txtNutritionFoodsYouCarve.Text.Trim();  
  27. nutritionInfo.FoodsYouDislike = nutritionInfoUC.txtNutritionFoodsYouDislike.Text.Trim();  
assesment

Exercise Info

Below is the code snippet for gathering the “Exercise” info.
  1. var exerciseInfoUC = (ExerciseUC)tabPages[5].Controls[0];  
  2. var exerciseInfo = patientWeightAssessment.ExerciseInfo;  
  3. exerciseInfo.DaysPerWeekOnCardio = int.Parse(exerciseInfoUC.txtExercisePerWeekOnCardio.Text.Trim());  
  4. exerciseInfo.DaysPerWeekOnStrength = int.Parse(exerciseInfoUC.txtExercisePerWeekOnStrength.Text.Trim());  
  5. exerciseInfo.LengthOfTimeSpentOnCardio = int.Parse(exerciseInfoUC.txtExerciseTimeSpentOnCardio.Text.Trim());  
  6. exerciseInfo.LengthOfTimeSpentOnStrength = int.Parse(exerciseInfoUC.txtExerciseTimeSpentOnStrength.Text.Trim());  
  7. exerciseInfo.InjuriesOrConditionsInterfere = exerciseInfoUC.txtExerciseInjuriesOrConditions.Text.Trim();  
assesment
Other Info

Below is the code snippet for gathering the “Other Info”.
  1. var otherInfoUC = (OtherUC)tabPages[6].Controls[0];  
  2. var otherInfo = patientWeightAssessment.OtherInfo;  
  3.   
  4. otherInfo.WeightAtBirth = otherInfoUC.txtOtherWeightAtBirth.Text.Trim();  
  5. otherInfo.WeightFiveYearsAgo = otherInfoUC.txtOtherWeight5yrsAgo.Text.Trim();  
  6. otherInfo.WeightSixMonthAgo = otherInfoUC.txtOtherWeight6MonthsAgo.Text.Trim();  
  7. otherInfo.HeaviestWeight = otherInfoUC.txtOtherHeaviestWeight.Text.Trim();  
  8. otherInfo.HeaviestWeightAge = int.Parse(otherInfoUC.txtOtherHeaviestWeightAge.Text.Trim());  
  9. otherInfo.LightestWeight = otherInfoUC.txtOtherLightestWeight.Text.Trim();  
  10. otherInfo.LightestWeightAge = int.Parse(otherInfoUC.txtOtherLightestWeightAge.Text.Trim());  
  11. otherInfo.TargetWeight = otherInfoUC.txtOtherTargetWeight.Text.Trim();  
  12. otherInfo.EatingDisorders = otherInfoUC.txtOtherEatingDisorders.Text.Trim();  
  13. otherInfo.LengthOfTime = otherInfoUC.txtOtherLengthOfTime.Text.Trim();  
  14. otherInfo.WeightLossOrGainBegin = otherInfoUC.txtOtherWeightLossOrGainBegin.Text.Trim();  
  15. otherInfo.LiveWithOverweight = otherInfoUC.cbOtherLiveWithOverweightYes.Checked;  

assesment

Here’s the code for saving the patient weight assessment information. We are making a call to our DAO class passing in the domain level entity.
  1. var patientWeightAssessmentDao = newPatientWeightAssessmentDao(false);  
  2. patientWeightAssessmentDao.Save(patientWeightAssessment);  
Conclusion

Coming to the article conclusion, the code is near production ready. Feel free to tweak the code as per your needs. The latest code is also made open source in GitHub.
 
Read more articles on NoSQL (Open Source Database)


Similar Articles