using IRaCIS.Core.Application.Contracts.DTO;
using IRaCIS.Core.Application.Helper;
using IRaCIS.Core.Application.ViewModel;
using IRaCIS.Core.Domain.Share;
using MiniExcelLibs.Attributes;
using Newtonsoft.Json;
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;

namespace IRaCIS.Core.Application.Contracts
{

    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? SiteId { 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 class GetNextQCInfoInDto
    {
        public Guid TrialId { 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? SiteId { 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 class GetNextIQCQualityInDto
    {
        [NotDefault]
        public Guid TrialId { get; set; }

        public Guid SubjectId { get; set; }
    }

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

        public Guid? VisitId { get; set; }
    }


    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 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;

    }


    #region 导出模型

    public class CRCVisitExportDTO
    {
        public ChallengeStateEnum ChallengeState { 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;

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

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

        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 class QCChanllengeExportDto
    {

        [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 LatestReplyUserName { get; set; } = String.Empty;

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

        [DictionaryTranslateAttribute("YesOrNo")]
        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)
                    return "";
                else return string.Format("{0}d {1}h {2}min", (ClosedTime - CreateTime)?.Days, (ClosedTime - CreateTime)?.Hours, (ClosedTime - CreateTime)?.Minutes);
            }
        }


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



        public string DialogStr { get; set; }

        //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 SubjectExportDTO
    {
        public string Code { get; set; } = String.Empty;

        //public int? Age { get; set; }
        //public string Sex { get; set; } = string.Empty;
        //public Guid SiteId { 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 DateTime? 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 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; }


        ///// <summary>
        ///// 任务展示访视 读片任务显示是否顺序
        ///// </summary>
        //public bool IsReadingTaskViewInOrder { get; set; } = true;
    }

    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; }




            //最终任务
            [Column(TypeName = "decimal(18,2)")]
            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 = string.Empty;

    }

    public class UnionStudyExportDTO
    {

        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;
        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 SiteId { 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 CheckDialogStr { get; set; }

        public DateTime? CheckBackTime { get; set; }

        public DateTime? EarliestScanDate { get; set; }

        public DateTime? LatestScanDate { get; set; }

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

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


    public class ReadingTaskExportDto
    {
        //public TaskAllocationState TaskAllocationState { get; set; }

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


        public DateTime? AllocateTime { get; set; }

        //public bool IsPMSetBack { get; set; }

        public string TaskCode { get; set; }

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

        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 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 class ReReadingTaskExportDto : ReadingTaskExportDto
    {


        //public ReadingTaskExportDto ApplyTask { 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;

        public DateTime? SuggesteFinishedTime { get; set; }

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




    }



    public class TaskMedicalReviewExportDto : ReadingTaskExportDto
    {

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


        [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; }

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



        //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 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 OverallTumorEvaluationExport
    {
        public String TrialSiteCode { get; set; } = String.Empty;
        public string SubjectCode { get; set; } = String.Empty;

        public Guid Id { 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 ReadingCategory ReadingCategory { get; set; }

        [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; }


        #region old 废弃

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

        //[DictionaryTranslateAttribute("YesOrNo")]
        //public bool IsGenerateJudge => JudgeResultTaskId != null;
        #endregion


        public Arm? JudgeArmEnum { get; set; }


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


    }



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

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

        // 是否存在新病灶
        [DictionaryTranslateAttribute("NewLesionAssessment", CriterionType.RECIST1Point1)]
        public string IsExistNewlesionEvaluationResult { 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; }



        //是否淋巴结
        [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")]
        //病灶状态
        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 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 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? SiteId { get; set; }
        public bool? IsClosed { get; set; }
        public bool? IsOverTime { get; set; }
        public Guid? CreateUserId { get; set; }

    }

    public class QCCRCChallengeViewModel
    {
        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 Guid? ClinicalDataSignUserId { 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 CreateUserName { get; set; } = String.Empty;

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

        public Guid SiteId { 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 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}min", (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? SiteId { get; set; }
        public string SubjectInfo { get; set; } = String.Empty;


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

    public class QCQuestionAnswer
    {
        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 class ForwardQuery : PageInput
    {
        public Guid TrialId { get; set; }

        public Guid? SiteId { 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 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 SiteId { 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 CurrentActionUserName { get; set; } = String.Empty;
        public string PreliminaryAuditUserName { get; set; } = String.Empty;


        public string ReviewAuditUserName { get; set; } = String.Empty;
        public DateTime? ReviewAuditTime { get; set; }
        public DateTime? PreliminaryAuditTime { get; set; }

        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 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 SiteId { 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 Guid? ClinicalDataSignUserId { get; set; }
    }



}
