using IRaCIS.Core.API._ServiceExtensions.NewtonsoftJson;
using IRaCIS.Core.Application.Contracts.DTO;
using IRaCIS.Core.Application.Helper;
using IRaCIS.Core.Application.Service.Reading.Dto;
using IRaCIS.Core.Domain.Share;
using MiniExcelLibs.Attributes;
using Newtonsoft.Json;
using Org.BouncyCastle.Asn1.X509;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;

namespace IRaCIS.Core.Application.Contracts
{

    public class ImageBackQueryDto : PageInput
    {
        [NotDefault]
        public Guid TrialId { get; set; }

        public Guid? TrialSiteId { get; set; }

        public string? SubjectCode { get; set; } = string.Empty;

        public Guid? CreateUserId { get; set; }

        public string? VisitName { get; set; }

        public ImageBackApplyEnum? ApplyUserRole { get; set; }

        public DateTime? ApplyBeginTime { get; set; }

        public DateTime? ApplyEndTime { get; set; }

        public ImageBackStateEnum? ImageBackState { get; set; }


        public DateTime? AuditBeginTime { get; set; }

        public DateTime? AuditEndTime { get; set; }

        public string[]? VisitPlanArray { get; set; }

    }

    public class CRCVisitSearchDTO : PageInput
    {

        public AuditStateEnum[]? AuditStateArray { get; set; }
        public SubmitStateEnum? SubmitState { get; set; }
        public ChallengeStateEnum? ChallengeState { get; set; }

        [NotDefault]
        public Guid TrialId { get; set; }
        public Guid? TrialSiteId { get; set; }
        public Guid? SubjectId { get; set; }

        public bool? IsUrgent { get; set; }
        public string SubjectInfo { get; set; } = string.Empty;
        //public string VisitPlanInfo { get; set; } = string.Empty;

        public string[]? VisitPlanArray { get; set; }
        public bool? IsSubjectQuit { get; set; }

        public SubjectStatus? SubjectStatus { get; set; } 
    }

    public class GetNextQCInfoInDto
    {
        public Guid TrialId { get; set; }

        public Guid? VisitId { get; set; }
    }

    public class QCVisitSearchDTO : PageInput
    {

        //public AuditStateEnum? AuditState { get; set; }

        public Guid? CurrentActionUserId { get; set; }

        public AuditStateEnum[]? AuditStateArray { get; set; }

        public ChallengeStateEnum? ChallengeState { get; set; }

        public bool? IsUrgent { get; set; }
        public Guid TrialId { get; set; }
        public Guid? TrialSiteId { get; set; }

        public Guid? VisitId { get; set; }
        public Guid? SubjectId { get; set; }

        public string SubjectInfo { get; set; } = String.Empty;

        public string[]? VisitPlanArray { get; set; }
        //public string VisitPlanInfo { get; set; } = String.Empty;

        public Guid? HandleUserId { get; set; }

        public DateTime? BeginAuditTime { get; set; }

        public DateTime? EndAuditTime { get; set; }

        public SubjectStatus? SubjectStatus { get; set; }

        public bool? IsSubjectQuit { get; set; }
    }

    public class GetNextIQCQualityInDto
    {
        [NotDefault]
        public Guid TrialId { get; set; }
        [NotDefault]
        public Guid SubjectId { get; set; }
        [NotDefault]
        public Guid SubjectVisitId { get; set; }


        public bool IsSkipCurrentVisit { get; set; }
    }

    public class GetNextIQCQualityOutDto
    {
        public Guid? SubjectId { get; set; }

        public Guid? VisitId { get; set; }

        /// <summary>
        /// 是否领取了
        /// </summary>
        public bool IsReceived { get; set; } = false;
    }

    public class CRCRequestToQCCommand
    {
        [NotDefault]
        public Guid TrialId { get; set; }


        public Guid[] SubjectVisitIds { get; set; } = new Guid[0];
    }



    public class CRCReuploadFinishedCommand
    {
        [NotDefault]
        public Guid TrialId { get; set; }

        [NotDefault]
        public Guid QCChallengeId { get; set; }

        public bool SetOrCancel { get; set; }

    }

    public class UploadSubjectAndVisitCommand
    {
        public Guid SubjectVisitId { get; set; }
        public Guid SubjectId { get; set; }
        public PDStateEnum PDState { get; set; }

        //前端有可能不传递  不是基线的时候
        public bool? IsEnrollmentConfirm { get; set; }
        public DateTime? SubjectFirstGiveMedicineTime { get; set; }

    }

    public class TrialSubjectAndSVConfig
    {
        public bool IsHaveFirstGiveMedicineDate { get; set; }
        public bool IsSubjectSexView { get; set; } = false;
        public bool IsSubjectExpeditedView { get; set; } = false;

        public bool IsEnrollementQualificationConfirm { get; set; }
        public bool IsPDProgressView { get; set; }

        public bool IsHaveStudyClinicalData { get; set; }



        public string OutEnrollmentVisitName { get; set; } = String.Empty;

        public string BodyPartTypes { get; set; } = String.Empty;

        public string Modalitys { get; set; } = String.Empty;
        public string DocumentConfirmSignText { get; set; } = String.Empty;

        public string ImageQCSignText { get; set; } = String.Empty;

        public string PreliminaryAuditReuploadText { get; set; } = string.Empty;

        public string ReviewAuditReuploadText { get; set; } = string.Empty;

        public string CheckBackText { get; set; } = String.Empty;

        public string CheckPassText { get; set; } = String.Empty;

        public int ClinicalInformationTransmissionEnum { get; set; }

        public TrialQCProcess QCProcessEnum { get; set; }

        public bool IsHaveSubjectClinicalData { get; set; } = false;

        public bool IsHaveVisitClinicalData { get; set; } = false;

        public bool IsPacsConnectConfiged { get; set; }

        [Comment("阅片任务产生之前 采集影像")]
        public CollectImagesType CollectImagesEnum { get; set; }

        public List<StudyName> StudyNameList { get; set; }


        public List<string> ImageFormatList { get; set; }

        public bool IsShowStudyName { get; set; } = false;

        public bool IsQCQuestionConfirmed { get; set; }

    }


    #region 导出模型


    public class TrainingRecordExportDTO
    {
        public Guid Id { get; set; }

        public Guid FileTypeId { get; set; }

        public Guid UserTypeId { get; set; }

        public string FileType { get; set; }

        public string Name { get; set; }

        [DictionaryTranslateAttribute("IsSystemDoc")]
        public bool IsSystemDoc { get; set; }

        [DictionaryTranslateAttribute("TrainingStatus")]
        public bool IsDeleted { get; set; }

        //上传时间
        public DateTime CreateTime { get; set; }

        [DictionaryTranslateAttribute("TrainingStatusEnum")]
        public bool IsConfirmed => ConfirmTime != null;

        public string RealName { get; set; }

        public string UserName { get; set; }

        public Guid ConfirmUserId { get; set; }

        public DateTime? ConfirmTime { get; set; }


        public string UserTypes => string.Join(',', UserConfirmedUserTypeList);

        public List<string> UserConfirmedUserTypeList => (DocNeedSignUserTypeList != null && IdentityUserTypeList != null) ? IdentityUserTypeList.Intersect(DocNeedSignUserTypeList).ToList() : new List<string>();


        public IEnumerable<string> IdentityUserTypeList { get; set; }
        public IEnumerable<string> DocNeedSignUserTypeList { get; set; }
    }

    public class CRCVisitExportDTO
    {
        //关闭 未关闭
        [DictionaryTranslateAttribute("CheckIsClosedEnum")]
        public ChallengeStateEnum ChallengeState { get; set; }

        //强行要分为两个字段  有无质疑
        [DictionaryTranslateAttribute("YesOrNo")]
        public bool IsHaveChallenge => (int)ChallengeState > 0;

        //临床数据收集

        public string ClinicalDataCollect => $"{DicomStudyCount},{NoneDicomStudyCount}{(IsHaveClinicalData ? ",w/" : ",w/o")}";

        public int? DicomStudyCount { get; set; }
        public int? NoneDicomStudyCount { get; set; }

        public int ClinicalInformationTransmissionEnum { get; set; }

        public bool IsBaseLine { get; set; }

        [DictionaryTranslateAttribute("YesOrNo")]
        public bool IsUrgent { get; set; }
        public string BlindName { get; set; } = String.Empty;
        public string VisitName { get; set; } = string.Empty;

        public string SubjectCode { get; set; } = String.Empty;

        [DictionaryTranslateAttribute("Subject_Visit_Status")]
        public SubjectStatus SubjectStatus { get; set; }

        public String TrialSiteCode { get; set; } = String.Empty;

        public DateTime? EarliestScanDate { get; set; }
        public DateTime? LatestScanDate { get; set; }

        public string EarliestScanDateStr => EarliestScanDate?.ToString("yyyy-MM-dd") ?? string.Empty;
        public string LatestScanDateStr => LatestScanDate?.ToString("yyyy-MM-dd") ?? string.Empty;

        public DateTime? SubmitTime { get; set; }


        [DictionaryTranslateAttribute("SubmitState")]
        public SubmitStateEnum SubmitState { get; set; }

        [DictionaryTranslateAttribute("AuditStateRC")]
        public AuditStateEnum AuditState { get; set; }

        [DictionaryTranslateAttribute("YesOrNo")]
        public bool IsHaveClinicalData { get; set; }

        public string SubmitUserName { get; set; }


        public TrialQCProcess QCProcessEnum { get; set; }

        public DateTime? ReviewAuditTime { get; set; }
        public DateTime? PreliminaryAuditTime { get; set; }

        //审核通过时间
        public DateTime? AuditTime => QCProcessEnum == TrialQCProcess.SingleAudit ? PreliminaryAuditTime : (QCProcessEnum == TrialQCProcess.DoubleAudit ? ReviewAuditTime : null);


    }


    public class QCVisitExportDTO : CRCVisitExportDTO
    {
        //上传人
        public string SubmitUserRealName { get; set; }

        public string PreliminaryAuditUserName { get; set; }

        public string ReviewAuditUserName { get; set; }

        public string CurrentActionUserName { get; set; }

        public string HistoryAuditUserName => string.Join(' ', PreliminaryAuditUserName, ReviewAuditUserName);
    }

    public class QCChanllengeExportDto
    {
        //审核批次
        [DictionaryTranslateAttribute("CurrentQCType")]
        public CurrentQC? CurrentQCEnum { get; set; }


        [DictionaryTranslateAttribute("Subject_Visit_Status")]
        public SubjectStatus SubjectState { get; set; }

        public string ChallengeCode { get; set; } = String.Empty;
        public String TrialSiteCode { get; set; } = String.Empty;
        public string SubjectCode { get; set; } = String.Empty;
        public string VisitName { get; set; } = string.Empty;
        public DateTime? CreateTime { get; set; }
        public string CreateUserName { get; set; } = String.Empty;
        public DateTime? LatestMsgTime { get; set; }

        public string LatestReplyUserFullName { get; set; } = String.Empty;

        public string LatestReplyUserName { get; set; } = String.Empty;

        public string Content { get; set; } = string.Empty;
        public string ContentReplaced
        {

            get
            {

                var msg = Content.Replace("<div style='margin-left:20px'>", "").Replace("</div>", "");

                string[] substrings = msg.Split(new string[] { "<br>", "<br/>" }, StringSplitOptions.None);

                return string.Join("\n\n", substrings);
            }

        }

        [DictionaryTranslateAttribute("ChallengeIsClosed")]
        public bool IsClosed { get; set; }

        public DateTime? ClosedTime { get; set; }

        public DateTime? DeadlineTime { get; set; }

        [DictionaryTranslateAttribute("YesOrNo")]
        public bool IsOverTime => IsClosed ? ClosedTime > DeadlineTime : DateTime.Now > DeadlineTime;

        public string ChallengeDuration
        {
            get
            {
                if (!ClosedTime.HasValue)
                {
                    var now = DateTime.Now;
                    return string.Format("{0}d {1}h {2}m", (now - CreateTime)?.Days, (now - CreateTime)?.Hours, (now - CreateTime)?.Minutes);

                }
                else return string.Format("{0}d {1}h {2}m", (ClosedTime - CreateTime)?.Days, (ClosedTime - CreateTime)?.Hours, (ClosedTime - CreateTime)?.Minutes);
            }
        }


        [DictionaryTranslateAttribute("ReuploadEnum")]
        public QCChanllengeReuploadEnum ReuploadEnum { get; set; }
        public List<DialogInfo> DialogList { get; set; }

        public string DialogStr => string.Join("\n\n", DialogList.OrderBy(t => t.CreateTime).Select(c => c.UserName + " (" + ExportExcelConverterDate.DateTimeInternationalToString(c.CreateTime) + ") :" + c.Content));

        //public SubmitStateEnum SubmitState { get; set; }
        //public string? CurrentActionUserName { get; set; }

        //public bool IsUrgent { get; set; }

        public DateTime? ReUploadedTime { get; set; }

        //public RequestBackStateEnum RequestBackState { get; set; }

        //public string PreliminaryAuditUserName { get; set; } = String.Empty;
        //public AuditStateEnum AuditState { get; set; }
        //public CurrentQC CurrentQCEnum { get; set; }
        //public string ChallengeType { get; set; } = string.Empty;
        //public string Note { get; set; } = string.Empty;



    }

    public class DialogInfo
    {
        public DateTime CreateTime { get; set; }

        public string UserName { get; set; }

        public string Content { get; set; }

        public string ContentReplaced => Content.Replace("<br>", "").Replace("<br/>", "").Replace("<div style='text-indent: 20px;'>", "")
            .Replace("<div>", "").Replace("</div>", "").Replace("<div/>", "").Replace("<div>", "");
    }



    public class SubjectExportDTO
    {

        public string Code { get; set; } = String.Empty;

        //public int? Age { get; set; }
        //public string Sex { get; set; } = string.Empty;
        //public Guid TrialSiteId { get; set; }
        //public Guid TrialId { get; set; }
        //public string MedicalNo { get; set; } = string.Empty;
        //public string ShortName { get; set; } = string.Empty;
        //public string Height { get; set; } = string.Empty;
        //public string Weight { get; set; } = string.Empty;
        //public DateTime? BirthDate { get; set; }
        //public DateTime? SignDate { get; set; }
        //public bool IsUrgent { get; set; }

        //[ExcelColumn(Name = "FirstGiveMedicineTime", Format = "yyyy-MM-dd")]
        public DateOnly? FirstGiveMedicineTime { get; set; }


        public string FirstGiveMedicineTimeStr => FirstGiveMedicineTime?.ToString("yyyy-MM-dd");

        public DateTime? OutEnrollmentTime { get; set; }
        public DateTime? VisitOverTime { get; set; }

        [DictionaryTranslateAttribute("Subject_Visit_Status")]

        public SubjectStatus Status { get; set; }


        public int? TotalVisitCount => OutPlanVisitCount + InPlanVisitCount;
        public int? TotalVisitSubmmitCount => OutPlanVisitSubmmitCount + InPlanVisitSubmmitCount;

        public int? OutPlanVisitCount { get; set; }
        public int? OutPlanVisitSubmmitCount { get; set; }

        public int? InPlanVisitCount { get; set; }
        public int? InPlanVisitSubmmitCount { get; set; }

        public string? FinalSubjectVisitName { get; set; }


        public int? MissingSubmmitCount { get; set; }

        public int? LostVisitCount { get; set; }


        public string SiteName { get; set; } = string.Empty;
        public string TrialSiteCode { get; set; } = string.Empty;

        public string LatestVisitName { get; set; } = string.Empty;

        public string LatestBlindName { get; set; } = string.Empty;


        [DictionaryTranslateAttribute("YesOrNo")]
        public bool IsMissingImages => MissingSubmmitCount > 0;

        [DictionaryTranslateAttribute("YesOrNo")]
        public bool IsEnrollmentConfirmed { get; set; }
        [DictionaryTranslateAttribute("YesOrNo")]
        public bool IsPDProgress { get; set; }


        public int? RadiologyClinicalDataCount { get; set; }
        [DictionaryTranslateAttribute("YesOrNo")]
        public bool IsHaveRadiologyClinicalData => RadiologyClinicalDataCount != null && RadiologyClinicalDataCount > 0;

        public int? OncologyClinicalDataCount { get; set; }
        [DictionaryTranslateAttribute("YesOrNo")]
        public bool IsHaveOncologyClinicalData => OncologyClinicalDataCount != null && OncologyClinicalDataCount > 0;


        public int? ChallengeWaitReplyCount { get; set; }


        public int? CheckWaitReplyCount { get; set; }

        public string SuspendReason { get; set; }

        public string Reason { get; set; }

        public string ExportReason => Status == SubjectStatus.OutOfVisit ? Reason : (Status == SubjectStatus.EndOfVisit ? SuspendReason : "");
    }


    public class SubjectReadingPeriodExportDto
    {
        [DictionaryTranslateAttribute("Subject_Visit_Status")]

        public SubjectStatus Status { get; set; }

        public string Code { get; set; } = String.Empty;

        public string TrialSiteCode { get; set; } = string.Empty;


        public CriterionType CriterionType { get; set; }

        public ReadingMethod ReadingType { get; set; }


    }

    public class ReadingPeriodOrVisitInfo
    {


        public Guid SubjectVisitId { get; set; }

        //核查状态
        public CheckStateEnum CheckState { get; set; }

        //提交状态
        public SubmitStateEnum SubmitState { get; set; }
        //审核状态
        public AuditStateEnum AuditState { get; set; }

        //阅片期或者访视名
        public string ReadingPeriodName { get; set; }




        //public ForwardStateEnum ForwardState { get; set; }
    }

    public class ReadPeriodQuery
    {
        public Guid TrialId { get; set; }
    }

    public class SubjectProgressQuery
    {
        [NotDefault]
        public Guid TrialId { get; set; }

        [NotDefault]
        public Guid TrialReadingCriterionId { get; set; }
    }

    public class SubjectProgressDto
    {
        public string SubjectCode { get; set; }

        public string TrialSiteCode { get; set; }

        [DictionaryTranslateAttribute("Subject_Visit_Status")]
        public SubjectStatus SubjectStatus { get; set; }


        public List<MouduleProgress> VisitList { get; set; }

        public List<MouduleProgress> ModuleList { get; set; }


        public List<MouduleProgress> TotalList => VisitList.OrderByDescending(t => t.Inplan).Union(ModuleList.OrderBy(t => t.ReadingSetType).ThenBy(t => t.VisitTaskNum)).ToList();


        public class MouduleProgress
        {
            public string TaskName { get; set; }

            public ReadingStatusEnum ReadingStatus { get; set; }

            //最终任务
            public decimal VisitTaskNum { get; set; }

            //访视会有
            public bool? Inplan { get; set; }

            public bool? IsLostVisit { get; set; }

            public bool? IsFinalVisit { get; set; }

            //阅片期会有
            public ReadingSetType? ReadingSetType { get; set; }
        }

    }

    public class ReadPeriodExportDto
    {
        public string SubjectCode { get; set; }

        public string TrialSiteCode { get; set; }

        [DictionaryTranslateAttribute("Subject_Visit_Status")]
        public SubjectStatus SubjectStatus { get; set; }
        public string TrialReadingCriterionName { get; set; }

        [ExcelFormat("yyyy-MM-dd")]
        public DateTime? FirstGiveMedicineTime { get; set; }

        public string FirstGiveMedicineTimeStr => FirstGiveMedicineTime?.ToString("yyyy-MM-dd");

        public string ModuleName { get; set; }


        public string DeadlineVisitName { get; set; }


        public DateTime? EarliestScanDate { get; set; }
        public DateTime? LatestScanDate { get; set; }





    }


    public class UnionStudyMonitorExportDto
    {
        public string SubjectCode { get; set; } = String.Empty;

        public string VisitName { get; set; } = string.Empty;


        public string TrialSiteCode { get; set; } = string.Empty;

        public string TrialSiteAliasName { get; set; } = string.Empty;

        public string Uploader { get; set; } = string.Empty;

        public DateTime UploadTime { get; set; }

        public string StudyCode { get; set; }


        public bool IsDicom { get; set; }

        public string IsDicomStr => IsDicom ? "DICOM" : "Non-DICOM";

        public string UploadStartTimeStr => UploadStartTime.ToString("yyyy-MM-dd HH:mm:ss.fff");
        public string UploadFinishedTimeStr => UploadFinishedTime?.ToString("yyyy-MM-dd HH:mm:ss.fff");

        public string ArchiveFinishedTimeStr => ArchiveFinishedTime?.ToString("yyyy-MM-dd HH:mm:ss.fff");


        public string UploadIntervalStr
        {
            get
            {
                var uploadTimeSpan = UploadFinishedTime - UploadStartTime;

                return $" {uploadTimeSpan?.Hours}:{uploadTimeSpan?.Minutes}:{uploadTimeSpan?.Seconds}.{uploadTimeSpan?.Milliseconds}";
            }
        }

        public string ArchiveIntervalStr
        {
            get
            {
                var uploadTimeSpan = ArchiveFinishedTime - UploadFinishedTime;

                return $" {uploadTimeSpan?.Hours}:{uploadTimeSpan?.Minutes}:{uploadTimeSpan?.Seconds}.{uploadTimeSpan?.Milliseconds}";
            }
        }



        public string TimeInterval
        {
            get
            {

                var uploadTimeSpan = ArchiveFinishedTime - UploadStartTime;

                return $" {uploadTimeSpan?.Hours}:{uploadTimeSpan?.Minutes}:{uploadTimeSpan?.Seconds}.{uploadTimeSpan?.Milliseconds}";

            }
        }

        public DateTime UploadStartTime { get; set; }

        public DateTime? ArchiveFinishedTime { get; set; }
        public DateTime? UploadFinishedTime { get; set; }


        public decimal FileSize { get; set; }

        public string FileSizeStr => $"{(FileSize / (decimal)Math.Pow(1024, 2)).ToString("F")}M";

        public string IP { get; set; } = String.Empty;

        [DictionaryTranslateAttribute("YesOrNo")]
        public bool IsDicomReUpload { get; set; }


        public int FileCount { get; set; }

        [DictionaryTranslateAttribute("YesOrNo")]
        public bool IsSuccess { get; set; }

        public string Note { get; set; } = string.Empty;

    }

    public class UnionStudyExportDTO
    {
        [DictionaryTranslateAttribute("Subject_Visit_Status")]
        public SubjectStatus SubjectStatus { get; set; }

        public string Modality { get; set; } = string.Empty;

        [ExcelFormat("yyyy-MM-dd")]
        public DateTime? StudyTime { get; set; }

        public string StudyTimeStr => StudyTime?.ToString("yyyy-MM-dd");

        public string SubjectCode { get; set; } = String.Empty;

        public string VisitName { get; set; } = string.Empty;

        public decimal VisitNum { get; set; }

        public string TrialSiteCode { get; set; } = string.Empty;

        public string TrialSiteAliasName { get; set; } = string.Empty;


        public string StudyCode { get; set; }

        [DictionaryTranslateAttribute("YesOrNo")]
        public bool IsDicom { get; set; }


        [DictionaryTranslateAttribute("CheckState")]
        public CheckStateEnum CheckState { get; set; }
    }


    public class PMKCheckEXportDTO
    {
        public string? TalkContent { get; set; } = String.Empty;
        public string BlindName { get; set; } = String.Empty;

        [DictionaryTranslateAttribute("YesOrNo")]
        public bool IsUrgent { get; set; }

        public DateTime? CheckPassedTime { get; set; }

        [DictionaryTranslateAttribute("AuditStateRC")]
        public AuditStateEnum AuditState { get; set; }


        [DictionaryTranslateAttribute("CheckState")]
        public CheckStateEnum CheckState { get; set; }
        public String TrialSiteCode { get; set; } = String.Empty;
        public string SubjectCode { get; set; } = String.Empty;

        [DictionaryTranslateAttribute("Subject_Visit_Status")]
        public SubjectStatus SubjectStatus { get; set; }

        public decimal VisitNum { get; set; }
        public string VisitName { get; set; } = string.Empty;

        public Guid SubjectId { get; set; }
        public Guid TrialSiteId { get; set; }

        [DictionaryTranslateAttribute("RequestBackState")]
        public RequestBackStateEnum RequestBackState { get; set; }

        public DateTime? CheckTime { get; set; }


        [DictionaryTranslateAttribute("CheckChallengeState")]
        public CheckChanllengeTypeEnum CheckChallengeState { get; set; }

        [DictionaryTranslateAttribute("YesOrNo")]
        public bool? IsCheckBack { get; set; }

        public string CheckResult { get; set; } = String.Empty;

        //public string CheckResultReplaced => CheckResult.Replace("<br>", "").Replace("<div style='text-indent: 20px;'>", "").Replace("</div>", "");

        public List<DialogInfo> CheckDialogList { get; set; }
        public string CheckDialogStr => string.Join("\n\n", CheckDialogList.OrderBy(t => t.CreateTime).Select(c => c.UserName + " (" + ExportExcelConverterDate.DateTimeInternationalToString(c.CreateTime) + ") :" + c.ContentReplaced));

        public DateTime? CheckBackTime { get; set; }

        public DateTime? EarliestScanDate { get; set; }

        public DateTime? LatestScanDate { get; set; }

        public string LatestScanDateStr => LatestScanDate?.ToString("yyyy-MM-dd") ?? string.Empty;

        public List<string> ModalityList { get; set; }

        public string Modalitys => string.Join(',', ModalityList);
    }


    public class ReadingTaskExportDto
    {

        [DictionaryTranslateAttribute("Subject_Visit_Status")]
        public SubjectStatus SubjectStatus { get; set; }


        public DateTime? AllocateTime { get; set; }


        public string TaskCode { get; set; }

        public string TaskName { get; set; }
        public string TaskBlindName { get; set; }

        public string FinalTaskName => TaskName != TaskBlindName ? $"{TaskName}/{TaskBlindName}" : TaskName;

        public decimal VisitTaskNum { get; set; }

        [DictionaryTranslateAttribute("ReadingCategory")]
        public ReadingCategory ReadingCategory { get; set; }


        [DictionaryTranslateAttribute("TaskState")]
        public TaskState TaskState { get; set; }

        public DateTime? SignTime { get; set; }

        public DateTime? CreateTime { get; set; }

        [DictionaryTranslateAttribute("YesOrNo")]
        public bool IsUrgent { get; set; }

        [DictionaryTranslateAttribute("ArmEnum")]
        public Arm ArmEnum { get; set; }

        public String TrialSiteCode { get; set; } = String.Empty;
        public string SubjectCode { get; set; } = String.Empty;
        public string MedicalNo { get; set; }
        public string FinalSubjectCode { get; set; }

        public string TrialReadingCriterionName { get; set; }

        [DictionaryTranslateAttribute("ReadingTaskState")]
        public ReadingTaskState ReadingTaskState { get; set; }

        [DictionaryTranslateAttribute("ReReadingApplyState")]
        public ReReadingApplyState ReReadingApplyState { get; set; }
        public DateTime? SuggesteFinishedTime { get; set; }
        public string UserCode { get; set; }
        public string UserName { get; set; }
        public string FullName { get; set; }

        public string UserTypeShortName { get; set; }

        public DateTime? FirstReadingTime { get; set; }

        public bool IsNeedClinicalDataSign { get; set; }

        public bool IsClinicalDataSign { get; set; }

        [DictionaryTranslateAttribute("CompleteClinicalDataEnum")]
        public CompleteClinicalDataEnum CompleteClinicalDataEnum =>
    (IsNeedClinicalDataSign && IsClinicalDataSign) ? CompleteClinicalDataEnum.Complete : (IsNeedClinicalDataSign && IsClinicalDataSign == false) ? CompleteClinicalDataEnum.NotComplete : CompleteClinicalDataEnum.NA;



        public string ReadingDuration
        {
            get
            {
                if (!SignTime.HasValue)
                    return "";
                else return string.Format("{0}h:{1}m:{2}s", (SignTime - FirstReadingTime)?.Hours, (SignTime - FirstReadingTime)?.Minutes, (SignTime - FirstReadingTime)?.Seconds)
                         /*string.Format("{0}分钟", (ReadingDurationTimeSpan)?.TotalMinutes)*/;
            }
        }

        public int? RandomOrder { get; set; }
    }


    public class ReReadingTaskExportDto : ReadingTaskExportDto
    {



        public string ApplicantName { get; set; }

        public string? ReReadingNewTaskCode { get; set; }



        [DictionaryTranslateAttribute("RequestReReadingType")]
        public RequestReReadingType RequestReReadingType { get; set; }

        public string RequestReReadingRejectReason { get; set; } = string.Empty;

        public DateTime? RequestReReadingTime { get; set; }

        public string RequestReReadingReason { get; set; } = string.Empty;


        [DictionaryTranslateAttribute("RequestReReadingResult")]
        public RequestReReadingResult RequestReReadingResultEnum { get; set; }




    }



    public class TaskMedicalReviewExportDto : ReadingTaskExportDto
    {

        public string QuestionContent { get; set; }

        [DictionaryTranslateAttribute("MedicalReviewAuditState")]
        public MedicalReviewAuditState AuditState { get; set; }
        public DateTime? AuditSignTime { get; set; }

        [DictionaryTranslateAttribute("MedicalReviewDoctorUserIdea")]
        public MedicalReviewDoctorUserIdea DoctorUserIdeaEnum { get; set; }

        [DictionaryTranslateAttribute("AuditAdvice")]
        public AuditAdvice AuditAdviceEnum { get; set; }

        //审核结论

        public bool IsHaveQuestion { get; set; }

        [DictionaryTranslateAttribute("IsPass")]

        public bool? IsHaveQuestionView => AuditState == MedicalReviewAuditState.WaitAudit ? null : IsHaveQuestion;
        //public UserSimpleInfo DoctorUser { get; set; }

        //public UserSimpleInfo MedicalManagerUser { get; set; }

        public string DoctorUserName { get; set; }


        public string MedicalManagerUserName { get; set; }

        /// <summary>
        /// 医学审核对话关闭原因
        /// </summary>
        public MedicalDialogClose MedicalDialogCloseEnum { get; set; }


        /// <summary>
        /// 无效的 为True无效
        /// </summary>
        [DictionaryTranslateAttribute("YesOrNo")]
        public bool IsInvalid { get; set; }



        public List<GetMedicalReviewDialogOutDto> DialogList { get; set; }

        public string DialogStr => string.Join("\n\n", DialogList.OrderBy(t => t.CreateTime).Select(c => c.CreateUserName + " (" + ExportExcelConverterDate.DateTimeInternationalToString(c.CreateTime) + ") :" + c.ResultContent));

    }

    public class TrialImageDownloadExportDto
    {
        public Guid TrialId { get; set; }

        public string TrialSiteCode { get; set; }

        public string SubjectCode { get; set; }

        [DictionaryTranslateAttribute("YesOrNo")]
        public bool IsSuccess { get; set; }

        public DateTime DownloadStartTime { get; set; }
        public DateTime? DownloadEndTime { get; set; }

        public string VisitName { get; set; }

        [DictionaryTranslateAttribute("downloadImageType")]
        public ImageType ImageType { get; set; }

        public int NoneDicomStudyCount { get; set; }

        public int DicomStudyCount { get; set; }

        public int TotalStudyCount => DicomStudyCount + NoneDicomStudyCount;

        public int ImageCount { get; set; }
        public long ImageSize { get; set; }


        public string UserName { get; set; }

        public string UserFullName { get; set; }
        public DateTime CreateTime { get; set; }

        public string IP { get; set; }

        [DictionaryTranslateAttribute("UserType")]
        public UserTypeEnum UserTypeEnum { get; set; }

        public string ImageSizeStr => (ImageSize / Math.Pow(1024, 2)).ToString("F3") + 'M';

        public string UploadIntervalStr
        {
            get
            {
                var uploadTimeSpan = DownloadEndTime - DownloadStartTime;

                return $" {uploadTimeSpan?.Hours}:{uploadTimeSpan?.Minutes}:{uploadTimeSpan?.Seconds}.{uploadTimeSpan?.Milliseconds}";
            }
        }

    }

    public class SCPImageUploadExportDTO
    {
        public string CallingAE { get; set; } = string.Empty;

        public string CalledAE { get; set; } = string.Empty;

        public string CallingAEIP { get; set; } = string.Empty;

        public DateTime StartTime { get; set; }

        public DateTime EndTime { get; set; }

        public int FileCount { get; set; }

        public long FileSize { get; set; }

        public int StudyCount { get; set; }


        public Guid TrialId { get; set; }
        public Guid TrialSiteId { get; set; }


        public string TrialSiteCode { get; set; }

        public string TrialSiteName { get; set; }

        public string TrialSiteAliasName { get; set; }

        public string UploadIntervalStr
        {
            get
            {
                var uploadTimeSpan = EndTime - StartTime;

                return $" {uploadTimeSpan.Hours}:{uploadTimeSpan.Minutes}:{uploadTimeSpan.Seconds}.{uploadTimeSpan.Milliseconds}";
            }
        }

        public string ImageSizeStr => (FileSize / Math.Pow(1024, 2)).ToString("F3") + 'M';
    }




    public class AnalysisExortCommon
    {
        public Guid Id { get; set; }
        public string TaskName { get; set; }
        public string TaskBlindName { get; set; }

        public decimal VisitTaskNum { get; set; }
        public bool? IsSelfAnalysis { get; set; }

        public string TrialReadingCriterionName { get; set; }

        public CriterionType CriterionType { get; set; }

        public String TrialSiteCode { get; set; } = String.Empty;
        public string SubjectCode { get; set; } = String.Empty;


        [DictionaryTranslateAttribute("ArmEnum")]
        public Arm ArmEnum { get; set; }
        public string UserName { get; set; }



        public bool? IsBaseline { get; set; }


        [DictionaryTranslateAttribute("ExistDisease", nameof(SelftAnalysisExport.IsBaseline), "true")]
        [DictionaryTranslateAttribute("OverallAssessment", nameof(SelftAnalysisExport.IsBaseline), "false")]
        public string EvaluateResult { get; set; }

        [DictionaryTranslateAttribute("ExistDisease", nameof(SelftAnalysisExport.IsBaseline), "true")]
        [DictionaryTranslateAttribute("OverallAssessment", nameof(SelftAnalysisExport.IsBaseline), "false")]
        public string AgainEvaluateResult { get; set; } = String.Empty;
    }

    public class GroupAnalysisExport : AnalysisExortCommon
    {

        [DictionaryTranslateAttribute("ArmEnum")]
        public Arm? AgainArmEnum { get; set; }

        public string AgainUserName { get; set; }

        /// <summary>
        /// 组件一致性和原Arm1是否有差异
        /// </summary>
        public bool? IsGroupDiffArm1 { get; set; }

        /// <summary>
        /// 组件一致性和原Arm2是否有差异
        /// </summary>
        public bool? IsGroupDiffArm2 { get; set; }

        public bool? IsGroupAnalysisDiffToOriginalData { get; set; }

    }

    public class SelftAnalysisExport : AnalysisExortCommon
    {
        //自身
        //
        //任务特有

        [DictionaryTranslateAttribute("YesOrNo")]
        public bool? IsAnalysisDiffToOriginalData { get; set; }


    }

    public class AnalysisDynamicCommonExport
    {
        public Guid Id { get; set; }
        public string TaskName { get; set; }
        public string TaskBlindName { get; set; }

        public decimal VisitTaskNum { get; set; }
        public bool? IsSelfAnalysis { get; set; }

        public string TrialReadingCriterionName { get; set; }

        public CriterionType CriterionType { get; set; }

        public String TrialSiteCode { get; set; } = String.Empty;
        public string SubjectCode { get; set; } = String.Empty;

        [DictionaryTranslateAttribute("ArmEnum")]
        public Arm ArmEnum { get; set; }
        public string UserName { get; set; }
        public bool? IsBaseline { get; set; }

        public ReadingCategory ReadingCategory { get; set; }

        /// <summary>
        /// 自身一致性分析任务上会有这个值
        /// </summary>
        [DictionaryTranslateAttribute("YesOrNo")]
        public bool? IsAnalysisDiffToOriginalData { get; set; }


        public List<CommonQuesionInfo> QuestionAnswerList { get; set; }

        #region 组件一致性额外加的
        public bool? IsGroupAnalysisDiffToOriginalData { get; set; }

        /// <summary>
        /// 组件一致性和原Arm1是否有差异
        /// </summary>
        public bool? IsGroupDiffArm1 { get; set; }

        /// <summary>
        /// 组件一致性和原Arm2是否有差异
        /// </summary>
        public bool? IsGroupDiffArm2 { get; set; }
        #endregion
    }


    //public class GroupAnalysisDynamicCommonExport: AnalysisDynamicCommonExport
    //{
    //    public bool? IsGroupAnalysisDiffToOriginalData { get; set; }

    //    /// <summary>
    //    /// 组件一致性和原Arm1是否有差异
    //    /// </summary>
    //    public bool? IsGroupDiffArm1 { get; set; }

    //    /// <summary>
    //    /// 组件一致性和原Arm2是否有差异
    //    /// </summary>
    //    public bool? IsGroupDiffArm2 { get; set; }

    //}
    public class DymamicQuestionInfo
    {
        public QuestionMark? QuestionMark { get; set; }
        public string QuestionName { get; set; }
        public string TranslateDicName { get; set; }
    }

    public class ExportQuestionBasicInfo
    {
        public QuestionType? QuestionType { get; set; }
        public string TableName { get; set; }
        public Guid QuestionId { get; set; }
        public string QuestionName { get; set; }
        public string TranslateDicName { get; set; }
        public string CDISCCode { get; set; }

        public string GroupName { get; set; }

        public int ShowOrder { get; set; }
    }


    public class CommonQuesionInfo
    {
        //问题标识，肿瘤评估用于区分是什么问题
        public QuestionType? QuestionType { get; set; }

        public OptionType OptionTypeEnum { get; set; }

        public ValueUnit? Unit { get; set; }


        public Guid QuestionId { get; set; }
        public string QuestionName { get; set; }

        public string QuestionValue { get; set; }

        public string TranslateDicName { get; set; }

        public string CDISCCode { get; set; }

        //外层问题会重复，所以需要分组名

        public string Group { get; set; }
    }
    public class CommonEvaluationExport
    {
        public List<CommonQuesionInfo> QuestionAnswerList { get; set; }

        public List<decimal> SubjectCriterionReadingPeriodVisitNumList { get; set; }

        public String TrialSiteCode { get; set; } = String.Empty;
        public string SubjectCode { get; set; } = String.Empty;

        public Guid Id { get; set; }

        public Guid SubjectId { get; set; }

        public Guid? DoctorUserId { get; set; }

        public string TaskName { get; set; }
        public string TaskBlindName { get; set; }

        public decimal VisitTaskNum { get; set; }

        public bool? IsBaseline { get; set; }


        [DictionaryTranslateAttribute("ArmEnum")]
        public Arm ArmEnum { get; set; }
        public string UserName { get; set; }

        public ReadingTaskState ReadingTaskState { get; set; }

        public ReadingCategory ReadingCategory { get; set; }

        //裁判结果选择的访视或者全局任务Id
        public Arm? JudgeArmEnum { get; set; }

        //裁判选择标记
        //根据裁判的任务结果 设置访视任务的这个字段  该字段表示  裁判认同该任务的结果
        [DictionaryTranslateAttribute("YesOrNoAudit")]
        public bool? IsJudgeSelect { get; set; }


        //在当前访视触发裁判，或者在截止日期小于等于当前访视的阅片期触发裁判
        [DictionaryTranslateAttribute("YesOrNoAudit")]
        public bool? IsTrigerJudge { get; set; }

        //（如果是访视点裁判，则仅在所选阅片人对应访视 显示；如果是阅片期裁判，则在所选阅片人 阅片期内的所有访视 显示此原因）
        public string JudgeNote { get; set; } = string.Empty;

        public string VisitNote { get; set; }

        #region CDISC_阅片结果表

        public string ResearchProgramNo { get; set; } = string.Empty;

        public string VisitName { get; set; }


        public string TrialSiteSubjectCode => ResearchProgramNo + SubjectCode;

        //最晚拍片日期
        public DateTime? LatestScanDate { get; set; }

        public string LatestScanDateStr => LatestScanDate?.ToString("yyyy-MM-dd");

        //阅片完成时间
        public DateTime? SignTime { get; set; }


        #endregion

        #region 肿瘤学结果

        [DictionaryTranslateAttribute("OncologyAssessType")]
        public string OncologyResult { get; set; } = string.Empty;

        public string OncologyReason { get; set; } = string.Empty;

        public string OncologyUserName { get; set; }

        #endregion

        #region CDISC 固定字段
        //组
        public string Group { get; set; }

        //行标识
        public string TRLINKID { get; set; }

        //列名
        public string TRTEST { get; set; }

        //值
        public string TRORRES { get; set; }

        //单位
        public string TRORRESU { get; set; }
        #endregion
    }

    public class CommonLessionExport : CommonEvaluationExport
    {

        [JsonIgnore]
        public List<CommonLessionInfo> LesionList { get; set; } = new List<CommonLessionInfo>();
    }

    public class CommonLessionInfo
    {
        //病灶编号
        public string LessionCode { get; set; }

        public string LessionType { get; set; }

        //病灶答案
        public List<CommonLessionQuestionAnswerInfo> LessionAnswerList { get; set; }

    }

    public class CommonLessionQuestionAnswerInfo
    {
        #region 肿瘤评估标准的时候需要

        public QuestionMark? QuestionMark { get; set; }

        #endregion


        #region CDISC导出

        public string CDISCCode { get; set; }


        //病灶Id
        public Guid RowId { get; set; }

        //如果是4 就取CustomUnit  否则就是字典翻译
        [Comment("单位")]
        public ValueUnit? Unit { get; set; }

        [Comment("自定义单位")]
        public string CustomUnit { get; set; } = string.Empty;

        public int ShowOrder { get; set; }

        #endregion


        #region 自定义表格名 特殊处理

        public string TableName { get; set; }
        #endregion

        public OptionType OptionTypeEnum { get; set; }

        public Guid TableQuesionId { get; set; }

        public string QuestionName { get; set; }

        public string QuestionValue { get; set; }

        public string TranslateDicName { get; set; }

    }



    public class DoctorJudgeRatio
    {
        public Guid? DoctorUserId { get; set; }

        public string UserName { get; set; }

        public string FullName { get; set; }

        public int TotalJudgeCount { get; set; }

        public int JudgeAgreeCount { get; set; }


        public string JudgeRatioStr => TotalJudgeCount == 0 ? $"NA" : $"{Math.Round((decimal)JudgeAgreeCount * 100 / TotalJudgeCount, 2)}%";


        public string ExceptionMark => TotalJudgeCount == 0 ? $"NA" : (JudgeAgreeCount * 3 / TotalJudgeCount < 1) ? "Y" : "N";

    }

    public class OverallTumorEvaluationExport
    {
        public String TrialSiteCode { get; set; } = String.Empty;
        public string SubjectCode { get; set; } = String.Empty;

        public Guid Id { get; set; }

        public Guid? DoctorUserId { get; set; }

        public string TaskName { get; set; }
        public string TaskBlindName { get; set; }

        public decimal VisitTaskNum { get; set; }

        public bool? IsBaseline { get; set; }


        [DictionaryTranslateAttribute("ArmEnum")]
        public Arm ArmEnum { get; set; }
        public string UserName { get; set; }

        public ReadingTaskState ReadingTaskState { get; set; }

        public ReadingCategory ReadingCategory { get; set; }

        [DictionaryTranslateAttribute("ExistDisease", CriterionType.Lugano2014, nameof(OverallTumorEvaluationExport.IsBaseline), "true")]
        [DictionaryTranslateAttribute("ImagingOverallAssessment_Lugano", CriterionType.Lugano2014, nameof(OverallTumorEvaluationExport.IsBaseline), "false")]
        [DictionaryTranslateAttribute("ExistDisease", CriterionType.Lugano2014WithoutPET, nameof(OverallTumorEvaluationExport.IsBaseline), "true")]
        [DictionaryTranslateAttribute("ImagingOverallAssessment_Lugano", CriterionType.Lugano2014WithoutPET, nameof(OverallTumorEvaluationExport.IsBaseline), "false")]

        [DictionaryTranslateAttribute("ExistDisease", CriterionType.IRECIST1Point1, nameof(OverallTumorEvaluationExport.IsBaseline), "true")]
        [DictionaryTranslateAttribute("OverallAssessment", CriterionType.IRECIST1Point1, nameof(OverallTumorEvaluationExport.IsBaseline), "false")]
        [DictionaryTranslateAttribute("ExistDisease", CriterionType.RECIST1Pointt1_MB, nameof(OverallTumorEvaluationExport.IsBaseline), "true")]
        [DictionaryTranslateAttribute("OverallAssessment", CriterionType.RECIST1Pointt1_MB, nameof(OverallTumorEvaluationExport.IsBaseline), "false")]
        [DictionaryTranslateAttribute("ExistDisease", CriterionType.RECIST1Point1, nameof(OverallTumorEvaluationExport.IsBaseline), "true")]
        [DictionaryTranslateAttribute("OverallAssessment", CriterionType.RECIST1Point1, nameof(OverallTumorEvaluationExport.IsBaseline), "false")]
        [DictionaryTranslateAttribute("VisitTumorEvaluation", CriterionType.PCWG3)]
        //整体肿瘤评估结果  需要翻译  
        public string OverallTumorEvaluationResult { get; set; }

        //裁判结果选择的访视或者全局任务Id
        public Arm? JudgeArmEnum { get; set; }

        //裁判选择标记
        //根据裁判的任务结果 设置访视任务的这个字段  该字段表示  裁判认同该任务的结果
        [DictionaryTranslateAttribute("YesOrNo")]
        public bool? IsJudgeSelect { get; set; }


        //在当前访视触发裁判，或者在截止日期小于等于当前访视的阅片期触发裁判
        [DictionaryTranslateAttribute("YesOrNo")]
        public bool IsTrigerJudge { get; set; }

        //（如果是访视点裁判，则仅在所选阅片人对应访视 显示；如果是阅片期裁判，则在所选阅片人 阅片期内的所有访视 显示此原因）
        public string JudgeNote { get; set; } = string.Empty;

        public string VisitNote { get; set; }
    }

    public class GlobalAnswerInfo
    {
        public decimal GlobalTaskVisitNum { get; set; }
        public Guid VisitTaskId { get; set; }

        public string Answer { get; set; }

    }


    public class RECIST1Point1EvaluationOfTumorEfficacyExport : OverallTumorEvaluationExport
    {
        [DictionaryTranslateAttribute("TargetAssessment", CriterionType.RECIST1Pointt1_MB)]
        [DictionaryTranslateAttribute("TargetAssessment", CriterionType.RECIST1Point1)]
        // 靶病灶评估
        public string TargetlesionEvaluationResult { get; set; }


        [DictionaryTranslateAttribute("NoTargetAssessment", CriterionType.RECIST1Pointt1_MB)]
        [DictionaryTranslateAttribute("NoTargetAssessment", CriterionType.RECIST1Point1)]
        // 非靶病灶评估
        public string NoneTargetlesionEvaluationResult { get; set; }

        // 是否存在新病灶
        [DictionaryTranslateAttribute("NewLesionAssessment", CriterionType.RECIST1Pointt1_MB)]
        [DictionaryTranslateAttribute("NewLesionAssessment", CriterionType.RECIST1Point1)]
        public string IsExistNewlesionEvaluationResult { get; set; }

    }

    public class Lugano2014EvaluationOfTumorEfficacyExport : OverallTumorEvaluationExport
    {
        [DictionaryTranslateAttribute("TargetAssessment", CriterionType.Lugano2014)]
        public string TargetlesionEvaluationResult { get; set; }


        [DictionaryTranslateAttribute("NoTargetAssessment", CriterionType.Lugano2014)]
        public string NoneTargetlesionEvaluationResult { get; set; }

        [DictionaryTranslateAttribute("NewLesionAssessment", CriterionType.Lugano2014)]
        public string IsExistNewlesionEvaluationResult { get; set; }

        //肝脏评估
        [DictionaryTranslateAttribute("LiverState", CriterionType.Lugano2014)]
        public string LiverResponse { get; set; }

        //脾脏评估
        [DictionaryTranslateAttribute("SpleenAssessment", CriterionType.Lugano2014)]
        public string SpleenResponse { get; set; }
        //CT/MRI总体评估
        [DictionaryTranslateAttribute("CT-MRIOverallAssessment", CriterionType.Lugano2014)]

        public string CT_MRI_OverallResponse { get; set; }

        //FDG-PET总体评估
        [DictionaryTranslateAttribute("FDG-PETOverallAssessment", CriterionType.Lugano2014)]
        public string FDG_PET_OverallResponse { get; set; }


    }

    public class IRECIST1Point1EvaluationOfTumorEfficacyExport : OverallTumorEvaluationExport
    {
        [DictionaryTranslateAttribute("TargetAssessment", CriterionType.IRECIST1Point1)]
        // 靶病灶评估
        public string TargetlesionEvaluationResult { get; set; }


        [DictionaryTranslateAttribute("NoTargetAssessment", CriterionType.IRECIST1Point1)]
        // 非靶病灶评估
        public string NoneTargetlesionEvaluationResult { get; set; }

        // 是否存在新病灶
        [DictionaryTranslateAttribute("NewLesionAssessment", CriterionType.IRECIST1Point1)]
        public string IsExistNewlesionEvaluationResult { get; set; }


        [DictionaryTranslateAttribute("NewLesionAssessment", CriterionType.IRECIST1Point1)]
        public string NewTargetResponse { get; set; }
        [DictionaryTranslateAttribute("NewLesionAssessment", CriterionType.IRECIST1Point1)]
        public string NewNoneTargetResponse { get; set; }
        [DictionaryTranslateAttribute("NewLesionAssessment", CriterionType.IRECIST1Point1)]
        public string OtherPreviousNewlesionsResponse { get; set; }

        //存在触发iRECIST后新病灶
        [DictionaryTranslateAttribute("NewLesionAssessment", CriterionType.IRECIST1Point1)]
        public string IsExistNewlesionsAfterTriggeringIRECIST { get; set; }


    }





    public class PCWG3LessionInfo
    {
        //病灶编号
        public string LessionCode { get; set; }


        [DictionaryTranslateAttribute("LesionType")]
        //病灶类型
        public string LessionType { get; set; }

        //所在部位
        public string LessionLocation { get; set; }

        //所在器官
        [DictionaryTranslate("OrganType")]
        public string LessionOrgan { get; set; }


        //部位描述
        public string BodyPartDescription { get; set; }


        [DictionaryTranslateAttribute("TargetState")]
        //病灶状态
        public string LessionState { get; set; }
    }

    public class PCWG3DetailedOfEvaluatedLesionExport : OverallTumorEvaluationExport
    {

        [JsonIgnore]
        public List<PCWG3LessionInfo> LesionList = new List<PCWG3LessionInfo>();

        //病灶编号
        public string LessionCode { get; set; }


        [DictionaryTranslateAttribute("LesionType")]
        //病灶类型
        public string LessionType { get; set; }

        //所在部位
        public string LessionLocation { get; set; }

        //所在器官

        public string LessionOrgan { get; set; }


        //部位描述
        public string BodyPartDescription { get; set; }


        [DictionaryTranslateAttribute("EvaluationOfState")]
        //病灶状态
        public string LessionState { get; set; }
    }


    //RECIST1.1评估病灶明细表 

    public class RECIST1Point1DetailedOfEvaluatedLesionExport : RECIST1Point1EvaluationOfTumorEfficacyExport
    {
        //EF  查询 需要   最后转成导表需要的展开形式
        [JsonIgnore]
        public List<RECIST1Point1LessionInfo> LesionList = new List<RECIST1Point1LessionInfo>();

        //病灶编号
        public string LessionCode { get; set; }


        [DictionaryTranslateAttribute("LesionType")]
        //病灶类型
        public string LessionType { get; set; }

        public string BeforeTranslateLessionTypeValue { get; set; }

        //是否淋巴结
        [DictionaryTranslateAttribute("IsLymph")]
        public string IsLymph { get; set; }

        //所在部位
        public string LessionLocation { get; set; }


        //所在器官

        public string LessionOrgan { get; set; }
        //部位描述
        public string BodyPartDescription { get; set; }

        //测量值
        //public string MeasurementResult { get; set; }

        //长径
        public string LongDiameter { get; set; }

        //短径
        public string ShortDiameter { get; set; }

        [DictionaryTranslateAttribute("TargetState", nameof(RECIST1Point1DetailedOfEvaluatedLesionExport.BeforeTranslateLessionTypeValue), "0")]
        [DictionaryTranslateAttribute("NoTargetState", nameof(RECIST1Point1DetailedOfEvaluatedLesionExport.BeforeTranslateLessionTypeValue), "1")]
        [DictionaryTranslateAttribute("NewLesionState", nameof(RECIST1Point1DetailedOfEvaluatedLesionExport.BeforeTranslateLessionTypeValue), "2")]
        //病灶状态
        public string LessionState { get; set; }

    }




    public class RECIST1Point1LessionInfo
    {
        //病灶编号
        public string LessionCode { get; set; }

        //病灶类型
        public string LessionType { get; set; }

        //所在部位
        public string LessionLocation { get; set; }

        //所在器官
        public string LessionOrgan { get; set; }

        //是否淋巴结
        public string IsLymph { get; set; }

        //部位描述
        public string BodyPartDescription { get; set; }

        //测量值
        //public string MeasurementResult { get; set; }


        //长径
        public string LongDiameter { get; set; }

        //短径
        public string ShortDiameter { get; set; }

        //病灶状态
        public string LessionState { get; set; }
    }


    public class PGW3DetailedOfEvaluatedLesionExport : OverallTumorEvaluationExport
    {
        //病灶编号
        public string LessionCode { get; set; }


        //病灶类型
        public string LessionType { get; set; }

        //所在部位
        public string LessionLocation { get; set; }

        //部位描述
        public string BodyPartDescription { get; set; }

        //病灶状态
        public string LessionState { get; set; }
    }

    #endregion


    public class ImageBackViewModel
    {
        public bool IsSubjectQuit { get; set; }
        public Guid Id { get; set; }

        public DateTime CreateTime { get; set; }

        public string CreateUserName { get; set; }

        public string CreateUserFullName { get; set; }


        public DateTime? AuditTime { get; set; }
        public Guid SubjectVisitId { get; set; }

        [DictionaryTranslateAttribute("ImageBackApplyEnum")]
        public ImageBackApplyEnum ApplyUserRole { get; set; }

        [DictionaryTranslateAttribute("ImageBackApplyEnum")]
        public ImageBackStateEnum ImageBackState { get; set; }

        public DateTime? SubmitTime { get; set; }

        [DictionaryTranslateAttribute("YesOrNo")]
        public bool IsUrgent { get; set; }

        public string VisitName { get; set; } = string.Empty;

        public DateTime? EarliestScanDate { get; set; }
        public DateTime? LatestScanDate { get; set; }
        public decimal VisitNum { get; set; }

        [DictionaryTranslateAttribute("Subject_Visit_Status")]
        public SubjectStatus SubjectStatus { get; set; }
        public string SubjectCode { get; set; } = String.Empty;

        public String TrialSiteCode { get; set; } = String.Empty;

        /// <summary>
        /// 申请原因
        /// </summary>
        public string ApplyReason { get; set; } = string.Empty;

        /// <summary>
        /// 结果备注
        /// </summary>
        public string ResultRemark { get; set; } = string.Empty;
    }


    public class QCCRCVisitViewModel : QCVisitBasicListViewModel
    {
        public Guid? OutPlanPreviousVisitId { get; set; }
        public bool IsOutEnromentVisit { get; set; }

        public PDStateEnum PDState { get; set; }
        public bool IsEnrollmentConfirm { get; set; }
        public DateTime? SubjectFirstGiveMedicineTime { get; set; }

        public SubjectStatus SubjectStatus { get; set; }
        public string SubjectCode { get; set; } = String.Empty;

        //public int? StudyCount { get; set; }
        public String TrialSiteCode { get; set; } = String.Empty;

        public DateTime? SubmitTime { get; set; }
        public AuditStateEnum AuditState { get; set; }


        public int? DicomStudyCount { get; set; }
        public int? NoneDicomStudyCount { get; set; }

        public bool IsHaveClinicalData { get; set; }

        public string MedicalNo { get; set; }

        public int? Age { get; set; }
        public string Sex { get; set; } = string.Empty;

        public bool IsHaveUploadFailed { get; set; }




    }

    public class GetNextCRCChallengeInDto
    {
        [NotDefault]
        public Guid TrialId { get; set; }

        /// <summary>
        /// QCChallengeId
        /// </summary>
        public Guid QCChallengeId { get; set; }
    }


    public class ChallengeQuery : PageInput
    {
        [NotDefault]
        public Guid TrialId { get; set; }

        public string[]? VisitPlanArray { get; set; }

        //public string VisitPlanInfo { get; set; } = String.Empty;
        public string SubjectCode { get; set; } = String.Empty;
        public QCChanllengeReuploadEnum? ReuploadEnum { get; set; }

        public bool? IsUrgent { get; set; }
        public Guid? SubjectId { get; set; }
        public Guid? TrialSiteId { get; set; }
        public bool? IsClosed { get; set; }
        public bool? IsOverTime { get; set; }
        public Guid? CreateUserId { get; set; }


    }

    public class QCCRCChallengeViewModel
    {
        public SecondReviewState SecondReviewState { get; set; }
        public bool IsSubjectQuit { get; set; }

        public Guid? PreliminaryAuditUserId { get; set; }
        public Guid? CurrentActionUserId { get; set; }


        public SubmitStateEnum SubmitState { get; set; }



        public string? CurrentActionUserName { get; set; }

        public bool IsBaseLine { get; set; }
        public bool IsUrgent { get; set; }

        public bool IsQCConfirmedReupload { get; set; }

        //public string CreatorFirstName { get; set; }
        //public string CreatorLastName { get; set; }
        public string BlindName { get; set; } = String.Empty;

        //public string ReplyerRealName { get; set; }

        public DateTime? ReUploadedTime { get; set; }
        public Guid SubjectVisitId { get; set; }
        public Guid SubjectId { get; set; }
        public Guid Id { get; set; }
        public String TrialSiteCode { get; set; } = String.Empty;

        public string SubjectCode { get; set; } = String.Empty;

        public decimal VisitNum { get; set; }
        public string VisitName { get; set; } = string.Empty;

        public RequestBackStateEnum RequestBackState { get; set; }

        public bool IsClosed { get; set; }

        public DateTime? ClosedTime { get; set; }

        public string PreliminaryAuditUserName { get; set; } = String.Empty;

        //public string ClosedUserUserName { get; set; } = String.Empty;

        public DateTime? CreateTime { get; set; }

        public Guid CreateUserId { get; set; }

        public string CreateUserFullName { get; set; } = String.Empty;

        public string CreateUserName { get; set; } = String.Empty;

        //public bool NeedReUpload { get; set; }
        public QCChanllengeReuploadEnum ReuploadEnum { get; set; }
        public DateTime? DeadlineTime { get; set; }

        public Guid TrialSiteId { get; set; }
        public AuditStateEnum AuditState { get; set; }
        public CurrentQC CurrentQCEnum { get; set; }
        public TrialQCProcess QCProcessEnum { get; set; }

        public string ChallengeCode { get; set; } = String.Empty;

        public string ChallengeType { get; set; } = string.Empty;

        public string Note { get; set; } = string.Empty;


        public bool IsOverTime => IsClosed ? ClosedTime > DeadlineTime : DateTime.Now > DeadlineTime;

        public Guid LatestReplyUserId { get; set; }

        public string LatestReplyUserFullName { get; set; } = String.Empty;
        public string LatestReplyUserName { get; set; } = String.Empty;

        public string Content { get; set; } = string.Empty;

        public UserTypeEnum UserTypeEnum { get; set; }


        public DateTime? LatestMsgTime { get; set; }

        public string ChallengeDuration
        {
            get
            {
                if (!ClosedTime.HasValue)
                    return "";
                else return string.Format("{0}d {1}h {2}m", (ClosedTime - CreateTime)?.Days, (ClosedTime - CreateTime)?.Hours, (ClosedTime - CreateTime)?.Minutes);
            }
        }


    }

    public class CheckQuery : PageInput
    {

        //public string VisitPlanInfo { get; set; } = String.Empty;
        public string[]? VisitPlanArray { get; set; }

        //核查状态
        public CheckStateEnum? CheckState { get; set; }

        public Guid TrialId { get; set; }

        public Guid? TrialSiteId { get; set; }
        public string SubjectInfo { get; set; } = String.Empty;


        //public bool? IsClosed { get; set; }
    }

    public class QCQuestionAnswer
    {
        public Guid? AnswerId { get; set; }
        public Guid Id { get; set; }
        public string QuestionName { get; set; } = String.Empty;
        public bool IsRequired { get; set; }

        public string Type { get; set; } = String.Empty;

        public string Answer { get; set; } = String.Empty;
        public string ParentTriggerValue { get; set; }
        public Guid? ParentId { get; set; }
        public string TypeValue { get; set; } = String.Empty;
        public int ShowOrder { get; set; }

        public int? ParentShowOrder { get; set; }



        public List<QCQuestionAnswer> Childrens = new List<QCQuestionAnswer>();
    }
    public class GetQCQuestionAnswerInDto
    {
        public Guid SubjectVisitId { get; set; }

        public Guid TrialId { get; set; }

        public TrialQCProcess QCProcessEnum { get; set; }

        // 1代表第一个人QC数据  2 代表第二个人QC数据
        public CurrentQC CurrentQCEnum { get; set; }

        public DateTime? SecondReviewTime { get; set; }
    }

    public class ForwardQuery : PageInput
    {
        public Guid TrialId { get; set; }

        public Guid? TrialSiteId { get; set; }
        public string SubjectInfo { get; set; } = String.Empty;

        public string[]? VisitPlanArray { get; set; }

        //public string VisitPlanInfo { get; set; } = String.Empty;

        public ForwardStateEnum? ForwardState { get; set; }
    }

    public class ForWardViewModel
    {
        public Guid Id { get; set; }
        public string BlindName { get; set; } = String.Empty;
        public String TrialSiteCode { get; set; } = String.Empty;
        public string SubjectCode { get; set; } = String.Empty;

        public decimal VisitNum { get; set; }
        public string VisitName { get; set; } = string.Empty;

        public Guid? ForwardUserId { get; set; }

        public string ForwardUserName { get; set; } = String.Empty;

        public DateTime? ForwardTime { get; set; }

        public ForwardStateEnum ForwardState { get; set; }

        public CheckStateEnum CheckState { get; set; }


    }


    public class CheckDialogDTO
    {
        public QCCheckViewModel SubjectVisitCheck { get; set; }

        public List<CheckChanllengeDialogDTO> DialogList { get; set; }
    }

    public class QCCheckWithModalityView : QCCheckViewModel
    {
        public DateTime? EarliestScanDate { get; set; }

        public DateTime? LatestScanDate { get; set; }

        public List<string> ModalityList { get; set; }

        public string Modalitys => string.Join(',', ModalityList);
    }

    public class QCCheckViewModel
    {
        public bool IsSubjectQuit { get; set; }
        public string? TalkContent { get; set; } = String.Empty;
        public string BlindName { get; set; } = String.Empty;
        public bool IsUrgent { get; set; }

        public DateTime? CheckPassedTime { get; set; }
        public Guid Id { get; set; }

        public Guid? CheckChallengeLatestUserId { get; set; }

        public AuditStateEnum AuditState { get; set; }

        public CheckStateEnum CheckState { get; set; }
        public String TrialSiteCode { get; set; } = String.Empty;
        public string SubjectCode { get; set; } = String.Empty;

        public decimal VisitNum { get; set; }
        public string VisitName { get; set; } = string.Empty;

        public Guid SubjectId { get; set; }
        public Guid TrialSiteId { get; set; }

        //public string Modality { get; set; }

        public RequestBackStateEnum RequestBackState { get; set; }

        [ExcelFormat("yyyy-MM-dd")]
        public DateTime? StudyTime { get; set; }

        public string StudyTimeStr => StudyTime?.ToString("yyyy-MM-dd");

        public DateTime? CheckTime { get; set; }
        public CheckChanllengeTypeEnum CheckChallengeState { get; set; }

        public bool? IsCheckBack { get; set; }

        public string CheckResult { get; set; } = String.Empty;
    }

    public class QCVisitViewModel : QCVisitBasicListViewModel
    {
        public int? DicomStudyCount { get; set; }
        public int? NoneDicomStudyCount { get; set; }
        public bool IsHaveClinicalData { get; set; }

        public SubjectStatus SubjectStatus { get; set; }
        public int? StudyCount { get; set; }

        public string SubjectCode { get; set; } = String.Empty;
        public String TrialSiteCode { get; set; } = String.Empty;



        public int? ChallengeCount { get; set; }


        public AuditStateEnum AuditState { get; set; }

        public DateTime? SubmitTime { get; set; }

        public string SubmitUserName { get; set; } = String.Empty;

        public string SubmitUserRealName { get; set; } = String.Empty;

        public string CurrentActionUserName { get; set; } = String.Empty;
        public string PreliminaryAuditUserName { get; set; } = String.Empty;


        public string ReviewAuditUserName { get; set; } = String.Empty;


        public bool IsEnrollmentConfirm { get; set; } = false;
        public DateTime? SubjectFirstGiveMedicineTime { get; set; }

        public PDStateEnum PDState { get; set; } = PDStateEnum.None;
    }

    //public class QCHistoryChallengeViewModel: QCCRCChallengeViewModel
    //{



    //}

    public class QCChallengeViewModel : QCCRCChallengeViewModel
    {


    }



    public class QCVisitBasicListViewModel
    {
        public SecondReviewState SecondReviewState { get; set; }
        public bool IsSubjectQuit { get; set; }
        public ChallengeStateEnum ChallengeState { get; set; }
        public bool? IsConfirmedClinicalData { get; set; }
        public bool IsQCConfirmedReupload { get; set; }

        public bool IsFinalVisit { get; set; }
        public string BlindName { get; set; } = String.Empty;
        public bool IsUrgent { get; set; }
        //public bool IsReuploaded { get; set; }
        //public bool NeedReUpload { get; set; }
        public QCChanllengeReuploadEnum ReuploadEnum { get; set; }
        public Guid? Id { get; set; }
        public Guid TrialId { get; set; }
        public Guid SubjectId { get; set; }
        public Guid TrialSiteId { get; set; }
        public bool InPlan { get; set; } = true;
        public int VisitExecuted { get; set; }
        public decimal VisitNum { get; set; }
        public string VisitName { get; set; } = string.Empty;
        public int VisitDay { get; set; }
        public string SVUPDES { get; set; } = string.Empty;
        public DateTime? SVSTDTC { get; set; }
        public DateTime? SVENDTC { get; set; }

        public TrialQCProcess QCProcessEnum { get; set; }
        public DateTime? EarliestScanDate { get; set; }
        public DateTime? LatestScanDate { get; set; }

        public bool IsBaseLine { get; set; } = false;
        public string AnonymousVisitName { get; set; } = string.Empty;
        public int VisitWindowLeft { get; set; }
        public int VisitWindowRight { get; set; }

        public bool IsTake { get; set; }
        public Guid? CurrentActionUserId { get; set; }
        public Guid? PreliminaryAuditUserId { get; set; }

        public Guid? ReviewAuditUserId { get; set; }
        public DateTime? CurrentActionUserExpireTime { get; set; }

        public SubmitStateEnum SubmitState { get; set; }

        public RequestBackStateEnum RequestBackState { get; set; }

        public bool IsLostVisit { get; set; }

        public string VisitImageZipPath { get; set; }

        public PackState PackState { get; set; }

        //public Guid? ClinicalDataSignUserId { get; set; }

        public DateTime? ReviewAuditTime { get; set; }
        public DateTime? PreliminaryAuditTime { get; set; }

        public bool IsImageBackApplying { get; set; }


        public DateTime? AuditTime => QCProcessEnum == TrialQCProcess.SingleAudit ? PreliminaryAuditTime : (QCProcessEnum == TrialQCProcess.DoubleAudit ? ReviewAuditTime : null);
    }


    public class GetQCQuestionAnswerQuery
    {
        public Guid TrialId { get; set; }
    }

    public class QCQuestionAnswerResult_export
    {
        public Guid SubjectVisitId { get; set; }
        public string TrialSiteCode { get; set; }

        public string SubjectCode { get; set; }

        public string VisitName { get; set; }

        public decimal VisitNum { get; set; }

        public CurrentQC CurrentQCEnum { get; set; }

        public string AuditUserName { get; set; }

        public string AuditUserFullName { get; set; }

        public string AuditUser => $"{AuditUserName}({AuditUserFullName})";

        public DateTime? AuditTime { get; set; }

        public DateTime? SecondReviewTime { get; set; }

        public Guid QuestionId { get; set; }
        public string QuesitonName { get; set; }

        public string Answer { get; set; }

        public int ShowOrder { get; set; }

    }

    public class QCQuestionResult_Export
    {
        public string TrialSiteCode { get; set; }

        public string SubjectCode { get; set; }

        public string VisitName { get; set; }
        public decimal VisitNum { get; set; }

        [DictionaryTranslate("CurrentQCType")]
        public CurrentQC CurrentQCEnum { get; set; }

        public string AuditUserName { get; set; }

        public string AuditUserFullName { get; set; }

        public string AuditUser => $"{AuditUserName}({AuditUserFullName})";

        public DateTime? AuditTime { get; set; }

        public List<QCQuestionAnswerExport> QuestionAnswerList { get; set; }

    }

    public class QCQuestionAnswerExport
    {
        public Guid QuestionId { get; set; }
        public string QuestionName { get; set; }

        public string Answer { get; set; }

        public int ShowOrder { get; set; }
    }
}
