Browse Source

挂号成功

hurugang 6 năm trước cách đây
mục cha
commit
0508224cc1

+ 163 - 0
src/main/java/cn/hnthyy/thmz/Utils/IDCardUtil.java

@@ -0,0 +1,163 @@
+package cn.hnthyy.thmz.Utils;
+
+
+import java.text.SimpleDateFormat;
+import java.util.Calendar;
+import java.util.GregorianCalendar;
+import java.util.Hashtable;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+/**
+ * 身份证号码验证
+ *   1、号码的结构 公民身份号码是特征组合码,由十七位数字本体码和一位校验码组成。排列顺序从左至右依次为:六位数字地址码,八位数字出生日期码,三位数字顺序码和一位数字校验码
+ *   2、地址码(前六位数)表示编码对象常住户口所在县(市、旗、区)的行政区划代码,按GB/T2260的规定执行
+ *   3、出生日期码(第七位至十四位)表示编码对象出生的年、月、日,按GB/T7408的规定执行,年、月、日代码之间不用分隔符
+ *   4、顺序码(第十五位至十七位)表示在同一地址码所标识的区域范围内,对同年、同月、同日出生的人编定的顺序号, 顺序码的奇数分配给男性,偶数分配给女性
+ *   5、校验码(第十八位数)
+ *   (1)十七位数字本体码加权求和公式 S = Sum(iDCardNo * wf), i = 0, ... , 16 ,先对前17位数字的权求和 iDCardNo:表示第i位置上的身份证号码数字值 Wi:表示第i位置上的加权因子 wf: 7 9 10 5 8 4 2 1 6 3 7 9 10 5 8 4 2
+ *   (2)计算模 Y = mod(S, 11) (3)通过模得到对应的校验码 Y: 0 1 2 3 4 5 6 7 8 9 10 校验码: 1 0 X 9 8 7 6 5 4 3 2
+ */
+public class IDCardUtil {
+    /**
+     * 身份证验证
+     *
+     * @param idStr
+     * @return
+     */
+    public static String IdentityCardVerification(String idStr) {
+        String[] wf = {"1", "0", "x", "9", "8", "7", "6", "5", "4", "3", "2"};
+        String[] checkCode = {"7", "9", "10", "5", "8", "4", "2", "1", "6", "3", "7", "9", "10", "5", "8", "4", "2"};
+        String iDCardNo = "";
+        try {
+            //判断号码的长度 15位或18位
+            if (idStr.length() != 15 && idStr.length() != 18) {
+                return "身份证号码长度应该为15位或18位";
+            }
+            if (idStr.length() == 18) {
+                iDCardNo = idStr.substring(0, 17);
+            } else if (idStr.length() == 15) {
+                iDCardNo = idStr.substring(0, 6) + "19" + idStr.substring(6, 15);
+            }
+            if (isStrNum(iDCardNo) == false) {
+                return "身份证15位号码都应为数字;18位号码除最后一位外,都应为数字";
+            }
+            //判断出生年月
+            String strYear = iDCardNo.substring(6, 10);// 年份
+            String strMonth = iDCardNo.substring(10, 12);// 月份
+            String strDay = iDCardNo.substring(12, 14);// 月份
+            if (isStrDate(strYear + "-" + strMonth + "-" + strDay) == false) {
+                return "身份证生日无效";
+            }
+            GregorianCalendar gc = new GregorianCalendar();
+            SimpleDateFormat s = new SimpleDateFormat("yyyy-MM-dd");
+            if ((gc.get(Calendar.YEAR) - Integer.parseInt(strYear)) > 150 || (gc.getTime().getTime() - s.parse(strYear + "-" + strMonth + "-" + strDay).getTime()) < 0) {
+                return "身份证生日不在有效范围";
+            }
+            if (Integer.parseInt(strMonth) > 12 || Integer.parseInt(strMonth) == 0) {
+                return "身份证月份无效";
+            }
+            if (Integer.parseInt(strDay) > 31 || Integer.parseInt(strDay) == 0) {
+                return "身份证日期无效";
+            }
+            //判断地区码
+            Hashtable h = GetAreaCode();
+            if (h.get(iDCardNo.substring(0, 2)) == null) {
+                return "身份证地区编码错误";
+            }
+            //判断最后一位
+            int theLastOne = 0;
+            for (int i = 0; i < 17; i++) {
+                theLastOne = theLastOne + Integer.parseInt(String.valueOf(iDCardNo.charAt(i))) * Integer.parseInt(checkCode[i]);
+            }
+            int modValue = theLastOne % 11;
+            String strVerifyCode = wf[modValue];
+            iDCardNo = iDCardNo + strVerifyCode;
+            if (idStr.length() == 18 && !iDCardNo.equals(idStr)) {
+                return "身份证无效,不是合法的身份证号码";
+            }
+        } catch (Exception e) {
+            e.printStackTrace();
+            return "身份证无效,出现未知错误";
+        }
+        return null;
+    }
+
+    /**
+     * 地区代码
+     *
+     * @return Hashtable
+     */
+    private static Hashtable GetAreaCode() {
+        Hashtable hashtable = new Hashtable();
+        hashtable.put("11", "北京");
+        hashtable.put("12", "天津");
+        hashtable.put("13", "河北");
+        hashtable.put("14", "山西");
+        hashtable.put("15", "内蒙古");
+        hashtable.put("21", "辽宁");
+        hashtable.put("22", "吉林");
+        hashtable.put("23", "黑龙江");
+        hashtable.put("31", "上海");
+        hashtable.put("32", "江苏");
+        hashtable.put("33", "浙江");
+        hashtable.put("34", "安徽");
+        hashtable.put("35", "福建");
+        hashtable.put("36", "江西");
+        hashtable.put("37", "山东");
+        hashtable.put("41", "河南");
+        hashtable.put("42", "湖北");
+        hashtable.put("43", "湖南");
+        hashtable.put("44", "广东");
+        hashtable.put("45", "广西");
+        hashtable.put("46", "海南");
+        hashtable.put("50", "重庆");
+        hashtable.put("51", "四川");
+        hashtable.put("52", "贵州");
+        hashtable.put("53", "云南");
+        hashtable.put("54", "西藏");
+        hashtable.put("61", "陕西");
+        hashtable.put("62", "甘肃");
+        hashtable.put("63", "青海");
+        hashtable.put("64", "宁夏");
+        hashtable.put("65", "新疆");
+        hashtable.put("71", "台湾");
+        hashtable.put("81", "香港");
+        hashtable.put("82", "澳门");
+        hashtable.put("91", "国外");
+        return hashtable;
+    }
+
+    /**
+     * 判断字符串是否为数字
+     *
+     * @param str
+     * @return
+     */
+    private static boolean isStrNum(String str) {
+        Pattern pattern = Pattern.compile("[0-9]*");
+        Matcher isNum = pattern.matcher(str);
+        if (isNum.matches()) {
+            return true;
+        } else {
+            return false;
+        }
+    }
+
+    /**
+     * 判断字符串是否为日期格式
+     *
+     * @param strDate
+     * @return
+     */
+    public static boolean isStrDate(String strDate) {
+        Pattern pattern = Pattern.compile("^((\\d{2}(([02468][048])|([13579][26]))[\\-\\/\\s]?((((0?[13578])|(1[02]))[\\-\\/\\s]?((0?[1-9])|([1-2][0-9])|(3[01])))|(((0?[469])|(11))[\\-\\/\\s]?((0?[1-9])|([1-2][0-9])|(30)))|(0?2[\\-\\/\\s]?((0?[1-9])|([1-2][0-9])))))|(\\d{2}(([02468][1235679])|([13579][01345789]))[\\-\\/\\s]?((((0?[13578])|(1[02]))[\\-\\/\\s]?((0?[1-9])|([1-2][0-9])|(3[01])))|(((0?[469])|(11))[\\-\\/\\s]?((0?[1-9])|([1-2][0-9])|(30)))|(0?2[\\-\\/\\s]?((0?[1-9])|(1[0-9])|(2[0-8]))))))(\\s(((0?[0-9])|([1-2][0-3]))\\:([0-5]?[0-9])((\\s)|(\\:([0-5]?[0-9])))))?$");
+        Matcher m = pattern.matcher(strDate);
+        if (m.matches()) {
+            return true;
+        } else {
+            return false;
+        }
+    }
+
+}

+ 47 - 16
src/main/java/cn/hnthyy/thmz/Utils/StringUtil.java

@@ -13,8 +13,8 @@ import java.util.regex.Pattern;
 public class StringUtil {
     /**
      * 判断字符串中是否包含中文
-     * @param str
-     * 待校验字符串
+     *
+     * @param str 待校验字符串
      * @return 是否为中文
      * @warn 不能校验是否为中文标点符号
      */
@@ -29,6 +29,7 @@ public class StringUtil {
 
     /**
      * 过滤掉中文
+     *
      * @param str 待过滤中文的字符串
      * @return 过滤掉中文后字符串
      */
@@ -63,8 +64,7 @@ public class StringUtil {
     /**
      * 校验一个字符是否是汉字
      *
-     * @param c
-     *  被校验的字符
+     * @param c 被校验的字符
      * @return true代表是汉字
      */
     public static boolean isChineseChar(char c) {
@@ -80,14 +80,14 @@ public class StringUtil {
      * 验证字符串内容是否包含下列非法字符<br>
      * `~!#%^&*=+\\|{};:'\",<>/?○●★☆☉♀♂※¤╬の〆
      *
-     * @param content
-     *  字符串内容
+     * @param content 字符串内容
      * @return 't'代表不包含非法字符,otherwise代表包含非法字符。
      */
     public static char validateLegalString(String content) {
         String illegal = "`~!#%^&*=+\\|{};:'\",<>/?○●★☆☉♀♂※¤╬の〆";
         char isLegalChar = 't';
-        L1: for (int i = 0; i < content.length(); i++) {
+        L1:
+        for (int i = 0; i < content.length(); i++) {
             for (int j = 0; j < illegal.length(); j++) {
                 if (content.charAt(i) == illegal.charAt(j)) {
                     isLegalChar = content.charAt(i);
@@ -101,8 +101,7 @@ public class StringUtil {
     /**
      * 验证是否是汉字或者0-9、a-z、A-Z
      *
-     * @param c
-     *  被验证的char
+     * @param c 被验证的char
      * @return true代表符合条件
      */
     public static boolean isRightChar(char c) {
@@ -112,8 +111,7 @@ public class StringUtil {
     /**
      * 校验某个字符是否是a-z、A-Z、_、0-9
      *
-     * @param c
-     *  被校验的字符
+     * @param c 被校验的字符
      * @return true代表符合条件
      */
     public static boolean isWord(char c) {
@@ -126,8 +124,7 @@ public class StringUtil {
     /**
      * 判定输入的是否是汉字
      *
-     * @param c
-     *  被校验的字符
+     * @param c 被校验的字符
      * @return true代表是汉字
      */
     public static boolean isChinese(char c) {
@@ -146,8 +143,7 @@ public class StringUtil {
     /**
      * 校验String是否全是中文
      *
-     * @param name
-     *  被校验的字符串
+     * @param name 被校验的字符串
      * @return true代表全是汉字
      */
     public static boolean checkNameChese(String name) {
@@ -164,6 +160,7 @@ public class StringUtil {
 
     /**
      * 字符串转成list
+     *
      * @param ids
      * @return
      */
@@ -171,9 +168,43 @@ public class StringUtil {
         if (StringUtils.isNotBlank(ids)) {
             String[] arr = ids.split(",");
             if (arr != null && arr.length > 0) {
-                return  Arrays.asList(arr);
+                return Arrays.asList(arr);
             }
         }
         return null;
     }
+
+    /**
+     * 手机号校验,如果返回为空,说明手机号正确
+     * <p>
+     * 中国电信号段 133、149、153、173、177、180、181、189、199
+     * 中国联通号段 130、131、132、145、155、156、166、175、176、185、186
+     * 中国移动号段 134(0-8)、135、136、137、138、139、147、150、151、152、157、158、159、178、182、183、184、187、188、198
+     * 其他号段
+     * 14号段以前为上网卡专属号段,如中国联通的是145,中国移动的是147等等。
+     * 虚拟运营商
+     * 电信:1700、1701、1702
+     * 移动:1703、1705、1706
+     * 联通:1704、1707、1708、1709、171
+     * 卫星通信:1349
+     *
+     * @param phone
+     * @return
+     */
+    public static String isPhone(String phone) {
+        String regex = "^((13[0-9])|(14[5,7,9])|(15([0-3]|[5-9]))|(166)|(17[0,1,3,5,6,7,8])|(18[0-9])|(19[8|9]))\\d{8}$";
+        if (phone.length() != 11) {
+            return "手机号应为11位数";
+        } else {
+            Pattern p = Pattern.compile(regex);
+            Matcher m = p.matcher(phone);
+            boolean isMatch = m.matches();
+            if (!isMatch) {
+                return "请填入正确的手机号";
+            }
+            return null;
+        }
+    }
+
+
 }

+ 119 - 19
src/main/java/cn/hnthyy/thmz/controller/MzPatientMiController.java

@@ -1,16 +1,18 @@
 package cn.hnthyy.thmz.controller;
 
+import cn.hnthyy.thmz.Utils.IDCardUtil;
+import cn.hnthyy.thmz.Utils.StringUtil;
 import cn.hnthyy.thmz.comment.UserLoginToken;
+import cn.hnthyy.thmz.entity.his.MzPatientMi;
 import cn.hnthyy.thmz.service.his.MzPatientMiService;
+import cn.hnthyy.thmz.service.his.MzSerialNoService;
 import lombok.extern.slf4j.Slf4j;
 import org.apache.commons.lang3.StringUtils;
 import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RequestMethod;
-import org.springframework.web.bind.annotation.RequestParam;
-import org.springframework.web.bind.annotation.RestController;
+import org.springframework.web.bind.annotation.*;
 
 import java.util.HashMap;
+import java.util.List;
 import java.util.Map;
 
 @Slf4j
@@ -18,9 +20,12 @@ import java.util.Map;
 public class MzPatientMiController {
     @Autowired
     private MzPatientMiService mzPatientMiService;
+    @Autowired
+    private MzSerialNoService mzSerialNoService;
 
     /**
      * 根据病人就诊卡号查询病人信息
+     *
      * @return
      */
     @UserLoginToken
@@ -29,7 +34,7 @@ public class MzPatientMiController {
         log.info("根据病人就诊卡号查询病人信息");
         Map<String, Object> resultMap = new HashMap<>();
         try {
-            if(StringUtils.isBlank(icCardNo)){
+            if (StringUtils.isBlank(icCardNo)) {
                 resultMap.put("code", -1);
                 resultMap.put("message", "就诊卡号不能为空");
                 return resultMap;
@@ -38,40 +43,40 @@ public class MzPatientMiController {
             resultMap.put("message", "查询病人信息成功");
             resultMap.put("data", mzPatientMiService.queryByIcCardNo(icCardNo));
             return resultMap;
-        }catch (Exception e){
+        } catch (Exception e) {
             resultMap.put("code", -1);
             resultMap.put("message", "系统出错,请联系管理员");
-            log.error("系统异常,错误信息{}",e.getMessage());
+            log.error("系统异常,错误信息{}", e.getMessage());
             return resultMap;
         }
     }
 
 
-
     /**
      * 根据病人姓名查询病人信息
+     *
      * @return
      */
     @UserLoginToken
     @RequestMapping(value = "/getPatientMiByName", method = {RequestMethod.GET})
-    public Map<String, Object> getPatientMiByName(@RequestParam("name") String name,@RequestParam("pageIndex") Integer pageIndex) {
+    public Map<String, Object> getPatientMiByName(@RequestParam("name") String name, @RequestParam("pageIndex") Integer pageIndex) {
         log.info("根据病人姓名查询病人信息");
         Map<String, Object> resultMap = new HashMap<>();
         try {
-            if(StringUtils.isBlank(name)){
-                name=null;
+            if (StringUtils.isBlank(name)) {
+                name = null;
             }
-            if(pageIndex==null){
-                pageIndex=1;
+            if (pageIndex == null) {
+                pageIndex = 1;
             }
             resultMap.put("code", 0);
             resultMap.put("message", "查询病人信息成功");
-            resultMap.put("data", mzPatientMiService.queryByNameFuzzy(name,pageIndex,10));
+            resultMap.put("data", mzPatientMiService.queryByNameFuzzy(name, pageIndex, 10));
             return resultMap;
-        }catch (Exception e){
+        } catch (Exception e) {
             resultMap.put("code", -1);
             resultMap.put("message", "系统出错,请联系管理员");
-            log.error("系统异常,错误信息{}",e.getMessage());
+            log.error("系统异常,错误信息{}", e.getMessage());
             return resultMap;
         }
     }
@@ -79,6 +84,7 @@ public class MzPatientMiController {
 
     /**
      * 根据病人ID查询病人信息
+     *
      * @return
      */
     @UserLoginToken
@@ -86,7 +92,7 @@ public class MzPatientMiController {
     public Map<String, Object> getByPatientId(@RequestParam("patientId") String patientId) {
         Map<String, Object> resultMap = new HashMap<>();
         try {
-            if(StringUtils.isBlank(patientId)){
+            if (StringUtils.isBlank(patientId)) {
                 resultMap.put("code", -1);
                 resultMap.put("message", "病人id不能为空");
                 return resultMap;
@@ -95,10 +101,104 @@ public class MzPatientMiController {
             resultMap.put("message", "根据病人ID查询病人信息成功");
             resultMap.put("data", mzPatientMiService.queryByPatientId(patientId));
             return resultMap;
-        }catch (Exception e){
+        } catch (Exception e) {
             resultMap.put("code", -1);
             resultMap.put("message", "系统出错,请联系管理员");
-            log.error("系统异常,错误信息{}",e.getMessage());
+            log.error("系统异常,错误信息{}", e.getMessage());
+            return resultMap;
+        }
+    }
+
+
+    /**
+     * 新增病人信息
+     *
+     * @return
+     */
+    @UserLoginToken
+    @RequestMapping(value = "/savePatient", method = {RequestMethod.POST})
+    public Map<String, Object> savePatient(@RequestBody MzPatientMi mzPatientMi) {
+        Map<String, Object> resultMap = new HashMap<>();
+        try {
+            if (mzPatientMi == null) {
+                resultMap.put("code", -1);
+                resultMap.put("message", "病人信息不能为空");
+                return resultMap;
+            }
+            if (StringUtils.isBlank(mzPatientMi.getName())) {
+                resultMap.put("code", -1);
+                resultMap.put("message", "病人姓名不能为空");
+                return resultMap;
+            }
+            if (mzPatientMi.getAge() == null) {
+                resultMap.put("code", -1);
+                resultMap.put("message", "病人年龄不能为空");
+                return resultMap;
+            }
+            if (mzPatientMi.getSex() == null) {
+                resultMap.put("code", -1);
+                resultMap.put("message", "病人性别不能为空");
+                return resultMap;
+            }
+            if (mzPatientMi.getBirthDay() == null) {
+                resultMap.put("code", -1);
+                resultMap.put("message", "病人出生日期不能为空");
+                return resultMap;
+            }
+            if (StringUtils.isBlank(mzPatientMi.getIcCardNo())) {
+                resultMap.put("code", -1);
+                resultMap.put("message", "病人卡号不能为空");
+                return resultMap;
+            }
+            if (StringUtils.isBlank(mzPatientMi.getPhoneNo())) {
+                resultMap.put("code", -1);
+                resultMap.put("message", "病人手机号码不能为空");
+                return resultMap;
+            }
+            if (StringUtils.isBlank(mzPatientMi.getResponseType())) {
+                resultMap.put("code", -1);
+                resultMap.put("message", "病人性质不能为空");
+                return resultMap;
+            }
+            if (StringUtils.isBlank(mzPatientMi.getSocialNo())) {
+                resultMap.put("code", -1);
+                resultMap.put("message", "病人身份证号码不能为空");
+                return resultMap;
+            }
+            //校验身份证号码格式
+            String checkResult = IDCardUtil.IdentityCardVerification(mzPatientMi.getSocialNo());
+            if (StringUtils.isNotBlank(checkResult)) {
+                resultMap.put("code", -1);
+                resultMap.put("message", checkResult);
+                return resultMap;
+            }
+            //校验手机号码格式
+            checkResult = StringUtil.isPhone(mzPatientMi.getPhoneNo());
+            if (StringUtils.isNotBlank(checkResult)) {
+                resultMap.put("code", -1);
+                resultMap.put("message", checkResult);
+                return resultMap;
+            }
+            List<MzPatientMi> mzPatientMis=mzPatientMiService.queryBySocialNo(mzPatientMi.getSocialNo());
+            if(mzPatientMis!=null && mzPatientMis.size()>0){
+                resultMap.put("code", -1);
+                resultMap.put("message", "保存病人信息失败,已经存在相同的身份证号码记录");
+                return resultMap;
+            }
+            int num=mzPatientMiService.saveMzPatientMi(mzPatientMi);
+            if(num==1){
+                resultMap.put("code", 0);
+                resultMap.put("message", "保存病人信息成功");
+                resultMap.put("data",mzPatientMi);
+                return resultMap;
+            }
+            resultMap.put("code", -1);
+            resultMap.put("message", "保存病人信息失败");
+            return resultMap;
+        } catch (Exception e) {
+            resultMap.put("code", -1);
+            resultMap.put("message", StringUtils.isBlank(e.getMessage())?"系统出错,请联系管理员":e.getMessage());
+            log.error("系统异常,错误信息{}", e.getMessage());
             return resultMap;
         }
     }

+ 5 - 4
src/main/java/cn/hnthyy/thmz/entity/his/MzPatientMi.java

@@ -28,10 +28,10 @@ public class MzPatientMi {
     private Integer baddebtMark;
     //病人身份
     private String responseType;
-    //费用类别 1-普通 2 -儿科
+    //费用类别 1-普通 2 -儿科 无特殊意义了
     private String chargeType;
     //就诊次数
-    private Integer times;
+    private Integer times=1;
     //预约删除标志
     private Integer reqdelMark;
     //年龄
@@ -50,9 +50,10 @@ public class MzPatientMi {
     private String firstDate;
     //联系人
     private String relName;
-    //最后一次访问日期
+
+    //最后一次访问日期 字符串
     private String lvDateStr;
-    //出生日期
+    //出生日期 字符串
     private String birthDayStr;
 
     public void setLvDate(Date lvDate) {

+ 74 - 0
src/main/java/cn/hnthyy/thmz/mapper/his/MzPatientMiMapper.java

@@ -1,8 +1,10 @@
 package cn.hnthyy.thmz.mapper.his;
 
 import cn.hnthyy.thmz.entity.his.MzPatientMi;
+import org.apache.ibatis.annotations.Insert;
 import org.apache.ibatis.annotations.Param;
 import org.apache.ibatis.annotations.Select;
+import org.apache.ibatis.annotations.Update;
 
 import java.util.List;
 
@@ -46,4 +48,76 @@ public interface MzPatientMiMapper {
             "rtrim(ic_card_no) ic_card_no,rtrim(phone_no) phone_no,rtrim(adress) address,rtrim(yb_card_no) yb_card_no,first_date,rtrim(rel_name) rel_name from mz_patient_mi  where  patient_id =#{patientId}")
     MzPatientMi selectByPatientId(@Param("patientId") String patientId);
 
+    /**
+     * 保存病人信息
+     * @param mzPatientMi
+     * @return
+     */
+    @Insert("INSERT INTO mz_patient_mi(social_no,name,sex,lv_date,patient_id,response_type,charge_type,times,age,birth_day,ic_card_no,phone_no,adress) " +
+            "VALUES(#{socialNo,jdbcType=CHAR},#{name,jdbcType=CHAR},#{sex,jdbcType=CHAR},#{lvDate,jdbcType=TIMESTAMP},#{patientId,jdbcType=CHAR},#{responseType,jdbcType=CHAR}," +
+            "#{chargeType,jdbcType=CHAR},#{times,jdbcType=INTEGER},#{age,jdbcType=TINYINT},#{birthDay,jdbcType=TIMESTAMP},#{icCardNo,jdbcType=CHAR},#{phoneNo,jdbcType=CHAR}," +
+            "#{address,jdbcType=CHAR}) ")
+    int insertMzPatientMi(MzPatientMi mzPatientMi);
+
+
+    /**
+     * 更新病人信息
+     * @param mzPatientMi
+     * @return
+     */
+    @Update({"<script>",
+            "update mz_patient_mi ",
+              "<trim prefix='set' prefixOverrides=',' suffix=' where patient_id =#{patientId,jdbcType=CHAR}' >",
+                 "<when test='socialNo!=null'>",
+                    "social_no =#{socialNo,jdbcType=CHAR}",
+                 "</when>",
+                 "<when test='name!=null'>",
+                    ",name =#{name,jdbcType=CHAR}",
+                 "</when>",
+                 "<when test='sex!=null'>",
+                   ",sex =#{sex,jdbcType=CHAR}",
+                 "</when>",
+                 "<when test='lvDate!=null'>",
+                    ",lv_date =#{lvDate,jdbcType=TIMESTAMP}",
+                 "</when>",
+                 "<when test='responseType!=null'>",
+                    ",response_type =#{responseType,jdbcType=CHAR}",
+                 "</when>",
+                 "<when test='chargeType!=null'>",
+                    ",charge_type =#{chargeType,jdbcType=CHAR}",
+                 "</when>",
+                 "<when test='times!=null'>",
+                    ",times =#{name,jdbcType=CHAR}",
+                 "</when>",
+                 "<when test='age!=null'>",
+                    ",age =#{age,jdbcType=TINYINT}",
+                 "</when>",
+                 "<when test='birthDay!=null'>",
+                    ",birth_day =#{birthDay,jdbcType=TIMESTAMP}",
+                 "</when>",
+                 "<when test='icCardNo!=null'>",
+                    ",ic_card_no =#{icCardNo,jdbcType=CHAR}",
+                 "</when>",
+                 "<when test='birthDay!=null'>",
+                    ",phone_no =#{phoneNo,jdbcType=CHAR}",
+                 "</when>",
+                 "<when test='adress!=null'>",
+                    ",adress =#{address,jdbcType=CHAR}",
+                 "</when>",
+              "</trim>"
+            ,"</script>"})
+    int updateMzPatientMi(MzPatientMi mzPatientMi);
+
+    /**
+     * 按照身份证号码查询病人信息
+     * @param socialNo
+     * @return
+     */
+    @Select("select rtrim(social_no) social_no,rtrim(hic_no) hic_no,rtrim(name) name,rtrim(sex) sex,lv_date,rtrim(patient_id) patient_id,rtrim(p_bar_code) p_bar_code," +
+            "rtrim(baddebt_mark) baddebt_mark,rtrim(response_type) response_type,rtrim(charge_type) charge_type,times,rtrim(reqdel_mark) reqdel_mark,age,birth_day," +
+            "rtrim(ic_card_no) ic_card_no,rtrim(phone_no) phone_no,rtrim(adress) address,rtrim(yb_card_no) yb_card_no,first_date,rtrim(rel_name) rel_name from mz_patient_mi  where  social_no =#{socialNo}")
+    List<MzPatientMi> selectBySocialNo(@Param("socialNo") String socialNo);
+
+
+
 }

+ 3 - 3
src/main/java/cn/hnthyy/thmz/mapper/his/MzSerialNoMapper.java

@@ -9,7 +9,7 @@ public interface MzSerialNoMapper {
      * 查询序列号记录
      * @return
      */
-    @Select("select serial_no,outpatient_no,inject_no,serial_out,prior_no,serial_new,hzyl_no from mz_serial_no")
+    @Select("select serial_no,rtrim(outpatient_no) outpatient_no,inject_no,serial_out,prior_no,serial_new,hzyl_no from mz_serial_no")
     MzSerialNo selectMzSerialNo();
 
     /**
@@ -24,10 +24,10 @@ public interface MzSerialNoMapper {
                   "outpatient_no =#{newOutpatientNo,jdbcType=VARCHAR}",
                "</when>",
                "<when test='newSerialOut!=null'>",
-                  "serial_out =#{newSerialOut,jdbcType=INTEGER}",
+                  ",serial_out =#{newSerialOut,jdbcType=INTEGER}",
                "</when>",
                "<when test='newSerialNew!=null'>",
-                  "serial_new =#{newSerialNew,jdbcType=INTEGER}",
+                  ",serial_new =#{newSerialNew,jdbcType=INTEGER}",
                "</when>",
             "</trim>"
             ,"</script>"})

+ 19 - 0
src/main/java/cn/hnthyy/thmz/service/his/MzPatientMiService.java

@@ -27,5 +27,24 @@ public interface MzPatientMiService {
      */
     MzPatientMi queryByPatientId(String patientId);
 
+    /**
+     * 保存病人信息
+     * @param mzPatientMi
+     * @return
+     */
+    int saveMzPatientMi(MzPatientMi mzPatientMi) throws Exception;
+
+    /**
+     * 更新病人信息
+     * @param mzPatientMi
+     * @return
+     */
+    int modifyMzPatientMi(MzPatientMi mzPatientMi);
 
+    /**
+     * 按照身份证号码查询病人信息
+     * @param socialNo
+     * @return
+     */
+    List<MzPatientMi> queryBySocialNo(String socialNo);
 }

+ 27 - 0
src/main/java/cn/hnthyy/thmz/service/impl/his/MzPatientMiServiceImpl.java

@@ -3,16 +3,20 @@ package cn.hnthyy.thmz.service.impl.his;
 import cn.hnthyy.thmz.entity.his.MzPatientMi;
 import cn.hnthyy.thmz.mapper.his.MzPatientMiMapper;
 import cn.hnthyy.thmz.service.his.MzPatientMiService;
+import cn.hnthyy.thmz.service.his.MzSerialNoService;
 import org.apache.commons.lang3.StringUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
+import java.util.Date;
 import java.util.List;
 @Service
 public class MzPatientMiServiceImpl implements MzPatientMiService {
     @SuppressWarnings("all")
     @Autowired
     private MzPatientMiMapper mzPatientMiMapper;
+    @Autowired
+    private MzSerialNoService mzSerialNoService;
     @Override
     public MzPatientMi queryByIcCardNo(String icCardNo) {
         return mzPatientMiMapper.selectByIcCardNo(icCardNo);
@@ -30,4 +34,27 @@ public class MzPatientMiServiceImpl implements MzPatientMiService {
     public MzPatientMi queryByPatientId(String patientId) {
         return mzPatientMiMapper.selectByPatientId(patientId);
     }
+
+    @Override
+    public int saveMzPatientMi(MzPatientMi mzPatientMi) throws Exception {
+        mzPatientMi.setLvDate(new Date());
+        String patientNo=mzSerialNoService.getMzPatientNo();
+        mzPatientMi.setPatientId(patientNo);
+        return mzPatientMiMapper.insertMzPatientMi(mzPatientMi);
+    }
+
+    @Override
+    public int modifyMzPatientMi(MzPatientMi mzPatientMi) {
+        if(StringUtils.isBlank(mzPatientMi.getPatientId())){
+            return 0;
+        }
+        return mzPatientMiMapper.updateMzPatientMi(mzPatientMi);
+    }
+
+    @Override
+    public List<MzPatientMi> queryBySocialNo(String socialNo) {
+        return mzPatientMiMapper.selectBySocialNo(socialNo);
+    }
+
+
 }

+ 88 - 36
src/main/resources/static/js/registration.js

@@ -191,44 +191,22 @@ $(function () {
     //     }
     // });
 
-
+    /**
+     * 保存挂号信息
+     */
     $("#saveConfirmFee").on("click",function (t) {
-        var mzyRequestId = $('#doctor').find("option:selected").attr('data-mzyRequestId');
-        $.ajax({
-            type: "POST",
-            url: '/thmz/saveMzyReqrec',
-            contentType: "application/json;charset=UTF-8",
-            dataType: "json",
-            data:JSON.stringify({"mzyReqrec":{"patientId":$("#patientId").val(),"ampm":$("#ampm").val(),"unitCode":$("#deptNo").val(),"chargeType":$("#chargeType").val()},"responceType":$("#patientsNature").val(),"mzyRequestId":mzyRequestId}),
-            headers: {'Accept': 'application/json', 'Authorization': 'Bearer ' + localStorage.getItem("token")},
-            success: function (res) {
-                if (res == '401' || res == 401) {
-                    window.location.href = '/thmz/login/view'
-                    return;
-                }
-                if (res.code == 0) {
-                    new PNotify({
-                        title: '操作提示',
-                        text: res.message,
-                        type: 'success',
-                        hide: true,
-                        styling: 'bootstrap3'
-                    });
-                    $('#confirmFeeModal').modal('hide');
-                } else {
-                    new PNotify({
-                        title: '错误提示',
-                        text: res.message,
-                        type: 'error',
-                        hide: true,
-                        styling: 'bootstrap3'
-                    });
-                }
-            }
-        });
-    });
+        var patientId=$("#patientId").val();
+        if(patientId==null || patientId==""){
+            savePatient();
+        }else {
+            saveMzyReqrec();
+        }
 
+    });
 
+    /**
+     * 设置窗口号
+     */
     $("#editWindows").on("click",function (t) {
         $.ajax({
             type: "GET",
@@ -1048,6 +1026,9 @@ function clearTextOrTitle(obj) {
         $(obj).attr("title", null);
     } else {
         $(obj).attr("title", $(obj).val());
+        if($(obj).attr("id")=="birthDay"){
+            $(obj).blur()
+        }
     }
 }
 
@@ -1085,7 +1066,7 @@ function readonlyOrNot(flag) {
         $("#birthDayGroup").removeClass("hide").addClass("in");
         $("#userName").removeClass("hide").addClass("in");
         $("#userNameReadOnly").removeClass("in").addClass("hide");
-        $("#webuiPopover0").css("display", "block");
+        //$("#webuiPopover0").css("display", "block");
     }
 
 }
@@ -1127,4 +1108,75 @@ function saveWindows() {
             }
         }
     });
+}
+
+/**
+ * 保存病人信息
+ */
+function savePatient() {
+    $.ajax({
+        type: "POST",
+        url: '/thmz/savePatient',
+        contentType: "application/json;charset=UTF-8",
+        dataType: "json",
+        data:JSON.stringify({"name":$("#userName").val(),"age":$("#age").val(),"sex":$("#gender").val(),"birthDay":$("#birthDay").val(),"icCardNo":$("#cardNo").val(),"phoneNo":$("#phoneNum").val(),"responseType":$("#patientsNature").val(),"socialNo":$("#idCard").val(),"address":$("#address").val()}),
+        headers: {'Accept': 'application/json', 'Authorization': 'Bearer ' + localStorage.getItem("token")},
+        success: function (res) {
+            if (res == '401' || res == 401) {
+                window.location.href = '/thmz/login/view'
+                return;
+            }
+            if (res.code == 0) {
+               $("#patientId").val(res.data.patientId);
+                saveMzyReqrec();
+            } else {
+                new PNotify({
+                    title: '错误提示',
+                    text: res.message,
+                    type: 'error',
+                    hide: true,
+                    styling: 'bootstrap3'
+                });
+            }
+        }
+    });
+}
+
+/**
+ * 保存挂号信息
+ */
+function saveMzyReqrec() {
+    var mzyRequestId = $('#doctor').find("option:selected").attr('data-mzyRequestId');
+    $.ajax({
+        type: "POST",
+        url: '/thmz/saveMzyReqrec',
+        contentType: "application/json;charset=UTF-8",
+        dataType: "json",
+        data:JSON.stringify({"mzyReqrec":{"patientId":$("#patientId").val(),"ampm":$("#ampm").val(),"unitCode":$("#deptNo").val(),"chargeType":$("#chargeType").val()},"responceType":$("#patientsNature").val(),"mzyRequestId":mzyRequestId}),
+        headers: {'Accept': 'application/json', 'Authorization': 'Bearer ' + localStorage.getItem("token")},
+        success: function (res) {
+            if (res == '401' || res == 401) {
+                window.location.href = '/thmz/login/view'
+                return;
+            }
+            if (res.code == 0) {
+                new PNotify({
+                    title: '操作提示',
+                    text: res.message,
+                    type: 'success',
+                    hide: true,
+                    styling: 'bootstrap3'
+                });
+                $('#confirmFeeModal').modal('hide');
+            } else {
+                new PNotify({
+                    title: '错误提示',
+                    text: res.message,
+                    type: 'error',
+                    hide: true,
+                    styling: 'bootstrap3'
+                });
+            }
+        }
+    });
 }

+ 3 - 3
src/main/resources/templates/menu.html

@@ -170,7 +170,7 @@
         </div>
 
         <!-- top navigation -->
-        <div class="top_nav">
+        <div class="top_nav" style="min-width: 1653px;">
             <div class="nav_menu">
                 <nav>
                     <div class="nav toggle">
@@ -258,7 +258,7 @@
         <!-- /top navigation -->
 
         <!-- page content -->
-        <div class="right_col" role="main">
+        <div class="right_col" role="main" style="min-width: 1653px;">
             <div th:include="profile_image::profile_image"></div>
             <div id="content">
             </div>
@@ -266,7 +266,7 @@
         <!-- /page content -->
 
         <!-- footer content -->
-        <footer>
+        <footer style="min-width: 1653px;">
             <div class="pull-right">
                 Gentelella - Bootstrap Admin Template by <a href="https://colorlib.com">Colorlib</a>
             </div>

+ 11 - 8
src/main/resources/templates/registration.html

@@ -157,13 +157,16 @@
                         </select>
                     </div>
                 </div>
-                <div class="col-md-6 col-sm-6 col-xs-12 item thmz_group_alert">
-                    <label class="control-label col-md-4 col-sm-4 col-xs-12" for="idCard">身份证 <span
+            </div>
+
+            <div class="item form-group thmz_alert">
+                <div class="col-md-12 col-sm-12 col-xs-12 item thmz_group_alert">
+                    <label class="control-label col-md-2 col-sm-2 col-xs-12" for="idCard" style="left: -3px;">身份证 <span
                             class="required">*</span>
                     </label>
-                    <div class="col-md-8 col-sm-8 col-xs-12">
+                    <div class="col-md-10 col-sm-10 col-xs-12">
                         <div class="input-group demo2">
-                            <input id="idCard" class="form-control col-md-7 col-xs-12" type="text"
+                            <input id="idCard" class="form-control" type="text"
                                    data-validate-length-range="18,18"
                                    placeholder="请输入" required="required">
                             <span class="input-group-addon"><a href="#"><i class="fa fa-newspaper-o"></i></a></span>
@@ -173,11 +176,11 @@
             </div>
 
             <div class="item form-group thmz_alert">
-                <div class="col-md-6 col-sm-6 col-xs-12 item">
-                    <label class="control-label col-md-4 col-sm-4 col-xs-12" for="address">地址
+                <div class="col-md-12 col-sm-12 col-xs-12 item">
+                    <label class="control-label col-md-2 col-sm-2 col-xs-12" for="address" style="left: -3px;">地址
                     </label>
-                    <div class="col-md-8 col-sm-8 col-xs-12">
-                        <input id="address" class="form-control col-md-7 col-xs-12 optional" type="text"
+                    <div class="col-md-10 col-sm-10 col-xs-12">
+                        <input id="address" class="form-control optional" type="text"
                                data-validate-length-range="0,25"
                                placeholder="请输入">
                     </div>

+ 187 - 0
src/test/java/cn/hnthyy/thmz/JunitIDCardTest.java

@@ -0,0 +1,187 @@
+package cn.hnthyy.thmz;
+
+import org.junit.Test;
+
+import java.text.SimpleDateFormat;
+import java.util.Calendar;
+import java.util.GregorianCalendar;
+import java.util.Hashtable;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+/**
+ * 身份证号码验证
+ *   1、号码的结构 公民身份号码是特征组合码,由十七位数字本体码和一位校验码组成。排列顺序从左至右依次为:六位数字地址码,八位数字出生日期码,三位数字顺序码和一位数字校验码
+ *   2、地址码(前六位数)表示编码对象常住户口所在县(市、旗、区)的行政区划代码,按GB/T2260的规定执行
+ *   3、出生日期码(第七位至十四位)表示编码对象出生的年、月、日,按GB/T7408的规定执行,年、月、日代码之间不用分隔符
+ *   4、顺序码(第十五位至十七位)表示在同一地址码所标识的区域范围内,对同年、同月、同日出生的人编定的顺序号, 顺序码的奇数分配给男性,偶数分配给女性
+ *   5、校验码(第十八位数)
+ *   (1)十七位数字本体码加权求和公式 S = Sum(iDCardNo * wf), i = 0, ... , 16 ,先对前17位数字的权求和 iDCardNo:表示第i位置上的身份证号码数字值 Wi:表示第i位置上的加权因子 wf: 7 9 10 5 8 4 2 1 6 3 7 9 10 5 8 4 2
+ *   (2)计算模 Y = mod(S, 11) (3)通过模得到对应的校验码 Y: 0 1 2 3 4 5 6 7 8 9 10 校验码: 1 0 X 9 8 7 6 5 4 3 2
+ */
+public class JunitIDCardTest {
+
+    @Test
+    public void test() {
+        System.out.println(IdentityCardVerification("110101199003074370"));
+        System.out.println(isPhone("12842524626"));
+    }
+
+
+    public static String isPhone(String phone) {
+        String regex = "^((13[0-9])|(14[5,7,9])|(15([0-3]|[5-9]))|(166)|(17[0,1,3,5,6,7,8])|(18[0-9])|(19[8|9]))\\d{8}$";
+        if (phone.length() != 11) {
+            return "手机号应为11位数";
+        } else {
+            Pattern p = Pattern.compile(regex);
+            Matcher m = p.matcher(phone);
+            boolean isMatch = m.matches();
+            if (!isMatch) {
+                return "请填入正确的手机号";
+            }
+            return null;
+        }
+    }
+
+    /**
+     * 身份证验证
+     *
+     * @param idStr
+     * @return
+     */
+    public static String IdentityCardVerification(String idStr) {
+        String[] wf = {"1", "0", "x", "9", "8", "7", "6", "5", "4", "3", "2"};
+        String[] checkCode = {"7", "9", "10", "5", "8", "4", "2", "1", "6", "3", "7", "9", "10", "5", "8", "4", "2"};
+        String iDCardNo = "";
+        try {
+            //判断号码的长度 15位或18位
+            if (idStr.length() != 15 && idStr.length() != 18) {
+                return "身份证号码长度应该为15位或18位";
+            }
+            if (idStr.length() == 18) {
+                iDCardNo = idStr.substring(0, 17);
+            } else if (idStr.length() == 15) {
+                iDCardNo = idStr.substring(0, 6) + "19" + idStr.substring(6, 15);
+            }
+            if (isStrNum(iDCardNo) == false) {
+                return "身份证15位号码都应为数字;18位号码除最后一位外,都应为数字";
+            }
+            //判断出生年月
+            String strYear = iDCardNo.substring(6, 10);// 年份
+            String strMonth = iDCardNo.substring(10, 12);// 月份
+            String strDay = iDCardNo.substring(12, 14);// 月份
+            if (isStrDate(strYear + "-" + strMonth + "-" + strDay) == false) {
+                return "身份证生日无效";
+            }
+            GregorianCalendar gc = new GregorianCalendar();
+            SimpleDateFormat s = new SimpleDateFormat("yyyy-MM-dd");
+            if ((gc.get(Calendar.YEAR) - Integer.parseInt(strYear)) > 150 || (gc.getTime().getTime() - s.parse(strYear + "-" + strMonth + "-" + strDay).getTime()) < 0) {
+                return "身份证生日不在有效范围";
+            }
+            if (Integer.parseInt(strMonth) > 12 || Integer.parseInt(strMonth) == 0) {
+                return "身份证月份无效";
+            }
+            if (Integer.parseInt(strDay) > 31 || Integer.parseInt(strDay) == 0) {
+                return "身份证日期无效";
+            }
+            //判断地区码
+            Hashtable h = GetAreaCode();
+            if (h.get(iDCardNo.substring(0, 2)) == null) {
+                return "身份证地区编码错误";
+            }
+            //判断最后一位
+            int theLastOne = 0;
+            for (int i = 0; i < 17; i++) {
+                theLastOne = theLastOne + Integer.parseInt(String.valueOf(iDCardNo.charAt(i))) * Integer.parseInt(checkCode[i]);
+            }
+            int modValue = theLastOne % 11;
+            String strVerifyCode = wf[modValue];
+            iDCardNo = iDCardNo + strVerifyCode;
+            if (idStr.length() == 18 && !iDCardNo.equals(idStr)) {
+                return "身份证无效,不是合法的身份证号码";
+            }
+        } catch (Exception e) {
+            e.printStackTrace();
+            return "身份证无效,出现未知错误";
+        }
+        return null;
+    }
+
+    /**
+     * 地区代码
+     *
+     * @return Hashtable
+     */
+    private static Hashtable GetAreaCode() {
+        Hashtable hashtable = new Hashtable();
+        hashtable.put("11", "北京");
+        hashtable.put("12", "天津");
+        hashtable.put("13", "河北");
+        hashtable.put("14", "山西");
+        hashtable.put("15", "内蒙古");
+        hashtable.put("21", "辽宁");
+        hashtable.put("22", "吉林");
+        hashtable.put("23", "黑龙江");
+        hashtable.put("31", "上海");
+        hashtable.put("32", "江苏");
+        hashtable.put("33", "浙江");
+        hashtable.put("34", "安徽");
+        hashtable.put("35", "福建");
+        hashtable.put("36", "江西");
+        hashtable.put("37", "山东");
+        hashtable.put("41", "河南");
+        hashtable.put("42", "湖北");
+        hashtable.put("43", "湖南");
+        hashtable.put("44", "广东");
+        hashtable.put("45", "广西");
+        hashtable.put("46", "海南");
+        hashtable.put("50", "重庆");
+        hashtable.put("51", "四川");
+        hashtable.put("52", "贵州");
+        hashtable.put("53", "云南");
+        hashtable.put("54", "西藏");
+        hashtable.put("61", "陕西");
+        hashtable.put("62", "甘肃");
+        hashtable.put("63", "青海");
+        hashtable.put("64", "宁夏");
+        hashtable.put("65", "新疆");
+        hashtable.put("71", "台湾");
+        hashtable.put("81", "香港");
+        hashtable.put("82", "澳门");
+        hashtable.put("91", "国外");
+        return hashtable;
+    }
+
+    /**
+     * 判断字符串是否为数字
+     *
+     * @param str
+     * @return
+     */
+    private static boolean isStrNum(String str) {
+        Pattern pattern = Pattern.compile("[0-9]*");
+        Matcher isNum = pattern.matcher(str);
+        if (isNum.matches()) {
+            return true;
+        } else {
+            return false;
+        }
+    }
+
+    /**
+     * 判断字符串是否为日期格式
+     *
+     * @param strDate
+     * @return
+     */
+    public static boolean isStrDate(String strDate) {
+        Pattern pattern = Pattern.compile("^((\\d{2}(([02468][048])|([13579][26]))[\\-\\/\\s]?((((0?[13578])|(1[02]))[\\-\\/\\s]?((0?[1-9])|([1-2][0-9])|(3[01])))|(((0?[469])|(11))[\\-\\/\\s]?((0?[1-9])|([1-2][0-9])|(30)))|(0?2[\\-\\/\\s]?((0?[1-9])|([1-2][0-9])))))|(\\d{2}(([02468][1235679])|([13579][01345789]))[\\-\\/\\s]?((((0?[13578])|(1[02]))[\\-\\/\\s]?((0?[1-9])|([1-2][0-9])|(3[01])))|(((0?[469])|(11))[\\-\\/\\s]?((0?[1-9])|([1-2][0-9])|(30)))|(0?2[\\-\\/\\s]?((0?[1-9])|(1[0-9])|(2[0-8]))))))(\\s(((0?[0-9])|([1-2][0-3]))\\:([0-5]?[0-9])((\\s)|(\\:([0-5]?[0-9])))))?$");
+        Matcher m = pattern.matcher(strDate);
+        if (m.matches()) {
+            return true;
+        } else {
+            return false;
+        }
+    }
+
+}