合并代码修改
parent
6faeecebb0
commit
12ab0d3eb4
|
@ -95,6 +95,25 @@
|
||||||
<param name="type"></param>
|
<param name="type"></param>
|
||||||
<returns></returns>
|
<returns></returns>
|
||||||
</member>
|
</member>
|
||||||
|
<member name="M:IRaCIS.Core.Application.Helper.OSSService.UploadToOSS(System.IO.Stream,System.String,System.String)">
|
||||||
|
<summary>
|
||||||
|
oosFolderPath 不要 "/ "开头 应该: TempFolder/ChildFolder
|
||||||
|
</summary>
|
||||||
|
<param name="fileStream"></param>
|
||||||
|
<param name="oosFolderPath"></param>
|
||||||
|
<param name="fileRealName"></param>
|
||||||
|
<returns></returns>
|
||||||
|
<exception cref="T:IRaCIS.Core.Infrastructure.BusinessValidationFailedException"></exception>
|
||||||
|
</member>
|
||||||
|
<member name="M:IRaCIS.Core.Application.Helper.OSSService.UploadToOSS(System.String,System.String)">
|
||||||
|
<summary>
|
||||||
|
oosFolderPath 不要 "/ "开头 应该: TempFolder/ChildFolder
|
||||||
|
</summary>
|
||||||
|
<param name="localFilePath"></param>
|
||||||
|
<param name="oosFolderPath"></param>
|
||||||
|
<returns></returns>
|
||||||
|
<exception cref="T:IRaCIS.Core.Infrastructure.BusinessValidationFailedException"></exception>
|
||||||
|
</member>
|
||||||
<member name="T:IRaCIS.Core.Application.Service.TaskMedicalReviewRuleService">
|
<member name="T:IRaCIS.Core.Application.Service.TaskMedicalReviewRuleService">
|
||||||
<summary>
|
<summary>
|
||||||
医学审核生成规则 废弃
|
医学审核生成规则 废弃
|
||||||
|
|
|
@ -31,6 +31,8 @@ namespace IRaCIS.Core.Application.Service
|
||||||
Task SendTrialQCQuestionEmailAsync(Guid trialId);
|
Task SendTrialQCQuestionEmailAsync(Guid trialId);
|
||||||
Task SendTrialImageQuestionAsync(Guid trialId);
|
Task SendTrialImageQuestionAsync(Guid trialId);
|
||||||
Task SendPIAuditResultAsync(Guid visitTaskId);
|
Task SendPIAuditResultAsync(Guid visitTaskId);
|
||||||
|
|
||||||
|
Task<(TrialEmailNoticeConfig?, SMTPEmailConfig?)> BuildEmailConfig(Guid trialId, EmailBusinessScenario businessScenario, Func<TrialEmailNoticeConfig, (string topicStr, string htmlBodyStr, bool isEn_us, Guid? onlyToUserId)> topicAndHtmlFunc, Guid? siteId = null, Guid? trialReadingCriterionId = null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public class EmailSendService : BaseService, IEmailSendService
|
public class EmailSendService : BaseService, IEmailSendService
|
||||||
|
@ -463,6 +465,142 @@ namespace IRaCIS.Core.Application.Service
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public async Task<(TrialEmailNoticeConfig?, SMTPEmailConfig?)> BuildEmailConfig(Guid trialId, EmailBusinessScenario businessScenario, Func<TrialEmailNoticeConfig, (string topicStr, string htmlBodyStr, bool isEn_us, Guid? onlyToUserId)> topicAndHtmlFunc, Guid? siteId = null, Guid? trialReadingCriterionId = null)
|
||||||
|
{
|
||||||
|
//找到配置
|
||||||
|
var trialEmailConfig = await _trialEmailNoticeConfigRepository.Where(t => t.TrialId == trialId && t.TrialReadingCriterionId == trialReadingCriterionId && t.BusinessScenarioEnum == businessScenario, ignoreQueryFilters: true)
|
||||||
|
.Include(t => t.TrialEmailNoticeUserList).Include(t => t.TrialEmailBlackUserList).FirstOrDefaultAsync();
|
||||||
|
|
||||||
|
|
||||||
|
if (trialEmailConfig == null || trialEmailConfig.IsAutoSend == false)
|
||||||
|
{
|
||||||
|
return (null, null);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
var sendEmailConfig = new SMTPEmailConfig();
|
||||||
|
|
||||||
|
var (topicStr, htmlBodyStr, isEn_us, onlyToUserId) = topicAndHtmlFunc(trialEmailConfig);
|
||||||
|
|
||||||
|
|
||||||
|
sendEmailConfig.TopicDescription = topicStr;
|
||||||
|
sendEmailConfig.HtmlBodyStr = htmlBodyStr;
|
||||||
|
|
||||||
|
|
||||||
|
var blackUserIdList = trialEmailConfig.TrialEmailBlackUserList.Select(t => t.UserId).ToList();
|
||||||
|
|
||||||
|
|
||||||
|
var toUserTypeEnumList = trialEmailConfig.TrialEmailNoticeUserList.Where(t => t.EmailUserType == EmailUserType.To).Select(c => c.UserType).ToList();
|
||||||
|
|
||||||
|
var copyUserTypeEnumList = trialEmailConfig.TrialEmailNoticeUserList.Where(t => t.EmailUserType == EmailUserType.Copy).Select(c => c.UserType).ToList();
|
||||||
|
|
||||||
|
var allUserTypeEnumList = toUserTypeEnumList.Union(copyUserTypeEnumList).Distinct().ToList();
|
||||||
|
|
||||||
|
var allUserList = await _repository.Where<TrialUser>(t => t.TrialId == trialId && allUserTypeEnumList.Contains(t.User.UserTypeEnum)).Select(t => new { t.UserId, t.User.EMail, t.User.FullName, t.User.UserTypeEnum }).ToListAsync();
|
||||||
|
|
||||||
|
|
||||||
|
var toUserList = allUserList.Where(t => toUserTypeEnumList.Contains(t.UserTypeEnum))
|
||||||
|
.ToList();
|
||||||
|
|
||||||
|
//收件人 有CRC CRA , CRC CRA的账户要按照中心发送
|
||||||
|
if (siteId == null && toUserTypeEnumList.Any(t => t == UserTypeEnum.ClinicalResearchCoordinator || t == UserTypeEnum.CRA) && onlyToUserId == null)
|
||||||
|
{
|
||||||
|
throw new BusinessValidationFailedException("当前场景收件人包含CRC CRA,但是没有siteId,请联系后端开发");
|
||||||
|
}
|
||||||
|
if (siteId != null && toUserTypeEnumList.Any(t => t == UserTypeEnum.ClinicalResearchCoordinator || t == UserTypeEnum.CRA))
|
||||||
|
{
|
||||||
|
var curentSiteUserIdList = _repository.Where<TrialSiteUser>(t => t.TrialId == trialId && t.SiteId == siteId).Select(t => t.UserId).ToList();
|
||||||
|
|
||||||
|
toUserList = toUserList.Where(t => (t.UserTypeEnum != UserTypeEnum.CRA && t.UserTypeEnum != UserTypeEnum.ClinicalResearchCoordinator) || curentSiteUserIdList.Contains(t.UserId)).ToList();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//去除黑名单
|
||||||
|
toUserList = toUserList.Where(t => !blackUserIdList.Contains(t.UserId)).ToList();
|
||||||
|
|
||||||
|
var copyUserList = allUserList.Where(t => copyUserTypeEnumList.Contains(t.UserTypeEnum))
|
||||||
|
.Where(t => !blackUserIdList.Contains(t.UserId)).ToList();
|
||||||
|
|
||||||
|
if (siteId != null && copyUserTypeEnumList.Any(t => t == UserTypeEnum.ClinicalResearchCoordinator || t == UserTypeEnum.CRA))
|
||||||
|
{
|
||||||
|
var curentSiteUserIdList = _repository.Where<TrialSiteUser>(t => t.TrialId == trialId && t.SiteId == siteId).Select(t => t.UserId).ToList();
|
||||||
|
|
||||||
|
copyUserList = copyUserList.Where(t => (t.UserTypeEnum != UserTypeEnum.CRA && t.UserTypeEnum != UserTypeEnum.ClinicalResearchCoordinator) || curentSiteUserIdList.Contains(t.UserId)).ToList();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (onlyToUserId != null)
|
||||||
|
{
|
||||||
|
toUserList = toUserList.Where(t => t.UserId == onlyToUserId).ToList();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
sendEmailConfig.HtmlBodyStr = htmlBodyStr.Replace(EmailNamePlaceholder, string.Join(isEn_us ? ", " : "、", toUserList.Select(t => t.FullName).ToList()));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (toUserList.Count() == 0)
|
||||||
|
{
|
||||||
|
//---没有收件人,无法发送邮件
|
||||||
|
throw new BusinessValidationFailedException(_localizer["TrialEmailN_NoRecipient"]);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
if (trialEmailConfig.FromEmail.Contains("@") && !string.IsNullOrEmpty(trialEmailConfig.FromEmail))
|
||||||
|
{
|
||||||
|
|
||||||
|
sendEmailConfig.FromEmailAddress = new MimeKit.MailboxAddress(trialEmailConfig.FromName, trialEmailConfig.FromEmail);
|
||||||
|
sendEmailConfig.AuthorizationCode = trialEmailConfig.AuthorizationCode;
|
||||||
|
sendEmailConfig.UserName = trialEmailConfig.FromEmail;
|
||||||
|
|
||||||
|
sendEmailConfig.Host = trialEmailConfig.SMTPServerAddress;
|
||||||
|
sendEmailConfig.Port = trialEmailConfig.SMTPServerPort;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
//---项目发件邮箱配置有误,请核实
|
||||||
|
throw new BusinessValidationFailedException(_localizer["TrialEmailN_InvalidEmailConfig"]);
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach (var item in toUserList)
|
||||||
|
{
|
||||||
|
|
||||||
|
if (item.EMail.Contains("@") && !string.IsNullOrEmpty(item.EMail))
|
||||||
|
{
|
||||||
|
|
||||||
|
sendEmailConfig.ToMailAddressList.Add(new MimeKit.MailboxAddress(item.FullName, item.EMail));
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
foreach (var item in copyUserList)
|
||||||
|
{
|
||||||
|
|
||||||
|
if (item.EMail.Contains("@") && !string.IsNullOrEmpty(item.EMail))
|
||||||
|
{
|
||||||
|
|
||||||
|
sendEmailConfig.CopyToMailAddressList.Add(new MimeKit.MailboxAddress(item.FullName, item.EMail));
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//邮件附件 这里是原格式发送,不是PDF
|
||||||
|
|
||||||
|
//if (trialEmailConfig.AttachCNPath != string.Empty && trialEmailConfig.AttachPath != string.Empty)
|
||||||
|
//{
|
||||||
|
// var phyPath = FileStoreHelper.GetPhysicalFilePath(_hostEnvironment, isEn_us? trialEmailConfig.AttachName: trialEmailConfig.AttachNameCN);
|
||||||
|
|
||||||
|
// //先预先生成了邮件,发送预先生成的邮件
|
||||||
|
// sendEmailConfig.EmailAttachMentConfigList.Add(new EmailAttachMentConfig()
|
||||||
|
// {
|
||||||
|
// FileName = $"{attachPrefix}_{Path.GetFileName(_userInfo.IsEn_Us ? trialEmailConfig.AttachName : trialEmailConfig.AttachNameCN)}",
|
||||||
|
|
||||||
|
// FileStream = File.OpenRead(phyPath),
|
||||||
|
// });
|
||||||
|
//}
|
||||||
|
|
||||||
|
return (trialEmailConfig, sendEmailConfig);
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -47,7 +47,7 @@ namespace IRaCIS.Core.Application.Service
|
||||||
private readonly IRepository<TrialUser> _trialUserRepository;
|
private readonly IRepository<TrialUser> _trialUserRepository;
|
||||||
private readonly IRepository<Subject> _subjectRepository;
|
private readonly IRepository<Subject> _subjectRepository;
|
||||||
private readonly IRepository<SubjectVisit> _subjectVisitRepository;
|
private readonly IRepository<SubjectVisit> _subjectVisitRepository;
|
||||||
|
private readonly IEmailSendService _emailSendService;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -73,6 +73,7 @@ namespace IRaCIS.Core.Application.Service
|
||||||
_subjectVisitRepository = subjectVisitRepository;
|
_subjectVisitRepository = subjectVisitRepository;
|
||||||
_trialEmailBlackUserRepository = trialEmailBlackUserRepository;
|
_trialEmailBlackUserRepository = trialEmailBlackUserRepository;
|
||||||
_emailNoticeConfigRepository = emailNoticeConfigRepository;
|
_emailNoticeConfigRepository = emailNoticeConfigRepository;
|
||||||
|
_emailSendService = emailSendService;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -261,8 +262,8 @@ namespace IRaCIS.Core.Application.Service
|
||||||
/// <exception cref="BusinessValidationFailedException"></exception>
|
/// <exception cref="BusinessValidationFailedException"></exception>
|
||||||
public async Task<string> BaseBusinessScenarioSendEmailAsync(Guid visitTaskId, bool? isHandSend, EmailStoreSendMode emailStoreMode, string sendFileRelativePath)
|
public async Task<string> BaseBusinessScenarioSendEmailAsync(Guid visitTaskId, bool? isHandSend, EmailStoreSendMode emailStoreMode, string sendFileRelativePath)
|
||||||
{
|
{
|
||||||
|
var isEn_us = _userInfo.IsEn_Us;
|
||||||
EmailBusinessScenario? businessScenarioEnum = null;
|
EmailBusinessScenario businessScenarioEnum = EmailBusinessScenario.None;
|
||||||
|
|
||||||
#region 任务关联的项目配置 标准信息及配置,subject 信息
|
#region 任务关联的项目配置 标准信息及配置,subject 信息
|
||||||
var taskInfo = await _visitTaskRepository.Where(t => t.Id == visitTaskId).Select(t => new
|
var taskInfo = await _visitTaskRepository.Where(t => t.Id == visitTaskId).Select(t => new
|
||||||
|
@ -358,286 +359,119 @@ namespace IRaCIS.Core.Application.Service
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
|
||||||
#region 发收件人配置 确保无误
|
#region 邮件内容装配
|
||||||
|
|
||||||
|
Func<TrialEmailNoticeConfig, (string topicStr, string htmlBodyStr, bool isEn_us, Guid? onlyToUserId)> topicAndHtmlFunc = trialEmailConfig =>
|
||||||
var emailConfig = await _trialEmailNoticeConfigRepository.Where(t => t.TrialId == taskInfo.TrialId && t.TrialReadingCriterionId == taskInfo.TrialReadingCriterionId && t.BusinessScenarioEnum == businessScenarioEnum)
|
|
||||||
.Include(t => t.TrialEmailNoticeUserList).FirstOrDefaultAsync();
|
|
||||||
|
|
||||||
|
|
||||||
if (emailConfig == null || (emailConfig.IsAutoSend == false && isHandSend == null))
|
|
||||||
{
|
{
|
||||||
//throw new BusinessValidationFailedException("找不到该项目标准场景下邮件的配置");
|
var topicStr = string.Format(isEn_us ? trialEmailConfig.EmailTopic : trialEmailConfig.EmailTopicCN, taskInfo.ResearchProgramNo, taskInfo.SubjectCode);
|
||||||
|
|
||||||
return string.Empty;
|
var htmlBodyStr = string.Format(isEn_us ? trialEmailConfig.EmailHtmlContent : trialEmailConfig.EmailHtmlContentCN,
|
||||||
}
|
StaticData.EmailSend.EmailNamePlaceholder, taskInfo.ResearchProgramNo, taskInfo.SubjectCode);
|
||||||
|
|
||||||
|
|
||||||
var sendEmailConfig = new SMTPEmailConfig();
|
return (topicStr, htmlBodyStr, isEn_us, null);
|
||||||
|
};
|
||||||
//收件人 如果是CRC CRA 要按照中心发送
|
|
||||||
var toUserTypeEnumList = emailConfig.TrialEmailNoticeUserList.Where(t => t.EmailUserType == EmailUserType.To).Select(c => c.UserType).ToList();
|
|
||||||
|
|
||||||
|
|
||||||
|
var (trialEmailConfig, sendEmailConfig) = await _emailSendService.BuildEmailConfig(taskInfo.TrialId, businessScenarioEnum, topicAndHtmlFunc, taskInfo.SiteId);
|
||||||
var toUserList = _repository.Where<TrialSiteUser>(t => t.TrialId == taskInfo.TrialId && toUserTypeEnumList.Contains(t.User.UserTypeEnum) && t.SiteId == taskInfo.SiteId).Select(t => new { t.User.EMail, t.User.FullName }).ToList();
|
|
||||||
|
|
||||||
var copyUserTypeEnumList = emailConfig.TrialEmailNoticeUserList.Where(t => t.EmailUserType == EmailUserType.Copy).Select(c => c.UserType).ToList();
|
|
||||||
var copyUserList = _repository.Where<TrialUser>(t => t.TrialId == taskInfo.TrialId && copyUserTypeEnumList.Contains(t.User.UserTypeEnum)).Select(t => new { t.User.EMail, t.User.FullName }).ToList();
|
|
||||||
|
|
||||||
|
|
||||||
if (toUserList.Count() == 0)
|
|
||||||
{
|
|
||||||
//---没有收件人,无法发送邮件
|
|
||||||
throw new BusinessValidationFailedException(_localizer["TrialEmailN_NoRecipient"]);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
if (emailConfig.FromEmail.Contains("@") && !string.IsNullOrEmpty(emailConfig.FromEmail))
|
|
||||||
{
|
|
||||||
|
|
||||||
sendEmailConfig.FromEmailAddress = new MimeKit.MailboxAddress(emailConfig.FromName, emailConfig.FromEmail);
|
|
||||||
sendEmailConfig.AuthorizationCode = emailConfig.AuthorizationCode;
|
|
||||||
sendEmailConfig.UserName = emailConfig.FromEmail;
|
|
||||||
|
|
||||||
sendEmailConfig.Host = emailConfig.SMTPServerAddress;
|
|
||||||
sendEmailConfig.Port = emailConfig.SMTPServerPort;
|
|
||||||
|
|
||||||
|
|
||||||
//测试
|
|
||||||
//sendEmailConfig.ToMailAddressList.Add(new MimeKit.MailboxAddress("ddd", "872297557@qq.com"));
|
|
||||||
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
//---项目发件邮箱配置有误,请核实
|
|
||||||
throw new BusinessValidationFailedException(_localizer["TrialEmailN_InvalidEmailConfig"]);
|
|
||||||
}
|
|
||||||
|
|
||||||
foreach (var item in toUserList)
|
|
||||||
{
|
|
||||||
|
|
||||||
if (item.EMail.Contains("@") && !string.IsNullOrEmpty(item.EMail))
|
|
||||||
{
|
|
||||||
|
|
||||||
sendEmailConfig.ToMailAddressList.Add(new MimeKit.MailboxAddress(item.FullName, item.EMail));
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
foreach (var item in copyUserList)
|
|
||||||
{
|
|
||||||
|
|
||||||
if (item.EMail.Contains("@") && !string.IsNullOrEmpty(item.EMail))
|
|
||||||
{
|
|
||||||
|
|
||||||
sendEmailConfig.CopyToMailAddressList.Add(new MimeKit.MailboxAddress(item.FullName, item.EMail));
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region 确保 邮件Html存在
|
|
||||||
|
|
||||||
//邮件附件
|
|
||||||
var path = FileStoreHelper.GetPhysicalFilePath(_hostEnvironment, _userInfo.IsEn_Us ? emailConfig.AttachPath : emailConfig.AttachCNPath);
|
|
||||||
|
|
||||||
if (!File.Exists(path))
|
|
||||||
{
|
|
||||||
//---找不到该项目标准场景下邮件模板
|
|
||||||
throw new BusinessValidationFailedException(_localizer["TrialEmailN_EmailTemplateNotFound"]);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
var pathToFile = _hostEnvironment.WebRootPath
|
|
||||||
+ Path.DirectorySeparatorChar.ToString()
|
|
||||||
+ "EmailTemplate"
|
|
||||||
+ Path.DirectorySeparatorChar.ToString()
|
|
||||||
//+ "SubjectEnrollConfirmOrPDProgress.html";
|
|
||||||
+ (_userInfo.IsEn_Us ? "SubjectEnrollConfirmOrPDProgress_US.html" : "SubjectEnrollConfirmOrPDProgress.html");
|
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
|
||||||
#region 不同场景 Tile 设置
|
|
||||||
|
|
||||||
if (businessScenarioEnum == EmailBusinessScenario.EnrollConfirmed)
|
//自动发送
|
||||||
|
if (sendEmailConfig != null)
|
||||||
{
|
{
|
||||||
sendEmailConfig.TopicDescription = _localizer["TrialEmailN_EnrollmentConfirmation", taskInfo.ResearchProgramNo, taskInfo.SubjectCode];
|
#region 不同标准 不同项目配置 发送邮件的时机 处理具体逻辑
|
||||||
|
|
||||||
using (StreamReader SourceReader = System.IO.File.OpenText(pathToFile))
|
var answer = "否";
|
||||||
|
var isNeedSend = true;
|
||||||
|
var minUserIdList = _trialUserRepository.Where(t => t.User.UserTypeEnum == Domain.Share.UserTypeEnum.MIM && t.TrialId == taskInfo.TrialId).Select(t => t.UserId).ToList();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//入组确认 根据每个标准配置的是否自动发送,发送邮件与否
|
||||||
|
if (businessScenarioEnum == EmailBusinessScenario.EnrollConfirmed)
|
||||||
{
|
{
|
||||||
var templateInfo = SourceReader.ReadToEnd();
|
if (await _repository.Where<ReadingTableQuestionAnswer>().AnyAsync(x => x.VisitTaskId == visitTaskId && x.Answer == TargetState.Exist.GetEnumInt() &&
|
||||||
|
x.ReadingTableQuestionTrial.QuestionMark == QuestionMark.State && x.ReadingQuestionTrial.LesionType == LesionType.TargetLesion))
|
||||||
|
|
||||||
sendEmailConfig.HtmlBodyStr = string.Format(templateInfo,
|
|
||||||
//--- 附件为疾病进展确认报告,请查收
|
|
||||||
_localizer["TrialEmailN_SubjectDiseaseProgression"]
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if (businessScenarioEnum == EmailBusinessScenario.PDConfirmed)
|
|
||||||
{
|
|
||||||
sendEmailConfig.TopicDescription = _localizer["TrialEmailN_PDReport", taskInfo.ResearchProgramNo, taskInfo.SubjectCode];
|
|
||||||
|
|
||||||
using (StreamReader SourceReader = System.IO.File.OpenText(pathToFile))
|
|
||||||
{
|
|
||||||
var templateInfo = SourceReader.ReadToEnd();
|
|
||||||
|
|
||||||
|
|
||||||
sendEmailConfig.HtmlBodyStr = string.Format(templateInfo,
|
|
||||||
//--- 附件为疾病进展确认报告,请查收
|
|
||||||
_localizer["TrialEmailN_SubjectDiseaseProgression"]
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
//
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
|
|
||||||
#region 不同标准 不同项目配置 发送邮件的时机 处理具体逻辑
|
|
||||||
|
|
||||||
var answer = "否";
|
|
||||||
var isNeedSend = true;
|
|
||||||
var minUserIdList = _trialUserRepository.Where(t => t.User.UserTypeEnum == Domain.Share.UserTypeEnum.MIM && t.TrialId == taskInfo.TrialId).Select(t => t.UserId).ToList();
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//入组确认 根据每个标准配置的是否自动发送,发送邮件与否
|
|
||||||
if (businessScenarioEnum == EmailBusinessScenario.EnrollConfirmed)
|
|
||||||
{
|
|
||||||
if (await _repository.Where<ReadingTableQuestionAnswer>().AnyAsync(x => x.VisitTaskId == visitTaskId && x.Answer == TargetState.Exist.GetEnumInt() &&
|
|
||||||
x.ReadingTableQuestionTrial.QuestionMark == QuestionMark.State && x.ReadingQuestionTrial.LesionType == LesionType.TargetLesion))
|
|
||||||
{
|
|
||||||
answer = "是";
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
//如果其他阅片人已经做了,说明发送了入组确认报告,第二个人做完就不发送了
|
|
||||||
|
|
||||||
//入组确认一直交给第一个人,如果第一个人重阅 还未做完,第二个人先做完了,此时不发
|
|
||||||
|
|
||||||
var existFirstEnrollTask = await _visitTaskRepository.Where(t => t.SourceSubjectVisitId == taskInfo.SourceSubjectVisitId && t.IsAnalysisCreate == false
|
|
||||||
&& t.ReadingTaskState == ReadingTaskState.HaveSigned && t.TrialReadingCriterionId == taskInfo.TrialReadingCriterionId).OrderBy(t => t.SignTime).FirstOrDefaultAsync();
|
|
||||||
|
|
||||||
//入组确认的医生已确定
|
|
||||||
if ((existFirstEnrollTask != null) && (taskInfo.DoctorUserId != existFirstEnrollTask.DoctorUserId))
|
|
||||||
{
|
|
||||||
isNeedSend = false;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
isNeedSend = await DealMedicalReviewTasKGenerateAndIsSendAsync(taskInfo.TrialId, isHandSend, answer, new List<Guid>() { visitTaskId }, minUserIdList);
|
|
||||||
|
|
||||||
|
|
||||||
if (answer == "是")
|
|
||||||
{
|
{
|
||||||
//把另外一个人的任务设置为不加急(如果项目加急是否 subject 加急是否)
|
answer = "是";
|
||||||
var urgent = _repository.Where<SubjectVisit>(t => t.Id == taskInfo.SourceSubjectVisitId).Select(t => new { IsSubjectUrgent = t.Subject.IsUrgent, t.Trial.IsUrgent }).FirstOrDefault();
|
|
||||||
|
|
||||||
if (urgent?.IsUrgent == false || urgent?.IsSubjectUrgent == false)
|
|
||||||
{
|
|
||||||
await _visitTaskRepository.BatchUpdateNoTrackingAsync(t => t.SourceSubjectVisitId == taskInfo.SourceSubjectVisitId && t.TaskState == TaskState.Effect && t.IsAnalysisCreate == false &&
|
|
||||||
t.Id != visitTaskId && t.TrialReadingCriterionId == taskInfo.TrialReadingCriterionId, u => new VisitTask() { IsUrgent = false });
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//如果其他阅片人已经做了,说明发送了入组确认报告,第二个人做完就不发送了
|
||||||
|
|
||||||
|
//入组确认一直交给第一个人,如果第一个人重阅 还未做完,第二个人先做完了,此时不发
|
||||||
|
|
||||||
|
var existFirstEnrollTask = await _visitTaskRepository.Where(t => t.SourceSubjectVisitId == taskInfo.SourceSubjectVisitId && t.IsAnalysisCreate == false
|
||||||
|
&& t.ReadingTaskState == ReadingTaskState.HaveSigned && t.TrialReadingCriterionId == taskInfo.TrialReadingCriterionId).OrderBy(t => t.SignTime).FirstOrDefaultAsync();
|
||||||
|
|
||||||
|
//入组确认的医生已确定
|
||||||
|
if ((existFirstEnrollTask != null) && (taskInfo.DoctorUserId != existFirstEnrollTask.DoctorUserId))
|
||||||
|
{
|
||||||
|
isNeedSend = false;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
isNeedSend = await DealMedicalReviewTasKGenerateAndIsSendAsync(taskInfo.TrialId, isHandSend, answer, new List<Guid>() { visitTaskId }, minUserIdList);
|
||||||
|
|
||||||
|
|
||||||
|
if (answer == "是")
|
||||||
|
{
|
||||||
|
//把另外一个人的任务设置为不加急(如果项目加急是否 subject 加急是否)
|
||||||
|
var urgent = _repository.Where<SubjectVisit>(t => t.Id == taskInfo.SourceSubjectVisitId).Select(t => new { IsSubjectUrgent = t.Subject.IsUrgent, t.Trial.IsUrgent }).FirstOrDefault();
|
||||||
|
|
||||||
|
if (urgent?.IsUrgent == false || urgent?.IsSubjectUrgent == false)
|
||||||
|
{
|
||||||
|
await _visitTaskRepository.BatchUpdateNoTrackingAsync(t => t.SourceSubjectVisitId == taskInfo.SourceSubjectVisitId && t.TaskState == TaskState.Effect && t.IsAnalysisCreate == false &&
|
||||||
|
t.Id != visitTaskId && t.TrialReadingCriterionId == taskInfo.TrialReadingCriterionId, u => new VisitTask() { IsUrgent = false });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
else if (businessScenarioEnum == EmailBusinessScenario.PDConfirmed)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
else if (businessScenarioEnum == EmailBusinessScenario.PDConfirmed)
|
|
||||||
{
|
|
||||||
|
|
||||||
|
|
||||||
//有序
|
|
||||||
|
|
||||||
if (taskInfo.IsReadingTaskViewInOrder)
|
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
||||||
|
//有序
|
||||||
|
|
||||||
//双重
|
if (taskInfo.IsReadingTaskViewInOrder)
|
||||||
if (taskInfo.ReadingType == ReadingMethod.Double)
|
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
||||||
//仲裁在访视上 就没有全局阅片 没有阅片期
|
|
||||||
if (taskInfo.ArbitrationRule == ArbitrationRule.Visit)
|
//双重
|
||||||
|
if (taskInfo.ReadingType == ReadingMethod.Double)
|
||||||
{
|
{
|
||||||
//找到 访视,裁判 所有有效任务(不可能有全局的) 访视和裁判任务的SourceSubjectVisitId 一样
|
|
||||||
var taskList = await _visitTaskRepository.Where(t => t.SourceSubjectVisitId == taskInfo.SourceSubjectVisitId && t.TrialReadingCriterionId == taskInfo.TrialReadingCriterionId && t.IsAnalysisCreate == false && t.TaskState == TaskState.Effect &&
|
|
||||||
(t.ReadingCategory == ReadingCategory.Visit || t.ReadingCategory == ReadingCategory.Judge)).ToListAsync();
|
|
||||||
|
|
||||||
|
|
||||||
//这里要求 到这里已经如果有裁判 已经生成裁判了保存数据库
|
//仲裁在访视上 就没有全局阅片 没有阅片期
|
||||||
//双人阅片,没有产生裁判 第二个人读完发
|
if (taskInfo.ArbitrationRule == ArbitrationRule.Visit)
|
||||||
if (taskList.Count == 2 && taskList.Count(t => t.ReadingTaskState == ReadingTaskState.HaveSigned && t.ReadingCategory == ReadingCategory.Visit) == 2)
|
|
||||||
{
|
{
|
||||||
|
//找到 访视,裁判 所有有效任务(不可能有全局的) 访视和裁判任务的SourceSubjectVisitId 一样
|
||||||
answer = await TranslatePdStateAsync(visitTaskId, taskInfo.ReadingCategory, taskInfo.CriterionType);
|
var taskList = await _visitTaskRepository.Where(t => t.SourceSubjectVisitId == taskInfo.SourceSubjectVisitId && t.TrialReadingCriterionId == taskInfo.TrialReadingCriterionId && t.IsAnalysisCreate == false && t.TaskState == TaskState.Effect &&
|
||||||
|
(t.ReadingCategory == ReadingCategory.Visit || t.ReadingCategory == ReadingCategory.Judge)).ToListAsync();
|
||||||
|
|
||||||
|
|
||||||
isNeedSend = await DealMedicalReviewTasKGenerateAndIsSendAsync(taskInfo.TrialId, isHandSend, answer, taskList.Select(t => t.Id).ToList(), minUserIdList);
|
//这里要求 到这里已经如果有裁判 已经生成裁判了保存数据库
|
||||||
|
//双人阅片,没有产生裁判 第二个人读完发
|
||||||
}
|
if (taskList.Count == 2 && taskList.Count(t => t.ReadingTaskState == ReadingTaskState.HaveSigned && t.ReadingCategory == ReadingCategory.Visit) == 2)
|
||||||
//双人 产生裁判,并且裁判完成 发
|
|
||||||
else if (taskList.Count == 3 && taskList.Count(t => t.ReadingTaskState == ReadingTaskState.HaveSigned) == 3 && taskList.Where(t => t.ReadingCategory == ReadingCategory.Judge).Count() == 1)
|
|
||||||
{
|
|
||||||
var judgeResultId = taskList.Where(t => t.ReadingCategory == ReadingCategory.Judge).First().JudgeResultTaskId.Value;
|
|
||||||
answer = await TranslatePdStateAsync(judgeResultId, ReadingCategory.Visit, taskInfo.CriterionType);
|
|
||||||
|
|
||||||
isNeedSend = await DealMedicalReviewTasKGenerateAndIsSendAsync(taskInfo.TrialId, isHandSend, answer, taskList.Where(t => t.ReadingCategory == ReadingCategory.Judge).Select(t => t.Id).ToList(), minUserIdList);
|
|
||||||
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
isNeedSend = false;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
//仲裁在阅片期
|
|
||||||
else if (taskInfo.ArbitrationRule == ArbitrationRule.Reading)
|
|
||||||
{
|
|
||||||
//是访视任务 不可能是裁判任务(访视上不会生成裁判),也不会是全局任务(全局任务 SourceSubjectVisitId=null )
|
|
||||||
if (taskInfo.SourceSubjectVisitId != null)
|
|
||||||
{
|
|
||||||
|
|
||||||
//访视类型的任务 根本就不需要发送邮件
|
|
||||||
|
|
||||||
isNeedSend = false;
|
|
||||||
|
|
||||||
}
|
|
||||||
//是全局任务 或者全局的裁判任务 (如果是全局任务,那么此时裁判任务已经生成)
|
|
||||||
else if (taskInfo.SouceReadModuleId != null)
|
|
||||||
{
|
|
||||||
var taskList = await _visitTaskRepository.Where(t => t.TrialReadingCriterionId == taskInfo.TrialReadingCriterionId && t.IsAnalysisCreate == false && t.TaskState == TaskState.Effect && t.SouceReadModuleId == taskInfo.SouceReadModuleId
|
|
||||||
&& (t.ReadingCategory == ReadingCategory.Global || t.ReadingCategory == ReadingCategory.Judge)).ToListAsync();
|
|
||||||
|
|
||||||
//两个全局没有裁判
|
|
||||||
if (taskList.Count == 2 && taskList.Count(t => t.ReadingTaskState == ReadingTaskState.HaveSigned && t.ReadingCategory == ReadingCategory.Global) == 2)
|
|
||||||
{
|
{
|
||||||
|
|
||||||
answer = await TranslatePdStateAsync(visitTaskId, taskInfo.ReadingCategory, taskInfo.CriterionType);
|
answer = await TranslatePdStateAsync(visitTaskId, taskInfo.ReadingCategory, taskInfo.CriterionType);
|
||||||
|
|
||||||
isNeedSend = await DealMedicalReviewTasKGenerateAndIsSendAsync(taskInfo.TrialId, isHandSend, answer, taskList.Select(t => t.Id).ToList(), minUserIdList);
|
|
||||||
}
|
|
||||||
//双人全局产生裁判
|
|
||||||
else if (taskList.Count == 3 && taskList.Count(t => t.ReadingTaskState == ReadingTaskState.HaveSigned) == 3 && taskList.Where(t => t.ReadingCategory == ReadingCategory.Judge).Count() == 1 && taskList.Where(t => t.ReadingCategory == ReadingCategory.Global).Count() == 2)
|
|
||||||
{
|
|
||||||
|
|
||||||
|
isNeedSend = await DealMedicalReviewTasKGenerateAndIsSendAsync(taskInfo.TrialId, isHandSend, answer, taskList.Select(t => t.Id).ToList(), minUserIdList);
|
||||||
|
|
||||||
|
}
|
||||||
|
//双人 产生裁判,并且裁判完成 发
|
||||||
|
else if (taskList.Count == 3 && taskList.Count(t => t.ReadingTaskState == ReadingTaskState.HaveSigned) == 3 && taskList.Where(t => t.ReadingCategory == ReadingCategory.Judge).Count() == 1)
|
||||||
|
{
|
||||||
var judgeResultId = taskList.Where(t => t.ReadingCategory == ReadingCategory.Judge).First().JudgeResultTaskId.Value;
|
var judgeResultId = taskList.Where(t => t.ReadingCategory == ReadingCategory.Judge).First().JudgeResultTaskId.Value;
|
||||||
answer = await TranslatePdStateAsync(judgeResultId, ReadingCategory.Global, taskInfo.CriterionType);
|
answer = await TranslatePdStateAsync(judgeResultId, ReadingCategory.Visit, taskInfo.CriterionType);
|
||||||
|
|
||||||
isNeedSend = await DealMedicalReviewTasKGenerateAndIsSendAsync(taskInfo.TrialId, isHandSend, answer, taskList.Where(t => t.ReadingCategory == ReadingCategory.Judge).Select(t => t.Id).ToList(), minUserIdList);
|
isNeedSend = await DealMedicalReviewTasKGenerateAndIsSendAsync(taskInfo.TrialId, isHandSend, answer, taskList.Where(t => t.ReadingCategory == ReadingCategory.Judge).Select(t => t.Id).ToList(), minUserIdList);
|
||||||
|
|
||||||
|
@ -647,201 +481,250 @@ namespace IRaCIS.Core.Application.Service
|
||||||
isNeedSend = false;
|
isNeedSend = false;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
//仲裁在阅片期
|
||||||
|
else if (taskInfo.ArbitrationRule == ArbitrationRule.Reading)
|
||||||
|
{
|
||||||
|
//是访视任务 不可能是裁判任务(访视上不会生成裁判),也不会是全局任务(全局任务 SourceSubjectVisitId=null )
|
||||||
|
if (taskInfo.SourceSubjectVisitId != null)
|
||||||
|
{
|
||||||
|
|
||||||
|
//访视类型的任务 根本就不需要发送邮件
|
||||||
|
|
||||||
|
isNeedSend = false;
|
||||||
|
|
||||||
|
}
|
||||||
|
//是全局任务 或者全局的裁判任务 (如果是全局任务,那么此时裁判任务已经生成)
|
||||||
|
else if (taskInfo.SouceReadModuleId != null)
|
||||||
|
{
|
||||||
|
var taskList = await _visitTaskRepository.Where(t => t.TrialReadingCriterionId == taskInfo.TrialReadingCriterionId && t.IsAnalysisCreate == false && t.TaskState == TaskState.Effect && t.SouceReadModuleId == taskInfo.SouceReadModuleId
|
||||||
|
&& (t.ReadingCategory == ReadingCategory.Global || t.ReadingCategory == ReadingCategory.Judge)).ToListAsync();
|
||||||
|
|
||||||
|
//两个全局没有裁判
|
||||||
|
if (taskList.Count == 2 && taskList.Count(t => t.ReadingTaskState == ReadingTaskState.HaveSigned && t.ReadingCategory == ReadingCategory.Global) == 2)
|
||||||
|
{
|
||||||
|
|
||||||
|
answer = await TranslatePdStateAsync(visitTaskId, taskInfo.ReadingCategory, taskInfo.CriterionType);
|
||||||
|
|
||||||
|
isNeedSend = await DealMedicalReviewTasKGenerateAndIsSendAsync(taskInfo.TrialId, isHandSend, answer, taskList.Select(t => t.Id).ToList(), minUserIdList);
|
||||||
|
}
|
||||||
|
//双人全局产生裁判
|
||||||
|
else if (taskList.Count == 3 && taskList.Count(t => t.ReadingTaskState == ReadingTaskState.HaveSigned) == 3 && taskList.Where(t => t.ReadingCategory == ReadingCategory.Judge).Count() == 1 && taskList.Where(t => t.ReadingCategory == ReadingCategory.Global).Count() == 2)
|
||||||
|
{
|
||||||
|
|
||||||
|
var judgeResultId = taskList.Where(t => t.ReadingCategory == ReadingCategory.Judge).First().JudgeResultTaskId.Value;
|
||||||
|
answer = await TranslatePdStateAsync(judgeResultId, ReadingCategory.Global, taskInfo.CriterionType);
|
||||||
|
|
||||||
|
isNeedSend = await DealMedicalReviewTasKGenerateAndIsSendAsync(taskInfo.TrialId, isHandSend, answer, taskList.Where(t => t.ReadingCategory == ReadingCategory.Judge).Select(t => t.Id).ToList(), minUserIdList);
|
||||||
|
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
isNeedSend = false;
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
//---发送PD 进展邮件中发现任务数据有问题!
|
||||||
|
throw new BusinessValidationFailedException(_localizer["TrialEmailN_PDProgressEmailTask"]);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
//---发送PD 进展邮件中发现任务数据有问题!
|
|
||||||
throw new BusinessValidationFailedException(_localizer["TrialEmailN_PDProgressEmailTask"]);
|
//---双重有序阅片 没有定义该仲裁规则处理逻辑,请联系业务和后台开发核查!
|
||||||
|
throw new BusinessValidationFailedException(_localizer["TrialEmailN_DoubleBlindedError"]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//屏蔽单重阅片添加
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
isNeedSend = false;
|
||||||
//---双重有序阅片 没有定义该仲裁规则处理逻辑,请联系业务和后台开发核查!
|
return string.Empty;
|
||||||
throw new BusinessValidationFailedException(_localizer["TrialEmailN_DoubleBlindedError"]);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#region 发邮件屏蔽单重的
|
||||||
|
////单重
|
||||||
|
//else if (taskInfo.ReadingType == ReadingMethod.Single)
|
||||||
|
//{
|
||||||
|
// //仲裁在访视上 或者在阅片期
|
||||||
|
// if (taskInfo.ArbitrationRule != ArbitrationRule.None)
|
||||||
|
// {
|
||||||
|
|
||||||
|
//---单重有序阅片配置有误(不应该有仲裁对象配置),请核查!
|
||||||
|
// throw new BusinessValidationFailedException(_localizer["TrialEmailN_SingleBlindedSet"]);
|
||||||
|
// }
|
||||||
|
|
||||||
|
|
||||||
|
// //要求PD 确认的访视 是截止访视 还是非截止访视(根据该访视有没有配置阅片期来判断)
|
||||||
|
|
||||||
|
// if (taskInfo.ReadingCategory == ReadingCategory.Visit)
|
||||||
|
// {
|
||||||
|
// //存在阅片期 那么就是截止访视
|
||||||
|
// if (await _repository.Where<ReadModule>(t => t.TrialReadingCriterionId == taskInfo.TrialReadingCriterionId && t.SubjectVisitId == taskInfo.SourceSubjectVisitId && t.ReadingSetType == ReadingSetType.ImageReading).AnyAsync())
|
||||||
|
// {
|
||||||
|
// isNeedSend = false;
|
||||||
|
// }
|
||||||
|
// else//非截止访视 在访视读完后,发送
|
||||||
|
// {
|
||||||
|
// answer = await TranslatePdStateAsync(visitTaskId, ReadingCategory.Visit, taskInfo.CriterionType);
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// //截止访视 在访视读完,并完成全局阅片后发送全局的结果
|
||||||
|
// else if (taskInfo.ReadingCategory == ReadingCategory.Global)
|
||||||
|
// {
|
||||||
|
// answer = await TranslatePdStateAsync(visitTaskId, ReadingCategory.Global, taskInfo.CriterionType);
|
||||||
|
// }
|
||||||
|
// else
|
||||||
|
// {
|
||||||
|
//---单重有序阅片 该类型的任务不应进入此处逻辑,请联系后台开发核查!
|
||||||
|
// throw new BusinessValidationFailedException(_localizer["TrialEmailN_SingleBlindedSequenced"]);
|
||||||
|
// }
|
||||||
|
|
||||||
|
// isNeedSend = await DealMedicalReviewTasKGenerateAndIsSendAsync(taskInfo.TrialId, isHandSend, answer, new List<Guid>() { visitTaskId }, minUserIdList);
|
||||||
|
|
||||||
|
|
||||||
|
//}
|
||||||
|
//else
|
||||||
|
//{
|
||||||
|
//---有序阅片配置有误(应为单重或者双重阅片),请核查!
|
||||||
|
// throw new BusinessValidationFailedException(_localizer["TrialEmailN_BlindedSequencedReading"]);
|
||||||
|
//}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
//屏蔽无序阅片添加
|
||||||
//屏蔽单重阅片添加
|
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
isNeedSend = false;
|
isNeedSend = false;
|
||||||
return string.Empty;
|
return string.Empty;
|
||||||
}
|
}
|
||||||
|
|
||||||
#region 发邮件屏蔽单重的
|
#region 发送邮件屏蔽无序的
|
||||||
////单重
|
// //无序
|
||||||
//else if (taskInfo.ReadingType == ReadingMethod.Single)
|
//else
|
||||||
//{
|
//{
|
||||||
// //仲裁在访视上 或者在阅片期
|
// //单重
|
||||||
// if (taskInfo.ArbitrationRule != ArbitrationRule.None)
|
|
||||||
// {
|
|
||||||
|
|
||||||
//---单重有序阅片配置有误(不应该有仲裁对象配置),请核查!
|
|
||||||
// throw new BusinessValidationFailedException(_localizer["TrialEmailN_SingleBlindedSet"]);
|
// if (taskInfo.ReadingType == ReadingMethod.Single && taskInfo.ArbitrationRule == ArbitrationRule.None)
|
||||||
|
// {
|
||||||
|
// answer = await TranslatePdStateAsync(visitTaskId, taskInfo.ReadingCategory, taskInfo.CriterionType);
|
||||||
|
|
||||||
|
// isNeedSend = await DealMedicalReviewTasKGenerateAndIsSendAsync(taskInfo.TrialId, isHandSend, answer, new List<Guid>() { visitTaskId }, minUserIdList);
|
||||||
// }
|
// }
|
||||||
|
// //双重 截止访视只在阅片期的时候存在 要求PD确认的访视 肯定是非截止访视
|
||||||
|
// else if (taskInfo.ReadingType == ReadingMethod.Double && taskInfo.ArbitrationRule == ArbitrationRule.Visit)
|
||||||
// //要求PD 确认的访视 是截止访视 还是非截止访视(根据该访视有没有配置阅片期来判断)
|
|
||||||
|
|
||||||
// if (taskInfo.ReadingCategory == ReadingCategory.Visit)
|
|
||||||
// {
|
// {
|
||||||
// //存在阅片期 那么就是截止访视
|
// //在两位阅片人读完访视后,如果有裁判者等裁判读完,如果无裁判则等第二个人的读完
|
||||||
// if (await _repository.Where<ReadModule>(t => t.TrialReadingCriterionId == taskInfo.TrialReadingCriterionId && t.SubjectVisitId == taskInfo.SourceSubjectVisitId && t.ReadingSetType == ReadingSetType.ImageReading).AnyAsync())
|
|
||||||
|
// var taskList = await _visitTaskRepository.Where(t => t.SourceSubjectVisitId == taskInfo.SourceSubjectVisitId && t.TrialReadingCriterionId == taskInfo.TrialReadingCriterionId && t.IsAnalysisCreate == false && t.TaskState == TaskState.Effect
|
||||||
|
// && (t.ReadingCategory == ReadingCategory.Visit || t.ReadingCategory == ReadingCategory.Judge)).ToListAsync();
|
||||||
|
|
||||||
|
// //这里要求 到这里已经如果有裁判 已经生成裁判了保存数据库
|
||||||
|
// if (taskList.Count == 2 && taskList.Count(t => t.ReadingTaskState == ReadingTaskState.HaveSigned && t.ReadingCategory == ReadingCategory.Visit) == 2)
|
||||||
|
// {
|
||||||
|
|
||||||
|
// answer = await TranslatePdStateAsync(visitTaskId, taskInfo.ReadingCategory, taskInfo.CriterionType);
|
||||||
|
|
||||||
|
// isNeedSend = await DealMedicalReviewTasKGenerateAndIsSendAsync(taskInfo.TrialId, isHandSend, answer, taskList.Select(t => t.Id).ToList(), minUserIdList);
|
||||||
|
// }
|
||||||
|
// else if (taskList.Count == 3 && taskList.Count(t => t.ReadingTaskState == ReadingTaskState.HaveSigned) == 3 && taskList.Where(t => t.ReadingCategory == ReadingCategory.Judge).Count() == 1)
|
||||||
|
// {
|
||||||
|
// var judgeResultId = taskList.Where(t => t.ReadingCategory == ReadingCategory.Judge).First().JudgeResultTaskId.Value;
|
||||||
|
// answer = await TranslatePdStateAsync(judgeResultId, ReadingCategory.Visit, taskInfo.CriterionType);
|
||||||
|
|
||||||
|
// isNeedSend = await DealMedicalReviewTasKGenerateAndIsSendAsync(taskInfo.TrialId, isHandSend, answer, taskList.Where(t => t.ReadingCategory == ReadingCategory.Judge).Select(t => t.Id).ToList(), minUserIdList);
|
||||||
|
|
||||||
|
|
||||||
|
// }
|
||||||
|
// else
|
||||||
// {
|
// {
|
||||||
// isNeedSend = false;
|
// isNeedSend = false;
|
||||||
// }
|
// }
|
||||||
// else//非截止访视 在访视读完后,发送
|
|
||||||
// {
|
|
||||||
// answer = await TranslatePdStateAsync(visitTaskId, ReadingCategory.Visit, taskInfo.CriterionType);
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// //截止访视 在访视读完,并完成全局阅片后发送全局的结果
|
|
||||||
// else if (taskInfo.ReadingCategory == ReadingCategory.Global)
|
|
||||||
// {
|
|
||||||
// answer = await TranslatePdStateAsync(visitTaskId, ReadingCategory.Global, taskInfo.CriterionType);
|
|
||||||
// }
|
// }
|
||||||
// else
|
// else
|
||||||
// {
|
// {
|
||||||
//---单重有序阅片 该类型的任务不应进入此处逻辑,请联系后台开发核查!
|
//---无序阅片配置有误(应为单重无仲裁对象,双重针对访视仲裁),请核查!
|
||||||
// throw new BusinessValidationFailedException(_localizer["TrialEmailN_SingleBlindedSequenced"]);
|
// throw new BusinessValidationFailedException(_localizer["TrialEmailN_UnblindedSequencedReading"]);
|
||||||
// }
|
// }
|
||||||
|
|
||||||
// isNeedSend = await DealMedicalReviewTasKGenerateAndIsSendAsync(taskInfo.TrialId, isHandSend, answer, new List<Guid>() { visitTaskId }, minUserIdList);
|
|
||||||
|
|
||||||
|
|
||||||
//}
|
|
||||||
//else
|
|
||||||
//{
|
|
||||||
//---有序阅片配置有误(应为单重或者双重阅片),请核查!
|
|
||||||
// throw new BusinessValidationFailedException(_localizer["TrialEmailN_BlindedSequencedReading"]);
|
|
||||||
//}
|
//}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
//屏蔽无序阅片添加
|
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
isNeedSend = false;
|
isNeedSend = false;
|
||||||
return string.Empty;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#region 发送邮件屏蔽无序的
|
|
||||||
// //无序
|
|
||||||
//else
|
|
||||||
//{
|
|
||||||
// //单重
|
|
||||||
|
|
||||||
|
|
||||||
// if (taskInfo.ReadingType == ReadingMethod.Single && taskInfo.ArbitrationRule == ArbitrationRule.None)
|
|
||||||
// {
|
|
||||||
// answer = await TranslatePdStateAsync(visitTaskId, taskInfo.ReadingCategory, taskInfo.CriterionType);
|
|
||||||
|
|
||||||
// isNeedSend = await DealMedicalReviewTasKGenerateAndIsSendAsync(taskInfo.TrialId, isHandSend, answer, new List<Guid>() { visitTaskId }, minUserIdList);
|
|
||||||
// }
|
|
||||||
// //双重 截止访视只在阅片期的时候存在 要求PD确认的访视 肯定是非截止访视
|
|
||||||
// else if (taskInfo.ReadingType == ReadingMethod.Double && taskInfo.ArbitrationRule == ArbitrationRule.Visit)
|
|
||||||
// {
|
|
||||||
// //在两位阅片人读完访视后,如果有裁判者等裁判读完,如果无裁判则等第二个人的读完
|
|
||||||
|
|
||||||
// var taskList = await _visitTaskRepository.Where(t => t.SourceSubjectVisitId == taskInfo.SourceSubjectVisitId && t.TrialReadingCriterionId == taskInfo.TrialReadingCriterionId && t.IsAnalysisCreate == false && t.TaskState == TaskState.Effect
|
|
||||||
// && (t.ReadingCategory == ReadingCategory.Visit || t.ReadingCategory == ReadingCategory.Judge)).ToListAsync();
|
|
||||||
|
|
||||||
// //这里要求 到这里已经如果有裁判 已经生成裁判了保存数据库
|
|
||||||
// if (taskList.Count == 2 && taskList.Count(t => t.ReadingTaskState == ReadingTaskState.HaveSigned && t.ReadingCategory == ReadingCategory.Visit) == 2)
|
|
||||||
// {
|
|
||||||
|
|
||||||
// answer = await TranslatePdStateAsync(visitTaskId, taskInfo.ReadingCategory, taskInfo.CriterionType);
|
|
||||||
|
|
||||||
// isNeedSend = await DealMedicalReviewTasKGenerateAndIsSendAsync(taskInfo.TrialId, isHandSend, answer, taskList.Select(t => t.Id).ToList(), minUserIdList);
|
|
||||||
// }
|
|
||||||
// else if (taskList.Count == 3 && taskList.Count(t => t.ReadingTaskState == ReadingTaskState.HaveSigned) == 3 && taskList.Where(t => t.ReadingCategory == ReadingCategory.Judge).Count() == 1)
|
|
||||||
// {
|
|
||||||
// var judgeResultId = taskList.Where(t => t.ReadingCategory == ReadingCategory.Judge).First().JudgeResultTaskId.Value;
|
|
||||||
// answer = await TranslatePdStateAsync(judgeResultId, ReadingCategory.Visit, taskInfo.CriterionType);
|
|
||||||
|
|
||||||
// isNeedSend = await DealMedicalReviewTasKGenerateAndIsSendAsync(taskInfo.TrialId, isHandSend, answer, taskList.Where(t => t.ReadingCategory == ReadingCategory.Judge).Select(t => t.Id).ToList(), minUserIdList);
|
|
||||||
|
|
||||||
|
|
||||||
// }
|
|
||||||
// else
|
|
||||||
// {
|
|
||||||
// isNeedSend = false;
|
|
||||||
// }
|
|
||||||
|
|
||||||
// }
|
|
||||||
// else
|
|
||||||
// {
|
|
||||||
//---无序阅片配置有误(应为单重无仲裁对象,双重针对访视仲裁),请核查!
|
|
||||||
// throw new BusinessValidationFailedException(_localizer["TrialEmailN_UnblindedSequencedReading"]);
|
|
||||||
// }
|
|
||||||
|
|
||||||
//}
|
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
isNeedSend = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
|
|
||||||
#region MiniWord 组织字典 发送
|
#region MiniWord 组织字典 发送
|
||||||
|
|
||||||
|
|
||||||
if (emailStoreMode == EmailStoreSendMode.NotStoreLocalOnlySentEmail)
|
if (emailStoreMode == EmailStoreSendMode.NotStoreLocalOnlySentEmail)
|
||||||
{
|
|
||||||
|
|
||||||
var phyPath = FileStoreHelper.GetPhysicalFilePath(_hostEnvironment, sendFileRelativePath);
|
|
||||||
|
|
||||||
|
|
||||||
//先预先生成了邮件,发送预先生成的邮件
|
|
||||||
sendEmailConfig.EmailAttachMentConfigList.Add(new EmailAttachMentConfig()
|
|
||||||
{
|
{
|
||||||
FileName = $"{taskInfo.SubjectCode}_{Path.GetFileNameWithoutExtension(_userInfo.IsEn_Us ? emailConfig.AttachName : emailConfig.AttachNameCN)}.pdf",
|
|
||||||
|
|
||||||
FileStream = File.OpenRead(phyPath),
|
var phyPath = FileStoreHelper.GetPhysicalFilePath(_hostEnvironment, sendFileRelativePath);
|
||||||
});
|
|
||||||
|
var attachPrefix = $"{taskInfo.SubjectCode}";
|
||||||
|
|
||||||
|
//先预先生成了邮件,发送预先生成的邮件
|
||||||
|
sendEmailConfig.EmailAttachMentConfigList.Add(new EmailAttachMentConfig()
|
||||||
|
{
|
||||||
|
FileName = $"{attachPrefix}_{Path.GetFileNameWithoutExtension(_userInfo.IsEn_Us ? trialEmailConfig.AttachName : trialEmailConfig!.AttachNameCN)}.pdf",
|
||||||
|
|
||||||
|
FileStream = File.OpenRead(phyPath),
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
await SendEmailHelper.SendEmailAsync(sendEmailConfig);
|
await SendEmailHelper.SendEmailAsync(sendEmailConfig);
|
||||||
|
|
||||||
return string.Empty;
|
return string.Empty;
|
||||||
}
|
}
|
||||||
|
|
||||||
var value = new Dictionary<string, object>()
|
var value = new Dictionary<string, object>()
|
||||||
{
|
{
|
||||||
["SponsorName"] = taskInfo.SponsorName,
|
["SponsorName"] = taskInfo.SponsorName,
|
||||||
["ResearchProgramNo"] = taskInfo.ResearchProgramNo,
|
["ResearchProgramNo"] = taskInfo.ResearchProgramNo,
|
||||||
["TrialSiteCode"] = taskInfo.TrialSiteCode,
|
["TrialSiteCode"] = taskInfo.TrialSiteCode,
|
||||||
["SubjectCode"] = taskInfo.SubjectCode,
|
["SubjectCode"] = taskInfo.SubjectCode,
|
||||||
["VisitName"] = taskInfo.SourceSubjectVisitId != null ? taskInfo.VisitName : taskInfo.ModuleVisitName,
|
["VisitName"] = taskInfo.SourceSubjectVisitId != null ? taskInfo.VisitName : taskInfo.ModuleVisitName,
|
||||||
["EarliestScanDate"] = taskInfo.SourceSubjectVisitId != null ? taskInfo.VisitEarliestScanDate?.ToString("yyyy-MM-dd") : taskInfo.ModuleEarliestScanDate?.ToString("yyyy-MM-dd"),
|
["EarliestScanDate"] = taskInfo.SourceSubjectVisitId != null ? taskInfo.VisitEarliestScanDate?.ToString("yyyy-MM-dd") : taskInfo.ModuleEarliestScanDate?.ToString("yyyy-MM-dd"),
|
||||||
["SignTime"] = taskInfo.SignTime?.ToString("yyyy-MM-dd"),
|
["SignTime"] = taskInfo.SignTime?.ToString("yyyy-MM-dd"),
|
||||||
["Result"] = answer
|
["Result"] = answer
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
var (serverFilePath, relativePath, fileRealName) = FileStoreHelper.GetSubjectEnrollConfirmOrPDEmailPath(_hostEnvironment, Path.GetFileName(path), taskInfo.TrialId, taskInfo.SiteId, taskInfo.SubjectId, true);
|
var path = FileStoreHelper.GetPhysicalFilePath(_hostEnvironment, _userInfo.IsEn_Us ? trialEmailConfig.AttachPath : trialEmailConfig.AttachCNPath);
|
||||||
|
|
||||||
if (emailStoreMode == EmailStoreSendMode.StoreLocalSend || emailStoreMode == EmailStoreSendMode.OnlyStoreLocalNotSentEmail)
|
var (serverFilePath, relativePath, fileRealName) = FileStoreHelper.GetSubjectEnrollConfirmOrPDEmailPath(_hostEnvironment, Path.GetFileName(path), taskInfo.TrialId, taskInfo.SiteId, taskInfo.SubjectId, true);
|
||||||
{
|
|
||||||
|
|
||||||
MemoryStream wordMemoryStream = new MemoryStream();
|
if (emailStoreMode == EmailStoreSendMode.StoreLocalSend || emailStoreMode == EmailStoreSendMode.OnlyStoreLocalNotSentEmail)
|
||||||
|
{
|
||||||
|
|
||||||
|
MemoryStream wordMemoryStream = new MemoryStream();
|
||||||
|
|
||||||
|
|
||||||
MiniSoftware.MiniWord.SaveAsByTemplate(wordMemoryStream, path, value);
|
MiniSoftware.MiniWord.SaveAsByTemplate(wordMemoryStream, path, value);
|
||||||
|
|
||||||
|
|
||||||
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
|
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
|
||||||
|
@ -854,8 +737,8 @@ namespace IRaCIS.Core.Application.Service
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
var wordStoreServerPath = Path.Combine(Path.GetDirectoryName(serverFilePath), Path.GetFileNameWithoutExtension(serverFilePath)+".docx");
|
var wordStoreServerPath = Path.Combine(Path.GetDirectoryName(serverFilePath), Path.GetFileNameWithoutExtension(serverFilePath) + ".docx");
|
||||||
|
|
||||||
using (FileStream fileStream = new FileStream(wordStoreServerPath, FileMode.Create, FileAccess.Write))
|
using (FileStream fileStream = new FileStream(wordStoreServerPath, FileMode.Create, FileAccess.Write))
|
||||||
{
|
{
|
||||||
wordMemoryStream.WriteTo(fileStream);
|
wordMemoryStream.WriteTo(fileStream);
|
||||||
|
@ -873,13 +756,13 @@ namespace IRaCIS.Core.Application.Service
|
||||||
{
|
{
|
||||||
isNeedSend = false;
|
isNeedSend = false;
|
||||||
|
|
||||||
return relativePath;
|
return relativePath;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//正常的即时生成邮件 并发送邮件
|
//正常的即时生成邮件 并发送邮件
|
||||||
if (isNeedSend)
|
if (isNeedSend)
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
||||||
MemoryStream wordMemoryStream = new MemoryStream();
|
MemoryStream wordMemoryStream = new MemoryStream();
|
||||||
|
@ -893,7 +776,7 @@ namespace IRaCIS.Core.Application.Service
|
||||||
Document document = new Document();
|
Document document = new Document();
|
||||||
document.LoadFromStream(wordMemoryStream, FileFormat.Docx);
|
document.LoadFromStream(wordMemoryStream, FileFormat.Docx);
|
||||||
document.SaveToStream(pdfMemoryStream, FileFormat.PDF);
|
document.SaveToStream(pdfMemoryStream, FileFormat.PDF);
|
||||||
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -919,23 +802,28 @@ namespace IRaCIS.Core.Application.Service
|
||||||
{
|
{
|
||||||
FileName = $"{taskInfo.SubjectCode}_{Path.GetFileNameWithoutExtension(_userInfo.IsEn_Us ? trialEmailConfig.AttachName : trialEmailConfig.AttachNameCN)}.pdf",
|
FileName = $"{taskInfo.SubjectCode}_{Path.GetFileNameWithoutExtension(_userInfo.IsEn_Us ? trialEmailConfig.AttachName : trialEmailConfig.AttachNameCN)}.pdf",
|
||||||
|
|
||||||
FileStream = pdfMemoryStream
|
FileStream = pdfMemoryStream
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
await SendEmailHelper.SendEmailAsync(sendEmailConfig);
|
await SendEmailHelper.SendEmailAsync(sendEmailConfig);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
return string.Empty;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return string.Empty;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
return string.Empty;
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -46,6 +46,7 @@ namespace IRaCIS.Core.Domain.Share
|
||||||
|
|
||||||
public enum EmailBusinessScenario
|
public enum EmailBusinessScenario
|
||||||
{
|
{
|
||||||
|
None = -1,
|
||||||
EnrollConfirmed = 1,
|
EnrollConfirmed = 1,
|
||||||
|
|
||||||
PDConfirmed = 2,
|
PDConfirmed = 2,
|
||||||
|
|
|
@ -121,7 +121,10 @@ public static class StaticData
|
||||||
public static readonly string UploadFileFolder = "UploadFile";
|
public static readonly string UploadFileFolder = "UploadFile";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static class EmailSend
|
||||||
|
{
|
||||||
|
public static string EmailNamePlaceholder = "EmailNamePlaceholder";
|
||||||
|
}
|
||||||
|
|
||||||
public static class TrialOpt
|
public static class TrialOpt
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue