药品信息查询API服务器

一个全面的药品信息查询、替代建议和成分分析API服务器,提供搜索、过滤和分析药品数据的高级功能。

  • by nowitsidb
  • Python
  • 本地部署
  • 7 星标
  • 更新于
在 GitHub 查看 nowitsidb/INDIAN_MEDICINE_MCP_SERVER

使用说明

印度药品(MCP服务器)

一个全面的API服务器,用于医学信息查询、替代建议和成分分析。该服务器提供多个端点,用于搜索、过滤和分析具有模糊匹配和价格比较等高级功能的药品数据。

📖 目录

📋 引言

MedicineDB API服务器是一款高性能工具,旨在提供对医学信息的全面访问。它提供了从基本药物查找到高级成分分析和替代药物建议的广泛功能。该服务器旨在高效处理大型数据集,同时提供准确和相关的结果。

✨ 特性

  • 高级搜索功能

    • 药品名称的精确与模糊匹配
    • 基于成分/成分的搜索
    • 带分页的多条件过滤
    • 制造商和价格范围过滤
  • 分析工具

    • 组合字符串解析器和分析器
    • 数据库的统计分析
    • 成分分类
  • 医疗决策支持

    • 替代医学建议
    • 同类药品价格比较
    • 处方要求过滤
  • 性能优化

    • 多重索引,实现快速查找
    • 高效的相似性计算
    • 预计算提取成分

🛠️ 技术栈

技术 目的
核心编程语言
服务器框架
数据存储格式

图书馆:

  • difflib:用于模糊字符串匹配和药品名称相似性
  • re:用于解析组合字符串和成分提取
  • collections:用于优化数据结构(defaultdict、Counter)
  • math:用于价格跳跃和分页计算
  • typing:用于类型提示
  • dataclasses:对于结构化数据

🚀 安装

  1. 克隆存储库:
git clone https://github.com/yourusername/medicines-db.git
cd medicines-db
  1. 安装依赖项:
pip install -r requirements.txt
  1. 准备您的药物数据库:
# Ensure your JSON data file is at the correct path
# Default path: /Users/siddharthbajpai/Downloads/MCP_SERVER/medicines.json
# Update DATA_PATH in the code if needed
  1. 运行服务器:
python medicines_server.py

📘 用法

服务器通过MCP(模型上下文协议)架构公开多个API端点。您可以使用任何MCP客户端与服务器交互。

基本示例:

from mcp.client import MCPClient

# Connect to the server
client = MCPClient("medicines-db")

# Search for a medicine
result = client.search_medicines("paracetamol", max_results=5)
print(result)

# Get alternatives to a specific medicine
alternatives = client.suggest_alternatives("Dolo 650")
print(alternatives)

📚 api参考

服务器通过MCP框架提供15个API端点:

搜索端点

1. get_medicine_by_name

GET /get_medicine_by_name

按确切名称检索病历,并提供可选的更便宜的替代方案。

参数:

  • name (string,必填):药物的确切名称字段
  • include_alternatives (布尔值,可选,默认值=true):是否在结果中包含更便宜的替代方案

答复:

{
  "medicine": {
    "Name": "Dolo 650",
    "Manufacturer": "Micro Labs Ltd",
    "Composition": "Paracetamol (650mg)",
    "MRP": "30.29",
    "Prescription": "No",
    "Price_INR": "₹30.29",
    "Price_Category": "Low",
    "Active_Ingredients": ["Paracetamol"],
    "Ingredient_Count": 1,
    "Is_Combination": false,
    "Requires_Prescription": false,
    "Prescription_Type": "Over-the-Counter"
  },
  "cheaper_alternatives": [
    {
      "medicine": {...},
      "price_savings": "₹10.30",
      "savings_percentage": "34.0%",
      "similarity_score": "1.00"
    }
  ]
}

2. search_medicines

GET /search_medicines

所有医学领域的全文搜索。

参数:

  • query (字符串,必填):要搜索的子字符串(不区分大小写)
  • max_results (整数,可选,默认值=10):要返回的最大匹配记录数

答复:

[
  {
    "Name": "Dolo 650",
    "Manufacturer": "Micro Labs Ltd",
    "Composition": "Paracetamol (650mg)",
    "MRP": "30.29",
    "Price_INR": "₹30.29",
    ...
  },
  ...
]

3. fuzzy_search_by_name

GET /fuzzy_search_by_name

使用模糊匹配搜索名称与提供的部分名称相似的药物。

参数:

  • partial_name (string,必填):要搜索的部分或拼写错误的药品名称
  • similarity_threshold (数字,可选,默认值=0.6):结果中包含的最小相似性得分(0.0-1.0)
  • max_results (整数,可选,默认值=10):要返回的最大匹配记录数

答复:

[
  {
    "similarity_score": "0.92",
    "medicine": {
      "Name": "Dolo 650",
      ...
    }
  },
  ...
]

4. search_by_composition

GET /search_by_composition

搜索含有特定活性成分的药物。

参数:

  • ingredient (string,必填):要搜索的活性成分的名称
  • max_results (整数,可选,默认值=10):要返回的最大匹配记录数

答复:

[
  {
    "Name": "Dolo 650",
    "Composition": "Paracetamol (650mg)",
    ...
  },
  ...
]

筛选器端点

5. filter_by_price_range

GET /filter_by_price_range

按价格范围过滤药品。

参数:

  • min_price (数字,可选,默认=0):最低价格(印度卢比)
  • max_price (数字,可选,默认值=空):最高价格(印度卢比)
  • max_results (整数,可选,默认值=20):要返回的最大匹配记录数

答复:

[
  {
    "Name": "Crocin Pain Relief",
    "MRP": "49.43",
    "Price_INR": "₹49.43",
    ...
  },
  ...
]

6. filter_by_manufacturer

GET /filter_by_manufacturer

按制造商过滤药物。

参数:

  • manufacturer (string,必填):完整或部分制造商名称
  • max_results (整数,可选,默认值=20):要返回的最大匹配记录数

答复:

[
  {
    "Name": "Dolo 650",
    "Manufacturer": "Micro Labs Ltd",
    ...
  },
  ...
]

7. filter_by_prescription_requirement

GET /filter_by_prescription_requirement

根据处方要求过滤药物。

参数:

  • prescription_required (布尔值,必填):处方药为True,非处方药为False
  • max_results (整数,可选,默认值=20):要返回的最大匹配记录数

答复:

[
  {
    "Name": "Dolo 650",
    "Prescription": "No",
    "Requires_Prescription": false,
    "Prescription_Type": "Over-the-Counter",
    ...
  },
  ...
]

8. paginated_search

GET /paginated_search

具有分页和多个过滤器的高级搜索。

参数:

  • query (字符串,可选,默认值=“”):通用搜索词(在所有字段中搜索)
  • page (整数,可选,默认=1):页码(从1开始)
  • page_size (整数,可选,默认值=10):每页的结果数
  • manufacturer (string,可选,默认=“”):按制造商筛选(全部或部分)
  • min_price (数字,可选,默认=0):最低价格过滤器
  • max_price (数字,可选,默认值=空):最大价格过滤器
  • prescription_required (布尔值或null,可选,默认值=null):按处方要求过滤(任何为null)
  • ingredient (string,可选,默认=“”):按活性成分过滤

答复:

{
  "meta": {
    "total_results": 150,
    "page": 1,
    "page_size": 10,
    "total_pages": 15
  },
  "results": [
    {
      "Name": "Dolo 650",
      ...
    },
    ...
  ]
}

分析终点

9. find_similar_medicines

GET /find_similar_medicines

寻找与指定药物成分相似的药物。

参数:

  • medicine_name (string,必填):参考药物的名称
  • max_results (整数,可选,默认=5):要返回的类似药物的最大数量

答复:

{
  "reference_medicine": {
    "Name": "Dolo 650",
    ...
  },
  "similar_medicines": [
    {
      "similarity_score": "1.00",
      "medicine": {
        "Name": "Crocin Pain Relief",
        ...
      }
    },
    ...
  ]
}

10. analyze_composition

GET /analyze_composition

分析药物成分串以提取和构造成分。

参数:

  • composition (字符串,必填):成分字符串(例如“Ambroxol (30mg/5ml) + Levosalbutamol (1mg/5ml)”)

答复:

{
  "raw_composition": "Ambroxol (30mg/5ml) + Levosalbutamol (1mg/5ml)",
  "ingredients": [
    {
      "raw_text": "Ambroxol (30mg/5ml)",
      "name": "Ambroxol",
      "dosage": "30mg/5ml",
      "dosage_value": "30",
      "dosage_unit": "mg"
    },
    {
      "raw_text": "Levosalbutamol (1mg/5ml)",
      "name": "Levosalbutamol",
      "dosage": "1mg/5ml",
      "dosage_value": "1",
      "dosage_unit": "mg"
    }
  ],
  "medicines_with_this_composition": [
    {
      "Name": "Ascoril LS Syrup",
      ...
    },
    ...
  ]
}

11. count_medicines_by_composition

GET /count_medicines_by_composition

清点并列出所有具有特定成分或含有特定成分的药物。

参数:

  • composition (string,必填):要搜索的成分或配料
  • exact_match (boolean,可选,默认值=false):如果为True,则只查找具有确切成分的药物。如果为假,请找到含有这种成分的药物。

答复:

{
  "query": "Paracetamol",
  "exact_match": false,
  "total_medicines_found": 500,
  "total_manufacturers": 25,
  "price_statistics": {
    "min_price": "₹10.50",
    "max_price": "₹150.75",
    "avg_price": "₹45.30",
    "total_medicines_with_price": 490
  },
  "medicines": [...],
  "by_manufacturer": {
    "Cipla": {
      "count": 50,
      "medicines": [...]
    },
    ...
  }
}

12. categorize_medicines

GET /categorize_medicines

按活性成分对药物进行分类,并返回最常见的类别。

参数:

  • max_categories (整数,可选,默认值=10):要返回的最大类别数

答复:

[
  {
    "category": "Paracetamol",
    "medicine_count": 500,
    "example_medicines": [...]
  },
  {
    "category": "Amoxicillin",
    "medicine_count": 300,
    "example_medicines": [...]
  },
  ...
]

公用设施端点

13. get_medicine_statistics

GET /get_medicine_statistics

获取药品数据库的统计概览。

参数: 无

答复:

{
  "total_medicines": 15000,
  "prescription_count": 7500,
  "otc_count": 7000,
  "unknown_prescription_status": 500,
  "manufacturer_counts": {
    "Sun Pharma": 1200,
    "Cipla": 900,
    ...
  },
  "price_distribution": {
    "min_price": "₹1.50",
    "max_price": "₹2500.00",
    "avg_price": "₹125.45",
    "price_ranges": {
      "₹0 - ₹99.99": 5000,
      "₹100 - ₹199.99": 4000,
      ...
    }
  },
  "common_ingredients": {
    "Paracetamol": 500,
    "Amoxicillin": 300,
    ...
  }
}

14. get_all_manufacturers

GET /get_all_manufacturers

获取数据库中所有制造商的列表。

参数: 无

答复:

[
  {
    "name": "Sun Pharma",
    "medicine_count": 1200
  },
  {
    "name": "Cipla",
    "medicine_count": 900
  },
  ...
]

15. suggest_alternatives

GET /suggest_alternatives

根据成分相似性和价格建议替代药物。

参数:

  • medicine_name (string,必填):参考药物的名称
  • max_suggestions (整数,可选,默认值=5):建议的最大备选方案数量

答复:

{
  "reference_medicine": {
    "Name": "Dolo 650",
    "MRP": "30.29",
    ...
  },
  "alternatives": [
    {
      "medicine": {
        "Name": "Calpol 650",
        "MRP": "26.50",
        ...
      },
      "ingredient_similarity": 1.0,
      "price_difference_percentage": -12.5,
      "price_comparison": "cheaper",
      "absolute_price_difference": 3.79
    },
    ...
  ]
}

📊 数据结构

系统需要一个具有以下结构的JSON医学对象数组:

[
  {
    "Name": "Medicine Name",
    "Manufacturer": "Company Name",
    "Composition": "Ingredient1 (10mg) + Ingredient2 (20mg)",
    "MRP": "123.45",
    "Prescription": "Yes"
  },
  ...
]

该系统通过额外的计算字段增强了这些数据:

  • Price_INR:带货币符号的格式化价格
  • Price_Category:分为低/中/高/高级
  • Active_Ingredients:提取的成分清单
  • Ingredient_Count:活性成分数量
  • Is_Combination:药物是否含有多种成分
  • Requires_Prescription:布尔值表示处方要求
  • Prescription_Type:人类可读的处方状态

⚡ 性能优化

服务器实现了几个优化:

  1. 多个指数 为了快速查找:

    • 名称索引
    • 制造商索引
    • 成分指数
    • 价格指数
    • 处方指数
  2. 成分提取 在启动时执行一次,以避免重复解析

  3. 相似性计算 使用高效的算法:

    • 用于字符串相似性的SequenceMatcher
    • 成分相似性的Jaccard指数
  4. 价格暴涨 用于更快的范围查询

🤝 贡献

欢迎投稿!以下是您可以提供帮助的方式:

  1. 分叉存储库
  2. 创建要素分支(git checkout -b feature/amazing-feature)
  3. 提交您的更改(git commit -m 'Add some amazing feature')
  4. 推到分支(git push origin feature/amazing-feature)
  5. 打开拉取请求

请确保根据需要更新测试。

📄 许可证

此项目根据MIT许可证获得许可-有关详细信息,请参阅许可证文件。


Developed by Siddharth Bajpai

For questions or support, please contact

For medicines data, contact me on LinkedIn