File size: 1,350 Bytes
5bb1986 0f4b0ea 5bb1986 d9a5339 5bb1986 d9a5339 5bb1986 0f4b0ea 5bb1986 d38794d 5bb1986 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
import httpx
from app.tools.utils import generate_id
def find_drug_set_ids(name: str) -> list[dict]:
"""Get the Set IDs of drugs by a name.
The Set ID can be used to look up a drug's instruction.
Args:
name: Generic or brand name of a drug.
Returns:
A list of drug names and their Set ID.
"""
resp = httpx.get(
"https://dailymed.nlm.nih.gov/dailymed/services/v2/spls.json",
params={"drug_name": name},
)
return [
{
"title": row["title"],
"set_id": row["setid"],
"venue": "DailyMed",
"year": row["published_date"][-4:], # Original format: "May 05, 2025"
"url": f"https://dailymed.nlm.nih.gov/dailymed/drugInfo.cfm?setid={row['setid']}",
"id": f"med-{generate_id(row['setid'])}",
}
for row in resp.json()["data"]
]
def find_drug_instruction(set_id: str) -> str:
"""Get the instruction of a drug from the FDA database.
The instruction includes dosage, contradictions, adverse
reactions, drug interactions, etc.
Args:
set_id: Set ID of the drug to look up.
Returns:
Full package instruction in XML format.
"""
resp = httpx.get(
f"https://dailymed.nlm.nih.gov/dailymed/services/v2/spls/{set_id}.xml"
)
return resp.text
|