| | |
| | | const bodyParser = require('body-parser'); |
| | | const mysql = require('mysql2'); |
| | | const fs = require('fs').promises; |
| | | const fs2=require('fs') |
| | | const path = require('path'); |
| | | const moment = require('moment') |
| | | // 转成能识别的url |
| | |
| | | config.endpoint = `facebody.cn-shanghai.aliyuncs.com`; |
| | | return new facebody20191230.default(config); |
| | | } |
| | | app.get('/',async(req,res)=>{ |
| | | res.send('设备交换患者信息'); |
| | | }) |
| | | app.get('/', (req, res) => { |
| | | const title = '岱特智能'; // 动态设置标题 |
| | | const html = ` |
| | | <!DOCTYPE html> |
| | | <html lang="zh-CN"> |
| | | <head> |
| | | <meta charset="UTF-8"> |
| | | <meta name="viewport" content="width=device-width, initial-scale=1.0"> |
| | | <title>${title}</title> |
| | | </head> |
| | | <body> |
| | | <iframe |
| | | src="https://udify.app/chatbot/irsmISE8DBCWAhxz" |
| | | style="width: 100%; height: 100%; min-height: 700px" |
| | | frameborder="0" |
| | | allow="microphone"> |
| | | </iframe> |
| | | </body> |
| | | </html> |
| | | `; |
| | | res.send(html); |
| | | }); |
| | | // 定义 /webuser 路由处理器 用患者code 换信息 |
| | | app.post('/webuser', async (req, res) => { |
| | | const mode=req.body |
| | |
| | | |
| | | // 定义人脸识别 用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_systemtest', |
| | | 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]; |
| | | 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: getAgeFromIdCard(user.patient_identity_no), |
| | | headimgurl: user.patient_avatar_icon, |
| | | imgBaseData: '', |
| | | remark: '患者人脸识别111' |
| | | }, |
| | | dbinfo: {}, // 如果没有需要更新的数据库信息,可以保持空 |
| | | msg: "success" |
| | | }; |
| | | // res.json(response); |
| | | } else { |
| | | 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" |
| | | }; |
| | | // 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.code, //这个是数据返回会携带回来UID |
| | | address: user.patient_address, |
| | | remark: '患者人脸识别111' |
| | | }, |
| | | remsg: "success" |
| | | }; |
| | | } else { |
| | | response = { |
| | | retcode: 1001, |
| | | remsg: "没有找到患者,请先检查患者code" |
| | | }; |
| | | } |
| | | } else { |
| | | response = { |
| | | retcode: 1001, |
| | | remsg: "没有找到患者,请先检查患者code" |
| | | }; |
| | | } |
| | | } 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 }); |
| | | } |
| | | |
| | | |
| | |
| | | const action = req.body.action; |
| | | const deviceID = req.body.deviceID; |
| | | const mode=req.body |
| | | mode.action='webResults' |
| | | logHttps(mode) |
| | | console.log('----------') |
| | | try { |
| | | const datas=mode.datas |
| | | datas.forEach(async element => { |
| | | await installData(element) |
| | | }); |
| | | response = { |
| | | retCode: "1", |
| | | msg: "成功" |
| | | recode: "2000", |
| | | remsg: "成功" |
| | | }; |
| | | res.json(response) |
| | | |
| | | }catch(err){ |
| | | res.status(400).json({ retCode: "-1", msg: "Invalid request parameters" }); |
| | | res.status(4000).json({ retCode: "-1", msg: "Invalid request parameters" }); |
| | | } |
| | | |
| | | }) |
| | |
| | | /** |
| | | * patientId={patientId} |
| | | */ |
| | | app.post('/getpatientInfo',async(req,res)=>{ |
| | | app.get('/getpatientInfo',async(req,res)=>{ |
| | | // 使用req.query访问查询字符串参数 |
| | | const patientId = req.query.patientid; |
| | | const mode={"action":'getpatientInfo',"patientId":patientId} |
| | |
| | | if (rows.length > 0) { |
| | | const user = rows[0]; |
| | | const response = { |
| | | retCode: "1", |
| | | result: { |
| | | code: "1", |
| | | result:[ { |
| | | patientId: user.code, |
| | | fullName: user.patient_name, |
| | | gender: user.patient_gender, |
| | | age: getAgeFromIdCard(user.patient_identity_no), |
| | | // phoneNum:user. |
| | | headimgurl: user.patient_avatar_icon, |
| | | imgBaseData: '', |
| | | remark: '' |
| | | }, |
| | | dbinfo: {}, // 如果没有需要更新的数据库信息,可以保持空 |
| | | 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); |
| | |
| | | |
| | | |
| | | console |
| | | }) |
| | | /** |
| | | * PostCheckExam 病人信息及检测结果以JSON的形式回传至服务器 |
| | | */ |
| | | app.post('/PostCheckExam',async(req,res)=>{ |
| | | const mode=req.body |
| | | if(mode){ |
| | | logHttps(mode) |
| | | }else{ |
| | | mode.action='hahhaha' |
| | | logHttps(mode) |
| | | } |
| | | res.status(400).json({ retCode: "-1", msg: "kankan" }); |
| | | |
| | | |
| | | }) |
| | | // 启动服务器 |
| | | app.listen(port, async () => { |
| | |
| | | await fs.mkdir(directory, { recursive: true }); |
| | | } catch (err) { |
| | | console.error('Error creating directory:', err); |
| | | throw err; |
| | | } |
| | | } |
| | | // 将文件上传到阿里的oss |
| | |
| | | // 访问日志记录 |
| | | const logHttps=(mode)=>{ |
| | | try{ |
| | | 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) |
| | | let sqlStr=`INSERT INTO system_log (id, code, url, parameter) VALUES (0, '', '${mode.action}', '${JSON.stringify(mode)}')` |
| | | console.log(sqlStr) |
| | | pool.promise().query(sqlStr) |
| | | }catch (err) { |
| | | console.error('Error creating directory:', err); |
| | | throw err; |
| | | console.error('访问日志记录错误:', err); |
| | | } |
| | | } |
| | | // 插入数据 |
| | | const installData=async (mode)=>{ |
| | | try{ |
| | | let sqlStr=`INSERT INTO patient_rtcf_result (id, code, patient_code,`+ |
| | | let selectSql=`SELECT * FROM patient_rtcf_result WHERE code='${mode.occurTime}'` |
| | | const [rows] = await pool.promise().query(selectSql); |
| | | if(rows.length>0){ |
| | | let updateSql='' |
| | | if(mode.BF){ |
| | | updateSql=`UPDATE patient_rtcf_result SET rtcf_json_bf ='${JSON.stringify(mode.BF)}'` |
| | | }else if (mode.BMI){ |
| | | updateSql=`UPDATE patient_rtcf_result SET rtcf_json_bmi ='${JSON.stringify(mode.BMI)}'` |
| | | } |
| | | if(updateSql){ |
| | | console.log(`-------------------------更新${updateSql}---------`) |
| | | console.log(updateSql) |
| | | await pool.promise().query(updateSql) |
| | | } |
| | | }else{ |
| | | let sqlStr=`INSERT INTO patient_rtcf_result (id, code, patient_code,`+ |
| | | `comm_time,rtcf_json_bmi,`+ |
| | | `rtcf_json_bp,`+ |
| | | `rtcf_json_bf,`+ |
| | |
| | | `rtcf_json_fei,`+ |
| | | `rtcf_jiu,`+ |
| | | `rtcf_gmd)`+ |
| | | `VALUES (0, '', '${mode.UID}', '${moment(new Date()).format('YYYY-MM-DD HH:mm:ss')}','${JSON.stringify(mode.BMI)}',`+ |
| | | `VALUES (0, '${mode.occurTime}', '${mode.UID}', '${moment(new Date()).format('YYYY-MM-DD HH:mm:ss')}','${JSON.stringify(mode.BMI)}',`+ |
| | | `'${JSON.stringify(mode.BP)}','${JSON.stringify(mode.BF)}','${JSON.stringify(mode.temp)}','${JSON.stringify(mode.bo)}',`+ |
| | | `'${JSON.stringify(mode.bs)}','${JSON.stringify(mode.whr)}','${JSON.stringify(mode.ncg)}','${JSON.stringify(mode.zytz)}',`+ |
| | | `'${JSON.stringify(mode.ecg)}','${JSON.stringify(mode.xzsx)}','${JSON.stringify(mode.eye)}',`+ |
| | | `'${JSON.stringify(mode.sds)}','${JSON.stringify(mode.thxhdb)}','${JSON.stringify(mode.fei)}','${JSON.stringify(mode.jiu)}','${JSON.stringify(mode.gmd)}')` |
| | | |
| | | console.log('-------------------') |
| | | console.log(sqlStr) |
| | | await pool.promise().query(sqlStr) |
| | | await pool.promise().query(sqlStr) |
| | | } |
| | | |
| | | }catch(err){ |
| | | console.log('数据写入异常') |
| | | } |