|
|
@@ -1,11 +1,9 @@
|
|
|
package com.nb.web.service.bus.utils;
|
|
|
|
|
|
-import cn.hutool.core.collection.CollUtil;
|
|
|
import cn.hutool.core.collection.CollectionUtil;
|
|
|
import cn.hutool.core.io.IoUtil;
|
|
|
import cn.hutool.core.io.resource.ResourceUtil;
|
|
|
import cn.hutool.core.map.MapUtil;
|
|
|
-import cn.hutool.core.util.StrUtil;
|
|
|
import com.deepoove.poi.XWPFTemplate;
|
|
|
import com.deepoove.poi.config.Configure;
|
|
|
import com.deepoove.poi.data.PictureType;
|
|
|
@@ -13,15 +11,11 @@ import com.deepoove.poi.data.Pictures;
|
|
|
import com.deepoove.poi.plugin.table.LoopColumnTableRenderPolicy;
|
|
|
import com.deepoove.poi.plugin.table.LoopRowTableRenderPolicy;
|
|
|
import com.deepoove.poi.xwpf.NiceXWPFDocument;
|
|
|
-import com.nb.web.api.entity.BusEvaluationEntity;
|
|
|
-import com.nb.web.service.bus.service.dto.ClinicAnalInfusionRecord;
|
|
|
import com.nb.web.service.bus.service.dto.ClinicAnalRecordResult;
|
|
|
-import org.apache.poi.xwpf.usermodel.BreakType;
|
|
|
|
|
|
import javax.servlet.http.HttpServletResponse;
|
|
|
import java.io.*;
|
|
|
-import java.util.*;
|
|
|
-import java.util.stream.Collectors;
|
|
|
+import java.util.HashMap;
|
|
|
|
|
|
/**
|
|
|
* @ClassName : AnalExportUtils
|
|
|
@@ -32,13 +26,7 @@ import java.util.stream.Collectors;
|
|
|
|
|
|
public class AnalExportUtils {
|
|
|
//临床信息模板路径
|
|
|
- private static final byte[] clinic_pattern= IoUtil.readBytes(ResourceUtil.getStream("classpath:"+File.separator+"export"+File.separator+"patientTmp.docx"));
|
|
|
- //输注信息模板路径
|
|
|
- private static final byte[] infusion_pattern=IoUtil.readBytes(ResourceUtil.getStream("classpath:"+File.separator+"export"+File.separator+"infusionHistoryTmp.docx"));
|
|
|
- //图片模板路径
|
|
|
- private static final byte[] image_pattern=IoUtil.readBytes(ResourceUtil.getStream("classpath:"+File.separator+"export"+File.separator+"imageTmp.docx"));
|
|
|
- //评价模板路径
|
|
|
- private static final byte[] eval_pattern=IoUtil.readBytes(ResourceUtil.getStream("classpath:"+File.separator+"export"+File.separator+"evalTmp.docx"));
|
|
|
+ private static final byte[] clinic_pattern= IoUtil.readBytes(ResourceUtil.getStream("classpath:"+File.separator+"export"+File.separator+"AnalRecordTemp.docx"));
|
|
|
|
|
|
public static void export(HttpServletResponse response, ClinicAnalRecordResult record,String base64) throws Exception {
|
|
|
response.addHeader("Content-Disposition","attachment;filename="+record.getClinic().getPatientCode()+".docx");
|
|
|
@@ -48,94 +36,29 @@ public class AnalExportUtils {
|
|
|
}
|
|
|
|
|
|
private static void export0(OutputStream outputStream,ClinicAnalRecordResult record,String base64) throws Exception {
|
|
|
- NiceXWPFDocument document= XWPFTemplate.compile(
|
|
|
- new ByteArrayInputStream(clinic_pattern))
|
|
|
- .render(record.getClinic())
|
|
|
+ HashMap<String, Object> params = new HashMap<>();
|
|
|
+ params.put("clinic",record.getClinic());
|
|
|
+ params.put("infusionRecords", CollectionUtil.isEmpty(record.getInfusionRecords())?null:record.getInfusionRecords());
|
|
|
+ params.put("evaluations",MapUtil.of("evals",CollectionUtil.isEmpty(record.getEvaluations())?null:record.getEvaluations()));
|
|
|
+ params.put("image", MapUtil.of("base64",Pictures.ofBase64(base64,PictureType.PNG)
|
|
|
+ .size(687, 500).create()));
|
|
|
+
|
|
|
+ NiceXWPFDocument document= XWPFTemplate.compile(new ByteArrayInputStream(clinic_pattern),Configure.builder()
|
|
|
+ .bind("modifies", new LoopRowTableRenderPolicy())
|
|
|
+ .bind("evals",new LoopColumnTableRenderPolicy())
|
|
|
+ .build())
|
|
|
+ .render(params)
|
|
|
.getXWPFDocument();
|
|
|
- document=exportInfusionInfo(document,record.getInfusionRecords());
|
|
|
- document=exportEval(document,record.getEvaluations());
|
|
|
- document=exportImage(document,base64);
|
|
|
//文件输出流
|
|
|
- BufferedOutputStream bos = new BufferedOutputStream(outputStream);
|
|
|
try {
|
|
|
- document.write(bos);
|
|
|
- bos.flush();
|
|
|
+ document.write(outputStream);
|
|
|
outputStream.flush();
|
|
|
}catch (Exception e){
|
|
|
throw e;
|
|
|
}finally {
|
|
|
IoUtil.close(outputStream);
|
|
|
- IoUtil.close(bos);
|
|
|
IoUtil.close(document);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-
|
|
|
- /**
|
|
|
- * 导出输注记录
|
|
|
- */
|
|
|
- private static NiceXWPFDocument exportInfusionInfo(NiceXWPFDocument xwpfDocument,List<ClinicAnalInfusionRecord> infusions) throws Exception {
|
|
|
- if(CollUtil.isEmpty(infusions)){
|
|
|
- return xwpfDocument;
|
|
|
- }
|
|
|
- xwpfDocument.createParagraph().createRun().addBreak(BreakType.PAGE);
|
|
|
- LoopRowTableRenderPolicy policy = new LoopRowTableRenderPolicy();
|
|
|
- Configure config = Configure.builder()
|
|
|
- .bind("modifies", policy)
|
|
|
- .build();
|
|
|
- Map<Date, List<NiceXWPFDocument>> document = infusions.stream()
|
|
|
- .collect(Collectors.groupingBy(ClinicAnalInfusionRecord::getStartTime, Collectors.collectingAndThen(Collectors.toList(), list -> list
|
|
|
- .parallelStream()
|
|
|
- .map(infusion -> XWPFTemplate.compile(new ByteArrayInputStream(infusion_pattern), config).render(infusion).getXWPFDocument())
|
|
|
- .collect(Collectors.toList())
|
|
|
- )
|
|
|
- ));
|
|
|
- List<Date> dates = new ArrayList<>(document.keySet());
|
|
|
- CollectionUtil.sort(dates,(o1,o2)->o1.compareTo(o2));
|
|
|
- for (Date date : dates) {
|
|
|
- for (NiceXWPFDocument d : document.get(date)) {
|
|
|
- xwpfDocument=xwpfDocument.merge(d);
|
|
|
- }
|
|
|
- }
|
|
|
- return xwpfDocument;
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- /**
|
|
|
- * 导出评价信息
|
|
|
- */
|
|
|
- private static NiceXWPFDocument exportEval(NiceXWPFDocument xwpfDocument,List<BusEvaluationEntity> evals) throws Exception {
|
|
|
- if(CollUtil.isEmpty(evals)){
|
|
|
- return xwpfDocument;
|
|
|
- }
|
|
|
- xwpfDocument.createParagraph().createRun().addBreak(BreakType.PAGE);
|
|
|
- LoopColumnTableRenderPolicy policy = new LoopColumnTableRenderPolicy();
|
|
|
- Configure config = Configure.builder()
|
|
|
- .bind("evals", policy)
|
|
|
- .build();
|
|
|
- xwpfDocument = xwpfDocument.merge(XWPFTemplate.compile(
|
|
|
- new ByteArrayInputStream(eval_pattern), config).render(MapUtil.builder()
|
|
|
- .put("evals", evals)
|
|
|
- .build())
|
|
|
- .getXWPFDocument());
|
|
|
- return xwpfDocument;
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 导出统计图片
|
|
|
- */
|
|
|
- private static NiceXWPFDocument exportImage(NiceXWPFDocument document,String base64) throws Exception {
|
|
|
- if(StrUtil.isEmpty(base64)){
|
|
|
- return document;
|
|
|
- }
|
|
|
- document.createParagraph().createRun().addBreak(BreakType.PAGE);
|
|
|
- document=document.merge(XWPFTemplate.compile(
|
|
|
- new ByteArrayInputStream(image_pattern))
|
|
|
- .render(MapUtil.builder()
|
|
|
- . put("image", Pictures.ofBase64(base64, PictureType.PNG)
|
|
|
- .size(687, 500).create())
|
|
|
- .build())
|
|
|
- .getXWPFDocument());
|
|
|
- return document;
|
|
|
- }
|
|
|
}
|