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

namespace IRaCIS.Core.Domain.Models
{
    ///<summary>
    ///VisitTask
    ///</summary>
    [Table("VisitTask")]
    public class VisitTask : Entity, IAuditUpdate, IAuditAdd
    {

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


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


        /// <summary>
        /// 任务类型
        /// </summary>
        public ReadingCategory ReadingCategory { get; set; }



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


        /// <summary>
        /// 分配时间
        /// </summary>
        public DateTime? AllocateTime { get; set; }

        public Guid SubjectId { get; set; }


        public int Code { get; set; }

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

        public bool IsUrgent { get; set; }

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

        /// <summary>
        /// 任务加急类型
        /// </summary>
        public string TaskUrgentRemake { get; set; } = string.Empty;

        /// <summary>
        /// 是否和编辑加急状态
        /// </summary>
        public bool IsCanEditUrgentState { get; set; } = true;

        /// <summary>
        /// 0 代表 单重阅片 产生的任务    否则就是双重  任务 1 任务  2 
        /// </summary>
        [Required]
        public Arm ArmEnum { get; set; }

        /// <summary>
        /// 分配状态
        /// </summary>
        public TaskAllocationState TaskAllocationState { get; set; }


        public TaskState TaskState { get; set; }


        /// <summary>
        /// 重阅状态
        /// </summary>
        public ReReadingApplyState ReReadingApplyState { get; set; }

        public Guid? DoctorUserId { get; set; }


        public Guid TrialReadingCriterionId { get; set; }

        [JsonIgnore]
        [ForeignKey("TrialReadingCriterionId")]
        public ReadingQuestionCriterionTrial TrialReadingCriterion { get; set; }



        [ForeignKey("DoctorUserId")]
        public User DoctorUser { get; set; }

        [ForeignKey("SouceReadModuleId")]
        public ReadModule ReadModule { get; set; }

        [ForeignKey("SourceSubjectVisitId")]
        public SubjectVisit SourceSubjectVisit { get; set; }
        [JsonIgnore]
        [ForeignKey("JudgeVisitTaskId")]
        public VisitTask JudgeVisitTask { get; set; }

        //public SubjectUser SujectArm { get; set; }

        [JsonIgnore]
        public Subject Subject { get; set; }



        [JsonIgnore]
        public List<TaskMedicalReview> TaskMedicalReviewList { get; set; }



        //排除一致性分析  因为souceVisitId 没值
        //public List<VisitTask> SameVisitTaskList { get; set; }

        //public List<VisitTask> SameSubjectVisiTaskList { get; set; }


        //public TaskAllocationRule DoctorTaskAllocationRule { get; set; }

        [JsonIgnore]
        public TaskMedicalReviewRule DoctorTaskMedicalReviewRule { get; set; }



        //裁判任务的Id
        public Guid? JudgeVisitTaskId { get; set; }

        //任务阅片状态
        public ReadingTaskState ReadingTaskState { get; set; }

        //签名时间
        public DateTime? SignTime { get; set; }

        public DateTime? SuggesteFinishedTime { get; set; }


        /// <summary>
        /// 是否是重阅产生的，方便过滤数据
        /// </summary>
        public bool IsReReadingCreate { get; set; }

        /// <summary>
        /// PM  对该任务进行了回退  影响的任务不设置
        /// </summary>
        public bool IsPMSetBack { get; set; }


        /// <summary> 裁判结果的任务ID </summary>
        public Guid? JudgeResultTaskId { get; set; }

        [ForeignKey("JudgeResultTaskId")]
        public VisitTask JudgeResultTask { get; set; }



        //随访任务号   取检查批次的号  计划外是 检查批次+0.1   裁判任务在检查批次任务上+0.002   全局任务在截止检查批次号上+0.03   肿瘤待定   
        public decimal VisitTaskNum { get; set; }

       

        /// <summary>
        /// 首次阅片时间
        /// </summary>
        public DateTime? FirstReadingTime { get; set; }

        /// <summary>
        /// 全局是否有更新
        /// </summary>
        public bool? IsGlobalHaveUpdate { get; set; }

        /// <summary>
        /// IR是否阅读临床数据
        /// </summary>
        public bool IsReadClinicalData { get; set; } = false;

        /// <summary>
        /// 关联的检查批次任务ID (当前任务是检查批次任务的话会有自己)
        /// </summary>
        public string RelatedVisitTaskIds { get; set; } = "[]";

        /// <summary>
        /// 关联的检查批次任务ID (当前任务是检查批次任务的话会有自己)集合
        /// </summary>
        [NotMapped]
        public List<Guid> RelatedVisitTaskIdList
        {
            get
            {

                try
                {

                    return JsonConvert.DeserializeObject<List<Guid>>(this.RelatedVisitTaskIds);
                }
                catch (Exception)
                {

                    return new List<Guid>();
                }

            }
        }

        /// <summary>
        /// 既往任务Id  不包括自己
        /// </summary>

        public string PastResultTaskIds { get; set; } = "[]";



        /// <summary>
        /// 既往任务Id  不包括自己集合
        /// </summary>
        [NotMapped]
        public List<Guid> PastResultTaskIdList
        {
            get
            {

                try
                {
                    return JsonConvert.DeserializeObject<List<Guid>>(this.PastResultTaskIds);
                }
                catch (Exception)
                {

                    return new List<Guid>();
                }

            }
        }

        #region 裁判任务特有

        [JsonIgnore]
        //对于裁判任务而言，触发裁判的列表
        public List<VisitTask> JudgeVisitList { get; set; }

        /// <summary>
        /// 裁判结果的备注
        /// </summary>
        public string JudgeResultRemark { get; set; } = string.Empty;
        /// <summary>
        /// 裁判结果的图片路径
        /// </summary>
        public string JudgeResultImagePath { get; set; } = string.Empty;

        #endregion


        #region  一致性分析的任务特有数据

        /// <summary>
        /// 阅片结果是否和原数据有差异
        /// </summary>
        public bool? IsAnalysisDiffToOriginalData { get; set; }

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

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

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

        public bool? IsSelfAnalysis { get; set; }

        public string BlindSubjectCode { get; set; } = string.Empty;
        public string BlindTrialSiteCode { get; set; } = string.Empty;

        //一致性分析规则Id  用于最后统计
        //public Guid? TaskConsistentRuleId { get; set; }

        /// <summary>
        /// 针对产生的一致性任务而言，这个字段存储的是原始任务
        /// </summary>
        public Guid? ConsistentAnalysisOriginalTaskId { get; set; }

        #endregion


        //临床数据

        public bool IsNeedClinicalDataSign { get; set; }

        public bool IsClinicalDataSign { get; set; }

        //前序任务需要签名 但是未签名
        public bool IsFrontTaskNeedSignButNotSign { get; set; }





        [JsonIgnore]

        public Trial Trial { get; set; }



        //影像质量  等等第一层级问题答案
        [JsonIgnore]
        public List<ReadingTaskQuestionAnswer> ReadingTaskQuestionAnswerList { get; set; } = new List<ReadingTaskQuestionAnswer>();


        //病灶表
        [JsonIgnore]
        public List<ReadingTableAnswerRowInfo> LesionList { get; set; } = new List<ReadingTableAnswerRowInfo>();

        //病灶答案表
        [JsonIgnore]
        public List<ReadingTableQuestionAnswer> LesionAnswerList { get; set; } = new List<ReadingTableQuestionAnswer>();



        //重阅或者退回影像的记录中间表
        [JsonIgnore]
        public List<TaskInfluence> TaskInfluenceList { get; set; } = new List<TaskInfluence>();


        [JsonIgnore]
        //对于全局任务而言 才可以用的  关联的检查批次阅片结果
        public List<ReadingGlobalTaskInfo> GlobalVisitResultList { get; set; } = new List<ReadingGlobalTaskInfo>();


        /// <summary>
        /// 裁判结果图片地址
        /// </summary>
        [NotMapped]
        public List<string> JudgeResultImagePathList
        {
            get
            {

                try
                {
                    return this.JudgeResultImagePath.Trim().Split(',').ToList();
                }
                catch (Exception)
                {

                    return new List<string>();
                }

            }
        }

    }
}
