public ParticipantViewModel GetPerson(int id, int studyId) { var participant = new ParticipantViewModel(); var mapper = new ParticipantMapper(); var personDetail = new ParticipantDetail(); var person = new ParticipantById(); if (studyId == 0) { person = db.GetParticipantById(id).FirstOrDefault(); } else { person = db.GetParticipantById(id).Where(s => s.StudyId == studyId).FirstOrDefault(); } if (person != null) { participant = mapper.GetParticipantViewModel(person); //HouseholdMembers if (participant.HouseholdId != null) { var participantList = GetPeople(); participant.HouseholdMembers = participantList.Where(p => p.HouseholdId == participant.HouseholdId).ToList(); } if (studyId != 0) { #region StudyParticipation var ic = db.GetParticipantConsentById(participant.PersonId).Where(s => s.StudyId == participant.StudyId).ToArray(); var informedConsents = Mapper.Map <ParticipantConsentById[], IEnumerable <LinkedInformedConsentViewModel> >(ic); foreach (var i in informedConsents) { if (i.WrittenConsentBy.HasValue) { i.WrittenConsenByName = db.uspGetStaffFullNameById(i.WrittenConsentBy.Value).FirstOrDefault(); } if (i.VerbalConsentBy.HasValue) { i.VerbalConsentByName = db.uspGetStaffFullNameById(i.VerbalConsentBy.Value).FirstOrDefault(); } } participant.InformedConsents = informedConsents.ToList(); #endregion //Corresponsdance #region Corresponsdance var userCorrespondance = db.Correspondences.Where(c => c.StudyId == studyId && c.PersonId == id).ToArray(); var correspondance = Mapper.Map <Correspondence[], IEnumerable <CorrespondanceViewModel> >(userCorrespondance); foreach (var c in correspondance) { if (c.VtgStaffId.HasValue) { c.VtgStaff = db.uspGetStaffFullNameById(c.VtgStaffId.Value).FirstOrDefault(); } if (c.FollowupStaff1.HasValue) { c.FollowupStaff = db.uspGetStaffFullNameById(c.FollowupStaff1.Value).FirstOrDefault(); } if (c.FollowupStaff2.HasValue) { c.FollowupStaff = c.FollowupStaff + ',' + db.uspGetStaffFullNameById(c.FollowupStaff2.Value).FirstOrDefault(); } } participant.Correspondance = correspondance; #endregion #region Medical History var medHistory = db.MedicalHistories.Where(m => m.PersonId == id).ToArray(); var medicalHistory = Mapper.Map <MedicalHistory[], IEnumerable <MedicalHistoryViewModel> >(medHistory); foreach (var md in medicalHistory) { } participant.MedicalHistory = medicalHistory; #endregion } else { #region Corresponsdance var userCorrespondance = db.Correspondences.Where(c => c.StudyId == null && c.PersonId == id).ToArray(); var correspondance = Mapper.Map <Correspondence[], IEnumerable <CorrespondanceViewModel> >(userCorrespondance); foreach (var c in correspondance) { if (c.VtgStaffId.HasValue) { c.VtgStaff = db.uspGetStaffFullNameById(c.VtgStaffId.Value).FirstOrDefault(); } if (c.FollowupStaff1.HasValue) { c.FollowupStaff = db.uspGetStaffFullNameById(c.FollowupStaff1.Value).FirstOrDefault(); } if (c.FollowupStaff2.HasValue) { c.FollowupStaff = c.FollowupStaff + ',' + db.uspGetStaffFullNameById(c.FollowupStaff2.Value).FirstOrDefault(); } } participant.Correspondance = correspondance; #endregion } #region Practices/Doctors var linkedDocPractice = db.LinkSubjectDoctorPractices.Where(d => d.PersonId == id).ToList(); var linkedDocPracticeVM = Mapper.Map <List <LinkSubjectDoctorPractice>, IEnumerable <LinkedSubjectDoctorPracticeViewModel> >(linkedDocPractice); foreach (var link in linkedDocPracticeVM) { var practiceDocs = db.LinkDoctorPractices.Where(p => p.DoctorPracticeLinkId == link.DoctorPracticeLinkId).FirstOrDefault(); //PracticeName link.Practice = db.Practices.Where(p => p.PracticeId == practiceDocs.PracticeId).Select(p => p.NamePractice).FirstOrDefault(); link.PracticeId = practiceDocs.PracticeId; //Doctor Detail var doctor = db.Doctors.Where(d => d.DoctorId == practiceDocs.DoctorId).FirstOrDefault(); link.DoctorId = practiceDocs.DoctorId; link.DoctorName = doctor.Fullname; link.DoctorType = doctor.TypeDoctor; } participant.LinkedSubjectDoctorPractices = linkedDocPracticeVM; #endregion //Next of Kins //if (person.Nok1PersonId != null) //{ // participant.Nok1PersonId = person.Nok1PersonId; // participant.Nok1Person = person.NoK1Person; //} //if (person.Nok2PersonId != null) //{ // participant.Nok2PersonId = person.Nok2PersonId; // participant.Nok2Person = person.NoK2Person; //} } return(participant); }