diff --git a/IRaCIS.Core.Application/Service/Reading/Dto/ReadingCalculateViewModel.cs b/IRaCIS.Core.Application/Service/Reading/Dto/ReadingCalculateViewModel.cs index f580bda15..599bb8379 100644 --- a/IRaCIS.Core.Application/Service/Reading/Dto/ReadingCalculateViewModel.cs +++ b/IRaCIS.Core.Application/Service/Reading/Dto/ReadingCalculateViewModel.cs @@ -234,6 +234,34 @@ namespace IRaCIS.Core.Application.Service.Reading.Dto } } + public class OCTFCTUploadData + { + /// + /// 斑块编号 + /// + public int PlaqueNum { get; set; } + + /// + /// 第一次 + /// + public int FirstData { get; set; } + + /// + /// 第二次 + /// + public int SecondData { get; set; } + + /// + /// 第三次 + /// + public int ThirdData { get; set; } + + public decimal Avg { get { + + return ( FirstData*1m + SecondData * 1m + ThirdData * 1m) / 3; + } } + } + public class OCTInfo { diff --git a/IRaCIS.Core.Application/Service/ReadingCalculate/OCTCalculateService.cs b/IRaCIS.Core.Application/Service/ReadingCalculate/OCTCalculateService.cs index 414e7cb28..ba5225d8d 100644 --- a/IRaCIS.Core.Application/Service/ReadingCalculate/OCTCalculateService.cs +++ b/IRaCIS.Core.Application/Service/ReadingCalculate/OCTCalculateService.cs @@ -2,7 +2,9 @@ using IRaCIS.Core.Application.ViewModel; using IRaCIS.Core.Domain.Share; using IRaCIS.Core.Infra.EFCore.Common; +using IRaCIS.Core.Infrastructure; using MassTransit; +using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; using Microsoft.Extensions.Logging; @@ -18,6 +20,7 @@ namespace IRaCIS.Core.Application.Service.ReadingCalculate IRepository _readingTableAnswerRowInfoRepository, IRepository _readingQuestionTrialRepository, IRepository _organInfoRepository, + IHttpContextAccessor httpContext, IRepository _readingGlobalTaskInfoRepository, IRepository _subjectVisitRepository, IRepository _tumorAssessmentRepository, @@ -456,6 +459,159 @@ namespace IRaCIS.Core.Application.Service.ReadingCalculate }); } + /// + /// 导入OCT-FCT数据 + /// + /// + [HttpPost] + public async Task UploadOCTFCTTemplate() + { + var request = httpContext.HttpContext!.Request; + var file = request.Form.Files[0]; + Guid visitTaskId = Guid.Parse(request.Form["VisitTaskId"]); + var dataTable = await _generalCalculateService.GetDataTableFromUpload(file); + + var taskinfo = await _visitTaskRepository.Where(x => x.Id == visitTaskId).Include(x => x.Subject).Include(x => x.TrialReadingCriterion).FirstNotNullAsync(); + + var values = new + { + SubjectID = taskinfo.BlindSubjectCode.IsNullOrEmpty() ? taskinfo.Subject.Code : taskinfo.BlindSubjectCode, + TaskBlindName = taskinfo.TaskBlindName, + }; + + if (values.SubjectID != dataTable.Rows[0]["B"].ToString() || values.TaskBlindName != dataTable.Rows[1]["B"].ToString()) + { + throw new BusinessValidationFailedException(_localizer["IVUS_UploadVisitTaskError"]); + } + + List measuredValueList = new List(); + + try + { + for (int i = 3; i < dataTable.Rows.Count; i++) + { + measuredValueList.Add(new OCTFCTUploadData() + { + PlaqueNum = int.Parse(dataTable.Rows[i]["A"].ToString()), + FirstData = int.Parse(dataTable.Rows[i]["B"].ToString()), + SecondData = int.Parse(dataTable.Rows[i]["C"].ToString()), + ThirdData = int.Parse(dataTable.Rows[i]["D"].ToString()), + }); + } + } + catch (Exception) + { + throw new BusinessValidationFailedException(_localizer["IVUS_UplpadDataError"]); + } + + var questionInfo = await _readingQuestionTrialRepository.Where(x => x.ReadingQuestionCriterionTrialId == taskinfo.TrialReadingCriterionId && x.LesionType == LesionType.FCT).FirstNotNullAsync(); + var tableQuestionList = await _readingTableQuestionTrialRepository.Where(x => x.ReadingQuestionId == questionInfo.Id).ToListAsync(); + List tableAnsweRowInfos = new List(); + List tableAnswers = new List(); + + var maxnum = _readingTableAnswerRowInfoRepository.Where(x => x.QuestionId == questionInfo.Id && x.VisitTaskId == taskinfo.Id).MaxOrDefault(x => x.RowIndex); + + + foreach (var item in measuredValueList) + { + maxnum = maxnum + 1; + var newRowId = NewId.NextGuid(); + // 斑块数据统计 + tableAnsweRowInfos.Add(new ReadingTableAnswerRowInfo() + { + Id = newRowId, + QuestionId = questionInfo.Id, + VisitTaskId = taskinfo.Id, + TrialId = taskinfo.TrialId, + RowIndex = maxnum, + IsCurrentTaskAdd = true, + BlindName = taskinfo.TaskBlindName, + OrderMark = questionInfo.OrderMark, + FristAddTaskNum = taskinfo.VisitTaskNum, + FristAddTaskId = taskinfo.Id, + RowMark = questionInfo.OrderMark + decimal.Parse(maxnum.ToString()).GetLesionMark() + }); + + // 编号 + tableAnswers.Add(new ReadingTableQuestionAnswer() + { + Answer = item.PlaqueNum.ToString(), + QuestionId = questionInfo.Id, + TrialId = taskinfo.TrialId, + VisitTaskId = taskinfo.Id, + RowId = newRowId, + RowIndex = maxnum, + TableQuestionId = tableQuestionList.Where(x => x.ReadingQuestionId == questionInfo.Id && x.QuestionMark == QuestionMark.PlaqueNumber).Select(x => x.Id).FirstOrDefault(), + }); + + var avg = item.Avg.ToString(); + + + if (taskinfo.TrialReadingCriterion.DigitPlaces != -1) + { + var digitPlaces = taskinfo.TrialReadingCriterion.DigitPlaces ?? 0; + avg = decimal.Round(decimal.Parse(avg ?? "0"), digitPlaces).ToString("F" + digitPlaces.ToString()); + + } + + // 第一次 + tableAnswers.Add(new ReadingTableQuestionAnswer() + { + Answer = item.FirstData.ToString(), + QuestionId = questionInfo.Id, + TrialId = taskinfo.TrialId, + VisitTaskId = taskinfo.Id, + RowId = newRowId, + RowIndex = maxnum, + TableQuestionId = tableQuestionList.Where(x => x.ReadingQuestionId == questionInfo.Id && x.QuestionMark == QuestionMark.FirstFCT).Select(x => x.Id).FirstOrDefault(), + }); + + tableAnswers.Add(new ReadingTableQuestionAnswer() + { + Answer = item.SecondData.ToString(), + QuestionId = questionInfo.Id, + TrialId = taskinfo.TrialId, + VisitTaskId = taskinfo.Id, + RowId = newRowId, + RowIndex = maxnum, + TableQuestionId = tableQuestionList.Where(x => x.ReadingQuestionId == questionInfo.Id && x.QuestionMark == QuestionMark.SecondFCT).Select(x => x.Id).FirstOrDefault(), + }); + + tableAnswers.Add(new ReadingTableQuestionAnswer() + { + Answer = item.ThirdData.ToString(), + QuestionId = questionInfo.Id, + TrialId = taskinfo.TrialId, + VisitTaskId = taskinfo.Id, + RowId = newRowId, + RowIndex = maxnum, + TableQuestionId = tableQuestionList.Where(x => x.ReadingQuestionId == questionInfo.Id && x.QuestionMark == QuestionMark.ThirdFCT).Select(x => x.Id).FirstOrDefault(), + }); + + tableAnswers.Add(new ReadingTableQuestionAnswer() + { + Answer = avg, + QuestionId = questionInfo.Id, + TrialId = taskinfo.TrialId, + VisitTaskId = taskinfo.Id, + RowId = newRowId, + RowIndex = maxnum, + TableQuestionId = tableQuestionList.Where(x => x.ReadingQuestionId == questionInfo.Id && x.QuestionMark == QuestionMark.AvgFCT).Select(x => x.Id).FirstOrDefault(), + }); + } + await _readingTableAnswerRowInfoRepository.BatchDeleteNoTrackingAsync(x => x.QuestionId == questionInfo.Id && x.VisitTaskId == taskinfo.Id); + await _readingTableQuestionAnswerRepository.BatchDeleteNoTrackingAsync(x => x.QuestionId == questionInfo.Id && x.VisitTaskId == taskinfo.Id); + await _readingTableAnswerRowInfoRepository.AddRangeAsync(tableAnsweRowInfos); + await _readingTableQuestionAnswerRepository.AddRangeAsync(tableAnswers); + await _readingTableQuestionAnswerRepository.SaveChangesAsync(); + + await this.CalculateTask(new CalculateTaskInDto() + { + + VisitTaskId = taskinfo.Id, + }); + } + /// /// 获取OCT-脂质角度模板 /// @@ -478,6 +634,125 @@ namespace IRaCIS.Core.Application.Service.ReadingCalculate }); } + /// + /// 导入OCT-脂质角度数据 + /// + /// + [HttpPost] + public async Task UploadOCTLipidAngleTemplate() + { + var request = httpContext.HttpContext!.Request; + var file = request.Form.Files[0]; + Guid visitTaskId = Guid.Parse(request.Form["VisitTaskId"]); + var dataTable = await _generalCalculateService.GetDataTableFromUpload(file); + + var taskinfo = await _visitTaskRepository.Where(x => x.Id == visitTaskId).Include(x => x.Subject).Include(x => x.TrialReadingCriterion).FirstNotNullAsync(); + + var values = new + { + SubjectID = taskinfo.BlindSubjectCode.IsNullOrEmpty() ? taskinfo.Subject.Code : taskinfo.BlindSubjectCode, + TaskBlindName = taskinfo.TaskBlindName, + }; + + if (values.SubjectID != dataTable.Rows[0]["B"].ToString() || values.TaskBlindName != dataTable.Rows[1]["B"].ToString()) + { + throw new BusinessValidationFailedException(_localizer["IVUS_UploadVisitTaskError"]); + } + + List measuredValueList = new List(); + + try + { + for (int i = 3; i < dataTable.Rows.Count; i++) + { + measuredValueList.Add(new OCTFCTUploadData() + { + PlaqueNum = int.Parse(dataTable.Rows[i]["A"].ToString()), + FirstData = int.Parse(dataTable.Rows[i]["B"].ToString()), + + }); + } + } + catch (Exception) + { + throw new BusinessValidationFailedException(_localizer["IVUS_UplpadDataError"]); + } + + var questionInfo = await _readingQuestionTrialRepository.Where(x => x.ReadingQuestionCriterionTrialId == taskinfo.TrialReadingCriterionId && x.LesionType == LesionType.LipidAngle).FirstNotNullAsync(); + var tableQuestionList = await _readingTableQuestionTrialRepository.Where(x => x.ReadingQuestionId == questionInfo.Id).ToListAsync(); + List tableAnsweRowInfos = new List(); + List tableAnswers = new List(); + + var maxnum = _readingTableAnswerRowInfoRepository.Where(x => x.QuestionId == questionInfo.Id && x.VisitTaskId == taskinfo.Id).MaxOrDefault(x => x.RowIndex); + + + foreach (var item in measuredValueList) + { + maxnum = maxnum + 1; + var newRowId = NewId.NextGuid(); + // 斑块数据统计 + tableAnsweRowInfos.Add(new ReadingTableAnswerRowInfo() + { + Id = newRowId, + QuestionId = questionInfo.Id, + VisitTaskId = taskinfo.Id, + TrialId = taskinfo.TrialId, + RowIndex = maxnum, + IsCurrentTaskAdd = true, + BlindName = taskinfo.TaskBlindName, + OrderMark = questionInfo.OrderMark, + FristAddTaskNum = taskinfo.VisitTaskNum, + FristAddTaskId = taskinfo.Id, + RowMark = questionInfo.OrderMark + decimal.Parse(maxnum.ToString()).GetLesionMark() + }); + + // 编号 + tableAnswers.Add(new ReadingTableQuestionAnswer() + { + Answer = item.PlaqueNum.ToString(), + QuestionId = questionInfo.Id, + TrialId = taskinfo.TrialId, + VisitTaskId = taskinfo.Id, + RowId = newRowId, + RowIndex = maxnum, + TableQuestionId = tableQuestionList.Where(x => x.ReadingQuestionId == questionInfo.Id && x.QuestionMark == QuestionMark.PlaqueNumber).Select(x => x.Id).FirstOrDefault(), + }); + + var avg = item.Avg.ToString(); + + + if (taskinfo.TrialReadingCriterion.DigitPlaces != -1) + { + var digitPlaces = taskinfo.TrialReadingCriterion.DigitPlaces ?? 0; + avg = decimal.Round(decimal.Parse(avg ?? "0"), digitPlaces).ToString("F" + digitPlaces.ToString()); + + } + + // 脂质角度 + tableAnswers.Add(new ReadingTableQuestionAnswer() + { + Answer = item.FirstData.ToString(), + QuestionId = questionInfo.Id, + TrialId = taskinfo.TrialId, + VisitTaskId = taskinfo.Id, + RowId = newRowId, + RowIndex = maxnum, + TableQuestionId = tableQuestionList.Where(x => x.ReadingQuestionId == questionInfo.Id && x.QuestionMark == QuestionMark.LipidAngle).Select(x => x.Id).FirstOrDefault(), + }); + } + await _readingTableAnswerRowInfoRepository.BatchDeleteNoTrackingAsync(x => x.QuestionId == questionInfo.Id && x.VisitTaskId == taskinfo.Id); + await _readingTableQuestionAnswerRepository.BatchDeleteNoTrackingAsync(x => x.QuestionId == questionInfo.Id && x.VisitTaskId == taskinfo.Id); + await _readingTableAnswerRowInfoRepository.AddRangeAsync(tableAnsweRowInfos); + await _readingTableQuestionAnswerRepository.AddRangeAsync(tableAnswers); + await _readingTableQuestionAnswerRepository.SaveChangesAsync(); + + await this.CalculateTask(new CalculateTaskInDto() + { + + VisitTaskId = taskinfo.Id, + }); + } + /// /// 自动计算