public CustomerAppointmentViewModel GetPatientDetail(long eventCustomerId) { var eventCustomer = _eventCustomerRepository.GetById(eventCustomerId); if (eventCustomer == null) { return(null); } var customer = _customerRepository.GetCustomer(eventCustomer.CustomerId); var account = !string.IsNullOrWhiteSpace(customer.Tag) ? _corporateAccountRepository.GetByTagWithOrganization(customer.Tag) : null; var appointment = eventCustomer.AppointmentId.HasValue ? _appointmentRepository.GetById(eventCustomer.AppointmentId.Value) : null; var order = _orderRepository.GetOrderByEventCustomerId(eventCustomerId); var eventPackages = _eventPackageRepository.GetPackagesForEvent(eventCustomer.EventId); var eventTests = _eventTestRepository.GetTestsForEvent(eventCustomer.EventId); var eventpackageId = order.OrderDetails.Where(od => od.OrderItemStatus.OrderStatusState == OrderStatusState.FinalSuccess && od.OrderItem.OrderItemType == OrderItemType.EventPackageItem) .Select(od => od.OrderItem.ItemId).SingleOrDefault(); var eventPackage = eventPackages.SingleOrDefault(ep => eventpackageId == ep.Id); var eventTestIds = order.OrderDetails.Where(od => od.OrderItemStatus.OrderStatusState == OrderStatusState.FinalSuccess && od.OrderItem.OrderItemType == OrderItemType.EventTestItem).Select(od => od.OrderItem.ItemId).ToArray(); var eventTestsonOrder = eventTests.Where(et => eventTestIds.Contains(et.Id)).ToArray(); var address = Mapper.Map <Address, AddressViewModel>(customer.Address); var pcp = _primaryCarePhysicianRepository.Get(eventCustomer.CustomerId); var isParticipationConsentSaved = _participationConsentSignatureRepository.IsSaved(eventCustomerId); var isGiftCardSaved = _eventCustomerGiftCardRepository.IsSaved(eventCustomerId); var isFluConsentSaved = _fluConsentSignatureRepository.IsSaved(eventCustomerId); var isPhysicianRecordRequestSaved = _physicianRecordRequestSignatureRepository.IsSaved(eventCustomerId); var chaperoneSignature = _chaperoneSignatureRepository.GetByEventCustomerId(eventCustomer.Id); var model = new CustomerAppointmentViewModel { CustomerId = customer.CustomerId, EventCustomerId = eventCustomer.Id, FirstName = customer.Name.FirstName, MiddleName = customer.Name.MiddleName, LastName = customer.Name.LastName, Email = customer.Email.ToString(), Address = address, HomePhone = customer.HomePhoneNumber.FormatPhoneNumber, MobileNumber = customer.MobilePhoneNumber.FormatPhoneNumber, MemberId = customer.InsuranceId, Dob = customer.DateOfBirth, Gender = customer.Gender.GetDescription(), HealthPlan = account != null ? account.Name : "", EventId = eventCustomer.EventId, AppointmentId = appointment != null ? appointment.Id : (long?)null, AppointmentTime = appointment != null ? appointment.StartTime : (DateTime?)null, CheckInTime = appointment != null ? appointment.CheckInTime : null, CheckOutTime = appointment != null ? appointment.CheckOutTime : null, Packages = eventPackage != null ? eventPackage.Package.Name : "", Tests = !eventTestsonOrder.IsNullOrEmpty() ? string.Join(", ", eventTestsonOrder.Select(t => t.Test.Name)) : "", HipaaConsent = eventCustomer.HIPAAStatus, PcpConsent = eventCustomer.PcpConsentStatus, MatrixConsent = isParticipationConsentSaved, PhysicianRecordRequest = isPhysicianRecordRequestSaved, GiftCard = isGiftCardSaved, FluVaccine = isFluConsentSaved, Survey = false, ExitInterview = false, NoShow = eventCustomer.AppointmentId.HasValue && eventCustomer.NoShow, LeftWithoutScreening = eventCustomer.AppointmentId.HasValue && eventCustomer.LeftWithoutScreeningReasonId.HasValue, ChaperoneConsent = chaperoneSignature != null ? true : false }; if (pcp != null) { var pcpAddress = pcp.Address != null?Mapper.Map <Address, AddressViewModel>(pcp.Address) : null; model.PrimaryCarePhysician = new PcpInfoViewModel { Name = pcp.Name.FullName, Address = pcpAddress, PhoneNumber = pcp.Primary != null ? pcp.Primary.FormatPhoneNumber : pcp.Secondary != null ? pcp.Secondary.FormatPhoneNumber : "", Fax = pcp.Fax != null ? pcp.Fax.FormatPhoneNumber : "" }; } return(model); }