499 lines
23 KiB
C#
499 lines
23 KiB
C#
//using System;
|
||
//using Castle.DynamicProxy;
|
||
//using IRaCIS.Core.Application.Contracts.Dicom.DTO;
|
||
//using IRaCIS.Core.Infra.EFCore;
|
||
|
||
//using System.Linq;
|
||
//using IRaCIS.Core.Domain.Models;
|
||
//using IRaCIS.Core.Domain.Share;
|
||
|
||
//namespace IRaCIS.Core.API.Utility.AOP
|
||
//{
|
||
//#pragma warning disable
|
||
// public class QANoticeAOP : IInterceptor
|
||
// {
|
||
// private readonly IRepository<QANotice> _qaNoticeRepository;
|
||
|
||
// private readonly IRepository<DicomStudy> _studyRepository;
|
||
// private readonly IRepository<TrialUser> _userTrialRepository;
|
||
// private readonly IRepository<TrialSiteUser> _userTrialSiteRepository;
|
||
// private readonly IUserInfo _userInfo;
|
||
|
||
// public QANoticeAOP(IRepository<QANotice> qaNoticeRepository,
|
||
// IUserInfo userInfo, IRepository<DicomStudy> studyRepository, IRepository<TrialUser> userTrialRepository, IRepository<TrialSiteUser> userTrialSiteRepository)
|
||
// {
|
||
// _qaNoticeRepository = qaNoticeRepository;
|
||
|
||
// _studyRepository = studyRepository;
|
||
// _userTrialRepository = userTrialRepository;
|
||
// _userTrialSiteRepository = userTrialSiteRepository;
|
||
// _userInfo = userInfo;
|
||
// }
|
||
|
||
// public void Intercept(IInvocation invocation)
|
||
// {
|
||
// //处理拦截的方法
|
||
// invocation.Proceed();
|
||
|
||
// if (invocation.Method.Name == "UpdateStudyStatus")
|
||
// {
|
||
// var studyStatus = invocation.Arguments[0] as StudyStatusDetailCommand;
|
||
|
||
// var study = _studyRepository.FirstOrDefault(t=>t.Id==studyStatus.StudyId);
|
||
|
||
|
||
// if (study.Status == (int)StudyStatus.Uploaded)
|
||
// {
|
||
// _qaNoticeRepository.Add(new QANotice()
|
||
// {
|
||
// TrialId = study.TrialId,
|
||
// SubjectVisitId = study.Id,
|
||
// FromUser = _userInfo.RealName,
|
||
// FromUserId = _userInfo.Id,
|
||
// FromUserType = _userInfo.UserTypeShortName,
|
||
|
||
// NoticeTypeEnum = NoticeType.NotNeedNotice,
|
||
// NeedDeal = false,
|
||
// StudyStatusStr = "Uploaded",
|
||
// Message = $"IC : {_userInfo.RealName} has uploaded {study.StudyCode} ",
|
||
// SendTime = DateTime.Now,
|
||
// });
|
||
// }
|
||
|
||
// #region 处理QA通知模块
|
||
|
||
// //查询项目的参与者 和 负责site下IC用户
|
||
// var trialUserList = _userTrialRepository.Where(t => t.TrialId == study.TrialId).ToList();
|
||
|
||
// // 找到该study 关联Site 下的IC
|
||
|
||
// var crcList = _userTrialSiteRepository.Where(t =>
|
||
// t.SiteId == study.SiteId && t.User.UserTypeEnum == UserTypeEnum.ClinicalResearchCoordinator && t.TrialId == study.TrialId).ToList();
|
||
|
||
|
||
// var qaList = trialUserList.Where(t => t.User.UserTypeEnum == UserTypeEnum.IQC).ToList();
|
||
|
||
// var pm = trialUserList.FirstOrDefault(t => t.User.UserTypeEnum == UserTypeEnum.ProjectManager);
|
||
|
||
|
||
|
||
|
||
// // IC =>QA
|
||
// if (studyStatus.Status == (int)StudyStatus.QARequested)
|
||
// {
|
||
// //找出当前操作的IC
|
||
// //PM 或者admin可以代替IC角色 不能从IC列表中查询用户
|
||
// //var currentCRC = trialUserList.First(t => t.UserId == _userInfo.Id);
|
||
|
||
// var notice = new QANotice()
|
||
// {
|
||
// TrialId = study.TrialId,
|
||
// SubjectVisitId = study.Id,
|
||
// FromUser = _userInfo.RealName,
|
||
// FromUserId = _userInfo.Id,
|
||
// FromUserType = _userInfo.UserTypeShortName,
|
||
|
||
// //FromUser = currentCRC.UserRealName,
|
||
// //FromUserId = _userInfo.Id,
|
||
// //FromUserType = currentCRC.UserType,
|
||
// NoticeTypeEnum = NoticeType.CRC_RequestToQA_NoticeQA,
|
||
// NeedDeal = true,
|
||
// StudyStatusStr = "QA Requested",
|
||
// Message =
|
||
// $"IC -> QA : {_userInfo.RealName} request QA {study.StudyCode} , Inquiry can be performed! ",
|
||
// SendTime = DateTime.Now,
|
||
// };
|
||
|
||
// qaList.ForEach(t => notice.QANoticeUserList.Add(new QANoticeUser()
|
||
// {
|
||
// QANoticeId = notice.Id,
|
||
// SubjectVisitId = study.Id,
|
||
// ToUser = t.User.LastName + " / " + t.User.FirstName,
|
||
// ToUserId = t.UserId,
|
||
// ToUserType = t.User.UserTypeRole.UserTypeShortName
|
||
// }));
|
||
|
||
// _qaNoticeRepository.Add(notice);
|
||
|
||
// //DealRequestToQA(study.Id);
|
||
|
||
// var needDealNoticeList = _qaNoticeRepository.AsQueryable()
|
||
// .Where(t => t.SubjectVisitId == study.Id && t.NeedDeal && t.NoticeTypeEnum == NoticeType.CRC_RequestToQA_NoticeQA).ToList();
|
||
|
||
// needDealNoticeList.ForEach(t =>
|
||
// {
|
||
// t.NeedDeal = false;
|
||
// t.DealTime = DateTime.Now;
|
||
// _qaNoticeRepository.Update(t);
|
||
// });
|
||
// }
|
||
|
||
// // QA =>IC 向IC推送消息影像有问题 同时作为 requestToQA 的边界
|
||
// else if (studyStatus.Status == (int)StudyStatus.QAing)
|
||
// {
|
||
// //找出当前操作的QA 如果是pm 或者admin 代替操作 此时会有问题 所以 谁代替,就以谁的名义执行
|
||
// //var currentQA = qaList.First(t => t.UserId == _userInfo.Id);
|
||
// //var currentQA = trialUserList.First(t => t.UserId == _userInfo.Id);
|
||
|
||
// //在项目IC列表中筛选出 负责该study关联 site的IC
|
||
// var siteCRCList = _userTrialSiteRepository.Where(t =>
|
||
// t.SiteId == study.SiteId && t.User.UserTypeEnum == UserTypeEnum.ClinicalResearchCoordinator && t.TrialId == study.TrialId).ToList();
|
||
|
||
// //查询项目的参与者 和 负责site下IC用户
|
||
|
||
|
||
|
||
// var notice = new QANotice()
|
||
// {
|
||
// TrialId = study.TrialId,
|
||
// SubjectVisitId = study.Id,
|
||
// //FromUser = currentQA.UserRealName,
|
||
// //FromUserId = _userInfo.Id,
|
||
// //FromUserType = currentQA.UserType,
|
||
// FromUser = _userInfo.RealName,
|
||
// FromUserId = _userInfo.Id,
|
||
// FromUserType = _userInfo.UserTypeShortName,
|
||
// NoticeTypeEnum = NoticeType.QA_InQA_NoticeCRC,
|
||
// NeedDeal = true,
|
||
// StudyStatusStr = "In QA",
|
||
// Message = $"QA -> IC : {_userInfo.RealName} inquiry {study.StudyCode} ",
|
||
// SendTime = DateTime.Now,
|
||
// };
|
||
|
||
// siteCRCList.ForEach(t => notice.QANoticeUserList.Add(new QANoticeUser()
|
||
// {
|
||
// QANoticeId = notice.Id,
|
||
// SubjectVisitId = study.Id,
|
||
// ToUser = t.User.LastName + " / " + t.User.FirstName,
|
||
// ToUserId = t.UserId,
|
||
// ToUserType = t.UserTypeRole.UserTypeShortName
|
||
// }));
|
||
|
||
// //添加 发送给IC的消息 消息和IC是 一对多
|
||
// _qaNoticeRepository.Add(notice);
|
||
|
||
|
||
// //处理 消息 标记已处理
|
||
// var needDealNoticeList = _qaNoticeRepository.AsQueryable()
|
||
// .Where(t => t.SubjectVisitId == study.Id && t.NeedDeal &&
|
||
// (t.NoticeTypeEnum == NoticeType.CRC_RequestToQA_NoticeQA ||
|
||
// t.NoticeTypeEnum == NoticeType.CRC_ReUpload_NoticeQA ||
|
||
// t.NoticeTypeEnum == NoticeType.CRC_QARecordDialogPost_NoticeQA)).ToList();
|
||
|
||
// needDealNoticeList.ForEach(t =>
|
||
// {
|
||
// t.NeedDeal = false;
|
||
// t.DealTime = DateTime.Now;
|
||
// _qaNoticeRepository.Update(t);
|
||
// });
|
||
|
||
|
||
// }
|
||
// // QA =>QA 给自己的消息 通知需要匿名化 同时作为 requestToQA 的边界
|
||
// else if (studyStatus.Status == (int)StudyStatus.QAFinish)
|
||
// {
|
||
|
||
// //找出当前操作的QA 如果是pm 或者admin 代替操作 此时会有问题 所以 谁代替,就以谁的名义执行
|
||
// //var currentQA = qaList.First(t => t.UserId == _userInfo.Id);
|
||
// //var currentQA = trialUserList.First(t => t.UserId == _userInfo.Id);
|
||
|
||
// //发送给当前项目QA列表
|
||
|
||
// var notice = new QANotice()
|
||
// {
|
||
// TrialId = study.TrialId,
|
||
// SubjectVisitId = study.Id,
|
||
// //FromUser = currentQA.UserRealName,
|
||
// //FromUserId = _userInfo.Id,
|
||
// //FromUserType = currentQA.UserType,
|
||
// FromUser = _userInfo.RealName,
|
||
// FromUserId = _userInfo.Id,
|
||
// FromUserType = _userInfo.UserTypeShortName,
|
||
// NoticeTypeEnum = NoticeType.QA_QAPass_NoticeQA,
|
||
// NeedDeal = true,
|
||
// StudyStatusStr = "QA-Passed",
|
||
// Message =
|
||
// $"QA -> QA : {_userInfo.RealName} inquiry {study.StudyCode} finished,Anonymization can be performed!",
|
||
// SendTime = DateTime.Now,
|
||
// };
|
||
|
||
// qaList.ForEach(t => notice.QANoticeUserList.Add(new QANoticeUser()
|
||
// {
|
||
// QANoticeId = notice.Id,
|
||
// SubjectVisitId = study.Id,
|
||
// ToUser = t.User.LastName+" / "+t.User.FirstName,
|
||
// ToUserId = t.UserId,
|
||
// ToUserType = t.User.UserTypeRole.UserTypeShortName
|
||
// }));
|
||
|
||
// _qaNoticeRepository.Add(notice);
|
||
|
||
// //处理 消息 标记已处理 存在意外情况 qa发给IC的 但是qa里面设置了 通过或者不通过 此时qa发送的消息也设置为已处理
|
||
// var needDealNoticeList = _qaNoticeRepository.AsQueryable()
|
||
// .Where(t => t.SubjectVisitId == study.Id && t.NeedDeal &&
|
||
// (t.NoticeTypeEnum == NoticeType.CRC_RequestToQA_NoticeQA ||
|
||
// t.NoticeTypeEnum == NoticeType.CRC_ReUpload_NoticeQA ||
|
||
// t.NoticeTypeEnum == NoticeType.CRC_QARecordDialogPost_NoticeQA ||
|
||
|
||
// t.NoticeTypeEnum == NoticeType.QA_QARecordDialogPost_NoticeCRC ||
|
||
// t.NoticeTypeEnum == NoticeType.QA_InQA_NoticeCRC ||
|
||
// t.NoticeTypeEnum == NoticeType.QA_AddQARecord_NoticeCRC)).ToList();
|
||
|
||
// needDealNoticeList.ForEach(t =>
|
||
// {
|
||
// t.NeedDeal = false;
|
||
// t.DealTime = DateTime.Now;
|
||
// _qaNoticeRepository.Update(t);
|
||
// });
|
||
|
||
|
||
// }
|
||
// // QA =>IC 暂时不用发送消息给IC 因为IC 暂时没有入口回复 同时作为 requestToQA 的边界
|
||
// else if (studyStatus.Status == (int)StudyStatus.QAFInishNotPass)
|
||
// {
|
||
|
||
// _qaNoticeRepository.Add(new QANotice()
|
||
// {
|
||
// TrialId = study.TrialId,
|
||
// SubjectVisitId = study.Id,
|
||
// FromUser = _userInfo.RealName,
|
||
// FromUserId = _userInfo.Id,
|
||
// FromUserType = _userInfo.UserTypeShortName,
|
||
// NoticeTypeEnum = NoticeType.NotNeedNotice,
|
||
// NeedDeal = false,
|
||
// StudyStatusStr = "QA-Failed",
|
||
// Message = $"QA : {_userInfo.RealName} set {study.StudyCode} QA-Failed !",
|
||
// SendTime = DateTime.Now,
|
||
// });
|
||
|
||
// //处理 消息 标记已处理
|
||
// var needDealNoticeList = _qaNoticeRepository.AsQueryable()
|
||
// .Where(t => t.SubjectVisitId == study.Id && t.NeedDeal &&
|
||
// (t.NoticeTypeEnum == NoticeType.CRC_RequestToQA_NoticeQA ||
|
||
// t.NoticeTypeEnum == NoticeType.CRC_ReUpload_NoticeQA ||
|
||
// t.NoticeTypeEnum == NoticeType.CRC_QARecordDialogPost_NoticeQA ||
|
||
|
||
|
||
// t.NoticeTypeEnum == NoticeType.QA_QARecordDialogPost_NoticeCRC ||
|
||
// t.NoticeTypeEnum == NoticeType.QA_InQA_NoticeCRC ||
|
||
// t.NoticeTypeEnum == NoticeType.QA_AddQARecord_NoticeCRC)).ToList();
|
||
|
||
// needDealNoticeList.ForEach(t =>
|
||
// {
|
||
// t.NeedDeal = false;
|
||
// t.DealTime = DateTime.Now;
|
||
// _qaNoticeRepository.Update(t);
|
||
// });
|
||
// }
|
||
|
||
// #endregion
|
||
|
||
|
||
// }
|
||
|
||
// else if (invocation.Method.Name == "ReUploadSameStudy")
|
||
// {
|
||
// var studyId = Guid.Parse(invocation.Arguments[0].ToString());
|
||
|
||
// var study = _studyRepository.FirstOrDefault(t => t.Id == studyId);
|
||
// var status = study.Status;
|
||
|
||
// //处理IC 重传时 QA消息
|
||
|
||
// if (status == (int)StudyStatus.QAing)
|
||
// {
|
||
// //查询项目的参与者 和 负责site下IC用户
|
||
// var trialUserList = _userTrialRepository.Where(t => t.TrialId == study.TrialId).ToList();
|
||
|
||
// // 找到该study 关联Site 下的IC
|
||
|
||
// var crcList = _userTrialSiteRepository.Where(t =>
|
||
// t.SiteId == study.SiteId && t.User.UserTypeEnum == UserTypeEnum.ClinicalResearchCoordinator && t.TrialId == study.TrialId).ToList();
|
||
|
||
// var qaList = trialUserList.Where(t => t.User.UserTypeEnum == UserTypeEnum.IQC).ToList();
|
||
|
||
// //IC =>QA IC的职能被PM 或者admin代替
|
||
// //if (_userInfo.UserTypeEnumInt == (int)UserType.ClinicalResearchCoordinator)
|
||
// {
|
||
// //PM 或者admin可以代替IC角色 不能从IC列表中查询用户
|
||
// //var currentCRC = trialUserList.First(t => t.UserId == _userInfo.Id);
|
||
|
||
// var notice = new QANotice()
|
||
// {
|
||
// TrialId = study.TrialId,
|
||
// SubjectVisitId = study.Id,
|
||
// //FromUser = currentCRC.UserRealName,
|
||
// //FromUserId = _userInfo.Id,
|
||
// //FromUserType = currentCRC.UserType,
|
||
// FromUser = _userInfo.RealName,
|
||
// FromUserId = _userInfo.Id,
|
||
// FromUserType = _userInfo.UserTypeShortName,
|
||
// NoticeTypeEnum = NoticeType.CRC_ReUpload_NoticeQA,
|
||
// NeedDeal = true,
|
||
// Message = $"IC -> QA :{_userInfo.RealName} has reuploaded {study.StudyCode} , Need to be inquiry again",
|
||
// SendTime = DateTime.Now
|
||
// };
|
||
|
||
// qaList.ForEach(t => notice.QANoticeUserList.Add(new QANoticeUser()
|
||
// {
|
||
// QANoticeId = notice.Id,
|
||
// SubjectVisitId = study.Id,
|
||
// ToUser = t.User.LastName+" / "+t.User.FirstName,
|
||
// ToUserId = t.UserId,
|
||
// ToUserType = t.User.UserTypeRole.UserTypeShortName
|
||
// }));
|
||
|
||
// _qaNoticeRepository.Add(notice);
|
||
|
||
// //这里作为 QA 设置 Inqa 状态的回复 或者QA和IC对话的
|
||
// var needDealNoticeList = _qaNoticeRepository.Where(t => t.SubjectVisitId == study.Id && t.NeedDeal
|
||
// && (t.NoticeTypeEnum == NoticeType.QA_InQA_NoticeCRC || t.NoticeTypeEnum == NoticeType.QA_QARecordDialogPost_NoticeCRC))
|
||
// .ToList();
|
||
|
||
// needDealNoticeList.ForEach(t =>
|
||
// {
|
||
// t.NeedDeal = false;
|
||
// t.DealTime = DateTime.Now;
|
||
// _qaNoticeRepository.Update(t);
|
||
// });
|
||
|
||
// }
|
||
// }
|
||
// else
|
||
// {
|
||
// //不是QAing 的重传 不发送qa消息
|
||
// return;
|
||
// }
|
||
|
||
|
||
|
||
// }
|
||
|
||
// else if (invocation.Method.Name == "DicomAnonymize")
|
||
// {
|
||
// var studyId = Guid.Parse(invocation.Arguments[0].ToString());
|
||
|
||
// var study = _studyRepository.FirstOrDefault(t => t.Id == studyId);
|
||
|
||
// #region 处理QA通知 匿名化完毕 通知PM
|
||
|
||
// //查询项目的参与者 和 负责site下IC用户
|
||
// var trialUserList = _userTrialRepository.Where(t => t.TrialId == study.TrialId).ToList();
|
||
|
||
// // 找到该study 关联Site 下的IC
|
||
|
||
// var crcList = _userTrialSiteRepository.Where(t =>
|
||
// t.SiteId == study.SiteId && t.User.UserTypeEnum == UserTypeEnum.ClinicalResearchCoordinator && t.TrialId == study.TrialId).ToList();
|
||
|
||
// var qaList = trialUserList.Where(t => t.User.UserTypeEnum == UserTypeEnum.IQC).ToList();
|
||
|
||
// //
|
||
// var pm = trialUserList.FirstOrDefault(t => t.User.UserTypeEnum == UserTypeEnum.ProjectManager);
|
||
|
||
|
||
// //找出当前操作的QA 如果是pm 或者admin 代替操作 此时会有问题 所以 谁代替,就以谁的名义执行
|
||
// //var currentQA = trialUserList.First(t =>
|
||
// // t.UserTypeEnum == UserType.IQC && t.UserId == _userInfo.Id);
|
||
// //var currentQA = trialUserList.First(t => t.UserId == _userInfo.Id);
|
||
|
||
// var notice = new QANotice()
|
||
// {
|
||
// TrialId = study.TrialId,
|
||
// SubjectVisitId = study.Id,
|
||
// //FromUser = currentQA.UserRealName,
|
||
// //FromUserId = _userInfo.Id,
|
||
// //FromUserType = currentQA.UserType,
|
||
// FromUser = _userInfo.RealName,
|
||
// FromUserId = _userInfo.Id,
|
||
// FromUserType = _userInfo.UserTypeShortName,
|
||
// NoticeTypeEnum = NoticeType.QA_Anonymized_NoticeQA,
|
||
// NeedDeal = true,
|
||
// StudyStatusStr = "Anonymized",
|
||
// //Message = $"QA -> PM :{_userInfo.RealName} has anonymized {study.StudyCode} ,Forward can be performed!!",
|
||
// Message = $"QA -> QA :{_userInfo.RealName} has anonymized {study.StudyCode} ,Forward can be performed!!",
|
||
|
||
// SendTime = DateTime.Now,
|
||
|
||
// };
|
||
|
||
// //notice.QANoticeUserList.Add(new QANoticeUser()
|
||
// //{
|
||
// // QANoticeId = notice.Id,
|
||
// // StudyId = study.Id,
|
||
// // ToUser = pm.UserRealName,
|
||
// // ToUserId = pm.UserId,
|
||
// // ToUserType = pm.UserType
|
||
// //});
|
||
|
||
// qaList.ForEach(t => notice.QANoticeUserList.Add(new QANoticeUser()
|
||
// {
|
||
// QANoticeId = notice.Id,
|
||
// SubjectVisitId = study.Id,
|
||
// ToUser = t.User.LastName+" / "+t.User.FirstName,
|
||
// ToUserId = t.UserId,
|
||
// ToUserType = t.User.UserTypeRole.UserTypeShortName
|
||
// }));
|
||
|
||
// _qaNoticeRepository.Add(notice);
|
||
|
||
// var needDealNoticeList = _qaNoticeRepository.AsQueryable()
|
||
// .Where(t => t.SubjectVisitId == study.Id && t.NeedDeal && (t.NoticeTypeEnum == NoticeType.QA_QAPass_NoticeQA)).ToList();
|
||
|
||
// needDealNoticeList.ForEach(t =>
|
||
// {
|
||
// t.NeedDeal = false;
|
||
// t.DealTime = DateTime.Now;
|
||
// _qaNoticeRepository.Update(t);
|
||
// });
|
||
|
||
|
||
// #endregion
|
||
// }
|
||
|
||
// else if (invocation.Method.Name == "ForwardStudy")
|
||
// {
|
||
// var studyId = Guid.Parse(invocation.Arguments[0].ToString());
|
||
|
||
// var study = _studyRepository.FirstOrDefault(t => t.Id == studyId);
|
||
|
||
// //匿名化操作产生的消息 设置为已经处理
|
||
// _qaNoticeRepository.Add(new QANotice()
|
||
// {
|
||
// TrialId = study.TrialId,
|
||
// SubjectVisitId = study.Id,
|
||
// //FromUser = currentQA.UserRealName,
|
||
// //FromUserId = _userInfo.Id,
|
||
// //FromUserType = currentQA.UserType,
|
||
// FromUser = _userInfo.RealName,
|
||
// FromUserId = _userInfo.Id,
|
||
// FromUserType = _userInfo.UserTypeShortName,
|
||
// NoticeTypeEnum = NoticeType.NotNeedNotice,
|
||
// NeedDeal = false,
|
||
// StudyStatusStr = "Forwarded",
|
||
// //Message = $"PM :{_userInfo.RealName} has forwarded {study.StudyCode} !",
|
||
// Message = $"QA :{_userInfo.RealName} has forwarded {study.StudyCode} !",
|
||
// SendTime = DateTime.Now,
|
||
// });
|
||
|
||
// var needDealList = _qaNoticeRepository.Where(t =>
|
||
// t.SubjectVisitId == study.Id && t.NeedDeal && t.NoticeTypeEnum == NoticeType.QA_Anonymized_NoticeQA).ToList();
|
||
|
||
// needDealList.ForEach(t =>
|
||
// {
|
||
// t.NeedDeal = false;
|
||
// t.DealTime = DateTime.Now;
|
||
// _qaNoticeRepository.Update(t);
|
||
// });
|
||
// }
|
||
|
||
// var success = _qaNoticeRepository.SaveChanges();
|
||
|
||
// if (!success)
|
||
// {
|
||
// throw new Exception("Send QA message failed");
|
||
// }
|
||
// }
|
||
|
||
|
||
// }
|
||
//} |