| | |
| | | const thirdPartyApi = require(path.resolve(__dirname, 'thirdPartyApi')); |
| | | |
| | | const app = express(); |
| | | app.use(bodyParser.json()) |
| | | const port = 3000; |
| | | |
| | | // 设置 JSON 请求体的最大大小为 5MB |
| | |
| | | |
| | | |
| | | }) |
| | | // 假设这里有一个模拟的用户数据存储 |
| | | const usersData = [ |
| | | { |
| | | USER_ID: 'test1', |
| | | USER_NAME: 'name1', |
| | | USER_GENDER: 'M', |
| | | USER_BIRTHDAY: '19821201', |
| | | USER_AGE: '36', |
| | | USER_HEIGHT: '178.5', |
| | | ORDER_DATE: '20191025' |
| | | } |
| | | ]; |
| | | // 大连新的InBody 人体成分分析仪患者注册 |
| | | app.post('/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 || !ORDER_DATE) { |
| | | return res.status(400).json({ |
| | | IsResult: false, |
| | | INBODY_USER_INFO: [], |
| | | ErrorMsg: 'USER_ID or ORDER_DATE is missing' |
| | | }); |
| | | } |
| | | // 在模拟数据中查找匹配的用户信息 |
| | | const userInfo = usersData.find(user => user.USER_ID === USER_ID && user.ORDER_DATE === ORDER_DATE); |
| | | const pathParams = { clientCode:'CLIENT9195181802236kHJF',patientHemoCode:USER_ID} |
| | | const data = await thirdPartyApi.fetchThirdPartyData('/patient/info/queryInAndOuts', 'POST', {}, null, {},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.code, |
| | | USER_NAME: mode.patientName, |
| | | USER_GENDER: mode.patientGender===0? 'M':'F', |
| | | USER_BIRTHDAY: '', |
| | | USER_AGE: mode.age, |
| | | USER_HEIGHT: mode.patientHeight, |
| | | ORDER_DATE: getCurrentDateFormatted() |
| | | } |
| | | 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.listen(port, async () => { |
| | |
| | | } |
| | | |
| | | |
| | | } |
| | | } |
| | | 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}`; |
| | | } |