using System; using System.Collections.Generic; using IRaCIS.Api.Filter; using IRaCIS.Application.Interfaces; using IRaCIS.Application.ViewModels; using IRaCIS.Core.Application.Contracts.RequestAndResponse; using IRaCIS.Core.Domain.Share.AuthUser; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; namespace IRaCIS.Api.Controllers { /// /// 项目基本信息维护 /// [Route("trial")] [ApiController, Authorize, ApiExplorerSettings(GroupName = "Trial")] public class TrialController : ControllerBase { private readonly ITrialService _trialService; private readonly ITrialWorkloadService _trialWorkloadService; private readonly IUserInfo _userInfo; private readonly ICalculateService _calculateService; public TrialController(ITrialService trialService, ITrialWorkloadService trialWorkloadService,IUserInfo userInfo,ICalculateService calculateService) { _trialService = trialService; _trialWorkloadService = trialWorkloadService; _userInfo = userInfo; _calculateService = calculateService; } #region 项目查询 /// 分页获取临床实验项目列表(查询条件) /// 查询参数 /// [HttpPost, Route("getTrialList")] public IResponseOutput> GetTrialList(TrialQueryDTO param) { var userId = Guid.Parse(User.FindFirst("id").Value); return ResponseOutput.Ok(_trialService.GetTrialList(param, userId)) ; } /// 查询项目基本信息 /// 项目Id /// [HttpGet, Route("getTrialInfo/{trialId:guid}")] public IResponseOutput GetTrialInfoAndLockState(Guid trialId) { var trial = _trialService.GetTrialInfoAndLockState(trialId); return ResponseOutput.Ok(trial); } /// 查询项目基本信息 和项目最大状态, /// 项目Id /// [HttpGet, Route("getTrialInfoAndMaxTrialState/{trialId:guid}")] public IResponseOutput GetTrialInfoAndMaxTrialState(Guid trialId) { var result = new TrialAndTrialStateVieModel() { TrialView = _trialService.GetTrialInfoAndLockState(trialId), TrialMaxState = _trialService.GetTrialMaxState(trialId) }; return ResponseOutput.Ok(result); } /// 查询项目加急状态 /// 项目Id /// [HttpGet, Route("getTrialExpeditedState/{trialId:guid}")] public IResponseOutput GetTrialExpeditedState(Guid trialId) { return ResponseOutput.Ok(_trialService.GetTrialExpeditedState(trialId)); } /// /// 根据项目状态获取医生项目列表[New] /// /// 5-Submitted,8-Approved,10-Reading /// [HttpPost, Route("getDoctorTrialListByStatus")] [AllowAnonymous] public IResponseOutput> GetDoctorTrialListByStatus( TrialByStatusQueryDTO param) { return ResponseOutput.Ok(_trialService.GetReviewerTrialListByEnrollmentStatus(param)) ; } #endregion #region 项目更新删除 /// 添加实验项目-返回新增Id[AUTH] /// /// 新记录Id [LogFilter] [HttpPost, Route("addOrUpdateTrial")] public IResponseOutput AddOrUpdateTrial(TrialCommand param) { var userId = Guid.Parse(User.FindFirst("id").Value); var result= _trialService.AddOrUpdateTrial(param, userId); if (_trialService.TrialExpeditedChange) { var needCalReviewerIds = _trialService.GetTrialEnrollmentReviewerIds(param.Id); var calcList = _calculateService.GetNeedCalculateReviewerList(Guid.Empty, string.Empty); calcList.ForEach(t=> { if (needCalReviewerIds.Contains(t.DoctorId)) { _calculateService.CalculateMonthlyPayment(new CalculateDoctorAndMonthDTO() { NeedCalculateReviewers = new List() { t.DoctorId }, CalculateMonth = DateTime.Parse(t.YearMonth) }, User.FindFirst("id").Value); } }); } return result; } [LogFilter] [HttpPost, Route("confirmTrialVisitPlan/{trialId:guid}")] public IResponseOutput ConfirmTrialVisitPlan(Guid trialId) { return _trialService.ConfirmTrialVisitPlan(trialId); } /// /// 手动更新项目状态 /// /// 项目Id /// 状态值 /// [LogFilter] [HttpPost, Route("updateTrialStatus/{trialId:guid}/{statusStr}")] public IResponseOutput UpdateTrialStatusStr(Guid trialId, string statusStr) { if (string.IsNullOrWhiteSpace(statusStr)) { return ResponseOutput.NotOk("please select status."); } var result = _trialService.UpdateTrialStatus(trialId, statusStr); return result; } /// 删除临床项目 /// 临床试验项目Id [LogFilter] [HttpDelete, Route("deleteTrial/{trialId:guid}")] public IResponseOutput DeleteTrial(Guid trialId) { return _trialService.DeleteTrial(trialId); } #endregion #region ack sow /// /// 保存协议- ack Sow [AUTH] /// [HttpPost, Route("uploadReviewerAckSOW/{trialId}")] public IResponseOutput UploadReviewerAckSOW(Guid trialId, ReviewerAckDTO attachmentViewModel) { var userId = Guid.Parse(User.FindFirst("id").Value); return _trialWorkloadService.UploadReviewerAckSOW(userId, trialId, attachmentViewModel); } /// /// 删除协议 /// [HttpDelete, Route("deleteReviewerAckSOW/{trialId}/{doctorId}/{attachmentId}")] public IResponseOutput DeleteReviewerAckSOW(Guid trialId, Guid doctorId, Guid attachmentId) { return _trialWorkloadService.DeleteReviewerAckSOW(trialId, doctorId, attachmentId); } /// /// 0代表裁判和Tp 都可以 1、代表Tp 2 代表裁判 /// /// /// /// /// [HttpPost, Route("updateReviewerReadingType/{trialId}/{doctorId}/{reviewerReadingType}")] public IResponseOutput UpdateReviewerReadingType(Guid trialId, Guid doctorId, int reviewerReadingType) { return _trialWorkloadService.UpdateReviewerReadingType(trialId, doctorId, reviewerReadingType); } #endregion #region 医生用户接口 /// 分页获取医生参与的临床实验项目列表(查询条件) /// 查询参数 /// [HttpPost, Route("getTrialListByReviewer")] public IResponseOutput> GetTrialListByReviewer(ReviewerTrialQueryDTO param) { var userId = Guid.Parse(User.FindFirst("id").Value); return ResponseOutput.Ok(_trialService.GetTrialListByReviewer(param, userId)); } /// /// 医生确认入组或拒绝入组 /// /// 项目Id /// 9-拒绝入组,10-确认入组 /// [HttpPost, Route("updateEnrollStatus/{trialId:guid}/{status:int}")] public IResponseOutput UpdateTrialStatusStr(Guid trialId, int status) { return _trialService.UpdateEnrollStatus(trialId, status); } #endregion } }