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