x
This commit is contained in:
@@ -0,0 +1,630 @@
|
||||
|
||||
using IRaCIS.Core.Domain.Models;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using IRaCIS.Core.Application.Interfaces;
|
||||
using IRaCIS.Core.Application.ViewModel;
|
||||
using IRaCIS.Core.Infra.EFCore.Common;
|
||||
using MassTransit;
|
||||
using IRaCIS.Core.Infrastructure;
|
||||
using IRaCIS.Core.Application.Service.Reading.Dto;
|
||||
using IRaCIS.Core.Domain.Share;
|
||||
using Panda.DynamicWebApi.Attributes;
|
||||
using IRaCIS.Core.Application.Contracts;
|
||||
|
||||
namespace IRaCIS.Core.Application.Service
|
||||
{
|
||||
/// <summary>
|
||||
/// 阅片医学审核
|
||||
/// </summary>
|
||||
[ ApiExplorerSettings(GroupName = "Reading")]
|
||||
public class ReadingMedicalReviewService : BaseService, IReadingMedicalReviewService
|
||||
{
|
||||
|
||||
private readonly IRepository<ReadingMedicineTrialQuestion> _readingMedicineTrialQuestionRepository;
|
||||
private readonly IRepository<Trial> _trialRepository;
|
||||
private readonly IRepository<VisitTask> _visitTaskRepository;
|
||||
private readonly IRepository<User> _userTaskRepository;
|
||||
private readonly IVisitTaskService _visitTaskService;
|
||||
private readonly IRepository<TaskMedicalReview> _taskMedicalReviewRepository;
|
||||
private readonly IRepository<ReadingMedicalReviewDialog> _readingMedicalReviewDialogRepository;
|
||||
private readonly IRepository<ReadingQuestionCriterionTrial> _readingQuestionCriterionTrial;
|
||||
private readonly IRepository<ReadingMedicineQuestionAnswer> _readingMedicineQuestionAnswerRepository;
|
||||
private readonly IRepository<ReadingMedicineSystemQuestion> _readingMedicineSystemQuestionRepository;
|
||||
|
||||
public ReadingMedicalReviewService(
|
||||
IRepository<ReadingMedicineTrialQuestion> readingMedicineTrialQuestionRepository,
|
||||
IRepository<Trial> trialRepository,
|
||||
IRepository<VisitTask> visitTaskRepository,
|
||||
IRepository<User> userTaskRepository,
|
||||
IVisitTaskService visitTaskService,
|
||||
IRepository<TaskMedicalReview> taskMedicalReviewRepository,
|
||||
IRepository<ReadingMedicalReviewDialog> readingMedicalReviewDialogRepository,
|
||||
IRepository<ReadingQuestionCriterionTrial> readingQuestionCriterionTrial,
|
||||
IRepository<ReadingMedicineQuestionAnswer> readingMedicineQuestionAnswerRepository,
|
||||
IRepository<ReadingMedicineSystemQuestion> readingMedicineSystemQuestionRepository
|
||||
)
|
||||
{
|
||||
this._readingMedicineTrialQuestionRepository = readingMedicineTrialQuestionRepository;
|
||||
this._trialRepository = trialRepository;
|
||||
this._visitTaskRepository = visitTaskRepository;
|
||||
this._userTaskRepository = userTaskRepository;
|
||||
this._visitTaskService = visitTaskService;
|
||||
this._taskMedicalReviewRepository = taskMedicalReviewRepository;
|
||||
this._readingMedicalReviewDialogRepository = readingMedicalReviewDialogRepository;
|
||||
this._readingQuestionCriterionTrial = readingQuestionCriterionTrial;
|
||||
this._readingMedicineQuestionAnswerRepository = readingMedicineQuestionAnswerRepository;
|
||||
this._readingMedicineSystemQuestionRepository = readingMedicineSystemQuestionRepository;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取医学审核任务信息
|
||||
/// </summary>
|
||||
/// <param name="inDto"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
public async Task<GetMedicalReviewReadingTaskOutDto> GetMedicalReviewReadingTask(GetMedicalReviewReadingTaskInDto inDto)
|
||||
{
|
||||
MedicalReviewInfo reviewInfo= await _taskMedicalReviewRepository.Where(x => x.Id == inDto.TaskMedicalReviewId)
|
||||
.ProjectTo<MedicalReviewInfo>(_mapper.ConfigurationProvider).FirstNotNullAsync();
|
||||
|
||||
var visitTaskfInfo = await _visitTaskRepository.Where(x => x.Id == reviewInfo.VisitTaskId).FirstNotNullAsync();
|
||||
|
||||
var medicalReviewInfo = await _readingQuestionCriterionTrial.Where(x => x.Id == visitTaskfInfo.TrialReadingCriterionId).Select(x => new GetMedicalReviewReadingTaskOutDto()
|
||||
{
|
||||
ReadingType=x.ReadingType,
|
||||
IsReadingTaskViewInOrder=x.IsReadingTaskViewInOrder,
|
||||
|
||||
}).FirstNotNullAsync();
|
||||
|
||||
medicalReviewInfo.MedicalReviewInfo = reviewInfo;
|
||||
|
||||
var taskInfo = await _visitTaskRepository.Where(x => x.Id == medicalReviewInfo.MedicalReviewInfo.VisitTaskId).FirstNotNullAsync();
|
||||
|
||||
medicalReviewInfo.VisitTaskId = taskInfo.Id;
|
||||
medicalReviewInfo.ArmEnum = taskInfo.ArmEnum;
|
||||
medicalReviewInfo.IsClosedDialog = medicalReviewInfo.MedicalReviewInfo.IsClosedDialog;
|
||||
medicalReviewInfo.AuditState = medicalReviewInfo.MedicalReviewInfo.AuditState;
|
||||
medicalReviewInfo.IsSendMessage = medicalReviewInfo.MedicalReviewInfo.IsSendMessage;
|
||||
|
||||
#region 取任务
|
||||
if (medicalReviewInfo.IsReadingTaskViewInOrder)
|
||||
{
|
||||
medicalReviewInfo.TaskList = await _visitTaskRepository
|
||||
.WhereIf(taskInfo.ArmEnum == Arm.JudgeArm, x => x.ArmEnum == Arm.JudgeArm)
|
||||
.WhereIf(taskInfo.ArmEnum != Arm.JudgeArm, x => x.ArmEnum != Arm.JudgeArm)
|
||||
.Where(x=>x.IsAnalysisCreate== taskInfo.IsAnalysisCreate)
|
||||
.Where(x=>x.TaskState==TaskState.Effect)
|
||||
.Where(x => x.SubjectId == taskInfo.SubjectId
|
||||
&& x.DoctorUserId == taskInfo.DoctorUserId &&
|
||||
x.ReadingTaskState == ReadingTaskState.HaveSigned &&
|
||||
x.ReReadingApplyState != ReReadingApplyState.Agree
|
||||
).OrderBy(x => x.VisitTaskNum).Select(x => new TaskInfo()
|
||||
{
|
||||
TaskId = x.Id,
|
||||
IsCurrentTask = x.Id == taskInfo.Id,
|
||||
ReadingCategory = x.ReadingCategory,
|
||||
TaskBlindName = x.TaskBlindName,
|
||||
ArmEnum=x.ArmEnum,
|
||||
TaskName = x.TaskName,
|
||||
SouceReadModuleId=x.SouceReadModuleId,
|
||||
SourceSubjectVisitId=x.SourceSubjectVisitId,
|
||||
JudgeVisitTaskId=x.JudgeVisitTaskId,
|
||||
JudgeResultArm=x.JudgeResultTask.ArmEnum,
|
||||
SubjectId=x.SubjectId,
|
||||
JudgeQuestionAnswerInfoList = x.ArmEnum== Arm.JudgeArm? x.JudgeResultTask.ReadingTaskQuestionAnswerList.Where(y=>y.ReadingQuestionTrial.IsJudgeQuestion).Select(y=> new JudgeQuestionAnswerInfo()
|
||||
{
|
||||
Answer=y.Answer,
|
||||
QuestionName=y.ReadingQuestionTrial.QuestionName,
|
||||
|
||||
}).ToList() : x.ReadingTaskQuestionAnswerList.Where(y => y.ReadingQuestionTrial.IsJudgeQuestion).Select(y => new JudgeQuestionAnswerInfo()
|
||||
{
|
||||
Answer = y.Answer,
|
||||
QuestionName = y.ReadingQuestionTrial.QuestionName,
|
||||
|
||||
}).ToList()
|
||||
}).ToListAsync();
|
||||
|
||||
List<TaskInfo> otherTask = await _visitTaskRepository.Where(x => x.ArmEnum != Arm.JudgeArm && x.SubjectId == taskInfo.SubjectId
|
||||
&& x.DoctorUserId != taskInfo.DoctorUserId && x.ReadingTaskState == ReadingTaskState.HaveSigned && x.ReReadingApplyState != ReReadingApplyState.Agree)
|
||||
.Where(x => x.IsAnalysisCreate == taskInfo.IsAnalysisCreate)
|
||||
.OrderBy(x => x.VisitTaskNum).Select(x => new TaskInfo()
|
||||
{
|
||||
TaskId = x.Id,
|
||||
IsCurrentTask = x.Id == taskInfo.Id,
|
||||
ReadingCategory = x.ReadingCategory,
|
||||
TaskBlindName = x.TaskBlindName,
|
||||
ArmEnum = x.ArmEnum,
|
||||
TaskName = x.TaskName,
|
||||
SouceReadModuleId = x.SouceReadModuleId,
|
||||
SourceSubjectVisitId = x.SourceSubjectVisitId,
|
||||
}).ToListAsync();
|
||||
|
||||
medicalReviewInfo.TaskList.ForEach(x =>
|
||||
{
|
||||
x.OtherTaskId = otherTask.Where(y => y.SouceReadModuleId == x.SouceReadModuleId && y.SourceSubjectVisitId == x.SourceSubjectVisitId).Select(y => y.TaskId).FirstOrDefault();
|
||||
});
|
||||
}
|
||||
else
|
||||
{
|
||||
medicalReviewInfo.TaskList = await _visitTaskRepository.Where(x => x.Id == taskInfo.Id).Select(x => new TaskInfo()
|
||||
{
|
||||
TaskId = x.Id,
|
||||
IsCurrentTask = x.Id == taskInfo.Id,
|
||||
ReadingCategory = x.ReadingCategory,
|
||||
TaskBlindName = x.TaskBlindName,
|
||||
ArmEnum = x.ArmEnum,
|
||||
TaskName = x.TaskName,
|
||||
SouceReadModuleId = x.SouceReadModuleId,
|
||||
SourceSubjectVisitId = x.SourceSubjectVisitId,
|
||||
SubjectId = x.SubjectId,
|
||||
JudgeQuestionAnswerInfoList = x.ArmEnum == Arm.JudgeArm ? x.JudgeResultTask.ReadingTaskQuestionAnswerList.Where(y => y.ReadingQuestionTrial.IsJudgeQuestion).Select(y => new JudgeQuestionAnswerInfo()
|
||||
{
|
||||
Answer = y.Answer,
|
||||
QuestionName = y.ReadingQuestionTrial.QuestionName,
|
||||
|
||||
}).ToList() : x.ReadingTaskQuestionAnswerList.Where(y => y.ReadingQuestionTrial.IsJudgeQuestion).Select(y => new JudgeQuestionAnswerInfo()
|
||||
{
|
||||
Answer = y.Answer,
|
||||
QuestionName = y.ReadingQuestionTrial.QuestionName,
|
||||
|
||||
}).ToList()
|
||||
}).ToListAsync();
|
||||
|
||||
|
||||
|
||||
List<TaskInfo> otherTask = await _visitTaskRepository.Where(x => x.ArmEnum != Arm.JudgeArm && x.SouceReadModuleId == taskInfo.SouceReadModuleId && x.SourceSubjectVisitId == taskInfo.SourceSubjectVisitId
|
||||
&& x.DoctorUserId != taskInfo.DoctorUserId && x.ReadingTaskState == ReadingTaskState.HaveSigned && x.ReReadingApplyState != ReReadingApplyState.Agree
|
||||
)
|
||||
.Where(x => x.IsAnalysisCreate == taskInfo.IsAnalysisCreate)
|
||||
.OrderBy(x => x.VisitTaskNum).Select(x => new TaskInfo()
|
||||
{
|
||||
TaskId = x.Id,
|
||||
IsCurrentTask = x.Id == taskInfo.Id,
|
||||
ReadingCategory = x.ReadingCategory,
|
||||
TaskBlindName = x.TaskBlindName,
|
||||
ArmEnum = x.ArmEnum,
|
||||
TaskName = x.TaskName,
|
||||
SouceReadModuleId = x.SouceReadModuleId,
|
||||
SourceSubjectVisitId = x.SourceSubjectVisitId,
|
||||
}).ToListAsync();
|
||||
|
||||
medicalReviewInfo.TaskList.ForEach(x =>
|
||||
{
|
||||
x.OtherTaskId = otherTask.Where(y => y.SouceReadModuleId == x.SouceReadModuleId && y.SourceSubjectVisitId == x.SourceSubjectVisitId).Select(y => y.TaskId).FirstOrDefault();
|
||||
});
|
||||
}
|
||||
#endregion
|
||||
medicalReviewInfo.QuestionAnswerList = await this.GetMedicalQuestionAnswer(inDto);
|
||||
|
||||
|
||||
|
||||
var result = await _readingMedicineQuestionAnswerRepository.SaveChangesAsync();
|
||||
return medicalReviewInfo;
|
||||
|
||||
}
|
||||
|
||||
#region 问题
|
||||
|
||||
private async Task<List<ReadingMedicineQuestion>> GetMedicalQuestionAnswer(GetMedicalReviewReadingTaskInDto inDto)
|
||||
{
|
||||
var medicalReview = await _taskMedicalReviewRepository.Where(x => x.Id == inDto.TaskMedicalReviewId).FirstNotNullAsync();
|
||||
var taskInfo = await _visitTaskRepository.Where(x => x.Id == medicalReview.VisitTaskId).FirstNotNullAsync();
|
||||
|
||||
var questionQuery = from data in _readingMedicineTrialQuestionRepository.Where(x => x.TrialId == inDto.TrialId && x.IsConfirm && x.IsEnable&&x.ReadingCategory==taskInfo.ReadingCategory)
|
||||
join questionAnswer in _readingMedicineQuestionAnswerRepository.Where(x => x.TaskMedicalReviewId == inDto.TaskMedicalReviewId) on data.Id equals questionAnswer.ReadingMedicineQuestionId into questionAnswerTemp
|
||||
from leftquestionAnswer in questionAnswerTemp.DefaultIfEmpty()
|
||||
select new ReadingMedicineQuestion()
|
||||
{
|
||||
Id = data.Id,
|
||||
Type = data.Type,
|
||||
ParentTriggerValue = data.ParentTriggerValue,
|
||||
IsEnable = data.IsEnable,
|
||||
IsConfirm = data.IsConfirm,
|
||||
QuestionName = data.QuestionName,
|
||||
IsRequired = data.IsRequired,
|
||||
ShowOrder = data.ShowOrder,
|
||||
ParentId = data.ParentId,
|
||||
TypeValue = data.TypeValue,
|
||||
Answer = leftquestionAnswer.Answer
|
||||
};
|
||||
|
||||
var questionList = await questionQuery.OrderBy(x=>x.ShowOrder).ToListAsync();
|
||||
|
||||
List<ReadingMedicineQuestion> medicineQuestionList = questionList.Where(x => x.ParentId == null).ToList();
|
||||
medicineQuestionList.ForEach(x =>
|
||||
{
|
||||
FindChildQuestion(x, questionList);
|
||||
});
|
||||
|
||||
return medicineQuestionList;
|
||||
}
|
||||
|
||||
|
||||
private void FindChildQuestion(ReadingMedicineQuestion medicineQuestionList, List<ReadingMedicineQuestion> questionlists)
|
||||
{
|
||||
medicineQuestionList.Childrens = questionlists.Where(x => x.ParentId == medicineQuestionList.Id).ToList();
|
||||
if (medicineQuestionList.Childrens != null && medicineQuestionList.Childrens.Count != 0)
|
||||
{
|
||||
medicineQuestionList.Childrens.ForEach(x =>
|
||||
{
|
||||
this.FindChildQuestion(x, questionlists);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 保存医学审核问题 答案
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
public async Task<IResponseOutput> SaveMedicineQuestion(SaveMedicineQuestionInDto inDto)
|
||||
{
|
||||
var medicalReviewInfo = await _taskMedicalReviewRepository.Where(x => x.Id == inDto.TaskMedicalReviewId).FirstNotNullAsync();
|
||||
if (medicalReviewInfo.IsInvalid)
|
||||
{
|
||||
throw new BusinessValidationFailedException("该医学审核无效,操作失败");
|
||||
}
|
||||
await _readingMedicineQuestionAnswerRepository.BatchDeleteNoTrackingAsync(x => x.TaskMedicalReviewId == inDto.TaskMedicalReviewId);
|
||||
|
||||
List<ReadingMedicineQuestionAnswer> questionAnswerList = inDto.QuestionAnswerList.Select(x => new ReadingMedicineQuestionAnswer()
|
||||
{
|
||||
Answer = x.Answer,
|
||||
ReadingMedicineQuestionId = x.Id,
|
||||
TaskMedicalReviewId = inDto.TaskMedicalReviewId,
|
||||
VisitTaskId = inDto.VisitTaskId,
|
||||
|
||||
}).ToList();
|
||||
|
||||
await _readingMedicineQuestionAnswerRepository.AddRangeAsync(questionAnswerList);
|
||||
|
||||
await _taskMedicalReviewRepository.UpdatePartialFromQueryAsync(inDto.TaskMedicalReviewId, x => new TaskMedicalReview()
|
||||
{
|
||||
|
||||
SaveQuestionTime = DateTime.Now,
|
||||
AuditState = MedicalReviewAuditState.Auditing,
|
||||
|
||||
});
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
var result = await _readingMedicineQuestionAnswerRepository.SaveChangesAsync();
|
||||
|
||||
return ResponseOutput.Result(result);
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 保存医学审核 结论
|
||||
/// </summary>
|
||||
/// <param name="inDto"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<IResponseOutput> SaveMedicalReviewInfo(SaveMedicalReviewInfoInDto inDto)
|
||||
{
|
||||
var medicalReviewInfo = await _taskMedicalReviewRepository.Where(x => x.Id == inDto.TaskMedicalReviewId).FirstNotNullAsync();
|
||||
if (medicalReviewInfo.IsInvalid)
|
||||
{
|
||||
throw new BusinessValidationFailedException("该医学审核无效,操作失败");
|
||||
}
|
||||
if ((await _taskMedicalReviewRepository.Where(x => x.Id == inDto.TaskMedicalReviewId).Select(x => x.SaveQuestionTime).FirstOrDefaultAsync()) == null)
|
||||
{
|
||||
return ResponseOutput.NotOk("请先保存医学审核问题");
|
||||
}
|
||||
await _taskMedicalReviewRepository.UpdatePartialFromQueryAsync(inDto.TaskMedicalReviewId, x => new TaskMedicalReview()
|
||||
{
|
||||
IsHaveQuestion = inDto.IsHaveQuestion,
|
||||
Questioning = inDto.Questioning,
|
||||
IsSendMessage = inDto.IsSendDialog && inDto.IsHaveQuestion,
|
||||
AuditAdviceEnum = inDto.AuditAdviceEnum,
|
||||
SaveConclusionTime=DateTime.Now,
|
||||
|
||||
});
|
||||
|
||||
var medicalReview = await _taskMedicalReviewRepository.Where(x => x.Id == inDto.TaskMedicalReviewId).FirstNotNullAsync();
|
||||
if (inDto.IsSendDialog&& !medicalReview.IsSendMessage && inDto.IsHaveQuestion)
|
||||
{
|
||||
|
||||
await _readingMedicalReviewDialogRepository.AddAsync(new ReadingMedicalReviewDialog()
|
||||
{
|
||||
AuditAdviceEnum = inDto.AuditAdviceEnum,
|
||||
TaskMedicalReviewId = inDto.TaskMedicalReviewId,
|
||||
UserTypeShortName = _userInfo.UserTypeShortName,
|
||||
IsHaveQuestion=inDto.IsHaveQuestion,
|
||||
Questioning=inDto.Questioning,
|
||||
VisitTaskId= medicalReview.VisitTaskId,
|
||||
FileName = medicalReview.FileName,
|
||||
UserTypeEnumInt = _userInfo.UserTypeEnumInt,
|
||||
ImagePath= medicalReview.ImagePath,
|
||||
});
|
||||
}
|
||||
|
||||
var result = await _taskMedicalReviewRepository.SaveChangesAsync();
|
||||
return ResponseOutput.Result(result);
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 关闭医学审核对话
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
public async Task<IResponseOutput> ClosedMedicalReviewDialog(ClosedMedicalReviewDialogInDto inDto)
|
||||
{
|
||||
await _taskMedicalReviewRepository.UpdatePartialFromQueryAsync(inDto.TaskMedicalReviewId, x => new TaskMedicalReview()
|
||||
{
|
||||
IsClosedDialog = inDto.IsClosedDialog,
|
||||
MedicalDialogCloseEnum=inDto.MedicalDialogCloseEnum,
|
||||
DialogCloseReason=inDto.DialogCloseReason,
|
||||
});
|
||||
|
||||
|
||||
ReadingMedicalReviewDialog dialog = new ReadingMedicalReviewDialog()
|
||||
{
|
||||
TaskMedicalReviewId = inDto.TaskMedicalReviewId,
|
||||
UserTypeShortName = _userInfo.UserTypeShortName,
|
||||
Content = inDto.MedicalDialogCloseEnum.GetDescription()+ (inDto.DialogCloseReason.IsNullOrEmpty()? inDto.DialogCloseReason:","+ inDto.DialogCloseReason),
|
||||
UserTypeEnumInt = _userInfo.UserTypeEnumInt,
|
||||
};
|
||||
|
||||
await _readingMedicalReviewDialogRepository.AddAsync(dialog);
|
||||
var result = await _taskMedicalReviewRepository.SaveChangesAsync();
|
||||
return ResponseOutput.Result(result);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 发送对话消息
|
||||
/// </summary>
|
||||
/// <param name="inDto"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<IResponseOutput> SendMedicalReviewDialog(SendMedicalReviewDialogInDto inDto)
|
||||
{
|
||||
var medicalReviewInfo = await _taskMedicalReviewRepository.Where(x => x.Id == inDto.TaskMedicalReviewId).FirstNotNullAsync();
|
||||
if (medicalReviewInfo.IsInvalid)
|
||||
{
|
||||
throw new BusinessValidationFailedException("该医学审核无效,操作失败");
|
||||
}
|
||||
|
||||
var visitTaskId = await _taskMedicalReviewRepository.Where(x => x.Id == inDto.TaskMedicalReviewId).Select(x => x.VisitTaskId).FirstOrDefaultAsync();
|
||||
ReadingMedicalReviewDialog dialog = new ReadingMedicalReviewDialog()
|
||||
{
|
||||
TaskMedicalReviewId = inDto.TaskMedicalReviewId,
|
||||
UserTypeShortName = _userInfo.UserTypeShortName,
|
||||
Content = inDto.Content,
|
||||
UserTypeEnumInt = _userInfo.UserTypeEnumInt,
|
||||
VisitTaskId = visitTaskId,
|
||||
AuditAdviceEnum=inDto.AuditAdviceEnum,
|
||||
|
||||
IsHaveQuestion=inDto.IsHaveQuestion,
|
||||
Questioning=inDto.Questioning,
|
||||
};
|
||||
|
||||
await _readingMedicalReviewDialogRepository.AddAsync(dialog);
|
||||
|
||||
var result=await _readingMedicalReviewDialogRepository.SaveChangesAsync();
|
||||
return ResponseOutput.Result(result);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// IR发送消息
|
||||
/// </summary>
|
||||
/// <param name="inDto"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<IResponseOutput> IRSendMedicalReviewDialog(IRSendMedicalReviewDialogInDto inDto)
|
||||
{
|
||||
var medicalReviewInfo = await _taskMedicalReviewRepository.Where(x => x.Id == inDto.TaskMedicalReviewId).FirstNotNullAsync();
|
||||
if (medicalReviewInfo.IsInvalid)
|
||||
{
|
||||
throw new BusinessValidationFailedException("该医学审核无效,操作失败");
|
||||
}
|
||||
var visitTaskId = await _taskMedicalReviewRepository.Where(x => x.Id == inDto.TaskMedicalReviewId).Select(x => x.VisitTaskId).FirstOrDefaultAsync();
|
||||
if (inDto.IsApplyHeavyReading??false)
|
||||
{
|
||||
await _visitTaskService.ApplyReReading(new ApplyReReadingCommand()
|
||||
{
|
||||
IsCopyOrigenalForms = inDto.IsCopyOrigenalForms??false,
|
||||
IsCopyFollowForms=inDto.IsCopyFollowForms ?? false,
|
||||
RequestReReadingReason = inDto.RequestReReadingReason,
|
||||
RequestReReadingType = RequestReReadingType.DocotorApply,
|
||||
TrialId = inDto.TrialId,
|
||||
TaskIdList = new List<Guid>()
|
||||
{
|
||||
visitTaskId
|
||||
|
||||
}
|
||||
});
|
||||
await _taskMedicalReviewRepository.BatchUpdateNoTrackingAsync(x => !x.IsClosedDialog && x.Id == inDto.TaskMedicalReviewId, x => new TaskMedicalReview()
|
||||
{
|
||||
IsClosedDialog = true,
|
||||
MedicalDialogCloseEnum = MedicalDialogClose.IRApplyReReading,
|
||||
});
|
||||
}
|
||||
|
||||
await _taskMedicalReviewRepository.BatchUpdateNoTrackingAsync(x => x.Id == inDto.TaskMedicalReviewId, x => new TaskMedicalReview()
|
||||
{
|
||||
DoctorUserIdeaEnum = inDto.DoctorUserIdeaEnum,
|
||||
});
|
||||
ReadingMedicalReviewDialog dialog = new ReadingMedicalReviewDialog()
|
||||
{
|
||||
TaskMedicalReviewId = inDto.TaskMedicalReviewId,
|
||||
UserTypeShortName = _userInfo.UserTypeShortName,
|
||||
Content = inDto.Content,
|
||||
ImagePath=inDto.ImagePath,
|
||||
UserTypeEnumInt = _userInfo.UserTypeEnumInt,
|
||||
VisitTaskId = visitTaskId,
|
||||
FileName=inDto.FileName,
|
||||
DisagreeReason = inDto.DisagreeReason,
|
||||
DoctorUserIdeaEnum = inDto.DoctorUserIdeaEnum,
|
||||
IsApplyHeavyReading = inDto.IsApplyHeavyReading,
|
||||
};
|
||||
|
||||
await _readingMedicalReviewDialogRepository.AddAsync(dialog);
|
||||
var result = await _readingMedicalReviewDialogRepository.SaveChangesAsync();
|
||||
return ResponseOutput.Result(result);
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 获取医学审核对话
|
||||
/// </summary>
|
||||
/// <param name="inDto"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
public async Task<(List<GetMedicalReviewDialogOutDto>,object)> GetMedicalReviewDialog(GetMedicalReviewDialogInDto inDto)
|
||||
{
|
||||
var taskMedicalReview = await _taskMedicalReviewRepository.Where(x => x.Id == inDto.TaskMedicalReviewId).FirstNotNullAsync();
|
||||
List<GetMedicalReviewDialogOutDto> result = await _readingMedicalReviewDialogRepository.Where(x => x.TaskMedicalReviewId == inDto.TaskMedicalReviewId)
|
||||
.ProjectTo<GetMedicalReviewDialogOutDto>(_mapper.ConfigurationProvider)
|
||||
.OrderBy(x => x.CreateTime).ToListAsync();
|
||||
result.ForEach(x => {
|
||||
x.IsCurrentUser = x.CreateUserId == _userInfo.Id;
|
||||
});
|
||||
return (result,new {
|
||||
|
||||
IsIRReply= result.Any(x=>x.UserTypeEnumInt== (int)UserTypeEnum.IndependentReviewer),
|
||||
taskMedicalReview.IsClosedDialog,
|
||||
taskMedicalReview.IsHaveQuestion,
|
||||
});
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 完成医学审核
|
||||
/// </summary>
|
||||
/// <param name="inDto"></param>
|
||||
/// <returns></returns>
|
||||
[NonDynamicMethod]
|
||||
public async Task<IResponseOutput> FinishMedicalReview(FinishMedicalReviewInDto inDto)
|
||||
{
|
||||
var medicalReviewInfo = await _taskMedicalReviewRepository.Where(x => x.Id == inDto.TaskMedicalReviewId).FirstNotNullAsync();
|
||||
if (medicalReviewInfo.IsInvalid)
|
||||
{
|
||||
throw new BusinessValidationFailedException("该医学审核无效,操作失败");
|
||||
}
|
||||
|
||||
var taskmedicalReview = await _taskMedicalReviewRepository.Where(x => x.Id == inDto.TaskMedicalReviewId).Select(x => new
|
||||
{
|
||||
x.SaveConclusionTime,
|
||||
x.SaveQuestionTime,
|
||||
x.IsClosedDialog,
|
||||
x.IsHaveQuestion
|
||||
|
||||
}).FirstNotNullAsync();
|
||||
|
||||
if (taskmedicalReview.SaveQuestionTime == null || taskmedicalReview.SaveConclusionTime==null)
|
||||
{
|
||||
throw new BusinessValidationFailedException("请先保存问题和结论");
|
||||
|
||||
}
|
||||
|
||||
if (taskmedicalReview.IsHaveQuestion&&!taskmedicalReview.IsClosedDialog)
|
||||
{
|
||||
throw new BusinessValidationFailedException("对话未关闭");
|
||||
|
||||
}
|
||||
|
||||
await _taskMedicalReviewRepository.UpdatePartialFromQueryAsync(inDto.TaskMedicalReviewId, x => new TaskMedicalReview()
|
||||
{
|
||||
AuditState = MedicalReviewAuditState.HaveSigned,
|
||||
AuditSignTime=DateTime.Now,
|
||||
});
|
||||
|
||||
var result = await _taskMedicalReviewRepository.SaveChangesAsync();
|
||||
return ResponseOutput.Result(result);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// IR回复确认医学审核
|
||||
/// </summary>
|
||||
/// <param name="inDto"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
public async Task<IResponseOutput> IRConfirmMedicalReview(IRConfirmMedicalReviewInDto inDto)
|
||||
{
|
||||
var medicalReviewInfo = await _taskMedicalReviewRepository.Where(x => x.Id == inDto.TaskMedicalReviewId).FirstNotNullAsync();
|
||||
if (medicalReviewInfo.IsInvalid)
|
||||
{
|
||||
throw new BusinessValidationFailedException("该医学审核无效,操作失败");
|
||||
}
|
||||
|
||||
await _taskMedicalReviewRepository.UpdatePartialFromQueryAsync(inDto.TaskMedicalReviewId, x => new TaskMedicalReview()
|
||||
{
|
||||
DoctorUserIdeaEnum = inDto.DoctorUserIdeaEnum,
|
||||
DisagreeReason = inDto.DisagreeReason,
|
||||
IsApplyHeavyReading=inDto.IsApplyHeavyReading,
|
||||
});
|
||||
|
||||
var visitTaskId = await _taskMedicalReviewRepository.Where(x => x.Id == inDto.TaskMedicalReviewId).Select(x => x.VisitTaskId).FirstOrDefaultAsync();
|
||||
await _readingMedicalReviewDialogRepository.AddAsync(new ReadingMedicalReviewDialog()
|
||||
{
|
||||
|
||||
TaskMedicalReviewId = inDto.TaskMedicalReviewId,
|
||||
UserTypeShortName = _userInfo.UserTypeShortName,
|
||||
DoctorUserIdeaEnum = inDto.DoctorUserIdeaEnum,
|
||||
DisagreeReason = inDto.DisagreeReason,
|
||||
IsApplyHeavyReading = inDto.IsApplyHeavyReading,
|
||||
VisitTaskId = visitTaskId,
|
||||
UserTypeEnumInt = _userInfo.UserTypeEnumInt,
|
||||
});
|
||||
|
||||
var result = await _taskMedicalReviewRepository.SaveChangesAsync();
|
||||
return ResponseOutput.Result(result);
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 获取IR医学审核信息
|
||||
/// </summary>
|
||||
/// <param name="inDto"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
public async Task<PageOutput<GetIRMedicalFeedbackListOutDto>> GetIRMedicalFeedbackList(GetIRMedicalFeedbackListInDto inDto)
|
||||
{
|
||||
var taskMedicalReviewquery = _taskMedicalReviewRepository.Where(x => x.TrialId == inDto.TrialId).Include(x => x.VisitTask)
|
||||
.Where(x => x.VisitTask.DoctorUserId == _userInfo.Id)
|
||||
.Where(x => x.IsHaveQuestion)
|
||||
.WhereIf(!inDto.TaskBlindName.IsNullOrEmpty(), x => x.VisitTask.TaskBlindName == inDto.TaskBlindName)
|
||||
.WhereIf(inDto.IsUrgent != null, x => x.VisitTask.IsUrgent == inDto.IsUrgent!)
|
||||
.WhereIf(inDto.AuditState != null, x => x.AuditState == inDto.AuditState!)
|
||||
.WhereIf(inDto.ReadingCategory != null, x => x.VisitTask.ReadingCategory == inDto.ReadingCategory!)
|
||||
.WhereIf(inDto.AuditAdviceEnum != null, x => x.AuditAdviceEnum == inDto.AuditAdviceEnum!)
|
||||
.WhereIf(inDto.DoctorUserIdeaEnum != null, x => x.DoctorUserIdeaEnum == inDto.DoctorUserIdeaEnum!)
|
||||
.WhereIf(inDto.IsClosedDialog != null, x => x.IsClosedDialog == inDto.IsClosedDialog!)
|
||||
.WhereIf(inDto.IsHaveQuestion != null, x => x.IsHaveQuestion == inDto.IsHaveQuestion!)
|
||||
.WhereIf(inDto.MedicalDialogCloseEnum != null, x => x.MedicalDialogCloseEnum == inDto.MedicalDialogCloseEnum!)
|
||||
.WhereIf(inDto.IsInvalid != null, x => x.IsInvalid == inDto.IsInvalid!)
|
||||
.WhereIf(inDto.TrialReadingCriterionId != null, x => x.VisitTask.TrialReadingCriterionId == inDto.TrialReadingCriterionId!)
|
||||
.Select(x => new GetIRMedicalFeedbackListOutDto
|
||||
{
|
||||
TaskState=x.VisitTask.TaskState,
|
||||
Id = x.Id,
|
||||
VisitTaskId=x.VisitTaskId,
|
||||
IsUrgent = x.VisitTask.IsUrgent,
|
||||
AuditState = x.AuditState,
|
||||
SubjectCode = x.VisitTask.BlindSubjectCode == string.Empty ? x.VisitTask.Subject.Code : x.VisitTask.BlindSubjectCode,
|
||||
TaskBlindName = x.VisitTask.TaskBlindName,
|
||||
ReadingCategory = x.VisitTask.ReadingCategory,
|
||||
FirstReplyTime = x.ReadingMedicalReviewDialogList.Min(x => x.CreateTime),
|
||||
LastReplyTime = x.ReadingMedicalReviewDialogList.Max(x => x.CreateTime),
|
||||
AuditAdviceEnum = x.AuditAdviceEnum,
|
||||
DoctorUserIdeaEnum = x.DoctorUserIdeaEnum,
|
||||
SaveConclusionTime=x.SaveConclusionTime,
|
||||
IsClosedDialog=x.IsClosedDialog,
|
||||
IsHaveQuestion=x.IsHaveQuestion,
|
||||
MedicalDialogCloseEnum=x.MedicalDialogCloseEnum,
|
||||
IsInvalid=x.IsInvalid,
|
||||
|
||||
TrialReadingCriterionName=x.VisitTask.TrialReadingCriterion.CriterionName
|
||||
|
||||
}).WhereIf(!inDto.SubjectCode.IsNullOrEmpty(), x => x.SubjectCode == inDto.SubjectCode);
|
||||
|
||||
var result=await taskMedicalReviewquery.ToPagedListAsync(inDto.PageIndex, inDto.PageSize, inDto.SortField.IsNullOrEmpty() ? nameof(GetIRMedicalFeedbackListOutDto.AuditState) : inDto.SortField,
|
||||
inDto.Asc);
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
+473
@@ -0,0 +1,473 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using IRaCIS.Core.Application.ViewModel;
|
||||
using IRaCIS.Core.Infra.EFCore.Common;
|
||||
using MassTransit;
|
||||
using IRaCIS.Core.Infrastructure;
|
||||
using IRaCIS.Core.Application.Contracts;
|
||||
using IRaCIS.Core.Domain.Share;
|
||||
|
||||
namespace IRaCIS.Core.Application.Service
|
||||
{
|
||||
/// <summary>
|
||||
/// 医学审核问题
|
||||
/// </summary>
|
||||
[ ApiExplorerSettings(GroupName = "Reading")]
|
||||
public class ReadingMedicineQuestionService: BaseService, IReadingMedicineQuestionService
|
||||
{
|
||||
|
||||
private readonly IRepository<ReadingMedicineTrialQuestion> _readingMedicineTrialQuestionRepository;
|
||||
private readonly IRepository<ReadingQuestionCriterionTrial> _readingQuestionCriterionTrialRepository;
|
||||
private readonly IRepository<Trial> _trialRepository;
|
||||
private readonly IRepository<ReadingMedicineSystemQuestion> _readingMedicineSystemQuestionRepository;
|
||||
|
||||
public ReadingMedicineQuestionService(
|
||||
IRepository<ReadingMedicineTrialQuestion> readingMedicineTrialQuestionRepository,
|
||||
IRepository<ReadingQuestionCriterionTrial> readingQuestionCriterionTrial,
|
||||
IRepository<Trial> trialRepository,
|
||||
IRepository<ReadingMedicineSystemQuestion> readingMedicineSystemQuestionRepository
|
||||
)
|
||||
{
|
||||
this._readingMedicineTrialQuestionRepository = readingMedicineTrialQuestionRepository;
|
||||
this._readingQuestionCriterionTrialRepository = readingQuestionCriterionTrial;
|
||||
this._trialRepository = trialRepository;
|
||||
this._readingMedicineSystemQuestionRepository = readingMedicineSystemQuestionRepository;
|
||||
}
|
||||
|
||||
|
||||
|
||||
#region 系统
|
||||
|
||||
/// <summary>
|
||||
/// 获取系统的医学审核问题
|
||||
/// </summary>
|
||||
/// <param name="inDto"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
public async Task<List<ReadingMedicineSystemQuestionView>> GetReadingMedicineSystemQuestionList(ReadingMedicineSystemQuestionQuery inDto)
|
||||
{
|
||||
var query = _readingMedicineSystemQuestionRepository.AsQueryable()
|
||||
.WhereIf(!inDto.TypeValue.IsNullOrEmpty(), x => x.TypeValue.Contains(inDto.TypeValue))
|
||||
.WhereIf(!inDto.ParentTriggerValue.IsNullOrEmpty(), x => x.ParentTriggerValue.Contains(inDto.ParentTriggerValue))
|
||||
.WhereIf(!inDto.QuestionName.IsNullOrEmpty(), x => x.QuestionName.Contains(inDto.QuestionName))
|
||||
.WhereIf(!inDto.Type.IsNullOrEmpty(), x => x.Type.Contains(inDto.Type))
|
||||
.WhereIf(inDto.ReadingCategory != null, x => x.ReadingCategory == inDto.ReadingCategory)
|
||||
.ProjectTo<ReadingMedicineSystemQuestionView>(_mapper.ConfigurationProvider).OrderBy(x => x.ShowOrder);
|
||||
return await query.ToListAsync();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取系统的其他医学审核问题
|
||||
/// </summary>
|
||||
/// <param name="inDto"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
public async Task<List<GetReadingMedicineTrialOtherQuestionOutDto>> GetReadingMedicineSystemOtherQuestion(GetReadingMedicineSystemOtherQuestionInDto inDto)
|
||||
{
|
||||
var types = new List<string>()
|
||||
{
|
||||
"select","radio"
|
||||
};
|
||||
|
||||
var questionList = await _readingMedicineSystemQuestionRepository
|
||||
.Where(x => types.Contains(x.Type))
|
||||
.WhereIf(inDto.Id != null, x => x.Id != inDto.Id && x.ParentId != inDto.Id)
|
||||
.WhereIf(inDto.ShowOrder != null, x => x.ShowOrder < inDto.ShowOrder)
|
||||
.WhereIf(inDto.ReadingCategory != null, x => x.ReadingCategory == inDto.ReadingCategory)
|
||||
.Select(x => new GetReadingMedicineTrialOtherQuestionOutDto()
|
||||
{
|
||||
Id = x.Id,
|
||||
QuestionName = x.QuestionName,
|
||||
TypeValue = x.TypeValue,
|
||||
ReadingCategory = x.ReadingCategory,
|
||||
}).ToListAsync();
|
||||
|
||||
return questionList;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 新增或修改系统医学审核问题
|
||||
/// </summary>
|
||||
/// <param name="inDto"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
public async Task<IResponseOutput> AddOrUpdateReadingMedicineSystemQuestion(ReadingMedicineSystemQuestionAddOrEdit inDto)
|
||||
{
|
||||
var existsQuery = _readingMedicineSystemQuestionRepository
|
||||
.WhereIf(inDto.Id != null, x => x.Id != inDto.Id)
|
||||
.Where(x => x.ShowOrder == inDto.ShowOrder);
|
||||
|
||||
if (await existsQuery.AnyAsync())
|
||||
{
|
||||
return ResponseOutput.NotOk("当前问题序号存在重复");
|
||||
}
|
||||
var entity = await _readingMedicineSystemQuestionRepository.InsertOrUpdateAsync(inDto);
|
||||
await _readingMedicineSystemQuestionRepository.SaveChangesAsync();
|
||||
return ResponseOutput.Ok(entity.Id.ToString());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 删除系统的医学审核问题
|
||||
/// </summary>
|
||||
/// <param name="id"></param>
|
||||
/// <returns></returns>
|
||||
[HttpDelete("{id:guid}")]
|
||||
public async Task<IResponseOutput> DeleteReadingMedicineSystemQuestion(Guid id)
|
||||
{
|
||||
if (await _readingMedicineSystemQuestionRepository.AnyAsync(x => x.ParentId == id))
|
||||
{
|
||||
return ResponseOutput.NotOk("此问题存在子问题,请先删除子问题");
|
||||
}
|
||||
var success = await _readingMedicineSystemQuestionRepository.DeleteFromQueryAsync(t => t.Id == id);
|
||||
var result = await _readingMedicineSystemQuestionRepository.SaveChangesAsync();
|
||||
return ResponseOutput.Result(result);
|
||||
}
|
||||
#endregion
|
||||
|
||||
|
||||
#region 项目
|
||||
|
||||
/// 获取项目的医学审核问题
|
||||
/// </summary>
|
||||
/// <param name="inDto"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
public async Task<(List<ReadingMedicineTrialQuestionView>, object)> GetReadingMedicineTrialQuestionList(ReadingMedicineTrialQuestionQuery inDto)
|
||||
{
|
||||
var query = _readingMedicineTrialQuestionRepository.AsQueryable()
|
||||
.Where(x => x.TrialId == inDto.TrialId && x.TrialReadingCriterionId == inDto.TrialReadingCriterionId)
|
||||
.WhereIf(!inDto.TypeValue.IsNullOrEmpty(), x => x.TypeValue.Contains(inDto.TypeValue))
|
||||
.WhereIf(!inDto.ParentTriggerValue.IsNullOrEmpty(), x => x.ParentTriggerValue.Contains(inDto.ParentTriggerValue))
|
||||
.WhereIf(!inDto.QuestionName.IsNullOrEmpty(), x => x.QuestionName.Contains(inDto.QuestionName))
|
||||
.WhereIf(!inDto.Type.IsNullOrEmpty(), x => x.Type.Contains(inDto.Type))
|
||||
.WhereIf(inDto.ReadingCategory != null, x => x.ReadingCategory == inDto.ReadingCategory)
|
||||
.ProjectTo<ReadingMedicineTrialQuestionView>(_mapper.ConfigurationProvider).OrderBy(x => x.ShowOrder);
|
||||
|
||||
|
||||
var isConfirmMedicineQuestion = await _readingQuestionCriterionTrialRepository.Where(x => x.Id == inDto.TrialReadingCriterionId).Select(x => x.IsConfirmMedicineQuestion).FirstOrDefaultAsync();
|
||||
var questionList = await query.ToListAsync();
|
||||
return (questionList, new
|
||||
{
|
||||
IsConfirmMedicineQuestion = isConfirmMedicineQuestion,
|
||||
QuestionCount = questionList.Count(),
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 获取项目的其他医学审核问题
|
||||
/// </summary>
|
||||
/// <param name="inDto"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
public async Task<List<GetReadingMedicineTrialOtherQuestionOutDto>> GetReadingMedicineTrialOtherQuestion(GetReadingMedicineTrialOtherQuestionInDto inDto)
|
||||
{
|
||||
var types = new List<string>()
|
||||
{
|
||||
"select","radio"
|
||||
};
|
||||
|
||||
var questionList = await _readingMedicineTrialQuestionRepository.Where(x => x.TrialId == inDto.TrialId && x.TrialReadingCriterionId == inDto.TrialReadingCriterionId)
|
||||
.Where(x => types.Contains(x.Type))
|
||||
.WhereIf(inDto.Id != null, x => x.Id != inDto.Id && x.ParentId != inDto.Id)
|
||||
.WhereIf(inDto.ShowOrder != null, x => x.ShowOrder < inDto.ShowOrder)
|
||||
.WhereIf(inDto.ReadingCategory != null, x => x.ReadingCategory == inDto.ReadingCategory)
|
||||
.Select(x => new GetReadingMedicineTrialOtherQuestionOutDto()
|
||||
{
|
||||
Id = x.Id,
|
||||
QuestionName = x.QuestionName,
|
||||
TypeValue = x.TypeValue,
|
||||
ReadingCategory = x.ReadingCategory,
|
||||
}).ToListAsync();
|
||||
|
||||
return questionList;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// <summary>
|
||||
/// 获取预览问题信息
|
||||
/// </summary>
|
||||
/// <param name="inDto"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
public async Task<List<GetMedicineQuestionPreviewOutDto>> GetMedicineQuestionPreview(GetMedicineQuestionPreviewInDto inDto)
|
||||
{
|
||||
var trialQuestionList = await _readingMedicineTrialQuestionRepository.Where(x => x.TrialId == inDto.TrialId && x.TrialReadingCriterionId == inDto.TrialReadingCriterionId)
|
||||
.WhereIf(inDto.ReadingCategory != null, x => x.ReadingCategory == inDto.ReadingCategory)
|
||||
.ProjectTo<GetMedicineQuestionPreviewOutDto>(_mapper.ConfigurationProvider).OrderBy(x => x.ShowOrder).ToListAsync();
|
||||
|
||||
List<GetMedicineQuestionPreviewOutDto> readingQuestionList = trialQuestionList.Where(x => x.ParentId == null).ToList();
|
||||
readingQuestionList.ForEach(x =>
|
||||
{
|
||||
FindChildQuestion(x, trialQuestionList);
|
||||
});
|
||||
|
||||
return readingQuestionList;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 新增或修改项目医学审核问题
|
||||
/// </summary>
|
||||
/// <param name="inDto"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
public async Task<IResponseOutput> AddOrUpdateReadingMedicineTrialQuestion(ReadingMedicineTrialQuestionAddOrEdit inDto)
|
||||
{
|
||||
var existsQuery = _readingMedicineTrialQuestionRepository
|
||||
.WhereIf(inDto.Id != null, x => x.Id != inDto.Id)
|
||||
.Where(x => x.TrialId == inDto.TrialId && x.TrialReadingCriterionId == inDto.TrialReadingCriterionId)
|
||||
.Where(x => x.ShowOrder == inDto.ShowOrder);
|
||||
|
||||
if (await existsQuery.AnyAsync())
|
||||
{
|
||||
return ResponseOutput.NotOk("当前问题序号存在重复");
|
||||
}
|
||||
var entity = await _readingMedicineTrialQuestionRepository.InsertOrUpdateAsync(inDto);
|
||||
await _readingMedicineTrialQuestionRepository.SaveChangesAsync();
|
||||
return ResponseOutput.Ok(entity.Id.ToString());
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 删除项目的医学审核问题
|
||||
/// </summary>
|
||||
/// <param name="inDto"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
public async Task<IResponseOutput> DeleteReadingMedicineTrialQuestion(DeleteReadingMedicineTrialQuestion inDto)
|
||||
{
|
||||
if (await _readingMedicineTrialQuestionRepository.AnyAsync(x => x.ParentId == inDto.Id))
|
||||
{
|
||||
return ResponseOutput.NotOk("此问题存在子问题,请先删除子问题");
|
||||
}
|
||||
var success = await _readingMedicineTrialQuestionRepository.DeleteFromQueryAsync(t => t.Id == inDto.Id);
|
||||
var result = await _readingMedicineTrialQuestionRepository.SaveChangesAsync();
|
||||
return ResponseOutput.Result(result);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
|
||||
#region 项目 医学审核问题 验证 确认
|
||||
|
||||
/// <summary>
|
||||
/// 验证医学审核问题
|
||||
/// </summary>
|
||||
/// <param name="inDto"></param>
|
||||
/// <returns></returns>
|
||||
/// <exception cref="BusinessValidationFailedException"></exception>
|
||||
public async Task<IResponseOutput> VerifyReadingMedicineQuestion(ConfirmReadingMedicineQuestionInDto inDto)
|
||||
{
|
||||
var readingMedicineQuestionList = await _readingMedicineTrialQuestionRepository.Where(x => x.TrialId == inDto.TrialId && x.TrialReadingCriterionId == inDto.TrialReadingCriterionId)
|
||||
.Select(x => new TrialQuestion()
|
||||
{
|
||||
Id = x.Id,
|
||||
ReadingCategory = x.ReadingCategory,
|
||||
ParentShowOrder = (int?)x.ParentQuestion.ShowOrder,
|
||||
ShowOrder = x.ShowOrder,
|
||||
}).ToListAsync();
|
||||
if (readingMedicineQuestionList.Count == 0)
|
||||
{
|
||||
throw new BusinessValidationFailedException("当前未添加医学审核问题。请先添加医学审核问题,再进行确认。");
|
||||
}
|
||||
|
||||
if (readingMedicineQuestionList.Count() != readingMedicineQuestionList.Select(t => t.ShowOrder).Distinct().Count())
|
||||
{
|
||||
throw new BusinessValidationFailedException("影像医学审核问题显示序号不能重复。");
|
||||
}
|
||||
|
||||
|
||||
if (readingMedicineQuestionList.Where(t => t.ParentShowOrder != null).Any(t => t.ParentShowOrder > t.ShowOrder))
|
||||
{
|
||||
throw new BusinessValidationFailedException("父问题的显示序号要比子问题的显示序号小,请确认。");
|
||||
}
|
||||
|
||||
var criterionInfo = await _readingQuestionCriterionTrialRepository.Where(x => x.Id == inDto.TrialReadingCriterionId).Select(x => new
|
||||
{
|
||||
x.IsGlobalReading,
|
||||
x.IsOncologyReading,
|
||||
x.IsArbitrationReading,
|
||||
}).FirstNotNullAsync();
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
if (criterionInfo.IsGlobalReading && !readingMedicineQuestionList.Any(x => x.ReadingCategory == ReadingCategory.Global))
|
||||
{
|
||||
throw new BusinessValidationFailedException("当前项目启用了全局阅片,但未配置全局医学审核问题");
|
||||
}
|
||||
|
||||
if (criterionInfo.IsArbitrationReading && !readingMedicineQuestionList.Any(x => x.ReadingCategory == ReadingCategory.Judge))
|
||||
{
|
||||
throw new BusinessValidationFailedException("当前项目启用了仲裁阅片,但未配置仲裁医学审核问题");
|
||||
}
|
||||
|
||||
if (criterionInfo.IsOncologyReading && !readingMedicineQuestionList.Any(x => x.ReadingCategory == ReadingCategory.Oncology))
|
||||
{
|
||||
throw new BusinessValidationFailedException("当前项目启用了肿瘤学阅片,但未配置肿瘤学医学审核问题");
|
||||
}
|
||||
|
||||
return ResponseOutput.Ok();
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 确认医学审核问题
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public async Task<IResponseOutput> ConfirmReadingMedicineQuestion(ConfirmReadingMedicineQuestionInDto inDto)
|
||||
{
|
||||
|
||||
var criterionInfo = await _readingQuestionCriterionTrialRepository.Where(x => x.Id == inDto.TrialReadingCriterionId).Select(x => new
|
||||
{
|
||||
x.IsGlobalReading,
|
||||
x.IsOncologyReading,
|
||||
x.IsArbitrationReading,
|
||||
}).FirstNotNullAsync();
|
||||
var readingMedicineQuestionList = await _readingMedicineTrialQuestionRepository.Where(x => x.TrialId == inDto.TrialId && x.TrialReadingCriterionId == inDto.TrialReadingCriterionId)
|
||||
.Select(x => new TrialQuestion()
|
||||
{
|
||||
Id = x.Id,
|
||||
ReadingCategory = x.ReadingCategory,
|
||||
ParentShowOrder = (int?)x.ParentQuestion.ShowOrder,
|
||||
ShowOrder = x.ShowOrder,
|
||||
}).ToListAsync();
|
||||
if (readingMedicineQuestionList.Count == 0)
|
||||
{
|
||||
throw new BusinessValidationFailedException("当前未添加医学审核问题。请先添加医学审核问题,再进行确认。");
|
||||
}
|
||||
|
||||
if (readingMedicineQuestionList.Count() != readingMedicineQuestionList.Select(t => t.ShowOrder).Distinct().Count())
|
||||
{
|
||||
throw new BusinessValidationFailedException("影像医学审核问题显示序号不能重复。");
|
||||
}
|
||||
|
||||
|
||||
if (readingMedicineQuestionList.Where(t => t.ParentShowOrder != null).Any(t => t.ParentShowOrder > t.ShowOrder))
|
||||
{
|
||||
throw new BusinessValidationFailedException("父问题的显示序号要比子问题的显示序号小,请确认。");
|
||||
}
|
||||
|
||||
|
||||
var trialInfo = await _trialRepository.Where(x => x.Id == inDto.TrialId).FirstNotNullAsync();
|
||||
|
||||
if (criterionInfo.IsGlobalReading && !readingMedicineQuestionList.Any(x => x.ReadingCategory == ReadingCategory.Global))
|
||||
{
|
||||
throw new BusinessValidationFailedException("当前项目启用了全局阅片,但未配置全局医学审核问题");
|
||||
}
|
||||
|
||||
if (criterionInfo.IsArbitrationReading && !readingMedicineQuestionList.Any(x => x.ReadingCategory == ReadingCategory.Judge))
|
||||
{
|
||||
throw new BusinessValidationFailedException("当前项目启用了仲裁阅片,但未配置仲裁医学审核问题");
|
||||
}
|
||||
|
||||
if (criterionInfo.IsOncologyReading && !readingMedicineQuestionList.Any(x => x.ReadingCategory == ReadingCategory.Oncology))
|
||||
{
|
||||
throw new BusinessValidationFailedException("当前项目启用了肿瘤学阅片,但未配置肿瘤学医学审核问题");
|
||||
}
|
||||
|
||||
|
||||
await _readingMedicineTrialQuestionRepository.BatchUpdateNoTrackingAsync(x => x.TrialId == inDto.TrialId, x => new ReadingMedicineTrialQuestion()
|
||||
{
|
||||
IsConfirm = true
|
||||
});
|
||||
|
||||
await _readingQuestionCriterionTrialRepository.UpdatePartialFromQueryAsync(inDto.TrialReadingCriterionId, x => new ReadingQuestionCriterionTrial()
|
||||
{
|
||||
IsConfirmMedicineQuestion = true
|
||||
});
|
||||
|
||||
var result = await _trialRepository.SaveChangesAsync();
|
||||
return ResponseOutput.Result(result);
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
|
||||
private void FindChildQuestion(GetMedicineQuestionPreviewOutDto trialReadingQuestion, List<GetMedicineQuestionPreviewOutDto> questionlists)
|
||||
{
|
||||
trialReadingQuestion.Childrens = questionlists.Where(x => x.ParentId == trialReadingQuestion.Id).ToList();
|
||||
if (trialReadingQuestion.Childrens != null && trialReadingQuestion.Childrens.Count != 0)
|
||||
{
|
||||
trialReadingQuestion.Childrens.ForEach(x =>
|
||||
{
|
||||
this.FindChildQuestion(x, questionlists);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 从系统里面选择问题添加到项目里面
|
||||
/// </summary>
|
||||
/// <param name="inDto"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
public async Task<IResponseOutput> AddTrialDataFromSystem(AddTrialDataFromSystemInDto inDto)
|
||||
{
|
||||
// 直接写??
|
||||
var systemList = await _readingMedicineSystemQuestionRepository.Where(x => inDto.SystemQuestionIds.Contains(x.Id)).ToListAsync();
|
||||
|
||||
var maxOrder = await _readingMedicineTrialQuestionRepository.Where(x => x.TrialId == inDto.TrialId).OrderByDescending(x => x.ShowOrder).Select(x => x.ShowOrder).FirstOrDefaultAsync();
|
||||
|
||||
|
||||
var needList= systemList.Select(x => new TrialDataFromSystem()
|
||||
{
|
||||
Id = NewId.NextGuid(),
|
||||
ShowOrder = x.ShowOrder,
|
||||
IsEnable = x.IsEnable,
|
||||
IsRequired = x.IsRequired,
|
||||
QuestionName = x.QuestionName,
|
||||
TrialReadingCriterionId=inDto.TrialReadingCriterionId,
|
||||
Type = x.Type,
|
||||
ParentId=x.ParentId,
|
||||
SystemQuestionId=x.Id,
|
||||
ReadingCategory=x.ReadingCategory,
|
||||
TypeValue = x.TypeValue,
|
||||
TrialId=inDto.TrialId,
|
||||
}).ToList();
|
||||
|
||||
needList.ForEach(x => {
|
||||
maxOrder++;
|
||||
x.ShowOrder = maxOrder;
|
||||
});
|
||||
|
||||
foreach (var item in needList.Where(x => x.ParentId != null))
|
||||
{
|
||||
var parent = needList.Where(x => x.SystemQuestionId == item.ParentId).FirstOrDefault();
|
||||
if (parent == null)
|
||||
{
|
||||
item.ParentId = null;
|
||||
item.ParentTriggerValue = String.Empty;
|
||||
}
|
||||
else
|
||||
{
|
||||
item.ParentId = parent.Id;
|
||||
}
|
||||
}
|
||||
|
||||
await _readingMedicineTrialQuestionRepository.AddRangeAsync(needList);
|
||||
var result = await _readingMedicineTrialQuestionRepository.SaveChangesAsync();
|
||||
return ResponseOutput.Result(result);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user