import httpx | |
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 [ | |
{ | |
"name": row["title"], | |
"set_id": row["setid"], | |
"url": f"https://dailymed.nlm.nih.gov/dailymed/drugInfo.cfm?setid={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, drung 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 | |