90 lines
3.8 KiB
C#
90 lines
3.8 KiB
C#
//--------------------------------------------------------------------
|
|
// 此代码由T4模板自动生成 byzhouhang 20210918
|
|
// 生成时间 2022-07-01 15:33:04
|
|
// 对此文件的更改可能会导致不正确的行为,并且如果重新生成代码,这些更改将会丢失。
|
|
//--------------------------------------------------------------------
|
|
|
|
using IRaCIS.Core.Domain.Models;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using IRaCIS.Core.Application.Interfaces;
|
|
using IRaCIS.Core.Application.ViewModel;
|
|
using IRaCIS.Core.Infrastructure;
|
|
|
|
namespace IRaCIS.Core.Application.Service
|
|
{
|
|
/// <summary>
|
|
/// 一致性分析配置表
|
|
/// </summary>
|
|
[ApiExplorerSettings(GroupName = "Trial")]
|
|
public class TaskConsistentRuleService : BaseService, ITaskConsistentRuleService
|
|
{
|
|
|
|
private readonly IRepository<TaskConsistentRule> _taskConsistentRuleRepository;
|
|
private readonly IRepository<VisitTask> _visitTaskRepository;
|
|
|
|
public TaskConsistentRuleService(IRepository<VisitTask> visitTaskRepository, IRepository<TaskConsistentRule> taskConsistentRuleRepository)
|
|
{
|
|
_taskConsistentRuleRepository = taskConsistentRuleRepository;
|
|
_visitTaskRepository = visitTaskRepository;
|
|
}
|
|
|
|
[HttpPost]
|
|
public async Task<List<TaskConsistentRuleView>> GetTaskConsistentRuleList(TaskConsistentRuleQuery inQuery)
|
|
{
|
|
|
|
var taskConsistentRuleQueryable = _taskConsistentRuleRepository.Where(t => t.TrialId == inQuery.TrialId)
|
|
.WhereIf(inQuery.IsSelfAnalysis, t => t.CompareDoctorUserId != null)
|
|
.WhereIf(inQuery.IsSelfAnalysis == false, t => t.CompareDoctorUserId == null)
|
|
.ProjectTo<TaskConsistentRuleView>(_mapper.ConfigurationProvider);
|
|
|
|
return await taskConsistentRuleQueryable.ToListAsync();
|
|
}
|
|
|
|
|
|
public async Task<IResponseOutput> AddOrUpdateTaskConsistentRule(TaskConsistentRuleAddOrEdit addOrEditTaskConsistentRule)
|
|
{
|
|
|
|
var verifyExp1 = new EntityVerifyExp<TaskConsistentRule>()
|
|
{
|
|
VerifyExp = t => t.AnalysisDoctorUserId == addOrEditTaskConsistentRule.AnalysisDoctorUserId && t.CompareDoctorUserId == addOrEditTaskConsistentRule.CompareDoctorUserId && t.TrialId == addOrEditTaskConsistentRule.TrialId,
|
|
VerifyMsg = "已有该医生配置,不允许继续增加"
|
|
};
|
|
|
|
var entity = await _taskConsistentRuleRepository.InsertOrUpdateAsync(addOrEditTaskConsistentRule, true, verifyExp1);
|
|
|
|
return ResponseOutput.Ok(entity.Id.ToString());
|
|
|
|
}
|
|
|
|
|
|
[HttpDelete("{taskConsistentRuleId:guid}")]
|
|
public async Task<IResponseOutput> DeleteTaskConsistentRule(Guid taskConsistentRuleId)
|
|
{
|
|
var config = await _taskConsistentRuleRepository.FirstOrDefaultAsync(t => t.Id == taskConsistentRuleId);
|
|
|
|
//自身一致性分析
|
|
if (config.CompareDoctorUserId == null)
|
|
{
|
|
if (await _visitTaskRepository.AnyAsync(t => t.IsAnalysisCreate && t.DoctorUserId == config.AnalysisDoctorUserId && t.TrialId == config.TrialId))
|
|
{
|
|
throw new BusinessValidationFailedException("已产生一致性分析任务,不允许删除");
|
|
}
|
|
}
|
|
//组内一致性分析
|
|
else
|
|
{
|
|
if (await _visitTaskRepository.AnyAsync(t => t.IsAnalysisCreate && t.DoctorUserId == config.CompareDoctorUserId && t.TrialId == config.TrialId))
|
|
{
|
|
throw new BusinessValidationFailedException("已产生一致性分析任务,不允许删除");
|
|
}
|
|
}
|
|
|
|
|
|
var success = await _taskConsistentRuleRepository.DeleteFromQueryAsync(t => t.Id == taskConsistentRuleId, true);
|
|
return ResponseOutput.Ok();
|
|
}
|
|
|
|
|
|
}
|
|
}
|