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. public General GeneralInfo
  14. {
  15. get;
  16. set;
  17. }
  18. public HistoryOf HistoryOfInfo
  19. {
  20. get;
  21. set;
  22. }
  23. public MedicalHistory MedicalHistoryInfo
  24. {
  25. get;
  26. set;
  27. }
  28. public Nutrition NutritionInfo
  29. {
  30. get;
  31. set;
  32. }
  33. public OverAllHealthOverAllHealthInfo
  34. {
  35. get;
  36. set;
  37. }
  38. public ExerciseExerciseInfo
  39. {
  40. get;
  41. set;
  42. }
  43. public OtherOtherInfo
  44. {
  45. get;
  46. set;
  47. }
  48. }
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. // General Info
  3. var generalInfo = patientWeightAssessment.GeneralInfo;
  4. generalInfo.PatientName = generalInfoUC.txtGeneralName.Text.Trim();
  5. generalInfo.DOB = generalInfoUC.dtGeneralDOB.Value.ToShortDateString();
  6. generalInfo.Height = generalInfoUC.txtGeneralHeight.Text.Trim();
  7. generalInfo.Weight = generalInfoUC.txtGeneralWeight.Text.Trim();
  8. generalInfo.Race = generalInfoUC.txtGeneralRace.Text.Trim();
  9. if (generalInfoUC.rbMale.Checked)
  10. generalInfo.Gender = "Male";
  11. else if(generalInfoUC.rbFemale.Checked)
  12. generalInfo.Gender = "Female";
  13. else
  14. generalInfo.Gender = "Unknown";
  15. 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. medicalHistoryInfo.DateOfLastCheckUp = medicalHistoryInfoUC.dtCheckUp.Value.ToShortDateString();
  4. medicalHistoryInfo.Allegies = medicalHistoryInfoUC.txtMedicalAllergies.Text.Trim();
  5. medicalHistoryInfo.BloodPressure = medicalHistoryInfoUC.txtMedicalBloodPressure.Text.Trim();
  6. medicalHistoryInfo.Cholesterol = medicalHistoryInfoUC.txtMedicalCholestrol.Text.Trim();
  7. medicalHistoryInfo.Injuries = medicalHistoryInfoUC.txtMedicalInjuries.Text.Trim();
  8. medicalHistoryInfo.PreviousMedications = medicalHistoryInfoUC.txtMedicalPreviousMedications.Text.Trim();
  9. 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. var historyOfInfo = patientWeightAssessment.HistoryOfInfo;
  3. historyOfInfo.Cancer = newHowItsRelated
  4. {
  5. Me = historyOfInfoUC.chkHistoryOfCancerMe.Checked,
  6. IsRelation = historyOfInfoUC.chkHistoryOfCancerRelation.Checked,
  7. Relation = historyOfInfoUC.txtHistoryOfCancer.Text.Trim()
  8. };
  9. historyOfInfo.Diabetes = newHowItsRelated
  10. {
  11. Me = historyOfInfoUC.chkHistoryOfDiabetes.Checked,
  12. IsRelation = historyOfInfoUC.chkHistoryOfDiabetesRelation.Checked,
  13. Relation = historyOfInfoUC.txtHistoryOfDiabetes.Text.Trim()
  14. };
  15. historyOfInfo.Stroke = newHowItsRelated
  16. {
  17. Me = historyOfInfoUC.chkHistoryOfStroke.Checked,
  18. IsRelation = historyOfInfoUC.chkHistoryOfStrokeRelation.Checked,
  19. Relation = historyOfInfoUC.txtHistoryOfStroke.Text.Trim()
  20. };
  21. historyOfInfo.HeartDisease = newHowItsRelated
  22. {
  23. Me = historyOfInfoUC.chkHistoryOfHeartDisease.Checked,
  24. IsRelation = historyOfInfoUC.chkHistoryOfHeartDiseaseRelation.Checked,
  25. Relation = historyOfInfoUC.txtHistoryOfHeartDisease.Text.Trim()
  26. };
  27. historyOfInfo.HeartAttack = newHowItsRelated
  28. {
  29. Me = historyOfInfoUC.chkHistoryOfHeartAttack.Checked,
  30. IsRelation = historyOfInfoUC.chkHistoryOfHeartAttackRelation.Checked,
  31. Relation = historyOfInfoUC.txtHistoryOfHeartAttack.Text.Trim()
  32. };
  33. historyOfInfo.Depression = newHowItsRelated
  34. {
  35. Me = historyOfInfoUC.chkHistoryOfDepression.Checked,
  36. IsRelation = historyOfInfoUC.chkHistoryOfDepressionRelation.Checked,
  37. Relation = historyOfInfoUC.txtHistoryOfDepression.Text.Trim()
  38. };
  39. historyOfInfo.BipolarDisorder = newHowItsRelated
  40. {
  41. Me = historyOfInfoUC.chkHistoryOfBipolarDisorder.Checked,
  42. IsRelation = historyOfInfoUC.chkHistoryOfBipolarDisorderRelation.Checked,
  43. Relation = historyOfInfoUC.txtHistoryOfBipolarDisorder.Text.Trim()
  44. };
  45. historyOfInfo.Headaches = newHowItsRelated
  46. {
  47. Me = historyOfInfoUC.chkHistoryOfHeadaches.Checked,
  48. IsRelation = historyOfInfoUC.chkHistoryOfHeadachesRelation.Checked,
  49. Relation = historyOfInfoUC.txtHistoryOfHeadaches.Text.Trim()
  50. };
  51. historyOfInfo.Constipation = newHowItsRelated
  52. {
  53. Me = historyOfInfoUC.chkHistoryOfConstipation.Checked,
  54. IsRelation = historyOfInfoUC.chkHistoryOfConstipationRelation.Checked,
  55. Relation = historyOfInfoUC.txtHistoryOfConstipation.Text.Trim()
  56. };
  57. historyOfInfo.SleepDisorders = newHowItsRelated
  58. {
  59. Me = historyOfInfoUC.chkHistoryOfSleepDisorders.Checked,
  60. IsRelation = historyOfInfoUC.chkHistoryOfSleepDisordersRelation.Checked,
  61. Relation = historyOfInfoUC.txtHistoryOfSleepDisorders.Text.Trim()
  62. };
  63. historyOfInfo.Obesity = newHowItsRelated
  64. {
  65. Me = historyOfInfoUC.chkHistoryOfObesity.Checked,
  66. IsRelation = historyOfInfoUC.chkHistoryOfObesityRelation.Checked,
  67. Relation = historyOfInfoUC.txtHistoryOfObesity.Text.Trim()
  68. };
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. overAllHealthInfo.OverAllHealthRating = (HealthRatingEnum)Enum.Parse(typeof(HealthRatingEnum), overAllHealthInfoUC.cbOverAllHealthRate.SelectedValue.ToString());
  4. overAllHealthInfo.HowOftenDepressed = (DepressionEnum)Enum.Parse(typeof(DepressionEnum), overAllHealthInfoUC.cbFeelDepressed.SelectedValue.ToString());
  5. overAllHealthInfo.HowOftenExcercise = (ExerciseEnum)Enum.Parse(typeof(ExerciseEnum), overAllHealthInfoUC.cbExercise.SelectedValue.ToString());
  6. overAllHealthInfo.HowOftenSmoke = (GeneralEnum)Enum.Parse(typeof(GeneralEnum), overAllHealthInfoUC.cbSmoke.SelectedValue.ToString());
  7. overAllHealthInfo.HowOftenDrinkAlcohol = (GeneralEnum)Enum.Parse(typeof(GeneralEnum), overAllHealthInfoUC.cbDrinkAlcohol.SelectedValue.ToString());
  8. overAllHealthInfo.HowOftenFastFood = (GeneralEnum)Enum.Parse(typeof(GeneralEnum), overAllHealthInfoUC.cbEatFastFood.SelectedValue.ToString());
  9. overAllHealthInfo.HowOftenRestfulSleep = (SleepEnum)Enum.Parse(typeof(SleepEnum), overAllHealthInfoUC.cbRestfulSleep.SelectedValue.ToString());
  10. overAllHealthInfo.CigarettesPerDay = overAllHealthInfoUC.txtCigarettesPerDay.Text.Trim();
  11. overAllHealthInfo.AlcoholsPerWeek = overAllHealthInfoUC.txtAlcoholPerWeek.Text.Trim();
  12. overAllHealthInfo.HoursOfSleepPerNight = int.Parse(overAllHealthInfoUC.txtHoursOfSleepPerNight.Text.Trim());
  13. overAllHealthInfo.CurrentMedication = overAllHealthInfoUC.txtCurrentMedication.Text.Trim();
  14. overAllHealthInfo.StartingDate = overAllHealthInfoUC.dtStartingDate.Value.ToString();
  15. overAllHealthInfo.DietaryRestrictions = overAllHealthInfoUC.txtDietaryRestrictions.Text.Trim();
  16. 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. nutritionInfo.Vegetables = (NutritionEnum)Enum.Parse(typeof(NutritionEnum), nutritionInfoUC.cmbNutritionVegetablesDoYouEat.SelectedValue.ToString());
  4. nutritionInfo.Fruits = (NutritionEnum)Enum.Parse(typeof(NutritionEnum), nutritionInfoUC.cmbNutritionFruitsDoYouEat.SelectedValue.ToString());
  5. nutritionInfo.Grains = (NutritionEnum)Enum.Parse(typeof(NutritionEnum), nutritionInfoUC.cmbNutritionGrainsDoYouEat.SelectedValue.ToString());
  6. nutritionInfo.Meat = (NutritionEnum)Enum.Parse(typeof(NutritionEnum), nutritionInfoUC.cmbNutritionMeatDoYouEat.SelectedValue.ToString());
  7. nutritionInfo.SugarOrCarbs = (NutritionEnum)Enum.Parse(typeof(NutritionEnum), nutritionInfoUC.cmbNutritionSugar.SelectedValue.ToString());
  8. nutritionInfo.Snack = (SnackEnum)Enum.Parse(typeof(SnackEnum), nutritionInfoUC.cmbNutritionSnack.SelectedValue.ToString());
  9. nutritionInfo.CoffeeTea = (DrinkEnum)Enum.Parse(typeof(DrinkEnum), nutritionInfoUC.cmbNutritionCoffeeTea.SelectedValue.ToString());
  10. nutritionInfo.EatOut = (EatEnum)Enum.Parse(typeof(EatEnum), nutritionInfoUC.cmbNutritionEatOut.SelectedValue.ToString());
  11. nutritionInfo.MealsPerDay = int.Parse(nutritionInfoUC.txtNutritionMealsPerDay.Text.Trim());
  12. nutritionInfo.EatSameTime = nutritionInfoUC.cbNutritionEatSameTimeYes.Checked;
  13. nutritionInfo.SkipMeal = nutritionInfoUC.cbNutritionSkipMealsYes.Checked;
  14. nutritionInfo.CaloriesPerMeal = nutritionInfoUC.txtNutritionCaloriesEatPerMeal.Text.Trim();
  15. nutritionInfo.CaloriesPerDay = nutritionInfoUC.txtNutritionCaloriesEatPerDay.Text.Trim();
  16. nutritionInfo.ShopWithAGroceryList = nutritionInfoUC.cbNutritionShopWithAGroceryListYes.Checked;
  17. nutritionInfo.PlanMealsInAdvance = nutritionInfoUC.cbNutrititionPlanMealsYes.Checked;
  18. nutritionInfo.UseSugarOrButterSubstitutes = nutritionInfoUC.cbNutritionSugarYes.Checked;
  19. nutritionInfo.DrinkDietSoda = nutritionInfoUC.cbNutritionDietSodaYes.Checked;
  20. nutritionInfo.WakeupHungryAtNight = nutritionInfoUC.cbNutritionHungryAtNightYes.Checked;
  21. nutritionInfo.WhenDoYouFeelHungriest = nutritionInfoUC.txtNutritionWhenYouFeelHungriest.Text.Trim();
  22. nutritionInfo.SnackAtNight = nutritionInfoUC.cbNutritionSnackAtNightYes.Checked;
  23. nutritionInfo.EatWhenStressedOrSad = nutritionInfoUC.cbNutritionEatWhenStressedYes.Checked;
  24. nutritionInfo.StressedOrSad = nutritionInfoUC.cbNutritionCurrentlyStressedYes.Checked;
  25. nutritionInfo.FoodsYouCrave = nutritionInfoUC.txtNutritionFoodsYouCarve.Text.Trim();
  26. 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. otherInfo.WeightAtBirth = otherInfoUC.txtOtherWeightAtBirth.Text.Trim();
  4. otherInfo.WeightFiveYearsAgo = otherInfoUC.txtOtherWeight5yrsAgo.Text.Trim();
  5. otherInfo.WeightSixMonthAgo = otherInfoUC.txtOtherWeight6MonthsAgo.Text.Trim();
  6. otherInfo.HeaviestWeight = otherInfoUC.txtOtherHeaviestWeight.Text.Trim();
  7. otherInfo.HeaviestWeightAge = int.Parse(otherInfoUC.txtOtherHeaviestWeightAge.Text.Trim());
  8. otherInfo.LightestWeight = otherInfoUC.txtOtherLightestWeight.Text.Trim();
  9. otherInfo.LightestWeightAge = int.Parse(otherInfoUC.txtOtherLightestWeightAge.Text.Trim());
  10. otherInfo.TargetWeight = otherInfoUC.txtOtherTargetWeight.Text.Trim();
  11. otherInfo.EatingDisorders = otherInfoUC.txtOtherEatingDisorders.Text.Trim();
  12. otherInfo.LengthOfTime = otherInfoUC.txtOtherLengthOfTime.Text.Trim();
  13. otherInfo.WeightLossOrGainBegin = otherInfoUC.txtOtherWeightLossOrGainBegin.Text.Trim();
  14. 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)