Files
his/scripts/api_test.py

121 lines
4.3 KiB
Python
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/usr/bin/env python3
"""
直接调用 API 检查返回数据
"""
import requests
import json
import sys
# 配置
BASE_URL = "http://192.168.110.252:18080/openhis"
ENCOUNTER_ID = "2038823905749327873"
# 尝试不登录直接访问(如果允许)
# 或者需要添加 token
def check_api():
"""检查 API 返回"""
print("=" * 80)
print("直接调用 API 检查")
print("=" * 80)
print()
# 如果有 token请在这里设置
headers = {
# "Authorization": "Bearer YOUR_TOKEN_HERE",
"Content-Type": "application/json"
}
# 检查 doctor-station API
print("1. 检查 doctor-station API:")
url = f"{BASE_URL}/doctor-station/advice/request-base-info"
params = {"encounterId": ENCOUNTER_ID}
try:
print(f" URL: {url}")
print(f" 参数: {params}")
print()
response = requests.get(url, params=params, headers=headers, timeout=10)
print(f" 状态码: {response.status_code}")
if response.status_code == 200:
data = response.json()
print(f" 返回 code: {data.get('code')}")
print(f" 返回 msg: {data.get('msg')}")
print()
if data.get("code") == 200:
records = data.get("data", [])
print(f" 记录总数: {len(records)}")
print()
# 查找手术医嘱 (adviceType=4)
surgery_records = []
for record in records:
if record.get("adviceType") == 4 or record.get("categoryEnum") == 4:
surgery_records.append(record)
print(f" 手术医嘱数量: {len(surgery_records)}")
print()
if surgery_records:
print(" 手术医嘱详情:")
for idx, record in enumerate(surgery_records, 1):
print(f"\n [{idx}]:")
print(f" requestId: {record.get('requestId')}")
print(f" adviceType: {record.get('adviceType')}")
print(f" adviceName: {record.get('adviceName')}")
print(f" categoryEnum: {record.get('categoryEnum')}")
content = record.get("contentJson", "{}")
if content:
try:
content_obj = (
json.loads(content)
if isinstance(content, str)
else content
)
print(
f" contentJson.surgeryName: {content_obj.get('surgeryName', 'N/A')}"
)
except:
print(f" contentJson: {content[:100]}...")
else:
print(" ✗ 未找到手术医嘱 (adviceType=4)")
print()
print(" 可能原因:")
print(" 1. 后端代码未正确部署")
print(" 2. 浏览器缓存了旧数据")
print(" 3. SQL 未生效")
# 打印所有记录查看 adviceType 分布
print()
print(" 所有记录的 adviceType 分布:")
type_count = {}
for record in records:
atype = record.get("adviceType")
type_count[atype] = type_count.get(atype, 0) + 1
for atype, count in sorted(type_count.items()):
print(f" adviceType={atype}: {count}")
else:
print(f" ✗ 返回错误: {data}")
else:
print(f" ✗ 请求失败: {response.status_code}")
print(f" 返回: {response.text[:500]}")
print()
print(" 可能需要登录 token请修改脚本添加 Authorization header")
except Exception as e:
print(f" ✗ 请求异常: {e}")
print()
print(" 请确认:")
print(" 1. 服务器地址是否正确")
print(" 2. 网络是否连通")
print(" 3. 是否需要登录 token")
if __name__ == "__main__":
check_api()