get_trial_statistics
Analyze clinical trial data by grouping aggregate statistics across phases, statuses, study types, conditions, or sponsors to identify research trends and patterns.
Instructions
Get aggregate statistics about clinical trials
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| groupBy | No | Field to group statistics by | |
| filters | No | Optional filters to apply |
Implementation Reference
- src/index.ts:1095-1154 (handler)Handler implementation for the get_trial_statistics tool.
private async handleGetTrialStatistics(args: any) { // For statistics, we'll make a broader search and analyze the results const params: any = { format: "json", pageSize: 100, // Get more results for better statistics }; // Apply filters if provided if (args?.filters?.condition) { params["query.cond"] = args.filters.condition; } if (args?.filters?.phase) { params["filter.phase"] = args.filters.phase; } if (args?.filters?.status) { params["filter.overallStatus"] = args.filters.status; } try { const response: AxiosResponse<StudySearchResponse> = await this.axiosInstance.get("/studies", { params }); const studies = response.data.studies || []; const stats = this.calculateStatistics(studies, args?.groupBy); return { content: [ { type: "text", text: JSON.stringify( { totalStudies: response.data.totalCount || 0, analyzedStudies: studies.length, groupBy: args?.groupBy || "none", filters: args?.filters || {}, statistics: stats, }, null, 2 ), }, ], }; } catch (error) { if (axios.isAxiosError(error)) { return { content: [ { type: "text", text: `Clinical Trials API error: ${ error.response?.data?.message || error.message }`, }, ], isError: true, }; } throw error; } } - src/index.ts:277-298 (registration)Tool definition and schema registration for get_trial_statistics.
name: "get_trial_statistics", description: "Get aggregate statistics about clinical trials", inputSchema: { type: "object", properties: { groupBy: { type: "string", description: "Field to group statistics by", enum: ["phase", "status", "studyType", "condition", "sponsor"], }, filters: { type: "object", description: "Optional filters to apply", properties: { condition: { type: "string" }, phase: { type: "string" }, status: { type: "string" }, }, }, }, }, }, - src/index.ts:1199-1248 (helper)Helper functions to calculate statistics from study data.
private calculateStatistics(studies: Study[], groupBy?: string) { if (!groupBy) { return { totalStudies: studies.length, byStatus: this.groupByField(studies, "status"), byPhase: this.groupByField(studies, "phase"), byStudyType: this.groupByField(studies, "studyType"), }; } return this.groupByField(studies, groupBy); } private groupByField(studies: Study[], field: string) { const groups: { [key: string]: number } = {}; studies.forEach((study) => { let value: string | string[]; switch (field) { case "status": value = study.protocolSection.statusModule.overallStatus; break; case "phase": value = study.protocolSection.designModule?.phases?.[0] || "Not specified"; break; case "studyType": value = study.protocolSection.designModule?.studyType || "Unknown"; break; case "condition": value = study.protocolSection.conditionsModule?.conditions?.[0] || "Not specified"; break; case "sponsor": value = study.protocolSection.sponsorCollaboratorsModule?.leadSponsor ?.name || "Not specified"; break; default: value = "Unknown"; } const key = Array.isArray(value) ? value[0] : value; groups[key] = (groups[key] || 0) + 1; }); return groups; }