예제 #1
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);
            }
        }