Skip to content

Commit

Permalink
make unit/range format consistent with lab result
Browse files Browse the repository at this point in the history
  • Loading branch information
D-matz committed Jan 10, 2025
1 parent a8f625a commit 9248fd2
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 16 deletions.
28 changes: 13 additions & 15 deletions src/components/inputs/number/number.component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,28 +11,26 @@ import { useFormProviderContext } from '../../../provider/form-provider';
import FieldLabel from '../../field-label/field-label.component';
import { isEmpty } from '../../../validators/form-validator';


const extractFieldUnitsAndRange = (concept) => {
if (!concept) {
return '';
}

let unitsDisplay = '';
if (concept.units) {
unitsDisplay = ` (${concept.units})`;
}
const { hiAbsolute, lowAbsolute, units } = concept;
const displayUnit = units ? ` ${units}` : '';

let rangeDisplay = '';
if (concept.lowAbsolute != null && concept.hiAbsolute != null) {
rangeDisplay = ` (${concept.lowAbsolute}-${concept.hiAbsolute})`;
}
else if (concept.lowAbsolute != null) {
rangeDisplay = ` (Min ${concept.lowAbsolute})`;
}
else if (concept.hiAbsolute != null) {
rangeDisplay = ` (Max ${concept.hiAbsolute})`;
const hasLowerLimit = lowAbsolute != null;
const hasUpperLimit = hiAbsolute != null;

if (hasLowerLimit && hasUpperLimit) {
return ` (${lowAbsolute} - ${hiAbsolute} ${displayUnit})`;
} else if (hasUpperLimit) {
return ` (<= ${hiAbsolute} ${displayUnit})`;
} else if (hasLowerLimit) {
return ` (>= ${lowAbsolute} ${displayUnit})`;
}

return unitsDisplay + rangeDisplay;
return units ? ` (${displayUnit})` : '';
};

const NumberField: React.FC<FormFieldInputProps> = ({ field, value, errors, warnings, setFieldValue }) => {
Expand Down
2 changes: 1 addition & 1 deletion src/components/inputs/number/number.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,6 @@ describe('NumberField Component', () => {
warnings: [],
setFieldValue: jest.fn(),
});
expect(screen.getByLabelText('Weight (kg) (0-200)')).toBeInTheDocument();
expect(screen.getByLabelText('Weight (0 - 200 kg)')).toBeInTheDocument();
});
});

0 comments on commit 9248fd2

Please sign in to comment.