From 04b98e6e7204e304afee41888dc020e3e188eeec Mon Sep 17 00:00:00 2001 From: he <10978375@qq.com> Date: Fri, 29 Apr 2022 08:57:19 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- IRaCIS.Core.Domain/Trial/DataInspection.cs | 3 +- .../Dto/SetDictionaryValueDto.cs | 76 +++++++ .../Repository/Repository.cs | 208 ++++++++++++++++-- 3 files changed, 268 insertions(+), 19 deletions(-) diff --git a/IRaCIS.Core.Domain/Trial/DataInspection.cs b/IRaCIS.Core.Domain/Trial/DataInspection.cs index b6d8e94fe..c585bee03 100644 --- a/IRaCIS.Core.Domain/Trial/DataInspection.cs +++ b/IRaCIS.Core.Domain/Trial/DataInspection.cs @@ -38,8 +38,7 @@ namespace IRaCIS.Core.Domain.Models /// /// 项目iD /// - [Required] - public Guid TrialId { get; set; } + public Guid? TrialId { get; set; } /// /// 中心 diff --git a/IRaCIS.Core.Infra.EFCore/Dto/SetDictionaryValueDto.cs b/IRaCIS.Core.Infra.EFCore/Dto/SetDictionaryValueDto.cs index 02ca2f968..fa8691efa 100644 --- a/IRaCIS.Core.Infra.EFCore/Dto/SetDictionaryValueDto.cs +++ b/IRaCIS.Core.Infra.EFCore/Dto/SetDictionaryValueDto.cs @@ -17,6 +17,82 @@ namespace IRaCIS.Core.Infra.EFCore.Dto } + /// + /// 稽查数据 + /// + public class InspectionData + { + public dynamic Data { get; set; } + + public InspectionGeneralData Inspection { get; set; } + } + + /// + /// 稽查外层数据 + /// + public class InspectionGeneralData + { + /// + /// 项目iD + /// + public Guid? TrialId { get; set; } + + /// + /// 中心 + /// + public Guid? SiteId { get; set; } + + /// + /// 受试者 + /// + public Guid? SubjectId { get; set; } + + /// + /// 访视 + /// + public Guid? SubjectVisitId { get; set; } + + /// + /// 创建人名称 + /// + public string CreateUserName { get; set; } + + /// + /// 项目名称 + /// + public string TrialName { get; set; } + + /// + /// 中心名称 + /// + public string SiteName { get; set; } + + /// + /// 受试者名称 + /// + public string SubjectCode { get; set; } + + /// + /// 访视名称 + /// + public string SubjectVisitName { get; set; } + + /// + /// 角色名称 + /// + public string RoleName { get; set; } + + /// + /// 中心Code + /// + public string SiteCode { get; set; } + + /// + /// 项目编码 + /// + public string ResearchProgramNo { get; set; } + } + public class SetInspectionEnum { public string Identification { get; set; } diff --git a/IRaCIS.Core.Infra.EFCore/Repository/Repository.cs b/IRaCIS.Core.Infra.EFCore/Repository/Repository.cs index a3d771e01..b8dc1adf4 100644 --- a/IRaCIS.Core.Infra.EFCore/Repository/Repository.cs +++ b/IRaCIS.Core.Infra.EFCore/Repository/Repository.cs @@ -770,19 +770,24 @@ namespace IRaCIS.Core.Infra.EFCore /// 添加稽查记录 /// /// 实体 - /// + /// 是否保存 /// private async Task AddInspectionAsync(TEntity entity, bool isSaveAudit = false) { - List datas = new List(); - - var createtime = DateTime.Now.AddMilliseconds(200); + bool needsave = true; + DataInspection inspectionData = new DataInspection() { + Identification = $"{GetRequestUrl()}/{ typeof(TEntity).ToString().Substring(typeof(TEntity).ToString().LastIndexOf('.') + 1)}/Add", + }; + + + MapData(entity, inspectionData); + var createtime = DateTime.Now; // 项目 if (typeof(TEntity) == typeof(Trial)) { Trial data = entity as Trial; - datas.Add(new DataInspection() + inspectionData = new DataInspection() { TrialId = data.Id, SubjectId = data.Id, @@ -792,17 +797,18 @@ namespace IRaCIS.Core.Infra.EFCore CreateTime = createtime, Identification = "Init|Trial|Status|Trial Setting-Infomation", // 初始化项目 JsonDetail = entity.ToJcJson() - }); - - + }; + } + // 项目人员 + else if (typeof(TEntity) == typeof(TrialUser)) + { } - // 受试者 - if (typeof(TEntity) == typeof(Subject)) + else if (typeof(TEntity) == typeof(Subject)) { Subject data = entity as Subject; - datas.Add(new DataInspection() + inspectionData = new DataInspection() { TrialId = data.TrialId, SiteId = data.SiteId, @@ -812,9 +818,7 @@ namespace IRaCIS.Core.Infra.EFCore CreateTime = createtime, Identification = "Init|Subject|Status|Subject", // 初始化受试者信息 JsonDetail = entity.ToJcJson() - }); - - + }; } // Dicom序列 // 移动不进来 @@ -857,6 +861,10 @@ namespace IRaCIS.Core.Infra.EFCore var subjectVisitId = await _dbContext.NoneDicomStudy.Where(x => x.Id == data.NoneDicomStudyId).Select(x => x.SubjectVisitId).FirstOrDefaultAsync(); await UpdateSubjectVisit(subjectVisitId, SubmitStateEnum.ToSubmit, "上传非Dicom影像"); } + else + { + needsave = false; + } // 修改访视状态记录稽查 async Task UpdateSubjectVisit(Guid subvisitVisit, SubmitStateEnum submit, string reason) @@ -866,7 +874,7 @@ namespace IRaCIS.Core.Infra.EFCore { subjectvisit.SubmitState = submit; - datas.Add(new DataInspection() + inspectionData = new DataInspection() { Identification = "Edit|Visit|Status|Visit-Image Upload|Add Image", TrialId = subjectvisit.TrialId, @@ -876,15 +884,110 @@ namespace IRaCIS.Core.Infra.EFCore Reason = reason, CreateTime = createtime.AddMilliseconds(100), JsonDetail = subjectvisit.ToJcJson(), - }); + }; } } - await AddListInspectionRecordAsync(datas); + if (needsave) + { + await AddInspectionRecordAsync(inspectionData, entity); + } + } + + + /// + /// 获取URl参数 + /// + /// + private string GetRequestUrl() + { + return _userInfo.RequestUrl; + } + + /// + /// 映射数据 + /// + /// + /// 要赋值的对象 + private void MapData(dynamic data, dynamic mapData) + { + List column = new List() { "TrialId", "SiteId", "SubjectId", "SubjectVisitId", "CreateUserName", "TrialName", "SiteName", "SubjectCode", "SubjectVisitName", "RoleName", "SiteCode", "ResearchProgramNo" }; + foreach (var item in column) + { + try + { + var i = mapData.GetType().GetProperty(item).GetValue(mapData); + if (i == null) + { + var value = data.GetType().GetProperty(item).GetValue(data); + mapData.GetType().GetProperty(item).SetValue(mapData, value); + } + + } + catch (Exception) + { + continue; + + } + } + } + + + /// + /// 添加稽查记录 + /// + /// 稽查数据 + /// 实体信息 + /// + public async Task AddInspectionRecordAsync(DataInspection add, dynamic data) + { + InspectionGeneralData generalData = new InspectionGeneralData(); + MapData(add, generalData); + await SetInspectionNameValue(generalData); + #region 处理标识 + try + { + var from = await _dbContext.FrontAuditConfig.FirstOrDefaultAsync(x => x.Identification == add.Identification); + add.ObjectType = from?.ObjectTypeId; + add.OptType = from?.OptTypeId; + add.ChildrenType = from?.ChildrenTypeId; + add.ModuleType = from?.ModuleTypeId; + } + catch (Exception) + { + + throw new BusinessValidationFailedException("操作标识异常"); + } + #endregion + if (add.ParentId == null) + { + add.ParentId = (await _dbContext.DataInspection.AsQueryable().Where(x => x.TrialId == add.TrialId && x.SubjectVisitId == add.SubjectVisitId && x.SubjectId == add.SubjectId && x.SiteId == add.SiteId && x.ChildrenType == add.ChildrenType && x.ObjectType == add.ObjectType && x.VisitStageId == add.VisitStageId && x.GeneralId == add.GeneralId).OrderByDescending(x => x.CreateTime).FirstOrDefaultAsync())?.Id; + + } + add.CreateUserId = _userInfo.Id; + add.IP = _userInfo.IP; + if (add.CreateTime == default(DateTime)) + { + add.CreateTime = DateTime.Now; + } + var inspectionData = new InspectionData() + { + Data = data, + Inspection = generalData + }; + + add.JsonDetail = inspectionData.ToJcJson(); + await SetDataInspectionDateType(add); + + await _dbContext.DataInspection.AddAsync(add); + } + + + /// /// 添加稽查记录 /// @@ -1099,6 +1202,77 @@ namespace IRaCIS.Core.Infra.EFCore #endregion + } + + + /// + /// 设置项目以及名称 + /// + /// + /// + public async Task SetInspectionNameValue(InspectionGeneralData Data) + { + #region 项目名称 + + var trialdata = await _dbContext.Trial.Select(x => new { x.Id, x.ResearchProgramNo, x.ExperimentName, }).FirstOrDefaultAsync(x => x.Id == Data.TrialId); + if (IsNullOrEmpty(Data.ResearchProgramNo)) + { + + Data.ResearchProgramNo = trialdata?.ResearchProgramNo; + } + + if (IsNullOrEmpty(Data.TrialName)) + { + Data.TrialName = trialdata?.ExperimentName; + } + #endregion + + #region 测试中心名称 + + + Data.SiteCode = (await _dbContext.TrialSite.IgnoreQueryFilters().FirstOrDefaultAsync(x => x.TrialId == Data.TrialId && x.SiteId == Data.SiteId))?.TrialSiteCode; + + + + if (IsNullOrEmpty(Data.SiteName) && Data.SiteId != null) + { + var sitedata = await _dbContext.Site.Where(x => x.Id == Data.SiteId).Select(x => new { x.SiteName }).FirstOrDefaultAsync(); + Data.SiteName = sitedata?.SiteName; + } + #endregion + + #region 受试者 + + + if (IsNullOrEmpty(Data.SubjectCode) && Data.SubjectId != null) + { + + Data.SubjectCode = (await _dbContext.Subject.Where(x => x.Id == Data.SubjectId).Select(x => new { x.Code }).FirstOrDefaultAsync())?.Code; + } + #endregion + + #region 访视 + if (IsNullOrEmpty(Data.SubjectVisitName)) + { + Data.SubjectVisitName = (await _dbContext.SubjectVisit.Where(x => x.Id == Data.SubjectVisitId).Select(x => new { x.VisitName }).FirstOrDefaultAsync())?.VisitName; + } + #endregion + + #region 创建者 + + if (IsNullOrEmpty(Data.CreateUserName)) + { + Data.CreateUserName = _userInfo.RealName; + } + + if (IsNullOrEmpty(Data.RoleName)) + { + Data.RoleName = _userInfo.UserTypeShortName; + } + #endregion + + + } #endregion