tooluniverse.openfda_tool 模块

tooluniverse.openfda_tool._get_drug_names_query()[源代码]

Get the GraphQL query for drug names (cached)

tooluniverse.openfda_tool._execute_opentargets_query(chembl_id)[源代码]

Directly execute OpenTargets GraphQL query (most efficient)

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

递归提取字典列表中的嵌套字段。

参数:
  • records – 用于提取字段的字典列表

  • fields – 要提取的嵌套字段列表,每个字段均以点表示法指定(例如,’openfda.brand_name’)

返回:

仅包含指定字段的字典列表

tooluniverse.openfda_tool.map_properties_to_openfda_fields(arguments, search_fields)[源代码]

根据 search_fields 映射,将提供的参数映射到相应的 openFDA 字段。

参数:
  • arguments – 包含属性名称和值的输入参数。

  • search_fields – 属性名称与 openFDA 字段的映射。

返回:

一个包含openFDA字段及其对应值的字典。

tooluniverse.openfda_tool.extract_sentences_with_keywords(text_list, keywords)[源代码]

从文本中提取包含任何指定关键词的句子。

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)[源代码]
class tooluniverse.openfda_tool.FDATool[源代码]

基类:BaseTool

__init__(tool_config, endpoint_url, api_key=None)[源代码]
run(arguments)[源代码]

执行该工具。

默认的 BaseTool 实现接受一个可选的参数映射,以便与大多数具体工具实现保持一致,这些工具通常期望输入为一个字典。

参数:
  • arguments (dict, optional) – 工具专用参数

  • stream_callback (callable, optional) – 用于流式响应的回调

  • use_cache (bool, optional) – 是否启用了结果缓存

  • validate (bool, optional) – 是否已执行参数验证

备注

这些附加参数(stream_callback、use_cache、validate)由 run_one_function() 传递,用于提供有关执行的上下文信息。工具可以利用这些参数进行优化或特殊处理。

为了向后兼容,不接受这些参数的工具仍然可以正常运行——它们将只接收 arguments 参数。

class tooluniverse.openfda_tool.FDADrugLabelTool[源代码]

基类:FDATool

__init__(tool_config, api_key=None)[源代码]
_is_chembl_id(value)[源代码]

Check if the value looks like a ChEMBL ID

_convert_id_to_drug_name(chembl_id)[源代码]

Convert ChEMBL ID to drug name using OpenTargets API

run(arguments)[源代码]

Override run to support ChEMBL ID conversion

class tooluniverse.openfda_tool.FDADrugLabelSearchTool[源代码]

基类:FDATool

__init__(tool_config=None, api_key=None)[源代码]
run(arguments)[源代码]

执行该工具。

默认的 BaseTool 实现接受一个可选的参数映射,以便与大多数具体工具实现保持一致,这些工具通常期望输入为一个字典。

参数:
  • arguments (dict, optional) – 工具专用参数

  • stream_callback (callable, optional) – 用于流式响应的回调

  • use_cache (bool, optional) – 是否启用了结果缓存

  • validate (bool, optional) – 是否已执行参数验证

备注

这些附加参数(stream_callback、use_cache、validate)由 run_one_function() 传递,用于提供有关执行的上下文信息。工具可以利用这些参数进行优化或特殊处理。

为了向后兼容,不接受这些参数的工具仍然可以正常运行——它们将只接收 arguments 参数。

class tooluniverse.openfda_tool.FDADrugLabelSearchIDTool[源代码]

基类:FDATool

__init__(tool_config=None, api_key=None)[源代码]
run(arguments)[源代码]

执行该工具。

默认的 BaseTool 实现接受一个可选的参数映射,以便与大多数具体工具实现保持一致,这些工具通常期望输入为一个字典。

参数:
  • arguments (dict, optional) – 工具专用参数

  • stream_callback (callable, optional) – 用于流式响应的回调

  • use_cache (bool, optional) – 是否启用了结果缓存

  • validate (bool, optional) – 是否已执行参数验证

备注

这些附加参数(stream_callback、use_cache、validate)由 run_one_function() 传递,用于提供有关执行的上下文信息。工具可以利用这些参数进行优化或特殊处理。

为了向后兼容,不接受这些参数的工具仍然可以正常运行——它们将只接收 arguments 参数。

class tooluniverse.openfda_tool.FDADrugLabelFieldValueTool[源代码]

基类:BaseTool

Search the openFDA drug label dataset by specifying a single openFDA field (e.g., “openfda.generic_name”) and a corresponding field_value.

This tool is intentionally generic and does not modify any existing FDA tools.

__init__(tool_config, api_key=None)[源代码]
run(arguments)[源代码]

执行该工具。

默认的 BaseTool 实现接受一个可选的参数映射,以便与大多数具体工具实现保持一致,这些工具通常期望输入为一个字典。

参数:
  • arguments (dict, optional) – 工具专用参数

  • stream_callback (callable, optional) – 用于流式响应的回调

  • use_cache (bool, optional) – 是否启用了结果缓存

  • validate (bool, optional) – 是否已执行参数验证

备注

这些附加参数(stream_callback、use_cache、validate)由 run_one_function() 传递,用于提供有关执行的上下文信息。工具可以利用这些参数进行优化或特殊处理。

为了向后兼容,不接受这些参数的工具仍然可以正常运行——它们将只接收 arguments 参数。

class tooluniverse.openfda_tool.FDADrugLabelGetDrugGenericNameTool[源代码]

基类:FDADrugLabelTool

__init__(tool_config=None, api_key=None)[源代码]
run(arguments)[源代码]

Override run to support ChEMBL ID conversion

class tooluniverse.openfda_tool.FDADrugLabelGetDrugNamesByIndicationAggregated[源代码]

基类: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)[源代码]
run(arguments)[源代码]

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[源代码]

基类: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)[源代码]
run(arguments)[源代码]

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

class tooluniverse.openfda_tool.OpenFDADrugEventsTool[源代码]

基类:BaseRESTTool

OpenFDA drug adverse event search with convenience parameters.

Accepts either a raw Lucene ‘search’ string or the convenience parameters ‘drug_name’ and ‘reaction’ (which are assembled into a Lucene query).

Note: MedDRA terms in FAERS use British English spelling (e.g. ‘haemorrhage’ not ‘hemorrhage’, ‘haematoma’ not ‘hematoma’).

_VALID_API_PARAMS = frozenset({'api_key', 'count', 'limit', 'search', 'skip'})
run(arguments)[源代码]

Execute the API request.

参数:

arguments (Dict[str, Any]) – Tool arguments dictionary

返回:

Result dictionary with status, data, url, and optional error info

返回类型:

Dict[str, Any]