//--------------------------------------------------------------------
//     此代码由T4模板自动生成  byzhouhang 20210918
//	   生成时间 2022-06-07 14:10:54 
//     对此文件的更改可能会导致不正确的行为，并且如果重新生成代码，这些更改将会丢失。
//--------------------------------------------------------------------
using System;
using IRaCIS.Core.Domain.Share;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using Newtonsoft.Json;

namespace IRaCIS.Core.Application.ViewModel
{

    public class VisitTaskViewBasic
    {
        public Guid Id { get; set; }
        public Guid TrialId { get; set; }

        public string TaskCode { get; set; }

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

        public decimal VisitTaskNum { get; set; }

        public bool IsUrgent { get; set; }

        /// <summary>
        /// 加急类型
        /// </summary>
        public TaskUrgentType? TaskUrgentType { get; set; }


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

        public ReadingCategory ReadingCategory { get; set; }

        public TaskAllocationState TaskAllocationState { get; set; }
        public TaskState TaskState { get; set; }

        public DateTime? SignTime { get; set; }

        public DateTime? AllocateTime { get; set; }
        public Guid SubjectId { get; set; }

        public Arm ArmEnum { get; set; }
        public Guid? DoctorUserId { get; set; }


        public Guid CreateUserId { get; set; }
        public DateTime CreateTime { get; set; }
        public DateTime UpdateTime { get; set; }
        public Guid UpdateUserId { get; set; }


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

        public bool IsPMSetBack { get; set; }

        #region 标准配置
        public Guid TrialReadingCriterionId { get; set; }

        public string TrialReadingCriterionName { get; set; }


        public bool IsNeedClinicalDataSign { get; set; }

        public bool IsClinicalDataSign { get; set; }


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


        /// <summary>
        /// 阅片工具
        /// </summary>
        public ReadingTool? ReadingTool { get; set; }

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


        /// <summary>
        /// 阅片是否显示患者信息
        /// </summary>
        public bool IsReadingShowSubjectInfo { get; set; } = false;

        /// <summary>
        /// IR阅片页面是否可以查看既往任务结果
        /// </summary>
        public bool IsReadingShowPreviousResults { get; set; } = false;

        public int? DigitPlaces { get; set; } = 2;

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

        public CriterionType CriterionType { get; set; }



        ///// <summary>
        ///// 仲裁对象
        ///// </summary>
        //public ArbitrationRule ArbitrationRule { get; set; } = ArbitrationRule.Reading;


        ///// <summary>
        ///// 阅片模式
        ///// </summary>
        //public ReadingMethod ReadingType { get; set; } = ReadingMethod.Double;

        ///// <summary>
        ///// 全局阅片
        ///// </summary>
        //public bool IsGlobalReading { get; set; } = true;

        ///// <summary>
        ///// 仲裁阅片
        ///// </summary>
        //public bool IsArbitrationReading { get; set; } = true;


        ///// <summary>
        ///// 肿瘤学阅片  原字段 IsClinicalReading
        ///// </summary>
        //public bool IsOncologyReading { get; set; }
        #endregion

    }


    /// <summary> VisitTaskView  列表视图模型 </summary>
    public class VisitTaskView : VisitTaskViewBasic
    {

        public string UserCode { get; set; }
        public string UserName { get; set; }
        public string FullName { get; set; }

        public string UserTypeShortName { get; set; }

        public bool IsCanEditUrgentState { get; set; }


    }

    public class UserSimpleInfo
    {
        public Guid UserId { get; set; }
        public string UserCode { get; set; }
        public string UserName { get; set; }
        public string FullName { get; set; }

        //public string UserTypeShortName { get; set; }
    }


    public class JudgeVisitTaskView : VisitTaskView
    {

        public List<HistoryReadingDoctorUser> HistoryReadingDoctorUserList { get; set; }

    }


    public class ReadingTaskView : VisitTaskView
    {

        public ReadingTaskState ReadingTaskState { get; set; }

        public ReReadingApplyState ReReadingApplyState { get; set; }
        public DateTime? SuggesteFinishedTime { get; set; }

        //任务来源检查批次Id  方便回更检查批次读片状态
        public Guid? SourceSubjectVisitId { get; set; }
        public Guid? SouceReadModuleId { get; set; }


    }


    public class AnalysisTaskView : ReadingTaskView
    {
        public bool? IsSelfAnalysis { get; set; }

        public bool IsReReadingOrBackInfluenceAnalysis { get; set; }
    }



    public class ReReadingTaskView
    {

        //重阅原始编号
        //public string ReReadingOriginalTaskCode { get; set; }



        public Guid Id { get; set; }

        public AnalysisTaskView OriginalReReadingTask { get; set; }

        public string? ReReadingNewTaskCode { get; set; }



        public ReadingTaskState ReadingTaskState { get; set; }

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

        public RequestReReadingResult RequestReReadingResultEnum { get; set; }

        //重阅原始任务Id  重阅会产生新的任务 
        public Guid OriginalReReadingTaskId { get; set; }

        //重阅申请 产生的新任务Id
        public Guid? NewReReadingTaskId { get; set; }


        //产生重阅的根任务Id
        public Guid RootReReadingTaskId { get; set; }


    }


    public class IRHaveReadView : VisitTaskViewBasic
    {
        public ReadingTaskState ReadingTaskState { get; set; }

        public ReReadingApplyState ReReadingApplyState { get; set; }
        public DateTime? SuggesteFinishedTime { get; set; }

    }

    public class IRUnReadSubjectView
    {
        public int Index { get; set; } = 0;

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

        public bool IsUrgent => UnReadTaskList.Any(t => t.IsUrgent);

        public int UnReadTaskCount { get; set; }

        public int UnReadCanReadTaskCount { get; set; }

        public int HaveReadTaskCount { get; set; }

        public int TotalTaskCount { get; set; }

        public bool ExistReadingApply { get; set; }

        public DateTime? SuggesteFinishedTime { get; set; }

        public List<IRUnreadTaskView> UnReadCanReadTaskList => UnReadTaskList.Where(y => y.IsFrontTaskNeedSignButNotSign == false && (y.IsNeedClinicalDataSign == false || y.IsClinicalDataSign == true)).ToList();

        public List<IRUnreadTaskView> UnReadTaskList { get; set; } = new List<IRUnreadTaskView>();
    }

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

        public ReadingCategory ReadingCategory { get; set; }

        /// <summary>
        /// 是否是一致性分析产生
        /// </summary>
        public bool IsAnalysisCreate { get; set; }

        public bool IsUrgent { get; set; }

        public decimal VisitNum { get; set; }

        public string TaskBlindName { get; set; }

        public Arm ArmEnum { get; set; }

        public Guid? VisistId { get; set; }
        public DateTime? SuggesteFinishedTime { get; set; }

        public Guid TrialReadingCriterionId { get; set; }

        public bool IsNeedClinicalDataSign { get; set; }

        public bool IsClinicalDataSign { get; set; }

        public bool IsFrontTaskNeedSignButNotSign { get; set; }
    }


    public class HistoryReadingDoctorUser
    {

        public string? JudgeTaskCode { get; set; }
        public Guid DoctorUserId { get; set; }

        public string UserCode { get; set; }
        public string UserName { get; set; }
        public string FullName { get; set; }
    }


    public class GetOrderReadingIQueryableInDto
    {
       public Guid TrialId { get; set; }
        
       public Guid TrialReadingCriterionId { get; set; }

        public string? SubjectCode { get; set; } = null;

        public PageInput? Page { get; set; } = null;

    }

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

        public Guid? SiteId { get; set; }

        public Guid? SubjectId { get; set; }

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

        public bool? IsUrgent { get; set; }

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

        public Guid? DoctorUserId { get; set; }

        public ReadingCategory? ReadingCategory { get; set; }

        public ReadingTaskState? ReadingTaskState { get; set; }
        public TaskAllocationState? TaskAllocationState { get; set; }

        public TaskState? TaskState { get; set; }
        public DateTime? BeginAllocateDate { get; set; }

        public DateTime? EndAllocateDate { get; set; }

        public Guid? RootReReadingTaskId { get; set; }

        public string? TaskCode { get; set; }

        public String? TrialSiteCode { get; set; }

        public ReReadingApplyState? ReReadingApplyState { get; set; }

        public RequestReReadingType? RequestReReadingType { get; set; }


        public bool? IsSelfAnalysis { get; set; }

        public Arm? ArmEnum { get; set; }

        public Guid? TrialReadingCriterionId { get; set; }

        public CompleteClinicalDataEnum? CompleteClinicalDataEnum { get; set; }

        public RequestReReadingResult? RequestReReadingResultEnum { get; set; }


        public DateTime? BeginSignTime { get; set; }

        public DateTime? EndSignTime { get; set; }



    }









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

        public string SubjectCode { get; set; }

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

    }

    public class IRUnReadOutDto
    {
        /// <summary>
        /// 未完成阅片量
        /// </summary>
        public int UnReadTaskCount { get; set; }

        /// <summary>
        /// 完成阅片量
        /// </summary>
        public int FinishTaskCount { get; set; }

        /// <summary>
        /// 未完成裁判任务数量
        /// </summary>
        public int UnReadJudgeTaskCount { get; set; }

        /// <summary>
        /// 完成裁判任务数量
        /// </summary>
        public int FinishJudgeTaskCount { get; set; }

        /// <summary>
        /// 建议完成时间
        /// </summary>
        public DateTime? SuggesteFinishedTime { get; set; }

    }

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

        public Guid? SiteId { get; set; }

        public Guid? SubjectId { get; set; }

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

        public bool IsJudgeDoctor { get; set; }


        public Guid? DoctorUserId { get; set; }

        public bool? IsHaveAssigned { get; set; }

        public bool? IsAssignConfirmed { get; set; }

    }

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

        public Guid? SiteId { get; set; }

        public Guid? SubjectId { get; set; }

        public Guid? DoctorUserId { get; set; }


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


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


    }

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

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

        public List<Guid> SubjectIdList { get; set; }

        public List<DoctorArm> DoctorArmList { get; set; }

    }








    public class SubjectAssignStat
    {
        public Guid TrialId { get; set; }
        public Guid SiteId { get; set; }

        public Guid SubjectId { get; set; }

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

        public int? VisitTaskTypeCount { get; set; }
        public int? GlobalTaskTypeCount { get; set; }
        public int? JudgeTaskTypeCount { get; set; }

        public int? OncologyTaskTypeCount { get; set; }

        [JsonIgnore]
        public List<SubjectUserView> DoctorUserList { get; set; }

        public List<SubjectUserView> PreviousDoctorUserList => DoctorUserList.Where(t => t.OrignalSubjectUserId != null).ToList();

        public List<SubjectUserView> NowDoctorUserList => DoctorUserList.Where(t => t.OrignalSubjectUserId == null).ToList();



    }

    public class SubjectUserView
    {
        public Guid TrialReadingCriterionId { get; set; }
        public Guid Id { get; set; }
        public DateTime? AssignTime { get; set; }

        public Guid DoctorUserId { get; set; }
        public Arm ArmEnum { get; set; }

        public bool IsConfirmed { get; set; }

        //该属性有值 说明该医生被替换了 分配的时候 要过滤掉
        public Guid? OrignalSubjectUserId { get; set; }

        public UserSimpleInfo DoctorUser { get; set; }
    }


    public class SubjectUserDTO : SubjectUserView
    {
        public bool IsHaveReading { get; set; }
    }


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


        public Guid SubjectId { get; set; }
        public Guid DoctorUserId { get; set; }
        public Arm ArmEnum { get; set; }


        public bool IsCancelAssign { get; set; }

    }


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

        [NotDefault]
        public Guid TrialReadingCriterionId { get; set; }
        public List<CancelSubjectAssignedDoctorCommand> CancelList { get; set; }

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



    public class SubjectAssignView
    {
        public Guid TrialId { get; set; }
        public Guid SiteId { get; set; }

        public Guid SubjectId { get; set; }

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


        public bool IsAssignedDoctorUser { get; set; }

        [JsonIgnore]
        public bool IsJudge { get; set; }

        public bool IsConfirmed => DoctorUserList.Where(t => IsJudge ? t.ArmEnum == Arm.JudgeArm : t.ArmEnum != Arm.JudgeArm).All(t => t.IsConfirmed)
            && DoctorUserList.Where(t => IsJudge ? t.ArmEnum == Arm.JudgeArm : t.ArmEnum != Arm.JudgeArm).Count() > 0;

        public List<Guid> DoctorUserIdList => DoctorUserList.Select(t => t.DoctorUserId).ToList();

        //.ForEach(t => t.HistoryDoctorList = TotalDoctorUserList.Where(c => (Guid?)t.Id == c.OrignalSubjectUserId).ToList())
        public List<AssignDoctorView> DoctorUserList => TotalDoctorUserList.Where(t => t.OrignalSubjectUserId == null).ToList()
           ;

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



    public class AssignDoctorView
    {
        public Guid Id { get; set; }
        public Guid DoctorUserId { get; set; }

        public string UserCode { get; set; }
        public string UserName { get; set; }
        public string FullName { get; set; }

        public string UserTypeShortName { get; set; }

        public DateTime? AssignTime { get; set; }

        public Arm ArmEnum { get; set; }

        public bool IsConfirmed { get; set; }

        //该属性有值 说明该医生被替换了 分配的时候 要过滤掉
        public Guid? OrignalSubjectUserId { get; set; }

        //public List<AssignDoctorView> HistoryDoctorList { get; set; }

    }



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

        public bool IsReAssign { get; set; }

        public List<Guid> SubjectIdList { get; set; }

        public bool IsJudgeDoctor { get; set; }

        public List<DoctorArm> DoctorUserIdArmList { get; set; } = new List<DoctorArm>();
    }

    public class DoctorArm
    {
        public Guid DoctorUserId { get; set; }

        public Arm ArmEnum { get; set; }
    }

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

        public bool IsJudgeDoctor { get; set; }

        public List<Guid> SubjectIdList { get; set; }
    }

    public class AutoAssignResultDTO
    {
        public Guid DoctorUserId { get; set; }

        public int PlanReadingRatio { get; set; }

        public List<SubjectArm> SubjectArmList { get; set; } = new List<SubjectArm>();

        public int SubjectCount { get; set; }

        public int Weight => (SubjectCount - SubjectArmList.Count) * PlanReadingRatio;

    }

    public class SubjectArm
    {
        public Guid SubjectId { get; set; }

        public Arm ArmEnum { get; set; }
    }


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

        public bool IsJudgeDoctor { get; set; }

        public List<Guid> SubjectIdList { get; set; } = new List<Guid>();
    }


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

        public bool IsJudgeDoctor { get; set; }

        public List<SubjectDoctorCommand> SubjectDoctorUserList { get; set; } = new List<SubjectDoctorCommand>();
    }

    public class SubjectDoctorCommand
    {
        public Guid SubjectId { get; set; }

        public List<DoctorArm> DoctorUserIdArmList { get; set; } = new List<DoctorArm>();
    }

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

        public bool IsJudgeDoctor { get; set; }
    }

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

        public Guid TrialId { get; set; }

        public Guid SubjectId { get; set; }

        public bool IsJudgeDoctor { get; set; }

        public Guid? DoctorUserId { get; set; }

        public TaskOptType TaskOptType { get; set; }

    }



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

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


    public class ApplyReReadingCommand
    {


        public List<Guid> TaskIdList { get; set; }

        public Guid TrialId { get; set; }

        public bool IsCopyOrigenalForms { get; set; }
        public bool IsCopyFollowForms { get; set; }

        public RequestReReadingType RequestReReadingType { get; set; }

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


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

        public List<ConfirmReReadingDTO> ConfirmReReadingList { get; set; }

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

    public class ConfirmReReadingDTO
    {
        [NotDefault]
        public Guid Id { get; set; }

        //重阅原始任务Id  重阅会产生新的任务 

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

    }


    public enum TaskOptType
    {
        Assign = 1,

        ReAssign = 2,

        Confirm = 3,

        CancelAssign = 4,
    }

}


