From 1b9ae89ff9286816d452239d99883cd5641babe9 Mon Sep 17 00:00:00 2001
From: chenyc <501753378@qq.com>
Date: 星期一, 21 十月 2024 16:53:08 +0800
Subject: [PATCH] 34
---
app.js | 66 ++++++++++++++++++++++++++++++--
1 files changed, 61 insertions(+), 5 deletions(-)
diff --git a/app.js b/app.js
index 04c0dca..1af5ba1 100644
--- a/app.js
+++ b/app.js
@@ -63,10 +63,10 @@
userNum: user.patient_no,
name: user.patient_name,
sex: user.patient_gender === 0 ? '男' : '女',
- age: user.patient_age_2,
+ age: getAgeFromIdCard(user.patient_identity_no),
headimgurl: user.patient_avatar_icon,
imgBaseData: '',
- remark: 'ccc'
+ remark: ''
},
dbinfo: {}, // 如果没有需要更新的数据库信息,可以保持空
msg: "success"
@@ -136,10 +136,10 @@
userNum: user.patient_no,
name: user.patient_name,
sex: user.patient_gender === 0 ? '男' : '女',
- age: user.patient_age_2,
+ age: getAgeFromIdCard(user.patient_identity_no),
headimgurl: user.patient_avatar_icon,
imgBaseData: '',
- remark: ''
+ remark: '患者人脸识别'
},
dbinfo: {}, // 如果没有需要更新的数据库信息,可以保持空
msg: "success"
@@ -296,4 +296,60 @@
}catch(err){
console.log('数据写入异常')
}
-}
\ No newline at end of file
+}
+const getAge=(idCard)=>{
+ // 检查身份证号码长度是否正确
+ if (idCard.length !== 18) {
+ throw new Error('身份证号码长度必须为18位');
+ }
+
+ // 获取出生年月日
+ const birthYear = parseInt(idCard.substring(6, 10), 10);
+ const birthMonth = parseInt(idCard.substring(10, 12), 10);
+ const birthDay = parseInt(idCard.substring(12, 14), 10);
+
+ // 获取当前日期
+ const now = new Date();
+ const currentYear = now.getFullYear();
+ const currentMonth = now.getMonth() + 1; // 注意:getMonth() 返回的月份是从0开始的
+ const currentDay = now.getDate();
+
+ // 计算年龄
+ let age = currentYear - birthYear;
+
+ // 如果当前日期在生日之前,则年龄减一
+ if (currentMonth < birthMonth || (currentMonth === birthMonth && currentDay < birthDay)) {
+ age--;
+ }
+
+ return age;
+}
+function getAgeFromIdCard(idCard) {
+ // 检查身份证号码长度是否正确
+ if (idCard.length !== 18) {
+ // throw new Error('身份证号码长度必须为18位');
+ return ''
+ }
+
+ // 获取出生年月日
+ const birthYear = parseInt(idCard.substring(6, 10), 10);
+ const birthMonth = parseInt(idCard.substring(10, 12), 10);
+ const birthDay = parseInt(idCard.substring(12, 14), 10);
+
+ // 获取当前日期
+ const now = new Date();
+ const currentYear = now.getFullYear();
+ const currentMonth = now.getMonth() + 1; // 注意:getMonth() 返回的月份是从0开始的
+ const currentDay = now.getDate();
+
+ // 计算年龄
+ let age = currentYear - birthYear;
+
+ // 如果当前日期在生日之前,则年龄减一
+ if (currentMonth < birthMonth || (currentMonth === birthMonth && currentDay < birthDay)) {
+ age--;
+ }
+
+ return age;
+}
+
--
Gitblit v1.8.0