loinc_answers
Retrieve the list of valid answers and response codes for any LOINC questionnaire item. Use for data entry validation and standardized answer lookup.
Instructions
Get the list of valid answers for a LOINC questionnaire item.
Use this tool to:
Find valid response options for survey questions
Get answer codes for data entry validation
Look up standardized answer lists
Only applicable to LOINC codes that represent questions with defined answer sets.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| loinc_num | Yes | LOINC number (e.g., "2339-0") |
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
| loinc_num | Yes | ||
| answers | Yes |
Implementation Reference
- src/tools/loinc.ts:298-320 (handler)Handler function for the loinc_answers tool. Parses LOINC number from args, calls NLM client to get answers, then returns formatted text and structured output.
async function handleLOINCAnswers(args: Record<string, unknown>): Promise<CallToolResult> { try { const params = LOINCByCodeParamsSchema.parse(args); const client = getNLMClient(); const answers = await client.getLOINCAnswers(params.loinc_num); const structured: LOINCAnswersOutput = { loinc_num: params.loinc_num, answers: answers.map((a) => ({ sequence: a.sequence, answer_code: a.answerCode, answer_string: a.answerString, })), }; return { content: [{ type: 'text', text: formatLOINCAnswers(params.loinc_num, answers) }], structuredContent: structured, }; } catch (error) { return handleToolError(error); } } - src/types/index.ts:207-216 (schema)Zod output schema defining the shape of structured output for loinc_answers tool (loinc_num + array of answer objects).
export const LOINCAnswersOutputSchema = z.object({ loinc_num: z.string(), answers: z.array( z.object({ sequence: z.number().int(), answer_code: z.string(), answer_string: z.string(), }), ), }); - src/types/index.ts:238-238 (schema)TypeScript type inferred from LOINCAnswersOutputSchema.
export type LOINCAnswersOutput = z.infer<typeof LOINCAnswersOutputSchema>; - src/tools/loinc.ts:359-360 (registration)Registration of the loinc_answers tool with the tool registry, linking the tool definition to its handler.
toolRegistry.register(loincAnswersTool, handleLOINCAnswers); toolRegistry.register(loincPanelsTool, handleLOINCPanels); - src/tools/loinc.ts:171-196 (helper)Helper function that formats LOINC answers into a human-readable markdown table.
function formatLOINCAnswers(loincNum: string, answers: LOINCAnswer[]): string { const lines: string[] = []; lines.push(`# Answers for ${loincNum}`); lines.push(''); if (answers.length === 0) { lines.push('No predefined answers available for this LOINC code.'); lines.push(''); lines.push('This may mean:'); lines.push('- The code represents a numeric measurement (not a questionnaire)'); lines.push('- The code has free-text responses'); lines.push('- Answer list is not defined in LOINC'); } else { lines.push(`Found ${answers.length} answer(s):`); lines.push(''); lines.push('| # | Code | Answer |'); lines.push('|---|------|--------|'); for (const answer of answers) { lines.push(`| ${answer.sequence} | ${answer.answerCode} | ${answer.answerString} |`); } } return lines.join('\n'); }