418 lines
19 KiB
C#
418 lines
19 KiB
C#
|
|
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 IRepository<TaskMedicalReview> _taskMedicalReviewRepository;
|
|
private readonly IRepository<ReadingMedicalReviewDialog> _readingMedicalReviewDialogRepository;
|
|
private readonly IRepository<ReadingMedicineQuestionAnswer> _readingMedicineQuestionAnswerRepository;
|
|
private readonly IRepository<ReadingMedicineSystemQuestion> _readingMedicineSystemQuestionRepository;
|
|
|
|
public ReadingMedicalReviewService(
|
|
IRepository<ReadingMedicineTrialQuestion> readingMedicineTrialQuestionRepository,
|
|
IRepository<Trial> trialRepository,
|
|
IRepository<VisitTask> visitTaskRepository,
|
|
IRepository<User> userTaskRepository,
|
|
IRepository<TaskMedicalReview> taskMedicalReviewRepository,
|
|
IRepository<ReadingMedicalReviewDialog> readingMedicalReviewDialogRepository,
|
|
IRepository<ReadingMedicineQuestionAnswer> readingMedicineQuestionAnswerRepository,
|
|
IRepository<ReadingMedicineSystemQuestion> readingMedicineSystemQuestionRepository
|
|
)
|
|
{
|
|
this._readingMedicineTrialQuestionRepository = readingMedicineTrialQuestionRepository;
|
|
this._trialRepository = trialRepository;
|
|
this._visitTaskRepository = visitTaskRepository;
|
|
this._userTaskRepository = userTaskRepository;
|
|
this._taskMedicalReviewRepository = taskMedicalReviewRepository;
|
|
this._readingMedicalReviewDialogRepository = readingMedicalReviewDialogRepository;
|
|
this._readingMedicineQuestionAnswerRepository = readingMedicineQuestionAnswerRepository;
|
|
this._readingMedicineSystemQuestionRepository = readingMedicineSystemQuestionRepository;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 获取医学审核任务信息
|
|
/// </summary>
|
|
/// <param name="inDto"></param>
|
|
/// <returns></returns>
|
|
[HttpPost]
|
|
public async Task<GetMedicalReviewReadingTaskOutDto> GetMedicalReviewReadingTask(GetMedicalReviewReadingTaskInDto inDto)
|
|
{
|
|
var medicalReviewInfo = await _trialRepository.Where(x => x.Id == inDto.TrialId).Select(x => new GetMedicalReviewReadingTaskOutDto()
|
|
{
|
|
ReadingType=x.ReadingType,
|
|
IsReadingTaskViewInOrder=x.IsReadingTaskViewInOrder
|
|
}).FirstNotNullAsync();
|
|
|
|
medicalReviewInfo.MedicalReviewInfo = await _taskMedicalReviewRepository.Where(x => x.Id == inDto.TaskMedicalReviewId)
|
|
.ProjectTo<MedicalReviewInfo>(_mapper.ConfigurationProvider).FirstNotNullAsync();
|
|
|
|
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;
|
|
|
|
|
|
#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.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,
|
|
}).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
|
|
).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,
|
|
}).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
|
|
).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);
|
|
|
|
|
|
return medicalReviewInfo;
|
|
|
|
}
|
|
|
|
#region 问题
|
|
private async Task<List<ReadingMedicineQuestion>> GetMedicalQuestionAnswer(GetMedicalReviewReadingTaskInDto inDto)
|
|
{
|
|
var questionQuery = from data in _readingMedicineTrialQuestionRepository.Where(x => x.TrialId == inDto.TrialId && x.IsConfirm && x.IsEnable)
|
|
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)
|
|
{
|
|
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
|
|
});
|
|
|
|
var result = await _readingMedicineQuestionAnswerRepository.SaveChangesAsync();
|
|
|
|
return ResponseOutput.Result(result);
|
|
|
|
}
|
|
|
|
/// <summary>
|
|
/// 保存医学审核信息
|
|
/// </summary>
|
|
/// <param name="inDto"></param>
|
|
/// <returns></returns>
|
|
public async Task<IResponseOutput> SaveMedicalReviewInfo(SaveMedicalReviewInfoInDto inDto)
|
|
{
|
|
await _taskMedicalReviewRepository.UpdatePartialFromQueryAsync(inDto.TaskMedicalReviewId, x => new TaskMedicalReview()
|
|
{
|
|
IsHaveQuestion = inDto.IsHaveQuestion,
|
|
Questioning = inDto.Questioning,
|
|
|
|
AuditAdviceEnum = inDto.AuditAdviceEnum,
|
|
|
|
SaveConclusionTime=DateTime.Now,
|
|
|
|
});
|
|
|
|
if(inDto.IsSendDialog)
|
|
{
|
|
var medicalReview = await _taskMedicalReviewRepository.Where(x => x.Id == inDto.TaskMedicalReviewId).FirstNotNullAsync();
|
|
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
|
|
});
|
|
|
|
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 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,
|
|
DisagreeReason=inDto.DisagreeReason,
|
|
DoctorUserIdeaEnum=inDto.DoctorUserIdeaEnum,
|
|
IsApplyHeavyReading=inDto.IsApplyHeavyReading,
|
|
IsHaveQuestion=inDto.IsHaveQuestion,
|
|
Questioning=inDto.Questioning,
|
|
};
|
|
|
|
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 {
|
|
|
|
taskMedicalReview.IsClosedDialog,
|
|
});
|
|
}
|
|
|
|
/// <summary>
|
|
/// 完成医学审核
|
|
/// </summary>
|
|
/// <param name="inDto"></param>
|
|
/// <returns></returns>
|
|
[NonDynamicMethod]
|
|
public async Task<IResponseOutput> FinishMedicalReview(FinishMedicalReviewInDto inDto)
|
|
{
|
|
|
|
var taskmedicalReview = await _taskMedicalReviewRepository.Where(x => x.Id == inDto.TaskMedicalReviewId).Select(x => new
|
|
{
|
|
x.SaveConclusionTime,
|
|
x.SaveQuestionTime,
|
|
|
|
}).FirstNotNullAsync();
|
|
|
|
if (taskmedicalReview.SaveQuestionTime == null || taskmedicalReview.SaveConclusionTime==null)
|
|
{
|
|
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)
|
|
{
|
|
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);
|
|
}
|
|
|
|
|
|
}
|
|
}
|