技能创建器
skill-creator
创建、改进和评估自定义技能,把专业流程转化为可重复使用的 AI 能力。
fda-database【数据与研究】Query the openFDA API to retrieve FDA regulatory datasets (drugs, devices, adverse events, recalls, submissions, UNII) when you need programmatic safety/regulatory evidence for analysis or research.
独立 GitHub 快照 · 自动分类 · 以原作者文档为准
FDAQuery) for multiple openFDA domains (drug, device, food, animalandveterinary, other).count_by_field(...) (with .exact support)skip/limit and bulk retrieval via query_all(...)scripts/fda_query.py)Additional endpoint notes and query syntax are typically documented in:
references/api_basics.md,references/drugs.md,references/devices.md,references/foods.md,references/animal_veterinary.md,references/other.md.
Package-level dependencies (e.g.,
requests) are defined by the repository implementation inscripts/fda_query.py. If you maintain this skill, pin them inrequirements.txt(for example,requests==2.31.0) to ensure reproducibility.
The following example is designed to be runnable in a repository that contains scripts/fda_query.py and the FDAQuery class.
export FDA_API_KEY="your_key_here"
import os
from datetime import datetime, timedelta
from scripts.fda_query import FDAQuery
def drug_safety_profile(fda: FDAQuery, drug_name: str):
# Total adverse events (meta.total)
events = fda.query_drug_events(drug_name, limit=1)
total = events.get("meta", {}).get("results", {}).get("total", 0)
# Top reactions (aggregation)
reactions = fda.count_by_field(
"drug",
"event",
search=f"patient.drug.medicinalproduct:*{drug_name}*",
field="patient.reaction.reactionmeddrapt",
exact=True,
)
top_reactions = reactions.get("results", [])[:10]
# Serious events
serious = fda.query(
"drug",
"event",
search=f"patient.drug.medicinalproduct:*{drug_name}*+AND+serious:1",
limit=1,
)
serious_total = serious.get("meta", {}).get("results", {}).get("total", 0)
# Recent recalls
recalls = fda.query_drug_recalls(drug_name=drug_name)
recall_results = recalls.get("results", [])
return {
"drug": drug_name,
"total_events": total,
"serious_events": serious_total,
"serious_rate_pct": (serious_total / total * 100.0) if total else 0.0,
"top_reactions": top_reactions,
"recalls_sample": recall_results[:5],
}
def monthly_event_trend(fda: FDAQuery, drug_name: str, months: int = 6):
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}*"
f"+AND+receivedate:{date_range}"
)
result = fda.query("drug", "event", search=search, limit=1)
count = result.get("meta", {}).get("results", {}).get("total", 0)
trends.append({"month": start.strftime("%Y-%m"), "events": count})
return list(reversed(trends))
def main():
fda = FDAQuery(api_key=os.getenv("FDA_API_KEY"))
# Drug: safety profile + trend
profile = drug_safety_profile(fda, "aspirin")
trend = monthly_event_trend(fda, "aspirin", months=6)
# Device: quick cross-database lookup
device_lookup = {
"adverse_events": fda.query_device_events("pacemaker", limit=10),
"classification": fda.query_device_classification("DQY"),
"510k": fda.query_device_510k(applicant="Medtronic"),
"udi": fda.query("device", "udi", search="brand_name:*pacemaker*", limit=5),
}
# Food: recall monitoring
food_recalls = fda.query_food_recalls(reason="undeclared peanut", limit=10)
# Substance: UNII lookup
substance = fda.query_substance_by_unii("R16CO5Y76E")
print({"drug_profile": profile, "drug_trend": trend})
print({"device_lookup_keys": list(device_lookup.keys())})
print({"food_recalls_count": len(food_recalls.get("results", []))})
print({"substance_keys": list(substance.keys())})
if __name__ == "__main__":
main()
python scripts/fda_examples.py
This skill is a thin client over openFDA endpoints, typically accessed as:
drug/event, drug/label, drug/ndc, drug/enforcement, drug/drugsfda, drug/drugshortagesdevice/event, device/510k, device/classification, device/enforcement, device/recall, device/pma, device/registrationlisting, device/udi, device/covid19serologyfood/event, food/enforcementanimalandveterinary/eventother/substance, other/nsdeExact helper method names (e.g., query_drug_events, query_device_510k) are implemented in scripts/fda_query.py.
patient.drug.medicinalproduct:aspirin*aspirin* (use sparingly)A+AND+Breceivedate:[20240101+TO+20241231]limit (page size)skip (offset)count_by_field(domain, endpoint, search, field, exact=True):
exact=True, the implementation typically appends .exact to the aggregation field to avoid tokenization issues.FDAQuery implementation){
"meta": { "results": { "skip": 0, "limit": 100, "total": 12345 } },
"results": []
}
resultserror objects returned by the APIFDAQuery, caching reduces repeated calls for identical queries.use_cache=Truecache_ttl=<seconds>