Ejemplo n.º 1
0
        private static bool isBMIMatched(string fieldValue)
        {
            bool result = false;

            if (fieldValue != null)
            {
                if (IsJson(fieldValue))
                {
                    JavaScriptSerializer serializer = new JavaScriptSerializer();
                    BMIViewModel         bmi        = serializer.Deserialize <BMIViewModel>(fieldValue as string);
                    if (bmi != null && bmi.BodyMassIndex != null)
                    {
                        float ftValue = 0;

                        try
                        {
                            ftValue = float.Parse(bmi.BodyMassIndex, CultureInfo.InvariantCulture.NumberFormat);
                            if (ftValue >= 23)
                            {
                                result = true;// If BMI >/= 23
                            }
                        }
                        catch (FormatException e)
                        {
                            e.ToString();
                            ftValue = 0;
                        }
                    }
                }
            }

            return(result);
        }
Ejemplo n.º 2
0
        public BMIView()
        {
            InitializeComponent();

            _viewModel     = new BMIViewModel();
            BindingContext = _viewModel;
        }
Ejemplo n.º 3
0
        //create a view user method for our httpGet
        public ActionResult ViewBMI()
        {
            //instantiate and name
            BMIViewModel _viewModel = new BMIViewModel();

            //use method from DAL that has stored procedure, map it to the model called playerlist
            _viewModel.BMIList = _Mapper.Map(_BMIDataAccess.GetBMIByUser_ID((int)Session["User_ID"]));
            //load viewmodel into view and return the view
            return(View(_viewModel.BMIList));
        }
Ejemplo n.º 4
0
        public static string Format(this BMIViewModel bmi)
        {
            StringBuilder sb = new StringBuilder();

            sb.AppendFormat("Weight(kg): {0},", bmi.Weight);

            sb.AppendFormat(" Height(cm): {0}, ", bmi.Height);
            sb.AppendFormat(" BMI: {0} ", bmi.BodyMassIndex);

            return(sb.ToString());
        }
Ejemplo n.º 5
0
        // GET: /<controller>/
        public IActionResult Calculator()
        {
            BMIViewModel model = new BMIViewModel();

            var userid = userManager.GetUserId(HttpContext.User);
            var user   = userManager.FindByIdAsync(userid).Result;

            user.currentWeight = model.currentWeight;

            model.height     = user.heightInInches;
            model.goalWeight = user.goalWeight;
            return(View(model));
        }
Ejemplo n.º 6
0
        public BMI()
        {
            InitializeComponent();

            this.entWeight.Completed += EntWeight_Completed;
            this.entHeight.Completed += EntHeight_Completed;
            this.entAge.Completed    += EntAge_Completed;
            this.entWaist.Completed  += EntWaist_Completed;
            this.entHip.Completed    += EntHip_Completed;

            viewModel           = new BMIViewModel();
            this.BindingContext = viewModel;
        }
Ejemplo n.º 7
0
        public async Task <IActionResult> Calculator(BMIViewModel model)
        {
            var userid = userManager.GetUserId(HttpContext.User);
            var user   = userManager.FindByIdAsync(userid).Result;

            user.currentWeight = model.currentWeight;

            model.height     = user.heightInInches;
            model.goalWeight = user.goalWeight;
            var result = await userManager.UpdateAsync(user);

            foreach (var error in result.Errors)
            {
                ModelState.AddModelError(String.Empty, error.Description);
            }
            return(View(model));
        }
Ejemplo n.º 8
0
        public ActionResult BMI(BMIViewModel model)
        {
            double weight   = model.Weight;
            double height   = model.Height;
            double solution = weight / Math.Pow(model.Height / 100, 2);

            ViewBag.solution = string.Format("Your BMI is {0}", solution.ToString("F"));
            if (solution < 18.5)
            {
                double correctWeight = 18.5 * Math.Pow(model.Height / 100, 2);
                ViewBag.correct = string.Format("Your correct body weight is {0} kg.", correctWeight.ToString("F"));
            }
            else if (solution < 25)
            {
                ViewBag.correct = string.Format("Your  body weight is correct.");
            }
            else
            {
                double correctWeight = 25 * Math.Pow(model.Weight / 100, 2);
                ViewBag.correct = string.Format("Your  body weight is too high. You should lose {0} kg.",
                                                correctWeight.ToString("F"));
            }
            return(View());
        }
Ejemplo n.º 9
0
        public static string GetSubmittedOtherOptionsTextValue(this HtmlHelper helper, TemplateFieldViewModel model, string fieldType = "", string returnIfNull = "")
        {
            string tempValue = GetTempFormValue(helper, model, fieldType, returnIfNull);

            if (!string.IsNullOrEmpty(tempValue))
            {
                return(tempValue);
            }

            if (string.IsNullOrEmpty(model.EntryId) || model.EntryId.Equals(Guid.Empty.ToString()))
            {
                if (!model.IsValueRequiredForRegistration)
                {
                    return("");
                }

                else
                {
                    return(GetTempRegistrationFormValue(helper, model, fieldType));
                }
            }

            else
            {
                using (var formManager = new FormManager())
                {
                    switch (model.FieldType)
                    {
                    case TemplateFieldType.ADDRESS:

                        var addressValue = formManager.FindSaveValue(model.EntryId, model.TemplateFieldID ?? default(int));

                        AddressViewModel address = addressValue.FromJson <AddressViewModel>();

                        if (address != null)
                        {
                            if (fieldType == "Blk")
                            {
                                return(address.Blk);
                            }
                            else if (fieldType == "Unit")
                            {
                                return(address.Unit);
                            }
                            else if (fieldType == "StreetAddress")
                            {
                                return(address.StreetAddress);
                            }
                            else if (fieldType == "ZipCode")
                            {
                                return(address.ZipCode);
                            }
                        }
                        break;

                    case TemplateFieldType.BMI:

                        var bmiValue = formManager.FindSaveValue(model.EntryId, model.TemplateFieldID ?? default(int));

                        BMIViewModel bmi = bmiValue.FromJson <BMIViewModel>();

                        if (fieldType == "Weight")
                        {
                            return(bmi.Weight);
                        }
                        else if (fieldType == "Height")
                        {
                            return(bmi.Height);
                        }

                        break;

                    case TemplateFieldType.BIRTHDAYPICKER:
                        var birthdayValue = formManager.FindSaveValue(model.EntryId, model.TemplateFieldID ?? default(int));

                        if (!string.IsNullOrEmpty(birthdayValue))
                        {
                            string[] values = birthdayValue.Split("/");

                            if (fieldType == "Day")
                            {
                                int dayValue = int.Parse(values[0]);
                                return((dayValue < 10) ? ("0" + dayValue) : values[0]);
                            }

                            else if (fieldType == "Month")
                            {
                                return(values[1]);
                            }

                            else if (fieldType == "Year")
                            {
                                return(values[2].Substring(0, 4));
                            }
                        }

                        else
                        {
                            return("");
                        }

                        break;

                    default:
                        return(formManager.FindSaveValue(model.EntryId, model.TemplateFieldID ?? default(int)));
                    }
                }
            }

            return("");
        }
Ejemplo n.º 10
0
        public static string SubmittedValue(this TemplateFieldViewModel field, FormCollection form)
        {
            var    fType = field.FieldType.ToString().ToTitleCase();
            string value = "";

            switch (field.FieldType)
            {
            case Constants.TemplateFieldType.MATRIX:
                StringBuilder builder = new StringBuilder();

                for (int x = 0; x < 100; x++)
                {
                    value = form.SubmittedFieldValue(field.DomId, "[" + x + "].RadioButton");

                    if (value == null)
                    {
                        break;
                    }

                    if (x == 0)
                    {
                        builder.Append(value);
                    }
                    else
                    {
                        builder.Append(Constants.Form_Option_Split + value);
                    }
                }

                value = builder.ToString();

                break;

            case Constants.TemplateFieldType.BMI:
                var bmi = new BMIViewModel
                {
                    Weight = form.SubmittedFieldValue(field.DomId, "Weight"),
                    Height = form.SubmittedFieldValue(field.DomId, "Height"),
                };

                if (bmi.Weight == "" || bmi.Height == "")
                {
                    value = "";
                }
                else
                {
                    value = bmi.ToJson();
                }

                break;

            case Constants.TemplateFieldType.NRICPICKER:
                string icNumber = form.SubmittedFieldValue(field.DomId, fType.ToTitleCase());
                //string icFirstDigit = form.SubmittedFieldValue(field.DomId, "FirstDigit");
                //  string icLastDigit = form.SubmittedFieldValue(field.DomId, "LastDigit");

                value = icNumber;
                break;

            case Constants.TemplateFieldType.EMAIL:
                value = form.SubmittedFieldValue(field.DomId, fType.ToTitleCase());
                break;

            case Constants.TemplateFieldType.ADDRESS:
                var address = new AddressViewModel
                {
                    Blk           = form.SubmittedFieldValue(field.DomId, "Blk"),
                    Unit          = form.SubmittedFieldValue(field.DomId, "Unit"),
                    StreetAddress = form.SubmittedFieldValue(field.DomId, "StreetAddress"),
                    ZipCode       = form.SubmittedFieldValue(field.DomId, "ZipCode"),
                };

                if (address.Blk.IsEmptyOrWhiteSpace() && address.StreetAddress.IsEmptyOrWhiteSpace())
                {
                    value = "";
                }
                else
                {
                    value = address.ToJson();
                }
                break;

            case Constants.TemplateFieldType.BIRTHDAYPICKER:
                var day   = form.SubmittedFieldValue(field.DomId, "Day");
                var month = form.SubmittedFieldValue(field.DomId, "Month");
                var year  = form.SubmittedFieldValue(field.DomId, "Year");

                if (day.IsNullOrEmpty() && month.IsNullOrEmpty() && year.IsNullOrEmpty())
                {
                    value = "";
                }
                else
                {
                    DateTime date = new DateTime(Int32.Parse(year), Int32.Parse(month), Int32.Parse(day));
                    value = date.ToString("dd/M/yyyy hh:mm:ss tt");

                    /*
                     * var dateValue = "{0}-{1}-{2}".FormatWith(month, day, year);
                     * //var format = new string[] { "M-dd-yyyy" };
                     * DateTime date;
                     * if (DateTime.TryParseExact(dateValue, "M-dd-yyyy", CultureInfo.InvariantCulture, DateTimeStyles.NoCurrentDateDefault, out date))
                     * {
                     *  value = date.ToString("dd/M/yyyy hh:mm:ss tt");
                     * }
                     * else
                     * {
                     *  value = "";
                     * }*/
                }
                break;

            case Constants.TemplateFieldType.CHECKBOX:
                value = form.SubmittedFieldValue(field.DomId, fType.ToTitleCase());
                if (!value.IsNullOrEmpty())
                {
                    string newValue = "";
                    foreach (var option in field.Options.Split(Constants.Form_Option_Split))
                    {
                        if (value.Contains(option))
                        {
                            newValue += Constants.Form_Option_Split_Concate + option;
                        }
                    }


                    if (value.Contains("OthersOption"))
                    {
                        string othersOptionValue = form.SubmittedFieldValue(field.DomId, "OthersOption");
                        newValue += Constants.Form_Option_Split_Concate + othersOptionValue;
                    }


                    if (newValue.Substring(0, 1).Equals(Constants.Form_Option_Split_Concate))
                    {
                        newValue = newValue.Remove(0, 1);
                    }

                    value = newValue;
                }
                break;

            case Constants.TemplateFieldType.PHONE:
                var area   = form.SubmittedFieldValue(field.DomId, "AreaCode");
                var number = form.SubmittedFieldValue(field.DomId, "Number");
                if (string.IsNullOrEmpty(area) && string.IsNullOrEmpty(number))
                {
                    value = "";
                }
                else
                {
                    value = "{0}-{1}".FormatWith(area, number);
                }
                break;

            case Constants.TemplateFieldType.DROPDOWNLIST:
                value = form.SubmittedFieldValue(field.DomId, fType.ToTitleCase());
                break;

            case Constants.TemplateFieldType.RADIOBUTTON:
                value = form.SubmittedFieldValue(field.DomId, fType.ToTitleCase());
                if (!value.IsNullOrEmpty() && value.Equals("OthersOption"))
                {
                    value = form.SubmittedFieldValue(field.DomId, "OthersOption");
                }
                break;

            case Constants.TemplateFieldType.FULLNAME:
                var fName    = form.SubmittedFieldValue(field.DomId, "FirstName");
                var lName    = form.SubmittedFieldValue(field.DomId, "LastName");
                var initials = form.SubmittedFieldValue(field.DomId, "Initials");
                if (string.IsNullOrEmpty(fName) && string.IsNullOrEmpty(lName))
                {
                    value = "";
                }
                else
                {
                    value = "{0} {1} {2}".FormatWith(fName, initials, lName);
                }
                break;

            case Constants.TemplateFieldType.TEXTAREA:
                value = form.SubmittedFieldValue(field.DomId, fType.ToTitleCase());
                break;

            case Constants.TemplateFieldType.TEXTBOX:
                value = form.SubmittedFieldValue(field.DomId, fType.ToTitleCase());
                break;

            case Constants.TemplateFieldType.TEXTBOXNUMBER:
                value = form.SubmittedFieldValue(field.DomId, fType.ToTitleCase());
                break;

            case Constants.TemplateFieldType.SIGNATURE:
                value = form.SubmittedFieldValue(field.DomId, fType.ToTitleCase());
                break;

            case Constants.TemplateFieldType.DOCTORMEMO:
                value = form.SubmittedFieldValue(field.DomId, "TextArea");
                break;

            case Constants.TemplateFieldType.FILEPICKER:
                //HttpPostedFile file = HttpContext.Current.Request.Files[SubmittedFieldName(field.DomId, fType.ToTitleCase())];
                //value = "";
                //if (file != null && file.ContentLength > 0)
                //{
                //    var extension = Path.GetExtension(file.FileName);

                //    var valueObject = new FileValueObject()
                //    {
                //        FileName = file.FileName,
                //        SaveName = Guid.NewGuid().ToString() + extension,
                //        SavePath = WebConfig.Get("filesavepath"),
                //        IsSavedInCloud = UtilityHelper.UseCloudStorage(),
                //        Extension = extension
                //    };

                //    value = valueObject.ToJson();
                //}
                break;
            }

            return(value);
        }
        public List <SummaryCategoryViewModel> GetSummaryCategories(string summaryType)
        {
            List <SummaryCategoryViewModel> result = new List <SummaryCategoryViewModel>();

            List <string> categoryNames = null;
            Dictionary <string, List <string> > summaryLabelMap = null;

            using (var summaryMappingManager = new SummaryMappingManager())
            {
                categoryNames   = summaryMappingManager.GetAllCategoryNamesBySummaryType(summaryType);
                summaryLabelMap = summaryMappingManager.GetSummaryLabelMapBySummaryType(summaryType);
            }

            if (categoryNames == null)
            {
                return(result);
            }

            foreach (var summaryCategoryName in categoryNames)
            {
                SummaryCategoryViewModel sumCategoryViewModel = new SummaryCategoryViewModel(summaryCategoryName);

                if (summaryCategoryName.Contains("Gastrointestinal Health"))
                {
                    sumCategoryViewModel.Highlight = true;
                }

                foreach (var summary in Participant.Summaries)
                {
                    if (summary != null && summary.PHSEventID.Equals(Event.PHSEventID))
                    {
                        if (SummaryHelper.IsFieldNameAndCategoryFoundInSummaryMap(summaryLabelMap, summaryCategoryName, summary.Label))
                        {
                            if (summary.SummaryValue == null || summary.SummaryValue.Count() <= 0)
                            {
                                continue;
                            }

                            SummaryViewModel sumview = new SummaryViewModel(summary);

                            if (sumCategoryViewModel.Highlight != true)
                            {
                                // summary.TemplateFieldID;
                                if (SummaryHelper.IsHighlightCategoryRequired(summaryCategoryName, summary.TemplateField.SummaryFieldName, summary.SummaryValue))
                                {
                                    sumCategoryViewModel.Highlight = true;
                                }
                            }


                            if (summary.StandardReferenceID != null && summary.StandardReferenceID > 0 &&
                                summary.SummaryValue != null)
                            {
                                if (SummaryHelper.IsJson(summary.SummaryValue))
                                {
                                    //if (summary.StandardReferenceID == 1) //Systolic Blood Pressure
                                    //{
                                    //    sumview.SummaryValue = summary.SummaryValue;
                                    //    sumview.SummaryInnerValue = summary.SummaryValue;
                                    //}else if (summary.StandardReferenceID == 2) //Diastolic Blood Pressure
                                    //{
                                    //        sumview.SummaryValue = summary.SummaryValue;
                                    //        sumview.SummaryInnerValue = summary.SummaryValue;
                                    //}else if (summary.StandardReferenceID == 3) //Sugar
                                    //{
                                    //    sumview.SummaryValue = summary.SummaryValue;
                                    //    sumview.SummaryInnerValue = summary.SummaryValue;
                                    //}else

                                    if (summary.StandardReferenceID == 4) //BMI
                                    {
                                        JavaScriptSerializer serializer = new JavaScriptSerializer();
                                        BMIViewModel         bmi        = serializer.Deserialize <BMIViewModel>(summary.SummaryValue as string);
                                        if (bmi.BodyMassIndex != null)
                                        {
                                            //Weight: 50, Height: 180, BodyMassIndex: 15.43  (UNDERWEIGHT)
                                            sumview.SummaryValue      = "Weight: " + bmi.Weight + ", Height: " + bmi.Height + ", BodyMassIndex: " + bmi.BodyMassIndex;
                                            sumview.SummaryInnerValue = bmi.BodyMassIndex;
                                        }
                                    }
                                }
                                else
                                {
                                    sumview.SummaryInnerValue = summary.SummaryValue;
                                }

                                ReferenceRange referenceRange = null;

                                using (var StandardReferenceManager = new StandardReferenceManager())
                                {
                                    string message = string.Empty;
                                    referenceRange = StandardReferenceManager.GetReferenceRange(summary.StandardReferenceID.GetValueOrDefault(),
                                                                                                sumview.SummaryInnerValue, out message);
                                }

                                if (referenceRange != null)
                                {
                                    sumview.Result    = referenceRange.Result;
                                    sumview.Highlight = referenceRange.Highlight;
                                }
                            }

                            if (sumview != null)
                            {
                                sumCategoryViewModel.AddSummary(sumview);
                            }
                        }
                    }
                }

                result.Add(sumCategoryViewModel);
            }

            return(result);
        }