From 1a75bdddcea613825535fd03c9ac318c3ca8dc3c Mon Sep 17 00:00:00 2001
From: chenyc <501753378@qq.com>
Date: 星期四, 31 七月 2025 16:23:10 +0800
Subject: [PATCH] 更新到大连仁人inbody分析仪接口1
---
app.js | 154 ++++++++++++++++++++++++++++++++++++++++++++++++++-
1 files changed, 150 insertions(+), 4 deletions(-)
diff --git a/app.js b/app.js
index d97bce9..9056ebb 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
@@ -48,7 +49,7 @@
}
app.get('/', (req, res) => {
- res.json({mas:'hahahahh'});
+ res.json({mas:'hdadsadas'});
});
app.get('/test', async (req, res) => {
try {
@@ -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,12 +409,100 @@
}
catch(err){
logger.info(`血流量设备上报结果,请求报错`)
- res.status(400).json({ retCode: "-1", msg: "请求出错了" });
+ 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 () => {
@@ -510,3 +599,60 @@
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');
+}
\ No newline at end of file
--
Gitblit v1.8.0