using AutoMapper;
using IRaCIS.Core.Application.Contracts;
using IRaCIS.Core.Application.Service.Reading.Dto;
using IRaCIS.Core.Application.ViewModel;
using IRaCIS.Core.Infra.EFCore.Common;

namespace IRaCIS.Core.Application.Service
{
    public class ReadingConfig : Profile
    {
        public ReadingConfig()
        {


            //是否英文环境
            var isEn_Us = false;

            //  在此处拷贝automapper 映射

            CreateMap<Segment, SegmentVersionData>();
            CreateMap<SegmentVersionData, Segment>();

            CreateMap<Segment, SegmentView>();
            CreateMap<Segment, SegmentAddOrEdit>().ReverseMap();

            //  在此处拷贝automapper 映射

            CreateMap<Segmentation, SegmentationView>();
            CreateMap<Segmentation, SegmentationAddOrEdit>().ReverseMap();

            CreateMap<SegmentationVersion, SegmentationVersionView>();

            //  在此处拷贝automapper 映射

            CreateMap<SegmentBinding, SegmentBindingView>()
                  .ForMember(d => d.SegmentName, u => u.MapFrom(s => s.Segment.SegmentName))
                     .ForMember(d => d.SegmentationName, u => u.MapFrom(s => s.Segmentation.SegmentationName));
            CreateMap<SegmentBinding, SegmentBindingAddOrEdit>().ReverseMap();

            CreateMap<ReadingQuestionTrial, ReadingReportDto>()
                .ForMember(d => d.QuestionId, u => u.MapFrom(s => s.Id));

            CreateMap<ReadingTableQuestionTrial, ReadingReportDto>()
                   .ForMember(d => d.QuestionId, u => u.MapFrom(s => s.ReadingQuestionId))
                    .ForMember(d => d.TableQuestionId, u => u.MapFrom(s => s.Id));



            CreateMap<SystemCriterionKeyFile, SystemCriterionKeyFileView>();
            CreateMap<SystemCriterionKeyFile, SystemCriterionKeyFileAddOrEdit>().ReverseMap();

            //  在此处拷贝automapper 映射

            CreateMap<TrialCriterionKeyFile, TrialCriterionKeyFileView>();
            CreateMap<TrialCriterionKeyFile, TrialCriterionKeyFileAddOrEdit>().ReverseMap();

            //标准Id
            List<Guid> CriterionIds = new List<Guid>();

            CreateMap<ReadModule, GetReadModulePageListOutDto>()
                  .ForMember(d => d.SiteCode, u => u.MapFrom(s => s.Subject.TrialSite.TrialSiteCode))
                    .ForMember(d => d.SubjectCode, u => u.MapFrom(s => s.Subject.Code))
                       .ForMember(d => d.VisitName, u => u.MapFrom(s => s.SubjectVisit.VisitName))
                          .ForMember(d => d.LatestScanDate, u => u.MapFrom(s => s.SubjectVisit.LatestScanDate));

            #region 临床问题
            CreateMap<TrialClinicalQuestion, TrialClinicalQuestionDto>()
                   .ForMember(d => d.GroupName, opt => opt.MapFrom(src => src.GroupQuestin.QuestionName))
                   .ForMember(d => d.GroupEnName, opt => opt.MapFrom(src => src.GroupQuestin.QuestionEnName));

            CreateMap<TrialClinicalQuestionDto, TrialClinicalQuestion>();

            CreateMap<SystemClinicalQuestion, SystemClinicalQuestionDto>()
               .ForMember(d => d.GroupName, opt => opt.MapFrom(src => src.GroupQuestin.QuestionName))
                   .ForMember(d => d.GroupEnName, opt => opt.MapFrom(src => src.GroupQuestin.QuestionEnName));

            CreateMap<SystemClinicalQuestionDto, SystemClinicalQuestion>();

            CreateMap<SystemClinicalTableQuestion, SystemClinicalTableQuestionDto>();
            CreateMap<SystemClinicalTableQuestionDto, SystemClinicalTableQuestion>();

            CreateMap<TrialClinicalTableQuestion, TrialClinicalTableQuestionDto>();
            CreateMap<TrialClinicalTableQuestionDto, TrialClinicalTableQuestion>();

            CreateMap<SystemClinicalQuestion, TrialClinicalQuestion>()
                   .ForMember(dest => dest.CreateUserRole, opt => opt.Ignore())
                  .ForMember(d => d.SystemClinicalQuestionId, opt => opt.MapFrom(src => src.Id));

            CreateMap<SystemClinicalQuestion, TrialClinicalQuestionSynchronize>()
                .ForMember(d => d.CreateUserRole, opt => opt.Ignore())
               .ForMember(d => d.SystemClinicalQuestionId, opt => opt.MapFrom(src => src.Id));


            CreateMap<SystemClinicalTableQuestion, TrialClinicalTableQuestion>()
                   .ForMember(dest => dest.CreateUserRole, opt => opt.Ignore())
             .ForMember(d => d.SystemTableQuestionId, u => u.MapFrom(s => s.Id));

            CreateMap<SystemClinicalTableQuestion, TrialClinicalTableQuestionSynchronize>()
           .ForMember(d => d.SystemTableQuestionId, opt => opt.MapFrom(src => src.Id))
            .ForMember(d => d.CreateUserRole, opt => opt.Ignore());


            // 预览
            CreateMap<TrialClinicalQuestion, ClinicalQuestionPreviewDto>();


            CreateMap<SystemClinicalQuestion, ClinicalQuestionPreviewDto>();

            CreateMap<SystemClinicalTableQuestion, ClinicalTablePreviewDto>();
            CreateMap<TrialClinicalTableQuestion, ClinicalTablePreviewDto>();
            #endregion
            CreateMap<TableMarkInfo, ReadingTaskQuestionMark>();
            CreateMap<AddNoneDicomMarkInDto, ReadingNoneDicomMark>();
            CreateMap<ReadingNoneDicomMark, AddNoneDicomMarkInDto>();
            CreateMap<AddNoneDicomMarkAndBinding, BindingData>();
            CreateMap<ReadingTaskQuestionMark, TableMarkInfo>();
            CreateMap<VisitTask, VisitTaskDto>();
            CreateMap<SaveTableQuestionMarkInDto, ReadingTaskQuestionMark>();
            CreateMap<ReadingTaskQuestionMark, TableQuestionMark>();
            CreateMap<SubmitTableQuestionInDto, ReadingTableAnswerRowInfo>()
                .ForMember(dest => dest.CreateUserRole, opt => opt.Ignore())
                .ForAllMembers(opts => opts.Condition((src, dest, srcMember) => srcMember != null));

            CreateMap<ShortcutKey, DefaultShortcutKeyView>();
            CreateMap<TrialDataFromSystem, ReadingMedicineTrialQuestion>().ForMember(dest => dest.CreateUserRole, opt => opt.Ignore());

         
            CreateMap<ReadingTaskQuestionMark, ReadingCustomTagDto>();
            CreateMap<ReadingCustomTagDto, ReadingTaskQuestionMark>().ForMember(dest => dest.CreateUserRole, opt => opt.Ignore());

            CreateMap<UserWLTemplate, UserWLTemplateView>();
            CreateMap<UserWLTemplate, UserWLTemplateAddOrEdit>().ReverseMap().ForMember(dest => dest.CreateUserRole, opt => opt.Ignore());

            CreateMap<ReadingPeriodSetAddOrEdit, ReadingPeriodSet>().ForMember(dest => dest.CreateUserRole, opt => opt.Ignore());
            CreateMap<ReadingTableQuestionAnswer, TableQuestionAnswerInfo>().ReverseMap()
                   .ForMember(dest => dest.CreateUserRole, opt => opt.Ignore())
                .ForMember(dest => dest.CreateUserRole, opt => opt.Ignore());

            CreateMap<ReadingTableQuestionAnswer, TableQuestionAnswerInfo>()

                    .ForMember(d => d.QuestionMark, u => u.MapFrom(s => s.ReadingTableQuestionTrial == null ? null : s.ReadingTableQuestionTrial.QuestionMark));

            CreateMap<AddOrUpdateTumorAssessmentInDto, TumorAssessment_RECIST1Point1>();

            CreateMap<ReadingPeriodSet, ReadingPeriodSetView>()
                .ForMember(d => d.SubjectVisitName, u => u.MapFrom(s => s.VisitStage == null ? string.Empty : s.VisitStage.VisitName))
                .ForMember(d => d.SiteIds, u => u.MapFrom(s => s.ReadingPeriodSites.Select(x => x.TrialSiteId)))
                .ForMember(d => d.SiteCodes, u => u.MapFrom(s => s.ReadingPeriodSites.Select(x => x.TrialSite.TrialSiteCode)))
                .ForMember(d => d.PlanCount, u => u.MapFrom(s => s.ReadingPeriodPlanList.Count));

            CreateMap<ReadingSystemCriterionDictionary, CriterionDictionaryInfo>()
             .ForMember(d => d.ChildGroup, u => u.MapFrom(s => s.Dictionary.ChildGroup))
             .ForMember(d => d.Code, u => u.MapFrom(s => s.Dictionary.Code))
             .ForMember(d => d.Description, u => u.MapFrom(s => s.Dictionary.Description))
              .ForMember(d => d.ShowOrder, u => u.MapFrom(s => s.Dictionary.ShowOrder))
               .ForMember(d => d.ParentCode, u => u.MapFrom(s => s.Dictionary.Parent.Code))
                .ForMember(d => d.Value, u => u.MapFrom(s => s.Dictionary.Value))
                 .ForMember(d => d.ValueCN, u => u.MapFrom(s => s.Dictionary.ValueCN));

            CreateMap<ReadingTrialCriterionDictionary, CriterionDictionaryInfo>()
          .ForMember(d => d.ChildGroup, u => u.MapFrom(s => s.Dictionary.ChildGroup))
         .ForMember(d => d.Code, u => u.MapFrom(s => s.Dictionary.Code))
          .ForMember(d => d.Description, u => u.MapFrom(s => s.Dictionary.Description))
           .ForMember(d => d.ShowOrder, u => u.MapFrom(s => s.Dictionary.ShowOrder))
            .ForMember(d => d.ParentCode, u => u.MapFrom(s => s.Dictionary.Parent.Code))
             .ForMember(d => d.Value, u => u.MapFrom(s => s.Dictionary.Value))
              .ForMember(d => d.ValueCN, u => u.MapFrom(s => s.Dictionary.ValueCN));

            CreateMap<ReadingTaskQuestionMark, GetTableAnswerRowInfoOutDto>()
                .ForMember(d => d.FristAddTaskId, u => u.MapFrom(s => s.FristAddTaskId!.Value));
            CreateMap<ReadingTaskQuestionMark, QuestionMarkInfo>();

            CreateMap<ReadingNoneDicomMark, QuestionMarkInfo>();
              

            CreateMap<ReadingNoneDicomMarkBinding, QuestionMarkInfo>();

            CreateMap<QuestionMarkInfo, ReadingTaskQuestionMark>();
            //CreateMap<ReadingClinicalDataView, GetReadingClinicalDataListOutDto>();
            // CreateMap<ReadingClinicalData, GetReadingClinicalDataListOutDto>()
            //.ForMember(d => d.ClinicalDataLevel, u => u.MapFrom(s => s.ClinicalDataTrialSet.ClinicalDataLevel))
            //.ForMember(d => d.ClinicalDataLevelName, u => u.MapFrom(s => s.ClinicalDataTrialSet.ClinicalDataSetName))
            //.ForMember(d => d.ClinicalUploadType, u => u.MapFrom(s => s.ClinicalDataTrialSet.ClinicalUploadType));
            //.ForMember(d => d.FileCount, u => u.MapFrom(s => s.ReadingClinicalDataPDFList.Count()));

            CreateMap<ReadingClinicalDataPDF, GetReadingClinicalDataPDFListOutDto>();

            //.ForMember(d => d.SiteNames, u => u.MapFrom(s => s.ReadingPeriodSites.SelectMany(x => x.Site.SiteName).ToList()));

            CreateMap<ReadingClinicalData, AddOrUpdateReadingClinicalDataDto>().ReverseMap();
            CreateMap<ReadingConsistentClinicalData, AddOrUpdateReadingClinicalDataDto>().ReverseMap();

            CreateMap<ReadingClinicalDataPDF, AddOrUpdateReadingClinicalDataPDFDto>().ReverseMap();

            CreateMap<ClinicalDataTrialSet, ClinicalDataTrialSetAddOrEdit>().ReverseMap();

            CreateMap<ClinicalDataSystemSet, ClinicalDataSystemSetAddOrEdit>().ReverseMap();

            CreateMap<ClinicalDataTrialSet, ClinicalDataTrialSetView>()
                .ForMember(t => t.TrialCriterionNameList, u => u.MapFrom(c => c.TrialClinicalDataSetCriteriaList.Where(x =>
                CriterionIds.Contains(x.TrialReadingCriterionId)).Select(t => t.TrialReadingCriterion.CriterionName)))
                    .ForMember(t => t.TrialCriterionIdList, u => u.MapFrom(c => c.TrialClinicalDataSetCriteriaList.Select(t => t.TrialReadingCriterion.Id)))
                    .ForMember(d => d.IsUsed, u => u.MapFrom(s => s.ReadingClinicalDataList.Count() > 0))
                     ;

            CreateMap<ClinicalDataSystemSet, ClinicalDataSystemSetView>();
            //.ForMember(t=>t.SystemCriterionNameList,u=>u.MapFrom(c=>c.SystemClinicalDataCriterionList.Select(t=>t.SystemReadingCriterion.CriterionName)))
            //.ForMember(t => t.SystemCriterionIdList, u => u.MapFrom(c => c.SystemClinicalDataCriterionList.Select(t => t.SystemReadingCriterion.Id)));

            CreateMap<PreviousPDF, PreviousPDFAddOrEdit>().ReverseMap().ForMember(dest => dest.CreateUserRole, opt => opt.Ignore());

            CreateMap<PreviousPDF, PreviousPDFView>();

            CreateMap<ReadModuleAddOrEdit, ReadModule>().ForMember(dest => dest.CreateUserRole, opt => opt.Ignore());

            CreateMap<TumorAssessment_RECIST1Point1, TumorAssessmentView>();


            CreateMap<CopyTableAnswerRowInfo, ReadingTableAnswerRowInfo>().ForMember(dest => dest.CreateUserRole, opt => opt.Ignore());

            CreateMap<ReadingTableAnswerRowInfo, CopyTableAnswerRowInfo>()
                .ForMember(d => d.OriginalId, u => u.MapFrom(s => s.Id))
                  .ForMember(d => d.LesionType, u => u.MapFrom(s => s.ReadingQuestionTrial.LesionType));

            //.ForMember(dest => dest.Instance, opt => opt.Ignore())
            //.ForMember(dest => dest.ReadingQuestionTrial, opt => opt.Ignore());

            #region 阅片问题


            // 忽略列
            CreateMap<ReadingQuestionTrial, DicomReadingQuestionAnswer>()
                    .ForMember(d => d.QuestionName, u => u.MapFrom(s => isEn_Us ? s.QuestionEnName : s.QuestionName))
                     .ForMember(d => d.GroupName, u => u.MapFrom(s => isEn_Us ? s.GroupEnName : s.GroupName))
                 .ForMember(dest => dest.ReadingCriterionPage, opt => opt.Ignore())
                    .ForMember(dest => dest.CreateUserRole, opt => opt.Ignore())
                 .ForMember(dest => dest.ParentReadingQuestionTrial, opt => opt.Ignore())
                 .ForMember(dest => dest.RelevanceReadingQuestionTrial, opt => opt.Ignore())
                 .ForMember(dest => dest.ReadingQuestionCriterionTrial, opt => opt.Ignore());


            CreateMap<ReadingTableAnswerRowInfo, GetTableAnswerRowInfoOutDto>()
                    .ForMember(d => d.LesionType, u => u.MapFrom(s => s.ReadingQuestionTrial.LesionType))
                  .ForMember(d => d.ShowOrder, u => u.MapFrom(s => s.ReadingQuestionTrial.ShowOrder))
                     .ForMember(d => d.OrderMark, u => u.MapFrom(s => s.ReadingQuestionTrial.OrderMark))
                   .ForMember(d => d.RowIndex, u => u.MapFrom(s => s.RowIndex.ToString()))
                   .ForMember(d => d.RowIndexNum, u => u.MapFrom(s => s.RowIndex))
                   .ForMember(d => d.RowId, u => u.MapFrom(s => s.Id))
               ;



            CreateMap<ReadingTableQuestionTrial, TableQuestionTrial>()
                   .ForMember(dest => dest.CreateUserRole, opt => opt.Ignore())
                .ForMember(d => d.QuestionName, u => u.MapFrom(s => isEn_Us ? s.QuestionEnName : s.QuestionName));
            CreateMap<ReadingTableQuestionAnswer, ReadingTableQuestionAnswerInfo>()
                   .ForMember(dest => dest.CreateUserRole, opt => opt.Ignore())
                 .ForMember(d => d.ShowOrder, u => u.MapFrom(s => s.ReadingQuestionTrial.ShowOrder))
                   .ForMember(d => d.QuestionMark, u => u.MapFrom(s => s.ReadingTableQuestionTrial.QuestionMark));

            CreateMap<ReadingQuestionTrial, TrialReadQuestionData>()
                   .ForMember(dest => dest.CreateUserRole, opt => opt.Ignore())
                  .ForMember(d => d.QuestionName, u => u.MapFrom(s => isEn_Us ? s.QuestionEnName : s.QuestionName))
                 .ForMember(d => d.GroupName, u => u.MapFrom(s => isEn_Us ? s.GroupEnName : s.GroupName))
                .ForMember(d => d.PageShowOrder, u => u.MapFrom(s => s.ReadingCriterionPage.ShowOrder))
                .ForMember(d => d.PageName, u => u.MapFrom(s => s.ReadingCriterionPage.PageName))
                   .ForMember(d => d.CriterionType, u => u.MapFrom(s => s.ReadingQuestionCriterionTrial.CriterionType))
                   .ForMember(dest => dest.CreateUserRole, opt => opt.Ignore())
                .ForMember(d => d.IsPublicPage, u => u.MapFrom(s => s.ReadingCriterionPage.IsPublicPage));

            CreateMap<ReadingQuestionSystem, GetSystemReadingQuestionOutDto>()
               ;

            CreateMap<TableQuestionDataInfo, GetSystemReadingQuestionOutDto>();

            CreateMap<ReadingTableQuestionSystem, TableQuestionDataInfo>();
            CreateMap<ReadingTableQuestionTrial, TableQuestionDataInfo>()
                 .ForMember(d => d.QuestionName, u => u.MapFrom(s => isEn_Us ? s.QuestionEnName : s.QuestionName));

            CreateMap<ReadingTableQuestionSystem, ReadingTableQuestionSystemView>()
                   .ForMember(dest => dest.CreateUserRole, opt => opt.Ignore())
                    .ForMember(d => d.DependShowOrder, u => u.MapFrom(s => s.DependParentQuestion.ShowOrder));



            CreateMap<ReadingTableQuestionTrial, ReadingTableQuestionSystemView>()
               .ForMember(dest => dest.CreateUserRole, opt => opt.Ignore())
                .ForMember(d => d.DependShowOrder, u => u.MapFrom(s => s.DependParentQuestion.ShowOrder));

            CreateMap<ReadingQuestionTrial, GetCalculateQuestionsOutDto>();


            CreateMap<ReadingQuestionSystem, GetSystemCalculateQuestionsOutDto>();


            CreateMap<ReadingTableQuestionSystem, GetCalculateTableQuestionsOutDto>()
                    .ForMember(d => d.QuestionId, u => u.MapFrom(s => s.Id))
                .ForMember(d => d.QuestionName, u => u.MapFrom(s => isEn_Us ? s.QuestionEnName : s.QuestionName));

            CreateMap<ReadingTableQuestionTrial, GetCalculateTableQuestionsOutDto>()
                 .ForMember(d => d.QuestionId, u => u.MapFrom(s => s.Id))
             .ForMember(d => d.QuestionName, u => u.MapFrom(s => isEn_Us ? s.QuestionEnName : s.QuestionName));


            CreateMap<ReadingTableQuestionTrial, ReadingTableQuestionTrialView>()
                   .ForMember(dest => dest.CreateUserRole, opt => opt.Ignore())
                  .ForMember(d => d.DependShowOrder, u => u.MapFrom(s => s.DependParentQuestion.ShowOrder))
                   .ForMember(d => d.CreateUserRole, u => u.Ignore());
            CreateMap<ReadingTableQuestionSystemAddOrEdit, ReadingTableQuestionSystem>().ForMember(dest => dest.CreateUserRole, opt => opt.Ignore());

            CreateMap<ReadingTableQuestionTrialAddOrEdit, ReadingTableQuestionTrial>().ForMember(dest => dest.CreateUserRole, opt => opt.Ignore());


            CreateMap<ReadingCriterionPageAddOrEdit, ReadingCriterionPage>().ForMember(dest => dest.CreateUserRole, opt => opt.Ignore());

            CreateMap<ReadingQuestionTrial, ReadingQuestionSystem>()
                 .ForMember(d => d.CreateUserRole, u => u.Ignore());

            CreateMap<Dictionary, OrganDictionary>()
                ;

            CreateMap<ReadingQuestionSystem, ReadingQuestionSystemData>()
                   .ForMember(dest => dest.CreateUserRole, opt => opt.Ignore())
                  .ForMember(d => d.OriginalId, u => u.MapFrom(s => s.Id));

            CreateMap<ReadingTableQuestionSystem, ReadingTableQuestionSystemData>()
                   .ForMember(dest => dest.CreateUserRole, opt => opt.Ignore())
               .ForMember(d => d.OriginalId, u => u.MapFrom(s => s.Id));

            CreateMap<ReadingQuestionSystem, ReadingQuestionTrial>()
                .ForMember(d => d.CreateUserRole, u => u.Ignore())
                 .ForMember(d => d.ReadingTableQuestionTrialList, u => u.Ignore())
                .ForMember(d => d.ReadingQuestionSystemId, u => u.MapFrom(s => s.Id));

            CreateMap<ReadingTableAnswerRowInfo, TableAnsweRowInfo>()
                     .ForMember(d => d.FristAddTaskNum, u => u.MapFrom(s => s.FristAddTask.VisitTaskNum))
                   .ForMember(dest => dest.CreateUserRole, opt => opt.Ignore())
             .ForMember(d => d.MergeName, u => u.MapFrom(s => s.MergeRow == null ? string.Empty : s.MergeRow.ReadingQuestionTrial.OrderMark + s.MergeRow.RowIndex.GetLesionMark()))
             .ForMember(d => d.SplitName, u => u.MapFrom(s => s.SplitRow == null ? string.Empty : s.SplitRow.ReadingQuestionTrial.OrderMark + s.SplitRow.RowIndex.GetLesionMark()))
             .ForMember(d => d.LesionType, u => u.MapFrom(s => s.ReadingQuestionTrial == null ? null : s.ReadingQuestionTrial.LesionType));


            CreateMap<ReadingTableQuestionSystem, ReadingTrialTableQuestionData>()
                   .ForMember(dest => dest.CreateUserRole, opt => opt.Ignore())
             .ForMember(dest => dest.DependParentQuestion, opt => opt.Ignore())
         .ForMember(d => d.OriginalId, u => u.MapFrom(s => s.Id))
          .ForMember(d => d.SystemTableQuestionId, u => u.MapFrom(s => s.Id));

            CreateMap<ReadingTableQuestionTrial, ReadingTrialTableQuestionData>()
                   .ForMember(dest => dest.CreateUserRole, opt => opt.Ignore())
                .ForMember(d => d.OriginalId, u => u.MapFrom(s => s.Id));

            CreateMap<ReadingTrialTableQuestionData, ReadingTableQuestionTrial>()
                   .ForMember(dest => dest.CreateUserRole, opt => opt.Ignore())
                ;


            CreateMap<ReadingQuestionCriterionSystem, ReadingQuestionCriterionTrial>()
                   .ForMember(dest => dest.CreateUserRole, opt => opt.Ignore())
                 .ForMember(dest => dest.ReadingQuestionTrialList, opt => opt.Ignore())
                 .ForMember(dest => dest.CreateUserRole, opt => opt.Ignore())
                 .ForMember(d => d.ReadingQuestionCriterionSystemId, u => u.MapFrom(s => s.Id));


            CreateMap<AddOrUpdateReadingQuestionCriterionSystemInDto, ReadingQuestionCriterionSystem>()
                   .ForMember(dest => dest.CreateUserRole, opt => opt.Ignore());
            CreateMap<ReadingQuestionCriterionSystem, ReadingQuestionCriterionSystemView>()

                  .ForMember(d => d.QuestionCount, u => u.MapFrom(s => s.ReadingQuestionSystemList.Count()));
            //.ForMember(d => d.IsEnable, u => u.MapFrom(s => s.Dictionary.IsEnable))
            //.ForMember(d => d.ShowOrder, u => u.MapFrom(s => s.Dictionary.ShowOrder)); 

            CreateMap<ReadingQuestionSystem, AddOrUpdateReadingQuestionSystemInDto>();

            CreateMap<AddOrUpdateReadingQuestionSystemInDto, ReadingQuestionSystem>()
                   .ForMember(dest => dest.CreateUserRole, opt => opt.Ignore());
            CreateMap<ReadingQuestionSystem, ReadingQuestionSystemView>()

               .ForMember(d => d.GroupName, u => u.MapFrom(s => s.GroupInfo == null ? s.GroupName : s.GroupInfo.GroupName))
              .ForMember(d => d.ParentQuestionName, u => u.MapFrom(s => s.ParentReadingQuestionSystem == null ? string.Empty : s.ParentReadingQuestionSystem.QuestionName))
              .ForMember(d => d.ParentQuestionShowOrder, u => u.MapFrom(s => s.ParentReadingQuestionSystem.ShowOrder))
              .ForMember(d => d.ParentDictionaryCode, u => u.MapFrom(s => s.ParentReadingQuestionSystem.DictionaryCode))
              .ForMember(d => d.ParentQuestionGenre, u => u.MapFrom(s => s.ParentReadingQuestionSystem.QuestionGenre))
              .ForMember(d => d.RelevanceShowOrder, u => u.MapFrom(s => s.RelevanceReadingQuestionSystem.ShowOrder))
              .ForMember(d => d.RelevanceDictionaryCode, u => u.MapFrom(s => s.RelevanceReadingQuestionSystem.DictionaryCode))
              .ForMember(d => d.RelevanceQuestionGenre, u => u.MapFrom(s => s.RelevanceReadingQuestionSystem.QuestionGenre));


            CreateMap<AddOrUpdateReadingQuestionCriterionTrialInDto, ReadingQuestionCriterionTrial>()
                   .ForMember(dest => dest.CreateUserRole, opt => opt.Ignore());
            CreateMap<ReadingQuestionCriterionTrial, ReadingQuestionCriterionTrialView>()

                 .ForMember(d => d.QuestionCount, u => u.MapFrom(s => s.ReadingQuestionTrialList.Count()));


            CreateMap<AddOrUpdateReadingQuestionTrialInDto, ReadingQuestionTrial>()
                   .ForMember(dest => dest.CreateUserRole, opt => opt.Ignore());
            CreateMap<ReadingQuestionTrial, ReadingQuestionTrialView>()
                  .ForMember(d => d.QuestionGroupName, u => u.MapFrom(s => s.GroupInfo == null ? s.GroupName : s.GroupInfo.GroupName))
                     .ForMember(d => d.QuestionGroupEnName, u => u.MapFrom(s => s.GroupInfo == null ? s.GroupEnName : s.GroupInfo.GroupEnName))
                 .ForMember(d => d.GroupName, u => u.MapFrom(s => s.GroupInfo == null ? s.GroupName : s.GroupInfo.GroupName))
                    .ForMember(d => d.GroupEnName, u => u.MapFrom(s => s.GroupInfo == null ? s.GroupEnName : s.GroupInfo.GroupEnName))
                .ForMember(d => d.ParentQuestionName, u => u.MapFrom(s => s.ParentReadingQuestionTrial == null ? string.Empty : s.ParentReadingQuestionTrial.QuestionName))
            .ForMember(d => d.ParentQuestionShowOrder, u => u.MapFrom(s => s.ParentReadingQuestionTrial.ShowOrder))
             .ForMember(d => d.ParentQuestionGenre, u => u.MapFrom(s => s.ParentReadingQuestionTrial.QuestionGenre))
             .ForMember(d => d.ParentDictionaryCode, u => u.MapFrom(s => s.ParentReadingQuestionTrial.DictionaryCode))
              .ForMember(d => d.RelevanceShowOrder, u => u.MapFrom(s => s.RelevanceReadingQuestionTrial.ShowOrder))
              .ForMember(d => d.RelevanceDictionaryCode, u => u.MapFrom(s => s.RelevanceReadingQuestionTrial.DictionaryCode))
              .ForMember(d => d.RelevanceQuestionGenre, u => u.MapFrom(s => s.RelevanceReadingQuestionTrial.QuestionGenre)); ;
            #endregion

            #region IR阅片
            CreateMap<ReadingQuestionTrial, GetTrialReadingQuestionOutDto>()

                  .ForMember(d => d.QuestionName, u => u.MapFrom(s => isEn_Us ? s.QuestionEnName : s.QuestionName))
                .ForMember(x => x.Id, y => y.MapFrom(z => z.Id));

            CreateMap<TableQuestionTrial, GetTrialReadingQuestionOutDto>();
              

            //CreateMap<VisitTask, GetReadingPastResultListOutDto>()
            //      .ForMember(x => x.VisitTaskId, y => y.MapFrom(z => z.Id))
            //     .ForMember(x => x.JudgeResultArm, y => y.MapFrom(z => (z.JudgeResultTask==null?null:z.JudgeResultTask.ArmEnum)));
            #endregion

            #region 医学审核
            CreateMap<ReadingMedicineSystemQuestionAddOrEdit, ReadingMedicineSystemQuestion>()
                   .ForMember(dest => dest.CreateUserRole, opt => opt.Ignore());
            CreateMap<ReadingMedicineSystemQuestion, ReadingMedicineSystemQuestionView>()

                .ForMember(x => x.ParentShowOrder, y => y.MapFrom(n => n.ParentQuestion.ShowOrder));


            CreateMap<TrialDataFromSystem, ReadingMedicineTrialQuestion>()
                   .ForMember(dest => dest.CreateUserRole, opt => opt.Ignore());

            CreateMap<ReadingMedicineTrialQuestionAddOrEdit, ReadingMedicineTrialQuestion>()
                   .ForMember(dest => dest.CreateUserRole, opt => opt.Ignore());
            CreateMap<ReadingMedicineTrialQuestion, ReadingMedicineTrialQuestionView>()

                .ForMember(x => x.ParentShowOrder, y => y.MapFrom(n => n.ParentQuestion.ShowOrder));

            CreateMap<ReadingMedicineTrialQuestion, GetMedicineQuestionPreviewOutDto>();


            CreateMap<TaskMedicalReview, MedicalReviewInfo>()
                .ForMember(x => x.TaskMedicalReviewId, y => y.MapFrom(n => n.Id));

            CreateMap<ReadingMedicalReviewDialog, GetMedicalReviewDialogOutDto>()
                 //.ForMember(x => x.FileList, y => y.MapFrom(n => n.FileList))
                 .ForMember(x => x.CreateUserName, y => y.MapFrom(n => n.CreateUserRole.IdentityUser.UserName));

            #endregion

            #region 阅片部位

            CreateMap<CriterionNidusTrial, CriterionNidusView>();
            CreateMap<CriterionNidusSystem, CriterionNidusView>();
            CreateMap<CriterionNidusSystem, CriterionNidusAddOrEdit>().ReverseMap()
                   .ForMember(dest => dest.CreateUserRole, opt => opt.Ignore());

            CreateMap<OrganInfoAddOrEdit, OrganInfo>()
                   .ForMember(dest => dest.CreateUserRole, opt => opt.Ignore());
            CreateMap<OrganInfo, OrganInfoView>();
            #endregion

            #region 附加评估
            //CreateMap<SubjectCriteriaEvaluation, SubjectCriteriaEvaluationView>()
            //     .ForMember(d => d.TrialSiteCode, u => u.MapFrom(s => s.subject.TrialSite.TrialSiteCode))
            //    .ForMember(d => d.SubjectCode, u => u.MapFrom(s => s.subject.Code))
            //    .ForMember(d => d.SubjectStatus, u => u.MapFrom(s => s.subject.Status));


            CreateMap<SubjectCriteriaEvaluationAddOrEdit, SubjectCriteriaEvaluation>().ReverseMap();
            CreateMap<SubjectCriteriaEvaluation, SubjectCriteriaEvaluationView>().ReverseMap()
                   .ForMember(dest => dest.CreateUserRole, opt => opt.Ignore());
            CreateMap<SubjectCriteriaEvaluationVisitFilter, SubjectCriteriaEvaluationVisitFilterAddOrEdit>().ReverseMap()
                   .ForMember(dest => dest.CreateUserRole, opt => opt.Ignore());

            CreateMap<SubjectCriteriaEvaluationVisitStudyFilterAddOrEdit, SubjectCriteriaEvaluationVisitStudyFilter>().ReverseMap();

            CreateMap<DicomStudy, SelectStudyView>()
                 .ForMember(o => o.UploadedTime, t => t.MapFrom(u => u.CreateTime))
                .ForMember(o => o.Uploader, t => t.MapFrom(u => u.CreateUserRole.IdentityUser.FullName))
                .ForMember(o => o.StudyId, t => t.MapFrom(u => u.Id));

            CreateMap<VisitTask, HaveGeneratedTaskDto>()
                .ForMember(o => o.VisitName, t => t.MapFrom(u => u.SourceSubjectVisit.VisitName));

            #endregion
        }
    }

}
