public bool SaveCheckList(MedicareStandingOrderViewModel standingOrder)
        {
            _logger.Info("Saving CheckList from HRA for Visit : " + standingOrder.PatientVisitId + ", version :" + standingOrder.Version + "-> Started");
            var evtCust = _eventCustomerRepository.GetByMedicareVisitId(standingOrder.PatientVisitId);

            if (evtCust != null)
            {
                var model = new CheckListAnswerEditModel();
                model.EventCustomerId = evtCust.Id;
                model.Answers         = standingOrder.Questions.Select(ques => new CheckListQuestionAnswerEditModel {
                    QuestionId = ques.QuestionId, Answer = ques.Answer
                }).ToList();
                _customerCheckListService.SaveCheckListAnswer(model, _sessionContext.UserSession.CurrentOrganizationRole.OrganizationRoleUserId, _sessionContext.UserSession.UserLoginLogId, "");
            }
            _logger.Info("Saving CheckList from HRA for Visit : " + standingOrder.PatientVisitId + ", version :" + standingOrder.Version + "-> Completed");
            return(true);
        }
        public void SaveCheckListAnswer(CheckListAnswerEditModel model, long orgUserId, long userLoginLogId, string token)
        {
            if (model.Answers.IsNullOrEmpty())
            {
                return;
            }

            var eventCustomer = ((IUniqueItemRepository <EventCustomer>)_eventCustomerRepository).GetById(model.EventCustomerId);

            var lastestVersion = model.Version;

            if (model.Version == 0)
            {
                lastestVersion = _checkListAnswerRepository.GetLatestVersion(model.EventCustomerId);
            }
            if (model.Answers.IsNullOrEmpty())
            {
                return;
            }
            var checklistAnswer = new List <CheckListAnswer>();

            foreach (var answer in model.Answers)
            {
                checklistAnswer.Add(new CheckListAnswer
                {
                    Answer               = answer.Answer,
                    QuestionId           = answer.QuestionId,
                    Version              = lastestVersion + 1,
                    Id                   = model.EventCustomerId,
                    IsActive             = true,
                    DataRecorderMetaData = new DataRecorderMetaData(orgUserId, DateTime.Now, null),
                    Type                 = (long)CheckListType.CheckList
                });
            }

            _checkListAnswerRepository.SaveAnswer(checklistAnswer);

            try
            {
                var result = _eventCustomerResultRepository.GetById(model.EventCustomerId);

                if (token != "" && (result == null || result.ResultState < (long)TestResultStateNumber.PreAudit))
                {
                    var questionIds = model.Answers.Where(x => TestQuestionList.Contains(x.QuestionId)).Select(x => x.QuestionId);

                    if (!questionIds.IsNullOrEmpty())
                    {
                        var testIdsToBeUpdated = GetStandingOrderTest(questionIds);
                        if (!testIdsToBeUpdated.IsNullOrEmpty())
                        {
                            UpdateCustomerOrder(eventCustomer.EventId, eventCustomer.CustomerId, testIdsToBeUpdated, orgUserId);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                _logger.Error(string.Format("Some Error Occurred While Customer Updating Order. Exception Message {0} \t\n Stack Trace: {1}", ex.Message, ex.StackTrace));
            }

            if (_settings.SyncWithHra)
            {
                if (token != "")
                {
                    try
                    {
                        var visitId = _eventCustomerRepository.GetById(model.EventCustomerId).AwvVisitId;
                        if (visitId.HasValue)
                        {
                            var answers = new MedicareStandingOrderViewModel
                            {
                                PatientVisitId = visitId.Value,
                                Version        = lastestVersion + 1,
                                IsSync         = true,
                                Questions      = model.Answers.Select(answer => new MedicareCheckListQuestionViewModel
                                {
                                    Answer     = answer.Answer,
                                    QuestionId = answer.QuestionId
                                }).ToList()
                            };
                            try
                            {
                                _medicareApiService.Connect(userLoginLogId);
                            }
                            catch (Exception)
                            {
                                var auth = new MedicareAuthenticationModel {
                                    UserToken = token, CustomerId = 0, OrgName = _settings.OrganizationNameForHraQuestioner, Tag = _settings.OrganizationNameForHraQuestioner, IsForAdmin = false, RoleAlias = "CallCenterRep"
                                };
                                _medicareApiService.PostAnonymous <string>(_settings.MedicareApiUrl + MedicareApiUrl.AuthenticateUser, auth);

                                _medicareApiService.Connect(userLoginLogId);
                            }

                            _medicareApiService.Post <bool>(MedicareApiUrl.SaveCheckList, answers);
                        }
                    }
                    catch (Exception ex)
                    {
                        _logger.Error(string.Format("Some Error Occured Whicle Saving Checklist Answer To MEDICARE\n Exception Message {0} \t\n Stack Trace: {1}", ex.Message, ex.StackTrace));
                    }
                }
            }
            else
            {
                _logger.Info("Syncing with HRA is off ");
            }
        }