diff --git a/IRaCIS.Core.Application/Service/Allocation/DTO/VisitTaskViewModel.cs b/IRaCIS.Core.Application/Service/Allocation/DTO/VisitTaskViewModel.cs index d680022ac..2f0b41192 100644 --- a/IRaCIS.Core.Application/Service/Allocation/DTO/VisitTaskViewModel.cs +++ b/IRaCIS.Core.Application/Service/Allocation/DTO/VisitTaskViewModel.cs @@ -602,9 +602,9 @@ namespace IRaCIS.Core.Application.ViewModel [JsonIgnore] public List DoctorUserList { get; set; } - public List PreviousDoctorUserList => DoctorUserList.Where(t => t.OrignalSubjectUserId != null).ToList(); + public List PreviousDoctorUserList => DoctorUserList.Where(t => t.ReplacedSubjectUserId != null).ToList(); - public List NowDoctorUserList => DoctorUserList.Where(t => t.OrignalSubjectUserId == null).ToList(); + public List NowDoctorUserList => DoctorUserList.Where(t => t.ReplacedSubjectUserId == null).ToList(); @@ -622,7 +622,7 @@ namespace IRaCIS.Core.Application.ViewModel public bool IsConfirmed { get; set; } //该属性有值 说明该医生被替换了 分配的时候 要过滤掉 - public Guid? OrignalSubjectUserId { get; set; } + public Guid? ReplacedSubjectUserId { get; set; } public UserSimpleInfo DoctorUser { get; set; } } diff --git a/IRaCIS.Core.Application/Service/Allocation/VisitTaskHelpeService.cs b/IRaCIS.Core.Application/Service/Allocation/VisitTaskHelpeService.cs index 8a7108bb9..7d83da129 100644 --- a/IRaCIS.Core.Application/Service/Allocation/VisitTaskHelpeService.cs +++ b/IRaCIS.Core.Application/Service/Allocation/VisitTaskHelpeService.cs @@ -144,7 +144,7 @@ namespace IRaCIS.Core.Application.Service foreach (var subjectGroup in needGenerateVisit.GroupBy(t => t.SubjectId).Select(g => new { SubjectId = g.Key, SubjectVisitList = g.ToList() })) { - var assignConfigList = await _subjectUserRepository.Where(t => t.TrialId == trialId && t.TrialReadingCriterionId == trialReadingCriterionConfig.TrialReadingCriterionId && t.SubjectId == subjectGroup.SubjectId && t.OrignalSubjectUserId == null && t.IsConfirmed).Select(u => new { u.DoctorUserId, u.ArmEnum }).ToListAsync(); + var assignConfigList = await _subjectUserRepository.Where(t => t.TrialId == trialId && t.TrialReadingCriterionId == trialReadingCriterionConfig.TrialReadingCriterionId && t.SubjectId == subjectGroup.SubjectId && t.ReplacedSubjectUserId == null && t.IsConfirmed).Select(u => new { u.DoctorUserId, u.ArmEnum }).ToListAsync(); @@ -632,7 +632,7 @@ namespace IRaCIS.Core.Application.Service { - var assignConfigList = await _subjectUserRepository.Where(t => t.TrialId == trialId && t.TrialReadingCriterionId == trialReadingCriterionConfig.TrialReadingCriterionId && t.SubjectId == subjectVisit.SubjectId && t.OrignalSubjectUserId == null && t.IsConfirmed).Select(u => new { u.DoctorUserId, u.ArmEnum }).ToListAsync(); + var assignConfigList = await _subjectUserRepository.Where(t => t.TrialId == trialId && t.TrialReadingCriterionId == trialReadingCriterionConfig.TrialReadingCriterionId && t.SubjectId == subjectVisit.SubjectId && t.ReplacedSubjectUserId == null && t.IsConfirmed).Select(u => new { u.DoctorUserId, u.ArmEnum }).ToListAsync(); var isNeedClinicalDataSign = IsNeedClinicalDataSign(ReadingCategory.Visit, subjectVisit.IsBaseLine, trialReadingCriterionConfig.TrialReadingCriterionId, clinicalDataConfirmList); var isClinicalDataSign = IsClinicalDataSign(ReadingCategory.Visit, subjectVisit.IsBaseLine, trialReadingCriterionConfig.TrialReadingCriterionId, clinicalDataConfirmList, subjectVisit.Id, trialId); diff --git a/IRaCIS.Core.Application/Service/Allocation/VisitTaskService.cs b/IRaCIS.Core.Application/Service/Allocation/VisitTaskService.cs index 83d1bb3cf..e480900e2 100644 --- a/IRaCIS.Core.Application/Service/Allocation/VisitTaskService.cs +++ b/IRaCIS.Core.Application/Service/Allocation/VisitTaskService.cs @@ -171,7 +171,7 @@ namespace IRaCIS.Core.Application.Service.Allocation { foreach (var doctorArm in command.DoctorArmList) { - if (!await _subjectUserRepository.Where(t => t.TrialReadingCriterionId == command.TrialReadingCriterionId).AnyAsync(t => t.SubjectId == subjectId && t.DoctorUserId == doctorArm.DoctorUserId && t.ArmEnum == doctorArm.ArmEnum && t.IsConfirmed && t.OrignalSubjectUserId == null)) + if (!await _subjectUserRepository.Where(t => t.TrialReadingCriterionId == command.TrialReadingCriterionId).AnyAsync(t => t.SubjectId == subjectId && t.DoctorUserId == doctorArm.DoctorUserId && t.ArmEnum == doctorArm.ArmEnum && t.IsConfirmed && t.ReplacedSubjectUserId == null)) { await _subjectUserRepository.AddAsync(new SubjectUser() { TrialId = command.TrialId, TrialReadingCriterionId = command.TrialReadingCriterionId, ArmEnum = doctorArm.ArmEnum, DoctorUserId = doctorArm.DoctorUserId, SubjectId = subjectId, AssignTime = DateTime.Now }); @@ -246,7 +246,7 @@ namespace IRaCIS.Core.Application.Service.Allocation /// public async Task<(List, object)> GetSubjectAssignedDoctorList(Guid subjectId, Guid trialReadingCriterionId) { - var list = await _subjectUserRepository.Where(t => t.SubjectId == subjectId && t.OrignalSubjectUserId == null && t.IsConfirmed && t.TrialReadingCriterionId == trialReadingCriterionId).ProjectTo(_mapper.ConfigurationProvider).ToListAsync(); + var list = await _subjectUserRepository.Where(t => t.SubjectId == subjectId && t.ReplacedSubjectUserId == null && t.IsConfirmed && t.TrialReadingCriterionId == trialReadingCriterionId).ProjectTo(_mapper.ConfigurationProvider).ToListAsync(); var criterionConfig = (await _trialReadingCriterionRepository.Where(x => x.Id == trialReadingCriterionId).Select(x => new { x.ReadingTool, x.IsReadingTaskViewInOrder, x.ReadingType, x.IsGlobalReading, x.IsOncologyReading, x.IsArbitrationReading }).FirstOrDefaultAsync()).IfNullThrowException(); @@ -479,13 +479,13 @@ namespace IRaCIS.Core.Application.Service.Allocation var armEnum = assginSubjectDoctorCommand.DoctorUserIdArmList.Where(t => t.DoctorUserId == doctorUserId).First().ArmEnum; - if (await _subjectUserRepository.AnyAsync(t => t.TrialId == trialId && t.SubjectId == subjectId && t.DoctorUserId == doctorUserId && t.ArmEnum != armEnum && t.OrignalSubjectUserId == null)) + if (await _subjectUserRepository.AnyAsync(t => t.TrialId == trialId && t.SubjectId == subjectId && t.DoctorUserId == doctorUserId && t.ArmEnum != armEnum && t.ReplacedSubjectUserId == null)) { //---有Subject 在其他Arm组已有该医生,不允许在新的组添加该医生 throw new BusinessValidationFailedException(_localizer["VisitTask_InconsistentSubjectStatus"]); } - if (await _subjectUserRepository.AnyAsync(t => t.TrialId == trialId && t.SubjectId == subjectId && t.DoctorUserId == doctorUserId && t.ArmEnum == armEnum && t.OrignalSubjectUserId == null)) + if (await _subjectUserRepository.AnyAsync(t => t.TrialId == trialId && t.SubjectId == subjectId && t.DoctorUserId == doctorUserId && t.ArmEnum == armEnum && t.ReplacedSubjectUserId == null)) { //---有Subject 已有该Arm组的医生,不允许继续分配,请刷新页面,确认页面数据是否过期 throw new BusinessValidationFailedException(_localizer["VisitTask_DuplicateDoctorInArm"]); @@ -568,11 +568,11 @@ namespace IRaCIS.Core.Application.Service.Allocation //将关系确认 if (assignConfirmCommand.SubjectDoctorUserList.Count == 0) { - await _subjectUserRepository.BatchUpdateNoTrackingAsync(t => t.TrialId == trialId && t.IsConfirmed == false && t.OrignalSubjectUserId == null, u => new SubjectUser() { IsConfirmed = true }); + await _subjectUserRepository.BatchUpdateNoTrackingAsync(t => t.TrialId == trialId && t.IsConfirmed == false && t.ReplacedSubjectUserId == null, u => new SubjectUser() { IsConfirmed = true }); } else { - await _subjectUserRepository.BatchUpdateNoTrackingAsync(t => t.TrialId == trialId && t.IsConfirmed == false && t.OrignalSubjectUserId == null + await _subjectUserRepository.BatchUpdateNoTrackingAsync(t => t.TrialId == trialId && t.IsConfirmed == false && t.ReplacedSubjectUserId == null && subjectIdList.Contains(t.SubjectId), u => new SubjectUser() { IsConfirmed = true }); } @@ -597,7 +597,7 @@ namespace IRaCIS.Core.Application.Service.Allocation if (assignConfirmCommand.SubjectDoctorUserList.Count == 0) { - subjectDoctorIdArmList = _subjectUserRepository.Where(t => t.SubjectId == subjectId && t.OrignalSubjectUserId == null).Select(t => new DoctorArm() { DoctorUserId = t.DoctorUserId, ArmEnum = t.ArmEnum }).ToList(); + subjectDoctorIdArmList = _subjectUserRepository.Where(t => t.SubjectId == subjectId && t.ReplacedSubjectUserId == null).Select(t => new DoctorArm() { DoctorUserId = t.DoctorUserId, ArmEnum = t.ArmEnum }).ToList(); } else { diff --git a/IRaCIS.Core.Domain/Allocation/SubjectUser.cs b/IRaCIS.Core.Domain/Allocation/SubjectUser.cs index 88680dc39..f4adcfcde 100644 --- a/IRaCIS.Core.Domain/Allocation/SubjectUser.cs +++ b/IRaCIS.Core.Domain/Allocation/SubjectUser.cs @@ -24,8 +24,8 @@ namespace IRaCIS.Core.Domain.Models [JsonIgnore] //Parent - [ForeignKey("OrignalSubjectUserId")] - public SubjectUser OrignalSubjectUser { get; set; } + [ForeignKey("ReplacedSubjectUserId")] + public SubjectUser ReplacedSubjectUser { get; set; } //ChildList [JsonIgnore] @@ -34,6 +34,9 @@ namespace IRaCIS.Core.Domain.Models [JsonIgnore] public User DoctorUser { get; set; } + + [JsonIgnore] + public Subject Subject { get; set; } #endregion public Guid TrialId { get; set; } @@ -44,8 +47,6 @@ namespace IRaCIS.Core.Domain.Models public Guid SubjectId { get; set; } - public Subject Subject { get; set; } - public Guid DoctorUserId { get; set; } @@ -55,7 +56,7 @@ namespace IRaCIS.Core.Domain.Models public bool IsConfirmed { get; set; } = true; //该属性有值 说明该医生被替换了 分配的时候 要过滤掉 - public Guid? OrignalSubjectUserId { get; set; } + public Guid? ReplacedSubjectUserId { get; set; } diff --git a/IRaCIS.Core.Domain/Allocation/TaskInfluence.cs b/IRaCIS.Core.Domain/Allocation/TaskInfluence.cs index c372cbb50..9f0ce8173 100644 --- a/IRaCIS.Core.Domain/Allocation/TaskInfluence.cs +++ b/IRaCIS.Core.Domain/Allocation/TaskInfluence.cs @@ -19,6 +19,7 @@ namespace IRaCIS.Core.Domain.Models #region 导航属性 [JsonIgnore] public VisitTask OriginalTask { get; set; } + [JsonIgnore] public VisitTask InfluenceTask { get; set; } #endregion diff --git a/IRaCIS.Core.Domain/Reading/ClinicalData/ReadingClinicalData.cs b/IRaCIS.Core.Domain/Reading/ClinicalData/ReadingClinicalData.cs index a4188779c..989a66465 100644 --- a/IRaCIS.Core.Domain/Reading/ClinicalData/ReadingClinicalData.cs +++ b/IRaCIS.Core.Domain/Reading/ClinicalData/ReadingClinicalData.cs @@ -22,7 +22,8 @@ namespace IRaCIS.Core.Domain.Models public ClinicalDataTrialSet ClinicalDataTrialSet { get; set; } [JsonIgnore] - public DicomStudy? DicomStudy { get; set; } + [ForeignKey("StudyId")] + public DicomStudy DicomStudy { get; set; } [JsonIgnore] [ForeignKey("TrialId")] diff --git a/IRaCIS.Core.Domain/Reading/ClinicalData/ReadingConsistentClinicalData.cs b/IRaCIS.Core.Domain/Reading/ClinicalData/ReadingConsistentClinicalData.cs index 37510150f..6c0d126ad 100644 --- a/IRaCIS.Core.Domain/Reading/ClinicalData/ReadingConsistentClinicalData.cs +++ b/IRaCIS.Core.Domain/Reading/ClinicalData/ReadingConsistentClinicalData.cs @@ -21,8 +21,8 @@ namespace IRaCIS.Core.Domain.Models public ClinicalDataTrialSet ClinicalDataTrialSet { get; set; } [JsonIgnore] - - public DicomStudy? DicomStudy { get; set; } + [ForeignKey("StudyId")] + public DicomStudy DicomStudy { get; set; } [JsonIgnore] [ForeignKey("TrialId")] diff --git a/IRaCIS.Core.Infra.EFCore/EntityConfigration/StudyConfigration.cs b/IRaCIS.Core.Infra.EFCore/EntityConfigration/StudyConfigration.cs index 4114c225a..5fa1e61c3 100644 --- a/IRaCIS.Core.Infra.EFCore/EntityConfigration/StudyConfigration.cs +++ b/IRaCIS.Core.Infra.EFCore/EntityConfigration/StudyConfigration.cs @@ -5,39 +5,38 @@ using Microsoft.EntityFrameworkCore.Metadata.Builders; namespace IRaCIS.Core.Infra.EFCore.EntityConfigration { - public class StudyConfigration : IEntityTypeConfiguration - { - - /// - /// 一个外键,关联多个表 - /// - /// - public void Configure(EntityTypeBuilder builder) - { - - builder - .HasMany(s => s.ReadingClinicalDataList) - .WithOne(c => c.DicomStudy) - .HasForeignKey(s => new { s.StudyId }) - .HasPrincipalKey(c => new { c.Id }); + //public class StudyConfigration : IEntityTypeConfiguration + //{ + + // /// + // /// 一个外键,关联多个表 ReadingId + // /// + // /// + // public void Configure(EntityTypeBuilder builder) + // { + + // builder + // .HasMany(s => s.ReadingClinicalDataList) + // .WithOne(c => c.DicomStudy) + // .HasForeignKey(s => new { s.StudyId }) + // .HasPrincipalKey(c => new { c.Id }); - builder - .HasMany(s => s.ReadingConsistentClinicalDataList) - .WithOne(c => c.DicomStudy) - .HasForeignKey(s => new { s.StudyId }) - .HasPrincipalKey(c => new { c.Id }); + // builder + // .HasMany(s => s.ReadingConsistentClinicalDataList) + // .WithOne(c => c.DicomStudy) + // .HasForeignKey(s => new { s.StudyId }) + // .HasPrincipalKey(c => new { c.Id }); - } - } + // } + //} - public class ReadModuleConfigration : IEntityTypeConfiguration - { - - public void Configure(EntityTypeBuilder builder) - { - - builder.HasOne(t => t.SubjectVisit).WithMany(t => t.ReadModuleList).HasForeignKey(t => t.SubjectVisitId); - } - } + //public class UserConfigration : IEntityTypeConfiguration + //{ + // public void Configure(EntityTypeBuilder builder) + // { + // //对于阅片人来讲,会有很多任务 + // builder.HasMany(t => t.VisitTaskList).WithOne(t => t.DoctorUser).HasForeignKey(t => t.DoctorUserId).IsRequired(false); + // } + //} } diff --git a/IRaCIS.Core.Infra.EFCore/EntityConfigration/VisitTaskConfigration.cs b/IRaCIS.Core.Infra.EFCore/EntityConfigration/VisitTaskConfigration.cs index 0c48832b7..61f1d1111 100644 --- a/IRaCIS.Core.Infra.EFCore/EntityConfigration/VisitTaskConfigration.cs +++ b/IRaCIS.Core.Infra.EFCore/EntityConfigration/VisitTaskConfigration.cs @@ -12,26 +12,31 @@ namespace IRaCIS.Core.Infra.EFCore.EntityConfigration public void Configure(EntityTypeBuilder builder) { + //对于裁判任务而言,一个裁判任务,关联了两个产生裁判的任务 + builder.HasMany(t => t.JudgeVisitList).WithOne(t => t.JudgeVisitTask).HasForeignKey(t => t.JudgeVisitTaskId); - builder.HasMany(t => t.JudgeVisitList).WithOne(t => t.JudgeVisitTask); - - builder.HasMany(t => t.TaskMedicalReviewList).WithOne(t => t.VisitTask).HasForeignKey(t => t.VisitTaskId); - - builder.HasOne(t => t.Subject).WithMany(s => s.SubjectVisitTaskList).HasForeignKey(t => t.SubjectId); - + //对于退回或者重阅的任务而已,会关联多个影响的任务 builder.HasMany(t => t.TaskInfluenceList).WithOne(s => s.OriginalTask).HasForeignKey(t => t.OriginalTaskId); + //对于全局任务而言,会关联多个全局访视阅片结果(因为同一全局会对多个访视的结果进行修改) builder.HasMany(t => t.GlobalVisitResultList).WithOne(s => s.GlobalVisitTask).HasForeignKey(t => t.GlobalTaskId); + //对于全局修改的任务而言,会关联多个全局访视阅片结果(因为同一个访视结果,会被多个全局修改) + //subject 删除了,但是任务没删除,导致的查询问题 builder.HasQueryFilter(b => b.Subject.IsDeleted == false); + + //builder.HasOne(t => t.Subject).WithMany(s => s.SubjectVisitTaskList).HasForeignKey(t => t.SubjectId); + //builder.HasMany(t => t.TaskMedicalReviewList).WithOne(t => t.VisitTask).HasForeignKey(t => t.VisitTaskId); + + } } public class ReadingQuestionTrialConfigration : IEntityTypeConfiguration { public void Configure(EntityTypeBuilder builder) { - + //不影响之前的逻辑,附加评估 builder.HasQueryFilter(p => p.IsAdditional == false); } @@ -41,16 +46,11 @@ namespace IRaCIS.Core.Infra.EFCore.EntityConfigration { public void Configure(EntityTypeBuilder builder) { - builder.HasMany(t => t.EarlierSubjectUserList).WithOne(t => t.OrignalSubjectUser); - } - } - public class UserConfigration : IEntityTypeConfiguration - { - public void Configure(EntityTypeBuilder builder) - { - builder.HasMany(t => t.VisitTaskList).WithOne(t => t.DoctorUser).HasForeignKey(t => t.DoctorUserId).IsRequired(false); + //对于替换后的医生而言,关联多个之前的医生 + builder.HasMany(t => t.EarlierSubjectUserList).WithOne(t => t.ReplacedSubjectUser); } } + } diff --git a/IRaCIS.Core.Test/CodeFirstTest/CodeFirst使用说明 b/IRaCIS.Core.Test/CodeFirstTest/CodeFirst使用说明 index 5a329af9d..78ded9bf4 100644 --- a/IRaCIS.Core.Test/CodeFirstTest/CodeFirst使用说明 +++ b/IRaCIS.Core.Test/CodeFirstTest/CodeFirst使用说明 @@ -12,4 +12,12 @@ https://www.cnblogs.com/cqpanda/p/16815263.html dotnet ef migrations remove -p IRaCIS.Core.Test -c IRCContext 3Ǩļµݿ - dotnet ef database update -p IRaCIS.Core.Test -c IRCContext \ No newline at end of file + dotnet ef database update -p IRaCIS.Core.Test -c IRCContext + + 4鿴Ǩ + dotnet ef migrations list -p IRaCIS.Core.Test -c IRCContext + + 5ijθµݿǨ + dotnet ef database update ijǨƵǰһǨ -p IRaCIS.Core.Test -c IRCContext + + diff --git a/IRaCIS.Core.Test/CodeFirstTest/MSSQL/EntityConfigration/SubjectConfigration.cs b/IRaCIS.Core.Test/CodeFirstTest/MSSQL/EntityConfigration/SubjectConfigration.cs index 888935f60..ff0800238 100644 --- a/IRaCIS.Core.Test/CodeFirstTest/MSSQL/EntityConfigration/SubjectConfigration.cs +++ b/IRaCIS.Core.Test/CodeFirstTest/MSSQL/EntityConfigration/SubjectConfigration.cs @@ -18,16 +18,5 @@ namespace IRaCIS.Core.Test.CodeFirstTest.MSSQL } } - public class TestOneConfigration : IEntityTypeConfiguration - { - - public void Configure(EntityTypeBuilder builder) - { - - builder.HasOne(s => s.LatestTestMany).WithMany().HasForeignKey(t=>t.LatestTestManyId); - builder.HasOne(s => s.FinalTestMany).WithMany().HasForeignKey(t => t.FinalTestManyId); - builder.HasMany(s => s.TestManyList).WithOne(sv => sv.TestOne).HasForeignKey(t => t.TestOneId); - } - } } diff --git a/IRaCIS.Core.Test/CodeFirstTest/MSSQL/IRCContext.cs b/IRaCIS.Core.Test/CodeFirstTest/MSSQL/IRCContext.cs index 01eb69f95..099056b6f 100644 --- a/IRaCIS.Core.Test/CodeFirstTest/MSSQL/IRCContext.cs +++ b/IRaCIS.Core.Test/CodeFirstTest/MSSQL/IRCContext.cs @@ -27,8 +27,8 @@ public partial class IRCContext : DbContext public virtual DbSet SubejectVisit { get; set; } public virtual DbSet Dictionary { get; set; } - public virtual DbSet TestOne { get; set; } - public virtual DbSet TestMany { get; set; } + public virtual DbSet ReadingClinicalData { get; set; } + public virtual DbSet ReadModule { get; set; } protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) => optionsBuilder.UseSqlServer("Server=106.14.89.110,1433;Database=IRC_Code;User ID=sa;Password=mssql_KnTs2a;TrustServerCertificate=true"); diff --git a/IRaCIS.Core.Test/CodeFirstTest/MSSQL/TrialImageDownload.cs b/IRaCIS.Core.Test/CodeFirstTest/MSSQL/TrialImageDownload.cs index 56a90d864..02eee8fe9 100644 --- a/IRaCIS.Core.Test/CodeFirstTest/MSSQL/TrialImageDownload.cs +++ b/IRaCIS.Core.Test/CodeFirstTest/MSSQL/TrialImageDownload.cs @@ -102,33 +102,30 @@ namespace IRaCIS.Core.Test.CodeFirstTest.MSSQL public string Code { get; set; } } - - public class TestOne : BaseFullAuditEntity + #region 一个外键 关联两个实体 + public class ReadingClinicalData : BaseFullAuditEntity { public string Code { get; set; } - [ForeignKey(nameof(TestOne.FinalTestMany))] - public Guid? LatestTestManyId { get; set; } - [ForeignKey(nameof(TestOne.LatestTestMany))] - public Guid? FinalTestManyId { get; set; } - - #region 同时配置一对多,一对一 导航属性 + public Guid ReadingId { get; set; } - public TestMany FinalTestMany { get; set; } + [ForeignKey("ReadingId")] - public TestMany LatestTestMany { get; set; } + public SubejectVisit SubjectVisit { get; set; } - public List TestManyList { get; set; } + [ForeignKey("ReadingId")] - #endregion + public ReadModule ReadModule { get; set; } } - public class TestMany : BaseFullAuditEntity + public class ReadModule : BaseFullAuditEntity { - public TestOne TestOne { get; set; } - - public Guid TestOneId { get; set; } + public string Name { get; set; } } + #endregion + + + }