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);
        }
Example #2
0
 public void InsertRomChangeLog(RomchangeLog plog)
 {
     context.RomchangeLog.Add(plog);
     context.SaveChanges();
 }
        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 #4
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 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);
            }
        }