Files
AIclinicalresearch/backend/src/modules/dc/tool-c/README.md
HaHafeng b31255031e feat(iit-manager): Add WeChat Official Account integration for patient notifications
Features:
- PatientWechatCallbackController for URL verification and message handling
- PatientWechatService for template and customer messages
- Support for secure mode (message encryption/decryption)
- Simplified route /wechat/patient/callback for WeChat config
- Event handlers for subscribe/unsubscribe/text messages
- Template message for visit reminders

Technical details:
- Reuse @wecom/crypto for encryption (compatible with Official Account)
- Relaxed Fastify schema validation to prevent early request blocking
- Access token caching (7000s with 5min pre-refresh)
- Comprehensive logging for debugging

Testing: Local URL verification passed, ready for SAE deployment

Status: Code complete, waiting for WeChat platform configuration
2026-01-04 22:53:42 +08:00

3.3 KiB
Raw Blame History

工具C (Tool C) - 科研数据编辑器

📁 项目结构

tool-c/
├── services/
│   └── PythonExecutorService.ts    # Python代码执行服务
├── controllers/
│   └── TestController.ts           # 测试控制器Day 1
├── routes/
│   └── index.ts                    # 路由定义
└── README.md                        # 本文件

⚙️ 环境变量配置

backend/.env 文件中添加以下配置:

# Python微服务地址
EXTRACTION_SERVICE_URL=http://localhost:8000

说明

  • 默认值:http://localhost:8000
  • Python微服务需要先启动才能使用工具C
  • 启动命令:cd extraction_service && .\venv\Scripts\activate && uvicorn main:app --host 0.0.0.0 --port 8000

🚀 API端点Day 1 测试)

1. 测试Python服务健康检查

GET /api/v1/dc/tool-c/test/health

响应

{
  "success": true,
  "message": "Python服务正常",
  "healthy": true
}

2. 测试代码验证

POST /api/v1/dc/tool-c/test/validate

请求体

{
  "code": "df['age_group'] = df['age'] > 60"
}

响应

{
  "success": true,
  "data": {
    "valid": true,
    "errors": [],
    "warnings": []
  }
}

3. 测试代码执行

POST /api/v1/dc/tool-c/test/execute

请求体

{
  "data": [
    {"age": 25},
    {"age": 65}
  ],
  "code": "df['old'] = df['age'] > 60"
}

响应

{
  "success": true,
  "data": {
    "success": true,
    "result_data": [
      {"age": 25, "old": false},
      {"age": 65, "old": true}
    ],
    "output": "",
    "error": null,
    "execution_time": 0.004,
    "result_shape": [2, 2]
  }
}

Day 1 完成情况

  • 创建Python微服务dc_executor.py
  • 添加AST安全检查
  • 实现Pandas代码执行
  • 创建FastAPI端点/api/dc/validate, /api/dc/execute
  • 创建Node.js服务PythonExecutorService.ts
  • 创建测试控制器和路由
  • 验证功能正常工作

📝 使用示例

启动Python微服务

cd extraction_service
.\venv\Scripts\activate
python main.py

启动Node.js后端

cd backend
npm run dev

测试API

# 1. 健康检查
curl http://localhost:3000/api/v1/dc/tool-c/test/health

# 2. 代码验证
curl -X POST http://localhost:3000/api/v1/dc/tool-c/test/validate \
  -H "Content-Type: application/json" \
  -d '{"code":"df[\"x\"] = 1"}'

# 3. 代码执行
curl -X POST http://localhost:3000/api/v1/dc/tool-c/test/execute \
  -H "Content-Type: application/json" \
  -d '{"data":[{"age":25},{"age":65}],"code":"df[\"old\"] = df[\"age\"] > 60"}'

🔐 安全特性

  • AST静态检查拦截危险模块导入os, sys, subprocess等
  • 超时保护代码执行超时30秒自动终止
  • 沙箱环境:限制可用的内置函数
  • 错误处理:完整的异常捕获和错误信息

📚 技术栈

  • Python后端: FastAPI + Pandas + AST
  • Node.js后端: Fastify + Axios + TypeScript
  • 通信方式: HTTP REST API
  • 数据格式: JSON

🎯 下一步Day 2

  • Session管理数据库 + OSS
  • 数据处理服务
  • AI代码生成服务LLMFactory集成
  • 前端基础框架搭建