tooluniverse.openfda_tool module

tooluniverse.openfda_tool._get_drug_names_query()[source]

Get the GraphQL query for drug names (cached)

tooluniverse.openfda_tool._execute_opentargets_query(chembl_id)[source]

Directly execute OpenTargets GraphQL query (most efficient)

tooluniverse.openfda_tool.check_keys_present(api_capabilities_dict, keys)[source]
tooluniverse.openfda_tool.extract_nested_fields(records, fields, keywords=None)[source]

Recursively extracts nested fields from a list of dictionaries.

Parameters:
  • records – List of dictionaries from which to extract fields

  • fields – List of nested fields to extract, each specified with dot notation (e.g., ‘openfda.brand_name’)

Returns:

List of dictionaries containing only the specified fields

tooluniverse.openfda_tool.map_properties_to_openfda_fields(arguments, search_fields)[source]

Maps the provided arguments to the corresponding openFDA fields based on the search_fields mapping.

Parameters:
  • arguments – The input arguments containing property names and values.

  • search_fields – The mapping of property names to openFDA fields.

Returns:

A dictionary with openFDA fields and corresponding values.

tooluniverse.openfda_tool.extract_sentences_with_keywords(text_list, keywords)[source]

Extracts sentences containing any of the specified keywords from the text.

Parameters - text (str): The input text from which to extract sentences. - keywords (list): A list of keywords to search for in the text.

Returns - list: A list of sentences containing any of the keywords.

tooluniverse.openfda_tool.search_openfda(params=None, endpoint_url=None, api_key=None, sort=None, limit=5, skip=None, count=None, exists=None, return_fields=None, exist_option='OR', search_keyword_option='AND', keywords_filter=True)[source]
class tooluniverse.openfda_tool.FDATool[source]

Bases: BaseTool

__init__(tool_config, endpoint_url, api_key=None)[source]
run(arguments)[source]

Execute the tool.

The default BaseTool implementation accepts an optional arguments mapping to align with most concrete tool implementations which expect a dictionary of inputs.

Parameters:
  • arguments (dict, optional) – Tool-specific arguments

  • stream_callback (callable, optional) – Callback for streaming responses

  • use_cache (bool, optional) – Whether result caching is enabled

  • validate (bool, optional) – Whether parameter validation was performed

Note

These additional parameters (stream_callback, use_cache, validate) are passed from run_one_function() to provide context about the execution. Tools can use these for optimization or special handling.

For backward compatibility, tools that don’t accept these parameters will still work - they will only receive the arguments parameter.

class tooluniverse.openfda_tool.FDADrugLabelTool[source]

Bases: FDATool

__init__(tool_config, api_key=None)[source]
_is_chembl_id(value)[source]

Check if the value looks like a ChEMBL ID

_convert_id_to_drug_name(chembl_id)[source]

Convert ChEMBL ID to drug name using OpenTargets API

run(arguments)[source]

Override run to support ChEMBL ID conversion

class tooluniverse.openfda_tool.FDADrugLabelSearchTool[source]

Bases: FDATool

__init__(tool_config=None, api_key=None)[source]
run(arguments)[source]

Execute the tool.

The default BaseTool implementation accepts an optional arguments mapping to align with most concrete tool implementations which expect a dictionary of inputs.

Parameters:
  • arguments (dict, optional) – Tool-specific arguments

  • stream_callback (callable, optional) – Callback for streaming responses

  • use_cache (bool, optional) – Whether result caching is enabled

  • validate (bool, optional) – Whether parameter validation was performed

Note

These additional parameters (stream_callback, use_cache, validate) are passed from run_one_function() to provide context about the execution. Tools can use these for optimization or special handling.

For backward compatibility, tools that don’t accept these parameters will still work - they will only receive the arguments parameter.

class tooluniverse.openfda_tool.FDADrugLabelSearchIDTool[source]

Bases: FDATool

__init__(tool_config=None, api_key=None)[source]
run(arguments)[source]

Execute the tool.

The default BaseTool implementation accepts an optional arguments mapping to align with most concrete tool implementations which expect a dictionary of inputs.

Parameters:
  • arguments (dict, optional) – Tool-specific arguments

  • stream_callback (callable, optional) – Callback for streaming responses

  • use_cache (bool, optional) – Whether result caching is enabled

  • validate (bool, optional) – Whether parameter validation was performed

Note

These additional parameters (stream_callback, use_cache, validate) are passed from run_one_function() to provide context about the execution. Tools can use these for optimization or special handling.

For backward compatibility, tools that don’t accept these parameters will still work - they will only receive the arguments parameter.

class tooluniverse.openfda_tool.FDADrugLabelGetDrugGenericNameTool[source]

Bases: FDADrugLabelTool

__init__(tool_config=None, api_key=None)[source]
run(arguments)[source]

Override run to support ChEMBL ID conversion

class tooluniverse.openfda_tool.FDADrugLabelGetDrugNamesByIndicationAggregated[source]

Bases: FDADrugLabelTool

Enhanced version of FDA_get_drug_names_by_indication that: - Iterates through all results in batches of 100 (no limit) - Aggregates results by generic name - Returns one entry per generic name with indication and all brand names

__init__(tool_config, api_key=None)[source]
run(arguments)[source]

Run the aggregated drug names search by indication.

Iterates through all results in batches of 100, aggregates by generic name, and returns a list where each entry contains: - generic_name: The generic drug name - indication: The indication (from input) - brand_names: List of all brand names for this generic name

class tooluniverse.openfda_tool.FDADrugLabelGetDrugNamesByIndicationStats[source]

Bases: FDADrugLabelTool

Enhanced version using FDA count API to efficiently aggregate drug names by indication. Uses count mechanism to get brand_name and generic_name distributions without fetching full records.

__init__(tool_config, api_key=None)[source]
run(arguments)[source]

Run the aggregated drug names search using count API.

Uses count API to: 1. Get all unique generic names for the indication 2. For each generic name, get corresponding brand names 3. Return aggregated results