Example #1
0
        public StudyViewModel GetStudy(int id)
        {
            var study          = db.GetStudyDetailById(id).FirstOrDefault();
            var studyViewModel = Mapper.Map <StudyDetailById, StudyViewModel>(study);



            #region SubjectAgeCriteria
            if (!string.IsNullOrEmpty(studyViewModel.SubjectMinAgeInequality))
            {
                if (studyViewModel.SubjectMinAgeInequality == "GTOET")
                {
                    studyViewModel.GreaterThanEquals = true;
                }
                else if (studyViewModel.SubjectMinAgeInequality == "GT")
                {
                    studyViewModel.GreaterThan = true;
                }
            }

            if (studyViewModel.SubjectMinAgeInYears.HasValue)
            {
                if (studyViewModel.SubjectMinAgeInYears.Value > 1)
                {
                    studyViewModel.MinYear = (int)(studyViewModel.SubjectMinAgeInYears.Value);
                    var remainder = (studyViewModel.SubjectMinAgeInYears.Value % 1);
                    studyViewModel.MinMonth = (int)(remainder * 12);
                }
                else
                {
                    studyViewModel.MinYear = 0;
                    var remainder = studyViewModel.SubjectMinAgeInYears.Value;
                    studyViewModel.MinMonth = (int)(remainder * 12);
                }
            }

            if (!string.IsNullOrEmpty(studyViewModel.SubjectMaxAgeInequality))
            {
                if (studyViewModel.SubjectMaxAgeInequality == "LTOET")
                {
                    studyViewModel.LessThanEquals = true;
                }
                else if (studyViewModel.SubjectMaxAgeInequality == "LT")
                {
                    studyViewModel.LessThan = true;
                }
            }
            if (studyViewModel.SubjectMaxAgeInYears.HasValue)
            {
                if (studyViewModel.SubjectMaxAgeInYears.Value > 1)
                {
                    studyViewModel.MaxYear = (int)(studyViewModel.SubjectMaxAgeInYears.Value);
                    var remainder = (studyViewModel.SubjectMaxAgeInYears.Value % 1);
                    studyViewModel.MaxMonth = (int)(Math.Round(remainder * 12));
                }
                else
                {
                    studyViewModel.MaxYear = 0;
                    var remainder = studyViewModel.SubjectMaxAgeInYears.Value;
                    studyViewModel.MaxMonth = (int)(Math.Round(remainder * 12));
                }
            }
            #endregion


            #region VisitSchedule
            var visitSchedule = db.GetStudyVisitTasks(id).ToArray();
            var visitList     = Mapper.Map <StudyVisitTasks[], IEnumerable <VisitScheduleViewModel> > (visitSchedule);

            studyViewModel.VisitList = visitList;
            #endregion

            #region Recruitment
            var recuitment           = db.Recruitments.Where(r => r.StudyId == id).ToArray();
            var recruitmentViewModel = Mapper.Map <Recruitment[], IEnumerable <RecruitmentViewModel> >(recuitment);
            studyViewModel.RecruitmentList = recruitmentViewModel;
            #endregion

            #region InformedConsent
            var informedConsent          = db.InformedConsents.Where(ic => ic.StudyId == id).ToArray();
            var informedConsentViewModel = Mapper.Map <InformedConsent[], IEnumerable <InformedConsentViewModel> >(informedConsent);
            studyViewModel.InformedConsentList = informedConsentViewModel;
            #endregion

            #region StaffRoles
            var staff = db.GetStaffRolesForStudy(id).ToArray();
            var staffRolesViewModel = Mapper.Map <StaffRolesForStudy[], IEnumerable <LinkVtgStaffStudyViewModel> >(staff);
            studyViewModel.LinkVtgStaffStudies = staffRolesViewModel;
            #endregion

            return(studyViewModel);
        }