DigitalReceiptService.java 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540
  1. package thyyxxk.simzfeeoprnsystm.service;
  2. import com.alibaba.fastjson.JSONArray;
  3. import com.alibaba.fastjson.JSONObject;
  4. import com.itextpdf.text.Font;
  5. import lombok.extern.slf4j.Slf4j;
  6. import org.springframework.beans.factory.annotation.Autowired;
  7. import org.springframework.stereotype.Service;
  8. import org.springframework.web.client.RestTemplate;
  9. import thyyxxk.simzfeeoprnsystm.config.MedinsurConfig;
  10. import thyyxxk.simzfeeoprnsystm.dao.RxDao;
  11. import thyyxxk.simzfeeoprnsystm.dicts.SiFunction;
  12. import thyyxxk.simzfeeoprnsystm.pojo.CodeName;
  13. import thyyxxk.simzfeeoprnsystm.pojo.ResultVo;
  14. import thyyxxk.simzfeeoprnsystm.pojo.digitalreceipt.*;
  15. import thyyxxk.simzfeeoprnsystm.pojo.digitalreceipt.request.*;
  16. import thyyxxk.simzfeeoprnsystm.pojo.digitalreceipt.response.RxMedicine;
  17. import thyyxxk.simzfeeoprnsystm.utils.*;
  18. import thyyxxk.simzfeeoprnsystm.utils.rxsign.HseEncAndDecUtil;
  19. import com.itextpdf.text.*;
  20. import com.itextpdf.text.pdf.*;
  21. import com.itextpdf.text.pdf.draw.LineSeparator;
  22. import java.io.File;
  23. import java.io.IOException;
  24. import java.io.OutputStream;
  25. import java.nio.file.Files;
  26. import java.util.*;
  27. import java.util.List;
  28. @Slf4j
  29. @Service
  30. public class DigitalReceiptService {
  31. private final ExecService exec;
  32. private final RxDao rxDao;
  33. private final RestTemplate template;
  34. private final MedinsurConfig cfg;
  35. // 处方流转正式地址
  36. // private final static String cflzUrl = "http://130.150.161.72:8079/cflz";
  37. // private final static String ypcxUrl = "http://130.150.161.72:8079/cflzYpCx";
  38. // private final static String drCxUrl = "http://130.150.161.72:8079/drCx";
  39. // 处方流转测试地址
  40. private final static String cflzUrl = "http://130.150.161.72:8079/testCflz";
  41. private final static String ypcxUrl = "http://130.150.161.72:8079/testCflzYpCx";
  42. private final static String drcxUrl = "http://130.150.161.72:8079/testDrCx";
  43. @Autowired
  44. public DigitalReceiptService(ExecService exec, RxDao rxDao, RestTemplate template, MedinsurConfig cfg) {
  45. this.exec = exec;
  46. this.rxDao = rxDao;
  47. this.template = template;
  48. this.cfg = cfg;
  49. }
  50. public ResultVo<JSONObject> drInquiry() throws Exception {
  51. JSONObject data = new JSONObject();
  52. data.put("fixmedinsCode", cfg.getHospId());
  53. data.put("mdtrtareaAdmvs", cfg.getHospArea());
  54. JSONObject input = HseEncAndDecUtil.encryptMsg(data);
  55. log.info("查询定点医师信息明文:{}", data);
  56. JSONObject result = template.postForObject(drcxUrl, input, JSONObject.class);
  57. if (null == result) {
  58. return ResultVoUtil.fail(ExceptionEnum.NETWORK_ERROR);
  59. }
  60. Integer code = result.getInteger("code");
  61. if (null == code || code != 0){
  62. return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, result.getString("message"));
  63. }
  64. JSONObject decryptResult = HseEncAndDecUtil.decryptMsg(result);
  65. return ResultVoUtil.success(decryptResult);
  66. }
  67. public ResultVo<JSONObject> medicineInquiry(MedicineInquiry inquiry) throws Exception {
  68. if (inquiry.needSaving()) {
  69. if (inquiry.getPageNum() == 1) {
  70. rxDao.truncateTable();
  71. } else {
  72. rxDao.deleteByPageNo(inquiry.getPageNum());
  73. }
  74. }
  75. return executeQuery(inquiry);
  76. }
  77. private ResultVo<JSONObject> executeQuery(MedicineInquiry inquiry) throws Exception {
  78. String dataRef = JSONObject.toJSONString(inquiry);
  79. JSONObject data = JSONObject.parseObject(dataRef);
  80. log.info("电子处方药品查询页码:{}", inquiry.getPageNum());
  81. JSONObject input = HseEncAndDecUtil.encryptMsg(data);
  82. JSONObject result = template.postForObject(ypcxUrl, input, JSONObject.class);
  83. log.info("电子处方药品查询结果:{}", result);
  84. if (null == result) {
  85. return ResultVoUtil.fail(ExceptionEnum.NETWORK_ERROR);
  86. }
  87. Integer code = result.getInteger("code");
  88. if (null == code || code != 0){
  89. return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, result.getString("message"));
  90. }
  91. JSONObject decryptResult = HseEncAndDecUtil.decryptMsg(result);
  92. Integer size = decryptResult.getInteger("size");
  93. if (null == size || 0 == size) {
  94. decryptResult.put("size", 0);
  95. }
  96. if (inquiry.needSaving()) {
  97. JSONArray list = decryptResult.getJSONArray("list");
  98. try {
  99. batchInsert(list, inquiry.getPageNum());
  100. } catch (Exception e) {
  101. log.info(list.toJSONString());
  102. throw new Exception(e);
  103. }
  104. if (!inquiry.onlyCurrentPage()) {
  105. Integer nextPage = decryptResult.getInteger("nextPage");
  106. if (null != nextPage && nextPage > inquiry.getPageNum()) {
  107. inquiry.setPageNum(nextPage);
  108. executeQuery(inquiry);
  109. }
  110. }
  111. decryptResult.remove("list");
  112. }
  113. return ResultVoUtil.success(decryptResult);
  114. }
  115. private void batchInsert(JSONArray array, int pageNo) {
  116. if (null == array || array.isEmpty()) {
  117. return;
  118. }
  119. List<RxMedicine> list = new ArrayList<>();
  120. for (int i = 0; i < array.size(); i++) {
  121. JSONObject item = array.getJSONObject(i);
  122. RxMedicine medicine = JSONObject.parseObject(item.toJSONString(), RxMedicine.class);
  123. medicine.setId(UUID.randomUUID().toString().replaceAll("-", ""));
  124. medicine.setPyCode(PingYinUtil.getPinYinHeadChar(medicine.getRegName()));
  125. medicine.setPageNo(pageNo);
  126. list.add(medicine);
  127. if (list.size() == 50) {
  128. rxDao.batchInsertRxMedicine(list);
  129. list.clear();
  130. }
  131. }
  132. if (!list.isEmpty()) {
  133. rxDao.batchInsertRxMedicine(list);
  134. }
  135. }
  136. public ResultVo<JSONObject> rxPreCheck(RxPreCheckRequest request) throws Exception {
  137. CodeName phar = rxDao.getDocYbCode(request.getStaffId());
  138. if (null == phar || StringUtil.isBlank(phar.getYbCode())) {
  139. return ResultVoUtil.fail(ExceptionEnum.NULL_POINTER, "审方药师医保编码不能为空。");
  140. }
  141. request.getRxMdtrtinfo().setPrscDrCertType("01");
  142. request.getRxMdtrtinfo().setPrscDrCertno("320823197007280258");
  143. String dataRef = JSONObject.toJSONStringWithDateFormat(request.getRxPreCheck(), "yyyy-MM-dd HH:mm:ss");
  144. JSONObject data = JSONObject.parseObject(dataRef);
  145. String rxdrugdetailRef = JSONArray.toJSONStringWithDateFormat(request.getRxDrugDetailList(), "yyyy-MM-dd HH:mm:ss");
  146. data.put("rxdrugdetail", JSONArray.parseArray(rxdrugdetailRef));
  147. String mdtrtinfoRef = JSONObject.toJSONStringWithDateFormat(request.getRxMdtrtinfo(), "yyyy-MM-dd HH:mm:ss");
  148. data.put("mdtrtinfo", JSONObject.parseObject(mdtrtinfoRef));
  149. String diseinfoRef = JSONArray.toJSONStringWithDateFormat(request.getRxDiseInfoList(), "yyyy-MM-dd HH:mm:ss");
  150. data.put("diseinfo", JSONArray.parseArray(diseinfoRef));
  151. log.info("明文:{}", data);
  152. JSONObject input = HseEncAndDecUtil.encryptMsg(data);
  153. JSONObject result = template.postForObject(cflzUrl + "/uploadChk", input, JSONObject.class);
  154. log.info("电子处方上传预核验:\n参数:{},\n结果:{}", input, result);
  155. if (null == result) {
  156. return ResultVoUtil.fail(ExceptionEnum.NETWORK_ERROR);
  157. }
  158. Integer code = result.getInteger("code");
  159. if (null == code || code != 0){
  160. return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, result.getString("message"));
  161. }
  162. JSONObject decryptResult = HseEncAndDecUtil.decryptMsg(result);
  163. RxUpload rxUpload = new RxUpload();
  164. rxUpload.setHiRxno(decryptResult.getString("hiRxno"));
  165. rxUpload.setRxTraceCode(decryptResult.getString("rxTraceCode"));
  166. rxUpload.setHospRxno(request.getHospRxno());
  167. rxUpload.setMdtrtId(request.getRxMdtrtinfo().getMdtrtId());
  168. rxUpload.setPatnName(request.getRxMdtrtinfo().getPatnName());
  169. rxUpload.setPsnCertType(request.getRxMdtrtinfo().getPsnCertType());
  170. rxUpload.setCertno(request.getRxMdtrtinfo().getCertno());
  171. rxUpload.setDrCode(request.getRxMdtrtinfo().getDrCode());
  172. rxUpload.setPrscDrName(request.getRxMdtrtinfo().getPrscDrName());
  173. rxUpload.setPharDeptCode(request.getRxMdtrtinfo().getPrscDeptCode());
  174. rxUpload.setPharDeptName(request.getRxMdtrtinfo().getPrscDeptName());
  175. rxUpload.setPharCode(phar.getYbCode());
  176. rxUpload.setPharName(phar.getName());
  177. rxUpload.setRxFile(createRxPdf(request));
  178. rxUpload.setPharChkTime(new Date());
  179. int d = rxDao.deleteOldRxPreCheck(request.getHospRxno());
  180. int i = rxDao.insertRxPrecheck(rxUpload);
  181. log.info("电子处方预核验入库:删除:{},新增:{}", d, i);
  182. deleteRxPdfFile(request);
  183. return ResultVoUtil.success(decryptResult);
  184. }
  185. public ResultVo<JSONObject> rxSign(RxSignRequest request) throws Exception {
  186. String dataRef = JSONObject.toJSONStringWithDateFormat(request.getRxSign(), "yyyy-MM-dd HH:mm:ss");
  187. JSONObject data = JSONObject.parseObject(dataRef);
  188. log.info("明文:{}", data);
  189. JSONObject input = HseEncAndDecUtil.encryptMsg(data);
  190. JSONObject result = template.postForObject(cflzUrl + "/rxFixmedinsSign", input, JSONObject.class);
  191. log.info("电子处方医保电子签名:\n参数:{},\n结果:{}", input, result);
  192. if (null == result) {
  193. return ResultVoUtil.fail(ExceptionEnum.NETWORK_ERROR);
  194. }
  195. Integer code = result.getInteger("code");
  196. if (null == code || code != 0){
  197. return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, result.getString("message"));
  198. }
  199. JSONObject decryptResult = HseEncAndDecUtil.decryptMsg(result);
  200. String signDigest = decryptResult.getString("signDigest");
  201. String rxFile = decryptResult.getString("rxFile");
  202. rxDao.updateSignDigest(request.getHospRxno(), signDigest, rxFile);
  203. return ResultVoUtil.success(decryptResult);
  204. }
  205. public ResultVo<JSONObject> rxUpload(RxUploadRequest request) throws Exception {
  206. String dataRef = JSONObject.toJSONStringWithDateFormat(request.getRxUpload(), "yyyy-MM-dd HH:mm:ss");
  207. JSONObject data = JSONObject.parseObject(dataRef);
  208. log.info("明文:{}", data);
  209. JSONObject input = HseEncAndDecUtil.encryptMsg(data);
  210. JSONObject result = template.postForObject(cflzUrl + "/rxFileUpld", input, JSONObject.class);
  211. log.info("电子处方上传:\n参数:{},\n结果:{}", input, result);
  212. if (null == result) {
  213. return ResultVoUtil.fail(ExceptionEnum.NETWORK_ERROR);
  214. }
  215. Integer code = result.getInteger("code");
  216. if (null == code || code != 0){
  217. return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, result.getString("message"));
  218. }
  219. JSONObject decryptResult = HseEncAndDecUtil.decryptMsg(result);
  220. String hiRxno = decryptResult.getString("hiRxno");
  221. rxDao.updateRxState(hiRxno, RxState.UPLOADED);
  222. return ResultVoUtil.success(decryptResult);
  223. }
  224. public ResultVo<JSONObject> rxRevoke(RxRevokeRequest request) throws Exception {
  225. String dataRef = JSONObject.toJSONStringWithDateFormat(request.getRxRevoke(), "yyyy-MM-dd HH:mm:ss");
  226. JSONObject data = JSONObject.parseObject(dataRef);
  227. log.info("明文:{}", data);
  228. JSONObject input = HseEncAndDecUtil.encryptMsg(data);
  229. JSONObject result = template.postForObject(cflzUrl + "/rxUndo", input, JSONObject.class);
  230. log.info("电子处方撤销:\n参数:{},\n结果:{}", input, result);
  231. if (null == result) {
  232. return ResultVoUtil.fail(ExceptionEnum.NETWORK_ERROR);
  233. }
  234. Integer code = result.getInteger("code");
  235. if (null == code || code != 0){
  236. return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, result.getString("message"));
  237. }
  238. JSONObject decryptResult = HseEncAndDecUtil.decryptMsg(result);
  239. String hiRxno = decryptResult.getString("hiRxno");
  240. rxDao.updateRxState(hiRxno, RxState.REVOKED);
  241. return ResultVoUtil.success(decryptResult);
  242. }
  243. public ResultVo<JSONObject> rxInfoQuery(RxInfoQueryRequest request) throws Exception {
  244. String dataRef = JSONObject.toJSONStringWithDateFormat(request.getRxInfoQuery(), "yyyy-MM-dd HH:mm:ss");
  245. JSONObject data = JSONObject.parseObject(dataRef);
  246. log.info("明文:{}", data);
  247. JSONObject input = HseEncAndDecUtil.encryptMsg(data);
  248. JSONObject result = template.postForObject(cflzUrl + "/hospRxDetlQuery", input, JSONObject.class);
  249. log.info("电子处方信息查询:\n参数:{},\n结果:{}", input, result);
  250. if (null == result) {
  251. return ResultVoUtil.fail(ExceptionEnum.NETWORK_ERROR);
  252. }
  253. Integer code = result.getInteger("code");
  254. if (null == code || code != 0){
  255. return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, result.getString("message"));
  256. }
  257. return ResultVoUtil.success(HseEncAndDecUtil.decryptMsg(result));
  258. }
  259. public ResultVo<JSONObject> rxAuditingQuery(RxAuditingQueryRequest request) throws Exception {
  260. String dataRef = JSONObject.toJSONStringWithDateFormat(request.getRxAuditingQuery(), "yyyy-MM-dd HH:mm:ss");
  261. JSONObject data = JSONObject.parseObject(dataRef);
  262. log.info("明文:{}", data);
  263. JSONObject input = HseEncAndDecUtil.encryptMsg(data);
  264. JSONObject result = template.postForObject(cflzUrl + "/rxChkInfoQuery", input, JSONObject.class);
  265. log.info("电子处方审核结果查询:\n参数:{},\n结果:{}", input, result);
  266. if (null == result) {
  267. return ResultVoUtil.fail(ExceptionEnum.NETWORK_ERROR);
  268. }
  269. Integer code = result.getInteger("code");
  270. if (null == code || code != 0){
  271. return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, result.getString("message"));
  272. }
  273. return ResultVoUtil.success(HseEncAndDecUtil.decryptMsg(result));
  274. }
  275. public ResultVo<JSONObject> rxSetlQuery(RxSetlQueryRequest request) throws Exception {
  276. String dataRef = JSONObject.toJSONStringWithDateFormat(request.getRxSetlQuery(), "yyyy-MM-dd HH:mm:ss");
  277. JSONObject data = JSONObject.parseObject(dataRef);
  278. log.info("明文:{}", data);
  279. JSONObject input = HseEncAndDecUtil.encryptMsg(data);
  280. JSONObject result = template.postForObject(cflzUrl + "/rxSetlInfoQuery", input, JSONObject.class);
  281. log.info("电子处方取药结果查询:\n参数:{},\n结果:{}", input, result);
  282. if (null == result) {
  283. return ResultVoUtil.fail(ExceptionEnum.NETWORK_ERROR);
  284. }
  285. Integer code = result.getInteger("code");
  286. if (null == code || code != 0){
  287. return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, result.getString("message"));
  288. }
  289. return ResultVoUtil.success(HseEncAndDecUtil.decryptMsg(result));
  290. }
  291. public String createRxPdf(RxPreCheckRequest request) throws Exception {
  292. String pdfFilePath = Global.FILE_PATH + request.getHospRxno() + ".pdf";
  293. File pdfFile = new File(pdfFilePath);
  294. if (pdfFile.exists()) {
  295. pdfFile.delete();
  296. }
  297. OutputStream outputStream = Files.newOutputStream(pdfFile.toPath());
  298. Document document = getDocument();
  299. PdfWriter pdfWriter = PdfWriter.getInstance(document, outputStream);
  300. document.open();
  301. BaseFont baseFont = BaseFont.createFont("STSong-Light","UniGB-UCS2-H", BaseFont.NOT_EMBEDDED);
  302. Font font = new Font(baseFont, 14, Font.BOLD);
  303. document.add(getTitleParagraph(font));
  304. document.add(getPatInfoTable(baseFont, request.getRxMdtrtinfo()));
  305. LineSeparator line = new LineSeparator(1, 100, BaseColor.BLACK, Element.ALIGN_CENTER, -7);
  306. document.add(getStamp());
  307. document.add(line);
  308. document.add(Chunk.NEWLINE);
  309. document.add(new Phrase("Rp", new Font(baseFont, 16, Font.BOLD)));
  310. document.add(Chunk.NEWLINE);
  311. document.add(getReceiptTable(baseFont, request.getRxDrugDetailList()));
  312. document.add(Chunk.NEWLINE);
  313. document.add(line);
  314. document.add(Chunk.NEWLINE);
  315. document.add(getFooter(baseFont, request));
  316. pdfWriter.setPageEvent(new PdfPageEventHelper() {
  317. @Override
  318. public void onStartPage(PdfWriter writer, Document document) {
  319. PdfContentByte pdfContentByte = writer.getDirectContent();
  320. pdfContentByte.saveState();
  321. pdfContentByte.beginText();
  322. pdfContentByte.setFontAndSize(baseFont, 10);
  323. float y = document.top(-20);
  324. pdfContentByte.showTextAligned(PdfContentByte.ALIGN_LEFT, "H-Left", document.left(), y, 0);
  325. pdfContentByte.showTextAligned(PdfContentByte.ALIGN_CENTER, "第" + writer.getPageNumber() + "页",
  326. (document.right() + document.left()) / 2, y, 0);
  327. pdfContentByte.showTextAligned(PdfContentByte.ALIGN_RIGHT, "H-Right", document.right(), y, 0);
  328. pdfContentByte.endText();
  329. LineSeparator line = new LineSeparator(1, 100, BaseColor.BLACK, Element.ALIGN_CENTER, 10);
  330. try {
  331. document.add(line);
  332. } catch (DocumentException e) {
  333. throw new RuntimeException(e);
  334. }
  335. pdfContentByte.restoreState();
  336. }
  337. });
  338. document.close();
  339. outputStream.close();
  340. byte[] pdfBytes = java.nio.file.Files.readAllBytes(java.nio.file.Paths.get(pdfFilePath));
  341. return Base64.getEncoder().encodeToString(pdfBytes);
  342. }
  343. private Document getDocument() {
  344. Document document = new Document(PageSize.A4);
  345. document.addAuthor("沭阳铭和医院");
  346. document.addCreationDate();
  347. document.addSubject("处方笺");
  348. return document;
  349. }
  350. private Paragraph getTitleParagraph(Font font) {
  351. Paragraph titleParagraph = new Paragraph();
  352. Chunk titleChunkLine = new Chunk("沭 阳 铭 和 医 院 外 配 药 品 处 方 笺");
  353. titleChunkLine.setFont(font);
  354. titleChunkLine.setTextRise(30);
  355. titleParagraph.add(titleChunkLine);
  356. titleParagraph.setAlignment(Element.ALIGN_CENTER);
  357. LineSeparator line = new LineSeparator(1, 100, BaseColor.BLACK, Element.ALIGN_CENTER, 5);
  358. titleParagraph.add(line);
  359. return titleParagraph;
  360. }
  361. private PdfPTable getPatInfoTable(BaseFont baseFont, RxMdtrtInfo mdtrt) {
  362. Font smallFont = new Font(baseFont, 10, Font.NORMAL);
  363. PdfPTable table = new PdfPTable(3);
  364. table.setWidthPercentage(100);
  365. PdfPCell nameCell = new PdfPCell(new Phrase("姓名:" + mdtrt.getPatnName(), smallFont));
  366. nameCell.setBorder(-1);
  367. nameCell.setPaddingTop(6);
  368. PdfPCell genderCell = new PdfPCell(new Phrase("性别:" + translateGender(mdtrt.getGend()), smallFont));
  369. genderCell.setBorder(-1);
  370. genderCell.setPaddingTop(6);
  371. PdfPCell ageCell = new PdfPCell(new Phrase("年龄: " + mdtrt.getPatnAge() + "岁",smallFont));
  372. ageCell.setBorder(-1);
  373. ageCell.setPaddingTop(6);
  374. table.addCell(nameCell);
  375. table.addCell(genderCell);
  376. table.addCell(ageCell);
  377. PdfPCell patNoCell = new PdfPCell(new Phrase("门诊号:" + mdtrt.getIptOtpNo(), smallFont));
  378. patNoCell.setBorder(-1);
  379. patNoCell.setPaddingTop(12);
  380. patNoCell.setPaddingBottom(6);
  381. PdfPCell deptCell = new PdfPCell(new Phrase("科别:" + mdtrt.getPrscDeptName(), smallFont));
  382. deptCell.setBorder(-1);
  383. deptCell.setPaddingTop(12);
  384. deptCell.setPaddingBottom(6);
  385. PdfPCell diagCell = new PdfPCell(new Phrase("临床诊断:" + mdtrt.getMaindiagName(),smallFont));
  386. diagCell.setBorder(-1);
  387. diagCell.setPaddingTop(12);
  388. diagCell.setPaddingBottom(6);
  389. table.addCell(patNoCell);
  390. table.addCell(deptCell);
  391. table.addCell(diagCell);
  392. PdfPCell mdtrtIdCell = new PdfPCell(new Phrase("就诊ID:" + mdtrt.getMdtrtId(), smallFont));
  393. mdtrtIdCell.setBorder(-1);
  394. mdtrtIdCell.setPaddingTop(12);
  395. mdtrtIdCell.setPaddingBottom(6);
  396. PdfPCell dateCell = new PdfPCell(new Phrase("开具日期:" + DateUtil.formatDatetime(mdtrt.getMdtrtTime()), smallFont));
  397. dateCell.setBorder(-1);
  398. dateCell.setPaddingTop(12);
  399. dateCell.setPaddingBottom(6);
  400. PdfPCell blankCell = new PdfPCell(new Phrase(""));
  401. blankCell.setBorder(-1);
  402. table.addCell(mdtrtIdCell);
  403. table.addCell(dateCell);
  404. table.addCell(blankCell);
  405. return table;
  406. }
  407. private PdfPTable getReceiptTable(BaseFont baseFont, List<RxDrugDetail> drugList) {
  408. Font smallFont = new Font(baseFont, 9, Font.NORMAL);
  409. PdfPTable table = new PdfPTable(4);
  410. table.setWidthPercentage(100);
  411. for (RxDrugDetail item : drugList) {
  412. String drugName = item.getDrugGenname() + "(" + item.getDrugSpec() + ")";
  413. PdfPCell drugNameCell = new PdfPCell(new Phrase(drugName, smallFont));
  414. drugNameCell.setBorder(-1);
  415. String usedWay = "用法:" + item.getMedcWayDscr() + "(" + item.getSinDoscnt() + item.getSinDosunt() + "/次)" ;
  416. PdfPCell usedWayCell = new PdfPCell(new Phrase(usedWay, smallFont));
  417. usedWayCell.setBorder(-1);
  418. String freq = "频率:" + item.getUsedFrquName();
  419. PdfPCell freqCell = new PdfPCell(new Phrase(freq, smallFont));
  420. freqCell.setBorder(-1);
  421. PdfPCell amountCell = new PdfPCell(new Phrase("× " + item.getDrugCnt() + item.getDrugDosunt(), smallFont));
  422. amountCell.setBorder(-1);
  423. table.addCell(drugNameCell);
  424. table.addCell(usedWayCell);
  425. table.addCell(freqCell);
  426. table.addCell(amountCell);
  427. }
  428. return table;
  429. }
  430. private PdfPTable getFooter(BaseFont baseFont, RxPreCheckRequest request) throws Exception {
  431. RxMdtrtInfo mdtrt = request.getRxMdtrtinfo();
  432. Font smallFont = new Font(baseFont, 10, Font.NORMAL);
  433. PdfPTable table = new PdfPTable(5);
  434. table.setHorizontalAlignment(Element.ALIGN_LEFT);
  435. table.setWidthPercentage(80);
  436. PdfPCell drNameCell = new PdfPCell(new Phrase("开方医师:", smallFont));
  437. drNameCell.setBorder(-1);
  438. String hisCode = rxDao.getDoctorHisCode(mdtrt.getDrCode());
  439. PdfPCell drSignCell = new PdfPCell();
  440. drSignCell.setBorder(-1);
  441. drSignCell.setImage(getDoctorSign(hisCode));
  442. PdfPCell blankCell = new PdfPCell(new Phrase(""));
  443. blankCell.setBorder(-1);
  444. PdfPCell phNameCell = new PdfPCell(new Phrase("审方药师:", smallFont));
  445. phNameCell.setBorder(-1);
  446. PdfPCell phSignCell = new PdfPCell();
  447. phSignCell.setBorder(-1);
  448. phSignCell.setImage(getDoctorSign(request.getStaffId()));
  449. table.addCell(drNameCell);
  450. table.addCell(drSignCell);
  451. table.addCell(blankCell);
  452. table.addCell(phNameCell);
  453. table.addCell(phSignCell);
  454. return table;
  455. }
  456. private Image getStamp() throws BadElementException, IOException {
  457. Image stamp = Image.getInstance("http://localhost:1100/stamp.png");
  458. stamp.scalePercent(50);
  459. int absoluteY = new Random().nextInt(20) + 630;
  460. stamp.setAbsolutePosition(460, absoluteY);
  461. return stamp;
  462. }
  463. private Image getDoctorSign(String hisCode) {
  464. return TryUtil.ignoreErr(() -> {
  465. Image signature = Image.getInstance("http://130.150.161.72:8080/doctorSignatureImage/" + hisCode + ".png");
  466. signature.scalePercent(35);
  467. return signature;
  468. });
  469. }
  470. private String translateGender(String gend) {
  471. gend = StringUtil.isBlank(gend) ? "9" : gend;
  472. switch (gend) {
  473. case "1":
  474. return "男";
  475. case "2":
  476. return "女";
  477. default:
  478. return "未知";
  479. }
  480. }
  481. private void deleteRxPdfFile(RxPreCheckRequest request) {
  482. String pdfFilePath = Global.FILE_PATH + request.getHospRxno() + ".pdf";
  483. File pdfFile = new File(pdfFilePath);
  484. if (pdfFile.exists()) {
  485. pdfFile.delete();
  486. }
  487. }
  488. }