Browse Source

入院登记优化

lihong 3 months ago
parent
commit
568c5712cc

+ 13 - 0
src/main/java/thyyxxk/webserver/dao/his/zygl/APatientMiDao.java

@@ -421,4 +421,17 @@ public interface APatientMiDao {
     List<APatientMi> selectByKeyWard(String keyWard);
     @Update(" update a_patient_mi set mz_no = #{mzNo} where inpatient_no =#{inpatientNo} ")
     int updateMzNoByInpatientNo(@Param("inpatientNo") String inpatientNo, @Param("mzNo") String mzNo);
+
+    @Update({"<script>",
+            "update zy_actpatient ",
+            "<trim prefix='set' prefixOverrides=',' suffix=' where inpatient_no =#{inpatientNo}' >",
+            "<when test='name!=null'>",
+            "name =#{name,jdbcType=CHAR}",
+            "</when>",
+            "<when test='sex!=null'>",
+            ",sex =#{sex,jdbcType=CHAR}",
+            "</when>",
+            "</trim>"
+            ,"</script>"})
+    void updateZyAcPatient(APatientMi aPatientMi);
 }

+ 1 - 0
src/main/java/thyyxxk/webserver/service/zygl/APatientMiService.java

@@ -58,6 +58,7 @@ public class APatientMiService {
      * @return: int
      */
     public int modifyMzPatientMiByInpatientNo(APatientMi aPatientMi) {
+        aPatientMiMapper.updateZyAcPatient(aPatientMi);
         return aPatientMiMapper.updateMzPatientMiInpatientNo(aPatientMi);
     }
 

+ 7 - 1
src/main/java/thyyxxk/webserver/service/zygl/AdmissionRegistrationService.java

@@ -406,8 +406,14 @@ public class AdmissionRegistrationService {
         AssertUtil.isnotBlank(patientMiSfz.getPatientId(),"门诊号不能为空");
         AssertUtil.isnotBlank(patientMiSfz.getInpatientNo(),"住院号不能为空");
         AssertUtil.isnotBlank(patientMiSfz.getBirthDay(),"出生日期不能为空");
-        //patientMiSfz.setSfzImage();
+        String base64SfzZm = dictDataDao.getDictValueByDictName("4.1", "sfzzm");
         patientMiSfz.setTxImage(Base64.decode(patientMiSfz.getTxImageBase64()));
+        byte[] sfzZmc = CommonUtil.createSfzZmc(patientMiSfz, patientMiSfz.getTxImage(), Base64.decode(base64SfzZm));
+        if(sfzZmc == null){
+            throw new BizException(ExceptionEnum.LOGICAL_ERROR, "上传身份证失败");
+        }
+        patientMiSfz.setSfzImage(sfzZmc);
+        patientMiSfz.setSex("男".equals(patientMiSfz.getSex()) ? "1" : "2");
         patientMiSfz.setBirthDay(DateUtil.format(DateUtil.parseDate(patientMiSfz.getBirthDay()),"yyyy年MM月dd日"));
         dao.deletePatientMiSfzByPatientId(patientMiSfz.getPatientId());
         return dao.insertPatientMiSfz(patientMiSfz);

+ 186 - 0
src/main/java/thyyxxk/webserver/utils/CommonUtil.java

@@ -2,15 +2,27 @@ package thyyxxk.webserver.utils;
 
 import cn.hutool.core.bean.BeanUtil;
 import cn.hutool.core.collection.CollUtil;
+import cn.hutool.core.io.IoUtil;
 import cn.hutool.core.util.ReflectUtil;
 import cn.hutool.core.util.StrUtil;
+import lombok.extern.slf4j.Slf4j;
+import thyyxxk.webserver.entity.zygl.PatientMiSfz;
 
+import javax.imageio.ImageIO;
+import javax.swing.*;
+import java.awt.*;
+import java.awt.font.TextAttribute;
+import java.awt.image.BufferedImage;
+import java.io.ByteArrayInputStream;
 import java.io.ByteArrayOutputStream;
 import java.io.FileNotFoundException;
 import java.io.IOException;
 import java.io.InputStream;
 import java.lang.reflect.Field;
+import java.text.AttributedCharacterIterator;
+import java.text.AttributedString;
 import java.text.SimpleDateFormat;
+import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Date;
 import java.util.HashMap;
@@ -23,6 +35,7 @@ import java.util.regex.Pattern;
  * @Author:lihong
  * @Date: 2023/1/12
  */
+@Slf4j
 public class CommonUtil {
     /**
      * @description:计算医保支付方式
@@ -241,4 +254,177 @@ public class CommonUtil {
         map.put("detail", detail);
     }
 
+
+    public static byte[] createSfzZmc(PatientMiSfz patientMiSfz, byte[] txImage, byte[] sfzZmc) {
+        List<Map<String, Object>> list = new ArrayList<>();
+        Map<String, Object> map = new HashMap<>();
+        Color color1 = new Color(30, 30, 30);
+        map.put("text", patientMiSfz.getName()); // 姓名
+        map.put("color", color1);
+        map.put("x", 90);
+        map.put("y", 48);
+        map.put("fontType", "幼圆");
+        map.put("fontSize", 18);
+        list.add(map);
+
+        map = new HashMap<>();
+        map.put("text", patientMiSfz.getSex()); // 性别
+        map.put("color", color1);
+        map.put("x", 90);
+        map.put("y", 94);
+        map.put("fontType", "幼圆");
+        map.put("fontSize", 18);
+        list.add(map);
+
+        map = new HashMap<>();
+        map.put("text", patientMiSfz.getNation()); // 民族
+        map.put("color", color1);
+        map.put("x", 210);
+        map.put("y", 94);
+        map.put("fontType", "幼圆");
+        map.put("fontSize", 18);
+        list.add(map);
+
+        map = new HashMap<>();
+        map.put("text", patientMiSfz.getBirthDay().split("-")[0]); // 年
+        map.put("color", color1);
+        map.put("x", 90);
+        map.put("y", 136);
+        map.put("fontType", "幼圆");
+        map.put("fontSize", 18);
+        list.add(map);
+
+        map = new HashMap<>();
+        map.put("text", patientMiSfz.getBirthDay().split("-")[1]);// 月
+        map.put("color", color1);
+        map.put("x", 180);
+        map.put("y", 136);
+        map.put("fontType", "幼圆");
+        map.put("fontSize", 18);
+        list.add(map);
+
+        map = new HashMap<>();
+        map.put("text", patientMiSfz.getBirthDay().split("-")[2]);// 日
+        map.put("color", color1);
+        map.put("x", 230);
+        map.put("y", 136);
+        map.put("fontType", "幼圆");
+        map.put("fontSize", 18);
+        list.add(map);
+
+        String[] adds = new String[2];
+        if (patientMiSfz.getAddress().length() > 11) {
+            adds[0] = patientMiSfz.getAddress().substring(0, 11);
+            adds[1] = patientMiSfz.getAddress().substring(11);
+        } else {
+            adds[0] = patientMiSfz.getAddress();
+            adds[1] = "";
+        }
+        map = new HashMap<>();
+        map.put("text", adds[0]); // 证件地址1
+        map.put("color", color1);
+        map.put("x", 90);
+        map.put("y", 184);
+        map.put("fontType", "幼圆");
+        map.put("fontSize", 18);
+        list.add(map);
+        if (patientMiSfz.getAddress().length() > 11) {
+            map = new HashMap<>();
+            map.put("text", adds[1]);// 证件地址2
+            map.put("color", color1);
+            map.put("x", 90);
+            map.put("y", 210);
+            map.put("fontType", "幼圆");
+            map.put("fontSize", 18);
+            list.add(map);
+        }
+
+        map = new HashMap<>();
+        map.put("text", patientMiSfz.getSocialNo()); // 证件号码
+        map.put("color", color1);
+        map.put("x", 167);
+        map.put("y", 296);
+        map.put("fontType", "微软雅黑");
+        map.put("fontSize", 24);
+        list.add(map);
+        InputStream sfzIn = new ByteArrayInputStream(sfzZmc);
+        InputStream txIn = new ByteArrayInputStream(txImage);
+        try {
+            Image theImg = ImageIO.read(sfzIn);
+            int width = theImg.getWidth(null);
+            int height = theImg.getHeight(null);
+            BufferedImage bimage = new BufferedImage(width, height,
+                    BufferedImage.TYPE_INT_RGB);
+            Graphics2D g = bimage.createGraphics();
+            g.drawImage(theImg, 0, 0, null);
+            for (int i = 0; i < list.size(); i++) {
+                add(g, list.get(i));
+            }
+            BufferedImage content = convertTx(txIn);
+            g.drawImage(content.getScaledInstance(150, 180, Image.SCALE_DEFAULT), 320, 50, null);
+            g.dispose();
+            return toByteArray(bimage, "jpg");
+        }catch (Exception e){
+            log.error("生成身份证正面照报错:",e);
+        }finally {
+            IoUtil.close(sfzIn);
+            IoUtil.close(txIn);
+        }
+        return null;
+    }
+
+    private static BufferedImage convertTx(InputStream txIn) throws Exception{
+        BufferedImage image = ImageIO.read(txIn);
+        ImageIcon imageIcon = new ImageIcon(image);
+        int w = imageIcon.getIconWidth();
+        int h = imageIcon.getIconHeight();
+        BufferedImage bufferedImage = new BufferedImage(w, h, BufferedImage.TYPE_4BYTE_ABGR);
+        Graphics2D g2D = (Graphics2D) bufferedImage.getGraphics();
+        g2D.drawImage(imageIcon.getImage(), 0, 0, imageIcon.getImageObserver());
+        int alpha = 0;
+        for (int i = bufferedImage.getMinX(); i < w; i++) {
+            for (int j = bufferedImage.getMinY(); j < h; j++) {
+                int rgb = bufferedImage.getRGB(i, j);
+                //以白色为例
+                int RGB = Color.WHITE.getRGB();
+                int r = (rgb & 0xff0000) >> 16;
+                int g = (rgb & 0xff00) >> 8;
+                int b = (rgb & 0xff);
+                int R = (RGB & 0xff0000) >> 16;
+                int G = (RGB & 0xff00) >> 8;
+                int B = (RGB & 0xff);
+                if (Math.abs(R - r) < 15 && Math.abs(G - g) < 15 && Math.abs(B - b) < 15) {
+                    alpha = 0;
+                } else
+                    alpha = 255;
+                rgb = (alpha << 24) | (rgb & 0x00ffffff);
+                bufferedImage.setRGB(i, j, rgb);
+            }
+        }
+        g2D.drawImage(bufferedImage, 0, 0, imageIcon.getImageObserver());
+        return bufferedImage;
+    }
+
+    public static byte[] toByteArray(BufferedImage image, String format) throws IOException {
+        // 使用ByteArrayOutputStream来存储字节数据
+        ByteArrayOutputStream baos = new ByteArrayOutputStream();
+        // 将BufferedImage写入到输出流中,指定格式
+        ImageIO.write(image, format, baos);
+        // 将输出流转换为字节数组
+        return baos.toByteArray();
+    }
+
+    public static void add(Graphics2D g, Map<String, Object> map) {
+        String markContent = (String) map.get("text");
+        g.setColor((Color) map.get("color"));
+        g.setBackground(Color.white);
+
+        AttributedString ats = new AttributedString(markContent);
+        Font f = new Font((String) map.get("fontType"), Font.BOLD,
+                (Integer) map.get("fontSize"));
+        ats.addAttribute(TextAttribute.FONT, f, 0, markContent.length());
+        AttributedCharacterIterator iter = ats.getIterator();
+
+        g.drawString(iter, (Integer) map.get("x"), (Integer) map.get("y")); // 添加水印的文字和设置水印文字出现的内容
+    }
 }