getObservationById
Retrieve specific observation data from a Medplum FHIR server using its unique ID for precise healthcare information access.
Instructions
Retrieves an observation by its unique ID.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| observationId | Yes | The unique ID of the observation to retrieve. |
Implementation Reference
- src/tools/observationUtils.ts:170-183 (handler)The main handler function that authenticates, validates the observationId, and retrieves the Observation resource using medplum.readResource, returning null if not found.export async function getObservationById(args: GetObservationByIdArgs): Promise<Observation | null> { await ensureAuthenticated(); if (!args.observationId) { throw new Error('Observation ID is required to fetch an observation.'); } try { return await medplum.readResource('Observation', args.observationId); } catch (error: any) { if (error.outcome?.issue?.[0]?.code === 'not-found') { return null; } throw error; } }
- src/tools/observationUtils.ts:38-40 (schema)TypeScript interface defining the input parameters for the getObservationById handler (observationId: string).export interface GetObservationByIdArgs { observationId: string; }
- src/index.ts:493-506 (schema)MCP tool schema defining the name, description, and inputSchema for validation in the ListTools and CallTool requests.{ name: "getObservationById", description: "Retrieves an observation by its unique ID.", inputSchema: { type: "object", properties: { observationId: { type: "string", description: "The unique ID of the observation to retrieve.", }, }, required: ["observationId"], }, },
- src/index.ts:38-43 (registration)Import statement bringing the getObservationById handler into the main index file for use in the MCP server.import { createObservation, getObservationById, updateObservation, searchObservations, } from './tools/observationUtils.js';
- src/index.ts:968-971 (registration)Entry in the toolMapping object that registers 'getObservationById' to its handler function for execution during CallTool requests.createObservation, getObservationById, updateObservation, searchObservations,