Skip to main content
Glama
SmartAppLaunchLink.tsx1.65 kB
// SPDX-FileCopyrightText: Copyright Orangebot, Inc. and Medplum contributors // SPDX-License-Identifier: Apache-2.0 import type { AnchorProps } from '@mantine/core'; import { Anchor } from '@mantine/core'; import { showNotification } from '@mantine/notifications'; import { ensureTrailingSlash, locationUtils, normalizeErrorString } from '@medplum/core'; import type { ClientApplication, Encounter, Patient, Reference, SmartAppLaunch } from '@medplum/fhirtypes'; import { useMedplum } from '@medplum/react-hooks'; import type { JSX, ReactNode } from 'react'; export interface SmartAppLaunchLinkProps extends AnchorProps { readonly client: ClientApplication; readonly patient?: Reference<Patient>; readonly encounter?: Reference<Encounter>; readonly children?: ReactNode; } export function SmartAppLaunchLink(props: SmartAppLaunchLinkProps): JSX.Element | null { const medplum = useMedplum(); const { client, patient, encounter, children, ...rest } = props; function launchApp(): void { medplum .createResource<SmartAppLaunch>({ resourceType: 'SmartAppLaunch', patient, encounter, }) .then((result) => { const url = new URL(client.launchUri as string); url.searchParams.set('iss', ensureTrailingSlash(medplum.fhirUrl().toString())); url.searchParams.set('launch', result.id as string); locationUtils.assign(url.toString()); }) .catch((err) => showNotification({ color: 'red', message: normalizeErrorString(err), autoClose: false })); } return ( <Anchor onClick={() => launchApp()} {...rest}> {children} </Anchor> ); }

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