예제 #1
0
        protected override IEnumerable <CheckPayment> PostFetchTransform(IEnumerable <CheckPayment> domainObjects)
        {
            IEnumerable <long>  checkIds = domainObjects.Select(cp => cp.CheckId);
            IEnumerable <Check> checks   = _checkRepository.GetByIds(checkIds);

            domainObjects = AssignChecksToCheckPayments(domainObjects, checks);

            return(domainObjects);
        }
예제 #2
0
        public CustomerScreeningViewData GetCustomerScreeningViewData(long customerId, long eventId)
        {
            var eventCustomer   = _eventCustomerRepository.Get(eventId, customerId);
            var customer        = _customerRepository.GetCustomer(customerId);
            var theEvent        = _eventRepository.GetById(eventId);
            var isNewResultFlow = theEvent.EventDate >= _settings.ResultFlowChangeDate;
            var testResults     = GetTestResults(customerId, eventId, isNewResultFlow);
            var appointment     = _appointmentRepository.GetEventCustomerAppointment(eventId, customerId);
            var order           = _orderRepository.GetOrder(customerId, eventId);
            var package         = _packageRepository.GetPackageForOrder(order.Id);

            var tests = _testRepository.GetTestsForOrder(order.Id);

            var evaluatingPhysicians = _physicianEvaluationRepsoitory.GetPhysicianEvaluation(eventCustomer.Id);
            var primaryEvalRecord    = evaluatingPhysicians != null?evaluatingPhysicians.Where(p => p.IsPrimaryEvaluator).OrderByDescending(p => p.EvaluationEndTime ?? p.EvaluationStartTime).FirstOrDefault() : null;

            var primaryPhysicianId  = primaryEvalRecord != null ? primaryEvalRecord.PhysicianId : 0;
            var overreadPhysicianId = primaryEvalRecord != null?evaluatingPhysicians.Where(p => !p.IsPrimaryEvaluator && p.EvaluationStartTime > primaryEvalRecord.EvaluationStartTime).OrderByDescending(
                p => p.EvaluationEndTime ?? p.EvaluationStartTime).Select(p => p.PhysicianId).FirstOrDefault() : 0;

            if (primaryPhysicianId < 1)
            {
                var assignment = _physicianAssignmentService.GetPhysicianIdsAssignedtoaCustomer(eventId, customerId);
                if (assignment != null)
                {
                    primaryPhysicianId  = assignment.First();
                    overreadPhysicianId = assignment.ElementAtOrDefault(1);
                }
                else // Should be Skip Evaluation Case
                {
                    var physicians = testResults.Where(tr => tr.EvaluatedbyOrgRoleUserId > 0).Select(tr => tr.EvaluatedbyOrgRoleUserId).Distinct().ToArray();

                    if (physicians.Any())
                    {
                        primaryPhysicianId = physicians.First();
                    }

                    if (physicians.Count() > 1)
                    {
                        overreadPhysicianId = physicians.Last();
                    }
                }
            }
            if (primaryPhysicianId < 1)
            {
                //todo:default for the state
                primaryPhysicianId = _physicianRepository.GetDefaultPhysicianforEvent(eventId);
            }

            var primaryPhysician  = _physicianRepository.GetPhysician(primaryPhysicianId);
            var overreadPhysician = overreadPhysicianId > 0 ? _physicianRepository.GetPhysician(overreadPhysicianId) : null;

            var host           = _hostRepository.GetHostForEvent(eventId);
            var basicBiometric = _basicBiometricRepository.Get(eventId, customerId);

            CustomerScreeningViewData viewData = _factory.Create(testResults, customer, appointment, theEvent, package != null ? package.Package : null, tests != null ? tests.Select(t => t.Test).ToArray() : null, host,
                                                                 primaryPhysician, overreadPhysician, order, basicBiometric);

            if (order.PaymentsApplied != null)
            {
                var chargeCardPayments =
                    order.PaymentsApplied.Where(pa => pa.PaymentType == PaymentType.CreditCard).Select(
                        pa => (ChargeCardPayment)pa).ToArray();

                if (chargeCardPayments.Count() > 0)
                {
                    viewData.ChargeCards = _chargeCardRepository.GetByIds(chargeCardPayments.Select(cp => cp.ChargeCardId).ToArray());
                }

                var checkPayments = order.PaymentsApplied.Where(pa => pa.PaymentType == PaymentType.Check).Select(
                    pa => (CheckPayment)pa).ToArray();

                if (checkPayments.Count() > 0)
                {
                    viewData.Checks = _checkRepository.GetByIds(checkPayments.Select(c => c.CheckId).ToArray());
                }
            }

            var eventHospitalPartner = _hospitalPartnerRepository.GetEventHospitalPartnersByEventId(eventId);

            if (eventHospitalPartner != null && eventHospitalPartner.RestrictEvaluation)
            {
                var eventPhysicianTests = _eventPhysicianTestRepository.GetByEventId(eventId);
                if (eventPhysicianTests != null && eventPhysicianTests.Any())
                {
                    viewData.EventPhysicianTests = eventPhysicianTests;
                }
            }

            return(viewData);
        }