Skip to main content
Glama

createMedicationRequest

Generate medication requests (prescriptions) by specifying patient ID, medication reference, prescriber, status, and intent using the Medplum MCP Server.

Instructions

Creates a new medication request (prescription). Requires patient ID, medication reference, and prescriber.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
intentYesThe intent of the medication request.
medicationReferenceYesReference to the medication being prescribed.
patientIdYesThe ID of the patient this prescription is for.
practitionerIdYesThe ID of the practitioner prescribing the medication.
statusYesThe status of the medication request.

Implementation Reference

  • The async handler function that validates input, constructs a FHIR MedicationRequest resource, and creates it via the Medplum client.
    export async function createMedicationRequest(args: CreateMedicationRequestArgs): Promise<MedicationRequest> { await ensureAuthenticated(); if (!args.status) { throw new Error('MedicationRequest status is required.'); } if (!args.intent) { throw new Error('MedicationRequest intent is required.'); } if (!args.medicationCodeableConcept) { // Add || !args.medicationReference if that's supported throw new Error('Medication (medicationCodeableConcept or medicationReference) is required.'); } if (!args.subjectId) { throw new Error('Subject (Patient ID) is required to create a MedicationRequest.'); } const medicationRequestResource: MedicationRequest = { resourceType: 'MedicationRequest', status: args.status, intent: args.intent, medicationCodeableConcept: args.medicationCodeableConcept, // medicationReference: args.medicationReference, subject: { reference: `Patient/${args.subjectId}` }, authoredOn: args.authoredOn || new Date().toISOString(), dosageInstruction: args.dosageInstruction, }; if (args.encounterId) { medicationRequestResource.encounter = { reference: `Encounter/${args.encounterId}` }; } if (args.requesterId) { medicationRequestResource.requester = { reference: `Practitioner/${args.requesterId}` }; } if (args.note) { medicationRequestResource.note = [{ text: args.note }]; } if (args.identifier) { medicationRequestResource.identifier = [{ system: args.identifier.system, value: args.identifier.value }]; } return medplum.createResource<MedicationRequest>(medicationRequestResource); }
  • TypeScript interface defining the input parameters expected by the createMedicationRequest handler.
    export interface CreateMedicationRequestArgs { status: MedicationRequest['status']; intent: MedicationRequest['intent']; medicationCodeableConcept?: CodeableConcept; // medicationReference?: Reference; // TODO: Add if direct reference to Medication resource is needed subjectId: string; // Convenience for Patient reference encounterId?: string; // Convenience for Encounter reference authoredOn?: string; requesterId?: string; // Convenience for Practitioner reference dosageInstruction?: Dosage[]; note?: string; identifier?: { system?: string; value: string }; // Add other relevant fields like dispenseRequest, category, priority, etc. as needed }
  • MCP tool schema defining the input validation for createMedicationRequest tool calls.
    { name: "createMedicationRequest", description: "Creates a new medication request (prescription). Requires patient ID, medication reference, and prescriber.", inputSchema: { type: "object", properties: { patientId: { type: "string", description: "The ID of the patient this prescription is for.", }, medicationReference: { type: "string", description: "Reference to the medication being prescribed.", }, practitionerId: { type: "string", description: "The ID of the practitioner prescribing the medication.", }, status: { type: "string", description: "The status of the medication request.", enum: ["active", "on-hold", "cancelled", "completed", "entered-in-error", "stopped", "draft", "unknown"], }, intent: { type: "string", description: "The intent of the medication request.", enum: ["proposal", "plan", "order", "original-order", "reflex-order", "filler-order", "instance-order", "option"], }, }, required: ["patientId", "medicationReference", "practitionerId", "status", "intent"], },
  • src/index.ts:44-49 (registration)
    Import statement registering the createMedicationRequest function from medicationRequestUtils.
    import { createMedicationRequest, getMedicationRequestById, updateMedicationRequest, searchMedicationRequests, } from './tools/medicationRequestUtils.js';
  • src/index.ts:972-972 (registration)
    Entry in toolMapping object that maps the tool name to its handler function for execution.
    createMedicationRequest,

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/rkirkendall/medplum-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server