private BiWeeklyMicroAlbuminFobtReportListModel GetBiWeeklyMicroAlbuminFobtReportModel(IReadOnlyCollection <EventCustomerResult> eventCustomerResultCollection) { if (eventCustomerResultCollection.IsNullOrEmpty()) { _logger.Info("eventCustomerResultCollection provided is null or empty"); return(null); } var listModel = new BiWeeklyMicroAlbuminFobtReportListModel(); var collection = new List <BiWeeklyMicroAlbuminFobtReportViewModel>(); var customerIds = eventCustomerResultCollection.Select(x => x.CustomerId).ToArray(); var eventIds = eventCustomerResultCollection.Select(x => x.EventId).ToArray(); var eventCustomerResultIds = eventCustomerResultCollection.Select(x => x.Id).ToArray(); var events = _eventRepository.GetEventswithPodbyIds(eventIds); var hosts = _hostRepository.GetEventHosts(eventIds); var physicianLabTests = _physicianLabTestRepository.GetPhysicicanLabTestByStateIds(hosts.Select(x => x.Address.StateId)); var customers = _customerRepository.GetCustomers(customerIds); var eventCustomerResultIdIfobtValuePair = _eventCustomerResultRepository.GetLabKitValueByEventCustomerResultId(eventCustomerResultIds, (long)TestType.IFOBT, (long)ReadingLabels.IFOBTSerialKey); var eventCustomerResultIdMicroAlbuminValuePair = _eventCustomerResultRepository.GetLabKitValueByEventCustomerResultId(eventCustomerResultIds, (long)TestType.UrineMicroalbumin, (long)ReadingLabels.MicroalbuminSerialKey); if (eventCustomerResultIdIfobtValuePair == null) { eventCustomerResultIdIfobtValuePair = new List <OrderedPair <long, string> >(); } if (eventCustomerResultIdMicroAlbuminValuePair == null) { eventCustomerResultIdMicroAlbuminValuePair = new List <OrderedPair <long, string> >(); } foreach (var eventCustomerResult in eventCustomerResultCollection) { var customer = customers.FirstOrDefault(x => x.CustomerId == eventCustomerResult.CustomerId); var @event = events.FirstOrDefault(x => x.Id == eventCustomerResult.EventId); var host = hosts.FirstOrDefault(x => x.Id == @event.HostId); var fobtKit = eventCustomerResultIdIfobtValuePair.Any(x => x.FirstValue == eventCustomerResult.Id && !string.IsNullOrEmpty(x.SecondValue)); var microAlbuminKit = eventCustomerResultIdMicroAlbuminValuePair.Any(x => x.FirstValue == eventCustomerResult.Id && !string.IsNullOrEmpty(x.SecondValue)); var physicianLabTest = physicianLabTests.FirstOrDefault(x => x.StateId == host.Address.StateId); var viewmodel = _biWeeklyMicroAlbuminFobtReportFactory.CreateModel(customer, @event.EventDate, fobtKit, microAlbuminKit, physicianLabTest); collection.Add(viewmodel); } listModel.Collection = collection; return(listModel); }