Пример #1
0
        public void Save(CustomerTrale domainObject)
        {
            var entity = Mapper.Map <CustomerTrale, CustomerTraleEntity>(domainObject);

            if (domainObject == null)
            {
                return;
            }
            using (var adapter = PersistenceLayer.GetDataAccessAdapter())
            {
                if (!adapter.SaveEntity(entity))
                {
                    throw new PersistenceFailureException();
                }
            }
        }
Пример #2
0
        private BioCheckJsonViewModel GenerateBioCheckResponseModel(EventCustomer eventCustomer, Customer customer,
                                                                    IEnumerable <HealthAssessmentAnswer> customerHealth, Event eventData, ILogger logger,
                                                                    IEnumerable <EventCustomerResultTrale> eventCustomerResultTrales, IEnumerable <CustomerTrale> customerTrales, CorporateAccount account)
        {
            var isNewResultFlow = eventData.EventDate >= _settings.ResultFlowChangeDate;

            var testResult    = _bioCheckAssessmentTestResultRepository.GetTestResults(customer.CustomerId, eventCustomer.EventId, isNewResultFlow);
            var kynLabValues  = _kynLabValuesRepository.Get(eventCustomer.Id, (long)TestType.MyBioCheckAssessment);
            var basicBioMeric = _basicBiometricRepository.Get(eventCustomer.EventId, eventCustomer.CustomerId);

            var traleResponse = eventCustomerResultTrales.FirstOrDefault(x => x.EventCustomerResultId == eventCustomer.Id);
            var traleUser     = customerTrales.FirstOrDefault(x => x.CustomerId == eventCustomer.CustomerId);

            var myBioCheck = testResult as MyBioAssessmentTestResult;

            if (myBioCheck != null && (myBioCheck.TestNotPerformed == null || myBioCheck.TestNotPerformed.TestNotPerformedReasonId <= 0) && (testResult.UnableScreenReason == null || testResult.UnableScreenReason.Count <= 0))
            {
                if (traleResponse == null)
                {
                    traleResponse = new EventCustomerResultTrale
                    {
                        EventCustomerResultId = eventCustomer.Id,
                        DateCreated           = DateTime.Now,
                        ResponseId            = Guid.NewGuid().ToString()
                    };

                    _eventCustomerResultTraleRepository.Save(traleResponse);
                }

                if (traleUser == null)
                {
                    traleUser = new CustomerTrale
                    {
                        CustomerId  = customer.CustomerId,
                        DateCreated = DateTime.Now,
                        UserId      = Guid.NewGuid().ToString()
                    };
                    _customerTraleRepository.Save(traleUser);
                }

                var biocheckResponse = new List <BioCheckResponseModel>();
                SetCustomerHafResponse(customerHealth, biocheckResponse);                         //Q1_1 to Q8_4
                SetCustomerBioMetricResponse(customer, biocheckResponse);                         //Q9 to Q10
                SetLabValus(biocheckResponse, myBioCheck, kynLabValues, basicBioMeric, customer); //Q11 to Q21
                SetA1CTestData(biocheckResponse, eventCustomer, isNewResultFlow);                 //Q22
                SetAwvBoneMassTestData(biocheckResponse, eventCustomer, isNewResultFlow);         // Q23
                SetPsaTestData(biocheckResponse, eventCustomer, isNewResultFlow);                 // Q24
                SetNicotineTestData(biocheckResponse);                                            // Q25-27
                SetBmiData(biocheckResponse, customer);                                           // Q28
                SetSmokerData(biocheckResponse, kynLabValues);                                    //Q60

                var bioCheckJsonViewModel = new BioCheckJsonViewModel
                {
                    ResponseId  = traleResponse.ResponseId,
                    UserId      = traleUser.UserId,
                    FirstName   = customer.Name.FirstName,
                    LastName    = customer.Name.LastName,
                    DoB         = customer.DateOfBirth,
                    CreatedAt   = DateTime.Now,
                    CompletedAt = eventData.EventDate,
                    Email       = (customer.Email == null || string.IsNullOrEmpty(customer.Email.ToString()))
                            ? string.Empty
                            : customer.Email.ToString(),

                    Gender = customer.Gender == Gender.Female
                            ? FemaleGender
                            : customer.Gender == Gender.Male ? MaleGender : string.Empty,
                    GroupId   = account != null ? account.Id : eventData.Id,
                    GroupName = account != null ? account.Name : eventData.Name,
                    Responses = biocheckResponse.ToArray(),
                    UniqueId  = customer.CustomerId.ToString(),
                    Exfld03   = "Kaiser"
                };

                return(bioCheckJsonViewModel);
            }
            //Todo: create XML for Customers JSON Not Created;
            logger.Info("Customer's My bio-check Result not Found");

            return(null);
        }