diff --git a/IRaCIS.Core.Application/Service/Inspection/FrontAuditConfigService.cs b/IRaCIS.Core.Application/Service/Inspection/FrontAuditConfigService.cs index 1dd935af2..633faa1de 100644 --- a/IRaCIS.Core.Application/Service/Inspection/FrontAuditConfigService.cs +++ b/IRaCIS.Core.Application/Service/Inspection/FrontAuditConfigService.cs @@ -195,7 +195,7 @@ namespace IRaCIS.Core.Application.Service var currentInspection = await _dataInspectionRepository.Where(t => t.Id == id).Select(t => new { t.GeneralId, t.ObjectRelationParentId, t.CreateTime }).FirstOrDefaultAsync(); - var beforeId = await _dataInspectionRepository.Where(x => x.GeneralId == currentInspection.GeneralId && x.ObjectRelationParentId == currentInspection.ObjectRelationParentId && x.CreateTime <= currentInspection.CreateTime && x.Id!=id).OrderByDescending(x => x.CreateTime).Select(t => t.Id) + var beforeId = await _dataInspectionRepository.Where(x => x.GeneralId == currentInspection.GeneralId && x.ObjectRelationParentId == currentInspection.ObjectRelationParentId && x.CreateTime <= currentInspection.CreateTime && x.Id != id).OrderByDescending(x => x.CreateTime).Select(t => t.Id) .FirstOrDefaultAsync(); List searchGuidList = new List() { id }; @@ -243,7 +243,9 @@ namespace IRaCIS.Core.Application.Service { //把父层级的数据的 CommonData 数据合并(每一个层级把下面层级需要的数据放在CommonData 里面) 麻烦点是每个层级都需要记录一些信息,而且名称不能重复 - var commonDataObjList = await GetRelationParentData(item.ObjectRelationParentId, item.ObjectRelationParentId2, item.CreateTime, item.BatchId); + var objectLsit = new List(); + + var commonDataObjList = await GetRelationParentData(item.ObjectRelationParentId, item.ObjectRelationParentId2, item.CreateTime, item.BatchId, objectLsit); var currentDic = JsonConvert.DeserializeObject>(jsonDict[nameof(InspectionJsonDetail.CommonData)].ToJsonStr()); @@ -276,7 +278,7 @@ namespace IRaCIS.Core.Application.Service if (!currentDic.ContainsKey(valuePair.Key)) { currentDic.Add(valuePair.Key, valuePair.Value); - } + } } } } @@ -345,12 +347,8 @@ namespace IRaCIS.Core.Application.Service - private async Task> GetRelationParentData(Guid? objectRelationParentId, Guid? objectRelationParentId2, DateTime createTime, Guid batchId) + private async Task AddJsonObjectToDic(Guid? objectRelationParentId, DateTime createTime, Guid batchId, List objectLsit) { - - var objectLsit = new List(); - - if (objectRelationParentId != null) { //父子层级的数据可能在同一个批次 进行更新 但是后插入的是父层级的数据 找父层级的稽查应该优先同一批次的 @@ -388,65 +386,133 @@ namespace IRaCIS.Core.Application.Service - await GetRelationParentData(relationParentInspection.ObjectRelationParentId, relationParentInspection.ObjectRelationParentId2, relationParentInspection.CreateTime, relationParentInspection.BatchId); + await AddJsonObjectToDic(relationParentInspection.ObjectRelationParentId, relationParentInspection.CreateTime, relationParentInspection.BatchId, objectLsit); + await AddJsonObjectToDic( relationParentInspection.ObjectRelationParentId2, relationParentInspection.CreateTime, relationParentInspection.BatchId, objectLsit); } - } - - if (objectRelationParentId2 != null) - { - //父子层级的数据可能在同一个批次 进行更新 但是后插入的是父层级的数据 找父层级的稽查应该优先同一批次的 - var relationParentInspection = await _dataInspectionRepository.Where(t => t.GeneralId == objectRelationParentId2 && (t.CreateTime <= createTime || t.BatchId == batchId)).OrderByDescending(x => x.CreateTime).Select(t => new { t.ObjectRelationParentId, t.CreateTime, t.JsonDetail, t.BatchId, t.ObjectRelationParentId2, t.EntityName }).FirstOrDefaultAsync(); - - - if (relationParentInspection != null) - { - Dictionary jsonDic = JsonConvert.DeserializeObject>(relationParentInspection.JsonDetail); - - - var commonDataDicObj = jsonDic[nameof(InspectionJsonDetail.CommonData)]; - - objectLsit.Add(commonDataDicObj); - - - //避免对象信息记录 把 Data里面的信息也取过去 但是加上稽查对象的前缀 - var dataDicObj = jsonDic[nameof(InspectionJsonDetail.Data)]; - - if (dataDicObj != null) - { - var entityName = relationParentInspection.EntityName; - - IDictionary newNamepDic = new Dictionary(); - - var tempDic = JsonConvert.DeserializeObject>(dataDicObj.ToJsonStr()); - - foreach (var valuePair in tempDic) - { - newNamepDic.Add(entityName + "_" + valuePair.Key, valuePair.Value); - } - - - objectLsit.Add(newNamepDic); - } - - - - - - await GetRelationParentData(relationParentInspection.ObjectRelationParentId, relationParentInspection.ObjectRelationParentId2, relationParentInspection.CreateTime, relationParentInspection.BatchId); - } else { //用户的数据稽查没有 临时处理 - var userObj = await _repository.Where(t => t.Id == objectRelationParentId2).Select(t => new { UserFullName = t.FullName, t.UserName }).FirstOrDefaultAsync(); + + var userObj = await _repository.Where(t => t.Id == objectRelationParentId).Select(t => new { UserRealName = t.FullName, t.Phone, t.UserName, UserType = t.UserTypeRole.UserTypeShortName, t.EMail, t.OrganizationName }).FirstOrDefaultAsync(); objectLsit.Add(userObj); } - - } + } + + + + private async Task> GetRelationParentData(Guid? objectRelationParentId, Guid? objectRelationParentId2, DateTime createTime, Guid batchId, List objectLsit) + { + await AddJsonObjectToDic(objectRelationParentId, createTime, batchId, objectLsit); + await AddJsonObjectToDic(objectRelationParentId2, createTime, batchId, objectLsit); + + #region 废弃 + //if (objectRelationParentId != null) + //{ + // //父子层级的数据可能在同一个批次 进行更新 但是后插入的是父层级的数据 找父层级的稽查应该优先同一批次的 + // var relationParentInspection = await _dataInspectionRepository.Where(t => t.GeneralId == objectRelationParentId && (t.CreateTime <= createTime || t.BatchId == batchId)).OrderByDescending(x => x.CreateTime).Select(t => new { t.ObjectRelationParentId, t.CreateTime, t.JsonDetail, t.BatchId, t.ObjectRelationParentId2, t.EntityName }).FirstOrDefaultAsync(); + + + // if (relationParentInspection != null) + // { + // Dictionary jsonDic = JsonConvert.DeserializeObject>(relationParentInspection.JsonDetail); + + + // var commonDataDicObj = jsonDic[nameof(InspectionJsonDetail.CommonData)]; + + // objectLsit.Add(commonDataDicObj); + + // //避免对象信息记录 把 Data里面的信息也取过去 但是加上稽查对象的前缀 + // var dataDicObj = jsonDic[nameof(InspectionJsonDetail.Data)]; + + // if (dataDicObj != null) + // { + // var entityName = relationParentInspection.EntityName; + + // IDictionary newNamepDic = new Dictionary(); + + // var tempDic = JsonConvert.DeserializeObject>(dataDicObj.ToJsonStr()); + + // foreach (var valuePair in tempDic) + // { + // newNamepDic.Add(entityName + "_" + valuePair.Key, valuePair.Value); + // } + + + // objectLsit.Add(newNamepDic); + // } + + + + // await GetRelationParentData(relationParentInspection.ObjectRelationParentId, relationParentInspection.ObjectRelationParentId2, relationParentInspection.CreateTime, relationParentInspection.BatchId, objectLsit); + // } + + + + //} + + //if (objectRelationParentId2 != null) + //{ + // //父子层级的数据可能在同一个批次 进行更新 但是后插入的是父层级的数据 找父层级的稽查应该优先同一批次的 + // var relationParentInspection = await _dataInspectionRepository.Where(t => t.GeneralId == objectRelationParentId2 && (t.CreateTime <= createTime || t.BatchId == batchId)).OrderByDescending(x => x.CreateTime).Select(t => new { t.ObjectRelationParentId, t.CreateTime, t.JsonDetail, t.BatchId, t.ObjectRelationParentId2, t.EntityName }).FirstOrDefaultAsync(); + + + // if (relationParentInspection != null) + // { + // Dictionary jsonDic = JsonConvert.DeserializeObject>(relationParentInspection.JsonDetail); + + + // var commonDataDicObj = jsonDic[nameof(InspectionJsonDetail.CommonData)]; + + // objectLsit.Add(commonDataDicObj); + + + // //避免对象信息记录 把 Data里面的信息也取过去 但是加上稽查对象的前缀 + // var dataDicObj = jsonDic[nameof(InspectionJsonDetail.Data)]; + + // if (dataDicObj != null) + // { + // var entityName = relationParentInspection.EntityName; + + // IDictionary newNamepDic = new Dictionary(); + + // var tempDic = JsonConvert.DeserializeObject>(dataDicObj.ToJsonStr()); + + // foreach (var valuePair in tempDic) + // { + // newNamepDic.Add(entityName + "_" + valuePair.Key, valuePair.Value); + // } + + + // objectLsit.Add(newNamepDic); + // } + + + + + // await GetRelationParentData(relationParentInspection.ObjectRelationParentId, relationParentInspection.ObjectRelationParentId2, relationParentInspection.CreateTime, relationParentInspection.BatchId, objectLsit); + // } + // else + // { + // //用户的数据稽查没有 临时处理 + + + + // var userObj = await _repository.Where(t => t.Id == objectRelationParentId2).Select(t => new { UserRealName = t.FullName, t.Phone, t.UserName, UserType = t.UserTypeRole.UserTypeShortName, t.EMail, t.OrganizationName }).FirstOrDefaultAsync(); + + // objectLsit.Add(userObj); + // } + + + + //} + + #endregion + return objectLsit; } @@ -455,6 +521,7 @@ namespace IRaCIS.Core.Application.Service + /// /// 格式化日期和时间 /// diff --git a/IRaCIS.Core.Domain/TrialSiteUser/TrialSite.cs b/IRaCIS.Core.Domain/TrialSiteUser/TrialSite.cs index e0754ce8e..3dc6ef9a7 100644 --- a/IRaCIS.Core.Domain/TrialSiteUser/TrialSite.cs +++ b/IRaCIS.Core.Domain/TrialSiteUser/TrialSite.cs @@ -25,11 +25,11 @@ namespace IRaCIS.Core.Domain.Models public Guid? DeleteUserId { get; set; } - + [JsonIgnore] //导航属性 [ForeignKey("SiteId")] public Site Site { get; set; } - + [JsonIgnore] [ForeignKey("TrialId")] public Trial Trial { get; set; } @@ -38,25 +38,27 @@ namespace IRaCIS.Core.Domain.Models /// /// Site 下面有多个访视记录 /// + [JsonIgnore] public List SubjectVisitList { get; set; } - + [JsonIgnore] public List TrialSiteSurveyList { get; set; } //Site 由多个人负责 + [JsonIgnore] public List CRCUserList { get; set; } - + [JsonIgnore] public List SubjectList { get; set; } - + [JsonIgnore] public List StudyList { get; set; } - + [JsonIgnore] public List NoneDicomStudyList { get; set; } - + [JsonIgnore] public List StudyMonitorList { get; set; } - + [JsonIgnore] public List ReadingPeriodSites { get; set; } } } \ No newline at end of file diff --git a/IRaCIS.Core.Domain/TrialSiteUser/TrialSiteUser.cs b/IRaCIS.Core.Domain/TrialSiteUser/TrialSiteUser.cs index 9c4af992b..205211176 100644 --- a/IRaCIS.Core.Domain/TrialSiteUser/TrialSiteUser.cs +++ b/IRaCIS.Core.Domain/TrialSiteUser/TrialSiteUser.cs @@ -44,21 +44,21 @@ namespace IRaCIS.Core.Domain.Models public Guid? DeleteUserId { get; set; } - + [JsonIgnore] [ForeignKey("UserId")] public User User { get; set; } - + [JsonIgnore] [ForeignKey("TrialId")] public Trial Trial { get; set; } - + [JsonIgnore] [ForeignKey("SiteId")] public Site Site { get; set; } - + [JsonIgnore] public TrialSite TrialSite { get; set; } - + [JsonIgnore] public TrialUser TrialUser { get; set; } diff --git a/IRaCIS.Core.Domain/TrialSiteUser/TrialUser.cs b/IRaCIS.Core.Domain/TrialSiteUser/TrialUser.cs index fc7a3e828..d1c5de42d 100644 --- a/IRaCIS.Core.Domain/TrialSiteUser/TrialUser.cs +++ b/IRaCIS.Core.Domain/TrialSiteUser/TrialUser.cs @@ -13,13 +13,13 @@ namespace IRaCIS.Core.Domain.Models { public Guid UserId { get; set; } public Guid TrialId { get; set; } - + [JsonIgnore] public Trial Trial { get; set; } - + [JsonIgnore] [ForeignKey("UserId")] public User User { get; set; } - + [JsonIgnore] public List SiteList { get; set; } diff --git a/IRaCIS.Core.Domain/Visit/Subject.cs b/IRaCIS.Core.Domain/Visit/Subject.cs index 7e915c494..0c83b81ce 100644 --- a/IRaCIS.Core.Domain/Visit/Subject.cs +++ b/IRaCIS.Core.Domain/Visit/Subject.cs @@ -24,21 +24,24 @@ namespace IRaCIS.Core.Domain.Models public List SubjectCanceDoctorList { get; set; } - + [JsonIgnore] [ForeignKey("FinalSubjectVisitId")] public SubjectVisit FinalSubjectVisit { get; set; } public Guid? FinalSubjectVisitId { get; set; } //需要配置是两个键连接 + [JsonIgnore] public TrialSite TrialSite { get; set; } + [JsonIgnore] [ForeignKey("TrialId")] public Trial Trial { get; set; } + [JsonIgnore] [ForeignKey("SiteId")] public Site Site { get; set; } - + [JsonIgnore] public List StudyList { get; set; } = new List(); public string Code { get; set; } @@ -48,6 +51,7 @@ namespace IRaCIS.Core.Domain.Models public string Sex { get; set; } = string.Empty; public Guid SiteId { get; set; } = Guid.Empty; + [JsonIgnore] [ForeignKey("LatestSubjectVisitId")] public SubjectVisit LatestSubjectVisit { get; set; } public Guid? LatestSubjectVisitId { get; set; } diff --git a/IRaCIS.Core.Infra.EFCore/Common/AuditingData.cs b/IRaCIS.Core.Infra.EFCore/Common/AuditingData.cs index 784280e5a..b43d7683f 100644 --- a/IRaCIS.Core.Infra.EFCore/Common/AuditingData.cs +++ b/IRaCIS.Core.Infra.EFCore/Common/AuditingData.cs @@ -119,46 +119,9 @@ namespace IRaCIS.Core.Infra.EFCore.Common }); } - // 签名模板 - foreach (var item in entitys.Where(x => x.Entity.GetType() == typeof(SystemBasicData))) - { - await InsertInspection(item.Entity as SystemBasicData, type); - } - // 项目 - foreach (var item in entitys.Where(x => x.Entity.GetType() == typeof(Trial))) - { - var entity = item.Entity as Trial; - List trialDics = new List(); - var dictionaryIds = new List(); - if (entity.TrialDicList == null || entity.TrialDicList.Count == 0) - { - dictionaryIds = await this._dbContext.TrialDictionary.Where(x => x.TrialId == entity.Id && x.KeyName == "Criterion").Select(x => x.DictionaryId).ToListAsync(); - } - else - { - dictionaryIds = entity.TrialDicList.Select(x => x.DictionaryId).ToList(); - - } - - trialDics = await this._dbContext.Dictionary.Where(x => dictionaryIds.Contains(x.Id)).Select(x => x.ValueCN).ToListAsync(); - - await InsertInspection(item.Entity as Trial, type, x => new InspectionConvertDTO() - - { - TrialId = x.Id, - TrialName = x.ExperimentName, - ResearchProgramNo = x.ResearchProgramNo, - }, new - { - ExperimentName = entity.ExperimentName, - ResearchProgramNo = entity.ResearchProgramNo, - - TrialDicList = string.Join(",", trialDics) - }); - } // 访视计划 foreach (var item in entitys.Where(x => x.Entity.GetType() == typeof(VisitStage))) @@ -237,95 +200,6 @@ namespace IRaCIS.Core.Infra.EFCore.Common } - // 项目中心 - foreach (var item in entitys.Where(x => x.Entity.GetType() == typeof(TrialSite))) - { - var entity = item.Entity as TrialSite; - if (entity.Site == null) - { - entity.Site = await _dbContext.Site.Where(x => x.Id == entity.SiteId).FirstOrDefaultAsync(); - } - await InsertInspection(entity, type, null, new - { - TrialSiteCode = entity.TrialSiteCode, - SiteName = entity.Site.SiteName, - SiteAliasName = entity.TrialSiteAliasName, - City = entity.Site.City, - Country = entity.Site.Country, - }); - } - - // 项目人员 - foreach (var item in entitys.Where(x => x.Entity.GetType() == typeof(TrialUser))) - { - - var entity = item.Entity as TrialUser; - var user = await _dbContext.Users.Include(x => x.UserTypeRole).FirstOrDefaultAsync(x => x.Id == entity.UserId); - await InsertInspection(entity, type, x => new InspectionConvertDTO - { - TrialId = x.TrialId, - }, new - { - UserRealName = user.FullName, - UserName = user.UserName, - UserType = user.UserTypeRole.UserTypeShortName, - EMail = user.EMail, - Phone = user.Phone, - OrganizationName = user.OrganizationName, - - }); - } - - // 项目中心人员 - foreach (var item in entitys.Where(x => x.Entity.GetType() == typeof(TrialSiteUser))) - { - var entity = item.Entity as TrialSiteUser; - if (entity.TrialSite == null) - { - entity.TrialSite = await _dbContext.TrialSite.Where(x => x.TrialId == entity.TrialId && x.SiteId == entity.SiteId).IgnoreQueryFilters().FirstOrDefaultAsync(); - } - - if (entity.Site == null) - { - entity.Site = await _dbContext.Site.Where(x => x.Id == entity.SiteId).FirstOrDefaultAsync(); - } - - var user = new User(); - - - - if (entity.User == null) - { - user = await _dbContext.User.Where(x => x.Id == entity.UserId).FirstOrDefaultAsync(); - } - else - { - user = entity.User; - } - - // 这里有问题 - - UserType userType = new UserType(); - userType = await _dbContext.UserType.Where(x => x.Id == user.UserTypeId).FirstOrDefaultAsync(); - - await InsertInspection(item.Entity as TrialSiteUser, type, null, new - { - TrialSiteCode = entity.TrialSite.TrialSiteCode, - SiteName = entity.Site.SiteName, - SiteAliasName = entity.TrialSite.TrialSiteAliasName, - City = entity.Site.City, - Country = entity.Site.Country, - - UserName = user.UserName, - UserRealName = user.FullName, - UserType = userType.UserTypeShortName, - Phone = user.Phone, - Email = user.EMail, - Organization = entity.User.OrganizationName, - - }); - } - // 中心调研表 foreach (var item in entitys.Where(x => x.Entity.GetType() == typeof(TrialSiteSurvey))) { @@ -689,6 +563,163 @@ namespace IRaCIS.Core.Infra.EFCore.Common } + + #region 已修改 + + // 签名模板 + foreach (var item in entitys.Where(x => x.Entity.GetType() == typeof(SystemBasicData))) + { + await InsertInspection(item.Entity as SystemBasicData, type); + } + + // 项目 + foreach (var item in entitys.Where(x => x.Entity.GetType() == typeof(Trial))) + { + + var entity = item.Entity as Trial; + List trialDics = new List(); + var dictionaryIds = new List(); + if (entity.TrialDicList == null || entity.TrialDicList.Count == 0) + { + dictionaryIds = await this._dbContext.TrialDictionary.Where(x => x.TrialId == entity.Id && x.KeyName == "Criterion").Select(x => x.DictionaryId).ToListAsync(); + } + else + { + dictionaryIds = entity.TrialDicList.Select(x => x.DictionaryId).ToList(); + } + + trialDics = await this._dbContext.Dictionary.Where(x => dictionaryIds.Contains(x.Id)).Select(x => x.ValueCN).ToListAsync(); + + await InsertInspection(item.Entity as Trial, type, x => new InspectionConvertDTO() + { + TrialId = x.Id, + }, new + { + TrialDicList = string.Join(",", trialDics) + }); + } + + + // 项目中心 + foreach (var item in entitys.Where(x => x.Entity.GetType() == typeof(TrialSite))) + { + var entity = item.Entity as TrialSite; + if (entity.Site == null) + { + entity.Site = await _dbContext.Site.Where(x => x.Id == entity.SiteId).FirstOrDefaultAsync(); + } + await InsertInspection(entity, type, x => new InspectionConvertDTO() + { + TrialId = x.TrialId, + + ObjectRelationParentId=x.TrialId + }, new + { + //兼容之前的配置 冗余该字段 + SiteCode=entity.TrialSiteCode, + + //Site 没记录稽查 必须查询存 + SiteName = entity.Site.SiteName, + City = entity.Site.City, + Country = entity.Site.Country, + }); + } + + + + // 项目人员 + foreach (var item in entitys.Where(x => x.Entity.GetType() == typeof(TrialUser))) + { + + var entity = item.Entity as TrialUser; + //var user = await _dbContext.Users.Include(x => x.UserTypeRole).FirstOrDefaultAsync(x => x.Id == entity.UserId); + await InsertInspection(entity, type, x => new InspectionConvertDTO + { + TrialId = x.TrialId, + ObjectRelationParentId = x.TrialId, + ObjectRelationParentId2=x.UserId, + }); + } + + + // 项目中心人员 + foreach (var item in entitys.Where(x => x.Entity.GetType() == typeof(TrialSiteUser))) + { + var entity = item.Entity as TrialSiteUser; + + + if (entity.TrialSite == null) + { + entity.TrialSite = await _dbContext.TrialSite.Where(x => x.TrialId == entity.TrialId && x.SiteId == entity.SiteId).IgnoreQueryFilters().FirstOrDefaultAsync(); + } + + await InsertInspection(item.Entity as TrialSiteUser, type, x => new InspectionConvertDTO + { + TrialId = x.TrialId, + ObjectRelationParentId = entity.TrialSite.Id, + ObjectRelationParentId2 = x.UserId, + }); + } + + + + + // 受试者 + foreach (var item in entitys.Where(x => x.Entity.GetType() == typeof(Subject))) + { + 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(); + + //var trialSiteCode = await _dbContext.TrialSite.Where(t => t.TrialId == entity.TrialId && t.SiteId == entity.SiteId).Select(t => t.TrialSiteCode).FirstOrDefaultAsync(); + + var trialSiteId = await _dbContext.TrialSite.Where(t => t.TrialId == entity.TrialId && t.SiteId == entity.SiteId).Select(t => t.Id).FirstOrDefaultAsync(); + + await InsertInspection(entity, type, x => new InspectionConvertDTO() + { + SubjectId = x.Id, + SiteId = x.SiteId, + + //项目的信息 找离的最近的项目稽查信息 + ObjectRelationParentId = trialSiteId, + }, new + { + FinalSubjectVisitName = finalSubjectVisitName, + + //变换名称 兼容之前做的稽查 冗余 + SubjectCode = entity.Code, + }); + } + + // 访视 + foreach (var item in entitys.Where(x => x.Entity.GetType() == typeof(SubjectVisit))) + { + var entity = item.Entity as SubjectVisit; + string reason = string.Empty; + + if (_userInfo.RequestUrl.ToLower() == "qcoperation/setcheckpass") + { + reason = entity.ManualPassReason; + } + + var subjectCode = entity.Subject?.Code; + + await InsertInspection(item.Entity as SubjectVisit, type, x => new InspectionConvertDTO() + { + //Subject的信息 找离的最近的Subject稽查信息 + ObjectRelationParentId = x.SubjectId, + + SubjectId = x.SubjectId, + SubjectVisitId = x.Id, + SiteId = x.SiteId, + Reason = reason, + }); + } + + + #endregion + + + #region 阅片人入组 //阅片人入组 @@ -697,7 +728,7 @@ namespace IRaCIS.Core.Infra.EFCore.Common var entity = item.Entity as Enroll; var doctor = await _dbContext.Doctor.FirstOrDefaultAsync(x => x.Id == entity.DoctorId); - var readingCategoryList = await _dbContext.EnrollReadingCategory.Where(x => x.EnrollId == entity.Id).Select(t=>t.ReadingCategory).ToListAsync(); + var readingCategoryList = await _dbContext.EnrollReadingCategory.Where(x => x.EnrollId == entity.Id).Select(t => t.ReadingCategory).ToListAsync(); await InsertInspection(item.Entity as Enroll, type, x => new InspectionConvertDTO() { ObjectRelationParentId = x.TrialId @@ -710,7 +741,7 @@ namespace IRaCIS.Core.Infra.EFCore.Common IsUploadedACKSOW = entity.AttachmentId != Guid.Empty, - ReadingCategoryList=readingCategoryList + ReadingCategoryList = readingCategoryList }); } @@ -742,53 +773,6 @@ namespace IRaCIS.Core.Infra.EFCore.Common #region Subject 阅片期和 临床数据 - // 受试者 - foreach (var item in entitys.Where(x => x.Entity.GetType() == typeof(Subject))) - { - 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(); - - await InsertInspection(entity, type, x => new InspectionConvertDTO() - { - SubjectId = x.Id, - SubjectCode = x.Code, - }, new - { - FinalSubjectVisitName = finalSubjectVisitName, - SujectCode = entity.Code - - }); - } - - // 访视 - foreach (var item in entitys.Where(x => x.Entity.GetType() == typeof(SubjectVisit))) - { - var entity = item.Entity as SubjectVisit; - string reason = string.Empty; - - if (_userInfo.RequestUrl.ToLower() == "qcoperation/setcheckpass") - { - reason = entity.ManualPassReason; - } - - var subjectCode = entity.Subject?.Code; - - await InsertInspection(item.Entity as SubjectVisit, type, x => new InspectionConvertDTO() - { - ObjectRelationParentId = x.SubjectId, - SubjectCode = subjectCode, - SubjectId = x.SubjectId, - SubjectVisitId = x.Id, - //SubjectVisitName = x.VisitName, - //BlindName = x.BlindName, - Reason = reason, - }, new - { - SubjectVisitName = entity.VisitName, - BlindName = entity.BlindName, - }); - } - //阅片期计划 foreach (var item in entitys.Where(x => x.Entity.GetType() == typeof(ReadingPeriodSet))) { @@ -887,6 +871,7 @@ namespace IRaCIS.Core.Infra.EFCore.Common { SubjectId = x.SubjectId, IsDistinctionInterface = false, + ObjectRelationParentId = entity.ReadingClinicalDataId }, new { @@ -947,7 +932,7 @@ namespace IRaCIS.Core.Infra.EFCore.Common ObjectRelationParentId2 = entity.DoctorUserId - },new { ArmToTask =entity.ArmEnum}); + }, new { ArmToTask = entity.ArmEnum }); } //任务 @@ -957,7 +942,10 @@ namespace IRaCIS.Core.Infra.EFCore.Common await InsertInspection(entity, type, x => new InspectionConvertDTO() { + VisitTaskId=x.Id, + IsDistinctionInterface = type == AuditOpt.Update ? true : false, + ObjectRelationParentId = entity.SourceSubjectVisitId != null ? entity.SourceSubjectVisitId : entity.SouceReadModuleId, ObjectRelationParentId2 = entity.DoctorUserId @@ -972,6 +960,9 @@ namespace IRaCIS.Core.Infra.EFCore.Common await InsertInspection(entity, type, x => new InspectionConvertDTO() { + VisitTaskId=entity.OriginalReReadingTaskId, + + Reason=entity.RequestReReadingReason, ObjectRelationParentId = entity.OriginalReReadingTaskId, @@ -987,6 +978,7 @@ namespace IRaCIS.Core.Infra.EFCore.Common await InsertInspection(entity, type, x => new InspectionConvertDTO() { + VisitTaskId = entity.VisitTaskId, ObjectRelationParentId = entity.VisitTaskId, @@ -1034,7 +1026,6 @@ namespace IRaCIS.Core.Infra.EFCore.Common InspectionConvertDTO inspection = new InspectionConvertDTO(); - if (expression != null) { var f = expression.Compile(); @@ -1051,7 +1042,9 @@ namespace IRaCIS.Core.Infra.EFCore.Common //将实体对象属性 映射到稽查实体 MapEntityPropertyToAuditEntity(entityObj, inspection); - var generalData = await GetInspectionGeneralDataAsync(inspection); + //var generalData = await GetInspectionGeneralDataAsync(inspection); + + var generalData = await GetInspectionGeneralGuidAsync(inspection); //不可少 因为稽查实体可能某些Id没有 MapEntityPropertyToAuditEntity(generalData, inspection); @@ -1065,13 +1058,17 @@ namespace IRaCIS.Core.Infra.EFCore.Common inspection.ModuleTypeId = from?.ModuleTypeId; #endregion - if (inspection.ParentId == null) - { - //inspection.ParentId = (await _dbContext.DataInspection.AsQueryable().Where(x => x.TrialId == inspection.TrialId && x.SubjectVisitId == inspection.SubjectVisitId && x.SubjectId == inspection.SubjectId && x.SiteId == inspection.SiteId && x.GeneralId == inspection.GeneralId).OrderByDescending(x => x.CreateTime).FirstOrDefaultAsync())?.Id; - inspection.ParentId = (await _dbContext.DataInspection.AsQueryable().Where(x => x.GeneralId == inspection.GeneralId && x.ObjectRelationParentId == inspection.ObjectRelationParentId).OrderByDescending(x => x.CreateTime).FirstOrDefaultAsync())?.Id; - } + + //if (inspection.ParentId == null) + //{ + // //inspection.ParentId = (await _dbContext.DataInspection.AsQueryable().Where(x => x.TrialId == inspection.TrialId && x.SubjectVisitId == inspection.SubjectVisitId && x.SubjectId == inspection.SubjectId && x.SiteId == inspection.SiteId && x.GeneralId == inspection.GeneralId).OrderByDescending(x => x.CreateTime).FirstOrDefaultAsync())?.Id; + + + // inspection.ParentId = (await _dbContext.DataInspection.AsQueryable().Where(x => x.GeneralId == inspection.GeneralId && x.ObjectRelationParentId == inspection.ObjectRelationParentId).OrderByDescending(x => x.CreateTime).FirstOrDefaultAsync())?.Id; + //} + inspection.CreateUserId = _userInfo.Id; inspection.IP = _userInfo.IP; inspection.CreateTime = inspection.CreateTime == default(DateTime) ? DateTime.Now : inspection.CreateTime; @@ -1140,122 +1137,71 @@ namespace IRaCIS.Core.Infra.EFCore.Common } - /// - /// 获取稽查通用数据 (每条稽查记录必须查询的) + /// 获取稽查通用Guid数据 (每条稽查记录必须查询的) /// /// /// - public async Task GetInspectionGeneralDataAsync(InspectionConvertDTO inspection) + public async Task GetInspectionGeneralGuidAsync(InspectionConvertDTO inspection) { InspectionGeneralData generalData = new InspectionGeneralData() { - SiteCode = inspection.SiteCode, SiteId = inspection.SiteId, - //SiteName = inspection.SiteName, - SubjectCode = inspection.SubjectCode, SubjectId = inspection.SubjectId, SubjectVisitId = inspection.SubjectVisitId, - SubjectVisitName = inspection.SubjectVisitName, - ResearchProgramNo = inspection.ResearchProgramNo, - TrialId = inspection.TrialId, - TrialName = inspection.TrialName + TrialId = inspection.TrialId }; - - #region 访视 阅片期那里关联了访视 - - //if (generalData.SubjectVisitId != null) + //if (inspection.TrialId == null && inspection.SubjectId == null && inspection.SubjectVisitId == null && inspection.SiteId == null && inspection.VisitTaskId == null) //{ - // //添加访视的时候,会带信息过来 - // if (string.IsNullOrEmpty(generalData.SubjectVisitName)) - // { - // var info = (await _dbContext.SubjectVisit.Where(x => x.Id == generalData.SubjectVisitId).Select(x => - // new { x.VisitName, x.SubjectId, x.SiteId, SubjectCode = x.Subject.Code, TrialSiteCode = x.TrialSite.TrialSiteCode, x.TrialId, x.Trial.ExperimentName, x.Trial.ResearchProgramNo }).FirstOrDefaultAsync()).IfNullThrowException(); - - // generalData.SubjectVisitName = info.VisitName; - - // generalData.TrialId = info.TrialId; - // generalData.TrialName = info.ExperimentName; - // generalData.ResearchProgramNo = info.ResearchProgramNo; - // generalData.SiteId = info.SiteId; - // generalData.SubjectCode = info.SubjectCode; - // generalData.SubjectId = info.SubjectId; - // generalData.SiteCode = info.TrialSiteCode; - // } + // throw new BusinessValidationFailedException("稽查记录 关联TrialId、SubjectId、SubjectVisitId、SiteId 都忘记进行了设置"); //} - - #endregion + if (inspection.VisitTaskId != null) + { + var info = (await _dbContext.VisitTask.Where(x => x.Id == inspection.VisitTaskId).Select(x => new { SubjectId = x.SubjectId, x.Subject.SiteId, x.TrialId,x.SourceSubjectVisitId, ReadModuleSubjectVisitId= (Guid?)x.ReadModule.SubjectVisitId }).FirstOrDefaultAsync()).IfNullThrowException(); - #region 受试者 + generalData.TrialId = info.TrialId; + generalData.SubjectId = info.SubjectId; + generalData.SiteId = info.SiteId; + generalData.SubjectVisitId = info.SourceSubjectVisitId!=null ?info.SourceSubjectVisitId: (info.ReadModuleSubjectVisitId != null ? info.ReadModuleSubjectVisitId : null ) ; + } + + // Suject visit 都进行了设置 不用处理 + + if (inspection.SubjectVisitId != null) + { + var info = await _dbContext.SubjectVisit.Where(x => x.Id == generalData.SubjectVisitId).Select(x => + new { x.SubjectId, x.SiteId, x.TrialId }).FirstOrDefaultAsync(); + + + generalData.TrialId = info?.TrialId ?? generalData.TrialId; + generalData.SiteId = info?.SiteId ?? generalData.SiteId; + + generalData.SubjectId = info?.SubjectId?? generalData.SubjectId; + } + if (generalData.SubjectId != null) { + var info = await _dbContext.Subject.Where(x => x.Id == generalData.SubjectId).Select(x => new { SubjectId = x.Id, x.SiteId ,x.TrialId }).FirstOrDefaultAsync(); - // 添加Subject 哪里会带信息过来 - if (string.IsNullOrEmpty(generalData.SubjectCode)) - { - var info = (await _dbContext.Subject.Where(x => x.Id == generalData.SubjectId).Select(x => new { SubjectId = x.Id, SubjectCode = x.Code, x.SiteId, TrialSiteCode = x.TrialSite.TrialSiteCode, x.TrialId, x.Trial.ExperimentName, x.Trial.ResearchProgramNo }).FirstOrDefaultAsync()).IfNullThrowException(); - - - generalData.TrialId = info.TrialId; - generalData.TrialName = info.ExperimentName; - generalData.ResearchProgramNo = info.ResearchProgramNo; - generalData.SiteId = info.SiteId; - generalData.SubjectCode = info.SubjectCode; - generalData.SubjectId = info.SubjectId; - generalData.SiteCode = info.TrialSiteCode; - - } + generalData.TrialId = info?.TrialId?? generalData.TrialId; + generalData.SiteId = info?.SiteId?? generalData.SiteId; } - - #endregion - - - - #region 中心Code - - if (generalData.TrialId != null && generalData.SiteId != null) - { - - generalData.SiteCode = (await _dbContext.TrialSite.IgnoreQueryFilters().Where(x => x.TrialId == generalData.TrialId && x.SiteId == generalData.SiteId).Select(t => t.TrialSiteCode).FirstOrDefaultAsync()).IfNullThrowException(); - - - } - - - #endregion - - - #region 项目名称 - - - if (generalData.TrialId != null) - { - - //项目添加哪里 直接会带信息过来,不用查询数据库 其他的地方需要查询数据库 - if (string.IsNullOrEmpty(generalData.ResearchProgramNo) || string.IsNullOrEmpty(generalData.TrialName)) - { - var trialdata = (await _dbContext.Trial.Select(x => new { x.Id, x.ResearchProgramNo, x.ExperimentName, }).FirstOrDefaultAsync(x => x.Id == generalData.TrialId)).IfNullThrowException(); - - generalData.ResearchProgramNo = trialdata.ResearchProgramNo; - - generalData.TrialName = trialdata.ExperimentName; - } - } - - #endregion - - - + return generalData; } + + + + + /// @@ -1426,6 +1372,16 @@ namespace IRaCIS.Core.Infra.EFCore.Common { type = type + "/" + 2; } + + if (visitTaskReReading.RequestReReadingResultEnum == RequestReReadingResult.Agree) + { + type = type + "/" + 1; + + } + else if (visitTaskReReading.RequestReReadingResultEnum == RequestReReadingResult.Reject) + { + type = type + "/" + 2; + } break; } @@ -1502,6 +1458,125 @@ namespace IRaCIS.Core.Infra.EFCore.Common #region 待废弃 -by zhouhang 调整 + /// + /// 获取稽查通用数据 (每条稽查记录必须查询的) + /// + /// + /// + public async Task GetInspectionGeneralDataAsync(InspectionConvertDTO inspection) + { + + InspectionGeneralData generalData = new InspectionGeneralData() + { + SiteCode = inspection.SiteCode, + SiteId = inspection.SiteId, + //SiteName = inspection.SiteName, + SubjectCode = inspection.SubjectCode, + SubjectId = inspection.SubjectId, + SubjectVisitId = inspection.SubjectVisitId, + SubjectVisitName = inspection.SubjectVisitName, + ResearchProgramNo = inspection.ResearchProgramNo, + TrialId = inspection.TrialId, + TrialName = inspection.TrialName + }; + + + + + #region 访视 阅片期那里关联了访视 + + //if (generalData.SubjectVisitId != null) + //{ + // //添加访视的时候,会带信息过来 + // if (string.IsNullOrEmpty(generalData.SubjectVisitName)) + // { + // var info = (await _dbContext.SubjectVisit.Where(x => x.Id == generalData.SubjectVisitId).Select(x => + // new { x.VisitName, x.SubjectId, x.SiteId, SubjectCode = x.Subject.Code, TrialSiteCode = x.TrialSite.TrialSiteCode, x.TrialId, x.Trial.ExperimentName, x.Trial.ResearchProgramNo }).FirstOrDefaultAsync()).IfNullThrowException(); + + // generalData.SubjectVisitName = info.VisitName; + + // generalData.TrialId = info.TrialId; + // generalData.TrialName = info.ExperimentName; + // generalData.ResearchProgramNo = info.ResearchProgramNo; + // generalData.SiteId = info.SiteId; + // generalData.SubjectCode = info.SubjectCode; + // generalData.SubjectId = info.SubjectId; + // generalData.SiteCode = info.TrialSiteCode; + // } + //} + + + #endregion + + + #region 受试者 + + if (generalData.SubjectId != null) + { + + // 添加Subject 哪里会带信息过来 + if (string.IsNullOrEmpty(generalData.SubjectCode)) + { + var info = (await _dbContext.Subject.Where(x => x.Id == generalData.SubjectId).Select(x => new { SubjectId = x.Id, SubjectCode = x.Code, x.SiteId, TrialSiteCode = x.TrialSite.TrialSiteCode, x.TrialId, x.Trial.ExperimentName, x.Trial.ResearchProgramNo }).FirstOrDefaultAsync()).IfNullThrowException(); + + + generalData.TrialId = info.TrialId; + generalData.TrialName = info.ExperimentName; + generalData.ResearchProgramNo = info.ResearchProgramNo; + generalData.SiteId = info.SiteId; + generalData.SubjectCode = info.SubjectCode; + generalData.SubjectId = info.SubjectId; + generalData.SiteCode = info.TrialSiteCode; + + } + } + + #endregion + + + + #region 中心Code + + if (generalData.TrialId != null && generalData.SiteId != null) + { + + generalData.SiteCode = (await _dbContext.TrialSite.IgnoreQueryFilters().Where(x => x.TrialId == generalData.TrialId && x.SiteId == generalData.SiteId).Select(t => t.TrialSiteCode).FirstOrDefaultAsync()).IfNullThrowException(); + + + } + + + #endregion + + + #region 项目名称 + + + if (generalData.TrialId != null) + { + + //项目添加哪里 直接会带信息过来,不用查询数据库 其他的地方需要查询数据库 + if (string.IsNullOrEmpty(generalData.ResearchProgramNo) || string.IsNullOrEmpty(generalData.TrialName)) + { + var trialdata = (await _dbContext.Trial.Select(x => new { x.Id, x.ResearchProgramNo, x.ExperimentName, }).FirstOrDefaultAsync(x => x.Id == generalData.TrialId)).IfNullThrowException(); + + generalData.ResearchProgramNo = trialdata.ResearchProgramNo; + + generalData.TrialName = trialdata.ExperimentName; + } + } + + #endregion + + + + return generalData; + } + + + + + ///// ///// 映射数据 ///// diff --git a/IRaCIS.Core.Infra.EFCore/Common/Dto/SetDictionaryValueDto.cs b/IRaCIS.Core.Infra.EFCore/Common/Dto/SetDictionaryValueDto.cs index 48196bd86..e32b71ea6 100644 --- a/IRaCIS.Core.Infra.EFCore/Common/Dto/SetDictionaryValueDto.cs +++ b/IRaCIS.Core.Infra.EFCore/Common/Dto/SetDictionaryValueDto.cs @@ -148,6 +148,8 @@ namespace IRaCIS.Core.Infra.EFCore.Common.Dto //标识操作 是否区分接口 public bool IsDistinctionInterface=true; + public Guid? VisitTaskId { get; set; } + }