name: fda-database description: “通过openFDA API查询药物、设备、不良事件、召回、监管提交(510k、PMA)、物质识别(UNII),用于FDA监管数据分析和安全研究。”
FDA数据库访问
概述
通过openFDA访问全面的FDA监管数据,openFDA是FDA提供公共数据集开放API的倡议。使用Python和标准化接口查询关于药物、医疗设备、食品、动物/兽医产品和物质的信息。
关键能力:
- 查询药物、设备、食品和兽医产品的不良事件
- 访问产品标签、批准和监管提交
- 监控召回和执法行动
- 查找国家药品代码(NDC)和物质标识符(UNII)
- 分析设备分类和许可(510k、PMA)
- 跟踪药物短缺和供应问题
- 研究化学结构和物质关系
何时使用此技能
此技能应在以下情况下使用:
- 药物研究:安全概况、不良事件、标签、批准、短缺
- 医疗设备监控:不良事件、召回、510(k)许可、PMA批准
- 食品安全:召回、过敏原跟踪、不良事件、膳食补充剂
- 兽医医学:按物种和品种的动物药物不良事件
- 化学/物质数据:UNII查找、CAS号映射、分子结构
- 监管分析:批准路径、执法行动、合规跟踪
- 药物警戒:上市后监控、安全信号检测
- 科学研究:药物相互作用、比较安全性、流行病学研究
快速开始
1. 基本设置
from scripts.fda_query import FDAQuery
# 初始化(API密钥可选但推荐)
fda = FDAQuery(api_key="YOUR_API_KEY")
# 查询药物不良事件
events = fda.query_drug_events("aspirin", limit=100)
# 获取药物标签
label = fda.query_drug_label("Lipitor", brand=True)
# 搜索设备召回
recalls = fda.query("device", "enforcement",
search="classification:Class+I",
limit=50)
2. API密钥设置
虽然API无需密钥也能工作,但注册可获得更高请求限制:
- 无密钥:240请求/分钟,1,000/天
- 有密钥:240请求/分钟,120,000/天
注册地址:https://open.fda.gov/apis/authentication/
设置为环境变量:
export FDA_API_KEY="your_key_here"
3. 运行示例
# 运行综合示例
python scripts/fda_examples.py
# 演示内容:
# - 药物安全概况
# - 设备监控
# - 食品召回监控
# - 物质查找
# - 比较药物分析
# - 兽医药物分析
FDA数据库类别
药物
访问6个与药物相关的端点,覆盖从批准到上市后监控的完整药物生命周期。
端点:
- 不良事件 – 副作用、错误和治疗失败的报告
- 产品标签 – 处方信息、警告、适应症
- NDC目录 – 国家药品代码产品信息
- 执法报告 – 药物召回和安全行动
- Drugs@FDA – 1939年以来的历史批准数据
- 药物短缺 – 当前和已解决的供应问题
常见用例:
# 安全信号检测
fda.count_by_field("drug", "event",
search="patient.drug.medicinalproduct:metformin",
field="patient.reaction.reactionmeddrapt")
# 获取处方信息
label = fda.query_drug_label("Keytruda", brand=True)
# 检查召回
recalls = fda.query_drug_recalls(drug_name="metformin")
# 监控短缺
shortages = fda.query("drug", "drugshortages",
search="status:Currently+in+Shortage")
参考: 见references/drugs.md获取详细文档
设备
访问9个与设备相关的端点,覆盖医疗设备安全、批准和注册。
端点:
- 不良事件 – 设备故障、伤害、死亡
- 510(k)许可 – 上市前通知
- 分类 – 设备类别和风险等级
- 执法报告 – 设备召回
- 召回 – 详细召回信息
- PMA – III类设备的上市前批准数据
- 注册与清单 – 制造设施数据
- UDI – 唯一设备标识数据库
- COVID-19血清学 – 抗体测试性能数据
常见用例:
# 监控设备安全
events = fda.query_device_events("pacemaker", limit=100)
# 查找设备分类
classification = fda.query_device_classification("DQY")
# 查找510(k)许可
clearances = fda.query_device_510k(applicant="Medtronic")
# 通过UDI搜索
device_info = fda.query("device", "udi",
search="identifiers.id:00884838003019")
参考: 见references/devices.md获取详细文档
食品
访问2个与食品相关的端点,用于安全监控和召回。
端点:
- 不良事件 – 食品、膳食补充剂和化妆品事件
- 执法报告 – 食品产品召回
常见用例:
# 监控过敏原召回
recalls = fda.query_food_recalls(reason="undeclared peanut")
# 跟踪膳食补充剂事件
events = fda.query_food_events(
industry="Dietary Supplements")
# 查找污染召回
listeria = fda.query_food_recalls(
reason="listeria",
classification="I")
参考: 见references/foods.md获取详细文档
动物与兽医
访问兽医药物不良事件数据,包括物种特定信息。
端点:
- 不良事件 – 按物种、品种和产品的动物药物副作用
常见用例:
# 物种特定事件
dog_events = fda.query_animal_events(
species="Dog",
drug_name="flea collar")
# 品种倾向分析
breed_query = fda.query("animalandveterinary", "event",
search="reaction.veddra_term_name:*seizure*+AND+"
"animal.breed.breed_component:*Labrador*")
参考: 见references/animal_veterinary.md获取详细文档
物质与其他
访问分子级物质数据,包括UNII代码、化学结构和关系。
端点:
- 物质数据 – UNII、CAS、化学结构、关系
- NSDE – 历史物质数据(旧版)
常见用例:
# UNII到CAS映射
substance = fda.query_substance_by_unii("R16CO5Y76E")
# 按名称搜索
results = fda.query_substance_by_name("acetaminophen")
# 获取化学结构
structure = fda.query("other", "substance",
search="names.name:ibuprofen+AND+substanceClass:chemical")
参考: 见references/other.md获取详细文档
常见查询模式
模式1:安全概况分析
结合多个数据源创建综合安全概况:
def drug_safety_profile(fda, drug_name):
"""生成完整安全概况。"""
# 1. 总不良事件数
events = fda.query_drug_events(drug_name, limit=1)
total = events["meta"]["results"]["total"]
# 2. 最常见反应
reactions = fda.count_by_field(
"drug", "event",
search=f"patient.drug.medicinalproduct:*{drug_name}*",
field="patient.reaction.reactionmeddrapt",
exact=True
)
# 3. 严重事件
serious = fda.query("drug", "event",
search=f"patient.drug.medicinalproduct:*{drug_name}*+AND+serious:1",
limit=1)
# 4. 近期召回
recalls = fda.query_drug_recalls(drug_name=drug_name)
return {
"total_events": total,
"top_reactions": reactions["results"][:10],
"serious_events": serious["meta"]["results"]["total"],
"recalls": recalls["results"]
}
模式2:时间趋势分析
使用日期范围分析趋势:
from datetime import datetime, timedelta
def get_monthly_trends(fda, drug_name, months=12):
"""获取月度不良事件趋势。"""
trends = []
for i in range(months):
end = datetime.now() - timedelta(days=30*i)
start = end - timedelta(days=30)
date_range = f"[{start.strftime('%Y%m%d')}+TO+{end.strftime('%Y%m%d')}]"
search = f"patient.drug.medicinalproduct:*{drug_name}*+AND+receivedate:{date_range}"
result = fda.query("drug", "event", search=search, limit=1)
count = result["meta"]["results"]["total"] if "meta" in result else 0
trends.append({
"month": start.strftime("%Y-%m"),
"events": count
})
return trends
模式3:比较分析
并排比较多个产品:
def compare_drugs(fda, drug_list):
"""比较多种药物的安全概况。"""
comparison = {}
for drug in drug_list:
# 总事件数
events = fda.query_drug_events(drug, limit=1)
total = events["meta"]["results"]["total"] if "meta" in events else 0
# 严重事件数
serious = fda.query("drug", "event",
search=f"patient.drug.medicinalproduct:*{drug}*+AND+serious:1",
limit=1)
serious_count = serious["meta"]["results"]["total"] if "meta" in serious else 0
comparison[drug] = {
"total_events": total,
"serious_events": serious_count,
"serious_rate": (serious_count/total*100) if total > 0 else 0
}
return comparison
模式4:跨数据库查找
跨多个端点链接数据:
def comprehensive_device_lookup(fda, device_name):
"""在所有相关数据库中查找设备。"""
return {
"adverse_events": fda.query_device_events(device_name, limit=10),
"510k_clearances": fda.query_device_510k(device_name=device_name),
"recalls": fda.query("device", "enforcement",
search=f"product_description:*{device_name}*"),
"udi_info": fda.query("device", "udi",
search=f"brand_name:*{device_name}*")
}
处理结果
响应结构
所有API响应遵循此结构:
{
"meta": {
"disclaimer": "...",
"results": {
"skip": 0,
"limit": 100,
"total": 15234
}
},
"results": [
# 结果对象数组
]
}
错误处理
始终处理潜在错误:
result = fda.query_drug_events("aspirin", limit=10)
if "error" in result:
print(f"错误: {result['error']}")
elif "results" not in result or len(result["results"]) == 0:
print("未找到结果")
else:
# 处理结果
for event in result["results"]:
# 处理事件数据
pass
分页
对于大型结果集,使用分页:
# 自动分页
all_results = fda.query_all(
"drug", "event",
search="patient.drug.medicinalproduct:aspirin",
max_results=5000
)
# 手动分页
for skip in range(0, 1000, 100):
batch = fda.query("drug", "event",
search="...",
limit=100,
skip=skip)
# 处理批次
最佳实践
1. 使用特定搜索
推荐:
# 特定字段搜索
search="patient.drug.medicinalproduct:aspirin"
不推荐:
# 过于宽泛的通配符
search="*aspirin*"
2. 实施速率限制
FDAQuery类自动处理速率限制,但注意限制:
- 240请求/分钟
- 120,000请求/天(有API密钥时)
3. 缓存频繁访问数据
FDAQuery类包含内置缓存(默认启用):
# 缓存自动启用
fda = FDAQuery(api_key=api_key, use_cache=True, cache_ttl=3600)
4. 使用精确匹配进行计数
当计数/聚合时,使用.exact后缀:
# 计数精确短语
fda.count_by_field("drug", "event",
search="...",
field="patient.reaction.reactionmeddrapt",
exact=True) # 自动添加.exact
5. 验证输入数据
清理和验证搜索词:
def clean_drug_name(name):
"""清理药物名称以用于查询。"""
return name.strip().replace('"', '\\"')
drug_name = clean_drug_name(user_input)
API参考
详细文档:
- 认证和速率限制 → 见
references/api_basics.md - 药物数据库 → 见
references/drugs.md - 设备数据库 → 见
references/devices.md - 食品数据库 → 见
references/foods.md - 动物/兽医数据库 → 见
references/animal_veterinary.md - 物质数据库 → 见
references/other.md
脚本
scripts/fda_query.py
主要查询模块,提供FDAQuery类:
- 所有FDA端点的统一接口
- 自动速率限制和缓存
- 错误处理和重试逻辑
- 常见查询模式
scripts/fda_examples.py
综合示例:
- 药物安全概况分析
- 设备监控监控
- 食品召回跟踪
- 物质查找
- 比较药物分析
- 兽医药物分析
运行示例:
python scripts/fda_examples.py
其他资源
- openFDA主页:https://open.fda.gov/
- API文档:https://open.fda.gov/apis/
- 交互式API浏览器:https://open.fda.gov/apis/try-the-api/
- GitHub仓库:https://github.com/FDA/openfda
- 服务条款:https://open.fda.gov/terms/
支持与故障排除
常见问题
问题:超出速率限制
- 解决方案:使用API密钥、实施延迟或减少请求频率
问题:未找到结果
- 解决方案:尝试更广泛的搜索词、检查拼写、使用通配符
问题:查询语法无效
- 解决方案:在
references/api_basics.md中审查查询语法
问题:结果中缺少字段
- 解决方案:并非所有记录包含所有字段;始终检查字段是否存在
获取帮助
- GitHub Issues:https://github.com/FDA/openfda/issues
- 电子邮件:open-fda@fda.hhs.gov