Skip to main content
Glama
patient-intake.ts1.81 kB
// SPDX-FileCopyrightText: Copyright Orangebot, Inc. and Medplum contributors // SPDX-License-Identifier: Apache-2.0 import { createReference, getQuestionnaireAnswers } from '@medplum/core'; import type { BotEvent, MedplumClient } from '@medplum/core'; import type { Communication, Patient, QuestionnaireResponse, ServiceRequest } from '@medplum/fhirtypes'; export async function handler(medplum: MedplumClient, event: BotEvent): Promise<any> { // Get all of the answers from the questionnaire response const answers = getQuestionnaireAnswers(event.input as QuestionnaireResponse); // Some quick data validation const firstName = answers['firstName']?.valueString; if (!firstName) { console.log('Missing first name'); return false; } const lastName = answers['lastName']?.valueString; if (!lastName) { console.log('Missing last name'); return false; } // Create a patient (FHIR Patient) const patient = await medplum.createResource<Patient>({ resourceType: 'Patient', name: [ { given: [firstName], family: lastName, }, ], }); // Create an order (FHIR ServiceRequest) const order = await medplum.createResource<ServiceRequest>({ resourceType: 'ServiceRequest', status: 'active', intent: 'order', subject: createReference(patient), code: { text: 'Order for a test', }, }); // Create a comment (FHIR Communication) if (answers['comment']?.valueString) { await medplum.createResource<Communication>({ resourceType: 'Communication', status: 'completed', basedOn: [createReference(order)], subject: createReference(patient), payload: [ { contentString: answers['comment']?.valueString, }, ], }); } return true; }

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/medplum/medplum'

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