Skip to main content
Glama
ExtensionInput.tsx2.37 kB
// SPDX-FileCopyrightText: Copyright Orangebot, Inc. and Medplum contributors // SPDX-License-Identifier: Apache-2.0 import { isPopulated, isProfileLoaded } from '@medplum/core'; import type { ElementDefinitionType, Extension } from '@medplum/fhirtypes'; import { useMedplum } from '@medplum/react-hooks'; import type { JSX } from 'react'; import { useEffect, useMemo, useState } from 'react'; import { BackboneElementInput } from '../BackboneElementInput/BackboneElementInput'; import type { ComplexTypeInputProps } from '../ResourcePropertyInput/ResourcePropertyInput.utils'; export type ExtensionInputProps = ComplexTypeInputProps<Extension> & { readonly propertyType: ElementDefinitionType; }; export function ExtensionInput(props: ExtensionInputProps): JSX.Element | null { const { propertyType } = props; const medplum = useMedplum(); const profileUrl: string | undefined = useMemo(() => { if (!isPopulated(propertyType.profile)) { return undefined; } return propertyType.profile[0] satisfies string; }, [propertyType]); const [loadingProfile, setLoadingProfile] = useState(profileUrl !== undefined); useEffect(() => { if (profileUrl) { setLoadingProfile(true); medplum .requestProfileSchema(profileUrl) .then(() => setLoadingProfile(false)) .catch((reason) => { setLoadingProfile(false); console.warn(reason); }); } }, [medplum, profileUrl]); if (profileUrl && (loadingProfile || !isProfileLoaded(profileUrl))) { return <div>Loading...</div>; } /* From the spec: An extension SHALL have either a value (i.e. a value[x] element) or sub-extensions, but not both. If present, the value[x] element SHALL have content (value attribute or other elements) */ // const valueElement = typeSchema.elements['value[x]']; // const extensionHasValue = valueElement.max !== 0; // console.debug(typeSchema.name, { extensionHasValue }); // It seems like the behavior of ExtensionInput should differ based on extensionHasValue. It likely // isn't strictly necessary to do so given the recursive use of BackboneElementInput return ( <BackboneElementInput profileUrl={profileUrl} path={props.path} typeName="Extension" defaultValue={props.defaultValue} onChange={props.onChange} /> ); }

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