get_drug_details
Retrieve comprehensive drug information from the FDA DailyMed database using a SET ID, including labels, NDC codes, RxNorm mappings, and pharmacologic classifications.
Instructions
Get detailed information about a specific drug by its SET ID
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| setId | Yes | The SET ID of the drug to get details for |
Implementation Reference
- src/clients/spl-client.ts:172-285 (handler)The handler logic for 'get_drug_details' (implemented as `getSPLBySetId` in `SPLClient`).
async getSPLBySetId(setId: string): Promise<SPLDocument> { if (!setId || typeof setId !== "string") { throw new Error("Valid SET ID is required"); } return new Promise((resolve, reject) => { this.client .get(`/spls/${setId}.xml`) .then((response) => { parseString(response.data, (err, result) => { if (err) { reject(new Error(`Failed to parse XML: ${err.message}`)); return; } try { // Extract basic information const document = result?.document; if (!document) { throw new Error("Invalid SPL document structure"); } const title = extractTextContent(document.title) || "No title available"; const effectiveTime = document.effectiveTime?.[0]?.$?.value || "Unknown"; const versionNumber = document.versionNumber?.[0]?.$?.value || "1"; // Extract sections const sections: SPLSection[] = []; const component = document.component?.[0]; if (component?.structuredBody?.[0]?.component) { const bodyComponents = component.structuredBody[0].component; for (const comp of bodyComponents) { const section = comp.section?.[0]; if (section) { const sectionTitle = extractTextContent(section.title) || "Untitled Section"; let content = ""; if (section.text?.[0]) { const textElement = section.text[0]; // Handle different content types if (textElement.paragraph) { content = textElement.paragraph.map((p: any) => extractTextContent(p)).join("\n\n"); } else if (textElement.list) { content = textElement.list.map((list: any) => { if (list.item) { return extractListContent(list.item); } return ""; }).join("\n\n"); } else if (textElement.table) { content = textElement.table.map((table: any) => extractTableContent(table)).join("\n\n"); } else { content = extractTextContent(textElement); } } if (content.trim()) { sections.push({ id: section.id?.[0]?.$?.root, title: sectionTitle, content: content.trim(), }); } } } } // Get mapping data for this setId const rxNormMappings = this.mappingService.getRxNormMappings(setId); const pharmacologicClassMappings = this.mappingService.getPharmacologicClassMappings(setId); // Filter out redundant fields from mappings const filteredRxNormMappings = rxNormMappings.map(mapping => ({ rxcui: mapping.rxcui, rxstring: mapping.rxstring, rxtty: mapping.rxtty, })); const filteredPharmacologicClassMappings = pharmacologicClassMappings.map(mapping => ({ pharmaSetId: mapping.pharmaSetId, pharmaVersion: mapping.pharmaVersion, })); resolve({ setId: setId, title: title || "No title available", effectiveTime: effectiveTime, versionNumber: versionNumber, sections: sections, spl_medguide: undefined, spl_patient_package_insert: undefined, spl_product_data_elements: undefined, rxNormMappings: filteredRxNormMappings.length > 0 ? filteredRxNormMappings : undefined, pharmacologicClassMappings: filteredPharmacologicClassMappings.length > 0 ? filteredPharmacologicClassMappings : undefined, }); } catch (parseError) { reject( new Error( `Failed to extract data from XML: ${parseError instanceof Error ? parseError.message : "Unknown error"}`, ), ); } }); }) .catch((error) => { reject( new Error( `Failed to fetch SPL: ${error instanceof Error ? error.message : "Unknown error"}`, ), ); }); }); } - src/tools.ts:12-25 (registration)Registration of the 'get_drug_details' tool in `src/tools.ts`.
{ name: "get_drug_details", description: "Get detailed information about a specific drug by its SET ID", inputSchema: { type: "object", properties: { setId: { type: "string", description: "The SET ID of the drug to get details for", }, }, required: ["setId"], }, },