ct 2 дней назад
Родитель
Сommit
4bcfa3f0d9

+ 8 - 2
fs-service/src/main/java/com/fs/his/service/impl/FsPrescribeServiceImpl.java

@@ -21,6 +21,7 @@ import com.fs.his.service.IFsPrescribeDrugService;
 import com.fs.his.service.IFsPrescribeService;
 import com.fs.his.service.IFsStoreOrderService;
 import com.fs.his.utils.ConfigUtil;
+import com.fs.his.utils.IdCardUtil;
 import com.fs.his.utils.qrcode.QRCodeUtils;
 import com.fs.his.vo.*;
 import com.fs.im.dto.MsgCustomDTO;
@@ -517,7 +518,12 @@ public class FsPrescribeServiceImpl implements IFsPrescribeService
             return null;
         }
         long currentTimeMillis = System.currentTimeMillis();
-        long ageInMillis = currentTimeMillis - patJson.getBirthday();
+        Long birthday = patJson.getBirthday();
+        if (birthday == null) {
+            birthday = IdCardUtil.getBirthdayFromIdCard(patJson.getIdCard());
+            patJson.setBirthday(birthday);
+        }
+        long ageInMillis = currentTimeMillis - birthday;
         long ageInSeconds = ageInMillis / 1000;
         long ageInYears = ageInSeconds / (365 * 24 * 3600);
         fsPrescribe.setPatientAge(ageInYears+"");
@@ -525,7 +531,7 @@ public class FsPrescribeServiceImpl implements IFsPrescribeService
         fsPrescribe.setPatientName(patJson.getPatientName());
         fsPrescribe.setPatientTel(patJson.getMobile());
         fsPrescribe.setPatientGender(patJson.getSex().toString());
-        fsPrescribe.setPatientBirthday(new SimpleDateFormat("yyyy-MM-dd").format(new Date(patJson.getBirthday())));
+        fsPrescribe.setPatientBirthday(new SimpleDateFormat("yyyy-MM-dd").format(new Date(birthday)));
         fsPrescribe.setDoctorId(packageOrder.getDoctorId());
         FsDoctor fsDoctor = doctorMapper.selectFsDoctorByDoctorId(packageOrder.getDoctorId());
         if (fsDoctor==null){

+ 20 - 0
fs-service/src/main/java/com/fs/his/utils/IdCardUtil.java

@@ -140,4 +140,24 @@ public class IdCardUtil {
             throw new RuntimeException("匹配请求异常", e);
         }
     }
+
+    /**
+     * 从身份证号码提取出生日期时间戳
+     * @param idCard 身份证号码
+     * @return 出生日期时间戳(毫秒)
+     */
+    public static Long getBirthdayFromIdCard(String idCard) {
+        if (idCard == null || idCard.length() != 18) {
+            throw new IllegalArgumentException("身份证号码格式不正确");
+        }
+
+        try {
+            String birthdayStr = idCard.substring(6, 14);
+            SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
+            Date birthday = sdf.parse(birthdayStr);
+            return birthday.getTime();
+        } catch (Exception e) {
+            throw new IllegalArgumentException("身份证出生日期解析失败", e);
+        }
+    }
 }