private void ParseRapsUploaded(IEnumerable <DataRow> rows, List <RapsUploadLog> failedRapsList, long rapsUploadId, out long successCount)
        {
            var rapsUploadLogs = rows.Select(row => _rapsUploadHelper.GetUploadLog(row, rapsUploadId));

            successCount = 0;
            if (rapsUploadLogs.IsNullOrEmpty())
            {
                _logger.Info("No Record Found For Parsing in file");
                return;
            }

            foreach (var rapsUploadLog in rapsUploadLogs)
            {
                try
                {
                    if (!rapsUploadLog.IsSuccessFull)
                    {
                        _rapsUploadLogRepository.SaveRapsUploadLog(rapsUploadLog);
                        failedRapsList.Add(rapsUploadLog);
                        continue;
                    }
                    var customerIds = new List <long>();
                    if (!string.IsNullOrEmpty(rapsUploadLog.CmsHicn))
                    {
                        customerIds =
                            _customerRepository.GetCustomerIdForRaps(rapsUploadLog.CmsHicn, rapsUploadLog.FirstName,
                                                                     rapsUploadLog.SecondName, rapsUploadLog.MemberDob).ToList();
                    }
                    if (!customerIds.Any())
                    {
                        rapsUploadLog.IsSuccessFull = false;
                        rapsUploadLog.ErrorMessage  = "Customer Not found for this HICN,First Name,Last Name and Date combination";
                        _rapsUploadLogRepository.SaveRapsUploadLog(rapsUploadLog);
                        failedRapsList.Add(rapsUploadLog);
                        continue;
                        //if (!string.IsNullOrEmpty(rapsUploadLog.MemberId))
                        //{
                        //    customerIds = _customerRepository.GetCustomerIdByInsuranceId(rapsUploadLog.MemberId).ToList();

                        //    if (!customerIds.Any())
                        //    {
                        //        rapsUploadLog.IsSuccessFull = false;
                        //        rapsUploadLog.ErrorMessage = "Customer Not found for this CMSHICN Or MemberId";
                        //        _rapsUploadLogRepository.SaveRapsUploadLog(rapsUploadLog);
                        //        failedRapsList.Add(rapsUploadLog);
                        //        continue;
                        //    }
                        //}
                    }
                    foreach (var customerId in customerIds)
                    {
                        var savedRaps  = _rapsRepository.GetByCustomerId(customerId).ToArray();
                        var isExisting = savedRaps.FirstOrDefault(x => x.IcdCode == rapsUploadLog.IcdCode &&
                                                                  x.ServiceDate == rapsUploadLog.ServiceDate
                                                                  ) != null;
                        if (!isExisting)
                        {
                            var rapDomain = new Raps
                            {
                                CmsHicn      = rapsUploadLog.CmsHicn,
                                CustomerId   = customerId,
                                ServiceDate  = rapsUploadLog.ServiceDate,
                                IcdCode      = rapsUploadLog.IcdCode,
                                MemberDob    = rapsUploadLog.MemberDob,
                                RapsUploadId = rapsUploadId,
                                MemberId     = rapsUploadLog.MemberId,
                                IcdVersion   = rapsUploadLog.IcdVersion,
                                FirstName    = rapsUploadLog.FirstName,
                                SecondName   = rapsUploadLog.SecondName,
                            };
                            _rapsRepository.SaveRaps(rapDomain);
                        }
                    }
                    successCount++;
                }
                catch (Exception exception)
                {
                    _logger.Error(string.Format("Error on Message: {0} \n Stack Trace: {1}", exception.Message, exception.StackTrace));
                }
            }
        }
Ejemplo n.º 2
0
        public MedicareCustomerViewModel GetCustomerDetails(long customerId)
        {
            var customer = _customerRepository.GetCustomer(customerId);

            if (customer == null)
            {
                return(null);
            }
            var model = _medicareFactory.CreateCustomerViewModel(customer);

            if (customer.LanguageId.HasValue)
            {
                var lang = _languageRepository.GetById(customer.LanguageId.Value);
                if (lang != null)
                {
                    model.PreferredLanguage = lang.Name;
                }
            }
            var currentMedications = _currentMedicationRepository.GetByCustomerId(customerId).ToArray();

            if (currentMedications.Any())
            {
                var currentMedicationList = new List <MedicareCurrentMedication>();
                var ndcIds = currentMedications.Select(x => x.NdcId);
                var ndcs   = _ndcRepository.GetByIds(ndcIds);
                if (ndcs != null && ndcs.Any())
                {
                    foreach (var ndc in ndcs)
                    {
                        var curr = currentMedications.FirstOrDefault(x => x.NdcId == ndc.Id);
                        currentMedicationList.Add(new MedicareCurrentMedication
                        {
                            CurrentMedication = ndc.NdcCode,
                            IsPrescribed      = curr != null && curr.IsPrescribed,
                            IsOtc             = curr != null && curr.IsOtc,
                        });
                    }
                }
                if (currentMedicationList.Any())
                {
                    model.CurrentMedications = new List <MedicareCurrentMedication>();
                    model.CurrentMedications = model.CurrentMedications.Concat(currentMedicationList);
                }
            }
            var raps = _rapsRepository.GetByCustomerId(customerId).ToArray();

            if (raps.Any())
            {
                model.Raps = raps.Select(Mapper.Map <Raps, MedicareRapsViewModel>);
            }

            var preApproved = _preApprovedTestRepository.GetByCustomerId(customerId).ToArray();

            if (preApproved.Any())
            {
                var testIds = preApproved.Select(x => x.TestId);
                model.PreapprovedTestList = _testRepository.GetAliasListByTestIdList(testIds);
            }

            return(model);
        }