From 40c67035890dc45ac8d998461037f19324e88809 Mon Sep 17 00:00:00 2001
From: chenyc <501753378@qq.com>
Date: 星期二, 22 十月 2024 13:49:27 +0800
Subject: [PATCH] 345
---
app.js | 262 ++++++++++++++++++++++++++++++++++++---------------
1 files changed, 184 insertions(+), 78 deletions(-)
diff --git a/app.js b/app.js
index 04c0dca..dfe80cf 100644
--- a/app.js
+++ b/app.js
@@ -14,6 +14,12 @@
const app = express();
const port = 3000;
+// 设置 JSON 请求体的最大大小为 5MB
+app.use(express.json({ limit: '5mb' }));
+
+// 设置 URL 编码请求体的最大大小为 5MB
+app.use(express.urlencoded({ extended: true, limit: '5mb' }));
+
// 使用 body-parser 中间件解析 JSON 请求体
app.use(bodyParser.json());
@@ -39,7 +45,9 @@
config.endpoint = `facebody.cn-shanghai.aliyuncs.com`;
return new facebody20191230.default(config);
}
-
+app.get('/',async(req,res)=>{
+ res.send('设备交换患者信息');
+})
// 定义 /webuser 路由处理器 用患者code 换信息
app.post('/webuser', async (req, res) => {
const mode=req.body
@@ -63,10 +71,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"
@@ -91,88 +99,89 @@
// 定义人脸识别 用base64图片文件换患者信息
app.post('/faceuser', async (req, res) => {
- const action = req.body.action;
- const deviceID = req.body.deviceID;
- // base64图像内容,base64 编码(长宽像素值范围:80*80~200*200,注意:图片的base64 编码是不包含图片头的,如 data:image/jpg;base64,)
- const content = req.body.content;
- const mode=req.body
- logHttps(mode)
- if (action == 'doFace' && deviceID && content) {
- // 转成oss路径
- const ossurl = await base64toFile(content, deviceID)
- console.log('得到oss图片路径', ossurl)
- let searchFaceRequest = new facebody20191230.SearchFaceRequest({
- dbName: 'Face_emeishan',
- imageUrl: ossurl,
- limit: 1,
- });
+ try{
+ const action = req.body.action;
+ const deviceID = req.body.deviceID;
+ // base64图像内容,base64 编码(长宽像素值范围:80*80~200*200,注意:图片的base64 编码是不包含图片头的,如 data:image/jpg;base64,)
+ const content = req.body.content;
+ const mode=req.body
+ mode.content=''
+ logHttps(mode)
+ if (action == 'doFace' && deviceID && content) {
+ // 转成oss路径
+ const ossurl = await base64toFile(content, deviceID)
+ console.log('得到oss图片路径', ossurl)
+ let searchFaceRequest = new facebody20191230.SearchFaceRequest({
+ dbName: 'Face_systemtest',
+ imageUrl: ossurl,
+ limit: 1,
+ });
- let runtime = new Util.RuntimeOptions({});
- try {
- // 复制代码运行请自行打印 API 的返回值
- const data = await createClient().searchFaceWithOptions(searchFaceRequest, runtime);
- const matchList = data.body.data?.matchList
- let response = null
- if (matchList?.length > 0) {
- const faceItems = matchList[0].faceItems
- if (faceItems?.length === 0) {
- console.log('没有找到患者对应的人脸')
- response = {
- retCode: "0",
- msg: "没有找到患者,请先检查患者code"
- };
- } else if (faceItems[0].score >= 0.2) {
- const entityId = faceItems[0].entityId
- console.log(entityId, '患者id找到了')
- let query = `SELECT * FROM patient_info WHERE code = '${entityId}'`
- const [rows] = await pool.promise().query(query);
- if (rows.length > 0) {
- const user = rows[0];
+ let runtime = new Util.RuntimeOptions({});
+ try {
+ // 复制代码运行请自行打印 API 的返回值
+ const data = await createClient().searchFaceWithOptions(searchFaceRequest, runtime);
+ const matchList = data.body.data?.matchList
+ let response = null
+ if (matchList?.length > 0) {
+ const faceItems = matchList[0].faceItems
+ if (faceItems?.length === 0) {
+ console.log('没有找到患者对应的人脸')
response = {
- retCode: "1",
- uinfo: {
- title: user.client_code,
- cardID: user.code,
- userNum: user.patient_no,
- name: user.patient_name,
- sex: user.patient_gender === 0 ? '男' : '女',
- age: user.patient_age_2,
- headimgurl: user.patient_avatar_icon,
- imgBaseData: '',
- remark: ''
- },
- dbinfo: {}, // 如果没有需要更新的数据库信息,可以保持空
- msg: "success"
+ retCode: "0",
+ msg: "没有找到患者,请先检查患者code"
};
- // res.json(response);
+ } else if (faceItems[0].score >= 0.2) {
+ const entityId = faceItems[0].entityId
+ console.log(entityId, '患者id找到了')
+ let query = `SELECT * FROM patient_info WHERE code = '${entityId}'`
+ const [rows] = await pool.promise().query(query);
+ if (rows.length > 0) {
+ const user = rows[0];
+ response = {
+ recode: 2001,
+ userinfo: {
+ name: user.patient_name,
+ sex: user.patient_gender === 0 ? '男' : '女',
+ age: getAgeFromIdCard(user.patient_identity_no),
+ usernum: user.patient_no,
+ address: user.code,
+ remark: '患者人脸识别111'
+ },
+ remsg: "success"
+ };
+ // res.json(response);
+ } else {
+ response = {
+ retCode: "0",
+ msg: "没有找到患者,请先检查患者code"
+ };
+ // res.json(response);
+ }
} else {
response = {
retCode: "0",
msg: "没有找到患者,请先检查患者code"
};
- // res.json(response);
}
- } else {
- response = {
- retCode: "0",
- msg: "没有找到患者,请先检查患者code"
- };
+ res.json(response);
}
- res.json(response);
- }
- else {
- res.status(500).json({ retCode: "-1", msg: "没有识别到患者" });
- }
- } catch (error) {
- // 此处仅做打印展示,请谨慎对待异常处理,在工程项目中切勿直接忽略异常。
- // 错误 message
- console.log(error)
- res.status(400).json({ retCode: "-1", msg: "Invalid request parameters" });
+ else {
+ res.status(500).json({ retCode: "-1", msg: "没有识别到患者" });
+ }
+ } catch (error) {
+ // 此处仅做打印展示,请谨慎对待异常处理,在工程项目中切勿直接忽略异常。
+ // 错误 message
+ console.log(error)
+ res.status(400).json({ retCode: "-1", msg: "Invalid request parameters" });
+ }
+ } else {
+ // 如果请求参数不符合预期,则返回错误信息
+ res.status(400).json({ retCode: "-1", msg: "Invalid request parameters" });
}
- } else {
- // 如果请求参数不符合预期,则返回错误信息
- res.status(400).json({ retCode: "-1", msg: "Invalid request parameters" });
+ }catch(err){
+ res.status(400).json({ retCode: "-1", msg: err });
}
@@ -201,6 +210,71 @@
res.status(400).json({ retCode: "-1", msg: "Invalid request parameters" });
}
+})
+// 定义北京悦琦创通科技有限公司VBP-10系列HTTP通信协议
+/**
+ * patientId={patientId}
+ */
+app.post('/getpatientInfo',async(req,res)=>{
+ // 使用req.query访问查询字符串参数
+ const patientId = req.query.patientid;
+ const mode={"action":'getpatientInfo',"patientId":patientId}
+ logHttps(mode)
+ if(patientId){
+ // 输出传入的patientid值
+ console.log('Patient ID:',patientId)
+ let query = `SELECT * FROM patient_info WHERE code = '${patientId}'`
+ try {
+ const [rows] = await pool.promise().query(query);
+ if (rows.length > 0) {
+ const user = rows[0];
+ const response = {
+ code: "1",
+ result:[ {
+ patientId: user.code,
+ fullName: user.patient_name,
+ gender: user.patient_gender,
+ age: getAgeFromIdCard(user.patient_identity_no),
+ phoneNum:user.patient_mobile,
+ address: user.patient_avatar_icon,
+ idType: user.patient_identity_type,
+ idNum: user.patient_identity_no,
+ height:'',
+ weight:'',
+ requestDoctor:'',
+ requestDept :"",
+ examDoctor:'',
+ examDept:"",
+ diagnosisDoctor:''
+ }],
+ msg: "success"
+ };
+ res.json(response);
+ } else {
+ const response = {
+ retCode: "0",
+ msg: "没有找到患者,请先检查患者code"
+ };
+ res.json(response);
+ }
+ } catch (err) {
+ console.error(err);
+ res.status(500).json({ retCode: "-1", msg: "Database error" });
+ }
+
+ }else{
+ // 如果请求参数不符合预期,则返回错误信息
+ res.status(400).json({ retCode: "-1", msg: "Invalid request parameters" });
+ }
+
+
+ console
+})
+/**
+ * PostCheckExam 病人信息及检测结果以JSON的形式回传至服务器
+ */
+app.post('/PostCheckExam',async(req,res)=>{
+
})
// 启动服务器
app.listen(port, async () => {
@@ -258,10 +332,13 @@
// 访问日志记录
const logHttps=(mode)=>{
- console.log(mode)
- console.log(JSON.stringify(mode))
- let sqlStr=`INSERT INTO system_log (id, code, url, parameter) VALUES (0, '', '${mode.action}', '${JSON.stringify(mode)}')`
- pool.promise().query(sqlStr)
+ try{
+ let sqlStr=`INSERT INTO system_log (id, code, url, parameter) VALUES (0, '', '${mode.action}', '${JSON.stringify(mode)}')`
+ pool.promise().query(sqlStr)
+ }catch (err) {
+ console.error('Error creating directory2222:', err);
+ throw err;
+ }
}
// 插入数据
const installData=async (mode)=>{
@@ -296,4 +373,33 @@
}catch(err){
console.log('数据写入异常')
}
-}
\ No newline at end of file
+}
+
+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