提交中心调研

Uat_Study
hang 2023-08-17 14:54:44 +08:00
parent b9ccf4bb12
commit 5e743b162d
5 changed files with 124 additions and 191 deletions

View File

@ -938,96 +938,6 @@ namespace IRaCIS.Core.API.Controllers
}
[HttpPost]
[UnitOfWork]
public async Task<IResponseOutput> UploadTrialSiteSurveyUser(Guid trialId,
[FromServices] IRepository<TrialSite> _trialSiteRepository,
[FromServices] IRepository<UserType> _usertypeRepository,
[FromServices] ITrialSiteSurveyService _trialSiteSurveyService)
{
var (serverFilePath, relativePath, fileName) = (string.Empty, string.Empty, string.Empty);
await FileUploadAsync(async (realFileName) =>
{
fileName = realFileName;
if (!fileName.EndsWith(".xlsx", StringComparison.OrdinalIgnoreCase))
{
throw new BusinessValidationFailedException("请用提供格式的模板excel上传需要处理的数据");
}
(serverFilePath, relativePath) = FileStoreHelper.GetTrialSiteSurveyFilePath(_hostEnvironment, fileName, trialId);
return serverFilePath;
});
//去掉空白行
var excelList = MiniExcel.Query<SiteSurveyUserImportDto>(serverFilePath).ToList()
.Where(t => !(string.IsNullOrWhiteSpace(t.TrialSiteCode) && string.IsNullOrWhiteSpace(t.FirstName) && string.IsNullOrWhiteSpace(t.LastName)) && string.IsNullOrWhiteSpace(t.Email)
&& string.IsNullOrWhiteSpace(t.Phone) && string.IsNullOrWhiteSpace(t.UserTypeStr) && string.IsNullOrWhiteSpace(t.OrganizationName));
if (excelList.Any(t => string.IsNullOrWhiteSpace(t.TrialSiteCode) || string.IsNullOrWhiteSpace(t.FirstName) || string.IsNullOrWhiteSpace(t.LastName) || string.IsNullOrWhiteSpace(t.Email) || string.IsNullOrWhiteSpace(t.UserTypeStr)))
{
throw new BusinessValidationFailedException("请确保Excel中 每一行的 中心编号,姓名,邮箱,用户类型数据记录完整再进行上传");
}
var siteCodeList = excelList.Select(t => t.TrialSiteCode.Trim()).Distinct().ToList();
if (_trialSiteRepository.Where(t => siteCodeList.Contains(t.TrialSiteCode)).Count() != siteCodeList.Count)
{
throw new BusinessValidationFailedException("在项目中未找到该Excel中部分或全部中心");
}
if (excelList.GroupBy(t => new { t.UserTypeStr, t.Email }).Any(g => g.Count() > 1))
{
throw new BusinessValidationFailedException("同一邮箱,同一用户类型,只能生成一个账户,请核查Excel数据");
}
if (excelList.Any(t => t.Email.Contains("@")))
{
throw new BusinessValidationFailedException("有邮箱不符合邮箱格式,请核查Excel数据");
}
var generateUserTypeList = new List<string>() { "CRC", "SR", "CRA" };
if (excelList.Any(t => !generateUserTypeList.Contains(t.UserTypeStr.ToUpper())))
{
throw new BusinessValidationFailedException("用户类型仅能为 CRC,SR,CRA 请核查Excel数据");
}
//处理好 用户类型 和用户类型枚举
var sysUserTypeList = _usertypeRepository.Where(t => t.UserTypeEnum == UserTypeEnum.CRA || t.UserTypeEnum == UserTypeEnum.ClinicalResearchCoordinator || t.UserTypeEnum == UserTypeEnum.SR).Select(t => new { UserTypeId = t.Id, t.UserTypeEnum }).ToList();
var siteList= _trialSiteRepository.Where(t=>t.TrialId==trialId && siteCodeList.Contains(t.TrialSiteCode)).Select(t=>new {t.TrialSiteCode,t.SiteId}).ToList();
foreach (var item in excelList)
{
switch (item.UserTypeStr.ToUpper())
{
case "CRC":
item.UserTypeId = sysUserTypeList.FirstOrDefault(t => t.UserTypeEnum == UserTypeEnum.ClinicalResearchCoordinator).UserTypeId;
item.UserTypeEnum = UserTypeEnum.ClinicalResearchCoordinator;
break;
case "CRA":
item.UserTypeId = sysUserTypeList.FirstOrDefault(t => t.UserTypeEnum == UserTypeEnum.CRA).UserTypeId;
item.UserTypeEnum = UserTypeEnum.CRA;
break;
case "SR":
item.UserTypeId = sysUserTypeList.FirstOrDefault(t => t.UserTypeEnum == UserTypeEnum.SR).UserTypeId;
item.UserTypeEnum = UserTypeEnum.SR;
break;
}
item.SiteId = siteList.FirstOrDefault(t => t.TrialSiteCode.ToUpper() == item.TrialSiteCode.ToUpper()).SiteId;
}
await _trialSiteSurveyService.ImportGenerateAccountAndJoinTrialAsync(trialId, excelList.ToList());
return ResponseOutput.Ok();
}
}
@ -1123,6 +1033,100 @@ namespace IRaCIS.Core.API.Controllers
_userInfo = userInfo;
}
[HttpPost, Route("TrialSiteSurvey/UploadTrialSiteSurveyUser")]
[DisableFormValueModelBinding]
[UnitOfWork]
public async Task<IResponseOutput> UploadTrialSiteSurveyUser(Guid trialId, string baseUrl, string routeUrl,
[FromServices] IRepository<TrialSite> _trialSiteRepository,
[FromServices] IRepository<UserType> _usertypeRepository,
[FromServices] ITrialSiteSurveyService _trialSiteSurveyService)
{
var (serverFilePath, relativePath, fileName) = (string.Empty, string.Empty, string.Empty);
await FileUploadAsync(async (realFileName) =>
{
fileName = realFileName;
if (!fileName.EndsWith(".xlsx", StringComparison.OrdinalIgnoreCase))
{
throw new BusinessValidationFailedException("请用提供格式的模板excel上传需要处理的数据");
}
(serverFilePath, relativePath) = FileStoreHelper.GetTrialSiteSurveyFilePath(_hostEnvironment, fileName, trialId);
return serverFilePath;
});
//去掉空白行
var excelList = MiniExcel.Query<SiteSurveyUserImportDto>(serverFilePath).ToList()
.Where(t => !(string.IsNullOrWhiteSpace(t.TrialSiteCode) && string.IsNullOrWhiteSpace(t.FirstName) && string.IsNullOrWhiteSpace(t.LastName) && string.IsNullOrWhiteSpace(t.Email)
&& string.IsNullOrWhiteSpace(t.Phone) && string.IsNullOrWhiteSpace(t.UserTypeStr) && string.IsNullOrWhiteSpace(t.OrganizationName))).ToList();
if (excelList.Any(t => string.IsNullOrWhiteSpace(t.TrialSiteCode) || string.IsNullOrWhiteSpace(t.FirstName) || string.IsNullOrWhiteSpace(t.LastName) || string.IsNullOrWhiteSpace(t.Email) || string.IsNullOrWhiteSpace(t.UserTypeStr)))
{
throw new BusinessValidationFailedException("请确保Excel中 每一行的 中心编号,姓名,邮箱,用户类型数据记录完整再进行上传");
}
var siteCodeList = excelList.Select(t => t.TrialSiteCode.Trim().ToUpper()).Distinct().ToList();
if (_trialSiteRepository.Where(t => t.TrialId==trialId && siteCodeList.Contains(t.TrialSiteCode.ToUpper())).Count() != siteCodeList.Count)
{
throw new BusinessValidationFailedException("在项目中未找到该Excel中部分或全部中心");
}
if (excelList.GroupBy(t => new { t.UserTypeStr, t.Email }).Any(g => g.Count() > 1))
{
throw new BusinessValidationFailedException("同一邮箱,同一用户类型,只能生成一个账户,请核查Excel数据");
}
if (excelList.Any(t => !t.Email.Contains("@")))
{
throw new BusinessValidationFailedException("有邮箱不符合邮箱格式,请核查Excel数据");
}
var generateUserTypeList = new List<string>() { "CRC", "SR", "CRA" };
if (excelList.Any(t => !generateUserTypeList.Contains(t.UserTypeStr.ToUpper())))
{
throw new BusinessValidationFailedException("用户类型仅能为 CRC,SR,CRA 请核查Excel数据");
}
//处理好 用户类型 和用户类型枚举
var sysUserTypeList = _usertypeRepository.Where(t => t.UserTypeEnum == UserTypeEnum.CRA || t.UserTypeEnum == UserTypeEnum.ClinicalResearchCoordinator || t.UserTypeEnum == UserTypeEnum.SR).Select(t => new { UserTypeId = t.Id, t.UserTypeEnum }).ToList();
var siteList = _trialSiteRepository.Where(t => t.TrialId == trialId && siteCodeList.Contains(t.TrialSiteCode)).Select(t => new { t.TrialSiteCode, t.SiteId }).ToList();
foreach (var item in excelList)
{
switch (item.UserTypeStr.ToUpper())
{
case "CRC":
item.UserTypeId = sysUserTypeList.FirstOrDefault(t => t.UserTypeEnum == UserTypeEnum.ClinicalResearchCoordinator).UserTypeId;
item.UserTypeEnum = UserTypeEnum.ClinicalResearchCoordinator;
break;
case "CRA":
item.UserTypeId = sysUserTypeList.FirstOrDefault(t => t.UserTypeEnum == UserTypeEnum.CRA).UserTypeId;
item.UserTypeEnum = UserTypeEnum.CRA;
break;
case "SR":
item.UserTypeId = sysUserTypeList.FirstOrDefault(t => t.UserTypeEnum == UserTypeEnum.SR).UserTypeId;
item.UserTypeEnum = UserTypeEnum.SR;
break;
}
item.SiteId = siteList.FirstOrDefault(t => t.TrialSiteCode.ToUpper() == item.TrialSiteCode.ToUpper()).SiteId;
}
await _trialSiteSurveyService.ImportGenerateAccountAndJoinTrialAsync(trialId, baseUrl, routeUrl, excelList.ToList());
return ResponseOutput.Ok();
}
/// <summary> 缩略图 </summary>
[AllowAnonymous]
[HttpGet("Common/LocalFilePreview")]

View File

@ -137,12 +137,12 @@ namespace IRaCIS.Core.Application.Contracts
public class SiteSurveyUserImportDto
{
public string TrialSiteCode { get;set; }
public string FirstName { get; set; }
public string LastName { get; set; }
public string Email { get; set; }
public string Phone { get; set; }
public string OrganizationName { get; set; }
public string TrialSiteCode { get;set; }=string.Empty;
public string FirstName { get; set; } = string.Empty;
public string LastName { get; set; } = string.Empty;
public string Email { get; set; } = string.Empty;
public string Phone { get; set; } = string.Empty;
public string OrganizationName { get; set; } = string.Empty;
[ExcelColumnName("UserType")]
public string UserTypeStr { get; set; }

View File

@ -21,6 +21,6 @@ namespace IRaCIS.Core.Application.Contracts
//IResponseOutput TrialSurveySubmmit(Guid trialId, Guid trialSiteSurveyId);
Task<IResponseOutput> VerifySendCode(LoginDto userInfo, [FromServices] ITokenService _tokenService);
Task ImportGenerateAccountAndJoinTrialAsync(Guid trialId, List<SiteSurveyUserImportDto> list);
Task ImportGenerateAccountAndJoinTrialAsync(Guid trialId, string baseUrl,string rootUrl, List<SiteSurveyUserImportDto> list);
}
}

View File

@ -838,14 +838,16 @@ namespace IRaCIS.Core.Application.Contracts
//判断TrialUser中是否存在 不存在就插入
if (!await _trialUserRepository.AnyAsync(t => t.TrialId == trialId && t.UserId == userId, true))
var findTrialUser = await _trialUserRepository.FirstOrDefaultAsync(t => t.TrialId == trialId && t.UserId == userId, true);
if (findTrialUser==null)
{
await _repository.AddAsync(new TrialUser() { TrialId = trialId, UserId = userId, JoinTime = DateTime.Now });
await _mailVerificationService.SiteSurveyUserJoinEmail(trialId, userId, joinCommand.BaseUrl, joinCommand.RouteUrl);
}
else
else if(findTrialUser.IsDeleted==true)
{
await _trialUserRepository.UpdatePartialFromQueryAsync(t => t.TrialId == trialId && t.UserId == userId, c => new TrialUser()
{
@ -853,13 +855,14 @@ namespace IRaCIS.Core.Application.Contracts
DeletedTime = null,
JoinTime = DateTime.Now,
});
await _mailVerificationService.SiteSurveyUserJoinEmail(trialId, userId, joinCommand.BaseUrl, joinCommand.RouteUrl);
}
if (!await _repository.AnyAsync<TrialSiteUser>(t => t.TrialId == trialId && t.UserId == userId && t.SiteId == siteId, true))
{
await _repository.AddAsync(new TrialSiteUser() { TrialId = trialId, SiteId = siteId, UserId = userId });
await _mailVerificationService.SiteSurveyUserJoinEmail(trialId, userId, joinCommand.BaseUrl, joinCommand.RouteUrl);
}
else
{
@ -935,7 +938,7 @@ namespace IRaCIS.Core.Application.Contracts
public async Task ImportGenerateAccountAndJoinTrialAsync(Guid trialId, List<SiteSurveyUserImportDto> list)
public async Task ImportGenerateAccountAndJoinTrialAsync(Guid trialId, string baseUrl, string routeUrl, List<SiteSurveyUserImportDto> list)
{
@ -977,18 +980,22 @@ namespace IRaCIS.Core.Application.Contracts
}
item.IsGeneratedAccount = true;
}
var userId = sysUserInfo.Id;
var siteId = item.SiteId;
if (!await _trialUserRepository.AnyAsync(t=>t.TrialId==trialId && t.UserId== userId, true))
//判断是否加入到项目
var findTrialUser = await _trialUserRepository.FirstOrDefaultAsync(t => t.TrialId == trialId && t.UserId == userId, true);
if (findTrialUser == null)
{
await _repository.AddAsync(new TrialUser() { TrialId = trialId, UserId = userId, JoinTime = DateTime.Now });
await _mailVerificationService.SiteSurveyUserJoinEmail(trialId, userId, baseUrl, routeUrl);
}
else
else if (findTrialUser.IsDeleted == true)
{
await _trialUserRepository.UpdatePartialFromQueryAsync(t => t.TrialId == trialId && t.UserId == userId, c => new TrialUser()
{
@ -996,6 +1003,8 @@ namespace IRaCIS.Core.Application.Contracts
DeletedTime = null,
JoinTime = DateTime.Now,
});
await _mailVerificationService.SiteSurveyUserJoinEmail(trialId, userId, baseUrl, routeUrl);
}
@ -1003,7 +1012,6 @@ namespace IRaCIS.Core.Application.Contracts
{
await _repository.AddAsync(new TrialSiteUser() { TrialId = trialId, SiteId = siteId, UserId = userId });
await _mailVerificationService.SiteSurveyUserJoinEmail(trialId, userId, joinCommand.BaseUrl, joinCommand.RouteUrl);
}
else
{
@ -1014,9 +1022,12 @@ namespace IRaCIS.Core.Application.Contracts
});
}
await _userRepository.BatchUpdateNoTrackingAsync(t => t.Id == userId, u => new User() { Status = UserStateEnum.Enable });
await _trialSiteUserRepository.SaveChangesAsync();
}
//判断是否加入到项目
}

View File

@ -280,52 +280,9 @@ namespace IRaCIS.Application.Services
public async Task<IResponseOutput> DeleteTrial(Guid trialId)
{
var trial = (await _trialRepository.FirstOrDefaultAsync(u => u.Id == trialId, true)).IfNullThrowException();
if (_verifyConfig.CurrentValue.OpenTrialRelationDelete)
{
#region 项目真删除废弃
//if (trial.VisitPlanConfirmed)
//{
// return ResponseOutput.NotOk("Trial访视计划已经确认无法删除");
//}
//if (await _repository.AnyAsync<Enroll>(u => u.TrialId == trialId))
//{
// return ResponseOutput.NotOk("该Trial有医生入组或在入组流程中无法删除");
//}
//if (await _repository.AnyAsync<TrialSite>(u => u.TrialId == trialId))
//{
// return ResponseOutput.NotOk("该Trial下面有Site无法删除");
//}
////PM 可以删除项目 仅仅在没有site 参与者只有他自己的时候
//if (_userInfo.UserTypeEnumInt == (int)UserTypeEnum.ProjectManager)
//{
// //参与者仅有他自己时,可以删除
// if (await _trialUserRepository.CountAsync(t => t.TrialId == trialId) == 1)
// {
// var success1 = await _repository.BatchDeleteAsync<Trial>(o => o.Id == trialId) ||
// await _repository.BatchDeleteAsync<TrialUser>(t => t.TrialId == trialId) ||
// await _repository.BatchDeleteAsync<TrialDictionary>(t => t.TrialId == trialId);
// return ResponseOutput.Result(success1);
// }
//}
//if (await _repository.AnyAsync<TrialUser>(u => u.TrialId == trialId))
//{
// return ResponseOutput.NotOk("该Trial下面有参与者无法删除");
//}
#endregion
await _repository.BatchDeleteAsync<CheckChallengeDialog>(o => o.SubjectVisit.TrialId == trialId);
await _repository.BatchDeleteAsync<ClinicalDataTrialSet>(o => o.TrialId == trialId);
@ -344,9 +301,6 @@ namespace IRaCIS.Application.Services
await _repository.BatchDeleteAsync<PreviousHistory>(t => t.SubjectVisit.TrialId == trialId);
await _repository.BatchDeleteAsync<PreviousOther>(t => t.SubjectVisit.TrialId == trialId);
await _repository.BatchDeleteAsync<PreviousPDF>(t => t.SubjectVisit.TrialId == trialId);
@ -438,7 +392,6 @@ namespace IRaCIS.Application.Services
await _repository.BatchDeleteAsync<VisitTaskReReading>(t => t.OriginalReReadingTask.TrialId == trialId);
await _repository.BatchDeleteAsync<VisitTask>(t => t.TrialId == trialId);
await _repository.BatchDeleteAsync<TrialAttachment>(t => t.TrialId == trialId);
await _repository.BatchDeleteAsync<TrialStateChange>(t => t.TrialId == trialId) ;
return ResponseOutput.Ok();
@ -454,41 +407,6 @@ namespace IRaCIS.Application.Services
}
[AllowAnonymous]
[HttpDelete, Route("{trialId:guid}")]
public async Task<IResponseOutput> DeleteTrialTaskData(Guid trialId)
{
//await _repository.BatchDeleteAsync<ReadingMedicineTrialQuestion>(t => t.TrialId == trialId) ||
// await _repository.BatchDeleteAsync<ReadingQuestionTrial>(t => t.TrialId == trialId) ||
// await _repository.BatchDeleteAsync<ReadingTableQuestionTrial>(t => t.TrialId == trialId) ||
//await _repository.BatchDeleteAsync<ReadingGlobalTaskInfo>(t => t.TrialId == trialId);
// await _repository.BatchDeleteAsync<ReadingJudgeInfo>(t => t.TrialId == trialId);
// await _repository.BatchDeleteAsync<ReadingMedicalReviewDialog>(t => t.TaskMedicalReview.TrialId == trialId);
// await _repository.BatchDeleteAsync<ReadingMedicineQuestionAnswer>(t => t.TaskMedicalReview.TrialId == trialId);
// await _repository.BatchDeleteAsync<ReadingOncologyTaskInfo>(t => t.VisitTask.TrialId == trialId);
// await _repository.BatchDeleteAsync<ReadingTableAnswerRowInfo>(t => t.TrialId == trialId);
// await _repository.BatchDeleteAsync<ReadingTableQuestionAnswer>(t => t.TrialId == trialId);
// await _repository.BatchDeleteAsync<ReadingTaskQuestionAnswer>(t => t.TrialId == trialId) ;
// await _repository.BatchDeleteAsync<ReadingTaskRelation>(t => t.VisitTask.TrialId == trialId);
// await _repository.BatchDeleteAsync<ReadingTaskQuestionAnswer>(t => t.TrialId == trialId);
// await _repository.BatchDeleteAsync<VisitTaskReReading>(t => t.OriginalReReadingTask.TrialId == trialId);
// await _repository.BatchDeleteAsync<VisitTask>(t => t.TrialId == trialId);
return ResponseOutput.Ok();
}