From 6022cfd5cd15b8917ccfd5a635cd49ba47f14ce1 Mon Sep 17 00:00:00 2001
From: chenyc <501753378@qq.com>
Date: 星期四, 24 七月 2025 15:43:02 +0800
Subject: [PATCH] gx大连INBODY人体成分分析仪

---
 app.js |  111 ++++++++++++++++++++++++++++++++++++++++++++++++++++++-
 1 files changed, 108 insertions(+), 3 deletions(-)

diff --git a/app.js b/app.js
index d97bce9..397b688 100644
--- a/app.js
+++ b/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
@@ -383,10 +384,10 @@
             image:body.image,
             request_doctor:body.requestDoctor,
             request_department:body.requestDepartment,
-            request_date:body.requestDate,
+            request_date:getDateString(body.requestDate),
             exam_department:body.examDepartment,
             diagnostician_doctor:body.diagnosticianDoctor,
-            check_date:body.checkDate,
+            check_date:getDateString(body.checkDate),
             check_result:body.checkResult,
             diagnosis:body.diagnosis,
             exam_type_id:body.examTypeId,
@@ -408,11 +409,82 @@
     }
     catch(err){
         logger.info(`血流量设备上报结果,请求报错`)
-        res.status(400).json({ retCode: "-1", msg: "请求出错了" });
+        res.status(400).json({ retCode: "-1", msg: "请求出错了11" });
     }
   
 
     
+})
+// 假设这里有一个模拟的用户数据存储
+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(`请求患者失败:没有找到用户`)
+        }
 })
 
 // 启动服务器
@@ -510,3 +582,36 @@
 
     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}`;
+}

--
Gitblit v1.8.0