diff --git a/IRaCIS.Core.Application/Service/Reading/ClinicalData/ClinicalAnswerService.cs b/IRaCIS.Core.Application/Service/Reading/ClinicalData/ClinicalAnswerService.cs index 19b0d7c54..4270ceab9 100644 --- a/IRaCIS.Core.Application/Service/Reading/ClinicalData/ClinicalAnswerService.cs +++ b/IRaCIS.Core.Application/Service/Reading/ClinicalData/ClinicalAnswerService.cs @@ -198,6 +198,7 @@ namespace IRaCIS.Core.Application.Service .Include(x=>x.ClinicalDataTrialSet).Select(x=>new GetCRCSubjectClinicalOutDto() { SubjectId=x.SubjectId, SubjectCode=x.Subject.Code, + TrialId=inDto.TrialId, ClinicalDataTrialSetId = x.ClinicalDataTrialSet.Id, ClinicalDataSetEnName= x.ClinicalDataTrialSet.ClinicalDataSetEnName, ClinicalDataSetName = x.ClinicalDataTrialSet.ClinicalDataSetName, @@ -408,56 +409,157 @@ namespace IRaCIS.Core.Application.Service [HttpPost] public async Task> GetCRCConfirmList(GetCRCConfirmListInDto inDto) { - - List result = await _readModuleRepository.Where(x => x.TrialId == inDto.TrialId) - .Select(x => new GetCRCConfirmListOutDto() - { - IsCRCConfirm = x.IsCRCConfirm, - LatestScanDate = x.SubjectVisit.LatestScanDate, - ReadingSetType = x.ReadingSetType, - IsPMConfirm = x.IsPMConfirm, - ReadModuleId=x.Id, - - }).OrderBy(x => x.LatestScanDate).ToListAsync(); - - var formList = await _clinicalFormRepository.Where(x => x.TrialId == inDto.TrialId) - .Where(x=> x.ClinicalDataTrialSet.UploadRole==UploadRole.CRC) - .Where(x=> x.ClinicalDataTrialSet.ClinicalDataLevel==ClinicalLevel.ImageRead|| x.ClinicalDataTrialSet.ClinicalDataLevel == ClinicalLevel.OncologyRead) - .Select(x =>new CRCConfirmFormList - { - CkeckDate=x.CheckDate, - ClinicalDataLevel= x.ClinicalDataTrialSet.ClinicalDataLevel, - - - }).ToListAsync(); - - var confirmList = await _readModuleCriterionFromRepository.Where(x => x.TrialId == inDto.TrialId).ToListAsync(); - + List result = await _readModuleRepository.Where(x => x.TrialId == inDto.TrialId) + .Select(x => new GetCRCConfirmListOutDto() + { + SubjectId= x.SubjectId, + IsCRCConfirm = x.IsCRCConfirm, + LatestScanDate = x.SubjectVisit.LatestScanDate, + ReadingSetType = x.ReadingSetType, + IsPMConfirm = x.IsPMConfirm, + ReadModuleId = x.Id, + }).OrderBy(x => x.LatestScanDate).ToListAsync(); + var formList = await _clinicalFormRepository.Where(x => x.TrialId == inDto.TrialId) + .Where(x => x.ClinicalDataTrialSet.UploadRole == UploadRole.CRC) + .Where(x => x.ClinicalDataTrialSet.ClinicalDataLevel == ClinicalLevel.ImageRead || x.ClinicalDataTrialSet.ClinicalDataLevel == ClinicalLevel.OncologyRead) + .Select(x => new CRCClinicalForm + { + CkeckDate = x.CheckDate, + ClinicalDataLevel = x.ClinicalDataTrialSet.ClinicalDataLevel, + ClinicalFormId = x.Id, + }).ToListAsync(); + var confirmList = await _readModuleCriterionFromRepository.Where(x => x.TrialId == inDto.TrialId).ToListAsync(); result.ForEach(x => { if (x.IsCRCConfirm) { - x.FormCount = confirmList.Where(y => y.ReadModuleId == x.ReadModuleId).Count(); - + x.ClinicalFormIdList = confirmList.Where(y => y.ReadModuleId == x.ReadModuleId).Select(y=>y.ClinicalFormId).ToList(); } else { if (x.ReadingSetType == ReadingSetType.ImageReading) { - x.FormCount = formList.Where(y => y.ClinicalDataLevel == ClinicalLevel.ImageRead&&y.CkeckDate<=x.LatestScanDate).Count(); - + x.ClinicalFormIdList = formList.Where(y => y.ClinicalDataLevel == ClinicalLevel.ImageRead&&y.CkeckDate<=x.LatestScanDate).Select(y => y.ClinicalFormId).ToList(); } else { - x.FormCount = formList.Where(y => y.ClinicalDataLevel == ClinicalLevel.OncologyRead&&y.CkeckDate <= x.LatestScanDate).Count(); + x.ClinicalFormIdList = formList.Where(y => y.ClinicalDataLevel == ClinicalLevel.OncologyRead&&y.CkeckDate <= x.LatestScanDate).Select(y => y.ClinicalFormId).ToList(); } - } - }); return result; } + /// + /// CRC 确认临床数据 + /// + /// + /// + [HttpPost] + public async Task CRCConfirmClinical(CRCConfirmClinicalInDto inDto) + { + var dataList =await this.GetCRCConfirmList(new GetCRCConfirmListInDto() + { + TrialId = inDto.TrialId + }); + + var presentData = dataList.Where(x => x.ReadModuleId == inDto.ReadModuleId).First(); + var confirmlist= dataList.Where(x =>(x.LatestScanDate < presentData.LatestScanDate && x.ReadingSetType == presentData.ReadingSetType) + || x.ReadModuleId == presentData.ReadModuleId).Where(x => !x.IsCRCConfirm).ToList(); + + List needAddList = new List() + { + + }; + confirmlist.ForEach(x => + { + x.ClinicalFormIdList.ForEach(y => + { + needAddList.Add(new ReadModuleCriterionFrom() + { + ClinicalFormId = y, + ReadModuleId = x.ReadModuleId, + SubjectId = x.SubjectId, + TrialId = inDto.TrialId, + }); + }); + }); + + var readModuleIds = confirmlist.Select(x => x.ReadModuleId).ToList(); + + await _readModuleRepository.UpdatePartialFromQueryAsync(x => readModuleIds.Contains(x.Id),x=>new ReadModule() { + IsCRCConfirm=true + }); + await _readModuleCriterionFromRepository.AddRangeAsync(needAddList); + + await _readModuleCriterionFromRepository.SaveChangesAsync(); + + return ResponseOutput.Ok(true); + } + + /// + /// CRC 取消确认 + /// + /// + /// + [HttpPost] + public async Task CRCCancelConfirmClinical(CRCCancelConfirmClinicalInDto inDto) + { + var dataList = await this.GetCRCConfirmList(new GetCRCConfirmListInDto() + { + TrialId = inDto.TrialId + }); + + var presentData = dataList.Where(x => x.ReadModuleId == inDto.ReadModuleId).First(); + + if (dataList.Any(x => x.IsPMConfirm && x.LatestScanDate > presentData.LatestScanDate && x.ReadingSetType == presentData.ReadingSetType)) + { + throw new BusinessValidationFailedException("当前数据并非最后一条确认信息,无法取消!"); + } + + if(presentData.IsPMConfirm) + { + throw new BusinessValidationFailedException("PM已确认,无法取消!"); + } + + + await _readModuleRepository.UpdatePartialFromQueryAsync(x => presentData.ReadModuleId==x.Id, x => new ReadModule() + { + IsCRCConfirm = false + }); + + await _readModuleCriterionFromRepository.BatchDeleteNoTrackingAsync(x=>x.ReadModuleId== presentData.ReadModuleId); + + await _readModuleCriterionFromRepository.SaveChangesAsync(); + + return ResponseOutput.Ok(true); + } + + /// + /// PM确认临床数据 + /// + /// + /// + /// + [HttpPost] + public async Task PMConfirmClinical(CRCConfirmClinicalInDto inDto) + { + var readModuleData = await _readModuleRepository.Where(x => x.Id == inDto.ReadModuleId).FirstNotNullAsync(); + if (!readModuleData.IsCRCConfirm) + { + throw new BusinessValidationFailedException("CRC还未确认数据,PM无法确认"); + } + + await _readModuleRepository.UpdatePartialFromQueryAsync(x => inDto.ReadModuleId == x.Id, x => new ReadModule() + { + IsPMConfirm = false + }); + + await _readModuleRepository.SaveChangesAsync(); + + return ResponseOutput.Ok(true); + } + } } diff --git a/IRaCIS.Core.Application/Service/Reading/ClinicalData/ClinicalQuestionService.cs b/IRaCIS.Core.Application/Service/Reading/ClinicalData/ClinicalQuestionService.cs index 79dde8334..93b92894a 100644 --- a/IRaCIS.Core.Application/Service/Reading/ClinicalData/ClinicalQuestionService.cs +++ b/IRaCIS.Core.Application/Service/Reading/ClinicalData/ClinicalQuestionService.cs @@ -42,12 +42,79 @@ namespace IRaCIS.Core.Application.Service _systemClinicalQuestionRepository = systemClinicalQuestionRepository; } - /// - /// 获取系统临床数据预览 - /// - /// - /// - [HttpPost] + /// + /// 获取问题计算关系 + /// + /// + /// + [HttpPost] + public async Task> GetTrialClinicalQuestionCalculateRelation(GetTrialClinicalQuestionCalculateRelationInDto inDto) + { + + var result= await _trialClinicalQuestionRepository.Where(x => x.TrialClinicalId == inDto.TrialClinicalId) + .Where( x=> x.ClinicalQuestionType == "number") + .Where(x => x.CustomCalculateMark != null && x.CustomCalculateMark > ClinicalCalculateMark.None) + .Select(x => new GetTrialClinicalQuestionCalculateRelationOutDto() + { + QuestionId = x.Id, + QuestionName = x.QuestionName, + CustomCalculateMark = x.CustomCalculateMark, + CalculateQuestionList = x.CalculateQuestionList, + }).ToListAsync(); + result = result.Where(x => x.CalculateQuestionList.Count() > 0).ToList(); + return result; + } + + /// + /// 获取计算问题 + /// + /// + /// + [HttpPost] + public async Task> GetClinicalCalculateQuestions(GetClinicalCalculateQuestionsInDto inDto) + { + var result = await _trialClinicalQuestionRepository + + .Where(x => x.TrialClinicalId == inDto.TrialClinicalId) + .WhereIf(!inDto.ClinicalQuestionType.IsNullOrEmpty(), x => x.ClinicalQuestionType == inDto.ClinicalQuestionType) + .OrderBy(x => x.ShowOrder) + .Select(x => new GetClinicalCalculateQuestionsOutDto + () + { + QuestionId = x.Id, + QuestionName = x.QuestionName.LanguageName(x.QuestionEnName, _userInfo.IsEn_Us) + + }).ToListAsync(); + + var tablequestion = await _trialClinicalTableQuestionRepository.Where(x => x.TrialClinicalId == inDto.TrialClinicalId && x.ClinicalTableQuestionType == "number").Select(x => + new + { + TableQuestionId = x.Id, + QuestionId= x.QuestionId, + QuestionName = x.QuestionName.LanguageName(x.QuestionEnName, _userInfo.IsEn_Us) + }).ToListAsync(); + + + result.ForEach(x => + { + x.TableQuestions = tablequestion.Where(y => x.QuestionId == y.QuestionId).Select(y => new CalculateQuestion() + { + + QuestionId = y.QuestionId, + QuestionName = y.QuestionName + + }).ToList(); + }); + + return result; + } + + /// + /// 获取系统临床数据预览 + /// + /// + /// + [HttpPost] public async Task<(List, bool)> GetSystemClinicalQuestionPreview(GetSystemClinicalQuestionPreviewDto inDto) { var questions = await _systemClinicalQuestionRepository.Where(x => x.SystemClinicalId == inDto.SystemClinicalId) @@ -104,7 +171,10 @@ namespace IRaCIS.Core.Application.Service public void FindChildQuestion(ClinicalQuestionPreviewDto item, List questions, List tableQuestions,List answers, List tableAnswers) { item.Childrens = questions.Where(x => (x.ParentId == item.Id)||(x.GroupId== item.Id&&x.ParentId==null)).ToList(); - item.Answer = answers.Where(x => x.QuestionId == item.Id).Select(x => x.Answer).FirstOrDefault()??string.Empty; + + item.RelationQuestions = questions.Where(x => x.RelevanceId == item.Id).ToList(); + + item.Answer = answers.Where(x => x.QuestionId == item.Id).Select(x => x.Answer).FirstOrDefault()??string.Empty; var tableIndexs = tableAnswers.Where(x => x.QuestionId == item.Id).Select(x => x.RowIndex).Distinct().OrderBy(x=>x).ToList(); @@ -120,10 +190,14 @@ namespace IRaCIS.Core.Application.Service item.TableQuestions = tableQuestions.Where(x => x.QuestionId == item.Id).OrderBy(x=>x.ShowOrder).ToList(); - item.Childrens.ForEach(x => { + item.RelationQuestions.ForEach(x => { this.FindChildQuestion(x, questions, tableQuestions, answers, tableAnswers); }); - } + + item.Childrens.ForEach(x => { + this.FindChildQuestion(x, questions, tableQuestions, answers, tableAnswers); + }); + } #region 项目问题 diff --git a/IRaCIS.Core.Application/Service/Reading/Dto/ClinicalAnswerDto.cs b/IRaCIS.Core.Application/Service/Reading/Dto/ClinicalAnswerDto.cs index 081775f70..4e125fd93 100644 --- a/IRaCIS.Core.Application/Service/Reading/Dto/ClinicalAnswerDto.cs +++ b/IRaCIS.Core.Application/Service/Reading/Dto/ClinicalAnswerDto.cs @@ -28,6 +28,8 @@ namespace IRaCIS.Core.Application.Service.Reading.Dto { public Guid SubjectId { get; set; } + public Guid TrialId { get; set; } + public string SubjectCode { get; set; } public Guid ClinicalDataTrialSetId { get; set; } @@ -99,10 +101,27 @@ namespace IRaCIS.Core.Application.Service.Reading.Dto public Guid TrialId { get; set; } } - public class CRCConfirmFormList + public class CRCCancelConfirmClinicalInDto + { + public Guid TrialId { get; set; } + + public Guid ReadModuleId { get; set; } + } + + public class CRCConfirmClinicalInDto + { + public Guid TrialId { get; set; } + + public Guid ReadModuleId { get; set; } + } + + + public class CRCClinicalForm { public DateTime? CkeckDate { get; set; } + public Guid ClinicalFormId { get; set; } + /// /// 临床级别 /// @@ -112,6 +131,11 @@ namespace IRaCIS.Core.Application.Service.Reading.Dto public class GetCRCConfirmListOutDto { + + /// + /// 受试者ID + /// + public Guid SubjectId { get; set; } public Guid ReadModuleId { get; set; } public bool IsPMConfirm { get; set; } @@ -125,7 +149,16 @@ namespace IRaCIS.Core.Application.Service.Reading.Dto /// public DateTime? LatestScanDate { get; set; } - public int FormCount { get; set; } + + public List ClinicalFormIdList { get; set; } + + public int FormCount + { + get + { + return this.ClinicalFormIdList.Count(); + } + } } public class SubmitClinicalFormInDto diff --git a/IRaCIS.Core.Application/Service/Reading/Dto/ClinicalQuestionDto.cs b/IRaCIS.Core.Application/Service/Reading/Dto/ClinicalQuestionDto.cs index 56894a7f5..f38dd1bca 100644 --- a/IRaCIS.Core.Application/Service/Reading/Dto/ClinicalQuestionDto.cs +++ b/IRaCIS.Core.Application/Service/Reading/Dto/ClinicalQuestionDto.cs @@ -1,6 +1,8 @@ using IRaCIS.Core.Domain.Share; +using Newtonsoft.Json; using System; using System.Collections.Generic; +using System.ComponentModel.DataAnnotations.Schema; using System.Linq; using System.Text; using System.Threading.Tasks; @@ -8,10 +10,80 @@ using System.Threading.Tasks; namespace IRaCIS.Core.Application.Service.Reading.Dto { - #region 预览 - public class GetSystemClinicalQuestionPreviewDto + #region 获取计算问题 + + public class GetTrialClinicalQuestionCalculateRelationInDto + { + /// + /// 项目临床数据Id + /// + public Guid TrialClinicalId { get; set; } + } + + + public class GetTrialClinicalQuestionCalculateRelationOutDto + { + public Guid QuestionId { get; set; } + + /// + /// 问题名称 + /// + public string QuestionName { get; set; } + + /// + /// 自定义计算标记 + /// + public ClinicalCalculateMark? CustomCalculateMark { get; set; } + + /// + /// 数值类型 + /// + public ValueOfType? ValueType { get; set; } + + /// + /// 单位 + /// + public ValueUnit? Unit { get; set; } + + /// + /// 自定义单位 + /// + public string CustomUnit { get; set; } = string.Empty; + + public List CalculateQuestionList { get; set; } + } + + + public class GetClinicalCalculateQuestionsOutDto + { + public Guid QuestionId { get; set; } + + public string QuestionName { get; set; } + + public List TableQuestions { get; set; } + } + + + public class GetClinicalCalculateQuestionsInDto + { + /// + /// 项目临床数据Id + /// + public Guid TrialClinicalId { get; set; } + + /// + /// 临床问题类型(分组,单选。) + /// + public string ClinicalQuestionType { get; set; } = string.Empty; + } + #endregion + + #region 预览 + + + public class GetSystemClinicalQuestionPreviewDto { /// /// 系统临床数据Id @@ -44,10 +116,16 @@ namespace IRaCIS.Core.Application.Service.Reading.Dto /// public List Childrens { get; set; } = new List(); - /// - /// 表格问题 - /// - public List TableQuestions { get; set; } = new List(); + + /// + /// 关联问题 + /// + public List RelationQuestions { get; set; } = new List(); + + /// + /// 表格问题 + /// + public List TableQuestions { get; set; } = new List(); public List> TableAnswer { get; set; } } @@ -172,7 +250,37 @@ namespace IRaCIS.Core.Application.Service.Reading.Dto /// 单位 /// public string Unit { get; set; } = string.Empty; - } + + /// + /// 自定义计算标记 + /// + public ClinicalCalculateMark? CustomCalculateMark { get; set; } + + /// + /// 自定义计算问题 + /// + public string CalculateQuestions { get; set; } = "[]"; + + [NotMapped] + public List CalculateQuestionList + { + get + { + + try + { + var result = JsonConvert.DeserializeObject>(this.CalculateQuestions); + return result == null ? new List() : result; + } + catch (Exception) + { + + return new List(); + } + + } + } + } /// /// 查询临床数据基类 @@ -212,16 +320,6 @@ namespace IRaCIS.Core.Application.Service.Reading.Dto /// 项目临床数据Id /// public Guid TrialClinicalId { get; set; } - - /// - /// 自定义计算标记 - /// - public ClinicalCalculateMark? ClinicalCalculateMarkEnum { get; set; } - - /// - /// 自定义计算问题 - /// - public string CalculateQuestions { get; set; } = "[]"; } /// diff --git a/IRaCIS.Core.Domain.Share/Reading/ReadEnum.cs b/IRaCIS.Core.Domain.Share/Reading/ReadEnum.cs index 826d10683..3608eb7fa 100644 --- a/IRaCIS.Core.Domain.Share/Reading/ReadEnum.cs +++ b/IRaCIS.Core.Domain.Share/Reading/ReadEnum.cs @@ -61,11 +61,12 @@ namespace IRaCIS.Core.Domain.Share /// public enum ClinicalCalculateMark { + None = -1, - /// - /// + - /// - Add = 1, + /// + /// + + /// + Add = 1, /// /// - diff --git a/IRaCIS.Core.Domain/Reading/ClinicalQuestion/SystemClinicalQuestion.cs b/IRaCIS.Core.Domain/Reading/ClinicalQuestion/SystemClinicalQuestion.cs index dac8fb262..539c62c0d 100644 --- a/IRaCIS.Core.Domain/Reading/ClinicalQuestion/SystemClinicalQuestion.cs +++ b/IRaCIS.Core.Domain/Reading/ClinicalQuestion/SystemClinicalQuestion.cs @@ -8,6 +8,7 @@ using IRaCIS.Core.Domain.Share; using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations.Schema; using IRaCIS.Core.Domain.Models; +using System.Collections.Generic; namespace IRaCIS.Core.Domain.Models { @@ -126,7 +127,37 @@ namespace IRaCIS.Core.Domain.Models /// 单位 /// public string Unit { get; set; } = string.Empty; - } + + /// + /// 自定义计算标记 + /// + public ClinicalCalculateMark? CustomCalculateMark { get; set; } + + /// + /// 自定义计算问题 + /// + public string CalculateQuestions { get; set; } = "[]"; + + [NotMapped] + public List CalculateQuestionList + { + get + { + + try + { + var result = JsonConvert.DeserializeObject>(this.CalculateQuestions); + return result == null ? new List() : result; + } + catch (Exception) + { + + return new List(); + } + + } + } + } } diff --git a/IRaCIS.Core.Domain/Reading/ClinicalQuestion/TrialClinicalQuestion.cs b/IRaCIS.Core.Domain/Reading/ClinicalQuestion/TrialClinicalQuestion.cs index 97ef17e9e..f741b2f93 100644 --- a/IRaCIS.Core.Domain/Reading/ClinicalQuestion/TrialClinicalQuestion.cs +++ b/IRaCIS.Core.Domain/Reading/ClinicalQuestion/TrialClinicalQuestion.cs @@ -8,6 +8,7 @@ using IRaCIS.Core.Domain.Share; using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations.Schema; using IRaCIS.Core.Domain.Models; +using System.Collections.Generic; namespace IRaCIS.Core.Domain.Models { @@ -125,17 +126,37 @@ namespace IRaCIS.Core.Domain.Models /// /// 自定义计算标记 /// - public ClinicalCalculateMark? ClinicalCalculateMarkEnum { get; set; } + public ClinicalCalculateMark? CustomCalculateMark { get; set; } /// /// 自定义计算问题 /// public string CalculateQuestions { get; set; } = "[]"; - /// - /// 小数点位数 - /// - public int? DigitPlaces { get; set; } + [NotMapped] + public List CalculateQuestionList + { + get + { + + try + { + var result = JsonConvert.DeserializeObject>(this.CalculateQuestions); + return result == null ? new List() : result; + } + catch (Exception) + { + + return new List(); + } + + } + } + + /// + /// 小数点位数 + /// + public int? DigitPlaces { get; set; } /// /// 单位