| | |
| | | |
| | | 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.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; |
| | | 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.common.utils.StringUtils; |
| | | import com.ltkj.framework.config.MatchUtils; |
| | | import com.ltkj.hosp.domain.*; |
| | | import com.ltkj.hosp.mapper.DictUserInfoMapper; |
| | | import com.ltkj.hosp.service.*; |
| | | import com.ltkj.hosp.sqlDomain.LtkjExamJcbgd; |
| | | import com.ltkj.hosp.sqlDomain.LtkjHybgd; |
| | | import com.ltkj.hosp.sqlDomain.LtkjHysqd; |
| | | import com.ltkj.mall.mallOrderUtils.TjConstants; |
| | | import com.ltkj.system.service.ISysConfigService; |
| | | import com.ltkj.system.service.ISysUserService; |
| | | import com.ltkj.web.config.pdfutils.PdfUtils; |
| | | import lombok.extern.slf4j.Slf4j; |
| | |
| | | import org.springframework.beans.factory.annotation.Value; |
| | | import org.springframework.stereotype.Component; |
| | | |
| | | import javax.annotation.Resource; |
| | | import java.io.*; |
| | | import java.lang.reflect.Field; |
| | | import java.lang.reflect.InvocationTargetException; |
| | |
| | | import java.math.BigDecimal; |
| | | import java.util.*; |
| | | import java.util.List; |
| | | |
| | | import static com.ltkj.web.config.pdfutils.PDFBinaryUtil.getPDFBinary; |
| | | |
| | | /** |
| | | * 检查 检验报告pdf生成 |
| | |
| | | private LtkjHysqdService ltkjHysqdService; |
| | | @Autowired |
| | | private LtkjGetexamreportinfoService ltkjGetexamreportinfoService; |
| | | @Value ("${path.filePath}") |
| | | @Value("${path.filePath}") |
| | | private String value; |
| | | @Value ("${path.reportServer}") |
| | | @Value("${path.reportServer}") |
| | | private String urlValue; |
| | | |
| | | // private static final |
| | | |
| | | /** |
| | | * 通过his API请求获取数据生成PDF |
| | | * |
| | | * @param pdfInfoMap |
| | | * @param params |
| | | * @param tjOrder |
| | | * @param tjReportTemplate |
| | | * @return |
| | | * @deprecated 有数据同步不在调用接口获取数据直接查数据库拿数据生成 |
| | | */ |
| | | @Deprecated |
| | | public AjaxResult execHisRequest(HashMap<String, Object> pdfInfoMap, Map<String, Object> params, TjOrder tjOrder, TjReportTemplate tjReportTemplate) { |
| | | List<Map<String, Object>> list; |
| | | String hisRegistrationId = params.get("his_registration_id").toString(); |
| | | AjaxResult getlabreportinfo = apiGetMethodService.getHISDataNew("Getlabreportinfo", params); |
| | | list = makePDFInfo(pdfInfoMap, getlabreportinfo, "获取检验报告记录信息"); |
| | | JSONArray jsonArray = JSONUtil.createArray(); |
| | | if (list != null) { |
| | | params.clear(); |
| | | for (Map<String, Object> stringObjectMap : list) { |
| | | if (stringObjectMap == null) |
| | | continue; |
| | | JSONObject obj = JSONUtil.createObj(); |
| | | obj.putOpt("报告记录", stringObjectMap); |
| | | String jybgid = stringObjectMap.get("JYBGID").toString(); |
| | | params.put("jybgid", jybgid); |
| | | // 获取检验结果记录信息 |
| | | AjaxResult getlabdetailinfo = apiGetMethodService.getHISDataNew("Getlabdetailinfo", params); |
| | | putData(obj, getlabdetailinfo, "检验结果记录"); |
| | | // 获取微生物报告记录信息 |
| | | AjaxResult getlabgermrepinfo = apiGetMethodService.getHISDataNew("Getlabgermrepinfo", params); |
| | | putData(obj, getlabgermrepinfo, "微生物报告记录"); |
| | | // 获取微生物药敏信息 |
| | | AjaxResult getlabgermdetailinfo = apiGetMethodService.getHISDataNew("Getlabgermdetailinfo", params); |
| | | putData(obj, getlabgermdetailinfo, "微生物药敏信息"); |
| | | // 获取危急值信息 |
| | | AjaxResult getlaburgentinfo = apiGetMethodService.getHISDataNew("Getlaburgentinfo", params); |
| | | putData(obj, getlaburgentinfo, "危机值信息"); |
| | | jsonArray.put(obj); |
| | | } |
| | | // 获取检查报告信息 |
| | | params.clear(); |
| | | params.put("his_registration_id", hisRegistrationId); |
| | | params.put("ksmc", ""); |
| | | params.put("pationid", ""); |
| | | params.put("ksrq", ""); |
| | | params.put("jsrq", ""); |
| | | params.put("pagecount", 100); |
| | | params.put("page", 1); |
| | | params.put("status", ""); |
| | | AjaxResult getexamreportinfo = apiGetMethodService.getHISDataNew("Getexamreportinfo", params); |
| | | JSONObject object = JSONUtil.parseObj(getexamreportinfo.get("result")); |
| | | JSONObject response = JSONUtil.parseObj(object.get("Response")); |
| | | if (!response.getStr("ResultCode").equals("0")) { |
| | | if (!response.getStr("ResultContent").contains("查询失败")) |
| | | return AjaxResult.error("生成超时,请重试"); |
| | | } |
| | | JSONObject obj = JSONUtil.createObj(); |
| | | putData(obj, getexamreportinfo, "检查报告"); |
| | | jsonArray.put(obj); |
| | | // System.out.println(JSONUtil.toJsonStr(jsonArray)); |
| | | if (makePDF(hisRegistrationId, jsonArray, tjOrder, tjReportTemplate)) { |
| | | log.info("已生成报告"); |
| | | return AjaxResult.success("已生成报告!可直接点击预览!"); |
| | | } else return AjaxResult.error(); |
| | | } else { |
| | | return AjaxResult.error("未获取到检验报告记录信息"); |
| | | } |
| | | } |
| | | @Autowired |
| | | private DictUserInfoMapper dictUserInfoMapper; |
| | | @Autowired |
| | | private ISysConfigService sysConfigService; |
| | | @Resource |
| | | private LtkjExamJcbgdService jcbgdService; |
| | | @Resource |
| | | private LtkjExamJcsqdService jcsqdService; |
| | | |
| | | private List<Map<String, Object>> makePDFInfo(HashMap<String, Object> map, AjaxResult ajaxResult, String key) { |
| | | List<Map<String, Object>> data = null; |
| | |
| | | } |
| | | } |
| | | |
| | | public AjaxResult hisPDF(TjOrder tjOrder, TjCustomer customer, TjReportTemplate tjReportTemplate) throws DocumentException { |
| | | public AjaxResult hisPDF(TjOrder tjOrder, TjCustomer customer, TjReportTemplate tjReportTemplate) throws Exception { |
| | | HashMap<String, Object> pdfChangGui = makePDFInfo(tjOrder, customer, tjReportTemplate); |
| | | if (pdfChangGui == null) |
| | | return AjaxResult.error(); |
| | | Document document = (Document) pdfChangGui.get("document"); |
| | | PdfCopy copy = (PdfCopy) pdfChangGui.get("copy"); |
| | | ByteArrayOutputStream finalOutPut = (ByteArrayOutputStream) pdfChangGui.get("stream"); |
| | |
| | | // 组装检验数据 |
| | | HashMap<String, Object> map = makeHisJianYan(tjOrder, customer); |
| | | makeHisJianYanTable(document1, map); |
| | | |
| | | |
| | | List<ByteArrayOutputStream> jianchas = makeHisJianChaTable(tjOrder); |
| | | // List<ByteArrayOutputStream> jianchas = makeCcgcHisJianChaTable(tjOrder); |
| | | document1.close(); |
| | | pdfWriter.close(); |
| | | PdfReader reader = null; |
| | |
| | | return AjaxResult.error(); |
| | | } |
| | | String outputFileName1 = customer.getCusId() + tjOrder.getTjNumber() + customer.getCusName() + "_报告.pdf"; |
| | | try { |
| | | PdfReader pdfReader = new PdfReader(finalOutPut.toByteArray()); |
| | | int pages = pdfReader.getNumberOfPages(); |
| | | ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); |
| | | PdfStamper pdfStamper = new PdfStamper(pdfReader, outputStream); |
| | | PdfContentByte contentByte; |
| | | BaseFont baseFont = PdfUtils.createBaseFont(null); |
| | | for (int i = 2; i <= pages; i++) { |
| | | contentByte = pdfStamper.getOverContent(i); |
| | | contentByte.beginText(); |
| | | contentByte.setFontAndSize(baseFont, 11); |
| | | float x = contentByte.getPdfDocument().getPageSize().getWidth() / 2; |
| | | float y = 20; |
| | | contentByte.showTextAligned(PdfContentByte.ALIGN_CENTER, String.valueOf(i - 1), x, y, 0); |
| | | contentByte.endText(); |
| | | } |
| | | pdfStamper.close(); |
| | | pdfReader.close(); |
| | | finalOutPut = outputStream; |
| | | } catch (IOException e) { |
| | | e.printStackTrace(); |
| | | return AjaxResult.error(); |
| | | } |
| | | savePDFFile(outputFileName1, tjOrder, customer, finalOutPut); |
| | | TjReport tjReport = new TjReport(); |
| | | String tjNumber = tjOrder.getTjNumber(); |
| | | tjReport.setTjNumber(String.valueOf(tjNumber)); |
| | | tjReport.setPath(urlValue + outputFileName1); |
| | | // 文件配置 |
| | | // String outputPath1 = "/Users/chacca/开发相关/代码/"; |
| | | String outputPath1 = value + "\\"; |
| | | String pdfBinary = getPDFBinary(outputPath1 + outputFileName1); |
| | | tjReport.setReport(pdfBinary); |
| | | tjReport.setType("体检报告"); |
| | | tjReport.setPrint("pdf"); |
| | | tjReportService.save(tjReport); |
| | | LambdaUpdateWrapper<TjOrder> updateWrapper = new LambdaUpdateWrapper<>(); |
| | | updateWrapper.eq(TjOrder::getTjNumber, tjNumber); |
| | | updateWrapper.set(TjOrder::getReportTime, new Date()); |
| | | updateWrapper.set(TjOrder::getPrintLastTime, new Date()); |
| | | updateWrapper.set(TjOrder::getDownloadLastTime, new Date()); |
| | | updateWrapper.set(TjOrder::getStatus, TjConstants.TJ_END); |
| | | tjOrderService.update(updateWrapper); |
| | | return AjaxResult.success(); |
| | | } |
| | | |
| | |
| | | * @param tjOrder |
| | | * @return |
| | | */ |
| | | private List<ByteArrayOutputStream> makeHisJianChaTable(TjOrder tjOrder) { |
| | | private List<ByteArrayOutputStream> makeHisJianChaTable(TjOrder tjOrder) throws Exception { |
| | | LambdaQueryWrapper<LtkjGetexamreportinfo> lambdaQueryWrapper = new LambdaQueryWrapper<>(); |
| | | lambdaQueryWrapper.eq(LtkjGetexamreportinfo::getRequestParamsHisRegistrationId, tjOrder.getCardId()); |
| | | lambdaQueryWrapper.groupBy(LtkjGetexamreportinfo::getJcbgid); |
| | | 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 tjOrder |
| | | * @return |
| | | */ |
| | | private List<ByteArrayOutputStream> makeCcgcHisJianChaTable(TjOrder tjOrder) throws Exception { |
| | | |
| | | TjCustomer customer = tjCustomerService.getById(tjOrder.getUserId()); |
| | | |
| | | List<LtkjExamJcbgd> list=jcbgdService.getJianJcBaoGaoDanByTjh(tjOrder.getCardId()); |
| | | |
| | | List<ByteArrayOutputStream> jianchas = new ArrayList<>(); |
| | | Paragraph elements = new Paragraph(); |
| | | elements.setLeading(5f); |
| | | elements.setSpacingBefore(10f); |
| | | elements.setSpacingAfter(10f); |
| | | elements.setAlignment(Element.ALIGN_RIGHT); |
| | | |
| | | for (LtkjExamJcbgd getexamreportinfo : list) { |
| | | String xm = customer.getCusName(); |
| | | String xb = customer.getCusSex()==2 ? "女" : "男"; |
| | | String nl = customer.getAge(); |
| | | String jcks = "体检中心"; |
| | | String sjks = ""; |
| | | String jcsb = ""; |
| | | String jch = getexamreportinfo.getTmh(); |
| | | String jcxm = getexamreportinfo.getXmmc(); |
| | | String ms = getexamreportinfo.getYxbx(); |
| | | String ts = getexamreportinfo.getYxzd(); |
| | | String bgysqm = getexamreportinfo.getShysxm(); |
| | | String shysqm = getexamreportinfo.getShysdm(); |
| | | String sqrxm = "王健萍"; |
| | | String zyh = ""; |
| | | String ch = ""; |
| | | String jcysqm = getexamreportinfo.getShysdm(); |
| | | StringBuilder builder; |
| | | String footer; |
| | | 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(); |
| | | 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 customer |
| | | * @param finalOutPut |
| | | */ |
| | | private void savePDFFile(String outputFileName1, TjOrder tjOrder, TjCustomer customer, ByteArrayOutputStream finalOutPut) { |
| | | private void savePDFFile(String outputFileName1, TjOrder tjOrder, TjCustomer customer, ByteArrayOutputStream finalOutPut) throws IOException { |
| | | // 文件配置 |
| | | // String outputPath1 = "/Users/chacca/开发相关/代码/"; |
| | | String outputPath1 = value + "\\"; |
| | | File file = new File(outputPath1 + outputFileName1); |
| | | BufferedOutputStream outputStream = null; |
| | | try { |
| | | outputStream = new BufferedOutputStream(new FileOutputStream(file)); |
| | | outputStream.write(finalOutPut.toByteArray()); |
| | | outputStream.flush(); |
| | | outputStream.close(); |
| | | finalOutPut.close(); |
| | | } catch (IOException e) { |
| | | log.error("本地存储pdf异常"); |
| | | e.printStackTrace(); |
| | | } |
| | | outputStream = new BufferedOutputStream(new FileOutputStream(file)); |
| | | outputStream.write(finalOutPut.toByteArray()); |
| | | outputStream.flush(); |
| | | outputStream.close(); |
| | | finalOutPut.close(); |
| | | } |
| | | |
| | | /** |
| | |
| | | * @param map |
| | | * @throws DocumentException |
| | | */ |
| | | private static void makeHisJianYanTable(Document document1, HashMap<String, Object> map) throws DocumentException { |
| | | 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}; |
| | |
| | | HashSet<String> jyys = (HashSet<String>) entryValue.get("jyys"); |
| | | ArrayList<List<String>> lists = (ArrayList<List<String>>) entryValue.get("data"); |
| | | addJianYanTable(document1, titleName, titles, titlesWidth, lists); |
| | | Font doctorFonts = PdfUtils.setFont(9); |
| | | String doctors = ""; |
| | | for (String s : jyys) { |
| | | doctors += s + "、"; |
| | | if (!jyys.isEmpty()) { |
| | | Font doctorFonts = PdfUtils.setFont(9); |
| | | String doctors = ""; |
| | | 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)); |
| | | boolean flag = false; |
| | | for (String s : jyys) { |
| | | if (s.contains("|")) { |
| | | flag = true; |
| | | String[] split = s.split("\\|"); |
| | | String qmImg = dictUserInfoMapper.selectQmImgInnerJoinUserByHisDictCode(split[1]); |
| | | 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(image,0,-10,true)); |
| | | } catch (IOException e) { |
| | | phrase.add(new Chunk(split[0].trim(),doctorFonts)); |
| | | } |
| | | } else { |
| | | phrase.add(new Chunk(split[0].trim(),doctorFonts)); |
| | | } |
| | | } else { |
| | | doctors += s.trim() + "、"; |
| | | } |
| | | } |
| | | if (!flag) { |
| | | String substring = doctors.substring(0, doctors.length() - 1).trim(); |
| | | Paragraph df = PdfUtils.setParagraph(doctorFonts, "审核医师:" + substring); |
| | | df.setAlignment(Element.ALIGN_RIGHT); |
| | | document1.add(df); |
| | | } else { |
| | | elements.add(phrase); |
| | | document1.add(elements); |
| | | } |
| | | } |
| | | String substring = doctors.substring(0, doctors.length() - 1); |
| | | Paragraph df = PdfUtils.setParagraph(doctorFonts, "检验医师:" + substring); |
| | | df.setAlignment(Element.ALIGN_RIGHT); |
| | | document1.add(df); |
| | | //分割线 |
| | | LineSeparator objectName = new LineSeparator(); |
| | | objectName.setOffset(-5); |
| | | document1.add(objectName); |
| | | } |
| | | } |
| | |
| | | String titleName = null; |
| | | if (null != one11 && "1".equals(one11.getResultType())) { |
| | | titleName = one11.getProName(); |
| | | // TODO 单位 |
| | | // 设置标题字体样式 |
| | | Font titleFonts = PdfUtils.setFont(9); |
| | | Paragraph paragraph = PdfUtils.setParagraph(titleFonts, titleName); |
| | |
| | | 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); |
| | | } |
| | | } |
| | | |
| | | public HashMap<String, Object> makeHisJianYan(TjOrder tjOrder, TjCustomer customer) { |
| | | // TODO 这里先使用查全部测试 |
| | | LambdaQueryWrapper<LtkjHysqd> ltkjHysqdLambdaQueryWrapper = new LambdaQueryWrapper<>(); |
| | | ltkjHysqdLambdaQueryWrapper.eq(LtkjHysqd::getTjh, tjOrder.getCardId()); |
| | | List<LtkjHysqd> list = ltkjHysqdService.list(ltkjHysqdLambdaQueryWrapper); |
| | |
| | | HashSet<String> hashSet = new HashSet<>(); |
| | | for (LtkjHybgd hybgd : hybgds) { |
| | | // 检查项目 |
| | | String jcxm = hybgd.getJcxm(); |
| | | String jcxm = hybgd.getJcxm() != null ? hybgd.getJcxm().trim() : null; |
| | | // 检验结果 |
| | | String jyjg = hybgd.getJyjg(); |
| | | String jyjg = hybgd.getJyjg() != null ? hybgd.getJyjg().trim() : null; |
| | | // 结果单位 |
| | | String jgdw = hybgd.getJgdw(); |
| | | String jgdw = hybgd.getJgdw() != null ? hybgd.getJgdw().trim() : null; |
| | | // 范围值 |
| | | String fwz = hybgd.getFwz(); |
| | | String fwz = hybgd.getFwz() != null ? hybgd.getFwz().trim() : null; |
| | | // 检验医师 |
| | | // String jyys = hybgd.getJyys(); |
| | | //审核医生 |
| | | String shysmc = hybgd.getShysmc(); |
| | | String shysmc = hybgd.getShysmc() != null ? hybgd.getShysmc().trim() : null; |
| | | // 审核医师编码 |
| | | String shys = hybgd.getShys() != null ? hybgd.getShys().trim() : null; |
| | | if (jyjg != null && StrUtil.isNotBlank(jyjg) && fwz != null && StrUtil.isNotBlank(fwz)) { |
| | | try { |
| | | String[] fwzs = fwz.split("-"); |
| | |
| | | // List<SysUser> sysUsers = userService.list(queryWrapper); |
| | | // if (!sysUsers.isEmpty()) |
| | | // hashSet.add(sysUsers.get(0).getNickName()); |
| | | if (null != shysmc) hashSet.add(shysmc); |
| | | String key = sysConfigService.selectConfigByKey("is_report_pdf_use_ysqm"); |
| | | if (null != shys && null != shysmc && key.equals("Y")) { |
| | | hashSet.add(shysmc + "|" + shys); |
| | | } else { |
| | | if (null != shysmc) hashSet.add(shysmc); |
| | | } |
| | | ArrayList<String> strings = new ArrayList<>(); |
| | | strings.add(jcxm); |
| | | strings.add(jyjg); |
| | |
| | | } |
| | | } |
| | | |
| | | public Boolean makePDF(String cardId, JSONArray jsonArray, TjOrder tjOrder, TjReportTemplate reportTemplate) { |
| | | String tjNumber = tjOrder.getTjNumber(); |
| | | String template = reportTemplate.getTemplate(); |
| | | LambdaQueryWrapper<TjCustomer> wq1 = new LambdaQueryWrapper<>(); |
| | | wq1.eq(TjCustomer::getCusId, tjOrder.getUserId()); |
| | | TjCustomer tjCustomer = tjCustomerService.getOne(wq1); |
| | | Long userId = tjCustomer.getCusId(); |
| | | LambdaQueryWrapper<DictComp> wq111 = new LambdaQueryWrapper<>(); |
| | | wq111.eq(DictComp::getDrugManufacturerId, tjOrder.getFirmId()); |
| | | DictComp dictComp = dictCompService.getOne(wq111); |
| | | LambdaQueryWrapper<TjOrderDetail> wq2 = new LambdaQueryWrapper<>(); |
| | | wq2.eq(TjOrderDetail::getOrderId, tjOrder.getOrderId()); |
| | | //20230306判断该项目是否退费/缴费 |
| | | wq2.isNotNull(TjOrderDetail::getFlowingWaterId); |
| | | //20230323判断该项目是否弃检/未检 |
| | | // wq2.eq(TjOrderDetail::getTjStatus,1); |
| | | List<TjOrderDetail> list = tjOrderDetailService.list(wq2); |
| | | for (TjOrderDetail tjOrderDetail : list) { |
| | | TjProject tjProject = projectService.selectTjProjectByProId(tjOrderDetail.getProId()); |
| | | tjOrderDetail.setProject(tjProject); |
| | | } |
| | | // 生成pdf |
| | | try { |
| | | ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); |
| | | PdfReader reader = new PdfReader(new ByteArrayInputStream(Base64.getDecoder().decode(template))); |
| | | PdfStamper pdfStamper = new PdfStamper(reader, byteArrayOutputStream); |
| | | // 获取pdf表单 |
| | | AcroFields acroFields = pdfStamper.getAcroFields(); |
| | | BaseFont bf = BaseFont.createFont("STSong-Light", "UniGB-UCS2-H", BaseFont.NOT_EMBEDDED); |
| | | acroFields.addSubstitutionFont(bf); |
| | | HashMap<String, Object> data = new HashMap<>(); |
| | | // 设置用户信息 |
| | | setUserInfo(tjNumber, tjOrder, tjCustomer, data); |
| | | //异常项目 |
| | | if (dictComp == null) { |
| | | data.put("work", "无"); |
| | | } else { |
| | | data.put("work", dictComp.getCnName()); |
| | | } |
| | | //封面页下面的总检建议显示 |
| | | if (tjOrder.getCheckAdvice() == null) { |
| | | data.put("remark", "无"); |
| | | } else { |
| | | data.put("remark", tjOrder.getCheckAdvice()); |
| | | } |
| | | //封面页下面的总检建议显示 |
| | | if (tjOrder.getCheckDoctor() == null) { |
| | | data.put("docname", "无"); |
| | | } else { |
| | | data.put("docname", tjOrder.getCheckDoctor()); |
| | | } |
| | | //拼接重大阳性结果 |
| | | StringBuffer str = new StringBuffer(); |
| | | str.append("【重大阳性项目】\n"); |
| | | LambdaQueryWrapper<TjBigPositive> bigPositiveLambdaQueryWrapper = new LambdaQueryWrapper<>(); |
| | | bigPositiveLambdaQueryWrapper.eq(TjBigPositive::getTjNumber, tjNumber); |
| | | List<TjBigPositive> list1 = tjBigPositiveService.list(bigPositiveLambdaQueryWrapper); |
| | | if (list1 != null && list1.size() > 0) { |
| | | for (int i = 0; i < list1.size(); i++) { |
| | | str.append((i + 1) + "、" + list1.get(i).getProName() + ";\n"); |
| | | } |
| | | } else { |
| | | str.append(" 无;\n"); |
| | | } |
| | | //拼接异常项目 |
| | | str.append("【异常情况项目】\n"); |
| | | if (list.size() > 0) { |
| | | for (int i = 0; i < list.size(); i++) { |
| | | if (list.get(i).getExceptionDesc() == 1) { |
| | | str.append((i + 1) + "、" + projectService.getById(list.get(i).getProId()).getProName() + ";\n"); |
| | | } |
| | | } |
| | | } else { |
| | | str.append(" 无;\n"); |
| | | } |
| | | |
| | | //异常项目 |
| | | data.put("yichang", str.toString()); |
| | | // 遍历data 给pdf表单表格赋值 |
| | | for (String key : data.keySet()) { |
| | | acroFields.setField(key, data.get(key).toString()); |
| | | } |
| | | //设置为无法编辑 |
| | | pdfStamper.setFormFlattening(true); |
| | | pdfStamper.close(); |
| | | reader.close(); |
| | | // 将修改后的PDF内容写入 |
| | | byte[] bytes = byteArrayOutputStream.toByteArray(); |
| | | // 创建新的PDF文档 |
| | | Document document = new Document(PageSize.A4); |
| | | ByteArrayOutputStream finalOutPut = new ByteArrayOutputStream(); |
| | | PdfCopy copy = new PdfCopy(document, finalOutPut); |
| | | document.open(); |
| | | reader = new PdfReader(bytes); |
| | | int numberOfPages = reader.getNumberOfPages(); |
| | | for (int i = 1; i <= numberOfPages; i++) { |
| | | PdfImportedPage page = copy.getImportedPage(reader, i); |
| | | copy.addPage(page); |
| | | } |
| | | // 添加详情页 |
| | | document.newPage(); |
| | | ByteArrayOutputStream byteArrayOutputStream1 = new ByteArrayOutputStream(); |
| | | Document document1 = new Document(PageSize.A4); |
| | | PdfWriter pdfWriter = PdfWriter.getInstance(document1, byteArrayOutputStream1); |
| | | document1.setMargins(70, 70, 40, 40); |
| | | document1.open(); |
| | | // 非化验项目报告 |
| | | Map<TjOrderRemark, List<TjPdfVO>> printReport = new HashMap<>(); |
| | | notHuaYanData(tjNumber, printReport, tjOrder, tjCustomer); |
| | | for (Map.Entry<TjOrderRemark, List<TjPdfVO>> entry : printReport.entrySet()) { |
| | | List<TjPdfVO> value = entry.getValue(); |
| | | LambdaQueryWrapper<TjProject> wqqq = new LambdaQueryWrapper<>(); |
| | | wqqq.eq(TjProject::getProId, entry.getKey().getProId()); |
| | | TjProject one11 = projectService.getOne(wqqq); |
| | | //判断该项目是否需要打印报告 |
| | | if (null != one11 && "N".equals(one11.getNeedReport())) { |
| | | continue; |
| | | } |
| | | String titleName = null; |
| | | if (null != one11 && "1".equals(one11.getResultType())) { |
| | | titleName = one11.getProName(); |
| | | // TODO 单位 |
| | | // 设置标题字体样式 |
| | | Font titleFonts = PdfUtils.setFont(9); |
| | | Paragraph paragraph = PdfUtils.setParagraph(titleFonts, titleName); |
| | | String[] titles = {"体检项目", "体检结果", "单位"}; |
| | | // 获取列表数据 |
| | | //设置表头字体样式 |
| | | Font headFont = PdfUtils.setFont(9); |
| | | // 设置正文字体样式:12号 |
| | | Font textFont = PdfUtils.setFont(9); |
| | | //创建表格 将表头字体和正文字体放进去 |
| | | PdfPTable table = PdfUtils.setTable2(headFont, textFont, titles, value); |
| | | document1.add(paragraph); |
| | | document1.add(table); |
| | | //判断备注是否为空 空不能显示null |
| | | if (entry.getKey().getRemark() == null) { |
| | | entry.getKey().setRemark(""); |
| | | } |
| | | String remark = "备注:" + entry.getKey().getRemark(); |
| | | if (entry.getKey().getRemark().length() > 50) { |
| | | int j = 0; |
| | | for (int i = 0; i < remark.length() / 50; i++) { |
| | | String substring = remark.substring(j, j + 50); |
| | | Font remarkFonts = PdfUtils.setFont(9); |
| | | Paragraph pp = PdfUtils.setParagraph(remarkFonts, substring); |
| | | document1.add(pp); |
| | | j = j + 50; |
| | | } |
| | | if (remark.length() % 50 != 0) { |
| | | String substring = remark.substring((remark.length() / 50) * 50, remark.length() - 1); |
| | | Font remarkFonts = PdfUtils.setFont(9); |
| | | Paragraph pp = PdfUtils.setParagraph(remarkFonts, substring); |
| | | document1.add(pp); |
| | | } |
| | | } else { |
| | | Font remarkFonts = PdfUtils.setFont(9); |
| | | Paragraph pp = PdfUtils.setParagraph(remarkFonts, remark); |
| | | 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); |
| | | } |
| | | //分割线 |
| | | LineSeparator objectName = new LineSeparator(); |
| | | document1.add(objectName); |
| | | } else { |
| | | if (null != one11) { |
| | | titleName = one11.getProName(); |
| | | } else { |
| | | titleName = entry.getKey().getProName(); |
| | | } |
| | | // 设置标题字体样式 |
| | | Font titleFonts = PdfUtils.setFont(9); |
| | | Paragraph paragraph = PdfUtils.setParagraph(titleFonts, titleName); |
| | | String[] titles = {"体检项目", "体检结果", "单位", "参考范围"}; |
| | | // 获取列表数据 |
| | | //设置表头字体样式 |
| | | Font headFont = PdfUtils.setFont(9); |
| | | // 设置正文字体样式:12号 |
| | | Font textFont = PdfUtils.setFont(9); |
| | | //创建表格 将表头字体和正文字体放进去 |
| | | PdfPTable table = PdfUtils.setTable(headFont, textFont, titles, value); |
| | | document1.add(paragraph); |
| | | document1.add(table); |
| | | //判断备注是否为空 空不能显示null |
| | | if (entry.getKey().getRemark() == null) { |
| | | entry.getKey().setRemark(""); |
| | | } |
| | | String remark = "备注:" + entry.getKey().getRemark(); |
| | | if (entry.getKey().getRemark().length() > 50) { |
| | | int j = 0; |
| | | for (int i = 0; i < remark.length() / 50; i++) { |
| | | String substring = remark.substring(j, j + 50); |
| | | Font remarkFonts = PdfUtils.setFont(9); |
| | | Paragraph pp = PdfUtils.setParagraph(remarkFonts, substring); |
| | | document1.add(pp); |
| | | j = j + 50; |
| | | } |
| | | if (remark.length() % 50 != 0) { |
| | | String substring = remark.substring((remark.length() / 50) * 50, remark.length() - 1); |
| | | Font remarkFonts = PdfUtils.setFont(9); |
| | | Paragraph pp = PdfUtils.setParagraph(remarkFonts, substring); |
| | | document1.add(pp); |
| | | } |
| | | } else { |
| | | Font remarkFonts = PdfUtils.setFont(9); |
| | | Paragraph pp = PdfUtils.setParagraph(remarkFonts, remark); |
| | | 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); |
| | | } |
| | | //分割线 |
| | | LineSeparator objectName = new LineSeparator(); |
| | | document1.add(objectName); |
| | | } |
| | | } |
| | | List<ByteArrayOutputStream> jianchas = new ArrayList<>(); |
| | | for (Object o : jsonArray) { |
| | | JSONObject jsonObject = (JSONObject) o; |
| | | // 检验报告以及结果信息 |
| | | JSONObject reportInfo = jsonObject.getJSONObject("报告记录"); |
| | | String titleName = ""; |
| | | if (reportInfo != null) { |
| | | titleName = reportInfo.getStr("JYXMMC").trim(); |
| | | } |
| | | JSONArray reportDetails = jsonObject.getJSONArray("检验结果记录"); |
| | | ArrayList<TjPdfVO> listPdf = new ArrayList<>(); |
| | | String[] titles = null; |
| | | float[] titlesWidth = null; |
| | | // 结果信息 |
| | | if (reportDetails != null && reportDetails.size() > 0) { |
| | | for (Object reportDetail : reportDetails) { |
| | | JSONObject detail = (JSONObject) reportDetail; |
| | | TjPdfVO tjPdfVO = new TjPdfVO(); |
| | | tjPdfVO.setProName(detail.getStr("JCZBMC")); |
| | | tjPdfVO.setProResult(detail.getStr("JCZBJG")); |
| | | tjPdfVO.setVal1(detail.getStr("JLDW")); |
| | | tjPdfVO.setVal2(detail.getStr("CKZFW")); |
| | | listPdf.add(tjPdfVO); |
| | | } |
| | | titles = new String[]{"体检项目", "体检结果", "单位", "参考范围"}; |
| | | titlesWidth = new float[]{120, 120, 120, 120}; |
| | | addTable(document1, titleName, titles, titlesWidth, listPdf); |
| | | // 主检医师 |
| | | String bgysqm = reportInfo.getStr("BGYSQM"); |
| | | String doctorName = "主检医师:" + bgysqm; |
| | | Font doctorFonts = PdfUtils.setFont(9); |
| | | Paragraph df = PdfUtils.setParagraph(doctorFonts, doctorName); |
| | | df.setAlignment(Element.ALIGN_RIGHT); |
| | | document1.add(df); |
| | | //分割线 |
| | | LineSeparator objectName = new LineSeparator(); |
| | | document1.add(objectName); |
| | | } |
| | | // 微生物报告记录信息 |
| | | JSONArray labgermrepInfos = jsonObject.getJSONArray("微生物报告记录"); |
| | | if (labgermrepInfos != null && labgermrepInfos.size() > 0) { |
| | | listPdf = new ArrayList<>(); |
| | | for (Object info : labgermrepInfos) { |
| | | JSONObject object = (JSONObject) info; |
| | | TjPdfVO tjPdfVO = new TjPdfVO(); |
| | | tjPdfVO.setProName(object.getStr("XJMC")); |
| | | tjPdfVO.setProResult(object.getStr("JCJG")); |
| | | listPdf.add(tjPdfVO); |
| | | } |
| | | titles = new String[]{"体检项目", "体检结果"}; |
| | | titlesWidth = new float[]{120, 120}; |
| | | addTable(document1, titleName, titles, titlesWidth, listPdf); |
| | | //分割线 |
| | | LineSeparator objectName = new LineSeparator(); |
| | | document1.add(objectName); |
| | | } |
| | | // 微生物药敏信息 |
| | | JSONArray labgermdetailinfos = jsonObject.getJSONArray("微生物药敏信息"); |
| | | if (labgermdetailinfos != null && labgermdetailinfos.size() > 0) { |
| | | listPdf = new ArrayList<>(); |
| | | for (Object info : labgermdetailinfos) { |
| | | JSONObject object = (JSONObject) info; |
| | | TjPdfVO tjPdfVO = new TjPdfVO(); |
| | | tjPdfVO.setProName(object.getStr("YMMC")); |
| | | tjPdfVO.setProResult(object.getStr("JCJG")); |
| | | tjPdfVO.setVal1(object.getStr("ZPHYL")); |
| | | tjPdfVO.setVal2(object.getStr("YJND")); |
| | | tjPdfVO.setVal3(object.getStr("YJHZJ")); |
| | | listPdf.add(tjPdfVO); |
| | | } |
| | | titles = new String[]{"药敏名称", "检查结果", "纸片含药量", "抑菌浓度", "抑菌环直径"}; |
| | | titlesWidth = new float[]{90, 90, 90, 90, 90}; |
| | | addTable(document1, titleName, titles, titlesWidth, listPdf); |
| | | //分割线 |
| | | LineSeparator objectName = new LineSeparator(); |
| | | document1.add(objectName); |
| | | } |
| | | // 危急值信息 |
| | | JSONArray laburgentinfos = jsonObject.getJSONArray("危机值信息"); |
| | | if (laburgentinfos != null && laburgentinfos.size() > 0) { |
| | | listPdf = new ArrayList<>(); |
| | | for (Object info : laburgentinfos) { |
| | | JSONObject object = (JSONObject) info; |
| | | TjPdfVO tjPdfVO = new TjPdfVO(); |
| | | tjPdfVO.setProName(object.getStr("zbmc")); |
| | | tjPdfVO.setProResult(object.getStr("jg")); |
| | | tjPdfVO.setVal1(object.getStr("clfs")); |
| | | tjPdfVO.setVal2(object.getStr("bgcljg")); |
| | | listPdf.add(tjPdfVO); |
| | | } |
| | | titles = new String[]{"指标名称", "危急值结果", "处理方式", "处理意见"}; |
| | | titlesWidth = new float[]{120, 120, 120, 120}; |
| | | addTable(document1, titleName, titles, titlesWidth, listPdf); |
| | | //分割线 |
| | | LineSeparator objectName = new LineSeparator(); |
| | | document1.add(objectName); |
| | | } |
| | | JSONArray object = jsonObject.getJSONArray("检查报告"); |
| | | if (object != null && object.size() > 0) { |
| | | for (Object info : object) { |
| | | JSONObject obj = (JSONObject) info; |
| | | String xm = obj.getStr("HZXM"); |
| | | String xb = obj.getStr("HZXB").equals("2") ? "女" : "男"; |
| | | String nl = obj.getStr("HZNL"); |
| | | if (StrUtil.isNotBlank(nl) && nl.contains(".")) { |
| | | String[] split = nl.split("\\."); |
| | | nl = split[0]; |
| | | } |
| | | String jcks = obj.getStr("JCKSMC"); |
| | | String zyh = ""; |
| | | String sqks = obj.getStr("SQKSMC"); |
| | | String sjks = obj.getStr("ZDJGMC"); |
| | | String jcsb = obj.getStr("SBBM"); |
| | | String jch = obj.getStr("JCH"); |
| | | String jcxm = obj.getStr("JCXMMC"); |
| | | String ms = obj.getStr("YXBX"); |
| | | String ts = obj.getStr("YXZD"); |
| | | String ch = obj.getStr("BZBCH"); |
| | | // 报告医师签名 |
| | | String bgysqm = obj.getStr("BGYSQM"); |
| | | // 审核医师签名 |
| | | String shysqm = obj.getStr("SHYSQM"); |
| | | // 申请人 |
| | | String sqrxm = obj.getStr("SQRXM"); |
| | | String footer = "申请人:" + sqrxm + " 审核医师:" + shysqm + " " + bgysqm; |
| | | ByteArrayOutputStream outputStream = makeJcPDFByteArrayStream(xm, xb, nl, jcks, zyh, ch, sjks, jcsb, jch, jcxm, ms, ts, null, footer); |
| | | jianchas.add(outputStream); |
| | | } |
| | | } |
| | | } |
| | | document1.close(); |
| | | pdfWriter.close(); |
| | | reader = new PdfReader(byteArrayOutputStream1.toByteArray()); |
| | | int numberOfPages1 = reader.getNumberOfPages(); |
| | | for (int i = 1; i <= numberOfPages1; i++) { |
| | | PdfImportedPage page = copy.getImportedPage(reader, i); |
| | | copy.addPage(page); |
| | | } |
| | | for (ByteArrayOutputStream jiancha : jianchas) { |
| | | reader = new PdfReader(jiancha.toByteArray()); |
| | | numberOfPages1 = reader.getNumberOfPages(); |
| | | for (int i = 1; i <= numberOfPages1; i++) { |
| | | PdfImportedPage page = copy.getImportedPage(reader, i); |
| | | copy.addPage(page); |
| | | } |
| | | jiancha.close(); |
| | | } |
| | | byteArrayOutputStream1.close(); |
| | | document.close(); |
| | | copy.close(); |
| | | reader.close(); |
| | | String outputFileName1 = userId + tjNumber + tjCustomer.getCusName() + "_报告.pdf"; |
| | | // 文件配置 |
| | | // String outputPath1 = "/Users/chacca/开发相关/代码/"; |
| | | String outputPath1 = value + "\\"; |
| | | File file = new File(outputPath1 + outputFileName1); |
| | | BufferedOutputStream outputStream = new BufferedOutputStream(new FileOutputStream(file)); |
| | | outputStream.write(finalOutPut.toByteArray()); |
| | | outputStream.flush(); |
| | | outputStream.close(); |
| | | finalOutPut.close(); |
| | | reader.close(); |
| | | // 保存数据 |
| | | TjReport tjReport = new TjReport(); |
| | | tjReport.setTjNumber(String.valueOf(tjNumber)); |
| | | tjReport.setPath(urlValue + outputFileName1); |
| | | String pdfBinary = getPDFBinary(outputPath1 + outputFileName1); |
| | | tjReport.setReport(pdfBinary); |
| | | tjReport.setType("体检报告"); |
| | | tjReport.setPrint("pdf"); |
| | | tjReportService.save(tjReport); |
| | | //修改order表中的打印报告时间为当前时间 |
| | | LambdaUpdateWrapper<TjOrder> updateWrapper = new LambdaUpdateWrapper<>(); |
| | | updateWrapper.eq(TjOrder::getTjNumber, tjNumber); |
| | | updateWrapper.set(TjOrder::getReportTime, new Date()); |
| | | updateWrapper.set(TjOrder::getPrintLastTime, new Date()); |
| | | updateWrapper.set(TjOrder::getDownloadLastTime, new Date()); |
| | | updateWrapper.set(TjOrder::getStatus, TjConstants.TJ_END); |
| | | tjOrderService.update(updateWrapper); |
| | | } catch (IOException | DocumentException e) { |
| | | e.printStackTrace(); |
| | | return false; |
| | | } |
| | | return true; |
| | | } |
| | | |
| | | /** |
| | | * 组合非化验项目报告数据 |
| | | * |
| | |
| | | if (null != tjProject && tjProject.getNeedReport().equals("Y")) { |
| | | tjOrderDetail.setProject(tjProject); |
| | | |
| | | if (tjOrderDetail.getProject().getProParentId().equals(entry.getKey().getProId())) { |
| | | TjPdfVO tjPdfVO = new TjPdfVO(); |
| | | tjPdfVO.setProName(tjOrderDetail.getProject().getProName()); |
| | | tjPdfVO.setProResult(tjOrderDetail.getProResult()); |
| | | tjPdfVO.setExc(tjOrderDetail.getExceptionDesc()); |
| | | if(null !=tjProject.getProMetering()){ |
| | | tjPdfVO.setCompany(tjProject.getProMetering()); |
| | | }else { |
| | | tjPdfVO.setCompany("/"); |
| | | if (tjOrderDetail.getProject().getProParentId().equals(entry.getKey().getProId())) { |
| | | TjPdfVO tjPdfVO = new TjPdfVO(); |
| | | tjPdfVO.setProName(tjOrderDetail.getProject().getProName()); |
| | | tjPdfVO.setProResult(tjOrderDetail.getProResult()); |
| | | tjPdfVO.setExc(tjOrderDetail.getExceptionDesc()); |
| | | if (null != tjProject.getProMetering()) { |
| | | tjPdfVO.setCompany(tjProject.getProMetering()); |
| | | } else { |
| | | tjPdfVO.setCompany("/"); |
| | | } |
| | | tjPdfVOS.add(tjPdfVO); |
| | | } |
| | | tjPdfVOS.add(tjPdfVO); |
| | | } |
| | | } |
| | | } |
| | | printReport.put(entry.getKey(), tjPdfVOS); |
| | |
| | | * @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); |
| | | |
| | |
| | | return baos; |
| | | } catch (DocumentException | IOException e) { |
| | | e.printStackTrace(); |
| | | return null; |
| | | } |
| | | return null; |
| | | } |
| | | |
| | | private static PdfPCell createImageCell(String path) throws IOException, BadElementException { |
| | |
| | | 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)); |
| | | |
| | | footer.writeSelectedRows(0, -1, 36, 36, writer.getDirectContent()); |
| | | if (footerText != null) |
| | | footer.addCell(new Phrase(footerText, footerFont)); |
| | | if (paragraph != null) |
| | | footer.addCell(paragraph); |
| | | footer.writeSelectedRows(0, -1, 36, 50, writer.getDirectContent()); |
| | | } |
| | | } |
| | | } |