导出OCT和Ivus 模板导出ZIP
This commit is contained in:
@@ -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<FileResult> GetIVUSTemplate(GetExportTemplateInDto inDto)
|
||||
{
|
||||
return await CreateIVUSTemplate(inDto.VisitTaskId);
|
||||
}
|
||||
|
||||
var taskinfo = await _visitTaskRepository.Where(x => x.Id == inDto.VisitTaskId).Include(x=>x.Subject).FirstNotNullAsync();
|
||||
/// <summary>
|
||||
/// 获取当前分组、受试者、标准下所有有效任务的IVUS模板压缩包
|
||||
/// </summary>
|
||||
/// <param name="inDto"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
public async Task<FileResult> 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<FileResult> 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));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 导入IVUS数据
|
||||
/// </summary>
|
||||
|
||||
@@ -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<FileResult> GetOCTFCTTemplate(GetExportTemplateInDto inDto)
|
||||
{
|
||||
var taskinfo = await _visitTaskRepository.Where(x => x.Id == inDto.VisitTaskId).Include(x => x.Subject).FirstNotNullAsync();
|
||||
return await CreateOCTFCTTemplate(inDto.VisitTaskId);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取当前分组、受试者、标准下所有有效任务的OCT-FCT模板压缩包
|
||||
/// </summary>
|
||||
/// <param name="inDto"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
public async Task<FileResult> 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<FileResult> 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));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 导入OCT-FCT数据
|
||||
/// </summary>
|
||||
|
||||
Reference in New Issue
Block a user