/// <summary>
        /// Add allergy to the current patient
        /// </summary>
        /// <returns></returns>
        public JsonResult AddAllergyToPatient()
        {
            try
            {
                int patientId = int.Parse(Request.Form["PatientId"]);
                int allergyId = int.Parse(Request.Form["AllergyId"]);

                PatientRepository patientRepo = new PatientRepository();
                var patient = patientRepo.Get(patientId);

                PatientAllergyRepository patientAllergyRepo = new PatientAllergyRepository();
                AllergyRepository allergyRepo = new AllergyRepository();

                PatientAllergy pallergy = new PatientAllergy();
                pallergy.Allergy = allergyRepo.Get(allergyId);
                pallergy.Patient = patient;
                patientAllergyRepo.Add(pallergy);

                return Json(new
                {
                    error = "false",
                    status = "Added patient allergy successfully",
                    ID = pallergy.Id,
                    Name = pallergy.Allergy.Name
                });

            }
            catch (Exception e)
            {

                return Json(new
                {
                    error = "true",
                    status = "Unable to add patient allergy!",
                    errorMessage = e.Message
                });
            }
        }
        /// <summary>
        /// Remove allergy from patient
        /// </summary>
        /// <returns></returns>
        public JsonResult RemoveAllergy()
        {
            try
            {
                PatientAllergyRepository patientAllergyRepo = new PatientAllergyRepository();
                PatientRepository patientRepo = new PatientRepository();
                AllergyRepository allergyRepo = new AllergyRepository();

                var patientId = patientRepo.Get(int.Parse(Request.Form["patientID"]));
                var allergyId = allergyRepo.Get(int.Parse(Request.Form["allergyID"]));

                PatientAllergy pa = new PatientAllergy();

                pa.Allergy = allergyId;
                pa.Patient = patientId;

                patientAllergyRepo.Remove(pa);

                //UnitOfWork.CurrentSession.Flush();

                return Json(new
                {
                    error = "false",
                    status = "Allergy Deleted"
                });
            }
            catch (Exception e)
            {

                return Json(new
                {
                    error = "true",
                    status = "Unable to remove patient allergy!",
                    errorMessage = e.Message
                });
            }
        }
        public JsonResult EditAllergy()
        {
            try
            {
                AllergyRepository allergyRepo = new AllergyRepository();
                Allergy allergy = allergyRepo.Get(int.Parse(Request.Form["Allergy"]));
                allergy.Name = Request.Form["EditAllergy"];

                return Json(new {
                    error = "false"
                });
            }
            catch
            {
                return Json(new {
                    error = "true"
                });
            }
        }
        /// <summary>
        /// Create new allergy
        /// </summary>
        /// <returns></returns>
        public JsonResult CreateNewAllergy()
        {
            try
            {
                AllergyRepository allergy = new AllergyRepository();
                Allergy newAllergy = new Allergy();

                newAllergy.Name = Request.Form["AllergyName"];
                newAllergy.IsActive = true;

                allergy.Add(newAllergy);

                return Json(new
                {
                    error = false,
                    status = "Added new allergy successfully!",
                    newAllergy.Id,
                    newAllergy.Name
                });
            }
            catch (Exception e)
            {
                return Json(new
                {
                    error = "true",
                    status = "Unable to add allergy!",
                    errorMessage = e.Message
                });
            }
        }
        public JsonResult DeleteAllergy()
        {
            try
            {
                AllergyRepository allergyRepo = new AllergyRepository();
                allergyRepo.Remove(allergyRepo.Get(int.Parse(Request.Form["Allergy"])));

                return Json(new
                {
                    error = "false"
                });
            }
            catch
            {
                return Json(new
                {
                    error = "true"
                });
            }
        }