//-------------------------------------------------------------------- // 此代码由T4模板自动生成 byzhouhang 20210918 // 生成时间 2022-06-07 13:14:38 // 对此文件的更改可能会导致不正确的行为,并且如果重新生成代码,这些更改将会丢失。 //-------------------------------------------------------------------- using IRaCIS.Core.Domain.Models; using Microsoft.AspNetCore.Mvc; using IRaCIS.Core.Application.Interfaces; using IRaCIS.Core.Application.ViewModel; using IRaCIS.Core.Application.Contracts; using IRaCIS.Core.Domain.Share; namespace IRaCIS.Core.Application.Service { /// /// 分配规则 /// [ApiExplorerSettings(GroupName = "Trial")] public class TaskAllocationRuleService : BaseService, ITaskAllocationRuleService { private readonly IRepository _taskAllocationRuleRepository; private readonly IRepository _userRepository; private readonly IRepository _trialRepository; private readonly IRepository _subjectCanceDoctorRepository; public TaskAllocationRuleService(IRepository taskAllocationRuleRepository, IRepository userRepository, IRepository trialRepository, IRepository subjectCanceDoctorRepository) { _taskAllocationRuleRepository = taskAllocationRuleRepository; _userRepository = userRepository; _trialRepository = trialRepository; _subjectCanceDoctorRepository = subjectCanceDoctorRepository; } /// /// 获取计划列表 医生带阅片类型 /// /// /// public async Task<(List, object?)> GetDoctorPlanAllocationRuleList(Guid trialId) { var list = await _taskAllocationRuleRepository.Where(t => t.TrialId == trialId).ProjectTo(_mapper.ConfigurationProvider).ToListAsync(); var trialTaskConfig = _trialRepository.Where(t => t.Id == trialId).ProjectTo(_mapper.ConfigurationProvider).FirstOrDefault(); return (list, trialTaskConfig); } public async Task AddOrUpdateTaskAllocationRule(TaskAllocationRuleAddOrEdit addOrEditTaskAllocationRule) { //冗余 存 var enrollId = _repository.Where(t => t.TrialId == addOrEditTaskAllocationRule.TrialId && t.DoctorUserId == addOrEditTaskAllocationRule.DoctorUserId).Select(t => t.Id).FirstOrDefault(); if (enrollId == Guid.Empty) { return ResponseOutput.NotOk("错误,未在入组表中找到该医生得账号Id"); } addOrEditTaskAllocationRule.EnrollId = enrollId; var verifyExp1 = new EntityVerifyExp() { VerifyExp = t => t.DoctorUserId == addOrEditTaskAllocationRule.DoctorUserId && t.TrialId == addOrEditTaskAllocationRule.TrialId, VerifyMsg = "已有该医生配置,不允许继续增加" }; var entity = await _taskAllocationRuleRepository.InsertOrUpdateAsync(addOrEditTaskAllocationRule, true, verifyExp1); return ResponseOutput.Ok(entity.Id.ToString()); } [HttpDelete("{taskAllocationRuleId:guid}")] public async Task DeleteTaskAllocationRule(Guid taskAllocationRuleId) { if (await _taskAllocationRuleRepository.Where(t => t.Id == taskAllocationRuleId).AnyAsync(t => t.DoctorUser.VisitTaskList.Where(u => u.TrialId == t.TrialId).Any())) { return ResponseOutput.NotOk("已分配任务给该医生,不允许删除"); } var success = await _taskAllocationRuleRepository.DeleteFromQueryAsync(t => t.Id == taskAllocationRuleId, true); return ResponseOutput.Ok(); } //public async Task AddSubjectCancelDoctorNote(CancelDoctorCommand command) //{ // await _subjectCanceDoctorRepository.InsertOrUpdateAsync(command, true); // return ResponseOutput.Ok(); //} public async Task> GetSubjectCancelDoctorHistoryList(Guid subjectId) { var list = await _subjectCanceDoctorRepository.Where(t => t.SubjectId == subjectId).ProjectTo(_mapper.ConfigurationProvider).ToListAsync(); return list; } /// /// 获取访视任务 应用Subject后 医生比率情况 /// /// [HttpPost] [Obsolete] public async Task> GetSubjectApplyDoctorTaskStatList(ApplySubjectCommand assignConfirmCommand) { var taskAllocationRuleQueryable = _taskAllocationRuleRepository.Where(t => t.TrialId == assignConfirmCommand.TrialId && t.IsJudgeDoctor == assignConfirmCommand.IsJudgeDoctor) .ProjectTo(_mapper.ConfigurationProvider, new { subjectIdList = assignConfirmCommand.SubjectIdList, isJudgeDoctor = assignConfirmCommand.IsJudgeDoctor }); return await taskAllocationRuleQueryable.ToListAsync(); } [HttpPost] [Obsolete] public async Task<(List, object?)> GetTaskAllocationRuleList(TaskAllocationRuleQuery queryTaskAllocationRule) { var taskAllocationRuleQueryable = _taskAllocationRuleRepository.Where(t => t.TrialId == queryTaskAllocationRule.TrialId /*&& t.IsJudgeDoctor == queryTaskAllocationRule.IsJudgeDoctor*/) .ProjectTo(_mapper.ConfigurationProvider); var trialTaskConfig = _trialRepository.Where(t => t.Id == queryTaskAllocationRule.TrialId).ProjectTo(_mapper.ConfigurationProvider, new { isJudgeDoctor = queryTaskAllocationRule.IsJudgeDoctor }).FirstOrDefault(); return (await taskAllocationRuleQueryable.ToListAsync(), trialTaskConfig); } /// /// 获取项目下 医生账户信息下拉 /// /// /// /// [HttpGet("{trialId:guid}")] public async Task> GetDoctorUserSelectList(Guid trialId, [FromServices] IRepository _enrollRepository) { var query = from enroll in _enrollRepository.Where(t => t.TrialId == trialId && t.EnrollStatus >= EnrollStatus.ConfirmIntoGroup) join user in _userRepository.AsQueryable() on enroll.DoctorId equals user.DoctorId select new TrialDoctorUserSelectView() { TrialId = enroll.TrialId, ReadingType = enroll.Trial.ReadingType, DoctorUserId = user.Id, FullName = user.FullName, UserCode = user.UserCode, UserName = user.UserName, UserTypeEnum = user.UserTypeRole.UserTypeEnum, ReadingCategoryList = enroll.EnrollReadingCategoryList.Select(t => t.ReadingCategory).ToList() }; return await query.ToListAsync(); } [HttpPost] public async Task> GetDoctorSelectList(DoctorSelectQuery selectQuery, [FromServices] IRepository _enrollRepository) { var query = from allocationRule in _taskAllocationRuleRepository.Where(t => t.TrialId == selectQuery.TrialId && t.IsEnable) .WhereIf(selectQuery.ReadingCategory != null, t => t.Enroll.EnrollReadingCategoryList.Any(t => t.ReadingCategory == selectQuery.ReadingCategory)) join user in _userRepository.AsQueryable() on allocationRule.DoctorUserId equals user.Id select new TrialDoctorUserSelectView() { TrialId = allocationRule.TrialId, ReadingType = allocationRule.Trial.ReadingType, DoctorUserId = user.Id, FullName = user.FullName, UserCode = user.UserCode, UserName = user.UserName, UserTypeEnum = user.UserTypeRole.UserTypeEnum, ReadingCategoryList = allocationRule.Enroll.EnrollReadingCategoryList.Select(t => t.ReadingCategory).ToList() }; return await query.ToListAsync(); } } }