Exemple #1
0
        public HospitalPartnerDashboardViewModel Create(long scheduledEvents, IEnumerable <OrderedPair <long, int> > totalCustomers, IEnumerable <OrderedPair <long, int> > customersAttended, IEnumerable <OrderedPair <long, int> > criticalCustomers,
                                                        IEnumerable <OrderedPair <long, int> > normalCustomers, IEnumerable <OrderedPair <long, int> > abnormalCustomers, IEnumerable <Event> events, IEnumerable <Host> hosts,
                                                        long reccentContactedEventId, IEnumerable <OrderedPair <long, DateTime> > recentMailedEvents, DateTime?mailedDate, IEnumerable <EventCustomerResult> recentCriticalCustomers, IEnumerable <Customer> customers,
                                                        IEnumerable <CustomerResultStatusViewModel> customerResultStatusViewModels, IEnumerable <OrderedPair <long, int> > urgentCustomers)
        {
            var model = new HospitalPartnerDashboardViewModel
            {
                ScheduleEvents      = scheduledEvents,
                RegisteredCustomers = totalCustomers.Sum(tc => tc.SecondValue),
                ScreenedCustomers   = customersAttended.Sum(ca => ca.SecondValue),
                NormalCustomers     = normalCustomers.Sum(ec => ec.SecondValue),
                AbnormalCustomers   = abnormalCustomers.Sum(ac => ac.SecondValue),
                CriticalCustomers   = criticalCustomers.Sum(cc => cc.SecondValue),
                UrgentCustomers     = urgentCustomers.Sum(uc => uc.SecondValue),
            };

            if (events != null && events.Count() > 0)
            {
                if (recentMailedEvents != null && recentMailedEvents.Count() > 0)
                {
                    model.RecentMailedEvents = _hospitalPartnerEventListFactory.Create(events, hosts, recentMailedEvents);
                }

                var recentContactedEvent = events.Where(e => e.Id == reccentContactedEventId).SingleOrDefault();
                if (recentContactedEvent != null)
                {
                    var host = hosts.Where(h => h.Id == recentContactedEvent.HostId).Single();
                    model.RecentContactedEvent = _hospitalPartnerEventListFactory.Create(recentContactedEvent, host,
                                                                                         mailedDate);
                }

                if (recentCriticalCustomers != null && recentCriticalCustomers.Count() > 0)
                {
                    var customerModel = (from recentCriticalCustomer in recentCriticalCustomers
                                         let theEvent = events.Where(e => e.Id == recentCriticalCustomer.EventId).Single()
                                                        let customer = customers.Where(c => c.CustomerId == recentCriticalCustomer.CustomerId).Single()
                                                                       let customerResultStatus = customerResultStatusViewModels.Where(crs => crs.EventCustomerId == recentCriticalCustomer.Id).Single()
                                                                                                  select new HospitalPartnerDashboardCustomerViewData
                    {
                        CustomerId = customer.CustomerId,
                        CustomerName = customer.Name,
                        EventDate = theEvent.EventDate,
                        EventId = theEvent.Id,
                        CriticalMarkedByPhysician = customerResultStatus.TestResults.Where(tr => tr.CriticalMarkedByPhysician && !tr.IsCritical).Any(),
                        ResultSummary = (recentCriticalCustomer.ResultSummary.HasValue ? (ResultInterpretation)recentCriticalCustomer.ResultSummary : ResultInterpretation.Critical).ToString()
                    }).ToList();
                    model.Customers = customerModel;
                }
            }
            return(model);
        }
Exemple #2
0
        public ListModelBase <HospitalPartnerEventViewModel, HospitalPartnerEventListModelFilter> GetHospitalPartnerEvents(int pageNumber, int pageSize, ModelFilterBase filter, out int totalRecords)
        {
            using (var t = new TransactionScope(TransactionScopeOption.Required, new TransactionOptions {
                IsolationLevel = IsolationLevel.ReadUncommitted
            }))
            {
                var normalValidityPeriod   = 0;
                var abnormalValidityPeriod = 0;
                var criticalValidityPeriod = 0;
                var eventFilter            = (filter as HospitalPartnerEventListModelFilter);
                if (eventFilter != null && eventFilter.HospitalPartnerId > 0)
                {
                    var hospitalPartner = _hospitalPartnerRepository.GetHospitalPartnerforaVendor(eventFilter.HospitalPartnerId);
                    normalValidityPeriod   = hospitalPartner.NormalResultValidityPeriod;
                    abnormalValidityPeriod = hospitalPartner.AbnormalResultValidityPeriod;
                    criticalValidityPeriod = hospitalPartner.CriticalResultValidityPeriod;
                }

                var events   = _eventRepository.GetEventsForHospitalPartner(pageNumber, pageSize, filter as HospitalPartnerEventListModelFilter, out totalRecords, normalValidityPeriod, abnormalValidityPeriod, criticalValidityPeriod);
                var eventIds = events.Select(e => e.Id).ToArray();

                var hosts             = _hostRepository.GetEventHosts(eventIds);
                var customersAttended = _eventRepository.GetAttendedCustomers(eventIds);

                var normalCustomers   = _eventCustomerResultRepository.GetResultSummaryIEventIdCustomersCountForEventIds(eventIds, ResultInterpretation.Normal, true, normalValidityPeriod);
                var abnormalCustomers = _eventCustomerResultRepository.GetResultSummaryIEventIdCustomersCountForEventIds(eventIds, ResultInterpretation.Abnormal, true, abnormalValidityPeriod);
                var criticalCustomers = _eventCustomerResultRepository.GetCriticalEventIdCustomersCountForEventIds(eventIds, ResultInterpretation.Critical, true, criticalValidityPeriod);
                var urgentCustomers   = _eventCustomerResultRepository.GetResultSummaryIEventIdCustomersCountForEventIds(eventIds, ResultInterpretation.Urgent, true, criticalValidityPeriod);

                var eventIdNotesIdPair = _hospitalPartnerRepository.GetEventIdNotesIdPair(eventIds);
                var notes = _notesRepository.Get(eventIdNotesIdPair.Select(ec => ec.SecondValue));

                var idNamePairs = _organizationRoleUserRepository.GetNameIdPairofUsers(notes.Select(n => n.DataRecorderMetaData.DataRecorderCreator.Id).ToArray());

                var model = new HospitalPartnerEventListModel();
                model.Collection = _hospitalPartnerEventListFactory.Create(events, hosts, customersAttended, criticalCustomers, abnormalCustomers, eventIdNotesIdPair, notes, urgentCustomers, normalCustomers, idNamePairs);
                t.Complete();
                return(model);
            }
        }