mcpField
C
clinicaltrials-database

clinicaltrials-database

github.com/jackspaceデータ・データベース1635 回インストール12 週間前に更新
リポジトリ

clinicaltrials-database について

ClinicalTrials.govの検索と研究記録の取得に使うPythonヘルパーとガイドを提供するスキルです。条件検索、研究詳細の取得、ページネーション、CSV出力に対応し、研究分析や試験の追跡に役立ちます。

主な機能

  1. 01疾患、介入、場所、スポンサーで検索
  2. 02研究状況による絞り込み
  3. 03研究記録の詳細取得
  4. 04該当研究のページネーション
  5. 05結果のCSV出力

活用シーン

  1. 01疾患に対する募集中の試験を探す
  2. 02特定の薬剤を試す研究を特定
  3. 03適格基準と連絡先を確認
  4. 04分析用に試験データを出力

インストール

コマンドをコピーしてターミナルで実行します。

$npx skills add https://github.com/jackspace/claudeskillz --skill clinicaltrials-database

インストール後、Claude Code で/clinicaltrials-databaseを入力して読み込まれたか確認します。

同梱ファイルSKILL.json

詳細

ClinicalTrials.gov データベース

概要

ClinicalTrials.gov は、世界中で実施されている臨床試験を網羅したレジストリであり、米国国立医学図書館が管理しています。API v2 にアクセスして、試験の検索、詳細な試験情報の取得、さまざまな条件によるフィルタリング、分析用データのエクスポートを行えます。この API は公開されており(認証は不要)、約 50 リクエスト/分のレート制限があり、JSON と CSV の形式をサポートしています。

このスキルを使用するタイミング

このスキルは、次のようなシナリオで臨床試験データを扱う際に使用します。

  • 患者マッチング - 特定の疾患や患者集団について、募集中の試験を見つける
  • 研究分析 - 臨床試験の傾向、アウトカム、または研究デザインを分析する
  • 薬剤・介入研究 - 特定の薬剤や介入を検証している試験を特定する
  • 地理的検索 - 特定の場所や地域で行われている試験を見つける
  • スポンサー・組織の追跡 - 特定の機関が実施している試験を見つける
  • データのエクスポート - さらなる分析や報告のために臨床試験データを抽出する
  • 試験のモニタリング - 特定の試験のステータス更新や結果を追跡する
  • 適格性スクリーニング - 試験の選択基準・除外基準を確認する

クイックスタート

基本的な検索クエリ

ヘルパースクリプトを使用して臨床試験を検索します。

cd scientific-databases/clinicaltrials-database/scripts
python3 query_clinicaltrials.py

または、requests ライブラリを使用して Python から直接実行することもできます。

import requests

url = "https://clinicaltrials.gov/api/v2/studies"
params = {
    "query.cond": "breast cancer",
    "filter.overallStatus": "RECRUITING",
    "pageSize": 10
}

response = requests.get(url, params=params)
data = response.json()

print(f"Found {data['totalCount']} trials")
特定の試験の取得

NCT ID を使用して、特定の試験の詳細情報を取得します。

import requests

nct_id = "NCT04852770"
url = f"https://clinicaltrials.gov/api/v2/studies/{nct_id}"

response = requests.get(url)
study = response.json()

# Access specific modules
title = study['protocolSection']['identificationModule']['briefTitle']
status = study['protocolSection']['statusModule']['overallStatus']

主な機能

1. 疾患・病態による検索

query.cond パラメーターを使用して、特定の医学的状態や疾患を対象とする試験を見つけます。

例: 募集中の糖尿病の試験を検索する

from scripts.query_clinicaltrials import search_studies

results = search_studies(
    condition="type 2 diabetes",
    status="RECRUITING",
    page_size=20,
    sort="LastUpdatePostDate:desc"
)

print(f"Found {results['totalCount']} recruiting diabetes trials")
for study in results['studies']:
    protocol = study['protocolSection']
    nct_id = protocol['identificationModule']['nctId']
    title = protocol['identificationModule']['briefTitle']
    print(f"{nct_id}: {title}")

一般的な使用例:

  • 希少疾患の試験を見つける
  • 併存疾患の試験を特定する
  • 特定の診断に対する試験の利用可能性を追跡する
2. 介入・薬剤による検索

query.intr パラメーターを使用して、特定の介入、薬剤、医療機器、または処置を検証している試験を検索します。

例: ペムブロリズマブを検証する第 3 相試験を検索する

from scripts.query_clinicaltrials import search_studies

results = search_studies(
    intervention="Pembrolizumab",
    status=["RECRUITING", "ACTIVE_NOT_RECRUITING"],
    page_size=50
)

# Filter by phase in results
phase3_trials = [
    study for study in results['studies']
    if 'PHASE3' in study['protocolSection'].get('designModule', {}).get('phases', [])
]

一般的な使用例:

  • 薬剤開発の追跡
  • 製薬企業向けの競合情報の収集
  • 臨床医向けの治療選択肢の調査
3. 地理的検索

query.locn パラメーターを使用して、特定の場所で実施されている試験を見つけます。

例: ニューヨークで行われているがんの試験を検索する

from scripts.query_clinicaltrials import search_studies

results = search_studies(
    condition="cancer",
    location="New York",
    status="RECRUITING",
    page_size=100
)

# Extract location details
for study in results['studies']:
    locations_module = study['protocolSection'].get('contactsLocationsModule', {})
    locations = locations_module.get('locations', [])
    for loc in locations:
        if 'New York' in loc.get('city', ''):
            print(f"{loc['facility']}: {loc['city']}, {loc.get('state', '')}")

一般的な使用例:

  • 患者を近隣の試験に紹介する
  • 試験の地理的分布を分析する
  • 新規試験の施設選定
4. スポンサー・組織による検索

query.spons パラメーターを使用して、特定の組織が実施している試験を見つけます。

例: NCI がスポンサーの試験を検索する

from scripts.query_clinicaltrials import search_studies

results = search_studies(
    sponsor="National Cancer Institute",
    page_size=100
)

# Extract sponsor information
for study in results['studies']:
    sponsor_module = study['protocolSection']['sponsorCollaboratorsModule']
    lead_sponsor = sponsor_module['leadSponsor']['name']
    collaborators = sponsor_module.get('collaborators', [])
    print(f"Lead: {lead_sponsor}")
    if collaborators:
        print(f"  Collaborators: {', '.join([c['name'] for c in collaborators])}")

一般的な使用例:

  • 機関の研究ポートフォリオの追跡
  • 資金提供機関の優先事項の分析
  • 共同研究の機会の特定
5. 試験ステータスによるフィルタリング

filter.overallStatus パラメーターを使用して、募集状況または完了状況で試験を絞り込みます。

有効なステータス値:

  • RECRUITING - 現在参加者を募集中
  • NOT_YET_RECRUITING - 募集開始前
  • ENROLLING_BY_INVITATION - 招待による登録のみ受付中
  • ACTIVE_NOT_RECRUITING - 実施中だが募集は終了
  • SUSPENDED - 一時的に停止中
  • TERMINATED - 早期に中止
  • COMPLETED - 試験が終了
  • WITHDRAWN - 登録前に取り下げ

例: 結果が公開されている最近完了した試験を検索する

from scripts.query_clinicaltrials import search_studies

results = search_studies(
    condition="alzheimer disease",
    status="COMPLETED",
    sort="LastUpdatePostDate:desc",
    page_size=50
)

# Filter for trials with results
trials_with_results = [
    study for study in results['studies']
    if study.get('hasResults', False)
]

print(f"Found {len(trials_with_results)} completed trials with results")
6. 詳細な試験情報の取得

適格基準、アウトカム、連絡先、実施場所を含む、特定の試験の包括的な情報を取得します。

例: 適格基準を抽出する

from scripts.query_clinicaltrials import get_study_details

study = get_study_details("NCT04852770")
eligibility = study['protocolSection']['eligibilityModule']

print(f"Eligible Ages: {eligibility.get('minimumAge')} - {eligibility.get('maximumAge')}")
print(f"Eligible Sex: {eligibility.get('sex')}")
print(f"\nInclusion Criteria:")
print(eligibility.get('eligibilityCriteria'))

例: 連絡先情報を抽出する

from scripts.query_clinicaltrials import get_study_details

study = get_study_details("NCT04852770")
contacts_module = study['protocolSection']['contactsLocationsModule']

# Overall contacts
if 'centralContacts' in contacts_module:
    for contact in contacts_module['centralContacts']:
        print(f"Contact: {contact.get('name')}")
        print(f"Phone: {contact.get('phone')}")
        print(f"Email: {contact.get('email')}")

# Study locations
if 'locations' in contacts_module:
    for location in contacts_module['locations']:
        print(f"\nFacility: {location.get('facility')}")
        print(f"City: {location.get('city')}, {location.get('state')}")
        if location.get('status'):
            print(f"Status: {location['status']}")
7. ページネーションと一括データ取得

ページネーションを使用して、大規模な結果セットを効率的に処理します。

例: 一致するすべての試験を取得する

from scripts.query_clinicaltrials import search_with_all_results

# Get all trials (automatically handles pagination)
all_trials = search_with_all_results(
    condition="rare disease",
    status="RECRUITING"
)

print(f"Retrieved {len(all_trials)} total trials")

例: 制御を伴う手動ページネーション

from scripts.query_clinicaltrials import search_studies

all_studies = []
page_token = None
max_pages = 10  # Limit to avoid excessive requests

for page in range(max_pages):
    results = search_studies(
        condition="cancer",
        page_size=1000,  # Max page size
        page_token=page_token
    )

    all_studies.extend(results['studies'])

    # Check for next page
    page_token = results.get('pageToken')
    if not page_token:
        break

print(f"Retrieved {len(all_studies)} studies across {page + 1} pages")
8. CSVへのデータエクスポート

試験データをCSV形式でエクスポートし、表計算ソフトやデータ分析ツールで分析できます。

例:CSVファイルへのエクスポート

from scripts.query_clinicaltrials import search_studies

# Request CSV format
results = search_studies(
    condition="heart disease",
    status="RECRUITING",
    format="csv",
    page_size=1000
)

# Save to file
with open("heart_disease_trials.csv", "w") as f:
    f.write(results)

print("Data exported to heart_disease_trials.csv")

注: CSV形式では、JSON辞書ではなく文字列が返されます。

9. 研究情報の抽出と要約

概要の把握や報告のために主要な情報を抽出します。

例:試験サマリーの作成

from scripts.query_clinicaltrials import get_study_details, extract_study_summary

# Get details and extract summary
study = get_study_details("NCT04852770")
summary = extract_study_summary(study)

print(f"NCT ID: {summary['nct_id']}")
print(f"Title: {summary['title']}")
print(f"Status: {summary['status']}")
print(f"Phase: {', '.join(summary['phase'])}")
print(f"Enrollment: {summary['enrollment']}")
print(f"Last Update: {summary['last_update']}")
print(f"\nBrief Summary:\n{summary['brief_summary']}")
10. 複合クエリ戦略

複数のフィルターを組み合わせて、対象を絞った検索を行います。

例:複数条件による検索

from scripts.query_clinicaltrials import search_studies

# Find Phase 2/3 immunotherapy trials for lung cancer in California
results = search_studies(
    condition="lung cancer",
    intervention="immunotherapy",
    location="California",
    status=["RECRUITING", "NOT_YET_RECRUITING"],
    page_size=100
)

# Further filter by phase
phase2_3_trials = [
    study for study in results['studies']
    if any(phase in ['PHASE2', 'PHASE3']
           for phase in study['protocolSection'].get('designModule', {}).get('phases', []))
]

print(f"Found {len(phase2_3_trials)} Phase 2/3 immunotherapy trials")

リソース

scripts/query_clinicaltrials.py

一般的なクエリパターン向けのヘルパー関数を提供する総合的なPythonスクリプトです。

  • search_studies() - さまざまなフィルターで試験を検索
  • get_study_details() - 特定の試験の完全な情報を取得
  • search_with_all_results() - すべての結果を自動的にページ送りして取得
  • extract_study_summary() - 概要把握のために主要な情報を抽出

使用例を確認するには、スクリプトを直接実行してください:

python3 scripts/query_clinicaltrials.py
references/api_reference.md

以下を含む詳細なAPIドキュメントです。

  • エンドポイントの完全な仕様
  • すべてのクエリパラメータと有効な値
  • レスポンスのデータ構造とモジュール
  • コード例を含む一般的なユースケース
  • エラー処理とベストプラクティス
  • データ標準(ISO 8601形式の日付、CommonMarkのMarkdown)

不慣れなAPI機能を扱う場合や、問題のトラブルシューティングを行う場合は、このリファレンスを参照してください。

ベストプラクティス

レート制限の管理

APIのレート制限は、おおよそ毎分50リクエストです。大量のデータを取得する場合は、次の点に従ってください。

  1. リクエスト数を最小限にするため、最大ページサイズ(1000)を使用する
  2. レート制限エラー(429ステータス)が発生したら、指数バックオフを実装する
  3. 大規模なデータ収集では、リクエストの間に遅延を入れる
import time
import requests

def search_with_rate_limit(params):
    try:
        response = requests.get("https://clinicaltrials.gov/api/v2/studies", params=params)
        response.raise_for_status()
        return response.json()
    except requests.exceptions.HTTPError as e:
        if e.response.status_code == 429:
            print("Rate limited. Waiting 60 seconds...")
            time.sleep(60)
            return search_with_rate_limit(params)  # Retry
        raise
データ構造の探索

APIのレスポンスは入れ子構造になっています。一般的な情報へのキーとなるパスは次のとおりです。

  • NCT ID: study['protocolSection']['identificationModule']['nctId']
  • タイトル: study['protocolSection']['identificationModule']['briefTitle']
  • ステータス: study['protocolSection']['statusModule']['overallStatus']
  • フェーズ: study['protocolSection']['designModule']['phases']
  • 適格基準: study['protocolSection']['eligibilityModule']
  • 所在地: study['protocolSection']['contactsLocationsModule']['locations']
  • 介入: study['protocolSection']['armsInterventionsModule']['interventions']
エラー処理

ネットワークリクエストでは、必ず適切なエラー処理を実装してください。

import requests

try:
    response = requests.get(url, params=params, timeout=30)
    response.raise_for_status()
    data = response.json()
except requests.exceptions.HTTPError as e:
    print(f"HTTP error: {e.response.status_code}")
except requests.exceptions.RequestException as e:
    print(f"Request failed: {e}")
except ValueError as e:
    print(f"JSON decode error: {e}")
欠損データの処理

すべての試験が完全な情報を持っているわけではありません。必ずフィールドの存在を確認してください。

# Safe navigation with .get()
phases = study['protocolSection'].get('designModule', {}).get('phases', [])
enrollment = study['protocolSection'].get('designModule', {}).get('enrollmentInfo', {}).get('count', 'N/A')

# Check before accessing
if 'resultsSection' in study:
    # Process results
    pass

技術仕様

  • ベースURL: https://clinicaltrials.gov/api/v2
  • 認証: 不要(公開API)
  • レート制限: IPアドレスごとに約50リクエスト/分
  • レスポンス形式: JSON(デフォルト)、CSV
  • 最大ページサイズ: リクエストごとに1000件の試験
  • 日付形式: ISO 8601
  • テキスト形式: リッチテキストフィールドにはCommonMark Markdown
  • APIバージョン: 2.0(2024年3月リリース)
  • APIの仕様: OpenAPI 3.0

技術的な詳細は、references/api_reference.mdを参照してください。

コメント