updateCondition
Modify existing medical condition details in Medplum MCP Server by updating fields like clinical status, verification status, or onset description using the condition ID.
Instructions
Updates an existing condition. Requires the condition ID and at least one field to update.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| clinicalStatus | No | The new clinical status of the condition. | |
| conditionId | Yes | The unique ID of the condition to update. | |
| onsetString | No | Update the onset description. To remove this field, provide a `null` value. | |
| verificationStatus | No | The new verification status of the condition. |
Implementation Reference
- src/tools/conditionUtils.ts:241-287 (handler)The core handler function that executes the updateCondition tool logic: reads existing Condition by ID, merges updates, handles null removals, and updates via Medplum client.export async function updateCondition( args: UpdateConditionArgs, client?: MedplumClient, ): Promise<Condition | OperationOutcome> { const medplumClient = client || medplum; await ensureAuthenticated(); try { const { id, ...updates } = args; if (!id) { throw new Error('Condition ID is required for update.'); } if (Object.keys(updates).length === 0) { throw new Error('No updates provided for Condition.'); } const existingCondition = (await medplumClient.readResource( 'Condition', id, )) as Condition; const updatedResource: Condition = { ...existingCondition, ...(updates as any) }; // Handle null values for removal if (updates.onsetDateTime === null) delete updatedResource.onsetDateTime; if (updates.onsetString === null) delete updatedResource.onsetString; if (updates.recordedDate === null) delete updatedResource.recordedDate; const result = (await medplumClient.updateResource(updatedResource)) as Condition; console.log('Condition updated successfully:', result.id); return result; } catch (error: any) { console.error('Error updating Condition:', error); const outcome: OperationOutcome = { resourceType: 'OperationOutcome', issue: [ { severity: 'error', code: 'exception', diagnostics: `Error updating Condition: ${error.message || 'Unknown error'}`, }, ], }; if (error.outcome) { console.error('Server OperationOutcome:', JSON.stringify(error.outcome, null, 2)); return error.outcome as OperationOutcome; } return outcome; }
- src/index.ts:866-891 (schema)MCP tool schema definition including input schema with properties for conditionId, clinicalStatus, verificationStatus, onsetString.name: "updateCondition", description: "Updates an existing condition. Requires the condition ID and at least one field to update.", inputSchema: { type: "object", properties: { conditionId: { type: "string", description: "The unique ID of the condition to update.", }, clinicalStatus: { type: "string", description: "The new clinical status of the condition.", enum: ["active", "recurrence", "relapse", "inactive", "remission", "resolved"], }, verificationStatus: { type: "string", description: "The new verification status of the condition.", enum: ["unconfirmed", "provisional", "differential", "confirmed", "refuted", "entered-in-error"], }, onsetString: { type: "string", description: "Update the onset description. To remove this field, provide a `null` value.", }, }, required: ["conditionId"], },
- src/index.ts:985-985 (registration)Registration of the updateCondition handler function in the toolMapping object used by the MCP server to dispatch tool calls.updateCondition,
- src/index.ts:1027-1043 (registration)Special dispatch logic in MCP server handler for updateCondition, converting schema inputs to UpdateConditionArgs format.// Special handling for updateCondition if (toolName === 'updateCondition') { const updateArgs: any = { id }; if ((updates as any).clinicalStatus) { const key = ((updates as any).clinicalStatus as string).toUpperCase() as keyof typeof ConditionClinicalStatusCodes; updateArgs.clinicalStatus = { coding: [ConditionClinicalStatusCodes[key]] }; } if ((updates as any).verificationStatus) { const verStatusMap: { [key: string]: string } = { 'entered-in-error': 'ENTERED-IN-ERROR' }; const key = (verStatusMap[(updates as any).verificationStatus] || ((updates as any).verificationStatus as string).toUpperCase()) as keyof typeof ConditionVerificationStatusCodes; updateArgs.verificationStatus = { coding: [ConditionVerificationStatusCodes[key]] }; } if ((updates as any).onsetString !== undefined) { updateArgs.onsetString = (updates as any).onsetString; } result = await toolFunction(updateArgs); } else {
- src/tools/conditionUtils.ts:103-111 (helper)TypeScript interface defining the arguments expected by the updateCondition handler function.export interface UpdateConditionArgs { id: string; clinicalStatus?: CodeableConcept; verificationStatus?: CodeableConcept; code?: CodeableConcept; onsetDateTime?: string | null; // null to remove onsetString?: string | null; recordedDate?: string | null; }