| | |
| | | |
| | | import cn.hutool.core.date.DateUtil; |
| | | import cn.hutool.core.util.StrUtil; |
| | | import cn.hutool.json.JSONArray; |
| | | import cn.hutool.json.JSONObject; |
| | | import cn.hutool.json.JSONUtil; |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.itextpdf.text.*; |
| | | import com.itextpdf.text.pdf.*; |
| | | import com.itextpdf.text.pdf.draw.LineSeparator; |
| | | import com.ltkj.common.core.domain.AjaxResult; |
| | | import com.ltkj.common.core.domain.entity.SysUser; |
| | | import com.ltkj.common.utils.DateUtils; |
| | | import com.ltkj.framework.config.MatchUtils; |
| | | import com.ltkj.hosp.domain.*; |
| | |
| | | private DictUserInfoMapper dictUserInfoMapper; |
| | | @Autowired |
| | | private ISysConfigService sysConfigService; |
| | | |
| | | // private static final |
| | | // TODO PDF所有医师名字显示 根据配置is_report_pdf_use_ysqm决定是否使用签名图片 |
| | | // TODO 有签名图片则使用签名图片 没有则使用文字显示 |
| | | |
| | | private List<Map<String, Object>> makePDFInfo(HashMap<String, Object> map, AjaxResult ajaxResult, String key) { |
| | | List<Map<String, Object>> data = null; |
| | |
| | | List<LtkjGetexamreportinfo> list = ltkjGetexamreportinfoService.list(lambdaQueryWrapper); |
| | | // List<LtkjGetexamreportinfo> list = ltkjGetexamreportinfoService.list(); |
| | | List<ByteArrayOutputStream> jianchas = new ArrayList<>(); |
| | | Paragraph elements = new Paragraph(); |
| | | elements.setLeading(5f); |
| | | elements.setSpacingBefore(10f); |
| | | elements.setSpacingAfter(10f); |
| | | elements.setAlignment(Element.ALIGN_RIGHT); |
| | | Phrase phrase = new Phrase(); |
| | | Font doctorFonts = PdfUtils.setFont(9); |
| | | for (LtkjGetexamreportinfo getexamreportinfo : list) { |
| | | String xm = getexamreportinfo.getHzxm(); |
| | | String xb = getexamreportinfo.getHzxb().equals("2") ? "女" : "男"; |
| | |
| | | String sqrxm = getexamreportinfo.getSqrxm(); |
| | | String zyh = ""; |
| | | String ch = ""; |
| | | String footer = "申请人:" + sqrxm + " 审核医师:" + shysqm + " 医师签名:" + bgysqm; |
| | | ByteArrayOutputStream outputStream = makeJcPDFByteArrayStream(xm, xb, nl, jcks, zyh, ch, sjks, jcsb, jch, jcxm, ms, ts, null, footer); |
| | | String sqrbh = getexamreportinfo.getSqrbh(); |
| | | String shysbh = getexamreportinfo.getShysbh(); |
| | | String bgysbh = getexamreportinfo.getBgysbh(); |
| | | String jcysqm = getexamreportinfo.getJcysqm(); |
| | | String jcysbh = getexamreportinfo.getJcysbh(); |
| | | StringBuilder builder; |
| | | String footer; |
| | | // 检查返回的医师编码不属于his医师id 暂注释 |
| | | // String key = sysConfigService.selectConfigByKey("is_report_pdf_use_ysqm"); |
| | | // if (key.equals("Y")){ |
| | | // footer = null; |
| | | // if (null != sqrbh && StrUtil.isNotBlank(sqrbh)){ |
| | | // makeYiShiInfoLine(phrase, doctorFonts, sqrxm, sqrbh,"申请人:"); |
| | | // } |
| | | // if (null != jcysbh && StrUtil.isNotBlank(jcysbh)){ |
| | | // makeYiShiInfoLine(phrase, doctorFonts, jcysqm, jcysbh," 检查医师:"); |
| | | // } |
| | | // if (null != shysbh && StrUtil.isNotBlank(shysbh)){ |
| | | // makeYiShiInfoLine(phrase, doctorFonts, shysqm, shysbh," 审核医师:"); |
| | | // } |
| | | // if (null != bgysbh && StrUtil.isNotBlank(bgysbh)){ |
| | | // makeYiShiInfoLine(phrase, doctorFonts, bgysqm, bgysbh," 报告医师:"); |
| | | // } |
| | | // }else { |
| | | builder = new StringBuilder(); |
| | | if (null != sqrxm && StrUtil.isNotBlank(sqrxm)){ |
| | | builder.append("申请人:").append(sqrxm); |
| | | } |
| | | if (null != jcysqm && StrUtil.isNotBlank(jcysqm)){ |
| | | builder.append(" 检查医师:").append(jcysqm); |
| | | } |
| | | if (null != shysqm && StrUtil.isNotBlank(shysqm)){ |
| | | builder.append(" 审核医师:").append(shysqm); |
| | | } |
| | | if (null != bgysqm && StrUtil.isNotBlank(bgysqm)){ |
| | | builder.append(" 报告医师:").append(bgysqm); |
| | | } |
| | | footer = builder.toString().trim(); |
| | | // } |
| | | // elements.add(phrase); |
| | | ByteArrayOutputStream outputStream = makeJcPDFByteArrayStream(xm, xb, nl, jcks, zyh, ch, sjks, jcsb, jch, jcxm, ms, ts, null, footer,elements); |
| | | if (outputStream == null) |
| | | throw new Exception(); |
| | | jianchas.add(outputStream); |
| | | } |
| | | return jianchas; |
| | | } |
| | | |
| | | /** |
| | | * 医师信息行 |
| | | * @param phrase |
| | | * @param doctorFonts |
| | | * @param sqrxm |
| | | * @param sqrbh |
| | | * @throws BadElementException |
| | | */ |
| | | private void makeYiShiInfoLine(Phrase phrase, Font doctorFonts, String sqrxm, String sqrbh,String title) throws BadElementException { |
| | | String qmImg = dictUserInfoMapper.selectQmImgInnerJoinUserByHisDictCode(sqrbh); |
| | | // String qmImg = dictUserInfoMapper.selectQmImgInnerJoinUserByUserId(sqrbh); |
| | | if (null != qmImg && StrUtil.isNotBlank(qmImg)) { |
| | | byte[] decode = Base64.getDecoder().decode(qmImg); |
| | | Image image = null; |
| | | try { |
| | | image = Image.getInstance(decode); |
| | | image.scaleToFit(60, 25); |
| | | phrase.add(new Chunk(title,doctorFonts)); |
| | | phrase.add(new Chunk(image,0,-10,true)); |
| | | } catch (IOException e) { |
| | | phrase.add(new Chunk(title+sqrxm, doctorFonts)); |
| | | } |
| | | }else { |
| | | phrase.add(new Chunk(title+sqrxm, doctorFonts)); |
| | | } |
| | | } |
| | | |
| | | /** |
| | |
| | | * @param map |
| | | * @throws DocumentException |
| | | */ |
| | | private void makeHisJianYanTable(Document document1, HashMap<String, Object> map) throws DocumentException, IOException { |
| | | private void makeHisJianYanTable(Document document1, HashMap<String, Object> map) throws DocumentException { |
| | | if (!map.isEmpty()) { |
| | | String[] titles = new String[]{"体检项目", "体检结果", "单位", "参考范围"}; |
| | | float[] titlesWidth = new float[]{120, 120, 120, 120}; |
| | |
| | | String[] split = s.split("\\|"); |
| | | String qmImg = dictUserInfoMapper.selectQmImgInnerJoinUserByHisDictCode(split[1]); |
| | | if (null != qmImg && StrUtil.isNotBlank(qmImg)) { |
| | | ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(Base64.getDecoder().decode(qmImg)); |
| | | byte[] decode = Base64.getDecoder().decode(qmImg); |
| | | Image image = Image.getInstance(decode); |
| | | image.scaleToFit(60, 25); |
| | | phrase.add(new Chunk(image,0,-10,true)); |
| | | Image image = null; |
| | | try { |
| | | image = Image.getInstance(decode); |
| | | image.scaleToFit(60, 25); |
| | | phrase.add(new Chunk(image,0,-10,true)); |
| | | } catch (IOException e) { |
| | | phrase.add(new Chunk(split[0].trim(),doctorFonts)); |
| | | } |
| | | } else { |
| | | phrase.add(new Chunk(split[0].trim(),doctorFonts)); |
| | | } |
| | |
| | | document1.add(pp); |
| | | } |
| | | //判断主检医师是否为空 空不能显示null |
| | | if (null != entry.getKey().getDoctorName() && null != userService.getById(entry.getKey().getDoctorName())) { |
| | | //主检医师 |
| | | String doctorName = "主检医师:" + userService.getById(entry.getKey().getDoctorName()).getNickName(); |
| | | Font doctorFonts = PdfUtils.setFont(9); |
| | | Paragraph df = PdfUtils.setParagraph(doctorFonts, doctorName); |
| | | df.setAlignment(Element.ALIGN_RIGHT); |
| | | document1.add(df); |
| | | } else { |
| | | String doctorName = "主检医师:" + "无"; |
| | | Font doctorFonts = PdfUtils.setFont(9); |
| | | Paragraph df = PdfUtils.setParagraph(doctorFonts, doctorName); |
| | | df.setAlignment(Element.ALIGN_RIGHT); |
| | | document1.add(df); |
| | | } |
| | | zhuJianYiShi(document1, entry); |
| | | //分割线 |
| | | LineSeparator objectName = new LineSeparator(); |
| | | document1.add(objectName); |
| | |
| | | document1.add(pp); |
| | | } |
| | | //判断主检医师是否为空 空不能显示null |
| | | if (null != entry.getKey().getDoctorName() && null != userService.getById(entry.getKey().getDoctorName())) { |
| | | //主检医师 |
| | | String doctorName = "主检医师:" + userService.getById(entry.getKey().getDoctorName()).getNickName(); |
| | | Font doctorFonts = PdfUtils.setFont(9); |
| | | Paragraph df = PdfUtils.setParagraph(doctorFonts, doctorName); |
| | | df.setAlignment(Element.ALIGN_RIGHT); |
| | | document1.add(df); |
| | | } else { |
| | | String doctorName = "主检医师:" + "无"; |
| | | Font doctorFonts = PdfUtils.setFont(9); |
| | | Paragraph df = PdfUtils.setParagraph(doctorFonts, doctorName); |
| | | df.setAlignment(Element.ALIGN_RIGHT); |
| | | document1.add(df); |
| | | } |
| | | zhuJianYiShi(document1, entry); |
| | | //分割线 |
| | | LineSeparator objectName = new LineSeparator(); |
| | | document1.add(objectName); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 主见医师行显示设置 |
| | | * @param document1 |
| | | * @param entry |
| | | * @throws DocumentException |
| | | */ |
| | | private void zhuJianYiShi(Document document1, Map.Entry<TjOrderRemark, List<TjPdfVO>> entry) throws DocumentException { |
| | | if (null != entry.getKey().getDoctorName() && null != userService.getById(entry.getKey().getDoctorName())) { |
| | | //主检医师 |
| | | String key = sysConfigService.selectConfigByKey("is_report_pdf_use_ysqm"); |
| | | SysUser sysUser = userService.getById(entry.getKey().getDoctorName()); |
| | | Font doctorFonts = PdfUtils.setFont(9); |
| | | if (key.equals("Y")){ |
| | | String qmImg = dictUserInfoMapper.selectQmImgInnerJoinUserByUserId(String.valueOf(sysUser.getUserId())); |
| | | if (null != qmImg && StrUtil.isNotBlank(qmImg)) { |
| | | Paragraph elements = new Paragraph(); |
| | | elements.setLeading(5f); |
| | | elements.setSpacingBefore(10f); |
| | | elements.setSpacingAfter(10f); |
| | | elements.setAlignment(Element.ALIGN_RIGHT); |
| | | Phrase phrase = new Phrase(); |
| | | phrase.add(new Chunk("主检医师:",doctorFonts)); |
| | | byte[] decode = Base64.getDecoder().decode(qmImg); |
| | | Image image = null; |
| | | try { |
| | | image = Image.getInstance(decode); |
| | | image.scaleToFit(60, 25); |
| | | phrase.add(new Chunk(image,0,-10,true)); |
| | | elements.add(phrase); |
| | | document1.add(elements); |
| | | } catch (IOException e) { |
| | | String doctorName = "主检医师:" + sysUser.getNickName(); |
| | | Paragraph df = PdfUtils.setParagraph(doctorFonts, doctorName); |
| | | df.setAlignment(Element.ALIGN_RIGHT); |
| | | document1.add(df); |
| | | } |
| | | }else { |
| | | String doctorName = "主检医师:" + sysUser.getNickName(); |
| | | Paragraph df = PdfUtils.setParagraph(doctorFonts, doctorName); |
| | | df.setAlignment(Element.ALIGN_RIGHT); |
| | | document1.add(df); |
| | | } |
| | | }else { |
| | | String doctorName = "主检医师:" + sysUser.getNickName(); |
| | | Paragraph df = PdfUtils.setParagraph(doctorFonts, doctorName); |
| | | df.setAlignment(Element.ALIGN_RIGHT); |
| | | document1.add(df); |
| | | } |
| | | } else { |
| | | String doctorName = "主检医师:" + "无"; |
| | | Font doctorFonts = PdfUtils.setFont(9); |
| | | Paragraph df = PdfUtils.setParagraph(doctorFonts, doctorName); |
| | | df.setAlignment(Element.ALIGN_RIGHT); |
| | | document1.add(df); |
| | | } |
| | | } |
| | | |
| | |
| | | * @param footer |
| | | * @return bytearrayoutputstream |
| | | */ |
| | | public static ByteArrayOutputStream makeJcPDFByteArrayStream(String xm, String xb, String nl, String jcks, String zyh, String ch, String sjks, String jcsb, String jch, String jcxm, String ms, String ts, File[] files, String footer) { |
| | | public static ByteArrayOutputStream makeJcPDFByteArrayStream(String xm, String xb, String nl, String jcks, String zyh, String ch, String sjks, String jcsb, String jch |
| | | , String jcxm, String ms, String ts, File[] files, String footer,Paragraph elements) { |
| | | try { |
| | | Document document = new Document(PageSize.A4); |
| | | ByteArrayOutputStream baos = new ByteArrayOutputStream(); |
| | | PdfWriter writer = PdfWriter.getInstance(document, baos); |
| | | writer.setPageEvent(new Footer(footer)); |
| | | if (footer != null) { |
| | | writer.setPageEvent(new Footer(footer)); |
| | | } else { |
| | | writer.setPageEvent(new Footer(elements)); |
| | | } |
| | | document.open(); |
| | | document.setMargins(70, 70, 40, 40); |
| | | |
| | |
| | | static class Footer extends PdfPageEventHelper { |
| | | private String footerText; |
| | | private Font footerFont = PdfUtils.setFont(10); |
| | | private Paragraph paragraph; |
| | | |
| | | public Footer(String footerText) { |
| | | this.footerText = footerText; |
| | | } |
| | | |
| | | public Footer(Paragraph paragraph){ |
| | | this.paragraph = paragraph; |
| | | } |
| | | |
| | | @Override |
| | |
| | | footer.setWidthPercentage(100); |
| | | footer.getDefaultCell().setBorder(Rectangle.NO_BORDER); |
| | | footer.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER); |
| | | footer.addCell(new Phrase(footerText, footerFont)); |
| | | if (footerText != null) |
| | | footer.addCell(new Phrase(footerText, footerFont)); |
| | | if (paragraph != null) |
| | | footer.addCell(paragraph); |
| | | footer.writeSelectedRows(0, -1, 36, 50, writer.getDirectContent()); |
| | | } |
| | | } |