Beispiel #1
0
        public JsonResult Save(int calStudyID, CalParenteral[] pis, CalInfuseColumn[] cic, CalStudyInfo csi, CalEnteral[] ces, CalAdditive[] cas, CalOtherNutrition con)
        {
            bool isEdit = false || calStudyID > 0;
            var  dto    = new DTO();

            if (isEdit)
            {
                //get the original calcdate and see if it has been changed
                //if changed then check for duplicate


                CalorieCalc.DeleteCurrentEntries(calStudyID);
                csi.Id = calStudyID;

                dto = CalorieCalc.UpdateCalStudyInfo(csi);
                if (dto.ReturnValue == -1)
                {
                    dto.Message = "There was an error updating this caloric entry.  It has been reported to the web master!";
                    return(Json(dto));
                }
            }
            else
            {
                if (CalorieCalc.IsCalStudyInfoDuplicate(csi.StudyId, csi.CalcDate) == 1)
                {
                    dto.ReturnValue = 0;
                    dto.Message     = "This study id for the date, " + csi.CalcDate + ", has already been entered!";

                    return(Json(dto));
                }

                dto = CalorieCalc.AddCalStudyInfo(csi);
                if (dto.ReturnValue == -1)
                {
                    dto.Message = "There was an error adding this caloric entry.  It has been reported to the web master!";
                    return(Json(dto));
                }
            }

            con.CalStudyId = csi.Id;
            if (con.OtherText == null)
            {
                con.OtherText = "";
            }
            dto = CalorieCalc.AddCalOtherNutrition(con);
            //check for any data and if there is data - send email
            if ((con.BreastFeeding) || (con.Drinks) || (con.SolidFoods) || (con.Other) || (con.OtherText.Trim().Length > 0))
            {
                //string[] users = ConfigurationManager.AppSettings["NewFormulaNotify"].ToString().Split(new[] { ',' }, StringSplitOptions.None);

                var siteId = DbUtils.GetSiteidIdForUser(User.Identity.Name);
                var staff  = NotificationUtils.GetStaffForEvent(6, siteId);

                string siteName = DbUtils.GetSiteNameForUser(User.Identity.Name);

                var    u   = new UrlHelper(this.Request.RequestContext);
                string url = "http://" + this.Request.Url.Host + u.RouteUrl("Default", new { Controller = "Account", Action = "Logon" });

                Utility.SendOtherNutritionMail(staff.ToArray(), null, con, csi, User.Identity.Name, siteName, Server, url);
            }

            if (dto.ReturnValue == -1)
            {
                dto.Message = "There was an error adding other nutrition.  It has been reported to the web master!";
                return(Json(dto));
            }

            if (cic != null)
            {
                foreach (var ci in cic)
                {
                    if (ci.Volumes == null)
                    {
                        continue;
                    }
                    var cid = new CalInfusionDex();
                    cid.DexVal     = ci.DexValue;
                    cid.CalStudyID = csi.Id;

                    dto = CalorieCalc.AddCalInfusionDex(cid);
                    if (dto.ReturnValue == -1)
                    {
                        dto.Message = "There was an error adding a infusion dextrose entry.  It has been reported to the web master!";
                        return(Json(dto));
                    }

                    foreach (var vol in ci.Volumes)
                    {
                        var civ = new CalInfusionVol();
                        civ.DexID  = cid.ID;
                        civ.Volume = vol;
                        CalorieCalc.AddCalInfusionVol(civ);
                        if (dto.ReturnValue == -1)
                        {
                            dto.Message = "There was an error adding a infusion volume entry.  It has been reported to the web master!";
                            return(Json(dto));
                        }
                    }
                }
            }

            if (pis != null)
            {
                foreach (var pi in pis)
                {
                    pi.CalStudyID = csi.Id;
                    dto           = CalorieCalc.AddCalParenteral(pi);
                    if (dto.ReturnValue == -1)
                    {
                        dto.Message = "There was an error adding a parenteral entry.  It has been reported to the web master!";
                        return(Json(dto));
                    }
                }
            }

            if (ces != null)
            {
                foreach (var ce in ces)
                {
                    ce.CalStudyID = csi.Id;
                    dto           = CalorieCalc.AddCalEnteral(ce);
                    if (dto.ReturnValue == -1)
                    {
                        dto.Message = "There was an error adding an enteral entry.  It has been reported to the web master!";
                        return(Json(dto));
                    }
                }
            }

            if (cas != null)
            {
                foreach (var ca in cas)
                {
                    ca.CalStudyID = csi.Id;
                    dto           = CalorieCalc.AddCalAdditive(ca);
                    if (dto.ReturnValue == -1)
                    {
                        dto.Message = "There was an error adding an additive entry.  It has been reported to the web master!";
                        return(Json(dto));
                    }
                }
            }

            dto.ReturnValue = 1;
            dto.Message     = "Caloric Entries were added successfully!";
            return(Json(dto));
        }
Beispiel #2
0
        public static double GetGirForCalStudyInfo(CalStudyInfo csi)
        {
            var    allData         = GetAllDataForRecalc(csi.StudyId.ToString(), csi.CalcDate);
            double totInfusions    = 0;
            double totParenProtein = 0;
            double totParenCho     = 0;
            double totParenLipid   = 0;
            double totEnProtein    = 0;
            double totEnCho        = 0;
            double totEnLipid      = 0;

            foreach (var ci in allData.calInfusionCol)
            {
                foreach (var vol in ci.Volumes)
                {
                    totInfusions += vol * ci.DexValue;
                }
            }

            foreach (var par in allData.calParenterals)
            {
                double lipVal = 0;
                totParenProtein += (par.AminoPercent * par.Volume * .04);
                if (par.DexPercent > 0)
                {
                    totParenCho += (par.DexPercent * par.Volume * .034);
                }
                else
                {
                    if (par.LipidPercent == 10)
                    {
                        lipVal = 1.1;
                    }
                    else if (par.LipidPercent == 20)
                    {
                        lipVal = 2.0;
                    }
                    else if (par.LipidPercent == 30)
                    {
                        lipVal = 3.0;
                    }

                    totParenLipid += lipVal * par.Volume;
                }
            }

            foreach (var ent in allData.calEnterals)
            {
                var kCals = ent.KcalMl * ent.Volume;
                totEnProtein += kCals * (ent.ProteinPercent / 100);
                totEnCho     += kCals * (ent.ChoPercent / 100);
                totEnLipid   += kCals * (ent.LipidPercent / 100);
            }

            foreach (var add in allData.calAdditives)
            {
                var kCals = add.KcalUnit * add.Volume;
                totEnProtein += kCals * (add.ProteinPercent / 100);
                totEnCho     += kCals * (add.ChoPercent / 100);
                totEnLipid   += kCals * (add.LipidPercent / 100);
            }

            //calculate gir
            var totalEntPar = totParenProtein + totParenCho + totParenLipid +
                              totEnProtein + totEnCho + totEnLipid;

            var choKcals = totEnCho;
            var choMg    = (choKcals / 4) * 1000;
            var dexKal   = totInfusions + totParenCho;
            var dexMg    = (dexKal / 3.4) * 1000;

            csi.Gir = ((choMg + dexMg) / csi.Weight) / (csi.Hours * 60);
            return(csi.Gir);
        }
Beispiel #3
0
        public ActionResult Edit(CalStudyInfo csi)
        {
            //DateTime date = DateTime.Parse( csi.CalcDate);

            ViewBag.Mode       = "Edit";
            ViewBag.Weight     = csi.Weight.ToString();
            ViewBag.CalcDate   = csi.CalcDate;
            ViewBag.CalStudyID = csi.Id;
            ViewBag.Hours      = csi.Hours;
            int studyDay = CalorieCalc.GetStudyDay(csi.StudyId, DateTime.Parse(csi.CalcDate));

            ViewBag.StudyDay = studyDay.ToString();

            int siteId = DbUtils.GetSiteidIdForUser(User.Identity.Name);
            //todo remove for production
            //if (siteId == 0)
            //    siteId = 1;

            var studyList = DbUtils.GetRandomizedStudiesForSite(siteId);

            studyList.Insert(0, new IDandStudyID {
                ID = 0, StudyID = "Select Study"
            });
            ViewBag.StudyList = new SelectList(studyList, "ID", "StudyID", csi.StudyId);

            var dc1 = CalorieCalc.GetDextroseConcentrations();
            var dc  = new DextroseConcentration {
                ID = 0, Concentration = " Dextrose % ", Kcal_ml = 0
            };

            dc1.Insert(0, dc);

            ViewBag.DexCons1 = new SelectList(dc1, "Kcal_ml", "Concentration");
            ViewBag.DexCons2 = new SelectList(dc1, "Kcal_ml", "Concentration");
            ViewBag.DexCons3 = new SelectList(dc1, "Kcal_ml", "Concentration");
            ViewBag.DexCons4 = new SelectList(dc1, "Kcal_ml", "Concentration");

            List <IDandName> sl = DbUtils.GetLookupItems("FormulaList");

            if (sl.Count == 0)
            {
                throw new Exception("There was an error retrieving the FormulaList from the database");
            }
            sl.Insert(0, new IDandName {
                ID = 0, Name = "Select"
            });
            ViewBag.FormulaList = new SelectList(sl, "ID", "Name");

            List <IDandName> sl2 = DbUtils.GetLookupItems("AdditiveList");

            if (sl2.Count == 0)
            {
                throw new Exception("There was an error retrieving the Additives from the database");
            }
            sl2.Insert(0, new IDandName {
                ID = 0, Name = "Select"
            });
            ViewBag.AdditiveList = new SelectList(sl2, "ID", "Name");

            List <IDandName> sl3 = DbUtils.GetLookupItems("Units");

            if (sl3.Count == 0)
            {
                throw new Exception("There was an error retrieving the Units from the database");
            }
            sl3.Insert(0, new IDandName {
                ID = 0, Name = "Select"
            });
            ViewBag.Units = new SelectList(sl3, "ID", "Name");

            return(View("Index"));
        }
Beispiel #4
0
		public static void SendOtherNutritionMail(string[] toAddress, string[] ccAddress, CalOtherNutrition con, CalStudyInfo csi, string name, string siteName, HttpServerUtilityBase server, string url)
		{
			string subject = "Halfpint - Other Nutrition Added";
			StringBuilder sbBody = new StringBuilder("<p>" + name + " from " + siteName + " has included other nutrition:</p>");
			
			sbBody.Append("Study ID: " + csi.SStudyId + ", Date: " + csi.CalcDate);
			sbBody.Append("<br/>");
			sbBody.Append("<table><tr><th>Type</th><th>Checked</th></tr>");
			sbBody.Append("<tr><td>Breast Feeding</td><td>" + con.BreastFeeding + "</td></tr>");
			sbBody.Append("<tr><td>Drinks</td><td>" + con.Drinks + "</td></tr>");
			sbBody.Append("<tr><td>Solid Foods</td><td>" + con.SolidFoods + "</td></tr>");
			sbBody.Append("<tr><td>Other</td><td>" + con.Other + "</td></tr>");            
			sbBody.Append("</table>");
			sbBody.Append("<br/>");
			sbBody.Append("Other Text:");
			sbBody.Append("<br/>");
			sbBody.Append(con.OtherText);

			string siteUrl = "Website: <a href='" + url + "'>HalfpintStudy.org</a>";
			SendHtmlEmail(subject, toAddress, ccAddress, sbBody.ToString(), server, siteUrl);
		}