|
|
@@ -1,54 +1,67 @@
|
|
|
package com.fs.store.service.impl;
|
|
|
|
|
|
+import java.awt.*;
|
|
|
+import java.awt.image.BufferedImage;
|
|
|
+import java.io.*;
|
|
|
+import java.net.URL;
|
|
|
import java.text.SimpleDateFormat;
|
|
|
-import java.util.ArrayList;
|
|
|
-import java.util.Date;
|
|
|
+import java.util.*;
|
|
|
import java.util.List;
|
|
|
|
|
|
+import cn.hutool.core.util.ObjectUtil;
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
import com.fs.common.config.FSSysConfig;
|
|
|
import com.fs.common.core.domain.R;
|
|
|
import com.fs.common.exception.CustomException;
|
|
|
import com.fs.common.utils.DateUtils;
|
|
|
import com.fs.common.utils.OrderUtils;
|
|
|
+import com.fs.common.utils.ParseUtils;
|
|
|
import com.fs.common.utils.StringUtils;
|
|
|
-import com.fs.store.bean.Drug;
|
|
|
-import com.fs.store.bean.DrugV2;
|
|
|
-import com.fs.store.bean.Prescribe;
|
|
|
-import com.fs.store.bean.PrescribeV2;
|
|
|
import com.fs.store.domain.*;
|
|
|
+import com.fs.store.dto.FsStoreCartDTO;
|
|
|
+import com.fs.store.dto.MedicalRecordDTO;
|
|
|
+import com.fs.store.mapper.FsStoreProductMapper;
|
|
|
import com.fs.store.param.*;
|
|
|
import com.fs.store.service.*;
|
|
|
import com.fs.store.vo.FsPrescribeVO;
|
|
|
+import com.fs.system.oss.CloudStorageService;
|
|
|
+import com.fs.system.oss.OSSFactory;
|
|
|
+import com.hc.openapi.tool.fastjson.JSON;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
+import net.coobird.thumbnailator.Thumbnails;
|
|
|
+import net.coobird.thumbnailator.resizers.configurations.Antialiasing;
|
|
|
+import org.apache.commons.lang.exception.ExceptionUtils;
|
|
|
+import org.apache.http.util.Asserts;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import com.fs.store.mapper.FsPrescribeMapper;
|
|
|
|
|
|
+import javax.imageio.ImageIO;
|
|
|
+
|
|
|
/**
|
|
|
* 处方Service业务层处理
|
|
|
*
|
|
|
* @author fs
|
|
|
* @date 2022-03-15
|
|
|
*/
|
|
|
+@Slf4j
|
|
|
@Service
|
|
|
public class FsPrescribeServiceImpl implements IFsPrescribeService
|
|
|
{
|
|
|
@Autowired
|
|
|
- IPrescribeService prescribeService;
|
|
|
- @Autowired
|
|
|
- FsPrescribeMapper fsPrescribeMapper;
|
|
|
+ private FsPrescribeMapper fsPrescribeMapper;
|
|
|
@Autowired
|
|
|
- IFsStoreOrderService orderService;
|
|
|
+ private IFsStoreOrderService orderService;
|
|
|
@Autowired
|
|
|
- IFsPatientService patientService;
|
|
|
+ private IFsPatientService patientService;
|
|
|
@Autowired
|
|
|
- IFsUserService userService;
|
|
|
+ private MedicalRecordService medicalRecordService;
|
|
|
@Autowired
|
|
|
- FSSysConfig fsSysConfig;
|
|
|
+ private IFsStoreOrderService fsStoreOrderService;
|
|
|
@Autowired
|
|
|
- IFsStoreOrderItemService orderItemService;
|
|
|
+ private FSSysConfig fsSysConfig;
|
|
|
@Autowired
|
|
|
- IFsStoreProductService productService;
|
|
|
-
|
|
|
+ private FsStoreProductMapper fsStoreProductMapper;
|
|
|
/**
|
|
|
* 查询处方
|
|
|
*
|
|
|
@@ -124,13 +137,13 @@ public class FsPrescribeServiceImpl implements IFsPrescribeService
|
|
|
|
|
|
@Override
|
|
|
public R doPrescribe(long userId, FsPrescribeParam param) {
|
|
|
+ if(param.getPatientId() == null) {
|
|
|
+ throw new CustomException("患者必须选择!");
|
|
|
+ }
|
|
|
FsStoreOrder order=orderService.selectFsStoreOrderById(param.getOrderId());
|
|
|
if(order==null){
|
|
|
throw new CustomException("订单不存在");
|
|
|
}
|
|
|
-// if(order.getStatus()!=1){
|
|
|
-// throw new CustomException("未支付订单不能开处方");
|
|
|
-// }
|
|
|
FsPrescribe checkPrescribe=fsPrescribeMapper.selectFsPrescribeByOrderId(order.getId());
|
|
|
if(checkPrescribe!=null){
|
|
|
throw new CustomException("已提交处方申请,正在开方...");
|
|
|
@@ -138,85 +151,36 @@ public class FsPrescribeServiceImpl implements IFsPrescribeService
|
|
|
FsStoreOrderItem orderItemMap=new FsStoreOrderItem();
|
|
|
orderItemMap.setOrderId(order.getId());
|
|
|
orderItemMap.setIsPrescribe(1);
|
|
|
- List<FsStoreOrderItem> items= orderItemService.selectFsStoreOrderItemList(orderItemMap);
|
|
|
String rpId=OrderUtils.getOrderNo();
|
|
|
FsPatient patient=patientService.selectFsPatientById(param.getPatientId());
|
|
|
- FsUser user=userService.selectFsUserById(userId);
|
|
|
- PrescribeV2Param prescribeParam=new PrescribeV2Param();
|
|
|
- PrescribeV2 prescribe=new PrescribeV2();
|
|
|
- prescribe.setDrugType("01");
|
|
|
- prescribe.setOnlyId(rpId);
|
|
|
- prescribe.setDrugstoreName("零利润药房");
|
|
|
- prescribe.setPatientName(patient.getPatientName());
|
|
|
- prescribe.setPatientAge(DateUtils.getAge(patient.getBirthday()));
|
|
|
-// prescribe.setPatientTel(user.getPhone());
|
|
|
- prescribe.setPatientSex(patient.getGender());
|
|
|
- prescribe.setPatientAllergy(param.getIsAllergic()?1:0);
|
|
|
- prescribe.setLiverUnusual(param.getIsLiver()?1:0);
|
|
|
- prescribe.setRenalUnusual(param.getIsRenal()?1:0);
|
|
|
- prescribe.setLactationFlag(param.getIsLactation()?1:0);
|
|
|
- prescribe.setChiefComplaint(param.getChiefComplaint());
|
|
|
- prescribe.setNowIllness(param.getNowIllness());
|
|
|
- prescribe.setHistoryIllness(param.getHistoryIllness());
|
|
|
- if(StringUtils.isNotEmpty(param.getRecordPic())){
|
|
|
- prescribe.setRecordPic(param.getRecordPic().split(","));
|
|
|
- }
|
|
|
- SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
|
|
- Date now = new Date();
|
|
|
- prescribe.setCreateTime(sdf.format(now));
|
|
|
- prescribe.setPictureType("png");
|
|
|
-// prescribe.setLactationFlag("否");
|
|
|
- prescribe.setCallbackUrl(fsSysConfig.getCallbackUrl());
|
|
|
-
|
|
|
- List<DrugV2> drug_list=new ArrayList<>();
|
|
|
- for(FsStoreOrderItem item:items){
|
|
|
- FsStoreProduct product=productService.selectFsStoreProductById(item.getProductId());
|
|
|
- DrugV2 drug=new DrugV2();
|
|
|
- drug.setDrugCommonName(product.getPrescribeName());
|
|
|
- drug.setDrugSpecification(product.getPrescribeSpec());
|
|
|
- drug.setSaleAmount(item.getNum().toString());
|
|
|
- drug.setSaleUnit(product.getUnitName());
|
|
|
- drug.setApprovalNumber(product.getPrescribeCode());
|
|
|
- drug.setDrugCode(product.getProductId());
|
|
|
- drug_list.add(drug);
|
|
|
- prescribe.setDrugList(drug_list);
|
|
|
- prescribeParam.setData(prescribe);
|
|
|
- }
|
|
|
- R response=prescribeService.doPrescribeV2(prescribeParam);
|
|
|
- if(response.get("code").equals(200)){
|
|
|
- FsPrescribe fsPrescribe=new FsPrescribe();
|
|
|
- fsPrescribe.setRpId(rpId);
|
|
|
- fsPrescribe.setUserId(userId);
|
|
|
- fsPrescribe.setPatientId(patient.getPatientId());
|
|
|
- fsPrescribe.setPharmacyCode("00001");
|
|
|
- fsPrescribe.setPharmacyName("零利润药房");
|
|
|
- fsPrescribe.setStatus(0);
|
|
|
- fsPrescribe.setPrescribeType(1);
|
|
|
- fsPrescribe.setOrderId(order.getId());
|
|
|
- fsPrescribe.setCreateTime(new Date());
|
|
|
- fsPrescribe.setPatientGender(patient.getGender().toString());
|
|
|
- fsPrescribe.setPatientName(patient.getPatientName());
|
|
|
- fsPrescribe.setIsHistoryAllergic(param.getIsAllergic()?"是":"否");
|
|
|
- fsPrescribe.setLiverUnusual(param.getIsLiver()?"是":"否");
|
|
|
- fsPrescribe.setLactationFlag(param.getIsLactation()?"是":"否");
|
|
|
- fsPrescribe.setRenalUnusual(param.getIsRenal()?"是":"否");
|
|
|
- fsPrescribe.setChiefComplaint(param.getChiefComplaint());
|
|
|
- fsPrescribe.setNowIllness(param.getNowIllness());
|
|
|
- fsPrescribe.setHistoryIllness(param.getHistoryIllness());
|
|
|
- fsPrescribe.setRecordPic(param.getRecordPic());
|
|
|
- fsPrescribe.setPatientAge(String.valueOf( DateUtils.getAge(patient.getBirthday())));
|
|
|
- fsPrescribeMapper.insertFsPrescribe(fsPrescribe);
|
|
|
-
|
|
|
- FsStoreOrder orderMap=new FsStoreOrder();
|
|
|
- orderMap.setId(order.getId());
|
|
|
- orderMap.setPrescribeId(fsPrescribe.getPrescribeId());
|
|
|
- orderService.updateFsStoreOrder(orderMap);
|
|
|
- return R.ok("操作成功").put("order",order);
|
|
|
-
|
|
|
- }
|
|
|
- else{
|
|
|
- return R.error(response.get("msg").toString());
|
|
|
- }
|
|
|
+ FsPrescribe fsPrescribe=new FsPrescribe();
|
|
|
+ fsPrescribe.setRpId(rpId);
|
|
|
+ fsPrescribe.setUserId(userId);
|
|
|
+ fsPrescribe.setPatientId(patient.getPatientId());
|
|
|
+ fsPrescribe.setPharmacyCode("00001");
|
|
|
+ fsPrescribe.setPharmacyName("零利润药房");
|
|
|
+ fsPrescribe.setStatus(0);
|
|
|
+ fsPrescribe.setPrescribeType(1);
|
|
|
+ fsPrescribe.setOrderId(order.getId());
|
|
|
+ fsPrescribe.setCreateTime(new Date());
|
|
|
+ fsPrescribe.setPatientGender(patient.getGender().toString());
|
|
|
+ fsPrescribe.setPatientName(patient.getPatientName());
|
|
|
+ fsPrescribe.setIsHistoryAllergic(param.getIsAllergic()?"是":"否");
|
|
|
+ fsPrescribe.setLiverUnusual(param.getIsLiver()?"是":"否");
|
|
|
+ fsPrescribe.setLactationFlag(param.getIsLactation()?"是":"否");
|
|
|
+ fsPrescribe.setRenalUnusual(param.getIsRenal()?"是":"否");
|
|
|
+ fsPrescribe.setChiefComplaint(param.getChiefComplaint());
|
|
|
+ fsPrescribe.setNowIllness(param.getNowIllness());
|
|
|
+ fsPrescribe.setHistoryIllness(param.getHistoryIllness());
|
|
|
+ fsPrescribe.setRecordPic(param.getRecordPic());
|
|
|
+ fsPrescribe.setPatientAge(String.valueOf( DateUtils.getAge(patient.getBirthday())));
|
|
|
+ fsPrescribeMapper.insertFsPrescribe(fsPrescribe);
|
|
|
+
|
|
|
+ FsStoreOrder orderMap=new FsStoreOrder();
|
|
|
+ orderMap.setId(order.getId());
|
|
|
+ orderMap.setPrescribeId(fsPrescribe.getPrescribeId());
|
|
|
+ orderService.updateFsStoreOrder(orderMap);
|
|
|
+ return R.ok("操作成功").put("order",order);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
@@ -239,4 +203,388 @@ public class FsPrescribeServiceImpl implements IFsPrescribeService
|
|
|
public FsPrescribe selectFsPrescribeByOrderId(Long id) {
|
|
|
return fsPrescribeMapper.selectFsPrescribeByOrderId(id);
|
|
|
}
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public String prescribeImg(Long prescribeId) {
|
|
|
+
|
|
|
+ FsPrescribe fsPrescribe = fsPrescribeMapper.selectFsPrescribeById(prescribeId);
|
|
|
+
|
|
|
+ Asserts.notNull(fsPrescribe, String.format("该处方 %d 无法找到!",prescribeId));
|
|
|
+
|
|
|
+ Long orderId = fsPrescribe.getOrderId();
|
|
|
+
|
|
|
+ Asserts.notNull(orderId,String.format("该处方 %d 对应订单号 %d 不存在!",prescribeId,orderId));
|
|
|
+
|
|
|
+ FsStoreOrder fsStoreOrder = orderService.selectFsStoreOrderById(orderId);
|
|
|
+
|
|
|
+ Asserts.notNull(fsStoreOrder,String.format("该处方 %d 对应订单号 %d 不存在!",prescribeId,orderId));
|
|
|
+
|
|
|
+ PrescribeXyImgParam param = new PrescribeXyImgParam();
|
|
|
+
|
|
|
+ param.setPrescribeId(String.valueOf(prescribeId));
|
|
|
+
|
|
|
+ // 门诊ID号
|
|
|
+ param.setOutpatientId(String.valueOf(prescribeId));
|
|
|
+ // 科别
|
|
|
+ param.setBedId("全科");
|
|
|
+ // 过敏史
|
|
|
+ param.setHistoryAllergic(fsPrescribe.getHistoryAllergic());
|
|
|
+ // 诊断
|
|
|
+ param.setDiagnose(fsPrescribe.getDiagnose());
|
|
|
+ // 开具日期
|
|
|
+ param.setTime(new Date());
|
|
|
+ // 药品目录
|
|
|
+ String itemJson = fsStoreOrder.getItemJson();
|
|
|
+ List<FsStoreOrderItem> fsStoreCartDTOS = JSONObject.parseArray(itemJson, FsStoreOrderItem.class);
|
|
|
+ List<FsPrescribeDrug> fsPrescribeDrugList = new ArrayList<>();
|
|
|
+ Map<Long,FsStoreProduct> allProductTypeMapping = fsStoreProductMapper.selectAllProductTypeMapping();
|
|
|
+ for (FsStoreOrderItem item : fsStoreCartDTOS) {
|
|
|
+ FsStoreProduct fsStoreProduct = allProductTypeMapping.get(item.getProductId());
|
|
|
+ if(fsStoreProduct != null) {
|
|
|
+ Integer productType = fsStoreProduct.getProductType();
|
|
|
+ Set<Integer> includeSet = new HashSet<>();
|
|
|
+ includeSet.add(1);
|
|
|
+ includeSet.add(2);
|
|
|
+ includeSet.add(4);
|
|
|
+
|
|
|
+ // 只对非处方、处方药、器械 进行开方
|
|
|
+ if(!includeSet.contains(productType)) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ FsStoreCartDTO cartDTO = JSON.parseObject(item.getJsonInfo(),FsStoreCartDTO.class);
|
|
|
+ FsPrescribeDrug fsPrescribeDrug = new FsPrescribeDrug();
|
|
|
+ fsPrescribeDrug.setDrugName(cartDTO.getProductName());
|
|
|
+
|
|
|
+ // 使⽤⽅法
|
|
|
+ fsPrescribeDrug.setUsageMethod(cartDTO.getUsageMethod());
|
|
|
+ // 药品频次
|
|
|
+ fsPrescribeDrug.setUsageFrequencyUnit(String.format("每日 %s 次",cartDTO.getFrequency()));
|
|
|
+ // 用药数量
|
|
|
+ fsPrescribeDrug.setUsagePerUseCount(String.format("每次 %s ",cartDTO.getDosage()));
|
|
|
+ fsPrescribeDrug.setDrugNum(Long.valueOf(item.getNum()));
|
|
|
+ fsPrescribeDrugList.add(fsPrescribeDrug);
|
|
|
+ }
|
|
|
+ param.setPrescribeDrug(fsPrescribeDrugList);
|
|
|
+
|
|
|
+ param.setPatientName(fsPrescribe.getPatientName());
|
|
|
+ param.setPatientGender(fsPrescribe.getPatientGender());
|
|
|
+ param.setPatientAge(fsPrescribe.getPatientAge());
|
|
|
+
|
|
|
+ // 医生名称
|
|
|
+ param.setDoctorName(fsPrescribe.getDoctorName());
|
|
|
+ // 订单总价
|
|
|
+ param.setTotalPrice(fsStoreOrder.getPayMoney());
|
|
|
+ param.setAuditDoctor(fsPrescribe.getAuditDoctor());
|
|
|
+ param.setDrugDoctorUrl(fsSysConfig.getDrugDoctorSignImgUrl());
|
|
|
+ param.setUrl(fsSysConfig.getDoctorSignImgUrl());
|
|
|
+ return getFsPrescribeXyImg(param);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public String getFsPrescribeZyImg(PrescribeZyImgParam o) {
|
|
|
+ File mb = new File("C:\\fs\\zycf.jpg");
|
|
|
+ if (!mb.exists()) {
|
|
|
+ // 创建目录
|
|
|
+ throw new CustomException("模板文件不存在");
|
|
|
+ }
|
|
|
+ BufferedImage image = null;
|
|
|
+ try {
|
|
|
+ image = ImageIO.read(mb);
|
|
|
+ } catch (IOException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ // 创建画笔(image为上一步的图片对象)
|
|
|
+ Graphics2D pen = image.createGraphics();
|
|
|
+ pen.setColor(Color.black);
|
|
|
+ //处理字体 高清加边缘模糊
|
|
|
+ pen.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING,
|
|
|
+ RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
|
|
|
+ pen.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
|
|
|
+ pen.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY);
|
|
|
+ pen.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_SPEED);
|
|
|
+ pen.setFont(new Font("黑体", Font.PLAIN, 21));
|
|
|
+ // 将date对象格式化为字符串
|
|
|
+
|
|
|
+ penDrawString(pen,new SimpleDateFormat("yyyy-MM-dd").format(o.getTime()), 730, 290);
|
|
|
+ penDrawString(pen,o.getPrescribeId(),1030,290);
|
|
|
+ penDrawString(pen,o.getPatientName(),136,372);
|
|
|
+ penDrawString(pen,o.getPatientGender().equals("1")?"男":o.getPatientGender().equals("2")?"女":o.getPatientGender(),420,372);
|
|
|
+ penDrawString(pen,o.getPatientAge(),690,372);
|
|
|
+ penDrawString(pen,o.getPatientTel(),970,372);
|
|
|
+ String address= o.getUserName()+" "+o.getUserPhone()+" "+o.getUserAddress();
|
|
|
+ penDrawString(pen,address,180,445);
|
|
|
+ penDrawString(pen,o.getDiagnose(),180,515);
|
|
|
+ List<FsPrescribeDrug> Drug = o.getPrescribeDrug();
|
|
|
+ int size=Drug.size();
|
|
|
+
|
|
|
+ for (int i = 0; i < size/3.0; i++) {
|
|
|
+ if (i*3<size){
|
|
|
+ pen.drawString(Drug.get(i*3).getDrugName(),145,680+i*50);
|
|
|
+ }
|
|
|
+ if (i*3+1<size){
|
|
|
+ pen.drawString(Drug.get(i*3+1).getDrugName(),510,680+i*50);
|
|
|
+ }
|
|
|
+ if (i*3+2<size){
|
|
|
+ pen.drawString(Drug.get(i*3+2).getDrugName(),875,680+i*50);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ penDrawString(pen,o.getEat(),110,1195);
|
|
|
+ penDrawString(pen,o.getUsageFrequencyUnit(),135,1240);
|
|
|
+ penDrawString(pen,o.getRemark(),110,1288);
|
|
|
+
|
|
|
+ if (o.getUrl()!=null){
|
|
|
+ try {
|
|
|
+ URL imageUrl = new URL(o.getUrl());
|
|
|
+ BufferedImage img = ImageIO.read(imageUrl);
|
|
|
+ pen.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR);
|
|
|
+ pen.drawImage(img, 130, 1420, 127, 60, null);
|
|
|
+ } catch (Exception e) {
|
|
|
+ throw new CustomException("获取医生签名图片失败");
|
|
|
+ }
|
|
|
+
|
|
|
+ }else {
|
|
|
+ penDrawString(pen,o.getPrescribeDoctorName(),152,1450);
|
|
|
+ }
|
|
|
+ if (o.getDrugDoctorUrl()!=null){
|
|
|
+ try {
|
|
|
+ URL imageUrl3 = new URL(o.getDrugDoctorUrl());
|
|
|
+ BufferedImage img3 = ImageIO.read(imageUrl3);
|
|
|
+ pen.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR);
|
|
|
+ pen.drawImage(img3, 370, 1345, 127, 60, null);
|
|
|
+ } catch (Exception e) {
|
|
|
+ throw new CustomException("获取药师签名图片失败");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ penDrawString(pen,o.getSize(),620,1378);
|
|
|
+ if (o.getTotalPrice()!=null){
|
|
|
+ penDrawString(pen,o.getTotalPrice().toString(),370,1452);
|
|
|
+ penDrawString(pen,o.getTotalPrice().toString(),620,1452);
|
|
|
+ }
|
|
|
+ ByteArrayOutputStream os = new ByteArrayOutputStream();
|
|
|
+ try {
|
|
|
+ ImageIO.write(image, "png", os);
|
|
|
+ } catch (IOException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ InputStream inputStream = new ByteArrayInputStream(os.toByteArray());
|
|
|
+ CloudStorageService storage = OSSFactory.build();
|
|
|
+ String url = storage.uploadSuffix(inputStream, ".jpg");
|
|
|
+ return url;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public String getFsPrescribeXyImg(PrescribeXyImgParam o) {
|
|
|
+ File mb = new File(fsSysConfig.getPrescribeTemplateImgPath());
|
|
|
+ if (!mb.exists()) {
|
|
|
+ // 创建目录
|
|
|
+ throw new CustomException("模板文件不存在");
|
|
|
+ }
|
|
|
+ BufferedImage image = null;
|
|
|
+ try {
|
|
|
+ image = ImageIO.read(mb);
|
|
|
+ } catch (IOException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ // 创建画笔(image为上一步的图片对象)
|
|
|
+ Graphics2D pen = image.createGraphics();
|
|
|
+ pen.setColor(Color.black);
|
|
|
+ //处理字体 高清加边缘模糊
|
|
|
+ pen.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING,
|
|
|
+ RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
|
|
|
+ pen.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
|
|
|
+ pen.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY);
|
|
|
+ pen.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_SPEED);
|
|
|
+ pen.setFont(new Font("黑体", Font.PLAIN, 14));
|
|
|
+ penDrawString(pen,o.getPrescribeId(),448,145);
|
|
|
+ penDrawString(pen,o.getPatientName(),60,178);
|
|
|
+ if (o.getPatientGender().equals("1")){
|
|
|
+ penDrawString(pen,"√",255,178);
|
|
|
+ }else if(o.getPatientGender().equals("2")){
|
|
|
+ penDrawString(pen,"√",298,178);
|
|
|
+ }
|
|
|
+ penDrawString(pen,o.getPatientAge(),400,178);
|
|
|
+ penDrawString(pen,o.getOutpatientId(),92,205);
|
|
|
+ penDrawString(pen,o.getBedId(),400,205);
|
|
|
+ penDrawString(pen,o.getHistoryAllergic(),95,230);
|
|
|
+ penDrawString(pen,o.getDiagnose(),95,257);
|
|
|
+ penDrawString(pen,new SimpleDateFormat("yyyy-MM-dd").format(o.getTime()),400,257);
|
|
|
+ List<FsPrescribeDrug> Drug = o.getPrescribeDrug();
|
|
|
+ int size=Drug.size();
|
|
|
+ for (int i = 0; i < size; i++) {
|
|
|
+ FsPrescribeDrug d = Drug.get(i);
|
|
|
+ String drugName = d.getDrugName();
|
|
|
+ if (drugName.length()>30){
|
|
|
+ drugName = drugName.substring(0, 30)+"...";
|
|
|
+ }
|
|
|
+
|
|
|
+ String drugSpec = (d.getDrugSpec() != null) ? d.getDrugSpec() : " ";
|
|
|
+
|
|
|
+ penDrawString(pen,i+1+","+drugName+" "+drugSpec+" "+d.getDrugNum(),35,305+i*40);
|
|
|
+ String usageMethod = (d.getUsageMethod() != null) ? d.getUsageMethod() : " ";
|
|
|
+ String usageFrequencyUnit = (d.getUsageFrequencyUnit() != null) ? d.getUsageFrequencyUnit() : " ";
|
|
|
+ String usagePerUseCount = (d.getUsagePerUseCount() != null) ? d.getUsagePerUseCount() : " ";
|
|
|
+
|
|
|
+ penDrawString(pen," Sig: "+usageMethod+" "+usageFrequencyUnit+" "+usagePerUseCount,35,325+i*40);
|
|
|
+ }
|
|
|
+ penDrawString(pen,"本页完",277,325+size*40);
|
|
|
+
|
|
|
+ penDrawString(pen,o.getRemark(),62,651);
|
|
|
+ if (o.getUrl()!=null){
|
|
|
+ try {
|
|
|
+ URL imageUrl = new URL(o.getUrl());
|
|
|
+ BufferedImage scaledImg = Thumbnails.of(imageUrl)
|
|
|
+ .size(120, 55)
|
|
|
+ .outputQuality(1.0)
|
|
|
+ .antialiasing(Antialiasing.ON)
|
|
|
+ .asBufferedImage();
|
|
|
+ pen.drawImage(scaledImg, 65, 688, null);
|
|
|
+ } catch (Exception e) {
|
|
|
+ throw new CustomException("获取签名图片失败");
|
|
|
+ }
|
|
|
+ }else {
|
|
|
+ penDrawString(pen,o.getDoctorName(),63,716);
|
|
|
+ }
|
|
|
+
|
|
|
+ penDrawString(pen,o.getTotalPrice().toString(),375,717);
|
|
|
+ if (o.getDrugDoctorUrl()!=null){
|
|
|
+ try {
|
|
|
+ URL imageUrl = new URL(o.getDrugDoctorUrl());
|
|
|
+ BufferedImage scaledImg = Thumbnails.of(imageUrl)
|
|
|
+ .size(120, 55)
|
|
|
+ .outputQuality(1.0)
|
|
|
+ .antialiasing(Antialiasing.ON)
|
|
|
+ .asBufferedImage();
|
|
|
+
|
|
|
+ pen.drawImage(scaledImg, 90, 730, null);
|
|
|
+ } catch (Exception e) {
|
|
|
+ throw new CustomException("获取药师签名图片失败");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ penDrawString(pen,o.getDispatcher(),357,757);
|
|
|
+ penDrawString(pen,o.getCheckDoctor(),135,796);
|
|
|
+
|
|
|
+
|
|
|
+ ByteArrayOutputStream os = new ByteArrayOutputStream();
|
|
|
+ try {
|
|
|
+ ImageIO.write(image, "png", os);
|
|
|
+ } catch (IOException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ InputStream inputStream = new ByteArrayInputStream(os.toByteArray());
|
|
|
+ CloudStorageService storage = OSSFactory.build();
|
|
|
+ return storage.uploadSuffix(inputStream, ".jpg");
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void generateDealImg() {
|
|
|
+ // 获取待处理数据
|
|
|
+ List<FsPrescribe> list = fsPrescribeMapper.selectPenddingData();
|
|
|
+ Map<Long,FsStoreProduct> allProductTypeMapping = fsStoreProductMapper.selectAllProductTypeMapping();
|
|
|
+
|
|
|
+ for (FsPrescribe fsPrescribe : list) {
|
|
|
+ String rpUrl = null;
|
|
|
+ try{
|
|
|
+ rpUrl = this.prescribeImg(fsPrescribe.getPrescribeId());
|
|
|
+ }catch (Exception e) {
|
|
|
+ log.error("生成处方失败!原因:{}",e.getMessage(),e);
|
|
|
+ fsPrescribe.setFailMsg(ExceptionUtils.getFullStackTrace(e));
|
|
|
+ }
|
|
|
+ // 生成处方图片
|
|
|
+ log.info("rpUrl: {}",rpUrl);
|
|
|
+
|
|
|
+ fsPrescribe.setRpUrl(rpUrl);
|
|
|
+ // 生成病历图片
|
|
|
+ MedicalRecordDTO medicalRecordDTO = new MedicalRecordDTO();
|
|
|
+ medicalRecordDTO.setVisitDate(new Date());
|
|
|
+ medicalRecordDTO.setOutpatientNo(String.valueOf(fsPrescribe.getPrescribeId()));
|
|
|
+ medicalRecordDTO.setDepartment("全科");
|
|
|
+ medicalRecordDTO.setPaymentType("自费缴费");
|
|
|
+
|
|
|
+ medicalRecordDTO.setPatientName(fsPrescribe.getPatientName());
|
|
|
+ if(StringUtils.isNotBlank(fsPrescribe.getPatientGender())){
|
|
|
+ if("1".equals(fsPrescribe.getPatientGender())){
|
|
|
+ medicalRecordDTO.setGender("男");
|
|
|
+ } else {
|
|
|
+ medicalRecordDTO.setGender("女");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ medicalRecordDTO.setAge(Integer.valueOf(fsPrescribe.getPatientAge()));
|
|
|
+ medicalRecordDTO.setHeight("-");
|
|
|
+ medicalRecordDTO.setWeight("-");
|
|
|
+
|
|
|
+ FsStoreOrder fsStoreOrder = fsStoreOrderService.selectFsStoreOrderById(fsPrescribe.getOrderId());
|
|
|
+ if(ObjectUtil.isNotNull(fsStoreOrder)) {
|
|
|
+ medicalRecordDTO.setAddress(ParseUtils.parseAddress(fsStoreOrder.getUserAddress()));
|
|
|
+ medicalRecordDTO.setPhone(ParseUtils.parsePhone(fsStoreOrder.getUserPhone()));
|
|
|
+
|
|
|
+ // 药品目录
|
|
|
+ String itemJson = fsStoreOrder.getItemJson();
|
|
|
+ List<FsStoreOrderItem> fsStoreCartDTOS = JSONObject.parseArray(itemJson, FsStoreOrderItem.class);
|
|
|
+ List<FsPrescribeDrug> fsPrescribeDrugList = new ArrayList<>();
|
|
|
+ StringBuilder prescription = new StringBuilder();
|
|
|
+
|
|
|
+ int i=1;
|
|
|
+ prescription.append("\n");
|
|
|
+ for (FsStoreOrderItem item : fsStoreCartDTOS) {
|
|
|
+ FsStoreProduct fsStoreProduct = allProductTypeMapping.get(item.getProductId());
|
|
|
+ if(fsStoreProduct != null) {
|
|
|
+ Integer productType = fsStoreProduct.getProductType();
|
|
|
+ Set<Integer> includeSet = new HashSet<>();
|
|
|
+ includeSet.add(1);
|
|
|
+ includeSet.add(2);
|
|
|
+ includeSet.add(4);
|
|
|
+
|
|
|
+ // 只对非处方、处方药、器械 进行开方
|
|
|
+ if(!includeSet.contains(productType)) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ FsStoreCartDTO cartDTO = JSON.parseObject(item.getJsonInfo(),FsStoreCartDTO.class);
|
|
|
+
|
|
|
+ prescription.append(i++).append(".").append(cartDTO.getProductName())
|
|
|
+ .append("\t\t\t").append(item.getNum())
|
|
|
+ .append("\n")
|
|
|
+ .append("Sig:\t\t\t").append(cartDTO.getUsageMethod())
|
|
|
+ .append("\t").append(String.format("每日 %s 次",cartDTO.getFrequency()))
|
|
|
+ .append("\t").append(String.format("每次 %s ",cartDTO.getDosage()))
|
|
|
+ .append("\n");
|
|
|
+ }
|
|
|
+ medicalRecordDTO.setPrescription(prescription.toString());
|
|
|
+ medicalRecordDTO.setDrugList(fsPrescribeDrugList);
|
|
|
+ }
|
|
|
+
|
|
|
+ medicalRecordDTO.setChiefComplaint(fsPrescribe.getChiefComplaint());
|
|
|
+ medicalRecordDTO.setPresentIllness(fsPrescribe.getNowIllness());
|
|
|
+ medicalRecordDTO.setPastHistory(fsPrescribe.getHistoryIllness());
|
|
|
+ medicalRecordDTO.setAllergyHistory(fsPrescribe.getHistoryAllergic());
|
|
|
+
|
|
|
+ medicalRecordDTO.setVitalSigns("");
|
|
|
+ medicalRecordDTO.setAuxiliaryExam("");
|
|
|
+ medicalRecordDTO.setDiagnosis(fsPrescribe.getDiagnose());
|
|
|
+ medicalRecordDTO.setMedicalAdvice("请遵照医嘱用药,如有不适,请及时就医!");
|
|
|
+ medicalRecordDTO.setTreatmentPlan("");
|
|
|
+ medicalRecordDTO.setHealthEducation("");
|
|
|
+ String medicalUrl = null;
|
|
|
+ try{
|
|
|
+
|
|
|
+
|
|
|
+ medicalUrl = medicalRecordService.generateMedicalRecord(medicalRecordDTO);
|
|
|
+ }catch (Exception e){
|
|
|
+ log.error("生成病历单图片失败!原因:{}",e.getMessage(),e);
|
|
|
+ fsPrescribe.setFailMsg(fsPrescribe.getFailMsg()+"\n"+ ExceptionUtils.getFullStackTrace(e));
|
|
|
+ }
|
|
|
+
|
|
|
+ fsPrescribe.setMedicalRecordUrl(medicalUrl);
|
|
|
+ fsPrescribe.setGenerateStatus(2);
|
|
|
+ fsPrescribeMapper.updateFsPrescribe(fsPrescribe);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public void penDrawString( Graphics2D pen,String value,int x,int y){
|
|
|
+ if (value!=null){
|
|
|
+ pen.drawString(value,x,y);
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|