Exemple #1
0
        public HospitalPartnerDashboardViewModel GetHospitalFacilityDashboardModel(long hospitalFacilityId)
        {
            var             hospitalPartnerId = _hospitalFacilityRepository.GetHospitalPartnerId(hospitalFacilityId);
            HospitalPartner hospitalPartner   = null;

            if (hospitalPartnerId > 0)
            {
                hospitalPartner = _hospitalPartnerRepository.GetHospitalPartnerforaVendor(hospitalPartnerId);
            }

            var eventIds = _hospitalFacilityRepository.GetEventIdsForHospitalFacility(hospitalFacilityId);

            if (eventIds.IsNullOrEmpty())
            {
                return(new HospitalPartnerDashboardViewModel());
            }

            var reccentContactedEventId = _hospitalPartnerCustomerRepository.GetMostRecentContactedEventForHospitalFacility(hospitalFacilityId);
            var recentMailedEvents      = _shippingDetailRepository.GetRecentMailedHospitalFacilityEvents(hospitalFacilityId).ToList();

            var recentCriticalCustomers = _eventCustomerResultRepository.GetRecentCriticalAndUrgentCustomersForHospitalFacility(hospitalFacilityId, 1, 8, hospitalPartner != null ? hospitalPartner.CriticalResultValidityPeriod : 0);

            var getEventIds = recentMailedEvents.Count() > 0 ? recentMailedEvents.Select(me => me.FirstValue).ToList() : new List <long>();

            if (reccentContactedEventId > 0)
            {
                getEventIds.Add(reccentContactedEventId);
            }

            IEnumerable <Customer> customers = null;
            IEnumerable <Event>    events    = null;
            IEnumerable <Host>     hosts     = null;
            IEnumerable <CustomerResultStatusViewModel> customerResultStatusViewModels = null;

            if (recentCriticalCustomers != null && recentCriticalCustomers.Count() > 0)
            {
                getEventIds.AddRange(recentCriticalCustomers.Select(rcc => rcc.EventId).ToArray());
                customers = _customerRepository.GetCustomers(recentCriticalCustomers.Select(rcc => rcc.CustomerId).ToArray());
                customerResultStatusViewModels = _eventCustomerResultRepository.GetTestResultStatus(recentCriticalCustomers.Select(rcc => rcc.Id).ToArray());
            }

            if (getEventIds.Count > 0)
            {
                events = _eventRepository.GetEventswithPodbyIds(getEventIds.ToArray());
                hosts  = _hostRepository.GetEventHosts(events.Select(e => e.Id).ToArray());
            }
            var totalCustomers    = _eventRepository.GetCustomersWithAppointmentByHospitalFacilityId(hospitalFacilityId);
            var customersAttended = _eventRepository.GetAttendedCustomersByHospitalFacilityId(hospitalFacilityId);

            var normalCustomers   = _eventCustomerResultRepository.GetResultSummaryEventIdCustomersCountForHospitalFacility(hospitalFacilityId, ResultInterpretation.Normal, true, hospitalPartner != null ? hospitalPartner.NormalResultValidityPeriod : 0);
            var abnormalCustomers = _eventCustomerResultRepository.GetResultSummaryEventIdCustomersCountForHospitalFacility(hospitalFacilityId, ResultInterpretation.Abnormal, true, hospitalPartner != null ? hospitalPartner.AbnormalResultValidityPeriod : 0);
            var criticalCustomers = _eventCustomerResultRepository.GetCriticalEventIdCustomersCountForHospitalFacility(hospitalFacilityId, ResultInterpretation.Critical, true, hospitalPartner != null ? hospitalPartner.CriticalResultValidityPeriod : 0);
            var urgentCustomers   = _eventCustomerResultRepository.GetResultSummaryEventIdCustomersCountForHospitalFacility(hospitalFacilityId, ResultInterpretation.Urgent, true, hospitalPartner != null ? hospitalPartner.CriticalResultValidityPeriod : 0);

            var mailedDate = _shippingDetailRepository.MailedDateForEvent(reccentContactedEventId, hospitalFacilityId);

            return(_hospitalPartnerViewModelFactory.Create(eventIds.Count(), totalCustomers, customersAttended,
                                                           criticalCustomers, normalCustomers, abnormalCustomers,
                                                           events, hosts,
                                                           reccentContactedEventId, recentMailedEvents, mailedDate,
                                                           recentCriticalCustomers, customers, customerResultStatusViewModels, urgentCustomers));
        }