public ActionResult View(long id)
        {
            var nvm = new PatientViewModel();

            using(var c = new DataModelContext())
            {
                var patient = c.Patients.Find(id);
                if(patient == null)
                {
                    TempData["Alert"] = "The selected patient does not exist.";
                    return RedirectToAction("Index");
                }

                nvm.ID = patient.ID;
                nvm.FirstName = patient.FirstName;
                nvm.LastName = patient.LastName;
                nvm.Therapist = patient.Therapist;
                nvm.Doctor = patient.Doctor;
                nvm.LastUpdate = patient.LastUpdate;
                nvm.Start = patient.Start;
                nvm.Age = patient.Age;
                nvm.Birthday = patient.Birthday;
                nvm.Gender = patient.Gender;
                nvm.Height = patient.Height;
                nvm.Weight = patient.Weight;
                nvm.ArthritisType = patient.ArthritisType;
                nvm.AffectedExtremity = patient.AffectedExtremity;
                nvm.Deformity = patient.Deformity;
                nvm.ShankLength = patient.ShankLength;
                nvm.ThighLength = patient.ThighLength;
                nvm.Email = patient.Email;
                nvm.PhoneNumber = patient.PhoneNumber;
                nvm.City = patient.City;
                nvm.ContactName = patient.ContactName;
                nvm.ContactRelation = patient.ContactRelation;
                nvm.ContactPhoneNumber = patient.ContactPhoneNumber;
                nvm.ContactEmail = patient.ContactEmail;

                nvm.Report = patient.ReportResult;
                nvm.MedProfile = patient.MedProfile;

                DateTime dateOnly = nvm.Birthday.Date;
                nvm.BirthdayString = dateOnly.ToString("d");

                DateTime dateOnly2 = nvm.Start.Date;
                nvm.StartString = dateOnly2.ToString("d");

                DateTime dateOnly3 = nvm.Birthday.Date;
                nvm.BirthdayHtml = dateOnly3.ToString("yyyy-MM-dd");

                //var nameNet = network;
                //while(nameNet.Parent != null && nameNet.Name == null)
                //	nameNet = nameNet.Parent;
                //nvm.Name = nameNet.Name;

                if(patient.ReportResult == null)
                {
                    nvm.OutOfDate = false;
                    //nvm.Optimized = false;
                }
                else
                {
                    nvm.OutOfDate = patient.ReportResult.OutOfDate;
                    //nvm.Optimized = true;
                }
            }

            return View("View", nvm);
        }
        public ActionResult Report(long id)
        {
            var nvm = new PatientViewModel();

            using (var c = new DataModelContext())
            {
                User currentUser = UserDataEngine.getInstance().GetCurrentUser(c, HttpContext);

                var patient = c.Patients.Find(id);
                if (patient == null)
                {
                    TempData["Alert"] = "The selected patient does not exist.";
                    return RedirectToAction("Index");
                }

                nvm.ID = patient.ID;
                nvm.FirstName = patient.FirstName;
                nvm.LastName = patient.LastName;
                nvm.Therapist = patient.Therapist;
                nvm.Doctor = patient.Doctor;
                nvm.LastUpdate = patient.LastUpdate;
                nvm.ArthritisType = patient.ArthritisType;
                nvm.AffectedExtremity = patient.AffectedExtremity;
                nvm.Deformity = patient.Deformity;
                nvm.ShankLength = patient.ShankLength;
                nvm.ThighLength = patient.ThighLength;
                nvm.Report = patient.ReportResult;
                nvm.MedProfile = patient.MedProfile;

            }
            return View("Report", nvm);
        }
        public ActionResult Upload(IEnumerable<HttpPostedFileBase> files, PatientViewModel model)
        {
            var pvm = new PatientViewModel();
            long patientID = 0;

            //HttpFileCollection someFiles = files;
            //IEnumerable<HttpPostedFileBase> someFiles = files;

            //try
            //{
            //	patientDoc = XDocument.Load(Request.Files["PatientFile"].InputStream);
            //}
            //catch (Exception e)
            //{
            //	Console.WriteLine(e.Message);
            //	ViewBag.UploadAlert = "You must select a valid file";
            //}

            using(var c = new DataModelContext())
            {
                var patient = c.Patients.Find(model.ID);
                patientID = patient.ID;

                HttpPostedFileBase patientDoc = Request.Files["PatientFile"];
                var fileName = Path.GetFileName(patientDoc.FileName);
                var path = Path.Combine(Server.MapPath("~/Content/excelfiles"), fileName);
                patientDoc.SaveAs(path);

                var ReportE = ReportEngine.getInstance();
                pvm.Report = ReportE.GenerateReport(patient, path);
                patient.ReportResult = pvm.Report;

                try
                {
                    c.SaveChanges();
                }
                catch(DbEntityValidationException e)
                {
                    foreach(var i in e.EntityValidationErrors)
                    {
                        Console.WriteLine(i.ValidationErrors);
                    }
                    throw e;
                }
                //nvm.Patients = c.Patients.Include("Therapist").Where(n => n.Name != null).ToList();

                //ViewBag.NewNetworkID = xmlnetwork.ID;

            }

            ViewBag.Alert = "Upload successful";
            ViewBag.AlertClass = "alert-success";

            return RedirectToAction("Report", new { id = patientID });
            //return View("Report", pvm);
        }
        public ActionResult EditRequired(double PatientShankLength, double PatientThighLength, PatientViewModel model)
        {
            var pvm = new PatientViewModel();
            long patientID = 0;

            using (var c = new DataModelContext())
            {
                var patient = c.Patients.Find(model.ID);
                patientID = patient.ID;
                patient.ShankLength = PatientShankLength;
                patient.ThighLength = PatientThighLength;

                c.SaveChanges();

            }

            ViewBag.Alert = "Profile update successful";
            ViewBag.AlertClass = "alert-success";
            //return View("View", pvm);
            return RedirectToAction("Report", new { id = patientID });
        }
        public ActionResult EditPatient(DateTime PatientBirthday, string PatientGender, double PatientHeight, 
			double PatientWeight, string PatientDoctor,	string PatientCity, string PatientEmail, string PatientPhoneNumber, 
			PatientViewModel model)
        {
            var pvm = new PatientViewModel();
            long patientID = 0;

            using (var c = new DataModelContext())
            {
                var patient = c.Patients.Find(model.ID);
                patientID = patient.ID;

                patient.Birthday = PatientBirthday;
                patient.Gender = PatientGender;
                patient.Height = PatientHeight;
                patient.Weight = PatientWeight;
                patient.Doctor = PatientDoctor;
                patient.City = PatientCity;
                patient.Email = PatientEmail;
                patient.PhoneNumber = PatientPhoneNumber;

                DateTime today = DateTime.Today;
                int age = today.Year - PatientBirthday.Year;
                if (PatientBirthday > today.AddYears(-age)) age--;
                patient.Age = age;

                c.SaveChanges();

            }

            ViewBag.Alert = "Profile update successful";
            ViewBag.AlertClass = "alert-success";
            //return View("View", pvm);
            return RedirectToAction("View", new { id = patientID});
        }
        public ActionResult EditMedicalProfile(string PatientCurrentMeds, string PatientHeartDisease, string PPatientHeartDisease,
			string PatientDiabetes, string PPatientDiabetes, string PatientCancer, 
			string PPatientCancer, string PatientHighBloodPressure, string PPatientHighBloodPressure,
			PatientViewModel model)
        {
            var pvm = new PatientViewModel();
            long patientID = 0;

            using (var c = new DataModelContext())
            {
                var patient = c.Patients.Find(model.ID);
                patientID = patient.ID;

                patient.MedProfile.CurrentMeds = new List<string>(
                    PatientCurrentMeds.Split(new string[] { "\r\n" },
                    StringSplitOptions.RemoveEmptyEntries));

                //Setting Current Conditions
                if (PatientHeartDisease == "Current")
                {
                    patient.MedProfile.HeartDisease = true;
                }
                else
                {
                    patient.MedProfile.HeartDisease = false;
                }
                if (PatientDiabetes == "Current")
                {
                    patient.MedProfile.Diabetes = true;
                }
                else
                {
                    patient.MedProfile.Diabetes = false;
                }
                if (PatientCancer == "Current")
                {
                    patient.MedProfile.Cancer = true;
                }
                else
                {
                    patient.MedProfile.Cancer = false;
                }
                if (PatientHighBloodPressure == "Current")
                {
                    patient.MedProfile.HighBloodPressure = true;
                }
                else
                {
                    patient.MedProfile.HighBloodPressure = false;
                }
                //Setting Past Conditions
                if (PPatientHeartDisease == "Past")
                {
                    patient.MedProfile.PHeartDisease = true;
                }
                else
                {
                    patient.MedProfile.PHeartDisease = false;
                }
                if (PPatientDiabetes == "Past")
                {
                    patient.MedProfile.PDiabetes = true;
                }
                else
                {
                    patient.MedProfile.PDiabetes = false;
                }
                if (PPatientCancer == "Past")
                {
                    patient.MedProfile.PCancer = true;
                }
                else
                {
                    patient.MedProfile.PCancer = false;
                }
                if (PPatientHighBloodPressure == "Past")
                {
                    patient.MedProfile.PHighBloodPressure = true;
                }
                else
                {
                    patient.MedProfile.PHighBloodPressure = false;
                }

                c.SaveChanges();

            }

            ViewBag.Alert = "Profile update successful";
            ViewBag.AlertClass = "alert-success";
            //return View("View", pvm);
            return RedirectToAction("View", new { id = patientID });
        }
        public ActionResult EditMedical(string PatientArthritisType, string PatientAffectedExtremity,
			string PatientDeformity, PatientViewModel model)
        {
            var pvm = new PatientViewModel();
            long patientID = 0;

            using (var c = new DataModelContext())
            {
                var patient = c.Patients.Find(model.ID);
                patientID = patient.ID;
                patient.ArthritisType = PatientArthritisType;
                patient.AffectedExtremity = PatientAffectedExtremity;
                patient.Deformity = PatientDeformity;

                c.SaveChanges();

            }

            ViewBag.Alert = "Profile update successful";
            ViewBag.AlertClass = "alert-success";
            //return View("View", pvm);
            return RedirectToAction("View", new { id = patientID });
        }
        public ActionResult EditContact(string PatientContactName, string PatientContactRelation, 
			string PatientContactPhoneNumber, string PatientContactEmail, PatientViewModel model)
        {
            var pvm = new PatientViewModel();
            long patientID = 0;

            using (var c = new DataModelContext())
            {
                var patient = c.Patients.Find(model.ID);
                patientID = patient.ID;
                patient.ContactName = PatientContactName;
                patient.ContactRelation = PatientContactRelation;
                patient.ContactPhoneNumber = PatientContactPhoneNumber;
                patient.ContactEmail = PatientContactEmail;

                c.SaveChanges();

            }

            ViewBag.Alert = "Profile update successful";
            ViewBag.AlertClass = "alert-success";
            //return View("View", pvm);
            return RedirectToAction("View", new { id = patientID });
        }