BN-70 | Add. Custom Logic For Date Distance Calc And Disabling Existing Conditions Being Selected #38
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Card BN-69
JIRA → BN-69
Description
This PR introduces several enhancements and fixes across the Conditions and Diagnoses forms and date utilities. Key updates include improved validation for condition duration, better handling of existing diagnoses when adding them as conditions, and significant refactoring of the Conditions display tables for better maintainability and accessibility.
Key Features
SelectedDiagnosisItemnow dynamically updates its text and disabled state based on whether the diagnosis already exists as a condition (either in the current form or in the patient's existing conditions).SelectedConditionItemis now limited to a maximum value of 999, preventing invalid entries.ExpandableDataTablenow includes anaria-labelfor its expand/collapse column, improving screen reader support.formatDateDistanceutility now provides more precise formatting for durations in years and months (e.g., "1.6 years") and improved rounding for longer durations.SelectedDiagnosisItem,AllergiesTable, andConditionsTableto ensure robustness, cover new features, and verify accessibility compliance.Implementation Details
UI Components
src/components/clinical/forms/conditionsAndDiagnoses/ConditionsAndDiagnoses.tsx:useConditionshook to fetch existing patient conditions.src/components/clinical/forms/conditionsAndDiagnoses/SelectedConditionItem.tsx:numValue <= 999validation to the duration input.itemToStringlogic for duration unit dropdown.src/components/common/expandableDataTable/ExpandableDataTable.tsx: Addedaria-labeltoTableExpandHeaderfor accessibility.src/displayControls/allergies/AllergiesTable.tsxandsrc/displayControls/conditions/ConditionsTable.tsx:renderExpandedContentprop and associated logic, simplifying the table structure.isOpen={true}prop to ensure tables are expanded by default.Custom Hooks
useConditions: Utilized inSelectedDiagnosisItemto check for existing conditions.API Integration
Performance & Optimization
ConditionsTableandAllergiesTableis implicitly handled byExpandableDataTableand React's rendering lifecycle.renderExpandedContentsimplifies rendering logic.Internationalisation
public/locales/locale_en.jsonandpublic/locales/locale_es.json:CONDITIONS_ADD_AS_CONDITIONtext.DIAGNOSES_ALREADY_ADDED_AS_CONDITIONfor disabled link text.TABLE_EXPAND_COLUMN_ARIA_LABELfor table accessibility.Accessibility
SelectedDiagnosisItem:aria-disabledattribute added to the "Add as condition" link.ExpandableDataTable:aria-labeladded to the expand/collapse column header.jest-axetests added toSelectedDiagnosisItem.test.tsx,AllergiesTable.test.tsx, andConditionsTable.test.tsxto ensure WCAG compliance for various states (loading, error, empty, data-filled).Limitations
Testing & Type Definitions
Unit Tests
src/components/clinical/forms/conditionsAndDiagnoses/__tests__/SelectedDiagnosisItem.test.tsx:DataTableSkeleton).doesConditionExistprop anduseConditionshook.onMarkAsConditionbeing called only when the link is enabled.src/components/clinical/forms/conditionsAndDiagnoses/__tests__/SelectedConditionItem.test.tsx:numValue <= 999limit.src/displayControls/allergies/__tests__/AllergiesTable.test.tsxandsrc/displayControls/conditions/__tests__/ConditionsTable.test.tsx:AllergiesTable.onsetDateformatting inConditionsTable.ExpandableDataTablefor more integrated testing.Type Definitions
Important
Checklist
Reviewer(s)
@bahnew/developers
Kindly review the proposed changes when convenient. Your feedback is appreciated.