diff --git a/IRaCIS.Core.Application/Helper/CacheHelper.cs b/IRaCIS.Core.Application/Helper/CacheHelper.cs index f3cf0cf51..5fb158ed1 100644 --- a/IRaCIS.Core.Application/Helper/CacheHelper.cs +++ b/IRaCIS.Core.Application/Helper/CacheHelper.cs @@ -10,6 +10,7 @@ namespace IRaCIS.Core.Application.Helper public static class CacheKeys { + //项目缓存 public static string Trial(string trialIdStr) => $"TrialId:{trialIdStr}"; //检查编号递增锁 @@ -33,8 +34,6 @@ namespace IRaCIS.Core.Application.Helper //超时没请求接口自动退出 public static string UserAutoLoginOut(Guid userId) => $"UserAutoLoginOut:{userId}"; - // 你可以为其他实体和模块定义更多的键 - /// /// 跳过阅片 /// diff --git a/IRaCIS.Core.Application/Helper/OSSService.cs b/IRaCIS.Core.Application/Helper/OSSService.cs index 9c7e96872..50d346ab3 100644 --- a/IRaCIS.Core.Application/Helper/OSSService.cs +++ b/IRaCIS.Core.Application/Helper/OSSService.cs @@ -109,17 +109,13 @@ namespace IRaCIS.Core.Application.Helper public string AccessKeyId { get; set; } public string AccessKeySecret { get; set; } - public string EndPoint { get; set; } public string BucketName { get; set; } - public string Region { get; set; } public string ViewEndpoint { get; set; } - - public string SecurityToken { get; set; } public DateTime Expiration { get; set; } 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.Application/Service/ImageAndDoc/DTO/UnionStudyViewDodel.cs b/IRaCIS.Core.Application/Service/ImageAndDoc/DTO/UnionStudyViewDodel.cs index 088c77ef3..7d82d7ec2 100644 --- a/IRaCIS.Core.Application/Service/ImageAndDoc/DTO/UnionStudyViewDodel.cs +++ b/IRaCIS.Core.Application/Service/ImageAndDoc/DTO/UnionStudyViewDodel.cs @@ -527,6 +527,8 @@ namespace IRaCIS.Core.Application.Contracts [NotDefault] public string SubjectCode { get; set; } + + public Guid? VisitTaskId { get; set; } } @@ -554,6 +556,6 @@ namespace IRaCIS.Core.Application.Contracts { public Guid SubjectVisitId { get; set; } - public Guid VisitTaskId { get; set; } + public Guid TaskId { get; set; } } } diff --git a/IRaCIS.Core.Application/Service/ImageAndDoc/DownloadAndUploadService.cs b/IRaCIS.Core.Application/Service/ImageAndDoc/DownloadAndUploadService.cs index 69534ade5..41d195d93 100644 --- a/IRaCIS.Core.Application/Service/ImageAndDoc/DownloadAndUploadService.cs +++ b/IRaCIS.Core.Application/Service/ImageAndDoc/DownloadAndUploadService.cs @@ -606,7 +606,7 @@ namespace IRaCIS.Core.Application.Service.ImageAndDoc var query = from u in _visitTaskRepository.Where(t => t.SubjectId == inQuery.SubjectId && t.TrialReadingCriterionId == inQuery.TrialReadingCriterionId && t.SourceSubjectVisitId != null && t.DoctorUserId == _userInfo.Id && t.TaskState == TaskState.Effect) - join ns in _noneDicomStudyReposiotry.Where(t => t.SubjectId == inQuery.SubjectId).WhereIf(info.IsImageFilter,t=> ("|" + info.CriterionModalitys + "|").Contains("|" + t.Modality + "|")) + join ns in _noneDicomStudyReposiotry.Where(t => t.SubjectId == inQuery.SubjectId).WhereIf(info.IsImageFilter, t => ("|" + info.CriterionModalitys + "|").Contains("|" + t.Modality + "|")) on u.SourceSubjectVisitId equals ns.SubjectVisitId select new TaskNoneDicomStudyDTO() @@ -738,9 +738,21 @@ namespace IRaCIS.Core.Application.Service.ImageAndDoc [HttpPost] public async Task> GetSubjectImageDownloadSelectList(IRReadingDownloadQuery inQuery) { + var doctorUserId = _userInfo.Id; + + var isAnalysisCreate = false; + + //医学审核查看下载按钮,这个时候需要知道医生 + if (inQuery.VisitTaskId != null && inQuery.VisitTaskId != Guid.Empty) + { + var info = await _visitTaskRepository.Where(t => t.Id == inQuery.VisitTaskId).Select(t => new { t.DoctorUserId, t.IsAnalysisCreate }).FirstNotNullAsync(); + + doctorUserId = (Guid)info.DoctorUserId!; + isAnalysisCreate = info.IsAnalysisCreate; + } var query = _visitTaskRepository.Where(t => t.SubjectId == inQuery.SubjectId && t.TrialReadingCriterionId == inQuery.TrialReadingCriterionId - && t.SourceSubjectVisitId != null && t.DoctorUserId == _userInfo.Id && t.TaskState == TaskState.Effect) + && t.SourceSubjectVisitId != null && t.DoctorUserId == doctorUserId && t.TaskState == TaskState.Effect && t.IsAnalysisCreate == isAnalysisCreate) .ProjectTo(_mapper.ConfigurationProvider); @@ -816,10 +828,14 @@ namespace IRaCIS.Core.Application.Service.ImageAndDoc var isQueryDicom = inQuery.DicomStudyIdList.Count > 0; var isQueryNoneDicom = inQuery.NoneDicomStudyIdList.Count > 0; + var taskIdList = inQuery.SubjectVisitTaskList.Select(t => t.TaskId).ToList(); + var subjectVisitIdList = inQuery.SubjectVisitTaskList.Select(t => t.SubjectVisitId).ToList(); var query = from sv in _subjectRepository.Where(t => t.Id == inQuery.SubjectId).SelectMany(t => t.SubjectVisitList.Where(t => subjectVisitIdList.Contains(t.Id))) - join visitTask in _visitTaskRepository.Where(t => t.TaskState == TaskState.Effect && t.DoctorUserId == _userInfo.Id && t.TrialReadingCriterionId == inQuery.TrialReadingCriterionId) + //一致性分析,导致查询出来两条数据 + join visitTask in _visitTaskRepository.Where(t => taskIdList.Contains(t.Id)) + on sv.Id equals visitTask.SourceSubjectVisitId select new { diff --git a/IRaCIS.Core.Application/Service/Management/_MapConfig.cs b/IRaCIS.Core.Application/Service/Management/_MapConfig.cs index d9ec78199..afc1653ac 100644 --- a/IRaCIS.Core.Application/Service/Management/_MapConfig.cs +++ b/IRaCIS.Core.Application/Service/Management/_MapConfig.cs @@ -136,7 +136,8 @@ namespace IRaCIS.Core.Application.Service .ForMember(d => d.FeedBackUserName, c => c.MapFrom(t => t.CreateUser.UserName)) .ForMember(d => d.FeedBackFullName, c => c.MapFrom(t => t.CreateUser.FullName)) .ForMember(d => d.UserTypeEnum, c => c.MapFrom(t => t.CreateUser.UserTypeEnum)); - CreateMap().ReverseMap(); + + CreateMap().ReverseMap(); } } diff --git a/IRaCIS.Core.Application/Service/Reading/ReadingImageTask/ReadingNoDicomTaskService.cs b/IRaCIS.Core.Application/Service/Reading/ReadingImageTask/ReadingNoDicomTaskService.cs index 4f3a7c39d..0276b80f9 100644 --- a/IRaCIS.Core.Application/Service/Reading/ReadingImageTask/ReadingNoDicomTaskService.cs +++ b/IRaCIS.Core.Application/Service/Reading/ReadingImageTask/ReadingNoDicomTaskService.cs @@ -6,6 +6,7 @@ using Panda.DynamicWebApi.Attributes; using IRaCIS.Core.Application.Contracts; using MassTransit; using IRaCIS.Core.Application.Filter; +using IRaCIS.Core.Domain.Models; namespace IRaCIS.Application.Services { @@ -66,7 +67,7 @@ namespace IRaCIS.Application.Services /// /// [HttpPost] - public async Task> > GetReadingImageFile(GetReadingImgInDto inDto) + public async Task>> GetReadingImageFile(GetReadingImgInDto inDto) { var task = await GetNextTask(new GetNextTaskInDto() { @@ -84,10 +85,26 @@ namespace IRaCIS.Application.Services // 阅片期取前面所有的图像 visitIds.AddRange(await _subjectVisitRepository.Where(x => x.VisitNum <= task.VisitNum && x.SubjectId == task.SubjectId).Select(x => x.Id).ToListAsync()); } - List result = await _noneDicomStudyRepository.Where(t => visitIds.Contains(t.SubjectVisitId) && t.NoneDicomFileList.Any(t=>!t.FileType.Contains(StaticData.FileType.Zip))) - .ProjectTo(_mapper.ConfigurationProvider, new { isFilterZip = true }).ToListAsync(); - var taskinfo = await _visitTaskRepository.Where(x => x.Id == inDto.VisistTaskId).FirstNotNullAsync(); + var taskinfo = await _visitTaskRepository.Where(x => x.Id == inDto.VisistTaskId).Select(t => new { t.BlindSubjectCode, t.TrialReadingCriterionId, t.TrialReadingCriterion.IsImageFilter, t.TrialReadingCriterion.CriterionModalitys }).FirstNotNullAsync(); + + + IQueryable noneDicomStudyQueryable = default; + if (inDto.VisistTaskId == null) + { + noneDicomStudyQueryable = _noneDicomStudyRepository + .Where(t => visitIds.Contains(t.SubjectVisitId) && t.NoneDicomFileList.Any(t => !t.FileType.Contains(StaticData.FileType.Zip))) + .WhereIf(taskinfo.IsImageFilter == true, t => taskinfo.CriterionModalitys.Contains(t.Modality)) + .ProjectTo(_mapper.ConfigurationProvider, new { isFilterZip = true }); + } + else + { + noneDicomStudyQueryable = _noneDicomStudyRepository.Where(t => t.TaskNoneDicomFileList.Any(t => t.VisitTaskId == inDto.VisistTaskId)) + .Where(t => visitIds.Contains(t.SubjectVisitId)) + .ProjectTo(_mapper.ConfigurationProvider, new { isFilterZip = true, visiTaskId = inDto.VisistTaskId }); + } + List result = await noneDicomStudyQueryable.ToListAsync(); + var trialInfo = await _trialRepository.Where(x => x.Id == inDto.TrialId).Select(x => new { @@ -121,7 +138,7 @@ namespace IRaCIS.Application.Services var taskInfo = await _visitTaskRepository.Where(x => x.Id == task.VisitTaskId).FirstNotNullAsync(); - return ResponseOutput.Ok (result, new + return ResponseOutput.Ok(result, new { VisitTaskId = task.VisitTaskId, SubjectId = task.SubjectId, diff --git a/IRaCIS.Core.Application/Service/Reading/ReadingPeriod/ReadModuleService.cs b/IRaCIS.Core.Application/Service/Reading/ReadingPeriod/ReadModuleService.cs index ddcc65d0b..a37441d60 100644 --- a/IRaCIS.Core.Application/Service/Reading/ReadingPeriod/ReadModuleService.cs +++ b/IRaCIS.Core.Application/Service/Reading/ReadingPeriod/ReadModuleService.cs @@ -654,7 +654,7 @@ namespace IRaCIS.Application.Services var query = subjectVisitQuery.Union(readMouduleQuery) - .WhereIf(inQuery.SubjectId != null, x => x.Id == inQuery.SubjectId) + .WhereIf(inQuery.SubjectId != null, x => x.SubjectId == inQuery.SubjectId) .WhereIf(!string.IsNullOrWhiteSpace(inQuery.TrialSiteCode), x => x.TrialSiteCode.Contains(inQuery.TrialSiteCode)) .WhereIf(!string.IsNullOrWhiteSpace(inQuery.SubjectCode), x => x.SubjectCode.Contains(inQuery.SubjectCode)) .WhereIf(isFilterModuleType, t => t.ModuleType == inQuery.ModuleType) diff --git a/IRaCIS.Core.Application/Service/TrialSiteUser/TrialMaintenanceService.cs b/IRaCIS.Core.Application/Service/TrialSiteUser/TrialMaintenanceService.cs index 0198b9589..57f4ad08c 100644 --- a/IRaCIS.Core.Application/Service/TrialSiteUser/TrialMaintenanceService.cs +++ b/IRaCIS.Core.Application/Service/TrialSiteUser/TrialMaintenanceService.cs @@ -67,7 +67,7 @@ namespace IRaCIS.Application.Services .WhereIf(inQuery.UserTypeId != null, t => t.User.UserTypeId == inQuery.UserTypeId) .WhereIf(!string.IsNullOrWhiteSpace(inQuery.UserRealName), t => (t.User.FullName).Contains(inQuery.UserRealName)) .WhereIf(!string.IsNullOrWhiteSpace(inQuery.OrganizationName), t => t.User.OrganizationName.Contains(inQuery.OrganizationName)) - .ProjectTo(_mapper.ConfigurationProvider, new { trialSiteId = inQuery.TrialSiteId }); + .ProjectTo(_mapper.ConfigurationProvider); return await query.ToPagedListAsync(inQuery); diff --git a/IRaCIS.Core.Application/Service/TrialSiteUser/_MapConfig.cs b/IRaCIS.Core.Application/Service/TrialSiteUser/_MapConfig.cs index 543e702de..ed572a3c3 100644 --- a/IRaCIS.Core.Application/Service/TrialSiteUser/_MapConfig.cs +++ b/IRaCIS.Core.Application/Service/TrialSiteUser/_MapConfig.cs @@ -98,7 +98,7 @@ namespace IRaCIS.Core.Application.Service .ForMember(d => d.UserRealName, u => u.MapFrom(s => s.User.FullName)) .ForMember(d => d.TrialSiteId, u => u.MapFrom(t => trialSiteId)) .ForMember(d => d.UserType, u => u.MapFrom(t => t.User.UserTypeRole.UserTypeShortName)) - .ForMember(d => d.IsSelect, u => u.MapFrom(t => t.SiteList.Any(k => k.TrialSiteId == trialSiteId))); + .ForMember(d => d.IsSelect, u => u.MapFrom(t => t.Trial.TrialSiteUserList.Any(k => k.UserId == t.UserId))); CreateMap(); var trialId = Guid.Empty; diff --git a/IRaCIS.Core.Application/Service/Visit/DTO/VisitPointViewModel.cs b/IRaCIS.Core.Application/Service/Visit/DTO/VisitPointViewModel.cs index 31e34b7b0..af0413301 100644 --- a/IRaCIS.Core.Application/Service/Visit/DTO/VisitPointViewModel.cs +++ b/IRaCIS.Core.Application/Service/Visit/DTO/VisitPointViewModel.cs @@ -186,8 +186,11 @@ namespace IRaCIS.Core.Application.Contracts public class GetReadingVisitStudyListIndto { + [NotDefault] public Guid TrialId { get; set; } + [NotDefault] public Guid SujectVisitId { get; set; } + [NotDefault] public Guid VisitTaskId { get; set; } } diff --git a/IRaCIS.Core.Application/Service/Visit/SubjectVisitService.cs b/IRaCIS.Core.Application/Service/Visit/SubjectVisitService.cs index 1a0b415f2..ee4383ff0 100644 --- a/IRaCIS.Core.Application/Service/Visit/SubjectVisitService.cs +++ b/IRaCIS.Core.Application/Service/Visit/SubjectVisitService.cs @@ -37,7 +37,7 @@ namespace IRaCIS.Core.Application.Services IRepository _trialReadingCriterionRepository ) : BaseService, ISubjectVisitService { - + [HttpPost] [TypeFilter(typeof(TrialResourceFilter), Arguments = new object[] { "AfterStopCannNotOpt" })] @@ -541,7 +541,7 @@ namespace IRaCIS.Core.Application.Services SeriesId = x.SeriesId, StudyId = x.StudyId, InstanceId = x.InstanceId, - NumberOfFrames=x.NumberOfFrames, + NumberOfFrames = x.NumberOfFrames, }).ToListAsync(); @@ -594,20 +594,20 @@ namespace IRaCIS.Core.Application.Services HtmlPath = k.HtmlPath, Path = k.Path, InstanceNumber = k.InstanceNumber, - StudyId= k.StudyId, - SeriesId= k.SeriesId, + StudyId = k.StudyId, + SeriesId = k.SeriesId, }).ToListAsync(); item.InstanceInfoList.ForEach(x => { - var keyFramesList = rowInfoList.Where(y => y.InstanceId == x.Id&&y.NumberOfFrames!=0).Select(y => y.NumberOfFrames).Distinct().ToList(); + var keyFramesList = rowInfoList.Where(y => y.InstanceId == x.Id && y.NumberOfFrames != 0).Select(y => y.NumberOfFrames).Distinct().ToList(); if (keyFramesList.Count() > 0) { x.KeyFramesList = keyFramesList; } - + var item = rowInfoList.FirstOrDefault(y => y.InstanceId == x.Id); if (item != null) { @@ -632,7 +632,7 @@ namespace IRaCIS.Core.Application.Services - studyList.Insert(0,thisVisitTaskStudy); + studyList.Insert(0, thisVisitTaskStudy); } @@ -658,7 +658,7 @@ namespace IRaCIS.Core.Application.Services #region 非Dicom 检查查询 var noDicomList = await _noneDicomStudyRepository.Where(x => x.TrialId == indto.TrialId && x.SubjectVisitId == indto.SujectVisitId && x.NoneDicomFileList.Any(t => !t.FileType.Contains(StaticData.FileType.Zip))) - .WhereIf(taskInfo.IsImageFilter == true, t => taskInfo.CriterionModalitys.Contains(t.Modality) ).ToListAsync(); + .WhereIf(taskInfo.IsImageFilter == true, t => taskInfo.CriterionModalitys.Contains(t.Modality)).ToListAsync(); List noDicomStudyList = noDicomList.Select(x => new VisitStudyDTO() @@ -672,11 +672,14 @@ namespace IRaCIS.Core.Application.Services }).ToList(); + var isExistTaskNoneDicomFile = _noneDicomStudyFileRepository.Any(t => t.VisitTaskId == indto.VisitTaskId); + foreach (var item in noDicomStudyList) { var nodicom = noDicomList.Where(x => x.Id == item.StudyId).First(); - var instanceCount = await _noneDicomStudyFileRepository.Where(x => x.NoneDicomStudyId == item.StudyId).CountAsync(); + var instanceCount = await _noneDicomStudyFileRepository.WhereIf(isExistTaskNoneDicomFile,x=>x.OriginNoneDicomStudyId== item.StudyId) + .WhereIf(isExistTaskNoneDicomFile==false, x=>x.NoneDicomStudyId == item.StudyId).CountAsync(); if (instanceCount == 0) { @@ -697,7 +700,9 @@ namespace IRaCIS.Core.Application.Services SubjectVisitId=nodicom.SubjectVisitId, SubjectId=nodicom.SubjectId, SeriesNumber=1, - NoneDicomFileFirstFile=await _noneDicomStudyFileRepository.Where(x=>x.NoneDicomStudyId==item.StudyId && !x.FileType.Contains(StaticData.FileType.Zip)).Select(x=>x.Path).FirstOrDefaultAsync(), + NoneDicomFileFirstFile=await _noneDicomStudyFileRepository.WhereIf(isExistTaskNoneDicomFile,x=>x.OriginNoneDicomStudyId== item.StudyId) + .WhereIf(isExistTaskNoneDicomFile==false, x=>x.NoneDicomStudyId == item.StudyId) + .Where(x=> !x.FileType.Contains(StaticData.FileType.Zip)).Select(x=>x.Path).FirstOrDefaultAsync(), } }; 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/Management/UserFeedBack.cs b/IRaCIS.Core.Domain/Management/UserFeedBack.cs index f83a4e91b..d02c8c12e 100644 --- a/IRaCIS.Core.Domain/Management/UserFeedBack.cs +++ b/IRaCIS.Core.Domain/Management/UserFeedBack.cs @@ -33,7 +33,7 @@ namespace IRaCIS.Core.Domain.Models public VisitTask VisitTask { get; set; } [NotMapped] - public List ScreenshotList => JsonConvert.DeserializeObject>(ScreenshotListStr); + public List FeedBackScreenshotList => JsonConvert.DeserializeObject>(ScreenshotListStr); #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.Domain/TrialSiteUser/TrialSiteUser.cs b/IRaCIS.Core.Domain/TrialSiteUser/TrialSiteUser.cs index 4cdda8998..ad366265a 100644 --- a/IRaCIS.Core.Domain/TrialSiteUser/TrialSiteUser.cs +++ b/IRaCIS.Core.Domain/TrialSiteUser/TrialSiteUser.cs @@ -27,8 +27,7 @@ namespace IRaCIS.Core.Domain.Models [JsonIgnore] public TrialSite TrialSite { get; set; } - [JsonIgnore] - public TrialUser TrialUser { get; set; } + #endregion public Guid TrialSiteId { get; set; } diff --git a/IRaCIS.Core.Domain/TrialSiteUser/TrialUser.cs b/IRaCIS.Core.Domain/TrialSiteUser/TrialUser.cs index 5ac7e53d8..1e5c15a93 100644 --- a/IRaCIS.Core.Domain/TrialSiteUser/TrialUser.cs +++ b/IRaCIS.Core.Domain/TrialSiteUser/TrialUser.cs @@ -17,9 +17,6 @@ namespace IRaCIS.Core.Domain.Models [JsonIgnore] [ForeignKey("UserId")] public User User { get; set; } - - [JsonIgnore] - public List SiteList { get; set; } #endregion public Guid UserId { get; set; } public Guid TrialId { get; set; } diff --git a/IRaCIS.Core.Domain/Visit/SubjectVisit.cs b/IRaCIS.Core.Domain/Visit/SubjectVisit.cs index 44e477ee1..2e7a566fa 100644 --- a/IRaCIS.Core.Domain/Visit/SubjectVisit.cs +++ b/IRaCIS.Core.Domain/Visit/SubjectVisit.cs @@ -16,8 +16,6 @@ namespace IRaCIS.Core.Domain.Models [JsonIgnore] public TrialSite TrialSite { get; set; } - [JsonIgnore] - public VisitStage VisitStage { get; set; } [JsonIgnore] [ForeignKey("OutPlanPreviousVisitId")] public SubjectVisit OutPlanPreviousVisit { get; set; } diff --git a/IRaCIS.Core.Infra.EFCore/EntityConfigration/DoctorConfigration.cs b/IRaCIS.Core.Infra.EFCore/EntityConfigration/DoctorConfigration.cs deleted file mode 100644 index a9011126a..000000000 --- a/IRaCIS.Core.Infra.EFCore/EntityConfigration/DoctorConfigration.cs +++ /dev/null @@ -1,33 +0,0 @@ -using IRaCIS.Core.Domain.Models; -using Microsoft.EntityFrameworkCore; -using Microsoft.EntityFrameworkCore.Metadata; -using Microsoft.EntityFrameworkCore.Metadata.Builders; -using System.Reflection.Emit; - - -namespace IRaCIS.Core.Infra.EFCore.EntityConfigration -{ - public class DoctorConfigration : IEntityTypeConfiguration - { - - - public void Configure(EntityTypeBuilder builder) - { - builder - .HasOne(dd => dd.Doctor) - .WithMany(p => p.DoctorDicRelationList) - .HasForeignKey(dd => dd.DoctorId); - - builder - .HasOne(dd => dd.Dictionary) - .WithMany(d => d.DoctorDicRelationList) - .HasForeignKey(dd => dd.DictionaryId); - } - - - } - - - - -} diff --git a/IRaCIS.Core.Infra.EFCore/EntityConfigration/NoneDicomStudyConfigration.cs b/IRaCIS.Core.Infra.EFCore/EntityConfigration/NoneDicomStudyConfigration.cs deleted file mode 100644 index a2a0f9ce9..000000000 --- a/IRaCIS.Core.Infra.EFCore/EntityConfigration/NoneDicomStudyConfigration.cs +++ /dev/null @@ -1,20 +0,0 @@ -using IRaCIS.Core.Domain.Models; -using Microsoft.EntityFrameworkCore; -using Microsoft.EntityFrameworkCore.Metadata.Builders; -using System.Reflection.Emit; - - -namespace IRaCIS.Core.Infra.EFCore.EntityConfigration -{ - public class NoneDicomStudyConfigration : IEntityTypeConfiguration - { - - - public void Configure(EntityTypeBuilder builder) - { - - builder.HasMany(t => t.NoneDicomFileList).WithOne(s => s.NoneDicomStudy).HasForeignKey(t => t.NoneDicomStudyId); - builder.HasMany(t => t.TaskNoneDicomFileList).WithOne(s => s.OriginNoneDicomStudy).HasForeignKey(t => t.OriginNoneDicomStudyId); - } - } -} diff --git a/IRaCIS.Core.Infra.EFCore/EntityConfigration/ReadModuleConfigration.cs b/IRaCIS.Core.Infra.EFCore/EntityConfigration/ReadModuleConfigration.cs deleted file mode 100644 index 5d7c8d501..000000000 --- a/IRaCIS.Core.Infra.EFCore/EntityConfigration/ReadModuleConfigration.cs +++ /dev/null @@ -1,18 +0,0 @@ -using IRaCIS.Core.Domain.Models; -using Microsoft.EntityFrameworkCore; -using Microsoft.EntityFrameworkCore.Metadata.Builders; - - -namespace IRaCIS.Core.Infra.EFCore.EntityConfigration -{ - public class ReadModuleConfigration : IEntityTypeConfiguration - { - - - public void Configure(EntityTypeBuilder builder) - { - - builder.HasOne(t => t.SubjectVisit).WithMany(t => t.ReadModuleList); - } - } -} diff --git a/IRaCIS.Core.Infra.EFCore/EntityConfigration/ReadingQuestionTrialConfigration.cs b/IRaCIS.Core.Infra.EFCore/EntityConfigration/ReadingQuestionTrialConfigration.cs deleted file mode 100644 index 85d875028..000000000 --- a/IRaCIS.Core.Infra.EFCore/EntityConfigration/ReadingQuestionTrialConfigration.cs +++ /dev/null @@ -1,25 +0,0 @@ -using IRaCIS.Core.Domain.Models; -using Microsoft.EntityFrameworkCore.Metadata.Builders; -using Microsoft.EntityFrameworkCore; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace IRaCIS.Core.Infra.EFCore.EntityConfigration -{ - - public class ReadingQuestionTrialConfigration : IEntityTypeConfiguration - { - - - public void Configure(EntityTypeBuilder builder) - { - - - builder.HasQueryFilter(p => p.IsAdditional == false); - - } - } -} diff --git a/IRaCIS.Core.Infra.EFCore/EntityConfigration/StudyConfigration.cs b/IRaCIS.Core.Infra.EFCore/EntityConfigration/StudyConfigration.cs index c1b0133e8..5fa1e61c3 100644 --- a/IRaCIS.Core.Infra.EFCore/EntityConfigration/StudyConfigration.cs +++ b/IRaCIS.Core.Infra.EFCore/EntityConfigration/StudyConfigration.cs @@ -5,27 +5,38 @@ using Microsoft.EntityFrameworkCore.Metadata.Builders; namespace IRaCIS.Core.Infra.EFCore.EntityConfigration { - public class StudyConfigration : IEntityTypeConfiguration - { - + //public class StudyConfigration : IEntityTypeConfiguration + //{ - public void Configure(EntityTypeBuilder builder) - { - + // /// + // /// 一个外键,关联多个表 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.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 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/SubjectConfigration.cs b/IRaCIS.Core.Infra.EFCore/EntityConfigration/SubjectConfigration.cs index 239c349da..1fb1584fd 100644 --- a/IRaCIS.Core.Infra.EFCore/EntityConfigration/SubjectConfigration.cs +++ b/IRaCIS.Core.Infra.EFCore/EntityConfigration/SubjectConfigration.cs @@ -6,16 +6,44 @@ using Microsoft.EntityFrameworkCore.Metadata.Builders; namespace IRaCIS.Core.Infra.EFCore.EntityConfigration { public class SubjectConfigration : IEntityTypeConfiguration - { - - + { public void Configure(EntityTypeBuilder builder) { //不能同时配置一对多 和一对一 但是有时表要存储多的最新的 比如受试者 最新的访视 在这里要显示配置 - builder.HasOne(s => s.LatestSubjectVisit); - builder.HasOne(s => s.FinalSubjectVisit); - builder.HasMany(s => s.SubjectVisitList).WithOne(sv => sv.Subject); + builder.HasOne(s => s.LatestSubjectVisit).WithMany().HasForeignKey(t => t.LatestSubjectVisitId); + builder.HasOne(s => s.FinalSubjectVisit).WithMany().HasForeignKey(t => t.FinalSubjectVisitId); + builder.HasMany(s => s.SubjectVisitList).WithOne(sv => sv.Subject).HasForeignKey(t => t.SubjectId); + } + } + public class DictionaryConfigration : IEntityTypeConfiguration + { + public void Configure(EntityTypeBuilder builder) + { + + //自身同时存在一对多 和一对一的关系,配置一对多的就可以,一对一 不用配置,有点奇怪 + builder.HasMany(t => t.ChildList).WithOne(t => t.Parent).HasForeignKey(d => d.ParentId); + + } + } + + public class NoneDicomStudyConfigration : IEntityTypeConfiguration + { + public void Configure(EntityTypeBuilder builder) + { + //同样一个实体 有两个相同的类型的导航属性,需要手动配置 + builder.HasMany(t => t.NoneDicomFileList).WithOne(s => s.NoneDicomStudy).HasForeignKey(t => t.NoneDicomStudyId); + builder.HasMany(t => t.TaskNoneDicomFileList).WithOne(s => s.OriginNoneDicomStudy).HasForeignKey(t => t.OriginNoneDicomStudyId); + } + } + + public class SubjectUserConfigration : IEntityTypeConfiguration + { + public void Configure(EntityTypeBuilder builder) + { + //自身存在一对多的关系 + //对于替换后的医生而言,关联多个之前的医生 + builder.HasMany(t => t.EarlierSubjectUserList).WithOne(t => t.ReplacedSubjectUser).HasForeignKey(t => t.ReplacedSubjectUserId); } } } diff --git a/IRaCIS.Core.Infra.EFCore/EntityConfigration/SubjectVisitConfigration.cs b/IRaCIS.Core.Infra.EFCore/EntityConfigration/SubjectVisitConfigration.cs deleted file mode 100644 index d916b4ee1..000000000 --- a/IRaCIS.Core.Infra.EFCore/EntityConfigration/SubjectVisitConfigration.cs +++ /dev/null @@ -1,16 +0,0 @@ -using IRaCIS.Core.Domain.Models; -using Microsoft.EntityFrameworkCore; -using Microsoft.EntityFrameworkCore.Metadata.Builders; - - -namespace IRaCIS.Core.Infra.EFCore.EntityConfigration -{ - public class SubjectVisitConfigration : IEntityTypeConfiguration - { - public void Configure(EntityTypeBuilder builder) - { - - builder.HasOne(s => s.Subject).WithMany(sv => sv.SubjectVisitList); - } - } -} diff --git a/IRaCIS.Core.Infra.EFCore/EntityConfigration/TrialSiteConfigration.cs b/IRaCIS.Core.Infra.EFCore/EntityConfigration/TrialSiteConfigration.cs deleted file mode 100644 index a9173db0a..000000000 --- a/IRaCIS.Core.Infra.EFCore/EntityConfigration/TrialSiteConfigration.cs +++ /dev/null @@ -1,25 +0,0 @@ -using IRaCIS.Core.Domain.Models; -using Microsoft.EntityFrameworkCore; -using Microsoft.EntityFrameworkCore.Metadata.Builders; - - -namespace IRaCIS.Core.Infra.EFCore.EntityConfigration -{ - - public class SubjectCriteriaEvaluationConfigration : IEntityTypeConfiguration - { - - - public void Configure(EntityTypeBuilder builder) - { - builder - .HasMany(s => s.SubjectCriteriaEvaluationVisitFilterList) - .WithOne(c => c.SubjectCriteriaEvaluation) - .HasForeignKey(s => new { s.SubjectId, s.TrialReadingCriterionId }) - .HasPrincipalKey(c => new { c.SubjectId, c.TrialReadingCriterionId }); - - } - } - - -} diff --git a/IRaCIS.Core.Infra.EFCore/EntityConfigration/TrialUserConfigration.cs b/IRaCIS.Core.Infra.EFCore/EntityConfigration/TrialUserConfigration.cs index ffc7a2ba8..c4f782f0c 100644 --- a/IRaCIS.Core.Infra.EFCore/EntityConfigration/TrialUserConfigration.cs +++ b/IRaCIS.Core.Infra.EFCore/EntityConfigration/TrialUserConfigration.cs @@ -6,29 +6,20 @@ namespace IRaCIS.Core.Infra.EFCore.EntityConfigration { - public class TrialUserConfigration : IEntityTypeConfiguration + + public class SubjectCriteriaEvaluationConfigration : IEntityTypeConfiguration { - - public void Configure(EntityTypeBuilder builder) + public void Configure(EntityTypeBuilder builder) { builder - .HasMany(s => s.SiteList) - .WithOne(c => c.TrialUser) - .HasForeignKey(s => new { s.TrialId, s.UserId }) - .HasPrincipalKey(c => new { c.TrialId, c.UserId }); + .HasMany(s => s.SubjectCriteriaEvaluationVisitFilterList) + .WithOne(c => c.SubjectCriteriaEvaluation) + .HasForeignKey(s => new { s.SubjectId, s.TrialReadingCriterionId }) + .HasPrincipalKey(c => new { c.SubjectId, c.TrialReadingCriterionId }); } } - 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 6cf3de657..0e15a0649 100644 --- a/IRaCIS.Core.Infra.EFCore/EntityConfigration/VisitTaskConfigration.cs +++ b/IRaCIS.Core.Infra.EFCore/EntityConfigration/VisitTaskConfigration.cs @@ -12,46 +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); - - //modelBuilder.Entity().HasMany(t => t.DoctorTrialVisitTaskList).WithOne(t => t.DoctorTaskMedicalReviewRule).HasForeignKey(t => new { t.DoctorUserId, t.TrialId }).HasPrincipalKey(u => new { u.DoctorUserId, u.TrialId }); - - //modelBuilder.Entity().HasMany(t => t.TaskMedicalReviewList).WithOne(t => t.TaskMedicalReviewRule).HasForeignKey(t => new { t.DoctorUserId, t.TrialId }).HasPrincipalKey(u => new { u.DoctorUserId, u.TrialId }); - - //会导致级联删除 - //modelBuilder.Entity().HasMany(t => t.SubjectArmVisitTaskList).WithOne(t => t.SujectArm).HasForeignKey(t => new { t.SubjectId, t.ArmEnum }).HasPrincipalKey(u => new { u.SubjectId, u.ArmEnum }) - // ./*IsRequired(false)*/OnDelete(DeleteBehavior.NoAction); - - // builder.HasOne(t => t.SujectArm).WithMany(s => s.SubjectArmVisitTaskList).HasForeignKey(t => new { t.SubjectId, t.ArmEnum }).HasPrincipalKey(u => new { u.SubjectId, u.ArmEnum }); - - + //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 SubjectUserConfigration : IEntityTypeConfiguration + public class ReadingQuestionTrialConfigration : IEntityTypeConfiguration { - public void Configure(EntityTypeBuilder builder) + public void Configure(EntityTypeBuilder builder) { - builder.HasMany(t => t.EarlierSubjectUserList).WithOne(t => t.OrignalSubjectUser); + //不影响之前的逻辑,附加评估 + builder.HasQueryFilter(p => p.IsAdditional == false); + } } - - } diff --git a/IRaCIS.Core.Test/CodeFirstTest/CodeFirst使用说明 b/IRaCIS.Core.Test/CodeFirstTest/CodeFirst使用说明 index 33b575bf1..78ded9bf4 100644 --- a/IRaCIS.Core.Test/CodeFirstTest/CodeFirst使用说明 +++ b/IRaCIS.Core.Test/CodeFirstTest/CodeFirst使用说明 @@ -2,13 +2,22 @@ #οѧϰĵ https://www.cnblogs.com/cqpanda/p/16815263.html -# ָĿƣҪĿĿ¼ һpwershellĿĿ¼ҪָĿ - cd .\IRaCIS.Core.Test - - # Ŀ¼жģҪֶָ # dotnet ef migrations add ǩ -p Ŀ -c -o ǨļĿ¼ + 1Ǩļ dotnet ef migrations add Initial -p IRaCIS.Core.Test -c IRCContext -o CodeFirstTest/MSSQL/Migrations - dotnet ef database update -p IRaCIS.Core.Test -c IRCContext \ No newline at end of file + 2ղɵǨļ + dotnet ef migrations remove -p IRaCIS.Core.Test -c IRCContext + + 3Ǩļµݿ + 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.Infra.EFCore/EntityConfigration/DictionaryConfigration.cs b/IRaCIS.Core.Test/CodeFirstTest/MSSQL/EntityConfigration/DictionaryConfigration.cs similarity index 85% rename from IRaCIS.Core.Infra.EFCore/EntityConfigration/DictionaryConfigration.cs rename to IRaCIS.Core.Test/CodeFirstTest/MSSQL/EntityConfigration/DictionaryConfigration.cs index 1326060fc..07ea337df 100644 --- a/IRaCIS.Core.Infra.EFCore/EntityConfigration/DictionaryConfigration.cs +++ b/IRaCIS.Core.Test/CodeFirstTest/MSSQL/EntityConfigration/DictionaryConfigration.cs @@ -7,7 +7,7 @@ using System.Linq; using System.Text; using System.Threading.Tasks; -namespace IRaCIS.Core.Infra.EFCore.EntityConfigration +namespace IRaCIS.Core.Test.CodeFirstTest.MSSQL { public class DictionaryConfigration : IEntityTypeConfiguration { @@ -17,7 +17,7 @@ namespace IRaCIS.Core.Infra.EFCore.EntityConfigration { - builder.HasMany(t => t.ChildList).WithOne(t => t.Parent); + builder.HasMany(t => t.ChildList).WithOne(t => t.Parent).HasForeignKey(d => d.ParentId); } } diff --git a/IRaCIS.Core.Test/CodeFirstTest/MSSQL/EntityConfigration/SubjectConfigration.cs b/IRaCIS.Core.Test/CodeFirstTest/MSSQL/EntityConfigration/SubjectConfigration.cs new file mode 100644 index 000000000..ff0800238 --- /dev/null +++ b/IRaCIS.Core.Test/CodeFirstTest/MSSQL/EntityConfigration/SubjectConfigration.cs @@ -0,0 +1,22 @@ +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Metadata.Builders; + + +namespace IRaCIS.Core.Test.CodeFirstTest.MSSQL +{ + public class SubjectConfigration : IEntityTypeConfiguration + { + + + public void Configure(EntityTypeBuilder builder) + { + + //不能同时配置一对多 和一对一 但是有时表要存储多的最新的 比如受试者 最新的访视 在这里要显示配置 + builder.HasOne(s => s.LatestSubjectVisit); + builder.HasOne(s => s.FinalSubjectVisit); + builder.HasMany(s => s.SubejectVisitList).WithOne(sv => sv.Subject); + } + } + + +} diff --git a/IRaCIS.Core.Test/CodeFirstTest/MSSQL/IRCContext.cs b/IRaCIS.Core.Test/CodeFirstTest/MSSQL/IRCContext.cs index 4f6220861..099056b6f 100644 --- a/IRaCIS.Core.Test/CodeFirstTest/MSSQL/IRCContext.cs +++ b/IRaCIS.Core.Test/CodeFirstTest/MSSQL/IRCContext.cs @@ -1,5 +1,7 @@ using System; using System.Collections.Generic; +using System.Linq; +using System.Reflection; using IRaCIS.Core.Test.CodeFirstTest.MSSQL; using Microsoft.EntityFrameworkCore; @@ -24,13 +26,23 @@ public partial class IRCContext : DbContext public virtual DbSet SubejectVisit { get; set; } + public virtual DbSet Dictionary { 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"); protected override void OnModelCreating(ModelBuilder modelBuilder) { + //遍历实体模型手动配置 + var typesToRegister = Assembly.GetExecutingAssembly().GetTypes().Where(q => q.GetInterface(typeof(IEntityTypeConfiguration<>).FullName) != null); + foreach (var type in typesToRegister) + { + dynamic configurationInstance = Activator.CreateInstance(type); + modelBuilder.ApplyConfiguration(configurationInstance); + } - OnModelCreatingPartial(modelBuilder); } diff --git a/IRaCIS.Core.Test/CodeFirstTest/MSSQL/Migrations/20240910073024_oneToManyAndOneToOne.Designer.cs b/IRaCIS.Core.Test/CodeFirstTest/MSSQL/Migrations/20240910073024_oneToManyAndOneToOne.Designer.cs new file mode 100644 index 000000000..20cdc133f --- /dev/null +++ b/IRaCIS.Core.Test/CodeFirstTest/MSSQL/Migrations/20240910073024_oneToManyAndOneToOne.Designer.cs @@ -0,0 +1,213 @@ +// +using System; +using IRaCIS.Core.Test.CodeFirstTest.MSSQL; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Metadata; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; + +#nullable disable + +namespace IRaCIS.Core.Test.CodeFirstTest.MSSQL.Migrations +{ + [DbContext(typeof(IRCContext))] + [Migration("20240910073024_oneToManyAndOneToOne")] + partial class oneToManyAndOneToOne + { + /// + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "8.0.8") + .HasAnnotation("Relational:MaxIdentifierLength", 128); + + SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder); + + modelBuilder.Entity("IRaCIS.Core.Test.CodeFirstTest.MSSQL.SubejectVisit", b => + { + b.Property("Id") + .HasColumnType("uniqueidentifier"); + + b.Property("CreateTime") + .HasColumnType("datetime2"); + + b.Property("CreateUserId") + .HasColumnType("uniqueidentifier"); + + b.Property("SubjectId") + .HasColumnType("uniqueidentifier"); + + b.Property("UpdateTime") + .HasColumnType("datetime2"); + + b.Property("UpdateUserId") + .HasColumnType("uniqueidentifier"); + + b.HasKey("Id"); + + b.HasIndex("SubjectId"); + + b.ToTable("SubejectVisit"); + }); + + modelBuilder.Entity("IRaCIS.Core.Test.CodeFirstTest.MSSQL.Subject", b => + { + b.Property("Id") + .HasColumnType("uniqueidentifier"); + + b.Property("CreateTime") + .HasColumnType("datetime2"); + + b.Property("CreateUserId") + .HasColumnType("uniqueidentifier"); + + b.Property("FinalSubjectVisitId") + .HasColumnType("uniqueidentifier"); + + b.Property("LatestSubjectVisitId") + .HasColumnType("uniqueidentifier"); + + b.Property("Name") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("UpdateTime") + .HasColumnType("datetime2"); + + b.Property("UpdateUserId") + .HasColumnType("uniqueidentifier"); + + b.HasKey("Id"); + + b.HasIndex("FinalSubjectVisitId"); + + b.HasIndex("LatestSubjectVisitId"); + + b.ToTable("Subject"); + }); + + modelBuilder.Entity("IRaCIS.Core.Test.CodeFirstTest.MSSQL.TestNew", b => + { + b.Property("Id") + .HasColumnType("uniqueidentifier"); + + b.Property("CreateTime") + .HasColumnType("datetime2"); + + b.Property("CreateUserId") + .HasColumnType("uniqueidentifier"); + + b.Property("TestName") + .IsRequired() + .HasMaxLength(100) + .HasColumnType("nvarchar(100)"); + + b.Property("TrialImageDownloadId") + .HasColumnType("uniqueidentifier"); + + b.Property("UpdateTime") + .HasColumnType("datetime2"); + + b.Property("UpdateUserId") + .HasColumnType("uniqueidentifier"); + + b.HasKey("Id"); + + b.HasIndex("TrialImageDownloadId"); + + b.ToTable("TestNew"); + }); + + modelBuilder.Entity("IRaCIS.Core.Test.CodeFirstTest.MSSQL.TrialImageDownload", b => + { + b.Property("Id") + .HasColumnType("uniqueidentifier"); + + b.Property("CreateTime") + .HasColumnType("datetime2"); + + b.Property("CreateUserId") + .HasColumnType("uniqueidentifier"); + + b.Property("DownloadEndTime") + .HasColumnType("datetime2"); + + b.Property("DownloadStartTime") + .HasColumnType("datetime2"); + + b.Property("ImageCount") + .HasColumnType("int"); + + b.Property("ImageSize") + .HasColumnType("bigint"); + + b.Property("ImageType") + .HasColumnType("int"); + + b.Property("IsSuccess") + .HasColumnType("bit"); + + b.Property("SubjectVisitId") + .HasColumnType("uniqueidentifier"); + + b.Property("UpdateTime") + .HasColumnType("datetime2"); + + b.Property("UpdateUserId") + .HasColumnType("uniqueidentifier"); + + b.HasKey("Id"); + + b.ToTable("TrialImageDownload"); + }); + + modelBuilder.Entity("IRaCIS.Core.Test.CodeFirstTest.MSSQL.SubejectVisit", b => + { + b.HasOne("IRaCIS.Core.Test.CodeFirstTest.MSSQL.Subject", "Subject") + .WithMany("SubejectVisitList") + .HasForeignKey("SubjectId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Subject"); + }); + + modelBuilder.Entity("IRaCIS.Core.Test.CodeFirstTest.MSSQL.Subject", b => + { + b.HasOne("IRaCIS.Core.Test.CodeFirstTest.MSSQL.SubejectVisit", "FinalSubjectVisit") + .WithMany() + .HasForeignKey("FinalSubjectVisitId"); + + b.HasOne("IRaCIS.Core.Test.CodeFirstTest.MSSQL.SubejectVisit", "LatestSubjectVisit") + .WithMany() + .HasForeignKey("LatestSubjectVisitId"); + + b.Navigation("FinalSubjectVisit"); + + b.Navigation("LatestSubjectVisit"); + }); + + modelBuilder.Entity("IRaCIS.Core.Test.CodeFirstTest.MSSQL.TestNew", b => + { + b.HasOne("IRaCIS.Core.Test.CodeFirstTest.MSSQL.TrialImageDownload", null) + .WithMany("TestNewList") + .HasForeignKey("TrialImageDownloadId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("IRaCIS.Core.Test.CodeFirstTest.MSSQL.Subject", b => + { + b.Navigation("SubejectVisitList"); + }); + + modelBuilder.Entity("IRaCIS.Core.Test.CodeFirstTest.MSSQL.TrialImageDownload", b => + { + b.Navigation("TestNewList"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/IRaCIS.Core.Test/CodeFirstTest/MSSQL/Migrations/20240910073024_oneToManyAndOneToOne.cs b/IRaCIS.Core.Test/CodeFirstTest/MSSQL/Migrations/20240910073024_oneToManyAndOneToOne.cs new file mode 100644 index 000000000..3627f081b --- /dev/null +++ b/IRaCIS.Core.Test/CodeFirstTest/MSSQL/Migrations/20240910073024_oneToManyAndOneToOne.cs @@ -0,0 +1,96 @@ +using System; +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace IRaCIS.Core.Test.CodeFirstTest.MSSQL.Migrations +{ + /// + public partial class oneToManyAndOneToOne : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.CreateTable( + name: "SubejectVisit", + columns: table => new + { + Id = table.Column(type: "uniqueidentifier", nullable: false), + SubjectId = table.Column(type: "uniqueidentifier", nullable: false), + CreateUserId = table.Column(type: "uniqueidentifier", nullable: false), + CreateTime = table.Column(type: "datetime2", nullable: false), + UpdateUserId = table.Column(type: "uniqueidentifier", nullable: false), + UpdateTime = table.Column(type: "datetime2", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_SubejectVisit", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "Subject", + columns: table => new + { + Id = table.Column(type: "uniqueidentifier", nullable: false), + Name = table.Column(type: "nvarchar(max)", nullable: false), + LatestSubjectVisitId = table.Column(type: "uniqueidentifier", nullable: true), + FinalSubjectVisitId = table.Column(type: "uniqueidentifier", nullable: true), + CreateUserId = table.Column(type: "uniqueidentifier", nullable: false), + CreateTime = table.Column(type: "datetime2", nullable: false), + UpdateUserId = table.Column(type: "uniqueidentifier", nullable: false), + UpdateTime = table.Column(type: "datetime2", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Subject", x => x.Id); + table.ForeignKey( + name: "FK_Subject_SubejectVisit_FinalSubjectVisitId", + column: x => x.FinalSubjectVisitId, + principalTable: "SubejectVisit", + principalColumn: "Id"); + table.ForeignKey( + name: "FK_Subject_SubejectVisit_LatestSubjectVisitId", + column: x => x.LatestSubjectVisitId, + principalTable: "SubejectVisit", + principalColumn: "Id"); + }); + + migrationBuilder.CreateIndex( + name: "IX_SubejectVisit_SubjectId", + table: "SubejectVisit", + column: "SubjectId"); + + migrationBuilder.CreateIndex( + name: "IX_Subject_FinalSubjectVisitId", + table: "Subject", + column: "FinalSubjectVisitId"); + + migrationBuilder.CreateIndex( + name: "IX_Subject_LatestSubjectVisitId", + table: "Subject", + column: "LatestSubjectVisitId"); + + migrationBuilder.AddForeignKey( + name: "FK_SubejectVisit_Subject_SubjectId", + table: "SubejectVisit", + column: "SubjectId", + principalTable: "Subject", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropForeignKey( + name: "FK_SubejectVisit_Subject_SubjectId", + table: "SubejectVisit"); + + migrationBuilder.DropTable( + name: "Subject"); + + migrationBuilder.DropTable( + name: "SubejectVisit"); + } + } +} diff --git a/IRaCIS.Core.Test/CodeFirstTest/MSSQL/Migrations/20240910075136_seftOneToManyAndOneToOne.Designer.cs b/IRaCIS.Core.Test/CodeFirstTest/MSSQL/Migrations/20240910075136_seftOneToManyAndOneToOne.Designer.cs new file mode 100644 index 000000000..69d7b8786 --- /dev/null +++ b/IRaCIS.Core.Test/CodeFirstTest/MSSQL/Migrations/20240910075136_seftOneToManyAndOneToOne.Designer.cs @@ -0,0 +1,269 @@ +// +using System; +using IRaCIS.Core.Test.CodeFirstTest.MSSQL; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Metadata; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; + +#nullable disable + +namespace IRaCIS.Core.Test.CodeFirstTest.MSSQL.Migrations +{ + [DbContext(typeof(IRCContext))] + [Migration("20240910075136_seftOneToManyAndOneToOne")] + partial class seftOneToManyAndOneToOne + { + /// + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "8.0.8") + .HasAnnotation("Relational:MaxIdentifierLength", 128); + + SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder); + + modelBuilder.Entity("IRaCIS.Core.Test.CodeFirstTest.MSSQL.Dictionary", b => + { + b.Property("Id") + .HasColumnType("uniqueidentifier"); + + b.Property("Code") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("ConfigTypeId") + .HasColumnType("uniqueidentifier"); + + b.Property("CreateTime") + .HasColumnType("datetime2"); + + b.Property("CreateUserId") + .HasColumnType("uniqueidentifier"); + + b.Property("ParentId") + .HasColumnType("uniqueidentifier"); + + b.Property("UpdateTime") + .HasColumnType("datetime2"); + + b.Property("UpdateUserId") + .HasColumnType("uniqueidentifier"); + + b.HasKey("Id"); + + b.HasIndex("ConfigTypeId"); + + b.HasIndex("ParentId"); + + b.ToTable("Dictionary"); + }); + + modelBuilder.Entity("IRaCIS.Core.Test.CodeFirstTest.MSSQL.SubejectVisit", b => + { + b.Property("Id") + .HasColumnType("uniqueidentifier"); + + b.Property("CreateTime") + .HasColumnType("datetime2"); + + b.Property("CreateUserId") + .HasColumnType("uniqueidentifier"); + + b.Property("SubjectId") + .HasColumnType("uniqueidentifier"); + + b.Property("UpdateTime") + .HasColumnType("datetime2"); + + b.Property("UpdateUserId") + .HasColumnType("uniqueidentifier"); + + b.HasKey("Id"); + + b.HasIndex("SubjectId"); + + b.ToTable("SubejectVisit"); + }); + + modelBuilder.Entity("IRaCIS.Core.Test.CodeFirstTest.MSSQL.Subject", b => + { + b.Property("Id") + .HasColumnType("uniqueidentifier"); + + b.Property("CreateTime") + .HasColumnType("datetime2"); + + b.Property("CreateUserId") + .HasColumnType("uniqueidentifier"); + + b.Property("FinalSubjectVisitId") + .HasColumnType("uniqueidentifier"); + + b.Property("LatestSubjectVisitId") + .HasColumnType("uniqueidentifier"); + + b.Property("Name") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("UpdateTime") + .HasColumnType("datetime2"); + + b.Property("UpdateUserId") + .HasColumnType("uniqueidentifier"); + + b.HasKey("Id"); + + b.HasIndex("FinalSubjectVisitId"); + + b.HasIndex("LatestSubjectVisitId"); + + b.ToTable("Subject"); + }); + + modelBuilder.Entity("IRaCIS.Core.Test.CodeFirstTest.MSSQL.TestNew", b => + { + b.Property("Id") + .HasColumnType("uniqueidentifier"); + + b.Property("CreateTime") + .HasColumnType("datetime2"); + + b.Property("CreateUserId") + .HasColumnType("uniqueidentifier"); + + b.Property("TestName") + .IsRequired() + .HasMaxLength(100) + .HasColumnType("nvarchar(100)"); + + b.Property("TrialImageDownloadId") + .HasColumnType("uniqueidentifier"); + + b.Property("UpdateTime") + .HasColumnType("datetime2"); + + b.Property("UpdateUserId") + .HasColumnType("uniqueidentifier"); + + b.HasKey("Id"); + + b.HasIndex("TrialImageDownloadId"); + + b.ToTable("TestNew"); + }); + + modelBuilder.Entity("IRaCIS.Core.Test.CodeFirstTest.MSSQL.TrialImageDownload", b => + { + b.Property("Id") + .HasColumnType("uniqueidentifier"); + + b.Property("CreateTime") + .HasColumnType("datetime2"); + + b.Property("CreateUserId") + .HasColumnType("uniqueidentifier"); + + b.Property("DownloadEndTime") + .HasColumnType("datetime2"); + + b.Property("DownloadStartTime") + .HasColumnType("datetime2"); + + b.Property("ImageCount") + .HasColumnType("int"); + + b.Property("ImageSize") + .HasColumnType("bigint"); + + b.Property("ImageType") + .HasColumnType("int"); + + b.Property("IsSuccess") + .HasColumnType("bit"); + + b.Property("SubjectVisitId") + .HasColumnType("uniqueidentifier"); + + b.Property("UpdateTime") + .HasColumnType("datetime2"); + + b.Property("UpdateUserId") + .HasColumnType("uniqueidentifier"); + + b.HasKey("Id"); + + b.ToTable("TrialImageDownload"); + }); + + modelBuilder.Entity("IRaCIS.Core.Test.CodeFirstTest.MSSQL.Dictionary", b => + { + b.HasOne("IRaCIS.Core.Test.CodeFirstTest.MSSQL.Dictionary", "ConfigType") + .WithMany() + .HasForeignKey("ConfigTypeId"); + + b.HasOne("IRaCIS.Core.Test.CodeFirstTest.MSSQL.Dictionary", "Parent") + .WithMany("ChildList") + .HasForeignKey("ParentId"); + + b.Navigation("ConfigType"); + + b.Navigation("Parent"); + }); + + modelBuilder.Entity("IRaCIS.Core.Test.CodeFirstTest.MSSQL.SubejectVisit", b => + { + b.HasOne("IRaCIS.Core.Test.CodeFirstTest.MSSQL.Subject", "Subject") + .WithMany("SubejectVisitList") + .HasForeignKey("SubjectId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Subject"); + }); + + modelBuilder.Entity("IRaCIS.Core.Test.CodeFirstTest.MSSQL.Subject", b => + { + b.HasOne("IRaCIS.Core.Test.CodeFirstTest.MSSQL.SubejectVisit", "FinalSubjectVisit") + .WithMany() + .HasForeignKey("FinalSubjectVisitId"); + + b.HasOne("IRaCIS.Core.Test.CodeFirstTest.MSSQL.SubejectVisit", "LatestSubjectVisit") + .WithMany() + .HasForeignKey("LatestSubjectVisitId"); + + b.Navigation("FinalSubjectVisit"); + + b.Navigation("LatestSubjectVisit"); + }); + + modelBuilder.Entity("IRaCIS.Core.Test.CodeFirstTest.MSSQL.TestNew", b => + { + b.HasOne("IRaCIS.Core.Test.CodeFirstTest.MSSQL.TrialImageDownload", null) + .WithMany("TestNewList") + .HasForeignKey("TrialImageDownloadId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("IRaCIS.Core.Test.CodeFirstTest.MSSQL.Dictionary", b => + { + b.Navigation("ChildList"); + }); + + modelBuilder.Entity("IRaCIS.Core.Test.CodeFirstTest.MSSQL.Subject", b => + { + b.Navigation("SubejectVisitList"); + }); + + modelBuilder.Entity("IRaCIS.Core.Test.CodeFirstTest.MSSQL.TrialImageDownload", b => + { + b.Navigation("TestNewList"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/IRaCIS.Core.Test/CodeFirstTest/MSSQL/Migrations/20240910075136_seftOneToManyAndOneToOne.cs b/IRaCIS.Core.Test/CodeFirstTest/MSSQL/Migrations/20240910075136_seftOneToManyAndOneToOne.cs new file mode 100644 index 000000000..32920762b --- /dev/null +++ b/IRaCIS.Core.Test/CodeFirstTest/MSSQL/Migrations/20240910075136_seftOneToManyAndOneToOne.cs @@ -0,0 +1,60 @@ +using System; +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace IRaCIS.Core.Test.CodeFirstTest.MSSQL.Migrations +{ + /// + public partial class seftOneToManyAndOneToOne : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.CreateTable( + name: "Dictionary", + columns: table => new + { + Id = table.Column(type: "uniqueidentifier", nullable: false), + ParentId = table.Column(type: "uniqueidentifier", nullable: true), + ConfigTypeId = table.Column(type: "uniqueidentifier", nullable: true), + Code = table.Column(type: "nvarchar(max)", nullable: false), + CreateUserId = table.Column(type: "uniqueidentifier", nullable: false), + CreateTime = table.Column(type: "datetime2", nullable: false), + UpdateUserId = table.Column(type: "uniqueidentifier", nullable: false), + UpdateTime = table.Column(type: "datetime2", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Dictionary", x => x.Id); + table.ForeignKey( + name: "FK_Dictionary_Dictionary_ConfigTypeId", + column: x => x.ConfigTypeId, + principalTable: "Dictionary", + principalColumn: "Id"); + table.ForeignKey( + name: "FK_Dictionary_Dictionary_ParentId", + column: x => x.ParentId, + principalTable: "Dictionary", + principalColumn: "Id"); + }); + + migrationBuilder.CreateIndex( + name: "IX_Dictionary_ConfigTypeId", + table: "Dictionary", + column: "ConfigTypeId"); + + migrationBuilder.CreateIndex( + name: "IX_Dictionary_ParentId", + table: "Dictionary", + column: "ParentId"); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropTable( + name: "Dictionary"); + } + } +} diff --git a/IRaCIS.Core.Test/CodeFirstTest/MSSQL/Migrations/IRCContextModelSnapshot.cs b/IRaCIS.Core.Test/CodeFirstTest/MSSQL/Migrations/IRCContextModelSnapshot.cs index f87ae145d..ffb12bafa 100644 --- a/IRaCIS.Core.Test/CodeFirstTest/MSSQL/Migrations/IRCContextModelSnapshot.cs +++ b/IRaCIS.Core.Test/CodeFirstTest/MSSQL/Migrations/IRCContextModelSnapshot.cs @@ -22,6 +22,105 @@ namespace IRaCIS.Core.Test.CodeFirstTest.MSSQL.Migrations SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder); + modelBuilder.Entity("IRaCIS.Core.Test.CodeFirstTest.MSSQL.Dictionary", b => + { + b.Property("Id") + .HasColumnType("uniqueidentifier"); + + b.Property("Code") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("ConfigTypeId") + .HasColumnType("uniqueidentifier"); + + b.Property("CreateTime") + .HasColumnType("datetime2"); + + b.Property("CreateUserId") + .HasColumnType("uniqueidentifier"); + + b.Property("ParentId") + .HasColumnType("uniqueidentifier"); + + b.Property("UpdateTime") + .HasColumnType("datetime2"); + + b.Property("UpdateUserId") + .HasColumnType("uniqueidentifier"); + + b.HasKey("Id"); + + b.HasIndex("ConfigTypeId"); + + b.HasIndex("ParentId"); + + b.ToTable("Dictionary", (string)null); + }); + + modelBuilder.Entity("IRaCIS.Core.Test.CodeFirstTest.MSSQL.SubejectVisit", b => + { + b.Property("Id") + .HasColumnType("uniqueidentifier"); + + b.Property("CreateTime") + .HasColumnType("datetime2"); + + b.Property("CreateUserId") + .HasColumnType("uniqueidentifier"); + + b.Property("SubjectId") + .HasColumnType("uniqueidentifier"); + + b.Property("UpdateTime") + .HasColumnType("datetime2"); + + b.Property("UpdateUserId") + .HasColumnType("uniqueidentifier"); + + b.HasKey("Id"); + + b.HasIndex("SubjectId"); + + b.ToTable("SubejectVisit", (string)null); + }); + + modelBuilder.Entity("IRaCIS.Core.Test.CodeFirstTest.MSSQL.Subject", b => + { + b.Property("Id") + .HasColumnType("uniqueidentifier"); + + b.Property("CreateTime") + .HasColumnType("datetime2"); + + b.Property("CreateUserId") + .HasColumnType("uniqueidentifier"); + + b.Property("FinalSubjectVisitId") + .HasColumnType("uniqueidentifier"); + + b.Property("LatestSubjectVisitId") + .HasColumnType("uniqueidentifier"); + + b.Property("Name") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("UpdateTime") + .HasColumnType("datetime2"); + + b.Property("UpdateUserId") + .HasColumnType("uniqueidentifier"); + + b.HasKey("Id"); + + b.HasIndex("FinalSubjectVisitId"); + + b.HasIndex("LatestSubjectVisitId"); + + b.ToTable("Subject", (string)null); + }); + modelBuilder.Entity("IRaCIS.Core.Test.CodeFirstTest.MSSQL.TestNew", b => { b.Property("Id") @@ -51,7 +150,7 @@ namespace IRaCIS.Core.Test.CodeFirstTest.MSSQL.Migrations b.HasIndex("TrialImageDownloadId"); - b.ToTable("TestNew"); + b.ToTable("TestNew", (string)null); }); modelBuilder.Entity("IRaCIS.Core.Test.CodeFirstTest.MSSQL.TrialImageDownload", b => @@ -94,7 +193,48 @@ namespace IRaCIS.Core.Test.CodeFirstTest.MSSQL.Migrations b.HasKey("Id"); - b.ToTable("TrialImageDownload"); + b.ToTable("TrialImageDownload", (string)null); + }); + + modelBuilder.Entity("IRaCIS.Core.Test.CodeFirstTest.MSSQL.Dictionary", b => + { + b.HasOne("IRaCIS.Core.Test.CodeFirstTest.MSSQL.Dictionary", "ConfigType") + .WithMany() + .HasForeignKey("ConfigTypeId"); + + b.HasOne("IRaCIS.Core.Test.CodeFirstTest.MSSQL.Dictionary", "Parent") + .WithMany("ChildList") + .HasForeignKey("ParentId"); + + b.Navigation("ConfigType"); + + b.Navigation("Parent"); + }); + + modelBuilder.Entity("IRaCIS.Core.Test.CodeFirstTest.MSSQL.SubejectVisit", b => + { + b.HasOne("IRaCIS.Core.Test.CodeFirstTest.MSSQL.Subject", "Subject") + .WithMany("SubejectVisitList") + .HasForeignKey("SubjectId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Subject"); + }); + + modelBuilder.Entity("IRaCIS.Core.Test.CodeFirstTest.MSSQL.Subject", b => + { + b.HasOne("IRaCIS.Core.Test.CodeFirstTest.MSSQL.SubejectVisit", "FinalSubjectVisit") + .WithMany() + .HasForeignKey("FinalSubjectVisitId"); + + b.HasOne("IRaCIS.Core.Test.CodeFirstTest.MSSQL.SubejectVisit", "LatestSubjectVisit") + .WithMany() + .HasForeignKey("LatestSubjectVisitId"); + + b.Navigation("FinalSubjectVisit"); + + b.Navigation("LatestSubjectVisit"); }); modelBuilder.Entity("IRaCIS.Core.Test.CodeFirstTest.MSSQL.TestNew", b => @@ -106,6 +246,16 @@ namespace IRaCIS.Core.Test.CodeFirstTest.MSSQL.Migrations .IsRequired(); }); + modelBuilder.Entity("IRaCIS.Core.Test.CodeFirstTest.MSSQL.Dictionary", b => + { + b.Navigation("ChildList"); + }); + + modelBuilder.Entity("IRaCIS.Core.Test.CodeFirstTest.MSSQL.Subject", b => + { + b.Navigation("SubejectVisitList"); + }); + modelBuilder.Entity("IRaCIS.Core.Test.CodeFirstTest.MSSQL.TrialImageDownload", b => { b.Navigation("TestNewList"); diff --git a/IRaCIS.Core.Test/CodeFirstTest/MSSQL/TrialImageDownload.cs b/IRaCIS.Core.Test/CodeFirstTest/MSSQL/TrialImageDownload.cs index 06119c778..02eee8fe9 100644 --- a/IRaCIS.Core.Test/CodeFirstTest/MSSQL/TrialImageDownload.cs +++ b/IRaCIS.Core.Test/CodeFirstTest/MSSQL/TrialImageDownload.cs @@ -1,4 +1,5 @@ using IRaCIS.Core.Domain.Models; +using IRaCIS.Core.Domain.Share; using System; using System.Collections.Generic; using System.ComponentModel.DataAnnotations; @@ -48,7 +49,7 @@ namespace IRaCIS.Core.Test.CodeFirstTest.MSSQL } - public class Subject: BaseFullAuditEntity + public class Subject : BaseFullAuditEntity { public string Name { get; set; } @@ -59,8 +60,10 @@ namespace IRaCIS.Core.Test.CodeFirstTest.MSSQL #region 同时配置一对多,一对一 导航属性 + [ForeignKey("FinalSubjectVisitId")] public SubejectVisit FinalSubjectVisit { get; set; } + [ForeignKey("LatestSubjectVisitId")] public SubejectVisit LatestSubjectVisit { get; set; } public List SubejectVisitList { get; set; } @@ -68,11 +71,61 @@ namespace IRaCIS.Core.Test.CodeFirstTest.MSSQL } - public class SubejectVisit: BaseFullAuditEntity + public class SubejectVisit : BaseFullAuditEntity { public Subject Subject { get; set; } - + public Guid SubjectId { get; set; } } + + + public class Dictionary : BaseFullAuditEntity + { + #region 导航属性 + [ForeignKey("ConfigTypeId")] + public Dictionary ConfigType { get; set; } + + [ForeignKey("ParentId")] + public Dictionary Parent { get; set; } + + public List ChildList { get; set; } = new List(); + + #endregion + + + public Guid? ParentId { get; set; } + + + public Guid? ConfigTypeId { get; set; } + + public string Code { get; set; } + } + + #region 一个外键 关联两个实体 + public class ReadingClinicalData : BaseFullAuditEntity + { + public string Code { get; set; } + + + public Guid ReadingId { get; set; } + + + [ForeignKey("ReadingId")] + + public SubejectVisit SubjectVisit { get; set; } + + [ForeignKey("ReadingId")] + + public ReadModule ReadModule { get; set; } + } + + public class ReadModule : BaseFullAuditEntity + { + public string Name { get; set; } + } + #endregion + + + } diff --git a/IRaCIS.Core.Test/IRaCIS.Core.Test.csproj b/IRaCIS.Core.Test/IRaCIS.Core.Test.csproj index 77dd99306..9d1a28e03 100644 --- a/IRaCIS.Core.Test/IRaCIS.Core.Test.csproj +++ b/IRaCIS.Core.Test/IRaCIS.Core.Test.csproj @@ -1,8 +1,4 @@  - - utf-8 - utf-8 - enable