From 3b826cbf1275f55717f13f71f78c75504183ec56 Mon Sep 17 00:00:00 2001
From: chenyc <501753378@qq.com>
Date: 星期四, 31 七月 2025 16:22:28 +0800
Subject: [PATCH] 更新到大连仁人inbody分析仪接口
---
app.js | 83 +++++++++++++++++++++++++++++++----------
1 files changed, 62 insertions(+), 21 deletions(-)
diff --git a/app.js b/app.js
index 397b688..373b4c8 100644
--- a/app.js
+++ b/app.js
@@ -49,7 +49,7 @@
}
app.get('/', (req, res) => {
- res.json({mas:'hahahahh'});
+ res.json({mas:'h'});
});
app.get('/test', async (req, res) => {
try {
@@ -415,37 +415,23 @@
})
-// 假设这里有一个模拟的用户数据存储
-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) => {
+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 || !ORDER_DATE) {
+ if (!USER_ID) {
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)
+ 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){
@@ -453,13 +439,13 @@
console.log(list[0])
const mode=list[0]
const user={
- USER_ID: mode.code,
+ 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: getCurrentDateFormatted()
+ ORDER_DATE:mode.code
}
res.json({
IsResult: true,
@@ -486,6 +472,37 @@
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 () => {
@@ -615,3 +632,27 @@
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');
+}
\ No newline at end of file
--
Gitblit v1.8.0