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);
        }
Exemplo n.º 2
0
        //Change Model to ViewModel
        public ParticipantViewModel GetParticipantViewModel(ParticipantById participantModel)
        {
            var participantViewModel = new ParticipantViewModel();

            participantViewModel.PersonId                                         = participantModel.PersonId;
            participantViewModel.VtgNumber                                        = participantModel.VtgNumber;
            participantViewModel.UMRN                                             = participantModel.UMRN;
            participantViewModel.DbConsentYesNo                                   = participantModel.DbConsentYesNo;
            participantViewModel.DbConsentType                                    = participantModel.DbConsentType;
            participantViewModel.DbConsentDateLastConfirmed                       = participantModel.DbConsentDateLastConfirmed;
            participantViewModel.NewsletterConsentYesNo                           = participantModel.NewsletterConsentYesNo;
            participantViewModel.NewsletterConsentDateLastConfirmed               = participantModel.NewsletterConsentDateLastConfirmed;
            participantViewModel.FutureVtgResearchConsentYesNo                    = participantModel.FutureVtgResearchConsentYesNo;
            participantViewModel.FutureVtgResearchConsentDateLastConfirmed        = participantModel.FutureVtgResearchConsentDateLastConfirmed;
            participantViewModel.FutureThirdPartyResearchlConsentYesNo            = participantModel.FutureThirdPartyResearchlConsentYesNo;
            participantViewModel.FutureThirdPartyResearchConsentDateLastConfirmed = participantModel.FutureThirdPartyResearchConsentDateLastConfirmed;
            participantViewModel.Title                                            = participantModel.Title;
            participantViewModel.Surname                                          = participantModel.Surname;
            participantViewModel.Firstname                                        = participantModel.Firstname;
            participantViewModel.MiddleName                                       = participantModel.MiddleName;
            participantViewModel.PreferredName                                    = participantModel.PreferredName;
            participantViewModel.Gender                                           = participantModel.Gender;
            participantViewModel.Dob                     = participantModel.Dob;
            participantViewModel.Ethnicity               = participantModel.Ethnicity;
            participantViewModel.PhoneWork               = participantModel.PhoneWork;
            participantViewModel.PhoneMobile             = participantModel.PhoneMobile;
            participantViewModel.Email                   = participantModel.Email;
            participantViewModel.PreferredContactWritten = participantModel.PreferredContactWritten;
            participantViewModel.Nok1PersonId            = participantModel.Nok1PersonId;
            participantViewModel.Nok1Relationship        = participantModel.Nok1Relationship;
            participantViewModel.Nok2PersonId            = participantModel.Nok2PersonId;
            participantViewModel.Nok2Relationship        = participantModel.Nok2Relationship;
            participantViewModel.AddresseeId             = participantModel.AddresseeId;
            participantViewModel.HouseholdId             = participantModel.HouseholdId;
            participantViewModel.RecruitmentSource       = participantModel.RecruitmentSource;
            participantViewModel.Comments                = participantModel.Comments;
            participantViewModel.PreferredContactVerbal  = participantModel.PreferredContactVerbal;
            participantViewModel.IsNok1ForKids           = ((participantModel.IsNok1ForKids.HasValue && participantModel.IsNok1ForKids == 1)?true:false);
            participantViewModel.IsNok2ForKids           = ((participantModel.IsNok2ForKids.HasValue && participantModel.IsNok2ForKids == 1) ? true : false);
            participantViewModel.AgeInYrs                = participantModel.AgeInYrs;
            participantViewModel.AgeInYrMo               = participantModel.AgeInYrMo;
            participantViewModel.StudyNickName           = participantModel.NicknameStudy;
            participantViewModel.StudyId                 = participantModel.StudyId.HasValue?participantModel.StudyId.Value:0;

            //Address
            participantViewModel.ActiveAddress      = participantModel.ActiveAddress.HasValue && participantModel.ActiveAddress == 1?true:false;
            participantViewModel.State              = participantModel.AddressState;
            participantViewModel.Suburb             = participantModel.AddressSuburb;
            participantViewModel.Postcode           = participantModel.AddressPostcode;
            participantViewModel.Street             = participantModel.AddressStreet;
            participantViewModel.ActiveAddress      = (participantModel.ActiveAddress == 1?true:false);
            participantViewModel.LastConfirmedWhen  = participantModel.LastConfirmedWhen;
            participantViewModel.LastConfirmedBy    = participantModel.LastConfirmedBy;
            participantViewModel.ConfirmedBy        = participantModel.ConfirmedBy;
            participantViewModel.PhoneHome          = participantModel.PhoneHome;
            participantViewModel.HouseholdAddressee = participantModel.HouseholdAddressee;
            //  participantViewModel.PhoneHome = participantModel.PhoneHome;

            participantViewModel.SubjectStudyLinkId       = participantModel.SubjectStudyLinkId.HasValue? participantModel.SubjectStudyLinkId.Value:0;
            participantViewModel.StudyParticipationStatus = participantModel.Status;
            participantViewModel.OfficialSubjectStudyNum  = participantModel.OfficialSubjectStudyNum;
            //  participantViewModel.VisitStream                                         = participantModel.VisitStream;
            participantViewModel.Reason        = participantModel.WithdrawnReason;
            participantViewModel.ReasonOther   = participantModel.WithdrawnReasonOther;
            participantViewModel.EffectiveFrom = participantModel.EffFrom;
            participantViewModel.EffectiveTo   = participantModel.EffTo;



            return(participantViewModel);
        }