From 88f6d2914d3956f4c476deeba4fa46ea48fe374d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=AD=A6?= <吴æ武慧娟> Date: Wed, 25 Dec 2019 16:00:51 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AF=BC=E5=87=BA=E5=88=86=E4=BA=AB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ht/api/PatientReportController.java | 50 ++++--- .../ccsens/ht/bean/po/HtPatientReport.java | 11 ++ .../ht/bean/po/HtPatientReportExample.java | 70 ++++++++++ .../ccsens/ht/bean/vo/PatientReportVo.java | 127 ++++++++++++------ .../ht/service/IPatientReportService.java | 18 +++ .../ht/service/PatientReportService.java | 76 ++++++++++- .../mapper_raw/HtPatientReportMapper.xml | 27 +++- util/pom.xml | 12 +- .../main/java/com/ccsens/util/PdfUtil.java | 47 ++++--- .../main/java/com/ccsens/util/QrCodeUtil.java | 44 ++++++ .../java/com/ccsens/util/PdfUtilTest.java | 123 +++++++++++++++-- 11 files changed, 508 insertions(+), 97 deletions(-) create mode 100644 util/src/main/java/com/ccsens/util/QrCodeUtil.java diff --git a/ht/src/main/java/com/ccsens/ht/api/PatientReportController.java b/ht/src/main/java/com/ccsens/ht/api/PatientReportController.java index 792344cd..ffec38c1 100644 --- a/ht/src/main/java/com/ccsens/ht/api/PatientReportController.java +++ b/ht/src/main/java/com/ccsens/ht/api/PatientReportController.java @@ -21,6 +21,9 @@ import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RestController; import javax.validation.Valid; +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; /** * @program: ptpro @@ -112,20 +115,35 @@ public class PatientReportController { return JsonResponse.newInstance().ok(authority); } -// @ApiOperation(value = "导出报告单",notes = "导出报告单") -// @ApiImplicitParams({ -// @ApiImplicitParam(name = "json", value = "导出报告单", required = true) -// }) -// @RequestMapping(value="/exportReport", method = RequestMethod.POST) -// public JsonResponse exportReport(@RequestBody @ApiParam @Valid QueryDto param){ -// //查询报告单信息 -// log.info("查询报告单详情:{}", param); -// PatientReportVo.ReprotDetail detail = patientReportService.queryReportDetail(param.getParam(), param.getUserId()); -// if (detail == null) { -// return JsonResponse.newInstance().ok(CodeEnum.); -// } -// PdfUtil.credatePdf(PropUtil.path, detail.getPatient().getName(), detail.getPatient().toPdfRow(), ) -// log.info("查询报告单详情结果:{}", detail); -// return JsonResponse.newInstance().ok(detail); -// } + @ApiOperation(value = "导出报告单",notes = "导出报告单") + @ApiImplicitParams({ + @ApiImplicitParam(name = "json", value = "导出报告单", required = true) + }) + @RequestMapping(value="/exportReport", method = RequestMethod.POST) + public JsonResponse exportReport(@RequestBody @ApiParam @Valid QueryDto param){ + //查询报告单信息 + log.info("查询报告单详情:{}", param); + String path = patientReportService.exportReport(param.getParam(), param.getUserId()); + log.info("文件路径:{}", path); + PatientReportVo.Export export = new PatientReportVo.Export(); + export.setPath(path); + + return JsonResponse.newInstance().ok(export); + } + + @ApiOperation(value = "分享报告单",notes = "分享报告单") + @ApiImplicitParams({ + @ApiImplicitParam(name = "json", value = "分享报告单", required = true) + }) + @RequestMapping(value="/shareReport", method = RequestMethod.POST) + public JsonResponse shareReport(@RequestBody @ApiParam @Valid QueryDto param) throws IOException { + //查询报告单信息 + log.info("查询报告单详情:{}", param); + String path = patientReportService.generateQRCode(param.getParam(), param.getUserId()); + log.info("文件路径:{}", path); + PatientReportVo.Export export = new PatientReportVo.Export(); + export.setPath(path); + + return JsonResponse.newInstance().ok(export); + } } diff --git a/ht/src/main/java/com/ccsens/ht/bean/po/HtPatientReport.java b/ht/src/main/java/com/ccsens/ht/bean/po/HtPatientReport.java index 1f695493..6d4f5287 100644 --- a/ht/src/main/java/com/ccsens/ht/bean/po/HtPatientReport.java +++ b/ht/src/main/java/com/ccsens/ht/bean/po/HtPatientReport.java @@ -36,6 +36,8 @@ public class HtPatientReport implements Serializable { private String url; + private String qrCodeUrl; + private String remark; private Date createTime; @@ -174,6 +176,14 @@ public class HtPatientReport implements Serializable { this.url = url == null ? null : url.trim(); } + public String getQrCodeUrl() { + return qrCodeUrl; + } + + public void setQrCodeUrl(String qrCodeUrl) { + this.qrCodeUrl = qrCodeUrl == null ? null : qrCodeUrl.trim(); + } + public String getRemark() { return remark; } @@ -228,6 +238,7 @@ public class HtPatientReport implements Serializable { sb.append(", checkTime=").append(checkTime); sb.append(", evaluationCode=").append(evaluationCode); sb.append(", url=").append(url); + sb.append(", qrCodeUrl=").append(qrCodeUrl); sb.append(", remark=").append(remark); sb.append(", createTime=").append(createTime); sb.append(", updateTime=").append(updateTime); diff --git a/ht/src/main/java/com/ccsens/ht/bean/po/HtPatientReportExample.java b/ht/src/main/java/com/ccsens/ht/bean/po/HtPatientReportExample.java index 43d35c50..b46be1bb 100644 --- a/ht/src/main/java/com/ccsens/ht/bean/po/HtPatientReportExample.java +++ b/ht/src/main/java/com/ccsens/ht/bean/po/HtPatientReportExample.java @@ -1155,6 +1155,76 @@ public class HtPatientReportExample { return (Criteria) this; } + public Criteria andQrCodeUrlIsNull() { + addCriterion("qr_code_url is null"); + return (Criteria) this; + } + + public Criteria andQrCodeUrlIsNotNull() { + addCriterion("qr_code_url is not null"); + return (Criteria) this; + } + + public Criteria andQrCodeUrlEqualTo(String value) { + addCriterion("qr_code_url =", value, "qrCodeUrl"); + return (Criteria) this; + } + + public Criteria andQrCodeUrlNotEqualTo(String value) { + addCriterion("qr_code_url <>", value, "qrCodeUrl"); + return (Criteria) this; + } + + public Criteria andQrCodeUrlGreaterThan(String value) { + addCriterion("qr_code_url >", value, "qrCodeUrl"); + return (Criteria) this; + } + + public Criteria andQrCodeUrlGreaterThanOrEqualTo(String value) { + addCriterion("qr_code_url >=", value, "qrCodeUrl"); + return (Criteria) this; + } + + public Criteria andQrCodeUrlLessThan(String value) { + addCriterion("qr_code_url <", value, "qrCodeUrl"); + return (Criteria) this; + } + + public Criteria andQrCodeUrlLessThanOrEqualTo(String value) { + addCriterion("qr_code_url <=", value, "qrCodeUrl"); + return (Criteria) this; + } + + public Criteria andQrCodeUrlLike(String value) { + addCriterion("qr_code_url like", value, "qrCodeUrl"); + return (Criteria) this; + } + + public Criteria andQrCodeUrlNotLike(String value) { + addCriterion("qr_code_url not like", value, "qrCodeUrl"); + return (Criteria) this; + } + + public Criteria andQrCodeUrlIn(List values) { + addCriterion("qr_code_url in", values, "qrCodeUrl"); + return (Criteria) this; + } + + public Criteria andQrCodeUrlNotIn(List values) { + addCriterion("qr_code_url not in", values, "qrCodeUrl"); + return (Criteria) this; + } + + public Criteria andQrCodeUrlBetween(String value1, String value2) { + addCriterion("qr_code_url between", value1, value2, "qrCodeUrl"); + return (Criteria) this; + } + + public Criteria andQrCodeUrlNotBetween(String value1, String value2) { + addCriterion("qr_code_url not between", value1, value2, "qrCodeUrl"); + return (Criteria) this; + } + public Criteria andRemarkIsNull() { addCriterion("remark is null"); return (Criteria) this; 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 5c88d090..a451cc00 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 @@ -7,7 +7,6 @@ import com.ccsens.util.PdfUtil; import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModelProperty; import lombok.Data; -import org.springframework.beans.factory.annotation.Autowired; import java.util.*; @@ -129,12 +128,17 @@ public class PatientReportVo { "病案号:" + this.hospitalNumber) ); //第四栏 - Date date = new Date(); - date.setTime(this.reportTime); + Date date = null; + if (this.reportTime > 0) { + date = new Date(); + date.setTime(this.reportTime); + } + rows.add( fillRow( "临床诊断:" + this.clinicalDiagnosis, - "检查日期:" + DateUtil.format(date, "yyyy-MM-dd")) + "", + "检查日期:" + (date == null ? "" : DateUtil.format(date, "yyyy-MM-dd"))) ); return rows; @@ -181,31 +185,39 @@ public class PatientReportVo { } public List toRow() { + 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.name + (StrUtil.isBlank(this.remark) ? "" : "("+this.remark+")")); + 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); row.addCell(cell1); row.addCell(cell2); + rows.add(row); - return rows; } else { String mmse = "MMSE"; String npi = "NPI"; if (mmse.equalsIgnoreCase(this.code) || npi.equalsIgnoreCase(this.code)) { PdfUtil.Row row1 = new PdfUtil.Row(); PdfUtil.Cell cell = new PdfUtil.Cell(); - cell.setContent(this.name + (StrUtil.isBlank(this.remark) ? "" : "("+this.remark+")")); + cell.setContent(this.code + (StrUtil.isBlank(this.remark) ? "" : "("+this.remark+")")); cell.setRowSpan(2); + cell.setColSpan(npi.equalsIgnoreCase(this.code) ? headNum : 1); row1.addCell(cell); + //被合并cell PdfUtil.Row row2 = new PdfUtil.Row(); +// fillBlankCell(row2); + //子测评项 this.subReport.forEach(reportScore -> { - fillRow(row1,row2, reportScore.getName(), reportScore.score == null ? "" : reportScore.score + (reportScore.totalScore > 0 ? "/" + reportScore.totalScore : "")); + fillRow(row1,row2, reportScore.getName(), reportScore.score == null ? "" : reportScore.score + (reportScore.totalScore > 0 ? "/" + reportScore.totalScore : ""), npi.equalsIgnoreCase(this.code) ? new int[]{3,3} : null); }); - + // 总分 if (mmse.equalsIgnoreCase(this.code)) { fillRow(row1,row2, "总分", this.score == null ? "" : this.score + (this.totalScore > 0 ? "/" + this.totalScore : "")); } @@ -213,75 +225,110 @@ public class PatientReportVo { rows.add(row2); } else { //moca - int firstIndex = 6; + int firstIndex = 5; PdfUtil.Row row1 = new PdfUtil.Row(); PdfUtil.Cell cell = new PdfUtil.Cell(); cell.setContent(this.name + (StrUtil.isBlank(this.remark) ? "" : "("+this.remark+")")); cell.setRowSpan(5); row1.addCell(cell); PdfUtil.Row row2 = new PdfUtil.Row(); +// fillBlankCell(row2); for (int i = 0; i < firstIndex; i++) { ReportScore reportScore = this.subReport.get(i); String jy = "JY"; if (jy.equalsIgnoreCase(reportScore.getCode())) { - fillRow(row1, row2, reportScore.getName(), ""); + fillRow(row1, row2, reportScore.getName(), "", i == 0 ? new int[]{2,2}: null); } else { - fillRow(row1, row2, reportScore.getName(), reportScore.score == null ? "" : reportScore.score + (reportScore.totalScore > 0 ? "/" + reportScore.totalScore : "")); + fillRow(row1, row2, reportScore.getName(), reportScore.score == null ? "" : reportScore.score + (reportScore.totalScore > 0 ? "/" + reportScore.totalScore : ""), i == 0 ? new int[]{2,2}: null); } } PdfUtil.Cell scoreNameCell = new PdfUtil.Cell(); scoreNameCell.setContent("总分"); row1.addCell(scoreNameCell); PdfUtil.Cell scoreCell = new PdfUtil.Cell(); - scoreNameCell.setContent("总分"); - row1.addCell(scoreNameCell); - - - for (ReportScore score: this.subReport) { - - - - if (firstIndex == 6) { - //设置总分 - PdfUtil.Cell scoreTitleCell = new PdfUtil.Cell(); - scoreTitleCell.setContent("总分"); - row1.addCell(scoreTitleCell); - PdfUtil.Cell scoreScoreCell = new PdfUtil.Cell(); - scoreScoreCell.setContent(this.score == null ? "" : this.score + (this.totalScore > 0 ? "/" + this.totalScore : "")); - scoreScoreCell.setRowSpan(4); - row2.addCell(scoreScoreCell); - rows.add(row1); - rows.add(row2); - //换行 - row1 = new PdfUtil.Row(); - row2 = new PdfUtil.Row(); - } - firstIndex++; - } + scoreCell.setContent(this.score == null ? "" : this.score + (this.totalScore > 0 ? "/" + this.totalScore : "")); + scoreCell.setRowSpan(4); + row2.addCell(scoreCell); +// fillBlankCell(row1, row2); rows.add(row1); rows.add(row2); + //下一行 + PdfUtil.Row row3 = new PdfUtil.Row(); + PdfUtil.Row row4 = new PdfUtil.Row(); + PdfUtil.Row row5 = new PdfUtil.Row(); +// fillBlankCell(row3, row4, row5); + //延迟回忆特殊处理 + String ychy = "YCHY"; + for (int i = firstIndex; i < this.subReport.size(); i++) { + ReportScore reportScore = this.subReport.get(i); + //设置名字 + PdfUtil.Cell scoreTitleCell = new PdfUtil.Cell(); + scoreTitleCell.setContent(reportScore.getName()); + scoreTitleCell.setColSpan(ychy.equalsIgnoreCase(reportScore.getCode()) ? 2 : 1); + row3.addCell(scoreTitleCell); + //设置子类 + if (ychy.equalsIgnoreCase(reportScore.getCode())) { + for (int j = 0; j < reportScore.subReport.size(); j++) { + ReportScore subScore = reportScore.getSubReport().get(j); + PdfUtil.Cell subCell = new PdfUtil.Cell(); + subCell.setContent(subScore.name + (subScore.getScore() == null ? " " : subScore.getScore()) + subScore.getRemark()); + if (j == 0 ) { + row4.addCell(subCell); + } else { + row5.addCell(subCell); + } + } + } + PdfUtil.Cell scoreScoreCell = new PdfUtil.Cell(); + scoreScoreCell.setContent(reportScore.score == null ? "" : reportScore.score + (reportScore.totalScore > 0 ? "/" + reportScore.totalScore : "")); + scoreScoreCell.setRowSpan(2); + row4.addCell(scoreScoreCell); +// fillBlankCell(row5); + + } +// fillBlankCell(row3); +// fillBlankCell(row3, row4, row5); + rows.add(row3); + rows.add(row4); + rows.add(row5); } } - PdfUtil.Row row = new PdfUtil.Row(); + PdfUtil.Row descRow = new PdfUtil.Row(); PdfUtil.Cell cell = new PdfUtil.Cell(); + cell.setColSpan(colNum); cell.setContent(this.description); - + descRow.addCell(cell); + rows.add(descRow); return rows; } - private void fillRow(PdfUtil.Row row1, PdfUtil.Row row2, String name, String score){ + /** + * 添加一个空格 + * @param rows + */ + private void fillBlankCell(PdfUtil.Row... rows) { + for (PdfUtil.Row row: rows) { + PdfUtil.Cell cell = new PdfUtil.Cell(); + row.addCell(cell); + } + } + + private void fillRow(PdfUtil.Row row1, PdfUtil.Row row2, String name, String score, int... colspan){ //名称 PdfUtil.Cell cell1 = new PdfUtil.Cell(); cell1.setContent(name); + cell1.setColSpan(colspan == null || colspan.length == 0 ? 1 : colspan[0]); row1.addCell(cell1); + //分数 PdfUtil.Cell cell2 = new PdfUtil.Cell(); cell2.setContent(score); + cell2.setColSpan(colspan == null || colspan.length <= 1 ? 1 : colspan[1]); row2.addCell(cell2); } } diff --git a/ht/src/main/java/com/ccsens/ht/service/IPatientReportService.java b/ht/src/main/java/com/ccsens/ht/service/IPatientReportService.java index b6620c3d..1f8fa78a 100644 --- a/ht/src/main/java/com/ccsens/ht/service/IPatientReportService.java +++ b/ht/src/main/java/com/ccsens/ht/service/IPatientReportService.java @@ -6,6 +6,8 @@ import com.ccsens.util.CodeEnum; import com.ccsens.util.JsonResponse; import com.github.pagehelper.PageInfo; +import java.io.IOException; + public interface IPatientReportService { @@ -56,4 +58,20 @@ public interface IPatientReportService { *@date: 2019/11/19 15:50 */ PatientReportVo.Authority queryReportAuthority(PatientReportDto.Authority authority, Long userId); + + /** + * 导出报告单 + * @param queryDetail + * @param userId + * @return + */ + String exportReport(PatientReportDto.QueryDetail queryDetail, Long userId); + + /** + * 生成二维码 + * @param queryDetail + * @param userId + * @return + */ + String generateQRCode(PatientReportDto.QueryDetail queryDetail, Long userId) throws IOException; } diff --git a/ht/src/main/java/com/ccsens/ht/service/PatientReportService.java b/ht/src/main/java/com/ccsens/ht/service/PatientReportService.java index 21f2f1ff..ba64c430 100644 --- a/ht/src/main/java/com/ccsens/ht/service/PatientReportService.java +++ b/ht/src/main/java/com/ccsens/ht/service/PatientReportService.java @@ -14,8 +14,7 @@ import com.ccsens.ht.persist.mapper.HtPatientFollowUpMapper; import com.ccsens.ht.persist.mapper.HtPatientMapper; import com.ccsens.ht.persist.mapper.HtPatientReportRecordMapper; import com.ccsens.ht.uitl.Constant; -import com.ccsens.util.CodeEnum; -import com.ccsens.util.JsonResponse; +import com.ccsens.util.*; import com.ccsens.util.exception.BaseException; import com.github.pagehelper.PageHelper; import com.github.pagehelper.PageInfo; @@ -27,6 +26,7 @@ import org.springframework.transaction.annotation.Propagation; import org.springframework.transaction.annotation.Transactional; import org.springframework.util.CollectionUtils; +import java.io.IOException; import java.math.BigDecimal; import java.util.*; import java.util.concurrent.atomic.AtomicBoolean; @@ -346,4 +346,76 @@ public class PatientReportService implements IPatientReportService { return sum.get(); } + + @Override + public String exportReport(PatientReportDto.QueryDetail queryDetail, Long userId) { + log.info("导出报告单:{}, 操作用户:{}", queryDetail, userId); + //查看是否已生成对应文件路径 + HtPatientReport report = htPatientReportDao.selectByPrimaryKey(queryDetail.getId()); + if (report == null) { + throw new BaseException(CodeEnum.REPORT_NOT_FOUND); + } + if (StrUtil.isNotBlank(report.getUrl())) { + return report.getUrl(); + } + PatientReportVo.ReprotDetail detail = queryReportDetail(queryDetail, userId); + if (detail == null) { + throw new BaseException(CodeEnum.REPORT_NOT_FOUND); + } + List content = new ArrayList<>(); + detail.getScores().forEach(reportScore -> { + content.addAll(reportScore.toRow()); + }); + PdfUtil.Row row = new PdfUtil.Row(); + addCell(row,"初步印象",2,2); + addCell(row, detail.getPatient().getInitialImpression(), 6, 2); + content.add(row); + PdfUtil.Row row2 = new PdfUtil.Row(); + addCell(row2,"测评员:",4,1, 0); + addCell(row2,"报告日期:",4,1, 0); + content.add(row2); + + String path = PropUtil.imgDomain + "/" + PdfUtil.credatePdf(PropUtil.path, detail.getPatient().getName(), detail.getPatient().toPdfRow(), content); + report.setUrl(path); + htPatientReportDao.updateByPrimaryKeySelective(report); + log.info("生成文件路径:{}", path); + return path; + } + + private void addCell(PdfUtil.Row row, String content, int colSpan, int rowSpan, int... border) { + PdfUtil.Cell cell1 = new PdfUtil.Cell(); + cell1.setContent(content); + cell1.setColSpan(colSpan); + cell1.setRowSpan(rowSpan); + cell1.setBorder(border == null || border.length == 0 ? 1 : border[0]); + row.addCell(cell1); + } + + @Override + public String generateQRCode(PatientReportDto.QueryDetail queryDetail, Long userId) throws IOException { + log.info("报告单分享:{},用户ID:{}", queryDetail, userId); + HtPatientReport report = htPatientReportDao.selectByPrimaryKey(queryDetail.getId()); + if (report == null) { + throw new BaseException(CodeEnum.REPORT_NOT_FOUND); + } + //有二维码直接返回 + if (StrUtil.isNotBlank(report.getQrCodeUrl())) { + log.info("直接返回二维码路径:{}", report.getQrCodeUrl()); + return report.getQrCodeUrl(); + } + + String pdfUrl = report.getUrl(); + if (StrUtil.isBlank(pdfUrl)) { + log.info("尚未生成pdf文件,生成文件"); + pdfUrl = exportReport(queryDetail, userId); + } + String qrCodePath = QrCodeUtil.urlToQRCode(pdfUrl, PropUtil.path); + String qrCodeUrl = PropUtil.imgDomain + "/" + qrCodePath; + log.info("生成的二维码路径:{}", qrCodeUrl); + HtPatientReport newReport = htPatientReportDao.selectByPrimaryKey(queryDetail.getId()); + newReport.setQrCodeUrl(qrCodeUrl); + htPatientReportDao.updateByPrimaryKeySelective(newReport); + log.info("修改报告单二维码路径"); + return qrCodeUrl; + } } diff --git a/ht/src/main/resources/mapper_raw/HtPatientReportMapper.xml b/ht/src/main/resources/mapper_raw/HtPatientReportMapper.xml index b87e2524..1c75f972 100644 --- a/ht/src/main/resources/mapper_raw/HtPatientReportMapper.xml +++ b/ht/src/main/resources/mapper_raw/HtPatientReportMapper.xml @@ -18,6 +18,7 @@ + @@ -84,7 +85,7 @@ id, name, patient_id, patient_idcard, patient_age, doctor_id, serial_number, initial_impression, clinical_diagnosis, pasi, department, bed_number, report_time, check_time, evaluation_code, - url, remark, create_time, update_time, is_del + url, qr_code_url, remark, create_time, update_time, is_del