diff --git a/IRaCIS.Core.Application/Service/ReadingCalculate/IVUSCalculateService.cs b/IRaCIS.Core.Application/Service/ReadingCalculate/IVUSCalculateService.cs index cdb6931a1..5ca9dc6ba 100644 --- a/IRaCIS.Core.Application/Service/ReadingCalculate/IVUSCalculateService.cs +++ b/IRaCIS.Core.Application/Service/ReadingCalculate/IVUSCalculateService.cs @@ -9,6 +9,7 @@ using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; using Microsoft.Extensions.Logging; using Newtonsoft.Json; +using System.IO.Compression; namespace IRaCIS.Core.Application.Service.ReadingCalculate { @@ -417,8 +418,52 @@ namespace IRaCIS.Core.Application.Service.ReadingCalculate [HttpPost] public async Task GetIVUSTemplate(GetExportTemplateInDto inDto) { + return await CreateIVUSTemplate(inDto.VisitTaskId); + } - var taskinfo = await _visitTaskRepository.Where(x => x.Id == inDto.VisitTaskId).Include(x=>x.Subject).FirstNotNullAsync(); + /// + /// 获取当前分组、受试者、标准下所有有效任务的IVUS模板压缩包 + /// + /// + /// + [HttpPost] + public async Task GetIVUSTemplatesZip(GetExportTemplateInDto inDto) + { + var currentTask = await _visitTaskRepository.Where(x => x.Id == inDto.VisitTaskId).Include(x=>x.Subject).FirstNotNullAsync(); + var taskList = await _visitTaskRepository.Where(x => x.ArmEnum == currentTask.ArmEnum + && x.SubjectId == currentTask.SubjectId + && x.TrialReadingCriterionId == currentTask.TrialReadingCriterionId + && x.TaskState == TaskState.Effect) + .Include(x => x.Subject) + .ToListAsync(); + + var zipStream = new MemoryStream(); + using (var archive = new ZipArchive(zipStream, ZipArchiveMode.Create, leaveOpen: true)) + { + foreach (var task in taskList) + { + var template = await CreateIVUSTemplate(task.Id) as FileStreamResult; + await using (template.FileStream) + await using (var entryStream = archive.CreateEntry($"{GetTemplateFileName(task)}.xlsx", CompressionLevel.Optimal).Open()) + { + await template.FileStream.CopyToAsync(entryStream); + } + } + } + + zipStream.Position = 0; + + var code = string.Concat(currentTask.Subject.Code.Select(c => Path.GetInvalidFileNameChars().Contains(c) ? '_' : c)); + return new FileStreamResult(zipStream, "application/zip") + { + FileDownloadName = code+"_IVUS_Templates.zip" + }; + } + + private async Task CreateIVUSTemplate(Guid visitTaskId) + { + + var taskinfo = await _visitTaskRepository.Where(x => x.Id == visitTaskId).Include(x=>x.Subject).FirstNotNullAsync(); //靶段 var targetSegmentdic = await _dictionaryRepository.Where(x => x.Parent.Code == "TargetSegment").ToListAsync(); @@ -429,7 +474,7 @@ namespace IRaCIS.Core.Application.Service.ReadingCalculate - var awswerList=await _readingTaskQuestionAnswerRepository.Where(x => x.VisitTaskId == inDto.VisitTaskId).Include(x=>x.ReadingQuestionTrial).ToListAsync(); + var awswerList=await _readingTaskQuestionAnswerRepository.Where(x => x.VisitTaskId == visitTaskId).Include(x=>x.ReadingQuestionTrial).ToListAsync(); @@ -447,7 +492,7 @@ namespace IRaCIS.Core.Application.Service.ReadingCalculate { SujectVisitId = taskinfo.SourceSubjectVisitId ?? default(Guid), TrialId = taskinfo.TrialId, - VisitTaskId = inDto.VisitTaskId + VisitTaskId = visitTaskId }); targetSegmentAnswer = string.Join(",", targetSegmentData .Where(x => x.BodyPartForEdit.IsNotNullOrEmpty()) @@ -493,6 +538,13 @@ namespace IRaCIS.Core.Application.Service.ReadingCalculate }); } + private static string GetTemplateFileName(VisitTask task) + { + var subjectCode = task.Subject.Code; + var fileName = $"{subjectCode}_{task.TaskName}"; + return string.Concat(fileName.Select(c => Path.GetInvalidFileNameChars().Contains(c) ? '_' : c)); + } + /// /// 导入IVUS数据 /// diff --git a/IRaCIS.Core.Application/Service/ReadingCalculate/OCTCalculateService.cs b/IRaCIS.Core.Application/Service/ReadingCalculate/OCTCalculateService.cs index 02e40a44d..17e570645 100644 --- a/IRaCIS.Core.Application/Service/ReadingCalculate/OCTCalculateService.cs +++ b/IRaCIS.Core.Application/Service/ReadingCalculate/OCTCalculateService.cs @@ -14,6 +14,7 @@ using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; using Microsoft.Extensions.Logging; using Newtonsoft.Json; +using System.IO.Compression; namespace IRaCIS.Core.Application.Service.ReadingCalculate { @@ -276,7 +277,51 @@ namespace IRaCIS.Core.Application.Service.ReadingCalculate [HttpPost] public async Task GetOCTFCTTemplate(GetExportTemplateInDto inDto) { - var taskinfo = await _visitTaskRepository.Where(x => x.Id == inDto.VisitTaskId).Include(x => x.Subject).FirstNotNullAsync(); + return await CreateOCTFCTTemplate(inDto.VisitTaskId); + } + + /// + /// 获取当前分组、受试者、标准下所有有效任务的OCT-FCT模板压缩包 + /// + /// + /// + [HttpPost] + public async Task GetOCTFCTTemplatesZip(GetExportTemplateInDto inDto) + { + var currentTask = await _visitTaskRepository.Where(x => x.Id == inDto.VisitTaskId).Include(x => x.Subject).FirstNotNullAsync(); + var taskList = await _visitTaskRepository.Where(x => x.ArmEnum == currentTask.ArmEnum + && x.SubjectId == currentTask.SubjectId + && x.TrialReadingCriterionId == currentTask.TrialReadingCriterionId + && x.TaskState == TaskState.Effect) + .Include(x => x.Subject) + .ToListAsync(); + + var zipStream = new MemoryStream(); + using (var archive = new ZipArchive(zipStream, ZipArchiveMode.Create, leaveOpen: true)) + { + foreach (var task in taskList) + { + var template = await CreateOCTFCTTemplate(task.Id) as FileStreamResult; + await using (template.FileStream) + await using (var entryStream = archive.CreateEntry($"{GetTemplateFileName(task)}.xlsx", CompressionLevel.Optimal).Open()) + { + await template.FileStream.CopyToAsync(entryStream); + } + } + } + + zipStream.Position = 0; + + var code = string.Concat(currentTask.Subject.Code.Select(c => Path.GetInvalidFileNameChars().Contains(c) ? '_' : c)); + return new FileStreamResult(zipStream, "application/zip") + { + FileDownloadName = $"{code}_OCT_FCT_Templates.zip" + }; + } + + private async Task CreateOCTFCTTemplate(Guid visitTaskId) + { + var taskinfo = await _visitTaskRepository.Where(x => x.Id == visitTaskId).Include(x => x.Subject).FirstNotNullAsync(); //靶段 var targetSegmentdic = await _dictionaryRepository.Where(x => x.Parent.Code == "TargetSegment").ToListAsync(); @@ -287,7 +332,7 @@ namespace IRaCIS.Core.Application.Service.ReadingCalculate - var awswerList = await _readingTaskQuestionAnswerRepository.Where(x => x.VisitTaskId == inDto.VisitTaskId).Include(x => x.ReadingQuestionTrial).ToListAsync(); + var awswerList = await _readingTaskQuestionAnswerRepository.Where(x => x.VisitTaskId == visitTaskId).Include(x => x.ReadingQuestionTrial).ToListAsync(); @@ -305,7 +350,7 @@ namespace IRaCIS.Core.Application.Service.ReadingCalculate { SujectVisitId = taskinfo.SourceSubjectVisitId ?? default(Guid), TrialId = taskinfo.TrialId, - VisitTaskId = inDto.VisitTaskId + VisitTaskId = visitTaskId }); targetSegmentAnswer = string.Join(",", targetSegmentData .Where(x => x.BodyPartForEdit.IsNotNullOrEmpty()) @@ -348,6 +393,13 @@ namespace IRaCIS.Core.Application.Service.ReadingCalculate }); } + private static string GetTemplateFileName(VisitTask task) + { + var subjectCode = task.Subject.Code; + var fileName = $"{subjectCode}_{task.TaskName}"; + return string.Concat(fileName.Select(c => Path.GetInvalidFileNameChars().Contains(c) ? '_' : c)); + } + /// /// 导入OCT-FCT数据 ///