Skip to main content
Glama
CodeInput.tsx1.55 kB
// SPDX-FileCopyrightText: Copyright Orangebot, Inc. and Medplum contributors // SPDX-License-Identifier: Apache-2.0 import type { ValueSetExpansionContains } from '@medplum/fhirtypes'; import type { JSX } from 'react'; import { useState } from 'react'; import type { ValueSetAutocompleteProps } from '../ValueSetAutocomplete/ValueSetAutocomplete'; import { ValueSetAutocomplete } from '../ValueSetAutocomplete/ValueSetAutocomplete'; export interface CodeInputProps extends Omit<ValueSetAutocompleteProps, 'defaultValue' | 'onChange'> { readonly defaultValue?: string; readonly onChange: ((value: string | undefined) => void) | undefined; } export function CodeInput(props: CodeInputProps): JSX.Element { const { defaultValue, onChange, withHelpText, ...rest } = props; const [value, setValue] = useState<string | undefined>(defaultValue); function handleChange(newValues: ValueSetExpansionContains[]): void { const newValue = newValues[0]; const newCode = valueSetElementToCode(newValue); setValue(newCode); if (onChange) { onChange(newCode); } } return ( <ValueSetAutocomplete defaultValue={codeToValueSetElement(value)} onChange={handleChange} withHelpText={withHelpText ?? true} {...rest} /> ); } function codeToValueSetElement(code: string | undefined): ValueSetExpansionContains | undefined { return code ? { code } : undefined; } function valueSetElementToCode(element: ValueSetExpansionContains | undefined): string | undefined { return element?.code; }

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