public int ChangeRxCurrentFlexion(string RxID, int CurrentFlexion, string Code)
        {
            int       result = 0;
            PatientRx patRx  = (from p in context.PatientRx
                                where p.RxId == RxID
                                select p).FirstOrDefault();

            if (patRx != null)
            {
                RomchangeLog plog = new RomchangeLog();
                plog.RxId              = patRx.RxId;
                plog.PreviousFlexion   = patRx.CurrentFlexion.HasValue ? Convert.ToInt32(patRx.CurrentFlexion) : 0;
                plog.PreviousExtension = patRx.CurrentExtension.HasValue ? Convert.ToInt32(patRx.CurrentExtension) : 0;
                plog.CreatedDate       = DateTime.UtcNow;
                plog.ChangedBy         = Code;
                context.RomchangeLog.Add(plog);
                int res = context.SaveChanges();
                if (res > 0)
                {
                    patRx.CurrentFlexion       = CurrentFlexion;
                    patRx.DateModified         = DateTime.UtcNow;
                    context.Entry(patRx).State = EntityState.Modified;
                    result = context.SaveChanges();
                }
            }
            return(result);
        }
        //
        public IActionResult AddEdit(string id)
        {
            PatientRxView lPatientRx = new PatientRxView();

            try
            {
                if (!string.IsNullOrEmpty(id))
                {
                    getDetails();
                    PatientRx patientRx = lIPatientRxRepository.getById(id);
                    if (patientRx != null)
                    {
                        lPatientRx = patientRx.PatientRxToPatientRxViewModel();
                    }
                }
                else
                {
                    if (!string.IsNullOrEmpty(HttpContext.Session.GetString("UserId")))
                    {
                        lPatientRx.ProviderId = HttpContext.Session.GetString("UserId");
                        lPatientRx.RxDays     = new List <checkboxModel>
                        {
                            new checkboxModel {
                                id = 1, name = "SUN", isCheck = false
                            },
                            new checkboxModel {
                                id = 2, name = "MON", isCheck = false
                            },
                            new checkboxModel {
                                id = 3, name = "TUE", isCheck = false
                            },
                            new checkboxModel {
                                id = 4, name = "WED", isCheck = false
                            },
                            new checkboxModel {
                                id = 5, name = "THR", isCheck = false
                            },
                            new checkboxModel {
                                id = 6, name = "FRI", isCheck = false
                            },
                            new checkboxModel {
                                id = 7, name = "SAT", isCheck = false
                            }
                        };
                        getDetails();
                    }
                    else
                    {
                        ViewBag.equipment = null;
                        ViewBag.Patients  = null;
                    }
                }
            }
            catch (Exception ex)
            {
                logger.LogDebug("Patent Rx Error: " + ex);
            }
            return(View(lPatientRx));
        }
        public static PatientRxView PatientRxToPatientRxViewModel(this PatientRx patientRx)
        {
            if (patientRx == null)
            {
                return(null);
            }

            PatientRxView patRx = new PatientRxView()
            {
                RxId          = patientRx.RxId.ToString(),
                ProviderId    = patientRx.ProviderId,
                PatientId     = patientRx.PatientId.ToString(),
                EquipmentType = patientRx.EquipmentType,
                RxStartDate   = Convert.ToDateTime(patientRx.RxStartDate).ToString("dd-MMM-yyyy"),
                RxEndDate     = Convert.ToDateTime(patientRx.RxEndDate).ToString("dd-MMM-yyyy"),

                RxSessionsPerWeek = (int)patientRx.RxSessionsPerWeek,

                DateCreated  = patientRx.DateCreated,
                DateModified = patientRx.DateModified,
                RxDays       = new List <checkboxModel>
                {
                    new checkboxModel {
                        id = 1, name = "SUN", isCheck = (!string.IsNullOrEmpty(patientRx.RxDays) && patientRx.RxDays.Split(',').ToList().Where(x => x == "SUN").Count() > 0) ? true : false
                    },
                    new checkboxModel {
                        id = 2, name = "MON", isCheck = (!string.IsNullOrEmpty(patientRx.RxDays) && patientRx.RxDays.Split(',').ToList().Where(x => x == "MON").Count() > 0) ? true : false
                    },
                    new checkboxModel {
                        id = 3, name = "TUE", isCheck = (!string.IsNullOrEmpty(patientRx.RxDays) && patientRx.RxDays.Split(',').ToList().Where(x => x == "TUE").Count() > 0) ? true : false
                    },
                    new checkboxModel {
                        id = 4, name = "WED", isCheck = (!string.IsNullOrEmpty(patientRx.RxDays) && patientRx.RxDays.Split(',').ToList().Where(x => x == "WED").Count() > 0) ? true : false
                    },
                    new checkboxModel {
                        id = 5, name = "THR", isCheck = (!string.IsNullOrEmpty(patientRx.RxDays) && patientRx.RxDays.Split(',').ToList().Where(x => x == "THR").Count() > 0) ? true : false
                    },
                    new checkboxModel {
                        id = 6, name = "FRI", isCheck = (!string.IsNullOrEmpty(patientRx.RxDays) && patientRx.RxDays.Split(',').ToList().Where(x => x == "FRI").Count() > 0) ? true : false
                    },
                    new checkboxModel {
                        id = 6, name = "SAT", isCheck = (!string.IsNullOrEmpty(patientRx.RxDays) && patientRx.RxDays.Split(',').ToList().Where(x => x == "FRI").Count() > 0) ? true : false
                    }
                },
                DateOfBirth = Convert.ToDateTime(patientRx.Patient.Dob).ToString("dd-MMM-yyyy"),

                Mobile      = patientRx.Patient.PhoneNumber,
                Address     = patientRx.Patient.AddressLine,
                PatientName = patientRx.Patient.PatientName
            };

            return(patRx);
        }
 //delete the patientRx record
 public IActionResult Delete(string id)
 {
     try
     {
         if (!string.IsNullOrEmpty(id))
         {
             PatientRx patientRx = lIPatientRxRepository.getById(id);
             if (patientRx != null)
             {
                 lIPatientRxRepository.DeletePatientRx(patientRx);
             }
         }
     }
     catch (Exception ex)
     {
         logger.LogDebug("Patent Rx Error: " + ex);
     }
     return(RedirectToAction("Index"));
 }
        public static PatientRx PatientRxViewToPatientRxModel(this PatientRxView patientRx)
        {
            if (patientRx == null)
            {
                return(null);
            }
            Console.WriteLine("Patient Rx: " + Newtonsoft.Json.JsonConvert.SerializeObject(patientRx));

            PatientRx patRx = new PatientRx()
            {
                RxId              = patientRx.RxId,
                ProviderId        = patientRx.ProviderId,
                PatientId         = Convert.ToInt32(patientRx.PatientId),
                EquipmentType     = patientRx.EquipmentType,
                RxStartDate       = Convert.ToDateTime(patientRx.RxStartDate.ToString()),
                RxEndDate         = Convert.ToDateTime(patientRx.RxEndDate.ToString()),
                RxDaysPerweek     = patientRx.RxDays.Where(x => x.isCheck == true).Count(),
                RxSessionsPerWeek = (int)patientRx.RxSessionsPerWeek,

                DateCreated  = patientRx.DateCreated,
                DateModified = patientRx.DateModified,
                RxDays       = string.Join(",", patientRx.RxDays.Where(x => x.isCheck == true).Select(x => x.name)),
                Patient      = new Patient()
                {
                    Dob = Convert.ToDateTime(patientRx.DateOfBirth),

                    PhoneNumber = patientRx.Mobile,
                    AddressLine = patientRx.Address,
                    PatientName = patientRx.PatientName,
                    PatientId   = Convert.ToInt32(patientRx.PatientId),

                    ProviderId = patientRx.ProviderId
                }
            };

            return(patRx);
        }
        public IActionResult AddEdit(PatientRxView pPatientRx)
        {
            try
            {
                if (pPatientRx != null && (!string.IsNullOrEmpty(pPatientRx.ProviderId)))
                {
                    if (ModelState.IsValid)
                    {
                        if (!string.IsNullOrEmpty(pPatientRx.RxId))
                        {
                            pPatientRx.DateModified = DateTime.Now;
                            PatientRx lpatientRx = PatientRxExtension.PatientRxViewToPatientRxModel(pPatientRx);

                            User lUser = lIUserRepository.getUser(lpatientRx.PatientId.ToString());
                            if (lUser != null && lpatientRx.Patient != null)
                            {
                                lIPatientRxRepository.UpdatePatientRx(lpatientRx);
                            }
                            else
                            {
                                lIPatientRxRepository.UpdatePatientRx(lpatientRx);
                            }

                            return(RedirectToAction("Dashboard", "Provider", new { id = lpatientRx.ProviderId }));
                        }
                        else
                        {
                            PatientRx lpatientRx = lIPatientRxRepository.getByPatientIdAndEquipmentTypeAndProviderId(pPatientRx.ProviderId, pPatientRx.PatientId, pPatientRx.EquipmentType.Trim());

                            if (lpatientRx == null)
                            {
                                pPatientRx.RxId         = Guid.NewGuid().ToString();
                                pPatientRx.DateCreated  = DateTime.Now;
                                pPatientRx.DateModified = DateTime.Now;


                                lpatientRx = PatientRxExtension.PatientRxViewToPatientRxModel(pPatientRx);
                                User lUser = lIUserRepository.getUser(pPatientRx.PatientId);
                                if (lUser == null && lpatientRx.Patient != null)
                                {
                                    lIPatientRxRepository.InsertPatientRx(lpatientRx);
                                }
                                else
                                {
                                    lIPatientRxRepository.InsertPatientRx(lpatientRx);
                                }
                                return(RedirectToAction("Dashboard", "Provider", new { id = lpatientRx.ProviderId }));
                            }
                            else
                            {
                                TempData["msg"] = "<script>alert('Patient already registered with the surgery type');</script>";
                                getDetails();
                            }
                        }
                    }
                    else
                    {
                        getDetails();
                    }
                }
                else
                {
                    getDetails();
                }
            }
            catch (Exception ex)
            {
                logger.LogDebug("Patent Rx Error: " + ex);
            }
            return(View(pPatientRx));
        }
Example #7
0
        public JsonResult patientsummary(string sessionid, string rxid)
        {
            PatientSummary lsummary = new PatientSummary();

            try
            {
                if (!string.IsNullOrEmpty(sessionid) && !string.IsNullOrEmpty(rxid))
                {
                    Patient lpatient = IPatient.GetPatientBySessionID(sessionid);
                    if (lpatient != null)
                    {
                        PatientRx lPatientRx = lIPatientRxRepository.getPatientRxbyRxId(rxid, lpatient.PatientId.ToString());
                        if (lPatientRx != null)
                        {
                            lsummary.RxStartDate   = lPatientRx.RxStartDate.Value;
                            lsummary.RxEndDate     = lPatientRx.RxEndDate.Value;
                            lsummary.RxDuration    = Convert.ToInt32((lsummary.RxEndDate - lsummary.RxStartDate).TotalDays);
                            lsummary.RemainingDays = Convert.ToInt32((lsummary.RxEndDate - DateTime.Now).TotalDays);
                            double requiredSession = (((Convert.ToDateTime(lPatientRx.RxEndDate) - Convert.ToDateTime(lPatientRx.RxStartDate)).TotalDays / 7) * (int)lPatientRx.RxDaysPerweek * (int)lPatientRx.RxSessionsPerWeek);
                            int    totalSession    = lPatientRx.Session != null?lPatientRx.Session.ToList().Count : 0;

                            lsummary.SessionSuggested = Convert.ToInt32(requiredSession);
                            lsummary.SessionCompleted = totalSession;


                            PatientRx lPatientRxPain = lIPatientRxRepository.getPatientRxPain(lPatientRx.RxId, lPatientRx.PatientId.ToString());

                            if (lPatientRxPain != null)
                            {
                                List <Session> lSessionList = lPatientRx.Session != null?lPatientRxPain.Session.ToList() : null;

                                if (lSessionList != null && lSessionList.Count > 0)
                                {
                                    lsummary.MaxPainLevel            = lSessionList.Select(x => x.Pain.Max(y => y.PainLevel)).Max().HasValue ? lSessionList.Select(x => x.Pain.Max(y => y.PainLevel)).Max().Value : 0;
                                    lsummary.MaxFlexionAchieved      = lSessionList.Max(x => x.MaxFlexion);
                                    lsummary.MaxExtensionAchieved    = lSessionList.Max(x => x.MaxExtension);
                                    lsummary.TrexMinutes             = lSessionList.Select(x => x.RangeDuration1).Sum().HasValue ? lSessionList.Select(x => x.RangeDuration1).Sum().Value : 0;
                                    lsummary.FlexionExtensionMinutes = lSessionList.Select(x => x.RangeDuration2).Sum().HasValue ? lSessionList.Select(x => x.RangeDuration2).Sum().Value : 0;
                                }
                            }
                        }
                        else
                        {
                            return(Json(new { Status = (int)HttpStatusCode.InternalServerError, result = "patientrx is not configured", TimeZone = DateTime.UtcNow.ToString("s") }));
                        }
                    }
                    else
                    {
                        return(Json(new { Status = (int)HttpStatusCode.Forbidden, result = "patient is not configured", TimeZone = DateTime.UtcNow.ToString("s") }));
                    }
                }
                else
                {
                    return(Json(new { Status = (int)HttpStatusCode.Forbidden, result = "session id not valid", TimeZone = DateTime.UtcNow.ToString("s") }));
                }
            }
            catch (Exception ex)
            {
                return(Json(new { Status = (int)HttpStatusCode.InternalServerError, result = "Internal server error", TimeZone = DateTime.UtcNow.ToString("s") }));
            }
            return(Json(new { Status = (int)HttpStatusCode.OK, result = "success", Summary = lsummary, TimeZone = DateTime.UtcNow.ToString("s") }));
        }
Example #8
0
        // GET: /<controller>/

        public IActionResult Index(int id, string Username, string equipmentType, string actuator = "", string tab = "")
        {
            ReviewModel lmodel = new ReviewModel();

            ViewBag.tab           = tab;
            ViewBag.User          = Username;
            ViewBag.actuator      = actuator;
            ViewBag.EquipmentType = equipmentType;
            ViewBag.Id            = id;
            UsageViewModel lusage = new UsageViewModel();

            lusage.MaxSessionSuggested = 0;
            lusage.PercentageCompleted = 0;
            lusage.PercentagePending   = 0;
            ViewBag.Usage = lusage;
            PainViewModel lpain = new PainViewModel();

            lpain.TotalPain  = 0;
            lpain.LowPain    = 0;
            lpain.MediumPain = 0;
            lpain.HighPain   = 0;
            ViewBag.Pain     = lpain;
            JsonSerializerSettings lsetting1 = new JsonSerializerSettings();

            lsetting1.ContractResolver      = new CamelCasePropertyNamesContractResolver();
            lsetting1.ReferenceLoopHandling = ReferenceLoopHandling.Ignore;

            ViewBag.AppleDataFlexionString      = JsonConvert.SerializeObject(new List <ColumnrangeSeriesData>(), lsetting1);
            ViewBag.VolumeDataFlexionString     = JsonConvert.SerializeObject(new List <ColumnSeriesData>(), lsetting1);
            ViewBag.PainVolumeDataFlexionString = JsonConvert.SerializeObject(new List <ColumnSeriesData>(), lsetting1);

            ViewBag.AppleDataExtensionString      = JsonConvert.SerializeObject(new List <ColumnrangeSeriesData>(), lsetting1);
            ViewBag.VolumeDataExtensionString     = JsonConvert.SerializeObject(new List <ColumnSeriesData>(), lsetting1);
            ViewBag.PainVolumeDataExtensionString = JsonConvert.SerializeObject(new List <ColumnSeriesData>(), lsetting1);

            ViewBag.AppleDataFlexionExtensionString      = JsonConvert.SerializeObject(new List <ColumnrangeSeriesData>(), lsetting1);
            ViewBag.VolumeDataFlexionExtensionString     = JsonConvert.SerializeObject(new List <ColumnSeriesData>(), lsetting1);
            ViewBag.PainVolumeDataFlexionExtensionString = JsonConvert.SerializeObject(new List <ColumnSeriesData>(), lsetting1);
            try
            {
                //Insert to User Activity Log -Patient
                JsonSerializerSettings lsetting = new JsonSerializerSettings();
                lsetting.ReferenceLoopHandling = ReferenceLoopHandling.Ignore;


                if (HttpContext.Session.GetString("UserType") != ConstantsVar.Admin.ToString())
                {
                    if (string.IsNullOrEmpty(HttpContext.Session.GetString("ReviewID")))
                    {
                        PatientReview lreview = new PatientReview();
                        lreview.ReviewId  = Guid.NewGuid().ToString();
                        lreview.UserId    = HttpContext.Session.GetString("UserId");
                        lreview.UserName  = HttpContext.Session.GetString("UserName");
                        lreview.UserType  = HttpContext.Session.GetString("UserType");
                        lreview.SessionId = HttpContext.Session.GetString("SessionId");
                        Patient ppatient = context.Patient.FirstOrDefault(x => x.PatientId == id);
                        if (ppatient != null)
                        {
                            lreview.PatientId   = id.ToString();
                            lreview.PatientName = ppatient.PatientName;
                        }
                        lreview.ActivityType   = "Review";
                        lreview.StartTimeStamp = DateTime.Now;
                        lreview.Duration       = 0;
                        int res = lIPatientReviewRepository.InsertPatientReview(lreview);
                        if (!string.IsNullOrEmpty(lreview.ReviewId) && res > 0)
                        {
                            HttpContext.Session.SetString("ReviewID", lreview.ReviewId);
                            HttpContext.SetCookie("ReviewID", lreview.ReviewId, 5, CookieExpiryIn.Hours);
                            ViewBag.StartTimer = "true";
                        }
                    }
                }


                if (!string.IsNullOrEmpty(actuator) && !string.IsNullOrEmpty(tab) && tab == "Dashboard")
                {
                    string _uType = HttpContext.Session.GetString("UserType");
                    if (_uType == "3" || _uType == "2" || _uType == "1" || _uType == "0" || _uType == "6")
                    {
                        {
                            PatientRx patientRx = lIPatientRxRepository.getByRxIDId(id, actuator);
                            ViewBag.PatientRx = patientRx;
                        }
                        //Usage
                        PatientRx lPatientRx = lIPatientRxRepository.getPatientRx(id, equipmentType, actuator);

                        lusage.MaxSessionSuggested = 0;
                        lusage.PercentageCompleted = 0;
                        lusage.PercentagePending   = 100;
                        ViewBag.Usage = lusage;
                        if (lPatientRx != null)
                        {
                            double requiredSession = (((Convert.ToDateTime(lPatientRx.RxEndDate) - Convert.ToDateTime(lPatientRx.RxStartDate)).TotalDays / 7) * (int)lPatientRx.RxDaysPerweek * (int)lPatientRx.RxSessionsPerWeek);
                            int    totalSession    = lPatientRx.Session != null?lPatientRx.Session.ToList().Count : 0;

                            lusage.MaxSessionSuggested = (int)requiredSession;
                            lusage.PercentageCompleted = (int)((totalSession / requiredSession) * 100);
                            lusage.PercentagePending   = 100 - lusage.PercentageCompleted;
                            ViewBag.Usage = lusage;
                        }

                        //Pain
                        PatientRx lPatientRxPain = lIPatientRxRepository.getPatientRxPain(id, equipmentType, actuator);

                        lpain.TotalPain  = 0;
                        lpain.LowPain    = 0;
                        lpain.MediumPain = 0;
                        lpain.HighPain   = 100;
                        ViewBag.Pain     = lpain;
                        if (lPatientRxPain != null)
                        {
                            List <Session> lSessionList = lPatientRx.Session != null?lPatientRxPain.Session.ToList() : null;

                            if (lSessionList != null && lSessionList.Count > 0)
                            {
                                lpain.TotalPain  = lSessionList.Select(x => x.Pain.Count).Sum();
                                lpain.LowPain    = lpain.TotalPain > 0 ? (int)(((double)(lSessionList.Select(x => x.Pain.Where(y => y.PainLevel <= 2).Count()).Sum()) / lpain.TotalPain) * 100) : 0;
                                lpain.MediumPain = lpain.TotalPain > 0 ? (int)(((double)(lSessionList.Select(x => x.Pain.Where(y => y.PainLevel > 2 && y.PainLevel <= 5).Count()).Sum()) / lpain.TotalPain) * 100) : 0;
                                lpain.HighPain   = 100 - lpain.MediumPain - lpain.LowPain;
                                ViewBag.Pain     = lpain;
                            }
                        }



                        ROMChartViewModel ROM = lIPatientRxRepository.getPatientRxROMChart(id, equipmentType, actuator);
                        if (ROM != null)
                        {
                            ViewBag.ROM = ROM;
                        }

                        ViewBag.EquipmentType = equipmentType;
                        if (equipmentType == "Shoulder")
                        {
                            List <ColumnrangeSeriesData> appleData      = new List <ColumnrangeSeriesData>();
                            List <ColumnSeriesData>      volumeData     = new List <ColumnSeriesData>();
                            List <ColumnSeriesData>      painvolumeData = new List <ColumnSeriesData>();


                            //Equipment ROM HighStock Chart
                            HightStockShoulderViewModel highStockModel = lIPatientRxRepository.getPatientRxEquipmentROMForShoulderInHighStockChart(id, equipmentType, actuator);

                            if (highStockModel != null)
                            {
                                appleData = highStockModel.ROM;
                                ViewBag.AppleDataFlexion       = (appleData != null && appleData.Count > 0) ? appleData.OrderBy(o => o.X).ToList() : appleData;
                                ViewBag.AppleDataFlexionString = appleData != null?JsonConvert.SerializeObject(appleData, lsetting1) : JsonConvert.SerializeObject(new List <ColumnrangeSeriesData>(), lsetting1);

                                volumeData = highStockModel.Volume;
                                ViewBag.VolumeDataFlexion       = (volumeData != null && volumeData.Count > 0) ? volumeData.OrderBy(o => o.X).ToList() : volumeData;
                                ViewBag.VolumeDataFlexionString = volumeData != null?JsonConvert.SerializeObject(volumeData, lsetting1) : JsonConvert.SerializeObject(new List <ColumnSeriesData>(), lsetting1);


                                painvolumeData = highStockModel.PainVolume;
                                ViewBag.PainVolumeDataFlexion       = (painvolumeData != null && painvolumeData.Count > 0) ? painvolumeData.OrderBy(o => o.X).ToList() : painvolumeData;
                                ViewBag.PainVolumeDataFlexionString = painvolumeData != null?JsonConvert.SerializeObject(painvolumeData, lsetting1) : JsonConvert.SerializeObject(new List <ColumnSeriesData>(), lsetting1);


                                ViewBag.AppleDataExtensionString      = JsonConvert.SerializeObject(new List <ColumnrangeSeriesData>(), lsetting1);
                                ViewBag.VolumeDataExtensionString     = JsonConvert.SerializeObject(new List <ColumnSeriesData>(), lsetting1);
                                ViewBag.PainVolumeDataExtensionString = JsonConvert.SerializeObject(new List <ColumnSeriesData>(), lsetting1);

                                ViewBag.AppleDataFlexionExtensionString      = JsonConvert.SerializeObject(new List <ColumnrangeSeriesData>(), lsetting1);
                                ViewBag.VolumeDataFlexionExtensionString     = JsonConvert.SerializeObject(new List <ColumnSeriesData>(), lsetting1);
                                ViewBag.PainVolumeDataFlexionExtensionString = JsonConvert.SerializeObject(new List <ColumnSeriesData>(), lsetting1);
                            }
                            else
                            {
                                ViewBag.AppleDataFlexionString      = JsonConvert.SerializeObject(new List <ColumnrangeSeriesData>(), lsetting1);
                                ViewBag.VolumeDataFlexionString     = JsonConvert.SerializeObject(new List <ColumnSeriesData>(), lsetting1);
                                ViewBag.PainVolumeDataFlexionString = JsonConvert.SerializeObject(new List <ColumnSeriesData>(), lsetting1);

                                ViewBag.AppleDataExtensionString      = JsonConvert.SerializeObject(new List <ColumnrangeSeriesData>(), lsetting1);
                                ViewBag.VolumeDataExtensionString     = JsonConvert.SerializeObject(new List <ColumnSeriesData>(), lsetting1);
                                ViewBag.PainVolumeDataExtensionString = JsonConvert.SerializeObject(new List <ColumnSeriesData>(), lsetting1);

                                ViewBag.AppleDataFlexionExtensionString      = JsonConvert.SerializeObject(new List <ColumnrangeSeriesData>(), lsetting1);
                                ViewBag.VolumeDataFlexionExtensionString     = JsonConvert.SerializeObject(new List <ColumnSeriesData>(), lsetting1);
                                ViewBag.PainVolumeDataFlexionExtensionString = JsonConvert.SerializeObject(new List <ColumnSeriesData>(), lsetting1);
                            }

                            //Equipment ROM
                            ViewBag.EquipmentType = equipmentType;
                        }
                        else
                        {
                            //Equipment ROM HighStock Chart
                            List <ColumnrangeSeriesData> appleDataFlexion      = new List <ColumnrangeSeriesData>();
                            List <ColumnSeriesData>      volumeDataFlexion     = new List <ColumnSeriesData>();
                            List <ColumnSeriesData>      painvolumeDataFlexion = new List <ColumnSeriesData>();

                            List <ColumnrangeSeriesData> appleDataExtension      = new List <ColumnrangeSeriesData>();
                            List <ColumnSeriesData>      volumeDataExtension     = new List <ColumnSeriesData>();
                            List <ColumnSeriesData>      painvolumeDataExtension = new List <ColumnSeriesData>();

                            List <ColumnrangeSeriesData> appleDataFlexionExtension      = new List <ColumnrangeSeriesData>();
                            List <ColumnSeriesData>      volumeDataFlexionExtension     = new List <ColumnSeriesData>();
                            List <ColumnSeriesData>      painvolumeDataFlexionExtension = new List <ColumnSeriesData>();

                            HightStockShoulderViewModel highStockModelFlexion          = lIPatientRxRepository.getPatientRxEquipmentROMByFlexionInHighStockChart(id, equipmentType, actuator);
                            HightStockShoulderViewModel highStockModelExtension        = lIPatientRxRepository.getPatientRxEquipmentROMByExtensionInHighStockChart(id, equipmentType, actuator);
                            HightStockShoulderViewModel highStockModelFlexionExtension = lIPatientRxRepository.getPatientRxEquipmentROMByFlexionExtensionInHighStockChart(id, equipmentType, actuator);
                            if (highStockModelFlexion != null)
                            {
                                appleDataFlexion               = highStockModelFlexion.ROM;
                                ViewBag.AppleDataFlexion       = (appleDataFlexion != null && appleDataFlexion.Count > 0) ? appleDataFlexion.OrderBy(o => o.X).ToList() : appleDataFlexion;
                                ViewBag.AppleDataFlexionString = appleDataFlexion != null?JsonConvert.SerializeObject(appleDataFlexion, lsetting1) : JsonConvert.SerializeObject(new List <ColumnrangeSeriesData>(), lsetting1);

                                volumeDataFlexion               = highStockModelFlexion.Volume;
                                ViewBag.VolumeDataFlexion       = (volumeDataFlexion != null && volumeDataFlexion.Count > 0) ? volumeDataFlexion.OrderBy(o => o.X).ToList() : volumeDataFlexion;
                                ViewBag.VolumeDataFlexionString = volumeDataFlexion != null?JsonConvert.SerializeObject(volumeDataFlexion, lsetting1) : JsonConvert.SerializeObject(new List <ColumnSeriesData>(), lsetting1);

                                painvolumeDataFlexion = highStockModelFlexion.PainVolume;

                                ViewBag.PainVolumeDataFlexion = (painvolumeDataFlexion != null && painvolumeDataFlexion.Count > 0) ? painvolumeDataFlexion.OrderBy(o => o.X).ToList() : painvolumeDataFlexion;

                                ViewBag.PainVolumeDataFlexionString = painvolumeDataFlexion != null?JsonConvert.SerializeObject(painvolumeDataFlexion, lsetting1) : JsonConvert.SerializeObject(new List <ColumnSeriesData>(), lsetting1);
                            }
                            else
                            {
                                ViewBag.AppleDataFlexionString      = JsonConvert.SerializeObject(new List <ColumnrangeSeriesData>(), lsetting1);
                                ViewBag.VolumeDataFlexionString     = JsonConvert.SerializeObject(new List <ColumnSeriesData>(), lsetting1);
                                ViewBag.PainVolumeDataFlexionString = JsonConvert.SerializeObject(new List <ColumnSeriesData>(), lsetting1);
                            }
                            if (highStockModelExtension != null)
                            {
                                appleDataExtension = highStockModelExtension.ROM;

                                ViewBag.AppleDataExtension = (appleDataExtension != null && appleDataExtension.Count > 0) ? appleDataExtension.OrderBy(o => o.X).ToList() : appleDataExtension;

                                ViewBag.AppleDataExtensionString = appleDataExtension != null?JsonConvert.SerializeObject(appleDataExtension, lsetting1) : JsonConvert.SerializeObject(new List <ColumnrangeSeriesData>(), lsetting1);

                                volumeDataExtension               = highStockModelExtension.Volume;
                                ViewBag.VolumeDataExtension       = (volumeDataExtension != null && volumeDataExtension.Count > 0) ? volumeDataExtension.OrderBy(o => o.X).ToList() : volumeDataExtension;
                                ViewBag.VolumeDataExtensionString = volumeDataExtension != null?JsonConvert.SerializeObject(volumeDataExtension, lsetting1) : JsonConvert.SerializeObject(new List <ColumnSeriesData>(), lsetting1);

                                painvolumeDataExtension               = highStockModelExtension.PainVolume;
                                ViewBag.PainVolumeDataExtension       = (painvolumeDataExtension != null && painvolumeDataExtension.Count > 0) ? painvolumeDataExtension.OrderBy(o => o.X).ToList() : painvolumeDataExtension;
                                ViewBag.PainVolumeDataExtensionString = painvolumeDataExtension != null?JsonConvert.SerializeObject(painvolumeDataExtension, lsetting1) : JsonConvert.SerializeObject(new List <ColumnSeriesData>(), lsetting1);
                            }
                            else
                            {
                                ViewBag.AppleDataExtensionString      = JsonConvert.SerializeObject(new List <ColumnrangeSeriesData>(), lsetting1);
                                ViewBag.VolumeDataExtensionString     = JsonConvert.SerializeObject(new List <ColumnSeriesData>(), lsetting1);
                                ViewBag.PainVolumeDataExtensionString = JsonConvert.SerializeObject(new List <ColumnSeriesData>(), lsetting1);
                            }
                            if (highStockModelFlexionExtension != null)
                            {
                                appleDataFlexionExtension = highStockModelFlexionExtension.ROM;

                                ViewBag.AppleDataFlexionExtension       = (appleDataFlexionExtension != null && appleDataFlexionExtension.Count > 0) ? appleDataFlexionExtension.OrderBy(o => o.X).ToList() : appleDataFlexionExtension;
                                ViewBag.AppleDataFlexionExtensionString = appleDataFlexionExtension != null?JsonConvert.SerializeObject(appleDataFlexionExtension, lsetting1) : JsonConvert.SerializeObject(new List <ColumnrangeSeriesData>(), lsetting1);

                                volumeDataFlexionExtension               = highStockModelFlexionExtension.Volume;
                                ViewBag.VolumeDataFlexionExtension       = (volumeDataFlexionExtension != null && volumeDataFlexionExtension.Count > 0) ? volumeDataFlexionExtension.OrderBy(o => o.X).ToList() : volumeDataFlexionExtension;
                                ViewBag.VolumeDataFlexionExtensionString = volumeDataFlexionExtension != null?JsonConvert.SerializeObject(volumeDataFlexionExtension, lsetting1) : JsonConvert.SerializeObject(new List <ColumnSeriesData>(), lsetting1);

                                painvolumeDataFlexionExtension               = highStockModelFlexionExtension.PainVolume;
                                ViewBag.PainVolumeDataFlexionExtension       = (painvolumeDataFlexionExtension != null && painvolumeDataFlexionExtension.Count > 0) ? painvolumeDataFlexionExtension.OrderBy(o => o.X).ToList() : painvolumeDataFlexionExtension;
                                ViewBag.PainVolumeDataFlexionExtensionString = painvolumeDataFlexionExtension != null?JsonConvert.SerializeObject(painvolumeDataFlexionExtension, lsetting1) : JsonConvert.SerializeObject(new List <ColumnSeriesData>(), lsetting1);
                            }
                            else
                            {
                                ViewBag.AppleDataFlexionExtensionString      = JsonConvert.SerializeObject(new List <ColumnrangeSeriesData>(), lsetting1);
                                ViewBag.VolumeDataFlexionExtensionString     = JsonConvert.SerializeObject(new List <ColumnSeriesData>(), lsetting1);
                                ViewBag.PainVolumeDataFlexionExtensionString = JsonConvert.SerializeObject(new List <ColumnSeriesData>(), lsetting1);
                            }
                            //Equipment ROM
                            ViewBag.EquipmentType = equipmentType;
                        }


                        //Treatment Calendar
                        List <TreatmentCalendarViewModel> TreatmentCalendarList = lIPatientRxRepository.getTreatmentCalendar(id, equipmentType, actuator);
                        if (TreatmentCalendarList != null && TreatmentCalendarList.Count > 0)
                        {
                            ViewBag.TreatmentCalendar = TreatmentCalendarList;
                        }

                        //Current Sessions
                        List <Session> SessionList = lIPatientRxRepository.getCurrentSessions(id, equipmentType, actuator);
                        if (SessionList != null && SessionList.Count > 0)
                        {
                            ViewBag.SessionList = SessionList;
                        }
                        if (actuator == "Forward Flexion" || actuator == "External Rotation")
                        {
                            ViewBag.Extension = "External Rotation";
                            ViewBag.Flexion   = "Flexion";
                        }
                        else
                        {
                            ViewBag.Flexion   = "Flexion";
                            ViewBag.Extension = "Extension";
                        }
                    }
                }
                else if (!string.IsNullOrEmpty(actuator) && !string.IsNullOrEmpty(tab) && tab == "Details")
                {
                    List <SelectListItem> list        = new List <SelectListItem>();
                    NewPatient            _newPatient = new NewPatient();
                    if (TempData["Patient"] != null && !string.IsNullOrEmpty(TempData["Patient"].ToString()))
                    {
                        _newPatient = JsonConvert.DeserializeObject <NewPatient>(TempData["Patient"].ToString());
                    }
                    getDetails();
                    List <Sides> Sides = Utilities.GetSide();
                    list = new List <SelectListItem>();
                    foreach (Sides ex in Sides)
                    {
                        list.Add(new SelectListItem {
                            Text = ex.Side.ToString(), Value = ex.Side.ToString()
                        });
                    }
                    ViewBag.sides = new SelectList(list, "Value", "Text");

                    _newPatient          = INewPatient.GetPatientByPatId(Convert.ToInt32(id));
                    ViewBag.PatientName  = _newPatient.PatientName;
                    _newPatient.Action   = "edit";
                    _newPatient.Actuator = actuator;

                    if (HttpContext.Session.GetString("UserType") == ConstantsVar.Admin.ToString() || HttpContext.Session.GetString("UserType") == ConstantsVar.Support.ToString())
                    {
                        List <User> _userProviderlist = lIUserRepository.getUserListByType(ConstantsVar.Provider);

                        var ObjList = _userProviderlist.Select(r => new SelectListItem
                        {
                            Value = r.UserId.ToString(),
                            Text  = r.Name
                        });
                        ViewBag.Provider = new SelectList(ObjList, "Value", "Text");
                    }
                    List <User> _userTherapistlist = lIUserRepository.getUserListByType(ConstantsVar.Therapist);

                    var ObjListTherapist = _userTherapistlist.Select(r => new SelectListItem
                    {
                        Value = r.UserId.ToString(),
                        Text  = r.Name
                    });
                    ViewBag.Therapist = new SelectList(ObjListTherapist, "Value", "Text");

                    List <User> _patientAdministratorlist = lIUserRepository.getUserListByType(ConstantsVar.PatientAdministrator);

                    var ObjListPatientAdmin = _patientAdministratorlist.Select(r => new SelectListItem
                    {
                        Value = r.UserId.ToString(),
                        Text  = r.Name
                    });
                    ViewBag.PatientAdministrator = new SelectList(ObjListPatientAdmin, "Value", "Text");
                    _newPatient.returnView       = "review";
                    lmodel.Patient = _newPatient;
                }
                else if (!string.IsNullOrEmpty(actuator) && !string.IsNullOrEmpty(tab) && tab == "Rx")
                {
                    NewPatientWithProtocol    newPatientWithProtocol = new NewPatientWithProtocol();
                    List <EquipmentExcercise> EquipmentExcerciselist = Utilities.GetEquipmentExcercise();
                    List <ExcerciseProtocol>  ExcerciseProtocollist  = Utilities.GetExcerciseProtocol();
                    newPatientWithProtocol.NewPatientRXList = new List <NewPatientRx>();
                    List <PatientRx> PatientRx = null;

                    ViewBag.Action = "edit";

                    PatientRx = INewPatient.GetNewPatientRxByPatId(id.ToString());
                    if (PatientRx != null && PatientRx.Count > 0)
                    {
                        foreach (PatientRx patRx in PatientRx)
                        {
                            ViewBag.EquipmentType = patRx.EquipmentType;
                            ViewBag.PatientName   = patRx.Patient.PatientName;
                            ViewBag.SurgeryDate   = patRx.Patient.SurgeryDate;
                            EquipmentExcercise EquipmentExcercise = EquipmentExcerciselist.Where(p => p.Limb.ToLower() == patRx.EquipmentType.ToLower() && p.ExcerciseEnum == patRx.DeviceConfiguration).FirstOrDefault();
                            ExcerciseProtocol  ExcerciseProtocol  = ExcerciseProtocollist.Where(p => p.Limb == patRx.EquipmentType && p.ExcerciseEnum == patRx.DeviceConfiguration).Distinct().FirstOrDefault();
                            NewPatientRx       _NewPatientRx      = new NewPatientRx();
                            _NewPatientRx.Action = "edit";

                            DeviceCalibration ldeviceCalibration = lIDeviceCalibrationRepository.getDeviceCalibrationByRxID(patRx.RxId);
                            if (patRx.EquipmentType.ToLower() == "shoulder")
                            {
                                if (patRx.DeviceConfiguration == "Forward Flexion")
                                {
                                    _NewPatientRx.HeadingFlexion = "Degree of Flexion";
                                    _NewPatientRx.CurrentFlex    = Constants.Sh_Flex_Current;
                                    _NewPatientRx.GoalFlex       = Constants.Sh_Flex_Goal;

                                    _NewPatientRx.Flex_Current_Start = Constants.Sh_Flex_Current;
                                    _NewPatientRx.Flex_Current_End   = Constants.Sh_Flex_Goal;
                                    _NewPatientRx.Flex_Goal_Start    = Constants.Sh_Flex_Current;
                                    _NewPatientRx.Flex_Goal_End      = Constants.Sh_Flex_Goal;
                                }
                                if (patRx.DeviceConfiguration == "External Rotation")
                                {
                                    _NewPatientRx.HeadingFlexion = "Degree of External Rotation";
                                    _NewPatientRx.CurrentFlex    = Constants.Sh_ExRot_Current;
                                    _NewPatientRx.GoalFlex       = Constants.Sh_ExRot_Goal;

                                    _NewPatientRx.Flex_Current_Start = Constants.Sh_ExRot_Current;
                                    _NewPatientRx.Flex_Current_End   = Constants.Sh_ExRot_Goal;
                                    _NewPatientRx.Flex_Goal_Start    = Constants.Sh_ExRot_Current;
                                    _NewPatientRx.Flex_Goal_End      = Constants.Sh_ExRot_Goal;
                                }
                            }
                            else if (patRx.EquipmentType.ToLower() == "ankle")
                            {
                                _NewPatientRx.HeadingFlexion   = "Degree of Flexion";
                                _NewPatientRx.HeadingExtension = "Degree of Extension";
                                _NewPatientRx.CurrentFlex      = Constants.Ankle_Flex_Current;
                                _NewPatientRx.GoalFlex         = Constants.Ankle_Flex_Goal;
                                _NewPatientRx.CurrentExten     = Constants.Ankle_Ext_Current;
                                _NewPatientRx.GoalExten        = Constants.Ankle_Ext_Goal;



                                _NewPatientRx.Flex_Current_Start = Constants.Ankle_Flex_Current;
                                _NewPatientRx.Flex_Current_End   = Constants.Ankle_Flex_Goal;
                                _NewPatientRx.Flex_Goal_Start    = Constants.Ankle_Flex_Current;
                                _NewPatientRx.Flex_Goal_End      = Constants.Ankle_Flex_Goal;

                                _NewPatientRx.Ext_Current_Start = Constants.Ankle_Ext_Current;
                                _NewPatientRx.Ext_Current_End   = Constants.Ankle_Ext_Goal;
                                _NewPatientRx.Ext_Goal_Start    = Constants.Ankle_Ext_Current;
                                _NewPatientRx.Ext_Goal_End      = Constants.Ankle_Ext_Goal;
                            }
                            else
                            {
                                _NewPatientRx.HeadingFlexion   = "Degree of Flexion";
                                _NewPatientRx.HeadingExtension = "Degree of Extension";
                                _NewPatientRx.CurrentFlex      = Constants.Knee_Flex_Current;
                                _NewPatientRx.GoalFlex         = Constants.Knee_Flex_Goal;
                                _NewPatientRx.CurrentExten     = Constants.Knee_Ext_Current;
                                _NewPatientRx.GoalExten        = Constants.Knee_Ext_Goal;

                                _NewPatientRx.Flex_Current_Start = Constants.Knee_Flex_Current_Start;
                                _NewPatientRx.Flex_Current_End   = Constants.Knee_Flex_Current_End;
                                _NewPatientRx.Flex_Goal_Start    = Constants.Knee_Flex_Goal_Start;
                                _NewPatientRx.Flex_Goal_End      = (ldeviceCalibration != null && ldeviceCalibration.Actuator2ExtendedAngle != null) ? Convert.ToInt32(ldeviceCalibration.Actuator2ExtendedAngle) : Constants.Knee_Flex_Goal_End;

                                _NewPatientRx.Ext_Current_Start = Constants.Knee_Ext_Current_Start;
                                _NewPatientRx.Ext_Current_End   = Constants.Knee_Ext_Current_End;
                                _NewPatientRx.Ext_Goal_Start    = Constants.Knee_Ext_Goal_Start;
                                _NewPatientRx.Ext_Goal_End      = (ldeviceCalibration != null && ldeviceCalibration.Actuator2RetractedAngle != null) ? Convert.ToInt32(ldeviceCalibration.Actuator2RetractedAngle) : Constants.Knee_Ext_Goal_End;
                            }
                            _NewPatientRx.TherapyType         = EquipmentExcercise.ExcerciseName;
                            _NewPatientRx.DeviceConfiguration = EquipmentExcercise.ExcerciseEnum;
                            _NewPatientRx.ProtocolEnum        = ExcerciseProtocol.ProtocolEnum;
                            _NewPatientRx.ProtocolName        = ExcerciseProtocol.ProtocolName;
                            _NewPatientRx.EquipmentType       = patRx.EquipmentType;

                            _NewPatientRx.RxId              = patRx.RxId;
                            _NewPatientRx.RxDaysPerweek     = patRx.RxDaysPerweek;
                            _NewPatientRx.RxSessionsPerWeek = patRx.RxSessionsPerWeek;
                            _NewPatientRx.RxStartDate       = patRx.RxStartDate;
                            _NewPatientRx.RxEndDate         = patRx.RxEndDate;
                            _NewPatientRx.ProviderId        = patRx.ProviderId;
                            _NewPatientRx.PatientId         = patRx.PatientId;

                            _NewPatientRx.CurrentExtension = patRx.CurrentExtension;
                            _NewPatientRx.CurrentFlexion   = patRx.CurrentFlexion;
                            _NewPatientRx.GoalExtension    = patRx.GoalExtension;
                            _NewPatientRx.GoalFlexion      = patRx.GoalFlexion;
                            _NewPatientRx.PainThreshold    = patRx.PainThreshold;
                            _NewPatientRx.RateOfChange     = patRx.RateOfChange;

                            newPatientWithProtocol.PainThreshold = patRx.PainThreshold;
                            newPatientWithProtocol.RateOfChange  = patRx.RateOfChange;
                            newPatientWithProtocol.NewPatientRXList.Add(_NewPatientRx);
                        }
                    }
                    newPatientWithProtocol.returnView = "Rx";
                    lmodel.Rx = newPatientWithProtocol;
                }
                else if (!string.IsNullOrEmpty(actuator) && !string.IsNullOrEmpty(tab) && tab == "Exercises")
                {
                    ViewBag.PatientName = Username;
                    List <NewProtocol> _result = INewPatient.GetProtocolListBypatId(id.ToString());
                    ViewBag.VisibleAddButton    = false;
                    ViewBag.VisibleAddButtonExt = false;
                    if (!string.IsNullOrEmpty(equipmentType))
                    {
                        if (equipmentType.ToLower() == "shoulder")
                        {
                            PatientConfiguration lconfig = lIPatientConfigurationRepository.getPatientConfigurationbyPatientId(id, equipmentType, "Forward Flexion");
                            if (lconfig != null)
                            {
                                ViewBag.VisibleAddButton = true;
                                if (_result != null)
                                {
                                    List <NewProtocol> _resultFlex = _result.Where(x => x.ExcerciseEnum == "Forward Flexion").ToList();
                                    if (_resultFlex == null || (_resultFlex != null && _resultFlex.Count == 0))
                                    {
                                        ViewBag.RxId = lconfig.RxId;
                                    }
                                }
                            }
                            PatientConfiguration lconfigext = lIPatientConfigurationRepository.getPatientConfigurationbyPatientId(Convert.ToInt32(id), equipmentType, "External Rotation");
                            if (lconfigext != null)
                            {
                                ViewBag.VisibleAddButtonExt = true;
                                if (_result != null)
                                {
                                    List <NewProtocol> _resultExt = _result.Where(x => x.ExcerciseEnum == "External Rotation").ToList();
                                    if (_resultExt == null || (_resultExt != null && _resultExt.Count == 0))
                                    {
                                        ViewBag.RxIdExt = lconfig.RxId;
                                    }
                                }
                            }
                        }
                        else
                        {
                            PatientConfiguration lconfig = lIPatientConfigurationRepository.getPatientConfigurationbyPatientId(Convert.ToInt32(id), equipmentType);

                            if (lconfig != null)
                            {
                                ViewBag.VisibleAddButton = true;

                                if (_result == null || (_result != null && _result.Count == 0))
                                {
                                    ViewBag.RxId = lconfig.RxId;
                                }
                                else
                                {
                                    ViewBag.RxId = _result[0].RxId;
                                }
                            }
                        }
                    }


                    ViewBag.ProtocolList = _result;
                    ViewBag.etype        = equipmentType;

                    if (String.IsNullOrEmpty(Username))
                    {
                        ViewBag.PatientName = Username;
                    }
                    if (_result != null && _result.Count > 0 && String.IsNullOrEmpty(Username))
                    {
                        ViewBag.PatientName = _result[0].PatientName;
                    }

                    lmodel.Exercises = _result;
                }
                else if (!string.IsNullOrEmpty(actuator) && !string.IsNullOrEmpty(tab) && tab == "Sessions")
                {
                    if (!String.IsNullOrEmpty(id.ToString()))
                    {
                        ViewBag.actuator      = actuator;
                        ViewBag.EquipmentType = equipmentType;
                        ViewBag.patientId     = id;
                        ViewBag.PatientName   = Username;
                        HttpContext.Session.SetString("PatientID", id.ToString());
                    }
                    if (string.IsNullOrEmpty(actuator) && !string.IsNullOrEmpty(equipmentType))
                    {
                        if (equipmentType.ToLower() == "shoulder")
                        {
                            actuator = "Forward Flexion";
                        }
                        else
                        {
                            actuator = "Flexion-Extension";
                        }
                        ViewBag.actuator = actuator;
                    }
                    logger.LogDebug("Pain Post Start");
                    if (!String.IsNullOrEmpty(Username))
                    {
                        HttpContext.Session.SetString("PatientName", Username);
                    }
                    if (HttpContext.Session.GetString("PatientName") != null && HttpContext.Session.GetString("PatientName").ToString() != "")
                    {
                        if (!String.IsNullOrEmpty(Username))
                        {
                            ViewBag.PatientName = HttpContext.Session.GetString("PatientName").ToString();
                        }
                    }
                    List <UserSession> pSession = new List <UserSession>();

                    HttpContext.Session.SetString("ProtocolName", "");
                    HttpContext.Session.SetString("ProtocoloId", "");
                    if (!String.IsNullOrEmpty(Username) && !String.IsNullOrEmpty(id.ToString()))
                    {
                        pSession = lISessionInterface.getSessionList(id.ToString(), actuator);
                    }
                    else
                    {
                        if (String.IsNullOrEmpty(Username) && String.IsNullOrEmpty(id.ToString()) && HttpContext.Session.GetString("UserId") != null && HttpContext.Session.GetString("UserType") != null && HttpContext.Session.GetString("UserType").ToString() == "2")
                        {
                            pSession = lISessionInterface.getSessionListByTherapistId(HttpContext.Session.GetString("UserId"));
                        }
                        else
                        {
                            pSession = lISessionInterface.getSessionList();
                        }
                    }
                    if (pSession != null && pSession.Count > 0)
                    {
                        lmodel.Sessions     = pSession;
                        ViewBag.SessionList = pSession;
                    }
                }
                else if (!string.IsNullOrEmpty(actuator) && !string.IsNullOrEmpty(tab) && tab == "History")
                {
                    ViewBag.History = lIAppointmentScheduleRepository.getAppointmentListByPatientId(Convert.ToInt32(id), HttpContext.Session.GetString("timezoneid"));
                }
                else if (!string.IsNullOrEmpty(actuator) && !string.IsNullOrEmpty(tab) && tab == "Messages")
                {
                    Patient lpatient = IPatient.GetPatientByPatientID(id);
                    if (lpatient != null)
                    {
                        List <MessageView> lmessages = lIMessageRepository.getMessagesbyTimeZone(lpatient.PatientLoginId, HttpContext.Session.GetString("UserId"), HttpContext.Session.GetString("timezoneid"));
                        ViewBag.PatientId = lpatient.PatientLoginId;
                        ViewBag.Messages  = lmessages.OrderBy(x => x.Datetime);
                    }
                }
                else if (!string.IsNullOrEmpty(actuator) && !string.IsNullOrEmpty(tab) && tab == "PatientReviews")
                {
                    List <PatientReviewTab> lPatientReviews = new List <PatientReviewTab>();
                    try
                    {
                        if (!string.IsNullOrEmpty(HttpContext.Session.GetString("UserId")))
                        {
                            ViewBag.lPatientReviews = lIPatientReviewRepository.GetPatientReviewListTab(ViewBag.User);

                            lmodel.PatientReviews = lPatientReviews;
                        }
                        else
                        {
                            ViewBag.lPatientReviews = lIPatientReviewRepository.GetPatientReviewList();
                            lmodel.PatientReviews   = ViewBag.lPatientReviews;
                        }
                    }
                    catch (Exception ex)
                    {
                        logger.LogDebug("Patient Review Error: " + ex);
                        return(View());
                    }
                }
                return(View(lmodel));
            }
            catch (Exception ex)
            {
                logger.LogDebug("Error: " + ex);
                return(View(null));
            }
        }
        public IActionResult Patient(int id, string Username, string equipmentType, string actuator = "")
        {
            ViewBag.User     = Username;
            ViewBag.actuator = actuator;

            string _uType = HttpContext.Session.GetString("UserType");

            if (_uType == "3" || _uType == "2" || _uType == "1" || _uType == "0" || _uType == "6")
            {
                {
                    PatientRx patientRx = lIPatientRxRepository.getByRxIDId(id, actuator);
                    ViewBag.PatientRx = patientRx;
                }
                //Usage
                PatientRx      lPatientRx = lIPatientRxRepository.getPatientRx(id, equipmentType, actuator);
                UsageViewModel lusage     = new UsageViewModel();
                lusage.MaxSessionSuggested = 0;
                lusage.PercentageCompleted = 0;
                lusage.PercentagePending   = 100;
                ViewBag.Usage = lusage;
                if (lPatientRx != null)
                {
                    double requiredSession = (((Convert.ToDateTime(lPatientRx.RxEndDate) - Convert.ToDateTime(lPatientRx.RxStartDate)).TotalDays / 7) * (int)lPatientRx.RxDaysPerweek * (int)lPatientRx.RxSessionsPerWeek);
                    int    totalSession    = lPatientRx.Session != null?lPatientRx.Session.ToList().Count : 0;

                    lusage.MaxSessionSuggested = (int)requiredSession;
                    lusage.PercentageCompleted = (int)((totalSession / requiredSession) * 100);
                    lusage.PercentagePending   = 100 - lusage.PercentageCompleted;
                    ViewBag.Usage = lusage;
                }

                //Pain
                PatientRx     lPatientRxPain = lIPatientRxRepository.getPatientRxPain(id, equipmentType, actuator);
                PainViewModel lpain          = new PainViewModel();
                lpain.TotalPain  = 0;
                lpain.LowPain    = 0;
                lpain.MediumPain = 0;
                lpain.HighPain   = 100;
                ViewBag.Pain     = lpain;
                if (lPatientRxPain != null)
                {
                    List <Session> lSessionList = lPatientRx.Session != null?lPatientRxPain.Session.ToList() : null;

                    if (lSessionList != null && lSessionList.Count > 0)
                    {
                        lpain.TotalPain  = lSessionList.Select(x => x.Pain.Count).Sum();
                        lpain.LowPain    = lpain.TotalPain > 0 ? (int)(((double)(lSessionList.Select(x => x.Pain.Where(y => y.PainLevel <= 2).Count()).Sum()) / lpain.TotalPain) * 100) : 0;
                        lpain.MediumPain = lpain.TotalPain > 0 ? (int)(((double)(lSessionList.Select(x => x.Pain.Where(y => y.PainLevel > 2 && y.PainLevel <= 5).Count()).Sum()) / lpain.TotalPain) * 100) : 0;
                        lpain.HighPain   = 100 - lpain.MediumPain - lpain.LowPain;
                        ViewBag.Pain     = lpain;
                    }
                }



                ROMChartViewModel ROM = lIPatientRxRepository.getPatientRxROMChart(id, equipmentType, actuator);
                if (ROM != null)
                {
                    ViewBag.ROM = ROM;
                }

                ViewBag.EquipmentType = equipmentType;
                if (equipmentType == "Shoulder")
                {
                    //Equipment ROM
                    ViewBag.EquipmentType = equipmentType;
                    List <ShoulderViewModel> ROMList = lIPatientRxRepository.getPatientRxEquipmentROMForShoulder(id, equipmentType, actuator);
                    if (ROMList != null && ROMList.Count > 0)
                    {
                        ViewBag.FlexionColor = (ROMList.Where(x => x.Flexion > 0).Count() > 0) ? "Orange" : "White";
                        ViewBag.EquipmentROM = ROMList;
                    }
                    //Compliance
                    List <ShoulderViewModel> ComplianceList = lIPatientRxRepository.getPatientRxComplianceForShoulder(id, equipmentType, actuator);
                    if (ComplianceList != null && ComplianceList.Count > 0)
                    {
                        ViewBag.ComFlexionColor = (ComplianceList.Where(x => x.Flexion > 0).Count() > 0) ? "Orange" : "White";
                        ViewBag.Compliance      = ComplianceList;
                    }
                }
                else
                {
                    //Equipment ROM
                    ViewBag.EquipmentType = equipmentType;
                    List <FlexionViewModel> FlexionList = lIPatientRxRepository.getPatientRxEquipmentROMByFlexion(id, equipmentType, actuator);
                    if (FlexionList != null && FlexionList.Count > 0)
                    {
                        ViewBag.EquipmentFlexion = FlexionList;
                    }
                    List <ExtensionViewModel> ExtensionList = lIPatientRxRepository.getPatientRxEquipmentROMByExtension(id, equipmentType, actuator);
                    if (ExtensionList != null && ExtensionList.Count > 0)
                    {
                        ViewBag.EquipmentExtension = ExtensionList;
                    }

                    //Compliance

                    List <FlexionViewModel> CFlexionList = lIPatientRxRepository.getPatientRxComplianceByFlexion(id, equipmentType, actuator);
                    if (CFlexionList != null && CFlexionList.Count > 0)
                    {
                        ViewBag.FlexionCompliance = CFlexionList;
                    }
                    List <ExtensionViewModel> CExtensionList = lIPatientRxRepository.getPatientRxComplianceByExtension(id, equipmentType, actuator);
                    if (CExtensionList != null && CExtensionList.Count > 0)
                    {
                        ViewBag.ExtensionCompliance = CExtensionList;
                    }
                }


                //Treatment Calendar
                List <TreatmentCalendarViewModel> TreatmentCalendarList = lIPatientRxRepository.getTreatmentCalendar(id, equipmentType, actuator);
                if (TreatmentCalendarList != null && TreatmentCalendarList.Count > 0)
                {
                    ViewBag.TreatmentCalendar = TreatmentCalendarList;
                }

                //Current Sessions
                List <Session> SessionList = lIPatientRxRepository.getCurrentSessions(id, equipmentType, actuator);
                if (SessionList != null && SessionList.Count > 0)
                {
                    ViewBag.SessionList = SessionList;
                }


                if (actuator == "Forward Flexion" || actuator == "External Rotation")
                {
                    ViewBag.Extension = "External Rotation";
                    ViewBag.Flexion   = "Flexion";
                }
                else
                {
                    ViewBag.Flexion   = "Flexion";
                    ViewBag.Extension = "Extension";
                }
            }


            return(View());
        }
        public IActionResult Add(SessionView session)
        {
            try
            {
                NewProtocol ptoList = INewPatient.GetProtocolByproId(session.ProtocolId);
                if (ptoList != null)
                {
                    PatientRx lrx = IPatientRx.getPatientRx(ptoList.RxId);
                    if (lrx != null)
                    {
                        Session _session = new Session();

                        _session.SessionId    = Guid.NewGuid().ToString();
                        _session.PatientId    = ptoList.PatientId;
                        _session.RxId         = ptoList.RxId;
                        _session.ProtocolId   = ptoList.ProtocolId;
                        _session.SessionDate  = session.SessionDate;
                        _session.Duration     = session.Duration;
                        _session.Reps         = session.Reps;
                        _session.MaxExtension = session.MaxExtension;
                        _session.MaxFlexion   = session.MaxFlexion;
                        _session.MaxPain      = session.MaxPain;
                        _session.PainCount    = session.PainCount;

                        if (session.MaxFlexion > lrx.CurrentFlexion && session.MaxExtension > lrx.CurrentExtension)
                        {
                            int res = INewPatient.ChangeRxCurrent(lrx.RxId, session.MaxFlexion, session.MaxExtension, "Patient");
                        }
                        else if (session.MaxFlexion > lrx.CurrentFlexion)
                        {
                            int res = INewPatient.ChangeRxCurrentFlexion(lrx.RxId, session.MaxFlexion, "Patient");
                        }
                        else if (session.MaxExtension > lrx.CurrentExtension)
                        {
                            int res = INewPatient.ChangeRxCurrentExtension(lrx.RxId, session.MaxExtension, "Patient");
                        }
                        else
                        {
                            RomchangeLog plog = new RomchangeLog();
                            plog.RxId              = lrx.RxId;
                            plog.PreviousFlexion   = lrx.CurrentFlexion.HasValue ? Convert.ToInt32(lrx.CurrentFlexion) : 0;
                            plog.PreviousExtension = lrx.CurrentExtension.HasValue ? Convert.ToInt32(lrx.CurrentExtension) : 0;
                            plog.CreatedDate       = DateTime.UtcNow;
                            plog.ChangedBy         = "Patient";
                            IRomChangeLog.InsertRomChangeLog(plog);
                        }

                        lISessionInterface.InsertSession(_session);
                    }
                }

                return(RedirectToAction("Index", "SessionView", new { id = session.PatientId, Username = session.Patname, Etype = session.EType, actuator = session.EEnum }));
            }


            catch (Exception ex)
            {
                logger.LogDebug("User Post Error: " + ex);
                return(null);
            }
        }
Example #11
0
        public JsonResult Post([FromBody] List <Session> pSessionList, string sessionid)
        {
            ErrorResponse error    = new ErrorResponse();
            var           response = new Dictionary <string, object>();

            try
            {
                logger.LogDebug("Session Post Start");
                if (pSessionList != null && pSessionList.Count > 0 && !string.IsNullOrEmpty(sessionid))
                {
                    Patient lpatient = IPatient.GetPatientBySessionID(sessionid);
                    if (lpatient != null)
                    {
                        foreach (Session pSession in pSessionList)
                        {
                            PatientRx lrx = IPatientRx.getPatientRx(pSession.RxId);
                            if (lrx != null)
                            {
                                Session lSession = lISessionRepository.getSession(pSession.SessionId);
                                if (lSession == null)
                                {
                                    if (pSession.MaxFlexion > lrx.CurrentFlexion && pSession.MaxExtension > lrx.CurrentExtension)
                                    {
                                        int res = INewPatient.ChangeRxCurrent(lrx.RxId, pSession.MaxFlexion, pSession.MaxExtension, "Patient");
                                    }
                                    else if (pSession.MaxFlexion > lrx.CurrentFlexion || pSession.MaxExtension > lrx.CurrentExtension)
                                    {
                                        if (pSession.MaxFlexion > lrx.CurrentFlexion)
                                        {
                                            int res = INewPatient.ChangeRxCurrentFlexion(lrx.RxId, pSession.MaxFlexion, "Patient");
                                        }
                                        if (pSession.MaxExtension > lrx.CurrentExtension)
                                        {
                                            int res = INewPatient.ChangeRxCurrentExtension(lrx.RxId, pSession.MaxExtension, "Patient");
                                        }
                                    }
                                    else
                                    {
                                        RomchangeLog plog = new RomchangeLog();
                                        plog.RxId              = lrx.RxId;
                                        plog.PreviousFlexion   = lrx.CurrentFlexion.HasValue ? Convert.ToInt32(lrx.CurrentFlexion) : 0;
                                        plog.PreviousExtension = lrx.CurrentExtension.HasValue ? Convert.ToInt32(lrx.CurrentExtension) : 0;
                                        plog.CreatedDate       = DateTime.UtcNow;
                                        plog.ChangedBy         = "Patient";
                                        IRomChangeLog.InsertRomChangeLog(plog);
                                    }
                                    pSession.PatientId = lpatient.PatientId;
                                    lISessionRepository.InsertSession(pSession);
                                }
                                else
                                {
                                    lSession.Duration       = pSession.Duration;
                                    lSession.ExtensionReps  = pSession.ExtensionReps;
                                    lSession.FlexionReps    = pSession.FlexionReps;
                                    lSession.MaxPain        = pSession.MaxPain;
                                    lSession.MaxFlexion     = pSession.MaxFlexion;
                                    lSession.MaxExtension   = pSession.MaxExtension;
                                    lSession.PatientId      = lpatient.PatientId;
                                    lSession.RxId           = pSession.RxId;
                                    lSession.ProtocolId     = pSession.ProtocolId;
                                    lSession.Reps           = pSession.Reps;
                                    lSession.SessionDate    = pSession.SessionDate;
                                    lSession.PainCount      = pSession.PainCount;
                                    lSession.TimeZoneOffset = pSession.TimeZoneOffset;
                                    lSession.Boom1Position  = pSession.Boom1Position;
                                    lSession.Boom2Position  = pSession.Boom2Position;
                                    lSession.RangeDuration1 = pSession.RangeDuration1;
                                    lSession.RangeDuration2 = pSession.RangeDuration2;
                                    lSession.GuidedMode     = pSession.GuidedMode;
                                    lISessionRepository.UpdateSession(lSession);

                                    if (pSession.MaxFlexion > lrx.CurrentFlexion && pSession.MaxExtension > lrx.CurrentExtension)
                                    {
                                        int res = INewPatient.ChangeRxCurrent(lrx.RxId, pSession.MaxFlexion, pSession.MaxExtension, "Patient");
                                    }
                                    else if (pSession.MaxFlexion > lrx.CurrentFlexion || pSession.MaxExtension > lrx.CurrentExtension)
                                    {
                                        if (pSession.MaxFlexion > lrx.CurrentFlexion)
                                        {
                                            int res = INewPatient.ChangeRxCurrentFlexion(lrx.RxId, pSession.MaxFlexion, "Patient");
                                        }
                                        if (pSession.MaxExtension > lrx.CurrentExtension)
                                        {
                                            int res = INewPatient.ChangeRxCurrentExtension(lrx.RxId, pSession.MaxExtension, "Patient");
                                        }
                                    }
                                    else
                                    {
                                        RomchangeLog plog = new RomchangeLog();
                                        plog.RxId              = lrx.RxId;
                                        plog.PreviousFlexion   = lrx.CurrentFlexion.HasValue ? Convert.ToInt32(lrx.CurrentFlexion) : 0;
                                        plog.PreviousExtension = lrx.CurrentExtension.HasValue ? Convert.ToInt32(lrx.CurrentExtension) : 0;
                                        plog.CreatedDate       = DateTime.UtcNow;
                                        plog.ChangedBy         = "Patient";
                                        IRomChangeLog.InsertRomChangeLog(plog);
                                    }
                                }
                            }
                        }
                        logger.LogDebug("Session Post End");
                        return(Json(new { Status = (int)HttpStatusCode.OK, result = "Session inserted successfully", TimeZone = DateTime.UtcNow.ToString("s") }));
                    }
                    else
                    {
                        return(Json(new { Status = (int)HttpStatusCode.BadRequest, result = "patient session is not valid", TimeZone = DateTime.UtcNow.ToString("s") }));
                    }
                }
                else
                {
                    logger.LogDebug("Session Post End");
                    return(Json(new { Status = (int)HttpStatusCode.InternalServerError, result = "Session insertion failed", TimeZone = DateTime.UtcNow.ToString("s") }));
                }
            }
            catch (Exception ex)
            {
                logger.LogDebug("Session Post Error: " + ex);

                return(Json(new { Status = (int)HttpStatusCode.InternalServerError, result = "Session insertion failed", TimeZone = DateTime.UtcNow.ToString("s") }));
            }
        }
        public List <PatientRx> UpdatePatientRx(List <NewPatientRx> NewPatientRxs, int PainThreshold = 0, int RateOfChange = 0, string usertype = "")
        {
            try
            {
                List <PatientRx> lrxlist = new List <PatientRx>();
                DateTime?        RXSD    = null;
                DateTime?        RXED    = null;

                NewPatientRx lpatientRx = NewPatientRxs.Where(x => x.RxStartDate != null && x.RxEndDate != null).Count() > 0 ? NewPatientRxs.Where(x => x.RxStartDate != null && x.RxEndDate != null).FirstOrDefault() : null;
                if (lpatientRx != null)
                {
                    RXSD = lpatientRx.RxStartDate;
                    RXED = lpatientRx.RxEndDate;
                }
                else
                {
                    return(null);
                }
                foreach (NewPatientRx NewPatientRx in NewPatientRxs)
                {
                    PatientRx patRx = (from p in context.PatientRx
                                       where p.RxId == NewPatientRx.RxId
                                       select p).FirstOrDefault();
                    if (patRx != null)
                    {
                        //Prabhu - insert RomChangeLog
                        RomchangeLog plog = new RomchangeLog();
                        plog.RxId              = patRx.RxId;
                        plog.PreviousFlexion   = patRx.CurrentFlexion.HasValue ? Convert.ToInt32(patRx.CurrentFlexion) : 0;
                        plog.PreviousExtension = patRx.CurrentExtension.HasValue ? Convert.ToInt32(patRx.CurrentExtension) : 0;
                        plog.CreatedDate       = DateTime.UtcNow;

                        if (usertype == ConstantsVar.Admin.ToString())
                        {
                            plog.ChangedBy = "Admin";
                        }
                        else if (usertype == ConstantsVar.Support.ToString())
                        {
                            plog.ChangedBy = "Support";
                        }
                        else if (usertype == ConstantsVar.Therapist.ToString())
                        {
                            plog.ChangedBy = "Therapist";
                        }
                        else if (usertype == ConstantsVar.PatientAdministrator.ToString())
                        {
                            plog.ChangedBy = "PatientAdministrator";
                        }
                        else if (usertype == ConstantsVar.Provider.ToString())
                        {
                            plog.ChangedBy = "Provider";
                        }

                        context.RomchangeLog.Add(plog);
                        int res = context.SaveChanges();

                        patRx.RxId                 = NewPatientRx.RxId;
                        patRx.EquipmentType        = NewPatientRx.EquipmentType;
                        patRx.DeviceConfiguration  = NewPatientRx.DeviceConfiguration;
                        patRx.RxStartDate          = RXSD;
                        patRx.RxEndDate            = RXED;
                        patRx.ProviderId           = NewPatientRx.ProviderId;
                        patRx.PatientId            = NewPatientRx.PatientId;
                        patRx.CurrentFlexion       = NewPatientRx.CurrentFlexion;
                        patRx.CurrentExtension     = NewPatientRx.CurrentExtension;
                        patRx.GoalFlexion          = NewPatientRx.GoalFlexion;
                        patRx.GoalExtension        = NewPatientRx.GoalExtension;
                        patRx.PainThreshold        = PainThreshold;
                        patRx.RateOfChange         = RateOfChange;
                        patRx.Active               = true;
                        patRx.DateModified         = DateTime.UtcNow;
                        context.Entry(patRx).State = EntityState.Modified;
                        int response = context.SaveChanges();
                        if (response > 0)
                        {
                            lrxlist.Add(patRx);
                        }
                    }
                }
                return(lrxlist);
            }
            catch (Exception ex)
            {
                return(null);
            }
        }
        public List <PatientRx> CreateNewPatientByProvider(NewPatientWithProtocol NewPatient)
        {
            List <PatientRx> lrxList = new List <PatientRx>();
            DateTime?        RXSD    = null;
            DateTime?        RXED    = null;

            try
            {
                Patient patient = new Patient();
                patient.PatientName   = NewPatient.NewPatient.PatientName;
                patient.ProviderId    = NewPatient.ProviderId;
                patient.Dob           = NewPatient.NewPatient.Dob;
                patient.AddressLine   = NewPatient.NewPatient.AddressLine;
                patient.EquipmentType = NewPatient.NewPatient.EquipmentType;
                patient.State         = NewPatient.NewPatient.State;
                patient.City          = NewPatient.NewPatient.City;
                patient.Zip           = NewPatient.NewPatient.Zip;
                patient.PhoneNumber   = NewPatient.NewPatient.PhoneNumber;
                patient.SurgeryDate   = NewPatient.NewPatient.SurgeryDate;
                patient.Ssn           = NewPatient.NewPatient.Ssn;
                patient.Side          = NewPatient.NewPatient.Side;
                patient.Therapistid   = NewPatient.NewPatient.TherapistId;
                patient.Paid          = NewPatient.NewPatient.PatientAdminId;
                patient.DateCreated   = DateTime.UtcNow;


                string patName = NewPatient.NewPatient.Ssn + NewPatient.NewPatient.PhoneNumber.Substring(NewPatient.NewPatient.PhoneNumber.Length - 4);
                patient.PatientLoginId = patName;

                context.Patient.Add(patient);
                context.SaveChanges();
                int count = 0;
                foreach (NewPatientRx _PatientRx in NewPatient.NewPatientRXList)
                {
                    if (count == 0)
                    {
                        RXSD = _PatientRx.RxStartDate;
                        RXED = _PatientRx.RxEndDate;
                        count++;
                    }
                    PatientRx patRx = new PatientRx();
                    patRx.RxId                = Guid.NewGuid().ToString();
                    patRx.EquipmentType       = NewPatient.NewPatient.EquipmentType;
                    patRx.DeviceConfiguration = _PatientRx.DeviceConfiguration;
                    patRx.RxStartDate         = RXSD;
                    patRx.RxEndDate           = RXED;
                    patRx.ProviderId          = NewPatient.ProviderId;
                    patRx.PatientId           = patient.PatientId;
                    patRx.CurrentFlexion      = _PatientRx.CurrentFlexion;
                    patRx.CurrentExtension    = _PatientRx.CurrentExtension;
                    patRx.GoalFlexion         = _PatientRx.GoalFlexion;
                    patRx.GoalExtension       = _PatientRx.GoalExtension;
                    patRx.RxDaysPerweek       = 2;
                    patRx.RxSessionsPerWeek   = 3;
                    patRx.Active              = true;
                    patRx.DateCreated         = DateTime.UtcNow;
                    patRx.PatientSide         = patient.Side;
                    patRx.PainThreshold       = NewPatient.PainThreshold;
                    patRx.RateOfChange        = NewPatient.RateOfChange;
                    context.PatientRx.Add(patRx);
                    int response = context.SaveChanges();
                    if (response > 0)
                    {
                        patRx.Session = null;

                        lrxList.Add(patRx);
                    }
                }
                if (patient.PatientId > 0)
                {
                    return(lrxList);
                }
                else
                {
                    return(lrxList);
                }
            }
            catch (Exception ex)
            {
                return(lrxList);
            }
        }
        public IActionResult AddEdit(SessionView session)
        {
            try
            {
                NewProtocol ptoList = INewPatient.GetProtocolByproId(session.ProtocolId);
                if (ptoList != null)
                {
                    PatientRx lrx = IPatientRx.getPatientRx(ptoList.RxId);
                    if (lrx != null)
                    {
                        Session _session = new Session();


                        _session.PatientId      = ptoList.PatientId;
                        _session.RxId           = ptoList.RxId;
                        _session.ProtocolId     = ptoList.ProtocolId;
                        _session.SessionDate    = session.SessionDate;
                        _session.Duration       = session.Duration;
                        _session.Reps           = session.Reps;
                        _session.MaxExtension   = session.MaxExtension;
                        _session.ExtensionReps  = session.ExtensionReps;
                        _session.MaxFlexion     = session.MaxFlexion;
                        _session.FlexionReps    = session.FlexionReps;
                        _session.MaxPain        = session.MaxPain;
                        _session.PainCount      = session.PainCount;
                        _session.Boom1Position  = session.Boom1Position;
                        _session.Boom2Position  = session.Boom2Position;
                        _session.RangeDuration1 = session.RangeDuration1;
                        _session.RangeDuration2 = session.RangeDuration2;
                        _session.GuidedMode     = _session.GuidedMode;
                        _session.TimeZoneOffset = "";

                        if (session.MaxFlexion > lrx.CurrentFlexion && session.MaxExtension > lrx.CurrentExtension)
                        {
                            int res = INewPatient.ChangeRxCurrent(lrx.RxId, session.MaxFlexion, session.MaxExtension, "Patient");
                        }
                        else if (session.MaxFlexion > lrx.CurrentFlexion)
                        {
                            int res = INewPatient.ChangeRxCurrentFlexion(lrx.RxId, session.MaxFlexion, "Patient");
                        }
                        else if (session.MaxExtension > lrx.CurrentExtension)
                        {
                            int res = INewPatient.ChangeRxCurrentExtension(lrx.RxId, session.MaxExtension, "Patient");
                        }
                        else
                        {
                            RomchangeLog plog = new RomchangeLog();
                            plog.RxId              = lrx.RxId;
                            plog.PreviousFlexion   = lrx.CurrentFlexion.HasValue ? Convert.ToInt32(lrx.CurrentFlexion) : 0;
                            plog.PreviousExtension = lrx.CurrentExtension.HasValue ? Convert.ToInt32(lrx.CurrentExtension) : 0;
                            plog.CreatedDate       = DateTime.UtcNow;
                            plog.ChangedBy         = "Patient";
                            IRomChangeLog.InsertRomChangeLog(plog);
                        }
                        if (!string.IsNullOrEmpty(session.SessionId))
                        {
                            _session.SessionId = session.SessionId;

                            //Session editSession = lISessionInterface.getSession(session.SessionId);
                            //if (editSession != null)
                            //{
                            lISessionInterface.UpdateSession(_session);
                            //}
                        }
                        else
                        {
                            _session.SessionId = Guid.NewGuid().ToString();
                            lISessionInterface.InsertSession(_session);
                        }
                    }
                }
                if (!string.IsNullOrEmpty(session.returnView))
                {
                    return(RedirectToAction("Index", "Review", new { id = session.PatientId, Username = session.Patname, EquipmentType = session.EType, actuator = session.EEnum, tab = "Sessions" }));
                }
                else
                {
                    return(RedirectToAction("Index", "SessionView", new { id = session.PatientId, Username = session.Patname, Etype = session.EType, actuator = session.EEnum }));
                }
            }


            catch (Exception ex)
            {
                logger.LogDebug("User Post Error: " + ex);
                return(null);
            }
        }