From edfdd1d4e718cb5cec451b257936cbf72d40ae25 Mon Sep 17 00:00:00 2001 From: zhizhi wu <2377881365@qq.com> Date: Sun, 25 Apr 2021 10:34:44 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8D=95=E4=B8=AA=E9=87=8F=E8=A1=A8=E5=AF=BC?= =?UTF-8?q?=E5=87=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ht/api/PatientReportExportController.java | 8 +- .../ccsens/ht/bean/vo/PatientReportVo.java | 288 ++++++++++++++-- .../ht/persist/dao/HtPatientReportDao.java | 16 + .../ht/service/IPatientReportService.java | 9 + .../com/ccsens/ht/service/ImportService.java | 7 +- .../ht/service/PatientReportService.java | 312 ++++++++++++++---- .../ccsens/ht/service/QuestionService.java | 33 +- .../java/com/ccsens/ht/uitl/Constant.java | 58 ++++ ht/src/main/resources/application.yml | 4 +- .../mapper_dao/HtPatientReportDao.xml | 57 +++- .../resources/mapper_dao/HtQuestionDao.xml | 1 + .../mapper_dao/HtQuestionOptionDao.xml | 4 +- .../service/PatientReportService.java | 3 +- .../main/java/com/ccsens/util/PdfUtil.java | 27 +- .../java/com/ccsens/util/PdfUtilTest.java | 2 +- 15 files changed, 695 insertions(+), 134 deletions(-) diff --git a/ht/src/main/java/com/ccsens/ht/api/PatientReportExportController.java b/ht/src/main/java/com/ccsens/ht/api/PatientReportExportController.java index 6cb35235..c758480b 100644 --- a/ht/src/main/java/com/ccsens/ht/api/PatientReportExportController.java +++ b/ht/src/main/java/com/ccsens/ht/api/PatientReportExportController.java @@ -1,5 +1,6 @@ package com.ccsens.ht.api; +import cn.hutool.core.util.CharsetUtil; import com.ccsens.ht.bean.dto.PatientReportDto; import com.ccsens.ht.bean.vo.PatientReportVo; import com.ccsens.ht.service.IPatientReportService; @@ -7,13 +8,18 @@ import com.ccsens.util.JsonResponse; import com.ccsens.util.bean.dto.QueryDto; import io.swagger.annotations.*; import lombok.extern.slf4j.Slf4j; +import org.apache.poi.ss.usermodel.Workbook; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RestController; import javax.annotation.Resource; +import javax.servlet.http.HttpServletResponse; import javax.validation.Valid; +import java.io.IOException; +import java.io.UnsupportedEncodingException; +import java.net.URLEncoder; /** * @description: @@ -47,7 +53,7 @@ public class PatientReportExportController { @ApiImplicitParam(name = "json", value = "导出报告单", required = true) }) @RequestMapping(value="/export", method = RequestMethod.POST) - public JsonResponse export(@RequestBody @ApiParam @Valid QueryDto param){ + public JsonResponse export(@RequestBody @ApiParam @Valid QueryDto param) { //查询报告单信息 log.info("导出指定报告单:{}", param); String path = patientReportService.export(param.getParam(), param.getUserId()); diff --git a/ht/src/main/java/com/ccsens/ht/bean/vo/PatientReportVo.java b/ht/src/main/java/com/ccsens/ht/bean/vo/PatientReportVo.java index 5a371bda..b777a8c7 100644 --- a/ht/src/main/java/com/ccsens/ht/bean/vo/PatientReportVo.java +++ b/ht/src/main/java/com/ccsens/ht/bean/vo/PatientReportVo.java @@ -129,10 +129,49 @@ public class PatientReportVo { private String hospital; public List toPdfRow(){ + List rows = getInitRows(); + //第四栏 + rows.add( + fillRow( + "临床诊断:" + this.clinicalDiagnosis, + "","") + ); + + return rows; + } + + + public List toPdfSimpleCodeRow(){ + List rows = getInitRows(); + //第四栏 + Date date = new Date(); + if (this.reportTime != null && this.reportTime > 0) { + date.setTime(this.reportTime); + } + PdfUtil.Row fourRow = new PdfUtil.Row(); + PdfUtil.Cell cell = new PdfUtil.Cell(); + cell.setContent("临床诊断:" ); + cell.setCenter(false); + cell.setColSpan(2); + cell.setBorderLeft(0); + cell.setBorderBottom(0); + fourRow.addCell(cell); + PdfUtil.Cell cell2 = new PdfUtil.Cell(); + cell2.setContent("检查日期:" + DateUtil.format(date, "yyyy-MM-dd")); + cell2.setCenter(false); + cell2.setBorderLeft(0); + cell2.setBorderBottom(0); + fourRow.addCell(cell2); + rows.add(fourRow); + + return rows; + } + + private List getInitRows() { Map careerMap = new HashMap<>(16); String careerMsg = "1:农林牧渔水利生产人员 2:教师 3:医务工作者 4:专业技术人员 5:生产、运输设备操作人员及有关人员 6:商业、服务业人员 7:国家机关、事业单位、企业负责人 8:国家机关、事业单位、企业办事人员和有关人员 9:军人 10:媒体、文体类工作人员 11:在校学生 12:未就业 13:家务 14:其他"; String splitStr = " "; - for (String careerOne: careerMsg.split(splitStr)) { + for (String careerOne : careerMsg.split(splitStr)) { String splitStr2 = ":"; careerMap.put(Byte.parseByte(careerOne.split(splitStr2)[0]), careerOne.split(splitStr2)[1]); } @@ -161,20 +200,6 @@ public class PatientReportVo { "床号:" + this.bedNumber, "病案号:" + this.hospitalNumber) ); - //第四栏 -// Date date = null; -// if (this.reportTime > 0) { -// date = new Date(); -// date.setTime(this.reportTime); -// } - - rows.add( - fillRow( - "临床诊断:" + this.clinicalDiagnosis, - "","") -// "检查日期:" + (date == null ? "" : DateUtil.format(date, "yyyy-MM-dd"))) - ); - return rows; } @@ -223,35 +248,57 @@ public class PatientReportVo { this.subReport.add(score); } + /** + * 将mmse的多层嵌套转成一层 + * @param score 报告 + * @param list 转换后的list + */ + public void dealMMSE(ReportScore score, List list) { + if (CollectionUtil.isEmpty(score.subReport)) { + list.add(score); + } else { + score.subReport.forEach(subScore -> dealMMSE(subScore, list)); + } + } + public List toRow() { - int colNum = 8; + int colNum = 8; int headNum = 2; List rows = new ArrayList<>(); if (CollectionUtil.isEmpty(subReport)) { - PdfUtil.Row row = new PdfUtil.Row(); - PdfUtil.Cell cell1 = new PdfUtil.Cell(); - cell1.setContent(this.code + (StrUtil.isBlank(this.remark) ? "" : "("+this.remark+")")); - cell1.setColSpan(headNum); - PdfUtil.Cell cell2 = new PdfUtil.Cell(); - cell2.setContent(this.score == null ? "" : this.score + (this.totalScore > 0 ? "/" + this.totalScore : "")); - cell2.setColSpan(colNum - headNum); - cell2.setBorderRight(1); - row.addCell(cell1); - row.addCell(cell2); - - rows.add(row); + toRowOnlyTotal(colNum, headNum, rows); } else { String mmse = Constant.Ht.Report.MMSE; String npi = Constant.Ht.Report.NPI; - if (mmse.equalsIgnoreCase(this.code) || npi.equalsIgnoreCase(this.code)) { - fillMmseOrNpi(headNum, rows, mmse, npi); - } else { - fillMoca(rows); + switch (this.code) { + case Constant.Ht.Report.MMSE: + case Constant.Ht.Report.NPI: + fillMmseOrNpi(headNum, rows, mmse, npi); + break; + case Constant.Ht.Report.MOCA: + fillMoca(rows); + break; + case Constant.Ht.Report.HAMD: + case Constant.Ht.Report.HAMA: + case Constant.Ht.Report.ADL: + toRowOnlyTotal(colNum, headNum, rows); + break; + default: + fillCommon(rows); + break; } + + } + toDescRow(colNum, headNum, rows); + + return rows; + } + + private void toDescRow(int colNum, int headNum, List rows) { if (StrUtil.isBlank(this.description)) { - return rows; + return ; } PdfUtil.Row descRow = new PdfUtil.Row(); PdfUtil.Cell cell = new PdfUtil.Cell(); @@ -264,10 +311,156 @@ public class PatientReportVo { // MOCA中,视直觉单独展示 fillSzj(colNum, headNum, rows); + } + + private void toRowOnlyTotal(int colNum, int headNum, List rows) { + PdfUtil.Row row = new PdfUtil.Row(); + PdfUtil.Cell cell1 = new PdfUtil.Cell(); + cell1.setContent(this.code + (StrUtil.isBlank(this.remark) ? "" : "(" + this.remark + ")")); + cell1.setColSpan(headNum); + PdfUtil.Cell cell2 = new PdfUtil.Cell(); + cell2.setContent(this.score == null ? "" : this.score + (this.totalScore > 0 ? "/" + this.totalScore : "")); + cell2.setColSpan(colNum - headNum); + cell2.setBorderRight(1); + row.addCell(cell1); + row.addCell(cell2); + + rows.add(row); + } + + public List toSingleRow() { + int colNum = Constant.Ht.Report.HAMD.equalsIgnoreCase(code) ? 9 : 8; + int headNum = 2; + List rows = new ArrayList<>(); + if (CollectionUtil.isEmpty(subReport)) { + toRowOnlyTotal(colNum, headNum, rows); + } else { + String mmse = Constant.Ht.Report.MMSE; + String npi = Constant.Ht.Report.NPI; + switch (this.code) { + case Constant.Ht.Report.MMSE: + fillMMSE(rows); + break; + case Constant.Ht.Report.NPI: + fillMmseOrNpi(headNum, rows, mmse, npi); + break; + case Constant.Ht.Report.MOCA: + fillMoca(rows); + break; + default: + fillCommon(rows); + break; + } + + + + } + toDescRow(colNum, headNum, rows); return rows; } + private void fillMMSE(List rows) { + List mmseList = new ArrayList<>(); + dealMMSE(this, mmseList); + PdfUtil.Row titleRow = new PdfUtil.Row(); + PdfUtil.Row scoreRow = new PdfUtil.Row(); + for (int i = 0; i < mmseList.size() ; i++) { + if (i == 0) { + PdfUtil.Cell cell = new PdfUtil.Cell("简明心理状况测验(MMSE)"); + cell.setRowSpan(4); + titleRow.addCell(cell); + rows.add(titleRow); + rows.add(scoreRow); + } else if (i==7){ + titleRow = new PdfUtil.Row(); + scoreRow = new PdfUtil.Row(); + rows.add(titleRow); + rows.add(scoreRow); + } + + ReportScore score = mmseList.get(i); + PdfUtil.Cell titleCell = new PdfUtil.Cell(score.getName()); + titleRow.addCell(titleCell); + titleCell.setBorderRight(i == 6 ? 1 : 0); + PdfUtil.Cell scoreCell = new PdfUtil.Cell(score.score == null ? "" : score.score + (score.totalScore > 0 ? "/" + score.totalScore : "")); + scoreCell.setBorderRight(i == 6 ? 1 : 0); + scoreRow.addCell(scoreCell); + + if (i == mmseList.size() - 1) { + PdfUtil.Cell titleTotalCell = new PdfUtil.Cell("总分"); + titleTotalCell.setColSpan(3); + titleTotalCell.setBorderRight(1); + titleRow.addCell(titleTotalCell); + PdfUtil.Cell scoreTotalCell = new PdfUtil.Cell(this.score == null ? "" : this.score + (this.totalScore > 0 ? "/" + this.totalScore : "")); + scoreTotalCell.setColSpan(3); + scoreTotalCell.setBorderRight(1); + scoreRow.addCell(scoreTotalCell); + } + + } + } + + /** + * 通用项目得分 + * @param rows pdf的内容 + */ + private void fillCommon(List rows) { + //总列数 + int total = Constant.Ht.Report.HAMD.equalsIgnoreCase(code) ? 9 : 8; + // 标题 + PdfUtil.Row row = new PdfUtil.Row(); + PdfUtil.Cell cell = new PdfUtil.Cell(); + cell.setContent(this.name + "(" + this.code + ")各项目的因子分和总分"); + + cell.setColSpan(total); + cell.setBorderTop(0); + cell.setBorderRight(0); + cell.setBorderLeft(0); + row.addCell(cell); + rows.add(row); + + // 默认两行 + PdfUtil.Row row1 = new PdfUtil.Row(); + PdfUtil.Row row2 = new PdfUtil.Row(); + // 题目 + PdfUtil.Cell firstCell1 = new PdfUtil.Cell(); + firstCell1.setContent("项目"); + row1.addCell(firstCell1); + PdfUtil.Cell firstCell2 = new PdfUtil.Cell(); + firstCell2.setContent("计分"); + row2.addCell(firstCell2); + + + // 子类型 + int colspan = (total - 1) / (this.subReport.size() + 1); + int lastSpan = total - 1 - colspan * this.subReport.size(); + this.subReport.forEach(score -> { + PdfUtil.Cell cell1 = new PdfUtil.Cell(); + PdfUtil.Cell cell2 = new PdfUtil.Cell(); + cell1.setContent(score.name); + cell1.setColSpan(colspan); + cell2.setContent(score.score == null ? "" : score.score + (score.totalScore > 0 ? "/" + score.totalScore : "")); + cell2.setColSpan(colspan); + row1.addCell(cell1); + row2.addCell(cell2); + + }); + // 总分 + PdfUtil.Cell lastCell1 = new PdfUtil.Cell(); + lastCell1.setContent("总分"); + lastCell1.setColSpan(lastSpan); + lastCell1.setBorderRight(1); + row1.addCell(lastCell1); + PdfUtil.Cell lastCell2 = new PdfUtil.Cell(); + lastCell2.setContent(this.score == null ? "" : this.score + (this.totalScore > 0 ? "/" + this.totalScore : "")); + lastCell2.setColSpan(lastSpan); + lastCell2.setBorderRight(1); + row2.addCell(lastCell2); + rows.add(row1); + rows.add(row2); + } + private void fillMmseOrNpi(int headNum, List rows, String mmse, String npi) { PdfUtil.Row row1 = new PdfUtil.Row(); PdfUtil.Cell cell = new PdfUtil.Cell(); @@ -397,8 +590,8 @@ public class PatientReportVo { //名称 PdfUtil.Cell cell1 = new PdfUtil.Cell(); cell1.setContent(name); - cell1.setBorderTop(isTop? 1 : 0); - cell1.setBorderRight(isRight? 1 : 0); + cell1.setBorderTop(isTop? 1 : null); + cell1.setBorderRight(isRight? 1 : null); cell1.setColSpan(colspan == null || colspan.length == 0 ? 1 : colspan[0]); row1.addCell(cell1); @@ -406,7 +599,7 @@ public class PatientReportVo { PdfUtil.Cell cell2 = new PdfUtil.Cell(); cell2.setContent(score); cell2.setColSpan(colspan == null || colspan.length <= 1 ? 1 : colspan[1]); - cell2.setBorderRight(isRight? 1 : 0); + cell2.setBorderRight(isRight? 1 : null); row2.addCell(cell2); } } @@ -519,4 +712,27 @@ public class PatientReportVo { @ApiModelProperty("图片路径") private String imgPath; } + + @Data + @ApiModel("导出试题") + public static class QuestionAndAnswer{ + private Long id; + @ApiModelProperty("排序") + private int sort; + @ApiModelProperty("试题") + private String question; + @ApiModelProperty("选项") + private List