) => void,
ctx: FilterRenderContext
) => ReactNode
}
Context Type:
export type FilterRenderContext = {
patient: NhrPatientInfo
}
export type NhrPatientInfo = {
fullName: string
gender: 'male' | 'female' | 'other'
birthDate: string
age: number
}
Purpose:
- key: unique identifier for the filter (used in applying/resetting)
- render: function that produces the UI for the filter, receiving:
- filters: current filter state (entire record of all active filters)
- onChange: callback to patch the filter state with partial updates
- ctx: context including patient info (for country-specific customization)
---
3. How Filters are Used/Rendered in the UI
Main Filter Panel Component: /Users/USER/workspace/doctolib/treatment-plan/packages/tpf-national-health-records-ui/src/components/NhrDocumentListFilterPanel/NhrDocumentListFilterPanel.tsx
Filter Rendering Flow:
1. Panel accepts an array of FilterConfig[] objects
2. Body rendering (lines 47-56):
{filters.map((config) => (
{config.render(pendingFilters, onChange, { patient: {...} })}
))}
3. State management: Each filter maintains its own key in a pendingFilters object
4. User interactions:
- User adjusts filters → onChange(patch) updates the pendingFilters state
- User clicks "Apply filters" → calls onApply(pendingFilters) to commit filters
- User clicks "Reset" → clears all filters (pendingFilters = {})
UI Subcomponents:
- Header: Title + close button
- Body: Maps over FilterConfig[] and renders each filter's UI
- Footer: Reset, Cancel, Apply buttons
---
4. Filter Component Examples
a) NhrDocumentCategoryFilter (Multi-select dropdown)
- File: /Users/USER/workspace/doctolib/treatment-plan/packages/tpf-national-health-records-ui/src/components/NhrDocumentCategoryFilter/NhrDocumentCategoryFilter.tsx
- Is a thin wrapper around
- Props: label, values (selected), options (choices), onToggle, onClear
b) MultiSelectDropdown (Reusable multi-select component)
- File: /Users/USER/workspace/doctolib/treatment-plan/packages/tpf-national-health-records-ui/src/components/MultiSelectDropdown/MultiSelectDropdown.tsx
- Provides search, selection toggle, clear
- Displays selected count (e.g., "Label, +2" for 3 items selected)
- Controlled by values prop (array of selected strings)
c) NhrDateSelectionFilterConfig (Date range filter)
- File: /Users/USER/workspace/doctolib/treatment-plan/packages/tpf-national-health-records-ui/src/business/factories/filters/createNhrDateSelectionFilterConfig.tsx
- key: 'dateMode'
- Manages: dateMode, dateType, submissionDateFrom, submissionDateTo
- Accepts last DMP access date from patient context
d) NhrDocumentStatusFilterConfig (Checkbox filter)
- File: /Users/USER/workspace/doctolib/treatment-plan/packages/tpf-national-health-records-ui/src/business/factories/filters/createNhrDocumentStatusFilterConfig.tsx
- key: 'documentStatus'
- Takes array of StatusOption[] objects
- Each status option maps individually to a boolean filter key
e) NhrDocumentVisibilityFilterConfig (Visibility options)
- File: /Users/USER/workspace/doctolib/treatment-plan/packages/tpf-national-health-records-ui/src/business/factories/filters/createNhrDocumentVisibilityFilterConfig.tsx
- key: 'visibilityGroup'
- Takes visibilityModes array and groupLabel
---
5. Public API Exported from the Package
File: /Users/USER/workspace/doctolib/treatment-plan/packages/tpf-national-health-records-ui/src/index.ts
Main Exports:
- Components: NhrDocumentList, NhrDocumentListFilterPanel, NhrEntryPoint, NhrDocumentVisibilityFilter
- Filter Factory Functions:
- createNhrDocumentCategoryFilterConfig
- createNhrDateSelectionFilterConfig
- createNhrDocumentStatusFilterConfig
- createNhrDocumentVisibilityFilterConfig
- Column Factory Functions: createNhrStatusColumn, createNhrSharedByColumn, createNhrProcedureDateColumn, etc.
- Action Factory Functions: createViewDocumentAction, createMoreActionsAction
- Types Exported: FilterConfig, FilterRenderContext, NhrPatientInfo, StatusOption, VisibilityOption, ActionConfig, ColumnConfig, and others
---
Architecture Highlights
1. Factory Pattern: All filters are created via factory functions that return FilterConfig objects
2. Composition: NhrDocumentListFilterPanel accepts an array of FilterConfig[], making it fully composable
3. State Management: Filters use a patch-based approach with a single pendingFilters object that accumulates changes
4. Component Separation:
- Factories (business layer) create configs
- Components (UI layer) render based on configs
- NhrDocumentListFilterPanel orchestrates the entire filter panel lifecycle
5. Type Safety: Strong TypeScript typing with generic FilterConfig interface allowing country-specific patient context extensions