import { Controller, useFormContext } from 'react-hook-form'; import { IValueSet, useValueSetServiceContext } from '../../services'; import { InputControl } from '../ui/input-control'; import { Divider } from '../ui/divider'; import { DismissibleAlert } from '../ui/dismissible-alert'; import { Heading } from '../ui/heading'; import { Flex, FlexBlock } from '../ui/flex'; import { Spacer } from '../ui/spacer'; import UcumUnitSearch from '../UcumUnitSearch/UcumUnitSearch.tsx'; import { getNestedError } from '../../utils/formUtils.ts'; import { FhirCode, FhirCodeableConcept } from '../index.ts'; interface FhirQuantityProps { label: string; context: string; units?: IValueSet[] | undefined; isSimpleQuantity?: boolean; isUnitMutable? :boolean; disabled?: boolean; required?: boolean } const FhirQuantity = ({ label, context, units, isSimpleQuantity = false, isUnitMutable = true, disabled, required = false }: FhirQuantityProps) => { const { quantityComparators } = useValueSetServiceContext(); const { control, formState: { errors } } = useFormContext(); // An empty list is truthy, so it would render an empty select and block the unit search below. const hasUnits = Array.isArray(units) && units.length > 0; return ( <> {label} {/* value */} ( )}/> {getNestedError(errors, `${context}.value`) && ( Value is required )} {hasUnits && ( <> {/* unit */} )} {!hasUnits && isUnitMutable && ( )} {!hasUnits && !isUnitMutable && ( ( )}/> )} {!isSimpleQuantity && ( {/* comparator */} )} ); }; export default FhirQuantity;