diff --git a/IRaCIS.Core.API/appsettings.json b/IRaCIS.Core.API/appsettings.json index 791297540..f142d1f51 100644 --- a/IRaCIS.Core.API/appsettings.json +++ b/IRaCIS.Core.API/appsettings.json @@ -57,9 +57,10 @@ } } }, - "UpdateConfig": { - "test": "123456", - "test1": "12345678" + "IRaCISImageStore": { + "SwitchingMode": "RemainingDiskCapacity", + "SwitchingRatio": 80, + "NotificationEmail": "872297557@qq.com" }, "IRaCISBasicConfig": { "DoctorCodePrefix": "RE", diff --git a/IRaCIS.Core.Application/Service/Common/SystemMonitor.cs b/IRaCIS.Core.Application/Service/Common/SystemMonitor.cs index 80e6973fb..429e4f4b7 100644 --- a/IRaCIS.Core.Application/Service/Common/SystemMonitor.cs +++ b/IRaCIS.Core.Application/Service/Common/SystemMonitor.cs @@ -16,6 +16,7 @@ using System.Text.Json.Nodes; using System.Text.Encodings.Web; using Newtonsoft.Json.Linq; using Newtonsoft.Json; +using IRaCIS.Core.Infrastructure; namespace IRaCIS.Core.Application.Service.Common { @@ -44,136 +45,95 @@ namespace IRaCIS.Core.Application.Service.Common } + + + public string GetBestStoreDisk() { + var json = File.ReadAllText("appsettings.json"); + + JObject jsonObject = JObject.Parse(json, new JsonLoadSettings() { CommentHandling = CommentHandling.Load }); + + int switchingRatio = 80; + + try + { + switchingRatio = (int)jsonObject["IRaCISImageStore"]["SwitchingRatio"]; + } + catch (Exception e) + { + + throw new BusinessValidationFailedException("解析Json文件配置出现问题"); + } + //默认存储的路径 var defaultStoreRootFolder = Path.Combine((Directory.GetParent(_hostEnvironment.ContentRootPath.TrimEnd('\\'))).IfNullThrowException().FullName, StaticData.Folder.IRaCISDataFolder); - - - + DriveInfo defaultDrive = new DriveInfo(Path.GetPathRoot(defaultStoreRootFolder)); var drives = DriveInfo.GetDrives().Where(t => !t.Name.Contains("C") && !t.Name.Contains("c")) .Where(d => d.DriveType == DriveType.Fixed && d.IsReady) + //剩余空间最多的 .OrderByDescending(d => d.AvailableFreeSpace) + + //存储空间相同,则按照按照总空间从大到小排序 .ThenByDescending(d => d.TotalSize - d.TotalFreeSpace); var bestDrive = drives.FirstOrDefault(); var bestStoreRootFolder = string.Empty; //仅仅只有C 盘 - if (bestDrive == null) + if (bestDrive == null || ((double)(defaultDrive.TotalSize - defaultDrive.TotalFreeSpace) / defaultDrive.TotalSize) * 100 < switchingRatio) { bestStoreRootFolder = defaultStoreRootFolder; } else { - bestStoreRootFolder = drives.FirstOrDefault()?.Name + _hostEnvironment.EnvironmentName; + bestStoreRootFolder = Path.Combine(drives.FirstOrDefault()?.Name, _hostEnvironment.EnvironmentName); } - DriveInfo drive = new DriveInfo(Path.GetPathRoot(defaultStoreRootFolder)); + + //找到最优驱动器 + DriveInfo drive = new DriveInfo(Path.GetPathRoot(bestStoreRootFolder)); //最优盘符使用率超过百分之80 - if (((double)(drive.TotalSize - drive.TotalFreeSpace) / drive.TotalSize) * 100 > 80) + if (((double)(drive.TotalSize - drive.TotalFreeSpace) / drive.TotalSize) * 100 > switchingRatio) { } + if (!Directory.Exists(bestStoreRootFolder)) + { + Directory.CreateDirectory(bestStoreRootFolder); + } return bestStoreRootFolder; } + public class GeneralRule + { + public string Endpoint { get; set; } + public string Period { get; set; } + public int Limit { get; set; } + } + public void UpdateAppSettings(string key, string newValue) { - #region NewtonSoftJson - //// 读取 JSON 文件 - //string jsonFilePath = "appsettings.json"; - //string jsonString = File.ReadAllText(jsonFilePath); - - //// 解析 JSON 文件 - //var jObject = JsonConvert.DeserializeObject(jsonString); - - //// 更新或添加配置项 - //jObject[key] = newValue; - - //// 将更新后的 JSON 字符串写入文件 - //using var streamWriter = new StreamWriter(jsonFilePath); - //using var jsonTextWriter = new JsonTextWriter(streamWriter); - //jsonTextWriter.Formatting = Formatting.Indented; - //jObject.WriteTo(jsonTextWriter); - #endregion - - #region test - //var json = File.ReadAllText("appsettings.json"); - //var jObject = JToken.Parse(json, new JsonLoadSettings { CommentHandling = CommentHandling.Load,DuplicatePropertyNameHandling=DuplicatePropertyNameHandling.Ignore }); - - //// Update or add the property - //jObject[key] = newValue; - - //// Preserve comments - //var settings = new JsonSerializerSettings - //{ - // PreserveReferencesHandling = PreserveReferencesHandling.Objects, - // Formatting = Formatting.Indented, - // StringEscapeHandling = StringEscapeHandling.Default, - - //}; - //var updatedJson = JsonConvert.SerializeObject(jObject, settings); - //File.WriteAllText("appsettings.json", updatedJson); - - //var json = File.ReadAllText("appsettings.json"); - //var jToken = JToken.Parse(json); - - //// Update or add the property - //jToken[key] = newValue; - - //// Preserve comments - //var settings = new JsonSerializerSettings - //{ - // TypeNameHandling = TypeNameHandling.All, - // PreserveReferencesHandling = PreserveReferencesHandling.Objects, - // Formatting = Formatting.Indented, - // StringEscapeHandling = StringEscapeHandling.Default - //}; - //var updatedJson = JsonConvert.SerializeObject(jToken, settings); - //File.WriteAllText("appsettings.json", updatedJson); - - - //string json = @"{ - // // This is a comment - // ""Name"": ""John Smith"", - // ""Age"": 30, - // ""Address"": { - // // This is another comment - // ""Street"": ""123 Main St"", - // ""City"": ""Anytown"", - // ""State"": ""CA"", - // ""Zip"": ""12345"" - // } - //}"; - - //// 使用 Json.NET 库解析 JSON 字符串 - //JObject jObject = JObject.Parse(json, new JsonLoadSettings() { CommentHandling = CommentHandling.Load }); - - //// 修改属性 - //jObject["Name"] = "Jane Smith"; - - //// 将修改后的 JObject 对象序列化为 JSON 字符串并保留注释 - //string newJson = jObject.ToString(Newtonsoft.Json.Formatting.Indented); - - //// 打印修改后的 JSON 字符串 - //Console.WriteLine(newJson); - - #endregion - + List generalRules = new List() +{ + new GeneralRule() { Endpoint = "*", Period = "1s", Limit = 3 }, + new GeneralRule() { Endpoint = "*", Period = "15m", Limit = 100 }, + new GeneralRule() { Endpoint = "*", Period = "12h", Limit = 1000 }, + new GeneralRule() { Endpoint = "*", Period = "7d", Limit = 10000 } +}; // 读取 Json 文件 string jsonFilePath = "appsettings.json"; @@ -181,37 +141,17 @@ namespace IRaCIS.Core.Application.Service.Common var json = File.ReadAllText("appsettings.json"); JObject jsonObject = JObject.Parse(json, new JsonLoadSettings() { CommentHandling = CommentHandling.Load }); - // 获取 UpdateConfig 属性所在的节点 - JToken updateConfigNode = jsonObject.SelectToken("UpdateConfig"); - JProperty updateConfigProperty = (JProperty)updateConfigNode.Parent; - JObject updateConfigParent = (JObject)updateConfigProperty.Value; - // 向 updateConfigParent 添加或者属性 - updateConfigParent[key] = newValue; + // 操作UpdateConfig对象 + jsonObject["UpdateConfig"][key] = newValue; + jsonObject["UpdateConfig"]["testArray"] = JArray.FromObject(generalRules); // 将更改保存回 Json 文件 File.WriteAllText(jsonFilePath, jsonObject.ToString()); - //using (var reader = new JsonTextReader(new StringReader(json))) - //using (var writer = new JsonTextWriter(new StreamWriter("appsettings.json"))) - //{ - // while (reader.Read()) - // { - // if (reader.TokenType == JsonToken.PropertyName && (string)reader.Value == key) - // { - // // Write the updated property value - // writer.WritePropertyName(key); - // writer.WriteValue(newValue); - // reader.Read(); - // continue; - // } - // // Write all other tokens - // writer.WriteToken(reader.TokenType, reader.Value); - // } - //} diff --git a/IRaCIS.Core.Application/Service/TrialSiteUser/DTO/TrialConfigDTO.cs b/IRaCIS.Core.Application/Service/TrialSiteUser/DTO/TrialConfigDTO.cs index 57c1f8329..da05ba48e 100644 --- a/IRaCIS.Core.Application/Service/TrialSiteUser/DTO/TrialConfigDTO.cs +++ b/IRaCIS.Core.Application/Service/TrialSiteUser/DTO/TrialConfigDTO.cs @@ -126,14 +126,14 @@ namespace IRaCIS.Core.Application.Contracts public bool? IsClinicalReading { get; set; } - + public int? DigitPlaces { get; set; } - // ////读片任务显示是否顺序 - //// public bool IsReadingTaskViewInOrder { get; set; } = false; + // ////读片任务显示是否顺序 + //// public bool IsReadingTaskViewInOrder { get; set; } = false; /// @@ -188,7 +188,7 @@ namespace IRaCIS.Core.Application.Contracts /// public bool IsTrialProcessConfirmed { get; set; } = false; - + //阅片方式 public int ReadingMode { get; set; } @@ -205,7 +205,7 @@ namespace IRaCIS.Core.Application.Contracts public ArbitrationRule ArbitrationRule { get; set; } - + } @@ -230,7 +230,7 @@ namespace IRaCIS.Core.Application.Contracts /// /// 阅片是否显示受试者信息 /// - public bool IsReadingShowSubjectInfo { get; set; } + public bool IsReadingShowSubjectInfo { get; set; } /// /// 阅片是否显示既往结果 @@ -269,7 +269,7 @@ namespace IRaCIS.Core.Application.Contracts /// /// 阅片是否显示既往结果 /// - public bool IsReadingShowPreviousResults { get; set; } + public bool IsReadingShowPreviousResults { get; set; } } public class TrialJudgeTaskConfig @@ -302,7 +302,7 @@ namespace IRaCIS.Core.Application.Contracts public bool IsPDProgressView { get; set; } - + } @@ -425,8 +425,10 @@ namespace IRaCIS.Core.Application.Contracts /// public DateTime? ReadingInfoSignTime { get; set; } - public bool IsSign { - get { + public bool IsSign + { + get + { return this.ReadingInfoSignTime != null; } } @@ -479,6 +481,9 @@ namespace IRaCIS.Core.Application.Contracts public bool IsAutoCreate { get; set; } + public List TrialCriterionAdditionalAssessmentTypeList { get; set; } = new List(); + + } @@ -524,7 +529,7 @@ namespace IRaCIS.Core.Application.Contracts public Guid CreateUserId { get; set; } } - public class TrialReadQuestion :ReadingQuestionTrial + public class TrialReadQuestion : ReadingQuestionTrial { /// /// 分页名称 @@ -552,11 +557,11 @@ namespace IRaCIS.Core.Application.Contracts public int? ParentQuestionShowOrder { get; set; } - + } - public class TrialAdditionaQuestion: TrialReadQuestion + public class TrialAdditionaQuestion : TrialReadQuestion { public List Childrens { get; set; } = new List(); public string Answer { get; set; } = string.Empty; @@ -565,7 +570,7 @@ namespace IRaCIS.Core.Application.Contracts public class TrialJudgeQuestion { - + public Guid ReadingQuestionCriterionTrialId { get; set; } public Guid QuestionId { get; set; } @@ -722,7 +727,7 @@ namespace IRaCIS.Core.Application.Contracts public string EvaluationReason { get; set; } = string.Empty; - + } public class GetGlobalReadingOutDto @@ -771,7 +776,7 @@ namespace IRaCIS.Core.Application.Contracts /// /// IsBaseLineUse /// - public bool IsBaseLineUse { get; set; } + public bool IsBaseLineUse { get; set; } /// /// IsBaseUse @@ -793,7 +798,7 @@ namespace IRaCIS.Core.Application.Contracts [NotDefault] public Guid TrialReadingCriterionId { get; set; } - + } public class SetTrialReadingCriterionInDto @@ -801,7 +806,7 @@ namespace IRaCIS.Core.Application.Contracts public Guid TrialReadingCriterionId { get; set; } - + /// /// 表单类型 @@ -905,7 +910,7 @@ namespace IRaCIS.Core.Application.Contracts /// public bool IsReadingShowPreviousResults { get; set; } - + /// /// 仲裁规则/对象 @@ -935,6 +940,8 @@ namespace IRaCIS.Core.Application.Contracts /// public bool IsOncologyReading { get; set; } + public List TrialCriterionAdditionalAssessmentTypeList { get; set; }=new List(); + } public class SignConfirmDTO diff --git a/IRaCIS.Core.Application/Service/TrialSiteUser/TrialConfigService.cs b/IRaCIS.Core.Application/Service/TrialSiteUser/TrialConfigService.cs index 7e875cf48..adc751bf5 100644 --- a/IRaCIS.Core.Application/Service/TrialSiteUser/TrialConfigService.cs +++ b/IRaCIS.Core.Application/Service/TrialSiteUser/TrialConfigService.cs @@ -19,6 +19,7 @@ using static IRaCIS.Core.Domain.Share.StaticData; using IRaCIS.Core.Application.Service; using DocumentFormat.OpenXml.Office.CustomUI; using IRaCIS.Core.Application.Service; +using IRaCIS.Core.Domain.Models; namespace IRaCIS.Core.Application { @@ -181,8 +182,6 @@ namespace IRaCIS.Core.Application public async Task GetCriterionReadingInfo(GetTrialReadingInfoInDto inDto) { - - GetTrialReadingInfoOutDto trialInfo = await _readingQuestionCriterionTrialRepository.Where(x => x.Id == inDto.TrialReadingCriterionId).ProjectTo(_mapper.ConfigurationProvider).FirstNotNullAsync(); if (trialInfo.ReadingTool == null) @@ -190,6 +189,9 @@ namespace IRaCIS.Core.Application trialInfo.ReadingTool = ReadingTool.Dicom; } + trialInfo.TrialCriterionAdditionalAssessmentTypeList = await _trialCriterionAdditionalAssessmentTypeRepository.Where(t => t.TrialReadingCriterionId == inDto.TrialReadingCriterionId).ToListAsync(); + + return trialInfo; } @@ -209,6 +211,28 @@ namespace IRaCIS.Core.Application if (trialCriterion.SynchronizeOriginalTime == null) { + + //同步附加评估类型 + + if (!await _trialCriterionAdditionalAssessmentTypeRepository.AnyAsync(t => t.TrialReadingCriterionId == inDto.TrialReadingCriterionId)) + { + AdditionalAssessment additional = new AdditionalAssessment(); + var addList = additional.GetSystemDefeaultAdditionalAssessmentList(trialCriterion.CriterionType); + + foreach (var addItem in addList) + { + await _trialCriterionAdditionalAssessmentTypeRepository.AddAsync(new TrialCriterionAdditionalAssessmentType() + { + CriterionType = trialCriterion.CriterionType, + TrialReadingCriterionId = inDto.TrialReadingCriterionId, + AdditionalAssessmentType = addItem.AdditionalAssessmentType + }); + } + } + + + + // 同步器官 await _iOrganInfoService.SynchronizeSystemOrganToTrial(new SynchronizeSystemOrganToTrialInDto() { @@ -517,7 +541,7 @@ namespace IRaCIS.Core.Application if (count == 0) { - //---当前标准下未配置问题 + //---当前标准下未配置问题 throw new BusinessValidationFailedException(_localizer["TrialConfig_StdConfigMissing"]); } } @@ -576,24 +600,68 @@ namespace IRaCIS.Core.Application }); - //判断是否存在附加评估,存在,就将标准对应的附加评估选项加进去 + //判断是否存在附加评估 if (inDto.IsAdditionalAssessment) { - if (!await _trialCriterionAdditionalAssessmentTypeRepository.AnyAsync(t => t.TrialReadingCriterionId == inDto.TrialReadingCriterionId)) - { - AdditionalAssessment additional = new AdditionalAssessment(); - var addList = additional.GetSystemDefeaultAdditionalAssessmentList(inDto.CriterionType); + #region 存在,就将标准对应的附加评估选项加进去--废弃 修改到同步标准的地方去了,不管存在附加评估与否,都增加附加评估类型 + //if (!await _trialCriterionAdditionalAssessmentTypeRepository.AnyAsync(t => t.TrialReadingCriterionId == inDto.TrialReadingCriterionId)) + //{ + // AdditionalAssessment additional = new AdditionalAssessment(); + // var addList = additional.GetSystemDefeaultAdditionalAssessmentList(inDto.CriterionType); - foreach (var addItem in addList) + // foreach (var addItem in addList) + // { + // await _trialCriterionAdditionalAssessmentTypeRepository.AddAsync(new TrialCriterionAdditionalAssessmentType() + // { + // CriterionType = inDto.CriterionType, + // TrialReadingCriterionId = inDto.TrialReadingCriterionId, + // AdditionalAssessmentType = addItem.AdditionalAssessmentType + // }); + // } + //} + #endregion + + + if (inDto.TrialCriterionAdditionalAssessmentTypeList.All(t => t.IsSelected != true)) + { + throw new BusinessValidationFailedException("选择了附加评估,必须勾选附加评估类型"); + } + + var trialId = _readingQuestionTrialRepository.Where(t => t.ReadingQuestionCriterionTrialId == inDto.TrialReadingCriterionId).Select(t => t.TrialId).FirstOrDefault(); + + + if (inDto.TrialCriterionAdditionalAssessmentTypeList.Count != 0) + { + foreach (var updateItem in inDto.TrialCriterionAdditionalAssessmentTypeList) { - await _trialCriterionAdditionalAssessmentTypeRepository.AddAsync(new TrialCriterionAdditionalAssessmentType() + if (updateItem.IsSelected == true) { - CriterionType = inDto.CriterionType, - TrialReadingCriterionId = inDto.TrialReadingCriterionId, - AdditionalAssessmentType = addItem.AdditionalAssessmentType - }); + //添加默认问题 + AdditionalAssessment additional = new AdditionalAssessment(); + var addTypeList = additional.GetSystemDefeaultAdditionalAssessmentList(updateItem.CriterionType, updateItem.AdditionalAssessmentType); + + foreach (var addType in addTypeList) + { + foreach (var question in addType.AdditionalQuestionList) + { + question.ReadingQuestionCriterionTrialId = updateItem.TrialReadingCriterionId; + question.TrialId = trialId; + + await _readingQuestionTrialRepository.AddAsync(question); + } + } + } + else + { + //删除附加问题 + + await _readingQuestionTrialRepository.BatchDeleteNoTrackingAsync(t => t.ReadingQuestionCriterionTrialId == updateItem.TrialReadingCriterionId && t.IsAdditional == true); + } + + await _trialCriterionAdditionalAssessmentTypeRepository.UpdatePartialFromQueryAsync(updateItem.Id, t => new TrialCriterionAdditionalAssessmentType() { IsSelected = updateItem.IsSelected }); } } + } else { @@ -612,6 +680,7 @@ namespace IRaCIS.Core.Application /// /// /// + [Obsolete] public async Task> GetTrialCriterionAdditionalAssessmentOptionList(Guid trialReadingCriterionId) { return await _trialCriterionAdditionalAssessmentTypeRepository.Where(t => t.TrialReadingCriterionId == trialReadingCriterionId).ToListAsync(); @@ -623,6 +692,7 @@ namespace IRaCIS.Core.Application /// /// /// + [Obsolete] public async Task SetTrialCriterionAdditionalAssessment(List updateList) { @@ -631,7 +701,8 @@ namespace IRaCIS.Core.Application return ResponseOutput.Ok(); } - var trialId= _readingQuestionTrialRepository.Where(t=>t.ReadingQuestionCriterionTrialId==updateList.First().TrialReadingCriterionId).Select(t=>t.TrialId).FirstOrDefault(); + var trialId = _readingQuestionTrialRepository.Where(t => t.ReadingQuestionCriterionTrialId == updateList.First().TrialReadingCriterionId).Select(t => t.TrialId).FirstOrDefault(); + foreach (var updateItem in updateList) { if (updateItem.IsSelected == true) @@ -727,7 +798,7 @@ namespace IRaCIS.Core.Application { if (showOrderList.Count == 0) { - //---当前未添加影像质控审核问题。请先添加影像质控审核问题,再进行确认。 + //---当前未添加影像质控审核问题。请先添加影像质控审核问题,再进行确认。 throw new BusinessValidationFailedException(_localizer["TrialConfig_NoImageAuditQuestion"]); } } @@ -797,26 +868,26 @@ namespace IRaCIS.Core.Application { if (showOrderList.Count == 0) { - //---当前未添加影像质控审核问题。请先添加影像质控审核问题,再进行确认。 + //---当前未添加影像质控审核问题。请先添加影像质控审核问题,再进行确认。 throw new BusinessValidationFailedException(_localizer["TrialConfig_NoImageAuditQuestion"]); } } if (showOrderList.Count() != showOrderList.Select(t => t.ShowOrder).Distinct().Count()) { - //---影像质控审核问题显示序号不能重复。 + //---影像质控审核问题显示序号不能重复。 throw new BusinessValidationFailedException(_localizer["TrialConfig_DuplicateAuditQuestionId"]); } if (showOrderList.Where(t => t.ParentShowOrder != null).Any(t => t.ParentShowOrder > t.ShowOrder)) { - //---父问题的显示序号要比子问题的显示序号小,请确认。 + //---父问题的显示序号要比子问题的显示序号小,请确认。 throw new BusinessValidationFailedException(_localizer["TrialConfig_InvalidParentQuestionId"]); } if (await _trialRepository.AnyAsync(t => t.Id == signConfirmDTO.TrialId && t.QCQuestionConfirmedUserId != null && t.QCQuestionConfirmedUserId != _userInfo.Id)) { - //---影像质控审核问题已被其他人员确认,不允许再次确认。 + //---影像质控审核问题已被其他人员确认,不允许再次确认。 throw new BusinessValidationFailedException(_localizer["TrialConfig_AuditQuestionConfirmed"]); } @@ -976,7 +1047,7 @@ namespace IRaCIS.Core.Application var canOPt = await _trialRepository.AnyAsync(trial => trial.Id == trialId && trial.IsTrialBasicLogicConfirmed && trial.IsTrialProcessConfirmed && trial.IsTrialUrgentConfirmed && trial.VisitPlanConfirmed); - //---该项目的项目配置(基础配置、流程配置、加急配置) 、访视管理,有配置未确认,不能设置项目状态为启动。 + //---该项目的项目配置(基础配置、流程配置、加急配置) 、访视管理,有配置未确认,不能设置项目状态为启动。 return ResponseOutput.Ok(canOPt, msg: canOPt ? "" : _localizer["TrialConfig_UnconfirmedConfiguration"]); } @@ -1004,7 +1075,7 @@ namespace IRaCIS.Core.Application } else { - //---无法变更项目状态。该项目的项目配置、访视管理中,有未确认项 + //---无法变更项目状态。该项目的项目配置、访视管理中,有未确认项 return ResponseOutput.NotOk(_localizer["TrialConfig_UnconfirmedUNACKD"]); } }