From d5507e057091828674df83f2e21bb5a550b5601e Mon Sep 17 00:00:00 2001 From: hang <872297557@qq.com> Date: Tue, 30 Aug 2022 17:28:45 +0800 Subject: [PATCH] =?UTF-8?q?qc=20=20=E9=97=AE=E9=A2=98=E7=A8=BD=E6=9F=A5?= =?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.Application/Helper/ImageHelper.cs | 14 - .../IRaCIS.Core.Application.xml | 16 + .../Service/ImageAndDoc/StudyService.cs | 1 + .../Service/WorkLoad/DoctorWorkloadService.cs | 18 +- .../Common/AuditingData.cs | 352 +++++++++++++----- .../Common/IAuditingData.cs | 4 +- .../Context/IRaCISDBContext.cs | 4 +- .../Helper/IdentifierHelper.cs | 22 ++ 8 files changed, 306 insertions(+), 125 deletions(-) create mode 100644 IRaCIS.Core.Infrastructure/Helper/IdentifierHelper.cs diff --git a/IRaCIS.Core.Application/Helper/ImageHelper.cs b/IRaCIS.Core.Application/Helper/ImageHelper.cs index 59a3d6b98..50f0ab4f6 100644 --- a/IRaCIS.Core.Application/Helper/ImageHelper.cs +++ b/IRaCIS.Core.Application/Helper/ImageHelper.cs @@ -58,19 +58,5 @@ public static class ImageHelper } -static class IdentifierHelper -{ - private static MD5 md5 = MD5.Create(); - private static object lockObj = new object(); - - public static Guid CreateGuid(params string[] parts) - { - lock (lockObj) - { - return new Guid(md5.ComputeHash(Encoding.UTF8.GetBytes(string.Concat(parts)))); - } - - } -} diff --git a/IRaCIS.Core.Application/IRaCIS.Core.Application.xml b/IRaCIS.Core.Application/IRaCIS.Core.Application.xml index c278294a7..b98441b03 100644 --- a/IRaCIS.Core.Application/IRaCIS.Core.Application.xml +++ b/IRaCIS.Core.Application/IRaCIS.Core.Application.xml @@ -3628,6 +3628,12 @@ + + + 获取上一个访视任务Id + + + 阅片医学审核 @@ -7042,6 +7048,16 @@ IR影像阅片 + + + 获取表格答案行信息 + + + + (QuestionId) 可为空 + + + 获取表格问题及答案(2022-08-26) diff --git a/IRaCIS.Core.Application/Service/ImageAndDoc/StudyService.cs b/IRaCIS.Core.Application/Service/ImageAndDoc/StudyService.cs index f5d390e7d..5ba8d03d0 100644 --- a/IRaCIS.Core.Application/Service/ImageAndDoc/StudyService.cs +++ b/IRaCIS.Core.Application/Service/ImageAndDoc/StudyService.cs @@ -6,6 +6,7 @@ using IRaCIS.Core.Application.Services; using EasyCaching.Core; using System.Linq.Expressions; using IRaCIS.Core.Application.Helper; +using IRaCIS.Core.Infrastructure; namespace IRaCIS.Core.Application.Service.ImageAndDoc { diff --git a/IRaCIS.Core.Application/Service/WorkLoad/DoctorWorkloadService.cs b/IRaCIS.Core.Application/Service/WorkLoad/DoctorWorkloadService.cs index 341302222..d7c47b4a9 100644 --- a/IRaCIS.Core.Application/Service/WorkLoad/DoctorWorkloadService.cs +++ b/IRaCIS.Core.Application/Service/WorkLoad/DoctorWorkloadService.cs @@ -121,15 +121,17 @@ namespace IRaCIS.Application.Services } - if (inDto.ReadingCategorys.Count > 0) - { - await _enrollReadingCategoryRepository.BatchDeleteNoTrackingAsync(x => x.EnrollId == inDto.EnrollId); + //if (inDto.ReadingCategorys.Count > 0) + //{ + // await _enrollReadingCategoryRepository.BatchDeleteNoTrackingAsync(x => x.EnrollId == inDto.EnrollId); - } - else - { - await _enrollReadingCategoryRepository.DeleteFromQueryAsync(x => x.EnrollId == inDto.EnrollId); - } + //} + //else + //{ + // await _enrollReadingCategoryRepository.DeleteFromQueryAsync(x => x.EnrollId == inDto.EnrollId); + //} + + await _enrollReadingCategoryRepository.DeleteFromQueryAsync(x => x.EnrollId == inDto.EnrollId); List enrollReadings = inDto.ReadingCategorys.Select(x => new EnrollReadingCategory() diff --git a/IRaCIS.Core.Infra.EFCore/Common/AuditingData.cs b/IRaCIS.Core.Infra.EFCore/Common/AuditingData.cs index d52c6b407..4bf05a630 100644 --- a/IRaCIS.Core.Infra.EFCore/Common/AuditingData.cs +++ b/IRaCIS.Core.Infra.EFCore/Common/AuditingData.cs @@ -51,27 +51,7 @@ namespace IRaCIS.Core.Infra.EFCore.Common _userInfo.BatchId = _userInfo.BatchId == null ? NewId.NextGuid() : _userInfo.BatchId; } - /// - /// 传入实体对象 - /// - public async Task IncomingEntitys(List entitys) - { - // 修改 - await InsertAddEntitys( - entitys.Where(x => x.State == EntityState.Modified && - (!typeof(ISoftDelete).IsAssignableFrom(x.Entity.GetType()) || !(bool)x.Entity.GetType().GetProperty(nameof(ISoftDelete.IsDeleted)).GetValue(x.Entity) || NodeleteTableTypes.Contains(x.Entity.GetType())) - ).ToList(), AuditOpt.Update); - // 新增 - await InsertAddEntitys(entitys.Where(x => x.State == EntityState.Added).ToList(), AuditOpt.Add); - - // 删除 - await InsertAddEntitys(entitys.Where(x => x.State == EntityState.Deleted - || (typeof(ISoftDelete).IsAssignableFrom(x.Entity.GetType()) && (bool)x.Entity.GetType().GetProperty(nameof(ISoftDelete.IsDeleted)).GetValue(x.Entity) && x.State == EntityState.Modified && !NodeleteTableTypes.Contains(x.Entity.GetType())) - ).ToList(), AuditOpt.Deleted); - - - } /// /// 特殊删除 @@ -91,11 +71,36 @@ namespace IRaCIS.Core.Infra.EFCore.Common } } + + public string GetEntityAuditOpt(EntityEntry entityEntry) + { + if (entityEntry.State == EntityState.Added) + { + return AuditOpt.Add; + } + + else if (entityEntry.State == EntityState.Deleted || + (entityEntry.State == EntityState.Modified + && typeof(ISoftDelete).IsAssignableFrom(entityEntry.Entity.GetType()) + && (bool)entityEntry.Entity.GetType().GetProperty(nameof(ISoftDelete.IsDeleted)).GetValue(entityEntry.Entity) + && entityEntry.State == EntityState.Modified + && !NodeleteTableTypes.Contains(entityEntry.Entity.GetType()) + ) + ) + { + return AuditOpt.Deleted; + } + else + { + return AuditOpt.Update; + } + } + /// /// 插入Add的实体 /// /// - public async Task InsertAddEntitys(List entitys, string type) + public async Task InsertAddEntitys(List entitys) { #region 区分 @@ -104,6 +109,8 @@ namespace IRaCIS.Core.Infra.EFCore.Common foreach (var item in entitys.Where(x => x.Entity.GetType() == typeof(Trial))) { + var type = GetEntityAuditOpt(item); + var entity = item.Entity as Trial; List trialDics = new List(); var dictionaryIds = new List(); @@ -131,6 +138,8 @@ namespace IRaCIS.Core.Infra.EFCore.Common // 系统文件签署 父层级未记录稽查(系统文档初始数据) foreach (var item in entitys.Where(x => x.Entity.GetType() == typeof(SystemDocConfirmedUser))) { + var type = GetEntityAuditOpt(item); + var entity = item.Entity as SystemDocConfirmedUser; var systemDocument = await _dbContext.SystemDocument.Where(x => x.Id == entity.SystemDocumentId).FirstOrDefaultAsync(); await InsertInspection(entity, type, x => new InspectionConvertDTO() @@ -155,6 +164,8 @@ namespace IRaCIS.Core.Infra.EFCore.Common // 项目文件签署 foreach (var item in entitys.Where(x => x.Entity.GetType() == typeof(TrialDocUserTypeConfirmedUser))) { + var type = GetEntityAuditOpt(item); + var entity = item.Entity as TrialDocUserTypeConfirmedUser; var trialDoc = await _dbContext.TrialDocument.Where(x => x.Id == entity.TrialDocumentId).FirstOrDefaultAsync(); @@ -171,8 +182,8 @@ namespace IRaCIS.Core.Infra.EFCore.Common UploadTime = trialDoc.CreateTime, CreateUserName = _userInfo.UserName, - UserType=_userInfo.UserTypeShortName, - IsSigned =true + UserType = _userInfo.UserTypeShortName, + IsSigned = true }); } @@ -180,74 +191,118 @@ namespace IRaCIS.Core.Infra.EFCore.Common - - - // Qc 问题答案 // 特殊GeneralId + // Qc 问题答案 if (entitys.Any(x => x.Entity.GetType() == typeof(TrialQCQuestionAnswer))) { - var entitylist = entitys.Where(x => x.Entity.GetType() == typeof(TrialQCQuestionAnswer)).Select(x => x.Entity as TrialQCQuestionAnswer).ToList(); - var firstEntity = entitylist.FirstOrDefault(); - var subjectVisit = await _dbContext.SubjectVisit.Where(x => x.Id == firstEntity.SubjectVisitId).FirstOrDefaultAsync(); - subjectVisit = subjectVisit ?? new SubjectVisit(); - if (type == "Add") + var entityEntryList = entitys.Where(x => x.Entity.GetType() == typeof(TrialQCQuestionAnswer)); + + var type = entityEntryList.All(t => t.State == EntityState.Added) ? AuditOpt.Add : AuditOpt.Update; + + + var list = entityEntryList.Select(t => t.Entity as TrialQCQuestionAnswer); + + + var firstEntity = list.FirstOrDefault(); + + var trialQuestionIdList = list.Select(t => t.TrialQCQuestionConfigureId); + + var trialQuestionNameList = await _dbContext.TrialQCQuestionConfigure.Where(x => x.TrialId==firstEntity.TrialId).Select(t => new { t.QuestionName , TrialQCQuestionConfigureId = t.Id,t.ShowOrder} ).ToListAsync(); + + var beforeAnswerList = await _dbContext.TrialQCQuestionAnswer.Where(x => x.SubjectVisitId == firstEntity.SubjectVisitId && x.CurrentQCEnum == firstEntity.CurrentQCEnum && x.QCProcessEnum == firstEntity.QCProcessEnum) + .Select(u => new { u.TrialQCQuestionConfigureId, u.Answer }).ToListAsync(); + + var answerList = list.Select(u => new { u.TrialQCQuestionConfigureId, u.Answer }).Union(beforeAnswerList).DistinctBy(t => t.TrialQCQuestionConfigureId); + + var cloneEntity = firstEntity.Clone(); + + //保证Id 唯一 + cloneEntity.Id = IdentifierHelper.CreateGuid(firstEntity.SubjectVisitId.ToString(), ((int)firstEntity.QCProcessEnum).ToString(), ((int)firstEntity.CurrentQCEnum).ToString()); + + await InsertInspection(cloneEntity, type, x => new InspectionConvertDTO() { + SubjectVisitId = x.SubjectVisitId, - - await InsertInspection(firstEntity, type, answer => new InspectionConvertDTO() - { - SiteId = subjectVisit.SiteId, - SubjectId = subjectVisit.SubjectId, - SubjectVisitName = subjectVisit.VisitName, - TrialId = subjectVisit.TrialId, - SubjectVisitId = subjectVisit.Id, - GeneralId = subjectVisit.Id, - //byzhouhang - ObjectRelationParentId = subjectVisit.Id, - }, new - { - QcQuestionAnswerCommands = await Getdata(entitylist), - }); - } - else if (type == "Update") + //byzhouhang + ObjectRelationParentId = x.SubjectVisitId, + }, new { + QcQuestionAnswerList = answerList.Join(trialQuestionNameList, t=>t.TrialQCQuestionConfigureId,u=>u.TrialQCQuestionConfigureId,(t,u)=>new {t.Answer,u.QuestionName,u.ShowOrder}).OrderBy(t=>t.ShowOrder).ToList(), + }); + + + + + #region OLd + //var entitylist = entitys.Where(x => x.Entity.GetType() == typeof(TrialQCQuestionAnswer)).Select(x => x.Entity as TrialQCQuestionAnswer).ToList(); + //var firstEntity = entitylist.FirstOrDefault(); + //var subjectVisit = await _dbContext.SubjectVisit.Where(x => x.Id == firstEntity.SubjectVisitId).FirstOrDefaultAsync(); + //subjectVisit = subjectVisit ?? new SubjectVisit(); + //if (type == "Add") + //{ + + + // await InsertInspection(firstEntity, type, answer => new InspectionConvertDTO() + // { + // SiteId = subjectVisit.SiteId, + // SubjectId = subjectVisit.SubjectId, + // SubjectVisitName = subjectVisit.VisitName, + // TrialId = subjectVisit.TrialId, + // SubjectVisitId = subjectVisit.Id, + + // //GeneralId = subjectVisit.Id, + // //byzhouhang + // ObjectRelationParentId = subjectVisit.Id, + // }, new + // { + // QcQuestionAnswerCommands = await Getdata(entitylist), + // }); + //} + //else if (type == "Update") + //{ + + // var questionIds = entitylist.Where(x => x.SubjectVisitId == subjectVisit.Id).Select(x => x.Id).ToList(); + // var createUserId = entitylist.Select(x => x.CreateUserId).FirstOrDefault(); + // var noUpdateData = _dbContext.TrialQCQuestionAnswer.Where(x => x.CreateUserId == createUserId && x.SubjectVisitId == subjectVisit.Id && !questionIds.Contains(x.Id)).ToList(); + // entitylist.AddRange(noUpdateData); + + // await InsertInspection(firstEntity, type, answer => new InspectionConvertDTO() + // { + // SiteId = subjectVisit.SiteId, + // SubjectId = subjectVisit.SubjectId, + // SubjectVisitName = subjectVisit.VisitName, + // TrialId = subjectVisit.TrialId, + // SubjectVisitId = subjectVisit.Id, + + // //GeneralId = subjectVisit.Id, + // //byzhouhang + // ObjectRelationParentId = subjectVisit.Id, + // }, new + // { + // QcQuestionAnswerCommands = await Getdata(entitylist), + // }); + + + //} + + //async Task> Getdata(List questionAnswers) + //{ + // var ids = questionAnswers.Select(x => x.TrialQCQuestionConfigureId).ToList(); + // var trialQCQuestionConfigureDatas = await _dbContext.TrialQCQuestionConfigure.Where(x => ids.Contains(x.Id)).ToListAsync(); + // var collect = questionAnswers.GroupJoin(trialQCQuestionConfigureDatas, one => one.TrialQCQuestionConfigureId, two => two.Id, (x, y) => new { one = x, two = y }) + // .SelectMany(a => a.two.DefaultIfEmpty(), (c, d) => new { c = c.one, d }) + // .OrderBy(x => x.d.ShowOrder) + // .Select(o => new AnswerDto() + // { + // QuestionName = o.d.QuestionName, + // Answer = o.c.Answer, + // }).ToList(); + // return collect; + //} + #endregion - var questionIds = entitylist.Where(x => x.SubjectVisitId == subjectVisit.Id).Select(x => x.Id).ToList(); - var createUserId = entitylist.Select(x => x.CreateUserId).FirstOrDefault(); - var noUpdateData = _dbContext.TrialQCQuestionAnswer.Where(x => x.CreateUserId == createUserId && x.SubjectVisitId == subjectVisit.Id && !questionIds.Contains(x.Id)).ToList(); - entitylist.AddRange(noUpdateData); - - await InsertInspection(firstEntity, type, answer => new InspectionConvertDTO() - { - SiteId = subjectVisit.SiteId, - SubjectId = subjectVisit.SubjectId, - SubjectVisitName = subjectVisit.VisitName, - TrialId = subjectVisit.TrialId, - SubjectVisitId = subjectVisit.Id, - GeneralId = subjectVisit.Id, - //byzhouhang - ObjectRelationParentId = subjectVisit.Id, - }, new - { - QcQuestionAnswerCommands = await Getdata(entitylist), - }); - } - async Task> Getdata(List questionAnswers) - { - var ids = questionAnswers.Select(x => x.TrialQCQuestionConfigureId).ToList(); - var trialQCQuestionConfigureDatas = await _dbContext.TrialQCQuestionConfigure.Where(x => ids.Contains(x.Id)).ToListAsync(); - var collect = questionAnswers.GroupJoin(trialQCQuestionConfigureDatas, one => one.TrialQCQuestionConfigureId, two => two.Id, (x, y) => new { one = x, two = y }) - .SelectMany(a => a.two.DefaultIfEmpty(), (c, d) => new { c = c.one, d }) - .OrderBy(x => x.d.ShowOrder) - .Select(o => new AnswerDto() - { - QuestionName = o.d.QuestionName, - Answer = o.c.Answer, - }).ToList(); - return collect; - } } @@ -262,6 +317,8 @@ namespace IRaCIS.Core.Infra.EFCore.Common //QC 质疑 foreach (var item in entitys.Where(x => x.Entity.GetType() == typeof(QCChallenge))) { + var type = GetEntityAuditOpt(item); + var entity = item.Entity as QCChallenge; await InsertInspection(entity, type, x => new InspectionConvertDTO() @@ -279,6 +336,8 @@ namespace IRaCIS.Core.Infra.EFCore.Common // 质疑 对话 foreach (var item in entitys.Where(x => x.Entity.GetType() == typeof(QCChallengeDialog))) { + var type = GetEntityAuditOpt(item); + var entity = item.Entity as QCChallengeDialog; await InsertInspection(entity, type, x => new InspectionConvertDTO() @@ -297,6 +356,7 @@ namespace IRaCIS.Core.Infra.EFCore.Common //一致性核查 对话 foreach (var item in entitys.Where(x => x.Entity.GetType() == typeof(CheckChallengeDialog))) { + var type = GetEntityAuditOpt(item); var entity = item.Entity as CheckChallengeDialog; //var subjectvisit = await _dbContext.SubjectVisit.Where(x => x.Id == entity.SubjectVisitId).FirstOrDefaultAsync(); @@ -332,6 +392,8 @@ namespace IRaCIS.Core.Infra.EFCore.Common // 一致性核查文件 是否需要单独一个表记录? foreach (var item in entitys.Where(x => x.Entity.GetType() == typeof(ConsistencyCheckFile))) { + var type = GetEntityAuditOpt(item); + await InsertInspection(item.Entity as ConsistencyCheckFile, type, x => new InspectionConvertDTO() { ObjectRelationParentId = x.TrialId @@ -342,6 +404,8 @@ namespace IRaCIS.Core.Infra.EFCore.Common // 中心调研表 foreach (var item in entitys.Where(x => x.Entity.GetType() == typeof(TrialSiteSurvey))) { + var type = GetEntityAuditOpt(item); + var entity = item.Entity as TrialSiteSurvey; if (entity.TrialSite == null) { @@ -381,6 +445,8 @@ namespace IRaCIS.Core.Infra.EFCore.Common // 既往手术史 foreach (var item in entitys.Where(x => x.Entity.GetType() == typeof(PreviousSurgery))) { + var type = GetEntityAuditOpt(item); + var entity = item.Entity as PreviousSurgery; await InsertInspection(entity, type, x => new InspectionConvertDTO() @@ -402,6 +468,9 @@ namespace IRaCIS.Core.Infra.EFCore.Common // 既往放疗史 foreach (var item in entitys.Where(x => x.Entity.GetType() == typeof(PreviousHistory))) { + + var type = GetEntityAuditOpt(item); + var entity = item.Entity as PreviousHistory; await InsertInspection(entity, type, x => new InspectionConvertDTO() @@ -424,6 +493,8 @@ namespace IRaCIS.Core.Infra.EFCore.Common // 其他治疗史 foreach (var item in entitys.Where(x => x.Entity.GetType() == typeof(PreviousOther))) { + var type = GetEntityAuditOpt(item); + var entity = item.Entity as PreviousOther; await InsertInspection(entity, type, x => new InspectionConvertDTO() @@ -443,12 +514,14 @@ namespace IRaCIS.Core.Infra.EFCore.Common } - + //系统文件 foreach (var item in entitys.Where(x => x.Entity.GetType() == typeof(SystemDocument))) { + var type = GetEntityAuditOpt(item); + var entity = item.Entity as SystemDocument; List needConfirmedUserTypeIdList = new List(); @@ -477,6 +550,7 @@ namespace IRaCIS.Core.Infra.EFCore.Common // 项目文档 foreach (var item in entitys.Where(x => x.Entity.GetType() == typeof(TrialDocument))) { + var type = GetEntityAuditOpt(item); var entity = item.Entity as TrialDocument; @@ -495,8 +569,8 @@ namespace IRaCIS.Core.Infra.EFCore.Common var usertypeName = string.Join(",", usertypeNames); await InsertInspection(entity, type, x => new InspectionConvertDTO() { - IsDistinctionInterface=true, - ObjectRelationParentId = x.TrialId + IsDistinctionInterface = true, + ObjectRelationParentId = x.TrialId }, new { @@ -509,6 +583,8 @@ namespace IRaCIS.Core.Infra.EFCore.Common //系统 Qc 问题 foreach (var item in entitys.Where(x => x.Entity.GetType() == typeof(QCQuestion))) { + var type = GetEntityAuditOpt(item); + var entity = item.Entity as QCQuestion; var parentQuestionName = await _dbContext.QCQuestionConfigure.Where(x => x.Id == entity.ParentId).Select(x => x.QuestionName).FirstOrDefaultAsync(); @@ -523,6 +599,9 @@ namespace IRaCIS.Core.Infra.EFCore.Common // 项目QC问题 foreach (var item in entitys.Where(x => x.Entity.GetType() == typeof(TrialQCQuestion))) { + + var type = GetEntityAuditOpt(item); + var entity = item.Entity as TrialQCQuestion; var parentQuestionName = await _dbContext.TrialQCQuestionConfigure.Where(x => x.Id == entity.ParentId).Select(x => x.QuestionName).FirstOrDefaultAsync(); @@ -540,9 +619,11 @@ namespace IRaCIS.Core.Infra.EFCore.Common //系统 医学审核问题 foreach (var item in entitys.Where(x => x.Entity.GetType() == typeof(ReadingMedicineSystemQuestion))) { + var type = GetEntityAuditOpt(item); + var entity = item.Entity as ReadingMedicineSystemQuestion; - var parentQuestionName = string.Empty; + var parentQuestionName = string.Empty; if (entity.ParentId != null) { parentQuestionName = await _dbContext.ReadingMedicineSystemQuestion.Where(x => x.Id == entity.ParentId).Select(x => x.QuestionName).FirstOrDefaultAsync(); @@ -551,12 +632,14 @@ namespace IRaCIS.Core.Infra.EFCore.Common await InsertInspection(entity, type, x => new InspectionConvertDTO() { IsDistinctionInterface = false, - },new { ParentQuestionName = parentQuestionName }); + }, new { ParentQuestionName = parentQuestionName }); } //项目医学审核问题 foreach (var item in entitys.Where(x => x.Entity.GetType() == typeof(ReadingMedicineTrialQuestion))) { + var type = GetEntityAuditOpt(item); + var entity = item.Entity as ReadingMedicineTrialQuestion; var parentQuestionName = string.Empty; @@ -577,9 +660,11 @@ namespace IRaCIS.Core.Infra.EFCore.Common // 签名模板 foreach (var item in entitys.Where(x => x.Entity.GetType() == typeof(SystemBasicData))) { + var type = GetEntityAuditOpt(item); + await InsertInspection(item.Entity as SystemBasicData, type, x => new InspectionConvertDTO() { - IsDistinctionInterface=false + IsDistinctionInterface = false }); } @@ -588,6 +673,8 @@ namespace IRaCIS.Core.Infra.EFCore.Common // 项目中心 Site未稽查 foreach (var item in entitys.Where(x => x.Entity.GetType() == typeof(TrialSite))) { + var type = GetEntityAuditOpt(item); + var entity = item.Entity as TrialSite; if (entity.Site == null) { @@ -615,6 +702,7 @@ namespace IRaCIS.Core.Infra.EFCore.Common // 项目人员 foreach (var item in entitys.Where(x => x.Entity.GetType() == typeof(TrialUser))) { + var type = GetEntityAuditOpt(item); var entity = item.Entity as TrialUser; //var user = await _dbContext.Users.Include(x => x.UserTypeRole).FirstOrDefaultAsync(x => x.Id == entity.UserId); @@ -630,6 +718,9 @@ namespace IRaCIS.Core.Infra.EFCore.Common // 项目中心人员 foreach (var item in entitys.Where(x => x.Entity.GetType() == typeof(TrialSiteUser))) { + + var type = GetEntityAuditOpt(item); + var entity = item.Entity as TrialSiteUser; @@ -650,6 +741,8 @@ namespace IRaCIS.Core.Infra.EFCore.Common // 受试者 foreach (var item in entitys.Where(x => x.Entity.GetType() == typeof(Subject))) { + var type = GetEntityAuditOpt(item); + var entity = item.Entity as Subject; var finalSubjectVisitName = await _dbContext.SubjectVisit.AsNoTracking().Where(x => x.Id == entity.FinalSubjectVisitId && entity.FinalSubjectVisitId != null).Select(x => x.VisitName).FirstOrDefaultAsync(); @@ -676,6 +769,9 @@ namespace IRaCIS.Core.Infra.EFCore.Common // 访视计划 foreach (var item in entitys.Where(x => x.Entity.GetType() == typeof(VisitStage))) { + + var type = GetEntityAuditOpt(item); + var entity = item.Entity as VisitStage; await InsertInspection(item.Entity as VisitStage, type, x => new InspectionConvertDTO() @@ -705,6 +801,9 @@ namespace IRaCIS.Core.Infra.EFCore.Common // 访视 foreach (var item in entitys.Where(x => x.Entity.GetType() == typeof(SubjectVisit))) { + + var type = GetEntityAuditOpt(item); + var entity = item.Entity as SubjectVisit; await InsertInspection(item.Entity as SubjectVisit, type, x => new InspectionConvertDTO() @@ -725,6 +824,8 @@ namespace IRaCIS.Core.Infra.EFCore.Common // Dicom foreach (var item in entitys.Where(x => x.Entity.GetType() == typeof(DicomStudy))) { + var type = GetEntityAuditOpt(item); + await InsertInspection(item.Entity as DicomStudy, type, x => new InspectionConvertDTO() { ObjectRelationParentId = x.SubjectVisitId @@ -734,6 +835,8 @@ namespace IRaCIS.Core.Infra.EFCore.Common // 序列 foreach (var item in entitys.Where(x => x.Entity.GetType() == typeof(DicomSeries))) { + var type = GetEntityAuditOpt(item); + var entity = item.Entity as DicomSeries; await InsertInspection(item.Entity as DicomSeries, type, x => new InspectionConvertDTO() @@ -747,6 +850,9 @@ namespace IRaCIS.Core.Infra.EFCore.Common // 非Dicom foreach (var item in entitys.Where(x => x.Entity.GetType() == typeof(NoneDicomStudy))) { + + var type = GetEntityAuditOpt(item); + var entity = item.Entity as NoneDicomStudy; await InsertInspection(item.Entity as NoneDicomStudy, type, x => new InspectionConvertDTO() @@ -789,6 +895,7 @@ namespace IRaCIS.Core.Infra.EFCore.Common //阅片人入组 父层级未记录稽查(医生) foreach (var item in entitys.Where(x => x.Entity.GetType() == typeof(Enroll))) { + var type = GetEntityAuditOpt(item); var entity = item.Entity as Enroll; var doctor = await _dbContext.Doctor.FirstOrDefaultAsync(x => x.Id == entity.DoctorId); @@ -813,9 +920,12 @@ namespace IRaCIS.Core.Infra.EFCore.Common if (entitys.Any(x => x.Entity.GetType() == typeof(EnrollReadingCategory))) { - var list = entitys.Where(x => x.Entity.GetType() == typeof(EnrollReadingCategory)).Select(t => t.Entity as EnrollReadingCategory).ToList(); + var type = AuditOpt.Update; - var first = list.FirstOrDefault(); + var addList = entitys.Where(x => x.Entity.GetType() == typeof(EnrollReadingCategory) && x.State == EntityState.Added).Select(t => t.Entity as EnrollReadingCategory).ToList(); + var deleteList = entitys.Where(x => x.Entity.GetType() == typeof(EnrollReadingCategory) && x.State == EntityState.Added).Select(t => t.Entity as EnrollReadingCategory).ToList(); + + var first = addList.Union(deleteList).FirstOrDefault(); var enrollId = first.EnrollId; @@ -843,7 +953,7 @@ namespace IRaCIS.Core.Infra.EFCore.Common { //子层级只需要记录自己这边的信息就好了 只有删除 和添加 没有更新(如果是删除,再添加,删除不会走稽查逻辑,业务代码已控制) - ReadingCategoryList = type == AuditOpt.Deleted ? null : list.Select(t => t.ReadingCategory).ToList(), + ReadingCategoryList = addList.Select(t => t.ReadingCategory).ToList(), }); } @@ -858,6 +968,8 @@ namespace IRaCIS.Core.Infra.EFCore.Common foreach (var item in entitys.Where(x => x.Entity.GetType() == typeof(ClinicalDataSystemSet))) { + var type = GetEntityAuditOpt(item); + var entity = item.Entity as ClinicalDataSystemSet; await InsertInspection(entity, type, x => new InspectionConvertDTO() @@ -871,6 +983,8 @@ namespace IRaCIS.Core.Infra.EFCore.Common //项目临床数据配置 foreach (var item in entitys.Where(x => x.Entity.GetType() == typeof(ClinicalDataTrialSet))) { + var type = GetEntityAuditOpt(item); + var entity = item.Entity as ClinicalDataTrialSet; await InsertInspection(entity, type, x => new InspectionConvertDTO() @@ -883,6 +997,8 @@ namespace IRaCIS.Core.Infra.EFCore.Common // CRC PM 临床数据 foreach (var item in entitys.Where(x => x.Entity.GetType() == typeof(ReadingClinicalData))) { + var type = GetEntityAuditOpt(item); + var entity = item.Entity as ReadingClinicalData; await InsertInspection(item.Entity as ReadingClinicalData, type, x => new InspectionConvertDTO() @@ -899,6 +1015,8 @@ namespace IRaCIS.Core.Infra.EFCore.Common //阅片期计划 foreach (var item in entitys.Where(x => x.Entity.GetType() == typeof(ReadingPeriodSet))) { + var type = GetEntityAuditOpt(item); + var entity = item.Entity as ReadingPeriodSet; var siteCodes = string.Empty; @@ -948,6 +1066,8 @@ namespace IRaCIS.Core.Infra.EFCore.Common //阅片期 foreach (var item in entitys.Where(x => x.Entity.GetType() == typeof(ReadModule))) { + var type = GetEntityAuditOpt(item); + var entity = item.Entity as ReadModule; await InsertInspection(item.Entity as ReadModule, type, x => new InspectionConvertDTO() @@ -968,6 +1088,8 @@ namespace IRaCIS.Core.Infra.EFCore.Common //用户添加 foreach (var item in entitys.Where(x => x.Entity.GetType() == typeof(User))) { + var type = GetEntityAuditOpt(item); + var entity = item.Entity as User; await InsertInspection(entity, type, x => new InspectionConvertDTO() @@ -985,6 +1107,8 @@ namespace IRaCIS.Core.Infra.EFCore.Common //分配规则 foreach (var item in entitys.Where(x => x.Entity.GetType() == typeof(TaskAllocationRule))) { + var type = GetEntityAuditOpt(item); + var entity = item.Entity as TaskAllocationRule; await InsertInspection(entity, type, x => new InspectionConvertDTO() @@ -1001,6 +1125,8 @@ namespace IRaCIS.Core.Infra.EFCore.Common // suject 医生绑定关系 foreach (var item in entitys.Where(x => x.Entity.GetType() == typeof(SubjectUser))) { + var type = GetEntityAuditOpt(item); + var entity = item.Entity as SubjectUser; await InsertInspection(entity, type, x => new InspectionConvertDTO() @@ -1017,6 +1143,8 @@ namespace IRaCIS.Core.Infra.EFCore.Common //任务 foreach (var item in entitys.Where(x => x.Entity.GetType() == typeof(VisitTask))) { + var type = GetEntityAuditOpt(item); + var entity = item.Entity as VisitTask; await InsertInspection(entity, type, x => new InspectionConvertDTO() @@ -1035,6 +1163,8 @@ namespace IRaCIS.Core.Infra.EFCore.Common //申请重阅记录表 foreach (var item in entitys.Where(x => x.Entity.GetType() == typeof(VisitTaskReReading))) { + var type = GetEntityAuditOpt(item); + var entity = item.Entity as VisitTaskReReading; await InsertInspection(entity, type, x => new InspectionConvertDTO() @@ -1053,6 +1183,8 @@ namespace IRaCIS.Core.Infra.EFCore.Common //医学审核 foreach (var item in entitys.Where(x => x.Entity.GetType() == typeof(TaskMedicalReview))) { + var type = GetEntityAuditOpt(item); + var entity = item.Entity as TaskMedicalReview; await InsertInspection(entity, type, x => new InspectionConvertDTO() @@ -1069,6 +1201,8 @@ namespace IRaCIS.Core.Infra.EFCore.Common foreach (var item in entitys.Where(x => x.Entity.GetType() == typeof(TaskConsistentRule))) { + var type = GetEntityAuditOpt(item); + var entity = item.Entity as TaskConsistentRule; await InsertInspection(entity, type, x => new InspectionConvertDTO() @@ -1321,14 +1455,8 @@ namespace IRaCIS.Core.Infra.EFCore.Common entityTypeName = "New/" + "UserSigned"; } - object entity; switch (entityObj.GetType().Name) { - //case nameof(QCChallengeDialog): - //case nameof(QCChallenge): - //case nameof(CheckChallengeDialog): - // type = type + "/(" + _userInfo.UserTypeShortName + ")"; - // break; case nameof(SystemBasicData): @@ -1355,7 +1483,7 @@ namespace IRaCIS.Core.Infra.EFCore.Common // 对话消息区分用户类型 - case nameof(CheckChallengeDialog): + case nameof(CheckChallengeDialog): type = type + "/(" + _userInfo.UserTypeShortName + ")"; var checkDialog = entityObj as CheckChallengeDialog; @@ -1367,14 +1495,14 @@ namespace IRaCIS.Core.Infra.EFCore.Common inspection.Reason = checkDialog.TalkContent.Substring(checkDialog.TalkContent.LastIndexOf(':') + 1); break; } - + break; // 对话消息区分用户类型 case nameof(QCChallengeDialog): type = type + "/(" + _userInfo.UserTypeShortName + ")"; - var dialog= entityObj as QCChallengeDialog; + var dialog = entityObj as QCChallengeDialog; switch (_userInfo.RequestUrl.ToLower()) { case "qcoperation/closeqcchallenge": @@ -1424,7 +1552,7 @@ namespace IRaCIS.Core.Infra.EFCore.Common break; } - if(sv.CheckChallengeState==CheckChanllengeTypeEnum.CRCWaitPMReply|| sv.CheckChallengeState == CheckChanllengeTypeEnum.PMWaitCRCReply) + if (sv.CheckChallengeState == CheckChanllengeTypeEnum.CRCWaitPMReply || sv.CheckChallengeState == CheckChanllengeTypeEnum.PMWaitCRCReply) { //发送对话 修改质疑状态 不需要区分接口 IsDistinctionInterface = false; @@ -1618,6 +1746,28 @@ namespace IRaCIS.Core.Infra.EFCore.Common #region 待废弃 -by zhouhang 调整 + ///// + ///// 传入实体对象 + ///// + //public async Task IncomingEntitys(List entitys) + //{ + // // 修改 + // await InsertAddEntitys( + // entitys.Where(x => x.State == EntityState.Modified && + // (!typeof(ISoftDelete).IsAssignableFrom(x.Entity.GetType()) || !(bool)x.Entity.GetType().GetProperty(nameof(ISoftDelete.IsDeleted)).GetValue(x.Entity) || NodeleteTableTypes.Contains(x.Entity.GetType())) + // ).ToList(), AuditOpt.Update); + + // // 新增 + // await InsertAddEntitys(entitys.Where(x => x.State == EntityState.Added).ToList(), AuditOpt.Add); + + // // 删除 + // await InsertAddEntitys(entitys.Where(x => x.State == EntityState.Deleted + // || (typeof(ISoftDelete).IsAssignableFrom(x.Entity.GetType()) && (bool)x.Entity.GetType().GetProperty(nameof(ISoftDelete.IsDeleted)).GetValue(x.Entity) && x.State == EntityState.Modified && !NodeleteTableTypes.Contains(x.Entity.GetType())) + // ).ToList(), AuditOpt.Deleted); + + + //} + //// 非Dicom文件 //if (entitys.Any(x => x.Entity.GetType() == typeof(NoneDicomStudyFile))) //{ diff --git a/IRaCIS.Core.Infra.EFCore/Common/IAuditingData.cs b/IRaCIS.Core.Infra.EFCore/Common/IAuditingData.cs index 3ae884ef7..4c4debaab 100644 --- a/IRaCIS.Core.Infra.EFCore/Common/IAuditingData.cs +++ b/IRaCIS.Core.Infra.EFCore/Common/IAuditingData.cs @@ -9,6 +9,8 @@ namespace IRaCIS.Core.Infra.EFCore.Common { public interface IAuditingData { - Task IncomingEntitys(List entitys); + //Task IncomingEntitys(List entitys); + + Task InsertAddEntitys(List entitys); } } diff --git a/IRaCIS.Core.Infra.EFCore/Context/IRaCISDBContext.cs b/IRaCIS.Core.Infra.EFCore/Context/IRaCISDBContext.cs index 4ae6e0008..72838201b 100644 --- a/IRaCIS.Core.Infra.EFCore/Context/IRaCISDBContext.cs +++ b/IRaCIS.Core.Infra.EFCore/Context/IRaCISDBContext.cs @@ -481,7 +481,9 @@ namespace IRaCIS.Core.Infra.EFCore .ToList(); AuditingData auditingData = new AuditingData(this, _userInfo); - await auditingData.IncomingEntitys(entities); + //await auditingData.IncomingEntitys(entities); + + await auditingData.InsertAddEntitys(entities); //} //catch (Exception) //{ diff --git a/IRaCIS.Core.Infrastructure/Helper/IdentifierHelper.cs b/IRaCIS.Core.Infrastructure/Helper/IdentifierHelper.cs new file mode 100644 index 000000000..5f9a54d70 --- /dev/null +++ b/IRaCIS.Core.Infrastructure/Helper/IdentifierHelper.cs @@ -0,0 +1,22 @@ +using System; +using System.Security.Cryptography; +using System.Text; + +namespace IRaCIS.Core.Infrastructure +{ + public static class IdentifierHelper + { + private static MD5 md5 = MD5.Create(); + + private static object lockObj = new object(); + + public static Guid CreateGuid(params string[] parts) + { + lock (lockObj) + { + return new Guid(md5.ComputeHash(Encoding.UTF8.GetBytes(string.Concat(parts)))); + } + + } + } +}