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.
As you can see there are three projects, out of which two are class libraries.
- PatientWeightAssesment: A Windows Form Application for managing the patient assessment.
- PatientWeightAssesment.DataAccess: Contains domain level entities. Also has data access classes.
- 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.
- private void FrmPatientWeightAssessment_Load(object sender, EventArgs e)
- {
- tabControl = Controls.Find("tbPatientWeightAssessment", true);
- if (tabControl != null)
- {
- tabPages = ((TabControl) tabControl[0]).TabPages;
- tabPages[0].Controls.Add(newGeneralUC());
- tabPages[1].Controls.Add(newMedicalHistoryUC());
- tabPages[2].Controls.Add(newHistoryOfUC());
- tabPages[3].Controls.Add(newOverAllHealthUC());
- tabPages[4].Controls.Add(newNutritionUC());
- tabPages[5].Controls.Add(newExerciseUC());
- tabPages[6].Controls.Add(newOtherUC());
- }
- }
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.
Here’s the code snippet for “PatientWeightAssessment.” It has composed objects for gathering all the assessment related information.
- public class PatientWeightAssessment
- {
- public PatientWeightAssessment()
- {
- GeneralInfo = new General();
- HistoryOfInfo = new HistoryOf();
- MedicalHistoryInfo = new MedicalHistory();
- NutritionInfo = new Nutrition();
- OverAllHealthInfo = new OverAllHealth();
- ExerciseInfo = new Exercise();
- OtherInfo = new Other();
- }
-
- public General GeneralInfo
- {
- get;
- set;
- }
- public HistoryOf HistoryOfInfo
- {
- get;
- set;
- }
- public MedicalHistory MedicalHistoryInfo
- {
- get;
- set;
- }
- public Nutrition NutritionInfo
- {
- get;
- set;
- }
- public OverAllHealthOverAllHealthInfo
- {
- get;
- set;
- }
- public ExerciseExerciseInfo
- {
- get;
- set;
- }
- public OtherOtherInfo
- {
- get;
- set;
- }
- }
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.
- var generalInfoUC = (GeneralUC) tabPages[0].Controls[0];
-
-
- var generalInfo = patientWeightAssessment.GeneralInfo;
- generalInfo.PatientName = generalInfoUC.txtGeneralName.Text.Trim();
- generalInfo.DOB = generalInfoUC.dtGeneralDOB.Value.ToShortDateString();
- generalInfo.Height = generalInfoUC.txtGeneralHeight.Text.Trim();
- generalInfo.Weight = generalInfoUC.txtGeneralWeight.Text.Trim();
- generalInfo.Race = generalInfoUC.txtGeneralRace.Text.Trim();
-
- if (generalInfoUC.rbMale.Checked)
- generalInfo.Gender = "Male";
- else if(generalInfoUC.rbFemale.Checked)
- generalInfo.Gender = "Female";
- else
- generalInfo.Gender = "Unknown";
-
- generalInfo.Phone = generalInfoUC.txtGeneralPhone.Text.Trim();
Medical History Info
Below is the code snippet and screenshot for gathering the medical history info.
- var medicalHistoryInfoUC = (MedicalHistoryUC)tabPages[1].Controls[0];
- var medicalHistoryInfo = patientWeightAssessment.MedicalHistoryInfo;
-
- medicalHistoryInfo.DateOfLastCheckUp = medicalHistoryInfoUC.dtCheckUp.Value.ToShortDateString();
- medicalHistoryInfo.Allegies = medicalHistoryInfoUC.txtMedicalAllergies.Text.Trim();
- medicalHistoryInfo.BloodPressure = medicalHistoryInfoUC.txtMedicalBloodPressure.Text.Trim();
- medicalHistoryInfo.Cholesterol = medicalHistoryInfoUC.txtMedicalCholestrol.Text.Trim();
- medicalHistoryInfo.Injuries = medicalHistoryInfoUC.txtMedicalInjuries.Text.Trim();
- medicalHistoryInfo.PreviousMedications = medicalHistoryInfoUC.txtMedicalPreviousMedications.Text.Trim();
- medicalHistoryInfo.Surguries = medicalHistoryInfoUC.txtMedicalSurgeries.Text.Trim();
History Info
Below is the code snippet for gathering the “History Of” information.
- var historyOfInfoUC = (HistoryOfUC) tabPages[2].Controls[0];
-
- var historyOfInfo = patientWeightAssessment.HistoryOfInfo;
- historyOfInfo.Cancer = newHowItsRelated
- {
- Me = historyOfInfoUC.chkHistoryOfCancerMe.Checked,
- IsRelation = historyOfInfoUC.chkHistoryOfCancerRelation.Checked,
- Relation = historyOfInfoUC.txtHistoryOfCancer.Text.Trim()
- };
- historyOfInfo.Diabetes = newHowItsRelated
- {
- Me = historyOfInfoUC.chkHistoryOfDiabetes.Checked,
- IsRelation = historyOfInfoUC.chkHistoryOfDiabetesRelation.Checked,
- Relation = historyOfInfoUC.txtHistoryOfDiabetes.Text.Trim()
- };
- historyOfInfo.Stroke = newHowItsRelated
- {
- Me = historyOfInfoUC.chkHistoryOfStroke.Checked,
- IsRelation = historyOfInfoUC.chkHistoryOfStrokeRelation.Checked,
- Relation = historyOfInfoUC.txtHistoryOfStroke.Text.Trim()
- };
- historyOfInfo.HeartDisease = newHowItsRelated
- {
- Me = historyOfInfoUC.chkHistoryOfHeartDisease.Checked,
- IsRelation = historyOfInfoUC.chkHistoryOfHeartDiseaseRelation.Checked,
- Relation = historyOfInfoUC.txtHistoryOfHeartDisease.Text.Trim()
- };
- historyOfInfo.HeartAttack = newHowItsRelated
- {
- Me = historyOfInfoUC.chkHistoryOfHeartAttack.Checked,
- IsRelation = historyOfInfoUC.chkHistoryOfHeartAttackRelation.Checked,
- Relation = historyOfInfoUC.txtHistoryOfHeartAttack.Text.Trim()
- };
- historyOfInfo.Depression = newHowItsRelated
- {
- Me = historyOfInfoUC.chkHistoryOfDepression.Checked,
- IsRelation = historyOfInfoUC.chkHistoryOfDepressionRelation.Checked,
- Relation = historyOfInfoUC.txtHistoryOfDepression.Text.Trim()
- };
- historyOfInfo.BipolarDisorder = newHowItsRelated
- {
- Me = historyOfInfoUC.chkHistoryOfBipolarDisorder.Checked,
- IsRelation = historyOfInfoUC.chkHistoryOfBipolarDisorderRelation.Checked,
- Relation = historyOfInfoUC.txtHistoryOfBipolarDisorder.Text.Trim()
- };
- historyOfInfo.Headaches = newHowItsRelated
- {
- Me = historyOfInfoUC.chkHistoryOfHeadaches.Checked,
- IsRelation = historyOfInfoUC.chkHistoryOfHeadachesRelation.Checked,
- Relation = historyOfInfoUC.txtHistoryOfHeadaches.Text.Trim()
- };
- historyOfInfo.Constipation = newHowItsRelated
- {
- Me = historyOfInfoUC.chkHistoryOfConstipation.Checked,
- IsRelation = historyOfInfoUC.chkHistoryOfConstipationRelation.Checked,
- Relation = historyOfInfoUC.txtHistoryOfConstipation.Text.Trim()
- };
- historyOfInfo.SleepDisorders = newHowItsRelated
- {
- Me = historyOfInfoUC.chkHistoryOfSleepDisorders.Checked,
- IsRelation = historyOfInfoUC.chkHistoryOfSleepDisordersRelation.Checked,
- Relation = historyOfInfoUC.txtHistoryOfSleepDisorders.Text.Trim()
- };
- historyOfInfo.Obesity = newHowItsRelated
- {
- Me = historyOfInfoUC.chkHistoryOfObesity.Checked,
- IsRelation = historyOfInfoUC.chkHistoryOfObesityRelation.Checked,
- Relation = historyOfInfoUC.txtHistoryOfObesity.Text.Trim()
- };
Overall Health Info
Below is the code snippet for gathering the Overall health info.
- var overAllHealthInfoUC = (OverAllHealthUC)tabPages[3].Controls[0];
- var overAllHealthInfo = patientWeightAssessment.OverAllHealthInfo;
-
- overAllHealthInfo.OverAllHealthRating = (HealthRatingEnum)Enum.Parse(typeof(HealthRatingEnum), overAllHealthInfoUC.cbOverAllHealthRate.SelectedValue.ToString());
- overAllHealthInfo.HowOftenDepressed = (DepressionEnum)Enum.Parse(typeof(DepressionEnum), overAllHealthInfoUC.cbFeelDepressed.SelectedValue.ToString());
- overAllHealthInfo.HowOftenExcercise = (ExerciseEnum)Enum.Parse(typeof(ExerciseEnum), overAllHealthInfoUC.cbExercise.SelectedValue.ToString());
- overAllHealthInfo.HowOftenSmoke = (GeneralEnum)Enum.Parse(typeof(GeneralEnum), overAllHealthInfoUC.cbSmoke.SelectedValue.ToString());
- overAllHealthInfo.HowOftenDrinkAlcohol = (GeneralEnum)Enum.Parse(typeof(GeneralEnum), overAllHealthInfoUC.cbDrinkAlcohol.SelectedValue.ToString());
- overAllHealthInfo.HowOftenFastFood = (GeneralEnum)Enum.Parse(typeof(GeneralEnum), overAllHealthInfoUC.cbEatFastFood.SelectedValue.ToString());
- overAllHealthInfo.HowOftenRestfulSleep = (SleepEnum)Enum.Parse(typeof(SleepEnum), overAllHealthInfoUC.cbRestfulSleep.SelectedValue.ToString());
-
- overAllHealthInfo.CigarettesPerDay = overAllHealthInfoUC.txtCigarettesPerDay.Text.Trim();
- overAllHealthInfo.AlcoholsPerWeek = overAllHealthInfoUC.txtAlcoholPerWeek.Text.Trim();
- overAllHealthInfo.HoursOfSleepPerNight = int.Parse(overAllHealthInfoUC.txtHoursOfSleepPerNight.Text.Trim());
- overAllHealthInfo.CurrentMedication = overAllHealthInfoUC.txtCurrentMedication.Text.Trim();
- overAllHealthInfo.StartingDate = overAllHealthInfoUC.dtStartingDate.Value.ToString();
- overAllHealthInfo.DietaryRestrictions = overAllHealthInfoUC.txtDietaryRestrictions.Text.Trim();
- overAllHealthInfo.HowOftenHeadaches = overAllHealthInfoUC.txtHowOftenHeadaches.Text.Trim();
Nutrition Info
Below is the code snippet for gathering the nutrition information.
- var nutritionInfoUC = (NutritionUC)tabPages[4].Controls[0];
- var nutritionInfo = patientWeightAssessment.NutritionInfo;
-
- nutritionInfo.Vegetables = (NutritionEnum)Enum.Parse(typeof(NutritionEnum), nutritionInfoUC.cmbNutritionVegetablesDoYouEat.SelectedValue.ToString());
- nutritionInfo.Fruits = (NutritionEnum)Enum.Parse(typeof(NutritionEnum), nutritionInfoUC.cmbNutritionFruitsDoYouEat.SelectedValue.ToString());
- nutritionInfo.Grains = (NutritionEnum)Enum.Parse(typeof(NutritionEnum), nutritionInfoUC.cmbNutritionGrainsDoYouEat.SelectedValue.ToString());
- nutritionInfo.Meat = (NutritionEnum)Enum.Parse(typeof(NutritionEnum), nutritionInfoUC.cmbNutritionMeatDoYouEat.SelectedValue.ToString());
- nutritionInfo.SugarOrCarbs = (NutritionEnum)Enum.Parse(typeof(NutritionEnum), nutritionInfoUC.cmbNutritionSugar.SelectedValue.ToString());
- nutritionInfo.Snack = (SnackEnum)Enum.Parse(typeof(SnackEnum), nutritionInfoUC.cmbNutritionSnack.SelectedValue.ToString());
- nutritionInfo.CoffeeTea = (DrinkEnum)Enum.Parse(typeof(DrinkEnum), nutritionInfoUC.cmbNutritionCoffeeTea.SelectedValue.ToString());
- nutritionInfo.EatOut = (EatEnum)Enum.Parse(typeof(EatEnum), nutritionInfoUC.cmbNutritionEatOut.SelectedValue.ToString());
- nutritionInfo.MealsPerDay = int.Parse(nutritionInfoUC.txtNutritionMealsPerDay.Text.Trim());
- nutritionInfo.EatSameTime = nutritionInfoUC.cbNutritionEatSameTimeYes.Checked;
- nutritionInfo.SkipMeal = nutritionInfoUC.cbNutritionSkipMealsYes.Checked;
- nutritionInfo.CaloriesPerMeal = nutritionInfoUC.txtNutritionCaloriesEatPerMeal.Text.Trim();
- nutritionInfo.CaloriesPerDay = nutritionInfoUC.txtNutritionCaloriesEatPerDay.Text.Trim();
- nutritionInfo.ShopWithAGroceryList = nutritionInfoUC.cbNutritionShopWithAGroceryListYes.Checked;
- nutritionInfo.PlanMealsInAdvance = nutritionInfoUC.cbNutrititionPlanMealsYes.Checked;
- nutritionInfo.UseSugarOrButterSubstitutes = nutritionInfoUC.cbNutritionSugarYes.Checked;
- nutritionInfo.DrinkDietSoda = nutritionInfoUC.cbNutritionDietSodaYes.Checked;
- nutritionInfo.WakeupHungryAtNight = nutritionInfoUC.cbNutritionHungryAtNightYes.Checked;
- nutritionInfo.WhenDoYouFeelHungriest = nutritionInfoUC.txtNutritionWhenYouFeelHungriest.Text.Trim();
- nutritionInfo.SnackAtNight = nutritionInfoUC.cbNutritionSnackAtNightYes.Checked;
- nutritionInfo.EatWhenStressedOrSad = nutritionInfoUC.cbNutritionEatWhenStressedYes.Checked;
- nutritionInfo.StressedOrSad = nutritionInfoUC.cbNutritionCurrentlyStressedYes.Checked;
- nutritionInfo.FoodsYouCrave = nutritionInfoUC.txtNutritionFoodsYouCarve.Text.Trim();
- nutritionInfo.FoodsYouDislike = nutritionInfoUC.txtNutritionFoodsYouDislike.Text.Trim();
Exercise Info
Below is the code snippet for gathering the “Exercise” info.
- var exerciseInfoUC = (ExerciseUC)tabPages[5].Controls[0];
- var exerciseInfo = patientWeightAssessment.ExerciseInfo;
- exerciseInfo.DaysPerWeekOnCardio = int.Parse(exerciseInfoUC.txtExercisePerWeekOnCardio.Text.Trim());
- exerciseInfo.DaysPerWeekOnStrength = int.Parse(exerciseInfoUC.txtExercisePerWeekOnStrength.Text.Trim());
- exerciseInfo.LengthOfTimeSpentOnCardio = int.Parse(exerciseInfoUC.txtExerciseTimeSpentOnCardio.Text.Trim());
- exerciseInfo.LengthOfTimeSpentOnStrength = int.Parse(exerciseInfoUC.txtExerciseTimeSpentOnStrength.Text.Trim());
- exerciseInfo.InjuriesOrConditionsInterfere = exerciseInfoUC.txtExerciseInjuriesOrConditions.Text.Trim();
Other Info
Below is the code snippet for gathering the “Other Info”.
- var otherInfoUC = (OtherUC)tabPages[6].Controls[0];
- var otherInfo = patientWeightAssessment.OtherInfo;
-
- otherInfo.WeightAtBirth = otherInfoUC.txtOtherWeightAtBirth.Text.Trim();
- otherInfo.WeightFiveYearsAgo = otherInfoUC.txtOtherWeight5yrsAgo.Text.Trim();
- otherInfo.WeightSixMonthAgo = otherInfoUC.txtOtherWeight6MonthsAgo.Text.Trim();
- otherInfo.HeaviestWeight = otherInfoUC.txtOtherHeaviestWeight.Text.Trim();
- otherInfo.HeaviestWeightAge = int.Parse(otherInfoUC.txtOtherHeaviestWeightAge.Text.Trim());
- otherInfo.LightestWeight = otherInfoUC.txtOtherLightestWeight.Text.Trim();
- otherInfo.LightestWeightAge = int.Parse(otherInfoUC.txtOtherLightestWeightAge.Text.Trim());
- otherInfo.TargetWeight = otherInfoUC.txtOtherTargetWeight.Text.Trim();
- otherInfo.EatingDisorders = otherInfoUC.txtOtherEatingDisorders.Text.Trim();
- otherInfo.LengthOfTime = otherInfoUC.txtOtherLengthOfTime.Text.Trim();
- otherInfo.WeightLossOrGainBegin = otherInfoUC.txtOtherWeightLossOrGainBegin.Text.Trim();
- otherInfo.LiveWithOverweight = otherInfoUC.cbOtherLiveWithOverweightYes.Checked;
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.
- var patientWeightAssessmentDao = newPatientWeightAssessmentDao(false);
- 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)