public static void ProcessAnswerRiskAndVigilance(ref LABAnswer answer, LABAnswer firstQuestionAnswer)
        {
            var assessmentList = QuestionAssessmentBL.GetQuestionAssessmentForAnswer(answer);
            QuestionAssessment assessmentToApply = null;

            if (assessmentList.Count > 1)
                assessmentToApply = QuestionAssessmentBL.ValidateSpecialCondition(assessmentList);
            else 
                assessmentToApply = assessmentList.First();

            //particular case for Question 7 (IdLabQuestion = 8) response yes
            if (firstQuestionAnswer != null && answer.idLABQuestion == 8 && answer.idResponse == 1)
            {
                if (firstQuestionAnswer.idResponse == 1) //yes
                {
                    answer.idRisk = 2;
                    answer.idVigilance = 3;
                }
                else if (firstQuestionAnswer.idResponse == 2) //no
                {
                    answer.idRisk = 3;
                    answer.idVigilance = 5;
                }
            }
            else
            {
                answer.idRisk = assessmentToApply.idRisk;
                answer.idVigilance = assessmentToApply.idVigilance;
            }
        }
 public static List<QuestionAssessment> GetQuestionAssessmentForAnswer(LABAnswer answer)
 {
     using (UpsilabEntities context = new UpsilabEntities())
     {
         return context.QuestionAssessment.Where(assessment => assessment.idLABQuestion == answer.idLABQuestion)
                                          .Where(assessment => assessment.idResponse == answer.idResponse).ToList();
     }
 }
예제 #3
0
        /// <summary>
        /// Returns measure for respective lab answer
        /// </summary>
        /// <param name="labAnswer"></param>
        /// <returns>The corresponding measure for the LAB answer, or null.</returns>
        public static Data.Model.Measure GetMeasureByLABAnswer(LABAnswer labAnswer)
        {
            if (!labAnswer.idRisk.HasValue)
                return null;

            if (!labAnswer.idVigilance.HasValue)
                return null;

            return MeasureBL.GetMeasureByIdLABQuestionAndIdRiskAndIdVigilance(labAnswer.idLABQuestion, labAnswer.idRisk.Value, labAnswer.idVigilance.Value);
        }
        public LABAnswer GetAnswerByIdQuestion(int idQuestion)
        {
            LABAnswer answer = this.LABAnswers.Where(a => a.idLABQuestion.Equals(idQuestion)).FirstOrDefault();
            
            if (answer == null)
            {
                answer = new LABAnswer();                
            }

            return answer;
        }
        public static LABAnswerMeasure CreateLABAnswerMeasureByIdLABMeasureAndLABAnswer(Guid idLABMeasure, LABAnswer labAnswer)
        {
            if (labAnswer == null)
                return null;

            LABAnswerMeasure returnValue = new LABAnswerMeasure();
            returnValue.idLABMeasure = idLABMeasure;
            returnValue.idLABAnswer = labAnswer.idLABAnswer;

            //TODO: Not sure.
            var measure = MeasureBL.GetMeasureByLABAnswer(labAnswer);
            returnValue.idMeasure = measure == null ? measure.idMeasure : Guid.Empty;

            using (UpsilabEntities context = new UpsilabEntities())
            {
                context.LABAnswerMeasure.Attach(returnValue);
                context.ObjectStateManager.ChangeObjectState(returnValue, System.Data.EntityState.Added);
                context.SaveChanges();
            }

            return returnValue;
        }
예제 #6
0
        public static void SaveAnswer(LABAnswer pLABAnswer)
        {
            bool hasSentToCoffreLAB = false;
            string sentToCoffreStatus = LABStudy.StatusEnum.SentToCoffreFort.ToString();

            using (UpsilabEntities db = new UpsilabEntities())
            {
                var existingAnswer = db.LABAnswer.Where(la => la.idLABStudy == pLABAnswer.idLABStudy
                                                            && la.idLABQuestion == pLABAnswer.idLABQuestion).FirstOrDefault();

                //Check if customer has "SentToCoffreFort" LAB
                var labStudy = (from lab in db.LABStudy.Include("CustomerProspect")
                                where lab.idLABStudy == pLABAnswer.idLABStudy
                                select lab).FirstOrDefault();

                var checkSentToCoffreLAB = (from lab in db.LABStudy
                                            where lab.CustomerProspect.idCustomer == labStudy.CustomerProspect.idCustomer
                                                  && lab.Status == sentToCoffreStatus
                                            select lab).FirstOrDefault();

                if (checkSentToCoffreLAB != null)
                {
                    hasSentToCoffreLAB = true;
                }

                //Insert / update
                if (existingAnswer == null) //Insert
                {
                    db.LABAnswer.AddObject(pLABAnswer);
                }
                else //update
                {
                    existingAnswer.idResponse = pLABAnswer.idResponse;
                    existingAnswer.idRisk = pLABAnswer.idRisk;
                    existingAnswer.idVigilance = pLABAnswer.idVigilance;
                    existingAnswer.ExtensionAnswer = pLABAnswer.ExtensionAnswer;
                    existingAnswer.DateUpdated = (hasSentToCoffreLAB) ? DateTime.Now : (DateTime?)null;
                }
                
                //Commit
                db.SaveChanges();
            }
        }
예제 #7
0
        public static Boolean InsertAnswers(LABStudy labStudy, List<LABAnswer> answers)
        {
            try
            {
                using (UpsilabEntities context = new UpsilabEntities())
                {
                    answers.ForEach(answer =>
                    {
                        LABAnswer newLabAnswer = new LABAnswer()
                        {
                            idLABAnswer = GuidHelper.GenerateGuid(),
                            idLABStudy = labStudy.idLABStudy,
                            idLABQuestion = answer.idLABQuestion,
                            idResponse = answer.idResponse,
                            idVigilance = answer.idVigilance,
                            idRisk = answer.idRisk,
                            ExtensionAnswer = answer.ExtensionAnswer,
                            DateCreated = DateTime.Now
                        };

                        context.LABAnswer.AddObject(newLabAnswer);
                    });

                    context.SaveChanges();
                }

                return true;
            }
            catch
            {
                return false;
            }
        }
예제 #8
0
        private static void ProcessUser(User user)
        {


            try
            {

                string statusInProgress = LABStudy.StatusEnum.InProgress.ToString();
                string statusCompleted = LABStudy.StatusEnum.Completed.ToString();
                string statusSentToCoffreFort = LABStudy.StatusEnum.SentToCoffreFort.ToString();
                bool isSendTocoffreOk = false;




                ////////            


                {

                    //     System.Console.WriteLine("\nTraitement de l'utilisateur : {0} {1}", user.UserName, user.UserFirstName);

                    //     int randomNumber = Rand();
                    _Log.Trace("Starting thread  for {0} {1} from  iteration {2} Thread count : {3} ", user.UserName, user.UserFirstName, _IterationId, _countThread);

                    //     Thread.Sleep(randomNumber);

                    //     _LstOfCommand.Enqueue(new GuidAction() { guid = user.idUser, action = "remove" });
                    //   autoEvent.Set();
                    // _Log.Trace("Ending thread  for {0} {1} from  iteration {2}", user.UserName, user.UserFirstName, _IterationId);

                }
                //  return;

                //////

                //liste des CustomerProspectLABModel par utilisateur
                List<CustomerProspectLABModel> lstCustomerLABModels = new List<CustomerProspectLABModel>();
                lstCustomerLABModels = LABStudyBL.GetCustomerLABModelInProgress(user.idUser);

                //boucle sur liste customer
                LABModel labModelNow = null;
                LABStudy labStudyNow = null;

                List<Guid> lstFailingGuid = new List<Guid>();


                foreach (CustomerProspectLABModel customerLabModel in lstCustomerLABModels)
                {
                    try
                    {
                        using (UpsilabEntities db = new UpsilabEntities())
                        {
                            //LABModel d'un utilisateur en cour  
                            labModelNow = new LABModel();
                            labModelNow = db.LABModel.Where(l => l.idUser == user.idUser && l.idLABModel == customerLabModel.idLABModel).FirstOrDefault();

                            //copy LABModel vers LABStudy
                            labStudyNow = new LABStudy()
                            {
                                idLABStudy = GuidHelper.GenerateGuid(),
                                idCustomer = customerLabModel.idCustomerProspect,
                                DateCreated = DateTime.Now,
                                DateUpdated = DateTime.Now,
                                Status = statusInProgress,
                                idRisk = labModelNow.idRisk,
                                idVigilance = labModelNow.idVigilance
                            };

                            db.LABStudy.AddObject(labStudyNow);
                            _Log.Trace("\nApplication du modele LAB : {0} au client : {1} {2}", labModelNow.Name, customerLabModel.CustomerProspect.Name, customerLabModel.CustomerProspect.User.UserFirstName);

                            //liste des question/reponse (LABAnswerModel)
                            List<LABAnswerModel> lstanswermodel = new List<LABAnswerModel>();
                            lstanswermodel = db.LABAnswerModel.Where(lam => lam.idLABModel == labModelNow.idLABModel).ToList();
                            //copy LABAnswerModel vers LABAnswer
                            foreach (LABAnswerModel lam in lstanswermodel)
                            {
                                LABAnswer LABAnswerNow = new LABAnswer()
                                {
                                    idLABAnswer = GuidHelper.GenerateGuid(),
                                    idLABStudy = labStudyNow.idLABStudy,
                                    idLABQuestion = lam.idLABQuestion,
                                    idResponse = lam.idResponse,
                                    idRisk = lam.idRisk,
                                    idVigilance = lam.idVigilance,
                                    DateCreated = DateTime.Now,
                                    DateUpdated = DateTime.Now
                                };

                                db.LABAnswer.AddObject(LABAnswerNow);
                            }

                            labStudyNow.idElectronicSafeDocument = null;
                            labStudyNow.Status = statusCompleted;

                            //envoie la transaction
                            db.SaveChanges();
                        }

                        if (labStudyNow != null)
                        {
                            _Log.Trace("Début envoi de la LAB au coffre-fort");
                            //ElectronicSafeDocument
                            Guid idElectronicSafeDocument = Guid.Empty;
                            idElectronicSafeDocument = LABStudyBL.SendToCoffreFort(labStudyNow.idCustomer, labStudyNow.idLABStudy);

                            if (idElectronicSafeDocument != Guid.Empty)
                            {
                                isSendTocoffreOk = true;
                                using (UpsilabEntities db = new UpsilabEntities())
                                {
                                    //update 
                                    CustomerProspectLABModel customerLAbModeltoupdate = db.CustomerProspectLABModel.Where(c => c.idCustomerProspectLABModel == customerLabModel.idCustomerProspectLABModel).FirstOrDefault();
                                    customerLAbModeltoupdate.Status = statusCompleted;
                                    customerLAbModeltoupdate.DateUpdated = DateTime.Now;

                                    //update customerprospect
                                    CustomerProspect customerToUpdate = db.CustomerProspect.Where(c => c.idCustomer == customerLabModel.idCustomerProspect).FirstOrDefault();
                                    customerToUpdate.CurrentLabStatus = statusSentToCoffreFort;
                                    //envoie la transaction
                                    db.SaveChanges();
                                }
                                _Log.Trace("Envoi au coffre-fort OK");
                            }
                            else
                            {
                                lstFailingGuid.Add(customerLabModel.CustomerProspect.IdUser);
                                _Log.Trace("Erreur envoi au coffre-fort");
                            }

                        }
                    }
                    catch (Exception exc)
                    {

                        lstFailingGuid.Add(customerLabModel.CustomerProspect.IdUser);
                        _Log.Trace("Erreur pour le customer : {0}", customerLabModel.CustomerProspect.IdUser.ToString());

                    }
                    if (_CancelToken.IsCancellationRequested)
                        break;

                }

                //ajout nouveau message pour un utilisateur quand l'affectation LAB est fini  
                if (lstFailingGuid.Count == 0)
                {
                    using (UpsilabEntities db = new UpsilabEntities())
                    {
                        Message msg = new Message()
                        {
                            idUser = user.idUser,
                            NameKey = LABStudyBL.MessageNamekey,
                            Read = false,
                            DateCreated = DateTime.Now,
                            DateUpdated = DateTime.Now,
                            idLABModel = labModelNow.idLABModel,
                            From = LABStudyBL.FromLABModel
                        };

                        db.Message.AddObject(msg);
                        //envoie la transaction
                        db.SaveChanges();
                    }


                    _Log.Trace("\n Aucun incident pour l'utilisateur");
                }
                else
                {
                    using (UpsilabEntities db = new UpsilabEntities())
                    {
                        Message msg = new Message()
                        {
                            idUser = user.idUser,
                            NameKey = LABStudyBL.MessageNamekeyKO,
                            Read = false,
                            DateCreated = DateTime.Now,
                            DateUpdated = DateTime.Now,
                            idLABModel = labModelNow.idLABModel,
                            From = LABStudyBL.FromLABModel,
                            AdditionnalContent = String.Join(";", lstFailingGuid.ToArray())
                        };

                        db.Message.AddObject(msg);
                        //envoie la transaction
                        db.SaveChanges();
                    }
                    _Log.Trace("\n Erreur survenue pour l'utilisateur");
                }



            }
            catch (Exception ex)
            {
                _Log.Trace("Exception : {0}", ex.Message);
                Log.AppendException(ex);
            }

            finally
            {
                _LstOfCommand.Enqueue(new GuidAction() { guid = user.idUser, action = "remove" });
                autoEvent.Set();
                _Log.Trace("Ending thread  for {0} {1} from  iteration {2}", user.UserName, user.UserFirstName, _IterationId);
            }
            //  RemoveItemToLstOfProcessingUser(user);

        }
        public JsonResult SaveStudyData()
        {
            object returnValue = new { status = "None" };
            Guid idLabStudy;

            string prefixName = string.Empty;
            int questionId = 0;
            int responseId = 0;
            int riskId = 0;
            int vigilanceId = 0;

            try
            {
                if (Request.Form["name"] != null)
                {
                    //IdLabStudy
                    SessionManager.Get<Guid>(LABStudyBL.IdLABStudySessionKey, out idLabStudy);
                    if (idLabStudy == null)
                    {
                        returnValue = new { status = "ExpiredSession" };
                        return Json(returnValue, JsonRequestBehavior.AllowGet); //TODO => expired session
                    }

                    LABStudy labStudy = LABStudyBL.GetLABStudyByIdLABStudy(idLabStudy);

                    //Question, answer, risk, vigilance ID ?
                    string[] arrName = Request.Form["name"].Split(new char[] { '_' });
                    prefixName = arrName[0];
                    questionId = Convert.ToInt32(arrName[1]);
                    responseId = Convert.ToInt32(arrName[2]);
                    riskId = Convert.ToInt32(arrName[3]);
                    vigilanceId = Convert.ToInt32(arrName[4]);

                    //Insert / update Answer
                    LABAnswer labAnswer = new LABAnswer()
                    {
                        idLABAnswer = GuidHelper.GenerateGuid(),
                        idLABStudy = idLabStudy,
                        idLABQuestion = questionId,
                        idResponse = responseId,
                        idRisk = riskId,
                        idVigilance = vigilanceId,
                        ExtensionAnswer = string.Empty, //??
                        DateCreated = DateTime.Now
                    };

                    //particular case for Question 7 (IdLabQuestion = 8) response yes
                    if (questionId == 8 && responseId == 1)
                    {
                        var firstQuestionAnswer = LABAnswerBL.GetLABAnswerByIdLABQuestion(idLabStudy, 2); //idQuestion = 2 => first question
                        if (firstQuestionAnswer != null)
                        {
                            if (firstQuestionAnswer.idResponse == 1) //yes
                            {
                                labAnswer.idRisk = 2;
                                labAnswer.idVigilance = 3;
                            }
                            else if (firstQuestionAnswer.idResponse == 2) //no
                            {
                                labAnswer.idRisk = 3;
                                labAnswer.idVigilance = 5;
                            }
                        }
                    }

                    LABAnswerBL.SaveAnswer(labAnswer);
                    /////////////////////////////////////////////////////////////////////

                    Report _report = ReportBL.GetLatestReportByIdCustomerProspect(labStudy.idCustomer);

                    if (_report == null)
                    {
                        //wondering what to do ????
                    }

                    if (_report != null)
                    {
                        int optionID = 0;
                        if (questionId == 11)
                        {
                            if (responseId == 1)
                                optionID = 214;
                            else
                                if (responseId == 2)
                                    optionID = 215;
                        }
                        //else
                        //    if (questionId == 9)
                        //    {
                        //        if (responseId == 1)
                        //            optionID = 502;
                        //        else
                        //            if (responseId == 2)
                        //                optionID = 503;
                        //    }

                        if (optionID != 0)
                        {
                            try
                            {
                                Option objOption = OptionBL.GetOptionById(optionID);
                                ReportOptionBL.SaveReportOptionValue(_report.idReport, objOption, 0, "true", "rb", "", null);
                            }
                            catch { }
                        }
                    }

                    //////////////////////////////////////////////////////////////////////////////////
                    //Evaluate LABStudy
                    LABStudyBL.EvaluateLABStudy(labStudy); //Return "InProgress" or "Completed"

                    var returnObj = new { idRisk = labStudy.idRisk, idVigilance = labStudy.idVigilance, status = labStudy.Status };
                    return Json(returnObj, JsonRequestBehavior.AllowGet);
                }

            }
            catch (Exception ex)
            {
                returnValue = new { status = "Exception" };
                Upsilab.Business.Log.Log.AppendException(ex);
            }

            return Json(returnValue, JsonRequestBehavior.AllowGet); ;
        }
        public void SaveLABStudy(LABStudyModel _dbData)
        {
            //Save LAB Study to Database
            LABStudyBL.SaveLABStudy(_dbData.LABStudy);
            _dbData.LABStudy = LABStudyBL.GetLatestLABStudyByIdCustomerProspect(_dbData.idCustomer);

            //Retrieve Responses from Post Data
            foreach (LABQuestion _question in _dbData.LABQuestions)
            {
                string rbIdentifier = string.Format("rb_{0}_", _question.idLABQuestion);
                var rbKeys = Request.Params.AllKeys.Where(k => k.StartsWith(rbIdentifier)).ToList();
                int? _responseID = null;
                foreach (string rbKey in rbKeys)
                {
                    if (Request.Params[rbKey].ToLower().Equals("c"))
                    {
                        //_responseID = int.Parse(rbKey.Replace(rbIdentifier, ""));
                        string[] arrKeys = rbKey.Split('_');
                        //[0] => rb
                        //[1] => questionId
                        //[2] => responseId
                        //[3] => riskId
                        //[4] => vigilanceId
                        _responseID = int.Parse(arrKeys[2]);
                    }
                }
                if (_responseID.HasValue)
                {
                    var _answer = _dbData.LABAnswers.Where(a => a.idLABQuestion.Equals(_question.idLABQuestion)).FirstOrDefault();
                    if (_answer != null)
                    {
                        _answer.idResponse = _responseID.Value;
                    }
                    else
                    {
                        LABAnswer newAnswer = new LABAnswer()
                        {
                            idLABAnswer = GuidHelper.GenerateGuid(),
                            idLABStudy = _dbData.idLABStudy,
                            idLABQuestion = _question.idLABQuestion,
                            idResponse = _responseID.Value,
                            DateCreated = DateTime.Now
                        };
                        _dbData.LABAnswers.Add(newAnswer);
                    }
                }
            }

            LABAnswerBL.SaveAndProcessAnswers(_dbData.LABStudy, _dbData.LABAnswers);
        }