| | |
| | | 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') |
| | | const logger = require(path.resolve(__dirname, 'logger')); |
| | | // 转成能识别的url |
| | | const ViapiUtil = require('@alicloud/viapi-utils'); |
| | | |
| | | const facebody20191230 = require('@alicloud/facebody20191230'); |
| | | const OpenApi = require('@alicloud/openapi-client'); |
| | | const Util = require('@alicloud/tea-util'); |
| | | const thirdPartyApi = require(path.resolve(__dirname, 'thirdPartyApi')); |
| | | |
| | | const app = express(); |
| | | app.use(bodyParser.json()) |
| | | const port = 3000; |
| | | |
| | | // 设置 JSON 请求体的最大大小为 5MB |
| | |
| | | return new facebody20191230.default(config); |
| | | } |
| | | 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); |
| | | |
| | | res.json({mas:'h'}); |
| | | }); |
| | | app.get('/test', async (req, res) => { |
| | | try { |
| | | const token=await thirdPartyApi.getAccessToken() |
| | | logger.info('返回token=='+JSON.stringify(token)) |
| | | res.json(token); |
| | | }catch(err){ |
| | | logger.info('catch=='+JSON.stringify(err)) |
| | | } |
| | | }); |
| | | // 定义 /webuser 路由处理器 用患者code 换信息 |
| | | app.post('/webuser', async (req, res) => { |
| | | const mode=req.body |
| | |
| | | const deviceID = req.body.deviceID; |
| | | const type = req.body.type; |
| | | const xid = req.body.xid; |
| | | console.log(`action=${action},deviceID=${deviceID},type=${type},xid=${xid}`) |
| | | logger.info(`成分分析仪用户请求req body action=${action},deviceID=${deviceID},type=${type},xid=${xid}`) |
| | | if (action === 'doWebUser' && deviceID && type !== undefined) { |
| | | let query = `SELECT * FROM patient_info WHERE code = '${xid}'` |
| | | try { |
| | | const [rows] = await pool.promise().query(query); |
| | | if (rows.length > 0) { |
| | | const user = rows[0]; |
| | | const 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: '' |
| | | const pathParams={code:xid} |
| | | const data = await thirdPartyApi.fetchThirdPartyData('/patient/info/detail2', 'POST', {}, null, pathParams,{}); |
| | | logger.info(`get patInfo data=${JSON.stringify(data)}`) |
| | | console.log('get patInfo ----',data.data) |
| | | // console.log(data) |
| | | if(data?.code===200&&data?.message==='SUCCESS'&&data?.data){ |
| | | const user = data.data; |
| | | response = { |
| | | recode: 2001, |
| | | userinfo: { |
| | | name: user.patientName, |
| | | sex: user.patientGenderText, |
| | | age: user.age, |
| | | usernum: user.code, //这个是数据返回会携带回来UID |
| | | address: user.patientAddress, |
| | | remark: '患者人脸识别111' |
| | | }, |
| | | dbinfo: {}, // 如果没有需要更新的数据库信息,可以保持空 |
| | | msg: "success" |
| | | remsg: "success" |
| | | }; |
| | | res.json(response); |
| | | } else { |
| | | const response = { |
| | | retCode: "0", |
| | | msg: "没有找到患者,请先检查患者code" |
| | | logger.info('Successfully returned patient information') |
| | | console.log('Successfully returned patient information') |
| | | }else{ |
| | | response = { |
| | | retcode: 1001, |
| | | remsg: "没有找到患者,请先检查患者code" |
| | | }; |
| | | res.json(response); |
| | | } |
| | | res.json(response); |
| | | |
| | | } catch (err) { |
| | | console.error(err); |
| | | res.status(500).json({ retCode: "-1", msg: "Database error" }); |
| | | logger.error(err) |
| | | res.status(500).json({ retCode: "-1", msg: err }); |
| | | } |
| | | } else { |
| | | // 如果请求参数不符合预期,则返回错误信息 |
| | | res.status(400).json({ retCode: "-1", msg: "Invalid request parameters" }); |
| | | } |
| | | }); |
| | | app.post('/webuserPatientId',async(req,res)=>{ |
| | | const mode=req.body |
| | | logHttps(mode) |
| | | const patientId = req.query.patientId; |
| | | if (patientId) { |
| | | let query = `SELECT * FROM patient_info WHERE code = '${xid}'` |
| | | try { |
| | | const [rows] = await pool.promise().query(query); |
| | | if (rows.length > 0) { |
| | | const user = rows[0]; |
| | | const 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: '' |
| | | }, |
| | | dbinfo: {}, // 如果没有需要更新的数据库信息,可以保持空 |
| | | 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" }); |
| | | } |
| | | }) |
| | | |
| | | // 定义人脸识别 用base64图片文件换患者信息 |
| | | app.post('/faceuser', async (req, res) => { |
| | | try{ |
| | |
| | | const content = req.body.content; |
| | | const mode=req.body |
| | | mode.content='' |
| | | logHttps(mode) |
| | | logger.info(`人脸识别请求deviceID=${deviceID},action=${action}`) |
| | | if (action == 'doFace' && deviceID && content) { |
| | | // 转成oss路径 |
| | | const ossurl = await base64toFile(content, deviceID) |
| | | console.log('得到oss图片路径', ossurl) |
| | | logger.info(`得到oss图片路径=${ossurl}`) |
| | | let searchFaceRequest = new facebody20191230.SearchFaceRequest({ |
| | | dbName: 'Face_systemtest', |
| | | imageUrl: ossurl, |
| | |
| | | if (matchList?.length > 0) { |
| | | const faceItems = matchList[0].faceItems |
| | | if (faceItems?.length === 0) { |
| | | console.log('没有找到患者对应的人脸') |
| | | logger.info(`没有找到患者对应的人脸`) |
| | | 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]; |
| | | const pathParams={code:entityId} |
| | | const data = await thirdPartyApi.fetchThirdPartyData('/patient/info/detail2', 'POST', {}, null, pathParams,{}); |
| | | logger.info(`患者接口请求成功`) |
| | | if(data?.code===200&&data?.message==='SUCCESS'&&data?.data){ |
| | | const user = data.data; |
| | | response = { |
| | | recode: 2001, |
| | | userinfo: { |
| | | name: user.patient_name, |
| | | sex: user.patient_gender === 0 ? '男' : '女', |
| | | age: getAgeFromIdCard(user.patient_identity_no), |
| | | name: user.patientName, |
| | | sex: user.patientGenderText, |
| | | age: user.age, |
| | | usernum: user.code, //这个是数据返回会携带回来UID |
| | | address: user.patient_address, |
| | | address: user.patientAddress, |
| | | remark: '患者人脸识别111' |
| | | }, |
| | | remsg: "success" |
| | | }; |
| | | } else { |
| | | logger.info(`返回患者信息成功=${user.patientName}`) |
| | | }else{ |
| | | response = { |
| | | retcode: 1001, |
| | | remsg: "没有找到患者,请先检查患者code" |
| | | }; |
| | | } |
| | | |
| | | } else { |
| | | response = { |
| | | retcode: 1001, |
| | |
| | | // 此处仅做打印展示,请谨慎对待异常处理,在工程项目中切勿直接忽略异常。 |
| | | // 错误 message |
| | | console.log(error) |
| | | res.status(400).json({ retCode: "-1", msg: "Invalid request parameters" }); |
| | | res.status(400).json({ retCode: "-1", msg: error }); |
| | | |
| | | } |
| | | } else { |
| | | // 如果请求参数不符合预期,则返回错误信息 |
| | | res.status(400).json({ retCode: "-1", msg: "Invalid request parameters" }); |
| | | res.status(400).json({ retCode: "-1", msg: "Invalid request parameters 333" }); |
| | | } |
| | | }catch(err){ |
| | | res.status(400).json({ retCode: "-1", msg: err }); |
| | |
| | | const deviceID = req.body.deviceID; |
| | | const mode=req.body |
| | | mode.action='webResults' |
| | | logHttps(mode) |
| | | logger.info(`人体成分分析仪结果返回请求deviceID=${deviceID},action=${JSON.stringify(mode)}`) |
| | | try { |
| | | |
| | | |
| | | const datas=mode.datas |
| | | datas.forEach(async element => { |
| | | await installData(element) |
| | | // 组合数据 |
| | | let data={} |
| | | // 没有BF |
| | | if(element.fatFree){ |
| | | data={ |
| | | id:0, |
| | | code:element.recordNo, |
| | | patientCode:element.userID, |
| | | commTime:element.measureTime, |
| | | rtcfJsonBf:JSON.stringify(element) |
| | | } |
| | | } |
| | | // 没有BMI |
| | | if(element.bmi){ |
| | | data={ |
| | | id:0, |
| | | code:element.recordNo, |
| | | patientCode:element.userID, |
| | | commTime:element.measureTime, |
| | | rtcfJsonBmi:JSON.stringify(element) |
| | | } |
| | | } |
| | | console.log(data) |
| | | const resdata = await thirdPartyApi.fetchThirdPartyData('/patient/rtcf/result/save', 'POST', {}, data,{},{}); |
| | | logger.info(`结果插入成功`) |
| | | console.log(resdata) |
| | | }); |
| | | response = { |
| | | recode: "2000", |
| | |
| | | res.json(response) |
| | | |
| | | }catch(err){ |
| | | logger.errer(`结果插入失败`) |
| | | res.status(4000).json({ reCode: "4000", msg: "Invalid request parameters" }); |
| | | } |
| | | |
| | |
| | | app.get('/getpatientInfo',async(req,res)=>{ |
| | | // 使用req.query访问查询字符串参数 |
| | | const patientId = req.query.patientId; |
| | | const mode={"action":'getpatientInfo',"patientId":patientId} |
| | | console.log(patientId,'-----------------') |
| | | logHttps(mode) |
| | | if(patientId){ |
| | | const clientCode = req.query.clientCode; |
| | | const mode={"action":'getpatientInfo',"patientId":patientId,} |
| | | console.log(patientId,'-----------------',clientCode) |
| | | logger.info(`血流量设备请求患者信息,请求参数=${patientId},clintCode=${clientCode}`) |
| | | if(patientId&&clientCode){ |
| | | // 输出传入的patientid值 |
| | | console.log('Patient ID:',patientId) |
| | | let query = `SELECT * FROM patient_info WHERE code = '${patientId}'` |
| | | try { |
| | | const [rows] = await pool.promise().query(query); |
| | | //查询参数 |
| | | const pathParams={ |
| | | clientCode:clientCode, |
| | | patQueryCode:patientId |
| | | } |
| | | const data = await thirdPartyApi.fetchThirdPartyDataNoToke('/patient/info/listPatsPublic', 'POST', {}, null, pathParams,{}); |
| | | console.log(data.data.list) |
| | | const rows= data.data.list |
| | | if (rows.length > 0) { |
| | | const user = rows[0]; |
| | | const response = { |
| | | result:[ { |
| | | let users=[] |
| | | rows.forEach(user=>{ |
| | | users.push({ |
| | | 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, |
| | | fullName: user.patientName, |
| | | gender: user.patientGender, |
| | | age: user.age, |
| | | birthday:'', |
| | | phoneNum:user.patientMobile, |
| | | address: user.patientAvatarIcon, |
| | | idType: user.patientIdentityType, |
| | | idNum: user.patientIdentityNo, |
| | | height:'', |
| | | weight:'', |
| | | requestDoctor:'', |
| | |
| | | examDoctor:'', |
| | | examDept:"", |
| | | diagnosisDoctor:'' |
| | | }], |
| | | }; |
| | | res.json(response); |
| | | }) |
| | | }) |
| | | logger.info(`血流量设备请求患者信息,请求成功返回患者信息=${JSON.stringify(users)}`) |
| | | res.json(users); |
| | | } else { |
| | | const response = { |
| | | retCode: "0", |
| | | msg: "没有找到患者,请先检查患者code" |
| | | }; |
| | | res.json(response); |
| | | logger.info(`血流量设备请求患者信息,请求成功返回患者信息=[]`) |
| | | res.json([]); |
| | | } |
| | | } catch (err) { |
| | | console.error(err); |
| | | res.status(500).json({ retCode: "-1", msg: "Database error" }); |
| | | logger.errer(`血流量设备请求患者信息,请求失败=${err}`) |
| | | res.status(500).json({ retCode: "-1", msg: "接口出错!"+err }); |
| | | } |
| | | |
| | | }else{ |
| | | // 如果请求参数不符合预期,则返回错误信息 |
| | | res.status(400).json({ retCode: "-1", msg: "Invalid request parameters333" }); |
| | | |
| | | res.status(400).json({ retCode: "-1", msg: "请求参数出错" }); |
| | | } |
| | | |
| | | |
| | | console |
| | | }) |
| | | /** |
| | | * PostCheckExam 病人信息及检测结果以JSON的形式回传至服务器 |
| | | */ |
| | | app.post('/PostCheckExam',async(req,res)=>{ |
| | | const mode=req.body |
| | | if(mode){ |
| | | logHttps(mode) |
| | | }else{ |
| | | logHttps(mode) |
| | | app.post('/PostCheckExam',async (req,res)=>{ |
| | | try { |
| | | const clientCode = req.query.clientCode; |
| | | console.log('-------------------',clientCode) |
| | | if(!clientCode){ |
| | | res.json({"Msg": "请求参数没有clientCode", "Status": "err" }); |
| | | return |
| | | } |
| | | const body=req.body |
| | | console.log(body) |
| | | logger.info(`血流量设备上报结果,请求信息clientCode=${clientCode}`) |
| | | // 组合上传数据 |
| | | const data={ |
| | | id:0, |
| | | code:'', |
| | | patient_code :body.patientId, |
| | | client_code:clientCode, |
| | | exam_id:body.examId, |
| | | SBPLB:body.SBPLB, |
| | | MBPLB:body.MBPLB, |
| | | DBPLB:body.DBPLB, |
| | | PPLB:body.PPLB, |
| | | SBPRB:body.SBPRB, |
| | | MBPRB:body.MBPRB, |
| | | DBPRB:body.DBPRB, |
| | | PPRB:body.PPRB, |
| | | SBPLA:body.SBPLA, |
| | | MBPLA:body.MBPLA, |
| | | DBPLA:body.DBPLA, |
| | | SBPRA:body.SBPRA, |
| | | MBPRA:body.MBPRA, |
| | | DBPRA:body.DBPRA, |
| | | ABIL:body.ABIL, |
| | | ABIR:body.ABIR, |
| | | BAIL:body.BAIL, |
| | | BAIR:body.BAIR, |
| | | PWVL:body.PWVL, |
| | | PWVR:body.PWVR, |
| | | TBIL:body.TBIL, |
| | | TBIR:body.TBIR, |
| | | SBPLAPTA:body.SBPLAPTA, |
| | | DBPLAPTA:body.DBPLAPTA, |
| | | MBPLAPTA:body.MBPLAPTA, |
| | | PPLAPTA:body.PPLAPTA, |
| | | SBPRAPTA:body.SBPRAPTA, |
| | | DBPRAPTA:body.DBPRAPTA, |
| | | MBPRAPTA:body.MBPRAPTA, |
| | | PPRAPTA:body.PPRAPTA, |
| | | SBPLAFA:body.SBPLAFA, |
| | | DBPLAFA:body.DBPLAFA, |
| | | MBPLAFA:body.MBPLAFA, |
| | | PPLAFA:body.PPLAFA, |
| | | SBPRAFA:body.SBPRAFA, |
| | | DBPRAFA:body.DBPRAFA, |
| | | MBPRAFA:body.MBPRAFA, |
| | | PPRAFA:body.PPRAFA, |
| | | index_LB:body.indexLB, |
| | | index_RB:body.indexRB, |
| | | index_LAPTA:body.indexLAPTA, |
| | | index_RAPTA:body.indexRAPTA, |
| | | index_LAFA:body.indexLAFA, |
| | | index_RAFA:body.indexRAFA, |
| | | image:body.image, |
| | | request_doctor:body.requestDoctor, |
| | | request_department:body.requestDepartment, |
| | | request_date:getDateString(body.requestDate), |
| | | exam_department:body.examDepartment, |
| | | diagnostician_doctor:body.diagnosticianDoctor, |
| | | check_date:getDateString(body.checkDate), |
| | | check_result:body.checkResult, |
| | | diagnosis:body.diagnosis, |
| | | exam_type_id:body.examTypeId, |
| | | exam_type_name:body.examTypeName, |
| | | operator_doctor:body.operatorDoctor, |
| | | abi_advice:body.abiAdvice, |
| | | pwv_result:body.pwvResult |
| | | } |
| | | const resdata = await thirdPartyApi.fetchThirdPartyDataNoToke('/patient/result/from/doppler/blood/flow/device/saveData', 'POST', {}, data,{},{}); |
| | | console.log(resdata) |
| | | if(resdata.code===200&&resdata?.data=='OK'){ |
| | | logger.info(`血流量设备上报结果,请求成功`) |
| | | res.json({"Msg": "检查结果上传成功", "Status": "SUCCESS" }); |
| | | |
| | | }else{ |
| | | logger.info(`血流量设备上报结果,请求失败`) |
| | | res.json({"Msg": "检查结果上传失败", "Status": "err" }); |
| | | } |
| | | } |
| | | res.status(400).json({ retCode: "-1", msg: "kankan" }); |
| | | catch(err){ |
| | | logger.info(`血流量设备上报结果,请求报错`) |
| | | res.status(400).json({ retCode: "-1", msg: "请求出错了11" }); |
| | | } |
| | | |
| | | |
| | | |
| | | }) |
| | | // 大连新的InBody 人体成分分析仪患者注册 |
| | | app.post('/inbodyapi/getuserinfo',async (req, res) => { |
| | | logger.info(`人体成分分析仪患者注册请求body=${JSON.stringify(req.body)}`) |
| | | // 从请求体中获取用户信息 |
| | | // 这里假设请求体包含 USER_ID 和 ORDER_DATE 字段 |
| | | const { USER_ID, ORDER_DATE } = req.body; |
| | | // 检查请求参数是否有效 |
| | | if (!USER_ID) { |
| | | return res.status(400).json({ |
| | | IsResult: false, |
| | | INBODY_USER_INFO: [], |
| | | ErrorMsg: 'USER_ID or ORDER_DATE is missing' |
| | | }); |
| | | } |
| | | const pathParams = { clientCode:'CLIENT9195181802236kHJF',patientHemoCode:USER_ID} |
| | | const data = await thirdPartyApi.fetchThirdPartyData('/patient/info/queryInAndOuts', 'POST', {}, pathParams, {},{}); |
| | | // console.log('查询InAndOuts数据',data) |
| | | if(data.code===200&&data?.message==='SUCCESS'&&data?.data){ |
| | | const list= data.data.list; |
| | | if(list.length>0){ |
| | | |
| | | console.log(list[0]) |
| | | const mode=list[0] |
| | | const user={ |
| | | USER_ID: mode.patientHemoCode, |
| | | USER_NAME: mode.patientName, |
| | | USER_GENDER: mode.patientGender===0? 'M':'F', |
| | | USER_BIRTHDAY: '', |
| | | USER_AGE: mode.age, |
| | | USER_HEIGHT: mode.patientHeight, |
| | | ORDER_DATE:mode.code |
| | | } |
| | | res.json({ |
| | | IsResult: true, |
| | | INBODY_USER_INFO: [user], |
| | | ErrorMsg: '' |
| | | }); |
| | | |
| | | logger.info(`请求患者成功:${mode.patientName}`) |
| | | } |
| | | else{ |
| | | res.json({ |
| | | IsResult: false, |
| | | INBODY_USER_INFO: [], |
| | | ErrorMsg: 'User not found' |
| | | }); |
| | | logger.info(`请求患者失败:没有找到用户`) |
| | | } |
| | | }else{ |
| | | res.json({ |
| | | IsResult: false, |
| | | INBODY_USER_INFO: [], |
| | | ErrorMsg: 'User not found' |
| | | }); |
| | | logger.info(`请求患者失败:没有找到用户`) |
| | | } |
| | | }) |
| | | app.post('/inbodyapi/setinbodydata',async (req, res) => { |
| | | logger.info(`人体成分分析仪结果请求body=${JSON.stringify(req.body)}`) |
| | | const element = req.body; |
| | | try { |
| | | const data={ |
| | | id:0, |
| | | code:'', |
| | | // code:element.DATETIMES, |
| | | patientCode:element.ORDER_DATE, |
| | | commTime:formatted(), |
| | | uploadTime:formatTimestamp(element.DATETIMES), |
| | | rtcfJsonBmi:JSON.stringify(element), |
| | | } |
| | | const resdata = await thirdPartyApi.fetchThirdPartyData('/patient/rtcf/result/save', 'POST', {}, data,{},{}); |
| | | if(resdata.code===200&&resdata?.message==='SUCCESS'){ |
| | | logger.info(`结果插入成功`+JSON.stringify(resdata)) |
| | | res.json({ |
| | | IsResult: true, |
| | | ErrorMsg: 'User not found' |
| | | }); |
| | | }else{ |
| | | logger.info(`结果插入失败`+JSON.stringify(resdata)) |
| | | } |
| | | } catch (error) { |
| | | return res.status(400).json({ |
| | | IsResult: false, |
| | | ErrorMsg: error |
| | | }); |
| | | } |
| | | }) |
| | | |
| | | |
| | | // 启动服务器 |
| | | app.listen(port, async () => { |
| | | logger.info(`Server running at http://localhost:${port}/`) |
| | | console.log(`Server running at http://localhost:${port}/`); |
| | | }); |
| | | |
| | | /** |
| | | * |
| | | * @param {*} file base64图片格式转本地 |
| | |
| | | console.error('访问日志记录错误:', err); |
| | | } |
| | | } |
| | | // 插入数据 |
| | | const installData=async (mode)=>{ |
| | | console.log(mode) |
| | | try{ |
| | | let selectSql=`SELECT * FROM patient_rtcf_result WHERE code='${mode.recordNo}'` |
| | | const [rows] = await pool.promise().query(selectSql); |
| | | if(rows.length>0){ |
| | | let updateSql='' |
| | | if(mode.fatFree){ |
| | | updateSql=`UPDATE patient_rtcf_result SET rtcf_json_bf ='${JSON.stringify(mode)}'` |
| | | }else if (mode.bmi){ |
| | | updateSql=`UPDATE patient_rtcf_result SET rtcf_json_bmi ='${JSON.stringify(mode)}'` |
| | | } |
| | | if(updateSql){ |
| | | console.log(`-------------------------更新${updateSql}---------`) |
| | | console.log(updateSql) |
| | | await pool.promise().query(updateSql) |
| | | } |
| | | }else{ |
| | | console.log('34') |
| | | // 临时的人体成分分析 |
| | | let bf='' |
| | | // 临时的身高体重 |
| | | let bmi='' |
| | | if(mode.fatFree){ |
| | | bf=JSON.stringify(mode) |
| | | } |
| | | if(mode.bmi){ |
| | | bmi=JSON.stringify(mode) |
| | | } |
| | | console.log(`bf=${bf},bmi=====${bmi}`) |
| | | let sqlStr=`INSERT INTO patient_rtcf_result (id, code, patient_code,`+ |
| | | `comm_time,rtcf_json_bmi,`+ |
| | | `rtcf_json_bf,`+ |
| | | `create_time)`+ |
| | | `VALUES (0, '${mode.recordNo}', '${mode.userID}', '${mode.measureTime}','${bmi}','${bf}','${moment(new Date()).format('YYYY-MM-DD HH:mm:ss')}')` |
| | | console.log(sqlStr) |
| | | await pool.promise().query(sqlStr) |
| | | } |
| | | |
| | | }catch(err){ |
| | | console.log('数据写入异常22') |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 根据身份证算年龄 |
| | | */ |
| | | |
| | | function getAgeFromIdCard(idCard) { |
| | | // 检查身份证号码长度是否正确 |
| | |
| | | return age; |
| | | } |
| | | |
| | | /** |
| | | * 时间戳转string 输出: "2024-01-08 00:00:00" (假设时区为东八区) |
| | | * @param {*} date |
| | | */ |
| | | function getDateString(date){ |
| | | try{ |
| | | if(date){ |
| | | let timestamp = 1734624000000; |
| | | let d = new Date(timestamp); |
| | | return `${d.getFullYear()}-${String(d.getMonth() + 1).padStart(2, '0')}-${String(d.getDate()).padStart(2, '0')} ${String(d.getHours()).padStart(2, '0')}:${String(d.getMinutes()).padStart(2, '0')}:${String(d.getSeconds()).padStart(2, '0')}`; |
| | | }else{ |
| | | return '' |
| | | } |
| | | } |
| | | catch(err){ |
| | | console.log(err) |
| | | return '' |
| | | } |
| | | |
| | | |
| | | } |
| | | function getCurrentDateFormatted() { |
| | | const date = new Date(); |
| | | |
| | | const year = date.getFullYear(); // 获取年份,如 2025 |
| | | |
| | | const month = String(date.getMonth() + 1).padStart(2, '0'); // 获取月份(0-11),需要 +1,然后补零 |
| | | |
| | | const day = String(date.getDate()).padStart(2, '0'); // 获取日期,并补零 |
| | | |
| | | return `${year}${month}${day}`; |
| | | } |
| | | function formatTimestamp(timestampStr) { |
| | | const str = String(timestampStr); |
| | | |
| | | // 使用正则表达式匹配 YYYYMMDDHHMMSS 并分组 |
| | | const match = str.match(/^(\d{4})(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})$/); |
| | | |
| | | if (!match) { |
| | | throw new Error("Invalid timestamp format"); |
| | | } |
| | | |
| | | // 重组为 YYYY-MM-DD HH:mm:ss |
| | | return `${match[1]}-${match[2]}-${match[3]} ${match[4]}:${match[5]}:${match[6]}`; |
| | | } |
| | | |
| | | |
| | | function formatted() { |
| | | const date = new Date(); |
| | | return date.getFullYear() + '-' + |
| | | String(date.getMonth() + 1).padStart(2, '0') + '-' + |
| | | String(date.getDate()).padStart(2, '0') + ' ' + |
| | | String(date.getHours()).padStart(2, '0') + ':' + |
| | | String(date.getMinutes()).padStart(2, '0') + ':' + |
| | | String(date.getSeconds()).padStart(2, '0'); |
| | | } |