diff --git a/IRC.Core.SCP/IRC.Core.SCP.csproj b/IRC.Core.SCP/IRC.Core.SCP.csproj index 1f41904c0..afc7bbd18 100644 --- a/IRC.Core.SCP/IRC.Core.SCP.csproj +++ b/IRC.Core.SCP/IRC.Core.SCP.csproj @@ -7,26 +7,25 @@ - + - - - - - - - + + + + + + - + true - + - - - + + + diff --git a/IRaCIS.Core.API/IRaCIS.Core.API.csproj b/IRaCIS.Core.API/IRaCIS.Core.API.csproj index 75a98c8da..d10c90832 100644 --- a/IRaCIS.Core.API/IRaCIS.Core.API.csproj +++ b/IRaCIS.Core.API/IRaCIS.Core.API.csproj @@ -75,12 +75,12 @@ - + - - + + - + diff --git a/IRaCIS.Core.API/_ServiceExtensions/EFSetup.cs b/IRaCIS.Core.API/_ServiceExtensions/EFSetup.cs index 9cabfec27..a58f759f1 100644 --- a/IRaCIS.Core.API/_ServiceExtensions/EFSetup.cs +++ b/IRaCIS.Core.API/_ServiceExtensions/EFSetup.cs @@ -41,7 +41,7 @@ namespace IRaCIS.Core.API var dbType = configuration.GetSection("ConnectionStrings:Db_Type").Value ; if (!string.IsNullOrWhiteSpace(dbType) && dbType == "pgsql") { - options.UseNpgsql(@"Host=106.14.89.110;Port=5432;Username=sa;Password=pgsql_pwd;Database=Test2_PG"); + options.UseNpgsql(configuration.GetSection("ConnectionStrings:RemoteNew").Value, contextOptionsBuilder => contextOptionsBuilder.EnableRetryOnFailure()); } else diff --git a/IRaCIS.Core.Application/IRaCIS.Core.Application.csproj b/IRaCIS.Core.Application/IRaCIS.Core.Application.csproj index 37ecfb7ae..4f27873ad 100644 --- a/IRaCIS.Core.Application/IRaCIS.Core.Application.csproj +++ b/IRaCIS.Core.Application/IRaCIS.Core.Application.csproj @@ -58,24 +58,24 @@ - + - - + + - + - + - + diff --git a/IRaCIS.Core.Application/IRaCIS.Core.Application.xml b/IRaCIS.Core.Application/IRaCIS.Core.Application.xml index 84de882fd..0e01fbff5 100644 --- a/IRaCIS.Core.Application/IRaCIS.Core.Application.xml +++ b/IRaCIS.Core.Application/IRaCIS.Core.Application.xml @@ -523,6 +523,25 @@ 系统模板文档配置表 + + + 开始时候一些帮助 比如根据配置的字典生成枚举 + + + + + + 开始时候一些帮助 比如根据配置的字典生成枚举 + + + + + + 根据配置的字典名生成后端枚举 + + + + 项目参与人员导出 @@ -15359,6 +15378,13 @@ + + + 用ef 实现之前视图的功能 + + + + 获取读片模块 //加了标准参数 diff --git a/IRaCIS.Core.Application/Service/Reading/Dto/GetReadModuleDto.cs b/IRaCIS.Core.Application/Service/Reading/Dto/GetReadModuleDto.cs index de5f048ee..e02ce0652 100644 --- a/IRaCIS.Core.Application/Service/Reading/Dto/GetReadModuleDto.cs +++ b/IRaCIS.Core.Application/Service/Reading/Dto/GetReadModuleDto.cs @@ -1,4 +1,5 @@ using IRaCIS.Core.Domain.Share; +using Newtonsoft.Json; using System; using System.Collections.Generic; using System.ComponentModel.DataAnnotations; @@ -263,13 +264,20 @@ namespace IRaCIS.Core.Application.Service.Reading.Dto public string? TrialSiteCode { get; set; } - public string? SiteCode { get; set; } public Guid? TrialSiteId { get; set; } public Guid? SubjectId { get; set; } - public List Data { get; set; } + public List Data { get; set; } = new List(); + + //public List Data => VisitData.Union(ReadMouduleData).ToList(); + + + [JsonIgnore] + public List VisitData { get; set; } = new List(); + [JsonIgnore] + public List ReadMouduleData { get; set; } = new List(); } diff --git a/IRaCIS.Core.Application/Service/Reading/ReadingPeriod/ReadModuleService.cs b/IRaCIS.Core.Application/Service/Reading/ReadingPeriod/ReadModuleService.cs index 4cc96de78..ddcc65d0b 100644 --- a/IRaCIS.Core.Application/Service/Reading/ReadingPeriod/ReadModuleService.cs +++ b/IRaCIS.Core.Application/Service/Reading/ReadingPeriod/ReadModuleService.cs @@ -9,6 +9,8 @@ using IRaCIS.Core.Application.ViewModel; using IRaCIS.Core.Infrastructure; using IRaCIS.Core.Application.Filter; using IRaCIS.Core.Domain.Models; +using Microsoft.Identity.Client; +using NPOI.SS.Formula.Functions; namespace IRaCIS.Application.Services { @@ -50,7 +52,7 @@ namespace IRaCIS.Application.Services && x.ReadingTaskState == ReadingTaskState.HaveSigned && x.ReadingCategory == ReadingCategory.Visit && x.SubjectId == inDto.SubjectId - && x.TaskState == TaskState.Effect).OrderByDescending(x => x.VisitTaskNum).Select(x=> x.VisitTaskNum).FirstOrDefaultAsync(); + && x.TaskState == TaskState.Effect).OrderByDescending(x => x.VisitTaskNum).Select(x => x.VisitTaskNum).FirstOrDefaultAsync(); var visitQuery = _subjectVisitRepository.Where(x => x.SubjectId == inDto.SubjectId && x.LatestScanDate != null && !x.IsLostVisit); @@ -91,97 +93,706 @@ namespace IRaCIS.Application.Services throw new BusinessValidationFailedException(_localizer["ReadModule_CRCConfirmCanNtoEdit"]); } - await _readModuleRepository.UpdatePartialFromQueryAsync(x => x.Id == inDto.Id, x => new ReadModule() { - SubjectVisitId=inDto.SubjectVisitIdId, - ModuleName=inDto.Name, + await _readModuleRepository.UpdatePartialFromQueryAsync(x => x.Id == inDto.Id, x => new ReadModule() + { + SubjectVisitId = inDto.SubjectVisitIdId, + ModuleName = inDto.Name, }); return await _readModuleRepository.SaveChangesAsync(); } /// - /// 获取读片模块 //加了标准参数 + /// 用ef 实现之前视图的功能 /// + /// + /// [HttpPost] - public async Task<(PageOutput,object)> GetReadModuleList(GetReadModuleDto dto) + public async Task>> GetReadModuleList(GetReadModuleDto inQuery) { - #region MyRegion - - if (dto.SortField.IsNullOrEmpty()) - { - dto.SortField = nameof(ReadModuleView.SubjectCode); - dto.Asc = true; - } - - dto.SortField = dto.Asc ? dto.SortField : dto.SortField + " desc"; - var subjectQuery = _readModuleViewRepository.Where(x => x.TrialReadingCriterionId == dto.TrialReadingCriterionId) - .WhereIf(dto.TrialId != null, x => x.TrialId == dto.TrialId) - .WhereIf(dto.SubjectId != null, x => x.SubjectId == dto.SubjectId) - .WhereIf(dto.TrialSiteCode != null && dto.TrialSiteCode != string.Empty, x => x.TrialSiteCode.Contains(dto.TrialSiteCode)) - .WhereIf(dto.SubjectCode != null && dto.SubjectCode != string.Empty, x => x.SubjectCode.Contains(dto.SubjectCode)) - .WhereIf(dto.ModuleType != null, x => x.ModuleType == dto.ModuleType) - .WhereIf(dto.CompleteClinicalData == CompleteClinicalDataEnum.NA, x => x.NeedSignClinicalDataCount == 0) - .WhereIf(dto.CompleteClinicalData == CompleteClinicalDataEnum.NotComplete, x => x.NeedSignClinicalDataCount != x.SignClinicalDataCount) - .WhereIf(dto.CompleteClinicalData == CompleteClinicalDataEnum.Complete, x => x.NeedSignClinicalDataCount != 0 && x.NeedSignClinicalDataCount == x.SignClinicalDataCount) - .WhereIf(dto.ReadingStatus != null, x => x.ReadingStatus == dto.ReadingStatus); - //.WhereIf(dto.Name != null, x => x.Name.Contains(dto.Name!)).OrderBy(x => x.SiteCode); - - var subjectIds = await subjectQuery.OrderBy(dto.SortField).Select(x => x.SubjectId).Distinct().Skip((dto.PageIndex - 1) * dto.PageSize).Take(dto.PageSize).ToListAsync(); - - List ReadModuleViewList = await subjectQuery.Where(x => subjectIds.Contains(x.SubjectId)).OrderBy(dto.SortField).ToListAsync(); - List getReadList = ReadModuleViewList.GroupBy(x => new { x.SubjectId, x.TrialSiteId, x.TrialSiteCode, x.SubjectCode }) - .Select(x => new GetReadModuleDtoOut() - { - TrialSiteCode = x.Key.TrialSiteCode, - TrialSiteId = x.Key.TrialSiteId, - SubjectCode = x.Key.SubjectCode, - SubjectId = x.Key.SubjectId, - Data = x.OrderBy(x=>x.ModuleType).ThenBy(x=>x.VisitNum).ToList(), - }).ToList(); - PageOutput pageOutput = new PageOutput() - { - PageSize = dto.PageSize, - CurrentPageData = getReadList, - PageIndex = dto.PageIndex, - TotalCount = await subjectQuery.Select(x => x.SubjectId).Distinct().CountAsync(), - }; - var maxcount = 0; - pageOutput.CurrentPageData.ForEach(x => - { - maxcount = maxcount < x.Data.Count ? x.Data.Count : maxcount; - }); - - - var criterionInfo = await _readingQuestionCriterionTrialRepository.Where(x => x.Id == dto.TrialReadingCriterionId).Select(x => new + var criterionInfo = await _readingQuestionCriterionTrialRepository.Where(t => t.Id == inQuery.TrialReadingCriterionId).Select(x => new { + x.CriterionName, + x.ReadingType, x.IsReadingTaskViewInOrder, x.IsOncologyReading, x.IsGlobalReading, x.IsReadingPeriod, x.ReadingInfoSignTime, }).FirstNotNullAsync(); - - return (pageOutput, new - { - MaxLength = maxcount, - IsReadingTaskViewInOrder= criterionInfo.IsReadingTaskViewInOrder, - IsClinicalReading = criterionInfo.IsOncologyReading, - // OnlyExistsMedicalHistory = !(await _clinicalDataTrialSetRepository.AnyAsync(x => x.TrialId == dto.TrialId && x.ClinicalDataSetName != "既往局部治疗史" && x.IsConfirm)), - IsExistsSubjectClinicalData= await _clinicalDataTrialSetRepository.AnyAsync(x => x.TrialId == dto.TrialId&&x.ClinicalDataLevel== ClinicalLevel.Subject && x.IsConfirm&&x.TrialClinicalDataSetCriteriaList.Any(y=>y.TrialReadingCriterionId== dto.TrialReadingCriterionId)), - IsExistsVisitClinicalData = await _clinicalDataTrialSetRepository.AnyAsync(x => x.TrialId == dto.TrialId && x.ClinicalDataLevel == ClinicalLevel.SubjectVisit && x.IsConfirm && x.TrialClinicalDataSetCriteriaList.Any(y => y.TrialReadingCriterionId == dto.TrialReadingCriterionId)), - IsExistsStudyClinicalData = await _clinicalDataTrialSetRepository.AnyAsync(x => x.TrialId == dto.TrialId && x.ClinicalDataLevel == ClinicalLevel.Study && x.IsConfirm && x.TrialClinicalDataSetCriteriaList.Any(y => y.TrialReadingCriterionId == dto.TrialReadingCriterionId)), - IsExistsReadingClinicalData = await _clinicalDataTrialSetRepository.AnyAsync(x => x.TrialId == dto.TrialId && x.ClinicalDataLevel == ClinicalLevel.ImageRead && x.IsConfirm && x.TrialClinicalDataSetCriteriaList.Any(y => y.TrialReadingCriterionId == dto.TrialReadingCriterionId)), - IsExistsOncologyReadClinicalData = await _clinicalDataTrialSetRepository.AnyAsync(x => x.TrialId == dto.TrialId && x.ClinicalDataLevel == ClinicalLevel.OncologyRead && x.IsConfirm && x.TrialClinicalDataSetCriteriaList.Any(y => y.TrialReadingCriterionId == dto.TrialReadingCriterionId)), - IsGlobalReading = criterionInfo.IsGlobalReading, - IsReadingPeriod=criterionInfo.IsReadingPeriod, - ReadingInfoSignTime=criterionInfo.ReadingInfoSignTime, - ExistClinicalData=await _clinicalDataTrialSetRepository.AnyAsync(x => x.IsConfirm && x.TrialClinicalDataSetCriteriaList.Any(y => y.TrialReadingCriterionId == dto.TrialReadingCriterionId)), - }) ; + + var readingType = (int)criterionInfo.ReadingType; + + var isFilterModuleType = inQuery.ModuleType != null; + var isFilterCompleteClinicalData = inQuery.CompleteClinicalData != null; + var isFilterReadingStatus = inQuery.ReadingStatus != null; + var isFilterName = !string.IsNullOrWhiteSpace(inQuery.Name); + + + #region 方式一 + + + + //var query = _subjectRepository.Where(t => t.TrialId == inQuery.TrialId) + // .WhereIf(inQuery.SubjectId != null, x => x.Id == inQuery.SubjectId) + // .WhereIf(!string.IsNullOrWhiteSpace(inQuery.TrialSiteCode), x => x.TrialSite.TrialSiteCode.Contains(inQuery.TrialSiteCode)) + // .WhereIf(!string.IsNullOrWhiteSpace(inQuery.SubjectCode), x => x.Code.Contains(inQuery.SubjectCode)) + + // .Select(t => new GetReadModuleDtoOut() + // { + // SubjectCode = t.Code, + // SubjectId = t.Id, + // TrialSiteCode = t.TrialSite.TrialSiteCode, + // TrialSiteId = t.TrialSiteId, + + // #region 分开不用union 在属性里面union + + // //访视要查询不失访的其次要查在 <= 截止访视的,截止访视没有就查这个受试者所有的 + // VisitData = t.SubjectVisitList.Where(t => t.IsLostVisit == false) + + // .Where(sv => t.FinalSubjectVisitId == null ? true : sv.VisitNum < t.LatestSubjectVisit.VisitNum).Select(sv => new ReadModuleView() + // { + // Id = sv.Id, + // CreateTime = sv.CreateTime, + // PDState = sv.PDState, + // IsBaseLine = sv.IsBaseLine, + // SubjectCode = sv.Subject.Code, + // IsEnrollmentConfirm = sv.IsEnrollmentConfirm, + // IsFinalVisit = sv.IsFinalVisit, + // SubjectId = sv.SubjectId, + // SubjectVisitId = sv.Id, + // IsUrgent = sv.IsUrgent, + // SubjectVisitName = sv.VisitName, + // IsVisit = true, + + // Name = sv.VisitName, + // TrialSiteId = sv.TrialSiteId, + // TrialSiteCode = sv.TrialSite.TrialSiteCode, + + // TrialId = sv.TrialId, + // VisitNum = sv.VisitNum, + // TrialReadingCriterionId = inQuery.TrialReadingCriterionId, + + // OutPlanPreviousVisitId = sv.OutPlanPreviousVisitId, + + // OutPlanPreviousVisitName = sv.OutPlanPreviousVisit.VisitName, + + // ModuleType = sv.InPlan ? ModuleTypeEnum.InPlanSubjectVisit : ModuleTypeEnum.OutPlanSubjectVisit, + + // //只有阅片期有 + // CutOffVisitId = null, + // CutOffVisitName = null, + // ReadingSetType = null, + // ReadModuleId = null, + // ReadModuleName = "", + + + // ///阅片状态 0 1 2 保持访视的,任务全做完了就是5 没完成就是4 否则就是3 + // ReadingStatus = sv.ReadingStatus < ReadingStatusEnum.TaskAllocate ? sv.ReadingStatus : + // (sv.VisitTaskList.Count(t => t.TaskState == TaskState.Effect && t.IsAnalysisCreate == false && t.ReadingTaskState == ReadingTaskState.HaveSigned + // && t.ReadingCategory != ReadingCategory.Judge && t.TrialReadingCriterionId == inQuery.TrialReadingCriterionId) == readingType ? ReadingStatusEnum.ReadCompleted : + // (sv.VisitTaskList.Count(t => t.TaskState == TaskState.Effect && t.IsAnalysisCreate == false && t.TaskAllocationState == TaskAllocationState.Allocated + // && t.ReadingCategory != ReadingCategory.Judge && t.TrialReadingCriterionId == inQuery.TrialReadingCriterionId) == readingType ? ReadingStatusEnum.ImageReading : ReadingStatusEnum.TaskAllocate)), + + + + // //是否是截止访视? + // IsCanChangeCutOffVisit = false, + + // //需要签名数量计算 基线包含subject+访视级别的 + // NeedSignClinicalDataCount = sv.Trial.TrialReadingCriterionList.Where(t => t.Id == inQuery.TrialReadingCriterionId).SelectMany(u => u.TrialClinicalDataSetCriterionList.Select(t => t.TrialClinicalDataSet)).Where(t => t.IsConfirm == true). + // Where(t => sv.IsBaseLine ? t.ClinicalDataLevel <= ClinicalLevel.SubjectVisit : t.ClinicalDataLevel == ClinicalLevel.SubjectVisit).Count() + // + (sv.Trial.TrialReadingCriterionList.Where(t => t.Id == inQuery.TrialReadingCriterionId).SelectMany(u => u.TrialClinicalDataSetCriterionList.Select(t => t.TrialClinicalDataSet)).Where(t => t.IsConfirm == true) + // .Any(t => t.ClinicalDataLevel == ClinicalLevel.Study) ? 1 : 0), + + // //签名的数量 + + // SignClinicalDataCount = sv.ReadingClinicalDataList.Where(t => t.IsSign == true && t.ClinicalDataTrialSet.ClinicalDataLevel != ClinicalLevel.Study && + // t.ClinicalDataTrialSet.TrialClinicalDataSetCriteriaList.Any(t => t.TrialReadingCriterionId == inQuery.TrialReadingCriterionId)).Count() + // + + // (sv.SubmitState == SubmitStateEnum.Submitted && sv.Trial.ClinicalDataTrialSetList + // .Any(t => t.ClinicalDataLevel == ClinicalLevel.Study && t.TrialClinicalDataSetCriteriaList.Any(u => u.TrialReadingCriterionId == inQuery.TrialReadingCriterionId)) ? 1 : 0), + + + + + + // //标准名 应该是可以不查询的,只要保证逻辑正确 + // CriterionName = criterionInfo.CriterionName + + + // }) + + // .Where(t => isFilterModuleType ? t.ModuleType == inQuery.ModuleType : true) + // .Where(t => isFilterName ? t.Name == inQuery.Name : true) + // .Where(t => isFilterReadingStatus ? t.ReadingStatus == inQuery.ReadingStatus : true) + // .Where(t => isFilterCompleteClinicalData && inQuery.CompleteClinicalData == CompleteClinicalDataEnum.NA ? t.NeedSignClinicalDataCount == 0 : true) + // .Where(t => isFilterCompleteClinicalData && inQuery.CompleteClinicalData == CompleteClinicalDataEnum.NotComplete ? t.NeedSignClinicalDataCount != t.SignClinicalDataCount : true) + // .Where(t => isFilterCompleteClinicalData && inQuery.CompleteClinicalData == CompleteClinicalDataEnum.Complete ? t.NeedSignClinicalDataCount == t.SignClinicalDataCount : true) + + // //搜索条件报错 + // //.WhereIf(inQuery.ModuleType != null, t => t.ModuleType == inQuery.ModuleType) + // //.WhereIf(inQuery.CompleteClinicalData == CompleteClinicalDataEnum.NA, x => x.NeedSignClinicalDataCount == 0) + // //.WhereIf(inQuery.CompleteClinicalData == CompleteClinicalDataEnum.NotComplete, x => x.NeedSignClinicalDataCount != x.SignClinicalDataCount) + // //.WhereIf(inQuery.CompleteClinicalData == CompleteClinicalDataEnum.Complete, x => x.NeedSignClinicalDataCount != 0 && x.NeedSignClinicalDataCount == x.SignClinicalDataCount) + // //.WhereIf(inQuery.ReadingStatus != null, x => x.ReadingStatus == inQuery.ReadingStatus) + // .ToList(), + + // //阅片期 + // ReadMouduleData = t.ReadModuleList.Select(rm => new ReadModuleView() + // { + // Id = rm.Id, + // CreateTime = rm.CreateTime, + // PDState = PDStateEnum.None, + // IsBaseLine = false, + // SubjectCode = rm.SubjectVisit.Subject.Code, + // IsEnrollmentConfirm = false, + // IsFinalVisit = false, + // SubjectId = rm.SubjectId, + // SubjectVisitId = rm.SubjectVisitId, + // IsUrgent = rm.SubjectVisit.IsUrgent, + // SubjectVisitName = rm.SubjectVisit.VisitName, + // IsVisit = false, + + // Name = rm.ModuleName, + // TrialSiteId = rm.Subject.TrialSiteId, + // TrialSiteCode = rm.Subject.TrialSite.TrialSiteCode, + + // TrialId = rm.TrialId, + // VisitNum = rm.SubjectVisit.VisitNum, + // TrialReadingCriterionId = inQuery.TrialReadingCriterionId, + + // OutPlanPreviousVisitId = null, + + // OutPlanPreviousVisitName = null, + + // ModuleType = rm.ModuleType, + + // //只有阅片期有 + // CutOffVisitId = rm.SubjectVisit.Id, + // CutOffVisitName = rm.SubjectVisit.VisitName, + // ReadingSetType = null, + + // //之前视图返回的null 应该是没用的? + // ReadModuleId = rm.Id, + // ReadModuleName = rm.ModuleName, + + // //是否是截止访视? + // IsCanChangeCutOffVisit = false, + + + // ///阅片状态 0 1 2 保持访视的,任务全做完了就是5 没完成就是4 否则就是3 + // ReadingStatus = rm.ReadingStatus < ReadingStatusEnum.TaskAllocate ? rm.ReadingStatus : + // (rm.ModuleTaskList.Count(t => t.TaskState == TaskState.Effect && t.IsAnalysisCreate == false && t.ReadingTaskState == ReadingTaskState.HaveSigned + // && t.ReadingCategory != ReadingCategory.Judge && t.TrialReadingCriterionId == inQuery.TrialReadingCriterionId) == readingType ? ReadingStatusEnum.ReadCompleted : + + // (rm.ModuleTaskList.Count(t => t.TaskState == TaskState.Effect && t.IsAnalysisCreate == false && t.TaskAllocationState == TaskAllocationState.Allocated + // && t.ReadingCategory != ReadingCategory.Judge && t.TrialReadingCriterionId == inQuery.TrialReadingCriterionId) == readingType ? ReadingStatusEnum.ImageReading : ReadingStatusEnum.TaskAllocate + // ) + // ), + + + + + + // ////需要签名数量计算 基线包含subject+访视级别的 + // NeedSignClinicalDataCount = rm.Trial.TrialReadingCriterionList.Where(t => t.Id == inQuery.TrialReadingCriterionId).SelectMany(u => u.TrialClinicalDataSetCriterionList.Select(z => z.TrialClinicalDataSet)) + // .Where(t => t.IsConfirm == true && t.UploadRole == UploadRole.PM && (t.ClinicalDataLevel == ClinicalLevel.SubjectVisit || t.ClinicalDataLevel == ClinicalLevel.ImageRead || t.ClinicalDataLevel == ClinicalLevel.OncologyRead)).Count() + // + + // (rm.Trial.TrialReadingCriterionList.Where(t => t.Id == inQuery.TrialReadingCriterionId).SelectMany(u => u.TrialClinicalDataSetCriterionList.Select(z => z.TrialClinicalDataSet)) + // .Where(t => t.IsConfirm == true && t.UploadRole == UploadRole.CRC && + // (t.ClinicalDataLevel == ClinicalLevel.SubjectVisit || t.ClinicalDataLevel == ClinicalLevel.ImageRead || t.ClinicalDataLevel == ClinicalLevel.OncologyRead)).Any() ? 1 : 0) + // , + + // //签名的数量 + + // SignClinicalDataCount = rm.ReadingClinicalDataList.Where(t => t.IsSign == true && t.ClinicalDataTrialSet.UploadRole == UploadRole.PM && + // t.ClinicalDataTrialSet.TrialClinicalDataSetCriteriaList.Any(t => t.TrialReadingCriterionId == inQuery.TrialReadingCriterionId)).Count() + // + + // (rm.IsPMConfirm ? 1 : 0), + + + // //标准名 应该是可以不查询的,只要保证逻辑正确 + // CriterionName = criterionInfo.CriterionName + + // }) + // .Where(t => isFilterModuleType ? t.ModuleType == inQuery.ModuleType : true) + // .Where(t => isFilterName ? t.Name == inQuery.Name : true) + // .Where(t => isFilterReadingStatus ? t.ReadingStatus == inQuery.ReadingStatus : true) + // .Where(t => isFilterCompleteClinicalData && inQuery.CompleteClinicalData == CompleteClinicalDataEnum.NA ? t.NeedSignClinicalDataCount == 0 : true) + // .Where(t => isFilterCompleteClinicalData && inQuery.CompleteClinicalData == CompleteClinicalDataEnum.NotComplete ? t.NeedSignClinicalDataCount != t.SignClinicalDataCount : true) + // .Where(t => isFilterCompleteClinicalData && inQuery.CompleteClinicalData == CompleteClinicalDataEnum.Complete ? t.NeedSignClinicalDataCount == t.SignClinicalDataCount : true) + // .ToList() + + // #endregion + + // #region 用union 报错不行的 + + // ////访视要查询不失访的其次要查在 <= 截止访视的,截止访视没有就查这个受试者所有的 + // //Data = t.SubjectVisitList.Where(t => t.IsLostVisit == false) + // //.Where(sv => t.FinalSubjectVisitId == null ? true : sv.VisitNum < t.LatestSubjectVisit.VisitNum).Select(sv => new ReadModuleView() + // //{ + // // Id = sv.Id, + // // CreateTime = sv.CreateTime, + // // PDState = sv.PDState, + // // IsBaseLine = sv.IsBaseLine, + // // SubjectCode = sv.Subject.Code, + // // IsEnrollmentConfirm = sv.IsEnrollmentConfirm, + // // IsFinalVisit = sv.IsFinalVisit, + // // SubjectId = sv.SubjectId, + // // SubjectVisitId = sv.Id, + // // IsUrgent = sv.IsUrgent, + // // SubjectVisitName = sv.VisitName, + // // IsVisit = true, + + // // Name = sv.VisitName, + // // TrialSiteId = sv.TrialSiteId, + // // TrialSiteCode = sv.TrialSite.TrialSiteCode, + + // // TrialId = sv.TrialId, + // // VisitNum = sv.VisitNum, + // // TrialReadingCriterionId = inQuery.TrialReadingCriterionId, + + // // OutPlanPreviousVisitId = sv.OutPlanPreviousVisitId, + + // // OutPlanPreviousVisitName = sv.OutPlanPreviousVisit.VisitName, + + // // ModuleType = sv.InPlan ? ModuleTypeEnum.InPlanSubjectVisit : ModuleTypeEnum.OutPlanSubjectVisit, + + // // //只有阅片期有 + // // CutOffVisitId = null, + // // CutOffVisitName = null, + // // ReadingSetType = null, + // // ReadModuleId = null, + // // ReadModuleName = "", + + + // // ///阅片状态 0 1 2 保持访视的,任务全做完了就是5 没完成就是4 否则就是3 + // // ReadingStatus = sv.ReadingStatus < ReadingStatusEnum.TaskAllocate ? sv.ReadingStatus : + // // (sv.VisitTaskList.Count(t => t.TaskState == TaskState.Effect && t.IsAnalysisCreate == false && t.ReadingTaskState == ReadingTaskState.HaveSigned + // // && t.ReadingCategory != ReadingCategory.Judge && t.TrialReadingCriterionId == inQuery.TrialReadingCriterionId) == readingType ? ReadingStatusEnum.ReadCompleted : + // // (sv.VisitTaskList.Count(t => t.TaskState == TaskState.Effect && t.IsAnalysisCreate == false && t.TaskAllocationState == TaskAllocationState.Allocated + // // && t.ReadingCategory != ReadingCategory.Judge && t.TrialReadingCriterionId == inQuery.TrialReadingCriterionId) == readingType ? ReadingStatusEnum.ImageReading : ReadingStatusEnum.TaskAllocate)), + + + + // // //是否是截止访视? + // // IsCanChangeCutOffVisit = false, + + // // //需要签名数量计算 基线包含subject+访视级别的 + // // NeedSignClinicalDataCount = sv.Trial.TrialReadingCriterionList.Where(t => t.Id == inQuery.TrialReadingCriterionId).SelectMany(u => u.TrialClinicalDataSetCriterionList).Where(t => t.TrialClinicalDataSet.IsConfirm == true). + // // Where(t => sv.IsBaseLine ? t.TrialClinicalDataSet.ClinicalDataLevel <= ClinicalLevel.SubjectVisit : t.TrialClinicalDataSet.ClinicalDataLevel == ClinicalLevel.SubjectVisit).Count() + // // + (sv.Trial.TrialReadingCriterionList.Where(t => t.Id == inQuery.TrialReadingCriterionId).SelectMany(u => u.TrialClinicalDataSetCriterionList).Where(t => t.TrialClinicalDataSet.IsConfirm == true) + // // .Any(t => t.TrialClinicalDataSet.ClinicalDataLevel == ClinicalLevel.Study) ? 1 : 0), + + // // //签名的数量 + + // // SignClinicalDataCount = sv.ReadingClinicalDataList.Where(t => t.IsSign == true && t.ClinicalDataTrialSet.ClinicalDataLevel != ClinicalLevel.Study && + // // t.ClinicalDataTrialSet.TrialClinicalDataSetCriteriaList.Any(t => t.TrialReadingCriterionId == inQuery.TrialReadingCriterionId)).Count() + // // + + // // (sv.SubmitState == SubmitStateEnum.Submitted && sv.Trial.ClinicalDataTrialSetList + // // .Any(t => t.ClinicalDataLevel == ClinicalLevel.Study && t.TrialClinicalDataSetCriteriaList.Any(u => u.TrialReadingCriterionId == inQuery.TrialReadingCriterionId)) ? 1 : 0), + + + + + + // // //标准名 应该是可以不查询的,只要保证逻辑正确 + // // CriterionName = criterionInfo.CriterionName + + + // //}) + // //.Union(t.ReadModuleList.AsQueryable().Select(rm => new ReadModuleView() + // //{ + // // Id = rm.Id, + // // CreateTime = rm.CreateTime, + // // PDState = PDStateEnum.None, + // // IsBaseLine = false, + // // SubjectCode = rm.SubjectVisit.Subject.Code, + // // IsEnrollmentConfirm = false, + // // IsFinalVisit = false, + // // SubjectId = rm.SubjectId, + // // SubjectVisitId = rm.SubjectVisitId, + // // IsUrgent = rm.SubjectVisit.IsUrgent, + // // SubjectVisitName = rm.SubjectVisit.VisitName, + // // IsVisit = false, + + // // Name = rm.ModuleName, + // // TrialSiteId = rm.Subject.TrialSiteId, + // // TrialSiteCode = rm.Subject.TrialSite.TrialSiteCode, + + // // TrialId = rm.TrialId, + // // VisitNum = rm.SubjectVisit.VisitNum, + // // TrialReadingCriterionId = inQuery.TrialReadingCriterionId, + + // // OutPlanPreviousVisitId = null, + + // // OutPlanPreviousVisitName = null, + + // // ModuleType = rm.ModuleType, + + // // //只有阅片期有 + // // CutOffVisitId = rm.SubjectVisit.Id, + // // CutOffVisitName = rm.SubjectVisit.VisitName, + // // ReadingSetType = null, + + // // //之前视图返回的null 应该是没用的? + // // ReadModuleId = rm.Id, + // // ReadModuleName = rm.ModuleName, + + // // //是否是截止访视? + // // IsCanChangeCutOffVisit = false, + + + // // ///阅片状态 0 1 2 保持访视的,任务全做完了就是5 没完成就是4 否则就是3 + // // ReadingStatus = rm.ReadingStatus < ReadingStatusEnum.TaskAllocate ? rm.ReadingStatus : + // // (rm.ModuleTaskList.Count(t => t.TaskState == TaskState.Effect && t.IsAnalysisCreate == false && t.ReadingTaskState == ReadingTaskState.HaveSigned + // // && t.ReadingCategory != ReadingCategory.Judge && t.TrialReadingCriterionId == inQuery.TrialReadingCriterionId) == readingType ? ReadingStatusEnum.ReadCompleted : + + // // (rm.ModuleTaskList.Count(t => t.TaskState == TaskState.Effect && t.IsAnalysisCreate == false && t.TaskAllocationState == TaskAllocationState.Allocated + // // && t.ReadingCategory != ReadingCategory.Judge && t.TrialReadingCriterionId == inQuery.TrialReadingCriterionId) == readingType ? ReadingStatusEnum.ImageReading : ReadingStatusEnum.TaskAllocate + // // ) + // // ), + + + + + + // // //需要签名数量计算 基线包含subject+访视级别的 + // // NeedSignClinicalDataCount = rm.Trial.TrialReadingCriterionList.Where(t => t.Id == inQuery.TrialReadingCriterionId).SelectMany(u => u.TrialClinicalDataSetCriterionList.Select(z => z.TrialClinicalDataSet)) + // // .Where(t => t.IsConfirm == true && t.UploadRole == UploadRole.PM && (t.ClinicalDataLevel == ClinicalLevel.SubjectVisit || t.ClinicalDataLevel == ClinicalLevel.ImageRead || t.ClinicalDataLevel == ClinicalLevel.OncologyRead)).Count() + // // + + // // (rm.Trial.TrialReadingCriterionList.Where(t => t.Id == inQuery.TrialReadingCriterionId).SelectMany(u => u.TrialClinicalDataSetCriterionList.Select(z => z.TrialClinicalDataSet)) + // // .Where(t => t.IsConfirm == true && t.UploadRole == UploadRole.CRC && + // // (t.ClinicalDataLevel == ClinicalLevel.SubjectVisit || t.ClinicalDataLevel == ClinicalLevel.ImageRead || t.ClinicalDataLevel == ClinicalLevel.OncologyRead)).Any() ? 1 : 0) + // // , + + // // //签名的数量 + + // // SignClinicalDataCount = rm.ReadingClinicalDataList.Where(t => t.IsSign == true && t.ClinicalDataTrialSet.UploadRole == UploadRole.PM && + // // t.ClinicalDataTrialSet.TrialClinicalDataSetCriteriaList.Any(t => t.TrialReadingCriterionId == inQuery.TrialReadingCriterionId)).Count() + // // + + // // (rm.IsPMConfirm ? 1 : 0), + + + // // //标准名 应该是可以不查询的,只要保证逻辑正确 + // // CriterionName = criterionInfo.CriterionName + + // //})).ToList() + + // #endregion + + + + + + + // }); + + + //var pageList = await query/*.Where(t=> (t.VisitData.Count + t.ReadMouduleData.Count)>0)*//*.AsSplitQuery()*/ + // .ToPagedListAsync(inQuery, nameof(GetReadModuleDtoOut.SubjectCode)); #endregion + + #region 方式二 + + var subjectVisitQuery = _subjectVisitRepository.Where(t => t.TrialId == inQuery.TrialId).Where(t => t.IsLostVisit == false) + .Where(sv => sv.Subject.FinalSubjectVisitId == null ? true : sv.VisitNum < sv.Subject.LatestSubjectVisit.VisitNum).Select(sv => new ReadModuleView() + { + Id = sv.Id, + CreateTime = sv.CreateTime, + PDState = sv.PDState, + IsBaseLine = sv.IsBaseLine, + SubjectCode = sv.Subject.Code, + IsEnrollmentConfirm = sv.IsEnrollmentConfirm, + IsFinalVisit = sv.IsFinalVisit, + SubjectId = sv.SubjectId, + SubjectVisitId = sv.Id, + IsUrgent = sv.IsUrgent, + SubjectVisitName = sv.VisitName, + IsVisit = true, + + Name = sv.VisitName, + TrialSiteId = sv.TrialSiteId, + TrialSiteCode = sv.TrialSite.TrialSiteCode, + + TrialId = sv.TrialId, + VisitNum = sv.VisitNum, + TrialReadingCriterionId = inQuery.TrialReadingCriterionId, + + OutPlanPreviousVisitId = sv.OutPlanPreviousVisitId, + + OutPlanPreviousVisitName = sv.OutPlanPreviousVisit.VisitName, + + ModuleType = sv.InPlan ? ModuleTypeEnum.InPlanSubjectVisit : ModuleTypeEnum.OutPlanSubjectVisit, + + //只有阅片期有 + CutOffVisitId = null, + CutOffVisitName = null, + ReadingSetType = null, + ReadModuleId = null, + ReadModuleName = "", + + + ///阅片状态 0 1 2 保持访视的,任务全做完了就是5 没完成就是4 否则就是3 + ReadingStatus = sv.ReadingStatus < ReadingStatusEnum.TaskAllocate ? sv.ReadingStatus : + (sv.VisitTaskList.Count(t => t.TaskState == TaskState.Effect && t.IsAnalysisCreate == false && t.ReadingTaskState == ReadingTaskState.HaveSigned + && t.ReadingCategory != ReadingCategory.Judge && t.TrialReadingCriterionId == inQuery.TrialReadingCriterionId) == readingType ? ReadingStatusEnum.ReadCompleted : + (sv.VisitTaskList.Count(t => t.TaskState == TaskState.Effect && t.IsAnalysisCreate == false && t.TaskAllocationState == TaskAllocationState.Allocated + && t.ReadingCategory != ReadingCategory.Judge && t.TrialReadingCriterionId == inQuery.TrialReadingCriterionId) == readingType ? ReadingStatusEnum.ImageReading : ReadingStatusEnum.TaskAllocate)), + + + + //是否是截止访视? + IsCanChangeCutOffVisit = false, + + //需要签名数量计算 基线包含subject+访视级别的 + NeedSignClinicalDataCount = sv.Trial.TrialReadingCriterionList.Where(t => t.Id == inQuery.TrialReadingCriterionId).SelectMany(u => u.TrialClinicalDataSetCriterionList.Select(t => t.TrialClinicalDataSet)).Where(t => t.IsConfirm == true). + Where(t => sv.IsBaseLine ? t.ClinicalDataLevel <= ClinicalLevel.SubjectVisit : t.ClinicalDataLevel == ClinicalLevel.SubjectVisit).Count() + + (sv.Trial.TrialReadingCriterionList.Where(t => t.Id == inQuery.TrialReadingCriterionId).SelectMany(u => u.TrialClinicalDataSetCriterionList.Select(t => t.TrialClinicalDataSet)).Where(t => t.IsConfirm == true) + .Any(t => t.ClinicalDataLevel == ClinicalLevel.Study) ? 1 : 0), + + //签名的数量 + + SignClinicalDataCount = sv.ReadingClinicalDataList.Where(t => t.IsSign == true && t.ClinicalDataTrialSet.ClinicalDataLevel != ClinicalLevel.Study && + t.ClinicalDataTrialSet.TrialClinicalDataSetCriteriaList.Any(t => t.TrialReadingCriterionId == inQuery.TrialReadingCriterionId)).Count() + + + (sv.SubmitState == SubmitStateEnum.Submitted && sv.Trial.ClinicalDataTrialSetList + .Any(t => t.ClinicalDataLevel == ClinicalLevel.Study && t.TrialClinicalDataSetCriteriaList.Any(u => u.TrialReadingCriterionId == inQuery.TrialReadingCriterionId)) ? 1 : 0), + + + + + + //标准名 应该是可以不查询的,只要保证逻辑正确 + CriterionName = criterionInfo.CriterionName + + + }); + + var readMouduleQuery = _readModuleRepository.Where(t => t.TrialId == inQuery.TrialId && t.TrialReadingCriterionId==inQuery.TrialReadingCriterionId) + .Select(rm => new ReadModuleView() + { + Id = rm.Id, + CreateTime = rm.CreateTime, + PDState = PDStateEnum.None, + IsBaseLine = false, + SubjectCode = rm.SubjectVisit.Subject.Code, + IsEnrollmentConfirm = false, + IsFinalVisit = false, + SubjectId = rm.SubjectId, + SubjectVisitId = rm.SubjectVisitId, + IsUrgent = rm.SubjectVisit.IsUrgent, + SubjectVisitName = rm.SubjectVisit.VisitName, + IsVisit = false, + + Name = rm.ModuleName, + TrialSiteId = rm.Subject.TrialSiteId, + TrialSiteCode = rm.Subject.TrialSite.TrialSiteCode, + + TrialId = rm.TrialId, + VisitNum = rm.SubjectVisit.VisitNum, + TrialReadingCriterionId = rm.TrialReadingCriterionId, + + OutPlanPreviousVisitId = null, + + OutPlanPreviousVisitName = null, + + ModuleType = rm.ModuleType, + + //只有阅片期有 + CutOffVisitId = rm.SubjectVisit.Id, + CutOffVisitName = rm.SubjectVisit.VisitName, + ReadingSetType = null, + + //之前视图返回的null 应该是没用的? + ReadModuleId = rm.Id, + ReadModuleName = rm.ModuleName, + + //阅片期切换访视 限制(1、阅片期访视已完成了任务不能,如果本身是肿瘤学不能,或者本身是全局后续有肿瘤学) + IsCanChangeCutOffVisit = !(rm.ModuleTaskList.Any(t => t.TaskState == TaskState.Effect) && rm.ReadingSetType == ReadingSetType.TumorReading && + rm.SubjectVisit.ReadModuleList.Any(t => t.ReadingSetType == ReadingSetType.TumorReading)), + + + ///阅片状态 0 1 2 保持访视的,任务全做完了就是5 没完成就是4 否则就是3 + ReadingStatus = rm.ReadingStatus < ReadingStatusEnum.TaskAllocate ? rm.ReadingStatus : + (rm.ModuleTaskList.Count(t => t.TaskState == TaskState.Effect && t.IsAnalysisCreate == false && t.ReadingTaskState == ReadingTaskState.HaveSigned + && t.ReadingCategory != ReadingCategory.Judge && t.TrialReadingCriterionId == inQuery.TrialReadingCriterionId) == readingType ? ReadingStatusEnum.ReadCompleted : + + (rm.ModuleTaskList.Count(t => t.TaskState == TaskState.Effect && t.IsAnalysisCreate == false && t.TaskAllocationState == TaskAllocationState.Allocated + && t.ReadingCategory != ReadingCategory.Judge && t.TrialReadingCriterionId == inQuery.TrialReadingCriterionId) == readingType ? ReadingStatusEnum.ImageReading : ReadingStatusEnum.TaskAllocate + ) + ), + + + + + + ////需要签名数量计算 基线包含subject+访视级别的 + NeedSignClinicalDataCount = rm.Trial.TrialReadingCriterionList.Where(t => t.Id == inQuery.TrialReadingCriterionId).SelectMany(u => u.TrialClinicalDataSetCriterionList.Select(z => z.TrialClinicalDataSet)) + .Where(t => t.IsConfirm == true && t.UploadRole == UploadRole.PM && (rm.ReadingSetType == ReadingSetType.ImageReading ? t.ClinicalDataLevel == ClinicalLevel.ImageRead : t.ClinicalDataLevel == ClinicalLevel.OncologyRead)).Count() + + + (rm.Trial.TrialReadingCriterionList.Where(t => t.Id == inQuery.TrialReadingCriterionId).SelectMany(u => u.TrialClinicalDataSetCriterionList.Select(z => z.TrialClinicalDataSet)) + .Where(t => t.IsConfirm == true && t.UploadRole == UploadRole.CRC && + (rm.ReadingSetType == ReadingSetType.ImageReading ? t.ClinicalDataLevel == ClinicalLevel.ImageRead : t.ClinicalDataLevel == ClinicalLevel.OncologyRead)).Any() ? 1 : 0) + , + + //签名的数量 + + SignClinicalDataCount = rm.ReadingClinicalDataList.Where(t => t.IsSign == true && t.ClinicalDataTrialSet.UploadRole == UploadRole.PM && + t.ClinicalDataTrialSet.TrialClinicalDataSetCriteriaList.Any(t => t.TrialReadingCriterionId == inQuery.TrialReadingCriterionId)).Count() + + + (rm.IsPMConfirm ? 1 : 0), + + + //标准名 应该是可以不查询的,只要保证逻辑正确 + CriterionName = criterionInfo.CriterionName + + }); + + + var query = subjectVisitQuery.Union(readMouduleQuery) + .WhereIf(inQuery.SubjectId != null, x => x.Id == inQuery.SubjectId) + .WhereIf(!string.IsNullOrWhiteSpace(inQuery.TrialSiteCode), x => x.TrialSiteCode.Contains(inQuery.TrialSiteCode)) + .WhereIf(!string.IsNullOrWhiteSpace(inQuery.SubjectCode), x => x.SubjectCode.Contains(inQuery.SubjectCode)) + .WhereIf(isFilterModuleType, t => t.ModuleType == inQuery.ModuleType) + .WhereIf(isFilterName, t => t.Name == inQuery.Name) + .WhereIf(isFilterReadingStatus, t => t.ReadingStatus == inQuery.ReadingStatus) + .WhereIf(isFilterCompleteClinicalData && inQuery.CompleteClinicalData == CompleteClinicalDataEnum.NA, t => t.NeedSignClinicalDataCount == 0) + .WhereIf(isFilterCompleteClinicalData && inQuery.CompleteClinicalData == CompleteClinicalDataEnum.NotComplete, t => t.NeedSignClinicalDataCount != t.SignClinicalDataCount) + .WhereIf(isFilterCompleteClinicalData && inQuery.CompleteClinicalData == CompleteClinicalDataEnum.Complete, t => t.NeedSignClinicalDataCount == t.SignClinicalDataCount); + + inQuery.SortField = string.IsNullOrWhiteSpace(inQuery.SortField) ? nameof(ReadModuleView.SubjectCode) : inQuery.SortField; + + var subjectIdQuery = query.OrderBy(inQuery.SortField).Select(x => x.SubjectId).Distinct(); + var subjectIds = await subjectIdQuery.Skip((inQuery.PageIndex - 1) * inQuery.PageSize).Take(inQuery.PageSize).ToListAsync(); + var subjectCount = subjectIdQuery.Count(); + + var viewList = await query.Where(x => subjectIds.Contains(x.SubjectId)).SortToListAsync(inQuery); + + var list = viewList.GroupBy(x => new { x.SubjectId, x.TrialSiteId, x.TrialSiteCode, x.SubjectCode }) + .Select(x => new GetReadModuleDtoOut() + { + TrialSiteCode = x.Key.TrialSiteCode, + TrialSiteId = x.Key.TrialSiteId, + SubjectCode = x.Key.SubjectCode, + SubjectId = x.Key.SubjectId, + Data = x.OrderBy(x => x.ModuleType).ThenBy(x => x.VisitNum).ToList(), + }).ToList(); + + var pageOutput = new PageOutput() + { + PageSize = inQuery.PageSize, + CurrentPageData = list, + PageIndex = inQuery.PageIndex, + TotalCount = subjectCount, + }; + + #endregion + + return ResponseOutput.Ok(pageOutput, new + { + MaxLength = pageOutput.CurrentPageData.MaxOrDefault(t => t.Data.Count(), 0), + IsReadingTaskViewInOrder = criterionInfo.IsReadingTaskViewInOrder, + IsClinicalReading = criterionInfo.IsOncologyReading, + // OnlyExistsMedicalHistory = !(await _clinicalDataTrialSetRepository.AnyAsync(x => x.TrialId == dto.TrialId && x.ClinicalDataSetName != "既往局部治疗史" && x.IsConfirm)), + IsExistsSubjectClinicalData = await _clinicalDataTrialSetRepository.AnyAsync(x => x.TrialId == inQuery.TrialId && x.ClinicalDataLevel == ClinicalLevel.Subject && x.IsConfirm && x.TrialClinicalDataSetCriteriaList.Any(y => y.TrialReadingCriterionId == inQuery.TrialReadingCriterionId)), + IsExistsVisitClinicalData = await _clinicalDataTrialSetRepository.AnyAsync(x => x.TrialId == inQuery.TrialId && x.ClinicalDataLevel == ClinicalLevel.SubjectVisit && x.IsConfirm && x.TrialClinicalDataSetCriteriaList.Any(y => y.TrialReadingCriterionId == inQuery.TrialReadingCriterionId)), + IsExistsStudyClinicalData = await _clinicalDataTrialSetRepository.AnyAsync(x => x.TrialId == inQuery.TrialId && x.ClinicalDataLevel == ClinicalLevel.Study && x.IsConfirm && x.TrialClinicalDataSetCriteriaList.Any(y => y.TrialReadingCriterionId == inQuery.TrialReadingCriterionId)), + IsExistsReadingClinicalData = await _clinicalDataTrialSetRepository.AnyAsync(x => x.TrialId == inQuery.TrialId && x.ClinicalDataLevel == ClinicalLevel.ImageRead && x.IsConfirm && x.TrialClinicalDataSetCriteriaList.Any(y => y.TrialReadingCriterionId == inQuery.TrialReadingCriterionId)), + IsExistsOncologyReadClinicalData = await _clinicalDataTrialSetRepository.AnyAsync(x => x.TrialId == inQuery.TrialId && x.ClinicalDataLevel == ClinicalLevel.OncologyRead && x.IsConfirm && x.TrialClinicalDataSetCriteriaList.Any(y => y.TrialReadingCriterionId == inQuery.TrialReadingCriterionId)), + IsGlobalReading = criterionInfo.IsGlobalReading, + IsReadingPeriod = criterionInfo.IsReadingPeriod, + ReadingInfoSignTime = criterionInfo.ReadingInfoSignTime, + ExistClinicalData = await _clinicalDataTrialSetRepository.AnyAsync(x => x.IsConfirm && x.TrialClinicalDataSetCriteriaList.Any(y => y.TrialReadingCriterionId == inQuery.TrialReadingCriterionId)), + }); } + ///// + ///// 获取读片模块 //加了标准参数 + ///// + //[HttpPost] + //public async Task>> GetReadModuleList(GetReadModuleDto dto) + //{ + + // #region MyRegion + + // if (dto.SortField.IsNullOrEmpty()) + // { + // dto.SortField = nameof(ReadModuleView.SubjectCode); + // dto.Asc = true; + // } + + // dto.SortField = dto.Asc ? dto.SortField : dto.SortField + " desc"; + // var subjectQuery = _readModuleViewRepository.Where(x => x.TrialReadingCriterionId == dto.TrialReadingCriterionId) + // .WhereIf(dto.TrialId != null, x => x.TrialId == dto.TrialId) + // .WhereIf(dto.SubjectId != null, x => x.SubjectId == dto.SubjectId) + // .WhereIf(dto.TrialSiteCode != null && dto.TrialSiteCode != string.Empty, x => x.TrialSiteCode.Contains(dto.TrialSiteCode)) + // .WhereIf(dto.SubjectCode != null && dto.SubjectCode != string.Empty, x => x.SubjectCode.Contains(dto.SubjectCode)) + // .WhereIf(dto.ModuleType != null, x => x.ModuleType == dto.ModuleType) + // .WhereIf(dto.CompleteClinicalData == CompleteClinicalDataEnum.NA, x => x.NeedSignClinicalDataCount == 0) + // .WhereIf(dto.CompleteClinicalData == CompleteClinicalDataEnum.NotComplete, x => x.NeedSignClinicalDataCount != x.SignClinicalDataCount) + // .WhereIf(dto.CompleteClinicalData == CompleteClinicalDataEnum.Complete, x => x.NeedSignClinicalDataCount != 0 && x.NeedSignClinicalDataCount == x.SignClinicalDataCount) + // .WhereIf(dto.ReadingStatus != null, x => x.ReadingStatus == dto.ReadingStatus); + // //.WhereIf(dto.Name != null, x => x.Name.Contains(dto.Name!)).OrderBy(x => x.SiteCode); + + // var subjectIds = await subjectQuery.OrderBy(dto.SortField).Select(x => x.SubjectId).Distinct().Skip((dto.PageIndex - 1) * dto.PageSize).Take(dto.PageSize).ToListAsync(); + + // List ReadModuleViewList = await subjectQuery.Where(x => subjectIds.Contains(x.SubjectId)).OrderBy(dto.SortField).ToListAsync(); + // List getReadList = ReadModuleViewList.GroupBy(x => new { x.SubjectId, x.TrialSiteId, x.TrialSiteCode, x.SubjectCode }) + // .Select(x => new GetReadModuleDtoOut() + // { + // TrialSiteCode = x.Key.TrialSiteCode, + // TrialSiteId = x.Key.TrialSiteId, + // SubjectCode = x.Key.SubjectCode, + // SubjectId = x.Key.SubjectId, + // Data = x.OrderBy(x => x.ModuleType).ThenBy(x => x.VisitNum).ToList(), + // }).ToList(); + // PageOutput pageOutput = new PageOutput() + // { + // PageSize = dto.PageSize, + // CurrentPageData = getReadList, + // PageIndex = dto.PageIndex, + // TotalCount = await subjectQuery.Select(x => x.SubjectId).Distinct().CountAsync(), + // }; + // var maxcount = 0; + // pageOutput.CurrentPageData.ForEach(x => + // { + // maxcount = maxcount < x.Data.Count ? x.Data.Count : maxcount; + // }); + + + // var criterionInfo = await _readingQuestionCriterionTrialRepository.Where(x => x.Id == dto.TrialReadingCriterionId).Select(x => new + // { + // x.IsReadingTaskViewInOrder, + // x.IsOncologyReading, + // x.IsGlobalReading, + // x.IsReadingPeriod, + // x.ReadingInfoSignTime, + // }).FirstNotNullAsync(); + + // return ResponseOutput.Ok(pageOutput, new + // { + // MaxLength = maxcount, + // IsReadingTaskViewInOrder = criterionInfo.IsReadingTaskViewInOrder, + // IsClinicalReading = criterionInfo.IsOncologyReading, + // // OnlyExistsMedicalHistory = !(await _clinicalDataTrialSetRepository.AnyAsync(x => x.TrialId == dto.TrialId && x.ClinicalDataSetName != "既往局部治疗史" && x.IsConfirm)), + // IsExistsSubjectClinicalData = await _clinicalDataTrialSetRepository.AnyAsync(x => x.TrialId == dto.TrialId && x.ClinicalDataLevel == ClinicalLevel.Subject && x.IsConfirm && x.TrialClinicalDataSetCriteriaList.Any(y => y.TrialReadingCriterionId == dto.TrialReadingCriterionId)), + // IsExistsVisitClinicalData = await _clinicalDataTrialSetRepository.AnyAsync(x => x.TrialId == dto.TrialId && x.ClinicalDataLevel == ClinicalLevel.SubjectVisit && x.IsConfirm && x.TrialClinicalDataSetCriteriaList.Any(y => y.TrialReadingCriterionId == dto.TrialReadingCriterionId)), + // IsExistsStudyClinicalData = await _clinicalDataTrialSetRepository.AnyAsync(x => x.TrialId == dto.TrialId && x.ClinicalDataLevel == ClinicalLevel.Study && x.IsConfirm && x.TrialClinicalDataSetCriteriaList.Any(y => y.TrialReadingCriterionId == dto.TrialReadingCriterionId)), + // IsExistsReadingClinicalData = await _clinicalDataTrialSetRepository.AnyAsync(x => x.TrialId == dto.TrialId && x.ClinicalDataLevel == ClinicalLevel.ImageRead && x.IsConfirm && x.TrialClinicalDataSetCriteriaList.Any(y => y.TrialReadingCriterionId == dto.TrialReadingCriterionId)), + // IsExistsOncologyReadClinicalData = await _clinicalDataTrialSetRepository.AnyAsync(x => x.TrialId == dto.TrialId && x.ClinicalDataLevel == ClinicalLevel.OncologyRead && x.IsConfirm && x.TrialClinicalDataSetCriteriaList.Any(y => y.TrialReadingCriterionId == dto.TrialReadingCriterionId)), + // IsGlobalReading = criterionInfo.IsGlobalReading, + // IsReadingPeriod = criterionInfo.IsReadingPeriod, + // ReadingInfoSignTime = criterionInfo.ReadingInfoSignTime, + // ExistClinicalData = await _clinicalDataTrialSetRepository.AnyAsync(x => x.IsConfirm && x.TrialClinicalDataSetCriteriaList.Any(y => y.TrialReadingCriterionId == dto.TrialReadingCriterionId)), + // }); + + // #endregion + //} + /// @@ -195,24 +806,24 @@ namespace IRaCIS.Application.Services var data = await GetReadModuleList(new GetReadModuleDto() { SubjectId = dto.SubjectId, - TrialId=dto.TrialId, - TrialReadingCriterionId=dto.TrialReadingCriterionId, + TrialId = dto.TrialId, + TrialReadingCriterionId = dto.TrialReadingCriterionId, }); - GetReadModuleSingleOutdto? readModule = data.Item1.CurrentPageData.FirstOrDefault().Data.Where(x => x.Id == dto.Id).Select(x => new GetReadModuleSingleOutdto() + GetReadModuleSingleOutdto? readModule = data.Data.CurrentPageData.FirstOrDefault().Data.Where(x => x.Id == dto.Id).Select(x => new GetReadModuleSingleOutdto() { Id = x.Id, ModuleType = x.ModuleType, SubjectVisitId = x.SubjectVisitId, SubjectVisitName = x.SubjectVisitName, - + Status = x.ReadingStatus, }).FirstOrDefault(); var stakeholderIds = new List(); - var subjectVisit =await _subjectVisitRepository.FirstOrDefaultAsync(x => x.Id == readModule.SubjectVisitId); + var subjectVisit = await _subjectVisitRepository.FirstOrDefaultAsync(x => x.Id == readModule.SubjectVisitId); switch (readModule.Status) { @@ -239,11 +850,11 @@ namespace IRaCIS.Application.Services case ReadingStatusEnum.ImageReading: case ReadingStatusEnum.ReadCompleted: - var doctorUserId = await _visitTaskRepository.Where(x => (x.SouceReadModuleId == dto.Id || x.SourceSubjectVisitId == dto.Id)&&x.TaskState==TaskState.Effect) + var doctorUserId = await _visitTaskRepository.Where(x => (x.SouceReadModuleId == dto.Id || x.SourceSubjectVisitId == dto.Id) && x.TaskState == TaskState.Effect) .Where(x => x.DoctorUserId != null).Select(x => x.DoctorUserId.Value).ToListAsync(); stakeholderIds.AddRange(doctorUserId); - + break; }; @@ -261,26 +872,26 @@ namespace IRaCIS.Application.Services public async Task> GetSubjectReadVisitList(GetSubjectReadVisitsInDto inDto) { //增加标准 - var maxReadVisit = await _readModuleRepository.Where(x => x.SubjectId == inDto.SubjectId && x.ReadingSetType==inDto.ReadingSetType && x.TrialReadingCriterionId==inDto.TrialReadingCriterionId).Include(x=>x.SubjectVisit).OrderByDescending(x=>x.SubjectVisit.VisitNum).FirstOrDefaultAsync(); + var maxReadVisit = await _readModuleRepository.Where(x => x.SubjectId == inDto.SubjectId && x.ReadingSetType == inDto.ReadingSetType && x.TrialReadingCriterionId == inDto.TrialReadingCriterionId).Include(x => x.SubjectVisit).OrderByDescending(x => x.SubjectVisit.VisitNum).FirstOrDefaultAsync(); - var maxReadVisitNum= maxReadVisit==null?-1:maxReadVisit.SubjectVisit.VisitNum; + var maxReadVisitNum = maxReadVisit == null ? -1 : maxReadVisit.SubjectVisit.VisitNum; var visitQuery = _subjectVisitRepository.Where(x => x.SubjectId == inDto.SubjectId && x.LatestScanDate != null && !x.IsLostVisit); var finalVisitNum = await visitQuery.Where(x => x.IsFinalVisit).Select(x => x.VisitNum).FirstOrDefaultAsync(); //增加标准 - var readModulequery = _readModuleRepository.AsQueryable().Where(x=>x.TrialReadingCriterionId == inDto.TrialReadingCriterionId); + var readModulequery = _readModuleRepository.AsQueryable().Where(x => x.TrialReadingCriterionId == inDto.TrialReadingCriterionId); - var resultlist= await visitQuery.WhereIf(finalVisitNum!=0, x => x.VisitNum <= finalVisitNum) - .WhereIf(inDto.ReadingSetType== ReadingSetType.TumorReading, x => readModulequery.Where(y => y.SubjectVisitId == x.Id&&y.TrialReadingCriterionId== inDto.TrialReadingCriterionId && y.ReadingSetType == ReadingSetType.ImageReading).Count() > 0) - .Where(x=>x.VisitNum> maxReadVisitNum) - .Where(x=>!x.IsBaseLine) // 排除基线 - .Where(x => readModulequery.Where(y => y.SubjectVisitId == x.Id&& y.TrialReadingCriterionId == inDto.TrialReadingCriterionId && y.ReadingSetType == inDto.ReadingSetType).Count() == 0).OrderBy(x => finalVisitNum) - .Select(x => new GetSubjectReadVisitsOutDto() - { - SubjectVisitId = x.Id, - VisitName = x.VisitName, - VisitNum = x.VisitNum, - }).OrderBy(x=>x.VisitNum).ToListAsync(); + var resultlist = await visitQuery.WhereIf(finalVisitNum != 0, x => x.VisitNum <= finalVisitNum) + .WhereIf(inDto.ReadingSetType == ReadingSetType.TumorReading, x => readModulequery.Where(y => y.SubjectVisitId == x.Id && y.TrialReadingCriterionId == inDto.TrialReadingCriterionId && y.ReadingSetType == ReadingSetType.ImageReading).Count() > 0) + .Where(x => x.VisitNum > maxReadVisitNum) + .Where(x => !x.IsBaseLine) // 排除基线 + .Where(x => readModulequery.Where(y => y.SubjectVisitId == x.Id && y.TrialReadingCriterionId == inDto.TrialReadingCriterionId && y.ReadingSetType == inDto.ReadingSetType).Count() == 0).OrderBy(x => finalVisitNum) + .Select(x => new GetSubjectReadVisitsOutDto() + { + SubjectVisitId = x.Id, + VisitName = x.VisitName, + VisitNum = x.VisitNum, + }).OrderBy(x => x.VisitNum).ToListAsync(); return resultlist; } @@ -295,8 +906,8 @@ namespace IRaCIS.Application.Services public async Task AddReadModule(ReadModuleAddDto dto) { - - var visitQuery = _subjectVisitRepository.Where(x => x.SubjectId == dto.SubjectId); + + var visitQuery = _subjectVisitRepository.Where(x => x.SubjectId == dto.SubjectId); visitQuery = visitQuery //.WhereIf(dto.ExpirationDate != null, x => x.LatestScanDate <= dto.ExpirationDate.Value) @@ -308,9 +919,9 @@ namespace IRaCIS.Application.Services if (visit != null) { - if (await _readModuleRepository.AnyAsync(x => x.SubjectVisitId == visit.Id&&x.ModuleType== moduleType && x.TrialReadingCriterionId == dto.TrialReadingCriterionId)) + if (await _readModuleRepository.AnyAsync(x => x.SubjectVisitId == visit.Id && x.ModuleType == moduleType && x.TrialReadingCriterionId == dto.TrialReadingCriterionId)) { - //---当前访视已经添加过阅片期 + //---当前访视已经添加过阅片期 throw new BusinessValidationFailedException(_localizer["ReadModule_AlreadyAdded"]); } var readModuleData = new ReadModule() @@ -323,7 +934,7 @@ namespace IRaCIS.Application.Services SubjectVisitId = visit.Id, ReadingSetType = dto.ReadingSetType, TrialId = dto.TrialId, - + ReadingStatus = ReadingStatusEnum.TaskAllocate, //增加标准 @@ -338,9 +949,9 @@ namespace IRaCIS.Application.Services { case ModuleTypeEnum.Global: //增加标准 - var taskListInfo = await _visitTaskRepository.Where(x => x.SourceSubjectVisitId == readModuleData.SubjectVisitId&&x.TaskState==TaskState.Effect && x.ReadingTaskState == ReadingTaskState.HaveSigned - &&!x.IsAnalysisCreate && x.TrialReadingCriterionId==dto.TrialReadingCriterionId - + var taskListInfo = await _visitTaskRepository.Where(x => x.SourceSubjectVisitId == readModuleData.SubjectVisitId && x.TaskState == TaskState.Effect && x.ReadingTaskState == ReadingTaskState.HaveSigned + && !x.IsAnalysisCreate && x.TrialReadingCriterionId == dto.TrialReadingCriterionId + ).ToListAsync(); foreach (var taskInfo in taskListInfo) { @@ -354,7 +965,7 @@ namespace IRaCIS.Application.Services { IsUrgent = readModuleData.IsUrgent ?? false, SubjectId = readModuleData.SubjectId, - + ReadingName = readModuleData.ModuleName, ReadModuleId =readModuleData.Id, ReadingCategory = ReadingCategory.Global, @@ -370,18 +981,18 @@ namespace IRaCIS.Application.Services var criterionInfo = await _readingQuestionCriterionTrialRepository.Where(x => x.Id == dto.TrialReadingCriterionId).Select(x => new { x.ReadingType, - + }).FirstNotNullAsync(); - + //增加标准 - var globalModule = await _readModuleRepository.Where(x => x.SubjectId == readModuleData.SubjectId && x.SubjectVisitId == readModuleData.SubjectVisitId&& x.ModuleType == ModuleTypeEnum.Global && x.TrialReadingCriterionId == dto.TrialReadingCriterionId).FirstOrDefaultAsync(); + var globalModule = await _readModuleRepository.Where(x => x.SubjectId == readModuleData.SubjectId && x.SubjectVisitId == readModuleData.SubjectVisitId && x.ModuleType == ModuleTypeEnum.Global && x.TrialReadingCriterionId == dto.TrialReadingCriterionId).FirstOrDefaultAsync(); if (globalModule != null) { var globalTaskInfoList = await _visitTaskRepository.Where(x => x.SouceReadModuleId == globalModule.Id && x.TrialReadingCriterionId == dto.TrialReadingCriterionId - && x.TaskState == TaskState.Effect && x.ReadingTaskState == ReadingTaskState.HaveSigned&&!x.IsAnalysisCreate).ToListAsync(); + && x.TaskState == TaskState.Effect && x.ReadingTaskState == ReadingTaskState.HaveSigned && !x.IsAnalysisCreate).ToListAsync(); if (globalTaskInfoList.Count() > 0 && globalTaskInfoList.Count == (int)criterionInfo.ReadingType) { @@ -408,7 +1019,7 @@ namespace IRaCIS.Application.Services SubjectId = readModuleData.SubjectId, VisitNum=visit.VisitNum, ReadingName = readModuleData.ModuleName, - + ReadModuleId =readModuleData.Id, ReadingCategory = ReadingCategory.Oncology, } @@ -420,9 +1031,9 @@ namespace IRaCIS.Application.Services } - else + else { - //---请先添加全局阅片 + //---请先添加全局阅片 return ResponseOutput.NotOk(_localizer["ReadModule_AddGlobalFirst"]); } break; @@ -436,7 +1047,7 @@ namespace IRaCIS.Application.Services return ResponseOutput.NotOk(_localizer["ReadModule_VisitNotFound"]); } - + } @@ -455,40 +1066,40 @@ namespace IRaCIS.Application.Services var readModule = await _readModuleRepository.Where(x => x.Id == readModuleId).FirstNotNullAsync(); - if(await _readingClinicalDataRepository.Where(t => t.ReadingId == readModuleId).AnyAsync(t => t.ReadingClinicalDataState == ReadingClinicalDataStatus.HaveSigned)) + if (await _readingClinicalDataRepository.Where(t => t.ReadingId == readModuleId).AnyAsync(t => t.ReadingClinicalDataState == ReadingClinicalDataStatus.HaveSigned)) { //---临床资料已签名,不允许删除 return ResponseOutput.NotOk(_localizer["ReadModule_SignedDataCannotDelete"]); } - - if (await _readModuleRepository.AnyAsync(x => x.Id == readModuleId&&x.IsCRCConfirm)) + + if (await _readModuleRepository.AnyAsync(x => x.Id == readModuleId && x.IsCRCConfirm)) { //---CRC已经确认临床数据 不允许删除 return ResponseOutput.NotOk(_localizer["ReadModule_CRCConfirmClinicalData"]); } //增加标准 - if (readModule.ModuleType==ModuleTypeEnum.Global&&(await _readModuleRepository.AnyAsync(x=>x.ModuleType==ModuleTypeEnum.Oncology&&x.SubjectVisitId== readModule.SubjectVisitId && x.TrialReadingCriterionId==readModule.TrialReadingCriterionId))) + if (readModule.ModuleType == ModuleTypeEnum.Global && (await _readModuleRepository.AnyAsync(x => x.ModuleType == ModuleTypeEnum.Oncology && x.SubjectVisitId == readModule.SubjectVisitId && x.TrialReadingCriterionId == readModule.TrialReadingCriterionId))) { //---当前访视存在肿瘤学阅片,请先删除肿瘤学阅片 throw new BusinessValidationFailedException(_localizer["ReadModule_TumorExists"]); } - if (await _visitTaskRepository.AnyAsync(x => readModuleId==x.SouceReadModuleId)) + if (await _visitTaskRepository.AnyAsync(x => readModuleId == x.SouceReadModuleId)) { //---当前阅片已生成任务,操作失败。 throw new BusinessValidationFailedException(_localizer["ReadModule_TaskGenerated"]); } - await _visitTaskRepository.BatchUpdateNoTrackingAsync(x => readModuleId==x.SouceReadModuleId, x => new VisitTask() + await _visitTaskRepository.BatchUpdateNoTrackingAsync(x => readModuleId == x.SouceReadModuleId, x => new VisitTask() { TaskState = TaskState.Adbandon }); - + await _readModuleRepository.UpdatePartialFromQueryAsync(t => t.Id == readModuleId, x => new ReadModule() { diff --git a/IRaCIS.Core.Application/Service/TrialSiteUser/_MapConfig.cs b/IRaCIS.Core.Application/Service/TrialSiteUser/_MapConfig.cs index 9a3326db6..f27522f4f 100644 --- a/IRaCIS.Core.Application/Service/TrialSiteUser/_MapConfig.cs +++ b/IRaCIS.Core.Application/Service/TrialSiteUser/_MapConfig.cs @@ -164,8 +164,8 @@ namespace IRaCIS.Core.Application.Service CreateMap().ForMember(t => t.TrialId, u => u.MapFrom(c => c.Id)) .ForMember(t => t.TrialCriterionIds, u => u.MapFrom(c => c.TrialReadingCriterionList.Where(v => v.IsConfirm).OrderBy(x => x.ShowOrder).Select(r => r.Id))) .ForMember(t => t.TrialCriterionNames, u => u.MapFrom(c => c.TrialReadingCriterionList.Where(v => v.IsConfirm).OrderBy(x => x.ShowOrder).Select(r => r.CriterionName))) - .ForMember(t => t.ClinicalDataTrialSetIds, u => u.MapFrom(c => c.clinicalDataTrialSets.Where(v => v.IsConfirm).Select(r => r.Id))) - .ForMember(t => t.ClinicalDataSetNames, u => u.MapFrom(c => c.clinicalDataTrialSets.Where(v => v.IsConfirm).Select(r => isEn_Us ? r.ClinicalDataSetEnName : r.ClinicalDataSetName))) + .ForMember(t => t.ClinicalDataTrialSetIds, u => u.MapFrom(c => c.ClinicalDataTrialSetList.Where(v => v.IsConfirm).Select(r => r.Id))) + .ForMember(t => t.ClinicalDataSetNames, u => u.MapFrom(c => c.ClinicalDataTrialSetList.Where(v => v.IsConfirm).Select(r => isEn_Us ? r.ClinicalDataSetEnName : r.ClinicalDataSetName))) //.ForMember(t => t.CriterionIds, u => u.MapFrom(c => c.TrialDicList.Where(v => v.KeyName == StaticData.Criterion).Select(r => r.DictionaryId))) ; CreateMap(); diff --git a/IRaCIS.Core.Domain/BaseModel/Entity.cs b/IRaCIS.Core.Domain/BaseModel/Entity.cs index 5ca0a22aa..91638466d 100644 --- a/IRaCIS.Core.Domain/BaseModel/Entity.cs +++ b/IRaCIS.Core.Domain/BaseModel/Entity.cs @@ -16,6 +16,12 @@ namespace IRaCIS.Core.Domain.Models } + //针对dicom + public interface IEntitySeqId + { + public Guid SeqId { get; set; } + } + public abstract class Entity : IEntity { [Key] @@ -28,6 +34,7 @@ namespace IRaCIS.Core.Domain.Models private readonly List _domainEvents = []; + [JsonIgnore] [NotMapped] public IReadOnlyCollection DomainEvents => _domainEvents.AsReadOnly(); diff --git a/IRaCIS.Core.Domain/IRaCIS.Core.Domain.csproj b/IRaCIS.Core.Domain/IRaCIS.Core.Domain.csproj index 80a3e8702..15c6078d5 100644 --- a/IRaCIS.Core.Domain/IRaCIS.Core.Domain.csproj +++ b/IRaCIS.Core.Domain/IRaCIS.Core.Domain.csproj @@ -17,7 +17,7 @@ - + diff --git a/IRaCIS.Core.Domain/Image/DicomInstance.cs b/IRaCIS.Core.Domain/Image/DicomInstance.cs index 3096a0046..cc9a83c3a 100644 --- a/IRaCIS.Core.Domain/Image/DicomInstance.cs +++ b/IRaCIS.Core.Domain/Image/DicomInstance.cs @@ -5,7 +5,7 @@ using System.ComponentModel.DataAnnotations.Schema; namespace IRaCIS.Core.Domain.Models { [Table("DicomInstance")] - public class DicomInstance : BaseFullAuditEntity + public class DicomInstance : BaseFullAuditEntity, IEntitySeqId { #region 导航属性 [JsonIgnore] @@ -18,7 +18,6 @@ namespace IRaCIS.Core.Domain.Models #endregion - [DatabaseGenerated(DatabaseGeneratedOption.Identity)] public Guid SeqId { get; set; } public Guid StudyId { get; set; } diff --git a/IRaCIS.Core.Domain/Image/DicomSeries.cs b/IRaCIS.Core.Domain/Image/DicomSeries.cs index c4225697c..775cbe66f 100644 --- a/IRaCIS.Core.Domain/Image/DicomSeries.cs +++ b/IRaCIS.Core.Domain/Image/DicomSeries.cs @@ -6,7 +6,7 @@ using System.ComponentModel.DataAnnotations.Schema; namespace IRaCIS.Core.Domain.Models { [Table("DicomSeries")] - public class DicomSeries : BaseFullDeleteAuditEntity + public class DicomSeries : BaseFullDeleteAuditEntity, IEntitySeqId { #region 导航属性 [JsonIgnore] @@ -22,7 +22,6 @@ namespace IRaCIS.Core.Domain.Models - [DatabaseGenerated(DatabaseGeneratedOption.Identity)] public Guid SeqId { get; set; } public Guid StudyId { get; set; } public string StudyInstanceUid { get; set; } diff --git a/IRaCIS.Core.Domain/Image/DicomStudy.cs b/IRaCIS.Core.Domain/Image/DicomStudy.cs index ede2cf307..b22588a77 100644 --- a/IRaCIS.Core.Domain/Image/DicomStudy.cs +++ b/IRaCIS.Core.Domain/Image/DicomStudy.cs @@ -6,7 +6,7 @@ using System.ComponentModel.DataAnnotations.Schema; namespace IRaCIS.Core.Domain.Models { [Table("DicomStudy")] - public class DicomStudy : BaseFullDeleteAuditEntity + public class DicomStudy : BaseFullDeleteAuditEntity, IEntitySeqId { #region 导航属性 //一个检查 由多个人管理 @@ -41,7 +41,6 @@ namespace IRaCIS.Core.Domain.Models #endregion - [DatabaseGenerated(DatabaseGeneratedOption.Identity)] public Guid SeqId { get; set; } public Guid TrialId { get; set; } diff --git a/IRaCIS.Core.Domain/Image/SCPInstance.cs b/IRaCIS.Core.Domain/Image/SCPInstance.cs index 844283149..4bc2ed272 100644 --- a/IRaCIS.Core.Domain/Image/SCPInstance.cs +++ b/IRaCIS.Core.Domain/Image/SCPInstance.cs @@ -5,7 +5,7 @@ using System.ComponentModel.DataAnnotations.Schema; namespace IRaCIS.Core.Domain.Models { [Table("SCPInstance")] - public class SCPInstance : BaseFullAuditEntity + public class SCPInstance : BaseFullAuditEntity, IEntitySeqId { #region 导航属性 [JsonIgnore] @@ -18,7 +18,6 @@ namespace IRaCIS.Core.Domain.Models #endregion - [DatabaseGenerated(DatabaseGeneratedOption.Identity)] public Guid SeqId { get; set; } public Guid StudyId { get; set; } diff --git a/IRaCIS.Core.Domain/Image/SCPSeries.cs b/IRaCIS.Core.Domain/Image/SCPSeries.cs index 4cc3e689d..5e4d6abb8 100644 --- a/IRaCIS.Core.Domain/Image/SCPSeries.cs +++ b/IRaCIS.Core.Domain/Image/SCPSeries.cs @@ -6,7 +6,7 @@ using System.ComponentModel.DataAnnotations.Schema; namespace IRaCIS.Core.Domain.Models { [Table("SCPSeries")] - public class SCPSeries : BaseFullDeleteAuditEntity + public class SCPSeries : BaseFullDeleteAuditEntity, IEntitySeqId { #region 导航属性 [JsonIgnore] @@ -18,7 +18,6 @@ namespace IRaCIS.Core.Domain.Models #endregion - [DatabaseGenerated(DatabaseGeneratedOption.Identity)] public Guid SeqId { get; set; } public Guid StudyId { get; set; } public string StudyInstanceUid { get; set; } diff --git a/IRaCIS.Core.Domain/Image/SCPStudy.cs b/IRaCIS.Core.Domain/Image/SCPStudy.cs index 5a11ca22f..33c3f29d0 100644 --- a/IRaCIS.Core.Domain/Image/SCPStudy.cs +++ b/IRaCIS.Core.Domain/Image/SCPStudy.cs @@ -6,7 +6,7 @@ using System.ComponentModel.DataAnnotations.Schema; namespace IRaCIS.Core.Domain.Models { [Table("SCPStudy")] - public class SCPStudy : BaseFullDeleteAuditEntity + public class SCPStudy : BaseFullDeleteAuditEntity, IEntitySeqId { #region 导航属性 @@ -31,9 +31,6 @@ namespace IRaCIS.Core.Domain.Models //0 未知 1 单重 2 双重 public bool IsDoubleReview { get; set; } - - - [DatabaseGenerated(DatabaseGeneratedOption.Identity)] public Guid SeqId { get; set; } [ForeignKey("PatientId")] diff --git a/IRaCIS.Core.Domain/Image/TaskInstance.cs b/IRaCIS.Core.Domain/Image/TaskInstance.cs index 7276c500b..976ada1c5 100644 --- a/IRaCIS.Core.Domain/Image/TaskInstance.cs +++ b/IRaCIS.Core.Domain/Image/TaskInstance.cs @@ -4,7 +4,7 @@ using System.ComponentModel.DataAnnotations.Schema; namespace IRaCIS.Core.Domain.Models { - public class TaskInstance : BaseFullAuditEntity + public class TaskInstance : BaseFullAuditEntity, IEntitySeqId { #region 导航属性 [JsonIgnore] @@ -17,7 +17,6 @@ namespace IRaCIS.Core.Domain.Models #endregion - [DatabaseGenerated(DatabaseGeneratedOption.Identity)] public Guid SeqId { get; set; } public Guid StudyId { get; set; } diff --git a/IRaCIS.Core.Domain/Image/TaskSeries.cs b/IRaCIS.Core.Domain/Image/TaskSeries.cs index 1328a7c9f..b6d1ba154 100644 --- a/IRaCIS.Core.Domain/Image/TaskSeries.cs +++ b/IRaCIS.Core.Domain/Image/TaskSeries.cs @@ -5,7 +5,7 @@ using System.ComponentModel.DataAnnotations.Schema; namespace IRaCIS.Core.Domain.Models { - public class TaskSeries : BaseFullDeleteAuditEntity + public class TaskSeries : BaseFullDeleteAuditEntity, IEntitySeqId { #region 导航属性 [JsonIgnore] @@ -18,7 +18,6 @@ namespace IRaCIS.Core.Domain.Models - [DatabaseGenerated(DatabaseGeneratedOption.Identity)] public Guid SeqId { get; set; } public Guid StudyId { get; set; } public string StudyInstanceUid { get; set; } diff --git a/IRaCIS.Core.Domain/Image/TaskStudy.cs b/IRaCIS.Core.Domain/Image/TaskStudy.cs index b290796f9..7cabd23e5 100644 --- a/IRaCIS.Core.Domain/Image/TaskStudy.cs +++ b/IRaCIS.Core.Domain/Image/TaskStudy.cs @@ -5,7 +5,7 @@ using System.ComponentModel.DataAnnotations.Schema; namespace IRaCIS.Core.Domain.Models { - public class TaskStudy : BaseFullDeleteAuditEntity + public class TaskStudy : BaseFullDeleteAuditEntity, IEntitySeqId { #region 导航属性 [JsonIgnore] @@ -33,8 +33,6 @@ namespace IRaCIS.Core.Domain.Models #endregion - - [DatabaseGenerated(DatabaseGeneratedOption.Identity)] public Guid SeqId { get; set; } public Guid TrialId { get; set; } diff --git a/IRaCIS.Core.Domain/Reading/ReadingCriterion/ReadingQuestionCriterionTrial.cs b/IRaCIS.Core.Domain/Reading/ReadingCriterion/ReadingQuestionCriterionTrial.cs index 550d828f1..32f145c3b 100644 --- a/IRaCIS.Core.Domain/Reading/ReadingCriterion/ReadingQuestionCriterionTrial.cs +++ b/IRaCIS.Core.Domain/Reading/ReadingCriterion/ReadingQuestionCriterionTrial.cs @@ -32,6 +32,10 @@ namespace IRaCIS.Core.Domain.Models public List VisitTaskList { get; set; } + [JsonIgnore] + + public List TrialClinicalDataSetCriterionList { get; set; } + #endregion /// /// 系统标准ID diff --git a/IRaCIS.Core.Domain/Reading/ReadingPeriod/ReadModule.cs b/IRaCIS.Core.Domain/Reading/ReadingPeriod/ReadModule.cs index c05a12219..5be3f9597 100644 --- a/IRaCIS.Core.Domain/Reading/ReadingPeriod/ReadModule.cs +++ b/IRaCIS.Core.Domain/Reading/ReadingPeriod/ReadModule.cs @@ -47,14 +47,18 @@ namespace IRaCIS.Core.Domain.Models public List ReadModuleCriterionFromList { get; set; } = new List(); + [JsonIgnore] public List ModuleTaskList { get; set; } [JsonIgnore] public ReadingQuestionCriterionTrial TrialReadingCriterion { get; set; } + + [JsonIgnore] + public List ReadingClinicalDataList { get; set; } #endregion - public Guid SubjectId { get; set; } + public Guid SubjectId { get; set; } public Guid TrialReadingCriterionId { get; set; } diff --git a/IRaCIS.Core.Domain/Trial/Trial.cs b/IRaCIS.Core.Domain/Trial/Trial.cs index 6fbd4ea2e..37c384ca9 100644 --- a/IRaCIS.Core.Domain/Trial/Trial.cs +++ b/IRaCIS.Core.Domain/Trial/Trial.cs @@ -75,9 +75,12 @@ namespace IRaCIS.Core.Domain.Models [ForeignKey("ReviewModeId")] public Dictionary ReviewMode { get; set; } - [JsonIgnore] + //[JsonIgnore] - public List clinicalDataTrialSets { get; set; } = new List { }; + //public List TrialClinicalDataSetCriterionList { get; set; } + + [JsonIgnore] + public List ClinicalDataTrialSetList { get; set; } = new List { }; [JsonIgnore] public List ClinicalTrialProjectDetails { get; set; } = new List { }; [JsonIgnore] diff --git a/IRaCIS.Core.Domain/Visit/SubjectVisit.cs b/IRaCIS.Core.Domain/Visit/SubjectVisit.cs index e0e61e5f0..eaa1465a8 100644 --- a/IRaCIS.Core.Domain/Visit/SubjectVisit.cs +++ b/IRaCIS.Core.Domain/Visit/SubjectVisit.cs @@ -53,6 +53,9 @@ namespace IRaCIS.Core.Domain.Models public Trial Trial { get; set; } + [JsonIgnore] + public List ReadModuleList { get; set; } + [JsonIgnore] [ForeignKey("SubjectId")] diff --git a/IRaCIS.Core.Infra.EFCore/Context/AuditContext.cs b/IRaCIS.Core.Infra.EFCore/Context/AuditContext.cs deleted file mode 100644 index e6504b7d9..000000000 --- a/IRaCIS.Core.Infra.EFCore/Context/AuditContext.cs +++ /dev/null @@ -1,56 +0,0 @@ -using Microsoft.EntityFrameworkCore; -using System; -using System.Collections.Generic; -using IRaCIS.Core.Domain.Models; - -namespace IRaCIS.Core.Infra.EFCore -{ - #region AuditContext - public class AuditContext : DbContext - { - //传递委托进来写日志 - - private readonly string _connectionString; - - public AuditContext(string connectionString) - { - _connectionString = connectionString; - } - - protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) - => optionsBuilder.UseSqlServer(_connectionString); - - public DbSet SaveChangesAudits { get; set; } - } - - public class SaveChangesAudit - { - public Guid Id { get; set; } - //public Guid AuditId { get; set; } - public DateTime StartTime { get; set; } - public DateTime EndTime { get; set; } - public bool Succeeded { get; set; } = false; - public string ErrorMessage { get; set; } = string.Empty; - - public ICollection Entities { get; } = new List(); - } - - public class EntityAudit: IAuditAddWithUserName - { - public Guid Id { get; set; } - public Guid AlterId { get; set; }=Guid.Empty; - public Guid SaveChangesAuditId { get; set; } - public EntityState State { get; set; } - public string AuditMessage { get; set; } - - - - - public SaveChangesAudit SaveChangesAudit { get; set; } - - public string CreateUser { get; set; } = string.Empty; - public Guid CreateUserId { get; set; }=Guid.Empty; - public DateTime CreateTime { get; set; }=DateTime.Now; - } - #endregion -} diff --git a/IRaCIS.Core.Infra.EFCore/Context/IRaCISDBContext.cs b/IRaCIS.Core.Infra.EFCore/Context/IRaCISDBContext.cs index 7bd61df04..c8be13bf5 100644 --- a/IRaCIS.Core.Infra.EFCore/Context/IRaCISDBContext.cs +++ b/IRaCIS.Core.Infra.EFCore/Context/IRaCISDBContext.cs @@ -56,22 +56,21 @@ namespace IRaCIS.Core.Infra.EFCore public class IRaCISDBContext : DbContext { - private IUserInfo _userInfo; private readonly ILogger _logger; - public IRaCISDBContext(DbContextOptions options, IUserInfo userInfo, ILogger logger + public IRaCISDBContext(DbContextOptions options, ILogger logger ) : base(options) { - _userInfo = userInfo; _logger = logger; } protected override void OnModelCreating(ModelBuilder modelBuilder) { - + + //遍历实体模型手动配置 var typesToRegister = Assembly.GetExecutingAssembly().GetTypes().Where(q => q.GetInterface(typeof(IEntityTypeConfiguration<>).FullName) != null); foreach (var type in typesToRegister) @@ -95,12 +94,16 @@ namespace IRaCIS.Core.Infra.EFCore { modelBuilder.Entity(entityType.ClrType).Property(nameof(Entity.Id)).HasValueGenerator(); } + if (typeof(IEntitySeqId).IsAssignableFrom(entityType.ClrType)) + { + modelBuilder.Entity(entityType.ClrType).Property(nameof(IEntitySeqId.SeqId)).HasValueGenerator(); + } } } #region 获取表名 和字段名 优化 - + /// /// 直接获取代码定义的模型,以及表上定义的Description 获取表信息 以及备注 /// @@ -155,15 +158,13 @@ namespace IRaCIS.Core.Infra.EFCore }); } - return tableColumList.OrderBy(t=>t.Name).ToList(); + return tableColumList.OrderBy(t => t.Name).ToList(); } #endregion public override async Task SaveChangesAsync(CancellationToken cancellationToken = new CancellationToken()) { - // 采用触发器的方式 设置 CreateUserId CreateTime UpdateTime UpdateUserId 稽查实体里面没有这四个字段的值 因为先后顺序的原因 - await AddAudit(); try { @@ -222,28 +223,7 @@ namespace IRaCIS.Core.Infra.EFCore } - public async Task AddAudit() - { - //触发器里面提交事务 业务方法里面提交事务 会记录两次 - var inspectionGeneralIdList = ChangeTracker.Entries().Where(t => typeof(DataInspection).IsAssignableFrom(t.Entity.GetType())).Select(t => ((DataInspection)t.Entity).GeneralId).ToList(); - - var entities = ChangeTracker.Entries().Where(u => (u.State == EntityState.Modified || u.State == EntityState.Deleted || u.State == EntityState.Added)) - .Where(t => !typeof(DataInspection).IsAssignableFrom(t.Entity.GetType()) && !inspectionGeneralIdList.Contains(((Entity)t.Entity).Id)) - .ToList(); - AuditingData auditingData = new AuditingData(this, _userInfo); - - //await auditingData.IncomingEntitys(entities); - - - if (entities.Count > 0) - { - await auditingData.InsertAddEntitys(entities); - - } - - - } #region Doctor public virtual DbSet Dictionary { get; set; } @@ -399,7 +379,6 @@ namespace IRaCIS.Core.Infra.EFCore public virtual DbSet TrialAudit { get; set; } public virtual DbSet UserType { get; set; } - public virtual DbSet SaveChangesAudits { get; set; } diff --git a/IRaCIS.Core.Infra.EFCore/EntityConfigration/ReadModuleConfigration.cs b/IRaCIS.Core.Infra.EFCore/EntityConfigration/ReadModuleConfigration.cs new file mode 100644 index 000000000..5d7c8d501 --- /dev/null +++ b/IRaCIS.Core.Infra.EFCore/EntityConfigration/ReadModuleConfigration.cs @@ -0,0 +1,18 @@ +using IRaCIS.Core.Domain.Models; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Metadata.Builders; + + +namespace IRaCIS.Core.Infra.EFCore.EntityConfigration +{ + public class ReadModuleConfigration : IEntityTypeConfiguration + { + + + public void Configure(EntityTypeBuilder builder) + { + + builder.HasOne(t => t.SubjectVisit).WithMany(t => t.ReadModuleList); + } + } +} diff --git a/IRaCIS.Core.Infra.EFCore/IRaCIS.Core.Infra.EFCore.csproj b/IRaCIS.Core.Infra.EFCore/IRaCIS.Core.Infra.EFCore.csproj index bbedc4058..0f0f66b72 100644 --- a/IRaCIS.Core.Infra.EFCore/IRaCIS.Core.Infra.EFCore.csproj +++ b/IRaCIS.Core.Infra.EFCore/IRaCIS.Core.Infra.EFCore.csproj @@ -19,11 +19,11 @@ - + - - + + diff --git a/IRaCIS.Core.Infra.EFCore/Interceptor/AuditEntityInterceptor.cs b/IRaCIS.Core.Infra.EFCore/Interceptor/AuditEntityInterceptor.cs index b8235e0e8..3167bad6a 100644 --- a/IRaCIS.Core.Infra.EFCore/Interceptor/AuditEntityInterceptor.cs +++ b/IRaCIS.Core.Infra.EFCore/Interceptor/AuditEntityInterceptor.cs @@ -1,6 +1,9 @@ using IRaCIS.Core.Domain.Models; using IRaCIS.Core.Domain.Share; +using IRaCIS.Core.Infra.EFCore.Common; +using Microsoft.AspNetCore.Mvc.Diagnostics; using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.ChangeTracking; using Microsoft.EntityFrameworkCore.Diagnostics; using System; using System.Linq; @@ -23,8 +26,12 @@ public class AuditEntityInterceptor(IUserInfo _userInfo) : SaveChangesIntercepto public override ValueTask> SavingChangesAsync(DbContextEventData eventData, InterceptionResult result, CancellationToken cancellationToken = default) { + //审计时间 AuditEntities(eventData.Context); + //IRC稽查 放在savechange 之前 不影响之前的逻辑 + IRCDataInspection(eventData.Context); + return base.SavingChangesAsync(eventData, result, cancellationToken); } public override InterceptionResult SavingChanges(DbContextEventData eventData, InterceptionResult result) @@ -38,7 +45,7 @@ public class AuditEntityInterceptor(IUserInfo _userInfo) : SaveChangesIntercepto if (context == null) return; // 获取所有更改,删除,新增的实体,但排除审计实体(避免死循环) - foreach (var entry in context.ChangeTracker.Entries().Where(u => (u.State == EntityState.Modified || u.State == EntityState.Added)) + foreach (var entry in context.ChangeTracker.Entries().Where(u => (u.State == EntityState.Modified || u.State == EntityState.Added)) .Where(x => !typeof(DataInspection).IsAssignableFrom(x.Entity.GetType())).ToList()) { switch (entry.State) @@ -103,7 +110,23 @@ public class AuditEntityInterceptor(IUserInfo _userInfo) : SaveChangesIntercepto break; } } + } - + public void IRCDataInspection(DbContext? context) + { + //触发器里面提交事务 业务方法里面提交事务 会记录两次 + var inspectionGeneralIdList = context.ChangeTracker.Entries().Where(t => typeof(DataInspection).IsAssignableFrom(t.Entity.GetType())).Select(t => ((DataInspection)t.Entity).GeneralId).ToList(); + + var entities = context.ChangeTracker.Entries().Where(u => (u.State == EntityState.Modified || u.State == EntityState.Deleted || u.State == EntityState.Added)) + .Where(t => !typeof(DataInspection).IsAssignableFrom(t.Entity.GetType()) && !inspectionGeneralIdList.Contains(((Entity)t.Entity).Id)) + .ToList(); + AuditingData auditingData = new AuditingData((IRaCISDBContext)context, _userInfo); + + + if (entities.Count > 0) + { + auditingData.InsertAddEntitys(entities).GetAwaiter().GetResult(); + + } } } \ No newline at end of file diff --git a/IRaCIS.Core.Infra.EFCore/Interceptor/DispatchDomainEventsInterceptor.cs b/IRaCIS.Core.Infra.EFCore/Interceptor/DispatchDomainEventsInterceptor.cs index e12a02704..b18186107 100644 --- a/IRaCIS.Core.Infra.EFCore/Interceptor/DispatchDomainEventsInterceptor.cs +++ b/IRaCIS.Core.Infra.EFCore/Interceptor/DispatchDomainEventsInterceptor.cs @@ -11,6 +11,8 @@ using MassTransit; namespace IRaCIS.Core.Infra.EFCore.Interceptor { + // ISendEndpoint:提供了Send方法,用于发送命令。 + //IPublishEndpoint:提供了Publish方法,用于发布事件。 public class DispatchDomainEventsInterceptor(IPublishEndpoint publishEndpoint) : SaveChangesInterceptor { diff --git a/IRaCIS.Core.Infra.EFCore/Interceptor/OldAuditInterceptor.cs b/IRaCIS.Core.Infra.EFCore/Interceptor/OldAuditInterceptor.cs deleted file mode 100644 index 879e42af5..000000000 --- a/IRaCIS.Core.Infra.EFCore/Interceptor/OldAuditInterceptor.cs +++ /dev/null @@ -1,148 +0,0 @@ -using System; -using System.Linq; -using System.Threading; -using System.Threading.Tasks; -using IRaCIS.Core.Domain.Models; -using IRaCIS.Core.Infra.EFCore; -using Microsoft.EntityFrameworkCore; -using Microsoft.EntityFrameworkCore.ChangeTracking; -using Microsoft.EntityFrameworkCore.Diagnostics; - -public class AuditingInterceptor : ISaveChangesInterceptor -{ - private readonly string _connectionString; - private SaveChangesAudit _audit; - - public AuditingInterceptor(string connectionString) - { - _connectionString = connectionString; - } - - #region SavingChanges - public async ValueTask> SavingChangesAsync( - DbContextEventData eventData, - InterceptionResult result, - CancellationToken cancellationToken = default) - { - _audit = CreateAudit(eventData.Context); - - await Task.CompletedTask; - return result; - - - } - - public InterceptionResult SavingChanges( - DbContextEventData eventData, - InterceptionResult result) - { - _audit = CreateAudit(eventData.Context); - - return result; - } - #endregion - - #region SavedChanges - - public async ValueTask SavedChangesAsync( - SaveChangesCompletedEventData eventData, - int result, - CancellationToken cancellationToken = default) - { - if (_audit.Entities.Count > 0) - { - var auditContext = eventData.Context as IRaCISDBContext; - _audit.Succeeded = true; - auditContext.SaveChangesAudits.Add(_audit); - _audit.EndTime = DateTime.Now; - - await auditContext.SaveChangesAsync(); - } - - return result; - } - #endregion - - #region SaveChangesFailed - public void SaveChangesFailed(DbContextErrorEventData eventData) - { - using (var auditContext = new AuditContext(_connectionString)) - { - auditContext.Attach(_audit); - _audit.Succeeded = false; - _audit.EndTime = DateTime.Now; - _audit.ErrorMessage = eventData.Exception.Message; - - auditContext.SaveChanges(); - } - } - - public async Task SaveChangesFailedAsync( - DbContextErrorEventData eventData, - CancellationToken cancellationToken = default) - { - using (var auditContext = new AuditContext(_connectionString)) - { - auditContext.Attach(_audit); - _audit.Succeeded = false; - _audit.EndTime = DateTime.Now; - _audit.ErrorMessage = eventData.Exception.InnerException?.Message; - - await auditContext.SaveChangesAsync(cancellationToken); - } - } - #endregion - - - - #region CreateAudit - private static bool NeedAudit(EntityEntry entityEntry) - { - var type = entityEntry.Entity.GetType(); - return type != typeof(EntityAudit) && type != typeof(SaveChangesAudit) && type != typeof(DicomSeries) && type != typeof(DicomInstance) && type != typeof(TrialAudit); - } - - private static SaveChangesAudit CreateAudit(DbContext context) - { - context.ChangeTracker.DetectChanges(); - - var audit = new SaveChangesAudit { StartTime = DateTime.Now }; - - foreach (var entry in context.ChangeTracker.Entries().Where(t => NeedAudit(t))) - { - var auditMessage = entry.State switch - { - EntityState.Deleted => CreateDeletedMessage(entry), - EntityState.Modified => CreateModifiedMessage(entry), - EntityState.Added => CreateAddedMessage(entry), - _ => null - }; - - if (auditMessage != null) - { - var alterIdStr = entry.CurrentValues["Id"].ToString(); - audit.Entities.Add(new EntityAudit { State = entry.State, AuditMessage = auditMessage, AlterId = Guid.Parse(alterIdStr) }); - } - } - - return audit; - - string CreateAddedMessage(EntityEntry entry) - => - entry.Properties.Aggregate( - $"Inserting {entry.Metadata.DisplayName()} with ", - (auditString, property) => auditString + $"{property.Metadata.Name}: '{property.CurrentValue}' "); - - string CreateModifiedMessage(EntityEntry entry) - => entry.Properties.Where(property => property.IsModified || property.Metadata.IsPrimaryKey()).Aggregate( - $"Updating {entry.Metadata.DisplayName()} with ", - (auditString, property) => auditString + $"{property.Metadata.Name}: '{property.CurrentValue}' "); - - string CreateDeletedMessage(EntityEntry entry) - => entry.Properties.Where(property => property.Metadata.IsPrimaryKey()).Aggregate( - $"Deleting {entry.Metadata.DisplayName()} with ", - (auditString, property) => auditString + $"{property.Metadata.Name}: '{property.CurrentValue}' "); - } - #endregion - -} \ No newline at end of file diff --git a/IRaCIS.Core.Infrastructure/IRaCIS.Core.Infrastructure.csproj b/IRaCIS.Core.Infrastructure/IRaCIS.Core.Infrastructure.csproj index 39d3b1d66..e952396a9 100644 --- a/IRaCIS.Core.Infrastructure/IRaCIS.Core.Infrastructure.csproj +++ b/IRaCIS.Core.Infrastructure/IRaCIS.Core.Infrastructure.csproj @@ -11,14 +11,14 @@ - + - + - + - + diff --git a/IRaCIS.Core.Infrastructure/_IRaCIS/Input/PageInput.cs b/IRaCIS.Core.Infrastructure/_IRaCIS/Input/PageInput.cs index b3dad6a0a..b1a6978fe 100644 --- a/IRaCIS.Core.Infrastructure/_IRaCIS/Input/PageInput.cs +++ b/IRaCIS.Core.Infrastructure/_IRaCIS/Input/PageInput.cs @@ -5,12 +5,11 @@ namespace IRaCIS.Core.Infrastructure.Extention /// /// 分页信息输入 /// - public class PageInput + public class PageInput: SortInput { public int PageIndex { get; set; } = 1; public int PageSize { set; get; } = 10; - public bool Asc { get; set; } = true; - public string SortField { get; set; } = ""; + } public class SortInput diff --git a/IRaCIS.Core.Test/IRaCIS.Core.Test.csproj b/IRaCIS.Core.Test/IRaCIS.Core.Test.csproj index 2d9915d1d..0be844e14 100644 --- a/IRaCIS.Core.Test/IRaCIS.Core.Test.csproj +++ b/IRaCIS.Core.Test/IRaCIS.Core.Test.csproj @@ -12,16 +12,6 @@ ..\bin - - - - - - all - runtime; build; native; contentfiles; analyzers; buildtransitive - - - IRaCIS .Core.ServiceAsync.cs @@ -105,6 +95,7 @@ + diff --git a/IRaCIS.Core.Test/Test/Audit/AuditContext.cs b/IRaCIS.Core.Test/Test/Audit/AuditContext.cs deleted file mode 100644 index 2fc55e0ea..000000000 --- a/IRaCIS.Core.Test/Test/Audit/AuditContext.cs +++ /dev/null @@ -1,43 +0,0 @@ -using System; -using System.Collections.Generic; -using Microsoft.EntityFrameworkCore; - -#region AuditContext -public class AuditContext : DbContext -{ - private readonly string _connectionString; - - public AuditContext(string connectionString) - { - _connectionString = connectionString; - } - - //protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) - // => optionsBuilder.Usesq(_connectionString); - - public DbSet SaveChangesAudits { get; set; } -} - - -public class SaveChangesAudit -{ - public int Id { get; set; } - public Guid AuditId { get; set; } - public DateTime StartTime { get; set; } - public DateTime EndTime { get; set; } - public bool Succeeded { get; set; } - public string ErrorMessage { get; set; } - - public ICollection Entities { get; } = new List(); -} - -public class EntityAudit -{ - public int Id { get; set; } - public EntityState State { get; set; } - public string AuditMessage { get; set; } - - public SaveChangesAudit SaveChangesAudit { get; set; } -} - -#endregion \ No newline at end of file