chenyc
2025-07-31 3b826cbf1275f55717f13f71f78c75504183ec56
app.js
@@ -13,6 +13,7 @@
const thirdPartyApi = require(path.resolve(__dirname, 'thirdPartyApi'));
const app = express();
app.use(bodyParser.json())
const port = 3000;
// 设置 JSON 请求体的最大大小为 5MB
@@ -48,7 +49,7 @@
}
app.get('/', (req, res) => {
    
    res.json({mas:'hahahahh'});
    res.json({mas:'h'});
  });
app.get('/test', async (req, res) => {
try {
@@ -414,6 +415,94 @@
    
})
// 大连新的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 () => {
@@ -531,4 +620,39 @@
    }
    
   
}
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');
}